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
5 changes: 5 additions & 0 deletions sqlglot/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5732,6 +5732,11 @@ class ApproxTopKAccumulate(AggFunc):
arg_types = {"this": True, "expression": False}


# https://docs.snowflake.com/en/sql-reference/functions/approx_top_k_combine
class ApproxTopKCombine(AggFunc):
arg_types = {"this": True, "expression": False}


class ApproxTopSum(AggFunc):
arg_types = {"this": True, "expression": True, "count": True}

Expand Down
1 change: 1 addition & 0 deletions sqlglot/typing/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def _annotate_within_group(self: TypeAnnotator, expression: exp.WithinGroup) ->
exp.ParseIp,
exp.ParseUrl,
exp.ApproxTopKAccumulate,
exp.ApproxTopKCombine,
}
},
**{
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 @@ -52,6 +52,7 @@ def test_snowflake(self):
"SELECT APPROXIMATE_SIMILARITY(minhash_col)",
)
self.validate_identity("SELECT APPROX_TOP_K_ACCUMULATE(col, 10)")
self.validate_identity("SELECT APPROX_TOP_K_COMBINE(state, 2)")
self.validate_identity("SELECT EQUAL_NULL(1, 2)")
self.validate_identity("SELECT EXP(1)")
self.validate_identity("SELECT FACTORIAL(5)")
Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/optimizer/annotate_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3460,6 +3460,14 @@ DOUBLE;
APPROX_TOP_K_ACCUMULATE(tbl.str_col, 10);
OBJECT;

# dialect: snowflake
APPROX_TOP_K_COMBINE(tbl.state_col, 10);
OBJECT;

# dialect: snowflake
APPROX_TOP_K_COMBINE(tbl.state_col);
OBJECT;

# dialect: snowflake
APPROX_COUNT_DISTINCT(tbl.str_col);
BIGINT;
Expand Down