当前位置: 首页>>代码示例>>Java>>正文


Java SchemaProjectorException类代码示例

本文整理汇总了Java中org.apache.kafka.connect.errors.SchemaProjectorException的典型用法代码示例。如果您正苦于以下问题:Java SchemaProjectorException类的具体用法?Java SchemaProjectorException怎么用?Java SchemaProjectorException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SchemaProjectorException类属于org.apache.kafka.connect.errors包,在下文中一共展示了SchemaProjectorException类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldChangeSchema

import org.apache.kafka.connect.errors.SchemaProjectorException; //导入依赖的package包/类
public static boolean shouldChangeSchema(Schema valueSchema, Schema currentSchema, Compatibility compatibility) {
  if (currentSchema == null) {
    return true;
  }
  if ((valueSchema.version() == null || currentSchema.version() == null) && compatibility != Compatibility.NONE) {
    throw new SchemaProjectorException("Schema version required for " + compatibility.toString() + " compatibility");
  }
  switch (compatibility) {
    case BACKWARD:
    case FULL:
      return (valueSchema.version()).compareTo(currentSchema.version()) > 0;
    case FORWARD:
      return (valueSchema.version()).compareTo(currentSchema.version()) < 0;
    default:
      return !valueSchema.equals(currentSchema);
  }
}
 
开发者ID:jiangxiluning,项目名称:kafka-connect-hdfs,代码行数:18,代码来源:SchemaUtils.java

示例2: project

import org.apache.kafka.connect.errors.SchemaProjectorException; //导入依赖的package包/类
/**
 * This method project a value between compatible schemas and throw exceptions when non compatible schemas are provided
 * @param source the schema used to construct the record
 * @param record the value to project from source schema to target schema
 * @param target the schema to project the record to
 * @return the projected value with target schema
 * @throws SchemaProjectorException
 */
public static Object project(Schema source, Object record, Schema target) throws SchemaProjectorException {
    checkMaybeCompatible(source, target);
    if (source.isOptional() && !target.isOptional()) {
        if (target.defaultValue() != null) {
            if (record != null) {
                return projectRequiredSchema(source, record, target);
            } else {
                return target.defaultValue();
            }
        } else {
            throw new SchemaProjectorException("Writer schema is optional, however, target schema does not provide a default value.");
        }
    } else {
        if (record != null) {
            return projectRequiredSchema(source, record, target);
        } else {
            return null;
        }
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:29,代码来源:SchemaProjector.java

示例3: projectRequiredSchema

import org.apache.kafka.connect.errors.SchemaProjectorException; //导入依赖的package包/类
private static Object projectRequiredSchema(Schema source, Object record, Schema target) throws SchemaProjectorException {
    switch (target.type()) {
        case INT8:
        case INT16:
        case INT32:
        case INT64:
        case FLOAT32:
        case FLOAT64:
        case BOOLEAN:
        case BYTES:
        case STRING:
            return projectPrimitive(source, record, target);
        case STRUCT:
            return projectStruct(source, (Struct) record, target);
        case ARRAY:
            return projectArray(source, record, target);
        case MAP:
            return projectMap(source, record, target);
    }
    return null;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:22,代码来源:SchemaProjector.java

示例4: projectStruct

import org.apache.kafka.connect.errors.SchemaProjectorException; //导入依赖的package包/类
private static Object projectStruct(Schema source, Struct sourceStruct, Schema target) throws SchemaProjectorException {
    Struct targetStruct = new Struct(target);
    for (Field targetField : target.fields()) {
        String fieldName = targetField.name();
        Field sourceField = source.field(fieldName);
        if (sourceField != null) {
            Object sourceFieldValue = sourceStruct.get(fieldName);
            try {
                Object targetFieldValue = project(sourceField.schema(), sourceFieldValue, targetField.schema());
                targetStruct.put(fieldName, targetFieldValue);
            } catch (SchemaProjectorException e) {
                throw new SchemaProjectorException("Error projecting " + sourceField.name(), e);
            }
        } else if (targetField.schema().isOptional()) {
            // Ignore missing field
        } else if (targetField.schema().defaultValue() != null) {
            targetStruct.put(fieldName, targetField.schema().defaultValue());
        } else {
            throw new SchemaProjectorException("Required field `" +  fieldName + "` is missing from source schema: " + source);
        }
    }
    return targetStruct;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:24,代码来源:SchemaProjector.java

示例5: projectStruct

import org.apache.kafka.connect.errors.SchemaProjectorException; //导入依赖的package包/类
private static Object projectStruct(Schema source, Struct sourceStruct, Schema target) throws SchemaProjectorException {
    Struct targetStruct = new Struct(target);
    for (Field targetField : target.fields()) {
        String fieldName = targetField.name();
        Field sourceField = source.field(fieldName);
        if (sourceField != null) {
            Object sourceFieldValue = sourceStruct.get(fieldName);
            try {
                Object targetFieldValue = project(sourceField.schema(), sourceFieldValue, targetField.schema());
                targetStruct.put(fieldName, targetFieldValue);
            } catch (SchemaProjectorException e) {
                throw new SchemaProjectorException("Error projecting " + sourceField.name(), e);
            }
        } else {
            Object targetDefault;
            if (targetField.schema().defaultValue() != null) {
                targetDefault = targetField.schema().defaultValue();
            } else {
                throw new SchemaProjectorException("Cannot project " + source.schema() + " to " + target.schema());
            }
            targetStruct.put(fieldName, targetDefault);
        }
    }
    return targetStruct;
}
 
开发者ID:rogers,项目名称:change-data-capture,代码行数:26,代码来源:SchemaProjector.java

示例6: checkMaybeCompatible

import org.apache.kafka.connect.errors.SchemaProjectorException; //导入依赖的package包/类
private static void checkMaybeCompatible(Schema source, Schema target) {
    if (source.type() != target.type() && !isPromotable(source.type(), target.type())) {
        throw new SchemaProjectorException("Schema type mismatch. source type: " + source.type() + " and target type: " + target.type());
    } else if (!Objects.equals(source.name(), target.name())) {
        throw new SchemaProjectorException("Schema name mismatch. source name: " + source.name() + " and target name: " + target.name());
    } else if (!Objects.equals(source.parameters(), target.parameters())) {
        throw new SchemaProjectorException("Schema parameters not equal. source parameters: " + source.parameters() + " and target parameters: " + target.parameters());
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:10,代码来源:SchemaProjector.java

示例7: projectArray

import org.apache.kafka.connect.errors.SchemaProjectorException; //导入依赖的package包/类
private static Object projectArray(Schema source, Object record, Schema target) throws SchemaProjectorException {
    List<?> array = (List<?>) record;
    List<Object> retArray = new ArrayList<>();
    for (Object entry : array) {
        retArray.add(project(source.valueSchema(), entry, target.valueSchema()));
    }
    return retArray;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:9,代码来源:SchemaProjector.java

示例8: projectMap

import org.apache.kafka.connect.errors.SchemaProjectorException; //导入依赖的package包/类
private static Object projectMap(Schema source, Object record, Schema target) throws SchemaProjectorException {
    Map<?, ?> map = (Map<?, ?>) record;
    Map<Object, Object> retMap = new HashMap<>();
    for (Map.Entry<?, ?> entry : map.entrySet()) {
        Object key = entry.getKey();
        Object value = entry.getValue();
        Object retKey = project(source.keySchema(), key, target.keySchema());
        Object retValue = project(source.valueSchema(), value, target.valueSchema());
        retMap.put(retKey, retValue);
    }
    return retMap;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:13,代码来源:SchemaProjector.java

示例9: projectPrimitive

import org.apache.kafka.connect.errors.SchemaProjectorException; //导入依赖的package包/类
private static Object projectPrimitive(Schema source, Object record, Schema target) throws SchemaProjectorException {
    assert source.type().isPrimitive();
    assert target.type().isPrimitive();
    Object result;
    if (isPromotable(source.type(), target.type())) {
        Number numberRecord = (Number) record;
        switch (target.type()) {
            case INT8:
                result = numberRecord.byteValue();
                break;
            case INT16:
                result = numberRecord.shortValue();
                break;
            case INT32:
                result = numberRecord.intValue();
                break;
            case INT64:
                result = numberRecord.longValue();
                break;
            case FLOAT32:
                result = numberRecord.floatValue();
                break;
            case FLOAT64:
                result = numberRecord.doubleValue();
                break;
            default:
                throw new SchemaProjectorException("Not promotable type.");
        }
    } else {
        result = record;
    }
    return result;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:34,代码来源:SchemaProjector.java

示例10: testProjectMissingRequiredField

import org.apache.kafka.connect.errors.SchemaProjectorException; //导入依赖的package包/类
@Test(expected = SchemaProjectorException.class)
public void testProjectMissingRequiredField() {
    final Schema source = SchemaBuilder.struct().build();
    final Schema target = SchemaBuilder.struct().field("id", SchemaBuilder.INT64_SCHEMA).build();
    SchemaProjector.project(source, new Struct(source), target);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:7,代码来源:SchemaProjectorTest.java


注:本文中的org.apache.kafka.connect.errors.SchemaProjectorException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。