From b9f513339b2130daae3b670ec932ccb490213e3c Mon Sep 17 00:00:00 2001 From: lihangyu <15605149486@163.com> Date: Thu, 5 Sep 2024 21:26:17 +0800 Subject: [PATCH] [enhance](variant) throw exception when field type is not supported in cast elimation (#40388) --- be/src/olap/tablet_reader.cpp | 5 +++++ regression-test/suites/variant_p0/load.groovy | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/be/src/olap/tablet_reader.cpp b/be/src/olap/tablet_reader.cpp index 6b5d12118f7616..2af54242c08a6c 100644 --- a/be/src/olap/tablet_reader.cpp +++ b/be/src/olap/tablet_reader.cpp @@ -30,6 +30,7 @@ #include "common/compiler_util.h" // IWYU pragma: keep #include "common/config.h" +#include "common/exception.h" #include "common/logging.h" #include "common/status.h" #include "exprs/bitmapfilter_predicate.h" @@ -273,6 +274,10 @@ TabletColumn TabletReader::materialize_column(const TabletColumn& orig) { TabletColumn column_with_cast_type = orig; auto cast_type = _reader_context.target_cast_type_for_variants.at(orig.name()); FieldType filed_type = TabletColumn::get_field_type_by_type(cast_type.type); + if (filed_type == FieldType::OLAP_FIELD_TYPE_UNKNOWN) { + throw doris::Exception(ErrorCode::INTERNAL_ERROR, "Invalid type for variant column: {}", + cast_type.type); + } column_with_cast_type.set_type(filed_type); return column_with_cast_type; } diff --git a/regression-test/suites/variant_p0/load.groovy b/regression-test/suites/variant_p0/load.groovy index 4c46a615dcab96..161b8ce0ca5645 100644 --- a/regression-test/suites/variant_p0/load.groovy +++ b/regression-test/suites/variant_p0/load.groovy @@ -426,6 +426,11 @@ suite("regression_test_variant", "p0"){ exception("errCode = 2, detailMessage = Variant type should not be used in key") } + test { + sql """select * from ghdata where cast(v['actor']['url'] as ipv4) = '127.0.0.1'""" + exception("Invalid type for variant column: 36") + } + } finally { // reset flags }