Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/show_problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
def run(database: str, engine: str, profile: str):
cfg = config.read(profile=profile)
ctx = api.Context(**cfg)
rsp = api.exec(ctx, database, engine, "def output = **nonsense**")
rsp = api.exec(ctx, database, engine, "def output { **nonsense** }")
show.problems(rsp)


Expand Down
2 changes: 1 addition & 1 deletion examples/show_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
def run(database: str, engine: str, profile: str):
cfg = config.read(profile=profile)
ctx = api.Context(**cfg)
rsp = api.exec(ctx, database, engine, "def output = 'a'; 'b'; 'c'")
rsp = api.exec(ctx, database, engine, "def output { 'a'; 'b'; 'c' }")
show.results(rsp)


Expand Down
16 changes: 8 additions & 8 deletions railib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def poll_with_specified_overhead(

if start_time is None:
start_time = time.time()

tries = 0
max_time = time.time() + timeout if timeout else None

Expand All @@ -345,7 +345,7 @@ def poll_with_specified_overhead(
break

current_time = time.time()

if max_tries is not None and tries >= max_tries:
raise Exception(f'max tries {max_tries} exhausted')

Expand All @@ -354,8 +354,8 @@ def poll_with_specified_overhead(

duration = (current_time - start_time) * overhead_rate
duration = min(duration, max_delay)
time.sleep(duration)

time.sleep(duration)
tries += 1


Expand Down Expand Up @@ -800,7 +800,7 @@ def _gen_literal_list(items: list) -> str:
result = []
for item in items:
result.append(_gen_literal(item))
return "{" + ",".join(result) + "}"
return "(" + ",".join(result) + ")"


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


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


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


Expand Down
12 changes: 6 additions & 6 deletions relationalai-sdk-snowflake/test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def tearDownClass(cls):
cls._session.close()

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

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

Expand All @@ -217,15 +217,15 @@ def test_exec_with_data(self):
self._session,
self._db_name,
self._engine_name,
"def output = foo",
"def output { foo }",
{"foo": "hello"}
).collect()[0][0]

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

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

res = self._session.sql(f"select * from {table_name}").collect()
Expand All @@ -237,7 +237,7 @@ def test_exec_into_with_data(self):
self._session,
self._db_name,
self._engine_name,
"def output = foo",
"def output { foo }",
connection_parameters["warehouse"],
table_name,
{"foo": "hello"}
Expand All @@ -259,8 +259,8 @@ def setUp(self) -> None:
api.create_engine(self.session, self.engine_name)

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def setUp(self):
self.assertEqual("CREATED", rsp["database"]["state"])

def test_v2_exec(self):
cmd = "x, x^2, x^3, x^4 from x in {1; 2; 3; 4; 5}"
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"
rsp = api.exec(ctx, dbname, engine, cmd)

# transaction
Expand Down