This is an automated email from the ASF dual-hosted git repository.
nizhikov 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 3ef755d768f IGNITE-29117 Calcite-only node: integration test and
prerequisite fixes (#13668)
3ef755d768f is described below
commit 3ef755d768f730e2bb54ddd633bc486fda4b2b3e
Author: Nikolay <[email protected]>
AuthorDate: Mon Oct 12 15:08:36 2026 +0300
IGNITE-29117 Calcite-only node: integration test and prerequisite fixes
(#13668)
---
modules/calcite/pom.xml | 7 +
.../query/calcite/CalciteQueryProcessor.java | 4 +-
.../CalciteOnlyNodeIntegrationTest.java | 415 +++++++++++++++++++++
.../ignite/testsuites/IntegrationTestSuite.java | 2 +
.../internal/jdbc/thin/JdbcThinConnection.java | 12 +-
.../processors/cache/IgniteCacheProxyImpl.java | 18 +-
.../odbc/jdbc/JdbcConnectionContext.java | 21 +-
.../odbc/odbc/OdbcConnectionContext.java | 21 +-
.../processors/query/GridQueryProcessor.java | 53 ++-
.../internal/processors/query/NoOpQueryEngine.java | 5 +
.../internal/processors/query/QueryEngine.java | 3 +
.../processors/query/NoQueryEngineNodeTest.java | 122 ++++++
.../ignite/testsuites/IgniteBasicTestSuite.java | 2 +
13 files changed, 621 insertions(+), 64 deletions(-)
diff --git a/modules/calcite/pom.xml b/modules/calcite/pom.xml
index 113ca556b8c..c63689bd5ae 100644
--- a/modules/calcite/pom.xml
+++ b/modules/calcite/pom.xml
@@ -78,6 +78,13 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.thoughtworks.xstream</groupId>
+ <artifactId>xstream</artifactId>
+ <version>${xstream.version}</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
diff --git
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessor.java
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessor.java
index ca6fbd6f390..2fafad476dc 100644
---
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessor.java
+++
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessor.java
@@ -834,8 +834,8 @@ public class CalciteQueryProcessor extends
GridProcessorAdapter implements Query
return qryReg;
}
- /** */
- public CalciteQueryEngineConfiguration config() {
+ /** {@inheritDoc} */
+ @Override public CalciteQueryEngineConfiguration config() {
return cfg;
}
diff --git
a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/CalciteOnlyNodeIntegrationTest.java
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/CalciteOnlyNodeIntegrationTest.java
new file mode 100644
index 00000000000..54de44b55a2
--- /dev/null
+++
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/CalciteOnlyNodeIntegrationTest.java
@@ -0,0 +1,415 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.calcite.integration;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.cache.query.TextQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.Config;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobAdapter;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeTaskSplitAdapter;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.ClientConnectorConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.ThinClientConfiguration;
+import org.apache.ignite.internal.IgniteComponentType;
+import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException;
+import
org.apache.ignite.internal.processors.query.calcite.GridCommonAbstractWrapperTest;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.testframework.CallbackExecutorLogListener;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
+import static
org.apache.ignite.testframework.GridTestUtils.assertThrowsAnyCause;
+
+/**
+ * Checks behavior of a node that has the Calcite engine on the classpath but
<b>not</b> the H2 engine
+ * ({@code ignite-indexing}).
+ * This is the default node layout after the H2 module is moved to {@code
libs/optional} (IGNITE-29117).
+ */
+@SuppressWarnings("deprecation")
+public class CalciteOnlyNodeIntegrationTest extends
GridCommonAbstractWrapperTest {
+ /** */
+ private static final String JDBC_URL = "jdbc:ignite:thin://127.0.0.1";
+
+ /** */
+ public static final String H2_ONLY_QRY_MSG = "is supported by the H2 query
engine only. Add module " +
+ "'ignite-indexing' to the classpath of all Ignite nodes";
+
+ /** Name of the H2 engine, which is not available to the node. */
+ private static final String H2_ENGINE_NAME = "h2";
+
+ /** */
+ private static final String[] CLASS_PATH_PROPS = {"java.class.path",
"surefire.test.class.path"};
+
+ /** */
+ private static final String[] H2_ENTRY_PREFIXES = {"ignite-indexing",
"h2-", "lucene-"};
+
+ /** */
+ private static final String INDEXING_MODULE_DIR =
"/modules/indexing/target/";
+
+ /** Error message of the H2-only SQL commands ({@code SET STREAMING},
{@code COPY}): Calcite cannot parse them. */
+ private static final String PARSE_ERR_MSG = "Failed to parse query";
+
+ /** {@link NodeTask} operation: is the H2 engine visible to the node. */
+ private static final String OP_H2_IN_CLASSPATH = "h2InClassPath";
+
+ /** {@link NodeTask} operation: {@code SELECT QUERY_ENGINE()} via the
cache API. */
+ private static final String OP_QUERY_ENGINE = "queryEngine";
+
+ /** {@link NodeTask} operation: deprecated {@link SqlQuery} via the cache
API, returns the matching keys. */
+ private static final String OP_SQL_QUERY = "sqlQuery";
+
+ /** {@link NodeTask} operation: {@link TextQuery} via the cache API,
returns the matching keys. */
+ private static final String OP_TEXT_QUERY = "textQuery";
+
+ /** Prefix of a {@link NodeTask} result when the operation has failed; the
messages of the cause chain follow. */
+ private static final String ERR_PREFIX = "error: ";
+
+ /** {@inheritDoc} */
+ @BeforeAll
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ startCalciteOnlyNode();
+
+ assertEquals("H2 engine must not be visible to the Calcite-only node",
"false", nodeOp(OP_H2_IN_CLASSPATH));
+
+ try (IgniteClient cli = client()) {
+ ClientCache<Integer, String> cache = cli.cache(DEFAULT_CACHE_NAME);
+
+ cache.put(1, "v1");
+ cache.put(2, "v2");
+ }
+ }
+
+ /** {@inheritDoc} */
+ @AfterAll
+ @Override protected void afterTestsStopped() throws Exception {
+ IgniteProcessProxy.killAll();
+
+ super.afterTestsStopped();
+ }
+
+ /**
+ * Starts a node in a separate JVM with {@code ignite-indexing}, H2 and
Lucene removed from the classpath.
+ * No engine is configured explicitly: the node must pick the only
available one.
+ */
+ private void startCalciteOnlyNode() throws Exception {
+ IgniteConfiguration cfg = optimize(getConfiguration("calcite-only"))
+ .setClientConnectorConfiguration(new ClientConnectorConfiguration()
+ .setThinClientConfiguration(new
ThinClientConfiguration().setMaxActiveComputeTasksPerConnection(1)))
+ .setCacheConfiguration(
+ new CacheConfiguration<Integer,
String>(DEFAULT_CACHE_NAME).setIndexedTypes(Integer.class, String.class));
+
+ CountDownLatch started = new CountDownLatch(1);
+
+ ListeningTestLogger lsnrLog = new ListeningTestLogger(log);
+
+ lsnrLog.registerListener(new CallbackExecutorLogListener(".*Topology
snapshot \\[ver=1,.*", started::countDown));
+
+ new IgniteProcessProxy(cfg, lsnrLog, null, false) {
+ @Override protected Collection<String> filteredJvmArgs() throws
Exception {
+ Collection<String> args = super.filteredJvmArgs();
+
+ args.add("-cp");
+ args.add(Arrays.stream(CLASS_PATH_PROPS)
+ .map(System::getProperty)
+ .filter(Objects::nonNull)
+ .flatMap(s -> Arrays.stream(s.split(File.pathSeparator)))
+ .filter(e -> !isH2Entry(e))
+ .collect(Collectors.joining(File.pathSeparator)));
+
+ return args;
+ }
+ };
+
+ assertTrue("Calcite-only node has not started",
started.await(getTestTimeout(), TimeUnit.MILLISECONDS));
+ }
+
+ /** Baseline: {@link SqlFieldsQuery}, DDL and DML work on a Calcite-only
node, Calcite is the default engine. */
+ @Test
+ public void testSqlFieldsQuery() throws Exception {
+ assertEquals(CalciteQueryEngineConfiguration.ENGINE_NAME,
nodeOp(OP_QUERY_ENGINE));
+
+ try (Connection conn = DriverManager.getConnection(JDBC_URL);
+ Statement stmt = conn.createStatement()
+ ) {
+ stmt.executeUpdate("CREATE TABLE t(id INT PRIMARY KEY, val
VARCHAR) WITH \"template=replicated\"");
+ stmt.executeUpdate("INSERT INTO t VALUES (1, 'a')");
+
+ try (ResultSet rs = stmt.executeQuery("SELECT val FROM t WHERE id
= 1")) {
+ assertTrue(rs.next());
+ assertEquals("a", rs.getString(1));
+ }
+
+ stmt.executeUpdate("DROP TABLE t");
+ }
+ }
+
+ /** */
+ @Test
+ public void testSqlQueryNotSupported() throws Exception {
+ String msg = nodeOp(OP_SQL_QUERY);
+
+ assertTrue(msg, msg.startsWith(ERR_PREFIX) &&
msg.contains(H2_ONLY_QRY_MSG));
+ }
+
+ /** Deprecated {@link SqlQuery} sent by the Java thin client fails on the
server node with the same error. */
+ @Test
+ @SuppressWarnings("ThrowableNotThrown")
+ public void testThinClientSqlQuery() {
+ try (IgniteClient cli = client()) {
+ assertThrows(
+ log,
+ () -> cli.cache(DEFAULT_CACHE_NAME).query(new
SqlQuery<Integer, String>(String.class, "_val = ?").setArgs("v2")).getAll(),
+ ClientException.class,
+ H2_ONLY_QRY_MSG
+ );
+ }
+ }
+
+ /** {@link TextQuery} is implemented by the H2 engine only: the error must
name the missing module. */
+ @Test
+ public void testTextQuery() throws Exception {
+ String res = nodeOp(OP_TEXT_QUERY);
+
+ assertTrue(res, res.startsWith(ERR_PREFIX) &&
res.contains(H2_ONLY_QRY_MSG));
+ }
+
+ /**
+ * {@code SET STREAMING} is implemented by the H2 engine only and is
rejected by the Calcite parser. A rejected
+ * {@code SET STREAMING ON} must not leave the thin JDBC connection in a
state where {@code close()} hangs.
+ */
+ @Test
+ public void testSetStreaming() throws Exception {
+ Connection conn = DriverManager.getConnection(JDBC_URL);
+
+ try (Statement stmt = conn.createStatement()) {
+ assertThrowsAnyCause(
+ log,
+ () -> stmt.executeUpdate("SET STREAMING ON"),
+ SQLException.class,
+ PARSE_ERR_MSG
+ );
+ }
+ finally {
+ try {
+ GridTestUtils.runAsync(conn::close).get(10_000);
+ }
+ catch (IgniteFutureTimeoutCheckedException e) {
+ fail("Connection close hangs after a rejected SET STREAMING
ON");
+ }
+ }
+ }
+
+ /** {@code COPY} (bulk load) is implemented by the H2 engine only and is
rejected by the Calcite parser. */
+ @Test
+ public void testCopy() throws Exception {
+ try (Connection conn = DriverManager.getConnection(JDBC_URL);
+ Statement stmt = conn.createStatement()
+ ) {
+ assertThrowsAnyCause(
+ log,
+ () -> stmt.executeUpdate("COPY FROM '/nonexistent.csv' INTO
\"test\".String(_key, _val) FORMAT CSV"),
+ SQLException.class,
+ PARSE_ERR_MSG
+ );
+ }
+ }
+
+ /** The only available engine is the default one: no JDBC property and no
hint is needed. */
+ @Test
+ public void testJdbcDefaultQueryEngine() throws Exception {
+ try (Connection conn = DriverManager.getConnection(JDBC_URL);
+ Statement stmt = conn.createStatement();
+ ResultSet rs = stmt.executeQuery("SELECT QUERY_ENGINE()")
+ ) {
+ assertTrue(rs.next());
+ assertEquals(CalciteQueryEngineConfiguration.ENGINE_NAME,
rs.getString(1));
+ }
+ }
+
+ /** The only available engine can be selected by name via the JDBC
property without an explicit configuration. */
+ @Test
+ public void testJdbcQueryEngineProperty() throws Exception {
+ try (Connection conn = DriverManager.getConnection(JDBC_URL +
"?queryEngine=" + CalciteQueryEngineConfiguration.ENGINE_NAME);
+ Statement stmt = conn.createStatement();
+ ResultSet rs = stmt.executeQuery("SELECT QUERY_ENGINE()")
+ ) {
+ assertTrue(rs.next());
+ assertEquals(CalciteQueryEngineConfiguration.ENGINE_NAME,
rs.getString(1));
+ }
+ }
+
+ /** The H2 engine cannot be selected via the JDBC property: the handshake
is rejected. */
+ @Test
+ public void testJdbcH2QueryEngineProperty() {
+ assertThrowsAnyCause(
+ log,
+ () -> DriverManager.getConnection(JDBC_URL + "?queryEngine=" +
H2_ENGINE_NAME),
+ SQLException.class,
+ "Not found configuration for query engine: " + H2_ENGINE_NAME
+ );
+ }
+
+ /** The only available engine can be selected by the query hint without an
explicit configuration. */
+ @Test
+ public void testQueryEngineHint() throws Exception {
+ String qry = "SELECT /*+ QUERY_ENGINE('" +
CalciteQueryEngineConfiguration.ENGINE_NAME + "') */ QUERY_ENGINE()";
+
+ try (Connection conn = DriverManager.getConnection(JDBC_URL);
+ Statement stmt = conn.createStatement();
+ ResultSet rs = stmt.executeQuery(qry)
+ ) {
+ assertTrue(rs.next());
+ assertEquals(CalciteQueryEngineConfiguration.ENGINE_NAME,
rs.getString(1));
+ }
+ }
+
+ /** The H2 engine cannot be selected by the query hint. */
+ @Test
+ public void testH2QueryEngineHint() throws Exception {
+ String qry = "SELECT /*+ QUERY_ENGINE('" + H2_ENGINE_NAME + "') */
QUERY_ENGINE()";
+
+ try (Connection conn = DriverManager.getConnection(JDBC_URL);
+ Statement stmt = conn.createStatement()
+ ) {
+ assertThrowsAnyCause(
+ log,
+ () -> stmt.executeQuery(qry),
+ SQLException.class,
+ "Query engine not found: " + H2_ENGINE_NAME
+ );
+ }
+ }
+
+ /** @return {@code True} if the classpath entry belongs to the H2 engine.
*/
+ private static boolean isH2Entry(String entry) {
+ String name = new File(entry).getName();
+
+ return Arrays.stream(H2_ENTRY_PREFIXES).anyMatch(name::startsWith)
+ || entry.replace('\\', '/').contains(INDEXING_MODULE_DIR);
+ }
+
+ /** */
+ private static IgniteClient client() {
+ return Ignition.startClient(new
ClientConfiguration().setAddresses(Config.SERVER));
+ }
+
+ /**
+ * Runs a cache API operation inside the Calcite-only node.
+ *
+ * @param op One of the {@code OP_*} constants.
+ * @return Operation result, or {@link #ERR_PREFIX} followed by the error
messages if the operation has failed.
+ */
+ private static String nodeOp(String op) throws Exception {
+ try (IgniteClient cli = client()) {
+ return cli.compute().execute(NodeTask.class.getName(), op);
+ }
+ }
+
+ /** Runs a cache API operation inside the Calcite-only node, see {@link
#nodeOp(String)}. */
+ private static class NodeTask extends ComputeTaskSplitAdapter<String,
String> {
+ /** {@inheritDoc} */
+ @Override protected Collection<? extends ComputeJob> split(int
gridSize, String op) {
+ return Collections.singleton(new NodeJob(op));
+ }
+
+ /** {@inheritDoc} */
+ @Override public String reduce(List<ComputeJobResult> results) {
+ return results.get(0).getData();
+ }
+ }
+
+ /** */
+ private static class NodeJob extends ComputeJobAdapter {
+ /** */
+ @IgniteInstanceResource
+ private Ignite ignite;
+
+ /** */
+ private final String op;
+
+ /** */
+ private NodeJob(String op) {
+ this.op = op;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object execute() {
+ try {
+ IgniteCache<Integer, String> cache =
ignite.cache(DEFAULT_CACHE_NAME);
+
+ return switch (op) {
+ case OP_H2_IN_CLASSPATH ->
+
String.valueOf(IgniteComponentType.INDEXING.inClassPath());
+
+ case OP_QUERY_ENGINE ->
+ String.valueOf(cache.query(new SqlFieldsQuery("SELECT
QUERY_ENGINE()")).getAll().get(0).get(0));
+
+ case OP_SQL_QUERY ->
+ cache.query(new SqlQuery<Integer,
String>(String.class, "_val = ?").setArgs("v1")).getAll();
+
+ case OP_TEXT_QUERY ->
+ cache.query(new TextQuery<Integer,
String>(String.class, "v1")).getAll();
+
+ default ->
+ throw new IllegalArgumentException("Unknown operation:
" + op);
+ };
+ }
+ catch (Throwable e) {
+ StringBuilder sb = new StringBuilder(ERR_PREFIX);
+
+ for (Throwable t = e; t != null; t = t.getCause())
+ sb.append(t.getMessage()).append(t.getCause() == null ? ""
: " <- ");
+
+ return sb.toString();
+ }
+ }
+ }
+}
diff --git
a/modules/calcite/src/test/java/org/apache/ignite/testsuites/IntegrationTestSuite.java
b/modules/calcite/src/test/java/org/apache/ignite/testsuites/IntegrationTestSuite.java
index 833729b5e0b..6cfa81743f9 100644
---
a/modules/calcite/src/test/java/org/apache/ignite/testsuites/IntegrationTestSuite.java
+++
b/modules/calcite/src/test/java/org/apache/ignite/testsuites/IntegrationTestSuite.java
@@ -32,6 +32,7 @@ import
org.apache.ignite.internal.processors.query.calcite.integration.CacheStor
import
org.apache.ignite.internal.processors.query.calcite.integration.CacheWithInterceptorIntegrationTest;
import
org.apache.ignite.internal.processors.query.calcite.integration.CalciteBasicSecondaryIndexIntegrationTest;
import
org.apache.ignite.internal.processors.query.calcite.integration.CalciteErrorHandlilngIntegrationTest;
+import
org.apache.ignite.internal.processors.query.calcite.integration.CalciteOnlyNodeIntegrationTest;
import
org.apache.ignite.internal.processors.query.calcite.integration.CalcitePlanningDumpTest;
import
org.apache.ignite.internal.processors.query.calcite.integration.CollectIntegrationTest;
import
org.apache.ignite.internal.processors.query.calcite.integration.CorrelatesIntegrationTest;
@@ -182,6 +183,7 @@ import org.junit.platform.suite.api.Suite;
TpchScale010Test.class,
TpchScale100Test.class,
UnnestIntegrationTest.class,
+ CalciteOnlyNodeIntegrationTest.class,
CalcitePlanningDumpTest.class,
KeyClassChangeIntegrationTest.class,
QueryEntityValueColumnAliasTest.class,
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java
b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java
index 60a6a4921e6..e8bf4d08ee0 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java
@@ -450,7 +450,7 @@ public class JdbcThinConnection implements Connection {
if (txCtx != null)
throw new SQLException("Can't change stream mode inside
transaction");
- SqlSetStreamingCommand cmd0 = (SqlSetStreamingCommand)cmd;
+ SqlSetStreamingCommand streamingCmd = (SqlSetStreamingCommand)cmd;
// If streaming is already on, we have to close it first.
if (streamState != null) {
@@ -459,7 +459,7 @@ public class JdbcThinConnection implements Connection {
streamState = null;
}
- boolean newVal = ((SqlSetStreamingCommand)cmd).isTurnOn();
+ boolean newVal = streamingCmd.isTurnOn();
ensureConnected();
@@ -467,17 +467,19 @@ public class JdbcThinConnection implements Connection {
// Actual ON, if needed.
if (newVal) {
- if (!cmd0.isOrdered() && !cliIo.isUnorderedStreamSupported()) {
+ if (!streamingCmd.isOrdered() &&
!cliIo.isUnorderedStreamSupported()) {
throw new SQLException("Streaming without order doesn't
supported by server [remoteNodeVer="
+ cliIo.igniteVersion() + ']', INTERNAL_ERROR);
}
- streamState = new StreamState((SqlSetStreamingCommand)cmd,
cliIo);
+ StreamState streamState0 = new StreamState(streamingCmd,
cliIo);
sendRequest(new
JdbcQueryExecuteRequest(JdbcStatementType.ANY_STATEMENT_TYPE,
schema, 1, 1, autoCommit, stmt.explicitTimeout, sql, null,
NONE_TX), stmt, cliIo);
- streamState.start();
+ streamState = streamState0;
+
+ streamState0.start();
}
}
else
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java
index 156380c2985..4bb3a56b9a9 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java
@@ -114,6 +114,10 @@ import org.jetbrains.annotations.Nullable;
@SuppressWarnings("unchecked")
public class IgniteCacheProxyImpl<K, V> extends
AsyncSupportAdapter<IgniteCache<K, V>>
implements IgniteCacheProxy<K, V> {
+ /** */
+ public static final String NO_QRY_ENGINE_MSG = "Failed to execute query.
Add module 'ignite-indexing' to the " +
+ "classpath of all Ignite nodes or configure any query engine.";
+
/** */
private static final long serialVersionUID = 0L;
@@ -891,10 +895,16 @@ public class IgniteCacheProxyImpl<K, V> extends
AsyncSupportAdapter<IgniteCache<
throw new CacheException("Indexing is disabled for cache: " +
cacheName +
". Use setIndexedTypes or setTypeMetadata methods on
CacheConfiguration to enable.");
- if (!ctx.kernalContext().query().moduleEnabled() &&
- (qry instanceof SqlQuery || qry instanceof SqlFieldsQuery || qry
instanceof TextQuery))
- throw new CacheException("Failed to execute query. Add module
'ignite-indexing' to the classpath " +
- "of all Ignite nodes or configure any query engine.");
+ if (!ctx.kernalContext().query().moduleEnabled() && qry instanceof
SqlFieldsQuery)
+ throw new CacheException(NO_QRY_ENGINE_MSG);
+
+ if ((qry instanceof SqlQuery || qry instanceof TextQuery) &&
!ctx.kernalContext().query().indexingEnabled()) {
+ throw new CacheException("Failed to execute query. '" +
qry.getClass().getSimpleName() + "' is supported " +
+ "by the H2 query engine only. Add module 'ignite-indexing' to
the classpath of all Ignite nodes" +
+ (qry instanceof SqlQuery &&
ctx.kernalContext().query().moduleEnabled()
+ ? " or use SqlFieldsQuery instead."
+ : "."));
+ }
}
/** {@inheritDoc} */
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/jdbc/JdbcConnectionContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/jdbc/JdbcConnectionContext.java
index 1ecfdd02f00..a1478ae43c2 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/jdbc/JdbcConnectionContext.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/jdbc/JdbcConnectionContext.java
@@ -23,7 +23,6 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.configuration.QueryEngineConfiguration;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.binary.BinaryReaderEx;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
@@ -36,7 +35,6 @@ import
org.apache.ignite.internal.processors.odbc.ClientListenerResponse;
import org.apache.ignite.internal.processors.odbc.ClientListenerResponseSender;
import
org.apache.ignite.internal.processors.platform.client.tx.ClientTxContext;
import org.apache.ignite.internal.processors.query.IgniteSQLException;
-import org.apache.ignite.internal.processors.query.QueryEngineConfigurationEx;
import org.apache.ignite.internal.util.GridSpinBusyLock;
import org.apache.ignite.internal.util.nio.GridNioSession;
import org.apache.ignite.internal.util.typedef.F;
@@ -217,23 +215,8 @@ public class JdbcConnectionContext extends
ClientListenerAbstractConnectionConte
if (ver.compareTo(VER_2_13_0) >= 0) {
qryEngine = reader.readString();
- if (qryEngine != null) {
- QueryEngineConfiguration[] cfgs =
ctx.config().getSqlConfiguration().getQueryEnginesConfiguration();
-
- boolean found = false;
-
- if (cfgs != null) {
- for (int i = 0; i < cfgs.length; i++) {
- if
(qryEngine.equalsIgnoreCase(((QueryEngineConfigurationEx)cfgs[i]).engineName()))
{
- found = true;
- break;
- }
- }
- }
-
- if (!found)
- throw new IgniteCheckedException("Not found configuration
for query engine: " + qryEngine);
- }
+ if (qryEngine != null &&
!ctx.query().queryEngineConfigured(qryEngine))
+ throw new IgniteCheckedException("Not found configuration for
query engine: " + qryEngine);
}
TransactionConcurrency concurrency = null;
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcConnectionContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcConnectionContext.java
index 626ccf5d63b..6b641f7fcda 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcConnectionContext.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcConnectionContext.java
@@ -21,7 +21,6 @@ import java.util.HashSet;
import java.util.Set;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.configuration.QueryEngineConfiguration;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.binary.BinaryReaderEx;
import
org.apache.ignite.internal.processors.odbc.ClientListenerAbstractConnectionContext;
@@ -31,7 +30,6 @@ import
org.apache.ignite.internal.processors.odbc.ClientListenerRequestHandler;
import org.apache.ignite.internal.processors.odbc.ClientListenerResponse;
import org.apache.ignite.internal.processors.odbc.ClientListenerResponseSender;
import
org.apache.ignite.internal.processors.platform.client.tx.ClientTxContext;
-import org.apache.ignite.internal.processors.query.QueryEngineConfigurationEx;
import org.apache.ignite.internal.util.GridSpinBusyLock;
import org.apache.ignite.internal.util.nio.GridNioSession;
@@ -166,23 +164,8 @@ public class OdbcConnectionContext extends
ClientListenerAbstractConnectionConte
if (ver.compareTo(VER_2_13_0) >= 0) {
qryEngine = reader.readString();
- if (qryEngine != null) {
- QueryEngineConfiguration[] cfgs =
ctx.config().getSqlConfiguration().getQueryEnginesConfiguration();
-
- boolean found = false;
-
- if (cfgs != null) {
- for (int i = 0; i < cfgs.length; i++) {
- if
(qryEngine.equalsIgnoreCase(((QueryEngineConfigurationEx)cfgs[i]).engineName()))
{
- found = true;
- break;
- }
- }
- }
-
- if (!found)
- throw new IgniteCheckedException("Not found configuration
for query engine: " + qryEngine);
- }
+ if (qryEngine != null &&
!ctx.query().queryEngineConfigured(qryEngine))
+ throw new IgniteCheckedException("Not found configuration for
query engine: " + qryEngine);
}
authenticate(ses, user, passwd);
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index f88deb1c5c4..c64e2e4f724 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -198,6 +198,10 @@ public class GridQueryProcessor extends
GridProcessorAdapter {
Pattern.compile("QUERY_ENGINE[\\s]*\\([\\s]*'([a-z0-9]+)'[\\s]*\\)",
CASE_INSENSITIVE);
+ /** Error message of the SQL features that require the H2 query engine
when it is not on the classpath. */
+ public static final String INDEXING_DISABLED_MSG = "Failed to execute
query because indexing is disabled " +
+ "(consider adding module '" + INDEXING.module() + "' to classpath or
moving it from 'optional' to 'libs' folder).";
+
/** */
private static final ThreadLocal<AffinityTopologyVersion> requestTopVer =
new ThreadLocal<>();
@@ -293,8 +297,8 @@ public class GridQueryProcessor extends
GridProcessorAdapter {
/** All available query engines. */
private QueryEngine[] qryEngines;
- /** Query engines configuration. */
- private QueryEngineConfigurationEx[] qryEnginesCfg;
+ /** Query engines configuration. {@code null} if neither indexing nor any
query engine is available. */
+ private @Nullable QueryEngineConfigurationEx[] qryEnginesCfg;
/** Running query manager. */
private RunningQueryManager runningQryMgr;
@@ -562,9 +566,12 @@ public class GridQueryProcessor extends
GridProcessorAdapter {
// If indexing is disabled, try to find any query engine in
components.
if (!indexingEnabled()) {
for (GridComponent cmp : ctx.components()) {
- if (cmp instanceof QueryEngine) {
- qryEngines = new QueryEngine[] {(QueryEngine)cmp};
- dfltQryEngine = (QueryEngine)cmp;
+ if (cmp instanceof QueryEngine qryEngine &&
qryEngine.config() != null) {
+ qryEngines = new QueryEngine[] {qryEngine};
+ dfltQryEngine = qryEngine;
+ this.qryEnginesCfg = new QueryEngineConfigurationEx[]
{qryEngine.config()};
+
+ break;
}
}
}
@@ -1019,6 +1026,23 @@ public class GridQueryProcessor extends
GridProcessorAdapter {
return indexingEnabled() || dfltQryEngine != null;
}
+ /**
+ * @param engineName Query engine name.
+ * @return {@code True} if a query engine with the given name can be
selected by the {@code QUERY_ENGINE} hint or
+ * by the client connection property.
+ */
+ public boolean queryEngineConfigured(String engineName) {
+ if (qryEnginesCfg == null)
+ return false;
+
+ for (QueryEngineConfigurationEx cfg : qryEnginesCfg) {
+ if (engineName.equalsIgnoreCase(cfg.engineName()))
+ return true;
+ }
+
+ return false;
+ }
+
/**
* @return Indexing.
* @throws IgniteException If module is not enabled.
@@ -2899,7 +2923,7 @@ public class GridQueryProcessor extends
GridProcessorAdapter {
*/
private void checkIndexingEnabled() throws IgniteCheckedException {
if (idx == null)
- throw new IgniteCheckedException("Indexing is disabled.");
+ throw new IgniteCheckedException(INDEXING_DISABLED_MSG);
}
/**
@@ -2907,20 +2931,15 @@ public class GridQueryProcessor extends
GridProcessorAdapter {
*/
private void checkxIndexingEnabled() throws IgniteException {
if (idx == null)
- throw new IgniteException("Failed to execute query because
indexing is disabled (consider adding module " +
- INDEXING.module() + " to classpath or moving it from
'optional' to 'libs' folder).");
+ throw new IgniteException(INDEXING_DISABLED_MSG);
}
/**
- * @throws IgniteException If indexing is disabled.
+ * @throws IgniteException If neither indexing nor any query engine is
enabled.
*/
private void checkxModuleEnabled() throws IgniteException {
- if (!moduleEnabled()) {
- throw new IgniteException("Failed to execute query because
indexing is disabled and no query engine is " +
- "configured (consider adding module " + INDEXING.module() + "
to classpath or moving it " +
- "from 'optional' to 'libs' folder or configuring any query
engine with " +
-
"IgniteConfiguration.SqlConfiguration.QueryEnginesConfiguration property).");
- }
+ if (!moduleEnabled())
+ throw new IgniteException(INDEXING_DISABLED_MSG);
}
/**
@@ -3301,6 +3320,8 @@ public class GridQueryProcessor extends
GridProcessorAdapter {
String qryInitiatorId) {
assert streamer != null;
+ checkxIndexingEnabled();
+
if (!busyLock.enterBusy())
throw new IllegalStateException("Failed to execute query (grid is
stopping).");
@@ -3363,6 +3384,8 @@ public class GridQueryProcessor extends
GridProcessorAdapter {
final SqlQuery qry,
boolean keepBinary
) {
+ checkxIndexingEnabled();
+
// Generate.
String type = qry.getType();
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/NoOpQueryEngine.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/NoOpQueryEngine.java
index 62dbdeb3d4f..98ad724aa23 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/NoOpQueryEngine.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/NoOpQueryEngine.java
@@ -70,4 +70,9 @@ public class NoOpQueryEngine extends GridProcessorAdapter
implements QueryEngine
) throws IgniteSQLException {
return Collections.emptyList();
}
+
+ /** {@inheritDoc} */
+ @Override public @Nullable QueryEngineConfigurationEx config() {
+ return null;
+ }
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryEngine.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryEngine.java
index faf2f78ad6b..d0999c5ea9c 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryEngine.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryEngine.java
@@ -81,4 +81,7 @@ public interface QueryEngine extends GridProcessor {
String qry,
List<Object[]> batchedParams
) throws IgniteSQLException;
+
+ /** @return Configuration of the engine. {@code null} if the engine has no
configuration and cannot be selected. */
+ @Nullable QueryEngineConfigurationEx config();
}
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/processors/query/NoQueryEngineNodeTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/query/NoQueryEngineNodeTest.java
new file mode 100644
index 00000000000..1f5be9ac8ae
--- /dev/null
+++
b/modules/core/src/test/java/org/apache/ignite/internal/processors/query/NoQueryEngineNodeTest.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import javax.cache.CacheException;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.cache.query.TextQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static
org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.NO_QRY_ENGINE_MSG;
+import static
org.apache.ignite.internal.processors.query.GridQueryProcessor.INDEXING_DISABLED_MSG;
+import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
+import static
org.apache.ignite.testframework.GridTestUtils.assertThrowsAnyCause;
+
+/** */
+@SuppressWarnings("deprecation")
+public class NoQueryEngineNodeTest extends GridCommonAbstractTest {
+ /** */
+ private static final String JDBC_URL = "jdbc:ignite:thin://127.0.0.1";
+
+ /** */
+ public static final String H2_ONLY_QRY_MSG = "is supported by the H2 query
engine only. Add module " +
+ "'ignite-indexing' to the classpath of all Ignite nodes";
+
+ /** */
+ private static IgniteCache<Integer, String> cache;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String
igniteInstanceName) throws Exception {
+ return
super.getConfiguration(igniteInstanceName).setCacheConfiguration(
+ new CacheConfiguration<Integer,
String>(DEFAULT_CACHE_NAME).setIndexedTypes(Integer.class, String.class));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ cache = startGrid(0).cache(DEFAULT_CACHE_NAME);
+
+ assertFalse("Test must run on a node without any query engine",
grid(0).context().query().moduleEnabled());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ super.afterTestsStopped();
+ }
+
+ /** */
+ @Test
+ public void testSqlFieldsQuery() {
+ assertThrows(log, () -> cache.query(new SqlFieldsQuery("SELECT
1")).getAll(), CacheException.class, NO_QRY_ENGINE_MSG);
+ }
+
+ /** */
+ @Test
+ public void testSqlQuery() {
+ Throwable e = assertThrows(
+ log,
+ () -> cache.query(new SqlQuery<Integer, String>(String.class, "1 =
1")).getAll(),
+ CacheException.class,
+ "'SqlQuery' " + H2_ONLY_QRY_MSG + "."
+ );
+
+ assertFalse(e.getMessage(),
e.getMessage().contains(SqlFieldsQuery.class.getSimpleName()));
+ }
+
+ /** */
+ @Test
+ public void testTextQuery() {
+ assertThrows(
+ log,
+ () -> cache.query(new TextQuery<Integer, String>(String.class,
"text")).getAll(),
+ CacheException.class,
+ "'TextQuery' " + H2_ONLY_QRY_MSG + "."
+ );
+ }
+
+ /** */
+ @Test
+ public void testJdbc() throws Exception {
+ try (Connection conn = DriverManager.getConnection(JDBC_URL);
Statement stmt = conn.createStatement()) {
+ assertThrowsAnyCause(log, () -> stmt.executeQuery("SELECT 1"),
SQLException.class, INDEXING_DISABLED_MSG);
+ }
+ }
+
+ /** */
+ @Test
+ public void testJdbcQueryEngineProperty() {
+ assertThrowsAnyCause(
+ log,
+ () -> DriverManager.getConnection(JDBC_URL +
"?queryEngine=calcite"),
+ SQLException.class,
+ "Not found configuration for query engine: calcite"
+ );
+ }
+}
diff --git
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index e8a54f1c0d4..7273f0d23b2 100644
---
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -63,6 +63,7 @@ import
org.apache.ignite.internal.processors.odbc.ClientSessionOutboundQueueLimi
import
org.apache.ignite.internal.processors.odbc.OdbcConfigurationValidationSelfTest;
import org.apache.ignite.internal.processors.odbc.OdbcEscapeSequenceSelfTest;
import org.apache.ignite.internal.processors.odbc.SqlListenerUtilsTest;
+import org.apache.ignite.internal.processors.query.NoQueryEngineNodeTest;
import
org.apache.ignite.internal.processors.rollingupgrade.CoreVersionRollingUpgradeTest;
import
org.apache.ignite.internal.processors.rollingupgrade.PluginVersionRollingUpgradeTest;
import
org.apache.ignite.internal.processors.rollingupgrade.feature.IgniteFeatureSetTest;
@@ -164,6 +165,7 @@ import org.junit.runners.Suite;
GridIoManagerOrderedUnmarshalFailureTest.class,
MessageUnmarshalOnceCheckTest.class,
GridCacheQueryResponseUnmarshalTest.class,
+ NoQueryEngineNodeTest.class,
ErrorMessageSelfTest.class,
DefaultEnumMapperTest.class,
IgniteDataTransferObjectProcessorTest.class,