|
15 | 15 | * limitations under the License. |
16 | 16 | */ |
17 | 17 |
|
18 | | -package com.alibaba.fluss.client.utils; |
19 | | - |
20 | | -import com.alibaba.fluss.row.BinaryString; |
21 | | -import com.alibaba.fluss.row.Decimal; |
22 | | -import com.alibaba.fluss.row.GenericRow; |
23 | | -import com.alibaba.fluss.row.InternalRow; |
24 | | -import com.alibaba.fluss.row.TimestampLtz; |
25 | | -import com.alibaba.fluss.row.TimestampNtz; |
26 | | -import com.alibaba.fluss.types.DataType; |
27 | | -import com.alibaba.fluss.types.DataTypeRoot; |
28 | | -import com.alibaba.fluss.types.DecimalType; |
29 | | -import com.alibaba.fluss.types.LocalZonedTimestampType; |
30 | | -import com.alibaba.fluss.types.RowType; |
31 | | -import com.alibaba.fluss.types.TimestampType; |
32 | | -import com.alibaba.fluss.utils.MapUtils; |
| 18 | +package org.apache.fluss.client.utils; |
| 19 | + |
| 20 | +import org.apache.fluss.row.BinaryString; |
| 21 | +import org.apache.fluss.row.Decimal; |
| 22 | +import org.apache.fluss.row.GenericRow; |
| 23 | +import org.apache.fluss.row.InternalRow; |
| 24 | +import org.apache.fluss.row.TimestampLtz; |
| 25 | +import org.apache.fluss.row.TimestampNtz; |
| 26 | +import org.apache.fluss.types.DataType; |
| 27 | +import org.apache.fluss.types.DataTypeRoot; |
| 28 | +import org.apache.fluss.types.DecimalType; |
| 29 | +import org.apache.fluss.types.LocalZonedTimestampType; |
| 30 | +import org.apache.fluss.types.RowType; |
| 31 | +import org.apache.fluss.types.TimestampType; |
33 | 32 |
|
34 | 33 | import org.slf4j.Logger; |
35 | 34 | import org.slf4j.LoggerFactory; |
|
51 | 50 | import java.util.LinkedHashSet; |
52 | 51 | import java.util.Map; |
53 | 52 | import java.util.Set; |
54 | | -import java.util.concurrent.ConcurrentHashMap; |
55 | 53 |
|
56 | 54 | /** |
57 | 55 | * Helper class for converting Java objects to Fluss's {@link InternalRow} format and vice versa. |
58 | 56 | * |
59 | 57 | * <p>This utility uses reflection to map fields from POJOs to InternalRow and back based on a given |
60 | | - * schema. It includes caching mechanisms to avoid repeated reflection operations for the same POJO |
| 58 | + * schema. This implementation does not cache converters; getConverter creates a new instance each time. |
61 | 59 | * types. |
62 | 60 | * |
63 | 61 | * <p>Example usage: |
|
81 | 79 | public class ConverterUtils<T> { |
82 | 80 | private static final Logger LOG = LoggerFactory.getLogger(ConverterUtils.class); |
83 | 81 |
|
84 | | - /** Cache for converters to avoid repeated reflection operations. */ |
85 | | - private static final ConcurrentHashMap<CacheKey, ConverterUtils<?>> CONVERTER_CACHE = |
86 | | - MapUtils.newConcurrentHashMap(); |
87 | 82 |
|
88 | 83 | /** Map of supported Java types for each DataTypeRoot. */ |
89 | 84 | private static final Map<DataTypeRoot, Set<Class<?>>> SUPPORTED_TYPES = new HashMap<>(); |
@@ -168,9 +163,7 @@ private ConverterUtils(Class<T> pojoClass, RowType rowType) { |
168 | 163 | */ |
169 | 164 | @SuppressWarnings("unchecked") |
170 | 165 | public static <T> ConverterUtils<T> getConverter(Class<T> pojoClass, RowType rowType) { |
171 | | - CacheKey key = new CacheKey(pojoClass, rowType); |
172 | | - return (ConverterUtils<T>) |
173 | | - CONVERTER_CACHE.computeIfAbsent(key, k -> new ConverterUtils<>(pojoClass, rowType)); |
| 166 | + return new ConverterUtils<>(pojoClass, rowType); |
174 | 167 | } |
175 | 168 |
|
176 | 169 | /** Creates field converters for converting from POJO to Row for each field in the schema. */ |
@@ -580,31 +573,4 @@ private static LinkedHashSet<Class<?>> orderedSet(Class<?>... javaTypes) { |
580 | 573 | return linkedHashSet; |
581 | 574 | } |
582 | 575 |
|
583 | | - /** Key for caching converters. */ |
584 | | - private static class CacheKey { |
585 | | - private final Class<?> pojoClass; |
586 | | - private final RowType rowType; |
587 | | - |
588 | | - public CacheKey(Class<?> pojoClass, RowType rowType) { |
589 | | - this.pojoClass = pojoClass; |
590 | | - this.rowType = rowType; |
591 | | - } |
592 | | - |
593 | | - @Override |
594 | | - public boolean equals(Object o) { |
595 | | - if (this == o) { |
596 | | - return true; |
597 | | - } |
598 | | - if (o == null || getClass() != o.getClass()) { |
599 | | - return false; |
600 | | - } |
601 | | - CacheKey cacheKey = (CacheKey) o; |
602 | | - return pojoClass.equals(cacheKey.pojoClass) && rowType.equals(cacheKey.rowType); |
603 | | - } |
604 | | - |
605 | | - @Override |
606 | | - public int hashCode() { |
607 | | - return 31 * pojoClass.hashCode() + rowType.hashCode(); |
608 | | - } |
609 | | - } |
610 | 576 | } |
0 commit comments