chrismead:
私はこのコードを変換したいと思います:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.parquet.column.page.PageReadStore;
import org.apache.parquet.example.data.simple.SimpleGroup;
import org.apache.parquet.example.data.simple.convert.GroupRecordConverter;
import org.apache.parquet.hadoop.ParquetFileReader;
import org.apache.parquet.hadoop.util.HadoopInputFile;
import org.apache.parquet.io.ColumnIOFactory;
import org.apache.parquet.io.MessageColumnIO;
import org.apache.parquet.io.RecordReader;
import org.apache.parquet.schema.MessageType;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ParquetReaderUtils {
public static Parquet getParquetData(String filePath) throws IOException {
List<SimpleGroup> simpleGroups = new ArrayList<>();
ParquetFileReader reader = ParquetFileReader.open(HadoopInputFile.fromPath(new Path(filePath), new Configuration()));
MessageType schema = reader.getFooter().getFileMetaData().getSchema();
//List<Type> fields = schema.getFields();
PageReadStore pages;
while ((pages = reader.readNextRowGroup()) != null) {
long rows = pages.getRowCount();
MessageColumnIO columnIO = new ColumnIOFactory().getColumnIO(schema);
RecordReader recordReader = columnIO.getRecordReader(pages, new GroupRecordConverter(schema));
for (int i = 0; i < rows; i++) {
SimpleGroup simpleGroup = (SimpleGroup) recordReader.read();
simpleGroups.add(simpleGroup);
}
}
reader.close();
return new Parquet(simpleGroups, schema);
}
}
(からなるhttps://www.arm64.ca/post/reading-parquet-files-java/)
代わりに、filePathにのByteArrayOutputStreamパラメータを取ります。
これは可能ですか?私はorg.apache.parquet.hadoopでParquetStreamReaderが表示されません。
すべてのヘルプは大歓迎です。私は寄木細工がカフカから来ると、ファイルがかなり遅いに出て多くのメッセージのそれぞれを記述するためのテストアプリケーションを記述しようとしています。
m4gic:
(出力ストリームの内容は寄木細工互換でなければなりませんが)ので、より深いテストを行わずに、私はこのクラスにしようとするだろう。私は(何かが間違っていた場合ParquetFileReaderはinstance.toString()アウトを印刷します)簡単にByteArrayの処理されたの識別を行うことがstreamIDでを置きます。
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import org.apache.parquet.io.DelegatingSeekableInputStream;
import org.apache.parquet.io.InputFile;
import org.apache.parquet.io.SeekableInputStream;
public class ParquetStream implements InputFile
{
private final String streamId;
private final byte[] data;
public class SeekableByteArrayInputStream extends ByteArrayInputStream
{
public SeekableByteArrayInputStream(byte[] buf)
{
super(buf);
}
public void setPos(int pos)
{
this.pos = pos;
}
public int getPos()
{
return this.pos;
}
}
public ParquetStream(String streamId, ByteArrayOutputStream stream)
{
this.streamId = streamId;
this.data = stream.toByteArray();
}
@Override
public long getLength() throws IOException
{
return this.data.length;
}
@Override
public SeekableInputStream newStream() throws IOException
{
return new DelegatingSeekableInputStream(new SeekableByteArrayInputStream(this.data))
{
@Override
public void seek(long newPos) throws IOException
{
((SeekableByteArrayInputStream) this.getStream()).setPos(new Long(newPos).intValue());
}
@Override
public long getPos() throws IOException
{
return new Integer(((SeekableByteArrayInputStream) this.getStream()).getPos()).longValue();
}
};
}
@Override
public String toString()
{
return new StringBuilder("ParquetStream[").append(streamId).append("]").toString();
}
}