本文整理了Java中org.apache.kafka.connect.data.Decimal.builder()
方法的一些代码示例,展示了Decimal.builder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Decimal.builder()
方法的具体详情如下:
包路径:org.apache.kafka.connect.data.Decimal
类名称:Decimal
方法名:builder
[英]Returns a SchemaBuilder for a Decimal with the given scale factor. By returning a SchemaBuilder you can override additional schema settings such as required/optional, default value, and documentation.
[中]返回具有给定比例因子的十进制的SchemaBuilder。通过返回SchemaBuilder,您可以覆盖其他模式设置,如必需/可选、默认值和文档。
代码示例来源:origin: debezium/debezium
/**
* Returns a {@link SchemaBuilder} for a decimal number depending on {@link JdbcValueConverters.DecimalMode}. You
* can use the resulting schema builder to set additional schema settings such as required/optional, default value,
* and documentation.
*
* @param mode the mode in which the number should be encoded
* @param precision the precision of the decimal
* @param scale scale of the decimal
* @return the schema builder
*/
public static SchemaBuilder builder(DecimalMode mode, int precision, int scale) {
switch (mode) {
case DOUBLE:
return SchemaBuilder.float64();
case PRECISE:
return Decimal.builder(scale)
.parameter(PRECISION_PARAMETER_KEY, String.valueOf(precision));
case STRING:
return SchemaBuilder.string();
}
throw new IllegalArgumentException("Unknown decimalMode");
}
代码示例来源:origin: debezium/debezium
protected List<SchemaAndValueField> schemaAndValuesForMoneyTypes() {
return Collections.singletonList(new SchemaAndValueField("csh", Decimal.builder(0).optional().build(),
BigDecimal.valueOf(1234.11d)));
}
代码示例来源:origin: debezium/debezium
protected List<SchemaAndValueField> schemasAndValuesForBigDecimalEncodedNumericTypes() {
final Struct dvs = new Struct(VariableScaleDecimal.schema());
dvs.put("scale", 4).put("value", new BigDecimal("10.1111").unscaledValue().toByteArray());
final Struct nvs = new Struct(VariableScaleDecimal.schema());
nvs.put("scale", 4).put("value", new BigDecimal("22.2222").unscaledValue().toByteArray());
final Struct dvs_int = new Struct(VariableScaleDecimal.schema());
dvs_int.put("scale", 0).put("value", new BigDecimal("10").unscaledValue().toByteArray());
final Struct nvs_int = new Struct(VariableScaleDecimal.schema());
nvs_int.put("scale", 0).put("value", new BigDecimal("22").unscaledValue().toByteArray());
final List<SchemaAndValueField> fields = new ArrayList<SchemaAndValueField>(Arrays.asList(
new SchemaAndValueField("d", Decimal.builder(2).parameter(TestHelper.PRECISION_PARAMETER_KEY, "3").optional().build(), new BigDecimal("1.10")),
new SchemaAndValueField("dzs", Decimal.builder(0).parameter(TestHelper.PRECISION_PARAMETER_KEY, "4").optional().build(), new BigDecimal("10")),
new SchemaAndValueField("dvs", VariableScaleDecimal.optionalSchema(), dvs),
new SchemaAndValueField("d_nn", Decimal.builder(2).parameter(TestHelper.PRECISION_PARAMETER_KEY, "3").build(), new BigDecimal("3.30")),
new SchemaAndValueField("n", Decimal.builder(4).parameter(TestHelper.PRECISION_PARAMETER_KEY, "6").optional().build(), new BigDecimal("22.2200")),
new SchemaAndValueField("nzs", Decimal.builder(0).parameter(TestHelper.PRECISION_PARAMETER_KEY, "4").optional().build(), new BigDecimal("22")),
new SchemaAndValueField("nvs", VariableScaleDecimal.optionalSchema(), nvs),
new SchemaAndValueField("d_int", Decimal.builder(2).parameter(TestHelper.PRECISION_PARAMETER_KEY, "3").optional().build(), new BigDecimal("1.00")),
new SchemaAndValueField("dvs_int", VariableScaleDecimal.optionalSchema(), dvs_int),
new SchemaAndValueField("n_int", Decimal.builder(4).parameter(TestHelper.PRECISION_PARAMETER_KEY, "6").optional().build(), new BigDecimal("22.0000")),
new SchemaAndValueField("nvs_int", VariableScaleDecimal.optionalSchema(), nvs_int)
));
return fields;
}
代码示例来源:origin: debezium/debezium
(int)LocalDate.of(2016, Month.NOVEMBER, 6).toEpochDay()
)),
new SchemaAndValueField("numeric_array", SchemaBuilder.array(Decimal.builder(2).parameter(TestHelper.PRECISION_PARAMETER_KEY, "10").optional().build()).optional().build(),
Arrays.asList(
new BigDecimal("1.20"),
代码示例来源:origin: debezium/debezium
assertRecordSchemaAndValues(expectedBefore, updatedRecord, Envelope.FieldName.BEFORE);
List<SchemaAndValueField> expectedAfter = Collections.singletonList(new SchemaAndValueField("num_val", Decimal.builder(2).parameter(TestHelper.PRECISION_PARAMETER_KEY, "5").optional().build(), new BigDecimal("123.45")));
assertRecordSchemaAndValues(expectedAfter, updatedRecord, Envelope.FieldName.AFTER);
Collections.singletonList(new SchemaAndValueField("num_val", Decimal.builder(1).parameter(TestHelper.PRECISION_PARAMETER_KEY, "6").optional().build(), new BigDecimal("123.4"))), updatedRecord, Envelope.FieldName.AFTER);
Collections.singletonList(new SchemaAndValueField("num_val", Decimal.builder(4).parameter(TestHelper.PRECISION_PARAMETER_KEY, "12").optional().build(), new BigDecimal("2.4800"))), updatedRecord, Envelope.FieldName.AFTER);
Collections.singletonList(new SchemaAndValueField("num_val", Decimal.builder(0).parameter(TestHelper.PRECISION_PARAMETER_KEY, "12").optional().build(), new BigDecimal("1238"))), updatedRecord, Envelope.FieldName.AFTER);
代码示例来源:origin: debezium/debezium
private void assertBigintUnsignedPrecise(Struct value) {
Struct after = value.getStruct(Envelope.FieldName.AFTER);
Integer i = after.getInt32("id");
assertThat(i).isNotNull();
//Validate the schema first, we are expecting org.apache.kafka.connect.data.Decimal:Byte since we are dealing with unsignd-bigint
//So Unsigned BIGINY would be an int32 type
assertThat(after.schema().field("c1").schema()).isEqualTo(Decimal.builder(0).schema());
assertThat(after.schema().field("c2").schema()).isEqualTo(Decimal.builder(0).schema());
//Validate the schema first, we are expecting int-64 since we are dealing with signed-bigint.
//So Signed BIGINT would be an INT64 type
assertThat(after.schema().field("c3").schema()).isEqualTo(Schema.INT64_SCHEMA);
//Validate candidates values
switch (i) {
case 1:
assertThat(after.get("c1")).isEqualTo(new BigDecimal("18446744073709551615"));
assertThat(after.get("c2")).isEqualTo(new BigDecimal("18446744073709551615"));
assertThat(after.getInt64("c3")).isEqualTo(9223372036854775807L);
break;
case 2:
assertThat(after.get("c1")).isEqualTo(new BigDecimal("14446744073709551615"));
assertThat(after.get("c2")).isEqualTo(new BigDecimal("14446744073709551615"));
assertThat(after.getInt64("c3")).isEqualTo(-1223372036854775807L);
break;
case 3:
assertThat(after.get("c1")).isEqualTo(new BigDecimal("0"));
assertThat(after.get("c2")).isEqualTo(new BigDecimal("0"));
assertThat(after.getInt64("c3")).isEqualTo(-9223372036854775808L);
}
}
代码示例来源:origin: debezium/debezium
Assertions.assertThat(results).hasSize(1);
final Struct valueA = (Struct) results.get(0).value();
Assertions.assertThat(valueA.schema().field("after").schema().field("cola").schema()).isEqualTo(Decimal.builder(4).parameter("connect.decimal.precision", "8").optional().schema());
Assertions.assertThat(valueA.schema().field("after").schema().field("colb").schema()).isEqualTo(Decimal.builder(0).parameter("connect.decimal.precision", "18").optional().schema());
Assertions.assertThat(valueA.schema().field("after").schema().field("colc").schema()).isEqualTo(Decimal.builder(1).parameter("connect.decimal.precision", "8").optional().schema());
Assertions.assertThat(valueA.schema().field("after").schema().field("cold").schema()).isEqualTo(Decimal.builder(0).parameter("connect.decimal.precision", "18").optional().schema());
Assertions.assertThat(((Struct) valueA.get("after")).get("cola")).isEqualTo(BigDecimal.valueOf(333.3333));
Assertions.assertThat(((Struct) valueA.get("after")).get("colb")).isEqualTo(BigDecimal.valueOf(3333));
代码示例来源:origin: debezium/debezium
return Decimal.builder(0);
代码示例来源:origin: debezium/debezium
Schema.OPTIONAL_FLOAT64_SCHEMA, Schema.INT16_SCHEMA, Schema.INT64_SCHEMA, Schema.OPTIONAL_BOOLEAN_SCHEMA);
assertTableSchema("public.numeric_decimal_table", "d, dzs, dvs, n, nzs, nvs",
Decimal.builder(2).parameter(TestHelper.PRECISION_PARAMETER_KEY, "3").optional().build(),
Decimal.builder(0).parameter(TestHelper.PRECISION_PARAMETER_KEY, "4").optional().build(),
VariableScaleDecimal.builder().optional().build(),
Decimal.builder(4).parameter(TestHelper.PRECISION_PARAMETER_KEY, "6").optional().build(),
Decimal.builder(0).parameter(TestHelper.PRECISION_PARAMETER_KEY, "4").optional().build(),
VariableScaleDecimal.builder().optional().build()
);
Schema.OPTIONAL_STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA,
Schema.OPTIONAL_STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA);
assertTableSchema("public.cash_table", "csh", Decimal.builder(0).optional().build());
assertTableSchema("public.bitbin_table", "ba, bol, bs, bv",
Schema.OPTIONAL_BYTES_SCHEMA, Schema.OPTIONAL_BOOLEAN_SCHEMA, Bits.builder(2).optional().build(),
代码示例来源:origin: debezium/debezium
protected List<SchemaAndValueField> schemasAndValuesForArrayTypesWithNullValues() {
return Arrays.asList(
new SchemaAndValueField("int_array", SchemaBuilder.array(Schema.OPTIONAL_INT32_SCHEMA).optional().build(), null),
new SchemaAndValueField("bigint_array", SchemaBuilder.array(Schema.OPTIONAL_INT64_SCHEMA).optional().build(), null),
new SchemaAndValueField("text_array", SchemaBuilder.array(Schema.OPTIONAL_STRING_SCHEMA).optional().build(), null),
new SchemaAndValueField("char_array", SchemaBuilder.array(Schema.OPTIONAL_STRING_SCHEMA).optional().build(), null),
new SchemaAndValueField("varchar_array", SchemaBuilder.array(Schema.OPTIONAL_STRING_SCHEMA).optional().build(), null),
new SchemaAndValueField("date_array", SchemaBuilder.array(Date.builder().optional().schema()).optional().build(), null),
new SchemaAndValueField("numeric_array", SchemaBuilder.array(Decimal.builder(2).parameter(TestHelper.PRECISION_PARAMETER_KEY, "10").optional().build()).optional().build(), null),
new SchemaAndValueField("citext_array", SchemaBuilder.array(Schema.OPTIONAL_STRING_SCHEMA).optional().build(), null)
);
}
代码示例来源:origin: debezium/debezium
return Point.builder();
case PgOid.MONEY:
return Decimal.builder(column.scale().get());
case PgOid.NUMERIC:
return numericSchema(column);
代码示例来源:origin: debezium/debezium
assertThat(values.field("C2").name()).isEqualTo("C2");
assertThat(values.field("C2").index()).isEqualTo(1);
assertThat(values.field("C2").schema()).isEqualTo(Decimal.builder(3).parameter("connect.decimal.precision", "5").optional().build()); // scale of 3
assertThat(values.field("C3").name()).isEqualTo("C3");
assertThat(values.field("C3").index()).isEqualTo(2);
代码示例来源:origin: org.apache.kafka/connect-api
public static Schema schema(int scale) {
return builder(scale).build();
}
代码示例来源:origin: com.github.jcustenborder.kafka.connect/connect-utils
public static SchemaBuilder builder(Object input) {
Preconditions.checkNotNull(input, "input cannot be null.");
final SchemaBuilder builder;
if (PRIMITIVES.containsKey(input.getClass())) {
final Schema.Type type = PRIMITIVES.get(input.getClass());
builder = SchemaBuilder.type(type);
} else if (input instanceof Date) {
builder = Timestamp.builder();
} else if (input instanceof BigDecimal) {
builder = Decimal.builder(((BigDecimal) input).scale());
} else {
throw new UnsupportedOperationException(
String.format("Unsupported Type: %s", input.getClass())
);
}
return builder.optional();
}
代码示例来源:origin: io.debezium/debezium-core
/**
* Returns a {@link SchemaBuilder} for a decimal number depending on {@link JdbcValueConverters.DecimalMode}. You
* can use the resulting schema builder to set additional schema settings such as required/optional, default value,
* and documentation.
*
* @param mode the mode in which the number should be encoded
* @param precision the precision of the decimal
* @param scale scale of the decimal
* @return the schema builder
*/
public static SchemaBuilder builder(DecimalMode mode, int precision, int scale) {
switch (mode) {
case DOUBLE:
return SchemaBuilder.float64();
case PRECISE:
return Decimal.builder(scale)
.parameter(PRECISION_PARAMETER_KEY, String.valueOf(precision));
case STRING:
return SchemaBuilder.string();
}
throw new IllegalArgumentException("Unknown decimalMode");
}
代码示例来源:origin: io.debezium/debezium-connector-postgres
protected List<SchemaAndValueField> schemaAndValuesForMoneyTypes() {
return Collections.singletonList(new SchemaAndValueField("csh", Decimal.builder(0).optional().build(),
BigDecimal.valueOf(1234.11d)));
}
代码示例来源:origin: io.debezium/debezium-connector-postgres
protected List<SchemaAndValueField> schemasAndValuesForBigDecimalEncodedNumericTypes() {
final Struct dvs = new Struct(VariableScaleDecimal.schema());
dvs.put("scale", 4).put("value", new BigDecimal("10.1111").unscaledValue().toByteArray());
final Struct nvs = new Struct(VariableScaleDecimal.schema());
nvs.put("scale", 4).put("value", new BigDecimal("22.2222").unscaledValue().toByteArray());
final Struct dvs_int = new Struct(VariableScaleDecimal.schema());
dvs_int.put("scale", 0).put("value", new BigDecimal("10").unscaledValue().toByteArray());
final Struct nvs_int = new Struct(VariableScaleDecimal.schema());
nvs_int.put("scale", 0).put("value", new BigDecimal("22").unscaledValue().toByteArray());
final List<SchemaAndValueField> fields = new ArrayList<SchemaAndValueField>(Arrays.asList(
new SchemaAndValueField("d", Decimal.builder(2).parameter(TestHelper.PRECISION_PARAMETER_KEY, "3").optional().build(), new BigDecimal("1.10")),
new SchemaAndValueField("dzs", Decimal.builder(0).parameter(TestHelper.PRECISION_PARAMETER_KEY, "4").optional().build(), new BigDecimal("10")),
new SchemaAndValueField("dvs", VariableScaleDecimal.optionalSchema(), dvs),
new SchemaAndValueField("d_nn", Decimal.builder(2).parameter(TestHelper.PRECISION_PARAMETER_KEY, "3").build(), new BigDecimal("3.30")),
new SchemaAndValueField("n", Decimal.builder(4).parameter(TestHelper.PRECISION_PARAMETER_KEY, "6").optional().build(), new BigDecimal("22.2200")),
new SchemaAndValueField("nzs", Decimal.builder(0).parameter(TestHelper.PRECISION_PARAMETER_KEY, "4").optional().build(), new BigDecimal("22")),
new SchemaAndValueField("nvs", VariableScaleDecimal.optionalSchema(), nvs),
new SchemaAndValueField("d_int", Decimal.builder(2).parameter(TestHelper.PRECISION_PARAMETER_KEY, "3").optional().build(), new BigDecimal("1.00")),
new SchemaAndValueField("dvs_int", VariableScaleDecimal.optionalSchema(), dvs_int),
new SchemaAndValueField("n_int", Decimal.builder(4).parameter(TestHelper.PRECISION_PARAMETER_KEY, "6").optional().build(), new BigDecimal("22.0000")),
new SchemaAndValueField("nvs_int", VariableScaleDecimal.optionalSchema(), nvs_int)
));
return fields;
}
代码示例来源:origin: hpgrahsl/kafka-connect-mongodb
@TestFactory
@DisplayName("tests for logical type decimal field conversions (legacy)")
public List<DynamicTest> testDecimalFieldConverterLegacy() {
SinkFieldConverter converter =
new DecimalFieldConverter(DecimalFieldConverter.Format.LEGACYDOUBLE);
List<DynamicTest> tests = new ArrayList<>();
new ArrayList<>(Arrays.asList(
new BigDecimal("-1234567890.09876543210"),
BigDecimal.ZERO,
new BigDecimal("+1234567890.09876543210")
)).forEach(
el -> tests.add(dynamicTest("conversion with "
+ converter.getClass().getSimpleName() + " for "+el,
() -> assertEquals(el.doubleValue(),
((BsonDouble)converter.toBson(el)).getValue())
))
);
tests.add(dynamicTest("optional type conversions", () -> {
Schema valueOptionalDefault = Decimal.builder(0).optional().defaultValue(BigDecimal.ZERO);
assertAll("checks",
() -> assertThrows(DataException.class, () -> converter.toBson(null, Decimal.schema(0))),
() -> assertEquals(new BsonNull(), converter.toBson(null, Decimal.builder(0).optional())),
() -> assertEquals(((BigDecimal)valueOptionalDefault.defaultValue()).doubleValue(),
((BsonDouble)converter.toBson(null,valueOptionalDefault)).getValue())
);
}));
return tests;
}
代码示例来源:origin: io.debezium/debezium-connector-mysql
private void assertBigintUnsignedPrecise(Struct value) {
Struct after = value.getStruct(Envelope.FieldName.AFTER);
Integer i = after.getInt32("id");
assertThat(i).isNotNull();
//Validate the schema first, we are expecting org.apache.kafka.connect.data.Decimal:Byte since we are dealing with unsignd-bigint
//So Unsigned BIGINY would be an int32 type
assertThat(after.schema().field("c1").schema()).isEqualTo(Decimal.builder(0).schema());
assertThat(after.schema().field("c2").schema()).isEqualTo(Decimal.builder(0).schema());
//Validate the schema first, we are expecting int-64 since we are dealing with signed-bigint.
//So Signed BIGINT would be an INT64 type
assertThat(after.schema().field("c3").schema()).isEqualTo(Schema.INT64_SCHEMA);
//Validate candidates values
switch (i) {
case 1:
assertThat(after.get("c1")).isEqualTo(new BigDecimal("18446744073709551615"));
assertThat(after.get("c2")).isEqualTo(new BigDecimal("18446744073709551615"));
assertThat(after.getInt64("c3")).isEqualTo(9223372036854775807L);
break;
case 2:
assertThat(after.get("c1")).isEqualTo(new BigDecimal("14446744073709551615"));
assertThat(after.get("c2")).isEqualTo(new BigDecimal("14446744073709551615"));
assertThat(after.getInt64("c3")).isEqualTo(-1223372036854775807L);
break;
case 3:
assertThat(after.get("c1")).isEqualTo(new BigDecimal("0"));
assertThat(after.get("c2")).isEqualTo(new BigDecimal("0"));
assertThat(after.getInt64("c3")).isEqualTo(-9223372036854775808L);
}
}
代码示例来源:origin: io.debezium/debezium-connector-postgres
protected List<SchemaAndValueField> schemasAndValuesForArrayTypesWithNullValues() {
return Arrays.asList(
new SchemaAndValueField("int_array", SchemaBuilder.array(Schema.OPTIONAL_INT32_SCHEMA).optional().build(), null),
new SchemaAndValueField("bigint_array", SchemaBuilder.array(Schema.OPTIONAL_INT64_SCHEMA).optional().build(), null),
new SchemaAndValueField("text_array", SchemaBuilder.array(Schema.OPTIONAL_STRING_SCHEMA).optional().build(), null),
new SchemaAndValueField("char_array", SchemaBuilder.array(Schema.OPTIONAL_STRING_SCHEMA).optional().build(), null),
new SchemaAndValueField("varchar_array", SchemaBuilder.array(Schema.OPTIONAL_STRING_SCHEMA).optional().build(), null),
new SchemaAndValueField("date_array", SchemaBuilder.array(Date.builder().optional().schema()).optional().build(), null),
new SchemaAndValueField("numeric_array", SchemaBuilder.array(Decimal.builder(2).parameter(TestHelper.PRECISION_PARAMETER_KEY, "10").optional().build()).optional().build(), null),
new SchemaAndValueField("citext_array", SchemaBuilder.array(Schema.OPTIONAL_STRING_SCHEMA).optional().build(), null)
);
}
内容来源于网络,如有侵权,请联系作者删除!