ydb-sqlglot-plugin 0.2.1__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ydb-sqlglot-plugin
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: YDB dialect plugin for sqlglot
5
5
  Author: YDB Team
6
6
  License: Apache-2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ydb-sqlglot-plugin"
7
- version = "0.2.1" # AUTOVERSION
7
+ version = "0.2.2" # AUTOVERSION
8
8
  description = "YDB dialect plugin for sqlglot"
9
9
  readme = "README.md"
10
10
  license = {text = "Apache-2.0"}
@@ -0,0 +1 @@
1
+ VERSION = "0.2.2"
@@ -1,3 +1,4 @@
1
+ import inspect as _inspect
1
2
  import re
2
3
  import typing as t
3
4
 
@@ -426,6 +427,13 @@ _YDB_GENERIC_TYPES = {
426
427
  }
427
428
 
428
429
 
430
+ # sqlglot >= 30.0.0 changed Parser.expression() to take a pre-built instance instead of
431
+ # (cls, **kwargs). Detect once so the YDB parser override below can support both APIs.
432
+ _EXPRESSION_TAKES_INSTANCE = (
433
+ "instance" in _inspect.signature(parser.Parser.expression).parameters
434
+ )
435
+
436
+
429
437
  def _reassemble_ctes(
430
438
  statements: t.List[t.Optional[exp.Expression]],
431
439
  ) -> t.List[t.Optional[exp.Expression]]:
@@ -582,6 +590,38 @@ class YDB(Dialect):
582
590
  statements = super().parse(raw_tokens, sql)
583
591
  return _reassemble_ctes(statements)
584
592
 
593
+ def expression(self, exp_class_or_instance, token=None, comments=None, **kwargs):
594
+ """Bridge sqlglot's two `Parser.expression()` calling conventions.
595
+
596
+ sqlglot < 30 expects ``expression(cls, **kwargs)`` and instantiates internally.
597
+ sqlglot >= 30 expects a pre-built ``expression(instance)`` and rejects kwargs.
598
+ Several call sites in this dialect (and a few in upstream code paths we exercise)
599
+ mix both styles, so normalise here before delegating.
600
+ """
601
+ if _EXPRESSION_TAKES_INSTANCE:
602
+ if not isinstance(exp_class_or_instance, exp.Expression):
603
+ exp_class_or_instance = exp_class_or_instance(**kwargs)
604
+ return super().expression(
605
+ exp_class_or_instance, token=token, comments=comments
606
+ )
607
+
608
+ if isinstance(exp_class_or_instance, exp.Expression):
609
+ # Old super() would attempt instance(**kwargs) -> "object is not callable".
610
+ instance = exp_class_or_instance
611
+ if token is not None:
612
+ update_positions = getattr(instance, "update_positions", None)
613
+ if update_positions is not None:
614
+ update_positions(token)
615
+ if comments:
616
+ instance.add_comments(comments)
617
+ else:
618
+ self._add_comments(instance)
619
+ return self.validate_expression(instance)
620
+
621
+ return super().expression(
622
+ exp_class_or_instance, token=token, comments=comments, **kwargs
623
+ )
624
+
585
625
  def _parse_dcolon(self) -> t.Optional[exp.Expression]:
586
626
  return self._parse_function(anonymous=True) or self._parse_var(any_token=True)
587
627
 
@@ -759,7 +799,9 @@ class YDB(Dialect):
759
799
 
760
800
  def _parse_lambda_body(self, params):
761
801
  if (
762
- self._curr.token_type != TokenType.R_PAREN
802
+ self._curr is None
803
+ or self._curr.token_type != TokenType.R_PAREN
804
+ or self._next is None
763
805
  or self._next.token_type != TokenType.ARROW
764
806
  ):
765
807
  return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ydb-sqlglot-plugin
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: YDB dialect plugin for sqlglot
5
5
  Author: YDB Team
6
6
  License: Apache-2.0
@@ -1 +0,0 @@
1
- VERSION = "0.2.1"