[feature](window-func) support percent_rank window function (#30926)
This commit is contained in:
@ -23,6 +23,7 @@ import org.apache.doris.nereids.trees.expressions.functions.window.Lag;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.LastValue;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.Lead;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.Ntile;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.PercentRank;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.Rank;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.RowNumber;
|
||||
|
||||
@ -43,6 +44,7 @@ public class BuiltinWindowFunctions implements FunctionHelper {
|
||||
window(LastValue.class, "last_value"),
|
||||
window(Lead.class, "lead"),
|
||||
window(Ntile.class, "ntile"),
|
||||
window(PercentRank.class, "percent_rank"),
|
||||
window(Rank.class, "rank"),
|
||||
window(RowNumber.class, "row_number")
|
||||
);
|
||||
|
||||
@ -1557,6 +1557,14 @@ public class FunctionSet<T> {
|
||||
null,
|
||||
"",
|
||||
""));
|
||||
// Percent Rank
|
||||
addBuiltin(AggregateFunction.createAnalyticBuiltin("percent_rank",
|
||||
Lists.<Type>newArrayList(), Type.DOUBLE, Type.VARCHAR,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
"",
|
||||
""));
|
||||
// Dense rank
|
||||
addBuiltin(AggregateFunction.createAnalyticBuiltin("dense_rank",
|
||||
Lists.<Type>newArrayList(), Type.BIGINT, Type.VARCHAR,
|
||||
@ -1584,6 +1592,14 @@ public class FunctionSet<T> {
|
||||
null,
|
||||
"",
|
||||
"", true));
|
||||
//vec Percent Rank
|
||||
addBuiltin(AggregateFunction.createAnalyticBuiltin("percent_rank",
|
||||
Lists.<Type>newArrayList(), Type.DOUBLE, Type.VARCHAR,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
"",
|
||||
"", true));
|
||||
//vec Dense rank
|
||||
addBuiltin(AggregateFunction.createAnalyticBuiltin("dense_rank",
|
||||
Lists.<Type>newArrayList(), Type.BIGINT, Type.VARCHAR,
|
||||
|
||||
@ -33,6 +33,7 @@ import org.apache.doris.nereids.trees.expressions.functions.window.Lag;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.LastValue;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.Lead;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.Ntile;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.PercentRank;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.Rank;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.RowNumber;
|
||||
import org.apache.doris.nereids.trees.expressions.literal.Literal;
|
||||
@ -361,6 +362,18 @@ public class WindowFunctionChecker extends DefaultExpressionVisitor<Expression,
|
||||
return denseRank;
|
||||
}
|
||||
|
||||
/**
|
||||
* required WindowFrame: (RANGE, UNBOUNDED PRECEDING, CURRENT ROW)
|
||||
*/
|
||||
@Override
|
||||
public PercentRank visitPercentRank(PercentRank percentRank, Void ctx) {
|
||||
WindowFrame requiredFrame = new WindowFrame(FrameUnitsType.RANGE,
|
||||
FrameBoundary.newPrecedingBoundary(), FrameBoundary.newCurrentRowBoundary());
|
||||
|
||||
checkAndCompleteWindowFrame(requiredFrame, percentRank.getName());
|
||||
return percentRank;
|
||||
}
|
||||
|
||||
/**
|
||||
* required WindowFrame: (ROWS, UNBOUNDED PRECEDING, CURRENT ROW)
|
||||
*/
|
||||
|
||||
@ -0,0 +1,61 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.doris.nereids.trees.expressions.functions.window;
|
||||
|
||||
import org.apache.doris.catalog.FunctionSignature;
|
||||
import org.apache.doris.nereids.trees.expressions.Expression;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable;
|
||||
import org.apache.doris.nereids.trees.expressions.shape.LeafExpression;
|
||||
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
|
||||
import org.apache.doris.nereids.types.DoubleType;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Window function: PercentRank()
|
||||
*/
|
||||
public class PercentRank extends WindowFunction implements AlwaysNotNullable, LeafExpression {
|
||||
|
||||
public PercentRank() {
|
||||
super("percent_rank");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FunctionSignature> getSignatures() {
|
||||
return ImmutableList.of(FunctionSignature.ret(DoubleType.INSTANCE).args());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunctionSignature searchSignature(List<FunctionSignature> signatures) {
|
||||
return signatures.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PercentRank withChildren(List<Expression> children) {
|
||||
Preconditions.checkArgument(children.size() == 0);
|
||||
return new PercentRank();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
|
||||
return visitor.visitPercentRank(this, context);
|
||||
}
|
||||
}
|
||||
@ -23,6 +23,7 @@ import org.apache.doris.nereids.trees.expressions.functions.window.Lag;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.LastValue;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.Lead;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.Ntile;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.PercentRank;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.Rank;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.RowNumber;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.window.WindowFunction;
|
||||
@ -56,6 +57,10 @@ public interface WindowFunctionVisitor<R, C> {
|
||||
return visitWindowFunction(ntile, context);
|
||||
}
|
||||
|
||||
default R visitPercentRank(PercentRank percentRank, C context) {
|
||||
return visitWindowFunction(percentRank, context);
|
||||
}
|
||||
|
||||
default R visitRank(Rank rank, C context) {
|
||||
return visitWindowFunction(rank, context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user