This is an automated email from the ASF dual-hosted git repository.
singhpk234 pushed a commit to branch 1.10.x
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/1.10.x by this push:
new 4112dad0d0 Align PlanTableScanRequest filter with OpenAPI spec
4112dad0d0 is described below
commit 4112dad0d0045667cf3eb5d782b2fa0c64028a41
Author: geruh <[email protected]>
AuthorDate: Fri Nov 21 18:24:29 2025 -0800
Align PlanTableScanRequest filter with OpenAPI spec
---
.../rest/requests/PlanTableScanRequestParser.java | 5 ++--
.../requests/TestPlanTableScanRequestParser.java | 33 ++++++++++++++++++++--
2 files changed, 34 insertions(+), 4 deletions(-)
diff --git
a/core/src/main/java/org/apache/iceberg/rest/requests/PlanTableScanRequestParser.java
b/core/src/main/java/org/apache/iceberg/rest/requests/PlanTableScanRequestParser.java
index 6801330466..040236e1fb 100644
---
a/core/src/main/java/org/apache/iceberg/rest/requests/PlanTableScanRequestParser.java
+++
b/core/src/main/java/org/apache/iceberg/rest/requests/PlanTableScanRequestParser.java
@@ -78,7 +78,8 @@ public class PlanTableScanRequestParser {
}
if (request.filter() != null) {
- gen.writeStringField(FILTER, ExpressionParser.toJson(request.filter()));
+ gen.writeFieldName(FILTER);
+ ExpressionParser.toJson(request.filter(), gen);
}
gen.writeBooleanField(CASE_SENSITIVE, request.caseSensitive());
@@ -106,7 +107,7 @@ public class PlanTableScanRequestParser {
Expression filter = null;
if (json.has(FILTER)) {
- filter = ExpressionParser.fromJson(json.get(FILTER).textValue());
+ filter = ExpressionParser.fromJson(json.get(FILTER));
}
boolean caseSensitive = true;
diff --git
a/core/src/test/java/org/apache/iceberg/rest/requests/TestPlanTableScanRequestParser.java
b/core/src/test/java/org/apache/iceberg/rest/requests/TestPlanTableScanRequestParser.java
index 55929d53d3..bf9c2b8caa 100644
---
a/core/src/test/java/org/apache/iceberg/rest/requests/TestPlanTableScanRequestParser.java
+++
b/core/src/test/java/org/apache/iceberg/rest/requests/TestPlanTableScanRequestParser.java
@@ -111,7 +111,7 @@ public class TestPlanTableScanRequestParser {
String expectedJson =
"{\"snapshot-id\":1,"
- + "\"filter\":\"false\","
+ + "\"filter\":false,"
+ "\"case-sensitive\":true,"
+ "\"use-snapshot-schema\":false}";
@@ -157,7 +157,7 @@ public class TestPlanTableScanRequestParser {
"{\"start-snapshot-id\":1,"
+ "\"end-snapshot-id\":2,"
+ "\"select\":[\"col1\",\"col2\"],"
- + "\"filter\":\"true\","
+ + "\"filter\":true,"
+ "\"case-sensitive\":false,"
+ "\"use-snapshot-schema\":true,"
+ "\"stats-fields\":[\"col1\",\"col2\"]}";
@@ -188,4 +188,33 @@ public class TestPlanTableScanRequestParser {
assertThat(str).contains("useSnapshotSchema=true");
assertThat(str).contains("statsFields=[stat1]");
}
+
+ @Test
+ public void roundTripSerdeWithFilterExpression() {
+ PlanTableScanRequest request =
+ PlanTableScanRequest.builder()
+ .withSnapshotId(1L)
+ .withFilter(Expressions.equal("id", 1))
+ .build();
+
+ String expectedJson =
+ "{\"snapshot-id\":1,"
+ + "\"filter\":{\"type\":\"eq\",\"term\":\"id\",\"value\":1},"
+ + "\"case-sensitive\":true,"
+ + "\"use-snapshot-schema\":false}";
+
+ String json = PlanTableScanRequestParser.toJson(request, false);
+ assertThat(json).isEqualTo(expectedJson);
+
assertThat(PlanTableScanRequestParser.toJson(PlanTableScanRequestParser.fromJson(json),
false))
+ .isEqualTo(expectedJson);
+ }
+
+ @Test
+ public void testFilterFieldWithExplicitNullThrowsError() {
+ String json =
"{\"snapshot-id\":123,\"filter\":null,\"case-sensitive\":true}";
+
+ assertThatThrownBy(() -> PlanTableScanRequestParser.fromJson(json))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Cannot parse expression from non-object: null");
+ }
}