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());
}
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);
}
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());
}
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());
}
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());
}
Aggregations