use of org.apache.iceberg.expressions.Expression in project drill by apache.
the class TestFilterTransformer method testToFilterGreaterThan.
@Test
public void testToFilterGreaterThan() {
Expression expected = Expressions.greaterThan(MetastoreColumn.ROW_GROUP_INDEX.columnName(), 1);
Expression actual = transformer.transform(FilterExpression.greaterThan(MetastoreColumn.ROW_GROUP_INDEX, 1));
assertEquals(expected.toString(), actual.toString());
}
use of org.apache.iceberg.expressions.Expression in project drill by apache.
the class TestFilterTransformer method testToFilterMetadataTypesAll.
@Test
public void testToFilterMetadataTypesAll() {
Expression expected = Expressions.alwaysTrue();
Expression actual = transformer.transform(Sets.newHashSet(MetadataType.PARTITION, MetadataType.FILE, MetadataType.ALL));
assertEquals(expected.toString(), actual.toString());
}
use of org.apache.iceberg.expressions.Expression in project drill by apache.
the class TestFilterTransformer method testCombineFour.
@Test
public void testCombineFour() {
Expression expected = Expressions.and(Expressions.equal("a", 1), Expressions.equal("a", 2), Expressions.equal("a", 3), Expressions.equal("a", 4));
Expression actual = transformer.combine(Expressions.equal("a", 1), Expressions.equal("a", 2), Expressions.equal("a", 3), Expressions.equal("a", 4));
assertEquals(expected.toString(), actual.toString());
}
use of org.apache.iceberg.expressions.Expression in project drill by apache.
the class TestFilterTransformer method testToFilterIsNull.
@Test
public void testToFilterIsNull() {
Expression expected = Expressions.isNull(MetastoreColumn.ROW_GROUP_INDEX.columnName());
Expression actual = transformer.transform(FilterExpression.isNull(MetastoreColumn.ROW_GROUP_INDEX));
assertEquals(expected.toString(), actual.toString());
}
use of org.apache.iceberg.expressions.Expression in project presto by prestodb.
the class ExpressionConverter method toIcebergExpression.
private static Expression toIcebergExpression(String columnName, Type type, Domain domain) {
if (domain.isAll()) {
return alwaysTrue();
}
if (domain.getValues().isNone()) {
return domain.isNullAllowed() ? isNull(columnName) : alwaysFalse();
}
if (domain.getValues().isAll()) {
return domain.isNullAllowed() ? alwaysTrue() : not(isNull(columnName));
}
// Skip structural types. TODO: Evaluate Apache Iceberg's support for predicate on structural types
if (type instanceof ArrayType || type instanceof MapType || type instanceof RowType) {
return alwaysTrue();
}
ValueSet domainValues = domain.getValues();
Expression expression = null;
if (domain.isNullAllowed()) {
expression = isNull(columnName);
}
if (domainValues instanceof SortedRangeSet) {
List<Range> orderedRanges = ((SortedRangeSet) domainValues).getOrderedRanges();
expression = firstNonNull(expression, alwaysFalse());
for (Range range : orderedRanges) {
Marker low = range.getLow();
Marker high = range.getHigh();
Marker.Bound lowBound = low.getBound();
Marker.Bound highBound = high.getBound();
// case col <> 'val' is represented as (col < 'val' or col > 'val')
if (lowBound == EXACTLY && highBound == EXACTLY) {
// case ==
if (getIcebergLiteralValue(type, low).equals(getIcebergLiteralValue(type, high))) {
expression = or(expression, equal(columnName, getIcebergLiteralValue(type, low)));
} else {
// case between
Expression between = and(greaterThanOrEqual(columnName, getIcebergLiteralValue(type, low)), lessThanOrEqual(columnName, getIcebergLiteralValue(type, high)));
expression = or(expression, between);
}
} else {
if (lowBound == EXACTLY && low.getValueBlock().isPresent()) {
// case >=
expression = or(expression, greaterThanOrEqual(columnName, getIcebergLiteralValue(type, low)));
} else if (lowBound == ABOVE && low.getValueBlock().isPresent()) {
// case >
expression = or(expression, greaterThan(columnName, getIcebergLiteralValue(type, low)));
}
if (highBound == EXACTLY && high.getValueBlock().isPresent()) {
// case <=
if (low.getValueBlock().isPresent()) {
expression = and(expression, lessThanOrEqual(columnName, getIcebergLiteralValue(type, high)));
} else {
expression = or(expression, lessThanOrEqual(columnName, getIcebergLiteralValue(type, high)));
}
} else if (highBound == BELOW && high.getValueBlock().isPresent()) {
// case <
if (low.getValueBlock().isPresent()) {
expression = and(expression, lessThan(columnName, getIcebergLiteralValue(type, high)));
} else {
expression = or(expression, lessThan(columnName, getIcebergLiteralValue(type, high)));
}
}
}
}
return expression;
}
throw new VerifyException("Did not expect a domain value set other than SortedRangeSet but got " + domainValues.getClass().getSimpleName());
}
Aggregations