3131import org .apache .hudi .internal .schema .Types ;
3232import org .apache .hudi .internal .schema .utils .InternalSchemaUtils ;
3333
34- import org .apache .avro .LogicalType ;
3534import org .apache .avro .LogicalTypes ;
3635import org .apache .avro .Schema ;
3736
@@ -301,42 +300,8 @@ private static Type visitSchemaToBuildType(HoodieSchema schema, Deque<String> vi
301300 }
302301 }
303302
304- private static Type visitPrimitiveToBuildInternalType (HoodieSchema hoodieSchema ) {
305- Schema primitive = hoodieSchema .toAvroSchema ();
306- LogicalType logical = primitive .getLogicalType ();
307- if (logical != null ) {
308- String name = logical .getName ();
309- if (logical instanceof LogicalTypes .Decimal ) {
310- if (primitive .getType () == Schema .Type .FIXED ) {
311- return Types .DecimalTypeFixed .get (((LogicalTypes .Decimal ) logical ).getPrecision (),
312- ((LogicalTypes .Decimal ) logical ).getScale (), primitive .getFixedSize ());
313- } else if (primitive .getType () == Schema .Type .BYTES ) {
314- return Types .DecimalTypeBytes .get (
315- ((LogicalTypes .Decimal ) logical ).getPrecision (),
316- ((LogicalTypes .Decimal ) logical ).getScale ());
317- } else {
318- throw new IllegalArgumentException ("Unsupported primitive type for Decimal: " + primitive .getType ().getName ());
319- }
320- } else if (logical instanceof LogicalTypes .Date ) {
321- return Types .DateType .get ();
322- } else if (logical instanceof LogicalTypes .TimeMillis ) {
323- return Types .TimeMillisType .get ();
324- } else if (logical instanceof LogicalTypes .TimeMicros ) {
325- return Types .TimeType .get ();
326- } else if (logical instanceof LogicalTypes .TimestampMillis ) {
327- return Types .TimestampMillisType .get ();
328- } else if (logical instanceof LogicalTypes .TimestampMicros ) {
329- return Types .TimestampType .get ();
330- } else if (logical instanceof LogicalTypes .LocalTimestampMillis ) {
331- return Types .LocalTimestampMillisType .get ();
332- } else if (logical instanceof LogicalTypes .LocalTimestampMicros ) {
333- return Types .LocalTimestampMicrosType .get ();
334- } else if (LogicalTypes .uuid ().getName ().equals (name )) {
335- return Types .UUIDType .get ();
336- }
337- }
338-
339- switch (primitive .getType ()) {
303+ private static Type visitPrimitiveToBuildInternalType (HoodieSchema schema ) {
304+ switch (schema .getType ()) {
340305 case BOOLEAN :
341306 return Types .BooleanType .get ();
342307 case INT :
@@ -351,13 +316,41 @@ private static Type visitPrimitiveToBuildInternalType(HoodieSchema hoodieSchema)
351316 case ENUM :
352317 return Types .StringType .get ();
353318 case FIXED :
354- return Types .FixedType .getFixed (primitive .getFixedSize ());
319+ return Types .FixedType .getFixed (schema .getFixedSize ());
355320 case BYTES :
356321 return Types .BinaryType .get ();
322+ case UUID :
323+ return Types .UUIDType .get ();
324+ case DECIMAL :
325+ HoodieSchema .Decimal decimalSchema = (HoodieSchema .Decimal ) schema ;
326+ if (decimalSchema .isFixed ()) {
327+ return Types .DecimalTypeFixed .get (decimalSchema .getPrecision (), decimalSchema .getScale (), decimalSchema .getFixedSize ());
328+ }
329+ return Types .DecimalType .get (decimalSchema .getPrecision (), decimalSchema .getScale ());
330+ case TIME :
331+ HoodieSchema .Time timeSchema = (HoodieSchema .Time ) schema ;
332+ if (timeSchema .getPrecision () == HoodieSchema .TimePrecision .MICROS ) {
333+ return Types .TimeType .get ();
334+ } else if (timeSchema .getPrecision () == HoodieSchema .TimePrecision .MILLIS ) {
335+ return Types .TimeMillisType .get ();
336+ } else {
337+ throw new UnsupportedOperationException ("Unsupported time precision: " + timeSchema .getPrecision ());
338+ }
339+ case TIMESTAMP :
340+ HoodieSchema .Timestamp timestampSchema = (HoodieSchema .Timestamp ) schema ;
341+ if (timestampSchema .getPrecision () == HoodieSchema .TimePrecision .MICROS ) {
342+ return timestampSchema .isUtcAdjusted () ? Types .TimestampType .get () : Types .LocalTimestampMicrosType .get ();
343+ } else if (timestampSchema .getPrecision () == HoodieSchema .TimePrecision .MILLIS ) {
344+ return timestampSchema .isUtcAdjusted () ? Types .TimestampMillisType .get () : Types .LocalTimestampMillisType .get ();
345+ } else {
346+ throw new UnsupportedOperationException ("Unsupported timestamp precision: " + timestampSchema .getPrecision ());
347+ }
348+ case DATE :
349+ return Types .DateType .get ();
357350 case NULL :
358351 return null ;
359352 default :
360- throw new UnsupportedOperationException ("Unsupported primitive type: " + primitive );
353+ throw new UnsupportedOperationException ("Unsupported primitive type: " + schema . getType () );
361354 }
362355 }
363356
0 commit comments