From 82f1ba4eecb6f502dc587d0315ee5711d9ea869b Mon Sep 17 00:00:00 2001 From: rui-mo Date: Wed, 10 Apr 2024 16:42:40 +0800 Subject: [PATCH] Reuse isPositiveInteger function --- velox/expression/CMakeLists.txt | 2 +- velox/expression/FunctionSignature.cpp | 9 +-------- velox/expression/SignatureBinder.cpp | 9 +-------- velox/expression/tests/utils/ArgumentTypeFuzzer.cpp | 10 +--------- velox/type/fbhive/CMakeLists.txt | 2 +- velox/type/fbhive/HiveTypeParser.cpp | 8 +------- velox/type/parser/ParserUtil.cpp | 7 +++++++ velox/type/parser/ParserUtil.h | 3 +++ 8 files changed, 16 insertions(+), 34 deletions(-) diff --git a/velox/expression/CMakeLists.txt b/velox/expression/CMakeLists.txt index 3166487983811..73de601d2d92c 100644 --- a/velox/expression/CMakeLists.txt +++ b/velox/expression/CMakeLists.txt @@ -21,7 +21,7 @@ add_library( ReverseSignatureBinder.cpp) target_link_libraries( - velox_expression_functions velox_common_base velox_type_calculation + velox_expression_functions velox_type_parser velox_common_base velox_type_calculation velox_type_signature velox_signature_parser) add_library( diff --git a/velox/expression/FunctionSignature.cpp b/velox/expression/FunctionSignature.cpp index f4cd3530cafd9..e0f605da74f1d 100644 --- a/velox/expression/FunctionSignature.cpp +++ b/velox/expression/FunctionSignature.cpp @@ -19,6 +19,7 @@ #include "velox/common/base/Exceptions.h" #include "velox/expression/FunctionSignature.h" #include "velox/type/Type.h" +#include "velox/type/parser/ParserUtil.h" namespace facebook::velox::exec { @@ -93,14 +94,6 @@ size_t findNextComma(const std::string& str, size_t start) { } namespace { -/// Returns true only if 'str' contains digits. -bool isPositiveInteger(const std::string& str) { - return !str.empty() && - std::find_if(str.begin(), str.end(), [](unsigned char c) { - return !std::isdigit(c); - }) == str.end(); -} - void validateBaseTypeAndCollectTypeParams( const std::unordered_map& variables, const TypeSignature& arg, diff --git a/velox/expression/SignatureBinder.cpp b/velox/expression/SignatureBinder.cpp index 4ea670d4d1951..9eaa01456eeab 100644 --- a/velox/expression/SignatureBinder.cpp +++ b/velox/expression/SignatureBinder.cpp @@ -19,6 +19,7 @@ #include "velox/expression/SignatureBinder.h" #include "velox/expression/type_calculation/TypeCalculation.h" #include "velox/type/Type.h" +#include "velox/type/parser/ParserUtil.h" namespace facebook::velox::exec { @@ -27,14 +28,6 @@ bool isAny(const TypeSignature& typeSignature) { return typeSignature.baseName() == "any"; } -/// Returns true only if 'str' contains digits. -bool isPositiveInteger(const std::string& str) { - return !str.empty() && - std::find_if(str.begin(), str.end(), [](unsigned char c) { - return !std::isdigit(c); - }) == str.end(); -} - std::string buildCalculation( const std::string& variable, const std::string& calculation) { diff --git a/velox/expression/tests/utils/ArgumentTypeFuzzer.cpp b/velox/expression/tests/utils/ArgumentTypeFuzzer.cpp index 1b32b5c946746..4cd5537c2ac45 100644 --- a/velox/expression/tests/utils/ArgumentTypeFuzzer.cpp +++ b/velox/expression/tests/utils/ArgumentTypeFuzzer.cpp @@ -23,6 +23,7 @@ #include "velox/expression/SignatureBinder.h" #include "velox/type/Type.h" #include "velox/vector/fuzzer/VectorFuzzer.h" +#include "velox/type/parser/ParserUtil.h" namespace facebook::velox::test { @@ -45,15 +46,6 @@ bool isDecimalBaseName(const std::string& typeName) { return normalized == "decimal"; } - -/// Returns true only if 'str' contains digits. -bool isPositiveInteger(const std::string& str) { - return !str.empty() && - std::find_if(str.begin(), str.end(), [](unsigned char c) { - return !std::isdigit(c); - }) == str.end(); -} - } // namespace void ArgumentTypeFuzzer::determineUnboundedIntegerVariables( diff --git a/velox/type/fbhive/CMakeLists.txt b/velox/type/fbhive/CMakeLists.txt index 8db23f2f667fe..ea5009808a889 100644 --- a/velox/type/fbhive/CMakeLists.txt +++ b/velox/type/fbhive/CMakeLists.txt @@ -14,7 +14,7 @@ add_library(velox_type_fbhive HiveTypeParser.cpp HiveTypeSerializer.cpp) -target_link_libraries(velox_type_fbhive velox_type) +target_link_libraries(velox_type_fbhive velox_type velox_type_parser) if(${VELOX_BUILD_TESTING}) add_subdirectory(tests) diff --git a/velox/type/fbhive/HiveTypeParser.cpp b/velox/type/fbhive/HiveTypeParser.cpp index 331aacc854ba7..3d9ea55e51253 100644 --- a/velox/type/fbhive/HiveTypeParser.cpp +++ b/velox/type/fbhive/HiveTypeParser.cpp @@ -22,18 +22,12 @@ #include #include "velox/common/base/Exceptions.h" +#include "velox/type/parser/ParserUtil.h" using facebook::velox::Type; using facebook::velox::TypeKind; namespace { -/// Returns true only if 'str' contains digits. -bool isPositiveInteger(const std::string& str) { - return !str.empty() && - std::find_if(str.begin(), str.end(), [](unsigned char c) { - return !std::isdigit(c); - }) == str.end(); -} bool isSupportedSpecialChar(char c) { static std::unordered_set supported{'_', '$', '#'}; diff --git a/velox/type/parser/ParserUtil.cpp b/velox/type/parser/ParserUtil.cpp index b7fa36ec27b9b..b47a1970bbbf2 100644 --- a/velox/type/parser/ParserUtil.cpp +++ b/velox/type/parser/ParserUtil.cpp @@ -52,4 +52,11 @@ std::pair> inferTypeWithSpaces( fieldName, typeFromString(allWords.substr(fieldName.size() + 1))); } + +bool isPositiveInteger(const std::string& str) { + return !str.empty() && + std::find_if(str.begin(), str.end(), [](unsigned char c) { + return !std::isdigit(c); + }) == str.end(); +} } // namespace facebook::velox diff --git a/velox/type/parser/ParserUtil.h b/velox/type/parser/ParserUtil.h index 7906b8bbf29d6..4d2d097bf4a31 100644 --- a/velox/type/parser/ParserUtil.h +++ b/velox/type/parser/ParserUtil.h @@ -36,4 +36,7 @@ std::pair inferTypeWithSpaces( std::vector& words, bool cannotHaveFieldName = false); +/// Returns true only if 'str' contains digits. +bool isPositiveInteger(const std::string& str); + } // namespace facebook::velox