Skip to content

Commit bf07abd

Browse files
fivetran-ashashankargeorgesittas
authored andcommitted
feat(snowflake)!: annotation support for APPROX_TOP_K_COMBINE (#6378)
* feat(snowflake)!:annotation support for APPROX_TOP_K_COMBINE , return type is ARRAY * feat(snowflake)!:annotation support for APPROX_TOP_K_COMBINE ,return type modified to OBJECT * feat(snowflake)!:annotation support for APPROX_TOP_K_COMBINE ,return type modified to OBJECT
1 parent 2c462a8 commit bf07abd

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

sqlglot/expressions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5734,6 +5734,11 @@ class ApproxTopKAccumulate(AggFunc):
57345734
arg_types = {"this": True, "expression": False}
57355735

57365736

5737+
# https://docs.snowflake.com/en/sql-reference/functions/approx_top_k_combine
5738+
class ApproxTopKCombine(AggFunc):
5739+
arg_types = {"this": True, "expression": False}
5740+
5741+
57375742
class ApproxTopSum(AggFunc):
57385743
arg_types = {"this": True, "expression": True, "count": True}
57395744

sqlglot/typing/snowflake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ def _annotate_within_group(self: TypeAnnotator, expression: exp.WithinGroup) ->
244244
exp.ParseIp,
245245
exp.ParseUrl,
246246
exp.ApproxTopKAccumulate,
247+
exp.ApproxTopKCombine,
247248
}
248249
},
249250
**{

tests/dialects/test_snowflake.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def test_snowflake(self):
5252
"SELECT APPROXIMATE_SIMILARITY(minhash_col)",
5353
)
5454
self.validate_identity("SELECT APPROX_TOP_K_ACCUMULATE(col, 10)")
55+
self.validate_identity("SELECT APPROX_TOP_K_COMBINE(state, 2)")
56+
self.validate_identity("SELECT APPROX_TOP_K_COMBINE(state)")
5557
self.validate_identity("SELECT EQUAL_NULL(1, 2)")
5658
self.validate_identity("SELECT EXP(1)")
5759
self.validate_identity("SELECT FACTORIAL(5)")

tests/fixtures/optimizer/annotate_functions.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3460,6 +3460,14 @@ DOUBLE;
34603460
APPROX_TOP_K_ACCUMULATE(tbl.str_col, 10);
34613461
OBJECT;
34623462

3463+
# dialect: snowflake
3464+
APPROX_TOP_K_COMBINE(tbl.state_col, 10);
3465+
OBJECT;
3466+
3467+
# dialect: snowflake
3468+
APPROX_TOP_K_COMBINE(tbl.state_col);
3469+
OBJECT;
3470+
34633471
# dialect: snowflake
34643472
APPROX_COUNT_DISTINCT(tbl.str_col);
34653473
BIGINT;

0 commit comments

Comments
 (0)