本文整理汇总了Java中org.apache.avro.generic.GenericData.Record.get方法的典型用法代码示例。如果您正苦于以下问题:Java Record.get方法的具体用法?Java Record.get怎么用?Java Record.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.generic.GenericData.Record
的用法示例。
在下文中一共展示了Record.get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import org.apache.avro.generic.GenericData.Record; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public JetstreamEvent decode(byte[] key, byte[] message) {
ByteArrayInputStream stream = new ByteArrayInputStream(message);
BinaryDecoder reusedDecoder = decoderHolder.get();
BinaryDecoder decoder = DecoderFactory.get().directBinaryDecoder(stream, reusedDecoder);
if (reusedDecoder == null) {
decoderHolder.set(decoder);
}
Record object;
try {
object = reader.read(null, decoder);
Map<String, Object> m = (Map<String, Object>) object.get(MAP_FIELD_NAME);
return new JetstreamEvent(m);
} catch (IOException e) {
throw new IllegalArgumentException("Can not read the avro message", e);
}
}
示例2: CamusAvroWrapper
import org.apache.avro.generic.GenericData.Record; //导入方法依赖的package包/类
public CamusAvroWrapper(Record record) {
super(record);
Record header = (Record) super.getRecord().get("header");
if (header != null) {
if (header.get("server") != null) {
put(new Text("server"), new Text(header.get("server").toString()));
}
if (header.get("service") != null) {
put(new Text("service"), new Text(header.get("service").toString()));
}
}
}
示例3: getTimestamp
import org.apache.avro.generic.GenericData.Record; //导入方法依赖的package包/类
@Override
public long getTimestamp() {
Record header = (Record) super.getRecord().get("header");
if (header != null && header.get("time") != null) {
return (Long) header.get("time");
} else if (super.getRecord().get("timestamp") != null) {
return (Long) super.getRecord().get("timestamp");
} else {
return System.currentTimeMillis();
}
}
示例4: nextKeyValue
import org.apache.avro.generic.GenericData.Record; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public boolean nextKeyValue() throws IOException {
while (lines.size() == 0) {
// If we're out of lines in the current record, then get the next record -
// unless we're out of records or past the end of where we should be.
while (reader == null || reader.hasNext() == false
|| reader.pastSync(end)) {
return false;
}
Record record = reader.next();
lld = new LogLineData();
lld.setBlockNumber((Long) record.get("blockNumber"));
lld.setCreateTime((Long) record.get("createTime"));
second = (Long) record.get("second");
lineNumber = 0;
lines.addAll((List<Record>) record.get("logLines"));
}
Record line = lines.pollFirst();
long ms = (Long) line.get("ms");
String message = line.get("message").toString();
int eventId = (Integer) line.get("eventId");
++lineNumber;
key.set(lld);
key.setLineNumber(lineNumber);
key.setTimestamp(second * 1000 + ms);
key.setEventId(eventId);
value.set(message);
pos = reader.tell();
return true;
}
示例5: convertUnionDefaultValueFromJson
import org.apache.avro.generic.GenericData.Record; //导入方法依赖的package包/类
/**
* Convert union default value from json.
*
* @param acceptableValuesArray the acceptable values array
* @param jsonValue the json value
* @return the record
*/
private static Record convertUnionDefaultValueFromJson(GenericData.Array<Record> acceptableValuesArray, JsonNode jsonValue) {
if (jsonValue == null) {
return null;
}
for (Record type : acceptableValuesArray) {
if (matchesType(type, jsonValue)) {
if (type.getSchema().getName().equals(ENUM_FIELD_TYPE)) {
String val = jsonValue.asText();
@SuppressWarnings("unchecked")
GenericData.Array<Record> symbolsArray = (GenericData.Array<Record>) type.get(SYMBOLS);
boolean found = false;
for (Record enumSymbol : symbolsArray) {
String symbol = (String) enumSymbol.get(SYMBOL);
if (symbol.equals(val)) {
found = true;
break;
}
}
if (!found) {
continue;
}
}
if (type.getSchema().getField(DEFAULT_VALUE) != null) {
setDefaultValueFromJsonNode(type, jsonValue);
}
return type;
}
}
return null;
}
示例6: customizeSchemaField
import org.apache.avro.generic.GenericData.Record; //导入方法依赖的package包/类
@Override
protected void customizeSchemaField(Field avroField, Record fieldType) {
if (fieldType.getSchema().getName().equals(ARRAY_FIELD_TYPE)) {
GenericData.EnumSymbol overrideStrategy =
(GenericData.EnumSymbol) fieldType.get(OVERRIDE_STRATEGY);
if (overrideStrategy != null
&& !overrideStrategy.toString().equalsIgnoreCase(OverrideStrategy.REPLACE.name())) {
avroField.addProp(OVERRIDE_STRATEGY, overrideStrategy.toString().toLowerCase());
}
}
}
示例7: next
import org.apache.avro.generic.GenericData.Record; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public boolean next(LogLineData key, Text value) throws IOException {
while (lines.size() == 0) {
// If we're out of lines in the current record, then get the next record -
// unless we're out of records or past the end of where we should be.
while (reader == null || reader.hasNext() == false
|| reader.pastSync(end)) {
// If we have another file, then init that and keep going, otherwise,
// just return false.
currentFile++;
if (currentFile >= split.getNumPaths()) {
return false;
}
initCurrentFile();
}
Record record = reader.next();
lld = new LogLineData();
lld.setBlockNumber((Long) record.get("blockNumber"));
lld.setCreateTime((Long) record.get("createTime"));
second = (Long) record.get("second");
lineNumber = 0;
lines.addAll((List<Record>) record.get("logLines"));
}
Record line = lines.pollFirst();
long ms = (Long) line.get("ms");
String message = line.get("message").toString();
int eventId = (Integer) line.get("eventId");
++lineNumber;
key.set(lld);
key.setLineNumber(lineNumber);
key.setTimestamp(second * 1000 + ms);
key.setEventId(eventId);
value.set(message);
pos = reader.tell();
return true;
}
示例8: nextKeyValue
import org.apache.avro.generic.GenericData.Record; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public boolean nextKeyValue() throws IOException {
while (lines.size() == 0) {
// If we're out of lines in the current record, then get the next record -
// unless we're out of records or past the end of where we should be.
while (reader == null || reader.hasNext() == false
|| reader.pastSync(end)) {
// If we have another file, then init that and keep going, otherwise,
// just return false.
currentFile++;
if (currentFile >= split.getNumPaths()) {
return false;
}
initCurrentFile();
}
Record record = reader.next();
lld = new LogLineData();
lld.setBlockNumber((Long) record.get("blockNumber"));
lld.setCreateTime((Long) record.get("createTime"));
second = (Long) record.get("second");
lineNumber = 0;
lines.addAll((List<Record>) record.get("logLines"));
}
Record line = lines.pollFirst();
long ms = (Long) line.get("ms");
String message = line.get("message").toString();
int eventId = (Integer) line.get("eventId");
++lineNumber;
key.set(lld);
key.setLineNumber(lineNumber);
key.setTimestamp(second * 1000 + ms);
key.setEventId(eventId);
value.set(message);
pos = reader.tell();
return true;
}
示例9: run
import org.apache.avro.generic.GenericData.Record; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void run(String[] args) throws IOException {
if (args.length == 0) {
args = new String[] { "-" };
}
for (String file : args) {
InputStream in = null;
if (file.equals("-")) {
in = System.in;
} else {
in = new FileInputStream(file);
}
GenericDatumReader<Record> datumReader = new GenericDatumReader<Record>(
Schemas.getSchema("logBlock"));
reader = new DataFileStream<Record>(in, datumReader);
datumReader.setExpected(Schemas.getSchema("logBlock"));
datumReader.setSchema(reader.getSchema());
// read lines!
while (lines.size() == 0) {
if (reader.hasNext() == false) {
break;
}
Record record = reader.next();
Long blockNumber = (Long) record.get("blockNumber");
Long createTime = (Long) record.get("createTime");
Long second = (Long) record.get("second");
Long lineNumber = 0l;
for (Record line : (List<Record>) record.get("logLines")) {
Long ms = (Long) line.get("ms");
String message = line.get("message").toString();
Integer eventId = (Integer) line.get("eventId");
Long timestamp = second * 1000 + ms;
System.out.println(timestamp + "\t" + message + "\t" + eventId + "\t"
+ createTime + "\t" + blockNumber + "\t" + lineNumber);
lineNumber++;
}
}
}
}
示例10: test
import org.apache.avro.generic.GenericData.Record; //导入方法依赖的package包/类
@Test
public void test() throws IOException {
ReferenceManager manager = new ReferenceManager();
GenericData model = new GenericData();
model.addLogicalTypeConversion(manager.getTracker());
model.addLogicalTypeConversion(manager.getHandler());
Schema parentSchema = Schema.createRecord("Parent", null, null, false);
Schema placeholderSchema = Schema.createRecord("Placeholder", null, null, false);
List<Schema.Field> placeholderFields = new ArrayList<Schema.Field>();
placeholderFields.add( // at least one field is needed to be a valid schema
new Schema.Field("id", Schema.create(Schema.Type.LONG), null, null));
placeholderSchema.setFields(placeholderFields);
Referenceable idRef = new Referenceable("id");
Schema parentRefSchema = Schema.createUnion(
Schema.create(Schema.Type.NULL),
Schema.create(Schema.Type.LONG),
idRef.addToSchema(placeholderSchema));
Reference parentRef = new Reference("parent");
List<Schema.Field> childFields = new ArrayList<Schema.Field>();
childFields.add(new Schema.Field("c", Schema.create(Schema.Type.STRING), null, null));
childFields.add(new Schema.Field("parent", parentRefSchema, null, null));
Schema childSchema = parentRef.addToSchema(
Schema.createRecord("Child", null, null, false, childFields));
List<Schema.Field> parentFields = new ArrayList<Schema.Field>();
parentFields.add(new Schema.Field("id", Schema.create(Schema.Type.LONG), null, null));
parentFields.add(new Schema.Field("p", Schema.create(Schema.Type.STRING), null, null));
parentFields.add(new Schema.Field("child", childSchema, null, null));
parentSchema.setFields(parentFields);
Schema schema = idRef.addToSchema(parentSchema);
System.out.println("Schema: " + schema.toString(true));
Record parent = new Record(schema);
parent.put("id", 1L);
parent.put("p", "parent data!");
Record child = new Record(childSchema);
child.put("c", "child data!");
child.put("parent", parent);
parent.put("child", child);
// serialization round trip
File data = AvroTestUtil.write(temp, model, schema, parent);
List<Record> records = AvroTestUtil.read(model, schema, data);
Record actual = records.get(0);
// because the record is a recursive structure, equals won't work
Assert.assertEquals("Should correctly read back the parent id",
1L, actual.get("id"));
Assert.assertEquals("Should correctly read back the parent data",
new Utf8("parent data!"), actual.get("p"));
Record actualChild = (Record) actual.get("child");
Assert.assertEquals("Should correctly read back the child data",
new Utf8("child data!"), actualChild.get("c"));
Object childParent = actualChild.get("parent");
Assert.assertTrue("Should have a parent Record object",
childParent instanceof Record);
Record childParentRecord = (Record) actualChild.get("parent");
Assert.assertEquals("Should have the right parent id",
1L, childParentRecord.get("id"));
Assert.assertEquals("Should have the right parent data",
new Utf8("parent data!"), childParentRecord.get("p"));
}