From b3f29092033245f3b8d71c6654f660dfc8a14b34 Mon Sep 17 00:00:00 2001 From: PHILO-HE Date: Wed, 10 Apr 2024 08:49:00 +0800 Subject: [PATCH] Initial commit --- velox/functions/sparksql/Register.cpp | 22 +++++++++++++++++++ .../functions/sparksql/RegisterArithmetic.cpp | 12 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/velox/functions/sparksql/Register.cpp b/velox/functions/sparksql/Register.cpp index 72a8ca5275684..88fc9c3829b18 100644 --- a/velox/functions/sparksql/Register.cpp +++ b/velox/functions/sparksql/Register.cpp @@ -23,9 +23,11 @@ #include "velox/functions/lib/RegistrationHelpers.h" #include "velox/functions/lib/Repeat.h" #include "velox/functions/prestosql/ArrayFunctions.h" +#include "velox/functions/prestosql/BinaryFunctions.h" #include "velox/functions/prestosql/DateTimeFunctions.h" #include "velox/functions/prestosql/JsonFunctions.h" #include "velox/functions/prestosql/StringFunctions.h" +#include "velox/functions/prestosql/URLFunctions.h" #include "velox/functions/sparksql/ArrayMinMaxFunction.h" #include "velox/functions/sparksql/ArraySort.h" #include "velox/functions/sparksql/Bitwise.h" @@ -94,6 +96,13 @@ static void workAroundRegistrationMacro(const std::string& prefix) { VELOX_REGISTER_VECTOR_FUNCTION(udf_array_contains, prefix + "array_contains"); VELOX_REGISTER_VECTOR_FUNCTION( udf_array_intersect, prefix + "array_intersect"); + VELOX_REGISTER_VECTOR_FUNCTION(udf_array_distinct, prefix + "array_distinct"); + VELOX_REGISTER_VECTOR_FUNCTION(udf_array_except, prefix + "array_except"); + VELOX_REGISTER_VECTOR_FUNCTION(udf_array_position, prefix + "array_position"); + VELOX_REGISTER_VECTOR_FUNCTION(udf_map_entries, prefix + "map_entries"); + VELOX_REGISTER_VECTOR_FUNCTION(udf_map_keys, prefix + "map_keys"); + VELOX_REGISTER_VECTOR_FUNCTION(udf_map_values, prefix + "map_values"); + // This is the semantics of spark.sql.ansi.enabled = false. registerElementAtFunction(prefix + "element_at", true); @@ -105,6 +114,7 @@ static void workAroundRegistrationMacro(const std::string& prefix) { VELOX_REGISTER_VECTOR_FUNCTION(udf_concat, prefix + "concat"); VELOX_REGISTER_VECTOR_FUNCTION(udf_lower, prefix + "lower"); VELOX_REGISTER_VECTOR_FUNCTION(udf_upper, prefix + "upper"); + VELOX_REGISTER_VECTOR_FUNCTION(udf_reverse, prefix + "reverse"); // Logical. VELOX_REGISTER_VECTOR_FUNCTION(udf_not, prefix + "not"); registerIsNullFunction(prefix + "isnull"); @@ -222,11 +232,18 @@ void registerFunctions(const std::string& prefix) { {prefix + "sha1"}); registerFunction( {prefix + "sha2"}); + registerFunction({prefix + "crc32"}); exec::registerStatefulVectorFunction( prefix + "regexp_extract", re2ExtractSignatures(), makeRegexExtract); + exec::registerStatefulVectorFunction( + prefix + "regexp_extract_all", + re2ExtractAllSignatures(), + makeRe2ExtractAll); exec::registerStatefulVectorFunction( prefix + "rlike", re2SearchSignatures(), makeRLike); + exec::registerStatefulVectorFunction( + prefix + "like", likeSignatures(), makeLike); VELOX_REGISTER_VECTOR_FUNCTION(udf_regexp_split, prefix + "split"); exec::registerStatefulVectorFunction( @@ -300,6 +317,11 @@ void registerFunctions(const std::string& prefix) { registerFunction( {prefix + "find_in_set"}); + registerFunction( + {prefix + "url_encode"}); + registerFunction( + {prefix + "url_decode"}); + // Register array sort functions. exec::registerStatefulVectorFunction( prefix + "array_sort", arraySortSignatures(), makeArraySort); diff --git a/velox/functions/sparksql/RegisterArithmetic.cpp b/velox/functions/sparksql/RegisterArithmetic.cpp index 50d516823cc29..3409c0d4c0880 100644 --- a/velox/functions/sparksql/RegisterArithmetic.cpp +++ b/velox/functions/sparksql/RegisterArithmetic.cpp @@ -40,15 +40,27 @@ void registerArithmeticFunctions(const std::string& prefix) { registerUnaryNumeric({prefix + "unaryminus"}); // Math functions. registerUnaryNumeric({prefix + "abs"}); + registerFunction< + DecimalAbsFunction, + LongDecimal, + LongDecimal>({prefix + "abs"}); + registerFunction< + DecimalAbsFunction, + ShortDecimal, + ShortDecimal>({prefix + "abs"}); registerFunction({prefix + "acos"}); + registerFunction({prefix + "asin"}); registerFunction({prefix + "acosh"}); registerFunction({prefix + "asinh"}); + registerFunction({prefix + "atan"}); registerFunction({prefix + "atanh"}); registerFunction({prefix + "sec"}); registerFunction({prefix + "csc"}); registerFunction({prefix + "sinh"}); + registerFunction({prefix + "cos"}); registerFunction({prefix + "cosh"}); registerFunction({prefix + "cot"}); + registerFunction({prefix + "degrees"}); registerFunction({prefix + "atan2"}); registerFunction({prefix + "log1p"}); registerFunction({prefix + "bin"});