legacy-timestamp-mapping.enabled |
false |
diff --git a/paimon-core/src/main/java/org/apache/paimon/table/format/FormatTablePartitionStatsCollector.java b/paimon-core/src/main/java/org/apache/paimon/table/format/FormatTablePartitionStatsCollector.java
new file mode 100644
index 000000000000..95f1e2519433
--- /dev/null
+++ b/paimon-core/src/main/java/org/apache/paimon/table/format/FormatTablePartitionStatsCollector.java
@@ -0,0 +1,288 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.table.format;
+
+import org.apache.paimon.CoreOptions;
+import org.apache.paimon.format.FileFormat;
+import org.apache.paimon.format.SimpleStatsExtractor;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.FileStatus;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.partition.PartitionStatistics;
+import org.apache.paimon.statistics.SimpleColStatsCollector;
+import org.apache.paimon.table.FormatTable;
+import org.apache.paimon.types.RowType;
+import org.apache.paimon.utils.PartitionPathUtils;
+import org.apache.paimon.utils.ThreadPoolUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+
+/**
+ * Measures what the partitions of a Format Table currently hold, by listing their directories. File
+ * count, byte size and last file creation time come from the listing; the row count does not, since
+ * no listing opens a file. A partition holding nothing measures as an exact zero on the file
+ * numbers, with no last file to date.
+ *
+ * It lists through {@link FormatTableScan#listDataFiles}, the listing the scan itself uses, so a
+ * measurement counts exactly the files a reader would return and committer staging trees are pruned
+ * rather than walked. A listing failure aborts the whole collection: a truncated listing looks
+ * exactly like a partition that lost files.
+ *
+ *
The result is a whole-partition measurement, so it replaces rather than accumulates. It never
+ * decides that a partition should exist or stop existing; it measures the ones it is given.
+ */
+public class FormatTablePartitionStatsCollector {
+
+ private static final Logger LOG =
+ LoggerFactory.getLogger(FormatTablePartitionStatsCollector.class);
+
+ /** Row counts that need no columns: the file footer alone answers how many rows it holds. */
+ private static final RowType NO_COLUMNS = RowType.builder().build();
+
+ private static final SimpleColStatsCollector.Factory[] NO_COLLECTORS =
+ new SimpleColStatsCollector.Factory[0];
+
+ private final FormatTable table;
+
+ private final boolean onlyValueInPath;
+ private final int parallelism;
+
+ private final boolean withRecordCount;
+
+ /** Measures from the listing alone, leaving the record count unknown. */
+ public FormatTablePartitionStatsCollector(FormatTable table, int parallelism) {
+ this(table, false, parallelism);
+ }
+
+ /**
+ * Measures from the listing, and when {@code withRecordCount} is set also opens every file's
+ * footer for the rows it holds. That is the expensive half, so it is asked for rather than
+ * assumed.
+ */
+ public FormatTablePartitionStatsCollector(
+ FormatTable table, boolean withRecordCount, int parallelism) {
+ this.table = table;
+ this.onlyValueInPath =
+ new CoreOptions(table.options()).formatTablePartitionOnlyValueInPath();
+ this.withRecordCount = withRecordCount;
+ this.parallelism = Math.max(1, parallelism);
+ }
+
+ /**
+ * Measures the given partitions. The result is aligned to {@code partitions} one for one, so a
+ * caller can send it straight to the catalog alongside the same specs.
+ */
+ public List collect(List