Skip to content
Open
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 @@ -196,7 +196,10 @@ public Boolean visitIsNotNullPredicate(final IsNotNullPredicate node, final Void

@Override
public Boolean visitLikePredicate(final LikePredicate node, final Void context) {
return node.getValue().accept(this, context);
return node.getValue() instanceof SymbolReference
&& node.getValue().accept(this, context)
&& node.getPattern() instanceof StringLiteral
&& (!node.getEscape().isPresent() || node.getEscape().get() instanceof StringLiteral);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public SchemaFilter visitIsNotNullPredicate(
final LikePredicate node, final Context context) {
// TODO: Support stringLiteral like tag/attr?
if (!(node.getValue() instanceof SymbolReference)
|| !(node.getPattern() instanceof StringLiteral)) {
|| !(node.getPattern() instanceof StringLiteral)
|| (node.getEscape().isPresent() && !(node.getEscape().get() instanceof StringLiteral))) {
return null;
}
return wrapTagOrAttributeFilter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,43 @@ public void expressionTest() {
assertNull(deviceTableScanNode.getPushDownPredicate());
assertFalse(deviceTableScanNode.getTimePredicate().isPresent());

sql = "SELECT * FROM table1 WHERE tag1 like 'A' || '%'";
context = new MPPQueryContext(sql, queryId, sessionInfo, null, null);
analysis = analyzeSQL(sql, metadata, context);
symbolAllocator = new SymbolAllocator();
logicalQueryPlan =
new TableLogicalPlanner(
context, metadata, sessionInfo, symbolAllocator, WarningCollector.NOOP)
.plan(analysis);
rootNode = logicalQueryPlan.getRootNode();

// Like with a non-literal pattern is evaluated by the filter operator.
assertTrue(rootNode.getChildren().get(0) instanceof FilterNode);
filterNode = (FilterNode) rootNode.getChildren().get(0);
assertTrue(filterNode.getPredicate().toString().contains("LIKE"));
assertTrue(rootNode.getChildren().get(0).getChildren().get(0) instanceof DeviceTableScanNode);
deviceTableScanNode = (DeviceTableScanNode) rootNode.getChildren().get(0).getChildren().get(0);
assertNull(deviceTableScanNode.getPushDownPredicate());
assertFalse(deviceTableScanNode.getTimePredicate().isPresent());

sql = "SELECT * FROM table1 WHERE tag1 like concat('A', '%')";
context = new MPPQueryContext(sql, queryId, sessionInfo, null, null);
analysis = analyzeSQL(sql, metadata, context);
symbolAllocator = new SymbolAllocator();
logicalQueryPlan =
new TableLogicalPlanner(
context, metadata, sessionInfo, symbolAllocator, WarningCollector.NOOP)
.plan(analysis);
rootNode = logicalQueryPlan.getRootNode();

assertTrue(rootNode.getChildren().get(0) instanceof FilterNode);
filterNode = (FilterNode) rootNode.getChildren().get(0);
assertTrue(filterNode.getPredicate().toString().contains("LIKE"));
assertTrue(rootNode.getChildren().get(0).getChildren().get(0) instanceof DeviceTableScanNode);
deviceTableScanNode = (DeviceTableScanNode) rootNode.getChildren().get(0).getChildren().get(0);
assertNull(deviceTableScanNode.getPushDownPredicate());
assertFalse(deviceTableScanNode.getTimePredicate().isPresent());

// 3. in / not in
sql =
"SELECT *, s1/2, s2+1, s2*3, s1+s2, s2%1 FROM table1 WHERE tag1 in ('A', 'B') and tag2 not in ('A', 'C')";
Expand Down