Java Code Examples for org.apache.kafka.connect.data.Schema#OPTIONAL_FLOAT32_SCHEMA
The following examples show how to use
org.apache.kafka.connect.data.Schema#OPTIONAL_FLOAT32_SCHEMA .
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: StringParserTest.java From connect-utils with Apache License 2.0 | 7 votes |
@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); } }
Example 2
Source File: UnivocityFileReader.java From kafka-connect-fs with Apache License 2.0 | 6 votes |
private Schema strToSchema(String dataType) { switch (DataType.valueOf(dataType.trim().toUpperCase())) { case BYTE: return dataTypeMappingError && !allowNulls ? Schema.INT8_SCHEMA : Schema.OPTIONAL_INT8_SCHEMA; case SHORT: return dataTypeMappingError && !allowNulls ? Schema.INT16_SCHEMA : Schema.OPTIONAL_INT16_SCHEMA; case INT: return dataTypeMappingError && !allowNulls ? Schema.INT32_SCHEMA : Schema.OPTIONAL_INT32_SCHEMA; case LONG: return dataTypeMappingError && !allowNulls ? Schema.INT64_SCHEMA : Schema.OPTIONAL_INT64_SCHEMA; case FLOAT: return dataTypeMappingError && !allowNulls ? Schema.FLOAT32_SCHEMA : Schema.OPTIONAL_FLOAT32_SCHEMA; case DOUBLE: return dataTypeMappingError && !allowNulls ? Schema.FLOAT64_SCHEMA : Schema.OPTIONAL_FLOAT64_SCHEMA; case BOOLEAN: return dataTypeMappingError && !allowNulls ? Schema.BOOLEAN_SCHEMA : Schema.OPTIONAL_BOOLEAN_SCHEMA; case BYTES: return dataTypeMappingError && !allowNulls ? Schema.BYTES_SCHEMA : Schema.OPTIONAL_BYTES_SCHEMA; case STRING: default: return dataTypeMappingError && !allowNulls ? Schema.STRING_SCHEMA : Schema.OPTIONAL_STRING_SCHEMA; } }
Example 3
Source File: SchemaTest.java From schema-registry-transfer-smt with Apache License 2.0 | 5 votes |
@Test public void testNonByteTypeSchemas() { Schema[] schemas = new Schema[]{ // Boolean Schema.BOOLEAN_SCHEMA, Schema.OPTIONAL_BOOLEAN_SCHEMA, // Integers Schema.INT8_SCHEMA, Schema.INT16_SCHEMA, Schema.INT32_SCHEMA, Schema.INT64_SCHEMA, Schema.OPTIONAL_INT8_SCHEMA, Schema.OPTIONAL_INT16_SCHEMA, Schema.OPTIONAL_INT32_SCHEMA, Schema.OPTIONAL_INT64_SCHEMA, // Floats Schema.FLOAT32_SCHEMA, Schema.FLOAT64_SCHEMA, Schema.OPTIONAL_FLOAT32_SCHEMA, Schema.OPTIONAL_FLOAT64_SCHEMA, // String Schema.STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA, // Struct with a field of bytes SchemaBuilder.struct().name("record"). field("foo", Schema.BYTES_SCHEMA) .build(), SchemaBuilder.struct().name("record"). field("foo", Schema.OPTIONAL_BYTES_SCHEMA) .build(), // map<bytes, bytes> SchemaBuilder.map(Schema.BYTES_SCHEMA, Schema.OPTIONAL_BYTES_SCHEMA).build(), // array<bytes> SchemaBuilder.array(Schema.OPTIONAL_BYTES_SCHEMA).build() }; for (Schema s : schemas) { assertFalse(ConnectSchemaUtil.isBytesSchema(s)); } }
Example 4
Source File: JsonNodeTest.java From connect-utils with Apache License 2.0 | 5 votes |
@Test public void nullableTests() throws IOException { 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) { JsonNode inputNode = null; Object actual = this.parser.parseJsonNode(schema, inputNode); assertNull(actual); inputNode = objectMapper.readTree("{\"foo\": null}"); inputNode = inputNode.findValue("foo"); actual = this.parser.parseJsonNode(schema, inputNode); assertNull(actual); } }
Example 5
Source File: JsonFileReader.java From kafka-connect-fs with Apache License 2.0 | 4 votes |
private static Schema extractSchema(JsonNode jsonNode) { switch (jsonNode.getNodeType()) { case BOOLEAN: return Schema.OPTIONAL_BOOLEAN_SCHEMA; case NUMBER: if (jsonNode.isShort()) { return Schema.OPTIONAL_INT8_SCHEMA; } else if (jsonNode.isInt()) { return Schema.OPTIONAL_INT32_SCHEMA; } else if (jsonNode.isLong()) { return Schema.OPTIONAL_INT64_SCHEMA; } else if (jsonNode.isFloat()) { return Schema.OPTIONAL_FLOAT32_SCHEMA; } else if (jsonNode.isDouble()) { return Schema.OPTIONAL_FLOAT64_SCHEMA; } else if (jsonNode.isBigInteger()) { return Schema.OPTIONAL_INT64_SCHEMA; } else if (jsonNode.isBigDecimal()) { return Schema.OPTIONAL_FLOAT64_SCHEMA; } else { return Schema.OPTIONAL_FLOAT64_SCHEMA; } case STRING: return Schema.OPTIONAL_STRING_SCHEMA; case BINARY: return Schema.OPTIONAL_BYTES_SCHEMA; case ARRAY: Iterable<JsonNode> elements = jsonNode::elements; Schema arraySchema = StreamSupport.stream(elements.spliterator(), false) .findFirst().map(JsonFileReader::extractSchema) .orElse(SchemaBuilder.struct().build()); return SchemaBuilder.array(arraySchema).build(); case OBJECT: SchemaBuilder builder = SchemaBuilder.struct(); jsonNode.fields() .forEachRemaining(field -> builder.field(field.getKey(), extractSchema(field.getValue()))); return builder.build(); default: return SchemaBuilder.struct().optional().build(); } }