Skip to content

Commit

Permalink
[Bug](materialized-view) fix some bugs on create mv with percentile_a…
Browse files Browse the repository at this point in the history
…pprox (apache#26528) (apache#26764)

1. percentile_approx have wrong symbol
2. fnCall.getParams() get obsolete childrens
  • Loading branch information
BiteTheDDDDt authored and gnehil committed Dec 4, 2023
1 parent 14d267f commit 40481a4
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,21 @@ template <bool is_nullable>
AggregateFunctionPtr create_aggregate_function_percentile_approx(const std::string& name,
const DataTypes& argument_types,
const bool result_is_nullable) {
const DataTypePtr& argument_type = remove_nullable(argument_types[0]);
WhichDataType which(argument_type);
if (which.idx != TypeIndex::Float64) {
return nullptr;
}
if (argument_types.size() == 1) {
return creator_without_type::create<AggregateFunctionPercentileApproxMerge<is_nullable>>(
remove_nullable(argument_types), result_is_nullable);
} else if (argument_types.size() == 2) {
}
if (argument_types.size() == 2) {
return creator_without_type::create<
AggregateFunctionPercentileApproxTwoParams<is_nullable>>(
remove_nullable(argument_types), result_is_nullable);
} else if (argument_types.size() == 3) {
}
if (argument_types.size() == 3) {
return creator_without_type::create<
AggregateFunctionPercentileApproxThreeParams<is_nullable>>(
remove_nullable(argument_types), result_is_nullable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ AggregateFunctionSimpleFactory& AggregateFunctionSimpleFactory::instance() {
register_aggregate_function_replace_reader_load(instance);
register_aggregate_function_window_lead_lag_first_last(instance);
register_aggregate_function_HLL_union_agg(instance);
register_aggregate_function_percentile_approx(instance);
});
return instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,10 @@ private MVColumnItem buildMVColumnItem(Analyzer analyzer, FunctionCallExpr funct
break;
default:
mvAggregateType = AggregateType.GENERIC_AGGREGATION;
if (functionCallExpr.getParams().isDistinct() || functionCallExpr.getParams().isStar()) {
throw new AnalysisException(
"The Materialized-View's generic aggregation not support star or distinct");
}
defineExpr = Function.convertToStateCombinator(functionCallExpr);
type = defineExpr.type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.doris.analysis.Expr;
import org.apache.doris.analysis.FunctionCallExpr;
import org.apache.doris.analysis.FunctionName;
import org.apache.doris.analysis.FunctionParams;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.UserException;
import org.apache.doris.common.io.IOUtils;
Expand Down Expand Up @@ -848,7 +849,7 @@ public static FunctionCallExpr convertToStateCombinator(FunctionCallExpr fnCall)
aggFunction.hasVarArgs(), aggFunction.isUserVisible());
fn.setNullableMode(NullableMode.ALWAYS_NOT_NULLABLE);
fn.setBinaryType(TFunctionBinaryType.AGG_STATE);
return new FunctionCallExpr(fn, fnCall.getParams());
return new FunctionCallExpr(fn, new FunctionParams(fnCall.getChildren()));
}

public static FunctionCallExpr convertToMergeCombinator(FunctionCallExpr fnCall) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1321,15 +1321,6 @@ private void initAggregateBuiltins() {
true, false, true, true));

//vec percentile and percentile_approx
addBuiltin(AggregateFunction.createBuiltin("percentile",
Lists.newArrayList(Type.BIGINT, Type.DOUBLE), Type.DOUBLE, Type.VARCHAR,
"",
"",
"",
"",
"",
false, true, false, true));

addBuiltin(AggregateFunction.createBuiltin("percentile_approx",
Lists.<Type>newArrayList(Type.DOUBLE, Type.DOUBLE), Type.DOUBLE, Type.VARCHAR,
"",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select_base --
2023-01-02 450.0 600.0

-- !select_star --
1 2023-01-02 300
2 2023-01-02 600
2 2023-01-02 600

-- !select_group_mv --
2023-01-02 600.0 600.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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.

import org.codehaus.groovy.runtime.IOGroovyMethods

suite ("test_user_activity") {

sql """ DROP TABLE IF EXISTS d_table; """

sql """
CREATE TABLE u_axx (
r_xx INT,
n_dx DATE,
n_duration INT
)
DISTRIBUTED BY HASH(r_xx)
PROPERTIES (
"replication_num" = "1"
);
"""

sql """INSERT INTO u_axx VALUES (1, "2023-01-02", 300);"""
sql """INSERT INTO u_axx VALUES (2, "2023-01-02", 600);"""

qt_select_base " select n_dx, percentile_approx(n_duration, 0.5) as p50, percentile_approx(n_duration, 0.90) as p90 FROM u_axx GROUP BY n_dx; "

createMV ("create materialized view session_distribution_2 as select n_dx, percentile_approx(n_duration, 0.5) as p50, percentile_approx(n_duration, 0.90) as p90 FROM u_axx GROUP BY n_dx;")

sql """INSERT INTO u_axx VALUES (2, "2023-01-02", 600);"""

qt_select_star "select * from u_axx order by 1;"

explain {
sql("select n_dx, percentile_approx(n_duration, 0.5) as p50, percentile_approx(n_duration, 0.90) as p90 FROM u_axx GROUP BY n_dx;")
contains "(session_distribution_2)"
}
qt_select_group_mv "select n_dx, percentile_approx(n_duration, 0.5) as p50, percentile_approx(n_duration, 0.90) as p90 FROM u_axx GROUP BY n_dx;"
}

0 comments on commit 40481a4

Please sign in to comment.