From 8667bf1986085b070d2b3f0b42e092c2a6b06c0e Mon Sep 17 00:00:00 2001 From: rui-mo Date: Mon, 14 Aug 2023 07:23:32 +0000 Subject: [PATCH] Fix --- velox/expression/SwitchExpr.cpp | 7 ++++++- velox/functions/prestosql/aggregates/AverageAggregate.cpp | 2 +- velox/functions/prestosql/window/Rank.cpp | 4 ++-- velox/functions/sparksql/aggregates/Register.cpp | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/velox/expression/SwitchExpr.cpp b/velox/expression/SwitchExpr.cpp index af47879fe7eb..381c58f4c1c3 100644 --- a/velox/expression/SwitchExpr.cpp +++ b/velox/expression/SwitchExpr.cpp @@ -253,12 +253,17 @@ TypePtr SwitchExpr::resolveType(const std::vector& argTypes) { if (hasElse) { auto& elseClauseType = argTypes.back(); - VELOX_CHECK( + if (elseClauseType->isDecimal()) { + // Regard decimals as the same type regardless of precision and scale. + VELOX_CHECK(expressionType->isDecimal()); + } else { + VELOX_CHECK( *elseClauseType == *expressionType, "Else clause of a SWITCH statement must have the same type as 'then' clauses. " "Expected {}, but got {}.", expressionType->toString(), elseClauseType->toString()); + } } return expressionType; diff --git a/velox/functions/prestosql/aggregates/AverageAggregate.cpp b/velox/functions/prestosql/aggregates/AverageAggregate.cpp index 36f3123ffaae..32f81dc0d681 100644 --- a/velox/functions/prestosql/aggregates/AverageAggregate.cpp +++ b/velox/functions/prestosql/aggregates/AverageAggregate.cpp @@ -143,7 +143,7 @@ exec::AggregateRegistrationResult registerAverage(const std::string& name) { } // namespace void registerAverageAggregate(const std::string& prefix) { - registerAverage(prefix + kAvg); + // registerAverage(prefix + kAvg); } } // namespace facebook::velox::aggregate::prestosql diff --git a/velox/functions/prestosql/window/Rank.cpp b/velox/functions/prestosql/window/Rank.cpp index 49cfd6900396..5f21c37cac26 100644 --- a/velox/functions/prestosql/window/Rank.cpp +++ b/velox/functions/prestosql/window/Rank.cpp @@ -113,10 +113,10 @@ void registerRankInternal( } void registerRank(const std::string& name) { - registerRankInternal(name, "bigint"); + registerRankInternal(name, "integer"); } void registerDenseRank(const std::string& name) { - registerRankInternal(name, "bigint"); + registerRankInternal(name, "integer"); } void registerPercentRank(const std::string& name) { registerRankInternal(name, "double"); diff --git a/velox/functions/sparksql/aggregates/Register.cpp b/velox/functions/sparksql/aggregates/Register.cpp index a1af6e99ba51..111ecd0f712a 100644 --- a/velox/functions/sparksql/aggregates/Register.cpp +++ b/velox/functions/sparksql/aggregates/Register.cpp @@ -32,6 +32,6 @@ void registerAggregateFunctions(const std::string& prefix) { registerBitwiseXorAggregate(prefix); registerBloomFilterAggAggregate(prefix + "bloom_filter_agg"); registerAverage(prefix + "avg"); - registerDecimalSumAggregate(prefix + "sum"); + registerDecimalSumAggregate(prefix + "decimal_sum"); } } // namespace facebook::velox::functions::aggregate::sparksql