Skip to content

Commit f13d441

Browse files
0xPoeterry1purcell
authored andcommitted
planner: make var_samp can be used as a window function (pingcap#53130)
close pingcap#52933
1 parent 969689c commit f13d441

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

pkg/executor/window_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,12 @@ func TestIssue45964And46050(t *testing.T) {
470470
testReturnColumnNullableAttribute(tk, "cume_dist()", false)
471471
testReturnColumnNullableAttribute(tk, "percent_rank()", false)
472472
}
473+
474+
func TestVarSampAsAWindowFunction(t *testing.T) {
475+
store := testkit.CreateMockStore(t)
476+
tk := testkit.NewTestKit(t, store)
477+
tk.MustExec("use test")
478+
tk.MustExec("create table t1 (c1 int)")
479+
tk.MustExec("select var_samp(c1) from t1")
480+
tk.MustExec("select c1, var_samp(c1) over (partition by c1) from t1")
481+
}

pkg/parser/parser.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/parser/parser.y

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8364,7 +8364,11 @@ SumExpr:
83648364
}
83658365
| builtinVarSamp '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
83668366
{
8367-
$$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
8367+
if $6 != nil {
8368+
$$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
8369+
} else {
8370+
$$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
8371+
}
83688372
}
83698373
| "JSON_ARRAYAGG" '(' Expression ')' OptWindowingClause
83708374
{

0 commit comments

Comments
 (0)