xylaaaaa opened a new pull request, #71450: URL: https://github.com/apache/doris/pull/71450
### Background Apache Doris PR [#69904](https://github.com/apache/doris/pull/69904) landed M1 basic native Delta Lake reads on `branch-deltalake` (`62420d1bcbe5`), and [#70536](https://github.com/apache/doris/pull/70536) landed M2 advanced reads on `branch-deltalake` (`e9931adeb6`). Both are tracked under [#69884](https://github.com/apache/doris/issues/69884). This PR delivers **M3 (Basic DDL & Writes)** across `filesystem`, Unity Catalog (`uc`, managed & external), and AWS Glue (`glue`) catalogs while keeping `fe-connector-spi` completely unchanged (`0` lines modified). ### What problem does this PR solve? Issue Number: #69884 Related PR: #69904 (M1 reads), #70536 (M2 reads) PR Type: Feature Problem Summary: Native Delta Lake catalogs on `branch-deltalake` are currently read-only and cannot execute DDL or write Parquet data back to Delta tables. This PR adds end-to-end Delta Lake DDL (`CREATE/DROP DATABASE`, `CREATE/DROP TABLE`, `SHOW CREATE TABLE`, `ALTER TABLE`), native BE Parquet writing (`DELTALAKE_TABLE_SINK`), `INSERT INTO`, `CTAS`, `INSERT OVERWRITE` (whole-table, static, and dynamic partition modes), writer protocol feature support (including `NOT NULL` validation, `appendOnly`, atomic deferred-publish checkpoints, and BE `ParquetVariantShreddingEncoder`), and full Unity Catalog + AWS Glue write/DDL support. Existing read-only queries and other external catalog plugins remain unaffected; upgrading requires deploying the new BE before enabling the new FE/plugin for Delta writes. ### Details - **Change map:** 129 files changed (`+19,219 / -297`; `fe-connector-spi`: `0` lines): - **Production code (72 files, `+8,627 / -226`):** - `gensrc/thrift` (2 files, `+48 / -0`): `TDataSinkType.DELTALAKE_TABLE_SINK = 22`, `TDeltaLakeTableSink`, `TDeltaLakeCommitData`, `TDeltaLakeColumnStats`, `TDataSink.22`, and `TReportExecStatusParams.35`. - `be/src` (19 files, `+2,945 / -11`): pipeline sink operator (`deltalake_table_sink_operator`), partition & table writer (`vdeltalake_table_writer`, `vdeltalake_partition_writer`) with strict UTF-8 validation across `STRING`/`VARCHAR`/`CHAR`/`VARBINARY` partition values, recursive `NOT NULL` / Map-key validator (`delta_write_validator`), Arrow/Parquet converter & Delta writer with safe RowGroup stats (`delta_arrow_block_convertor`, `vdeltalake_parquet_writer`), reusable `ParquetVariantShreddingEncoder` (`be/src/format/parquet/variant_shredding_encoder.*`), and `RuntimeState` commit-data reporting. - `fe/fe-core` (20 files, `+305 / -70`): plugin DDL/CTAS/overwrite routing (`PluginDrivenExternalCatalog`, `CreateTableCommand`, `CreateTableInfo`, `AlterTableCommand`, `InsertIntoTableCommand`, `InsertOverwriteTableCommand`, `InsertUtils`, `ExplainCommand`, `PluginDrivenTableSink`, `CommitDataSerializer`), CTAS creation-identity fencing across insert retries, `SessionVariable.deltalake_partition_overwrite_mode`, explicit `DEFAULT NULL` isolation, external `VARBINARY` DDL pass-through, and `SHOW CREATE TABLE` plugin rendering. - `fe/fe-connector/fe-connector-deltalake` (31 files: 30 Java + `pom.xml`, `+5,329 / -145`): atomic S3A/HDFS/Local writes (`DeltaLakeFileIO`, `DeltaLakeOutputFile`), custom `DeltaLakeEngine` & deferred-publish `DeltaLakeParquetHandler` for atomic checkpoint publication, Delta Kernel 4.4.1 compat & writer feature gates (`DeltaKernelCompat`, `DeltaLakeWriterFeatureCheck`), DDL & schema evolution (`DeltaLakeDdl`, `DeltaLakeAlterTable`, `DeltaLakeSchemaBuilder`, `DeltaLakeCreateDirectories`, `DeltaLakeCreatedTable`), statement-scoped read/write snapshot alignment & OCC transactions (`DeltaLakeWritePlanProvider`, `DeltaLakeWriteSchema`, `DeltaLakeConnectorTransaction`, `DeltaLakeOverwrite`), Unity Catalog managed/external DDL & `READ_WRITE` vended credentials (`DeltaLakeUnityCatalog`, `DeltaLakeVendedFileIO`), and AWS Glue DDL/writes & post-`ALTER` metadata sync (`DeltaLakeGlueCatalog`, `DeltaLakeGlueTableMetadata`). - **Tests & regressions (57 files, `+10,592 / -71`):** 6 BE gtest files (`+1,739`), 12 `fe-core` unit test files (`+875 / -49`), 21 `fe-connector-deltalake` unit test files (`+6,821 / -6`), and 18 regression suite/golden files (`+1,157 / -16`, 8 new Delta write P0 suites). - **Scope:** - **Catalogs:** `filesystem`, Unity Catalog (`uc`: `MANAGED` via `catalogManaged` + `DeltaTablesApi` `/delta/v1/...` staged commits & `EXTERNAL`), and AWS Glue (`glue`). - **DDL:** `CREATE/DROP DATABASE`, `CREATE/DROP TABLE` (partitioning, `delta.clusteringColumns` Liquid Clustering, `columnMapping`, table/column comments, table properties, `VARBINARY`, `VARIANT`), `SHOW CREATE TABLE`, and `ALTER TABLE` (`ADD COLUMN` / `ADD COLUMNS`, `RENAME COLUMN` on mapped tables, `MODIFY COLUMN COMMENT`, `SET TBLPROPERTIES`). - **DML:** `INSERT INTO`, `CTAS` (with creation-identity fencing and fail-closed rollback), and `INSERT OVERWRITE` (whole-table, static partition, and dynamic partition via `deltalake_partition_overwrite_mode = static|dynamic`, default `static`). - **Writer Features & Constraints:** `columnMapping`, `timestampNtz`, `typeWidening`, `v2Checkpoint` (writes Classic Checkpoint), `deletionVectors` (preserves existing DVs), `changeDataFeed` (emits valid `RemoveFile` actions), `vacuumProtocolCheck`, `appendOnly` (blocks overwrite), `rowTracking`, `inCommitTimestamp`, `domainMetadata`, `materializePartitionColumns`, `clustering`, `variantType`, `variantShredding` (shredded `VARIANT(1)` Parquet output via `ParquetVariantShreddingEncoder`), and `catalogManaged` (UC only). Enforces top-level/nested `NOT NULL` and non-null Map keys in BE; legacy `delta.invariants` column expressions and unsupported writer features (`checkConstraints`, `generatedColumns`, `identityColumns`, `allowColumnDefaults`, `icebergCompat*`, `collations*`, `geospatial`, `checkpointProtection`) fail closed before writing files. - **Key Correctness & Safety Design:** - **Atomic commit log & checkpoint publication:** Reuses Hadoop 3.4.2 `S3AFileSystem` conditional put (`fs.s3a.create.conditional.enabled=true` + `fs.option.create.conditional.overwrite=true` mapping HTTP 412/409 to `FileAlreadyExistsException`), HDFS `create(overwrite=false)`, and local atomic `CREATE_NEW` rename. `DeltaLakeEngine` + `DeltaLakeParquetHandler` replaces Kernel's default close-as-publish Parquet writer with deferred publication (`overwrite = false`) and explicit abort cleanup so an upstream read failure cannot publish a truncated checkpoint or leak temp files/vended credential leases. - **Transaction, OCC & statement snapshot safety:** Pins table UUID, base version, and schema/layout/protocol fingerprint at bind time, sharing a single statement-scoped `DATA_SNAPSHOT_NAMESPACE` across ordinary reads and writes so self-overwrites cannot read a stale version while dropping newer concurrent appends. Blind `INSERT INTO` retries up to 10 times; `INSERT OVERWRITE` retries up to 5 times with disjoint-partition verification across all concurrent `AddFile` and `RemoveFile` actions (preserving explicit empty-string partitions distinct from `NULL`, handling `dataChange=false` `OPTIMIZE`, and failing closed on non-extended removes). Unknown commit states (`CommitStateUnknownException`) probe only actually uncertain attempted versions in the transaction log before deciding whether any newly written file may be reclaimed. - **CTAS identity fencing & fail-closed rollback:** `CreateTableInfo.CtasCreation` captures the pure in-memory write metadata identity (UUID, v0, fingerprint, canonical path, registration ID, managed flag) at `CREATE` time and passes it across inner `INSERT` planning retries via `PluginDrivenInsertCommandContext` to prevent writing into a concurrently replaced same-name table. On failed CTAS, only local `file://` filesystem catalogs run inode-anchored pristine-v0 cleanup; S3/HDFS, Unity Catalog, and AWS Glue skip automatic catalog/storage deletion (zero catalog/storage I/O) and retain initialized v0 after registration failures, preserving actionable manual-inspection diagnostics (with cache invalidation errors attached as suppressed). - **Native BE Parquet sink, strict partition UTF-8 & stats:** `VDeltaLakeTableWriter` validates constraints, normalizes empty string partitions to SQL `NULL`, strictly validates UTF-8 for `STRING`/`VARCHAR`/`CHAR`/`VARBINARY` partition values in BE (and rejects unpaired UTF-16 surrogates in FE static `STRING` partitions) so Thrift serialization cannot silently rewrite invalid bytes to `U+FFFD` or `?`, writes Hive-escaped (`NONE`) or 2-hex-prefix (`NAME`/`ID`) directories, populates Parquet `field_id` on mapped tables, rolls files at block boundaries, and collects safe Delta `AddFile.stats` (UTF-8 codepoint truncation with upper-bound carry, `-0.0`/`+0.0` float bounds, NaN-omitted min/max, sub-ms timestamp ceiling, Variant SQL `null_count` from `metadata` only). - **Variant Shredding (`ParquetVariantShreddingEncoder`):** Lives in shared `be/src/format/parquet/` for reuse across table formats. Supports explicit object schemas (`JSON` or `struct<...>`) or first-nonempty-block inference, emits standard Parquet `VariantShredding.md#objects` layout (`REQUIRED` object member groups, unified per-row sorted residual dictionary with zero duplicate keys across `typed_value` and `value`), and writes `LogicalType::Variant()` (`VARIANT(1)`) via `parquet::arrow::FileWriter::Make`. - **UC & Glue semantics:** UC isolates `READ` vs `READ_WRITE` vended credential pools, supports static configured storage on `EXTERNAL` tables after mandatory UC `READ_WRITE`/`PATH_CREATE_TABLE` authorization, and uses `UCCatalogManagedCommitter` + `publish()` for managed tables. Glue writes Spark/Athena-compatible `TableInput`, preserves existing Glue metadata and uses `VersionId` OCC on post-`ALTER` `UpdateTable` (WARN-only on sync failure), checks non-Delta tables before non-`FORCE` `DROP DATABASE`, and never deletes object-store data on `DROP`/CTAS rollback. - **Usage:** - Set `SET deltalake_partition_overwrite_mode = 'dynamic';` (default `'static'`) for dynamic partition overwrite. - Enable Variant shredding with `TBLPROPERTIES ('delta.enableVariantShredding' = 'true')`. - Use explicit `'location' = '...'` (or Glue database `locationUri` / UC staging) for external/managed table creation. - **Compatibility:** - `fe-connector-spi`: zero changes. - Thrift IDs (`TDataSinkType.22`, `TDataSink.22`, `TReportExecStatusParams.35`): audited against `branch-3.1`, `branch-4.0`, `branch-4.1`, `branch-4.2`, and `master` — all new fields are `optional` with zero ID collisions (must be reserved/landed on `master` before picking to release branches per `gensrc/AGENTS.md`). - Upgrade order: deploy BE before FE/plugin when enabling Delta writes. ### Testing Verification ran locally with ASAN BE, Maven Checkstyle FE builds (`DISABLE_JAVA_CHECK_STYLE=OFF`), `build-support/check-build-hygiene.sh`, `build-support/check-format.sh` (clang-format 16), and `build-support/run-clang-tidy.sh` on modified C++ files: - **Unit tests (post-rebase & post-review fixes):** - `fe-connector-deltalake` (all 43 test classes): 544 regular tests passed (0 failures, 0 errors; 2 opt-in 1M-`AddFile` scale tests skipped by default), 0 Checkstyle violations. - `fe-core` (all 12 modified test classes across 72 reactor modules): 252/252 tests passed, 0 skips, 0 Checkstyle violations. - BE ASAN UTs: `VDeltaLakeTableWriterTest` + `VDeltaLakeReportingTest` (22/22 passed, 0 skips, including 240 malformed UTF-8 partition combinations and rolled/open abort cleanup), plus per-milestone verification of `delta_write_validator_test`, `vdeltalake_parquet_writer_test`, `variant_shredding_encoder_test`, and `runtime_state_block_budget_test`. - **P0 regression suites (verified incrementally across milestones against isolated FE/ASAN BE + Spark 4.0.1 / Delta 4.4.1):** - `test_deltalake_insert`, `test_deltalake_ctas`, `test_deltalake_concurrent_append`, `test_deltalake_insert_overwrite`, `test_deltalake_writer_features`, `test_deltalake_variant_write`: generated & replayed (1/1 each). - `test_deltalake_glue_write`: updated for fail-closed CTAS retention (`writes_failed.failed_copy`), regenerated via `-forceGenOut` and replayed on local `file:` mode (1/1, 0 skips); MinIO mode was verified prior to the CTAS retention update and awaits replay on an isolated MinIO instance. - `test_deltalake_uc_write`: verified 1/1 against OSS Unity Catalog 0.7.0 + MinIO + Spark 4.0.1 prior to the UC/Glue fail-closed CTAS retention update; syncing `failed_copy` to an isolated database and regenerating its `.out` awaits an isolated UC service (the suite is gated by `enableDeltaLakeUcTest=true`). ### Notes for Reviewers - **Outbound HTTP / SSRF surface (`AGENTS.md`):** No new remote catalog endpoint properties or dynamic code loading paths (`URLClassLoader` / `driver_url`) are introduced. Write operations reuse existing catalog endpoints configured via `CREATE/ALTER CATALOG` (requiring catalog `CREATE_PRIV`/`ALTER_PRIV`): `unity.uri` (UC credential vending, schema/table REST CRUD, and `/delta/v1/...` Delta commit API), `glue.endpoint` (AWS Glue SigV4 DDL APIs), and `s3.endpoint`/Hadoop storage endpoints; table/database `location` paths on UC External and Glue require DB/table `CREATE_PRIV`. AWS/UC error wrappers sanitize raw upstream error bodies and unknown service error codes to avoid echoing credentials or SigV4 headers. - **Thrift ID reservation (`gensrc/AGENTS.md`):** `TDataSinkType.22`, `TDataSink.22`, and `TReportExecStatusParams.35` have zero collisions across `branch-3.1` through `master`; before merging `branch-deltalake` into release branches or `master`, coordinate reserving/landing these IDs on `master`. - **Documented boundaries:** - **Unity Catalog / AWS Glue real cloud accounts:** Verified against OSS Unity Catalog 0.7.0 + MinIO and a local SigV4 Glue HTTP stub + MinIO; real Databricks UC and real AWS Glue/IAM/STS/S3 accounts were not tested. - **UC P0 golden sync & Glue MinIO replay:** `test_deltalake_uc_write.{groovy,out}` still reflects the pre-retention auto-delete expectation for `failed_copy` and needs paired regeneration once an isolated UC service is available; Glue MinIO replay awaits an isolated MinIO service. - **Spark 4.0.1 shredded `VARIANT(1)` interop:** Vanilla Spark 4.0.1 (`ParquetToSparkSchemaConverter`) rejects Parquet 1.16's standard `VARIANT(1)` logical type annotation on shredded groups (`PARQUET_TYPE_NOT_RECOGNIZED`, fixed in Spark 4.1+); Doris writes standard `VARIANT(1)` (required by Doris `format_v2` and Parquet 1.16+ readers), cross-engine row-by-row parity in `test_deltalake_variant_write` uses a test-only Spark reader adapter, and vanilla Spark's own shredded appends are read back natively by Doris. - **Doris `format_v2` `CAST` MinMax pruning:** Written shredded files contain full typed-leaf RowGroup statistics and all-NULL fallback columns (3/4 groups disjoint), and Doris Profile confirms `VariantLeafProjection` + `FilteredRowsByLazyRead`; whole-group MinMax skip on `CAST(v['k'] AS BIGINT)` is currently gated by Doris's pre-existing `metadata_pruning_safe_conjunct_count` policy for `CAST` expressions. - **Kernel 4.4.1 reflection compat:** `DeltaKernelCompat` uses a targeted reflection bridge for v0 table description (Kernel 4.4.1 lacks a public description setter) — marked for review on future Kernel upgrades. ### Release note Native Delta Lake catalogs (`branch-deltalake`) now support database and table DDL (`CREATE/DROP DATABASE`, `CREATE/DROP TABLE`, `SHOW CREATE TABLE`, `ALTER TABLE`), native BE Parquet writes (`INSERT INTO`, `CTAS`, and whole-table/static/dynamic `INSERT OVERWRITE` controlled by `deltalake_partition_overwrite_mode`), Delta writer protocol features (including `NOT NULL`, `appendOnly`, `columnMapping`, `v2Checkpoint`, `deletionVectors`, `changeDataFeed`, `rowTracking`, `inCommitTimestamp`, `clustering`, and `delta.enableVariantShredding` shredded `VARIANT(1)` output), and write/DDL operations across `filesystem`, Unity Catalog (managed & external), and AWS Glue catalogs. Upgrade BE before enabling the new FE/plugin for Delta writes. ### Check List (For Author) - Test - [x] Regression test (8 new Delta write P0 suites verified incrementally against Spark 4.0.1 / Delta 4.4.1, MinIO, local Glue, and OSS Unity Catalog 0.7.0; see Testing & Documented boundaries for UC P0 retention sync / Glue MinIO replay) - [x] Unit Test (544 Delta FE tests, 252 modified `fe-core` tests, and targeted BE ASAN UTs passed with zero failures/errors; Checkstyle, clang-format 16, build hygiene, and clang-tidy passed) - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. - Behavior changed: - [ ] No. - [x] Yes. Enables DDL and write operations on native Delta Lake catalogs (see Details and Release note); read-only paths and other catalogs remain unchanged. - Does this need documentation? - [ ] No. - [x] Yes. Delta Lake DDL, `INSERT`/`OVERWRITE`, `deltalake_partition_overwrite_mode`, `delta.enableVariantShredding`, and UC/Glue write documentation tracked in #69884. ### AI Disclosure - Tool: OpenAI Codex / Antigravity. - Generated: Architecture design review, implementation across FE/BE/Thrift, unit and P0 regression tests, local Spark/UC/Glue/MinIO verification harnesses, and this PR description. - Human review: Maintainer review is pending (all milestone commits and review-fix follow-ups underwent iterative automated review and verification before submission). -- 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]
