[cherry-pick](branch-21) support lead/lag function input column as third params (#49381) (#50653)

### What problem does this PR solve?

cherry-pick from master (#49381)

### Release note

None

### Check List (For Author)

- Test <!-- At least one of them must be included. -->
    - [ ] Regression test
    - [ ] Unit Test
    - [ ] Manual test (add detailed scripts or steps below)
    - [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
        - [ ] Previous test can cover this change.
        - [ ] No code files have been changed.
        - [ ] Other reason <!-- Add your reason?  -->

- Behavior changed:
    - [ ] No.
    - [ ] Yes. <!-- Explain the behavior change -->

- Does this need documentation?
    - [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg:
https://github.com/apache/doris-website/pull/1214 -->

### Check List (For Reviewer who merge this PR)

- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR
should merge into -->
This commit is contained in:
zhangstar333
2025-05-07 23:08:56 +08:00
committed by GitHub
parent b9cfdcf46a
commit 9fe87a56bd
6 changed files with 85 additions and 45 deletions

View File

@ -99,7 +99,7 @@ public class Lag extends WindowFunction implements TernaryExpression, Explicitly
return;
}
if (children().size() >= 2) {
checkValidParams(getOffset(), true);
checkValidParams(getOffset());
if (getOffset() instanceof Literal) {
if (((Literal) getOffset()).getDouble() < 0) {
throw new AnalysisException(
@ -109,9 +109,6 @@ public class Lag extends WindowFunction implements TernaryExpression, Explicitly
throw new AnalysisException(
"The offset parameter of LAG must be a constant positive integer: " + this.toSql());
}
if (children().size() >= 3) {
checkValidParams(getDefaultValue(), false);
}
}
}

View File

@ -94,7 +94,7 @@ public class Lead extends WindowFunction implements TernaryExpression, Explicitl
return;
}
if (children().size() >= 2) {
checkValidParams(getOffset(), true);
checkValidParams(getOffset());
if (getOffset() instanceof Literal) {
if (((Literal) getOffset()).getDouble() < 0) {
throw new AnalysisException(
@ -104,9 +104,6 @@ public class Lead extends WindowFunction implements TernaryExpression, Explicitl
throw new AnalysisException(
"The offset parameter of LAG must be a constant positive integer: " + this.toSql());
}
if (children().size() >= 3) {
checkValidParams(getDefaultValue(), false);
}
}
}

View File

@ -59,14 +59,14 @@ public abstract class WindowFunction extends BoundFunction implements SupportWin
/**
* LAG/LEAD param must be const, and offset must be number
*/
protected void checkValidParams(Expression param, boolean isOffset) {
protected void checkValidParams(Expression param) {
DataType type = param.getDataType();
if (isOffset == true && !type.isNumericType()) {
if (!type.isNumericType()) {
throw new AnalysisException("The offset of LAG/LEAD must be a number: " + this.toSql());
}
if (!param.isConstant()) {
throw new AnalysisException(
"The parameter 2 or parameter 3 of LAG/LEAD must be a constant value: " + this.toSql());
"The parameter 2 of LAG/LEAD must be a constant value: " + this.toSql());
}
}
}