hello-stephen commented on code in PR #71373:
URL: https://github.com/apache/doris/pull/71373#discussion_r4788200397


##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java:
##########
@@ -385,6 +385,24 @@ public static DataType getDataType(Slot s, int i, 
ConnectContext ctx, String par
     }
 
     public static MTMVAnalyzeQueryInfo analyzeQueryWithSql(MTMV mtmv, 
ConnectContext ctx) throws UserException {
+        // SQL parsing replaces the context; the caller still owns its 
captured pins and metadata leases.
+        StatementContext caller = ctx.getStatementContext();
+        try {
+            return analyzeQueryWithSqlInternal(mtmv, ctx);

Review Comment:
   [P2] Reuse the task's partition view during schema reanalysis
   
   For a `SCHEMA_CHANGE` refresh of an MV joining an evolved HMS Iceberg PCT 
input with an OLAP table, `MTMVTask.run` calls this method while holding the 
OLAP table read lock. Parsing installs a temporary context without the task's 
materialized snapshot. PCT qualification through 
`IcebergDlaTable.getPartitionType` can then read every live manifest under that 
lock. With `meta.cache.iceberg.partition.enable=false`, the reload can occur 
even on the same Iceberg snapshot, delaying DDL waiting for the write lock. 
Seed the temporary analysis context with the materialized task pins, or 
complete the external partition load before acquiring the locks.



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergUtils.java:
##########
@@ -2345,13 +2338,29 @@ static IcebergPartitionInfo 
loadPartitionInfo(ExternalTable dorisTable, Table ta
     static IcebergPartitionInfo loadPartitionInfo(String displayName, Table 
table,
             long snapshotId, long schemaId, ExecutionAuthenticator 
authenticator,
             boolean enableMappingVarbinary, boolean enableMappingTimestampTz) 
throws AnalysisException {
-        if (snapshotId == IcebergUtils.UNKNOWN_SNAPSHOT_ID) {
-            return IcebergPartitionInfo.empty();
+        if (snapshotId == IcebergUtils.UNKNOWN_SNAPSHOT_ID && 
isLegacySupportedRelatedTable(table)) {
+            return new IcebergPartitionInfo(Collections.emptyMap(), 
Collections.emptyMap(), Collections.emptyMap());
         }
         List<IcebergPartition> icebergPartitions;
         List<Column> partitionColumns;
         try {
-            icebergPartitions = authenticator.execute(() -> 
loadIcebergPartition(table, snapshotId));
+            if (IcebergMvPartitionSnapshot.supportsAllSpecs(table)) {
+                icebergPartitions = authenticator.execute(() -> 
loadIcebergPartition(table, snapshotId));
+            } else {
+                IcebergMvPartitionSnapshot projection = authenticator.execute(
+                        () -> IcebergMvPartitionSnapshot.load(table, 
snapshotId));
+                if (!projection.isSupported()) {
+                    return IcebergPartitionInfo.empty();

Review Comment:
   [P1] Reject incompatible Iceberg snapshots during MV rewrite
   
   Consider a partitioned MV over `OLAP o INNER JOIN HMS-Iceberg i ON o.d = 
i.d`, with daily ranges A and B on `o` and DATE-identity files only for B on 
`i`. After a complete MV refresh, replace Iceberg's identity transform with a 
bucket on the same DATE column, append a row in A and run `REFRESH TABLE`.
   
   This branch makes the Iceberg partition map empty even though the new 
snapshot contains A. `MTMVPartitionUtil.isSyncWithPartitions` accepts A's empty 
current and saved Iceberg name sets, and the PCT path skips the Iceberg table 
snapshot check. With external MV rewrite enabled, A can admit the MV as a 
candidate and HMS Iceberg skips union compensation. The matching query can then 
scan the stored MV and omit the newly joined A row. Carry the unsupported 
verdict into rewrite freshness and reject the candidate for that snapshot.



-- 
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]

Reply via email to