Skip to content

Commit 2cc67cd

Browse files
authored
feat(singlestore): support dcolonqmark (#6485)
* support dcolonqmark * add testcases
1 parent aacc981 commit 2cc67cd

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

sqlglot/dialects/singlestore.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class Tokenizer(MySQL.Tokenizer):
8181
"!:>": TokenType.NCOLON_GT,
8282
"::$": TokenType.DCOLONDOLLAR,
8383
"::%": TokenType.DCOLONPERCENT,
84+
"::?": TokenType.DCOLONQMARK,
8485
}
8586

8687
class Parser(MySQL.Parser):
@@ -253,6 +254,12 @@ class Parser(MySQL.Parser):
253254
TokenType.DCOLONPERCENT: lambda self, this, path: build_json_extract_path(
254255
exp.JSONExtractScalar, json_type="DOUBLE"
255256
)([this, exp.Literal.string(path.name)]),
257+
TokenType.DCOLONQMARK: lambda self, this, path: self.expression(
258+
exp.JSONExists,
259+
this=this,
260+
path=path.name,
261+
from_dcolonqmark=True,
262+
),
256263
}
257264
COLUMN_OPERATORS.pop(TokenType.ARROW)
258265
COLUMN_OPERATORS.pop(TokenType.DARROW)
@@ -452,8 +459,10 @@ def _unicode_substitute(m: re.Match[str]) -> str:
452459
exp.JSONBExists: lambda self, e: self.func(
453460
"BSON_MATCH_ANY_EXISTS", e.this, e.args.get("path")
454461
),
455-
exp.JSONExists: unsupported_args("passing", "on_condition")(
456-
lambda self, e: self.func("JSON_MATCH_ANY_EXISTS", e.this, e.args.get("path"))
462+
exp.JSONExists: lambda self, e: (
463+
f"{self.sql(e.this)}::?{self.sql(e.args.get('path'))}"
464+
if e.args.get("from_dcolonqmark")
465+
else self.func("JSON_MATCH_ANY_EXISTS", e.this, e.args.get("path"))
457466
),
458467
exp.JSONObject: unsupported_args(
459468
"null_handling", "unique_keys", "return_type", "encoding"

sqlglot/expressions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7023,7 +7023,13 @@ class JSONArrayAgg(Func):
70237023

70247024

70257025
class JSONExists(Func):
7026-
arg_types = {"this": True, "path": True, "passing": False, "on_condition": False}
7026+
arg_types = {
7027+
"this": True,
7028+
"path": True,
7029+
"passing": False,
7030+
"on_condition": False,
7031+
"from_dcolonqmark": False,
7032+
}
70277033

70287034

70297035
# https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/JSON_TABLE.html

sqlglot/tokens.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class TokenType(AutoName):
4141
DCOLON = auto()
4242
DCOLONDOLLAR = auto()
4343
DCOLONPERCENT = auto()
44+
DCOLONQMARK = auto()
4445
DQMARK = auto()
4546
SEMICOLON = auto()
4647
STAR = auto()

tests/dialects/test_singlestore.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,3 +965,6 @@ def test_constraints(self):
965965
self.validate_identity(
966966
"CREATE TABLE ComputedColumnConstraint (points INT, score AS (points * 2) PERSISTED BIGINT NOT NULL)"
967967
)
968+
969+
def test_dcolonqmark(self):
970+
self.validate_identity("SELECT * FROM employee WHERE JSON_MATCH_ANY(payroll::?names)")

0 commit comments

Comments
 (0)