本文整理汇总了Java中org.apache.kafka.connect.data.Decimal类的典型用法代码示例。如果您正苦于以下问题:Java Decimal类的具体用法?Java Decimal怎么用?Java Decimal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Decimal类属于org.apache.kafka.connect.data包,在下文中一共展示了Decimal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scaleInternal
import org.apache.kafka.connect.data.Decimal; //导入依赖的package包/类
private static int scaleInternal(Schema schema) {
if (null == schema.parameters()) {
throw new DataException(NOT_FOUND_MESSAGE);
}
String scaleString = schema.parameters().get(Decimal.SCALE_FIELD);
if (scaleString == null) {
throw new DataException(NOT_FOUND_MESSAGE);
} else {
try {
return Integer.parseInt(scaleString);
} catch (NumberFormatException var3) {
throw new DataException(NOT_PARSABLE_MESSAGE, var3);
}
}
}
示例2: assertSchema
import org.apache.kafka.connect.data.Decimal; //导入依赖的package包/类
@TestFactory
public Stream<DynamicTest> assertSchema() {
List<TestCase> tests = new ArrayList<>();
of(tests, Schema.STRING_SCHEMA, Schema.STRING_SCHEMA, true);
of(tests, Schema.STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA, false);
of(tests, Schema.BYTES_SCHEMA, Decimal.schema(4), false);
of(tests, null, null, true);
of(tests, Schema.STRING_SCHEMA, null, false);
of(tests, null, Schema.STRING_SCHEMA, false);
return tests.stream().map(testCase -> dynamicTest(testCase.toString(), () -> {
if (testCase.isEqual) {
AssertSchema.assertSchema(testCase.expected, testCase.actual);
} else {
assertThrows(AssertionFailedError.class, () -> {
AssertSchema.assertSchema(testCase.expected, testCase.actual);
});
}
}));
}
示例3: Parser
import org.apache.kafka.connect.data.Decimal; //导入依赖的package包/类
public Parser() {
this.typeParsers = new HashMap<>();
registerTypeParser(Schema.BOOLEAN_SCHEMA, new BooleanParser());
registerTypeParser(Schema.BOOLEAN_SCHEMA, new BooleanParser());
registerTypeParser(Schema.FLOAT32_SCHEMA, new Float32TypeParser());
registerTypeParser(Schema.FLOAT64_SCHEMA, new Float64TypeParser());
registerTypeParser(Schema.INT8_SCHEMA, new Int8TypeParser());
registerTypeParser(Schema.INT16_SCHEMA, new Int16TypeParser());
registerTypeParser(Schema.INT32_SCHEMA, new Int32TypeParser());
registerTypeParser(Schema.INT64_SCHEMA, new Int64TypeParser());
registerTypeParser(Schema.STRING_SCHEMA, new StringTypeParser());
registerTypeParser(Decimal.schema(1), new DecimalTypeParser());
registerTypeParser(Date.SCHEMA, new DateTypeParser());
registerTypeParser(Time.SCHEMA, new TimeTypeParser());
registerTypeParser(Timestamp.SCHEMA, new TimestampTypeParser());
}
示例4: nullableTests
import org.apache.kafka.connect.data.Decimal; //导入依赖的package包/类
@Test
public void nullableTests() {
final Schema[] schemas = new Schema[]{
Schema.OPTIONAL_BOOLEAN_SCHEMA,
Schema.OPTIONAL_FLOAT32_SCHEMA,
Schema.OPTIONAL_FLOAT64_SCHEMA,
Schema.OPTIONAL_INT8_SCHEMA,
Schema.OPTIONAL_INT16_SCHEMA,
Schema.OPTIONAL_INT32_SCHEMA,
Schema.OPTIONAL_INT64_SCHEMA,
Schema.OPTIONAL_STRING_SCHEMA,
Decimal.builder(1).optional().build(),
Timestamp.builder().optional().build(),
Date.builder().optional().build(),
Time.builder().optional().build(),
};
for (Schema schema : schemas) {
Object actual = this.parser.parseString(schema, null);
assertNull(actual);
}
}
示例5: inferLogicalMapping
import org.apache.kafka.connect.data.Decimal; //导入依赖的package包/类
private static JsonNode inferLogicalMapping(Schema schema) {
String schemaName = schema.name();
Object defaultValue = schema.defaultValue();
if (schemaName == null) {
return null;
}
switch (schemaName) {
case Date.LOGICAL_NAME:
case Time.LOGICAL_NAME:
case Timestamp.LOGICAL_NAME:
return inferPrimitive(ElasticsearchSinkConnectorConstants.DATE_TYPE, defaultValue);
case Decimal.LOGICAL_NAME:
return inferPrimitive(ElasticsearchSinkConnectorConstants.DOUBLE_TYPE, defaultValue);
default:
// User-defined type or unknown built-in
return null;
}
}
示例6: decimal
import org.apache.kafka.connect.data.Decimal; //导入依赖的package包/类
@Test
public void decimal() {
Schema origSchema = Decimal.schema(2);
Schema preProcessedSchema = converter.preProcessSchema(origSchema);
assertEquals(Schema.FLOAT64_SCHEMA, preProcessedSchema);
assertEquals(0.02, converter.preProcessValue(new BigDecimal("0.02"), origSchema, preProcessedSchema));
// optional
assertEquals(
Schema.OPTIONAL_FLOAT64_SCHEMA,
converter.preProcessSchema(Decimal.builder(2).optional().build())
);
// defval
assertEquals(
SchemaBuilder.float64().defaultValue(0.00).build(),
converter.preProcessSchema(Decimal.builder(2).defaultValue(new BigDecimal("0.00")).build())
);
}
示例7: array
import org.apache.kafka.connect.data.Decimal; //导入依赖的package包/类
@Test
public void array() {
Schema origSchema = SchemaBuilder.array(Decimal.schema(2)).schema();
Schema preProcessedSchema = converter.preProcessSchema(origSchema);
assertEquals(SchemaBuilder.array(Schema.FLOAT64_SCHEMA).build(), preProcessedSchema);
assertEquals(
Arrays.asList(0.02, 0.42),
converter.preProcessValue(Arrays.asList(new BigDecimal("0.02"), new BigDecimal("0.42")), origSchema, preProcessedSchema)
);
// optional
assertEquals(
SchemaBuilder.array(preProcessedSchema.valueSchema()).optional().build(),
converter.preProcessSchema(SchemaBuilder.array(Decimal.schema(2)).optional().build())
);
// defval
assertEquals(
SchemaBuilder.array(preProcessedSchema.valueSchema()).defaultValue(Collections.emptyList()).build(),
converter.preProcessSchema(SchemaBuilder.array(Decimal.schema(2)).defaultValue(Collections.emptyList()).build())
);
}
示例8: struct
import org.apache.kafka.connect.data.Decimal; //导入依赖的package包/类
@Test
public void struct() {
Schema origSchema = SchemaBuilder.struct().name("struct").field("decimal", Decimal.schema(2)).build();
Schema preProcessedSchema = converter.preProcessSchema(origSchema);
assertEquals(
SchemaBuilder.struct().name("struct").field("decimal", Schema.FLOAT64_SCHEMA).build(),
preProcessedSchema
);
assertEquals(
new Struct(preProcessedSchema).put("decimal", 0.02),
converter.preProcessValue(new Struct(origSchema).put("decimal", new BigDecimal("0.02")), origSchema, preProcessedSchema)
);
// optional
assertEquals(
SchemaBuilder.struct().name("struct").field("decimal", Schema.FLOAT64_SCHEMA).optional().build(),
converter.preProcessSchema(SchemaBuilder.struct().name("struct").field("decimal", Decimal.schema(2)).optional().build())
);
}
示例9: createSchema
import org.apache.kafka.connect.data.Decimal; //导入依赖的package包/类
protected Schema createSchema() {
Schema structSchema = createInnerSchema();
return SchemaBuilder.struct().name("record")
.field("boolean", Schema.BOOLEAN_SCHEMA)
.field("bytes", Schema.BYTES_SCHEMA)
.field("int8", Schema.INT8_SCHEMA)
.field("int16", Schema.INT16_SCHEMA)
.field("int32", Schema.INT32_SCHEMA)
.field("int64", Schema.INT64_SCHEMA)
.field("float32", Schema.FLOAT32_SCHEMA)
.field("float64", Schema.FLOAT64_SCHEMA)
.field("string", Schema.STRING_SCHEMA)
.field("array", SchemaBuilder.array(Schema.STRING_SCHEMA).build())
.field("map", SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.STRING_SCHEMA).build())
.field("struct", structSchema)
.field("decimal", Decimal.schema(2))
.field("date", Date.SCHEMA)
.field("time", Time.SCHEMA)
.field("timestamp", Timestamp.SCHEMA)
.build();
}
示例10: createInnerSchema
import org.apache.kafka.connect.data.Decimal; //导入依赖的package包/类
private Schema createInnerSchema() {
return SchemaBuilder.struct().name("inner")
.field("boolean", Schema.BOOLEAN_SCHEMA)
.field("bytes", Schema.BYTES_SCHEMA)
.field("int8", Schema.INT8_SCHEMA)
.field("int16", Schema.INT16_SCHEMA)
.field("int32", Schema.INT32_SCHEMA)
.field("int64", Schema.INT64_SCHEMA)
.field("float32", Schema.FLOAT32_SCHEMA)
.field("float64", Schema.FLOAT64_SCHEMA)
.field("string", Schema.STRING_SCHEMA)
.field("array", SchemaBuilder.array(Schema.STRING_SCHEMA).build())
.field("map", SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.STRING_SCHEMA).build())
.field("decimal", Decimal.schema(2))
.field("date", Date.SCHEMA)
.field("time", Time.SCHEMA)
.field("timestamp", Timestamp.SCHEMA)
.build();
}
示例11: testDecimal
import org.apache.kafka.connect.data.Decimal; //导入依赖的package包/类
@Test
public void testDecimal() {
final String fieldName = "Decimal";
com.google.cloud.bigquery.Schema bigQueryExpectedSchema =
com.google.cloud.bigquery.Schema.of(
com.google.cloud.bigquery.Field.newBuilder(
fieldName,
com.google.cloud.bigquery.Field.Type.floatingPoint()
).setMode(
com.google.cloud.bigquery.Field.Mode.REQUIRED
).build()
);
Schema kafkaConnectTestSchema = SchemaBuilder
.struct()
.field(fieldName, Decimal.schema(0))
.build();
com.google.cloud.bigquery.Schema bigQueryTestSchema =
new BigQuerySchemaConverter().convertSchema(kafkaConnectTestSchema);
assertEquals(bigQueryExpectedSchema, bigQueryTestSchema);
}
示例12: decimalToConnect
import org.apache.kafka.connect.data.Decimal; //导入依赖的package包/类
@Test
public void decimalToConnect() {
Schema schema = Decimal.schema(2);
BigDecimal reference = new BigDecimal(new BigInteger("156"), 2);
// Payload is base64 encoded byte[]{0, -100}, which is the two's complement encoding of 156.
String msg = "{ \"schema\": { \"type\": \"bytes\", \"name\": \"org.apache.kafka.connect.data.Decimal\", \"version\": 1, \"parameters\": { \"scale\": \"2\" } }, \"payload\": \"AJw=\" }";
SchemaAndValue schemaAndValue = converter.toConnectData(TOPIC, msg.getBytes());
BigDecimal converted = (BigDecimal) schemaAndValue.value();
assertEquals(schema, schemaAndValue.schema());
assertEquals(reference, converted);
}
示例13: decimalToConnectOptional
import org.apache.kafka.connect.data.Decimal; //导入依赖的package包/类
@Test
public void decimalToConnectOptional() {
Schema schema = Decimal.builder(2).optional().schema();
String msg = "{ \"schema\": { \"type\": \"bytes\", \"name\": \"org.apache.kafka.connect.data.Decimal\", \"version\": 1, \"optional\": true, \"parameters\": { \"scale\": \"2\" } }, \"payload\": null }";
SchemaAndValue schemaAndValue = converter.toConnectData(TOPIC, msg.getBytes());
assertEquals(schema, schemaAndValue.schema());
assertNull(schemaAndValue.value());
}
示例14: decimalToConnectWithDefaultValue
import org.apache.kafka.connect.data.Decimal; //导入依赖的package包/类
@Test
public void decimalToConnectWithDefaultValue() {
BigDecimal reference = new BigDecimal(new BigInteger("156"), 2);
Schema schema = Decimal.builder(2).defaultValue(reference).build();
String msg = "{ \"schema\": { \"type\": \"bytes\", \"name\": \"org.apache.kafka.connect.data.Decimal\", \"version\": 1, \"default\": \"AJw=\", \"parameters\": { \"scale\": \"2\" } }, \"payload\": null }";
SchemaAndValue schemaAndValue = converter.toConnectData(TOPIC, msg.getBytes());
assertEquals(schema, schemaAndValue.schema());
assertEquals(reference, schemaAndValue.value());
}
示例15: decimalToConnectOptionalWithDefaultValue
import org.apache.kafka.connect.data.Decimal; //导入依赖的package包/类
@Test
public void decimalToConnectOptionalWithDefaultValue() {
BigDecimal reference = new BigDecimal(new BigInteger("156"), 2);
Schema schema = Decimal.builder(2).optional().defaultValue(reference).build();
String msg = "{ \"schema\": { \"type\": \"bytes\", \"name\": \"org.apache.kafka.connect.data.Decimal\", \"version\": 1, \"optional\": true, \"default\": \"AJw=\", \"parameters\": { \"scale\": \"2\" } }, \"payload\": null }";
SchemaAndValue schemaAndValue = converter.toConnectData(TOPIC, msg.getBytes());
assertEquals(schema, schemaAndValue.schema());
assertEquals(reference, schemaAndValue.value());
}