Skip to content

Commit d53a851

Browse files
committed
API client for tables import
1 parent 7a92487 commit d53a851

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

dataikuapi/dss/project.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,59 @@ 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+
return TablesImportBuffer(self.client, self.project_key)
829+
830+
class TablesImportBuffer(object):
831+
832+
def __init__(self, client, project_key):
833+
"""Do not call this directly, use :meth:`DSSProject.init_tables_import`"""
834+
self.client = client
835+
self.project_key = project_key
836+
self.keys = []
837+
838+
def add_hive_table(self, hive_database, hive_table):
839+
self.keys.append({
840+
"connectionName" : "@virtual(hive-jdbc):" + hive_database,
841+
"name" : hive_table
842+
})
843+
844+
def add_sql_table(self, connection, schema, table):
845+
self.keys.append({
846+
"connectionName" : connection,
847+
"schema": schema,
848+
"name" : table
849+
})
850+
851+
def prepare(self):
852+
ret = self.client._perform_json("POST", "/projects/%s/datasets/tables-import/actions/prepare-from-keys" % (self.project_key),
853+
body = {"keys": self.keys} )
854+
855+
future = self.client.get_future(ret["jobId"])
856+
future.wait_for_result()
857+
return TablesPreparedImport(self.client, self.project_key, future.get_result())
858+
859+
class TablesPreparedImport(object):
860+
"""Do not call this directly, use :meth:`DSSProject.init_tables_import` and then prepare"""
861+
def __init__(self, client, project_key, candidates):
862+
self.client = client
863+
self.project_key = project_key
864+
self.candidates = candidates
865+
866+
def execute(self):
867+
"""
868+
Executes the import in background
869+
870+
:rtype: :class:`dataikuapi.dss.future.DSSFuture`
871+
"""
872+
ret = self.client._perform_json("POST", "/projects/%s/datasets/tables-import/actions/execute-from-candidates" % (self.project_key),
873+
body = self.candidates)
874+
return self.client.get_future(ret["jobId"])
875+
823876
class DSSProjectSettings(object):
824877
"""Settings of a DSS project"""
825878

0 commit comments

Comments
 (0)