diff options
Diffstat (limited to 'sqlglot/dialects/starrocks.py')
-rw-r--r-- | sqlglot/dialects/starrocks.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/sqlglot/dialects/starrocks.py b/sqlglot/dialects/starrocks.py index baa62e8..4f6183c 100644 --- a/sqlglot/dialects/starrocks.py +++ b/sqlglot/dialects/starrocks.py @@ -17,6 +17,13 @@ class StarRocks(MySQL): "DATE_TRUNC": lambda args: exp.TimestampTrunc( this=seq_get(args, 1), unit=seq_get(args, 0) ), + "DATEDIFF": lambda args: exp.DateDiff( + this=seq_get(args, 0), expression=seq_get(args, 1), unit=exp.Literal.string("DAY") + ), + "DATE_DIFF": lambda args: exp.DateDiff( + this=seq_get(args, 1), expression=seq_get(args, 2), unit=seq_get(args, 0) + ), + "REGEXP": exp.RegexpLike.from_arg_list, } class Generator(MySQL.Generator): @@ -32,9 +39,11 @@ class StarRocks(MySQL): TRANSFORMS = { **MySQL.Generator.TRANSFORMS, exp.ApproxDistinct: approx_count_distinct_sql, + exp.DateDiff: lambda self, e: self.func( + "DATE_DIFF", exp.Literal.string(e.text("unit") or "DAY"), e.this, e.expression + ), 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( |