org.apache.kafka.connect.data.Struct.validate()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(233)

本文整理了Java中org.apache.kafka.connect.data.Struct.validate()方法的一些代码示例,展示了Struct.validate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Struct.validate()方法的具体详情如下:
包路径:org.apache.kafka.connect.data.Struct
类名称:Struct
方法名:validate

Struct.validate介绍

[英]Validates that this struct has filled in all the necessary data with valid values. For required fields without defaults, this validates that a value has been set and has matching types/schemas. If any validation fails, throws a DataException.
[中]验证此结构是否已使用有效值填充所有必需的数据。对于没有默认值的必填字段,这将验证是否已设置值,以及是否具有匹配的类型/架构。如果任何验证失败,将抛出DataException。

代码示例

代码示例来源:origin: confluentinc/ksql

@Override
 public void serialize(
   final Struct struct,
   final JsonGenerator jsonGenerator,
   final SerializerProvider serializerProvider
 ) throws IOException {
  struct.validate();
  jsonGenerator.writeObject(
    objectMapper.readTree(jsonConverter.fromConnectData("", struct.schema(), struct)));
 }
}

代码示例来源:origin: debezium/debezium

/**
 * Assert that the supplied {@link Struct} is {@link Struct#validate() valid} and its {@link Struct#schema() schema}
 * matches that of the supplied {@code schema}.
 *
 * @param struct the {@link Struct} to validate; may not be null
 * @param schema the expected schema of the {@link Struct}; may not be null
 */
public static void schemaMatchesStruct(Struct struct, Schema schema) {
  // First validate the struct itself ...
  try {
    struct.validate();
  }
  catch (DataException e) {
    throw new AssertionError("The struct '" + struct + "' failed to validate", e);
  }
  Schema actualSchema = struct.schema();
  assertThat(actualSchema).isEqualTo(schema);
  fieldsInSchema(struct, schema);
}

代码示例来源:origin: com.github.jcustenborder.kafka.connect/connect-utils

public Struct build() {
  log.trace("build() - Creating struct for {}", this.schema);
  Struct struct = new Struct(this.schema);
  for (KeyValue keyValue : this.fieldValues) {
   log.trace("build() - Setting field value for '{}'", keyValue.name);
   struct.put(keyValue.name, keyValue.value());
  }
  struct.validate();
  return struct;
 }
}

代码示例来源:origin: jcustenborder/kafka-connect-spooldir

public Pair<Struct, Struct> convert(LogEntry entry) {
  final Struct key = null != this.keySchema ? new Struct(this.keySchema) : null;
  final Struct value = new Struct(this.valueSchema);

  if (null != key) {
   for (LogFieldConverter converter : this.keyConverters) {
    converter.convert(entry, key);
   }
  }

  for (LogFieldConverter converter : this.valueConverters) {
   converter.convert(entry, value);
  }

  if (null != key) {
   key.validate();
  }
  value.validate();
  return new ImmutablePair<>(key, value);
 }
}

代码示例来源:origin: com.github.jcustenborder.kafka.connect/kafka-connect-cdc-test

public static Struct struct(JsonStruct storage) {
 Struct struct = new Struct(storage.schema);
 for (FieldValue fieldValue : storage.fieldValues) {
  struct.put(fieldValue.name, fieldValue.value());
 }
 struct.validate();
 return struct;
}

代码示例来源:origin: com.github.jcustenborder.kafka.connect/connect-utils

@Override
 public void serialize(Struct struct, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
  struct.validate();
  Storage result = new Storage();
  result.schema = struct.schema();
  result.fieldValues = new ArrayList<>();
  for (Field field : struct.schema().fields()) {
   log.trace("serialize() - Processing field '{}'", field.name());
   KeyValue keyValue = new KeyValue();
   keyValue.name = field.name();
   keyValue.schema = field.schema();
   keyValue.value(struct.get(field));
   result.fieldValues.add(keyValue);
  }
  jsonGenerator.writeObject(result);
 }
}

代码示例来源:origin: com.github.jcustenborder.kafka.connect/kafka-connect-cdc-test

@Override
 public void serialize(Struct struct, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
  struct.validate();
  JsonStruct result = new JsonStruct();
  result.schema = struct.schema();
  result.fieldValues = new ArrayList<>();
  for (Field field : struct.schema().fields()) {
   FieldValue fieldValue = new FieldValue();
   fieldValue.name = field.name();
   fieldValue.schema = field.schema();
   fieldValue.value(struct.get(field));
   result.fieldValues.add(fieldValue);
  }
  jsonGenerator.writeObject(result);
 }
}

代码示例来源:origin: org.apache.kafka/connect-api

if (!struct.schema().equals(schema))
    throw new DataException("Struct schemas do not match.");
  struct.validate();
  break;
case ARRAY:

相关文章