Skip to content

Commit 50143fa

Browse files
committed
address comments
1 parent 1def20f commit 50143fa

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.time.LocalDateTime;
3535
import java.time.LocalTime;
3636
import java.time.OffsetDateTime;
37+
import java.util.List;
3738

3839
/**
3940
* Converter for writer path: converts POJO instances to Fluss InternalRow according to a (possibly
@@ -44,12 +45,14 @@ public final class PojoToRowConverter<T> {
4445
private final PojoType<T> pojoType;
4546
private final RowType tableSchema;
4647
private final RowType projection;
48+
private final List<String> projectionFieldNames;
4749
private final FieldToRow[] fieldConverters; // index corresponds to projection position
4850

4951
private PojoToRowConverter(PojoType<T> pojoType, RowType tableSchema, RowType projection) {
5052
this.pojoType = pojoType;
5153
this.tableSchema = tableSchema;
5254
this.projection = projection;
55+
this.projectionFieldNames = projection.getFieldNames();
5356
ConverterCommons.validatePojoMatchesTable(pojoType, tableSchema);
5457
ConverterCommons.validateProjectionSubset(projection, tableSchema);
5558
this.fieldConverters = createFieldConverters();
@@ -74,7 +77,7 @@ public GenericRow toRow(@Nullable T pojo) {
7477
} catch (Exception e) {
7578
throw new IllegalStateException(
7679
"Failed to access field '"
77-
+ projection.getFieldNames().get(i)
80+
+ projectionFieldNames.get(i)
7881
+ "' from POJO "
7982
+ pojoType.getPojoClass().getName(),
8083
e);
@@ -87,7 +90,7 @@ public GenericRow toRow(@Nullable T pojo) {
8790
private FieldToRow[] createFieldConverters() {
8891
FieldToRow[] arr = new FieldToRow[projection.getFieldCount()];
8992
for (int i = 0; i < projection.getFieldCount(); i++) {
90-
String fieldName = projection.getFieldNames().get(i);
93+
String fieldName = projectionFieldNames.get(i);
9194
DataType fieldType = projection.getTypeAt(i);
9295
PojoType.Property prop = requireProperty(fieldName);
9396
ConverterCommons.validateCompatibility(fieldType, prop);

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.time.LocalTime;
3838
import java.time.OffsetDateTime;
3939
import java.time.ZoneOffset;
40+
import java.util.List;
4041

4142
/**
4243
* Converter for scanner path: converts InternalRow (possibly projected) to POJO, leaving
@@ -47,12 +48,14 @@ public final class RowToPojoConverter<T> {
4748
private final PojoType<T> pojoType;
4849
private final RowType tableSchema;
4950
private final RowType projection;
51+
private final List<String> projectionFieldNames;
5052
private final RowToField[] rowReaders;
5153

5254
private RowToPojoConverter(PojoType<T> pojoType, RowType tableSchema, RowType projection) {
5355
this.pojoType = pojoType;
5456
this.tableSchema = tableSchema;
5557
this.projection = projection;
58+
this.projectionFieldNames = projection.getFieldNames();
5659
ConverterCommons.validatePojoMatchesTable(pojoType, tableSchema);
5760
ConverterCommons.validateProjectionSubset(projection, tableSchema);
5861
this.rowReaders = createRowReaders();
@@ -73,7 +76,7 @@ public T fromRow(@Nullable InternalRow row) {
7376
if (!row.isNullAt(i)) {
7477
Object v = rowReaders[i].convert(row, i);
7578
PojoType.Property prop =
76-
pojoType.getProperty(projection.getFieldNames().get(i));
79+
pojoType.getProperty(projectionFieldNames.get(i));
7780
if (v != null) {
7881
prop.write(pojo, v);
7982
}
@@ -97,7 +100,7 @@ public T fromRow(@Nullable InternalRow row) {
97100
private RowToField[] createRowReaders() {
98101
RowToField[] arr = new RowToField[projection.getFieldCount()];
99102
for (int i = 0; i < projection.getFieldCount(); i++) {
100-
String name = projection.getFieldNames().get(i);
103+
String name = projectionFieldNames.get(i);
101104
DataType type = projection.getTypeAt(i);
102105
PojoType.Property prop = requireProperty(name);
103106
ConverterCommons.validateCompatibility(type, prop);
@@ -147,10 +150,14 @@ private static RowToField createRowReader(DataType fieldType, PojoType.Property
147150
return RowToPojoConverter::convertDateValue;
148151
case TIME_WITHOUT_TIME_ZONE:
149152
return RowToPojoConverter::convertTimeValue;
150-
case TIMESTAMP_WITHOUT_TIME_ZONE:
151-
return (row, pos) -> convertTimestampNtzValue(fieldType, row, pos);
152-
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
153-
return (row, pos) -> convertTimestampLtzValue(fieldType, prop, row, pos);
153+
case TIMESTAMP_WITHOUT_TIME_ZONE: {
154+
final int precision = DataTypeChecks.getPrecision(fieldType);
155+
return (row, pos) -> convertTimestampNtzValue(precision, row, pos);
156+
}
157+
case TIMESTAMP_WITH_LOCAL_TIME_ZONE: {
158+
final int precision = DataTypeChecks.getPrecision(fieldType);
159+
return (row, pos) -> convertTimestampLtzValue(precision, prop, row, pos);
160+
}
154161
default:
155162
throw new UnsupportedOperationException(
156163
String.format(
@@ -224,8 +231,7 @@ private static LocalTime convertTimeValue(InternalRow row, int pos) {
224231
}
225232

226233
/** Converts a TIMESTAMP_WITHOUT_TIME_ZONE value to a LocalDateTime honoring precision. */
227-
private static Object convertTimestampNtzValue(DataType fieldType, InternalRow row, int pos) {
228-
final int precision = DataTypeChecks.getPrecision(fieldType);
234+
private static Object convertTimestampNtzValue(int precision, InternalRow row, int pos) {
229235
TimestampNtz t = row.getTimestampNtz(pos, precision);
230236
return t.toLocalDateTime();
231237
}
@@ -235,8 +241,7 @@ private static Object convertTimestampNtzValue(DataType fieldType, InternalRow r
235241
* depending on the target POJO property type.
236242
*/
237243
private static Object convertTimestampLtzValue(
238-
DataType fieldType, PojoType.Property prop, InternalRow row, int pos) {
239-
final int precision = DataTypeChecks.getPrecision(fieldType);
244+
int precision, PojoType.Property prop, InternalRow row, int pos) {
240245
TimestampLtz t = row.getTimestampLtz(pos, precision);
241246
if (prop.type == Instant.class) {
242247
return t.toInstant();

0 commit comments

Comments
 (0)