@@ -646,14 +646,14 @@ def get_scenario(self, scenario_id):
646646 """
647647 return DSSScenario (self .client , self .project_key , scenario_id )
648648
649- def create_scenario (self , scenario_name , type , definition = {}):
649+ def create_scenario (self , scenario_name , type , definition = {'params' : {} }):
650650 """
651651 Create a new scenario in the project, and return a handle to interact with it
652652
653653 :param str scenario_name: The name for the new scenario. This does not need to be unique
654654 (although this is strongly recommended)
655655 :param str type: The type of the scenario. MUst be one of 'step_based' or 'custom_python'
656- :param object definition: the JSON definition of the scenario. Use ``get_definition`` on an
656+ :param object definition: the JSON definition of the scenario. Use ``get_definition(with_status=False) `` on an
657657 existing ``DSSScenario`` object in order to get a sample definition object
658658
659659 :returns: a :class:`.scenario.DSSScenario` handle to interact with the newly-created scenario
@@ -820,6 +820,82 @@ def get_object_discussions(self):
820820 """
821821 return DSSObjectDiscussions (self .client , self .project_key , "PROJECT" , self .project_key )
822822
823+ ########################################################
824+ # Tables import
825+ ########################################################
826+
827+ def init_tables_import (self ):
828+ """
829+ Start an operation to import Hive or SQL tables as datasets into this project
830+
831+ :returns: a :class:`TablesImportDefinition` to add tables to import
832+ :rtype: :class:`TablesImportDefinition`
833+ """
834+ return TablesImportDefinition (self .client , self .project_key )
835+
836+ class TablesImportDefinition (object ):
837+ """
838+ Temporary structure holding the list of tables to import
839+ """
840+
841+ def __init__ (self , client , project_key ):
842+ """Do not call this directly, use :meth:`DSSProject.init_tables_import`"""
843+ self .client = client
844+ self .project_key = project_key
845+ self .keys = []
846+
847+ def add_hive_table (self , hive_database , hive_table ):
848+ """Add a Hive table to the list of tables to import"""
849+ self .keys .append ({
850+ "connectionName" : "@virtual(hive-jdbc):" + hive_database ,
851+ "name" : hive_table
852+ })
853+
854+ def add_sql_table (self , connection , schema , table ):
855+ """Add a SQL table to the list of table to import"""
856+ self .keys .append ({
857+ "connectionName" : connection ,
858+ "schema" : schema ,
859+ "name" : table
860+ })
861+
862+ def prepare (self ):
863+ """
864+ Run the first step of the import process. In this step, DSS will check
865+ the tables whose import you have requested and prepare dataset names and
866+ target connections
867+
868+ :returns: a :class:`TablesPreparedImport` object that allows you to finalize the import process
869+ :rtype: :class:`TablesPreparedImport`
870+
871+ """
872+ ret = self .client ._perform_json ("POST" , "/projects/%s/datasets/tables-import/actions/prepare-from-keys" % (self .project_key ),
873+ body = {"keys" : self .keys } )
874+
875+ future = self .client .get_future (ret ["jobId" ])
876+ future .wait_for_result ()
877+ return TablesPreparedImport (self .client , self .project_key , future .get_result ())
878+
879+ class TablesPreparedImport (object ):
880+ """Result of preparing a tables import. Import can now be finished"""
881+
882+ def __init__ (self , client , project_key , candidates ):
883+ """Do not call this directly, use :meth:`DSSProject.init_tables_import` and then prepare"""
884+ self .client = client
885+ self .project_key = project_key
886+ self .candidates = candidates
887+
888+ def execute (self ):
889+ """
890+ Starts executing the import in background and returns a :class:`dataikuapi.dss.future.DSSFuture` to wait on the result
891+
892+ :returns: a future to wait on the result
893+ :rtype: :class:`dataikuapi.dss.future.DSSFuture`
894+ """
895+ ret = self .client ._perform_json ("POST" , "/projects/%s/datasets/tables-import/actions/execute-from-candidates" % (self .project_key ),
896+ body = self .candidates )
897+ return self .client .get_future (ret ["jobId" ])
898+
823899class DSSProjectSettings (object ):
824900 """Settings of a DSS project"""
825901
0 commit comments