Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support predicate pushdown on floating point types in mongodb #19575

Merged
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 @@ -102,6 +102,7 @@
import static io.trino.spi.type.DateType.DATE;
import static io.trino.spi.type.DecimalType.createDecimalType;
import static io.trino.spi.type.DoubleType.DOUBLE;
import static io.trino.spi.type.RealType.REAL;
import static io.trino.spi.type.SmallintType.SMALLINT;
import static io.trino.spi.type.TimeType.TIME_MILLIS;
import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS;
Expand All @@ -114,6 +115,7 @@
import static io.trino.spi.type.VarbinaryType.VARBINARY;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static io.trino.spi.type.VarcharType.createUnboundedVarcharType;
import static java.lang.Float.intBitsToFloat;
import static java.lang.Math.floorDiv;
import static java.lang.Math.floorMod;
import static java.lang.Math.toIntExact;
Expand Down Expand Up @@ -688,6 +690,14 @@ private static Optional<Object> translateValue(Object trinoNativeValue, Type typ
return Optional.of(trinoNativeValue);
}

if (type == REAL) {
return Optional.of(intBitsToFloat(toIntExact((long) trinoNativeValue)));
}

if (type == DOUBLE) {
return Optional.of(trinoNativeValue);
}

if (type instanceof DecimalType decimalType) {
if (decimalType.isShort()) {
return Optional.of(Decimal128.parse(Decimals.toString((long) trinoNativeValue, decimalType.getScale())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import static io.trino.spi.type.BigintType.BIGINT;
import static io.trino.spi.type.BooleanType.BOOLEAN;
import static io.trino.spi.type.DateType.DATE;
import static io.trino.spi.type.DoubleType.DOUBLE;
import static io.trino.spi.type.IntegerType.INTEGER;
import static io.trino.spi.type.RealType.REAL;
import static io.trino.spi.type.SmallintType.SMALLINT;
import static io.trino.spi.type.StandardTypes.JSON;
import static io.trino.spi.type.TimeType.TIME_MILLIS;
Expand All @@ -40,6 +42,8 @@ public final class TypeUtils
SMALLINT,
INTEGER,
BIGINT,
REAL,
DOUBLE,
DATE,
TIME_MILLIS,
TIMESTAMP_MILLIS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,39 @@ public Object[][] predicatePushdownProvider()
};
}

@Test
public void testPredicatePushdownRealType()
{
testPredicatePushdownFloatingPoint("real '1.234'");
}

@Test
public void testPredicatePushdownDoubleType()
{
testPredicatePushdownFloatingPoint("double '5.678'");
}

private void testPredicatePushdownFloatingPoint(String value)
{
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_floating_point_pushdown", "AS SELECT %s col".formatted(value))) {
assertThat(query("SELECT * FROM " + table.getName() + " WHERE col = " + value))
.isFullyPushedDown();
assertThat(query("SELECT * FROM " + table.getName() + " WHERE col <= " + value))
.isFullyPushedDown();
assertThat(query("SELECT * FROM " + table.getName() + " WHERE col >= " + value))
.isFullyPushedDown();
assertThat(query("SELECT * FROM " + table.getName() + " WHERE col > " + value))
.returnsEmptyResult()
.isFullyPushedDown();
assertThat(query("SELECT * FROM " + table.getName() + " WHERE col < " + value))
.returnsEmptyResult()
.isFullyPushedDown();
assertThat(query("SELECT * FROM " + table.getName() + " WHERE col != " + value))
.returnsEmptyResult()
.isNotFullyPushedDown(FilterNode.class);
}
}

@Test
public void testPredicatePushdownCharWithPaddedSpace()
{
Expand Down
Loading