Skip to content

Commit

Permalink
fix: object_construct now supports different types
Browse files Browse the repository at this point in the history
  • Loading branch information
tekumara committed Jun 3, 2023
1 parent 02fd6a4 commit fa50752
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions fakesnow/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,15 @@ def object_construct(expression: exp.Expression) -> exp.Expression:
Example:
>>> import sqlglot
>>> sqlglot.parse_one("SELECT OBJECT_CONSTRUCT('a',1,'b','BBBB', 'c',null)", read="snowflake").transform(object_construct).sql(dialect="duckdb")
"SELECT TO_JSON(OBJECT_CONSTRUCT('a',1,'b','BBBB', 'c',null))"
"SELECT TO_JSON({'a': 1, 'b': 'BBBB', 'c': NULL})"
Args:
expression (exp.Expression): the expression that will be transformed.
Returns:
exp.Expression: The transformed expression.
""" # noqa: E501

if isinstance(expression, exp.VarMap):
if isinstance(expression, exp.Struct):
return exp.Anonymous(this="TO_JSON", expressions=[expression])

return expression
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies = [
"duckdb~=0.8.0",
# include the pandas extra to get compatible version of pyarrow
"snowflake-connector-python[pandas]",
"sqlglot~=14.1.1",
"sqlglot~=15.0.0",
]

[project.urls]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_object_construct() -> None:
sqlglot.parse_one("SELECT OBJECT_CONSTRUCT('a',1,'b','BBBB', 'c',null)", read="snowflake")
.transform(object_construct)
.sql(dialect="duckdb")
== "SELECT TO_JSON(MAP(LIST_VALUE('a', 'b', 'c'), LIST_VALUE(1, 'BBBB', NULL)))"
== "SELECT TO_JSON({'a': 1, 'b': 'BBBB', 'c': NULL})"
)


Expand Down

0 comments on commit fa50752

Please sign in to comment.