diff --git a/velox/expression/SignatureBinder.cpp b/velox/expression/SignatureBinder.cpp index 4ea670d4d1951..1c8bd43a9d291 100644 --- a/velox/expression/SignatureBinder.cpp +++ b/velox/expression/SignatureBinder.cpp @@ -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; } diff --git a/velox/type/Type.cpp b/velox/type/Type.cpp index 1d2ba1cb3ccca..4d335669e2e8d 100644 --- a/velox/type/Type.cpp +++ b/velox/type/Type.cpp @@ -1140,18 +1140,32 @@ bool hasType(const std::string& name) { return false; } -TypePtr getType( +Status getType( const std::string& name, - const std::vector& parameters) { + const std::vector& 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 diff --git a/velox/type/parser/ParserUtil.cpp b/velox/type/parser/ParserUtil.cpp index b7fa36ec27b9b..e2a95e6bc24f0 100644 --- a/velox/type/parser/ParserUtil.cpp +++ b/velox/type/parser/ParserUtil.cpp @@ -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; }