github-actions[bot] commented on code in PR #66321:
URL: https://github.com/apache/doris/pull/66321#discussion_r3744289131
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Array.java:
##########
@@ -66,12 +67,14 @@ private Array(ScalarFunctionParams functionParams) {
@Override
public void checkLegalityBeforeTypeCoercion() {
- if (children.isEmpty()) {
+ if (arity() == 0) {
return;
}
- DataType firstChildType = getArgument(0).getDataType();
- if (firstChildType.isJsonType() || firstChildType.isVariantType()) {
- throw new AnalysisException("array does not support jsonb/variant
type");
+ for (Expression argument : getArguments()) {
+ DataType childType = argument.getDataType();
+ if (childType.isJsonType() ||
VariantType.isLegacyVariant(childType)) {
Review Comment:
[P1] Preserve Variant elements across container unification
This now admits compute-V2 values into arrays and map values, but the
common-element paths still prefer the scalar family. Inside one constructor,
`array(parse_to_variant('{"a":1}'), 'tail')` becomes `ARRAY<STRING>`. The same
loss happens after individually valid homogeneous arrays are combined:
`array_concat(array(parse_to_variant('{"a":1}')), array('tail'))` resolves its
indexed-Any element to `STRING`. A Paimon `ARRAY<VARIANT>` sink then re-encodes
the object as a Variant string; `CreateMap` values and the other indexed-Any
array combinators share these paths.
Please keep compute-V2 as the common element/value type whenever every other
input is a supported V2 cast source, while retaining V1 rejection, and add
exact-kind regressions for mixed constructors, map values, and
homogeneous-array combiners.
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/PaimonVariantWriteAnalyzer.java:
##########
@@ -0,0 +1,155 @@
+// 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.datasource.paimon;
+
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Type;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.types.ArrayType;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.MapType;
+import org.apache.doris.nereids.types.StructField;
+import org.apache.doris.nereids.types.StructType;
+import org.apache.doris.nereids.types.VariantType;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/** Analysis checks for the V2-only Paimon Variant write protocol. */
+public final class PaimonVariantWriteAnalyzer {
+ private PaimonVariantWriteAnalyzer() {
+ }
+
+ /**
+ * Rejects a disabled V2 protocol and unsupported Variant V2 conversions
before sink coercion.
+ */
+ public static void validate(
+ PaimonWriteTarget writeTarget,
+ List<Column> writeColumns,
+ Map<String, NamedExpression> columnToOutput,
+ boolean enableVariantV2) throws AnalysisException {
+ for (Column column : writeColumns) {
+ Type targetCatalogType =
writeTarget.getColumnTypes().get(column.getName());
+ if (targetCatalogType == null) {
+ continue;
+ }
+ DataType targetType = DataType.fromCatalogType(targetCatalogType);
+ if (!VariantType.containsVariant(targetType)) {
+ continue;
+ }
+ if (!enableVariantV2) {
+ throw new AnalysisException(
+ "Paimon VARIANT write only supports Variant V2; "
+ + "set enable_variant_v2=true");
+ }
+ NamedExpression output = columnToOutput.get(column.getName());
+ if (output != null) {
+ validateVariantConversion(output.getDataType(), targetType,
column.getName());
Review Comment:
[P1] Reject pre-sink coercions that erase Variant V2
This validation sees only the already-coerced output. A mixed `UNION
ALL`/`CASE`/`IF`/`COALESCE` can first resolve `parse_to_variant('{"a":1}')`
with `'tail'` to `STRING`, so this accepts `STRING` and BindSink stores the
object as a Variant string. There is also a homogeneous path: one-argument
`LEAD`/`LAG` has no Variant overload, chooses a trivial scalar signature, and
inserts a V2-to-scalar cast; the BE scalar cast turns an object/array root into
`NULL` before this check.
Please preserve V2 through common-result and window signatures, or reject
the expression before a lossy cast is inserted, while retaining V1 rejection.
Add exact-kind/null regressions for ordinary/constant UNION,
conditional/coalesce results, and `LEAD`/`LAG` of object/array V2 values.
--
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]