Skip to content

Commit a5c258d

Browse files
Fix make style errors (mypy, ruff)
Signed-off-by: Mateusz Jukiewicz <mateusz@marketer.tech>
1 parent 55b3bb5 commit a5c258d

2 files changed

Lines changed: 57 additions & 59 deletions

File tree

sqlmesh/core/engine_adapter/starrocks.py

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,24 @@
5252
"identifier", # exp.Identifier
5353
"literal", # exp.Literal.string("HASH")
5454
"column", # exp.Column(this="HASH")
55-
"ast_expr", # generic exp.Expression
55+
"ast_expr", # generic exp.Expr
5656
}
5757

5858

5959
# ============================================================
6060
# Fragment parser (robust-ish)
6161
# ============================================================
62-
def parse_fragment(text: str) -> t.Union[exp.Expression, t.List[exp.Expression]]:
62+
def parse_fragment(text: str) -> t.Union[exp.Expr, t.List[exp.Expr]]:
6363
"""
6464
Try to parse a DSL fragment into SQLGlot AST(s).
6565
6666
Behavior:
67-
1. If parse_one succeeds, return the exp.Expression.
67+
1. If parse_one succeeds, return the exp.Expr.
6868
2. If fails but text contains comma, split by commas and parse each part.
6969
3. If it's parenthesized like "(a, b)", parse and return exp.Tuple or list.
7070
4. If it's a simple token like "IDENT", return exp.Identifier.
7171
"""
72-
if isinstance(text, exp.Expression):
72+
if isinstance(text, exp.Expr):
7373
return text
7474

7575
if not isinstance(text, str):
@@ -381,7 +381,7 @@ class EnumType(DeclarativeType):
381381
- "identifier": exp.Identifier
382382
- "literal": exp.Literal.string()
383383
- "column": exp.Column
384-
- "ast_expr": generic exp.Expression (defaults to Identifier)
384+
- "ast_expr": generic exp.Expr (defaults to Identifier)
385385
case_sensitive : bool
386386
Whether to perform case-sensitive matching (default: False)
387387
@@ -682,7 +682,7 @@ def _extract_elements(self, value: t.Any) -> t.Optional[t.List[t.Any]]:
682682
return [inner]
683683

684684
# Single AST element: promote to list (if allow_single)
685-
if self.allow_single and isinstance(value, exp.Expression):
685+
if self.allow_single and isinstance(value, exp.Expr):
686686
return [value]
687687

688688
return None
@@ -1291,11 +1291,11 @@ class PropertySpecs:
12911291
in the usage layer via factory methods like DistributionTupleInputType.to_unified_dict().
12921292
12931293
Expected Output Types (after normalization):
1294-
- table keys: List[exp.Expression] - columns
1295-
- partitioned_by: List[exp.Expression] - columns, functions
1294+
- table keys: List[exp.Expr] - columns
1295+
- partitioned_by: List[exp.Expr] - columns, functions
12961296
- partitions: List[str] - partition definition strings
12971297
- distributed_by: Dict | str | exp.Func - DistributionTupleInputType, EnumType, or FuncType output
1298-
- order_by: List[exp.Expression] - columns
1298+
- order_by: List[exp.Expr] - columns
12991299
- generic properties: str - normalized string values
13001300
"""
13011301
GeneralColumnListOutputSpec: DeclarativeType = SequenceOf(ColumnType(), allow_single=False)
@@ -1880,7 +1880,7 @@ def _create_table_like(
18801880
def delete_from(
18811881
self,
18821882
table_name: TableName,
1883-
where: t.Optional[t.Union[str, exp.Expression]] = None,
1883+
where: t.Optional[t.Union[str, exp.Expr]] = None,
18841884
) -> None:
18851885
"""
18861886
Delete from a table.
@@ -1907,7 +1907,7 @@ def delete_from(
19071907
where: The where clause to filter rows to delete
19081908
"""
19091909
# Parse where clause if it's a string
1910-
where_expr: t.Optional[exp.Expression]
1910+
where_expr: t.Optional[exp.Expr]
19111911
if isinstance(where, str):
19121912
from sqlglot import parse_one
19131913

@@ -1929,7 +1929,7 @@ def delete_from(
19291929
# Note: We conservatively apply restrictions to all tables since we can't easily
19301930
# determine table type at DELETE time. PRIMARY KEY tables will still work with
19311931
# simplified conditions, while non-PRIMARY KEY tables require them.
1932-
if isinstance(where_expr, exp.Expression):
1932+
if isinstance(where_expr, exp.Expr):
19331933
original_where = where_expr
19341934
# Remove boolean literals (not supported in any table type)
19351935
where_expr = self._where_clause_remove_boolean_literals(where_expr)
@@ -1946,7 +1946,7 @@ def delete_from(
19461946
# Use parent implementation
19471947
super().delete_from(table_name, where_expr)
19481948

1949-
def _where_clause_remove_boolean_literals(self, expression: exp.Expression) -> exp.Expression:
1949+
def _where_clause_remove_boolean_literals(self, expression: exp.Expr) -> exp.Expr:
19501950
"""
19511951
Remove TRUE/FALSE boolean literals from WHERE expressions.
19521952
@@ -1966,7 +1966,7 @@ def _where_clause_remove_boolean_literals(self, expression: exp.Expression) -> e
19661966
Cleaned expression without boolean literals
19671967
"""
19681968

1969-
def transform(node: exp.Expression) -> exp.Expression:
1969+
def transform(node: exp.Expr) -> exp.Expr:
19701970
# Handle standalone TRUE/FALSE at the top level
19711971
if node == exp.true():
19721972
# Convert TRUE to 1=1
@@ -2002,9 +2002,7 @@ def transform(node: exp.Expression) -> exp.Expression:
20022002
# Transform the expression tree
20032003
return expression.transform(transform, copy=True)
20042004

2005-
def _where_clause_convert_between_to_comparison(
2006-
self, expression: exp.Expression
2007-
) -> exp.Expression:
2005+
def _where_clause_convert_between_to_comparison(self, expression: exp.Expr) -> exp.Expr:
20082006
"""
20092007
Convert BETWEEN expressions to >= AND <= comparisons.
20102008
@@ -2024,7 +2022,7 @@ def _where_clause_convert_between_to_comparison(
20242022
Expression with BETWEEN converted to comparisons
20252023
"""
20262024

2027-
def transform(node: exp.Expression) -> exp.Expression:
2025+
def transform(node: exp.Expr) -> exp.Expr:
20282026
if isinstance(node, exp.Between):
20292027
# Extract components: col BETWEEN low AND high
20302028
column = node.this # The column being tested
@@ -2044,7 +2042,7 @@ def transform(node: exp.Expression) -> exp.Expression:
20442042

20452043
def execute(
20462044
self,
2047-
expressions: t.Union[str, exp.Expression, t.Sequence[exp.Expression]],
2045+
expressions: t.Union[str, exp.Expr, t.Sequence[exp.Expr]],
20482046
ignore_unsupported_errors: bool = False,
20492047
quote_identifiers: bool = True,
20502048
track_rows_processed: bool = False,
@@ -2076,9 +2074,9 @@ def execute(
20762074
return
20772075

20782076
# Process expressions to remove FOR UPDATE
2079-
processed_expressions: t.List[exp.Expression] = []
2077+
processed_expressions: t.List[exp.Expr] = []
20802078
for e in ensure_list(expressions):
2081-
if not isinstance(e, exp.Expression):
2079+
if not isinstance(e, exp.Expr):
20822080
super().execute(
20832081
expressions,
20842082
ignore_unsupported_errors=ignore_unsupported_errors,
@@ -2235,7 +2233,7 @@ def create_view(
22352233
materialized_properties: t.Optional[t.Dict[str, t.Any]] = None,
22362234
table_description: t.Optional[str] = None,
22372235
column_descriptions: t.Optional[t.Dict[str, str]] = None,
2238-
view_properties: t.Optional[t.Dict[str, exp.Expression]] = None,
2236+
view_properties: t.Optional[t.Dict[str, exp.Expr]] = None,
22392237
source_columns: t.Optional[t.List[str]] = None,
22402238
**create_kwargs: t.Any,
22412239
) -> None:
@@ -2292,7 +2290,7 @@ def _create_materialized_view(
22922290
materialized_properties: t.Optional[t.Dict[str, t.Any]] = None,
22932291
table_description: t.Optional[str] = None,
22942292
column_descriptions: t.Optional[t.Dict[str, str]] = None,
2295-
view_properties: t.Optional[t.Dict[str, exp.Expression]] = None,
2293+
view_properties: t.Optional[t.Dict[str, exp.Expr]] = None,
22962294
source_columns: t.Optional[t.List[str]] = None,
22972295
**create_kwargs: t.Any,
22982296
) -> None:
@@ -2403,7 +2401,7 @@ def _build_materialized_view_schema_exp(
24032401
return table
24042402

24052403
column_descriptions = column_descriptions or {}
2406-
expressions: t.List[exp.Expression] = []
2404+
expressions: t.List[exp.Expr] = []
24072405
for col in columns:
24082406
constraints: t.List[exp.ColumnConstraint] = []
24092407
comment = column_descriptions.get(col)
@@ -2430,10 +2428,10 @@ def _build_table_properties_exp(
24302428
catalog_name: t.Optional[str] = None,
24312429
table_format: t.Optional[str] = None,
24322430
storage_format: t.Optional[str] = None,
2433-
partitioned_by: t.Optional[t.List[exp.Expression]] = None,
2431+
partitioned_by: t.Optional[t.List[exp.Expr]] = None,
24342432
partition_interval_unit: t.Optional[IntervalUnit] = None,
2435-
clustered_by: t.Optional[t.List[exp.Expression]] = None,
2436-
table_properties: t.Optional[t.Dict[str, exp.Expression]] = None,
2433+
clustered_by: t.Optional[t.List[exp.Expr]] = None,
2434+
table_properties: t.Optional[t.Dict[str, exp.Expr]] = None,
24372435
target_columns_to_types: t.Optional[t.Dict[str, exp.DataType]] = None,
24382436
table_description: t.Optional[str] = None,
24392437
table_kind: t.Optional[str] = None,
@@ -2477,7 +2475,7 @@ def _build_table_properties_exp(
24772475
- replication_num, storage_medium, etc.: Literal values
24782476
table_description: Table comment
24792477
"""
2480-
properties: t.List[exp.Expression] = []
2478+
properties: t.List[exp.Expr] = []
24812479
table_properties_copy = dict(table_properties) if table_properties else {}
24822480
# logger.debug(
24832481
# "_build_table_properties_exp: table_properties=%s",
@@ -2566,17 +2564,17 @@ def _build_table_properties_exp(
25662564

25672565
def _build_view_properties_exp(
25682566
self,
2569-
view_properties: t.Optional[t.Dict[str, exp.Expression]] = None,
2567+
view_properties: t.Optional[t.Dict[str, exp.Expr]] = None,
25702568
table_description: t.Optional[str] = None,
25712569
**kwargs: t.Any,
25722570
) -> t.Optional[exp.Properties]:
25732571
"""
25742572
Build CREATE VIEW properties for StarRocks.
25752573
25762574
Supports StarRocks view SECURITY syntax: SECURITY {NONE | INVOKER}
2577-
via exp.SecurityProperty (renders as `SECURITY <value>`).
2575+
via exp.SqlSecurityProperty (renders as `SECURITY <value>`).
25782576
"""
2579-
properties: t.List[exp.Expression] = []
2577+
properties: t.List[exp.Expr] = []
25802578

25812579
if table_description:
25822580
properties.append(
@@ -2592,8 +2590,8 @@ def _build_view_properties_exp(
25922590
security_text = PropertyValidator.validate_and_normalize_property(
25932591
"security", security
25942592
)
2595-
# exp.SecurityProperty renders as `SECURITY <value>` (no '=')
2596-
properties.append(exp.SecurityProperty(this=exp.Var(this=security_text)))
2593+
# exp.SqlSecurityProperty renders as `SECURITY <value>` (no '=')
2594+
properties.append(exp.SqlSecurityProperty(this=exp.Var(this=security_text)))
25972595

25982596
properties.extend(self._table_or_view_properties_to_expressions(view_properties_copy))
25992597

@@ -2603,7 +2601,7 @@ def _build_view_properties_exp(
26032601

26042602
def _build_table_key_property(
26052603
self, table_properties: t.Dict[str, t.Any], active_key_type: t.Optional[str]
2606-
) -> t.Optional[exp.Expression]:
2604+
) -> t.Optional[exp.Expr]:
26072605
"""
26082606
Build key constraint property for ALL key types including PRIMARY KEY.
26092607
@@ -2628,7 +2626,7 @@ def _build_table_key_property(
26282626
return None
26292627

26302628
# Configuration: key_name -> Property class (excluding primary_key)
2631-
KEY_PROPERTY_CLASSES: t.Dict[str, t.Type[exp.Expression]] = {
2629+
KEY_PROPERTY_CLASSES: t.Dict[str, t.Type[exp.Expr]] = {
26322630
"primary_key": exp.PrimaryKey,
26332631
"duplicate_key": exp.DuplicateKeyProperty,
26342632
"unique_key": exp.UniqueKeyProperty,
@@ -2670,14 +2668,14 @@ def _build_table_key_property(
26702668

26712669
def _build_partition_property(
26722670
self,
2673-
partitioned_by: t.Optional[t.List[exp.Expression]],
2671+
partitioned_by: t.Optional[t.List[exp.Expr]],
26742672
partition_interval_unit: t.Optional["IntervalUnit"],
26752673
target_columns_to_types: t.Optional[t.Dict[str, exp.DataType]],
26762674
catalog_name: t.Optional[str],
26772675
table_properties: t.Dict[str, t.Any],
26782676
key_type: t.Optional[str],
26792677
key_columns: t.Optional[t.Tuple[str, ...]],
2680-
) -> t.Optional[exp.Expression]:
2678+
) -> t.Optional[exp.Expr]:
26812679
"""
26822680
Build partition property expression.
26832681
@@ -2722,7 +2720,7 @@ def _build_partition_property(
27222720
partition_cols,
27232721
)
27242722

2725-
def extract_column_name(expr: exp.Expression) -> t.Optional[str]:
2723+
def extract_column_name(expr: exp.Expr) -> t.Optional[str]:
27262724
if isinstance(expr, exp.Column):
27272725
return str(expr.name)
27282726
elif isinstance(expr, (exp.Anonymous, exp.Func)): # noqa: RET505
@@ -2768,8 +2766,8 @@ def extract_column_name(expr: exp.Expression) -> t.Optional[str]:
27682766
return result
27692767

27702768
def _parse_partition_expressions(
2771-
self, partitioned_by: t.List[exp.Expression]
2772-
) -> t.Tuple[t.Optional[str], t.List[exp.Expression]]:
2769+
self, partitioned_by: t.List[exp.Expr]
2770+
) -> t.Tuple[t.Optional[str], t.List[exp.Expr]]:
27732771
"""
27742772
Parse partition expressions and extract partition kind (RANGE/LIST).
27752773
@@ -2789,7 +2787,7 @@ def _parse_partition_expressions(
27892787
- partition_kind: "RANGE", "LIST", or None
27902788
- normalized_columns: List of Column expressions, or function expressions
27912789
"""
2792-
parsed_cols: t.List[exp.Expression] = []
2790+
parsed_cols: t.List[exp.Expr] = []
27932791
partition_kind: t.Optional[str] = None
27942792

27952793
normalized = PropertyValidator.validate_and_normalize_property(
@@ -2828,7 +2826,7 @@ def _parse_partition_expressions(
28282826

28292827
def _build_partitioned_by_exp(
28302828
self,
2831-
partitioned_by: t.List[exp.Expression],
2829+
partitioned_by: t.List[exp.Expr],
28322830
*,
28332831
partition_interval_unit: t.Optional["IntervalUnit"] = None,
28342832
target_columns_to_types: t.Optional[t.Dict[str, exp.DataType]] = None,
@@ -2939,15 +2937,15 @@ def _build_distributed_by_property(
29392937
kind_expr = exp.Var(this=unified["kind"])
29402938
# Convert columns to expressions
29412939
columns: t.List[exp.Column] = unified.get("columns", [])
2942-
expressions_list: t.List[exp.Expression] = []
2940+
expressions_list: t.List[exp.Expr] = []
29432941
for col in columns:
2944-
if isinstance(col, exp.Expression):
2942+
if isinstance(col, exp.Expr):
29452943
expressions_list.append(col)
29462944
else:
29472945
expressions_list.append(exp.to_column(str(col)))
29482946
# Build buckets expression
29492947
buckets: t.Optional[t.Any] = unified.get("buckets")
2950-
buckets_expr: t.Optional[exp.Expression] = None
2948+
buckets_expr: t.Optional[exp.Expr] = None
29512949
if buckets is not None:
29522950
if isinstance(buckets, exp.Literal):
29532951
buckets_expr = buckets
@@ -2992,10 +2990,10 @@ def _build_refresh_property(
29922990
)
29932991
method_expr = exp.Var(this=refresh_moment_text)
29942992

2995-
kind_expr: t.Optional[exp.Expression] = None
2996-
starts_expr: t.Optional[exp.Expression] = None
2997-
every_expr: t.Optional[exp.Expression] = None
2998-
unit_expr: t.Optional[exp.Expression] = None
2993+
kind_expr: t.Optional[exp.Expr] = None
2994+
starts_expr: t.Optional[exp.Expr] = None
2995+
every_expr: t.Optional[exp.Expr] = None
2996+
unit_expr: t.Optional[exp.Expr] = None
29992997

30002998
if refresh_scheme is not None:
30012999
scheme_text = PropertyValidator.validate_and_normalize_property(
@@ -3019,10 +3017,10 @@ def _build_refresh_property(
30193017
def _parse_refresh_scheme(
30203018
self, refresh_scheme: str
30213019
) -> t.Tuple[
3022-
t.Optional[exp.Expression],
3023-
t.Optional[exp.Expression],
3024-
t.Optional[exp.Expression],
3025-
t.Optional[exp.Expression],
3020+
t.Optional[exp.Expr],
3021+
t.Optional[exp.Expr],
3022+
t.Optional[exp.Expr],
3023+
t.Optional[exp.Expr],
30263024
]:
30273025
"""
30283026
Parse StarRocks refresh_scheme text into (kind, starts, every, unit).
@@ -3042,11 +3040,11 @@ def _parse_refresh_scheme(
30423040
f"[StarRocks] Invalid refresh_scheme {refresh_scheme!r}. Expected to start with MANUAL or ASYNC."
30433041
)
30443042
kind = m_kind.group(1).upper()
3045-
kind_expr: t.Optional[exp.Expression] = exp.Var(this=kind)
3043+
kind_expr: t.Optional[exp.Expr] = exp.Var(this=kind)
30463044

3047-
starts_expr: t.Optional[exp.Expression] = None
3048-
every_expr: t.Optional[exp.Expression] = None
3049-
unit_expr: t.Optional[exp.Expression] = None
3045+
starts_expr: t.Optional[exp.Expr] = None
3046+
every_expr: t.Optional[exp.Expr] = None
3047+
unit_expr: t.Optional[exp.Expr] = None
30503048
m_start = re.search(
30513049
r"\bSTART\s*\(\s*(?:'([^']*)'|\"([^\"]*)\"|([^)]*))\s*\)", text, flags=re.IGNORECASE
30523050
)
@@ -3110,7 +3108,7 @@ def _parse_distribution_with_buckets(
31103108
def _build_order_by_property(
31113109
self,
31123110
table_properties: t.Dict[str, t.Any],
3113-
clustered_by: t.Optional[t.List[exp.Expression]],
3111+
clustered_by: t.Optional[t.List[exp.Expr]],
31143112
) -> t.Optional[exp.Cluster]:
31153113
"""
31163114
Build ORDER BY (clustering) property.

sqlmesh/core/snapshot/evaluator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,7 @@ def _ensure_primary_key_for_starrocks_when_incremental_by_unique_key(
20612061
or "primary_key" in properties
20622062
):
20632063
return properties
2064-
unique_key: t.Optional[t.List[exp.Expression]] = model.unique_key
2064+
unique_key: t.Optional[t.List[exp.Expr]] = model.unique_key
20652065
if unique_key:
20662066
properties["primary_key"] = (
20672067
unique_key[0] if len(unique_key) == 1 else exp.Tuple(expressions=unique_key)

0 commit comments

Comments
 (0)