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 @@ -396,11 +396,17 @@ public void testDouble()

.execute(getQueryRunner(), clickhouseCreateAndInsert("tpch.test_double"))

.addRoundTrip("double", "nan()", DOUBLE, "CAST(nan() AS DOUBLE)")
.addRoundTrip("double", "-infinity()", DOUBLE, "CAST(-infinity() AS DOUBLE)")
.addRoundTrip("double", "+infinity()", DOUBLE, "CAST(+infinity() AS DOUBLE)")
.addRoundTrip("double", "NULL", DOUBLE, "CAST(NULL AS DOUBLE)")

.execute(getQueryRunner(), trinoCreateAsSelect("trino_test_double"));

SqlDataTypeTest.create()
.addRoundTrip("double", "nan", DOUBLE, "CAST(nan() AS DOUBLE)")
.addRoundTrip("double", "-inf", DOUBLE, "CAST(-infinity() AS DOUBLE)")
.addRoundTrip("double", "+inf", DOUBLE, "CAST(+infinity() AS DOUBLE)")
.addRoundTrip("Nullable(double)", "NULL", DOUBLE, "CAST(NULL AS DOUBLE)")
.execute(getQueryRunner(), clickhouseCreateAndInsert("tpch.trino_test_nullable_double"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,16 @@ protected QueryRunner createQueryRunner()
@Test
public void testSampleBySqlInjection()
{
assertQueryFails("CREATE TABLE test (p1 int NOT NULL, p2 boolean NOT NULL, x VARCHAR) WITH (engine = 'MergeTree', order_by = ARRAY['p1', 'p2'], primary_key = ARRAY['p1', 'p2'], sample_by = 'p2; drop table tpch.nation')", "(?s).*Missing columns: 'p2; drop table tpch.nation.*");
assertUpdate("CREATE TABLE test (p1 int NOT NULL, p2 boolean NOT NULL, x VARCHAR) WITH (engine = 'MergeTree', order_by = ARRAY['p1', 'p2'], primary_key = ARRAY['p1', 'p2'], sample_by = 'p2')");
assertQueryFails("ALTER TABLE test SET PROPERTIES sample_by = 'p2; drop table tpch.nation'", "(?s).*Missing columns: 'p2; drop table tpch.nation.*");
assertUpdate("ALTER TABLE test SET PROPERTIES sample_by = 'p2'");
String tableName = "sql_injection_" + randomNameSuffix();
try {
assertQueryFails("CREATE TABLE " + tableName + " (p1 int NOT NULL, p2 boolean NOT NULL, x VARCHAR) WITH (engine = 'MergeTree', order_by = ARRAY['p1', 'p2'], primary_key = ARRAY['p1', 'p2'], sample_by = 'p2; drop table tpch.nation')", "(?s).*Missing columns: 'p2; drop table tpch.nation.*");
assertUpdate("CREATE TABLE " + tableName + " (p1 int NOT NULL, p2 boolean NOT NULL, x VARCHAR) WITH (engine = 'MergeTree', order_by = ARRAY['p1', 'p2'], primary_key = ARRAY['p1', 'p2'], sample_by = 'p2')");
assertQueryFails("ALTER TABLE " + tableName + " SET PROPERTIES sample_by = 'p2; drop table tpch.nation'", "(?s).*Missing columns: 'p2; drop table tpch.nation.*");
assertUpdate("ALTER TABLE " + tableName + " SET PROPERTIES sample_by = 'p2'");
}
finally {
assertUpdate("DROP TABLE IF EXISTS " + tableName);
}
}

@Test
Expand Down Expand Up @@ -816,6 +822,52 @@ public void testLargeDefaultDomainCompactionThreshold()
"VALUES('" + propertyName + "','1000', '1000', 'integer', 'Maximum ranges to allow in a tuple domain without simplifying it')");
}

@Test
public void testFloatPredicatePushdown()
{
try (TestTable table = new TestTable(
getQueryRunner()::execute,
"test_float_predicate_pushdown",
"""
(
c_real real,
c_real_neg_infinity real,
c_real_pos_infinity real,
c_real_nan real,
c_double double,
c_double_neg_infinity double,
c_double_pos_infinity double,
c_double_nan double)""",
List.of("3.14, -infinity(), +infinity(), nan(), 3.14, -infinity(), +infinity(), nan()"))) {
assertThat(query("SELECT c_real FROM %s WHERE c_real = real '3.14'".formatted(table.getName())))
// because of https://github.com/trinodb/trino/issues/9998
.isNotFullyPushedDown(FilterNode.class);

assertThat(query("SELECT c_real FROM %s WHERE c_real_neg_infinity = -infinity()".formatted(table.getName())))
// because of https://github.com/trinodb/trino/issues/9998
.isNotFullyPushedDown(FilterNode.class);

assertThat(query("SELECT c_real FROM %s WHERE c_real_pos_infinity = +infinity()".formatted(table.getName())))
// because of https://github.com/trinodb/trino/issues/9998
.isNotFullyPushedDown(FilterNode.class);

assertThat(query("SELECT c_real FROM %s WHERE c_real_nan = nan()".formatted(table.getName())))
.isReplacedWithEmptyValues();

assertThat(query("SELECT c_real FROM %s WHERE c_double = double '3.14'".formatted(table.getName())))
.isFullyPushedDown();

assertThat(query("SELECT c_real FROM %s WHERE c_double_neg_infinity = -infinity()".formatted(table.getName())))
.isFullyPushedDown();

assertThat(query("SELECT c_real FROM %s WHERE c_double_pos_infinity = +infinity()".formatted(table.getName())))
.isFullyPushedDown();

assertThat(query("SELECT c_real FROM %s WHERE c_double_nan = nan()".formatted(table.getName())))
.isReplacedWithEmptyValues();
}
}

@Test
public void testTextualPredicatePushdown()
{
Expand Down