Merging upstream version 20.9.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
9421b254ec
commit
37a231f554
144 changed files with 78309 additions and 59609 deletions
|
@ -11,7 +11,6 @@ from sqlglot.dialects.dialect import (
|
|||
datestrtodate_sql,
|
||||
format_time_lambda,
|
||||
isnull_to_is_null,
|
||||
json_keyvalue_comma_sql,
|
||||
locate_to_strposition,
|
||||
max_or_greatest,
|
||||
min_or_least,
|
||||
|
@ -21,6 +20,7 @@ from sqlglot.dialects.dialect import (
|
|||
no_tablesample_sql,
|
||||
no_trycast_sql,
|
||||
parse_date_delta_with_interval,
|
||||
path_to_jsonpath,
|
||||
rename_func,
|
||||
strposition_to_locate_sql,
|
||||
)
|
||||
|
@ -37,21 +37,21 @@ def _show_parser(*args: t.Any, **kwargs: t.Any) -> t.Callable[[MySQL.Parser], ex
|
|||
|
||||
def _date_trunc_sql(self: MySQL.Generator, expression: exp.DateTrunc) -> str:
|
||||
expr = self.sql(expression, "this")
|
||||
unit = expression.text("unit")
|
||||
unit = expression.text("unit").upper()
|
||||
|
||||
if unit == "day":
|
||||
if unit == "DAY":
|
||||
return f"DATE({expr})"
|
||||
|
||||
if unit == "week":
|
||||
if unit == "WEEK":
|
||||
concat = f"CONCAT(YEAR({expr}), ' ', WEEK({expr}, 1), ' 1')"
|
||||
date_format = "%Y %u %w"
|
||||
elif unit == "month":
|
||||
elif unit == "MONTH":
|
||||
concat = f"CONCAT(YEAR({expr}), ' ', MONTH({expr}), ' 1')"
|
||||
date_format = "%Y %c %e"
|
||||
elif unit == "quarter":
|
||||
elif unit == "QUARTER":
|
||||
concat = f"CONCAT(YEAR({expr}), ' ', QUARTER({expr}) * 3 - 2, ' 1')"
|
||||
date_format = "%Y %c %e"
|
||||
elif unit == "year":
|
||||
elif unit == "YEAR":
|
||||
concat = f"CONCAT(YEAR({expr}), ' 1 1')"
|
||||
date_format = "%Y %c %e"
|
||||
else:
|
||||
|
@ -292,9 +292,15 @@ class MySQL(Dialect):
|
|||
"DATE_ADD": parse_date_delta_with_interval(exp.DateAdd),
|
||||
"DATE_FORMAT": format_time_lambda(exp.TimeToStr, "mysql"),
|
||||
"DATE_SUB": parse_date_delta_with_interval(exp.DateSub),
|
||||
"DAY": lambda args: exp.Day(this=exp.TsOrDsToDate(this=seq_get(args, 0))),
|
||||
"DAYOFMONTH": lambda args: exp.DayOfMonth(this=exp.TsOrDsToDate(this=seq_get(args, 0))),
|
||||
"DAYOFWEEK": lambda args: exp.DayOfWeek(this=exp.TsOrDsToDate(this=seq_get(args, 0))),
|
||||
"DAYOFYEAR": lambda args: exp.DayOfYear(this=exp.TsOrDsToDate(this=seq_get(args, 0))),
|
||||
"INSTR": lambda args: exp.StrPosition(substr=seq_get(args, 1), this=seq_get(args, 0)),
|
||||
"ISNULL": isnull_to_is_null,
|
||||
"LOCATE": locate_to_strposition,
|
||||
"MAKETIME": exp.TimeFromParts.from_arg_list,
|
||||
"MONTH": lambda args: exp.Month(this=exp.TsOrDsToDate(this=seq_get(args, 0))),
|
||||
"MONTHNAME": lambda args: exp.TimeToStr(
|
||||
this=exp.TsOrDsToDate(this=seq_get(args, 0)),
|
||||
format=exp.Literal.string("%B"),
|
||||
|
@ -308,11 +314,6 @@ class MySQL(Dialect):
|
|||
)
|
||||
+ 1
|
||||
),
|
||||
"DAY": lambda args: exp.Day(this=exp.TsOrDsToDate(this=seq_get(args, 0))),
|
||||
"DAYOFMONTH": lambda args: exp.DayOfMonth(this=exp.TsOrDsToDate(this=seq_get(args, 0))),
|
||||
"DAYOFWEEK": lambda args: exp.DayOfWeek(this=exp.TsOrDsToDate(this=seq_get(args, 0))),
|
||||
"DAYOFYEAR": lambda args: exp.DayOfYear(this=exp.TsOrDsToDate(this=seq_get(args, 0))),
|
||||
"MONTH": lambda args: exp.Month(this=exp.TsOrDsToDate(this=seq_get(args, 0))),
|
||||
"WEEK": lambda args: exp.Week(
|
||||
this=exp.TsOrDsToDate(this=seq_get(args, 0)), mode=seq_get(args, 1)
|
||||
),
|
||||
|
@ -441,6 +442,7 @@ class MySQL(Dialect):
|
|||
}
|
||||
|
||||
LOG_DEFAULTS_TO_LN = True
|
||||
STRING_ALIASES = True
|
||||
|
||||
def _parse_primary_key_part(self) -> t.Optional[exp.Expression]:
|
||||
this = self._parse_id_var()
|
||||
|
@ -620,13 +622,15 @@ class MySQL(Dialect):
|
|||
|
||||
class Generator(generator.Generator):
|
||||
LOCKING_READS_SUPPORTED = True
|
||||
NULL_ORDERING_SUPPORTED = False
|
||||
NULL_ORDERING_SUPPORTED = None
|
||||
JOIN_HINTS = False
|
||||
TABLE_HINTS = True
|
||||
DUPLICATE_KEY_UPDATE_WITH_SET = False
|
||||
QUERY_HINT_SEP = " "
|
||||
VALUES_AS_TABLE = False
|
||||
NVL2_SUPPORTED = False
|
||||
LAST_DAY_SUPPORTS_DATE_PART = False
|
||||
JSON_KEY_VALUE_PAIR_SEP = ","
|
||||
|
||||
TRANSFORMS = {
|
||||
**generator.Generator.TRANSFORMS,
|
||||
|
@ -642,15 +646,16 @@ class MySQL(Dialect):
|
|||
exp.DayOfMonth: _remove_ts_or_ds_to_date(rename_func("DAYOFMONTH")),
|
||||
exp.DayOfWeek: _remove_ts_or_ds_to_date(rename_func("DAYOFWEEK")),
|
||||
exp.DayOfYear: _remove_ts_or_ds_to_date(rename_func("DAYOFYEAR")),
|
||||
exp.GetPath: path_to_jsonpath(),
|
||||
exp.GroupConcat: lambda self, e: f"""GROUP_CONCAT({self.sql(e, "this")} SEPARATOR {self.sql(e, "separator") or "','"})""",
|
||||
exp.ILike: no_ilike_sql,
|
||||
exp.JSONExtractScalar: arrow_json_extract_scalar_sql,
|
||||
exp.JSONKeyValue: json_keyvalue_comma_sql,
|
||||
exp.Max: max_or_greatest,
|
||||
exp.Min: min_or_least,
|
||||
exp.Month: _remove_ts_or_ds_to_date(),
|
||||
exp.NullSafeEQ: lambda self, e: self.binary(e, "<=>"),
|
||||
exp.NullSafeNEQ: lambda self, e: f"NOT {self.binary(e, '<=>')}",
|
||||
exp.ParseJSON: lambda self, e: self.sql(e, "this"),
|
||||
exp.Pivot: no_pivot_sql,
|
||||
exp.Select: transforms.preprocess(
|
||||
[
|
||||
|
@ -665,6 +670,7 @@ class MySQL(Dialect):
|
|||
exp.StrToTime: _str_to_date_sql,
|
||||
exp.Stuff: rename_func("INSERT"),
|
||||
exp.TableSample: no_tablesample_sql,
|
||||
exp.TimeFromParts: rename_func("MAKETIME"),
|
||||
exp.TimestampAdd: date_add_interval_sql("DATE", "ADD"),
|
||||
exp.TimestampSub: date_add_interval_sql("DATE", "SUB"),
|
||||
exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue