From a5ce83d9fc5e780b8dec6f7666c6b80b78bb6ca1 Mon Sep 17 00:00:00 2001 From: chenjian2664 Date: Thu, 19 Oct 2023 22:04:28 +0800 Subject: [PATCH] Don't pushdown like expression with escape in Ignite connector --- .../io/trino/plugin/ignite/IgniteClient.java | 1 - .../ignite/TestIgniteConnectorTest.java | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/plugin/trino-ignite/src/main/java/io/trino/plugin/ignite/IgniteClient.java b/plugin/trino-ignite/src/main/java/io/trino/plugin/ignite/IgniteClient.java index d385d4e8174a..ea579992270b 100644 --- a/plugin/trino-ignite/src/main/java/io/trino/plugin/ignite/IgniteClient.java +++ b/plugin/trino-ignite/src/main/java/io/trino/plugin/ignite/IgniteClient.java @@ -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, diff --git a/plugin/trino-ignite/src/test/java/io/trino/plugin/ignite/TestIgniteConnectorTest.java b/plugin/trino-ignite/src/test/java/io/trino/plugin/ignite/TestIgniteConnectorTest.java index aaddab434b2b..94ef4dd034b0 100644 --- a/plugin/trino-ignite/src/test/java/io/trino/plugin/ignite/TestIgniteConnectorTest.java +++ b/plugin/trino-ignite/src/test/java/io/trino/plugin/ignite/TestIgniteConnectorTest.java @@ -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; @@ -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; @@ -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() {