Skip to content

Commit

Permalink
Reuse isPositiveInteger function
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo committed Apr 11, 2024
1 parent cef85a1 commit 8138675
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 35 deletions.
4 changes: 2 additions & 2 deletions velox/expression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ add_library(
ReverseSignatureBinder.cpp)

target_link_libraries(
velox_expression_functions velox_common_base velox_type_calculation
velox_type_signature velox_signature_parser)
velox_expression_functions velox_type_parser velox_common_base
velox_type_calculation velox_type_signature velox_signature_parser)

add_library(
velox_expression
Expand Down
9 changes: 1 addition & 8 deletions velox/expression/FunctionSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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<std::string, SignatureVariable>& variables,
const TypeSignature& arg,
Expand Down
9 changes: 1 addition & 8 deletions velox/expression/SignatureBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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) {
Expand Down
10 changes: 1 addition & 9 deletions velox/expression/tests/utils/ArgumentTypeFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "velox/expression/ReverseSignatureBinder.h"
#include "velox/expression/SignatureBinder.h"
#include "velox/type/Type.h"
#include "velox/type/parser/ParserUtil.h"
#include "velox/vector/fuzzer/VectorFuzzer.h"

namespace facebook::velox::test {
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion velox/type/fbhive/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions velox/type/fbhive/HiveTypeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,12 @@
#include <utility>

#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<char> supported{'_', '$', '#'};
Expand Down
6 changes: 6 additions & 0 deletions velox/type/parser/ParserUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ std::pair<std::string, std::shared_ptr<const Type>> 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
3 changes: 3 additions & 0 deletions velox/type/parser/ParserUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ std::pair<std::string, TypePtr> inferTypeWithSpaces(
std::vector<std::string>& words,
bool cannotHaveFieldName = false);

/// Returns true only if 'str' contains digits.
bool isPositiveInteger(const std::string& str);

} // namespace facebook::velox

0 comments on commit 8138675

Please sign in to comment.