Skip to content

Commit

Permalink
Don't pushdown like expression with escape in Ignite connector
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjian2664 authored and ebyhr committed Oct 20, 2023
1 parent b1c629a commit a5ce83d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ public IgniteClient(
this.connectorExpressionRewriter = JdbcConnectorExpressionRewriterBuilder.newBuilder()
.addStandardRules(this::quoted)
.map("$like(value: varchar, pattern: varchar): boolean").to("value LIKE pattern")
.map("$like(value: varchar, pattern: varchar, escape: varchar(1)): boolean").to("value LIKE pattern ESCAPE escape")
.build();
this.aggregateFunctionRewriter = new AggregateFunctionRewriter<>(
connectorExpressionRewriter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.trino.plugin.jdbc.BaseJdbcConnectorTest;
import io.trino.sql.planner.plan.FilterNode;
import io.trino.sql.planner.plan.TableScanNode;
import io.trino.testing.QueryRunner;
import io.trino.testing.TestingConnectorBehavior;
import io.trino.testing.sql.SqlExecutor;
Expand All @@ -31,6 +33,7 @@

import static com.google.common.base.Strings.nullToEmpty;
import static io.trino.plugin.ignite.IgniteQueryRunner.createIgniteQueryRunner;
import static io.trino.sql.planner.assertions.PlanMatchPattern.node;
import static io.trino.testing.TestingNames.randomNameSuffix;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -96,6 +99,34 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
};
}

@Test
public void testLikeWithEscape()
{
try (TestTable testTable = new TestTable(
getQueryRunner()::execute,
"test_like_with_escape",
"(id int, a varchar(4))",
List.of(
"1, 'abce'",
"2, 'abcd'",
"3, 'a%de'"))) {
String tableName = testTable.getName();

assertThat(query("SELECT * FROM " + tableName + " WHERE a LIKE 'a%'"))
.isFullyPushedDown();
assertThat(query("SELECT * FROM " + tableName + " WHERE a LIKE '%c%' ESCAPE '\\'"))
.matches("VALUES (1, 'abce'), (2, 'abcd')")
.isNotFullyPushedDown(node(FilterNode.class, node(TableScanNode.class)));

assertThat(query("SELECT * FROM " + tableName + " WHERE a LIKE 'a\\%d%' ESCAPE '\\'"))
.matches("VALUES (3, 'a%de')")
.isNotFullyPushedDown(node(FilterNode.class, node(TableScanNode.class)));

assertThatThrownBy(() -> onRemoteDatabase().execute("SELECT * FROM " + tableName + " WHERE a LIKE 'a%' ESCAPE '\\'"))
.hasMessageContaining("Failed to execute statement");
}
}

@Test
public void testDatabaseMetadataSearchEscapedWildCardCharacters()
{
Expand Down

0 comments on commit a5ce83d

Please sign in to comment.