|
23 | 23 | import static org.apache.parquet.schema.converters.ParquetEnumConverter.fromParquetEdgeInterpolationAlgorithm; |
24 | 24 | import static org.apache.parquet.schema.converters.ParquetEnumConverter.getPrimitive; |
25 | 25 | import static org.apache.parquet.schema.converters.ParquetEnumConverter.getType; |
| 26 | +import static org.apache.parquet.schema.converters.ParquetEnumConverter.toParquetOriginalType; |
26 | 27 | import static org.apache.parquet.schema.converters.ParquetEnumConverter.toParquetRepetition; |
27 | 28 |
|
28 | 29 | import java.util.ArrayList; |
|
47 | 48 | import org.apache.parquet.format.Type; |
48 | 49 | import org.apache.parquet.format.TypeDefinedOrder; |
49 | 50 | import org.apache.parquet.format.VariantType; |
| 51 | +import org.apache.parquet.schema.DecimalMetadata; |
50 | 52 | import org.apache.parquet.schema.GroupType; |
51 | 53 | import org.apache.parquet.schema.LogicalTypeAnnotation; |
52 | 54 | import org.apache.parquet.schema.MessageType; |
@@ -176,57 +178,10 @@ private static org.apache.parquet.schema.ColumnOrder fromParquetColumnOrder(Colu |
176 | 178 |
|
177 | 179 | // Visible for testing |
178 | 180 | LogicalTypeAnnotation getLogicalTypeAnnotation(ConvertedType type, SchemaElement schemaElement) { |
179 | | - switch (type) { |
180 | | - case UTF8: |
181 | | - return LogicalTypeAnnotation.stringType(); |
182 | | - case MAP: |
183 | | - return LogicalTypeAnnotation.mapType(); |
184 | | - case MAP_KEY_VALUE: |
185 | | - return LogicalTypeAnnotation.MapKeyValueTypeAnnotation.getInstance(); |
186 | | - case LIST: |
187 | | - return LogicalTypeAnnotation.listType(); |
188 | | - case ENUM: |
189 | | - return LogicalTypeAnnotation.enumType(); |
190 | | - case DECIMAL: |
191 | | - int scale = (schemaElement == null ? 0 : schemaElement.scale); |
192 | | - int precision = (schemaElement == null ? 0 : schemaElement.precision); |
193 | | - return LogicalTypeAnnotation.decimalType(scale, precision); |
194 | | - case DATE: |
195 | | - return LogicalTypeAnnotation.dateType(); |
196 | | - case TIME_MILLIS: |
197 | | - return LogicalTypeAnnotation.timeType(true, LogicalTypeAnnotation.TimeUnit.MILLIS); |
198 | | - case TIME_MICROS: |
199 | | - return LogicalTypeAnnotation.timeType(true, LogicalTypeAnnotation.TimeUnit.MICROS); |
200 | | - case TIMESTAMP_MILLIS: |
201 | | - return LogicalTypeAnnotation.timestampType(true, LogicalTypeAnnotation.TimeUnit.MILLIS); |
202 | | - case TIMESTAMP_MICROS: |
203 | | - return LogicalTypeAnnotation.timestampType(true, LogicalTypeAnnotation.TimeUnit.MICROS); |
204 | | - case INTERVAL: |
205 | | - return LogicalTypeAnnotation.IntervalLogicalTypeAnnotation.getInstance(); |
206 | | - case INT_8: |
207 | | - return LogicalTypeAnnotation.intType(8, true); |
208 | | - case INT_16: |
209 | | - return LogicalTypeAnnotation.intType(16, true); |
210 | | - case INT_32: |
211 | | - return LogicalTypeAnnotation.intType(32, true); |
212 | | - case INT_64: |
213 | | - return LogicalTypeAnnotation.intType(64, true); |
214 | | - case UINT_8: |
215 | | - return LogicalTypeAnnotation.intType(8, false); |
216 | | - case UINT_16: |
217 | | - return LogicalTypeAnnotation.intType(16, false); |
218 | | - case UINT_32: |
219 | | - return LogicalTypeAnnotation.intType(32, false); |
220 | | - case UINT_64: |
221 | | - return LogicalTypeAnnotation.intType(64, false); |
222 | | - case JSON: |
223 | | - return LogicalTypeAnnotation.jsonType(); |
224 | | - case BSON: |
225 | | - return LogicalTypeAnnotation.bsonType(); |
226 | | - default: |
227 | | - throw new RuntimeException( |
228 | | - "Can't convert converted type to logical type, unknown converted type " + type); |
229 | | - } |
| 181 | + int scale = (schemaElement == null ? 0 : schemaElement.scale); |
| 182 | + int precision = (schemaElement == null ? 0 : schemaElement.precision); |
| 183 | + return LogicalTypeAnnotation.fromOriginalType( |
| 184 | + toParquetOriginalType(type), new DecimalMetadata(scale, precision)); |
230 | 185 | } |
231 | 186 |
|
232 | 187 | LogicalTypeAnnotation getLogicalTypeAnnotation(LogicalType type) { |
|
0 commit comments