protected Schema toKsqlFieldSchema(final Schema schema) { // CHECKSTYLE_RULES.ON: CyclomaticComplexity switch (schema.type()) { case INT8: case INT16: case INT32: return Schema.OPTIONAL_INT32_SCHEMA; case FLOAT32: case FLOAT64: return Schema.OPTIONAL_FLOAT64_SCHEMA; case INT64: case STRING: case BOOLEAN: return SchemaBuilder.type(schema.type()).optional().build(); case ARRAY: return toKsqlArraySchema(schema); case MAP: return toKsqlMapSchema(schema); case STRUCT: return toKsqlStructSchema(schema); default: throw new UnsupportedTypeException( String.format("Unsupported type: %s", schema.type().getName())); } }
/** * Add to the supplied {@link SchemaBuilder} a field for the column with the given information. * * @param builder the schema builder; never null * @param column the column definition * @param mapper the mapping function for the column; may be null if the columns is not to be mapped to different values */ protected void addField(SchemaBuilder builder, Column column, ColumnMapper mapper) { SchemaBuilder fieldBuilder = valueConverterProvider.schemaBuilder(column); if (fieldBuilder != null) { if (mapper != null) { // Let the mapper add properties to the schema ... mapper.alterFieldSchema(column, fieldBuilder); } if (column.isOptional()) fieldBuilder.optional(); // if the default value is provided if (column.hasDefaultValue()) { fieldBuilder.defaultValue(column.defaultValue()); } builder.field(column.name(), fieldBuilder.build()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("- field '{}' ({}{}) from column {}", column.name(), builder.isOptional() ? "OPTIONAL " : "", fieldBuilder.type(), column); } } else { LOGGER.warn("Unexpected JDBC type '{}' for column '{}' that will be ignored", column.jdbcType(), column.name()); } }
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(); }
public Schema schema() { SchemaBuilder builder = SchemaBuilder.type(knownType); if (optional) { builder.optional(); } return builder.schema(); } }
void addField(SchemaBuilder builder, String name, Schema.Type schemaType) { log.trace("addField() - name = {} schemaType = {}", name, schemaType); builder.field( name, SchemaBuilder.type(schemaType).optional().build() ); }
break; default: builder = SchemaBuilder.type(this.type); break;
break; default: builder = SchemaBuilder.type(this.type); break;
/** * Add to the supplied {@link SchemaBuilder} a field for the column with the given information. * * @param builder the schema builder; never null * @param column the column definition * @param mapper the mapping function for the column; may be null if the columns is not to be mapped to different values */ protected void addField(SchemaBuilder builder, Column column, ColumnMapper mapper) { SchemaBuilder fieldBuilder = valueConverterProvider.schemaBuilder(column); if (fieldBuilder != null) { if (mapper != null) { // Let the mapper add properties to the schema ... mapper.alterFieldSchema(column, fieldBuilder); } if (column.isOptional()) fieldBuilder.optional(); // if the default value is provided if (column.hasDefaultValue()) { fieldBuilder.defaultValue(column.defaultValue()); } builder.field(column.name(), fieldBuilder.build()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("- field '{}' ({}{}) from column {}", column.name(), builder.isOptional() ? "OPTIONAL " : "", fieldBuilder.type(), column); } } else { LOGGER.warn("Unexpected JDBC type '{}' for column '{}' that will be ignored", column.jdbcType(), column.name()); } }
if (field.schema().defaultValue() != null) { Schema fieldSchema = field.schema(); fieldBuilder.defaultValue(castValueToType(fieldSchema, fieldSchema.defaultValue(), fieldBuilder.type())); builder.optional(); if (valueSchema.defaultValue() != null) builder.defaultValue(castValueToType(valueSchema, valueSchema.defaultValue(), builder.type()));