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 954206b commit ec75860
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,8 @@ public Lead visitLead(Lead lead, Void ctx) {
*/
@Override
public FirstOrLastValue visitFirstValue(FirstValue firstValue, Void ctx) {
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;
}
if (2 == firstValue.arity() && firstValue.child(1).equals(BooleanLiteral.TRUE)) {
return firstValue;
}
Optional<WindowFrame> windowFrame = windowExpression.getWindowFrame();
if (windowFrame.isPresent()) {
Expand All @@ -348,14 +343,6 @@ 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 last_value must be constant");
}
return lastValue;
}

/**
* required WindowFrame: (RANGE, UNBOUNDED PRECEDING, CURRENT ROW)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.doris.nereids.trees.expressions.functions.window;

import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable;
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
Expand Down Expand Up @@ -63,4 +64,11 @@ public FirstOrLastValue reverse() {
public List<FunctionSignature> getSignatures() {
return SIGNATURES;
}

@Override
public void checkLegalityBeforeTypeCoercion() {
if (2 == arity() && !child(1).isConstant()) {
throw new AnalysisException("The second parameter of " + getName() + " must be constant");
}
}
}

0 comments on commit ec75860

Please sign in to comment.