本文整理了Java中org.apache.avro.file.FileReader.next()
方法的一些代码示例,展示了FileReader.next()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileReader.next()
方法的具体详情如下:
包路径:org.apache.avro.file.FileReader
类名称:FileReader
方法名:next
[英]Read the next datum from the file.
[中]从文件中读取下一个基准。
代码示例来源:origin: apache/avro
public boolean next(Text key, Text ignore) throws IOException {
if (!reader.hasNext() || reader.pastSync(end))
return false;
datum = reader.next(datum);
if (datum instanceof ByteBuffer) {
ByteBuffer b = (ByteBuffer) datum;
if (b.hasArray()) {
int offset = b.arrayOffset();
int start = b.position();
int length = b.remaining();
key.set(b.array(), offset + start, offset + start + length);
} else {
byte[] bytes = new byte[b.remaining()];
b.duplicate().get(bytes);
key.set(bytes);
}
} else {
key.set(GenericData.get().toString(datum));
}
return true;
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
/**
* Read a single byte from the stream.
*/
@Override
public int read() throws IOException {
if (pos < buffer.length) {
return buffer[pos++];
}
if (!fileReader.hasNext()) {
return -1;
}
writer.write(fileReader.next(), encoder);
encoder.flush();
if (!fileReader.hasNext()) {
// Write a new line after the last Avro record.
output.write(System.getProperty("line.separator")
.getBytes(StandardCharsets.UTF_8));
output.flush();
}
pos = 0;
buffer = output.toByteArray();
output.reset();
return read();
}
代码示例来源:origin: apache/avro
public boolean next(AvroWrapper<T> wrapper, NullWritable ignore)
throws IOException {
if (!reader.hasNext() || reader.pastSync(end))
return false;
wrapper.datum(reader.next(wrapper.datum()));
return true;
}
代码示例来源:origin: apache/hive
@Override
public boolean next(NullWritable nullWritable, AvroGenericRecordWritable record) throws IOException {
if(isEmptyInput || !reader.hasNext() || reader.pastSync(stop)) {
return false;
}
GenericData.Record r = (GenericData.Record)reader.next();
record.setRecord(r);
record.setRecordReaderID(recordReaderID);
record.setFileSchema(reader.getSchema());
return true;
}
代码示例来源:origin: apache/flink
dataFileReader.next(rec);
代码示例来源:origin: apache/flink
User rec = dataFileReader.next();
代码示例来源:origin: apache/avro
@Test
public void testSerialization() throws Exception {
Schema testSchema = getTestSchema();
GenericRecord message = new Record(testSchema);
message.put("name", "testValue");
byte[] data = getSerializedMessage(message, testSchema);
GenericDatumReader<IndexedRecord> reader = new GenericDatumReader<>(testSchema);
SeekableInput in = new SeekableByteArrayInput(data);
FileReader<IndexedRecord> dfr = null;
IndexedRecord result = null;
try {
dfr = DataFileReader.openReader(in, reader);
result = dfr.next();
} finally {
if (dfr != null) {
dfr.close();
}
}
Assert.assertNotNull(result);
Assert.assertTrue(result instanceof GenericRecord);
Assert.assertEquals(new Utf8("testValue"), ((GenericRecord) result).get("name"));
}
}
代码示例来源:origin: org.apache.pig/pig
@Override
public boolean nextKeyValue() throws IOException, InterruptedException {
if (reader.pastSync(end)) {
return false;
}
try {
currentArray = reader.next();
} catch (NoSuchElementException e) {
return false;
}
return true;
}
代码示例来源:origin: Netflix/iceberg
@Override
public D next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
try {
this.reused = reader.next(reused);
return reused;
} catch (IOException e) {
throw new RuntimeIOException(e, "Failed to read next record");
}
}
代码示例来源:origin: Netflix/iceberg
@Override
public D next(D reuse) {
if (!hasNext()) {
throw new NoSuchElementException();
}
try {
return reader.next(reuse);
} catch (IOException e) {
throw new RuntimeIOException(e, "Failed to read next record");
}
}
代码示例来源:origin: tomslabs/avro-utils
public boolean next(Text key, Text value) throws IOException {
if (!reader.hasNext() || reader.pastSync(end)) {
return false;
}
StringBuilder buf = new StringBuilder();
JSONUtils.writeJSON(reader.next(), buf);
key.set(buf.toString());
return true;
}
代码示例来源:origin: stratosphere/stratosphere
@Override
public E nextRecord(E reuseValue) throws IOException {
if (!dataFileReader.hasNext()) {
return null;
}
if (!reuseAvroValue) {
reuseValue = InstantiationUtil.instantiate(avroValueType, Object.class);
}
reuseValue = dataFileReader.next(reuseValue);
return reuseValue;
}
}
代码示例来源:origin: com.google.cloud.bigdataoss/bigquery-connector
@Override
public boolean nextKeyValue() throws IOException, InterruptedException {
Preconditions.checkState(currentRecord != null);
// Stop reading as soon as we hit a sync point out of our split:
if (dataFileReader.hasNext() && !dataFileReader.pastSync(splitStart + splitLength)) {
currentKey.set(currentKey.get() + 1);
dataFileReader.next(currentRecord);
return true;
} else {
return false;
}
}
代码示例来源:origin: org.apache.hadoop.hive/hive-exec
@Override
public boolean next(NullWritable nullWritable, AvroGenericRecordWritable record) throws IOException {
if(!reader.hasNext() || reader.pastSync(stop)) {
return false;
}
GenericData.Record r = (GenericData.Record)reader.next();
record.setRecord(r);
return true;
}
代码示例来源:origin: uber/hudi
public static <T extends SpecificRecordBase> T deserializeAvroMetadata(byte[] bytes,
Class<T> clazz) throws IOException {
DatumReader<T> reader = new SpecificDatumReader<>(clazz);
FileReader<T> fileReader =
DataFileReader.openReader(new SeekableByteArrayInput(bytes), reader);
Preconditions
.checkArgument(fileReader.hasNext(), "Could not deserialize metadata of type " + clazz);
return fileReader.next();
}
}
代码示例来源:origin: jghoman/haivvreo
@Override
public boolean next(NullWritable nullWritable, AvroGenericRecordWritable record) throws IOException {
if(!reader.hasNext() || reader.pastSync(stop)) return false;
GenericData.Record r = (GenericData.Record)reader.next();
record.setRecord(r);
return true;
}
代码示例来源:origin: com.datasalt.pangool/pangool-core
@Override
public boolean nextKeyValue() throws IOException, InterruptedException {
if (!reader.hasNext() || reader.pastSync(end))
return false;
wrapper.datum(reader.next(wrapper.datum()));
return true;
}
代码示例来源:origin: org.apache.avro/avro-mapred
public boolean next(AvroWrapper<T> wrapper, NullWritable ignore)
throws IOException {
if (!reader.hasNext() || reader.pastSync(end))
return false;
wrapper.datum(reader.next(wrapper.datum()));
return true;
}
代码示例来源:origin: datasalt/pangool
@Override
public boolean nextKeyValue() throws IOException, InterruptedException {
if (!reader.hasNext() || reader.pastSync(end)){
return false;
}
wrapper.datum(reader.next(wrapper.datum()));
return true;
}
代码示例来源:origin: apache/sqoop
private boolean checkAvroFileForLine(FileSystem fs, Path p, List<Integer> record)
throws IOException {
SeekableInput in = new FsInput(p, new Configuration());
DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>();
FileReader<GenericRecord> reader = DataFileReader.openReader(in, datumReader);
reader.sync(0);
while (reader.hasNext()) {
if (valueMatches(reader.next(), record)) {
return true;
}
}
return false;
}
内容来源于网络,如有侵权,请联系作者删除!