[Improvement](window funnel) restrict timestamp to datetime type in window funnel (#12123)

This commit is contained in:
Gabriel
2022-08-29 12:14:04 +08:00
committed by GitHub
parent 957bf98784
commit af09c1f4eb
2 changed files with 16 additions and 7 deletions

View File

@ -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<DateV2Value<DateTimeV2ValueType>, UInt64>>(
argument_types);
} else if (WhichDataType(argument_types[2]).is_date_v2()) {
return std::make_shared<
AggregateFunctionWindowFunnel<DateV2Value<DateV2ValueType>, 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<AggregateFunctionWindowFunnel<VecDateTimeValue, Int64>>(
argument_types);
} else {
LOG(FATAL) << "Only support Date/DateTime type as window argument!";
LOG(FATAL) << "Only support DateTime type as window argument!";
}
}

View File

@ -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);