Skip to content

Commit 5f8f2e1

Browse files
feat(optimizer)!: annotate type for Snowflake COSH function
1 parent 8b48f7b commit 5f8f2e1

File tree

9 files changed

+15
-0
lines changed

9 files changed

+15
-0
lines changed

sqlglot/dialects/snowflake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ class Snowflake(Dialect):
565565
**Dialect.TYPE_TO_EXPRESSIONS,
566566
exp.DataType.Type.DOUBLE: {
567567
*Dialect.TYPE_TO_EXPRESSIONS[exp.DataType.Type.DOUBLE],
568+
exp.Cosh,
568569
exp.Cot,
569570
exp.Sin,
570571
exp.Tan,

sqlglot/expressions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5553,6 +5553,10 @@ class Tan(Func):
55535553
pass
55545554

55555555

5556+
class Cosh(Func):
5557+
pass
5558+
5559+
55565560
class CosineDistance(Func):
55575561
arg_types = {"this": True, "expression": True}
55585562

tests/dialects/test_bigquery.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,7 @@ def test_ml_functions(self):
21082108
self.validate_identity(
21092109
"SELECT * FROM ML.PREDICT(MODEL mydataset.mymodel, (SELECT custom_label, column1, column2 FROM mydataset.mytable), STRUCT(0.55 AS threshold))"
21102110
)
2111+
self.validate_identity("SELECT COSH(1.5)")
21112112
self.validate_identity(
21122113
"SELECT * FROM ML.PREDICT(MODEL `my_project`.my_dataset.my_model, (SELECT * FROM input_data))"
21132114
)

tests/dialects/test_databricks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class TestDatabricks(Validator):
77
dialect = "databricks"
88

99
def test_databricks(self):
10+
self.validate_identity("SELECT COSH(1.5)")
1011
null_type = exp.DataType.build("VOID", dialect="databricks")
1112
self.assertEqual(null_type.sql(), "NULL")
1213
self.assertEqual(null_type.sql("databricks"), "VOID")

tests/dialects/test_duckdb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class TestDuckDB(Validator):
99
dialect = "duckdb"
1010

1111
def test_duckdb(self):
12+
self.validate_identity("SELECT COSH(1.5)")
1213
with self.assertRaises(ParseError):
1314
parse_one("1 //", read="duckdb")
1415

tests/dialects/test_postgres.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class TestPostgres(Validator):
88
dialect = "postgres"
99

1010
def test_postgres(self):
11+
self.validate_identity("SELECT COSH(1.5)")
1112
self.validate_identity(
1213
"select count() OVER(partition by a order by a range offset preceding exclude current row)",
1314
"SELECT COUNT() OVER (PARTITION BY a ORDER BY a range BETWEEN offset preceding AND CURRENT ROW EXCLUDE CURRENT ROW)",

tests/dialects/test_redshift.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class TestRedshift(Validator):
66
dialect = "redshift"
77

88
def test_redshift(self):
9+
self.validate_identity("SELECT COSH(1.5)")
910
self.validate_all(
1011
"SELECT SPLIT_TO_ARRAY('12,345,6789')",
1112
write={

tests/dialects/test_snowflake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def test_snowflake(self):
4949
self.validate_identity("SELECT SOUNDEX_P123(column_name)")
5050
self.validate_identity("SELECT ABS(x)")
5151
self.validate_identity("SELECT SIGN(x)")
52+
self.validate_identity("SELECT COSH(1.5)")
5253
self.validate_identity("SELECT JAROWINKLER_SIMILARITY('hello', 'world')")
5354
self.validate_identity("SELECT TRANSLATE(column_name, 'abc', '123')")
5455
self.validate_identity("SELECT UNICODE(column_name)")

tests/fixtures/optimizer/annotate_functions.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,10 @@ VARCHAR;
16311631
COLLATE('hello', 'utf8');
16321632
VARCHAR;
16331633

1634+
# dialect: snowflake
1635+
COSH(1.5);
1636+
DOUBLE;
1637+
16341638
# dialect: snowflake
16351639
COMPRESS('Hello World', 'SNAPPY');
16361640
BINARY;

0 commit comments

Comments
 (0)