本文整理匯總了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));
}