Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update sqlglot requirement from ~=25.9.0 to ~=25.21.3 #137

Closed
wants to merge 2 commits into from
Closed
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
37 changes: 15 additions & 22 deletions fakesnow/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def alias_in_join(expression: exp.Expression) -> exp.Expression:
def alter_table_strip_cluster_by(expression: exp.Expression) -> exp.Expression:
"""Turn alter table cluster by into a no-op"""
if (
isinstance(expression, exp.AlterTable)
isinstance(expression, exp.Alter)
and (actions := expression.args.get("actions"))
and len(actions) == 1
and (isinstance(actions[0], exp.Cluster))
Expand Down Expand Up @@ -356,7 +356,7 @@ def extract_comment_on_columns(expression: exp.Expression) -> exp.Expression:
exp.Expression: The transformed expression, with any comment stored in the new 'table_comment' arg.
"""

if isinstance(expression, exp.AlterTable) and (actions := expression.args.get("actions")):
if isinstance(expression, exp.Alter) and (actions := expression.args.get("actions")):
new_actions: list[exp.Expression] = []
col_comments: list[tuple[str, str]] = []
for a in actions:
Expand Down Expand Up @@ -410,7 +410,7 @@ def extract_comment_on_table(expression: exp.Expression) -> exp.Expression:
new.args["table_comment"] = (table, cexp.this)
return new
elif (
isinstance(expression, exp.AlterTable)
isinstance(expression, exp.Alter)
and (sexp := expression.find(exp.AlterSet))
and (scp := sexp.find(exp.SchemaCommentProperty))
and isinstance(scp.this, exp.Literal)
Expand All @@ -436,7 +436,7 @@ def extract_text_length(expression: exp.Expression) -> exp.Expression:
exp.Expression: The original expression, with any text lengths stored in the new 'text_lengths' arg.
"""

if isinstance(expression, (exp.Create, exp.AlterTable)):
if isinstance(expression, (exp.Create, exp.Alter)):
text_lengths = []

# exp.Select is for a ctas, exp.Schema is a plain definition
Expand Down Expand Up @@ -707,8 +707,8 @@ def random(expression: exp.Expression) -> exp.Expression:
new_rand = exp.Cast(
this=exp.Paren(
this=exp.Mul(
this=exp.Paren(this=exp.Sub(this=exp.Rand(), expression=exp.Literal(this=0.5, is_string=False))),
expression=exp.Literal(this=9223372036854775807, is_string=False),
this=exp.Paren(this=exp.Sub(this=exp.Rand(), expression=exp.Literal(this="0.5", is_string=False))),
expression=exp.Literal(this="9223372036854775807", is_string=False),
)
),
to=exp.DataType(this=exp.DataType.Type.BIGINT, nested=False, prefix=False),
Expand Down Expand Up @@ -809,31 +809,24 @@ def regex_substr(expression: exp.Expression) -> exp.Expression:
pattern.args["this"] = pattern.this.replace("\\\\", "\\")

# number of characters from the beginning of the string where the function starts searching for matches
try:
position = expression.args["position"]
except KeyError:
position = exp.Literal(this="1", is_string=False)
position = expression.args["position"] or exp.Literal(this="1", is_string=False)

# which occurrence of the pattern to match
try:
occurrence = int(expression.args["occurrence"].this)
except KeyError:
occurrence = 1
occurrence = expression.args["occurrence"]
occurrence = int(occurrence.this) if occurrence else 1

# the duckdb dialect increments bracket (ie: index) expressions by 1 because duckdb is 1-indexed,
# so we need to compensate by subtracting 1
occurrence = exp.Literal(this=str(occurrence - 1), is_string=False)

try:
regex_parameters_value = str(expression.args["parameters"].this)
if parameters := expression.args["parameters"]:
# 'e' parameter doesn't make sense for duckdb
regex_parameters = exp.Literal(this=regex_parameters_value.replace("e", ""), is_string=True)
except KeyError:
regex_parameters = exp.Literal(this=parameters.this.replace("e", ""), is_string=True)
else:
regex_parameters = exp.Literal(is_string=True)

try:
group_num = expression.args["group"]
except KeyError:
group_num = expression.args["group"]
if not group_num:
if isinstance(regex_parameters.this, str) and "e" in regex_parameters.this:
group_num = exp.Literal(this="1", is_string=False)
else:
Expand Down Expand Up @@ -1023,7 +1016,7 @@ def tag(expression: exp.Expression) -> exp.Expression:
exp.Expression: The transformed expression.
"""

if isinstance(expression, exp.AlterTable) and (actions := expression.args.get("actions")):
if isinstance(expression, exp.Alter) and (actions := expression.args.get("actions")):
for a in actions:
if isinstance(a, exp.AlterSet) and a.args.get("tag"):
return SUCCESS_NOP
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~=1.0.0",
"pyarrow",
"snowflake-connector-python",
"sqlglot~=25.9.0",
"sqlglot~=25.21.3",
]

[project.urls]
Expand Down
Loading