CTTY commented on code in PR #11947:
URL: https://github.com/apache/hudi/pull/11947#discussion_r1797748764


##########
hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/HoodieIncrSource.java:
##########
@@ -212,35 +257,43 @@ public Pair<Option<Dataset<Row>>, String> 
fetchNextBatch(Option<String> lastCkpt
           .collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
       reader = reader.options(optionsMap);
     }
+    boolean shouldFullScan =
+        
queryContext.getActiveTimeline().isBeforeTimelineStartsByCompletionTime(startTime)
+        && missingCheckpointStrategy == 
MissingCheckpointStrategy.READ_UPTO_LATEST_COMMIT;
     Dataset<Row> source;
-    // Do Incr pull. Set end instant if available
-    if (queryInfo.isIncremental()) {
-      source = reader
-          .options(readOpts)
-          .option(QUERY_TYPE().key(), QUERY_TYPE_INCREMENTAL_OPT_VAL())
-          .option(BEGIN_INSTANTTIME().key(), queryInfo.getStartInstant())
-          .option(END_INSTANTTIME().key(), queryInfo.getEndInstant())
-          .option(INCREMENTAL_FALLBACK_TO_FULL_TABLE_SCAN().key(),
-              props.getString(INCREMENTAL_FALLBACK_TO_FULL_TABLE_SCAN().key(),
-                  INCREMENTAL_FALLBACK_TO_FULL_TABLE_SCAN().defaultValue()))
-          .option(INCREMENTAL_READ_HANDLE_HOLLOW_COMMIT().key(), 
handlingMode.name())
-          .load(srcPath);
-    } else {
-      // if checkpoint is missing from source table, and if strategy is set to 
READ_UPTO_LATEST_COMMIT, we have to issue snapshot query
+    if (instantRange.isEmpty() || shouldFullScan) {
+      // snapshot query
       Dataset<Row> snapshot = reader
           .options(readOpts)
           .option(DataSourceReadOptions.QUERY_TYPE().key(), 
DataSourceReadOptions.QUERY_TYPE_SNAPSHOT_OPT_VAL())
           .load(srcPath);
       if (snapshotLoadQuerySplitter.isPresent()) {
-        queryInfo = 
snapshotLoadQuerySplitter.get().getNextCheckpoint(snapshot, queryInfo, 
sourceProfileSupplier);
+        queryContext = 
snapshotLoadQuerySplitter.get().getNextCheckpoint(snapshot, queryContext, 
sourceProfileSupplier);
+        // update endTime/next checkpoint
+        endTime = 
queryContext.getEndInstant().orElse(queryContext.getLastInstant());
       }
+      Set<String> validInstants = new HashSet<>(queryContext.getInstants());
+      snapshot = 
queryContext.getPredicateFilter().map(snapshot::filter).orElse(snapshot);
       source = snapshot
           // add filtering so that only interested records are returned.
-          .filter(String.format("%s > '%s'", 
HoodieRecord.COMMIT_TIME_METADATA_FIELD,
-              queryInfo.getStartInstant()))
+          // completion time comparison uses ( , ], but when comparing start 
time we need to use [, ]
+          .filter(String.format("%s >= '%s'", 
HoodieRecord.COMMIT_TIME_METADATA_FIELD,
+              queryContext.getStartInstant().get()))
           .filter(String.format("%s <= '%s'", 
HoodieRecord.COMMIT_TIME_METADATA_FIELD,
-              queryInfo.getEndInstant()));
-      source = 
queryInfo.getPredicateFilter().map(source::filter).orElse(source);
+              
queryContext.getEndInstant().orElse(queryContext.getLastInstant())))

Review Comment:
   There are only two cases for `queryContext.getStartInstant()` and 
`queryContext.getEndInstant()`:
   - Both of them are null
   - Both of them have values
   
   If both of them are null, then we would return early when checking 
`queryContext.isEmpty()` above



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

Reply via email to