3737import java .time .LocalTime ;
3838import java .time .OffsetDateTime ;
3939import 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