本文整理了Java中org.talend.daikon.avro.AvroUtils._decimal()
方法的一些代码示例,展示了AvroUtils._decimal()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AvroUtils._decimal()
方法的具体详情如下:
包路径:org.talend.daikon.avro.AvroUtils
类名称:AvroUtils
方法名:_decimal
暂无
代码示例来源:origin: Talend/components
@Override
public String convertToDatum(T value) {
if (value == null) {
return null;
}
if (thousandsSepChar != null || decimalSepChar != null) {
return FormatterUtils.formatNumber(new BigDecimal(String.valueOf(value)).toPlainString(), thousandsSepChar,
decimalSepChar);
} else {
if (value instanceof BigDecimal) {
String precision = field.getProp(SchemaConstants.TALEND_COLUMN_PRECISION);
if (precision != null) {
return ((BigDecimal) value).setScale(Integer.valueOf(precision), RoundingMode.HALF_UP).toPlainString();
} else {
return ((BigDecimal) value).toPlainString();
}
} else if (AvroUtils.isSameType(AvroUtils._decimal(), AvroUtils.unwrapIfNullable(field.schema()))) {
String precision = field.getProp(SchemaConstants.TALEND_COLUMN_PRECISION);
if (precision != null) {
return new BigDecimal(String.valueOf(value)).setScale(Integer.valueOf(precision), RoundingMode.HALF_UP)
.toPlainString();
}
}
return String.valueOf(value);
}
}
代码示例来源:origin: Talend/components
/**
* Checks {@link TalendType#convertFromAvro(Schema)} converts string avro type with java-class flag "java.math.BigDecimal" to
* "id_BigDecimal" di type
*/
@Test
public void testConvertFromAvroBigDecimal() {
TalendType expectedType = TalendType.BIG_DECIMAL;
Schema fieldSchema = AvroUtils._decimal();
assertEquals(expectedType, TalendType.convertFromAvro(fieldSchema));
}
代码示例来源:origin: Talend/components
/**
* Checks {@link AvroTypeConverter#convertToAvro(String, String)} returns String avro schema with
* "java-class"=java.math.BigDecimal in case TalendType.BIG_DECIMAL Talend type is passed
*/
@Test
public void testConvertToAvroBigDecimal() {
Schema expectedSchema = AvroUtils._decimal();
assertEquals(expectedSchema, AvroTypeConverter.convertToAvro(TalendType.BIG_DECIMAL, null));
}
代码示例来源:origin: org.talend.components/components-dataprep
/**
* A helper method to convert the String representation of a datum in the DataPrep system to the Avro type that
* matches the Schema generated for it.
*
* @param f is field in Avro Schema.
* @return converter for a given type.
*/
public AvroConverter<String, ?> getConverterFromString(org.apache.avro.Schema.Field f) {
Schema fieldSchema = AvroUtils.unwrapIfNullable(f.schema());
// FIXME use avro type to decide the converter is not correct if the user change the avro type, Date to String
// for instance
if (AvroUtils.isSameType(fieldSchema, AvroUtils._boolean())) {
return new StringToBooleanConverter(f);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._decimal())) {
return new StringToDecimalConverter(f);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._double())) {
return new StringToDoubleConverter(f);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._int())) {
return new StringToIntegerConverter(f);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._date())) {
return new StringToDateConverter(f);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._string())) {
return super.getConverter(String.class);
}
throw new UnsupportedOperationException("The type " + fieldSchema.getType() + " is not supported."); //$NON-NLS-1$ //$NON-NLS-2$
}
代码示例来源:origin: org.talend.components/components-common
return AvroUtils._character();
case BIG_DECIMAL:
return AvroUtils._decimal();
case DATE:
return AvroUtils._logicalTimestamp();
代码示例来源:origin: org.talend.components/components-salesforce
/**
* A helper method to convert the String representation of a datum in the Salesforce system to the Avro type that
* matches the Schema generated for it.
*
* @param f
* @return
*/
public AvroConverter<String, ?> getConverterFromString(org.apache.avro.Schema.Field f) {
Schema fieldSchema = AvroUtils.unwrapIfNullable(f.schema());
// FIXME use avro type to decide the converter is not correct if the user change the avro type, Date to String
// for instance
if (AvroUtils.isSameType(fieldSchema, AvroUtils._boolean())) {
return new StringToBooleanConverter(f);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._decimal())) {
return new StringToDecimalConverter(f);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._double())) {
return new StringToDoubleConverter(f);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._int())) {
return new StringToIntegerConverter(f);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._date())) {
return new StringToDateConverter(f);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._bytes())) {
return new StringToBytesConverter(f);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._string())) {
return super.getConverter(String.class);
}
throw new UnsupportedOperationException("The type " + fieldSchema.getType() + " is not supported."); //$NON-NLS-1$ //$NON-NLS-2$
}
代码示例来源:origin: Talend/components
return AvroUtils._character();
case BIG_DECIMAL:
return AvroUtils._decimal();
case DATE:
return AvroUtils._logicalTimestamp();
代码示例来源:origin: org.talend.components/components-jdbc-runtime
return AvroUtils._character();
case BIG_DECIMAL:
return AvroUtils._decimal();
case DATE:
return AvroUtils._date();
代码示例来源:origin: Talend/components
return AvroUtils._character();
case BIG_DECIMAL:
return AvroUtils._decimal();
case DATE:
return AvroUtils._date();
代码示例来源:origin: Talend/components
@Test
public void testWriteDecimal() throws Throwable {
String resources = getResourceFolder();
String outputFile = resources + "/out/test_write_decimal.csv";
String refFilePath = resources + "/ref_test_write_decimal.csv";
LOGGER.debug("Test file path: " + outputFile);
TFileOutputDelimitedProperties properties = createOutputProperties(outputFile, false);
Schema outputSchema = SchemaBuilder.builder().record("Schema").fields().name("TestBigDecimal")
.prop(SchemaConstants.TALEND_COLUMN_PRECISION, "10").prop(SchemaConstants.TALEND_COLUMN_PRECISION, "2")
.type(AvroUtils._decimal()).noDefault().endRecord();
properties.main.schema.setValue(outputSchema);
List<IndexedRecord> records = new ArrayList<>();
IndexedRecord r1 = new GenericData.Record(outputSchema);
r1.put(0, "3.1415926");
IndexedRecord r2 = new GenericData.Record(outputSchema);
r2.put(0, "9.1798");
records.add(r1);
records.add(r2);
// Delete generated empty file function not be checked
doWriteRows(properties, records);
assertTrue(FileRuntimeHelper.compareInTextMode(outputFile, refFilePath, getEncoding(properties.encoding)));
assertTrue(deleteFile(outputFile));
}
代码示例来源:origin: org.talend.components/components-salesforce
break;
case currency:
base = AvroUtils._decimal();
break;
case date:
代码示例来源:origin: org.talend.components/components-salesforce-runtime
break;
case currency:
base = AvroUtils._decimal();
break;
case date:
代码示例来源:origin: org.talend.components/components-salesforce-runtime
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._decimal())) {
return new StringToDecimalConverter(f);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._double())) {
代码示例来源:origin: Talend/components
public AvroConverter<String, ?> getConverter(Schema.Field f, FileDelimitedProperties properties) {
Schema fieldSchema = AvroUtils.unwrapIfNullable(f.schema());
if (AvroUtils.isSameType(fieldSchema, AvroUtils._boolean())) {
return new BooleanConverter(f);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._decimal())) {
return new DecimalConverter(f, properties);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._double())) {
return new DoubleConverter(f, properties);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._float())) {
return new FloatConverter(f, properties);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._int())) {
return new IntegerConverter(f, properties);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._date())) {
return new DateConverter(f, properties);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._long())) {
return new LongConverter(f, properties);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._bytes())) {
return new BytesConverter(f, properties);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._byte())) {
return new ByteConverter(f, properties);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._short())) {
return new ShortConverter(f, properties);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._character())) {
return new CharacterConverter(f);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._string())) {
return super.getConverter(String.class);
}
throw new UnsupportedOperationException("The type " + fieldSchema.getType() + " is not supported."); //$NON-NLS-1$ //$NON-NLS-2$
}
代码示例来源:origin: Talend/components
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._decimal())) {
return new StringToDecimalConverter(f);
} else if (AvroUtils.isSameType(fieldSchema, AvroUtils._double())) {
代码示例来源:origin: org.talend.components/components-jdbc-runtime
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._date())) {
return Types.DATE;
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._decimal())) {
return Types.DECIMAL;
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._long())) {
代码示例来源:origin: Talend/components
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._date())) {
return Types.DATE;
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._decimal())) {
return Types.DECIMAL;
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._long())) {
代码示例来源:origin: org.talend.components/components-azurestorage
public static DTEConverter createConverter(final Field f, final String mappedName) {
Schema basicSchema = AvroUtils.unwrapIfNullable(f.schema());
AzureStorageDTEConverters converters = new AzureStorageDTEConverters();
DTEConverter dteConverter;
if (AvroUtils.isSameType(basicSchema, AvroUtils._string()) || AvroUtils.isSameType(basicSchema, AvroUtils._character())) {
dteConverter = converters.new StringDTEConverter(f, mappedName);
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._int()) || AvroUtils.isSameType(basicSchema, AvroUtils._short())
|| AvroUtils.isSameType(basicSchema, AvroUtils._byte())) {
dteConverter = converters.new IntegerDTEConverter(mappedName);
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._date())) {
dteConverter = converters.new DateDTEConverter(f, mappedName);
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._decimal())
|| AvroUtils.isSameType(basicSchema, AvroUtils._double())
|| AvroUtils.isSameType(basicSchema, AvroUtils._float())) {
dteConverter = converters.new DoubleDTEConverter(mappedName);
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._long())) {
dteConverter = converters.new LongDTEConverter(f, mappedName);
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._boolean())) {
dteConverter = converters.new BooleanDTEConverter(mappedName);
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._bytes())) {
dteConverter = converters.new ByteArrayDTEConverter(mappedName);
} else {
dteConverter = converters.new StringDTEConverter(f, mappedName);
}
return dteConverter;
}
代码示例来源:origin: Talend/components
public static DTEConverter createConverter(final Field f, final String mappedName) {
Schema basicSchema = AvroUtils.unwrapIfNullable(f.schema());
AzureStorageDTEConverters converters = new AzureStorageDTEConverters();
DTEConverter dteConverter;
if (AvroUtils.isSameType(basicSchema, AvroUtils._string()) || AvroUtils.isSameType(basicSchema, AvroUtils._character())) {
dteConverter = converters.new StringDTEConverter(f, mappedName);
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._int()) || AvroUtils.isSameType(basicSchema, AvroUtils._short())
|| AvroUtils.isSameType(basicSchema, AvroUtils._byte())) {
dteConverter = converters.new IntegerDTEConverter(mappedName);
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._date())) {
dteConverter = converters.new DateDTEConverter(f, mappedName);
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._decimal())
|| AvroUtils.isSameType(basicSchema, AvroUtils._double())
|| AvroUtils.isSameType(basicSchema, AvroUtils._float())) {
dteConverter = converters.new DoubleDTEConverter(mappedName);
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._long())) {
dteConverter = converters.new LongDTEConverter(f, mappedName);
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._boolean())) {
dteConverter = converters.new BooleanDTEConverter(mappedName);
} else if (AvroUtils.isSameType(basicSchema, AvroUtils._bytes())) {
dteConverter = converters.new ByteArrayDTEConverter(mappedName);
} else {
dteConverter = converters.new StringDTEConverter(f, mappedName);
}
return dteConverter;
}
代码示例来源:origin: Talend/components
public static Schema getBasicSchema(String pattern) {
return SchemaBuilder.builder().record("Schema").fields() //
.name("TestBoolean").type().booleanType().noDefault() //
.name("TestByte").type(AvroUtils._byte()).noDefault() //
.name("TestBytes").type(AvroUtils._bytes()).noDefault() //
.name("TestChar").type(AvroUtils._character()).noDefault() //
.name("TestDate").prop(SchemaConstants.TALEND_COLUMN_PATTERN, pattern)//
.type(AvroUtils._date()).noDefault() //
.name("TestDouble").type().doubleType().noDefault() //
.name("TestFloat").type().floatType().noDefault() //
.name("TestBigDecimal").type(AvroUtils._decimal()).noDefault()//
.name("TestInteger").type().intType().noDefault() //
.name("TestLong").type().longType().noDefault() //
.name("TestObject").type(AvroUtils._bytes()).noDefault().endRecord();
}
内容来源于网络,如有侵权,请联系作者删除!