Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo committed Apr 10, 2024
1 parent 89de5d3 commit 37d8bb1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
12 changes: 6 additions & 6 deletions velox/expression/SignatureBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ TypePtr SignatureBinder::tryResolveType(
typeParameters.push_back(TypeParameter(type));
}

try {
if (auto type = getType(typeName, typeParameters)) {
return type;
}
} catch (const std::exception&) {
// TODO Perhaps, modify getType to add suppress-errors flag.
TypePtr type;
auto status = getType(typeName, typeParameters, type);
if (type) {
return type;
}
if (!status.ok()) {
return nullptr;
}

Expand Down
24 changes: 19 additions & 5 deletions velox/type/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1140,18 +1140,32 @@ bool hasType(const std::string& name) {
return false;
}

TypePtr getType(
Status getType(
const std::string& name,
const std::vector<TypeParameter>& parameters) {
const std::vector<TypeParameter>& parameters,
TypePtr& type) {
if (singletonBuiltInTypes().count(name)) {
return singletonBuiltInTypes().at(name);
type = singletonBuiltInTypes().at(name);
VELOX_DCHECK_NOT_NULL(type);
return Status::OK();
}

if (parametricBuiltinTypes().count(name)) {
return parametricBuiltinTypes().at(name)(parameters);
try {
type = parametricBuiltinTypes().at(name)(parameters);
} catch (const std::exception& e) {
type = nullptr;
return Status::UserError(e.what());
}
VELOX_DCHECK_NOT_NULL(type);
return Status::OK();
}

return getCustomType(name);
type = getCustomType(name);
if (type == nullptr) {
return Status::Invalid("Type {} not found." + name);
}
return Status::OK();
}

} // namespace facebook::velox
8 changes: 6 additions & 2 deletions velox/type/parser/ParserUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ TypePtr typeFromString(
} else if (upper == "DOUBLE PRECISION") {
upper = "DOUBLE";
}
auto inferredType = getType(upper, {});
TypePtr inferredType;
const auto status = getType(upper, {}, inferredType);
if (failIfNotRegistered) {
VELOX_CHECK(
inferredType, "Failed to parse type [{}]. Type not registered.", type);
inferredType && status.ok(),
"Failed to parse type [{}] due to {}. Type not registered.",
type,
status.message());
}
return inferredType;
}
Expand Down

0 comments on commit 37d8bb1

Please sign in to comment.