Skip to content

Commit 99bfebb

Browse files
0xPoeRidRisR
authored andcommitted
planner: make var_samp can be used as a window function (pingcap#53130)
close pingcap#52933
1 parent ac7bb55 commit 99bfebb

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
@@ -8418,7 +8418,11 @@ SumExpr:
84188418
}
84198419
| builtinVarSamp '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
84208420
{
8421-
$$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
8421+
if $6 != nil {
8422+
$$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
8423+
} else {
8424+
$$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
8425+
}
84228426
}
84238427
| "JSON_ARRAYAGG" '(' Expression ')' OptWindowingClause
84248428
{

0 commit comments

Comments
 (0)