From 54069cdf210d6e75378c4b69948cc160ec735761 Mon Sep 17 00:00:00 2001 From: rui-mo Date: Wed, 10 Apr 2024 14:26:03 +0800 Subject: [PATCH] refactor --- velox/expression/SignatureBinder.cpp | 12 ++++++------ velox/type/Type.cpp | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 11 deletions(-) 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..55b7cc875fc2e 100644 --- a/velox/type/Type.cpp +++ b/velox/type/Type.cpp @@ -1140,18 +1140,25 @@ 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); } 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()); + } } - return getCustomType(name); + type = getCustomType(name); + return Status::OK(); } } // namespace facebook::velox