Skip to content

Commit baeb788

Browse files
it-is-a-robotgitee-org
authored andcommitted
!1088 Memory Connector: fix column is null predicate query
Merge pull request !1088 from farhan3/mem-con-fix-null-val
2 parents 38a272c + 095a63e commit baeb788

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

presto-memory/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@
137137
<scope>test</scope>
138138
</dependency>
139139

140+
<dependency>
141+
<groupId>io.hetu.core</groupId>
142+
<artifactId>presto-tpcds</artifactId>
143+
<scope>test</scope>
144+
</dependency>
145+
140146
<dependency>
141147
<groupId>io.airlift.tpch</groupId>
142148
<artifactId>tpch</artifactId>

presto-memory/src/main/java/io/prestosql/plugin/memory/data/LogicalPart.java

+25
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ List<Page> getPages(TupleDomain<ColumnHandle> predicate)
283283
int expressionColumnIndex = ((MemoryColumnHandle) e.getKey()).getColumnIndex();
284284
List<Range> ranges = ((SortedRangeSet) e.getValue().getValues()).getOrderedRanges();
285285

286+
// e.g. column=null
287+
if (ranges.isEmpty()) {
288+
continue;
289+
}
290+
286291
if (minMaxIdx.containsKey(expressionColumnIndex)) {
287292
minmaxChannelsToRangesMap.put(expressionColumnIndex, ranges);
288293
}
@@ -341,6 +346,11 @@ List<Page> getPages(
341346
noMatches++;
342347
}
343348
}
349+
else {
350+
// the lookup value isn't comparable, we can't do filtering, e.g. if it's null
351+
LOG.warn("Lookup value is not Comparable. MinMax index could not be used.");
352+
return getPages();
353+
}
344354
}
345355
else {
346356
// <, <=, >=, >, BETWEEN
@@ -368,6 +378,11 @@ List<Page> getPages(
368378
}
369379
}
370380
}
381+
else {
382+
// the lookup value isn't comparable, we can't do filtering, e.g. if it's null
383+
LOG.warn("Lookup value is not Comparable. MinMax index could not be used.");
384+
return getPages();
385+
}
371386
}
372387
else if (!highBoundless && lowBoundless) {
373388
// <= or <
@@ -388,6 +403,11 @@ else if (!highBoundless && lowBoundless) {
388403
}
389404
}
390405
}
406+
else {
407+
// the lookup value isn't comparable, we can't do filtering, e.g. if it's null
408+
LOG.warn("Lookup value is not Comparable. MinMax index could not be used.");
409+
return getPages();
410+
}
391411
}
392412
else if (!highBoundless && !lowBoundless) {
393413
// BETWEEN
@@ -401,6 +421,11 @@ else if (!highBoundless && !lowBoundless) {
401421
noMatches++;
402422
}
403423
}
424+
else {
425+
// the lookup value isn't comparable, we can't do filtering, e.g. if it's null
426+
LOG.warn("Lookup value is not Comparable. MinMax index could not be used.");
427+
return getPages();
428+
}
404429
}
405430
}
406431
}

presto-memory/src/test/java/io/prestosql/plugin/memory/MemoryQueryRunner.java

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.hetu.core.filesystem.HetuFileSystemClientPlugin;
2222
import io.hetu.core.metastore.HetuMetastorePlugin;
2323
import io.prestosql.Session;
24+
import io.prestosql.plugin.tpcds.TpcdsPlugin;
2425
import io.prestosql.plugin.tpch.TpchPlugin;
2526
import io.prestosql.tests.DistributedQueryRunner;
2627

@@ -122,6 +123,8 @@ public static DistributedQueryRunner createQueryRunner(int nodes, Map<String, St
122123

123124
queryRunner.installPlugin(new TpchPlugin());
124125
queryRunner.createCatalog("tpch", "tpch", ImmutableMap.of());
126+
queryRunner.installPlugin(new TpcdsPlugin());
127+
queryRunner.createCatalog("tpcds", "tpcds", ImmutableMap.of());
125128

126129
if (createTpchTables) {
127130
copyTpchTables(queryRunner, "tpch", TINY_SCHEMA_NAME, session, TpchTable.getTables());

presto-memory/src/test/java/io/prestosql/plugin/memory/TestMemorySelection.java

+18
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ public void dropAllTables()
5353
}
5454
}
5555

56+
@Test
57+
public void testNullSelect()
58+
{
59+
getQueryRunner().execute("CREATE TABLE test_null_noidx AS SELECT * FROM tpcds.tiny.customer");
60+
getQueryRunner().execute("CREATE TABLE test_null_sort WITH (sorted_by=ARRAY['c_birth_year']) AS SELECT * FROM tpcds.tiny.customer");
61+
getQueryRunner().execute("CREATE TABLE test_null_idx WITH (index_columns=ARRAY['c_birth_year']) AS SELECT * FROM tpcds.tiny.customer");
62+
63+
Object expectedCount = getSingleResult("SELECT count(*) FROM tpcds.tiny.customer where c_birth_year is null");
64+
Object noidxCount = getSingleResult("SELECT count(*) FROM test_null_noidx where c_birth_year is null");
65+
Object sortCount = getSingleResult("SELECT count(*) FROM test_null_sort where c_birth_year is null");
66+
Object idxCount = getSingleResult("SELECT count(*) FROM test_null_idx where c_birth_year is null");
67+
68+
assertTrue((long) expectedCount > 0, "expected null count is 0, testcase should be updated");
69+
assertEquals(noidxCount, expectedCount);
70+
assertEquals(sortCount, expectedCount);
71+
assertEquals(idxCount, expectedCount);
72+
}
73+
5674
@Test
5775
public void testSortedBySelect()
5876
{

0 commit comments

Comments
 (0)