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


Java Schema.toString方法代码示例

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


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

示例1: internalValidate

import org.apache.avro.Schema; //导入方法依赖的package包/类
private void internalValidate(Schema schema) throws SchemaValidationException {
  if (schema.getType() == RECORD) {
    String name = schema.getFullName();
    if (recordTypeNames.contains(name)) {
      return;
    }
    recordTypeNames.add(name);
    for (Field field : schema.getFields()) {
      internalValidate(field.schema());
    }
  } else if (schema.getType() == MAP) {
    internalValidate(schema.getValueType());
  } else if (schema.getType() == ARRAY) {
    internalValidate(schema.getElementType());
  } else if (schema.getType() == UNION) {
    boolean containsBytes = false;
    boolean containsString = false;
    for (Schema unionSchema : schema.getTypes()) {
      if (unionSchema.getType() == Schema.Type.BYTES) {
        containsBytes = true;
      } else if (unionSchema.getType() == Schema.Type.STRING) {
        containsString = true;
      }
      if (containsBytes && containsString) {
        String message = "Schema contains a variant of union[bytes, string]: " + unionSchema.toString();
        throw new SchemaValidationException(message);
      }
      if (COMPOSITE_TYPES.contains(unionSchema)) {
        internalValidate(unionSchema);
      }
    }
  }
}
 
开发者ID:HotelsDotCom,项目名称:jasvorno,代码行数:34,代码来源:SchemaValidator.java

示例2: computeSchema

import org.apache.avro.Schema; //导入方法依赖的package包/类
private Schema computeSchema(String streamName, SamzaSqlRelMessage relMessage) {
  List<Schema.Field> keyFields = new ArrayList<>();
  List<String> fieldNames = relMessage.getFieldNames();
  List<Object> values = relMessage.getFieldValues();

  for (int index = 0; index < fieldNames.size(); index++) {
    if (fieldNames.get(index).equals(SamzaSqlRelMessage.KEY_NAME) || values.get(index) == null) {
      continue;
    }

    Object value = values.get(index);
    Schema avroType;
    if (value instanceof GenericData.Record) {
      avroType = ((GenericData.Record) value).getSchema();
    } else {
      avroType = ReflectData.get().getSchema(value.getClass());
    }
    keyFields.add(new Schema.Field(fieldNames.get(index), avroType, "", null));
  }

  Schema ks = Schema.createRecord(streamName, "", streamName + "_namespace", false);
  ks.setFields(keyFields);
  String schemaStr = ks.toString();
  Schema schema;
  // See whether we have a schema object corresponding to the schemaValue and reuse it.
  // CachedSchemaRegistryClient doesn't like if we recreate schema objects.
  if (_schemas.containsKey(schemaStr)) {
    schema = _schemas.get(schemaStr);
  } else {
    schema = Schema.parse(schemaStr);
    _schemas.put(schemaStr, schema);
  }

  return schema;
}
 
开发者ID:srinipunuru,项目名称:samza-sql-tools,代码行数:36,代码来源:AvroSchemaGenRelConverter.java

示例3: downloadContent

import org.apache.avro.Schema; //导入方法依赖的package包/类
/**
 * Get the avro schema from the active editor and display it in a text format.
 *  
 * @param editor
 */
public void downloadContent(AvroSchemaEditor editor) {
	
	/*
	Schema schema = SchemaBuilder
			.unionOf()
			.record("Author")
			.fields()
			.name("name").type().stringType().noDefault()
			.name("birthday").type().longType().noDefault()				
			.endRecord().and()
			.record("Book")
			.fields()				
			.name("title").type().stringType().noDefault()
			.name("author").type().unionOf()
			.type("Author").and()
			.stringType().endUnion()
			.noDefault()
			.endRecord().endUnion();
			*/
	
	RootNode rootNode = editor.getContext().getRootNode();
	
	IEditorConfiguration editorConfiguration = editor.getEditorConfiguration();		
	
	AvroSchemaGenerator schemaGenerator = editorConfiguration.getGenerator(editor.getContext());
	Schema schema = schemaGenerator.generate(rootNode);
	
	String content = schema == null ? "" : schema.toString(true);
	
	text.setText(content);
	
}
 
开发者ID:Talend,项目名称:avro-schema-editor,代码行数:38,代码来源:ThumbnailView.java

示例4: assertSchemaContains

import org.apache.avro.Schema; //导入方法依赖的package包/类
static void assertSchemaContains(Schema schemaSubset, Schema original) {
  String subset = schemaSubset.toString(false);
  String whole = original.toString(false);
  assertTrue(String.format("Subset '%s' not found in '%s'", subset, whole),
      whole.contains(subset));
}
 
开发者ID:HotelsDotCom,项目名称:avro-compatibility,代码行数:7,代码来源:TestSchemas.java

示例5: format

import org.apache.avro.Schema; //导入方法依赖的package包/类
public String format(String content) {		
	Schema schema = new Schema.Parser().parse(content);
	return schema.toString(true);		
}
 
开发者ID:Talend,项目名称:avro-schema-editor,代码行数:5,代码来源:AvroSchemaFormatter.java


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