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


##########
core/src/main/java/org/apache/iceberg/rest/responses/PlanTableScanResponseParser.java:
##########
@@ -92,13 +105,28 @@ public static PlanTableScanResponse fromJson(
     List<FileScanTask> fileScanTasks =
         TableScanResponseParser.parseFileScanTasks(json, deleteFiles, 
specsById, caseSensitive);
 
-    return PlanTableScanResponse.builder()
-        .withPlanId(planId)
-        .withPlanStatus(planStatus)
-        .withPlanTasks(planTasks)
-        .withFileScanTasks(fileScanTasks)
-        .withDeleteFiles(deleteFiles)
-        .withSpecsById(specsById)
-        .build();
+    PlanTableScanResponse.Builder builder =
+        PlanTableScanResponse.builder()
+            .withPlanId(planId)
+            .withPlanStatus(planStatus)
+            .withPlanTasks(planTasks)
+            .withFileScanTasks(fileScanTasks)
+            .withDeleteFiles(deleteFiles)
+            .withSpecsById(specsById);
+
+    if (json.hasNonNull(STORAGE_CREDENTIALS)) {
+      JsonNode credsNode = JsonUtil.get(STORAGE_CREDENTIALS, json);
+      Preconditions.checkArgument(
+          credsNode.isArray(), "Cannot parse credentials from non-array: %s", 
credsNode);
+
+      List<Credential> credentials = Lists.newArrayList();
+      for (JsonNode credential : credsNode) {
+        credentials.add(CredentialParser.fromJson(credential));
+      }
+
+      builder.withCredentials(credentials);

Review Comment:
   can we do 
   
   ```suggestion
       
builder.withCredentials(LoadCredentialsResponseParser.fromJson(json).credentials())
   ```
   
   
   Like we do : 
   
https://github.com/apache/iceberg/blob/f09dc3c108b746852a3febda49978ae1546797e8/core/src/main/java/org/apache/iceberg/rest/responses/LoadTableResponseParser.java#L100-L102



##########
core/src/test/java/org/apache/iceberg/rest/responses/TestPlanTableScanResponseParser.java:
##########
@@ -440,4 +444,231 @@ public void roundTripSerdeWithoutDeleteFiles() {
 
     
assertThat(PlanTableScanResponseParser.toJson(copyResponse)).isEqualTo(expectedJson);
   }
+
+  @Test
+  public void emptyOrInvalidCredentials() {
+    assertThat(
+            PlanTableScanResponseParser.fromJson(
+                    "{\"plan-status\": \"completed\",\"storage-credentials\": 
null}",
+                    PARTITION_SPECS_BY_ID,
+                    false)
+                .credentials())
+        .isEmpty();
+
+    assertThat(
+            PlanTableScanResponseParser.fromJson(
+                    "{\"plan-status\": \"completed\",\"storage-credentials\": 
[]}",
+                    PARTITION_SPECS_BY_ID,
+                    false)
+                .credentials())
+        .isEmpty();
+
+    assertThatThrownBy(
+            () ->
+                PlanTableScanResponseParser.fromJson(
+                    "{\"plan-status\": \"completed\",\"storage-credentials\": 
\"invalid\"}",
+                    PARTITION_SPECS_BY_ID,
+                    false))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Cannot parse credentials from non-array: \"invalid\"");
+  }
+
+  @Test
+  public void roundTripSerdeWithCredentials() {
+    PlanStatus planStatus = PlanStatus.fromName("completed");
+    List<Credential> credentials =
+        ImmutableList.of(
+            ImmutableCredential.builder()
+                .prefix("s3://custom-uri")
+                .config(
+                    ImmutableMap.of(
+                        "s3.access-key-id",
+                        "keyId",
+                        "s3.secret-access-key",
+                        "accessKey",
+                        "s3.session-token",
+                        "sessionToken"))
+                .build(),
+            ImmutableCredential.builder()
+                .prefix("gs://custom-uri")
+                .config(
+                    ImmutableMap.of(
+                        "gcs.oauth2.token", "gcsToken1", 
"gcs.oauth2.token-expires-at", "1000"))
+                .build(),

Review Comment:
   is this possible can there be location for both S3 and GCS ? do we expect 
Resolving FileIO in this case ?



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