當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。