Skip to content

Commit

Permalink
chore: bump sqlglot 20.4.0
Browse files Browse the repository at this point in the history
and adjust index to accomodate change from tobymao/sqlglot#2619
  • Loading branch information
tekumara committed Dec 29, 2023
1 parent df9bb35 commit 2b216f9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ repos:
rev: v1.16.23
hooks:
- id: typos
# needed because .typos.toml is ignored see https://github.com/crate-ci/typos/issues/347
exclude: CHANGELOG.md
# formatters and linters are available in the virtualenv so they can be run from the makefile & vscode
- repo: local
hooks:
Expand Down
8 changes: 6 additions & 2 deletions fakesnow/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,13 @@ def regex_substr(expression: exp.Expression) -> exp.Expression:

# which occurrence of the pattern to match
try:
occurrence = expression.args["occurrence"]
occurrence = int(expression.args["occurrence"].this)
except KeyError:
occurrence = exp.Literal(this="1", is_string=False)
occurrence = 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)
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.9.2",
"pyarrow",
"snowflake-connector-python",
"sqlglot~=19.5.1",
"sqlglot~=20.4.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 @@ -150,7 +150,7 @@ def test_regex_substr() -> None:
assert (
sqlglot.parse_one("SELECT regexp_substr(string1, 'the\\\\W+\\\\w+')", read="snowflake")
.transform(regex_substr)
.sql()
.sql(dialect="duckdb")
== "SELECT REGEXP_EXTRACT_ALL(string1[1 : ], 'the\\W+\\w+', 0, '')[1]"
)

Expand Down

0 comments on commit 2b216f9

Please sign in to comment.