Skip to content

Commit 1cdadc5

Browse files
authored
feat(sqlglot): pin to latest version of sqlglot (#372)
Pin minimum version of sqlglot and add `sqlglot[c]` group.
1 parent 1c9b19d commit 1cdadc5

8 files changed

Lines changed: 856 additions & 894 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ default_language_version:
22
python: "3"
33
repos:
44
- repo: https://github.com/compilerla/conventional-pre-commit
5-
rev: v4.3.0
5+
rev: v4.4.0
66
hooks:
77
- id: conventional-pre-commit
88
stages: [commit-msg]
@@ -17,7 +17,7 @@ repos:
1717
- id: mixed-line-ending
1818
- id: trailing-whitespace
1919
- repo: https://github.com/charliermarsh/ruff-pre-commit
20-
rev: "v0.15.0"
20+
rev: "v0.15.2"
2121
hooks:
2222
- id: ruff
2323
args: ["--fix"]

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ maintainers = [{ name = "Litestar Developers", email = "hello@litestar.dev" }]
2424
name = "sqlspec"
2525
readme = "README.md"
2626
requires-python = ">=3.10, <4.0"
27-
version = "0.39.0"
27+
version = "0.40.0"
2828

2929
[project.urls]
3030
Discord = "https://discord.gg/litestar"
@@ -49,15 +49,15 @@ flask = ["flask"]
4949
fsspec = ["fsspec"]
5050
litestar = ["litestar"]
5151
msgspec = ["msgspec"]
52-
mypyc = []
52+
mypyc = ["sqlglot[c]"]
5353
mysql-connector = ["mysql-connector-python"]
5454
nanoid = ["fastnanoid>=0.4.1"]
5555
obstore = ["obstore"]
5656
opentelemetry = ["opentelemetry-instrumentation"]
5757
oracledb = ["oracledb"]
5858
orjson = ["orjson"]
5959
pandas = ["pandas", "pyarrow"]
60-
performance = ["sqlglot[rs]", "msgspec"]
60+
performance = ["msgspec"]
6161
polars = ["polars", "pyarrow"]
6262
prometheus = ["prometheus-client"]
6363
psqlpy = ["psqlpy"]
@@ -241,7 +241,7 @@ opt_level = "3" # Maximum optimization (0-3)
241241
allow_dirty = true
242242
commit = false
243243
commit_args = "--no-verify"
244-
current_version = "0.39.0"
244+
current_version = "0.40.0"
245245
ignore_missing_files = false
246246
ignore_missing_version = false
247247
message = "chore(release): bump to v{new_version}"

sqlspec/adapters/spanner/dialect/_spangres.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
from sqlglot import exp
66
from sqlglot.dialects.postgres import Postgres
7-
from sqlglot.tokens import TokenType
7+
from sqlglot.tokenizer_core import TokenType
88

99
__all__ = ("Spangres",)
1010

11+
1112
_ROW_DELETION_NAME = "ROW_DELETION_POLICY"
1213
_TTL_MIN_COMPONENTS = 2
1314

@@ -16,16 +17,16 @@ class SpangresParser(Postgres.Parser):
1617
"""Parse Spanner row deletion policies."""
1718

1819
def _parse_property(self) -> exp.Expression:
19-
if self._match_text_seq("ROW", "DELETION", "POLICY"): # type: ignore[no-untyped-call]
20-
self._match(TokenType.L_PAREN) # type: ignore[no-untyped-call]
21-
self._match_text_seq("OLDER_THAN") # type: ignore[no-untyped-call]
22-
self._match(TokenType.L_PAREN) # type: ignore[no-untyped-call]
20+
if self._match_text_seq("ROW", "DELETION", "POLICY"):
21+
self._match(TokenType.L_PAREN)
22+
self._match_text_seq("OLDER_THAN")
23+
self._match(TokenType.L_PAREN)
2324
column = cast("exp.Expression", self._parse_id_var())
24-
self._match(TokenType.COMMA) # type: ignore[no-untyped-call]
25-
self._match_text_seq("INTERVAL") # type: ignore[no-untyped-call]
25+
self._match(TokenType.COMMA)
26+
self._match_text_seq("INTERVAL")
2627
interval = cast("exp.Expression", self._parse_expression())
27-
self._match(TokenType.R_PAREN) # type: ignore[no-untyped-call]
28-
self._match(TokenType.R_PAREN) # type: ignore[no-untyped-call]
28+
self._match(TokenType.R_PAREN)
29+
self._match(TokenType.R_PAREN)
2930

3031
return exp.Property(
3132
this=exp.Literal.string(_ROW_DELETION_NAME), value=exp.Tuple(expressions=[column, interval])

sqlspec/adapters/spanner/dialect/_spanner.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from sqlglot import exp
1111
from sqlglot.dialects.bigquery import BigQuery
12-
from sqlglot.tokens import TokenType
12+
from sqlglot.tokenizer_core import TokenType
1313

1414
__all__ = ("Spanner",)
1515

@@ -41,14 +41,14 @@ def _parse_table_parts(
4141
"""Parse Spanner table options including interleaving metadata."""
4242
table = super()._parse_table_parts(schema=schema, is_db_reference=is_db_reference, wildcard=wildcard)
4343

44-
if self._match_text_seq("INTERLEAVE", "IN", "PARENT"): # type: ignore[no-untyped-call]
44+
if self._match_text_seq("INTERLEAVE", "IN", "PARENT"):
4545
parent = cast("exp.Expression", self._parse_table(schema=True, is_db_reference=True))
4646
on_delete: str | None = None
4747

48-
if self._match_text_seq("ON", "DELETE"): # type: ignore[no-untyped-call]
49-
if self._match_text_seq("CASCADE"): # type: ignore[no-untyped-call]
48+
if self._match_text_seq("ON", "DELETE"):
49+
if self._match_text_seq("CASCADE"):
5050
on_delete = "CASCADE"
51-
elif self._match_text_seq("NO", "ACTION"): # type: ignore[no-untyped-call]
51+
elif self._match_text_seq("NO", "ACTION"):
5252
on_delete = "NO ACTION"
5353

5454
table.set("interleave_parent", parent)
@@ -59,25 +59,25 @@ def _parse_table_parts(
5959

6060
def _parse_property(self) -> exp.Expression:
6161
"""Parse Spanner row deletion policy or PostgreSQL-style TTL."""
62-
if self._match_text_seq("ROW", "DELETION", "POLICY"): # type: ignore[no-untyped-call]
63-
self._match(TokenType.L_PAREN) # type: ignore[no-untyped-call]
64-
self._match_text_seq("OLDER_THAN") # type: ignore[no-untyped-call]
65-
self._match(TokenType.L_PAREN) # type: ignore[no-untyped-call]
62+
if self._match_text_seq("ROW", "DELETION", "POLICY"):
63+
self._match(TokenType.L_PAREN)
64+
self._match_text_seq("OLDER_THAN")
65+
self._match(TokenType.L_PAREN)
6666
column = cast("exp.Expression", self._parse_id_var())
67-
self._match(TokenType.COMMA) # type: ignore[no-untyped-call]
68-
self._match_text_seq("INTERVAL") # type: ignore[no-untyped-call]
67+
self._match(TokenType.COMMA)
68+
self._match_text_seq("INTERVAL")
6969
interval = cast("exp.Expression", self._parse_expression())
70-
self._match(TokenType.R_PAREN) # type: ignore[no-untyped-call]
71-
self._match(TokenType.R_PAREN) # type: ignore[no-untyped-call]
70+
self._match(TokenType.R_PAREN)
71+
self._match(TokenType.R_PAREN)
7272

7373
return exp.Property(
7474
this=exp.Literal.string(_ROW_DELETION_NAME), value=exp.Tuple(expressions=[column, interval])
7575
)
7676

77-
if self._match_text_seq("TTL"): # type: ignore[no-untyped-call] # PostgreSQL-dialect style, keep for compatibility
78-
self._match_text_seq("INTERVAL") # type: ignore[no-untyped-call]
77+
if self._match_text_seq("TTL"):
78+
self._match_text_seq("INTERVAL")
7979
interval = cast("exp.Expression", self._parse_expression())
80-
self._match_text_seq("ON") # type: ignore[no-untyped-call]
80+
self._match_text_seq("ON")
8181
column = cast("exp.Expression", self._parse_id_var())
8282

8383
return exp.Property(this=exp.Literal.string("TTL"), value=exp.Tuple(expressions=[interval, column]))

sqlspec/builder/_base.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def _parameterize_expression(self, expression: exp.Expression) -> exp.Expression
394394
A new expression with literals replaced by parameter placeholders
395395
"""
396396

397-
return expression.transform(_ExpressionParameterizer(self), copy=False)
397+
return cast("exp.Expression", expression.transform(_ExpressionParameterizer(self), copy=False))
398398

399399
def add_parameter(self: Self, value: Any, name: str | None = None) -> tuple[Self, str]:
400400
"""Explicitly adds a parameter to the query.
@@ -426,9 +426,6 @@ def load_parameters(self, parameters: "Mapping[str, Any]") -> None:
426426
427427
Args:
428428
parameters: Mapping of parameter names to values.
429-
430-
Raises:
431-
SQLBuilderError: If a parameter name already exists on the builder.
432429
"""
433430
if not parameters:
434431
return
@@ -444,9 +441,6 @@ def load_ctes(self, ctes: "Iterable[exp.CTE]") -> None:
444441
445442
Args:
446443
ctes: Iterable of CTE expressions to register.
447-
448-
Raises:
449-
SQLBuilderError: If a CTE alias is missing or duplicated.
450444
"""
451445
for cte in ctes:
452446
alias = self._resolve_cte_alias(cte)
@@ -543,7 +537,7 @@ def _update_placeholders_in_expression(
543537
Updated expression with new placeholder names
544538
"""
545539

546-
return expression.transform(_PlaceholderReplacer(param_mapping), copy=False)
540+
return cast("exp.Expression", expression.transform(_PlaceholderReplacer(param_mapping), copy=False))
547541

548542
def _generate_builder_cache_key(self, config: "StatementConfig | None" = None) -> str:
549543
"""Generate cache key based on builder state and configuration.
@@ -893,7 +887,7 @@ def _is_oracle_dialect(self, dialect: "DialectType | str | None") -> bool:
893887
def _unquote_identifiers_for_oracle(self, expression: exp.Expression) -> exp.Expression:
894888
"""Remove identifier quoting to avoid Oracle case-sensitive lookup issues."""
895889

896-
return expression.copy().transform(_unquote_identifier, copy=False)
890+
return cast("exp.Expression", expression.copy().transform(_unquote_identifier, copy=False))
897891

898892
def _strip_lock_identifier_quotes(self, sql_string: str) -> str:
899893
for keyword in ("FOR UPDATE OF ", "FOR SHARE OF "):

tests/unit/adapters/test_spanner/test_dialect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ def test_dialect_inheritance() -> None:
703703

704704
def test_dialect_keywords() -> None:
705705
"""Test that Spanner-specific keywords are registered."""
706-
from sqlglot.tokens import TokenType
706+
from sqlglot.tokenizer_core import TokenType
707707

708708
# Keywords are only registered if sqlglot supports them
709709
keywords = Spanner.Tokenizer.KEYWORDS

tests/unit/builder/test_temporal.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ def test_join_as_of_dialect() -> None:
9696
sql_str = query.build(dialect="bigquery").sql
9797
normalized = normalize_sql(sql_str)
9898
# Should use FOR SYSTEM_TIME AS OF because dialect is passed at build time
99-
assert "LEFT JOIN audit_log FOR SYSTEM_TIME AS OF '-1h'" in normalized
100-
assert "log ON orders.id = log.order_id" in normalized
99+
assert "LEFT JOIN audit_log" in normalized
100+
assert "FOR SYSTEM_TIME AS OF '-1h'" in normalized
101+
assert "ON orders.id = log.order_id" in normalized
101102

102103

103104
def test_join_as_of_dialect_override() -> None:

0 commit comments

Comments
 (0)