use of org.apache.iceberg.Transaction in project drill by apache.
the class IcebergQueriesTest method writeAndCommitDataFile.
private static void writeAndCommitDataFile(Table table, String name, FileFormat fileFormat, Iterable<Record> records) throws IOException {
OutputFile outputFile = table.io().newOutputFile(new Path(table.location(), fileFormat.addExtension(name)).toUri().getPath());
FileAppender<Record> fileAppender = new GenericAppenderFactory(table.schema()).newAppender(outputFile, fileFormat);
fileAppender.addAll(records);
fileAppender.close();
DataFile dataFile = DataFiles.builder(table.spec()).withInputFile(outputFile.toInputFile()).withMetrics(fileAppender.metrics()).build();
Transaction transaction = table.newTransaction();
transaction.newAppend().appendFile(dataFile).commit();
transaction.commitTransaction();
}
Aggregations