Skip to content

Commit

Permalink
fix second parameter of first_value/second_value is not constant lead…
Browse files Browse the repository at this point in the history
…ing to be core
  • Loading branch information
feiniaofeiafei committed Dec 9, 2024
1 parent 3629ff6 commit eb4e1ba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,13 @@ public Lead visitLead(Lead lead, Void ctx) {
*/
@Override
public FirstOrLastValue visitFirstValue(FirstValue firstValue, Void ctx) {
if (firstValue.arity() == 2 && firstValue.child(1).equals(BooleanLiteral.TRUE)) {
return firstValue;
if (2 == firstValue.arity()) {
if (!firstValue.child(1).isConstant()) {
throw new AnalysisException("The second parameter of first_value must be constant");
}
if (firstValue.child(1).equals(BooleanLiteral.TRUE)) {
return firstValue;
}
}
Optional<WindowFrame> windowFrame = windowExpression.getWindowFrame();
if (windowFrame.isPresent()) {
Expand All @@ -343,6 +348,14 @@ public FirstOrLastValue visitFirstValue(FirstValue firstValue, Void ctx) {
return firstValue;
}

@Override
public FirstOrLastValue visitLastValue(LastValue lastValue, Void ctx) {
if (2 == lastValue.arity() && !lastValue.child(1).isConstant()) {
throw new AnalysisException("The second parameter of lasst_value must be constant");
}
return lastValue;
}

/**
* required WindowFrame: (RANGE, UNBOUNDED PRECEDING, CURRENT ROW)
*/
Expand Down
11 changes: 11 additions & 0 deletions regression-test/suites/nereids_syntax_p0/window_function.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,15 @@ suite("window_function") {
)t
)a where rn=1
"""

// test first value second param is not constant
test {
sql "select first_value(c1,c1) over() from window_test"
exception "The second parameter of first_value must be constant"
}

test {
sql "select last_value(c1,c1) over() from window_test"
exception "The second parameter of first_value must be constant"
}
}

0 comments on commit eb4e1ba

Please sign in to comment.