當前位置: 首頁>>代碼示例>>Java>>正文


Java Schema.isOptional方法代碼示例

本文整理匯總了Java中org.apache.kafka.connect.data.Schema.isOptional方法的典型用法代碼示例。如果您正苦於以下問題:Java Schema.isOptional方法的具體用法?Java Schema.isOptional怎麽用?Java Schema.isOptional使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.kafka.connect.data.Schema的用法示例。


在下文中一共展示了Schema.isOptional方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toAmpool

import org.apache.kafka.connect.data.Schema; //導入方法依賴的package包/類
public Object toAmpool(Object data, Schema fieldSchema) {
  if(!fieldSchema.isOptional()) {

    if(data == null)
      throw new DataException("error: schema not optional but data was null");

    return toAmpool(data);
  }

  if(data != null) {
    return toAmpool(data);
  }

  if(fieldSchema.defaultValue() != null) {
    return toAmpool(fieldSchema.defaultValue());
  }

  return null;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:20,代碼來源:SinkFieldConverter.java

示例2: apply

import org.apache.kafka.connect.data.Schema; //導入方法依賴的package包/類
@Override
public R apply(R record) {
    final Schema schema = operatingSchema(record);
    requireSchema(schema, "updating schema metadata");
    final boolean isArray = schema.type() == Schema.Type.ARRAY;
    final boolean isMap = schema.type() == Schema.Type.MAP;
    final Schema updatedSchema = new ConnectSchema(
            schema.type(),
            schema.isOptional(),
            schema.defaultValue(),
            schemaName != null ? schemaName : schema.name(),
            schemaVersion != null ? schemaVersion : schema.version(),
            schema.doc(),
            schema.parameters(),
            schema.fields(),
            isMap ? schema.keySchema() : null,
            isMap || isArray ? schema.valueSchema() : null
    );
    return newRecord(record, updatedSchema);
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:21,代碼來源:SetSchemaMetadata.java

示例3: getOrBuildSchema

import org.apache.kafka.connect.data.Schema; //導入方法依賴的package包/類
private Schema getOrBuildSchema(Schema valueSchema) {
    Schema updatedSchema = schemaUpdateCache.get(valueSchema);
    if (updatedSchema != null)
        return updatedSchema;

    final SchemaBuilder builder;
    if (wholeValueCastType != null) {
        builder = SchemaUtil.copySchemaBasics(valueSchema, convertFieldType(wholeValueCastType));
    } else {
        builder = SchemaUtil.copySchemaBasics(valueSchema, SchemaBuilder.struct());
        for (Field field : valueSchema.fields()) {
            SchemaBuilder fieldBuilder =
                    convertFieldType(casts.containsKey(field.name()) ? casts.get(field.name()) : field.schema().type());
            if (field.schema().isOptional())
                fieldBuilder.optional();
            if (field.schema().defaultValue() != null)
                fieldBuilder.defaultValue(castValueToType(field.schema().defaultValue(), fieldBuilder.type()));
            builder.field(field.name(), fieldBuilder.build());
        }
    }

    if (valueSchema.isOptional())
        builder.optional();
    if (valueSchema.defaultValue() != null)
        builder.defaultValue(castValueToType(valueSchema.defaultValue(), builder.type()));

    updatedSchema = builder.build();
    schemaUpdateCache.put(valueSchema, updatedSchema);
    return updatedSchema;
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:31,代碼來源:Cast.java

示例4: copySchemaBasics

import org.apache.kafka.connect.data.Schema; //導入方法依賴的package包/類
private static SchemaBuilder copySchemaBasics(Schema source, SchemaBuilder target) {
  if (source.isOptional()) {
    target.optional();
  }
  if (source.defaultValue() != null && source.type() != Schema.Type.STRUCT) {
    final Object preProcessedDefaultValue = preProcessValue(source.defaultValue(), source, target);
    target.defaultValue(preProcessedDefaultValue);
  }
  return target;
}
 
開發者ID:chaokunyang,項目名稱:jkes,代碼行數:11,代碼來源:DataConverter.java

示例5: convertToConnect

import org.apache.kafka.connect.data.Schema; //導入方法依賴的package包/類
private static Object convertToConnect(Schema schema, JsonNode jsonValue) {
    final Schema.Type schemaType;
    if (schema != null) {
        schemaType = schema.type();
        if (jsonValue.isNull()) {
            if (schema.defaultValue() != null)
                return schema.defaultValue(); // any logical type conversions should already have been applied
            if (schema.isOptional())
                return null;
            throw new DataException("Invalid null value for required " + schemaType +  " field");
        }
    } else {
        switch (jsonValue.getNodeType()) {
            case NULL:
                // Special case. With no schema
                return null;
            case BOOLEAN:
                schemaType = Schema.Type.BOOLEAN;
                break;
            case NUMBER:
                if (jsonValue.isIntegralNumber())
                    schemaType = Schema.Type.INT64;
                else
                    schemaType = Schema.Type.FLOAT64;
                break;
            case ARRAY:
                schemaType = Schema.Type.ARRAY;
                break;
            case OBJECT:
                schemaType = Schema.Type.MAP;
                break;
            case STRING:
                schemaType = Schema.Type.STRING;
                break;

            case BINARY:
            case MISSING:
            case POJO:
            default:
                schemaType = null;
                break;
        }
    }

    final JsonToConnectTypeConverter typeConverter = TO_CONNECT_CONVERTERS.get(schemaType);
    if (typeConverter == null)
        throw new DataException("Unknown schema type: " + String.valueOf(schemaType));

    Object converted = typeConverter.convert(schema, jsonValue);
    if (schema != null && schema.name() != null) {
        LogicalTypeConverter logicalConverter = TO_CONNECT_LOGICAL_CONVERTERS.get(schema.name());
        if (logicalConverter != null)
            converted = logicalConverter.convert(schema, converted);
    }
    return converted;
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:57,代碼來源:JsonConverter.java


注:本文中的org.apache.kafka.connect.data.Schema.isOptional方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。