Skip to content

Commit

Permalink
duckdb matrix type fixes #1094
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Feb 5, 2023
1 parent 3a13fdf commit 6e182cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2346,12 +2346,21 @@ def _parse_types(self, check_func: bool = False) -> t.Optional[exp.Expression]:
maybe_func = True

if not nested and self._match_pair(TokenType.L_BRACKET, TokenType.R_BRACKET):
return exp.DataType(
this = exp.DataType(
this=exp.DataType.Type.ARRAY,
expressions=[exp.DataType.build(type_token.value, expressions=expressions)],
nested=True,
)

while self._match_pair(TokenType.L_BRACKET, TokenType.R_BRACKET):
this = exp.DataType(
this=exp.DataType.Type.ARRAY,
expressions=[this],
nested=True,
)

return this

if self._match(TokenType.L_BRACKET):
self._retreat(index)
return None
Expand Down
8 changes: 8 additions & 0 deletions tests/dialects/test_duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ def test_cast(self):
},
)

self.validate_all(
"cast([[1]] as int[][])",
write={
"duckdb": "CAST(LIST_VALUE(LIST_VALUE(1)) AS INT[][])",
"spark": "CAST(ARRAY(ARRAY(1)) AS ARRAY<ARRAY<INT>>)",
},
)

def test_bool_or(self):
self.validate_all(
"SELECT a, LOGICAL_OR(b) FROM table GROUP BY a",
Expand Down

0 comments on commit 6e182cf

Please sign in to comment.