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 @@ -461,6 +461,10 @@ private static Optional<Object> translateValue(Object trinoNativeValue, Type typ
requireNonNull(type, "type is null");
checkArgument(Primitives.wrap(type.getJavaType()).isInstance(trinoNativeValue), "%s (%s) is not a valid representation for %s", trinoNativeValue, trinoNativeValue.getClass(), type);

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

if (type == TINYINT) {
return Optional.of((long) SignedBytes.checkedCast(((Long) trinoNativeValue)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,19 @@ public void testDropTable()
assertQueryFails("SELECT * FROM test.drop_table", ".*Table 'mongodb.test.drop_table' does not exist");
}

@Test
public void testBooleanPredicates()
{
assertUpdate("CREATE TABLE boolean_predicates(id integer, value boolean)");
assertUpdate("INSERT INTO boolean_predicates VALUES(1, true)", 1);
assertUpdate("INSERT INTO boolean_predicates VALUES(2, false)", 1);

assertQuery("SELECT id FROM boolean_predicates WHERE value = true", "VALUES 1");
assertQuery("SELECT id FROM boolean_predicates WHERE value = false", "VALUES 2");

assertUpdate("DROP TABLE boolean_predicates");
}

@Test
public void testNullPredicates()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static io.trino.spi.predicate.Range.lessThan;
import static io.trino.spi.predicate.Range.range;
import static io.trino.spi.type.BigintType.BIGINT;
import static io.trino.spi.type.BooleanType.BOOLEAN;
import static io.trino.spi.type.VarcharType.createUnboundedVarcharType;
import static java.util.Arrays.asList;
import static org.testng.Assert.assertEquals;
Expand All @@ -40,6 +41,7 @@ public class TestMongoSession
private static final MongoColumnHandle COL1 = new MongoColumnHandle("col1", BIGINT, false, Optional.empty());
private static final MongoColumnHandle COL2 = new MongoColumnHandle("col2", createUnboundedVarcharType(), false, Optional.empty());
private static final MongoColumnHandle COL3 = new MongoColumnHandle("col3", createUnboundedVarcharType(), false, Optional.empty());
private static final MongoColumnHandle COL4 = new MongoColumnHandle("col4", BOOLEAN, false, Optional.empty());

@Test
public void testBuildQuery()
Expand Down Expand Up @@ -105,4 +107,14 @@ public void testBuildQueryNull()
new Document(COL1.getName(), new Document("$eq", null))));
assertEquals(query, expected);
}

@Test
public void testBooleanPredicatePushdown()
{
TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(COL4, Domain.singleValue(BOOLEAN, true)));

Document query = MongoSession.buildQuery(tupleDomain);
Document expected = new Document().append(COL4.getName(), new Document("$eq", true));
assertEquals(query, expected);
}
}