Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sqlglot/dialects/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class Trino(Presto):
SUPPORTS_USER_DEFINED_TYPES = False
LOG_BASE_FIRST = True

class Tokenizer(Presto.Tokenizer):
KEYWORDS = {
**Presto.Tokenizer.KEYWORDS,
"REFRESH": TokenType.REFRESH,
}

class Parser(Presto.Parser):
FUNCTION_PARSERS = {
**Presto.Parser.FUNCTION_PARSERS,
Expand Down
2 changes: 1 addition & 1 deletion sqlglot/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ class Uncache(Expression):


class Refresh(Expression):
pass
arg_types = {"this": True, "kind": True}


class DDL(Expression):
Expand Down
4 changes: 2 additions & 2 deletions sqlglot/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4375,8 +4375,8 @@ def forin_sql(self, expression: exp.ForIn) -> str:

def refresh_sql(self, expression: exp.Refresh) -> str:
this = self.sql(expression, "this")
table = "" if isinstance(expression.this, exp.Literal) else "TABLE "
return f"REFRESH {table}{this}"
kind = "" if isinstance(expression.this, exp.Literal) else f"{expression.text('kind')} "
return f"REFRESH {kind}{this}"

def toarray_sql(self, expression: exp.ToArray) -> str:
arg = expression.this
Expand Down
16 changes: 13 additions & 3 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7554,9 +7554,19 @@ def _parse_commit_or_rollback(self) -> exp.Commit | exp.Rollback:

return self.expression(exp.Commit, chain=chain)

def _parse_refresh(self) -> exp.Refresh:
self._match(TokenType.TABLE)
return self.expression(exp.Refresh, this=self._parse_string() or self._parse_table())
def _parse_refresh(self) -> exp.Refresh | exp.Command:
if self._match(TokenType.TABLE):
kind = "TABLE"
elif self._match_text_seq("MATERIALIZED", "VIEW"):
kind = "MATERIALIZED VIEW"
else:
kind = ""

this = self._parse_string() or self._parse_table()
if not kind and not isinstance(this, exp.Literal):
return self._parse_as_command(self._prev)

return self.expression(exp.Refresh, this=this, kind=kind)

def _parse_column_def_with_exists(self):
start = self._index
Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class TestTrino(Validator):
dialect = "trino"

def test_trino(self):
self.validate_identity("REFRESH MATERIALIZED VIEW mynamespace.test_view")
self.validate_identity("JSON_QUERY(m.properties, 'lax $.area' OMIT QUOTES NULL ON ERROR)")
self.validate_identity("JSON_EXTRACT(content, json_path)")
self.validate_identity("JSON_QUERY(content, 'lax $.HY.*')")
Expand Down