Skip to content

Commit f071179

Browse files
check styles
1 parent c973f9d commit f071179

4 files changed

Lines changed: 79 additions & 61 deletions

File tree

core/src/main/java/org/apache/iceberg/SingleValueParser.java

Lines changed: 69 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -119,61 +119,14 @@ public static Object fromJson(Type type, JsonNode defaultValue) {
119119
}
120120
return uuid;
121121
case DATE:
122-
if (defaultValue.isTextual()) {
123-
return DateTimeUtil.isoDateToDays(defaultValue.textValue());
124-
} else if (defaultValue.isIntegralNumber() && defaultValue.canConvertToInt()) {
125-
return defaultValue.intValue();
126-
} else {
127-
throw new IllegalArgumentException(
128-
String.format("Cannot parse default as a %s value: %s", type, defaultValue));
129-
}
122+
return parseDateValue(type, defaultValue);
130123
case TIME:
131-
if (defaultValue.isTextual()) {
132-
return DateTimeUtil.isoTimeToMicros(defaultValue.textValue());
133-
} else if (defaultValue.isIntegralNumber() && defaultValue.canConvertToLong()) {
134-
return defaultValue.longValue();
135-
} else {
136-
throw new IllegalArgumentException(
137-
String.format("Cannot parse default as a %s value: %s", type, defaultValue));
138-
}
124+
return parseTimeValue(type, defaultValue);
139125
case TIMESTAMP:
140-
if (defaultValue.isTextual()) {
141-
if (((Types.TimestampType) type).shouldAdjustToUTC()) {
142-
String timestampTz = defaultValue.textValue();
143-
Preconditions.checkArgument(
144-
DateTimeUtil.isUTCTimestamptz(timestampTz),
145-
"Cannot parse default as a %s value: %s, offset must be +00:00",
146-
type,
147-
defaultValue);
148-
return DateTimeUtil.isoTimestamptzToMicros(timestampTz);
149-
} else {
150-
return DateTimeUtil.isoTimestampToMicros(defaultValue.textValue());
151-
}
152-
} else if (defaultValue.isIntegralNumber() && defaultValue.canConvertToLong()) {
153-
return defaultValue.longValue();
154-
} else {
155-
throw new IllegalArgumentException(
156-
String.format("Cannot parse default as a %s value: %s", type, defaultValue));
157-
}
126+
return parseTimestampValue(type, defaultValue);
158127
case TIMESTAMP_NANO:
159-
if (defaultValue.isTextual()) {
160-
if (((Types.TimestampNanoType) type).shouldAdjustToUTC()) {
161-
String timestampTzNano = defaultValue.textValue();
162-
Preconditions.checkArgument(
163-
DateTimeUtil.isUTCTimestamptz(timestampTzNano),
164-
"Cannot parse default as a %s value: %s, offset must be +00:00",
165-
type,
166-
defaultValue);
167-
return DateTimeUtil.isoTimestamptzToNanos(timestampTzNano);
168-
} else {
169-
return DateTimeUtil.isoTimestampToNanos(defaultValue.textValue());
170-
}
171-
} else if (defaultValue.isIntegralNumber() && defaultValue.canConvertToLong()) {
172-
return defaultValue.longValue();
173-
} else {
174-
throw new IllegalArgumentException(
175-
String.format("Cannot parse default as a %s value: %s", type, defaultValue));
176-
}
128+
return parseTimestampNanoValue(type, defaultValue);
129+
177130
case FIXED:
178131
Preconditions.checkArgument(
179132
defaultValue.isTextual(), "Cannot parse default as a %s value: %s", type, defaultValue);
@@ -434,4 +387,68 @@ public static void toJson(Type type, Object defaultValue, JsonGenerator generato
434387
throw new UnsupportedOperationException(String.format("Type: %s is not supported", type));
435388
}
436389
}
390+
391+
private static Object parseDateValue(Type type, JsonNode value) {
392+
if (value.isTextual()) {
393+
return DateTimeUtil.isoDateToDays(value.textValue());
394+
} else if (value.isIntegralNumber() && value.canConvertToInt()) {
395+
return value.intValue();
396+
} else {
397+
throw new IllegalArgumentException(
398+
String.format("Cannot parse default as a %s value: %s", type, value));
399+
}
400+
}
401+
402+
private static Object parseTimeValue(Type type, JsonNode value) {
403+
if (value.isTextual()) {
404+
return DateTimeUtil.isoTimeToMicros(value.textValue());
405+
} else if (value.isIntegralNumber() && value.canConvertToLong()) {
406+
return value.longValue();
407+
} else {
408+
throw new IllegalArgumentException(
409+
String.format("Cannot parse default as a %s value: %s", type, value));
410+
}
411+
}
412+
413+
private static Object parseTimestampValue(Type type, JsonNode value) {
414+
if (value.isTextual()) {
415+
if (((Types.TimestampType) type).shouldAdjustToUTC()) {
416+
String timestampTz = value.textValue();
417+
Preconditions.checkArgument(
418+
DateTimeUtil.isUTCTimestamptz(timestampTz),
419+
"Cannot parse default as a %s value: %s, offset must be +00:00",
420+
type,
421+
value);
422+
return DateTimeUtil.isoTimestamptzToMicros(timestampTz);
423+
} else {
424+
return DateTimeUtil.isoTimestampToMicros(value.textValue());
425+
}
426+
} else if (value.isIntegralNumber() && value.canConvertToLong()) {
427+
return value.longValue();
428+
} else {
429+
throw new IllegalArgumentException(
430+
String.format("Cannot parse default as a %s value: %s", type, value));
431+
}
432+
}
433+
434+
private static Object parseTimestampNanoValue(Type type, JsonNode value) {
435+
if (value.isTextual()) {
436+
if (((Types.TimestampNanoType) type).shouldAdjustToUTC()) {
437+
String timestampTzNano = value.textValue();
438+
Preconditions.checkArgument(
439+
DateTimeUtil.isUTCTimestamptz(timestampTzNano),
440+
"Cannot parse default as a %s value: %s, offset must be +00:00",
441+
type,
442+
value);
443+
return DateTimeUtil.isoTimestamptzToNanos(timestampTzNano);
444+
} else {
445+
return DateTimeUtil.isoTimestampToNanos(value.textValue());
446+
}
447+
} else if (value.isIntegralNumber() && value.canConvertToLong()) {
448+
return value.longValue();
449+
} else {
450+
throw new IllegalArgumentException(
451+
String.format("Cannot parse default as a %s value: %s", type, value));
452+
}
453+
}
437454
}

core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.apache.iceberg.Scan;
4949
import org.apache.iceberg.Schema;
5050
import org.apache.iceberg.SortOrder;
51-
import org.apache.iceberg.expressions.Expression;
5251
import org.apache.iceberg.Table;
5352
import org.apache.iceberg.TableMetadata;
5453
import org.apache.iceberg.TableOperations;
@@ -65,6 +64,7 @@
6564
import org.apache.iceberg.exceptions.NoSuchNamespaceException;
6665
import org.apache.iceberg.exceptions.NoSuchTableException;
6766
import org.apache.iceberg.exceptions.NoSuchViewException;
67+
import org.apache.iceberg.expressions.Expression;
6868
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
6969
import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
7070
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
@@ -658,7 +658,7 @@ public static PlanTableScanResponse planTableScan(
658658
.fromSnapshotInclusive(request.startSnapshotId())
659659
.toSnapshot(request.endSnapshotId());
660660

661-
configuredScan = configureScan(incrementalScan, request, table.schema());
661+
configuredScan = configureScan(incrementalScan, request, incrementalScan.schema());
662662
} else {
663663
// Regular table scan at a specific snapshot
664664
TableScan tableScan = table.newScan();
@@ -668,7 +668,7 @@ public static PlanTableScanResponse planTableScan(
668668
}
669669

670670
// Apply filters and projections using common method
671-
configuredScan = configureScan(tableScan, request, table.schema());
671+
configuredScan = configureScan(tableScan, request, tableScan.schema());
672672
}
673673

674674
if (shouldPlanAsync.test(configuredScan)) {

core/src/main/java/org/apache/iceberg/rest/requests/PlanTableScanRequest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ public void validate() {
156156
Preconditions.checkArgument(
157157
minRowsRequested >= 0L, "Invalid scan: minRowsRequested is negative");
158158
}
159+
160+
if (null != filterJson) {
161+
Preconditions.checkArgument(
162+
filterJson.isBoolean() || filterJson.isObject(),
163+
"Cannot parse expression from non-object: %s",
164+
filterJson);
165+
}
159166
}
160167

161168
@Override

spark/v4.0/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestRemoteScanPlanning.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.apache.iceberg.rest.RESTCatalogProperties;
2626
import org.apache.iceberg.spark.SparkCatalogConfig;
2727
import org.apache.iceberg.spark.sql.TestSelect;
28-
import org.junit.jupiter.api.TestTemplate;
2928
import org.junit.jupiter.api.extension.ExtendWith;
3029

3130
@ExtendWith(ParameterizedTestExtension.class)
@@ -47,9 +46,4 @@ protected static Object[][] parameters() {
4746
}
4847
};
4948
}
50-
51-
@TestTemplate
52-
public void testBinaryInFilter() {
53-
super.testBinaryInFilter();
54-
}
5549
}

0 commit comments

Comments
 (0)