ygerzhedovich commented on code in PR #4591: URL: https://github.com/apache/ignite-3/pull/4591#discussion_r1812841472
########## modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItRunningQueriesSystemViewTest.java: ########## @@ -0,0 +1,356 @@ +/* + * 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.sql.engine; + +import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl; +import static org.apache.ignite.internal.sql.engine.registry.RunningQueriesRegistryImpl.SCRIPT_QUERY_TYPE; +import static org.apache.ignite.internal.sql.engine.util.SqlTestUtils.assertThrowsSqlException; +import static org.apache.ignite.internal.testframework.IgniteTestUtils.await; +import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.hasLength; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.time.Instant; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import org.apache.ignite.Ignite; +import org.apache.ignite.internal.hlc.ClockService; +import org.apache.ignite.internal.sql.SqlCommon; +import org.apache.ignite.internal.sql.engine.registry.QueryExecutionPhase; +import org.apache.ignite.internal.sql.engine.util.MetadataMatcher; +import org.apache.ignite.internal.tx.InternalTransaction; +import org.apache.ignite.lang.ErrorGroups.Sql; +import org.apache.ignite.sql.ColumnType; +import org.hamcrest.Matcher; +import org.hamcrest.Matchers; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * End-to-end tests to verify {@code SQL_QUERIES} system view. + */ +public class ItRunningQueriesSystemViewTest extends BaseSqlMultiStatementTest { + @BeforeAll + void beforeAll() { + await(systemViewManager().completeRegistration()); + + sql("CREATE TABLE test(id INT PRIMARY KEY)"); + } + + @AfterEach + void cleanup() throws InterruptedException { + sql("DELETE FROM test"); + + checkNoPendingQueries(); + } + + @Override + protected int initialNodes() { + return 2; + } + + @Test + public void singleStatement() { + String query = "SELECT * FROM SQL_QUERIES ORDER BY START_TIME"; + + // Verify metadata. + assertQuery(query) + .withDefaultSchema("SYSTEM") + .columnMetadata( Review Comment: will be good to add check nullability for all columns ########## modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItRunningQueriesSystemViewTest.java: ########## @@ -0,0 +1,356 @@ +/* + * 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.sql.engine; + +import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl; +import static org.apache.ignite.internal.sql.engine.registry.RunningQueriesRegistryImpl.SCRIPT_QUERY_TYPE; +import static org.apache.ignite.internal.sql.engine.util.SqlTestUtils.assertThrowsSqlException; +import static org.apache.ignite.internal.testframework.IgniteTestUtils.await; +import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.hasLength; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.time.Instant; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import org.apache.ignite.Ignite; +import org.apache.ignite.internal.hlc.ClockService; +import org.apache.ignite.internal.sql.SqlCommon; +import org.apache.ignite.internal.sql.engine.registry.QueryExecutionPhase; +import org.apache.ignite.internal.sql.engine.util.MetadataMatcher; +import org.apache.ignite.internal.tx.InternalTransaction; +import org.apache.ignite.lang.ErrorGroups.Sql; +import org.apache.ignite.sql.ColumnType; +import org.hamcrest.Matcher; +import org.hamcrest.Matchers; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * End-to-end tests to verify {@code SQL_QUERIES} system view. + */ +public class ItRunningQueriesSystemViewTest extends BaseSqlMultiStatementTest { Review Comment: I expect that can find test by pattern nameOfView+Test, in this case it will be hard to fast find the test ########## modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/registry/RunningQueryInfoImpl.java: ########## @@ -0,0 +1,148 @@ +/* + * 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.sql.engine.registry; + +import java.time.Instant; +import java.util.Objects; +import java.util.UUID; +import org.apache.ignite.internal.sql.engine.AsyncSqlCursor; +import org.apache.ignite.internal.sql.engine.SqlQueryType; +import org.jetbrains.annotations.Nullable; + +/** + * Information about a running query. + */ +public class RunningQueryInfoImpl implements RunningQueryInfo { Review Comment: What about working in a multithreaded environment? Do we have right now a guarantee that all set/get methods will be invoked from the single thread? ########## modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/SqlQueryProcessor.java: ########## @@ -518,23 +533,30 @@ private CompletableFuture<AsyncSqlCursor<InternalSqlRow>> querySingle( : CompletableFuture.supplyAsync(() -> parseAndCache(sql), taskExecutor); return start.thenCompose(result -> { + queryInfo.queryType(result.queryType()); validateParsedStatement(properties, result); validateDynamicParameters(result.dynamicParamsCount(), params, true); HybridTimestamp operationTime = deriveOperationTime(txContext); SqlOperationContext operationContext = SqlOperationContext.builder() - .queryId(UUID.randomUUID()) + .queryId(queryInfo.queryId()) Review Comment: can we obtain the value under the hood instead of explicit set? ########## modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/registry/RunningQueriesRegistryImpl.java: ########## @@ -0,0 +1,142 @@ +/* + * 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.sql.engine.registry; + +import static org.apache.ignite.internal.type.NativeTypes.stringOf; + +import java.time.Instant; +import java.util.Collection; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Flow.Publisher; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.internal.sql.engine.AsyncSqlCursor; +import org.apache.ignite.internal.sql.engine.tx.QueryTransactionWrapper; +import org.apache.ignite.internal.sql.engine.tx.ScriptTransactionContext; +import org.apache.ignite.internal.systemview.api.SystemView; +import org.apache.ignite.internal.systemview.api.SystemViews; +import org.apache.ignite.internal.type.NativeType; +import org.apache.ignite.internal.type.NativeTypes; +import org.apache.ignite.internal.util.SubscriptionUtils; +import org.jetbrains.annotations.Nullable; + +/**git Review Comment: ```suggestion /** ``` -- 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-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org