Search in sources :

Example 1 with Expression

use of org.apache.iceberg.expressions.Expression in project drill by apache.

the class TablesOperationTransformer method toOverwrite.

/**
 * Groups given list of {@link TableMetadataUnit} based on table key
 * (storage plugin, workspace and table name), each table key is grouped by metadata key.
 * Each group is converted into overwrite operation.
 *
 * @param units Metastore component units
 * @return list of overwrite operations
 */
public List<Overwrite> toOverwrite(List<TableMetadataUnit> units) {
    Map<TableKey, Map<String, List<TableMetadataUnit>>> data = units.stream().collect(Collectors.groupingBy(TableKey::of, Collectors.groupingBy(TableMetadataUnit::metadataKey)));
    return data.entrySet().parallelStream().map(dataEntry -> dataEntry.getValue().entrySet().parallelStream().map(operationEntry -> {
        TableKey tableKey = dataEntry.getKey();
        String location = tableKey.toLocation(context.table().location());
        Map<MetastoreColumn, Object> filterConditions = new HashMap<>(tableKey.toFilterConditions());
        filterConditions.put(MetastoreColumn.METADATA_KEY, operationEntry.getKey());
        Expression expression = context.transformer().filter().transform(filterConditions);
        return toOverwrite(location, expression, operationEntry.getValue());
    }).collect(Collectors.toList())).flatMap(Collection::stream).collect(Collectors.toList());
}
Also used : TableMetadataUnit(org.apache.drill.metastore.components.tables.TableMetadataUnit) HashMap(java.util.HashMap) Expression(org.apache.iceberg.expressions.Expression) Map(java.util.Map) HashMap(java.util.HashMap) MetastoreColumn(org.apache.drill.metastore.MetastoreColumn)

Example 2 with Expression

use of org.apache.iceberg.expressions.Expression in project drill by apache.

the class FilterExpressionVisitor method visit.

@Override
public Expression visit(DoubleExpressionPredicate.And expression) {
    Expression right = expression.right().accept(this);
    Expression left = expression.left().accept(this);
    return Expressions.and(right, left);
}
Also used : Expression(org.apache.iceberg.expressions.Expression) FilterExpression(org.apache.drill.metastore.expressions.FilterExpression)

Example 3 with Expression

use of org.apache.iceberg.expressions.Expression 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)

Example 4 with Expression

use of org.apache.iceberg.expressions.Expression in project drill by apache.

the class TestFilterTransformer method testCombineTwo.

@Test
public void testCombineTwo() {
    Expression expected = Expressions.and(Expressions.equal("a", 1), Expressions.equal("a", 2));
    Expression actual = transformer.combine(Expressions.equal("a", 1), Expressions.equal("a", 2));
    assertEquals(expected.toString(), actual.toString());
}
Also used : FilterExpression(org.apache.drill.metastore.expressions.FilterExpression) Expression(org.apache.iceberg.expressions.Expression) Test(org.junit.Test) IcebergBaseTest(org.apache.drill.metastore.iceberg.IcebergBaseTest)

Example 5 with Expression

use of org.apache.iceberg.expressions.Expression in project drill by apache.

the class TestFilterTransformer method testToFilterEqual.

@Test
public void testToFilterEqual() {
    Expression expected = Expressions.equal(MetastoreColumn.ROW_GROUP_INDEX.columnName(), 1);
    Expression actual = transformer.transform(FilterExpression.equal(MetastoreColumn.ROW_GROUP_INDEX, 1));
    assertEquals(expected.toString(), actual.toString());
}
Also used : FilterExpression(org.apache.drill.metastore.expressions.FilterExpression) Expression(org.apache.iceberg.expressions.Expression) Test(org.junit.Test) IcebergBaseTest(org.apache.drill.metastore.iceberg.IcebergBaseTest)

Aggregations

Expression (org.apache.iceberg.expressions.Expression)40 FilterExpression (org.apache.drill.metastore.expressions.FilterExpression)28 IcebergBaseTest (org.apache.drill.metastore.iceberg.IcebergBaseTest)26 Test (org.junit.Test)26 MetastoreColumn (org.apache.drill.metastore.MetastoreColumn)5 Map (java.util.Map)4 Path (org.apache.hadoop.fs.Path)3 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)2 HashMap (java.util.HashMap)2 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)2 TableMetadataUnit (org.apache.drill.metastore.components.tables.TableMetadataUnit)2 Delete (org.apache.drill.metastore.iceberg.operate.Delete)2 MapWork (org.apache.hadoop.hive.ql.plan.MapWork)2 TableScan (org.apache.iceberg.TableScan)2 Domain (com.facebook.presto.common.predicate.Domain)1 Marker (com.facebook.presto.common.predicate.Marker)1 Range (com.facebook.presto.common.predicate.Range)1 SortedRangeSet (com.facebook.presto.common.predicate.SortedRangeSet)1 ValueSet (com.facebook.presto.common.predicate.ValueSet)1 ArrayType (com.facebook.presto.common.type.ArrayType)1