diff --git a/plugin/trino-pinot/src/main/java/io/trino/plugin/pinot/decoders/DoubleDecoder.java b/plugin/trino-pinot/src/main/java/io/trino/plugin/pinot/decoders/DoubleDecoder.java index 53dd1b03e75f..7e4d76b1c99e 100644 --- a/plugin/trino-pinot/src/main/java/io/trino/plugin/pinot/decoders/DoubleDecoder.java +++ b/plugin/trino-pinot/src/main/java/io/trino/plugin/pinot/decoders/DoubleDecoder.java @@ -29,6 +29,10 @@ public void decode(Supplier 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()); } diff --git a/plugin/trino-pinot/src/main/java/io/trino/plugin/pinot/decoders/RealDecoder.java b/plugin/trino-pinot/src/main/java/io/trino/plugin/pinot/decoders/RealDecoder.java index 0ec1878736bd..ea6dd1a09cd2 100644 --- a/plugin/trino-pinot/src/main/java/io/trino/plugin/pinot/decoders/RealDecoder.java +++ b/plugin/trino-pinot/src/main/java/io/trino/plugin/pinot/decoders/RealDecoder.java @@ -29,6 +29,10 @@ public void decode(Supplier 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()))); } diff --git a/plugin/trino-pinot/src/main/java/io/trino/plugin/pinot/query/PinotQueryBuilder.java b/plugin/trino-pinot/src/main/java/io/trino/plugin/pinot/query/PinotQueryBuilder.java index b7e44650abdb..83b91407348d 100755 --- a/plugin/trino-pinot/src/main/java/io/trino/plugin/pinot/query/PinotQueryBuilder.java +++ b/plugin/trino-pinot/src/main/java/io/trino/plugin/pinot/query/PinotQueryBuilder.java @@ -24,7 +24,9 @@ import io.trino.spi.predicate.TupleDomain; import io.trino.spi.type.RealType; 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; @@ -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; } diff --git a/plugin/trino-pinot/src/test/java/io/trino/plugin/pinot/TestPinotIntegrationSmokeTest.java b/plugin/trino-pinot/src/test/java/io/trino/plugin/pinot/TestPinotIntegrationSmokeTest.java index 18e5da8d24d8..0b8d66d3c0dd 100644 --- a/plugin/trino-pinot/src/test/java/io/trino/plugin/pinot/TestPinotIntegrationSmokeTest.java +++ b/plugin/trino-pinot/src/test/java/io/trino/plugin/pinot/TestPinotIntegrationSmokeTest.java @@ -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()))); } @@ -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 @@ -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))"); + } }