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


class ApproxTopKAccumulate(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 @@ -251,6 +251,7 @@ def _annotate_within_group(self: TypeAnnotator, expression: exp.WithinGroup) ->
exp.ObjectAgg,
exp.ParseIp,
exp.ParseUrl,
exp.ApproxTopKAccumulate,
}
},
**{
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 @@ -42,6 +42,7 @@ def test_snowflake(self):
expr.selects[0].assert_is(exp.AggFunc)
self.assertEqual(expr.sql(dialect="snowflake"), "SELECT APPROX_TOP_K(C4, 3, 5) FROM t")

self.validate_identity("SELECT APPROX_TOP_K_ACCUMULATE(col, 10)")
self.validate_identity("SELECT EQUAL_NULL(1, 2)")
self.validate_identity("SELECT EXP(1)")
self.validate_identity("SELECT FACTORIAL(5)")
Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_spark.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ def test_spark(self):
"REFRESH TABLE t",
)

self.validate_identity("SELECT APPROX_TOP_K_ACCUMULATE(col, 10)")
self.validate_identity("SELECT BITMAP_BIT_POSITION(10)")
self.validate_identity("SELECT BITMAP_CONSTRUCT_AGG(value)")
self.validate_identity("ALTER TABLE foo ADD PARTITION(event = 'click')")
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 @@ -3456,6 +3456,10 @@ DOUBLE;
APPROX_PERCENTILE(tbl.int_col, 0.9) OVER (PARTITION BY 1);
DOUBLE;

# dialect: snowflake
APPROX_TOP_K_ACCUMULATE(tbl.str_col, 10);
OBJECT;

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