Skip to content

Commit 9c17264

Browse files
authored
fix(hive): Enclose exp.Split with \E (#4163)
1 parent abafa60 commit 9c17264

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

sqlglot/dialects/hive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ class Generator(generator.Generator):
546546
exp.SchemaCommentProperty: lambda self, e: self.naked_property(e),
547547
exp.ArrayUniqueAgg: rename_func("COLLECT_SET"),
548548
exp.Split: lambda self, e: self.func(
549-
"SPLIT", e.this, self.func("CONCAT", "'\\\\Q'", e.expression)
549+
"SPLIT", e.this, self.func("CONCAT", "'\\\\Q'", e.expression, "'\\\\E'")
550550
),
551551
exp.Select: transforms.preprocess(
552552
[

tests/dialects/test_duckdb.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,17 +535,17 @@ def test_duckdb(self):
535535
write={
536536
"duckdb": "STR_SPLIT(x, 'a')",
537537
"presto": "SPLIT(x, 'a')",
538-
"hive": "SPLIT(x, CONCAT('\\\\Q', 'a'))",
539-
"spark": "SPLIT(x, CONCAT('\\\\Q', 'a'))",
538+
"hive": "SPLIT(x, CONCAT('\\\\Q', 'a', '\\\\E'))",
539+
"spark": "SPLIT(x, CONCAT('\\\\Q', 'a', '\\\\E'))",
540540
},
541541
)
542542
self.validate_all(
543543
"STRING_TO_ARRAY(x, 'a')",
544544
write={
545545
"duckdb": "STR_SPLIT(x, 'a')",
546546
"presto": "SPLIT(x, 'a')",
547-
"hive": "SPLIT(x, CONCAT('\\\\Q', 'a'))",
548-
"spark": "SPLIT(x, CONCAT('\\\\Q', 'a'))",
547+
"hive": "SPLIT(x, CONCAT('\\\\Q', 'a', '\\\\E'))",
548+
"spark": "SPLIT(x, CONCAT('\\\\Q', 'a', '\\\\E'))",
549549
},
550550
)
551551
self.validate_all(

tests/dialects/test_presto.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ def test_regex(self):
158158
write={
159159
"duckdb": "STR_SPLIT(x, 'a.')",
160160
"presto": "SPLIT(x, 'a.')",
161-
"hive": "SPLIT(x, CONCAT('\\\\Q', 'a.'))",
162-
"spark": "SPLIT(x, CONCAT('\\\\Q', 'a.'))",
161+
"hive": "SPLIT(x, CONCAT('\\\\Q', 'a.', '\\\\E'))",
162+
"spark": "SPLIT(x, CONCAT('\\\\Q', 'a.', '\\\\E'))",
163163
},
164164
)
165165
self.validate_all(

tests/dialects/test_starrocks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def test_unnest(self):
8585
r"""SELECT id, t.type, t.scores FROM example_table, unnest(split(type, ";"), scores) AS t(type,scores)""",
8686
write={
8787
"postgres": "SELECT id, t.type, t.scores FROM example_table, UNNEST(SPLIT(type, ';'), scores) AS t(type, scores)",
88-
"spark": r"""SELECT id, t.type, t.scores FROM example_table LATERAL VIEW INLINE(ARRAYS_ZIP(SPLIT(type, CONCAT('\\Q', ';')), scores)) t AS type, scores""",
89-
"databricks": r"""SELECT id, t.type, t.scores FROM example_table LATERAL VIEW INLINE(ARRAYS_ZIP(SPLIT(type, CONCAT('\\Q', ';')), scores)) t AS type, scores""",
88+
"spark": r"""SELECT id, t.type, t.scores FROM example_table LATERAL VIEW INLINE(ARRAYS_ZIP(SPLIT(type, CONCAT('\\Q', ';', '\\E')), scores)) t AS type, scores""",
89+
"databricks": r"""SELECT id, t.type, t.scores FROM example_table LATERAL VIEW INLINE(ARRAYS_ZIP(SPLIT(type, CONCAT('\\Q', ';', '\\E')), scores)) t AS type, scores""",
9090
"starrocks": r"""SELECT id, t.type, t.scores FROM example_table, UNNEST(SPLIT(type, ';'), scores) AS t(type, scores)""",
9191
"hive": UnsupportedError,
9292
},
@@ -95,7 +95,7 @@ def test_unnest(self):
9595
self.validate_all(
9696
r"""SELECT id, t.type, t.scores FROM example_table_2 CROSS JOIN LATERAL unnest(split(type, ";"), scores) AS t(type,scores)""",
9797
write={
98-
"spark": r"""SELECT id, t.type, t.scores FROM example_table_2 LATERAL VIEW INLINE(ARRAYS_ZIP(SPLIT(type, CONCAT('\\Q', ';')), scores)) t AS type, scores""",
98+
"spark": r"""SELECT id, t.type, t.scores FROM example_table_2 LATERAL VIEW INLINE(ARRAYS_ZIP(SPLIT(type, CONCAT('\\Q', ';', '\\E')), scores)) t AS type, scores""",
9999
"starrocks": r"""SELECT id, t.type, t.scores FROM example_table_2 CROSS JOIN LATERAL UNNEST(SPLIT(type, ';'), scores) AS t(type, scores)""",
100100
"hive": UnsupportedError,
101101
},

0 commit comments

Comments
 (0)