Skip to content

Commit f7458a4

Browse files
fivetran-MichaelLeeMichael Lee
andauthored
feat(optimizer)!: annotate type for snowflake func TO_BOOLEAN (#6481)
* chore(optimizer)!: annotate type for snowflake func TO_BOOLEAN * formatting * remove _sql_names from ToBoolean expression * remove TO_BOOLEAN from oracle function parsing --------- Co-authored-by: Michael Lee <[email protected]>
1 parent 68a5e61 commit f7458a4

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

sqlglot/dialects/oracle.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class Parser(parser.Parser):
132132
unabbreviate=False,
133133
),
134134
}
135+
FUNCTIONS.pop("TO_BOOLEAN")
135136

136137
NO_PAREN_FUNCTION_PARSERS = {
137138
**parser.Parser.NO_PAREN_FUNCTION_PARSERS,

sqlglot/expressions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5876,6 +5876,10 @@ class ToArray(Func):
58765876
pass
58775877

58785878

5879+
class ToBoolean(Func):
5880+
pass
5881+
5882+
58795883
# https://materialize.com/docs/sql/types/list/
58805884
class List(Func):
58815885
arg_types = {"expressions": False}

sqlglot/typing/snowflake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def _annotate_math_with_float_decfloat(
239239
exp.IsNullValue,
240240
exp.Search,
241241
exp.SearchIp,
242+
exp.ToBoolean,
242243
}
243244
},
244245
**{

tests/dialects/test_snowflake.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ def test_snowflake(self):
8585
self.validate_identity("SELECT BOOLAND(1, -2)")
8686
self.validate_identity("SELECT BOOLXOR(2, 0)")
8787
self.validate_identity("SELECT BOOLOR(1, 0)")
88+
self.validate_identity("SELECT TO_BOOLEAN('true')")
89+
self.validate_identity("SELECT TO_BOOLEAN(1)")
8890
self.validate_identity("SELECT IS_NULL_VALUE(GET_PATH(payload, 'field'))")
8991
self.validate_identity("SELECT RTRIMMED_LENGTH(' ABCD ')")
9092
self.validate_identity("SELECT HEX_DECODE_STRING('48656C6C6F')")

tests/fixtures/optimizer/annotate_functions.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,18 @@ BOOLEAN;
19081908
BOOLOR_AGG(tbl.bool_col);
19091909
BOOLEAN;
19101910

1911+
# dialect: snowflake
1912+
TO_BOOLEAN('true');
1913+
BOOLEAN;
1914+
1915+
# dialect: snowflake
1916+
TO_BOOLEAN(1);
1917+
BOOLEAN;
1918+
1919+
# dialect: snowflake
1920+
TO_BOOLEAN(tbl.varchar_col);
1921+
BOOLEAN;
1922+
19111923
# dialect: snowflake
19121924
ARRAY_AGG(tbl.bin_col);
19131925
ARRAY;

0 commit comments

Comments
 (0)