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 @@ -130,6 +130,9 @@ private static QueryBuilder buildTermQuery(BoolQueryBuilder queryBuilder, Connec
}
queryBuilder.should(rangeQueryBuilder);
}
if (domain.isNullAllowed()) {
queryBuilder.should(new BoolQueryBuilder().mustNot(new ExistsQueryBuilder(columnName)));
}
return queryBuilder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,87 @@ public void testEmptyObjectFields()
"VALUES ('stringfield', 32)");
}

@Test
public void testNullPredicate()
{
String indexName = "null_predicate1";

embeddedElasticsearchNode.getClient()
.admin()
.indices()
.prepareCreate(indexName)
.addMapping("doc",
"null_keyword", "type=keyword",
"custkey", "type=keyword")
.get();
index(indexName, ImmutableMap.<String, Object>builder()
.put("null_keyword", 32)
.put("custkey", 1301)
.build());
embeddedElasticsearchNode.getClient()
.admin()
.indices()
.refresh(refreshRequest(indexName))
.actionGet();

assertQueryReturnsEmptyResult("SELECT * FROM null_predicate1 WHERE null_keyword IS NULL");
assertQueryReturnsEmptyResult("SELECT * FROM null_predicate1 WHERE null_keyword = '10' OR null_keyword IS NULL");

assertQuery("SELECT custkey, null_keyword FROM null_predicate1 WHERE null_keyword = '32' OR null_keyword IS NULL", "VALUES (1301, 32)");
assertQuery("SELECT custkey FROM null_predicate1 WHERE null_keyword = '32' OR null_keyword IS NULL", "VALUES (1301)");

// not null filter
// filtered column is selected
assertQuery("SELECT custkey, null_keyword FROM null_predicate1 WHERE null_keyword IS NOT NULL", "VALUES (1301, 32)");
assertQuery("SELECT custkey, null_keyword FROM null_predicate1 WHERE null_keyword = '32' OR null_keyword IS NOT NULL", "VALUES (1301, 32)");

// filtered column is not selected
assertQuery("SELECT custkey FROM null_predicate1 WHERE null_keyword = '32' OR null_keyword IS NOT NULL", "VALUES (1301)");

indexName = "null_predicate2";

embeddedElasticsearchNode.getClient()
.admin()
.indices()
.prepareCreate(indexName)
.addMapping("doc",
"null_keyword", "type=keyword",
"custkey", "type=keyword")
.get();
index(indexName, ImmutableMap.<String, Object>builder()
.put("custkey", 1301)
.build());
embeddedElasticsearchNode.getClient()
.admin()
.indices()
.refresh(refreshRequest(indexName))
.actionGet();

// not null filter
assertQueryReturnsEmptyResult("SELECT * FROM null_predicate2 WHERE null_keyword IS NOT NULL");
assertQueryReturnsEmptyResult("SELECT * FROM null_predicate2 WHERE null_keyword = '10' OR null_keyword IS NOT NULL");

// filtered column is selected
assertQuery("SELECT custkey, null_keyword FROM null_predicate2 WHERE null_keyword IS NULL", "VALUES (1301, NULL)");
assertQuery("SELECT custkey, null_keyword FROM null_predicate2 WHERE null_keyword = '32' OR null_keyword IS NULL", "VALUES (1301, NULL)");

// filtered column is not selected
assertQuery("SELECT custkey FROM null_predicate2 WHERE null_keyword = '32' OR null_keyword IS NULL", "VALUES (1301)");

index(indexName, ImmutableMap.<String, Object>builder()
.put("null_keyword", 32)
.put("custkey", 1302)
.build());
embeddedElasticsearchNode.getClient()
.admin()
.indices()
.refresh(refreshRequest(indexName))
.actionGet();

assertQuery("SELECT custkey, null_keyword FROM null_predicate2 WHERE null_keyword = '32' OR null_keyword IS NULL", "VALUES (1301, NULL), (1302, 32)");
assertQuery("SELECT custkey FROM null_predicate2 WHERE null_keyword = '32' OR null_keyword IS NULL", "VALUES (1301), (1302)");
}

@Test
public void testNestedFields()
{
Expand Down