|
22 | 22 | import com.alibaba.fluss.row.InternalRow; |
23 | 23 | import com.alibaba.fluss.row.TimestampLtz; |
24 | 24 | import com.alibaba.fluss.row.TimestampNtz; |
25 | | -import com.alibaba.fluss.shaded.guava32.com.google.common.collect.Sets; |
26 | 25 | import com.alibaba.fluss.types.DataType; |
27 | 26 | import com.alibaba.fluss.types.DataTypeRoot; |
28 | 27 | import com.alibaba.fluss.types.DecimalType; |
|
42 | 41 | import java.time.LocalDateTime; |
43 | 42 | import java.time.LocalTime; |
44 | 43 | import java.time.OffsetDateTime; |
| 44 | +import java.util.Arrays; |
45 | 45 | import java.util.HashMap; |
| 46 | +import java.util.LinkedHashSet; |
46 | 47 | import java.util.Map; |
47 | 48 | import java.util.Set; |
48 | 49 |
|
@@ -74,27 +75,27 @@ public class PojoToRowConverter<T> { |
74 | 75 | private static final Map<DataTypeRoot, Set<Class<?>>> SUPPORTED_TYPES = new HashMap<>(); |
75 | 76 |
|
76 | 77 | 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)); |
84 | 85 | SUPPORTED_TYPES.put( |
85 | | - DataTypeRoot.CHAR, Sets.newHashSet(String.class, Character.class, char.class)); |
| 86 | + DataTypeRoot.CHAR, orderedSet(String.class, Character.class, char.class)); |
86 | 87 | 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)); |
93 | 94 | SUPPORTED_TYPES.put( |
94 | | - DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE, Sets.newHashSet(LocalDateTime.class)); |
| 95 | + DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE, orderedSet(LocalDateTime.class)); |
95 | 96 | SUPPORTED_TYPES.put( |
96 | 97 | DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE, |
97 | | - Sets.newHashSet(Instant.class, OffsetDateTime.class)); |
| 98 | + orderedSet(Instant.class, OffsetDateTime.class)); |
98 | 99 | // Add more supported types as needed |
99 | 100 |
|
100 | 101 | } |
@@ -332,4 +333,19 @@ public GenericRow convert(T pojo) { |
332 | 333 |
|
333 | 334 | return row; |
334 | 335 | } |
| 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 | + } |
335 | 351 | } |
0 commit comments