Skip to content

Commit

Permalink
Feat: Support regex function in Starrocks (#1528)
Browse files Browse the repository at this point in the history
* Support regex in Starrocks

* Format
  • Loading branch information
acreux authored May 3, 2023
1 parent e7111ba commit 52c80e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions sqlglot/dialects/starrocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Generator(MySQL.Generator): # type: ignore
exp.JSONExtractScalar: arrow_json_extract_sql,
exp.JSONExtract: arrow_json_extract_sql,
exp.DateDiff: rename_func("DATEDIFF"),
exp.RegexpLike: rename_func("REGEXP"),
exp.StrToUnix: lambda self, e: f"UNIX_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})",
exp.TimestampTrunc: lambda self, e: self.func(
"DATE_TRUNC", exp.Literal.string(e.text("unit")), e.this
Expand Down
8 changes: 8 additions & 0 deletions tests/dialects/test_starrocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ def test_identity(self):

def test_time(self):
self.validate_identity("TIMESTAMP('2022-01-01')")

def test_regex(self):
self.validate_all(
"SELECT REGEXP_LIKE(abc, '%foo%')",
write={
"starrocks": "SELECT REGEXP(abc, '%foo%')",
},
)

0 comments on commit 52c80e0

Please sign in to comment.