You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "jt2594838 (via GitHub)" <gi...@apache.org> on 2026/02/13 11:01:34 UTC

[PR] Support select locally for data consistency check [iotdb]

jt2594838 opened a new pull request, #17205:
URL: https://github.com/apache/iotdb/pull/17205

   Add a query option `LOCALLY` that may allow only selecting data from the currently connected node.
   
   This is designed for the data consistency check for developers and maintainers mainly.
   
   Refer to the newly added ITs for examples.


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support select locally for data consistency check [iotdb]

Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on code in PR #17205:
URL: https://github.com/apache/iotdb/pull/17205#discussion_r3360886199


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/distribute/TableDistributedPlanGenerator.java:
##########
@@ -810,6 +811,19 @@ private List<PlanNode> constructDeviceTableScanByRegionReplicaSet(
         context.deviceCrossRegion = true;
       }
       for (final TRegionReplicaSet regionReplicaSet : regionReplicaSets) {
+        if (analysis.isLocalQuery()) {
+          // only query this node in local query mode
+          int dataNodeId = IoTDBDescriptor.getInstance().getConfig().getDataNodeId();
+          boolean containsThisNode =
+              regionReplicaSet.dataNodeLocations.stream()
+                  .anyMatch(dn -> dn.getDataNodeId() == dataNodeId);
+          if (!containsThisNode) {
+            continue;
+          } else {
+            regionReplicaSet.dataNodeLocations.removeIf(dn -> dn.getDataNodeId() != dataNodeId);

Review Comment:
   This mutates the `TRegionReplicaSet` returned from `DataPartition`/`PartitionCache`. Those objects are shared by the query analysis/route cache, so after one local query the replica set can remain truncated for later normal queries. Please build a new `TRegionReplicaSet(regionReplicaSet.getRegionId(), localLocations)` and set/use that instead of changing `dataNodeLocations` in place.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/distribute/TableDistributedPlanGenerator.java:
##########
@@ -810,6 +811,19 @@ private List<PlanNode> constructDeviceTableScanByRegionReplicaSet(
         context.deviceCrossRegion = true;
       }
       for (final TRegionReplicaSet regionReplicaSet : regionReplicaSets) {
+        if (analysis.isLocalQuery()) {

Review Comment:
   This only runs in `constructDeviceTableScanByRegionReplicaSet`. When `visitDeviceTableScan` takes the `context.isPushDownGrouping()` branch, `constructDeviceTableScanByTags` never applies the local filter, so local queries with grouping/tag pushdown can still schedule remote replicas. The local restriction should be applied before both split paths or the unsupported shapes should be rejected.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java:
##########
@@ -860,6 +860,8 @@ protected Scope visitExplainAnalyze(ExplainAnalyze node, Optional<Scope> context
     @Override
     protected Scope visitQuery(Query node, Optional<Scope> context) {
       analysis.setQuery(true);
+      analysis.setLocalQuery(node.getQueryBody().isLocalQuery());

Review Comment:
   `Analysis` is shared across the whole statement, but `visitQuery` is also called for subqueries/CTEs. A nested SELECT will overwrite this flag, so `SELECT LOCALLY ... FROM (SELECT ...)` can lose local mode, and `SELECT ... FROM (SELECT LOCALLY ...)` can make outer scans local. The local marker needs to be scoped to the specific query/table scan or saved/restored when analyzing nested queries.



##########
iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4:
##########
@@ -1669,6 +1669,7 @@ LISTAGG: 'LISTAGG';
 LOAD: 'LOAD';
 LOADED: 'LOADED';

Review Comment:
   Adding `LOCALLY` as a lexer token makes unquoted `locally` stop parsing as an identifier unless it is also included in `nonReserved`. That breaks existing table/column names such as `SELECT locally FROM t` or `CREATE TABLE locally (...)`. Please keep it non-reserved if this is only a SELECT modifier.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support select locally for data consistency check [iotdb]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17205:
URL: https://github.com/apache/iotdb/pull/17205#issuecomment-3982947235

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17205) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [11 New issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17205&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17205&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_iotdb&pullRequest=17205&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17205&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [4.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17205&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17205)
   
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support select locally for data consistency check [iotdb]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #17205:
URL: https://github.com/apache/iotdb/pull/17205#issuecomment-3896829577

   ## [Codecov](https://app.codecov.io/gh/apache/iotdb/pull/17205?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `81.57895%` with `7 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 39.50%. Comparing base ([`fe0d62e`](https://app.codecov.io/gh/apache/iotdb/commit/fe0d62e3d7b52aff0222d3acd217e786585f78c1?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`58d6509`](https://app.codecov.io/gh/apache/iotdb/commit/58d65094a979925ef54b7452662a0cb707ef4531?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 1 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/iotdb/pull/17205?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...nner/distribute/TableDistributedPlanGenerator.java](https://app.codecov.io/gh/apache/iotdb/pull/17205?src=pr&el=tree&filepath=iotdb-core%2Fdatanode%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fiotdb%2Fdb%2Fqueryengine%2Fplan%2Frelational%2Fplanner%2Fdistribute%2FTableDistributedPlanGenerator.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aW90ZGItY29yZS9kYXRhbm9kZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW90ZGIvZGIvcXVlcnllbmdpbmUvcGxhbi9yZWxhdGlvbmFsL3BsYW5uZXIvZGlzdHJpYnV0ZS9UYWJsZURpc3RyaWJ1dGVkUGxhbkdlbmVyYXRvci5qYXZh) | 12.50% | [7 Missing :warning: ](https://app.codecov.io/gh/apache/iotdb/pull/17205?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #17205      +/-   ##
   ============================================
   - Coverage     39.50%   39.50%   -0.01%     
     Complexity      282      282              
   ============================================
     Files          5101     5101              
     Lines        341889   341916      +27     
     Branches      43525    43528       +3     
   ============================================
   + Hits         135069   135079      +10     
   - Misses       206820   206837      +17     
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/iotdb/pull/17205?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   </details>


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support select locally for data consistency check [iotdb]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17205:
URL: https://github.com/apache/iotdb/pull/17205#issuecomment-3896597412

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17205) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [11 New issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17205&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17205&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_iotdb&pullRequest=17205&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17205&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [4.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17205&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17205)
   
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support select locally for data consistency check [iotdb]

Posted by "luoluoyuyu (via GitHub) via reviews" <re...@iotdb.apache.org>.
luoluoyuyu commented on code in PR #17205:
URL: https://github.com/apache/iotdb/pull/17205#discussion_r4678871677


##########
integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBDataConsistencyIT.java:
##########
@@ -0,0 +1,329 @@
+/*
+ * 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.iotdb.relational.it.db.it;
+
+import org.apache.iotdb.consensus.ConsensusFactory;
+import org.apache.iotdb.db.it.utils.TestUtils;
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.TableClusterIT;
+import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;
+import org.apache.iotdb.itbase.env.BaseEnv;
+
+import org.apache.tsfile.utils.Pair;
+import org.awaitility.Awaitility;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+@SuppressWarnings("UnnecessaryLocalVariable")
+@RunWith(IoTDBTestRunner.class)
+@Category({TableLocalStandaloneIT.class, TableClusterIT.class})

Review Comment:
   **major** `integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBDataConsistencyIT.java:60` — New IT is tagged TableLocalStandaloneIT but requires a 3-DataNode cluster
   
   The class is annotated with both TableLocalStandaloneIT and TableClusterIT, yet setUpClass calls initClusterEnvironment(1, numDNs=3) with dataReplicationFactor=2. The TableSimpleIT profile (integration-test/pom.xml:707) includes TableLocalStandaloneIT and runs with testEnv=TABLE_SIMPLE, so this test executes in a standalone env where the 3-node/RF=2 setup and per-node LOCALLY checks cannot hold, making the test fail or be meaningless in that profile.
   
   **Fix:** Drop TableLocalStandaloneIT from the @Category (keep only TableClusterIT), or guard the cluster-only setup so the test is skipped in the standalone profile.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/QueryBody.java:
##########
@@ -31,4 +31,8 @@ protected QueryBody(@Nullable NodeLocation location) {
   public <R, C> R accept(AstVisitor<R, C> visitor, C context) {
     return visitor.visitQueryBody(this, context);
   }
+
+  public boolean isLocalQuery() {

Review Comment:
   **minor** `iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/QueryBody.java:35` — LOCALLY is silently ignored for set operations (UNION/INTERSECT/EXCEPT)
   
   Only QuerySpecification overrides isLocalQuery(); SetOperation/TableSubquery/Values inherit the false default, and StatementAnalyzer.visitQuery reads node.getQueryBody().isLocalQuery(). For `SELECT LOCALLY * FROM t1 UNION SELECT * FROM t1` the query body is a SetOperation, so the flag is lost and the statement is planned as a normal distributed query, returning remote replica data instead of local data without any error.
   
   **Fix:** Propagate the flag from the set-operation operands (e.g. override isLocalQuery in SetOperation to OR its children) or reject LOCALLY combined with set operations with a SemanticException.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org