Search in sources :

Example 1 with SchemaBuilderException

use of org.apache.kafka.connect.errors.SchemaBuilderException in project kafka by apache.

the class SchemaBuilder method defaultValue.

/**
     * Set the default value for this schema. The value is validated against the schema type, throwing a
     * {@link SchemaBuilderException} if it does not match.
     * @param value the default value
     * @return the SchemaBuilder
     */
public SchemaBuilder defaultValue(Object value) {
    checkNull(DEFAULT_FIELD, defaultValue);
    checkNotNull(TYPE_FIELD, type, DEFAULT_FIELD);
    try {
        ConnectSchema.validateValue(this, value);
    } catch (DataException e) {
        throw new SchemaBuilderException("Invalid default value", e);
    }
    defaultValue = value;
    return this;
}
Also used : DataException(org.apache.kafka.connect.errors.DataException) SchemaBuilderException(org.apache.kafka.connect.errors.SchemaBuilderException)

Example 2 with SchemaBuilderException

use of org.apache.kafka.connect.errors.SchemaBuilderException in project kafka by apache.

the class SchemaBuilder method field.

/**
     * Add a field to this struct schema. Throws a SchemaBuilderException if this is not a struct schema.
     * @param fieldName the name of the field to add
     * @param fieldSchema the Schema for the field's value
     * @return the SchemaBuilder
     */
public SchemaBuilder field(String fieldName, Schema fieldSchema) {
    if (type != Type.STRUCT)
        throw new SchemaBuilderException("Cannot create fields on type " + type);
    int fieldIndex = fields.size();
    fields.add(new Field(fieldName, fieldIndex, fieldSchema));
    return this;
}
Also used : SchemaBuilderException(org.apache.kafka.connect.errors.SchemaBuilderException)

Aggregations

SchemaBuilderException (org.apache.kafka.connect.errors.SchemaBuilderException)2 DataException (org.apache.kafka.connect.errors.DataException)1