This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-13756
in repository https://gitbox.apache.org/repos/asf/ignite.git

commit f987f1b12c7fe0afb557afe6eb0245e3b0ae66f7
Author: Andrew Mashenkov <[email protected]>
AuthorDate: Wed Nov 25 12:10:39 2020 +0300

    IGNITE-13756: Fix node crash if incorrect SQL query fails.
---
 .../jdbc/thin/JdbcThinComplexQuerySelfTest.java    | 36 +++++++++++++++++++++-
 .../cache/persistence/tree/BPlusTree.java          |  4 +++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git 
a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinComplexQuerySelfTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinComplexQuerySelfTest.java
index 610d900..4b2242e 100644
--- 
a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinComplexQuerySelfTest.java
+++ 
b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinComplexQuerySelfTest.java
@@ -21,6 +21,7 @@ import java.io.Serializable;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.sql.Statement;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.cache.affinity.AffinityKey;
@@ -28,6 +29,7 @@ import 
org.apache.ignite.cache.query.annotations.QuerySqlField;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.testframework.GridTestUtils;
 import org.junit.Test;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
@@ -256,6 +258,38 @@ public class JdbcThinComplexQuerySelfTest extends 
JdbcThinAbstractSelfTest {
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testWrongArgumentType() throws Exception {
+        try (ResultSet rs = stmt.executeQuery("select * from 
\"org\".Organization where name = '2'")) {
+            assertFalse(rs.next());
+        }
+
+        // Check non-indexed field.
+        GridTestUtils.assertThrowsWithCause(() -> {
+            try (ResultSet rs = stmt.executeQuery("select * from 
\"org\".Organization where name = 2")) {
+                assertFalse(rs.next());
+            }
+
+            return null;
+        }, SQLException.class);
+
+        // Check indexed field.
+        try (ResultSet rs = stmt.executeQuery("select * from \"pers\".Person 
where name = '2'")) {
+            assertFalse(rs.next());
+        }
+
+        GridTestUtils.assertThrowsWithCause(() -> {
+            try (ResultSet rs = stmt.executeQuery("select * from 
\"pers\".Person where name = 2")) {
+                assertFalse(rs.next());
+            }
+
+            return null;
+        }, SQLException.class);
+    }
+
+    /**
      * Person.
      */
     private static class Person implements Serializable {
@@ -264,7 +298,7 @@ public class JdbcThinComplexQuerySelfTest extends 
JdbcThinAbstractSelfTest {
         private final int id;
 
         /** Name. */
-        @QuerySqlField(index = false)
+        @QuerySqlField(index = true)
         private final String name;
 
         /** Age. */
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java
index ca92a71..42af026 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.internal.processors.cache.persistence.tree;
 
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -1115,6 +1116,9 @@ public abstract class BPlusTree<L, T extends L> extends 
DataStructure implements
             throw new IgniteCheckedException("Runtime failure on bounds: 
[lower=" + lower + ", upper=" + upper + "]", e);
         }
         catch (RuntimeException | AssertionError e) {
+            if (e.getCause() instanceof SQLException)
+                throw e;
+
             long[] pageIds = pages(
                 lower == null || cursor == null || cursor.getCursor == null,
                 () -> new long[]{cursor.getCursor.pageId}

Reply via email to