eldenmoon commented on code in PR #65561: URL: https://github.com/apache/doris/pull/65561#discussion_r3662362707
########## be/src/core/data_type/data_type_variant_v2.cpp: ########## @@ -0,0 +1,101 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "core/data_type/data_type_variant_v2.h" + +#include <fmt/format.h> +#include <gen_cpp/data.pb.h> + +#include <sstream> + +#include "common/exception.h" +#include "core/column/variant_v2/column_variant_v2.h" +#include "core/data_type_serde/data_type_variant_v2_serde.h" +#include "core/field.h" +#include "core/typeid_cast.h" + +namespace doris { + +DataTypeVariantV2::DataTypeVariantV2(int32_t max_subcolumns_count) + : DataTypeVariantV2(max_subcolumns_count, false) {} + +DataTypeVariantV2::DataTypeVariantV2(int32_t max_subcolumns_count, bool enable_doc_mode) + : _max_subcolumns_count(max_subcolumns_count), _enable_doc_mode(enable_doc_mode) { Review Comment: 暂时先留着, 后面去掉V1再删 ########## fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java: ########## @@ -302,4 +333,62 @@ public int getVariantDocShardCount() { public boolean getEnableNestedGroup() { return enableNestedGroup; } + + public boolean isComputeV2() { + return computeV2; + } + + /** Whether the type or any nested complex type contains Variant. */ + public static boolean containsVariant(DataType dataType) { + if (dataType instanceof VariantType) { + return true; + } else if (dataType instanceof ArrayType) { + return containsVariant(((ArrayType) dataType).getItemType()); + } else if (dataType instanceof MapType) { + MapType mapType = (MapType) dataType; + return containsVariant(mapType.getKeyType()) || containsVariant(mapType.getValueType()); + } else if (dataType instanceof StructType) { + return ((StructType) dataType).getFields().stream() + .anyMatch(field -> containsVariant(field.getDataType())); + } + return false; + } + + /** Selects the compute-only Variant representation in a possibly nested type. */ + public static DataType toComputeV2(DataType dataType) { + if (dataType instanceof VariantType) { + return ((VariantType) dataType).withComputeV2(true); + } else if (dataType instanceof ArrayType) { + return ArrayType.of(toComputeV2(((ArrayType) dataType).getItemType())); + } else if (dataType instanceof MapType) { + MapType mapType = (MapType) dataType; + return MapType.of(toComputeV2(mapType.getKeyType()), toComputeV2(mapType.getValueType())); + } else if (dataType instanceof StructType) { Review Comment: v2支持计算的 `cast struct<variant>, array<variant>` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
