You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "xtern (via GitHub)" <gi...@apache.org> on 2025/08/08 15:03:18 UTC
[PR] IGNITE-26087 [ignite-3]
xtern opened a new pull request, #6397:
URL: https://github.com/apache/ignite-3/pull/6397
https://issues.apache.org/jira/browse/IGNITE-26087
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26087 Ability to obtain results of a multi-statement query execution using the internal thin client SQL API. [ignite-3]
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #6397:
URL: https://github.com/apache/ignite-3/pull/6397#discussion_r2284623703
##########
modules/client/src/main/java/org/apache/ignite/internal/client/sql/ClientAsyncResultSet.java:
##########
@@ -139,6 +162,49 @@ public boolean hasRowSet() {
return hasRowSet;
}
+ /**
+ * Returns flag indicating whether the current result set is the result of
+ * a multi-statement query and this statement is not the last one.
+ */
+ public boolean hasNextResultSet() {
+ return nextResultResourceId != null;
+ }
+
+ /**
+ * Retrieves the next result set of a multi-statement query.
+ *
+ * @return Next result set.
+ * @throws NoSuchElementException if the query has no more statements to execute.
+ */
+ public CompletableFuture<ClientAsyncResultSet<T>> nextResultSet() {
+ if (nextResultResourceId == null) {
+ return CompletableFuture.failedFuture(new NoSuchElementException("Query has no more results"));
+ }
+
+ assert nextResultFuture != null;
+
+ if (!nextResultSetRetrieved.compareAndSet(false, true)) {
+ return nextResultFuture;
+ }
+
+ assert marshaller == null : "Multi-statement execution doesn't support custom mapper";
Review Comment:
I think this one should be checked in constructor or I am missing something?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26087 Ability to obtain results of a multi-statement query execution using the internal thin client SQL API. [ignite-3]
Posted by "ygerzhedovich (via GitHub)" <gi...@apache.org>.
ygerzhedovich merged PR #6397:
URL: https://github.com/apache/ignite-3/pull/6397
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26087 Ability to obtain results of a multi-statement query execution using the internal thin client SQL API. [ignite-3]
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #6397:
URL: https://github.com/apache/ignite-3/pull/6397#discussion_r2284612224
##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientMultistatementSqlTest.java:
##########
@@ -0,0 +1,520 @@
+/*
+ * 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.runner.app.client;
+
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static org.apache.ignite.internal.sql.engine.util.SqlTestUtils.assertThrowsSqlException;
+import static org.apache.ignite.internal.sql.engine.util.SqlTestUtils.expectQueryCancelled;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrows;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.await;
+import static org.apache.ignite.lang.ErrorGroups.Sql.RUNTIME_ERR;
+import static org.apache.ignite.lang.ErrorGroups.Sql.STMT_VALIDATION_ERR;
+import static org.apache.ignite.lang.ErrorGroups.Sql.TX_CONTROL_INSIDE_EXTERNAL_TX_ERR;
+import static org.apache.ignite.lang.ErrorGroups.Transactions.TX_ALREADY_FINISHED_ERR;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import org.apache.ignite.client.handler.ClientResourceRegistry;
+import org.apache.ignite.internal.client.sql.ClientAsyncResultSet;
+import org.apache.ignite.internal.client.sql.ClientSql;
+import org.apache.ignite.internal.client.sql.QueryModifier;
+import org.apache.ignite.internal.sql.SyncResultSetAdapter;
+import org.apache.ignite.internal.sql.engine.SqlQueryProcessor;
+import org.apache.ignite.internal.tx.TxManager;
+import org.apache.ignite.lang.CancelHandle;
+import org.apache.ignite.lang.CancellationToken;
+import org.apache.ignite.sql.ResultSet;
+import org.apache.ignite.sql.SqlRow;
+import org.apache.ignite.sql.Statement;
+import org.apache.ignite.sql.async.AsyncResultSet;
+import org.apache.ignite.table.Table;
+import org.apache.ignite.table.mapper.Mapper;
+import org.apache.ignite.tx.Transaction;
+import org.awaitility.Awaitility;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Thin client SQL multi-statement integration test.
+ *
+ * <p>Tests to check internal API for reading script execution results.
+ */
+@SuppressWarnings("resource")
+public class ItThinClientMultistatementSqlTest extends ItAbstractThinClientTest {
+ private final List<ClientAsyncResultSet<SqlRow>> resultsToClose = new ArrayList<>();
+
+ private int resourcesBefore;
+
+ @BeforeEach
+ void setup() {
+ resultsToClose.forEach(resultSet -> await(resultSet.closeAsync()));
+
+ resourcesBefore = countResources();
+ }
+
+ @AfterEach
+ protected void checkNoPendingTransactionsAndOpenedCursors() {
+ Awaitility.await().timeout(5, TimeUnit.SECONDS).untilAsserted(() -> {
+ for (int i = 0; i < nodes(); i++) {
+ assertThat("node=" + i, queryProcessor(i).openedCursors(), is(0));
+ }
+
+ for (int i = 0; i < nodes(); i++) {
+ assertThat("node=" + i, txManager(i).pending(), is(0));
+ }
+
+ assertThat(countResources() - resourcesBefore, is(0));
+
+ for (int i = 0; i < nodes(); i++) {
+ int cancelHandlesCount = unwrapIgniteImpl(server(i)).clientInboundMessageHandler().cancelHandlesCount();
+
+ assertThat("node=" + i, cancelHandlesCount, is(0));
+ }
+ });
+
+ String dropTablesScript = client().tables().tables().stream()
+ .map(Table::name)
+ .map(name -> "DROP TABLE " + name)
+ .collect(Collectors.joining(";\n"));
+
+ if (!dropTablesScript.isEmpty()) {
+ client().sql().executeScript(dropTablesScript);
+ }
+ }
+
+ @Test
+ void iterateOverResults() {
+ ClientAsyncResultSet<SqlRow> asyncRs = runSql("SELECT 1; SELECT 2; SELECT 3;");
+
+ // First result set.
+ {
+ SyncResultSetAdapter<SqlRow> rs = new SyncResultSetAdapter<>(asyncRs);
+ assertThat(rs.hasRowSet(), is(true));
+ assertThat(rs.next().intValue(0), is(1));
+
+ rs.close();
+ }
+
+ assertThat(asyncRs.hasNextResultSet(), is(true));
+ assertThat(asyncRs.nextResultSet(), is(asyncRs.nextResultSet()));
Review Comment:
What does this check do?
```
assertThat(asyncRs.nextResultSet(), is(asyncRs.nextResultSet()));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26087 Ability to obtain results of a multi-statement query execution using the internal thin client SQL API. [ignite-3]
Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #6397:
URL: https://github.com/apache/ignite-3/pull/6397#discussion_r2285071714
##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientMultistatementSqlTest.java:
##########
@@ -0,0 +1,520 @@
+/*
+ * 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.runner.app.client;
+
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static org.apache.ignite.internal.sql.engine.util.SqlTestUtils.assertThrowsSqlException;
+import static org.apache.ignite.internal.sql.engine.util.SqlTestUtils.expectQueryCancelled;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrows;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.await;
+import static org.apache.ignite.lang.ErrorGroups.Sql.RUNTIME_ERR;
+import static org.apache.ignite.lang.ErrorGroups.Sql.STMT_VALIDATION_ERR;
+import static org.apache.ignite.lang.ErrorGroups.Sql.TX_CONTROL_INSIDE_EXTERNAL_TX_ERR;
+import static org.apache.ignite.lang.ErrorGroups.Transactions.TX_ALREADY_FINISHED_ERR;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import org.apache.ignite.client.handler.ClientResourceRegistry;
+import org.apache.ignite.internal.client.sql.ClientAsyncResultSet;
+import org.apache.ignite.internal.client.sql.ClientSql;
+import org.apache.ignite.internal.client.sql.QueryModifier;
+import org.apache.ignite.internal.sql.SyncResultSetAdapter;
+import org.apache.ignite.internal.sql.engine.SqlQueryProcessor;
+import org.apache.ignite.internal.tx.TxManager;
+import org.apache.ignite.lang.CancelHandle;
+import org.apache.ignite.lang.CancellationToken;
+import org.apache.ignite.sql.ResultSet;
+import org.apache.ignite.sql.SqlRow;
+import org.apache.ignite.sql.Statement;
+import org.apache.ignite.sql.async.AsyncResultSet;
+import org.apache.ignite.table.Table;
+import org.apache.ignite.table.mapper.Mapper;
+import org.apache.ignite.tx.Transaction;
+import org.awaitility.Awaitility;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Thin client SQL multi-statement integration test.
+ *
+ * <p>Tests to check internal API for reading script execution results.
+ */
+@SuppressWarnings("resource")
+public class ItThinClientMultistatementSqlTest extends ItAbstractThinClientTest {
+ private final List<ClientAsyncResultSet<SqlRow>> resultsToClose = new ArrayList<>();
+
+ private int resourcesBefore;
+
+ @BeforeEach
+ void setup() {
+ resultsToClose.forEach(resultSet -> await(resultSet.closeAsync()));
+
+ resourcesBefore = countResources();
+ }
+
+ @AfterEach
+ protected void checkNoPendingTransactionsAndOpenedCursors() {
+ Awaitility.await().timeout(5, TimeUnit.SECONDS).untilAsserted(() -> {
+ for (int i = 0; i < nodes(); i++) {
+ assertThat("node=" + i, queryProcessor(i).openedCursors(), is(0));
+ }
+
+ for (int i = 0; i < nodes(); i++) {
+ assertThat("node=" + i, txManager(i).pending(), is(0));
+ }
+
+ assertThat(countResources() - resourcesBefore, is(0));
+
+ for (int i = 0; i < nodes(); i++) {
+ int cancelHandlesCount = unwrapIgniteImpl(server(i)).clientInboundMessageHandler().cancelHandlesCount();
+
+ assertThat("node=" + i, cancelHandlesCount, is(0));
+ }
+ });
+
+ String dropTablesScript = client().tables().tables().stream()
+ .map(Table::name)
+ .map(name -> "DROP TABLE " + name)
+ .collect(Collectors.joining(";\n"));
+
+ if (!dropTablesScript.isEmpty()) {
+ client().sql().executeScript(dropTablesScript);
+ }
+ }
+
+ @Test
+ void iterateOverResults() {
+ ClientAsyncResultSet<SqlRow> asyncRs = runSql("SELECT 1; SELECT 2; SELECT 3;");
+
+ // First result set.
+ {
+ SyncResultSetAdapter<SqlRow> rs = new SyncResultSetAdapter<>(asyncRs);
+ assertThat(rs.hasRowSet(), is(true));
+ assertThat(rs.next().intValue(0), is(1));
+
+ rs.close();
+ }
+
+ assertThat(asyncRs.hasNextResultSet(), is(true));
+ assertThat(asyncRs.nextResultSet(), is(asyncRs.nextResultSet()));
Review Comment:
we check that the repeated call returns the same future (no additional network requests)
Added comment about this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-26087 Ability to obtain results of a multi-statement query execution using the internal thin client SQL API. [ignite-3]
Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #6397:
URL: https://github.com/apache/ignite-3/pull/6397#discussion_r2285072473
##########
modules/client/src/main/java/org/apache/ignite/internal/client/sql/ClientAsyncResultSet.java:
##########
@@ -139,6 +162,49 @@ public boolean hasRowSet() {
return hasRowSet;
}
+ /**
+ * Returns flag indicating whether the current result set is the result of
+ * a multi-statement query and this statement is not the last one.
+ */
+ public boolean hasNextResultSet() {
+ return nextResultResourceId != null;
+ }
+
+ /**
+ * Retrieves the next result set of a multi-statement query.
+ *
+ * @return Next result set.
+ * @throws NoSuchElementException if the query has no more statements to execute.
+ */
+ public CompletableFuture<ClientAsyncResultSet<T>> nextResultSet() {
+ if (nextResultResourceId == null) {
+ return CompletableFuture.failedFuture(new NoSuchElementException("Query has no more results"));
+ }
+
+ assert nextResultFuture != null;
+
+ if (!nextResultSetRetrieved.compareAndSet(false, true)) {
+ return nextResultFuture;
+ }
+
+ assert marshaller == null : "Multi-statement execution doesn't support custom mapper";
Review Comment:
Removed this confusing assertion.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org