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 @@ -29,6 +29,10 @@ public void decode(Supplier<Object> getter, BlockBuilder output)
if (value == null) {
output.appendNull();
}
else if (value instanceof String) {
// Pinot returns NEGATIVE_INFINITY, POSITIVE_INFINITY as a String
DOUBLE.writeDouble(output, Double.valueOf((String) value));
}
else {
DOUBLE.writeDouble(output, ((Number) value).doubleValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public void decode(Supplier<Object> getter, BlockBuilder output)
if (value == null) {
output.appendNull();
}
else if (value instanceof String) {
// Pinot returns NEGATIVE_INFINITY, POSITIVE_INFINITY as a String
output.writeInt(floatToIntBits(Float.valueOf((String) value)));
}
else {
output.writeInt((floatToIntBits(((Number) value).floatValue())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import io.trino.spi.predicate.TupleDomain;
import io.trino.spi.type.RealType;
Comment thread
elonazoulay marked this conversation as resolved.
Outdated
import io.trino.spi.type.Type;
import io.trino.spi.type.VarbinaryType;
import io.trino.spi.type.VarcharType;
import org.apache.commons.codec.binary.Hex;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -156,6 +158,9 @@ private static Object convertValue(Type type, Object value)
else if (type instanceof VarcharType) {
return ((Slice) value).toStringUtf8();
}
else if (type instanceof VarbinaryType) {
return Hex.encodeHexString(((Slice) value).getBytes());
}
return value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ protected QueryRunner createQueryRunner()
Arrays.asList("string_" + (offset), "string1_" + (offset + 1), "string2_" + (offset + 2)),
Arrays.asList(false, true, true),
Arrays.asList(54, -10001, 1000),
Arrays.asList(-7.33F + i, .004F - i, 17.034F + i),
Arrays.asList(-17.33D + i, .00014D - i, 10596.034D + i),
Arrays.asList(-7.33F + i, Float.POSITIVE_INFINITY, 17.034F + i),
Arrays.asList(-17.33D + i, Double.POSITIVE_INFINITY, 10596.034D + i),
Arrays.asList(-3147483647L + i, 12L - i, 4147483647L + i),
Instant.parse("2021-05-10T00:00:00.00Z").plusMillis(offset).toEpochMilli())));
}
Expand Down Expand Up @@ -750,7 +750,7 @@ public void testNullBehavior()
" FROM " + ALL_TYPES_TABLE +
" WHERE bytes_col = X'' AND element_at(bool_array_col, 1) = 'null'"))
.matches("VALUES (VARCHAR 'null')")
.isNotFullyPushedDown(FilterNode.class);
.isNotFullyPushedDown(ExchangeNode.class, ProjectNode.class, FilterNode.class);

// Default null value for booleans is the string 'null'
// Booleans are treated as a string
Expand Down Expand Up @@ -1231,4 +1231,101 @@ public void testInClause()
" GROUP BY int_col"))
.isFullyPushedDown();
}

@Test
public void testVarbinaryFilters()
{
assertThat(query("SELECT string_col" +
" FROM " + ALL_TYPES_TABLE +
" WHERE bytes_col = X''"))
.matches("VALUES (VARCHAR 'null'), (VARCHAR 'array_null')")
.isFullyPushedDown();

assertThat(query("SELECT string_col" +
" FROM " + ALL_TYPES_TABLE +
" WHERE bytes_col != X''"))
.matches("VALUES (VARCHAR 'string_0')," +
" (VARCHAR 'string_1200')," +
" (VARCHAR 'string_2400')," +
" (VARCHAR 'string_3600')," +
" (VARCHAR 'string_4800')," +
" (VARCHAR 'string_6000')," +
" (VARCHAR 'string_7200')," +
" (VARCHAR 'string_8400')," +
" (VARCHAR 'string_9600')")
.isFullyPushedDown();

assertThat(query("SELECT string_col" +
" FROM " + ALL_TYPES_TABLE +
" WHERE bytes_col = X'73 74 72 69 6e 67 5f 30'"))
.matches("VALUES (VARCHAR 'string_0')")
.isFullyPushedDown();

assertThat(query("SELECT string_col" +
" FROM " + ALL_TYPES_TABLE +
" WHERE bytes_col != X'73 74 72 69 6e 67 5f 30'"))
.matches("VALUES (VARCHAR 'null')," +
" (VARCHAR 'array_null')," +
" (VARCHAR 'string_1200')," +
" (VARCHAR 'string_2400')," +
" (VARCHAR 'string_3600')," +
" (VARCHAR 'string_4800')," +
" (VARCHAR 'string_6000')," +
" (VARCHAR 'string_7200')," +
" (VARCHAR 'string_8400')," +
" (VARCHAR 'string_9600')")
.isFullyPushedDown();
}

@Test
public void testRealWithInfinity()
{
assertThat(query("SELECT element_at(float_array_col, 1)" +
" FROM " + ALL_TYPES_TABLE +
" WHERE bytes_col = X''"))
.matches("VALUES (CAST(-POWER(0, -1) AS REAL))," +
" (CAST(-POWER(0, -1) AS REAL))");

assertThat(query("SELECT element_at(float_array_col, 1) FROM \"SELECT float_array_col" +
" FROM " + ALL_TYPES_TABLE +
" WHERE bytes_col = '' \""))
.matches("VALUES (CAST(-POWER(0, -1) AS REAL))," +
" (CAST(-POWER(0, -1) AS REAL))");

assertThat(query("SELECT element_at(float_array_col, 2)" +
" FROM " + ALL_TYPES_TABLE +
" WHERE string_col = 'string_0'"))
.matches("VALUES (CAST(POWER(0, -1) AS REAL))");

assertThat(query("SELECT element_at(float_array_col, 2) FROM \"SELECT float_array_col" +
" FROM " + ALL_TYPES_TABLE +
" WHERE string_col = 'string_0'\""))
.matches("VALUES (CAST(POWER(0, -1) AS REAL))");
}

@Test
public void testDoubleWithInfinity()
{
assertThat(query("SELECT element_at(double_array_col, 1)" +
" FROM " + ALL_TYPES_TABLE +
" WHERE bytes_col = X''"))
.matches("VALUES (-POWER(0, -1))," +
" (-POWER(0, -1))");

assertThat(query("SELECT element_at(double_array_col, 1) FROM \"SELECT double_array_col" +
" FROM " + ALL_TYPES_TABLE +
" WHERE bytes_col = '' \""))
.matches("VALUES (-POWER(0, -1))," +
" (-POWER(0, -1))");

assertThat(query("SELECT element_at(double_array_col, 2)" +
" FROM " + ALL_TYPES_TABLE +
" WHERE string_col = 'string_0'"))
.matches("VALUES (POWER(0, -1))");

assertThat(query("SELECT element_at(double_array_col, 2) FROM \"SELECT double_array_col" +
" FROM " + ALL_TYPES_TABLE +
" WHERE string_col = 'string_0'\""))
.matches("VALUES (POWER(0, -1))");
}
}