@@ -838,6 +838,63 @@ def init_tables_import(self):
838838 """
839839 return TablesImportDefinition (self .client , self .project_key )
840840
841+ def list_sql_schemas (self , connection_name ):
842+ """
843+ Lists schemas from which tables can be imported in a SQL connection
844+
845+ :returns: an array of schemas names
846+ """
847+ return self ._list_schemas (connection_name )
848+
849+ def list_hive_databases (self ):
850+ """
851+ Lists Hive databases from which tables can be imported
852+
853+ :returns: an array of database names
854+ """
855+ return self ._list_schemas ("@virtual(hive-jdbc):default" )
856+
857+ def _list_schemas (self , connection_name ):
858+ return self .client ._perform_json ("GET" , "/projects/%s/datasets/tables-import/actions/list-schemas" % (self .project_key ),
859+ params = {"connectionName" : connection_name } )
860+
861+ def list_sql_tables (self , connection_name , schema_name = None ):
862+ """
863+ Lists tables to import in a SQL connection
864+
865+ :returns: an array of tables
866+ """
867+ ret = self .client ._perform_json ("GET" , "/projects/%s/datasets/tables-import/actions/list-tables" % (self .project_key ),
868+ params = {"connectionName" : connection_name , "schemaName" : schema_name } )
869+
870+ def to_schema_table_pair (x ):
871+ return {"schema" :x .get ("schema" , None ), "table" :x ["table" ]}
872+ if 'jobId' in ret :
873+ future = self .client .get_future (ret ["jobId" ])
874+ future .wait_for_result ()
875+ return [to_schema_table_pair (x ) for x in future .get_result ()]
876+ else :
877+ return [to_schema_table_pair (x ) for x in ret ['result' ]]
878+
879+ def list_hive_tables (self , hive_database ):
880+ """
881+ Lists tables to import in a Hive database
882+
883+ :returns: an array of tables
884+ """
885+ connection_name = "@virtual(hive-jdbc):" + hive_database
886+ ret = self .client ._perform_json ("GET" , "/projects/%s/datasets/tables-import/actions/list-tables" % (self .project_key ),
887+ params = {"connectionName" : connection_name } )
888+
889+ def to_schema_table_pair (x ):
890+ return {"schema" :x .get ("databaseName" , None ), "table" :x ["table" ]}
891+ if 'jobId' in ret :
892+ future = self .client .get_future (ret ["jobId" ])
893+ future .wait_for_result ()
894+ return [to_schema_table_pair (x ) for x in future .get_result ()['tables' ]]
895+ else :
896+ return [to_schema_table_pair (x ) for x in ret ['result' ]['tables' ]]
897+
841898class TablesImportDefinition (object ):
842899 """
843900 Temporary structure holding the list of tables to import
0 commit comments