924060929 opened a new pull request, #71003:
URL: https://github.com/apache/doris/pull/71003
### Background
Apache Doris routes external catalog statistics through
`ConnectorStatisticsOps` and `PluginDrivenExternalTable`:
1. On a `StatisticsCache` miss, `ColumnStatisticsCacheLoader` calls
`PluginDrivenExternalTable.getColumnStatistic(col)` ->
`ConnectorMetadata.getColumnStatistics(...)` to obtain zero-scan metadata
column statistics before falling back to `ColumnStatistic.UNKNOWN` or an
explicit `ANALYZE`.
2. Explicit `ANALYZE TABLE ... WITH SAMPLE` and `SELECT ...
TABLESAMPLE(...)` require two connector opt-ins on `fe-connector-spi`:
`ConnectorCapability.SUPPORTS_SAMPLE_ANALYZE` +
`ConnectorStatisticsOps.listFileSizes(...)` and
`ConnectorScanPlanProvider.supportsTableSample()`.
Previously, only plain Hive tables opted into metadata column statistics,
`TABLESAMPLE`, and `ANALYZE ... WITH SAMPLE`; Iceberg and Paimon returned
`Optional.empty()` for column statistics, ignored `TABLESAMPLE` with a full
scan, rejected `ANALYZE ... WITH SAMPLE`, and sampled external tables executed
one `TABLESAMPLE` scan and one `listFileSizes()` listing per column.
### What problem does this PR solve?
Issue Number: close #70992
Related PR: #71002 (depends on)
PR Type: Feature
Problem Summary:
Querying unanalyzed Iceberg or Paimon tables could not consume Puffin NDV
sketches or Paimon table statistics files already recorded in table metadata,
`SELECT ... TABLESAMPLE(...)` scanned the entire Iceberg/Paimon table, `ANALYZE
TABLE ... WITH SAMPLE` failed as unsupported on Iceberg and Paimon, and sampled
external analysis repeated file-size listing and full split scans once per
column. This PR wires zero-scan Puffin / Paimon `Statistics` column metadata
into `ConnectorStatisticsOps.getColumnStatistics`, enables split-weighted
`TABLESAMPLE` and `ANALYZE ... WITH SAMPLE` for Iceberg (including
Iceberg-on-HMS) and Paimon (both native ORC/Parquet and JNI/Rust `DataSplit`
readers), caches `getChunkSizes()` once per `(AnalysisJob, tableId)`, and
batches up to `statistics_sample_batch_columns` (default `16`) external columns
into a single `TABLESAMPLE` CTE scan.
### Details
- **Change map:** 20 files (+1,377/-27): production code +863/-26 across 11
files, unit and regression tests +514/-1 across 9 files:
1. Iceberg and Paimon zero-scan metadata column statistics,
`listFileSizes`, and `TABLESAMPLE` / `SUPPORTS_SAMPLE_ANALYZE` opt-ins
(`IcebergConnectorMetadata`, `IcebergScanPlanProvider`, `PaimonCatalogOps`,
`PaimonConnectorMetadata`, `PaimonScanPlanProvider`, ~295 lines).
2. Partial metadata stats normalization, Paimon JNI/Rust `DataSplit`
byte-weighted `sampleSplits`, per-job `chunkSizes` caching, and multi-column
batched external `TABLESAMPLE` collection (`ExternalSampleBatchCollector`,
`TableStatisticsSqlBuilder`, `PluginDrivenSampleAnalysisTask`,
`PluginDrivenScanNode`, `PluginDrivenExternalTable`, `AnalysisJob`, ~570 lines).
- **Scope:**
- **Metadata-first column statistics (`getColumnStatistics`):** Iceberg
data tables read inline `TableMetadata` `StatisticsFile` Puffin `BlobMetadata`
(`apache-iceberg-theta-v1` `ndv` property, preferring
`currentSnapshot().snapshotId()`); Paimon `FileStoreTable`s read
`table.statistics()` `ColStats` (`distinctCount`, `nullCount`, `avgLen`, and
`mergedRecordCount` / snapshot `rowCount`). System tables, empty tables,
equality-delete Iceberg tables without usable row count, and columns without
recorded NDV degrade to `Optional.empty()`.
- **`TABLESAMPLE` & `ANALYZE ... WITH SAMPLE`:** Supported on Iceberg data
tables (native and HMS-delegated) and Paimon `DataTable`s (append-only native
splits and primary-key / deletion-vector JNI or Rust `DataSplit`s). System
tables do not declare `SUPPORTS_SAMPLE_ANALYZE` and bypass `sampleSplits` when
split byte weights are non-positive.
- **Multi-column batched external sampling:**
`ExternalSampleBatchCollector` shares one `WITH sample_base AS (SELECT ... FROM
tbl TABLESAMPLE(...) [LIMIT ...])` scan across up to
`statistics_sample_batch_columns` columns per external table, preserving
single-distribution-column linear NDV vs DUJ1 NDV + hot values, `NULL` min/max,
and per-column `statistics_max_string_column_length` isolation.
- **Design:** Builds entirely on the existing `fe-connector-spi` contracts
(`ConnectorCapability.SUPPORTS_SAMPLE_ANALYZE`,
`ConnectorStatisticsOps.getColumnStatistics`,
`ConnectorStatisticsOps.listFileSizes`,
`ConnectorScanPlanProvider.supportsTableSample`) with zero SPI surface
additions. For Paimon JNI/Rust `DataSplit`s whose `Split.getLength()` is `-1`,
`PluginDrivenScanNode.sampleSplitByteLength` resolves byte weight from
`ConnectorScanRange.getSelfSplitWeight()` (gated on `paimon.bucket` /
`fileSize` and `getPushDownRowCount() < 0` so non-`DataSplit` system row-count
weights are never mistaken for bytes).
- **Usage:**
```sql
SELECT COUNT(*) FROM ice_cat.db.events TABLESAMPLE(10 PERCENT) REPEATABLE
42;
ANALYZE TABLE ice_cat.db.events WITH SAMPLE ROWS 400000 WITH SYNC;
ANALYZE TABLE paimon_cat.db.orders WITH SAMPLE PERCENT 10 WITH SYNC;
```
- **Default behavior:** Active by default for Iceberg and Paimon data
tables; multi-column external sample batching uses existing
`statistics_sample_batch_columns` (default `16`). When
`enable_auto_analyze_external_catalog` is enabled, huge Iceberg and Paimon
tables (`>= huge_table_lower_bound_size_in_bytes`) automatically use `SAMPLE`
instead of `FULL` scans.
- **Compatibility:** Pure FE + connector plugin change (`fe-core`,
`fe-connector-iceberg`, `fe-connector-paimon`); no EditLog, storage format,
Thrift, or Protobuf changes, and `fe-connector-spi` public API is unchanged.
- **Security and privileges:** Uses existing `ANALYZE` / `SELECT` privileges
and runs all Iceberg/Paimon metadata and manifest reads inside
`context.executeAuthenticated(...)` with plugin TCCL pinned per
`ConnectorStatisticsOps` contract.
- **Behavior change:** Unanalyzed Iceberg and Paimon data tables now expose
inline Puffin NDV and Paimon `ColStats` metadata on `StatisticsCache` misses,
`SELECT ... TABLESAMPLE(...)` samples splits instead of full-scanning
Iceberg/Paimon tables, and huge Iceberg/Paimon tables (`>=
huge_table_lower_bound_size_in_bytes`) under
`enable_auto_analyze_external_catalog = true` automatically run `SAMPLE`
instead of `FULL` analyze.
### Testing
- Connector & FE Checkstyle (`mvn checkstyle:check -pl
fe-connector/fe-connector-iceberg,fe-connector/fe-connector-paimon,fe-core`)
and 141 unit tests across `ConnectorPluginSurfaceTest`,
`IcebergConnectorMetadataStatisticsTest`,
`PaimonConnectorMetadataStatisticsTest`, `HiveConnectorMetadataSchemaTest`,
`HiveConnectorMetadataSiblingDelegationTest`,
`PluginDrivenExternalTableColumnStatTest`, `PluginDrivenExternalTableTest`,
`PluginDrivenScanNodeTableSampleTest`, `StatisticsAutoCollectorTest`, and
`ExternalSampleBatchCollectorTest` passed locally.
- Verified `CREATE CATALOG` (local Hadoop Iceberg), `SELECT ...
TABLESAMPLE(...)`, and multi-column batched `ANALYZE TABLE ... WITH SAMPLE` on
a local FE+BE cluster; extended `test_iceberg_statistics.groovy` and
`test_paimon_statistics.groovy` for CI external Docker pipelines.
### Notes for Reviewers
- Stacked on #71002; review top commit `e9537742f1b` for the standalone diff
until #71002 merges.
### Release note
Support zero-scan metadata column statistics (Iceberg Puffin NDV and Paimon
`ColStats`), `TABLESAMPLE`, and multi-column batched `ANALYZE TABLE ... WITH
SAMPLE` for Iceberg and Paimon external tables.
### Check List (For Author)
- Behavior changed: Yes (see Details)
- Does this need documentation: Yes (update Lakehouse statistics and
`TABLESAMPLE` documentation in `apache/doris-website` to list Iceberg and
Paimon support)
- Pre-submission status: Partially verified: unit tests and local-filesystem
Iceberg catalog sampling verified locally; Docker HMS/MinIO suites
(`test_iceberg_statistics`, `test_paimon_statistics`) run in CI external
pipeline
### AI Disclosure
- Tool: Antigravity (Claude Opus 4.6)
- Generated: code, tests, this description
- Human review: not stated
--
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]