Java Code Examples for org.apache.kafka.connect.data.SchemaBuilder#int8()
The following examples show how to use
org.apache.kafka.connect.data.SchemaBuilder#int8() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CloudPubSubSinkTaskTest.java From pubsub with Apache License 2.0 | 5 votes |
/** Tests that an exception is thrown when the schema of the value is not BYTES. */ @Test public void testPutPrimitives() { task.start(props); SinkRecord record8 = new SinkRecord(null, -1, null, null, SchemaBuilder.int8(), (byte) 5, -1); SinkRecord record16 = new SinkRecord(null, -1, null, null, SchemaBuilder.int16(), (short) 5, -1); SinkRecord record32 = new SinkRecord(null, -1, null, null, SchemaBuilder.int32(), (int) 5, -1); SinkRecord record64 = new SinkRecord(null, -1, null, null, SchemaBuilder.int64(), (long) 5, -1); SinkRecord recordFloat32 = new SinkRecord(null, -1, null, null, SchemaBuilder.float32(), (float) 8, -1); SinkRecord recordFloat64 = new SinkRecord(null, -1, null, null, SchemaBuilder.float64(), (double) 8, -1); SinkRecord recordBool = new SinkRecord(null, -1, null, null, SchemaBuilder.bool(), true, -1); SinkRecord recordString = new SinkRecord(null, -1, null, null, SchemaBuilder.string(), "Test put.", -1); List<SinkRecord> list = new ArrayList<>(); list.add(record8); list.add(record16); list.add(record32); list.add(record64); list.add(recordFloat32); list.add(recordFloat64); list.add(recordBool); list.add(recordString); task.put(list); }
Example 2
Source File: MsSqlTableMetadataProvider.java From kafka-connect-cdc-mssql with Apache License 2.0 | 4 votes |
Schema generateSchema(ResultSet resultSet, final ChangeKey changeKey, final String columnName) throws SQLException { boolean optional = resultSet.getBoolean(2); String dataType = resultSet.getString(3); int scale = resultSet.getInt(4); SchemaBuilder builder; log.trace("{}: columnName='{}' dataType='{}' scale={} optional={}", changeKey, columnName, dataType, scale, optional); switch (dataType) { case "bigint": builder = SchemaBuilder.int64(); break; case "bit": builder = SchemaBuilder.bool(); break; case "char": case "varchar": case "text": case "nchar": case "nvarchar": case "ntext": case "uniqueidentifier": builder = SchemaBuilder.string(); break; case "smallmoney": case "money": case "decimal": case "numeric": builder = Decimal.builder(scale); break; case "binary": case "image": case "varbinary": builder = SchemaBuilder.bytes(); break; case "date": builder = Date.builder(); break; case "datetime": case "datetime2": case "smalldatetime": builder = Timestamp.builder(); break; case "time": builder = Time.builder(); break; case "int": builder = SchemaBuilder.int32(); break; case "smallint": builder = SchemaBuilder.int16(); break; case "tinyint": builder = SchemaBuilder.int8(); break; case "real": builder = SchemaBuilder.float32(); break; case "float": builder = SchemaBuilder.float64(); break; default: throw new DataException( String.format("Could not process (dataType = '%s', optional = %s, scale = %d) for %s.", dataType, optional, scale, changeKey ) ); } log.trace("{}: columnName='{}' schema.type='{}' schema.name='{}'", changeKey, columnName, builder.type(), builder.name()); builder.parameters( ImmutableMap.of(Change.ColumnValue.COLUMN_NAME, columnName) ); if (optional) { builder.optional(); } return builder.build(); }
Example 3
Source File: DataUtilityTest.java From kinesis-kafka-connector with Apache License 2.0 | 3 votes |
@Test public void parseInt8ValueTest(){ Schema schema = SchemaBuilder.int8(); ByteBuffer actual = DataUtility.parseValue(schema, (byte) 2); ByteBuffer expected = ByteBuffer.allocate(1).put((byte) 2); Assert.assertTrue(actual.equals(expected)); }
Example 4
Source File: DataUtilityTest.java From kinesis-kafka-connector with Apache License 2.0 | 3 votes |
@Test public void parseArrayValueTest(){ Schema valueSchema = SchemaBuilder.int8(); Schema schema = SchemaBuilder.array(valueSchema); Object[] arrayOfInt8 = { (byte) 1, (byte) 2, (byte) 3, (byte) 4}; ByteBuffer actual = DataUtility.parseValue(schema, arrayOfInt8); ByteBuffer expected = ByteBuffer.allocate(4).put((byte) 1).put( (byte) 2).put( (byte) 3).put( (byte) 4); Assert.assertTrue(actual.equals(expected)); }