Skip to content

Support debug for query#17178

Open
Wei-hao-Li wants to merge 7 commits intomasterfrom
addQueryDebug
Open

Support debug for query#17178
Wei-hao-Li wants to merge 7 commits intomasterfrom
addQueryDebug

Conversation

@Wei-hao-Li
Copy link
Collaborator

No description provided.

Signed-off-by: Weihao Li <18110526956@163.com>
Signed-off-by: Weihao Li <18110526956@163.com>
Signed-off-by: Weihao Li <18110526956@163.com>
Signed-off-by: Weihao Li <18110526956@163.com>

# Conflicts:
#	iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/ClientRPCServiceImpl.java
Signed-off-by: Weihao Li <18110526956@163.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds support for the DEBUG keyword in SQL queries for both tree model and table model. When a query is prefixed with the DEBUG keyword, it enables detailed debug logging throughout the query execution pipeline, which is useful for troubleshooting and understanding query behavior.

Changes:

  • Added DEBUG keyword to ANTLR grammar files for both tree and table models
  • Threaded debug flag through the entire query execution pipeline (Statement, QueryContext, MPPQueryContext, FragmentInstance, FragmentInstanceContext)
  • Updated all QueryContext constructor calls to include the debug parameter
  • Added integration tests to verify DEBUG functionality for both tree and table model queries
  • Added helper methods to AbstractNodeWrapper to clear and check log contents

Reviewed changes

Copilot reviewed 42 out of 42 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
RelationalSql.g4 Added DEBUG token to grammar and included it in nonReserved keywords
Statement.java (relational) Added debug field and getter/setter methods
Statement.java (tree model) Already had debug support - no changes needed
AstBuilder.java Extracts debug flag from parse tree and sets it on Statement
QueryContext.java Made debug field final and added it to all constructors
MPPQueryContext.java Added debug field with getter/setter methods
FragmentInstance.java Added debug field, updated constructors, and implemented serialization/deserialization
FragmentInstanceContext.java Updated all constructors to accept and propagate debug flag
Coordinator.java Updated execution methods with debug parameter and added deprecated compatibility methods
Test files Updated all QueryContext instantiations to pass false for debug flag
IoTDBDebugQueryIT.java Added integration tests for DEBUG keyword functionality
AbstractNodeWrapper.java Added clearLogContent() and logContains() helper methods for log verification
Various other files Updated calls to pass debug flag through the execution pipeline

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 88 to 104
@Test
public void tableTest() throws IOException {
// clear log content to reduce lines spanned in logContains check
dataNodeWrapper.clearLogContent();

String[] expectedHeader =
new String[] {
"Time", "root.test.departments.department_id", "root.test.departments.dep_name"
};
String[] retArray = new String[] {"1,D001,研发部,"};
resultSetEqualTest(
"debug select department_id, dep_name from root.test.departments",
expectedHeader,
retArray);

assertTrue(dataNodeWrapper.logContains("Cache miss: root.test.departments"));
}
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test method name is misleading. The method is named "tableTest" but it's actually testing the tree model query with "debug select department_id, dep_name from root.test.departments". Consider renaming to "treeTest" for clarity.

Copilot uses AI. Check for mistakes.
Comment on lines 309 to 310
if (userQuery) {
System.out.println("--------------" + debug);
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statement should be removed before merging to production. This System.out.println was likely added for development testing but should not be part of the final code.

Suggested change
if (userQuery) {
System.out.println("--------------" + debug);
if (userQuery && LOGGER.isDebugEnabled()) {
LOGGER.debug("[QueryDebugFlag] debug: {}", debug);

Copilot uses AI. Check for mistakes.
Comment on lines 75 to 86
@Test
public void treeTest() throws IOException {
// clear log content to reduce lines spanned in logContains check
dataNodeWrapper.clearLogContent();

String[] expectedHeader = new String[] {"time", "device", "value"};
String[] retArray = new String[] {"2020-01-01T00:00:01.000Z,d1,1,"};
tableResultSetEqualTest(
"debug select time,device,value from table1", expectedHeader, retArray, DATABASE_NAME);

assertTrue(dataNodeWrapper.logContains("Cache miss: table1.d1"));
}
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test method name is misleading. The method is named "treeTest" but it's actually testing the table model query with "debug select time,device,value from table1". Consider renaming to "tableTest" for clarity.

Copilot uses AI. Check for mistakes.
Signed-off-by: Weihao Li <18110526956@163.com>
Signed-off-by: Weihao Li <18110526956@163.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 7, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
5.4% Duplication on New Code (required ≤ 5%)

See analysis details on SonarQube Cloud

@codecov
Copy link

codecov bot commented Feb 7, 2026

Codecov Report

❌ Patch coverage is 42.64706% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.50%. Comparing base (67fda53) to head (136abea).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
.../db/protocol/thrift/impl/ClientRPCServiceImpl.java 0.00% 13 Missing ⚠️
.../apache/iotdb/db/queryengine/plan/Coordinator.java 0.00% 5 Missing ⚠️
...ngine/plan/scheduler/load/LoadTsFileScheduler.java 0.00% 4 Missing ⚠️
...ne/execution/fragment/FragmentInstanceManager.java 0.00% 3 Missing ⚠️
...eceiver/protocol/thrift/IoTDBDataNodeReceiver.java 0.00% 2 Missing ⚠️
...e/iotdb/db/queryengine/common/MPPQueryContext.java 50.00% 2 Missing ⚠️
...ne/execution/fragment/FragmentInstanceContext.java 71.42% 2 Missing ⚠️
...eceiver/protocol/legacy/loader/DeletionLoader.java 0.00% 1 Missing ⚠️
.../receiver/protocol/legacy/loader/TsFileLoader.java 0.00% 1 Missing ⚠️
...db/pipe/sink/protocol/writeback/WriteBackSink.java 0.00% 1 Missing ⚠️
... and 5 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #17178      +/-   ##
============================================
- Coverage     39.50%   39.50%   -0.01%     
  Complexity      282      282              
============================================
  Files          5101     5101              
  Lines        341767   341817      +50     
  Branches      43555    43556       +1     
============================================
+ Hits         135009   135027      +18     
- Misses       206758   206790      +32     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants