Skip to content

Commit 1d3c9aa

Browse files
feat(snowflake)!: Transpile support for bitor/bit_or snowflake function (#4486)
* feat(snowflake): Transpile support for bitor/bit_or * feat(snowflake): Transpile support for bitor/bit_or * feat(snowflake): Transpile support for bitor/bit_or * chore: moved test cases of bitor to the test_snowflake * feat(snowflake): Added support for bitnow * Revert "feat(snowflake): Added support for bitnow" This reverts commit 85551c9. * feat(snowflake): Added support for bitor extra parameters * feat(snowflake): remove unnecessary test case * chore(snowflake): code refactoring --------- Co-authored-by: ranjanankur314 <[email protected]>
1 parent 2655d7c commit 1d3c9aa

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

sqlglot/dialects/snowflake.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ def _builder(args: t.List) -> E:
107107
return _builder
108108

109109

110+
def _build_bitor(args: t.List) -> exp.BitwiseOr | exp.Anonymous:
111+
if len(args) == 3:
112+
return exp.Anonymous(this="BITOR", expressions=args)
113+
114+
return binary_from_function(exp.BitwiseOr)(args)
115+
116+
110117
# https://docs.snowflake.com/en/sql-reference/functions/div0
111118
def _build_if_from_div0(args: t.List) -> exp.If:
112119
lhs = exp._wrap(seq_get(args, 0), exp.Binary)
@@ -393,6 +400,8 @@ class Parser(parser.Parser):
393400
),
394401
"BITXOR": binary_from_function(exp.BitwiseXor),
395402
"BIT_XOR": binary_from_function(exp.BitwiseXor),
403+
"BITOR": _build_bitor,
404+
"BIT_OR": _build_bitor,
396405
"BOOLXOR": binary_from_function(exp.Xor),
397406
"DATE": _build_datetime("DATE", exp.DataType.Type.DATE),
398407
"DATE_TRUNC": _date_trunc_to_time,
@@ -869,6 +878,7 @@ class Generator(generator.Generator):
869878
"CONVERT_TIMEZONE", e.args.get("zone"), e.this
870879
),
871880
exp.BitwiseXor: rename_func("BITXOR"),
881+
exp.BitwiseOr: rename_func("BITOR"),
872882
exp.Create: transforms.preprocess([_flatten_structured_types_unless_iceberg]),
873883
exp.DateAdd: date_delta_sql("DATEADD"),
874884
exp.DateDiff: date_delta_sql("DATEDIFF"),

tests/dialects/test_snowflake.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,12 @@ def test_snowflake(self):
976976
"snowflake": "EDITDISTANCE(col1, col2, 3)",
977977
},
978978
)
979+
self.validate_identity("SELECT BITOR(a, b) FROM table")
980+
981+
self.validate_identity("SELECT BIT_OR(a, b) FROM table", "SELECT BITOR(a, b) FROM table")
982+
983+
# Test BITOR with three arguments, padding on the left
984+
self.validate_identity("SELECT BITOR(a, b, 'LEFT') FROM table_name")
979985

980986
def test_null_treatment(self):
981987
self.validate_all(

0 commit comments

Comments
 (0)