private SourceRecord createUnknownUnnamedSchemaRecord() { final Schema recordSchema = SchemaBuilder.struct() .field("id", SchemaBuilder.int8()) .build(); final Struct before = new Struct(recordSchema); before.put("id", (byte)1); return new SourceRecord(new HashMap<>(), new HashMap<>(), "dummy", recordSchema, before); }
private SourceRecord createUnknownRecord() { final Schema recordSchema = SchemaBuilder.struct().name("unknown") .field("id", SchemaBuilder.int8()) .build(); final Struct before = new Struct(recordSchema); before.put("id", (byte)1); return new SourceRecord(new HashMap<>(), new HashMap<>(), "dummy", recordSchema, before); }
private SourceRecord createCreateRecord() { final Schema recordSchema = SchemaBuilder.struct().field("id", SchemaBuilder.int8()).build(); Envelope envelope = Envelope.defineSchema() .withName("dummy.Envelope") .withRecord(recordSchema) .withSource(SchemaBuilder.struct().build()) .build(); final Struct before = new Struct(recordSchema); before.put("id", (byte)1); final Struct payload = envelope.create(before, null, System.nanoTime()); return new SourceRecord(new HashMap<>(), new HashMap<>(), "dummy", envelope.schema(), payload); }
private SourceRecord createDeleteRecord() { final Schema recordSchema = SchemaBuilder.struct().field("id", SchemaBuilder.int8()).build(); Envelope envelope = Envelope.defineSchema() .withName("dummy.Envelope") .withRecord(recordSchema) .withSource(SchemaBuilder.struct().build()) .build(); final Struct before = new Struct(recordSchema); before.put("id", (byte)1); final Struct payload = envelope.delete(before, null, System.nanoTime()); return new SourceRecord(new HashMap<>(), new HashMap<>(), "dummy", envelope.schema(), payload); }
return SchemaBuilder.int8(); case Types.SMALLINT:
private SchemaBuilder getNumericSchema(Column column) { if (column.scale().isPresent()) { // return sufficiently sized int schema for non-floating point types Integer scale = column.scale().get(); // a negative scale means rounding, e.g. NUMBER(10, -2) would be rounded to hundreds if (scale <= 0) { int width = column.length() - scale; if (width < 3) { return SchemaBuilder.int8(); } else if (width < 5) { return SchemaBuilder.int16(); } else if (width < 10) { return SchemaBuilder.int32(); } else if (width < 19) { return SchemaBuilder.int64(); } } // larger non-floating point types and floating point types use Decimal return super.schemaBuilder(column); } else { return VariableScaleDecimal.builder(); } }
return new SchemaAndValue(SchemaBuilder.int8().optional(), value); } else if (cls.isAssignableFrom(Character.class)) { return new SchemaAndValue(SchemaBuilder.int32().optional(), value == null ? null : new Integer(((char) value)));
private SchemaBuilder convertFieldType(Schema.Type type) { switch (type) { case INT8: return SchemaBuilder.int8(); case INT16: return SchemaBuilder.int16(); case INT32: return SchemaBuilder.int32(); case INT64: return SchemaBuilder.int64(); case FLOAT32: return SchemaBuilder.float32(); case FLOAT64: return SchemaBuilder.float64(); case BOOLEAN: return SchemaBuilder.bool(); case STRING: return SchemaBuilder.string(); default: throw new DataException("Unexpected type in Cast transformation: " + type); } }
@TestFactory @DisplayName("tests for int8 field conversions") public List<DynamicTest> testInt8FieldConverter() { SinkFieldConverter converter = new Int8FieldConverter(); List<DynamicTest> tests = new ArrayList<>(); new ArrayList<>(Arrays.asList(Byte.MIN_VALUE,(byte)0,Byte.MAX_VALUE)).forEach( el -> tests.add(dynamicTest("conversion with " + converter.getClass().getSimpleName() + " for "+el, () -> assertEquals((int)el, ((BsonInt32)converter.toBson(el)).getValue()) )) ); tests.add(dynamicTest("optional type conversions", () -> { Schema valueOptionalDefault = SchemaBuilder.int8().optional().defaultValue((byte)0); assertAll("checks", () -> assertThrows(DataException.class, () -> converter.toBson(null, Schema.INT8_SCHEMA)), () -> assertEquals(new BsonNull(), converter.toBson(null, Schema.OPTIONAL_INT8_SCHEMA)), () -> assertEquals(((Byte)valueOptionalDefault.defaultValue()).intValue(), ((BsonInt32)converter.toBson(null, valueOptionalDefault)).getValue()) ); })); return tests; }
return SchemaBuilder.int8(); case Types.SMALLINT: