2525import org .apache .fluss .row .TimestampNtz ;
2626import org .apache .fluss .types .DataType ;
2727import org .apache .fluss .types .DataTypeRoot ;
28+ import org .apache .fluss .types .DataTypeChecks ;
2829import org .apache .fluss .types .DecimalType ;
29- import org .apache .fluss .types .LocalZonedTimestampType ;
3030import org .apache .fluss .types .RowType ;
31- import org .apache .fluss .types .TimestampType ;
3231
3332import javax .annotation .Nullable ;
3433
@@ -423,20 +422,23 @@ private RowToFieldConverter createRowToFieldConverter(DataType fieldType, Field
423422 int millis = row .getInt (pos );
424423 return LocalTime .ofNanoOfDay (millis * 1_000_000L );
425424 };
426- case TIMESTAMP_WITHOUT_TIME_ZONE :
425+ case TIMESTAMP_WITHOUT_TIME_ZONE : {
426+ final int precision = DataTypeChecks .getPrecision (fieldType );
427427 return (row , pos ) -> {
428428 if (row .isNullAt (pos )) {
429429 return null ;
430430 }
431- TimestampNtz timestampNtz = row .getTimestampNtz (pos , getPrecision ( fieldType ) );
431+ TimestampNtz timestampNtz = row .getTimestampNtz (pos , precision );
432432 return timestampNtz .toLocalDateTime ();
433433 };
434- case TIMESTAMP_WITH_LOCAL_TIME_ZONE :
434+ }
435+ case TIMESTAMP_WITH_LOCAL_TIME_ZONE : {
436+ final int precision = DataTypeChecks .getPrecision (fieldType );
435437 return (row , pos ) -> {
436438 if (row .isNullAt (pos )) {
437439 return null ;
438440 }
439- TimestampLtz timestampLtz = row .getTimestampLtz (pos , getPrecision ( fieldType ) );
441+ TimestampLtz timestampLtz = row .getTimestampLtz (pos , precision );
440442 if (fieldClass == Instant .class ) {
441443 return timestampLtz .toInstant ();
442444 } else if (fieldClass == OffsetDateTime .class ) {
@@ -448,6 +450,7 @@ private RowToFieldConverter createRowToFieldConverter(DataType fieldType, Field
448450 field .getName ()));
449451 }
450452 };
453+ }
451454 default :
452455 throw new UnsupportedOperationException (
453456 String .format (
@@ -535,24 +538,6 @@ public T fromRow(InternalRow row) {
535538 }
536539 }
537540
538- /**
539- * Gets the precision of a data type.
540- *
541- * @param dataType The data type
542- * @return The precision
543- */
544- private static int getPrecision (DataType dataType ) {
545- switch (dataType .getTypeRoot ()) {
546- case TIMESTAMP_WITHOUT_TIME_ZONE :
547- return ((TimestampType ) dataType ).getPrecision ();
548- case TIMESTAMP_WITH_LOCAL_TIME_ZONE :
549- return ((LocalZonedTimestampType ) dataType ).getPrecision ();
550- case DECIMAL :
551- return ((DecimalType ) dataType ).getPrecision ();
552- default :
553- return 0 ;
554- }
555- }
556541
557542 /**
558543 * Utility method to create a Set containing the specified Java type classes.
0 commit comments