Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -834,4 +835,18 @@ public Process getInstance() {
public int[] getPortList() {
return portList;
}

public void clearLogContent() throws IOException {
Files.newOutputStream(Paths.get(getLogPath()), StandardOpenOption.TRUNCATE_EXISTING).close();
}

public boolean logContains(String content) throws IOException {
List<String> lines = Files.readAllLines(Paths.get(getLogPath()), StandardCharsets.UTF_8);
for (String line : lines) {
if (line.contains(content)) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* 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.query.recent;

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.TableLocalStandaloneIT;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.io.IOException;

import static org.apache.iotdb.db.it.utils.TestUtils.prepareData;
import static org.apache.iotdb.db.it.utils.TestUtils.prepareTableData;
import static org.apache.iotdb.db.it.utils.TestUtils.resultSetEqualTest;
import static org.apache.iotdb.db.it.utils.TestUtils.tableResultSetEqualTest;
import static org.junit.Assert.assertTrue;

@RunWith(IoTDBTestRunner.class)
@Category({TableLocalStandaloneIT.class})
public class IoTDBDebugQueryIT {
private static final String DATABASE_NAME = "test_db";
private static final String[] createTableSqls =
new String[] {
"CREATE DATABASE " + DATABASE_NAME,
"USE " + DATABASE_NAME,
"create table table1(device string tag, value int32 field)",
"insert into table1(time,device,value) values(2020-01-01 00:00:01.000,'d1',1)",
"FLUSH",
};
private static final String[] createTreeSqls =
new String[] {
"create timeseries root.test.departments.department_id TEXT",
"create timeseries root.test.departments.dep_name TEXT",
"insert into root.test.departments(time, department_id, dep_name) values(1, 'D001', '研发部')",
"FLUSH",
};
private static DataNodeWrapper dataNodeWrapper;

@BeforeClass
public static void setUp() throws Exception {
EnvFactory.getEnv().initClusterEnvironment();
dataNodeWrapper = EnvFactory.getEnv().getDataNodeWrapperList().get(0);
prepareTableData(createTableSqls);
prepareData(createTreeSqls);
}

@AfterClass
public static void tearDown() throws Exception {
EnvFactory.getEnv().cleanClusterEnvironment();
}

@Test
public void tableTest() 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"));
}

@Test
public void treeTest() 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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ private boolean registerDatabase(
partitionFetcher,
schemaFetcher,
IoTDBDescriptor.getInstance().getConfig().getQueryTimeoutThreshold(),
false,
false);
if (result.status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()
&& result.status.code != TSStatusCode.DATABASE_ALREADY_EXISTS.getStatusCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public void load() throws PipeException {
PARTITION_FETCHER,
SCHEMA_FETCHER,
IoTDBDescriptor.getInstance().getConfig().getQueryTimeoutThreshold(),
false);
false,
statement.isDebug());
if (result.status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
LOGGER.error("Delete {} error, statement: {}.", deletion, statement);
LOGGER.error("Delete result status : {}.", result.status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public void load() {
PARTITION_FETCHER,
SCHEMA_FETCHER,
IoTDBDescriptor.getInstance().getConfig().getQueryTimeoutThreshold(),
false);
false,
statement.isDebug());
if (result.status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
LOGGER.error("Load TsFile {} error, statement: {}.", tsFile.getPath(), statement);
LOGGER.error("Load TsFile result status : {}.", result.status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,8 @@ private TSStatus executeStatementForTreeModel(final Statement statement) {
ClusterPartitionFetcher.getInstance(),
ClusterSchemaFetcher.getInstance(),
IoTDBDescriptor.getInstance().getConfig().getQueryTimeoutThreshold(),
false)
false,
statement.isDebug())
.status;
}

Expand All @@ -1075,7 +1076,8 @@ private TSStatus executeStatementForTableModelWithPermissionCheck(
"",
LocalExecutionPlanner.getInstance().metadata,
IoTDBDescriptor.getInstance().getConfig().getQueryTimeoutThreshold(),
false)
false,
statement.isDebug())
.status;

// Delete data & Update device attribute is itself idempotent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@ private TSStatus executeStatementForTreeModel(final Statement statement, final S
ClusterPartitionFetcher.getInstance(),
ClusterSchemaFetcher.getInstance(),
IoTDBDescriptor.getInstance().getConfig().getQueryTimeoutThreshold(),
false)
false,
statement.isDebug())
.status;
} catch (final IoTDBRuntimeException e) {
if (e.getErrorCode() == TSStatusCode.NO_PERMISSION.getStatusCode()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ private TSExecuteStatementResp executeStatementInternal(
statement,
LocalExecutionPlanner.getInstance().metadata,
config.getQueryTimeoutThreshold(),
false);
false,
s.isDebug());
} else {
// permission check
TSStatus status =
Expand Down Expand Up @@ -406,7 +407,8 @@ private TSExecuteStatementResp executeStatementInternal(
partitionFetcher,
schemaFetcher,
request.getTimeout(),
true);
true,
s.isDebug());
}
}
} else {
Expand Down Expand Up @@ -453,7 +455,8 @@ private TSExecuteStatementResp executeStatementInternal(
statement,
metadata,
request.getTimeout(),
true);
true,
s.isDebug());
}
}

Expand Down Expand Up @@ -757,7 +760,8 @@ private TSExecuteStatementResp executeRawDataQueryInternal(
partitionFetcher,
schemaFetcher,
req.getTimeout(),
true);
true,
s.isDebug());

if (result.status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
finished = true;
Expand Down Expand Up @@ -852,7 +856,8 @@ private TSExecuteStatementResp executeLastDataQueryInternal(
partitionFetcher,
schemaFetcher,
req.getTimeout(),
true);
true,
s.isDebug());

if (result.status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
finished = true;
Expand Down Expand Up @@ -949,7 +954,8 @@ private TSExecuteStatementResp executeAggregationQueryInternal(
partitionFetcher,
schemaFetcher,
req.getTimeout(),
true);
true,
s.isDebug());

if (result.status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
finished = true;
Expand Down Expand Up @@ -1408,7 +1414,8 @@ public TSExecuteStatementResp executeFastLastDataQueryForOneDeviceV2(
partitionFetcher,
schemaFetcher,
req.getTimeout(),
true);
true,
s.isDebug());

if (result.status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
finished = true;
Expand Down Expand Up @@ -2106,7 +2113,8 @@ public TSStatus executeBatchStatement(TSExecuteBatchStatementReq req) {
statement,
LocalExecutionPlanner.getInstance().metadata,
config.getQueryTimeoutThreshold(),
false);
false,
s.isDebug());
} else {
// permission check
TSStatus status =
Expand Down Expand Up @@ -2151,7 +2159,8 @@ public TSStatus executeBatchStatement(TSExecuteBatchStatementReq req) {
partitionFetcher,
schemaFetcher,
config.getQueryTimeoutThreshold(),
false);
false,
s.isDebug());
}
}
} else {
Expand Down Expand Up @@ -2197,7 +2206,8 @@ public TSStatus executeBatchStatement(TSExecuteBatchStatementReq req) {
statement,
metadata,
config.getQueryTimeoutThreshold(),
false);
false,
s.isDebug());
}
}

Expand Down Expand Up @@ -3119,7 +3129,8 @@ private TSQueryTemplateResp executeTemplateQueryStatement(
partitionFetcher,
schemaFetcher,
config.getQueryTimeoutThreshold(),
true);
true,
statement.isDebug());

if (executionResult.status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()
&& executionResult.status.code != TSStatusCode.REDIRECTION_RECOMMEND.getStatusCode()) {
Expand Down Expand Up @@ -3529,6 +3540,7 @@ private ExecutionResult executeBatchStatement(
ExecutionResult result = null;
final List<? extends Statement> subStatements = statement.getSubStatements();
final int totalSubStatements = subStatements.size();
boolean debug = statement.isDebug();

LOGGER.info(
"Start batch executing {} sub-statement(s) in tree model, queryId: {}",
Expand All @@ -3553,7 +3565,8 @@ private ExecutionResult executeBatchStatement(
partitionFetcher,
schemaFetcher,
timeoutMs,
userQuery);
userQuery,
debug);

// Exit early if any sub-statement execution fails
if (result != null
Expand Down Expand Up @@ -3643,7 +3656,8 @@ private ExecutionResult executeBatchTableStatement(
statementStr,
metadata,
timeoutMs,
userQuery);
userQuery,
statement.isDebug());

// Exit early if any sub-statement execution fails
if (result != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,7 @@ public TSStatus executeCQ(TExecuteCQ req) {
partitionFetcher,
schemaFetcher,
req.getTimeout(),
false,
false);

if (result.status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public enum ExplainType {

private boolean userQuery = false;

private boolean debug = false;

private Map<NodeRef<Table>, Query> cteQueries = new HashMap<>();

// Stores the EXPLAIN/EXPLAIN ANALYZE results for Common Table Expressions (CTEs)
Expand Down Expand Up @@ -503,6 +505,14 @@ public void setUserQuery(boolean userQuery) {
this.userQuery = userQuery;
}

public boolean isDebug() {
return debug;
}

public void setDebug(boolean debug) {
this.debug = debug;
}

public boolean isInnerTriggeredQuery() {
return innerTriggeredQuery;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public class FakedFragmentInstanceContext extends FragmentInstanceContext {

public FakedFragmentInstanceContext(Filter timeFilter, DataRegion dataRegion) {
super(0, new FakedMemoryReservationManager(), timeFilter, dataRegion);
super(0, new FakedMemoryReservationManager(), timeFilter, dataRegion, false);
}

public QueryDataSource getSharedQueryDataSource(IFullPath sourcePath)
Expand Down
Loading
Loading