hello-stephen commented on code in PR #71365:
URL: https://github.com/apache/doris/pull/71365#discussion_r4784949045
##########
fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java:
##########
@@ -516,7 +515,11 @@ private void syncPartitionsIfNeeded(ConnectContext ctx,
List<TableIf> tableIfs)
if (mtmv.getMvPartitionInfo().getPartitionType() !=
MTMVPartitionType.SELF_MANAGE) {
Set<MTMVRelatedTableIf> pctTables =
mtmv.getMvPartitionInfo().getPctTables();
for (MTMVRelatedTableIf pctTable : pctTables) {
- if (!pctTable.isValidRelatedTable()) {
+ Optional<MvccSnapshot> snapshot = pctTable instanceof
MvccTable
+ ? Optional.ofNullable(snapshots.get(new
MvccTableInfo((MvccTable) pctTable)))
+ : Optional.empty();
+ // Qualification must describe the same files that
partition alignment and execution read.
+ if (!pctTable.isValidRelatedTable(snapshot)) {
Review Comment:
[P2] Resolve partition columns from the same refresh pin
Alignment reads items from `snapshots`, but `MTMVPartitionInfo.getPctColPos`
still looks in the ambient statement context. The task installs its snapshots
only in the later execution statement, so this can reload latest Iceberg
metadata under the base-table read locks. With caching disabled, an external
partition-key drop just after capture makes alignment fail even though the
captured view passed this check. Pass `lastResult.resolveSnapshot(pctTable)` to
the column lookup in both descriptor generators.
##########
fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergPartitionUtils.java:
##########
@@ -940,38 +940,38 @@ static List<ConnectorPartitionInfo> listPartitions(Table
table, long pinnedSnaps
return partitions;
}
- /**
- * Port of master {@code IcebergExternalTable.isValidRelatedTable}: an
iceberg table is a valid MTMV related
- * table iff EVERY partition spec has exactly one field whose transform is
{@code year}/{@code month}/{@code
- * day}/{@code hour}, and the partition source column is stable across
partition evolution (a single distinct
- * source column over all specs). Failure -> the connector reports an
UNPARTITIONED view.
- */
+ /** Validates the current snapshot while retaining the original fast path
for time-transform-only tables. */
static boolean isValidRelatedTable(Table table) {
- Set<String> allFields = new HashSet<>();
- for (PartitionSpec spec : table.specs().values()) {
- if (spec == null) {
- return false;
- }
- List<PartitionField> fields = spec.fields();
- if (fields.size() != 1) {
- return false;
- }
- PartitionField partitionField = fields.get(0);
- Type sourceType =
spec.schema().findType(partitionField.sourceId());
- // Historical void partition fields can outlive their dropped
source column.
- if (sourceType == null || sourceType.typeId() ==
Type.TypeID.TIMESTAMP_NANO) {
- // Calendar boundaries and the NULL sentinel can exceed
TIMESTAMP_NS's domain.
- // Leave pruning to Iceberg instead of building invalid Doris
RANGE boundaries.
- return false;
- }
- String transformName = partitionField.transform().toString();
- if (!YEAR.equals(transformName) && !MONTH.equals(transformName)
- && !DAY.equals(transformName) &&
!HOUR.equals(transformName)) {
- return false;
- }
-
allFields.add(table.schema().findColumnName(partitionField.sourceId()));
+ return IcebergMvPartitionSnapshot.supportsAllSpecs(table)
+ || IcebergMvPartitionSnapshot.qualifies(table, -1);
+ }
+
+ private static ConnectorMvccPartitionView
buildEvolvedMvccPartitionView(Table table, long pinnedSnapshotId) {
+ IcebergMvPartitionSnapshot snapshot =
IcebergMvPartitionSnapshot.load(table, pinnedSnapshotId);
+ if (!snapshot.isSupported()) {
+ LOG.debug("Iceberg table {} is not eligible for a partitioned MV:
{}",
+ table.name(), snapshot.getUnsupportedReason());
+ return ConnectorMvccPartitionView.unpartitioned();
+ }
+ Map<String, RangeBuild> ranges = new java.util.TreeMap<>();
+ for (IcebergMvPartitionSnapshot.Partition partition :
snapshot.getPartitions()) {
+ ranges.put(partition.getName(), buildRange(partition.getName(),
partition.getValue(),
+ partition.getRangeTransform(), snapshot.getSourceType(),
snapshot.getUpdateTimeMicros(),
+ snapshot.getSnapshotId()));
}
- return allFields.size() == 1;
+ Set<String> survivors = new LinkedHashSet<>(ranges.keySet());
+ mergeOverlapPartitions(new ArrayList<>(ranges.values()), survivors);
Review Comment:
[P2] Keep timestamp hour ranges that overlap the NULL sentinel
Start with an empty unpartitioned table, add `hour(ts)` on a timestamp
without time zone, and append `NULL` and `0000-01-01 12:00:00`. The unused
original spec now passes qualification. The merge models NULL as the entire
first day and removes the noon-hour range, but the FE gives the surviving NULL
range an exclusive upper bound one microsecond after midnight. Even a complete
refresh then filters out the noon row. Use the same NULL interval for merging
and for the emitted range.
##########
fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergPartitionUtils.java:
##########
@@ -940,38 +940,38 @@ static List<ConnectorPartitionInfo> listPartitions(Table
table, long pinnedSnaps
return partitions;
}
- /**
- * Port of master {@code IcebergExternalTable.isValidRelatedTable}: an
iceberg table is a valid MTMV related
- * table iff EVERY partition spec has exactly one field whose transform is
{@code year}/{@code month}/{@code
- * day}/{@code hour}, and the partition source column is stable across
partition evolution (a single distinct
- * source column over all specs). Failure -> the connector reports an
UNPARTITIONED view.
- */
+ /** Validates the current snapshot while retaining the original fast path
for time-transform-only tables. */
static boolean isValidRelatedTable(Table table) {
- Set<String> allFields = new HashSet<>();
- for (PartitionSpec spec : table.specs().values()) {
- if (spec == null) {
- return false;
- }
- List<PartitionField> fields = spec.fields();
- if (fields.size() != 1) {
- return false;
- }
- PartitionField partitionField = fields.get(0);
- Type sourceType =
spec.schema().findType(partitionField.sourceId());
- // Historical void partition fields can outlive their dropped
source column.
- if (sourceType == null || sourceType.typeId() ==
Type.TypeID.TIMESTAMP_NANO) {
- // Calendar boundaries and the NULL sentinel can exceed
TIMESTAMP_NS's domain.
- // Leave pruning to Iceberg instead of building invalid Doris
RANGE boundaries.
- return false;
- }
- String transformName = partitionField.transform().toString();
- if (!YEAR.equals(transformName) && !MONTH.equals(transformName)
- && !DAY.equals(transformName) &&
!HOUR.equals(transformName)) {
- return false;
- }
-
allFields.add(table.schema().findColumnName(partitionField.sourceId()));
+ return IcebergMvPartitionSnapshot.supportsAllSpecs(table)
+ || IcebergMvPartitionSnapshot.qualifies(table, -1);
+ }
+
+ private static ConnectorMvccPartitionView
buildEvolvedMvccPartitionView(Table table, long pinnedSnapshotId) {
+ IcebergMvPartitionSnapshot snapshot =
IcebergMvPartitionSnapshot.load(table, pinnedSnapshotId);
+ if (!snapshot.isSupported()) {
+ LOG.debug("Iceberg table {} is not eligible for a partitioned MV:
{}",
+ table.name(), snapshot.getUnsupportedReason());
+ return ConnectorMvccPartitionView.unpartitioned();
+ }
+ Map<String, RangeBuild> ranges = new java.util.TreeMap<>();
+ for (IcebergMvPartitionSnapshot.Partition partition :
snapshot.getPartitions()) {
+ ranges.put(partition.getName(), buildRange(partition.getName(),
partition.getValue(),
Review Comment:
[P2] Handle the last valid DATE in identity partitions
A DATE identity value of `9999-12-31` now enters this range path. The day
transform calculates `+10000-01-01` as the exclusive upper bound, and
`PluginDrivenMvccExternalTable.toRangePartitionItem` fails to parse it as a
Doris DATE. This breaks MV planning and can also break an ordinary SELECT with
`enable_iceberg_internal_partition_pruning=true`, which previously handled the
value through the LIST view. Represent the exclusive upper bound as MAXVALUE or
fall back to native planning for this layout.
--
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]