Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug](materialized-view) fix some bugs on create mv with percentile_approx #26528

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -100,7 +100,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 @@ -518,6 +518,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.FeMetaVersion;
import org.apache.doris.common.UserException;
Expand Down Expand Up @@ -853,7 +854,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 @@ -1318,15 +1318,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;"
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ suite ("testProjectionMV1") {
sql """insert into emps values("2020-01-01",1,"a",1,1,1);"""
sql """insert into emps values("2020-01-02",2,"b",2,2,2);"""

sql """set enable_nereids_planner=false"""
test {
sql "create materialized view emps_mv as select deptno, empid from emps t order by deptno;"
exception "errCode = 2,"
Expand All @@ -57,6 +56,7 @@ suite ("testProjectionMV1") {
}
qt_select_mv "select empid, deptno from emps order by empid;"

sql """set enable_nereids_planner=false""" // need fix it on nereids
explain {
sql("select empid, sum(deptno) from emps group by empid order by empid;")
contains "(emps_mv)"
Expand Down
Loading