morrySnow commented on code in PR #54293:
URL: https://github.com/apache/doris/pull/54293#discussion_r2251157702
##########
fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java:
##########
@@ -159,6 +159,9 @@ public CastExpr(Type targetType, Expr e, Void v) {
if (from.isComplexType() && type.isJsonbType()) {
nullableMode = Function.NullableMode.ALWAYS_NULLABLE;
}
+ if (from.isVariantType() || type.isVariantType()) {
+ nullableMode = Function.NullableMode.DEPEND_ON_ARGUMENT;
+ }
Review Comment:
should not change any legacy planner's code, if u rely on it, u should
refactor ur code
##########
fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4:
##########
@@ -1766,6 +1767,23 @@ complexColType
: identifier COLON dataType commentSpec?
;
+variantTypeDefinitions
+ : VARIANT LT variantSubColTypeList COMMA properties=propertyClause GT
#variantWithFieldsAndProps
+ | VARIANT LT variantSubColTypeList GT
#variantWithOnlyFields
+ | VARIANT LT properties=propertyClause GT
#variantWithOnlyProps
+ | VARIANT
#variant
Review Comment:
use same alias for them, then u could process them in one function in
LogicalPlanBuilder
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java:
##########
@@ -58,7 +129,10 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
- return super.equals(o);
+ VariantType other = (VariantType) o;
Review Comment:
update hashcode too
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantField.java:
##########
@@ -0,0 +1,122 @@
+// 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.nereids.types;
+
+import org.apache.doris.nereids.util.Utils;
+import org.apache.doris.thrift.TPatternType;
+
+import java.util.Objects;
+
+/**
+ * A field inside a StructType.
+ */
+public class VariantField {
+ private final String pattern;
+ private final DataType dataType;
+ private final String comment;
+ private final TPatternType patternType;
+
+ public VariantField(String pattern, DataType dataType, String comment) {
+ this(pattern, dataType, comment, TPatternType.MATCH_NAME_GLOB.name());
+ }
+
+ /**
+ * StructField Constructor
+ * @param pattern of this field
+ * @param dataType The data type of this field
+ * @param comment The comment of this field
+ * @param patternType The patternType of this field
+ */
+ public VariantField(String pattern, DataType dataType, String comment,
String patternType) {
+ this.pattern = Objects.requireNonNull(pattern, "pattern should not be
null");
+ this.dataType = Objects.requireNonNull(dataType, "dataType should not
be null");
+ this.comment = Objects.requireNonNull(comment, "comment should not be
null");
+ TPatternType type;
+ if (patternType.equalsIgnoreCase("MATCH_NAME")) {
Review Comment:
```suggestion
if (TPatternType.MATCH_NAME.name().equalsIgnoreCase(patternType)) {
```
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java:
##########
@@ -18,26 +18,68 @@
package org.apache.doris.nereids.types;
import org.apache.doris.catalog.Type;
-import org.apache.doris.nereids.annotation.Developing;
import org.apache.doris.nereids.types.coercion.PrimitiveType;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+
+import java.util.ArrayList;
+import java.util.List;
import java.util.Objects;
+import java.util.stream.Collectors;
/**
* Variant type in Nereids.
* Why Variant is not complex type? Since it's nested structure is not
pre-defined, then using
* primitive type will be easy to handle meta info in FE.
+ * Also, could predefine some fields of nested columns.
+ * Example: VARIANT <`a.b`:INT, a.c:DATETIMEV2>
+ *
*/
-@Developing
public class VariantType extends PrimitiveType {
- public static final VariantType INSTANCE = new VariantType();
+ public static final VariantType INSTANCE = new VariantType(0);
public static final int WIDTH = 24;
+ private int variantMaxSubcolumnsCount = 0;
+
+ private boolean enableTypedPathsToSparse = false;
+
+ private final List<VariantField> predefinedFields;
+
+ // No predefined fields
+ public VariantType(int variantMaxSubcolumnsCount) {
+ this.variantMaxSubcolumnsCount = variantMaxSubcolumnsCount;
+ predefinedFields = Lists.newArrayList();
+ }
+
+ /**
+ * Contains predefined fields like struct
+ */
+ public VariantType(List<VariantField> fields) {
+ this.predefinedFields =
ImmutableList.copyOf(Objects.requireNonNull(fields, "fields should not be
null"));
+ }
+
+ public VariantType(List<VariantField> fields, int
variantMaxSubcolumnsCount, boolean enableTypedPathsToSparse) {
+ this.predefinedFields =
ImmutableList.copyOf(Objects.requireNonNull(fields, "fields should not be
null"));
+ this.variantMaxSubcolumnsCount = variantMaxSubcolumnsCount;
+ this.enableTypedPathsToSparse = enableTypedPathsToSparse;
+ }
+
+ @Override
+ public DataType conversion() {
+ return new
VariantType(predefinedFields.stream().map(VariantField::conversion)
+ .collect(Collectors.toList()),
variantMaxSubcolumnsCount,
+
enableTypedPathsToSparse);
Review Comment:
the indent is not good
##########
fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4:
##########
@@ -339,6 +339,8 @@ MAP: 'MAP';
MATCH: 'MATCH';
MATCH_ALL: 'MATCH_ALL';
MATCH_ANY: 'MATCH_ANY';
+MATCH_NAME: 'MATCH_NAME';
+MATCH_NAME_GLOB: 'MATCH_NAME_GLOB';
Review Comment:
add to non-reserved keywords list
##########
fe/fe-core/src/main/cup/sql_parser.cup:
##########
@@ -3098,6 +3102,13 @@ key_value_map ::=
:}
;
+type_opt_properties ::=
Review Comment:
not change this file anymore, u should not rely on legacy planner's parser
anymore
##########
fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java:
##########
@@ -766,7 +765,7 @@ public static boolean isUnsupportedType(Type type) {
return type instanceof ArrayType
|| type instanceof StructType
|| type instanceof MapType
- || type instanceof VariantType
+ || type.isVariantType()
Review Comment:
why this need to be changed?
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java:
##########
@@ -18,26 +18,68 @@
package org.apache.doris.nereids.types;
import org.apache.doris.catalog.Type;
-import org.apache.doris.nereids.annotation.Developing;
import org.apache.doris.nereids.types.coercion.PrimitiveType;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+
+import java.util.ArrayList;
+import java.util.List;
import java.util.Objects;
+import java.util.stream.Collectors;
/**
* Variant type in Nereids.
* Why Variant is not complex type? Since it's nested structure is not
pre-defined, then using
* primitive type will be easy to handle meta info in FE.
+ * Also, could predefine some fields of nested columns.
+ * Example: VARIANT <`a.b`:INT, a.c:DATETIMEV2>
+ *
*/
-@Developing
public class VariantType extends PrimitiveType {
- public static final VariantType INSTANCE = new VariantType();
+ public static final VariantType INSTANCE = new VariantType(0);
public static final int WIDTH = 24;
+ private int variantMaxSubcolumnsCount = 0;
+
+ private boolean enableTypedPathsToSparse = false;
Review Comment:
should be final
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementAt.java:
##########
@@ -45,8 +45,8 @@ public class ElementAt extends ScalarFunction
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(new FollowToAnyDataType(0))
.args(ArrayType.of(new AnyDataType(0)),
BigIntType.INSTANCE),
- FunctionSignature.ret(new VariantType())
- .args(new VariantType(), VarcharType.SYSTEM_DEFAULT),
+ FunctionSignature.ret(new VariantType(0))
Review Comment:
add a zero count static member into varaintType to reduce produce new object
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java:
##########
@@ -441,6 +440,18 @@ public static DataType fromCatalogType(Type type) {
} else if (type.isArrayType()) {
org.apache.doris.catalog.ArrayType arrayType =
(org.apache.doris.catalog.ArrayType) type;
return ArrayType.of(fromCatalogType(arrayType.getItemType()),
arrayType.getContainsNull());
+ } else if (type.isVariantType()) {
+ if (type instanceof org.apache.doris.catalog.VariantType) {
Review Comment:
why need this instanceof?
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java:
##########
@@ -1041,6 +1052,20 @@ private static void validateScalarType(ScalarType
scalarType) {
}
break;
}
+ case VARIANT: {
+ ArrayList<org.apache.doris.catalog.VariantField>
predefinedFields =
+ ((org.apache.doris.catalog.VariantType)
scalarType).getPredefinedFields();
+ Set<String> fieldPatterns = new HashSet<>();
Review Comment:
variant's field's name is case sensitive?
##########
fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java:
##########
@@ -787,6 +787,11 @@ public static double getHotValueThreshold() {
public static final String DEFAULT_LLM_RESOURCE = "default_llm_resource";
+ public static final String GLOBAL_VARIANT_SUBCOLUMNS_COUNT =
"global_variant_max_subcolumns_count";
Review Comment:
why add global into name? if u want a golbal variable, u should add it into
GlobalVariable
--
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]