Skip to content

Commit c7657c5

Browse files
authored
Chore: bump sqlglot version (#968)
* Chore: bump sqlglot version * Bump sqlglot to v15.3.0 * Bump sqlglot to v16.0.0
1 parent 8237f3c commit c7657c5

File tree

5 files changed

+16
-29
lines changed

5 files changed

+16
-29
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"requests",
4545
"rich",
4646
"ruamel.yaml",
47-
"sqlglot~=15.2.0",
47+
"sqlglot~=16.0.0",
4848
"fsspec",
4949
],
5050
extras_require={

sqlmesh/core/dialect.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def parse(self: Parser) -> t.Optional[exp.Expression]:
289289
PARSERS = {"MODEL": _parse_model, "AUDIT": _parse_audit}
290290

291291

292-
def _model_sql(self: Generator, expression: exp.Expression) -> str:
292+
def _model_sql(self: Generator, expression: Model) -> str:
293293
props = ",\n".join(
294294
self.indent(f"{prop.name} {self.sql(prop, 'value')}") for prop in expression.expressions
295295
)
@@ -313,7 +313,7 @@ def _macro_keyword_func_sql(self: Generator, expression: exp.Expression) -> str:
313313
return self.sql(clause).replace(keyword, macro, 1)
314314

315315

316-
def _macro_func_sql(self: Generator, expression: exp.Expression) -> str:
316+
def _macro_func_sql(self: Generator, expression: MacroFunc) -> str:
317317
expression = expression.this
318318
name = expression.name
319319
if name in KEYWORD_MACROS:
@@ -335,8 +335,9 @@ def format_model_expressions(
335335
Args:
336336
expressions: The model's expressions, must be at least model def + query.
337337
dialect: The dialect to render the expressions as.
338+
338339
Returns:
339-
A string with the formatted model.
340+
A string representing the formatted model.
340341
"""
341342
if len(expressions) == 1:
342343
return expressions[0].sql(pretty=True, dialect=dialect)
@@ -446,7 +447,7 @@ def parse(sql: str, default_dialect: t.Optional[str] = None) -> t.List[exp.Expre
446447
default_dialect: The dialect to use if the model does not specify one.
447448
448449
Returns:
449-
A list of the expressions, [Model, *Statements, Query | Jinja]
450+
A list of the parsed expressions: [Model, *Statements, Query, *Statements]
450451
"""
451452
match = DIALECT_PATTERN.search(sql[:MAX_MODEL_DEFINITION_SIZE])
452453
dialect = Dialect.get_or_raise(match.group(2) if match else default_dialect)()
@@ -528,16 +529,8 @@ def extend_sqlglot() -> None:
528529
generator.WITH_SEPARATED_COMMENTS = (*generator.WITH_SEPARATED_COMMENTS, Model) # type: ignore
529530

530531
for parser in parsers:
531-
parser.FUNCTIONS.update(
532-
{
533-
"JINJA": Jinja.from_arg_list,
534-
}
535-
)
536-
parser.PLACEHOLDER_PARSERS.update(
537-
{
538-
TokenType.PARAMETER: _parse_macro,
539-
}
540-
)
532+
parser.FUNCTIONS.update({"JINJA": Jinja.from_arg_list})
533+
parser.PLACEHOLDER_PARSERS.update({TokenType.PARAMETER: _parse_macro})
541534

542535
_override(Parser, _parse_statement)
543536
_override(Parser, _parse_join)

sqlmesh/core/model/definition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def set_time_format(self, default_time_format: str = c.DEFAULT_TIME_COLUMN_FORMA
384384
# Transpile the time column format into the generic dialect
385385
formatted_time = format_time(
386386
self.time_column.format,
387-
d.Dialect.get_or_raise(self.dialect).time_mapping,
387+
d.Dialect.get_or_raise(self.dialect).TIME_MAPPING,
388388
)
389389
assert formatted_time is not None
390390
self.time_column.format = formatted_time

sqlmesh/core/model/kind.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,7 @@ def to_expression(self, dialect: str) -> exp.Column | exp.Tuple:
184184
expressions=[
185185
column,
186186
exp.Literal.string(
187-
format_time(
188-
self.format,
189-
d.Dialect.get_or_raise(dialect).inverse_time_mapping, # type: ignore
190-
)
187+
format_time(self.format, d.Dialect.get_or_raise(dialect).INVERSE_TIME_MAPPING)
191188
),
192189
]
193190
)

web/client/src/workers/sqlglot/sqlglot.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@ def parse_to_json(sql: str, read: DialectType = None) -> str:
2323

2424
def get_dialect(name: str = "") -> str:
2525
dialect = Dialect.classes.get(name, Dialect)
26-
tokenizer = dialect.tokenizer_class
27-
output = {"keywords": "", "types": ""}
26+
keywords = dialect.tokenizer_class.KEYWORDS
27+
type_mapping = dialect.generator_class.TYPE_MAPPING
2828

29-
if tokenizer is not None and dialect.generator_class is not None:
30-
type_mapping = dialect.generator_class.TYPE_MAPPING
31-
32-
output = {
33-
"keywords": " ".join(tokenizer.KEYWORDS) + " ",
34-
"types": " ".join(type_mapping.get(t, t.value) for t in exp.DataType.Type) + " ",
35-
}
29+
output = {
30+
"keywords": " ".join(keywords) + " ",
31+
"types": " ".join(type_mapping.get(t, t.value) for t in exp.DataType.Type) + " ",
32+
}
3633

3734
return json.dumps(output)
3835

0 commit comments

Comments
 (0)