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


Java Schema.parse方法代码示例

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


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

示例1: checkNumeric

import org.apache.avro.Schema; //导入方法依赖的package包/类
private void checkNumeric(String type, Object value) throws Exception {
	String def =
			"{\"type\":\"record\",\"name\":\"X\",\"fields\":"
					+"[{\"type\":\""+type+"\",\"name\":\"n\"}]}";
	Schema schema = Schema.parse(def);
	DatumReader<GenericRecord> reader =
			new GenericDatumReader<GenericRecord>(schema);
	
	String[] records = {"{\"n\":1}", "{\"n\":1.0}"};
	
	for (String record : records) {
		Decoder decoder = new ExtendedJsonDecoder(schema, record);
		GenericRecord r = reader.read(null, decoder);
		Assert.assertEquals(value, r.get("n"));
	}
}
 
开发者ID:Celos,项目名称:avro-json-decoder,代码行数:17,代码来源:ExtendedJsonDecoderTest.java

示例2: testReorderFields

import org.apache.avro.Schema; //导入方法依赖的package包/类
@Test public void testReorderFields() throws Exception {
	String w =
			"{\"type\":\"record\",\"name\":\"R\",\"fields\":"
					+"[{\"type\":\"long\",\"name\":\"l\"},"
					+"{\"type\":{\"type\":\"array\",\"items\":\"int\"},\"name\":\"a\"}"
					+"]}";
	Schema ws = Schema.parse(w);
	String data = "{\"a\":[1,2],\"l\":100}{\"l\": 200, \"a\":[1,2]}";
	ExtendedJsonDecoder in = new ExtendedJsonDecoder(ws, data);
	Assert.assertEquals(100, in.readLong());
	in.skipArray();
	Assert.assertEquals(200, in.readLong());
	in.skipArray();
}
 
开发者ID:Celos,项目名称:avro-json-decoder,代码行数:15,代码来源:ExtendedJsonDecoderTest.java

示例3: EventReader

import org.apache.avro.Schema; //导入方法依赖的package包/类
/**
 * Create a new Event Reader
 * @param in
 * @throws IOException
 */
@SuppressWarnings("deprecation")
public EventReader(DataInputStream in) throws IOException {
  this.in = in;
  this.version = in.readLine();
  
  if (!EventWriter.VERSION.equals(version)) {
    throw new IOException("Incompatible event log version: "+version);
  }

  Schema myschema = new SpecificData(Event.class.getClassLoader()).getSchema(Event.class);
  this.schema = Schema.parse(in.readLine());
  this.reader = new SpecificDatumReader(schema, myschema);
  this.decoder = DecoderFactory.get().jsonDecoder(schema, in);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:EventReader.java

示例4: 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

示例5: readRecord

import org.apache.avro.Schema; //导入方法依赖的package包/类
public GenericRecord readRecord(String schemaString, String jsonData) throws IOException {
	Schema schema = Schema.parse(schemaString);
	Decoder decoder = new ExtendedJsonDecoder(schema, jsonData);
	DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>(schema);
	return datumReader.read(null, decoder);
}
 
开发者ID:Celos,项目名称:avro-json-decoder,代码行数:7,代码来源:ExtendedJsonDecoderTest.java

示例6: getMapOutputSchema

import org.apache.avro.Schema; //导入方法依赖的package包/类
/** Return a job's map output key schema. */
public static Schema getMapOutputSchema(Configuration job) {
  return Schema.parse(job.get(MAP_OUTPUT_SCHEMA, job.get(OUTPUT_SCHEMA)));
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:5,代码来源:AvroJob.java

示例7: getOutputSchema

import org.apache.avro.Schema; //导入方法依赖的package包/类
/** Return a job's output key schema. */
public static Schema getOutputSchema(Configuration job) {
  return Schema.parse(job.get(OUTPUT_SCHEMA));
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:5,代码来源:AvroJob.java

示例8: AvroSerDe

import org.apache.avro.Schema; //导入方法依赖的package包/类
public AvroSerDe(Config config) {
  schema = Schema.parse(config.get(CFG_AVRO_SCHEMA));
}
 
开发者ID:srinipunuru,项目名称:samza-sql-tools,代码行数:4,代码来源:AvroSerDeFactory.java


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