3434import datafusion_common .DatafusionCommon ;
3535
3636/**
37- * Convert between Arrow Java {@link Schema} and the {@code datafusion_common.Schema} protobuf
38- * shape used by DataFusion plan messages such as {@code ListingTableScanNode.schema}.
37+ * Convert between Arrow Java {@link Schema} and the {@code datafusion_common.Schema} protobuf shape
38+ * used by DataFusion plan messages such as {@code ListingTableScanNode.schema}.
3939 *
4040 * <p>Supports the primitive Arrow types this project's tests exercise (Bool, signed/unsigned Int
41- * 8..64, Float32/64, Utf8, Date32, Decimal128). Anything else raises
42- * {@link UnsupportedOperationException} with a message naming the offending type.
41+ * 8..64, Float32/64, Utf8, Date32, Decimal128). Anything else raises {@link
42+ * UnsupportedOperationException} with a message naming the offending type.
4343 */
4444public final class SchemaConverter {
4545
@@ -94,23 +94,35 @@ static DatafusionCommon.ArrowType arrowTypeToProto(ArrowType t) {
9494 ArrowType .Int i = (ArrowType .Int ) t ;
9595 if (i .getIsSigned ()) {
9696 switch (i .getBitWidth ()) {
97- case 8 : return b .setINT8 (empty ).build ();
98- case 16 : return b .setINT16 (empty ).build ();
99- case 32 : return b .setINT32 (empty ).build ();
100- case 64 : return b .setINT64 (empty ).build ();
97+ case 8 :
98+ return b .setINT8 (empty ).build ();
99+ case 16 :
100+ return b .setINT16 (empty ).build ();
101+ case 32 :
102+ return b .setINT32 (empty ).build ();
103+ case 64 :
104+ return b .setINT64 (empty ).build ();
101105 default :
102106 throw new UnsupportedOperationException (
103- "Arrow type Int signed width " + i .getBitWidth () + " not yet supported by SchemaConverter" );
107+ "Arrow type Int signed width "
108+ + i .getBitWidth ()
109+ + " not yet supported by SchemaConverter" );
104110 }
105111 } else {
106112 switch (i .getBitWidth ()) {
107- case 8 : return b .setUINT8 (empty ).build ();
108- case 16 : return b .setUINT16 (empty ).build ();
109- case 32 : return b .setUINT32 (empty ).build ();
110- case 64 : return b .setUINT64 (empty ).build ();
113+ case 8 :
114+ return b .setUINT8 (empty ).build ();
115+ case 16 :
116+ return b .setUINT16 (empty ).build ();
117+ case 32 :
118+ return b .setUINT32 (empty ).build ();
119+ case 64 :
120+ return b .setUINT64 (empty ).build ();
111121 default :
112122 throw new UnsupportedOperationException (
113- "Arrow type Int unsigned width " + i .getBitWidth () + " not yet supported by SchemaConverter" );
123+ "Arrow type Int unsigned width "
124+ + i .getBitWidth ()
125+ + " not yet supported by SchemaConverter" );
114126 }
115127 }
116128 }
@@ -134,7 +146,9 @@ static DatafusionCommon.ArrowType arrowTypeToProto(ArrowType t) {
134146 ArrowType .Decimal d = (ArrowType .Decimal ) t ;
135147 if (d .getBitWidth () != 128 ) {
136148 throw new UnsupportedOperationException (
137- "Arrow type Decimal bit width " + d .getBitWidth () + " not yet supported by SchemaConverter" );
149+ "Arrow type Decimal bit width "
150+ + d .getBitWidth ()
151+ + " not yet supported by SchemaConverter" );
138152 }
139153 return b .setDECIMAL128 (
140154 DatafusionCommon .Decimal128Type .newBuilder ()
@@ -151,24 +165,38 @@ static ArrowType arrowTypeFromProto(DatafusionCommon.ArrowType p) {
151165 switch (p .getArrowTypeEnumCase ()) {
152166 case BOOL :
153167 return ArrowType .Bool .INSTANCE ;
154- case INT8 : return new ArrowType .Int (8 , true );
155- case INT16 : return new ArrowType .Int (16 , true );
156- case INT32 : return new ArrowType .Int (32 , true );
157- case INT64 : return new ArrowType .Int (64 , true );
158- case UINT8 : return new ArrowType .Int (8 , false );
159- case UINT16 : return new ArrowType .Int (16 , false );
160- case UINT32 : return new ArrowType .Int (32 , false );
161- case UINT64 : return new ArrowType .Int (64 , false );
162- case FLOAT32 : return new ArrowType .FloatingPoint (FloatingPointPrecision .SINGLE );
163- case FLOAT64 : return new ArrowType .FloatingPoint (FloatingPointPrecision .DOUBLE );
164- case UTF8 : return ArrowType .Utf8 .INSTANCE ;
165- case DATE32 : return new ArrowType .Date (DateUnit .DAY );
168+ case INT8 :
169+ return new ArrowType .Int (8 , true );
170+ case INT16 :
171+ return new ArrowType .Int (16 , true );
172+ case INT32 :
173+ return new ArrowType .Int (32 , true );
174+ case INT64 :
175+ return new ArrowType .Int (64 , true );
176+ case UINT8 :
177+ return new ArrowType .Int (8 , false );
178+ case UINT16 :
179+ return new ArrowType .Int (16 , false );
180+ case UINT32 :
181+ return new ArrowType .Int (32 , false );
182+ case UINT64 :
183+ return new ArrowType .Int (64 , false );
184+ case FLOAT32 :
185+ return new ArrowType .FloatingPoint (FloatingPointPrecision .SINGLE );
186+ case FLOAT64 :
187+ return new ArrowType .FloatingPoint (FloatingPointPrecision .DOUBLE );
188+ case UTF8 :
189+ return ArrowType .Utf8 .INSTANCE ;
190+ case DATE32 :
191+ return new ArrowType .Date (DateUnit .DAY );
166192 case DECIMAL128 :
167193 DatafusionCommon .Decimal128Type d = p .getDECIMAL128 ();
168194 return new ArrowType .Decimal (d .getPrecision (), d .getScale (), 128 );
169195 default :
170196 throw new UnsupportedOperationException (
171- "datafusion_common.ArrowType " + p .getArrowTypeEnumCase () + " not yet supported by SchemaConverter" );
197+ "datafusion_common.ArrowType "
198+ + p .getArrowTypeEnumCase ()
199+ + " not yet supported by SchemaConverter" );
172200 }
173201 }
174202}
0 commit comments