1
0
Fork 0

Merging upstream version 26.2.1.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-13 22:00:08 +01:00
parent a5399bd16b
commit 4d0635d636
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
85 changed files with 57142 additions and 52288 deletions
sqlglot/dialects

View file

@ -62,6 +62,7 @@ class Dialects(str, Enum):
DATABRICKS = "databricks"
DORIS = "doris"
DRILL = "drill"
DRUID = "druid"
DUCKDB = "duckdb"
HIVE = "hive"
MATERIALIZE = "materialize"
@ -1089,7 +1090,19 @@ def str_position_sql(
this = self.func("SUBSTR", this, position)
position_offset = f" + {position} - 1"
return self.func(str_position_func_name, this, substr, instance) + position_offset
strpos_sql = self.func(str_position_func_name, this, substr, instance)
if position_offset:
zero = exp.Literal.number(0)
# If match is not found (returns 0) the position offset should not be applied
case = exp.If(
this=exp.EQ(this=strpos_sql, expression=zero),
true=zero,
false=strpos_sql + position_offset,
)
strpos_sql = self.sql(case)
return strpos_sql
def struct_extract_sql(self: Generator, expression: exp.StructExtract) -> str:
@ -1557,19 +1570,25 @@ def merge_without_target_sql(self: Generator, expression: exp.Merge) -> str:
targets.add(normalize(alias.this))
for when in expression.args["whens"].expressions:
# only remove the target names from the THEN clause
# theyre still valid in the <condition> part of WHEN MATCHED / WHEN NOT MATCHED
# ref: https://github.com/TobikoData/sqlmesh/issues/2934
then = when.args.get("then")
# only remove the target table names from certain parts of WHEN MATCHED / WHEN NOT MATCHED
# they are still valid in the <condition>, the right hand side of each UPDATE and the VALUES part
# (not the column list) of the INSERT
then: exp.Insert | exp.Update | None = when.args.get("then")
if then:
then.transform(
lambda node: (
exp.column(node.this)
if isinstance(node, exp.Column) and normalize(node.args.get("table")) in targets
else node
),
copy=False,
)
if isinstance(then, exp.Update):
for equals in then.find_all(exp.EQ):
equal_lhs = equals.this
if (
isinstance(equal_lhs, exp.Column)
and normalize(equal_lhs.args.get("table")) in targets
):
equal_lhs.replace(exp.column(equal_lhs.this))
if isinstance(then, exp.Insert):
column_list = then.this
if isinstance(column_list, exp.Tuple):
for column in column_list.expressions:
if normalize(column.args.get("table")) in targets:
column.replace(exp.column(column.this))
return self.merge_sql(expression)