eldenmoon opened a new pull request, #70359:
URL: https://github.com/apache/doris/pull/70359
### What problem does this PR solve?
Problem Summary: with the default `enable_variant_v2 = false`, a CAST from a
NOT NULL Variant column to a non-Variant type fails when the legacy Variant
kernel produces NULL for a non-NULL Variant input:
```sql
CREATE TABLE t (k int NOT NULL, v variant NOT NULL) DUPLICATE KEY(k)
DISTRIBUTED BY HASH(k) BUCKETS 1 PROPERTIES("replication_num" = "1");
INSERT INTO t VALUES (1, 'null'), (2, 'null');
SELECT CAST(v AS STRING) FROM t;
```
```
ERROR 1105 (HY000): errCode = 2, detailMessage =
(127.0.0.1)[INTERNAL_ERROR]Expr
(CAST v(Variant(max subcolumns count = 2048, enable doc mode = false)) TO
String)
return column type mismatch: declared=String, actual=Nullable(String)
```
`Cast.castNullable` only declared a Variant -> non-Variant cast nullable
when the Variant type used
the V2 execution representation (`isExecutionV2()`). For the legacy
representation it returned
false, so the `CastExpr` was serialized with `is_nullable = false` and the
BE slot type became a
non-nullable String. The legacy kernel (`cast_from_variant_impl` in
`be/src/exprs/function/cast/cast_to_variant.h`) serializes a Variant through
the root/WRAP path
(or through the all-default-values path) and legitimately yields
`ColumnNullable` with NULLs for
a non-NULL Variant input, so `VExpr::execute_column` rejects the column
against the non-nullable
slot. The same mismatch also hits non-string targets, e.g. `CAST(v AS INT)`
on a Variant column
that contains Variant nulls.
Fix: declare Variant -> non-Variant casts nullable for both execution
representations, which is
what master already does (master no longer has the legacy representation).
The values produced by
the cast are unchanged; only the declared nullability of the output slot is
relaxed, and `VExpr`
already wraps a non-nullable column when the declaration is nullable.
### Release note
Fix `return column type mismatch: declared=String, actual=Nullable(String)`
when casting a NOT
NULL Variant column to STRING (and other non-Variant types) with the legacy
Variant representation.
### Check List (For Author)
- Test: Unit Test + Manual test
- `CastTest#testCastFromVariant` (updated): fails before the change,
passes after it
- Manual end-to-end: 4.2 FE+BE built from this branch, minimal table
above
- before: the `CAST(v AS STRING)` query fails with the error above
- after: the query returns `NULL` for the Variant-null rows, and
`CAST(v AS INT)` returns
`1`, `NULL`, `3` on `(1, 1), (2, 'null'), (3, 3)`
- Behavior changed: No (cast results are unchanged; only the declared
nullability of the output
slot changes)
- Does this need documentation: No
--
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]