Skip to content

Commit 235fc14

Browse files
authored
fix(mysql,singlestore)!: support charset (#6633)
* support: charset * support for mysql as well * test fixed * pre-commit * undo the _sql position * removed nested from unsupported_args in datatype_sql * handle nested specific to STRUCT
1 parent 9a41cfc commit 235fc14

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

sqlglot/dialects/mysql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ class Parser(parser.Parser):
293293
TokenType.MOD,
294294
TokenType.SCHEMA,
295295
TokenType.VALUES,
296+
TokenType.CHARACTER_SET,
296297
}
297298

298299
CONJUNCTION = {

sqlglot/dialects/singlestore.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,6 @@ def _unicode_substitute(m: re.Match[str]) -> str:
499499
),
500500
exp.IsAscii: lambda self, e: f"({self.sql(e, 'this')} RLIKE '^[\x00-\x7f]*$')",
501501
exp.MD5Digest: lambda self, e: self.func("UNHEX", self.func("MD5", e.this)),
502-
exp.Chr: rename_func("CHAR"),
503502
exp.Contains: rename_func("INSTR"),
504503
exp.RegexpExtractAll: unsupported_args("position", "occurrence", "group")(
505504
lambda self, e: self.func(
@@ -1762,8 +1761,13 @@ def jsonarraycontains_sql(self, expression: exp.JSONArrayContains) -> str:
17621761
self.func("TO_JSON", expression.this),
17631762
)
17641763

1765-
@unsupported_args("kind", "nested", "values")
1764+
@unsupported_args("kind", "values")
17661765
def datatype_sql(self, expression: exp.DataType) -> str:
1766+
if expression.args.get("nested") and not expression.is_type(exp.DataType.Type.STRUCT):
1767+
self.unsupported(
1768+
f"Argument 'nested' is not supported for representation of '{expression.this.value}' in SingleStore"
1769+
)
1770+
17671771
if expression.is_type(exp.DataType.Type.VARBINARY) and not expression.expressions:
17681772
# `VARBINARY` must always have a size - if it doesn't, we always generate `BLOB`
17691773
return "BLOB"

tests/dialects/test_mysql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ def test_identity(self):
332332
)
333333
self.validate_identity("SELECT SUBSTR(1 FROM 2 FOR 3)", "SELECT SUBSTRING(1, 2, 3)")
334334
self.validate_identity("SELECT ELT(2, 'foo', 'bar', 'baz') AS Result")
335+
self.validate_identity("SELECT CHARSET(CHAR(100 USING utf8))")
335336

336337
def test_types(self):
337338
for char_type in MySQL.Generator.CHAR_CAST_MAPPING:

tests/dialects/test_singlestore.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def test_singlestore(self):
2020
self.validate_identity("SELECT 1")
2121
self.validate_identity("SELECT * FROM `users` ORDER BY ALL")
2222
self.validate_identity("SELECT ELT(2, 'foo', 'bar', 'baz')")
23+
self.validate_identity("SELECT CHARSET(CHAR(100 USING utf8))")
2324
self.validate_identity("SELECT TO_JSON(ROW(1, 2) :> RECORD(a INT, b INT))")
2425

2526
def test_byte_strings(self):

0 commit comments

Comments
 (0)