Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(snowflake, bigquery): Remove exp.Trim generation #4070

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion sqlglot/dialects/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,6 @@ class Generator(generator.Generator):
exp.TimestampSub: date_add_interval_sql("TIMESTAMP", "SUB"),
exp.TimeStrToTime: timestrtotime_sql,
exp.Transaction: lambda *_: "BEGIN TRANSACTION",
exp.Trim: lambda self, e: self.func("TRIM", e.this, e.expression),
exp.TsOrDsAdd: _ts_or_ds_add_sql,
exp.TsOrDsDiff: _ts_or_ds_diff_sql,
exp.TsOrDsToTime: rename_func("TIME"),
Expand Down
1 change: 0 additions & 1 deletion sqlglot/dialects/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,6 @@ class Generator(generator.Generator):
exp.TimeToUnix: lambda self, e: f"EXTRACT(epoch_second FROM {self.sql(e, 'this')})",
exp.ToArray: rename_func("TO_ARRAY"),
exp.ToChar: lambda self, e: self.function_fallback_sql(e),
exp.Trim: lambda self, e: self.func("TRIM", e.this, e.expression),
exp.TsOrDsAdd: date_delta_sql("DATEADD", cast=True),
exp.TsOrDsDiff: date_delta_sql("DATEDIFF"),
exp.TsOrDsToDate: lambda self, e: self.func(
Expand Down
47 changes: 47 additions & 0 deletions tests/dialects/test_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2802,3 +2802,50 @@ def test_coalesce(self):

# Check T-SQL's ISNULL which is parsed into exp.Coalesce
self.assertIsInstance(parse_one("ISNULL(x, y)", read="tsql").expressions, list)

def test_trim(self):
self.validate_all(
"TRIM('abc', 'a')",
read={
"bigquery": "TRIM('abc', 'a')",
"snowflake": "TRIM('abc', 'a')",
},
write={
"bigquery": "TRIM('abc', 'a')",
"snowflake": "TRIM('abc', 'a')",
},
)

self.validate_all(
"LTRIM('Hello World', 'H')",
read={
"oracle": "LTRIM('Hello World', 'H')",
"clickhouse": "TRIM(LEADING 'H' FROM 'Hello World')",
"snowflake": "LTRIM('Hello World', 'H')",
"bigquery": "LTRIM('Hello World', 'H')",
"": "LTRIM('Hello World', 'H')",
},
write={
"clickhouse": "TRIM(LEADING 'H' FROM 'Hello World')",
"oracle": "LTRIM('Hello World', 'H')",
"snowflake": "LTRIM('Hello World', 'H')",
"bigquery": "LTRIM('Hello World', 'H')",
},
)

self.validate_all(
"RTRIM('Hello World', 'd')",
read={
"clickhouse": "TRIM(TRAILING 'd' FROM 'Hello World')",
"oracle": "RTRIM('Hello World', 'd')",
"snowflake": "RTRIM('Hello World', 'd')",
"bigquery": "RTRIM('Hello World', 'd')",
"": "RTRIM('Hello World', 'd')",
},
write={
"clickhouse": "TRIM(TRAILING 'd' FROM 'Hello World')",
"oracle": "RTRIM('Hello World', 'd')",
"snowflake": "RTRIM('Hello World', 'd')",
"bigquery": "RTRIM('Hello World', 'd')",
},
)
16 changes: 0 additions & 16 deletions tests/dialects/test_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,22 +266,6 @@ def test_oracle(self):
"clickhouse": "COALESCE(NULL, 1)",
},
)
self.validate_all(
"LTRIM('Hello World', 'H')",
write={
"": "LTRIM('Hello World', 'H')",
"oracle": "LTRIM('Hello World', 'H')",
"clickhouse": "TRIM(LEADING 'H' FROM 'Hello World')",
},
)
self.validate_all(
"RTRIM('Hello World', 'd')",
write={
"": "RTRIM('Hello World', 'd')",
"oracle": "RTRIM('Hello World', 'd')",
"clickhouse": "TRIM(TRAILING 'd' FROM 'Hello World')",
},
)
self.validate_all(
"TRIM(BOTH 'h' FROM 'Hello World')",
write={
Expand Down
Loading