Skip to content

Commit

Permalink
ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkinulas committed Apr 5, 2024
1 parent 1d1101e commit 7c203b1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fakesnow/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _execute(
.transform(transforms.timestamp_ntz_ns)
.transform(transforms.float_to_double)
.transform(transforms.integer_precision)
# TODO(selman): Broken, fails on CTAS queries with CASTs;
# TODO(selman): Broken, fails on CTAS queries with CASTs;
# CREATE TABLE SOME_TABLE AS (
# SELECT
# R1 AS C1,
Expand Down
1 change: 1 addition & 0 deletions fakesnow/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,7 @@ def json_extract_in_string_literals(expression: exp.Expression) -> exp.Expressio
json_extract_scalar = exp.JSONExtractScalar(this=je.this, expression=path)
return exp.In(this=json_extract_scalar, expressions=expression.expressions)


def object_agg(expression: exp.Expression) -> exp.Expression:
if (
isinstance(expression, exp.Anonymous)
Expand Down
7 changes: 6 additions & 1 deletion tests/test_fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1507,12 +1507,17 @@ def test_json_extract_cast_as_varchar(dcur: snowflake.connector.cursor.DictCurso
dcur.execute("SELECT j:str::number as c_str_number, j:number::number as c_num_number FROM example")
assert dcur.fetchall() == [{"C_STR_NUMBER": 100, "C_NUM_NUMBER": 100}]


def test_json_group_object(dcur: snowflake.connector.cursor.DictCursor):
dcur.execute("create table table1 (id number, key varchar, value varchar)")
values = [(1, "a", "1"), (1, "b", "2"), (1, "c", "3"), (2, "e", "1"), (2, "f", "1"), (3, "a", "2")]

dcur.executemany("insert into table1 values (%s, %s, %s)", values)
expected = [{'ID': 1, 'OBJ': '{\n "a": "1",\n "b": "2",\n "c": "3"\n}'}, {'ID': 2, 'OBJ': '{\n "e": "1",\n "f": "1"\n}'}, {'ID': 3, 'OBJ': '{\n "a": "2"\n}'}]
expected = [
{"ID": 1, "OBJ": '{\n "a": "1",\n "b": "2",\n "c": "3"\n}'},
{"ID": 2, "OBJ": '{\n "e": "1",\n "f": "1"\n}'},
{"ID": 3, "OBJ": '{\n "a": "2"\n}'},
]
dcur.execute("select id, object_agg(key, value) as obj from table1 group by 1")
assert dindent(dcur.fetchall()) == expected

Expand Down
1 change: 1 addition & 0 deletions tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ def test_trim_cast_varchar() -> None:
== "SELECT TRIM(CAST(col AS TEXT)) FROM table1"
)


def test_upper_case_unquoted_identifiers() -> None:
assert (
sqlglot.parse_one("select name, name as fname from table1").transform(upper_case_unquoted_identifiers).sql()
Expand Down

0 comments on commit 7c203b1

Please sign in to comment.