Skip to content

Commit 60e0490

Browse files
authored
[hotfix] Use ordered set in PojoToRowConverter to make test stable (#1059)
1 parent 4383783 commit 60e0490

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

fluss-flink/fluss-flink-common/src/main/java/com/alibaba/fluss/flink/utils/PojoToRowConverter.java

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.alibaba.fluss.row.InternalRow;
2323
import com.alibaba.fluss.row.TimestampLtz;
2424
import com.alibaba.fluss.row.TimestampNtz;
25-
import com.alibaba.fluss.shaded.guava32.com.google.common.collect.Sets;
2625
import com.alibaba.fluss.types.DataType;
2726
import com.alibaba.fluss.types.DataTypeRoot;
2827
import com.alibaba.fluss.types.DecimalType;
@@ -42,7 +41,9 @@
4241
import java.time.LocalDateTime;
4342
import java.time.LocalTime;
4443
import java.time.OffsetDateTime;
44+
import java.util.Arrays;
4545
import java.util.HashMap;
46+
import java.util.LinkedHashSet;
4647
import java.util.Map;
4748
import java.util.Set;
4849

@@ -74,27 +75,27 @@ public class PojoToRowConverter<T> {
7475
private static final Map<DataTypeRoot, Set<Class<?>>> SUPPORTED_TYPES = new HashMap<>();
7576

7677
static {
77-
SUPPORTED_TYPES.put(DataTypeRoot.BOOLEAN, Sets.newHashSet(Boolean.class, boolean.class));
78-
SUPPORTED_TYPES.put(DataTypeRoot.TINYINT, Sets.newHashSet(Byte.class, byte.class));
79-
SUPPORTED_TYPES.put(DataTypeRoot.SMALLINT, Sets.newHashSet(Short.class, short.class));
80-
SUPPORTED_TYPES.put(DataTypeRoot.INTEGER, Sets.newHashSet(Integer.class, int.class));
81-
SUPPORTED_TYPES.put(DataTypeRoot.BIGINT, Sets.newHashSet(Long.class, long.class));
82-
SUPPORTED_TYPES.put(DataTypeRoot.FLOAT, Sets.newHashSet(Float.class, float.class));
83-
SUPPORTED_TYPES.put(DataTypeRoot.DOUBLE, Sets.newHashSet(Double.class, double.class));
78+
SUPPORTED_TYPES.put(DataTypeRoot.BOOLEAN, orderedSet(Boolean.class, boolean.class));
79+
SUPPORTED_TYPES.put(DataTypeRoot.TINYINT, orderedSet(Byte.class, byte.class));
80+
SUPPORTED_TYPES.put(DataTypeRoot.SMALLINT, orderedSet(Short.class, short.class));
81+
SUPPORTED_TYPES.put(DataTypeRoot.INTEGER, orderedSet(Integer.class, int.class));
82+
SUPPORTED_TYPES.put(DataTypeRoot.BIGINT, orderedSet(Long.class, long.class));
83+
SUPPORTED_TYPES.put(DataTypeRoot.FLOAT, orderedSet(Float.class, float.class));
84+
SUPPORTED_TYPES.put(DataTypeRoot.DOUBLE, orderedSet(Double.class, double.class));
8485
SUPPORTED_TYPES.put(
85-
DataTypeRoot.CHAR, Sets.newHashSet(String.class, Character.class, char.class));
86+
DataTypeRoot.CHAR, orderedSet(String.class, Character.class, char.class));
8687
SUPPORTED_TYPES.put(
87-
DataTypeRoot.STRING, Sets.newHashSet(String.class, Character.class, char.class));
88-
SUPPORTED_TYPES.put(DataTypeRoot.BINARY, Sets.newHashSet(byte[].class));
89-
SUPPORTED_TYPES.put(DataTypeRoot.BYTES, Sets.newHashSet(byte[].class));
90-
SUPPORTED_TYPES.put(DataTypeRoot.DECIMAL, Sets.newHashSet(BigDecimal.class));
91-
SUPPORTED_TYPES.put(DataTypeRoot.DATE, Sets.newHashSet(LocalDate.class));
92-
SUPPORTED_TYPES.put(DataTypeRoot.TIME_WITHOUT_TIME_ZONE, Sets.newHashSet(LocalTime.class));
88+
DataTypeRoot.STRING, orderedSet(String.class, Character.class, char.class));
89+
SUPPORTED_TYPES.put(DataTypeRoot.BINARY, orderedSet(byte[].class));
90+
SUPPORTED_TYPES.put(DataTypeRoot.BYTES, orderedSet(byte[].class));
91+
SUPPORTED_TYPES.put(DataTypeRoot.DECIMAL, orderedSet(BigDecimal.class));
92+
SUPPORTED_TYPES.put(DataTypeRoot.DATE, orderedSet(LocalDate.class));
93+
SUPPORTED_TYPES.put(DataTypeRoot.TIME_WITHOUT_TIME_ZONE, orderedSet(LocalTime.class));
9394
SUPPORTED_TYPES.put(
94-
DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE, Sets.newHashSet(LocalDateTime.class));
95+
DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE, orderedSet(LocalDateTime.class));
9596
SUPPORTED_TYPES.put(
9697
DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE,
97-
Sets.newHashSet(Instant.class, OffsetDateTime.class));
98+
orderedSet(Instant.class, OffsetDateTime.class));
9899
// Add more supported types as needed
99100

100101
}
@@ -332,4 +333,19 @@ public GenericRow convert(T pojo) {
332333

333334
return row;
334335
}
336+
337+
/**
338+
* Utility method to create an ordered {@link LinkedHashSet} containing the specified Java type
339+
* classes.
340+
*
341+
* <p>The returned set maintains the insertion order of the provided classes.
342+
*
343+
* @param javaTypes The Java type classes to include in the set. May be one or more classes.
344+
* @return A new {@link LinkedHashSet} containing the given classes, preserving their order.
345+
*/
346+
private static LinkedHashSet<Class<?>> orderedSet(Class<?>... javaTypes) {
347+
LinkedHashSet<Class<?>> linkedHashSet = new LinkedHashSet<>();
348+
linkedHashSet.addAll(Arrays.asList(javaTypes));
349+
return linkedHashSet;
350+
}
335351
}

fluss-flink/fluss-flink-common/src/test/java/com/alibaba/fluss/flink/utils/PojoToRowConverterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public void testUnsupportedJavaClass() {
234234
assertThatThrownBy(() -> new PojoToRowConverter<>(ProductWithPrice.class, rowType))
235235
.isInstanceOf(UnsupportedOperationException.class)
236236
.hasMessageContaining(
237-
"Field Java type class java.lang.Long for field id is not supported, the supported Java types are [int, class java.lang.Integer]");
237+
"Field Java type class java.lang.Long for field id is not supported, the supported Java types are [class java.lang.Integer, int]");
238238
}
239239

240240
@Test

0 commit comments

Comments
 (0)