/** * Returns a {@link SchemaBuilder} for a Bits. You can use the resulting SchemaBuilder * to set additional schema settings such as required/optional, default value, and documentation. * * @param length maximum the number of bits in the set * @return the schema builder */ public static SchemaBuilder builder(int length) { return SchemaBuilder.bytes() .name(LOGICAL_NAME) .parameter(LENGTH_FIELD, Integer.toString(length)) .version(1); }
@Test @FixFor("DBZ-759") public void correctlySerializesStructWithByteArray() { Schema schema = SchemaBuilder.struct() .field("some_field", SchemaBuilder.bytes().build()) .build(); Struct struct = new Struct(schema).put("some_field", new byte[]{1, 3, 5, 7}); assertThat(SchemaUtil.asString(struct)).isEqualTo("{\"some_field\" : [1, 3, 5, 7]}"); } }
assertThat(values.field("C4").schema()).isEqualTo(SchemaBuilder.int32().optional().build()); // JDBC INTEGER = 32 bits assertThat(values.field("C5").index()).isEqualTo(4); assertThat(values.field("C5").schema()).isEqualTo(SchemaBuilder.bytes().build()); // JDBC BINARY = bytes assertThat(values.field("C6").index()).isEqualTo(5); assertThat(values.field("C6").schema()).isEqualTo(SchemaBuilder.int16().build());
/** * 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. * @param scale the scale factor to apply to unscaled values * @return a SchemaBuilder */ public static SchemaBuilder builder(int scale) { return SchemaBuilder.bytes() .name(LOGICAL_NAME) .parameter(SCALE_FIELD, Integer.toString(scale)) .version(1); }
/** * Returns a {@link SchemaBuilder} for a Bits. You can use the resulting SchemaBuilder * to set additional schema settings such as required/optional, default value, and documentation. * * @param length maximum the number of bits in the set * @return the schema builder */ public static SchemaBuilder builder(int length) { return SchemaBuilder.bytes() .name(LOGICAL_NAME) .parameter(LENGTH_FIELD, Integer.toString(length)) .version(1); }
@TestFactory @DisplayName("tests for bytes field conversions based on ByteBuffer") public List<DynamicTest> testBytesFieldConverterByteBuffer() { SinkFieldConverter converter = new BytesFieldConverter(); List<DynamicTest> tests = new ArrayList<>(); new ArrayList<>(Arrays.asList(ByteBuffer.wrap(new byte[]{-128,-127,0}), ByteBuffer.wrap(new byte[]{}), ByteBuffer.wrap(new byte[]{0,126,127}))).forEach( el -> tests.add(dynamicTest("conversion with " + converter.getClass().getSimpleName() + " for "+el.toString() +" -> "+Arrays.toString(el.array()), () -> assertEquals(el.array(), ((BsonBinary)converter.toBson(el)).getData()) )) ); tests.add(dynamicTest("optional type conversions", () -> { Schema valueOptionalDefault = SchemaBuilder.bytes().optional().defaultValue(ByteBuffer.wrap(new byte[]{})); assertAll("checks", () -> assertThrows(DataException.class, () -> converter.toBson(null, Schema.BYTES_SCHEMA)), () -> assertEquals(new BsonNull(), converter.toBson(null, Schema.OPTIONAL_BYTES_SCHEMA)), () -> assertEquals(((ByteBuffer)valueOptionalDefault.defaultValue()).array(), ((BsonBinary)converter.toBson(null, valueOptionalDefault)).getData()) ); })); return tests; }
@TestFactory @DisplayName("tests for bytes field conversions based on byte[]") public List<DynamicTest> testBytesFieldConverterByteArray() { SinkFieldConverter converter = new BytesFieldConverter(); List<DynamicTest> tests = new ArrayList<>(); new ArrayList<>(Arrays.asList(new byte[]{-128,-127,0},new byte[]{},new byte[]{0,126,127})).forEach( el -> tests.add(dynamicTest("conversion with " + converter.getClass().getSimpleName() + " for "+Arrays.toString(el), () -> assertEquals(el, ((BsonBinary)converter.toBson(el)).getData()) )) ); tests.add(dynamicTest("optional type conversions", () -> { Schema valueOptionalDefault = SchemaBuilder.bytes().optional().defaultValue(new byte[]{}); assertAll("checks", () -> assertThrows(DataException.class, () -> converter.toBson(null, Schema.BYTES_SCHEMA)), () -> assertEquals(new BsonNull(), converter.toBson(null, Schema.OPTIONAL_BYTES_SCHEMA)), () -> assertEquals(valueOptionalDefault.defaultValue(), ((BsonBinary)converter.toBson(null, valueOptionalDefault)).getData()) ); })); return tests; }
builder = SchemaBuilder.bytes(); break;