From 340ec9ce9a914cf18e14b45b3a86b8dd1671559e Mon Sep 17 00:00:00 2001 From: David Sisson Date: Mon, 14 Aug 2023 18:16:55 -0700 Subject: [PATCH] Fix an issues processing varchar types. --- src/substrait/textplan/parser/SubstraitPlanTypeVisitor.cpp | 5 +++++ src/substrait/type/Type.cpp | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/substrait/textplan/parser/SubstraitPlanTypeVisitor.cpp b/src/substrait/textplan/parser/SubstraitPlanTypeVisitor.cpp index a26c964a..3d47206d 100644 --- a/src/substrait/textplan/parser/SubstraitPlanTypeVisitor.cpp +++ b/src/substrait/textplan/parser/SubstraitPlanTypeVisitor.cpp @@ -114,6 +114,11 @@ ::substrait::proto::Type SubstraitPlanTypeVisitor::typeToProto( break; } try { + if (!varChar->length()->isInteger()) { + errorListener_->addError( + ctx->getStart(), "Missing varchar length."); + break; + } int32_t length = std::stoi(varChar->length()->value()); type.mutable_varchar()->set_length(length); } catch (...) { diff --git a/src/substrait/type/Type.cpp b/src/substrait/type/Type.cpp index 1fa21115..5a0e3cff 100644 --- a/src/substrait/type/Type.cpp +++ b/src/substrait/type/Type.cpp @@ -197,7 +197,12 @@ ParameterizedTypePtr ParameterizedType::decode( const auto& leftAngleBracketPos = matchingType.find('<'); if (leftAngleBracketPos == std::string::npos) { - bool nullable = matchingType.back() == '?'; + bool nullable; + if (matchingType.empty()) { + nullable = false; + } else { + nullable = matchingType.back() == '?'; + } // deal with type and with a question mask like "i32?". const auto& baseType = nullable ? matchingType = matchingType.substr(0, questionMaskPos)