Skip to content

Commit 1c42ef4

Browse files
feat(singlestore): Fixed parsing/generation of exp.JSONArrayAgg (#5819)
* feat(singlestore): Fixed parsing/generation of exp.JSONArrayAgg * Fixed merge issues
1 parent 4c1908d commit 1c42ef4

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

sqlglot/dialects/mysql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ def _parse_alter_table_alter_index(self) -> exp.AlterIndex:
691691
class Generator(generator.Generator):
692692
INTERVAL_ALLOWS_PLURAL_FORM = False
693693
LOCKING_READS_SUPPORTED = True
694-
NULL_ORDERING_SUPPORTED = None
694+
NULL_ORDERING_SUPPORTED: t.Optional[bool] = None
695695
JOIN_HINTS = False
696696
TABLE_HINTS = True
697697
DUPLICATE_KEY_UPDATE_WITH_SET = False

sqlglot/dialects/singlestore.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ class Parser(MySQL.Parser):
205205

206206
FUNCTION_PARSERS: t.Dict[str, t.Callable] = {
207207
**MySQL.Parser.FUNCTION_PARSERS,
208+
"JSON_AGG": lambda self: exp.JSONArrayAgg(
209+
this=self._parse_term(),
210+
order=self._parse_order(),
211+
),
208212
}
209213

210214
NO_PAREN_FUNCTIONS = {
@@ -245,6 +249,7 @@ class Parser(MySQL.Parser):
245249

246250
class Generator(MySQL.Generator):
247251
SUPPORTS_UESCAPE = False
252+
NULL_ORDERING_SUPPORTED = True
248253
MATCH_AGAINST_TABLE_PREFIX = "TABLE "
249254

250255
@staticmethod
@@ -368,6 +373,9 @@ def _unicode_substitute(m: re.Match[str]) -> str:
368373
exp.JSONPathSubscript: lambda self, e: self.json_path_part(e.this),
369374
exp.JSONPathRoot: lambda *_: "",
370375
exp.JSONFormat: unsupported_args("options", "is_json")(rename_func("JSON_PRETTY")),
376+
exp.JSONArrayAgg: unsupported_args("null_handling", "return_type", "strict")(
377+
lambda self, e: self.func("JSON_AGG", e.this, suffix=f"{self.sql(e, 'order')})")
378+
),
371379
exp.JSONArray: unsupported_args("null_handling", "return_type", "strict")(
372380
rename_func("JSON_BUILD_ARRAY")
373381
),

tests/dialects/test_singlestore.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ def test_json(self):
226226
"": 'SELECT JSON_FORMAT(\'["G","alpha","20",10]\')',
227227
},
228228
)
229+
self.validate_all(
230+
"SELECT JSON_AGG(name ORDER BY id ASC NULLS LAST, name DESC NULLS FIRST) FROM t",
231+
read={
232+
"singlestore": "SELECT JSON_AGG(name ORDER BY id ASC NULLS LAST, name DESC NULLS FIRST) FROM t",
233+
"oracle": "SELECT JSON_ARRAYAGG(name ORDER BY id ASC, name DESC) FROM t",
234+
},
235+
)
236+
self.validate_identity("SELECT JSON_AGG(name) FROM t")
237+
self.validate_identity("SELECT JSON_AGG(t.*) FROM t")
229238
self.validate_all(
230239
"SELECT JSON_BUILD_ARRAY(id, name) FROM t",
231240
read={

0 commit comments

Comments
 (0)