Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
import org.apache.iceberg.exceptions.RuntimeIOException;
import org.apache.iceberg.io.FileAppender;
import org.apache.parquet.hadoop.ParquetWriter;
import org.apache.parquet.hadoop.metadata.ParquetMetadata;

public class ParquetWriteAdapter<D> implements FileAppender<D> {
private ParquetWriter<D> writer = null;
private long numRecords = 0L;
private ParquetMetadata footer = null;

public ParquetWriteAdapter(ParquetWriter<D> writer) throws IOException {
public ParquetWriteAdapter(ParquetWriter<D> writer) {
this.writer = writer;
}

@Override
public void add(D datum) {
try {
numRecords += 1L;
writer.write(datum);
} catch (IOException e) {
throw new RuntimeIOException(e, "Failed to write record %s", datum);
Expand All @@ -46,7 +46,8 @@ public void add(D datum) {

@Override
public Metrics metrics() {
return new Metrics(numRecords, null, null, null);
Preconditions.checkState(footer != null, "Cannot produce metrics until closed");
return ParquetMetrics.fromMetadata(footer);
}

@Override
Expand All @@ -60,6 +61,7 @@ public long length() {
public void close() throws IOException {
if (writer != null) {
writer.close();
this.footer = writer.getFooter();
this.writer = null;
}
}
Expand Down