@Override public Float convertToAvro(String value) { return StringUtils.isEmpty(value) ? null : Float.parseFloat(ParserUtils.transformNumberString(value, thousandsSepChar, decimalSepChar)); } }
@Override public Double convertToAvro(String value) { return StringUtils.isEmpty(value) ? null : Double.parseDouble(ParserUtils.transformNumberString(value, thousandsSepChar, decimalSepChar)); } }
@Override public String convertToAvro(String value) { return StringUtils.isEmpty(value) ? null : new BigDecimal(ParserUtils.transformNumberString(value, thousandsSepChar, decimalSepChar)).toPlainString(); } }
@Override public Integer convertToAvro(String value) { // String to Byte (datum type), then Byte (datum type to Integer (Avro-compatible types) // Because of migration issue, decode flag is always 'true' for byte type return StringUtils.isEmpty(value) ? null : ParserUtils.parseToByte(ParserUtils.transformNumberString(value, thousandsSepChar, decimalSepChar), true) .intValue(); } }
@Override public Integer convertToAvro(String value) { // String to Integer (datum type), then Integer (datum type to Integer (Avro-compatible types) return StringUtils.isEmpty(value) ? null : ParserUtils .parseToShort(ParserUtils.transformNumberString(value, thousandsSepChar, decimalSepChar), isDecode()) .intValue(); } }
@Override public Integer convertToAvro(String value) { return StringUtils.isEmpty(value) ? null : ParserUtils.parseToInteger(ParserUtils.transformNumberString(value, thousandsSepChar, decimalSepChar), isDecode()); } }
@Override public Long convertToAvro(String value) { return StringUtils.isEmpty(value) ? null : ParserUtils.parseToLong(ParserUtils.transformNumberString(value, thousandsSepChar, decimalSepChar), isDecode()); } }
@Test public void testTransformNumberString() throws Exception { // Transform xx[thousandsSeparator]xxx[thousandsSeparator]xxx[decimalSeparator]xx to xxxxxxxx.xx assertEquals("123456789.123", ParserUtils.transformNumberString("123,456,789.123", ',', '.')); assertEquals("123456789.123", ParserUtils.transformNumberString("123.456.789,123", '.', ',')); }