From 14eb8db3fc70986521c7c0c12b6c3db934ae411d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Sep 2024 11:00:50 +0000 Subject: [PATCH 1/2] chore(deps): update sqlglot requirement from ~=25.9.0 to ~=25.21.3 Updates the requirements on [sqlglot](https://github.com/tobymao/sqlglot) to permit the latest version. - [Changelog](https://github.com/tobymao/sqlglot/blob/main/CHANGELOG.md) - [Commits](https://github.com/tobymao/sqlglot/compare/v25.9.0...v25.21.3) --- updated-dependencies: - dependency-name: sqlglot dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f85fb52..e6d47c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ dependencies = [ "duckdb~=1.0.0", "pyarrow", "snowflake-connector-python", - "sqlglot~=25.9.0", + "sqlglot~=25.21.3", ] [project.urls] From 0a6c217a17487847c966d2124c9b01923bcb4132 Mon Sep 17 00:00:00 2001 From: Oliver Mannion <125105+tekumara@users.noreply.github.com> Date: Mon, 16 Sep 2024 22:19:50 +1000 Subject: [PATCH 2/2] . --- fakesnow/transforms.py | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/fakesnow/transforms.py b/fakesnow/transforms.py index d69be7a..7c362a8 100644 --- a/fakesnow/transforms.py +++ b/fakesnow/transforms.py @@ -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)) @@ -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: @@ -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) @@ -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 @@ -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), @@ -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: @@ -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