Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.trino.spi.predicate.TupleDomain;
import io.trino.spi.type.RealType;
import io.trino.spi.type.Type;
import io.trino.spi.type.VarcharType;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -136,13 +137,13 @@ private static String toPredicate(String columnName, Domain domain)
checkState(!rangeConjuncts.isEmpty());
disjuncts.add("(" + Joiner.on(" AND ").join(rangeConjuncts) + ")");
}
// Add back all of the possible single values either as an equality or an IN predicate
if (singleValues.size() == 1) {
disjuncts.add(toConjunct(columnName, "=", getOnlyElement(singleValues)));
}
else if (singleValues.size() > 1) {
disjuncts.add(inClauseValues(columnName, singleValues));
}
}
// Add back all of the possible single values either as an equality or an IN predicate
if (singleValues.size() == 1) {
disjuncts.add(toConjunct(columnName, "=", getOnlyElement(singleValues)));
}
else if (singleValues.size() > 1) {
disjuncts.add(inClauseValues(columnName, singleValues));
}
return "(" + Joiner.on(" OR ").join(disjuncts) + ")";
}
Expand All @@ -152,6 +153,9 @@ private static Object convertValue(Type type, Object value)
if (type instanceof RealType) {
return intBitsToFloat(toIntExact((Long) value));
}
else if (type instanceof VarcharType) {
return ((Slice) value).toStringUtf8();
}
return value;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In future we should handle all types explicitly here to avoid surprises.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, will do!

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1203,4 +1203,32 @@ public void testAggregationPushdown()
.withRootCauseInstanceOf(RuntimeException.class)
.withMessage("Operation not supported for DISTINCT aggregation function");
}

@Test
public void testInClause()
{
assertThat(query("SELECT string_col, sum(long_col)" +
" FROM " + ALL_TYPES_TABLE +
" WHERE string_col IN ('string_1200','string_2400','string_3600')" +
" GROUP BY string_col"))
.isFullyPushedDown();

assertThat(query("SELECT string_col, sum(long_col)" +
" FROM " + ALL_TYPES_TABLE +
" WHERE string_col NOT IN ('string_1200','string_2400','string_3600')" +
" GROUP BY string_col"))
.isFullyPushedDown();

assertThat(query("SELECT int_col, sum(long_col)" +
" FROM " + ALL_TYPES_TABLE +
" WHERE int_col IN (54, 56)" +
" GROUP BY int_col"))
.isFullyPushedDown();

assertThat(query("SELECT int_col, sum(long_col)" +
" FROM " + ALL_TYPES_TABLE +
" WHERE int_col NOT IN (54, 56)" +
" GROUP BY int_col"))
.isFullyPushedDown();
}
}