Search in sources :

Example 1 with Overwrite

use of org.apache.drill.metastore.iceberg.operate.Overwrite in project drill by apache.

the class OperationTransformer method toOverwrite.

public Overwrite toOverwrite(String location, Expression expression, List<T> units) {
    WriteData writeData = context.transformer().inputData().units(units).execute();
    File file = context.fileWriter().records(writeData.records()).location(location).name(UUID.randomUUID().toString()).write();
    DataFile dataFile = DataFiles.builder(context.table().spec()).withInputFile(file.input()).withMetrics(file.metrics()).withPartition(writeData.partition()).build();
    return new Overwrite(dataFile, expression);
}
Also used : DataFile(org.apache.iceberg.DataFile) Overwrite(org.apache.drill.metastore.iceberg.operate.Overwrite) File(org.apache.drill.metastore.iceberg.write.File) DataFile(org.apache.iceberg.DataFile)

Example 2 with Overwrite

use of org.apache.drill.metastore.iceberg.operate.Overwrite in project drill by apache.

the class TestTablesOperationTransformer method testToOverwriteOperation.

@Test
public void testToOverwriteOperation() {
    TableMetadataUnit unit = TableMetadataUnit.builder().storagePlugin("dfs").workspace("tmp").tableName("nation").metadataKey("dir0").build();
    TableKey tableKey = new TableKey(unit.storagePlugin(), unit.workspace(), unit.tableName());
    Map<MetastoreColumn, Object> filterConditions = new HashMap<>(tableKey.toFilterConditions());
    filterConditions.put(MetastoreColumn.METADATA_KEY, unit.metadataKey());
    String location = tableKey.toLocation(TestTablesOperationTransformer.location);
    Expression expression = new FilterTransformer().transform(filterConditions);
    Overwrite operation = transformer.toOverwrite(location, expression, Collections.singletonList(unit));
    assertEquals(expression.toString(), operation.filter().toString());
    Path path = new Path(String.valueOf(operation.dataFile().path()));
    File file = new File(path.toUri().getPath());
    assertTrue(file.exists());
    assertEquals(location, path.getParent().toUri().getPath());
}
Also used : Path(org.apache.hadoop.fs.Path) Overwrite(org.apache.drill.metastore.iceberg.operate.Overwrite) TableMetadataUnit(org.apache.drill.metastore.components.tables.TableMetadataUnit) HashMap(java.util.HashMap) FilterExpression(org.apache.drill.metastore.expressions.FilterExpression) Expression(org.apache.iceberg.expressions.Expression) File(java.io.File) MetastoreColumn(org.apache.drill.metastore.MetastoreColumn) FilterTransformer(org.apache.drill.metastore.iceberg.transform.FilterTransformer) Test(org.junit.Test) IcebergBaseTest(org.apache.drill.metastore.iceberg.IcebergBaseTest)

Aggregations

Overwrite (org.apache.drill.metastore.iceberg.operate.Overwrite)2 File (java.io.File)1 HashMap (java.util.HashMap)1 MetastoreColumn (org.apache.drill.metastore.MetastoreColumn)1 TableMetadataUnit (org.apache.drill.metastore.components.tables.TableMetadataUnit)1 FilterExpression (org.apache.drill.metastore.expressions.FilterExpression)1 IcebergBaseTest (org.apache.drill.metastore.iceberg.IcebergBaseTest)1 FilterTransformer (org.apache.drill.metastore.iceberg.transform.FilterTransformer)1 File (org.apache.drill.metastore.iceberg.write.File)1 Path (org.apache.hadoop.fs.Path)1 DataFile (org.apache.iceberg.DataFile)1 Expression (org.apache.iceberg.expressions.Expression)1 Test (org.junit.Test)1