本文整理汇总了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"));
}
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例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)));
}
示例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));
}
示例8: AvroSerDe
import org.apache.avro.Schema; //导入方法依赖的package包/类
public AvroSerDe(Config config) {
schema = Schema.parse(config.get(CFG_AVRO_SCHEMA));
}