From af09c1f4eba1f79916a97b62f85bc9efff85fe30 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Mon, 29 Aug 2022 12:14:04 +0800 Subject: [PATCH] [Improvement](window funnel) restrict timestamp to datetime type in window funnel (#12123) --- .../aggregate_function_window_funnel.cpp | 11 ++++------- .../org/apache/doris/analysis/FunctionCallExpr.java | 12 ++++++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/be/src/vec/aggregate_functions/aggregate_function_window_funnel.cpp b/be/src/vec/aggregate_functions/aggregate_function_window_funnel.cpp index ea323f1a6b..2dfa86df7a 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_window_funnel.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_window_funnel.cpp @@ -18,6 +18,7 @@ #include "vec/aggregate_functions/aggregate_function_window_funnel.h" #include "vec/aggregate_functions/aggregate_function_simple_factory.h" +#include "vec/data_types/data_type_nullable.h" namespace doris::vectorized { @@ -29,19 +30,15 @@ AggregateFunctionPtr create_aggregate_function_window_funnel(const std::string& LOG(WARNING) << "window_funnel's argument less than 3."; return nullptr; } - if (WhichDataType(argument_types[2]).is_date_time_v2()) { + if (WhichDataType(remove_nullable(argument_types[2])).is_date_time_v2()) { return std::make_shared< AggregateFunctionWindowFunnel, UInt64>>( argument_types); - } else if (WhichDataType(argument_types[2]).is_date_v2()) { - return std::make_shared< - AggregateFunctionWindowFunnel, UInt32>>( - argument_types); - } else if (WhichDataType(argument_types[2]).is_date_or_datetime()) { + } else if (WhichDataType(remove_nullable(argument_types[2])).is_date_time()) { return std::make_shared>( argument_types); } else { - LOG(FATAL) << "Only support Date/DateTime type as window argument!"; + LOG(FATAL) << "Only support DateTime type as window argument!"; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java index 2b7c6c837e..0505873c0e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java @@ -946,6 +946,18 @@ public class FunctionCallExpr extends Expr { } fn = getBuiltinFunction(fnName.getFunction(), childTypes, Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF); + if (fn != null && fn.getArgs()[2].isDatetime() && childTypes[2].isDatetimeV2()) { + fn.setArgType(childTypes[2], 2); + } else if (fn != null && fn.getArgs()[2].isDatetime() && childTypes[2].isDateV2()) { + fn.setArgType(ScalarType.DATETIMEV2, 2); + } + if (fn != null && childTypes[2].isDate()) { + // cast date to datetime + uncheckedCastChild(ScalarType.DATETIME, 2); + } else if (fn != null && childTypes[2].isDateV2()) { + // cast date to datetime + uncheckedCastChild(ScalarType.DATETIMEV2, 2); + } } else if (fnName.getFunction().equalsIgnoreCase("if")) { Type[] childTypes = collectChildReturnTypes(); Type assignmentCompatibleType = ScalarType.getAssignmentCompatibleType(childTypes[1], childTypes[2], true);