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


Java SchemaBuilder.optional方法代码示例

本文整理汇总了Java中org.apache.kafka.connect.data.SchemaBuilder.optional方法的典型用法代码示例。如果您正苦于以下问题:Java SchemaBuilder.optional方法的具体用法?Java SchemaBuilder.optional怎么用?Java SchemaBuilder.optional使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.kafka.connect.data.SchemaBuilder的用法示例。


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

示例1: getOrBuildSchema

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的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

示例2: convertFieldSchema

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
/**
 * Convert the schema for a field of a Struct with a primitive schema to the schema to be used for the flattened
 * version, taking into account that we may need to override optionality and default values in the flattened version
 * to take into account the optionality and default values of parent/ancestor schemas
 * @param orig the original schema for the field
 * @param optional whether the new flattened field should be optional
 * @param defaultFromParent the default value either taken from the existing field or provided by the parent
 */
private Schema convertFieldSchema(Schema orig, boolean optional, Object defaultFromParent) {
    // Note that we don't use the schema translation cache here. It might save us a bit of effort, but we really
    // only care about caching top-level schema translations.

    final SchemaBuilder builder = SchemaUtil.copySchemaBasics(orig);
    if (optional)
        builder.optional();
    if (defaultFromParent != null)
        builder.defaultValue(defaultFromParent);
    return builder.build();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:20,代码来源:Flatten.java

示例3: copySchemaBasics

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的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

示例4: buildStringSchema

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
/**
 * Build Kafka string schema definition
 * 
 * @param optional  Whether or not the field is optional
 * @param backwards Whether or not this field needs to be backwards
 *                  compatible
 * 
 * @return Kafka string schema
 */
private Schema buildStringSchema (boolean optional, boolean backwards) {
    SchemaBuilder fieldBuilder = SchemaBuilder.string();
    if (optional) {
        fieldBuilder.optional();
    }
    if (backwards) {
        /* add empty string default for missing values */
        fieldBuilder.defaultValue(new String(""));
    }
    
    return fieldBuilder.build();
}
 
开发者ID:dbvisitsoftware,项目名称:replicate-connector-for-kafka,代码行数:22,代码来源:ReplicateSchemaConverter.java

示例5: buildTimestampSchema

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
/**
 * Build Kafka timestamp schema definition
 * 
 * @param optional  Whether or not the field is optional
 * @param backwards Whether or not this field needs to be backwards
 *                  compatible
 * 
 * @return Kafka timestamp schema
 */
private Schema buildTimestampSchema (boolean optional, boolean backwards) {
    SchemaBuilder fieldBuilder = Timestamp.builder();
    if (optional) {
        fieldBuilder.optional();
    }
    if (backwards) {
        /* add epoch start as default for missing values */
        fieldBuilder.defaultValue(new Date(0));
    }
    return fieldBuilder.build();
}
 
开发者ID:dbvisitsoftware,项目名称:replicate-connector-for-kafka,代码行数:21,代码来源:ReplicateSchemaConverter.java

示例6: buildBytesSchema

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
/**
 * Build Kafka raw bytes schema definition
 * 
 * @param optional  Whether or not the field is nullable
 * @param backwards Whether or not this field needs to be backwards
 *                  compatible
 * 
 * @return Kafka bytes schema
 */
private Schema buildBytesSchema (boolean optional, boolean backwards) {
    SchemaBuilder fieldBuilder = SchemaBuilder.bytes();
    if (optional) {
        fieldBuilder.optional();
    }
    if (backwards) {
        /* add empty byte as default for missing values */
        fieldBuilder.defaultValue(new byte[] {});
    }
    
    return fieldBuilder.build();
}
 
开发者ID:dbvisitsoftware,项目名称:replicate-connector-for-kafka,代码行数:22,代码来源:ReplicateSchemaConverter.java

示例7: copySchemaBasics

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
private SchemaBuilder copySchemaBasics(Schema source, SchemaBuilder target) {
  if (source.isOptional()) {
    target.optional();
  }
  if (source.defaultValue() != null && source.type() != Schema.Type.STRUCT) {
    final Object defaultVal = preProcessValue(source.defaultValue(), source, target);
    target.defaultValue(defaultVal);
  }
  return target;
}
 
开发者ID:confluentinc,项目名称:kafka-connect-elasticsearch,代码行数:11,代码来源:DataConverter.java

示例8: generateSchema

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
Schema generateSchema(ResultSet resultSet, final String columnName) throws SQLException {
  SchemaBuilder builder = null;

  String dataType = resultSet.getString(2);
  int scale = resultSet.getInt(3);
  boolean nullable = "Y".equalsIgnoreCase(resultSet.getString(4));
  String comments = resultSet.getString(5);

  if (TYPE_LOOKUP.containsKey(dataType)) {
    Schema.Type type = TYPE_LOOKUP.get(dataType);
    builder = SchemaBuilder.type(type);
  } else if ("NUMBER".equals(dataType)) {
    builder = Decimal.builder(scale);
  } else if (matches(TIMESTAMP_PATTERN, dataType)) {
    builder = Timestamp.builder();
  } else if (matches(TIMESTAMP_WITH_LOCAL_TIMEZONE, dataType)) {
    builder = Timestamp.builder();
  } else if (matches(TIMESTAMP_WITH_TIMEZONE, dataType)) {
    builder = Timestamp.builder();
  } else if ("DATE".equals(dataType)) {
    builder = Timestamp.builder();
  } else {
    String message = String.format("Could not determine schema type for column %s. dataType = %s", columnName, dataType);
    throw new DataException(message);
  }


  if (nullable) {
    builder.optional();
  }

  if (!Strings.isNullOrEmpty(comments)) {
    builder.doc(comments);
  }

  builder.parameters(
      ImmutableMap.of(Change.ColumnValue.COLUMN_NAME, columnName)
  );

  return builder.build();
}
 
开发者ID:jcustenborder,项目名称:kafka-connect-cdc-oracle,代码行数:42,代码来源:Oracle12cTableMetadataProvider.java

示例9: build

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
public Schema build() {
  log.trace(this.toString());
  SchemaBuilder builder;

  switch (this.type) {
    case MAP:
      Preconditions.checkNotNull(this.keySchema, "keySchema cannot be null.");
      Preconditions.checkNotNull(this.valueSchema, "valueSchema cannot be null.");
      builder = SchemaBuilder.map(this.keySchema, this.valueSchema);
      break;
    case ARRAY:
      Preconditions.checkNotNull(this.valueSchema, "valueSchema cannot be null.");
      builder = SchemaBuilder.array(this.valueSchema);
      break;
    default:
      builder = SchemaBuilder.type(this.type);
      break;
  }

  if (Schema.Type.STRUCT == this.type) {
    for (Map.Entry<String, Schema> kvp : this.fieldSchemas.entrySet()) {
      builder.field(kvp.getKey(), kvp.getValue());
    }
  }

  if (!Strings.isNullOrEmpty(this.name)) {
    builder.name(this.name);
  }

  if (!Strings.isNullOrEmpty(this.doc)) {
    builder.doc(this.doc);
  }

  if (null != this.defaultValue) {
    Object value;
    switch (this.type) {
      case INT8:
        value = ((Number) this.defaultValue).byteValue();
        break;
      case INT16:
        value = ((Number) this.defaultValue).shortValue();
        break;
      case INT32:
        value = ((Number) this.defaultValue).intValue();
        break;
      case INT64:
        value = ((Number) this.defaultValue).longValue();
        break;
      case FLOAT32:
        value = ((Number) this.defaultValue).floatValue();
        break;
      case FLOAT64:
        value = ((Number) this.defaultValue).doubleValue();
        break;
      default:
        value = this.defaultValue;
        break;
    }
    builder.defaultValue(value);
  }

  if (null != this.parameters) {
    builder.parameters(this.parameters);
  }

  if (this.isOptional) {
    builder.optional();
  }

  if (null != this.version) {
    builder.version(this.version);
  }

  return builder.build();
}
 
开发者ID:jcustenborder,项目名称:connect-utils,代码行数:76,代码来源:SchemaSerializationModule.java

示例10: buildDecimalSchema

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
/**
 * Build decimal schema from scale and precision
 * 
 * @param scale     The numeric scale
 * @param precision The numeric precision
 * @param optional  Whether or not the field is optional
 * @param backwards Whether or not this field needs to be backwards
 *                  compatible
 * 
 * @return Kafka decimal schema
 */
private Schema buildDecimalSchema (
    int     scale,
    int     precision,
    boolean optional,
    boolean backwards
) {
    SchemaBuilder fieldBuilder = null;
    if (
        scale > 0 ||
        precision <= 0 ||
        precision - scale >= ColumnDataDecoder.NUMBER_LONG_MAX_PRECISION
    ) {
        /* decimal type */
        fieldBuilder = Decimal.builder(scale);
        if (optional) {
            fieldBuilder.optional();
        }
        if (backwards) {
            /* add zero default for missing values */
            fieldBuilder.defaultValue(BigDecimal.ZERO.setScale(scale));
        }
    }
    else if (
        scale <= 0 && 
        precision - Math.abs (scale) < 
            ColumnDataDecoder.NUMBER_INTEGER_MAX_PRECISION
    ) {
        /* integer data type */
        fieldBuilder = SchemaBuilder.int32();
        if (optional) {
            fieldBuilder.optional();
        }
        if (backwards) {
            /* add zero default for missing values */
            fieldBuilder.defaultValue(0);
        }
    }
    else {
        /* long data type */
        fieldBuilder = SchemaBuilder.int64();
        if (optional) {
            fieldBuilder.optional();
        }
        if (backwards) {
            /* add zero default for missing values */
            fieldBuilder.defaultValue(0L);
        }
    }
    return fieldBuilder.build();
}
 
开发者ID:dbvisitsoftware,项目名称:replicate-connector-for-kafka,代码行数:62,代码来源:ReplicateSchemaConverter.java


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