Skip to content

Commit cfa4fef

Browse files
0xPoeti-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#53130
Signed-off-by: ti-chi-bot <[email protected]>
1 parent 335e834 commit cfa4fef

File tree

3 files changed

+24996
-1
lines changed

3 files changed

+24996
-1
lines changed

executor/window_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,12 @@ func TestIssue29947(t *testing.T) {
498498
result.Check(testkit.Rows("2", "3"))
499499
tk.MustExec("commit")
500500
}
501+
502+
func TestVarSampAsAWindowFunction(t *testing.T) {
503+
store := testkit.CreateMockStore(t)
504+
tk := testkit.NewTestKit(t, store)
505+
tk.MustExec("use test")
506+
tk.MustExec("create table t1 (c1 int)")
507+
tk.MustExec("select var_samp(c1) from t1")
508+
tk.MustExec("select c1, var_samp(c1) over (partition by c1) from t1")
509+
}

parser/parser.y

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7868,7 +7868,11 @@ SumExpr:
78687868
}
78697869
| builtinVarSamp '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
78707870
{
7871-
$$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
7871+
if $6 != nil {
7872+
$$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
7873+
} else {
7874+
$$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
7875+
}
78727876
}
78737877
| "JSON_ARRAYAGG" '(' Expression ')' OptWindowingClause
78747878
{

0 commit comments

Comments
 (0)