Skip to content

Commit 140db25

Browse files
authored
[Rel v0.2] Migrate Python SDK files (#153)
1 parent 8daf2d2 commit 140db25

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

examples/show_problems.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
def run(database: str, engine: str, profile: str):
2424
cfg = config.read(profile=profile)
2525
ctx = api.Context(**cfg)
26-
rsp = api.exec(ctx, database, engine, "def output = **nonsense**")
26+
rsp = api.exec(ctx, database, engine, "def output { **nonsense** }")
2727
show.problems(rsp)
2828

2929

examples/show_results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
def run(database: str, engine: str, profile: str):
2525
cfg = config.read(profile=profile)
2626
ctx = api.Context(**cfg)
27-
rsp = api.exec(ctx, database, engine, "def output = 'a'; 'b'; 'c'")
27+
rsp = api.exec(ctx, database, engine, "def output { 'a'; 'b'; 'c' }")
2828
show.results(rsp)
2929

3030

railib/api.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def poll_with_specified_overhead(
336336

337337
if start_time is None:
338338
start_time = time.time()
339-
339+
340340
tries = 0
341341
max_time = time.time() + timeout if timeout else None
342342

@@ -345,7 +345,7 @@ def poll_with_specified_overhead(
345345
break
346346

347347
current_time = time.time()
348-
348+
349349
if max_tries is not None and tries >= max_tries:
350350
raise Exception(f'max tries {max_tries} exhausted')
351351

@@ -354,8 +354,8 @@ def poll_with_specified_overhead(
354354

355355
duration = (current_time - start_time) * overhead_rate
356356
duration = min(duration, max_delay)
357-
358-
time.sleep(duration)
357+
358+
time.sleep(duration)
359359
tries += 1
360360

361361

@@ -800,7 +800,7 @@ def _gen_literal_list(items: list) -> str:
800800
result = []
801801
for item in items:
802802
result.append(_gen_literal(item))
803-
return "{" + ",".join(result) + "}"
803+
return "(" + ",".join(result) + ")"
804804

805805

806806
# Genearte a rel literal for the given string.
@@ -832,7 +832,7 @@ def _gen_syntax_config(syntax: dict = {}) -> str:
832832
for k in _syntax_options:
833833
v = syntax.get(k, None)
834834
if v is not None:
835-
result += f"def config:syntax:{k}={_gen_literal(v)}\n"
835+
result += f"def config[:syntax, :{k}]: {_gen_literal(v)}\n"
836836
return result
837837

838838

@@ -861,7 +861,7 @@ def load_csv(
861861
raise TypeError(f"bad type for arg 'data': {data.__class__.__name__}")
862862
inputs = {"data": data}
863863
command = _gen_syntax_config(syntax)
864-
command += "def config:data = data\n" "def insert:%s = load_csv[config]" % relation
864+
command += "def config[:data]: data\n" "def insert[:%s]: load_csv[config]" % relation
865865
return exec_v1(ctx, database, engine, command, inputs=inputs, readonly=False)
866866

867867

@@ -879,7 +879,7 @@ def load_json(
879879
else:
880880
raise TypeError(f"bad type for arg 'data': {data.__class__.__name__}")
881881
inputs = {"data": data}
882-
command = "def config:data = data\n" "def insert:%s = load_json[config]" % relation
882+
command = "def config[:data]: data\n" "def insert[:%s]: load_json[config]" % relation
883883
return exec_v1(ctx, database, engine, command, inputs=inputs, readonly=False)
884884

885885

relationalai-sdk-snowflake/test/test_integration.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def tearDownClass(cls):
208208
cls._session.close()
209209

210210
def test_exec(self):
211-
res = json.loads(api.exec(self._session, self._db_name, self._engine_name, "def output = 1 + 1").collect()[0][0])
211+
res = json.loads(api.exec(self._session, self._db_name, self._engine_name, "def output {1 + 1}").collect()[0][0])
212212

213213
self.assertEqual(res[0][0], 2)
214214

@@ -217,15 +217,15 @@ def test_exec_with_data(self):
217217
self._session,
218218
self._db_name,
219219
self._engine_name,
220-
"def output = foo",
220+
"def output { foo }",
221221
{"foo": "hello"}
222222
).collect()[0][0]
223223

224224
self.assertEqual(json.loads(res)[0][0], "hello")
225225

226226
def test_exec_into(self):
227227
table_name = f"{FQ_SCHEMA}.test_exec_into_table"
228-
res = api.exec_into(self._session, self._db_name, self._engine_name, "def output = 1 + 1", connection_parameters["warehouse"], table_name)
228+
res = api.exec_into(self._session, self._db_name, self._engine_name, "def output {1 + 1}", connection_parameters["warehouse"], table_name)
229229
self.assertTrue(check_status_ok(res))
230230

231231
res = self._session.sql(f"select * from {table_name}").collect()
@@ -237,7 +237,7 @@ def test_exec_into_with_data(self):
237237
self._session,
238238
self._db_name,
239239
self._engine_name,
240-
"def output = foo",
240+
"def output { foo }",
241241
connection_parameters["warehouse"],
242242
table_name,
243243
{"foo": "hello"}
@@ -259,8 +259,8 @@ def setUp(self) -> None:
259259
api.create_engine(self.session, self.engine_name)
260260

261261
def test_load_model_code(self):
262-
res = api.load_model_code(self.session, self.db_name, self.engine_name, "my_model", "def mymax[x, y] = maximum[abs[x], abs[y]]")
263-
res = json.loads(api.exec(self.session, self.db_name, self.engine_name, "def output = mymax[5, -10]").collect()[0][0])
262+
res = api.load_model_code(self.session, self.db_name, self.engine_name, "my_model", "def mymax[x, y]: maximum[abs[x], abs[y]]")
263+
res = json.loads(api.exec(self.session, self.db_name, self.engine_name, "def output { mymax[5, -10] }").collect()[0][0])
264264

265265
self.assertEqual(res[0][0], 10)
266266

test/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def setUp(self):
5252
self.assertEqual("CREATED", rsp["database"]["state"])
5353

5454
def test_v2_exec(self):
55-
cmd = "x, x^2, x^3, x^4 from x in {1; 2; 3; 4; 5}"
55+
cmd = "def output(x, x2, x3, x4): {1; 2; 3; 4; 5}(x) and x2 = x^2 and x3 = x^3 and x4 = x^4"
5656
rsp = api.exec(ctx, dbname, engine, cmd)
5757

5858
# transaction

0 commit comments

Comments
 (0)