Skip to content

Commit 2bd6108

Browse files
committed
[fluss-client] Change validateCompatibility logic for MAP and ARRAY types
1 parent f0fd9eb commit 2bd6108

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

fluss-client/src/main/java/org/apache/fluss/client/converter/ConverterCommons.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
import java.math.BigDecimal;
2626
import java.util.Arrays;
27+
import java.util.Collection;
2728
import java.util.EnumMap;
28-
import java.util.EnumSet;
2929
import java.util.HashSet;
3030
import java.util.List;
3131
import java.util.Map;
@@ -41,8 +41,6 @@
4141
final class ConverterCommons {
4242

4343
static final Map<DataTypeRoot, Set<Class<?>>> SUPPORTED_TYPES = createSupportedTypes();
44-
static final Set<DataTypeRoot> SUPPORTED_COMPLEX_TYPES =
45-
EnumSet.of(DataTypeRoot.ARRAY, DataTypeRoot.MAP);
4644

4745
private static Map<DataTypeRoot, Set<Class<?>>> createSupportedTypes() {
4846
Map<DataTypeRoot, Set<Class<?>>> map = new EnumMap<>(DataTypeRoot.class);
@@ -64,8 +62,6 @@ private static Map<DataTypeRoot, Set<Class<?>>> createSupportedTypes() {
6462
map.put(
6563
DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE,
6664
setOf(java.time.Instant.class, java.time.OffsetDateTime.class));
67-
map.put(DataTypeRoot.ARRAY, setOf(java.util.Arrays.class));
68-
map.put(DataTypeRoot.MAP, setOf(java.util.Map.class));
6965
return map;
7066
}
7167

@@ -115,16 +111,36 @@ static void validateProjectionSubset(RowType projection, RowType tableSchema) {
115111
}
116112

117113
static void validateCompatibility(DataType fieldType, PojoType.Property prop) {
118-
Set<Class<?>> supported = SUPPORTED_TYPES.get(fieldType.getTypeRoot());
114+
DataTypeRoot typeRoot = fieldType.getTypeRoot();
119115
Class<?> actual = prop.type;
116+
if (typeRoot == DataTypeRoot.ARRAY) {
117+
if (!actual.isArray() && !Collection.class.isAssignableFrom(actual)) {
118+
throw new IllegalArgumentException(
119+
String.format(
120+
"Field '%s' must be an array or Collection for ARRAY type, got %s",
121+
prop.name, actual.getName()));
122+
}
123+
return;
124+
}
125+
126+
if (typeRoot == DataTypeRoot.MAP) {
127+
if (!Map.class.isAssignableFrom(actual)) {
128+
throw new IllegalArgumentException(
129+
String.format(
130+
"Field '%s' must be a Map for MAP type, got %s",
131+
prop.name, actual.getName()));
132+
}
133+
return;
134+
}
135+
136+
Set<Class<?>> supported = SUPPORTED_TYPES.get(fieldType.getTypeRoot());
120137
if (supported == null) {
121138
throw new UnsupportedOperationException(
122139
String.format(
123140
"Unsupported field type %s for field %s.",
124141
fieldType.getTypeRoot(), prop.name));
125142
}
126-
if (!supported.contains(actual)
127-
& !SUPPORTED_COMPLEX_TYPES.contains(fieldType.getTypeRoot())) {
143+
if (!supported.contains(actual)) {
128144
throw new IllegalArgumentException(
129145
String.format(
130146
"Field '%s' in POJO has Java type %s which is incompatible with Fluss type %s. Supported Java types: %s",

fluss-client/src/test/java/org/apache/fluss/client/converter/ConvertersTestFixtures.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ public int hashCode() {
193193
timestampLtzField,
194194
offsetDateTimeField,
195195
mapField);
196-
result = 31 * result + Arrays.hashCode(bytesField) + Arrays.hashCode(arrayField);
196+
result = 31 * result + Arrays.hashCode(bytesField);
197+
result = 31 * result + Arrays.hashCode(arrayField);
197198
return result;
198199
}
199200
}

0 commit comments

Comments
 (0)