Skip to content

Commit c9efdd7

Browse files
committed
Merge branch 'release/8.0'
2 parents 61d04c7 + b6ed6c5 commit c9efdd7

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

dataikuapi/dss/future.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def wait_for_result(self):
7272
"""
7373
Wait and get the future result
7474
"""
75+
if self.state.get('hasResult', False):
76+
return self.result_wrapper(self.state.get('result', None))
7577
if self.state is None or not self.state.get('hasResult', False) or self.state_is_peek:
7678
self.get_state()
7779
while not self.state.get('hasResult', False):

dataikuapi/dss/recipe.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,25 @@ def run(self, job_type="NON_RECURSIVE_FORCED_BUILD", partitions=None, wait=True,
7676
:return: the :class:`dataikuapi.dss.job.DSSJob` job handle corresponding to the built job
7777
:rtype: :class:`dataikuapi.dss.job.DSSJob`
7878
"""
79+
project = self.client.get_project(self.project_key)
80+
outputs = project.get_flow().get_graph().get_successor_computables(self)
7981

80-
settings = self.get_settings()
81-
output_refs = settings.get_flat_output_refs()
82-
83-
if len(output_refs) == 0:
82+
if len(outputs) == 0:
8483
raise Exception("recipe has no outputs, can't run it")
8584

86-
jd = self.client.get_project(self.project_key).new_job(job_type)
87-
jd.with_output(output_refs[0], partition=partitions)
85+
first_output = outputs[0]
86+
87+
object_type_map = {
88+
"COMPUTABLE_DATASET": "DATASET",
89+
"COMPUTABLE_FOLDER": "MANAGED_FOLDER",
90+
"COMPUTABLE_SAVED_MODEL": "SAVED_MODEL",
91+
"COMPUTABLE_STREAMING_ENDPOINT": "STREAMING_ENDPOINT",
92+
}
93+
if first_output["type"] in object_type_map:
94+
jd = project.new_job(job_type)
95+
jd.with_output(first_output["ref"], object_type=object_type_map[first_output["type"]], partition=partitions)
96+
else:
97+
raise Exception("Recipe has unsupported output type {}, can't run it".format(first_output["type"]))
8898

8999
if wait:
90100
return jd.start_and_wait()
@@ -1121,7 +1131,7 @@ def set_code_env(self, code_env=None, inherit=False, use_builtin=False):
11211131
raise ValueError("This recipe kind does not seem to take a code env selection")
11221132

11231133
if code_env is not None:
1124-
rp["envSelection"] = {"envMode": "EXPLICIT_ENV", "envName": "code_env"}
1134+
rp["envSelection"] = {"envMode": "EXPLICIT_ENV", "envName": code_env}
11251135
elif inherit:
11261136
rp["envSelection"] = {"envMode": "INHERIT"}
11271137
elif use_builtin:

dataikuapi/dss/sqlquery.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
from ..utils import DataikuStreamedHttpUTF8CSVReader
44
import json
55

6+
67
class DSSSQLQuery(object):
78
"""
8-
A connection to a database or database-like on which queries can be run through DSS
9+
A connection to a database or database-like on which queries can be run through DSS.
10+
Do not create this class directly, instead use :meth:`dataikuapi.DSSClient.sql_query`
911
"""
10-
def __init__(self, client, query, connection, database, dataset_full_name, pre_queries, post_queries, type, extra_conf, script_steps, script_input_schema, script_output_schema, script_report_location, read_timestamp_without_timezone_as_string, read_date_as_string):
12+
def __init__(self, client, query, connection, database, dataset_full_name, pre_queries, post_queries, type, extra_conf, script_steps, script_input_schema, script_output_schema, script_report_location, read_timestamp_without_timezone_as_string, read_date_as_string, project_key):
1113
self.client = client
1214

1315
self.streaming_session = self.client._perform_json(
@@ -19,6 +21,7 @@ def __init__(self, client, query, connection, database, dataset_full_name, pre_q
1921
"connection" : connection,
2022
"database" : database,
2123
"datasetFullName" : dataset_full_name,
24+
"projectKey" : project_key,
2225
"type" : type,
2326
"extraConf" : extra_conf,
2427
"scriptSteps" : script_steps,

dataikuapi/dssclient.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def get_plugin(self, plugin_id):
302302
# SQL queries
303303
########################################################
304304

305-
def sql_query(self, query, connection=None, database=None, dataset_full_name=None, pre_queries=None, post_queries=None, type='sql', extra_conf=None, script_steps=None, script_input_schema=None, script_output_schema=None, script_report_location=None, read_timestamp_without_timezone_as_string=True, read_date_as_string=False):
305+
def sql_query(self, query, connection=None, database=None, dataset_full_name=None, pre_queries=None, post_queries=None, type='sql', extra_conf=None, script_steps=None, script_input_schema=None, script_output_schema=None, script_report_location=None, read_timestamp_without_timezone_as_string=True, read_date_as_string=False, project_key=None):
306306
"""
307307
Initiate a SQL, Hive or Impala query and get a handle to retrieve the results of the query.
308308
Internally, the query is run by DSS. The database to run the query on is specified either by
@@ -316,12 +316,13 @@ def sql_query(self, query, connection=None, database=None, dataset_full_name=Non
316316
:param list pre_queries: (optional) array of queries to run before the query
317317
:param list post_queries: (optional) array of queries to run after the query
318318
:param str type: the type of query : either 'sql', 'hive' or 'impala'
319-
319+
:param str project_key: The project_key on which the query should be run (especially useful for user isolation/impersonation scenario)
320+
320321
:returns: A :class:`dataikuapi.dss.sqlquery.DSSSQLQuery` query handle
321322
"""
322323
if extra_conf is None:
323324
extra_conf = {}
324-
return DSSSQLQuery(self, query, connection, database, dataset_full_name, pre_queries, post_queries, type, extra_conf, script_steps, script_input_schema, script_output_schema, script_report_location, read_timestamp_without_timezone_as_string, read_date_as_string)
325+
return DSSSQLQuery(self, query, connection, database, dataset_full_name, pre_queries, post_queries, type, extra_conf, script_steps, script_input_schema, script_output_schema, script_report_location, read_timestamp_without_timezone_as_string, read_date_as_string, project_key)
325326

326327
########################################################
327328
# Users

0 commit comments

Comments
 (0)