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 10, 2024
1 parent 89de5d3 commit 8a605a8
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 32 deletions.
8 changes: 0 additions & 8 deletions velox/expression/FunctionSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,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
8 changes: 0 additions & 8 deletions velox/expression/SignatureBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,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
9 changes: 0 additions & 9 deletions velox/expression/tests/utils/ArgumentTypeFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,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
7 changes: 0 additions & 7 deletions velox/type/fbhive/HiveTypeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ 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
7 changes: 7 additions & 0 deletions velox/type/parser/ParserUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,11 @@ 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 8a605a8

Please sign in to comment.