singhpk234 commented on code in PR #14480:
URL: https://github.com/apache/iceberg/pull/14480#discussion_r2485411695


##########
core/src/test/java/org/apache/iceberg/rest/RESTCatalogAdapter.java:
##########
@@ -294,6 +320,113 @@ public <T extends RESTResponse> T handleRequest(
           return castResponse(responseType, response);
         }
 
+      case PLAN_TABLE_SCAN:
+        {
+          TableIdentifier ident = tableIdentFromPathVars(vars);
+          PlanTableScanRequest request = 
castRequest(PlanTableScanRequest.class, body);
+          Table table = catalog.loadTable(ident);
+          TableScan tableScan = table.newScan();
+
+          if (request.snapshotId() != null) {
+            tableScan = tableScan.useSnapshot(request.snapshotId());
+          }
+          if (request.select() != null) {
+            tableScan = tableScan.select(request.select());
+          }
+          if (request.filter() != null) {
+            tableScan = tableScan.filter(request.filter());
+          }
+          if (request.statsFields() != null) {
+            tableScan = tableScan.includeColumnStats(request.statsFields());
+          }
+
+          tableScan = tableScan.caseSensitive(request.caseSensitive());
+
+          if (planningBehavior.shouldPlanTableScanAsync(tableScan)) {
+            String asyncPlanId = UUID.randomUUID().toString();
+            asyncPlanFiles(tableScan, asyncPlanId);
+            return castResponse(
+                responseType,
+                PlanTableScanResponse.builder()
+                    .withPlanId(asyncPlanId)
+                    .withPlanStatus(PlanStatus.SUBMITTED)
+                    .withSpecsById(table.specs())
+                    .build());
+          }
+
+          String planId = UUID.randomUUID().toString();
+          planFilesFor(tableScan, planId);
+          Pair<List<FileScanTask>, String> tasksAndPlan = 
initialScanTasksForPlan(planId);
+          return castResponse(
+              responseType,
+              PlanTableScanResponse.builder()
+                  .withPlanStatus(PlanStatus.COMPLETED)
+                  .withPlanTasks(nextPlanTasks(tasksAndPlan.second()))
+                  .withFileScanTasks(tasksAndPlan.first())
+                  .withDeleteFiles(
+                      tasksAndPlan.first().stream()
+                          .flatMap(t -> t.deletes().stream())
+                          .distinct()
+                          .collect(Collectors.toList()))
+                  .withSpecsById(table.specs())
+                  .build());
+        }
+
+      case FETCH_PLANNING_RESULT:
+        {
+          TableIdentifier ident = tableIdentFromPathVars(vars);
+          Table table = catalog.loadTable(ident);
+          String planId = planIDFromPathVars(vars);
+          Pair<List<FileScanTask>, String> tasksAndPlan = 
initialScanTasksForPlan(planId);
+          return castResponse(
+              responseType,
+              FetchPlanningResultResponse.builder()
+                  .withPlanStatus(PlanStatus.COMPLETED)
+                  .withDeleteFiles(
+                      tasksAndPlan.first().stream()
+                          .flatMap(t -> t.deletes().stream())
+                          .distinct()
+                          .collect(Collectors.toList()))
+                  .withFileScanTasks(tasksAndPlan.first())
+                  .withPlanTasks(nextPlanTasks(tasksAndPlan.second()))
+                  .withSpecsById(table.specs())
+                  .build());
+        }
+
+      case FETCH_SCAN_TASKS:
+        {
+          TableIdentifier ident = tableIdentFromPathVars(vars);
+          Table table = catalog.loadTable(ident);
+          FetchScanTasksRequest request = 
castRequest(FetchScanTasksRequest.class, body);
+          String planTask = request.planTask();
+          List<FileScanTask> fileScanTasks = 
planTaskToFileScanTasks.get(planTask);
+          if (fileScanTasks == null) {
+            throw new NoSuchPlanTaskException("Could not find tasks for plan 
task %s", planTask);
+          }
+
+          // Simple implementation, only have at most 1 "next" plan task to 
simulate pagination
+          return castResponse(
+              responseType,
+              FetchScanTasksResponse.builder()
+                  .withFileScanTasks(fileScanTasks)
+                  .withPlanTasks(nextPlanTasks(planTask))
+                  .withSpecsById(table.specs())

Review Comment:
   I just realized, this is not accordance to the spec, we don't return specs 
by id, whats happening presently is (Apologies, I missed this in the Req / 
Response model implementation)
   
   This response `FetchScanTasksResponse` toJson skips serializing specs by id 
and when de-serializing to FetchScanTasksResponse this is skipped again even 
though we know what is by parser context
   
   there are 2 approaches to fix this : 
   1. remove spec-by-id from the base class or reduce the visibilty
   2. populate the spec-by-id in the deserailzed response too 
   
   Approach 1 seems cleaner but we might have to have a rev-api entry, which 
imho should be fine since no java based rest catalog supports this yet.
   Approach 2 is also fine but it might give an impression we are not according 
to the spec. 
   please let me know your thoughts



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