Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion sqlglot/dialects/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ def _parse_alter_table_alter_index(self) -> exp.AlterIndex:
class Generator(generator.Generator):
INTERVAL_ALLOWS_PLURAL_FORM = False
LOCKING_READS_SUPPORTED = True
NULL_ORDERING_SUPPORTED = None
NULL_ORDERING_SUPPORTED: t.Optional[bool] = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the type hint here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it, linter was giving errors

JOIN_HINTS = False
TABLE_HINTS = True
DUPLICATE_KEY_UPDATE_WITH_SET = False
Expand Down
12 changes: 12 additions & 0 deletions sqlglot/dialects/singlestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ class Parser(MySQL.Parser):
),
}

FUNCTION_PARSERS: t.Dict[str, t.Callable] = {
**MySQL.Parser.FUNCTION_PARSERS,
"JSON_AGG": lambda self: exp.JSONArrayAgg(
this=self._parse_term(),
order=self._parse_order(),
),
}

NO_PAREN_FUNCTIONS = {
**MySQL.Parser.NO_PAREN_FUNCTIONS,
TokenType.UTC_DATE: exp.UtcDate,
Expand Down Expand Up @@ -237,6 +245,7 @@ class Parser(MySQL.Parser):

class Generator(MySQL.Generator):
SUPPORTS_UESCAPE = False
NULL_ORDERING_SUPPORTED = True

@staticmethod
def _unicode_substitute(m: re.Match[str]) -> str:
Expand Down Expand Up @@ -354,6 +363,9 @@ def _unicode_substitute(m: re.Match[str]) -> str:
exp.JSONPathSubscript: lambda self, e: self.json_path_part(e.this),
exp.JSONPathRoot: lambda *_: "",
exp.JSONFormat: unsupported_args("options", "is_json")(rename_func("JSON_PRETTY")),
exp.JSONArrayAgg: unsupported_args("null_handling", "return_type", "strict")(
lambda self, e: self.func("JSON_AGG", e.this, suffix=f"{self.sql(e, 'order')})")
),
exp.DayOfWeekIso: lambda self, e: f"(({self.func('DAYOFWEEK', e.this)} % 7) + 1)",
exp.DayOfMonth: rename_func("DAY"),
exp.Hll: rename_func("APPROX_COUNT_DISTINCT"),
Expand Down
9 changes: 9 additions & 0 deletions tests/dialects/test_singlestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ def test_json(self):
"": 'SELECT JSON_FORMAT(\'["G","alpha","20",10]\')',
},
)
self.validate_all(
"SELECT JSON_AGG(name ORDER BY id ASC NULLS LAST, name DESC NULLS FIRST) FROM t",
read={
"singlestore": "SELECT JSON_AGG(name ORDER BY id ASC NULLS LAST, name DESC NULLS FIRST) FROM t",
"oracle": "SELECT JSON_ARRAYAGG(name ORDER BY id ASC, name DESC) FROM t",
},
)
self.validate_identity("SELECT JSON_AGG(name) FROM t")
self.validate_identity("SELECT JSON_AGG(t.*) FROM t")

def test_date_parts_functions(self):
self.validate_identity(
Expand Down