Search in sources :

Example 11 with DataException

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

the class OffsetUtils method validateFormat.

public static <K, V> void validateFormat(Map<K, V> offsetData) {
    // that there's not usable concept of offsets in your source system.
    if (offsetData == null)
        return;
    for (Map.Entry<K, V> entry : offsetData.entrySet()) {
        if (!(entry.getKey() instanceof String))
            throw new DataException("Offsets may only use String keys");
        Object value = entry.getValue();
        if (value == null)
            continue;
        Schema.Type schemaType = ConnectSchema.schemaType(value.getClass());
        if (schemaType == null)
            throw new DataException("Offsets may only contain primitive types as values, but field " + entry.getKey() + " contains " + value.getClass());
        if (!schemaType.isPrimitive())
            throw new DataException("Offsets may only contain primitive types as values, but field " + entry.getKey() + " contains " + schemaType);
    }
}
Also used : DataException(org.apache.kafka.connect.errors.DataException) ConnectSchema(org.apache.kafka.connect.data.ConnectSchema) Schema(org.apache.kafka.connect.data.Schema) Map(java.util.Map)

Aggregations

DataException (org.apache.kafka.connect.errors.DataException)11 Map (java.util.Map)5 HashMap (java.util.HashMap)4 ConnectSchema (org.apache.kafka.connect.data.ConnectSchema)4 Schema (org.apache.kafka.connect.data.Schema)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 Calendar (java.util.Calendar)2 Field (org.apache.kafka.connect.data.Field)2 ByteBuffer (java.nio.ByteBuffer)1 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1 SerializationException (org.apache.kafka.common.errors.SerializationException)1 SchemaBuilder (org.apache.kafka.connect.data.SchemaBuilder)1 Struct (org.apache.kafka.connect.data.Struct)1 SchemaBuilderException (org.apache.kafka.connect.errors.SchemaBuilderException)1