This is an automated email from the ASF dual-hosted git repository.
namelchev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 92a68658897 IGNITE-19350 Fixed assertion error in case of empty SQL
query (#10663)
92a68658897 is described below
commit 92a68658897833760ebf698b18135ccc951d1cce
Author: Nikita Amelchev <[email protected]>
AuthorDate: Mon Apr 24 17:40:24 2023 +0300
IGNITE-19350 Fixed assertion error in case of empty SQL query (#10663)
---
.../query/calcite/CalciteQueryProcessorTest.java | 11 +++++++++--
.../processors/query/h2/IgniteH2Indexing.java | 4 ++++
.../org/apache/ignite/client/FunctionalQueryTest.java | 19 +++++++++++++++++++
3 files changed, 32 insertions(+), 2 deletions(-)
diff --git
a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessorTest.java
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessorTest.java
index d9d5e4dfe14..7839badbd9d 100644
---
a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessorTest.java
+++
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessorTest.java
@@ -27,7 +27,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
-
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.apache.calcite.util.ImmutableIntList;
@@ -45,6 +44,7 @@ import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
import org.apache.ignite.internal.processors.cache.query.QueryCursorEx;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
import org.apache.ignite.internal.processors.query.QueryEngine;
import
org.apache.ignite.internal.processors.query.calcite.exec.MailboxRegistryImpl;
import org.apache.ignite.internal.processors.query.calcite.exec.rel.Inbox;
@@ -65,6 +65,7 @@ import org.junit.Test;
import static
org.apache.ignite.internal.processors.query.calcite.QueryChecker.awaitReservationsRelease;
import static
org.apache.ignite.internal.processors.query.calcite.QueryChecker.containsIndexScan;
import static
org.apache.ignite.internal.processors.query.calcite.QueryChecker.containsSubPlan;
+import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
@@ -587,7 +588,6 @@ public class CalciteQueryProcessorTest extends
GridCommonAbstractTest {
assertEquals(2, rows.size());
}
-
/** */
@Test
public void testUnion() throws Exception {
@@ -1148,6 +1148,13 @@ public class CalciteQueryProcessorTest extends
GridCommonAbstractTest {
.check();
}
+ /** */
+ @Test
+ @SuppressWarnings("ThrowableNotThrown")
+ public void testEmptyQuery() {
+ assertThrows(log, () -> sql(""), IgniteSQLException.class, "Failed to
parse query");
+ }
+
/** */
private static List<String> deriveColumnNamesFromCursor(FieldsQueryCursor
cursor) {
List<String> names = new ArrayList<>(cursor.getColumnsCount());
diff --git
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index 3930e893532..f54a223cc6f 100644
---
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -124,6 +124,7 @@ import
org.apache.ignite.internal.processors.query.schema.AbstractSchemaChangeLi
import org.apache.ignite.internal.processors.tracing.MTC;
import org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings;
import org.apache.ignite.internal.processors.tracing.Span;
+import org.apache.ignite.internal.sql.SqlParseException;
import org.apache.ignite.internal.sql.command.SqlCommand;
import org.apache.ignite.internal.sql.command.SqlCommitTransactionCommand;
import org.apache.ignite.internal.sql.command.SqlRollbackTransactionCommand;
@@ -1083,6 +1084,9 @@ public class IgniteH2Indexing implements
GridQueryIndexing {
}
}
+ if (res.isEmpty())
+ throw new SqlParseException(qry.getSql(), 0,
IgniteQueryErrorCode.PARSING, "Invalid SQL query.");
+
return res;
}
catch (RuntimeException | Error e) {
diff --git
a/modules/indexing/src/test/java/org/apache/ignite/client/FunctionalQueryTest.java
b/modules/indexing/src/test/java/org/apache/ignite/client/FunctionalQueryTest.java
index 86ac21f0cb5..e5440fdfcc5 100644
---
a/modules/indexing/src/test/java/org/apache/ignite/client/FunctionalQueryTest.java
+++
b/modules/indexing/src/test/java/org/apache/ignite/client/FunctionalQueryTest.java
@@ -37,11 +37,14 @@ import org.apache.ignite.cache.query.SqlQuery;
import org.apache.ignite.configuration.BinaryConfiguration;
import org.apache.ignite.configuration.ClientConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.sql.SqlParseException;
import org.apache.ignite.testframework.GridTestUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
+import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -298,6 +301,22 @@ public class FunctionalQueryTest {
}
}
+ /** */
+ @Test
+ @SuppressWarnings("ThrowableNotThrown")
+ public void testEmptyQuery() {
+ try (IgniteEx srv =
(IgniteEx)Ignition.start(Config.getServerConfiguration());
+ IgniteClient client = Ignition.startClient(new
ClientConfiguration().setAddresses(Config.SERVER))
+ ) {
+ SqlFieldsQuery empty = new SqlFieldsQuery("");
+
+ assertThrows(null, () ->
srv.context().query().querySqlFields(empty, false).getAll(),
+ SqlParseException.class, "Failed to parse SQL");
+
+ assertThrows(null, () -> client.query(empty).getAll(),
ClientException.class, "Failed to parse SQL");
+ }
+ }
+
/** */
private static ClientConfiguration getClientConfiguration() {
return new ClientConfiguration().setAddresses(Config.SERVER)