924060929 opened a new issue, #70992: URL: https://github.com/apache/doris/issues/70992
### Background External lakehouse tables in Iceberg and Paimon frequently store hundreds of millions of rows alongside rich metadata (Iceberg Puffin `StatisticsFile` theta sketches in `TableMetadata` and Paimon `Statistics` `ColStats`). Meanwhile, `fe-connector-spi` already defines `ConnectorStatisticsOps.getColumnStatistics`, `ConnectorStatisticsOps.listFileSizes`, `ConnectorCapability.SUPPORTS_SAMPLE_ANALYZE`, and `ConnectorScanPlanProvider.supportsTableSample()`, which previously only plain Hive implemented. ### Current behavior 1. Querying unanalyzed Iceberg or Paimon tables returns `ColumnStatistic.UNKNOWN` even when Iceberg Puffin `ndv` metadata or Paimon `ColStats` already exist. 2. `SELECT ... FROM ice_tbl TABLESAMPLE(10 PERCENT)` ignores `TABLESAMPLE` and scans the entire Iceberg/Paimon table. 3. `ANALYZE TABLE ice_tbl WITH SAMPLE ROWS 400000` fails because neither Iceberg nor Paimon advertises `SUPPORTS_SAMPLE_ANALYZE`, and sampled external tables run one `TABLESAMPLE` scan plus one `listFileSizes()` call per column. ### Expected behavior 1. Iceberg and Paimon return zero-scan column statistics from inline Puffin `BlobMetadata` (`apache-iceberg-theta-v1` `ndv`) and Paimon `table.statistics()` `ColStats` on `StatisticsCache` misses. 2. Iceberg (native and HMS-delegated) and Paimon (native ORC/Parquet and JNI/Rust `DataSplit`s) support split-weighted `TABLESAMPLE` and `ANALYZE TABLE ... WITH SAMPLE`. 3. External sampled `ANALYZE` caches `getChunkSizes()` once per `(AnalysisJob, tableId)` and batches up to `statistics_sample_batch_columns` (`16`) columns into one `TABLESAMPLE` CTE scan (`ExternalSampleBatchCollector`). ### Proposed design 1. Implement `getColumnStatistics`, `listFileSizes`, `SUPPORTS_SAMPLE_ANALYZE`, and `supportsTableSample()` in `IcebergConnectorMetadata` / `IcebergScanPlanProvider` and `PaimonConnectorMetadata` / `PaimonCatalogOps` / `PaimonScanPlanProvider` under plugin TCCL and `executeAuthenticated` without modifying `fe-connector-spi`. 2. Normalize unknown `numNulls < 0` in `PluginDrivenExternalTable.toColumnStatistic` and resolve Paimon JNI/Rust `DataSplit` byte weights from `ConnectorScanRange.getSelfSplitWeight()` (gated on `paimon.bucket` / `fileSize` and `getPushDownRowCount() < 0`) in `PluginDrivenScanNode.sampleSplits`. 3. Add `ExternalSampleBatchCollector` and `TableStatisticsSqlBuilder.buildBatchedExternalSampleSql` to share one `TABLESAMPLE` CTE scan across up to `16` columns per external table. - Rejected alternatives: (a) adding new methods to `fe-connector-spi`, which is unnecessary and alters plugin binary surface; (b) fetching remote Puffin files on FE cache misses, which adds object-store I/O to query planning when `ndv` is already inlined in `TableMetadata`. ### Impact Iceberg, Paimon, and Hive external catalog queries and `ANALYZE` jobs (`fe-connector-iceberg`, `fe-connector-paimon`, `fe-core`). ### Reproduction or evidence Verified via 141 unit tests (`ConnectorPluginSurfaceTest`, `IcebergConnectorMetadataStatisticsTest`, `PaimonConnectorMetadataStatisticsTest`, `PluginDrivenExternalTableColumnStatTest`, `PluginDrivenScanNodeTableSampleTest`, `StatisticsAutoCollectorTest`, `ExternalSampleBatchCollectorTest`) and live-cluster Iceberg Hadoop catalog `TABLESAMPLE` + `ANALYZE ... WITH SAMPLE` execution. ### Scope and non-goals Covers Iceberg data tables, Paimon `DataTable`s, and multi-column batched external `TABLESAMPLE` collection. Metadata system tables (`$snapshots`, `$files`, `$binlog`) remain non-sampled. ### Acceptance criteria - Zero-scan Puffin NDV and Paimon `ColStats` populate `ColumnStatistic` without negative `numNulls`. - `TABLESAMPLE` and `ANALYZE ... WITH SAMPLE` work on Iceberg and Paimon data tables, batching up to 16 columns per scan. - `ConnectorPluginSurfaceTest` confirms zero changes to `fe-connector-spi`. ### Risks and compatibility Pure FE + connector plugin change; no Thrift, Protobuf, EditLog, or storage changes. Rolling BE-then-FE upgrades remain compatible. ### Related Part of the OLAP & Lakehouse bounded-budget sampling statistics series. -- 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]
