@Test public void convertPrimitiveMaybeLogicalAllExceptDecimalTest() { Schema dateSchema = SchemaBuilder.int32().name(Date.LOGICAL_NAME).build(); assertEquals(TypeInfoFactory.intTypeInfo, HiveSchemaConverter.convertPrimitiveMaybeLogical(dateSchema)); Schema timeSchema = SchemaBuilder.int32().name(Time.LOGICAL_NAME).build(); assertEquals(TypeInfoFactory.intTypeInfo, HiveSchemaConverter.convertPrimitiveMaybeLogical(timeSchema)); Schema timestampSchema = SchemaBuilder.int64().name(Timestamp.LOGICAL_NAME).build(); assertEquals(TypeInfoFactory.longTypeInfo, HiveSchemaConverter.convertPrimitiveMaybeLogical(timestampSchema)); }
public static TypeInfo convertPrimitiveMaybeLogical(Schema schema) { if (schema.name() == null) { return convertPrimitive(schema); } if (Decimal.LOGICAL_NAME.equals(schema.name())) { String scale = schema.parameters().get(Decimal.SCALE_FIELD); String precision = schema.parameters().get(CONNECT_AVRO_DECIMAL_PRECISION_PROP); if (precision != null && Integer.parseInt(precision) > HIVE_DECIMAL_PRECISION_MAX) { throw new ConnectException( String.format("Illegal precision %s : Hive allows at most %d precision.", precision, HIVE_DECIMAL_PRECISION_MAX) ); } return new DecimalTypeInfo(HIVE_DECIMAL_PRECISION_MAX, Integer.parseInt(scale)); } else { return convertPrimitive(schema); } }
HiveSchemaConverter { public static TypeInfo convertPrimitiveMaybeLogical(Schema schema) { if (schema.name() == null) { return convertPrimitive(schema); } if (Decimal.LOGICAL_NAME.equals(schema.name())) { String scale = schema.parameters().get(Decimal.SCALE_FIELD); String precision = schema.parameters().get(CONNECT_AVRO_DECIMAL_PRECISION_PROP); if (precision != null && Integer.parseInt(precision) > HIVE_DECIMAL_PRECISION_MAX) { throw new ConnectException( String.format("Illegal precision %s : Hive allows at most %d precision.", precision, HIVE_DECIMAL_PRECISION_MAX) ); } return new DecimalTypeInfo(HIVE_DECIMAL_PRECISION_MAX, Integer.parseInt(scale)); } else { return convertPrimitive(schema); } } }
HiveSchemaConverter { public static TypeInfo convertPrimitiveMaybeLogical(Schema schema) { if (schema.name() == null) { return convertPrimitive(schema); } if (Decimal.LOGICAL_NAME.equals(schema.name())) { String scale = schema.parameters().get(Decimal.SCALE_FIELD); String precision = schema.parameters().get(CONNECT_AVRO_DECIMAL_PRECISION_PROP); if (precision != null && Integer.parseInt(precision) > HIVE_DECIMAL_PRECISION_MAX) { throw new ConnectException( String.format("Illegal precision %s : Hive allows at most %d precision.", precision, HIVE_DECIMAL_PRECISION_MAX) ); } return new DecimalTypeInfo(HIVE_DECIMAL_PRECISION_MAX, Integer.parseInt(scale)); } else { return convertPrimitive(schema); } }  }
HiveSchemaConverter { public static TypeInfo convertPrimitiveMaybeLogical(Schema schema) { if (schema.name() == null) { return convertPrimitive(schema); } if (Decimal.LOGICAL_NAME.equals(schema.name())) { String scale = schema.parameters().get(Decimal.SCALE_FIELD); String precision = schema.parameters().get(CONNECT_AVRO_DECIMAL_PRECISION_PROP); if (precision != null && Integer.parseInt(precision) > HIVE_DECIMAL_PRECISION_MAX) { throw new ConnectException( String.format("Illegal precision %s : Hive allows at most %d precision.", precision, HIVE_DECIMAL_PRECISION_MAX) ); } return new DecimalTypeInfo(HIVE_DECIMAL_PRECISION_MAX, Integer.parseInt(scale)); } else { return convertPrimitive(schema); } }  static List<FieldSchema> convertSchema(Schema schema); static List<FieldSchema> convertSchemaMaybeLogical(Schema schema); static TypeInfo convert(Schema schema); static TypeInfo convertMaybeLogical(Schema schema); static TypeInfo convertStruct(Schema schema); static TypeInfo convertArray(Schema schema); static TypeInfo convertMap(Schema schema); static TypeInfo convertPrimitive(Schema schema); static TypeInfo convertPrimitiveMaybeLogical(Schema schema); }
HiveSchemaConverter { public static TypeInfo convertPrimitiveMaybeLogical(Schema schema) { if (schema.name() == null) { return convertPrimitive(schema); } if (Decimal.LOGICAL_NAME.equals(schema.name())) { String scale = schema.parameters().get(Decimal.SCALE_FIELD); String precision = schema.parameters().get(CONNECT_AVRO_DECIMAL_PRECISION_PROP); if (precision != null && Integer.parseInt(precision) > HIVE_DECIMAL_PRECISION_MAX) { throw new ConnectException( String.format("Illegal precision %s : Hive allows at most %d precision.", precision, HIVE_DECIMAL_PRECISION_MAX) ); } return new DecimalTypeInfo(HIVE_DECIMAL_PRECISION_MAX, Integer.parseInt(scale)); } else { return convertPrimitive(schema); } }  static List<FieldSchema> convertSchema(Schema schema); static List<FieldSchema> convertSchemaMaybeLogical(Schema schema); static TypeInfo convert(Schema schema); static TypeInfo convertMaybeLogical(Schema schema); static TypeInfo convertStruct(Schema schema); static TypeInfo convertArray(Schema schema); static TypeInfo convertMap(Schema schema); static TypeInfo convertPrimitive(Schema schema); static TypeInfo convertPrimitiveMaybeLogical(Schema schema);  }