Skip to content
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: 1 addition & 0 deletions sqlglot/dialects/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ class Snowflake(Dialect):
**Dialect.TYPE_TO_EXPRESSIONS,
exp.DataType.Type.DOUBLE: {
*Dialect.TYPE_TO_EXPRESSIONS[exp.DataType.Type.DOUBLE],
exp.Cosh,
exp.Cot,
exp.Exp,
exp.Sin,
Expand Down
4 changes: 4 additions & 0 deletions sqlglot/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5553,6 +5553,10 @@ class Tan(Func):
pass


class Cosh(Func):
pass


class CosineDistance(Func):
arg_types = {"this": True, "expression": True}

Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,7 @@ def test_ml_functions(self):
self.validate_identity(
"SELECT * FROM ML.PREDICT(MODEL mydataset.mymodel, (SELECT custom_label, column1, column2 FROM mydataset.mytable), STRUCT(0.55 AS threshold))"
)
self.validate_identity("SELECT COSH(1.5)")
self.validate_identity(
"SELECT * FROM ML.PREDICT(MODEL `my_project`.my_dataset.my_model, (SELECT * FROM input_data))"
)
Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class TestDatabricks(Validator):
dialect = "databricks"

def test_databricks(self):
self.validate_identity("SELECT COSH(1.5)")
null_type = exp.DataType.build("VOID", dialect="databricks")
self.assertEqual(null_type.sql(), "NULL")
self.assertEqual(null_type.sql("databricks"), "VOID")
Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TestDuckDB(Validator):
dialect = "duckdb"

def test_duckdb(self):
self.validate_identity("SELECT COSH(1.5)")
with self.assertRaises(ParseError):
parse_one("1 //", read="duckdb")

Expand Down
11 changes: 6 additions & 5 deletions tests/dialects/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ class TestPostgres(Validator):
dialect = "postgres"

def test_postgres(self):
self.validate_identity("SELECT EXP(1)")
self.validate_identity(
"select count() OVER(partition by a order by a range offset preceding exclude current row)",
"SELECT COUNT() OVER (PARTITION BY a ORDER BY a range BETWEEN offset preceding AND CURRENT ROW EXCLUDE CURRENT ROW)",
)
expr = self.parse_one("SELECT * FROM r CROSS JOIN LATERAL UNNEST(ARRAY[1]) AS s(location)")
unnest = expr.args["joins"][0].this.this
unnest.assert_is(exp.Unnest)
Expand All @@ -27,6 +22,8 @@ def test_postgres(self):
expected_sql = "ARRAY[\n x" + (",\n x" * 27) + "\n]"
self.validate_identity(sql, expected_sql, pretty=True)

self.validate_identity("SELECT COSH(1.5)")
self.validate_identity("SELECT EXP(1)")
self.validate_identity("SELECT ST_DISTANCE(gg1, gg2, FALSE) AS sphere_dist")
self.validate_identity("SHA384(x)")
self.validate_identity("1.x", "1. AS x")
Expand Down Expand Up @@ -162,6 +159,10 @@ def test_postgres(self):
"pg_catalog.PG_TABLE_IS_VISIBLE(c.oid) "
"ORDER BY 2, 3"
)
self.validate_identity(
"select count() OVER(partition by a order by a range offset preceding exclude current row)",
"SELECT COUNT() OVER (PARTITION BY a ORDER BY a range BETWEEN offset preceding AND CURRENT ROW EXCLUDE CURRENT ROW)",
)
self.validate_identity(
"x::JSON -> 'duration' ->> -1",
"JSON_EXTRACT_PATH_TEXT(CAST(x AS JSON) -> 'duration', -1)",
Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class TestRedshift(Validator):
dialect = "redshift"

def test_redshift(self):
self.validate_identity("SELECT COSH(1.5)")
self.validate_all(
"SELECT SPLIT_TO_ARRAY('12,345,6789')",
write={
Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def test_snowflake(self):
self.validate_identity("SELECT SOUNDEX_P123(column_name)")
self.validate_identity("SELECT ABS(x)")
self.validate_identity("SELECT SIGN(x)")
self.validate_identity("SELECT COSH(1.5)")
self.validate_identity("SELECT JAROWINKLER_SIMILARITY('hello', 'world')")
self.validate_identity("SELECT TRANSLATE(column_name, 'abc', '123')")
self.validate_identity("SELECT UNICODE(column_name)")
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/optimizer/annotate_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,10 @@ VARCHAR;
COLLATE('hello', 'utf8');
VARCHAR;

# dialect: snowflake
COSH(1.5);
DOUBLE;

# dialect: snowflake
COMPRESS('Hello World', 'SNAPPY');
BINARY;
Expand Down