2016-06-23 20:34:04 +08:00
|
|
|
CREATE TYPE cdb_dataservices_server.ds_fdw_metadata as (schemaname text, tabname text, servername text);
|
2016-06-24 17:29:21 +08:00
|
|
|
|
2016-06-23 20:34:04 +08:00
|
|
|
CREATE TYPE cdb_dataservices_server.ds_return_metadata as (colnames text[], coltypes text[]);
|
2016-06-10 17:34:07 +08:00
|
|
|
|
2016-08-30 00:07:58 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_ConnectUserTable(username text, orgname text, user_db_role text, input_schema text, dbname text, table_name text)
|
2016-06-24 17:29:21 +08:00
|
|
|
RETURNS cdb_dataservices_server.ds_fdw_metadata AS $$
|
2016-07-15 17:54:38 +08:00
|
|
|
host_addr = plpy.execute("SELECT split_part(inet_client_addr()::text, '/', 1) as user_host")[0]['user_host']
|
2016-08-30 22:38:44 +08:00
|
|
|
return plpy.execute("SELECT * FROM cdb_dataservices_server.__DST_ConnectUserTable({username}::text, {orgname}::text, {user_db_role}::text, {schema}::text, {dbname}::text, {host_addr}::text, {table_name}::text)"
|
2016-07-15 17:54:38 +08:00
|
|
|
.format(username=plpy.quote_nullable(username), orgname=plpy.quote_nullable(orgname), user_db_role=plpy.quote_literal(user_db_role), schema=plpy.quote_literal(input_schema), dbname=plpy.quote_literal(dbname), table_name=plpy.quote_literal(table_name), host_addr=plpy.quote_literal(host_addr))
|
2016-06-24 17:29:21 +08:00
|
|
|
)[0]
|
2017-11-08 00:23:05 +08:00
|
|
|
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
|
2016-06-10 17:34:07 +08:00
|
|
|
|
2016-08-30 00:07:58 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.__DST_ConnectUserTable(username text, orgname text, user_db_role text, input_schema text, dbname text, host_addr text, table_name text)
|
2016-06-24 17:29:21 +08:00
|
|
|
RETURNS cdb_dataservices_server.ds_fdw_metadata AS $$
|
2016-06-10 17:34:07 +08:00
|
|
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
2016-06-24 17:29:21 +08:00
|
|
|
TARGET cdb_observatory._OBS_ConnectUserTable;
|
2017-11-07 22:32:07 +08:00
|
|
|
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
|
2016-06-10 17:34:07 +08:00
|
|
|
|
2016-08-30 00:07:58 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_GetReturnMetadata(username text, orgname text, function_name text, params json)
|
2016-06-24 17:29:21 +08:00
|
|
|
RETURNS cdb_dataservices_server.ds_return_metadata AS $$
|
2016-06-10 17:34:07 +08:00
|
|
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
2016-06-24 17:29:21 +08:00
|
|
|
TARGET cdb_observatory._OBS_GetReturnMetadata;
|
2017-11-07 22:32:07 +08:00
|
|
|
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
|
2016-06-10 17:34:07 +08:00
|
|
|
|
2016-08-30 00:07:58 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_FetchJoinFdwTableData(username text, orgname text, table_schema text, table_name text, function_name text, params json)
|
2016-06-10 17:34:07 +08:00
|
|
|
RETURNS SETOF record AS $$
|
|
|
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
2016-06-24 17:29:21 +08:00
|
|
|
TARGET cdb_observatory._OBS_FetchJoinFdwTableData;
|
2017-11-07 22:32:07 +08:00
|
|
|
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
|
2016-06-10 17:34:07 +08:00
|
|
|
|
|
|
|
|
2016-08-30 00:07:58 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_DisconnectUserTable(username text, orgname text, table_schema text, table_name text, servername text)
|
2016-06-10 17:34:07 +08:00
|
|
|
RETURNS boolean AS $$
|
|
|
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
2016-06-24 17:29:21 +08:00
|
|
|
TARGET cdb_observatory._OBS_DisconnectUserTable;
|
2017-11-07 22:32:07 +08:00
|
|
|
$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE;
|