amogh-jahagirdar commented on code in PR #14518:
URL: https://github.com/apache/iceberg/pull/14518#discussion_r2550891650
##########
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(
+ "{\"status\": \"completed\",\"storage-credentials\":
null}",
+ PARTITION_SPECS_BY_ID,
+ false)
+ .credentials())
+ .isEmpty();
+
+ assertThat(
+ PlanTableScanResponseParser.fromJson(
+ "{\"status\": \"completed\",\"storage-credentials\": []}",
+ PARTITION_SPECS_BY_ID,
+ false)
+ .credentials())
+ .isEmpty();
+
+ assertThatThrownBy(
+ () ->
+ PlanTableScanResponseParser.fromJson(
+ "{\"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");
Review Comment:
Minor: PlanStatus.Completed?
##########
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(
+ "{\"status\": \"completed\",\"storage-credentials\":
null}",
+ PARTITION_SPECS_BY_ID,
+ false)
+ .credentials())
+ .isEmpty();
+
+ assertThat(
+ PlanTableScanResponseParser.fromJson(
+ "{\"status\": \"completed\",\"storage-credentials\": []}",
+ PARTITION_SPECS_BY_ID,
+ false)
+ .credentials())
+ .isEmpty();
+
+ assertThatThrownBy(
+ () ->
+ PlanTableScanResponseParser.fromJson(
+ "{\"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(),
+ ImmutableCredential.builder()
+ .prefix("gs")
+ .config(
+ ImmutableMap.of(
+ "gcs.oauth2.token", "gcsToken2",
"gcs.oauth2.token-expires-at", "2000"))
+ .build());
+
+ PlanTableScanResponse response =
+ PlanTableScanResponse.builder()
+ .withPlanStatus(planStatus)
+ .withCredentials(credentials)
+ .withSpecsById(PARTITION_SPECS_BY_ID)
+ .build();
+
+ String expectedJson =
+ "{\n"
+ + " \"status\" : \"completed\",\n"
+ + " \"storage-credentials\" : [ {\n"
+ + " \"prefix\" : \"s3://custom-uri\",\n"
+ + " \"config\" : {\n"
+ + " \"s3.access-key-id\" : \"keyId\",\n"
+ + " \"s3.secret-access-key\" : \"accessKey\",\n"
+ + " \"s3.session-token\" : \"sessionToken\"\n"
+ + " }\n"
+ + " }, {\n"
+ + " \"prefix\" : \"gs://custom-uri\",\n"
+ + " \"config\" : {\n"
+ + " \"gcs.oauth2.token\" : \"gcsToken1\",\n"
+ + " \"gcs.oauth2.token-expires-at\" : \"1000\"\n"
+ + " }\n"
+ + " }, {\n"
+ + " \"prefix\" : \"gs\",\n"
+ + " \"config\" : {\n"
+ + " \"gcs.oauth2.token\" : \"gcsToken2\",\n"
+ + " \"gcs.oauth2.token-expires-at\" : \"2000\"\n"
+ + " }\n"
+ + " } ]\n"
+ + "}";
+
+ String json = PlanTableScanResponseParser.toJson(response, true);
+ assertThat(json).isEqualTo(expectedJson);
+
+ PlanTableScanResponse fromResponse =
+ PlanTableScanResponseParser.fromJson(json, PARTITION_SPECS_BY_ID,
false);
+ PlanTableScanResponse copyResponse =
+ PlanTableScanResponse.builder()
+ .withPlanStatus(fromResponse.planStatus())
+ .withPlanId(fromResponse.planId())
+ .withSpecsById(PARTITION_SPECS_BY_ID)
+ .withCredentials(credentials)
+ .build();
+
+ assertThat(PlanTableScanResponseParser.toJson(copyResponse,
true)).isEqualTo(expectedJson);
+ }
+
+ @Test
+ public void roundTripSerdeWithValidStatusAndFileScanTasksAndCredentials() {
+ ResidualEvaluator residualEvaluator =
+ ResidualEvaluator.of(SPEC, Expressions.equal("id", 1), true);
+ FileScanTask fileScanTask =
+ new BaseFileScanTask(
+ FILE_A,
+ new DeleteFile[] {FILE_A_DELETES},
+ SchemaParser.toJson(SCHEMA),
+ PartitionSpecParser.toJson(SPEC),
+ residualEvaluator);
+
+ PlanStatus planStatus = PlanStatus.fromName("completed");
Review Comment:
same as above, i think we can just use the enum directly
--
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]