org.apache.gobblin.util.AvroUtils.switchName()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(128)

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

AvroUtils.switchName介绍

[英]Copies the input org.apache.avro.Schema but changes the schema name.
[中]复制输入组织。阿帕奇。阿夫罗。架构,但更改架构名称。

代码示例

代码示例来源:origin: apache/incubator-gobblin

/**
 * Register a schema to the Kafka schema registry under the provided input name. This method will change the name
 * of the schema to the provided name. This is useful because certain services (like Gobblin kafka adaptor and
 * Camus) get the schema for a topic by querying for the latest schema with the topic name, requiring the topic
 * name and schema name to match for all topics. This method registers the schema to the schema registry in such a
 * way that any schema can be written to any topic.
 *
 * @param schema {@link org.apache.avro.Schema} to register.
 * @param overrideName Name of the schema when registerd to the schema registry. This name should match the name
 *                     of the topic where instances will be published.
 * @return schema ID of the registered schema.
 * @throws SchemaRegistryException if registration failed
 */
@Override
public String register(Schema schema, String overrideName) throws SchemaRegistryException {
 return register(AvroUtils.switchName(schema, overrideName));
}

代码示例来源:origin: apache/incubator-gobblin

/**
 * Register a schema to the Kafka schema registry under the provided input name. This method will change the name
 * of the schema to the provided name if configured to do so. This is useful because certain services (like Gobblin kafka adaptor and
 * Camus) get the schema for a topic by querying for the latest schema with the topic name, requiring the topic
 * name and schema name to match for all topics. If it is not configured to switch names, this is useful for the case
 * where the Kafka topic and Avro schema names do not match. This method registers the schema to the schema registry in such a
 * way that any schema can be written to any topic.
 *
 * @param schema {@link org.apache.avro.Schema} to register.
 * @param name Name of the schema when registerd to the schema registry. This name should match the name
 *                     of the topic where instances will be published.
 * @return schema ID of the registered schema.
 * @throws SchemaRegistryException if registration failed
 */
@Override
public MD5Digest register(String name, Schema schema) throws SchemaRegistryException {
 PostMethod post = new PostMethod(url);
 if (this.switchTopicNames) {
  return register(AvroUtils.switchName(schema, name), post);
 } else {
  post.addParameter("name", name);
  return register(schema, post);
 }
}

代码示例来源:origin: apache/incubator-gobblin

@Test
public void testSwitchName() {
 String originalName = "originalName";
 String newName = "newName";
 Schema schema = SchemaBuilder.record(originalName).fields().
   requiredDouble("double").optionalFloat("float").endRecord();
 Schema newSchema = AvroUtils.switchName(schema, newName);
 Assert.assertEquals(newSchema.getName(), newName);
 for(Schema.Field field : newSchema.getFields()) {
  Assert.assertEquals(field, schema.getField(field.name()));
 }
 Assert.assertEquals(newName, AvroUtils.switchName(schema, newName).getName());
 Assert.assertEquals(schema,
   AvroUtils.switchName(AvroUtils.switchName(schema, newName), schema.getName()));
}

代码示例来源:origin: org.apache.gobblin/gobblin-kafka-common

/**
 * Register a schema to the Kafka schema registry under the provided input name. This method will change the name
 * of the schema to the provided name. This is useful because certain services (like Gobblin kafka adaptor and
 * Camus) get the schema for a topic by querying for the latest schema with the topic name, requiring the topic
 * name and schema name to match for all topics. This method registers the schema to the schema registry in such a
 * way that any schema can be written to any topic.
 *
 * @param schema {@link org.apache.avro.Schema} to register.
 * @param overrideName Name of the schema when registerd to the schema registry. This name should match the name
 *                     of the topic where instances will be published.
 * @return schema ID of the registered schema.
 * @throws SchemaRegistryException if registration failed
 */
@Override
public String register(Schema schema, String overrideName) throws SchemaRegistryException {
 return register(AvroUtils.switchName(schema, overrideName));
}

代码示例来源:origin: org.apache.gobblin/gobblin-kafka-common

/**
 * Register a schema to the Kafka schema registry under the provided input name. This method will change the name
 * of the schema to the provided name if configured to do so. This is useful because certain services (like Gobblin kafka adaptor and
 * Camus) get the schema for a topic by querying for the latest schema with the topic name, requiring the topic
 * name and schema name to match for all topics. If it is not configured to switch names, this is useful for the case
 * where the Kafka topic and Avro schema names do not match. This method registers the schema to the schema registry in such a
 * way that any schema can be written to any topic.
 *
 * @param schema {@link org.apache.avro.Schema} to register.
 * @param name Name of the schema when registerd to the schema registry. This name should match the name
 *                     of the topic where instances will be published.
 * @return schema ID of the registered schema.
 * @throws SchemaRegistryException if registration failed
 */
@Override
public MD5Digest register(String name, Schema schema) throws SchemaRegistryException {
 PostMethod post = new PostMethod(url);
 if (this.switchTopicNames) {
  return register(AvroUtils.switchName(schema, name), post);
 } else {
  post.addParameter("name", name);
  return register(schema, post);
 }
}

相关文章