eldenmoon opened a new pull request, #70362: URL: https://github.com/apache/doris/pull/70362
### What problem does this PR solve? Related PR: #70359 Problem Summary: heavy schema change constructs a legacy `CastExpr` directly, without the nullable metadata assigned by Nereids `ExpressionTranslator`. Its separate `isNullable` heuristic omits conversions that can return NULL, including DATETIMEV2 scale changes on NOT NULL columns. A DATETIMEV2(3) to DATETIMEV2(6) rewrite can consequently declare a non-nullable result while the existing BE cast returns a nullable column, causing the alter job to fail. Reuse `Cast.castNullable` in the legacy `CastExpr.isNullable` fallback. This keeps direct construction and Nereids translation on the same source of truth, and also covers the direct casts in both runtime-filter translators without adding caller-specific special cases. Explicit nullable metadata from Nereids remains authoritative during serialization; TRY_CAST keeps its own nullable override. ### Validation - Baseline: branch-4.2 `66122209cac78805a96a42f44d2a4a20b428f038`. - Fixed product source: `1d9babbe12c`. - `build.sh --fe`: passed, including Checkstyle. - ASAN BE built with `build.sh --be`; the same binary was used before and after switching the FE jar. A private, API-compatible Lance dependency overlay was needed; no BE source was changed. - Before: new FE tests failed, and the SQL alter job was CANCELLED with `CAST required_dt(DateTimeV2(3)) TO DateTimeV2(6) return column type mismatch: declared=DateTimeV2(6), actual=Nullable(DATETIMEV2)`. - After: `test_schema_change_cast_nullable` passed with runner-generated output and normal comparison; `test_alter_table_column_nullable` also passed (2 suites, 0 failed). Maximum datetime, SQL NULL, rewritten historical data, and post-alter microsecond writes were verified. FE unit tests: 53 passed (CastExprTest, CastTest, TryCastTest, CastExprThriftSimplificationTest, SchemaChangeJobV2Test). The red baseline demonstrates false nullable inference for DATETIMEV2 scale conversion and BIGINT-to-TINYINT narrowing. Added unit coverage includes both scale directions, serialized nullable metadata, cloning, safe numeric widening, nullable inputs, and string-to-number conversion. SQL regression rewrites historical required/nullable datetime columns, including maximum date and SQL NULL values, then checks reads and new writes after the alter. ### Compatibility and performance No BE CAST code, storage format, persisted expression fields, or Thrift definitions change. The existing result-column nullable contract is reused; output values and conversion/error semantics stay unchanged. Inference runs during FE expression inspection/serialization, not in the BE row-processing loop. Safe numeric widening remains non-nullable. No performance benchmark is claimed. ### Release note Fix heavy schema change failures caused by incorrect CAST nullable metadata when changing DATETIMEV2 precision on a NOT NULL column. ### Check List (For Author) - Test: FE Unit Test: 53 passed; ASAN SQL regression: 2 suites passed; generated golden then reran in normal mode - Behavior changed: Yes. Directly constructed casts now declare their actual possible NULL results, allowing valid schema-change execution. BE conversion semantics are unchanged. - 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]
