@@ -860,6 +860,53 @@ def init_tables_import(self):
860860 """
861861 return TablesImportDefinition (self .client , self .project_key )
862862
863+ def list_sql_schemas (self , connection_name ):
864+ """
865+ Lists schemas from which tables can be imported in a SQL connection
866+
867+ :returns: an array of schemas names
868+ """
869+ return self ._list_schemas (connection_name )
870+
871+ def list_hive_databases (self ):
872+ """
873+ Lists Hive databases from which tables can be imported
874+
875+ :returns: an array of databases names
876+ """
877+ return self ._list_schemas ("@virtual(hive-jdbc):default" )
878+
879+ def _list_schemas (self , connection_name ):
880+ return self .client ._perform_json ("GET" , "/projects/%s/datasets/tables-import/actions/list-schemas" % (self .project_key ),
881+ params = {"connectionName" : connection_name } )
882+
883+ def list_sql_tables (self , connection_name , schema_name = None ):
884+ """
885+ Lists tables to import in a SQL connection
886+
887+ :returns: an array of tables
888+ """
889+ ret = self .client ._perform_json ("GET" , "/projects/%s/datasets/tables-import/actions/list-tables" % (self .project_key ),
890+ params = {"connectionName" : connection_name , "schemaName" : schema_name } )
891+
892+ def to_schema_table_pair (x ):
893+ return {"schema" :x .get ("schema" , None ), "table" :x ["table" ]}
894+ return [to_schema_table_pair (x ) for x in DSSFuture .get_result_wait_if_needed (self .client , ret )['tables' ]]
895+
896+ def list_hive_tables (self , hive_database ):
897+ """
898+ Lists tables to import in a Hive database
899+
900+ :returns: an array of tables
901+ """
902+ connection_name = "@virtual(hive-jdbc):" + hive_database
903+ ret = self .client ._perform_json ("GET" , "/projects/%s/datasets/tables-import/actions/list-tables" % (self .project_key ),
904+ params = {"connectionName" : connection_name } )
905+
906+ def to_schema_table_pair (x ):
907+ return {"schema" :x .get ("databaseName" , None ), "table" :x ["table" ]}
908+ return [to_schema_table_pair (x ) for x in DSSFuture .get_result_wait_if_needed (self .client , ret )['tables' ]]
909+
863910class TablesImportDefinition (object ):
864911 """
865912 Temporary structure holding the list of tables to import
0 commit comments