xiaokang commented on code in PR #40573:
URL: https://github.com/apache/doris/pull/40573#discussion_r1774611693
##########
fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java:
##########
@@ -554,7 +583,7 @@ public boolean isJsonbType() {
}
public boolean isVariantType() {
- return isScalarType(PrimitiveType.VARIANT);
+ return isScalarType(PrimitiveType.VARIANT) || isComplexVariant();
Review Comment:
It's confusing to have isVariantType() and isComplexVariant().
##########
fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4:
##########
@@ -1658,6 +1658,7 @@ dataType
: complex=ARRAY LT dataType GT
#complexDataType
| complex=MAP LT dataType COMMA dataType GT
#complexDataType
| complex=STRUCT LT complexColTypeList GT
#complexDataType
Review Comment:
What's the effect of 'complex=' and why VARIANT not use it?
##########
fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4:
##########
@@ -1708,6 +1709,13 @@ complexColType
: identifier COLON dataType commentSpec?
;
+variantSubColTypeList
+ : variantSubColType (COMMA variantSubColType)*
+ ;
+variantSubColType
+ : qualifiedName COLON dataType commentSpec?
Review Comment:
blank is better than COLON.
##########
fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java:
##########
@@ -611,8 +611,9 @@ private boolean processModifyColumn(ModifyColumnClause
alterClause, OlapTable ol
if (!col.equals(modColumn)) {
typeChanged = true;
// TODO:the case where columnPos is not empty has not been
considered
- if (columnPos == null && col.getDataType() ==
PrimitiveType.VARCHAR
- && modColumn.getDataType() ==
PrimitiveType.VARCHAR) {
+ if (columnPos == null && (col.getDataType() ==
PrimitiveType.VARCHAR
+ && modColumn.getDataType() ==
PrimitiveType.VARCHAR)
+ || (col.getDataType().isVariantType() &&
modColumn.getDataType().isVariantType())) {
Review Comment:
Do you mean sc between VariantType and ComplexVariantType?
##########
fe/fe-common/src/main/java/org/apache/doris/catalog/ComplexVariantType.java:
##########
@@ -0,0 +1,123 @@
+// 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.
+
+package org.apache.doris.catalog;
+
+
+import org.apache.doris.thrift.TTypeDesc;
+import org.apache.doris.thrift.TTypeNode;
+import org.apache.doris.thrift.TTypeNodeType;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.gson.annotations.SerializedName;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class ComplexVariantType extends Type {
Review Comment:
It's confusing to have two types ComplexVariantType and VariantType for
variant.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java:
##########
@@ -303,6 +304,10 @@ public static DataType
convertPrimitiveFromStrings(List<String> types) {
dataType = IPv6Type.INSTANCE;
break;
case "variant":
+ if
(ConnectContext.get().getSessionVariable().useVariantAsComplexVariant) {
+ dataType = ComplexVariantType.TEST_INSTANCE;
Review Comment:
Why use TEST_INSTANCE?
##########
fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java:
##########
@@ -324,7 +324,7 @@ public void analyze() throws AnalysisException {
FunctionName fnName = new FunctionName(getFnName(type));
Function searchDesc = new Function(fnName,
Arrays.asList(getActualArgTypes(collectChildReturnTypes())),
Type.INVALID, false);
- if (type.isScalarType()) {
+ if (type.isScalarType() || type.isComplexVariant()) {
Review Comment:
Why treat ComplexVariant and ScalarType the same way?
##########
be/src/vec/core/field.h:
##########
@@ -339,6 +339,13 @@ class DecimalField {
* Used to represent a single value of one of several types in memory.
* Warning! Prefer to use chunks of columns instead of single values. See
Column.h
*/
+
+struct DetailedTypeInfo {
Review Comment:
Is there any existed class can be reused? Adding a new type class will add
more complexity.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java:
##########
@@ -303,6 +304,10 @@ public static DataType
convertPrimitiveFromStrings(List<String> types) {
dataType = IPv6Type.INSTANCE;
break;
case "variant":
+ if
(ConnectContext.get().getSessionVariable().useVariantAsComplexVariant) {
Review Comment:
It's not suitable to depend on ConnectContext in DataType.
##########
be/src/vec/functions/function_cast.h:
##########
@@ -882,6 +879,15 @@ struct ConvertImplFromJsonb {
res[i] = 0;
continue;
}
+ if (value->isString()) {
+ // convert by parse
+ const auto& data = static_cast<const
JsonbBlobVal*>(value)->getBlob();
+ size_t len = static_cast<const
JsonbBlobVal*>(value)->getBlobLen();
+ ReadBuffer rb((char*)(data), len);
+ bool parsed = try_parse_impl<ToDataType>(res[i], rb,
context);
Review Comment:
What's the relationship to variant?
##########
be/src/vec/columns/column_object.h:
##########
@@ -176,6 +184,15 @@ class ColumnObject final : public COWHelper<IColumn,
ColumnObject> {
void remove_nullable();
void add_new_column_part(DataTypePtr type);
+ // get the column type and index of a specified row
+ // Example row = 10
+ // row 0-7 is column with int type
+ // row 7-8 is column with bigint type
+ // row 9-15 is column with string type
+ // the row 10 is string type and index is 1
+ // Return false if row < num_of_defaults_in_prefix
+ bool get_part_column_type_and_index(const size_t row, ColumnPtr*
part_column,
Review Comment:
It's not used.
##########
be/src/vec/columns/subcolumn_tree.h:
##########
@@ -20,6 +20,7 @@
#pragma once
#include <memory>
+#include <unordered_map>
Review Comment:
useless change
##########
be/src/vec/common/schema_util.cpp:
##########
@@ -231,9 +235,16 @@ void get_column_by_type(const vectorized::DataTypePtr&
data_type, const std::str
column.set_length(data_type->get_size_of_value_in_memory());
return;
}
- // TODO handle more types like struct/date/datetime/decimal...
- LOG(FATAL) << "__builtin_unreachable";
- __builtin_unreachable();
+ if (WhichDataType(*data_type).is_decimal()) {
+ column.set_precision(data_type->get_precision());
+ column.set_frac(data_type->get_scale());
+ return;
+ }
+ if (WhichDataType(*data_type).is_date_time_v2()) {
+ column.set_precision(-1);
Review Comment:
set_precision will set `_is_decimal = true;`
##########
be/src/olap/tablet_schema.h:
##########
@@ -176,6 +176,12 @@ class TabletColumn {
const std::vector<TabletColumnPtr>& sparse_columns() const;
size_t num_sparse_columns() const { return _num_sparse_columns; }
+ void set_precision(int32_t precision) {
Review Comment:
It's better to merge the two functions to set_decimal_precision_frac.
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java:
##########
@@ -330,8 +330,9 @@ public void createChildrenColumn(Type type, Column column) {
v.setIsAllowNull(((MapType) type).getIsValueContainsNull());
column.addChildrenColumn(k);
column.addChildrenColumn(v);
- } else if (type.isStructType()) {
- ArrayList<StructField> fields = ((StructType) type).getFields();
+ } else if (type.isStructType() || type.isComplexVariant()) {
+ ArrayList<StructField> fields = type.isStructType()
+ ? ((StructType) type).getFields() : ((ComplexVariantType)
type).getPredefinedFields();
Review Comment:
It's tricky to reuse code here.
##########
be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp:
##########
@@ -655,14 +671,22 @@ Status
VerticalSegmentWriter::_append_block_with_variant_subcolumns(RowsInBlock&
CHECK(entry->data.is_finalized());
int current_column_id = column_id++;
TabletColumn tablet_column = generate_column_info(entry);
+ DataTypePtr storage_type =
+
vectorized::DataTypeFactory::instance().create_data_type(tablet_column);
+ DataTypePtr finalized_type = entry->data.get_least_common_type();
+ vectorized::ColumnPtr current_column =
+ entry->data.get_finalized_column_ptr()->get_ptr();
+ if (!storage_type->equals(*finalized_type)) {
+ RETURN_IF_ERROR(vectorized::schema_util::cast_column(
Review Comment:
I think you mean casting sub column to user specifified type after normal
type processing in variant.
If that's right, I think it's not efficient enough compared to pass type
user specifified type to type procession in variant and do the type parsing or
casting at first time.
--
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]