@Test public void testToDecimalConversion() { final LogicalTypes.Decimal decimalType = LogicalTypes.decimal(18, 8); final Schema fieldSchema = Schema.create(Type.BYTES); decimalType.addToSchema(fieldSchema); final Map<Object, String> expects = new HashMap<>(); expects.put(123d, "123.00000000"); expects.put(1234567890.12345678d, "1234567890.12345670"); expects.put(123456789.12345678d, "123456789.12345678"); expects.put(1234567890123456d, "1234567890123456.00000000"); expects.put(0.1234567890123456d, "0.12345679"); expects.put(new BigDecimal("123"), "123.00000000"); expects.put(new BigDecimal("1234567890.12345678"), "1234567890.12345678"); expects.put(new BigDecimal("123456789012345678"), "123456789012345678.00000000"); expects.put(new BigDecimal("0.123456789012345678"), "0.12345679"); expects.put("123", "123.00000000"); expects.put("1234567890.12345678", "1234567890.12345678"); expects.put("123456789012345678", "123456789012345678.00000000"); expects.put("0.1234567890123456", "0.12345679"); expects.put("Not a number", "java.lang.NumberFormatException"); expects.put(123, "123.00000000"); expects.put(-1234567, "-1234567.00000000"); expects.put(123L, "123.00000000"); expects.put(123456789012345678L, "123456789012345678.00000000"); expects.forEach((rawValue, expect) -> { final Object convertedValue; try { convertedValue = AvroTypeUtil.convertToAvroObject(rawValue, fieldSchema, StandardCharsets.UTF_8); } catch (Exception e) { if (expect.equals(e.getClass().getCanonicalName())) { return; } fail(String.format("Unexpected exception, %s with %s %s while expecting %s", e, rawValue.getClass().getSimpleName(), rawValue, expect)); return; } assertTrue(convertedValue instanceof ByteBuffer); final ByteBuffer serializedBytes = (ByteBuffer) convertedValue; final BigDecimal bigDecimal = new Conversions.DecimalConversion().fromBytes(serializedBytes, fieldSchema, decimalType); assertEquals(String.format("%s %s should be converted to %s", rawValue.getClass().getSimpleName(), rawValue, expect), expect, bigDecimal.toString()); }); }
public static Object convertToAvroObject(final Object rawValue, final Schema fieldSchema) { return convertToAvroObject(rawValue, fieldSchema, StandardCharsets.UTF_8); }
AvroTypeUtil { public static Object convertToAvroObject(final Object rawValue, final Schema fieldSchema) { return convertToAvroObject(rawValue, fieldSchema, StandardCharsets.UTF_8); } }
AvroTypeUtil { public static Object convertToAvroObject(final Object rawValue, final Schema fieldSchema) { return convertToAvroObject(rawValue, fieldSchema, StandardCharsets.UTF_8); }  }
AvroTypeUtil { public static Object convertToAvroObject(final Object rawValue, final Schema fieldSchema) { return convertToAvroObject(rawValue, fieldSchema, StandardCharsets.UTF_8); }  static Schema extractAvroSchema(final RecordSchema recordSchema); static DataType determineDataType(final Schema avroSchema); static DataType determineDataType(final Schema avroSchema, Map<String, DataType> knownRecordTypes); static RecordSchema createSchema(final Schema avroSchema); static RecordSchema createSchema(final Schema avroSchema, final String schemaText, final SchemaIdentifier schemaId); static boolean isNullable(final Schema schema); static Object[] convertByteArray(final byte[] bytes); static ByteBuffer convertByteArray(final Object[] bytes); static GenericRecord createAvroRecord(final Record record, final Schema avroSchema); static GenericRecord createAvroRecord(final Record record, final Schema avroSchema, final Charset charset); static Object convertToAvroObject(final Object rawValue, final Schema fieldSchema); static Object convertToAvroObject(final Object rawValue, final Schema fieldSchema, final Charset charset); static Map<String, Object> convertAvroRecordToMap(final GenericRecord avroRecord, final RecordSchema recordSchema); static Map<String, Object> convertAvroRecordToMap(final GenericRecord avroRecord, final RecordSchema recordSchema, final Charset charset); }
AvroTypeUtil { public static Object convertToAvroObject(final Object rawValue, final Schema fieldSchema) { return convertToAvroObject(rawValue, fieldSchema, StandardCharsets.UTF_8); }  static Schema extractAvroSchema(final RecordSchema recordSchema); static DataType determineDataType(final Schema avroSchema); static DataType determineDataType(final Schema avroSchema, Map<String, DataType> knownRecordTypes); static RecordSchema createSchema(final Schema avroSchema); static RecordSchema createSchema(final Schema avroSchema, final String schemaText, final SchemaIdentifier schemaId); static boolean isNullable(final Schema schema); static Object[] convertByteArray(final byte[] bytes); static ByteBuffer convertByteArray(final Object[] bytes); static GenericRecord createAvroRecord(final Record record, final Schema avroSchema); static GenericRecord createAvroRecord(final Record record, final Schema avroSchema, final Charset charset); static Object convertToAvroObject(final Object rawValue, final Schema fieldSchema); static Object convertToAvroObject(final Object rawValue, final Schema fieldSchema, final Charset charset); static Map<String, Object> convertAvroRecordToMap(final GenericRecord avroRecord, final RecordSchema recordSchema); static Map<String, Object> convertAvroRecordToMap(final GenericRecord avroRecord, final RecordSchema recordSchema, final Charset charset); static final String AVRO_SCHEMA_FORMAT; }