Skip to content

Commit 27a76cd

Browse files
feat(optimizer)!: Annotate type for snowflake COT, SIN and TAN functions (#6022)
1 parent ac97f14 commit 27a76cd

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

sqlglot/dialects/snowflake.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,12 @@ class Snowflake(Dialect):
563563

564564
TYPE_TO_EXPRESSIONS = {
565565
**Dialect.TYPE_TO_EXPRESSIONS,
566+
exp.DataType.Type.DOUBLE: {
567+
*Dialect.TYPE_TO_EXPRESSIONS[exp.DataType.Type.DOUBLE],
568+
exp.Cot,
569+
exp.Sin,
570+
exp.Tan,
571+
},
566572
exp.DataType.Type.INT: {
567573
*Dialect.TYPE_TO_EXPRESSIONS[exp.DataType.Type.INT],
568574
exp.Ascii,

sqlglot/expressions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5549,6 +5549,10 @@ class Sinh(Func):
55495549
pass
55505550

55515551

5552+
class Tan(Func):
5553+
pass
5554+
5555+
55525556
class CosineDistance(Func):
55535557
arg_types = {"this": True, "expression": True}
55545558

tests/dialects/test_snowflake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def test_snowflake(self):
1919
self.assertEqual(ast.sql("snowflake"), "DATEADD(MONTH, n, d)")
2020

2121
self.validate_identity("SELECT GET(a, b)")
22+
self.validate_identity("SELECT TAN(x)")
2223
self.assertEqual(
2324
# Ensures we don't fail when generating ParseJSON with the `safe` arg set to `True`
2425
self.validate_identity("""SELECT TRY_PARSE_JSON('{"x: 1}')""").sql(),

tests/fixtures/optimizer/annotate_functions.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,10 @@ BINARY;
16831683
COLLATION('hello');
16841684
VARCHAR;
16851685

1686+
# dialect: snowflake
1687+
COT(tbl.double_col);
1688+
DOUBLE;
1689+
16861690
# dialect: snowflake
16871691
CONCAT('Hello', 'World!');
16881692
VARCHAR;
@@ -2151,6 +2155,10 @@ VARCHAR;
21512155
SHA2_HEX('foo', null);
21522156
VARCHAR;
21532157

2158+
# dialect: snowflake
2159+
SIN(tbl.double_col);
2160+
DOUBLE;
2161+
21542162
# dialect: snowflake
21552163
SOUNDEX(tbl.str_col);
21562164
VARCHAR;
@@ -2259,6 +2267,10 @@ BINARY;
22592267
SUBSTR(tbl.str_col, NULL);
22602268
STRING;
22612269

2270+
# dialect: snowflake
2271+
TAN(tbl.double_col);
2272+
DOUBLE;
2273+
22622274
# dialect: snowflake
22632275
TRANSLATE('hello world', 'elo', 'XYZ');
22642276
VARCHAR;

0 commit comments

Comments
 (0)