Skip to content

Commit 5db214e

Browse files
committed
Further refactor
1 parent b21f70f commit 5db214e

File tree

4 files changed

+22
-28
lines changed

4 files changed

+22
-28
lines changed

sqlglot/dialects/snowflake.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
from sqlglot._typing import E, B
4242

4343

44-
DATE_PARTS = ["YEAR", "QUARTER", "MONTH", "WEEK", "DAY"]
45-
46-
4744
def _build_strtok(args: t.List) -> exp.SplitPart:
4845
# Add default delimiter (space) if missing - per Snowflake docs
4946
if len(args) == 1:

sqlglot/typing/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,5 +311,4 @@
311311
},
312312
exp.ToMap: {"annotator": lambda self, e: self._annotate_to_map(e)},
313313
exp.Unnest: {"annotator": lambda self, e: self._annotate_unnest(e)},
314-
exp.Unnest: {"annotator": lambda self, e: self._annotate_unnest(e)},
315314
}

sqlglot/typing/bigquery.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,6 @@ def _annotate_array(self: TypeAnnotator, expression: exp.Array) -> exp.Array:
192192
exp.LaxBool,
193193
}
194194
},
195-
**{
196-
expr_type: {"returns": exp.DataType.Type.DATE}
197-
for expr_type in {
198-
exp.DateFromUnixDate,
199-
}
200-
},
201195
**{
202196
expr_type: {"returns": exp.DataType.Type.DATETIME}
203197
for expr_type in {
@@ -272,14 +266,30 @@ def _annotate_array(self: TypeAnnotator, expression: exp.Array) -> exp.Array:
272266
exp.Uuid,
273267
}
274268
},
269+
**{
270+
expr_type: {"annotator": lambda self, e: _annotate_by_args_with_coerce(self, e)}
271+
for expr_type in {
272+
exp.PercentileCont,
273+
exp.SafeAdd,
274+
exp.SafeMultiply,
275+
exp.SafeSubtract,
276+
}
277+
},
278+
**{
279+
expr_type: {"annotator": lambda self, e: self._annotate_by_args(e, "this", array=True)}
280+
for expr_type in {
281+
exp.ApproxQuantiles,
282+
exp.JSONExtractArray,
283+
exp.RegexpExtractAll,
284+
exp.Split,
285+
}
286+
},
275287
**{
276288
expr_type: {"returns": exp.DataType.Type.TIMESTAMPTZ} for expr_type in TIMESTAMP_EXPRESSIONS
277289
},
290+
exp.DateFromUnixDate: {"returns": exp.DataType.Type.DATE},
278291
exp.ParseBignumeric: {"returns": exp.DataType.Type.BIGDECIMAL},
279292
exp.ParseNumeric: {"returns": exp.DataType.Type.DECIMAL},
280-
exp.ApproxQuantiles: {
281-
"annotator": lambda self, e: self._annotate_by_args(e, "this", array=True)
282-
},
283293
exp.ApproxTopK: {"annotator": lambda self, e: _annotate_by_args_approx_top(self, e)},
284294
exp.ApproxTopSum: {"annotator": lambda self, e: _annotate_by_args_approx_top(self, e)},
285295
exp.Array: {"annotator": _annotate_array},
@@ -292,9 +302,6 @@ def _annotate_array(self: TypeAnnotator, expression: exp.Array) -> exp.Array:
292302
e, exp.DataType.build("ARRAY<TIMESTAMP>", dialect="bigquery")
293303
)
294304
},
295-
exp.JSONExtractArray: {
296-
"annotator": lambda self, e: self._annotate_by_args(e, "this", array=True)
297-
},
298305
exp.JSONFormat: {
299306
"annotator": lambda self, e: self._annotate_with_type(
300307
e, exp.DataType.Type.JSON if e.args.get("to_json") else exp.DataType.Type.VARCHAR
@@ -311,14 +318,6 @@ def _annotate_array(self: TypeAnnotator, expression: exp.Array) -> exp.Array:
311318
)
312319
},
313320
exp.Lag: {"annotator": lambda self, e: self._annotate_by_args(e, "this", "default")},
314-
exp.PercentileCont: {"annotator": lambda self, e: _annotate_by_args_with_coerce(self, e)},
315-
exp.RegexpExtractAll: {
316-
"annotator": lambda self, e: self._annotate_by_args(e, "this", array=True)
317-
},
318-
exp.SafeAdd: {"annotator": lambda self, e: _annotate_by_args_with_coerce(self, e)},
319-
exp.SafeMultiply: {"annotator": lambda self, e: _annotate_by_args_with_coerce(self, e)},
320-
exp.SafeSubtract: {"annotator": lambda self, e: _annotate_by_args_with_coerce(self, e)},
321-
exp.Split: {"annotator": lambda self, e: self._annotate_by_args(e, "this", array=True)},
322321
exp.ToCodePoints: {
323322
"annotator": lambda self, e: self._annotate_with_type(
324323
e, exp.DataType.build("ARRAY<BIGINT>", dialect="bigquery")

sqlglot/typing/snowflake.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ def _annotate_timestamp_from_parts(
3636

3737

3838
def _annotate_date_or_time_add(self: TypeAnnotator, expression: exp.Expression) -> exp.Expression:
39-
DATE_PARTS = {"DAY", "WEEK", "MONTH", "QUARTER", "YEAR"}
4039
self._annotate_args(expression)
4140

41+
DATE_PARTS = {"DAY", "WEEK", "MONTH", "QUARTER", "YEAR"}
42+
4243
if (
4344
expression.this.is_type(exp.DataType.Type.DATE)
4445
and expression.text("unit").upper() not in DATE_PARTS
@@ -69,9 +70,7 @@ def _annotate_date_or_time_add(self: TypeAnnotator, expression: exp.Expression)
6970
}
7071
},
7172
**{
72-
expr_type: {
73-
"annotator": lambda self, e: self._annotate_with_type(e, exp.DataType.Type.ARRAY)
74-
}
73+
expr_type: {"returns": exp.DataType.Type.ARRAY}
7574
for expr_type in (
7675
exp.RegexpExtractAll,
7776
exp.Split,

0 commit comments

Comments
 (0)