You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by lt...@apache.org on 2019/05/15 09:23:58 UTC
[incubator-iotdb] 01/01: add cluster framework and nonquery module
and query metadata module
This is an automated email from the ASF dual-hosted git repository.
lta pushed a commit to branch cluster_framework
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit cde6fac0904001bf91c5cf5a87115ebf5057376b
Author: lta <li...@163.com>
AuthorDate: Wed May 15 17:23:04 2019 +0800
add cluster framework and nonquery module and query metadata module
---
.../org/apache/iotdb/cluster/entity/Server.java | 20 -
.../qp/executor/ClusterQueryProcessExecutor.java | 35 +-
.../org/apache/iotdb/cluster/query/PathType.java | 33 --
.../org/apache/iotdb/cluster/query/QueryType.java | 37 --
.../dataset/ClusterDataSetWithTimeGenerator.java | 146 ------
.../executor/ClusterExecutorWithTimeGenerator.java | 130 -----
.../ClusterExecutorWithoutTimeGenerator.java | 102 ----
.../cluster/query/executor/ClusterQueryRouter.java | 121 -----
.../cluster/query/expression/TrueExpression.java | 43 --
.../query/factory/ClusterSeriesReaderFactory.java | 97 ----
.../coordinatornode/ClusterRpcQueryManager.java | 111 -----
.../ClusterRpcSingleQueryManager.java | 415 ----------------
.../manager/coordinatornode/FilterGroupEntity.java | 111 -----
.../coordinatornode/IClusterRpcQueryManager.java | 69 ---
.../IClusterRpcSingleQueryManager.java | 98 ----
.../querynode/ClusterLocalQueryManager.java | 125 -----
.../querynode/ClusterLocalSingleQueryManager.java | 335 -------------
.../querynode/IClusterLocalQueryManager.java | 82 ---
.../querynode/IClusterLocalSingleQueryManager.java | 74 ---
.../AbstractClusterPointReader.java | 73 ---
.../coordinatornode/ClusterFilterSeriesReader.java | 126 -----
.../coordinatornode/ClusterSelectSeriesReader.java | 167 -------
.../querynode/AbstractClusterBatchReader.java | 39 --
.../querynode/ClusterBatchReaderByTimestamp.java | 86 ----
.../ClusterBatchReaderWithoutTimeGenerator.java | 93 ----
.../querynode/ClusterFilterSeriesBatchReader.java | 120 -----
.../querynode/IClusterFilterSeriesBatchReader.java | 36 --
.../query/timegenerator/ClusterLeafNode.java | 49 --
.../timegenerator/ClusterNodeConstructor.java | 106 ----
.../query/timegenerator/ClusterTimeGenerator.java | 64 ---
.../cluster/query/utils/ClusterRpcReaderUtils.java | 129 -----
.../iotdb/cluster/query/utils/ExpressionUtils.java | 131 -----
.../query/utils/QueryPlanPartitionUtils.java | 127 -----
.../querydata/CloseSeriesReaderSyncProcessor.java | 43 --
.../querydata/InitSeriesReaderSyncProcessor.java | 63 ---
.../QuerySeriesDataByTimestampSyncProcessor.java | 38 --
.../querydata/QuerySeriesDataSyncProcessor.java | 39 --
.../querydata/CloseSeriesReaderRequest.java | 47 --
.../request/querydata/InitSeriesReaderRequest.java | 91 ----
.../QuerySeriesDataByTimestampRequest.java | 91 ----
.../request/querydata/QuerySeriesDataRequest.java | 98 ----
.../querydata/InitSeriesReaderResponse.java | 59 ---
.../QuerySeriesDataByTimestampResponse.java | 31 --
.../querydata/QuerySeriesDataResponse.java | 44 --
.../iotdb/cluster/service/ClusterMonitor.java | 113 -----
.../iotdb/cluster/service/ClusterMonitorMBean.java | 79 ---
.../cluster/service/TSServiceClusterImpl.java | 53 --
.../iotdb/cluster/service/nodetool/Host.java | 84 ----
.../apache/iotdb/cluster/service/nodetool/Lag.java | 42 --
.../iotdb/cluster/service/nodetool/NodeTool.java | 147 ------
.../iotdb/cluster/service/nodetool/Query.java | 37 --
.../iotdb/cluster/service/nodetool/Ring.java | 38 --
.../cluster/service/nodetool/StorageGroup.java | 38 --
.../org/apache/iotdb/cluster/utils/RaftUtils.java | 10 -
.../cluster/query/ClusterQueryLargeDataTest.java | 507 -------------------
.../iotdb/cluster/query/ClusterQueryTest.java | 550 ---------------------
.../query/manager/ClusterLocalManagerTest.java | 406 ---------------
.../query/manager/ClusterRpcManagerTest.java | 334 -------------
.../cluster/query/utils/ExpressionUtilsTest.java | 230 ---------
.../query/utils/QueryPlanPartitionUtilsTest.java | 332 -------------
60 files changed, 4 insertions(+), 7170 deletions(-)
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/entity/Server.java b/cluster/src/main/java/org/apache/iotdb/cluster/entity/Server.java
index 842d2ed..1d1d7e5 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/entity/Server.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/entity/Server.java
@@ -35,10 +35,6 @@ import org.apache.iotdb.cluster.rpc.raft.impl.RaftNodeAsClientManager;
import org.apache.iotdb.cluster.rpc.raft.processor.QueryMetricAsyncProcessor;
import org.apache.iotdb.cluster.rpc.raft.processor.nonquery.DataGroupNonQueryAsyncProcessor;
import org.apache.iotdb.cluster.rpc.raft.processor.nonquery.MetaGroupNonQueryAsyncProcessor;
-import org.apache.iotdb.cluster.rpc.raft.processor.querydata.CloseSeriesReaderSyncProcessor;
-import org.apache.iotdb.cluster.rpc.raft.processor.querydata.InitSeriesReaderSyncProcessor;
-import org.apache.iotdb.cluster.rpc.raft.processor.querydata.QuerySeriesDataByTimestampSyncProcessor;
-import org.apache.iotdb.cluster.rpc.raft.processor.querydata.QuerySeriesDataSyncProcessor;
import org.apache.iotdb.cluster.rpc.raft.processor.querymetadata.QueryMetadataAsyncProcessor;
import org.apache.iotdb.cluster.rpc.raft.processor.querymetadata.QueryMetadataInStringAsyncProcessor;
import org.apache.iotdb.cluster.rpc.raft.processor.querymetadata.QueryPathsAsyncProcessor;
@@ -47,11 +43,9 @@ import org.apache.iotdb.cluster.rpc.raft.processor.querymetadata.QueryTimeSeries
import org.apache.iotdb.cluster.utils.RaftUtils;
import org.apache.iotdb.cluster.utils.hash.PhysicalNode;
import org.apache.iotdb.cluster.utils.hash.Router;
-import org.apache.iotdb.db.exception.StartupException;
import org.apache.iotdb.db.exception.ProcessorException;
import org.apache.iotdb.db.service.IoTDB;
import org.apache.iotdb.db.service.RegisterManager;
-import org.apache.iotdb.cluster.service.ClusterMonitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -108,7 +102,6 @@ public class Server {
registerNonQueryProcessor(rpcServer);
registerQueryMetadataProcessor(rpcServer);
- registerQueryDataProcessor(rpcServer);
registerQueryMetricProcessor(rpcServer);
metadataHolder = new MetadataRaftHolder(peerIds, serverId, rpcServer, true);
@@ -133,12 +126,6 @@ public class Server {
Router.getInstance().showPhysicalNodes(groupId);
}
- try {
- LOGGER.info("Register Cluster Monitor to JMX service.");
- registerManager.register(ClusterMonitor.INSTANCE);
- } catch (StartupException e) {
- stop();
- }
}
private void registerNonQueryProcessor(RpcServer rpcServer) {
@@ -154,13 +141,6 @@ public class Server {
rpcServer.registerUserProcessor(new QueryPathsAsyncProcessor());
}
- private void registerQueryDataProcessor(RpcServer rpcServer) {
- rpcServer.registerUserProcessor(new InitSeriesReaderSyncProcessor());
- rpcServer.registerUserProcessor(new QuerySeriesDataSyncProcessor());
- rpcServer.registerUserProcessor(new QuerySeriesDataByTimestampSyncProcessor());
- rpcServer.registerUserProcessor(new CloseSeriesReaderSyncProcessor());
- }
-
private void registerQueryMetricProcessor(RpcServer rpcServer) {
rpcServer.registerUserProcessor(new QueryMetricAsyncProcessor());
}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/qp/executor/ClusterQueryProcessExecutor.java b/cluster/src/main/java/org/apache/iotdb/cluster/qp/executor/ClusterQueryProcessExecutor.java
index 3dc8c43..8f5c513 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/qp/executor/ClusterQueryProcessExecutor.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/qp/executor/ClusterQueryProcessExecutor.java
@@ -21,16 +21,12 @@ package org.apache.iotdb.cluster.qp.executor;
import java.io.IOException;
import java.util.List;
import java.util.Map;
-import org.apache.iotdb.cluster.query.executor.ClusterQueryRouter;
import org.apache.iotdb.db.exception.FileNodeManagerException;
import org.apache.iotdb.db.exception.PathErrorException;
import org.apache.iotdb.db.exception.ProcessorException;
import org.apache.iotdb.db.qp.constant.SQLConstant;
import org.apache.iotdb.db.qp.executor.IQueryProcessExecutor;
import org.apache.iotdb.db.qp.physical.PhysicalPlan;
-import org.apache.iotdb.db.qp.physical.crud.AggregationPlan;
-import org.apache.iotdb.db.qp.physical.crud.FillQueryPlan;
-import org.apache.iotdb.db.qp.physical.crud.GroupByPlan;
import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
import org.apache.iotdb.db.query.context.QueryContext;
import org.apache.iotdb.db.query.fill.IFill;
@@ -38,14 +34,12 @@ import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.read.common.Path;
import org.apache.iotdb.tsfile.read.expression.IExpression;
-import org.apache.iotdb.tsfile.read.expression.QueryExpression;
import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
import org.apache.iotdb.tsfile.utils.Pair;
public class ClusterQueryProcessExecutor extends AbstractQPExecutor implements IQueryProcessExecutor {
private ThreadLocal<Integer> fetchSize = new ThreadLocal<>();
- private ClusterQueryRouter clusterQueryRouter = new ClusterQueryRouter();
private QueryMetadataExecutor queryMetadataExecutor = new QueryMetadataExecutor();
@@ -53,49 +47,28 @@ public class ClusterQueryProcessExecutor extends AbstractQPExecutor implements I
public QueryDataSet processQuery(QueryPlan queryPlan, QueryContext context)
throws IOException, FileNodeManagerException, PathErrorException,
QueryFilterOptimizationException, ProcessorException {
-
- QueryExpression queryExpression = QueryExpression.create().setSelectSeries(queryPlan.getPaths())
- .setExpression(queryPlan.getExpression());
- clusterQueryRouter.setReadDataConsistencyLevel(getReadDataConsistencyLevel());
- if (queryPlan instanceof GroupByPlan) {
- GroupByPlan groupByPlan = (GroupByPlan) queryPlan;
- return groupBy(groupByPlan.getPaths(), groupByPlan.getAggregations(),
- groupByPlan.getExpression(), groupByPlan.getUnit(), groupByPlan.getOrigin(),
- groupByPlan.getIntervals(), context);
- }
-
- if (queryPlan instanceof AggregationPlan) {
- return aggregate(queryPlan.getPaths(), queryPlan.getAggregations(),
- queryPlan.getExpression(), context);
- }
-
- if (queryPlan instanceof FillQueryPlan) {
- FillQueryPlan fillQueryPlan = (FillQueryPlan) queryPlan;
- return fill(queryPlan.getPaths(), fillQueryPlan.getQueryTime(),
- fillQueryPlan.getFillType(), context);
- }
- return clusterQueryRouter.query(queryExpression, context);
+ return null;
}
@Override
public QueryDataSet aggregate(List<Path> paths, List<String> aggres, IExpression expression,
QueryContext context)
throws ProcessorException, IOException, PathErrorException, FileNodeManagerException, QueryFilterOptimizationException {
- return clusterQueryRouter.aggregate(paths, aggres, expression, context);
+ return null;
}
@Override
public QueryDataSet groupBy(List<Path> paths, List<String> aggres, IExpression expression,
long unit, long origin, List<Pair<Long, Long>> intervals, QueryContext context)
throws ProcessorException, IOException, PathErrorException, FileNodeManagerException, QueryFilterOptimizationException {
- return clusterQueryRouter.groupBy(paths, aggres, expression, unit, origin, intervals, context);
+ return null;
}
@Override
public QueryDataSet fill(List<Path> fillPaths, long queryTime, Map<TSDataType, IFill> fillTypes,
QueryContext context)
throws ProcessorException, IOException, PathErrorException, FileNodeManagerException {
- return clusterQueryRouter.fill(fillPaths, queryTime, fillTypes, context);
+ return null;
}
@Override
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/PathType.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/PathType.java
deleted file mode 100644
index 78c54f7..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/PathType.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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.cluster.query;
-
-/**
- * Type of path
- */
-public enum PathType {
- /**
- * Select paths in a query
- */
- SELECT_PATH,
- /**
- * Filter paths in a query
- */
- FILTER_PATH
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/QueryType.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/QueryType.java
deleted file mode 100644
index 5bf8c53..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/QueryType.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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.cluster.query;
-
-/**
- * Type of query
- */
-public enum QueryType {
- /**
- * Query with no filter
- */
- NO_FILTER,
- /**
- * Query with global time
- */
- GLOBAL_TIME,
- /**
- * Query with value filter
- */
- FILTER
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/dataset/ClusterDataSetWithTimeGenerator.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/dataset/ClusterDataSetWithTimeGenerator.java
deleted file mode 100644
index 5a06ca8..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/dataset/ClusterDataSetWithTimeGenerator.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/**
- * 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.cluster.query.dataset;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import org.apache.iotdb.cluster.config.ClusterConfig;
-import org.apache.iotdb.cluster.config.ClusterDescriptor;
-import org.apache.iotdb.cluster.exception.RaftConnectionException;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcSingleQueryManager;
-import org.apache.iotdb.cluster.query.timegenerator.ClusterTimeGenerator;
-import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.common.Field;
-import org.apache.iotdb.tsfile.read.common.Path;
-import org.apache.iotdb.tsfile.read.common.RowRecord;
-import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
-
-/**
- * Dataset with time generator for cluster
- */
-public class ClusterDataSetWithTimeGenerator extends QueryDataSet {
-
- private ClusterRpcSingleQueryManager queryManager;
-
- private ClusterTimeGenerator timeGenerator;
-
- private EngineReaderByTimeStamp[] readers;
-
- private static final ClusterConfig CLUSTER_CONF = ClusterDescriptor.getInstance().getConfig();
-
- /**
- * Cached batch timestamp
- */
- private Iterator<Long> cachedBatchTimestamp;
-
- private boolean hasCachedRowRecord;
-
- private RowRecord cachedRowRecord;
-
- /**
- * constructor of EngineDataSetWithTimeGenerator.
- *
- * @param paths paths in List structure
- * @param dataTypes time series data type
- * @param timeGenerator EngineTimeGenerator object
- * @param readers readers in List(EngineReaderByTimeStamp) structure
- */
- public ClusterDataSetWithTimeGenerator(List<Path> paths, List<TSDataType> dataTypes,
- ClusterTimeGenerator timeGenerator, EngineReaderByTimeStamp[] readers,
- ClusterRpcSingleQueryManager queryManager) {
- super(paths, dataTypes);
- this.timeGenerator = timeGenerator;
- this.readers = readers;
- this.queryManager = queryManager;
- }
-
- @Override
- public boolean hasNext() throws IOException {
- if (hasCachedRowRecord) {
- return true;
- }
- return cacheRowRecord();
- }
-
- @Override
- public RowRecord next() throws IOException {
- if (!hasCachedRowRecord && !cacheRowRecord()) {
- return null;
- }
- hasCachedRowRecord = false;
- return cachedRowRecord;
- }
-
- /**
- * Cache row record
- *
- * @return if there has next row record.
- */
- private boolean cacheRowRecord() throws IOException {
- while (hasNextTimestamp()) {
- boolean hasField = false;
- long timestamp = cachedBatchTimestamp.next();
- RowRecord rowRecord = new RowRecord(timestamp);
- for (int i = 0; i < readers.length; i++) {
- EngineReaderByTimeStamp reader = readers[i];
- Object value = reader.getValueInTimestamp(timestamp);
- if (value == null) {
- rowRecord.addField(new Field(null));
- } else {
- hasField = true;
- rowRecord.addField(getField(value, dataTypes.get(i)));
- }
- }
- if (hasField) {
- hasCachedRowRecord = true;
- cachedRowRecord = rowRecord;
- break;
- }
- }
- return hasCachedRowRecord;
- }
-
- /**
- * Check if it has next valid timestamp
- */
- private boolean hasNextTimestamp() throws IOException {
- if (cachedBatchTimestamp == null || !cachedBatchTimestamp.hasNext()) {
- List<Long> batchTimestamp = new ArrayList<>();
- for (int i = 0; i < CLUSTER_CONF.getBatchReadSize(); i++) {
- if (timeGenerator.hasNext()) {
- batchTimestamp.add(timeGenerator.next());
- } else {
- break;
- }
- }
- if (!batchTimestamp.isEmpty()) {
- cachedBatchTimestamp = batchTimestamp.iterator();
- try {
- queryManager.fetchBatchDataByTimestampForAllSelectPaths(batchTimestamp);
- } catch (RaftConnectionException e) {
- throw new IOException(e);
- }
- }
- }
- return cachedBatchTimestamp != null && cachedBatchTimestamp.hasNext();
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/executor/ClusterExecutorWithTimeGenerator.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/executor/ClusterExecutorWithTimeGenerator.java
deleted file mode 100644
index fed8c0d..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/executor/ClusterExecutorWithTimeGenerator.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/**
- * 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.cluster.query.executor;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.apache.iotdb.cluster.query.dataset.ClusterDataSetWithTimeGenerator;
-import org.apache.iotdb.cluster.query.factory.ClusterSeriesReaderFactory;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcSingleQueryManager;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.FilterGroupEntity;
-import org.apache.iotdb.cluster.query.reader.coordinatornode.ClusterSelectSeriesReader;
-import org.apache.iotdb.cluster.query.timegenerator.ClusterTimeGenerator;
-import org.apache.iotdb.db.exception.FileNodeManagerException;
-import org.apache.iotdb.db.exception.PathErrorException;
-import org.apache.iotdb.db.metadata.MManager;
-import org.apache.iotdb.db.query.context.QueryContext;
-import org.apache.iotdb.db.query.control.QueryResourceManager;
-import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.common.Path;
-import org.apache.iotdb.tsfile.read.expression.QueryExpression;
-import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
-
-public class ClusterExecutorWithTimeGenerator {
-
- /**
- * query expression
- */
- private QueryExpression queryExpression;
-
- /**
- * Manger for all remote query series reader resource in the query
- */
- private ClusterRpcSingleQueryManager queryManager;
-
- /**
- * Constructor of ClusterExecutorWithTimeGenerator
- */
- public ClusterExecutorWithTimeGenerator(QueryExpression queryExpression,
- ClusterRpcSingleQueryManager queryManager) {
- this.queryExpression = queryExpression;
- this.queryManager = queryManager;
- }
-
- /**
- * Execute query with value filter.
- *
- * @return QueryDataSet object
- */
- public QueryDataSet execute(QueryContext context) throws FileNodeManagerException {
-
- /** add query token for query series which can handle locally **/
- List<Path> localQuerySeries = new ArrayList<>(queryExpression.getSelectedSeries());
- Set<Path> remoteQuerySeries = queryManager.getSelectSeriesReaders().keySet();
- localQuerySeries.removeAll(remoteQuerySeries);
- QueryResourceManager.getInstance()
- .beginQueryOfGivenQueryPaths(context.getJobId(), localQuerySeries);
-
- /** add query token for filter series which can handle locally **/
- Set<String> deviceIdSet = new HashSet<>();
- for (FilterGroupEntity filterGroupEntity : queryManager.getFilterGroupEntityMap().values()) {
- List<Path> remoteFilterSeries = filterGroupEntity.getFilterPaths();
- remoteFilterSeries.forEach(seriesPath -> deviceIdSet.add(seriesPath.getDevice()));
- }
- QueryResourceManager.getInstance()
- .beginQueryOfGivenExpression(context.getJobId(), queryExpression.getExpression(),
- deviceIdSet);
-
- ClusterTimeGenerator timestampGenerator;
- List<EngineReaderByTimeStamp> readersOfSelectedSeries;
- try {
- timestampGenerator = new ClusterTimeGenerator(queryExpression.getExpression(), context,
- queryManager);
- readersOfSelectedSeries = ClusterSeriesReaderFactory
- .createReadersByTimestampOfSelectedPaths(queryExpression.getSelectedSeries(), context,
- queryManager);
- } catch (IOException ex) {
- throw new FileNodeManagerException(ex);
- }
-
- /** Get data type of select paths **/
- List<TSDataType> dataTypes = new ArrayList<>();
- Map<Path, ClusterSelectSeriesReader> selectSeriesReaders = queryManager
- .getSelectSeriesReaders();
- for (Path path : queryExpression.getSelectedSeries()) {
- try {
- if (selectSeriesReaders.containsKey(path)) {
- dataTypes.add(selectSeriesReaders.get(path).getDataType());
- } else {
- dataTypes.add(MManager.getInstance().getSeriesType(path.getFullPath()));
- }
- } catch (PathErrorException e) {
- throw new FileNodeManagerException(e);
- }
-
- }
-
- EngineReaderByTimeStamp[] readersOfSelectedSeriesArray = new EngineReaderByTimeStamp[readersOfSelectedSeries
- .size()];
- int index = 0;
- for (EngineReaderByTimeStamp reader : readersOfSelectedSeries) {
- readersOfSelectedSeriesArray[index] = reader;
- index++;
- }
-
- return new ClusterDataSetWithTimeGenerator(queryExpression.getSelectedSeries(), dataTypes,
- timestampGenerator,
- readersOfSelectedSeriesArray, queryManager);
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/executor/ClusterExecutorWithoutTimeGenerator.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/executor/ClusterExecutorWithoutTimeGenerator.java
deleted file mode 100644
index 8f42c9f..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/executor/ClusterExecutorWithoutTimeGenerator.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * 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.cluster.query.executor;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcSingleQueryManager;
-import org.apache.iotdb.cluster.query.reader.coordinatornode.ClusterSelectSeriesReader;
-import org.apache.iotdb.db.exception.FileNodeManagerException;
-import org.apache.iotdb.db.query.context.QueryContext;
-import org.apache.iotdb.db.query.control.QueryResourceManager;
-import org.apache.iotdb.db.query.dataset.EngineDataSetWithoutTimeGenerator;
-import org.apache.iotdb.db.query.executor.AbstractExecutorWithoutTimeGenerator;
-import org.apache.iotdb.db.query.reader.IPointReader;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.common.Path;
-import org.apache.iotdb.tsfile.read.expression.QueryExpression;
-import org.apache.iotdb.tsfile.read.expression.impl.GlobalTimeExpression;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
-
-public class ClusterExecutorWithoutTimeGenerator extends AbstractExecutorWithoutTimeGenerator {
-
- /**
- * Query expression
- */
- private QueryExpression queryExpression;
-
- /**
- * Manger for all remote query series reader resource in the query
- */
- private ClusterRpcSingleQueryManager queryManager;
-
- /**
- * Constructor of ClusterExecutorWithoutTimeGenerator
- */
- public ClusterExecutorWithoutTimeGenerator(QueryExpression queryExpression,
- ClusterRpcSingleQueryManager queryManager) {
- this.queryExpression = queryExpression;
- this.queryManager = queryManager;
- }
-
- /**
- * Execute query without filter or with only global time filter.
- */
- public QueryDataSet execute(QueryContext context)
- throws FileNodeManagerException {
-
- Filter timeFilter = null;
- if (queryExpression.getExpression() != null) {
- timeFilter = ((GlobalTimeExpression) queryExpression.getExpression()).getFilter();
- }
-
- List<IPointReader> readersOfSelectedSeries = new ArrayList<>();
- List<TSDataType> dataTypes = new ArrayList<>();
-
- Map<Path, ClusterSelectSeriesReader> selectPathReaders = queryManager.getSelectSeriesReaders();
- List<Path> paths = new ArrayList<>();
- for (Path path : queryExpression.getSelectedSeries()) {
-
- if (selectPathReaders.containsKey(path)) {
- ClusterSelectSeriesReader reader = selectPathReaders.get(path);
- readersOfSelectedSeries.add(reader);
- dataTypes.add(reader.getDataType());
-
- } else {
- IPointReader reader = createSeriesReader(context, path, dataTypes, timeFilter);
- readersOfSelectedSeries.add(reader);
- paths.add(path);
- }
- }
-
- QueryResourceManager.getInstance()
- .beginQueryOfGivenQueryPaths(context.getJobId(), paths);
-
- try {
- return new EngineDataSetWithoutTimeGenerator(queryExpression.getSelectedSeries(), dataTypes,
- readersOfSelectedSeries);
- } catch (IOException e) {
- throw new FileNodeManagerException(e);
- }
- }
-
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/executor/ClusterQueryRouter.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/executor/ClusterQueryRouter.java
deleted file mode 100644
index 4211528..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/executor/ClusterQueryRouter.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/**
- * 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.cluster.query.executor;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import org.apache.iotdb.cluster.exception.RaftConnectionException;
-import org.apache.iotdb.cluster.query.QueryType;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcQueryManager;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcSingleQueryManager;
-import org.apache.iotdb.db.exception.FileNodeManagerException;
-import org.apache.iotdb.db.exception.PathErrorException;
-import org.apache.iotdb.db.exception.ProcessorException;
-import org.apache.iotdb.db.query.context.QueryContext;
-import org.apache.iotdb.db.query.executor.IEngineQueryRouter;
-import org.apache.iotdb.db.query.fill.IFill;
-import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.common.Path;
-import org.apache.iotdb.tsfile.read.expression.ExpressionType;
-import org.apache.iotdb.tsfile.read.expression.IExpression;
-import org.apache.iotdb.tsfile.read.expression.QueryExpression;
-import org.apache.iotdb.tsfile.read.expression.util.ExpressionOptimizer;
-import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
-import org.apache.iotdb.tsfile.utils.Pair;
-
-/**
- * Query entrance class of cluster query process. All query clause will be transformed to physical
- * plan, physical plan will be executed by ClusterQueryRouter.
- */
-public class ClusterQueryRouter implements IEngineQueryRouter {
-
- /**
- * Consistency level of reading data
- */
- private ThreadLocal<Integer> readDataConsistencyLevel = new ThreadLocal<>();
-
- @Override
- public QueryDataSet query(QueryExpression queryExpression, QueryContext context)
- throws FileNodeManagerException, PathErrorException {
-
- ClusterRpcSingleQueryManager queryManager = ClusterRpcQueryManager.getInstance()
- .getSingleQuery(context.getJobId());
- try {
- if (queryExpression.hasQueryFilter()) {
-
- IExpression optimizedExpression = ExpressionOptimizer.getInstance()
- .optimize(queryExpression.getExpression(), queryExpression.getSelectedSeries());
- queryExpression.setExpression(optimizedExpression);
- // update query expression of origin query plan, it's necessary.
- queryManager.getOriginQueryPlan().setExpression(optimizedExpression);
-
- if (optimizedExpression.getType() == ExpressionType.GLOBAL_TIME) {
- queryManager.initQueryResource(QueryType.GLOBAL_TIME, getReadDataConsistencyLevel());
- ClusterExecutorWithoutTimeGenerator engineExecutor =
- new ClusterExecutorWithoutTimeGenerator(queryExpression, queryManager);
- return engineExecutor.execute(context);
- } else {
- queryManager.initQueryResource(QueryType.FILTER, getReadDataConsistencyLevel());
- ClusterExecutorWithTimeGenerator engineExecutor = new ClusterExecutorWithTimeGenerator(
- queryExpression, queryManager);
- return engineExecutor.execute(context);
- }
-
- } else {
- queryManager.initQueryResource(QueryType.NO_FILTER, getReadDataConsistencyLevel());
- ClusterExecutorWithoutTimeGenerator engineExecutor =
- new ClusterExecutorWithoutTimeGenerator(queryExpression, queryManager);
- return engineExecutor.execute(context);
- }
- } catch (QueryFilterOptimizationException | IOException | RaftConnectionException e) {
- throw new FileNodeManagerException(e);
- }
- }
-
- @Override
- public QueryDataSet aggregate(List<Path> selectedSeries, List<String> aggres,
- IExpression expression, QueryContext context)
- throws QueryFilterOptimizationException, FileNodeManagerException, IOException, PathErrorException, ProcessorException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public QueryDataSet groupBy(List<Path> selectedSeries, List<String> aggres,
- IExpression expression, long unit, long origin, List<Pair<Long, Long>> intervals,
- QueryContext context)
- throws ProcessorException, QueryFilterOptimizationException, FileNodeManagerException, PathErrorException, IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public QueryDataSet fill(List<Path> fillPaths, long queryTime, Map<TSDataType, IFill> fillType,
- QueryContext context) throws FileNodeManagerException, PathErrorException, IOException {
- throw new UnsupportedOperationException();
- }
-
- public int getReadDataConsistencyLevel() {
- return readDataConsistencyLevel.get();
- }
-
- public void setReadDataConsistencyLevel(int readDataConsistencyLevel) {
- this.readDataConsistencyLevel.set(readDataConsistencyLevel);
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/expression/TrueExpression.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/expression/TrueExpression.java
deleted file mode 100644
index d62c885..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/expression/TrueExpression.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * 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.cluster.query.expression;
-
-import org.apache.iotdb.tsfile.read.expression.ExpressionType;
-import org.apache.iotdb.tsfile.read.expression.IExpression;
-
-/**
- * This type of Expression is used in pruning filter tree while handling query with value filter
- */
-public class TrueExpression implements IExpression {
-
- @Override
- public ExpressionType getType() {
- return ExpressionType.TRUE;
- }
-
- @Override
- public IExpression clone() {
- return new TrueExpression();
- }
-
- @Override
- public String toString() {
- return "TrueExpression{}";
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/factory/ClusterSeriesReaderFactory.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/factory/ClusterSeriesReaderFactory.java
deleted file mode 100644
index d65ed58..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/factory/ClusterSeriesReaderFactory.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- * 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.cluster.query.factory;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcSingleQueryManager;
-import org.apache.iotdb.cluster.query.reader.coordinatornode.ClusterSelectSeriesReader;
-import org.apache.iotdb.db.engine.querycontext.QueryDataSource;
-import org.apache.iotdb.db.exception.FileNodeManagerException;
-import org.apache.iotdb.db.query.context.QueryContext;
-import org.apache.iotdb.db.query.control.QueryResourceManager;
-import org.apache.iotdb.db.query.factory.SeriesReaderFactory;
-import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
-import org.apache.iotdb.db.query.reader.merge.PriorityMergeReaderByTimestamp;
-import org.apache.iotdb.db.query.reader.sequence.SequenceDataReaderByTimestamp;
-import org.apache.iotdb.tsfile.read.common.Path;
-
-/**
- * Reader factory for cluster
- */
-public class ClusterSeriesReaderFactory {
-
- private ClusterSeriesReaderFactory() {
- }
-
- /**
- * Construct ReaderByTimestamp , include sequential data and unsequential data.
- *
- * @param paths selected series path
- * @param context query context
- * @return the list of EngineReaderByTimeStamp
- */
- public static List<EngineReaderByTimeStamp> createReadersByTimestampOfSelectedPaths(
- List<Path> paths, QueryContext context, ClusterRpcSingleQueryManager queryManager)
- throws IOException, FileNodeManagerException {
-
- Map<Path, ClusterSelectSeriesReader> selectSeriesReaders = queryManager.getSelectSeriesReaders();
- List<EngineReaderByTimeStamp> readersOfSelectedSeries = new ArrayList<>();
-
- for (Path path : paths) {
-
- if (selectSeriesReaders.containsKey(path)) {
- readersOfSelectedSeries.add(selectSeriesReaders.get(path));
- } else {
- /** can handle series query locally **/
- EngineReaderByTimeStamp readerByTimeStamp = createReaderByTimeStamp(path, context);
- readersOfSelectedSeries.add(readerByTimeStamp);
- }
- }
- return readersOfSelectedSeries;
- }
-
- /**
- * Create single ReaderByTimestamp
- *
- * @param path series path
- * @param context query context
- */
- public static EngineReaderByTimeStamp createReaderByTimeStamp(Path path, QueryContext context)
- throws IOException, FileNodeManagerException {
- QueryDataSource queryDataSource = QueryResourceManager.getInstance()
- .getQueryDataSource(path,
- context);
-
- PriorityMergeReaderByTimestamp mergeReaderByTimestamp = new PriorityMergeReaderByTimestamp();
-
- // reader for sequence data
- SequenceDataReaderByTimestamp tsFilesReader = new SequenceDataReaderByTimestamp(
- queryDataSource.getSeqDataSource(), context);
- mergeReaderByTimestamp.addReaderWithPriority(tsFilesReader, 1);
-
- // reader for unSequence data
- PriorityMergeReaderByTimestamp unSeqMergeReader = SeriesReaderFactory.getInstance()
- .createUnSeqMergeReaderByTimestamp(queryDataSource.getOverflowSeriesDataSource());
- mergeReaderByTimestamp.addReaderWithPriority(unSeqMergeReader, 2);
- return mergeReaderByTimestamp;
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/coordinatornode/ClusterRpcQueryManager.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/coordinatornode/ClusterRpcQueryManager.java
deleted file mode 100644
index 6653601..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/coordinatornode/ClusterRpcQueryManager.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * 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.cluster.query.manager.coordinatornode;
-
-import com.alipay.sofa.jraft.util.OnlyForTest;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import org.apache.iotdb.cluster.config.ClusterConfig;
-import org.apache.iotdb.cluster.config.ClusterDescriptor;
-import org.apache.iotdb.cluster.exception.RaftConnectionException;
-import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
-
-public class ClusterRpcQueryManager implements IClusterRpcQueryManager {
-
- /**
- * Key is job id, value is task id.
- */
- private static final ConcurrentHashMap<Long, String> JOB_ID_MAP_TASK_ID = new ConcurrentHashMap<>();
-
- /**
- * Key is task id, value is manager of a client query.
- */
- private static final ConcurrentHashMap<String, ClusterRpcSingleQueryManager> SINGLE_QUERY_MANAGER_MAP = new ConcurrentHashMap<>();
-
- private static final ClusterConfig CLUSTER_CONFIG = ClusterDescriptor.getInstance().getConfig();
-
- /**
- * Local address
- */
- private static final String LOCAL_ADDR = String
- .format("%s:%d", CLUSTER_CONFIG.getIp(), CLUSTER_CONFIG.getPort());
-
- @Override
- public void addSingleQuery(long jobId, QueryPlan physicalPlan) {
- String taskId = createTaskId(jobId);
- JOB_ID_MAP_TASK_ID.put(jobId, taskId);
- SINGLE_QUERY_MANAGER_MAP.put(taskId, new ClusterRpcSingleQueryManager(taskId, physicalPlan));
- }
-
- @Override
- public String createTaskId(long jobId) {
- return String.format("%s:%d", LOCAL_ADDR, jobId);
- }
-
- @Override
- public ClusterRpcSingleQueryManager getSingleQuery(long jobId) {
- return SINGLE_QUERY_MANAGER_MAP.get(JOB_ID_MAP_TASK_ID.get(jobId));
- }
-
- @Override
- public ClusterRpcSingleQueryManager getSingleQuery(String taskId) {
- return SINGLE_QUERY_MANAGER_MAP.get(taskId);
- }
-
- @Override
- public void releaseQueryResource(long jobId) throws RaftConnectionException {
- if (JOB_ID_MAP_TASK_ID.containsKey(jobId)) {
- SINGLE_QUERY_MANAGER_MAP.remove(JOB_ID_MAP_TASK_ID.remove(jobId)).releaseQueryResource();
- }
- }
-
- @Override
- public Map<String, Integer> getAllReadUsage() {
- Map<String, Integer> readerUsageMap = new HashMap<>();
- SINGLE_QUERY_MANAGER_MAP.values().forEach(singleQueryManager -> {
- for (String groupId : singleQueryManager.getDataGroupUsage()) {
- readerUsageMap.put(groupId, readerUsageMap.getOrDefault(groupId, 0) + 1);
- }
- });
- return readerUsageMap;
- }
-
- @OnlyForTest
- public static ConcurrentHashMap<Long, String> getJobIdMapTaskId() {
- return JOB_ID_MAP_TASK_ID;
- }
-
- private ClusterRpcQueryManager() {
- }
-
- public static final ClusterRpcQueryManager getInstance() {
- return ClusterRpcQueryManagerHolder.INSTANCE;
- }
-
- private static class ClusterRpcQueryManagerHolder {
-
- private static final ClusterRpcQueryManager INSTANCE = new ClusterRpcQueryManager();
-
- private ClusterRpcQueryManagerHolder() {
-
- }
- }
-
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/coordinatornode/ClusterRpcSingleQueryManager.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/coordinatornode/ClusterRpcSingleQueryManager.java
deleted file mode 100644
index faeda22..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/coordinatornode/ClusterRpcSingleQueryManager.java
+++ /dev/null
@@ -1,415 +0,0 @@
-/**
- * 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.cluster.query.manager.coordinatornode;
-
-import com.alipay.sofa.jraft.entity.PeerId;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import org.apache.iotdb.cluster.config.ClusterConfig;
-import org.apache.iotdb.cluster.config.ClusterDescriptor;
-import org.apache.iotdb.cluster.exception.RaftConnectionException;
-import org.apache.iotdb.cluster.query.PathType;
-import org.apache.iotdb.cluster.query.QueryType;
-import org.apache.iotdb.cluster.query.reader.coordinatornode.ClusterFilterSeriesReader;
-import org.apache.iotdb.cluster.query.reader.coordinatornode.ClusterSelectSeriesReader;
-import org.apache.iotdb.cluster.query.utils.ClusterRpcReaderUtils;
-import org.apache.iotdb.cluster.query.utils.QueryPlanPartitionUtils;
-import org.apache.iotdb.cluster.rpc.raft.response.BasicQueryDataResponse;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.InitSeriesReaderResponse;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.QuerySeriesDataByTimestampResponse;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.QuerySeriesDataResponse;
-import org.apache.iotdb.cluster.utils.QPExecutorUtils;
-import org.apache.iotdb.cluster.utils.RaftUtils;
-import org.apache.iotdb.db.exception.PathErrorException;
-import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.common.BatchData;
-import org.apache.iotdb.tsfile.read.common.Path;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-
-/**
- * Manage all remote series reader resource in a query resource in coordinator node.
- */
-public class ClusterRpcSingleQueryManager implements IClusterRpcSingleQueryManager {
-
- /**
- * Statistic all usage of local data group.
- */
- private Set<String> dataGroupUsage = new HashSet<>();
-
- /**
- * Query job id assigned by ClusterRpcQueryManager
- */
- private String taskId;
-
- /**
- * Represents the number of query rounds
- */
- private long queryRounds = 0;
-
- /**
- * Origin query plan parsed by QueryProcessor
- */
- private QueryPlan originQueryPlan;
-
- /**
- * Represent selected reader nodes, key is group id and value is selected peer id
- */
- private Map<String, PeerId> queryNodes = new HashMap<>();
-
- // select path resource
- /**
- * Query plans of select paths which are divided from queryPlan group by group id, it contains all
- * group id ,including local data group if it involves.
- */
- private Map<String, QueryPlan> selectPathPlans = new HashMap<>();
-
- /**
- * Key is group id (only contains remote group id), value is all select series in group id.
- */
- private Map<String, List<Path>> selectSeriesByGroupId = new HashMap<>();
-
- /**
- * Series reader of select paths (only contains remote series), key is series path , value is
- * reader
- */
- private Map<Path, ClusterSelectSeriesReader> selectSeriesReaders = new HashMap<>();
-
- // filter path resource
- /**
- * Filter group entity group by data group, key is group id(only contain remote group id)
- */
- private Map<String, FilterGroupEntity> filterGroupEntityMap = new HashMap<>();
-
- private static final ClusterConfig CLUSTER_CONF = ClusterDescriptor.getInstance().getConfig();
-
- public ClusterRpcSingleQueryManager(String taskId,
- QueryPlan queryPlan) {
- this.taskId = taskId;
- this.originQueryPlan = queryPlan;
- }
-
- @Override
- public void initQueryResource(QueryType queryType, int readDataConsistencyLevel)
- throws PathErrorException, IOException, RaftConnectionException {
- switch (queryType) {
- case NO_FILTER:
- case GLOBAL_TIME:
- QueryPlanPartitionUtils.splitQueryPlanWithoutValueFilter(this);
- break;
- case FILTER:
- QueryPlanPartitionUtils.splitQueryPlanWithValueFilter(this);
- break;
- default:
- throw new UnsupportedOperationException();
- }
- initSeriesReader(readDataConsistencyLevel);
- }
-
- /**
- * Init series reader, complete all initialization with all remote query node of a specific data
- * group
- */
- private void initSeriesReader(int readDataConsistencyLevel)
- throws RaftConnectionException {
- // Init all series with data group of select series,if filter series has the same data group, init them together.
- for (Entry<String, QueryPlan> entry : selectPathPlans.entrySet()) {
- String groupId = entry.getKey();
- QueryPlan queryPlan = entry.getValue();
- if (!QPExecutorUtils.canHandleQueryByGroupId(groupId)) {
- PeerId randomPeer = RaftUtils.getRandomPeerID(groupId);
- queryNodes.put(groupId, randomPeer);
- Map<PathType, QueryPlan> allQueryPlan = new EnumMap<>(PathType.class);
- allQueryPlan.put(PathType.SELECT_PATH, queryPlan);
- List<Filter> filterList = null;
- if (filterGroupEntityMap.containsKey(groupId)) {
- FilterGroupEntity filterGroupEntity = filterGroupEntityMap.get(groupId);
- allQueryPlan.put(PathType.FILTER_PATH, filterGroupEntity.getQueryPlan());
- filterList = filterGroupEntity.getFilters();
- }
- InitSeriesReaderResponse response = (InitSeriesReaderResponse) ClusterRpcReaderUtils
- .createClusterSeriesReader(groupId, randomPeer, readDataConsistencyLevel,
- allQueryPlan, taskId, filterList);
- handleInitReaderResponse(groupId, allQueryPlan, response);
- } else {
- dataGroupUsage.add(groupId);
- selectSeriesByGroupId.remove(groupId);
- if (filterGroupEntityMap.containsKey(groupId)) {
- filterGroupEntityMap.remove(groupId);
- }
- }
- }
-
- //Init series reader with data groups of filter series, which don't exist in data groups list of select series.
- for (Entry<String, FilterGroupEntity> entry : filterGroupEntityMap.entrySet()) {
- String groupId = entry.getKey();
- if (!selectPathPlans.containsKey(groupId)) {
- PeerId randomPeer = RaftUtils.getRandomPeerID(groupId);
- Map<PathType, QueryPlan> allQueryPlan = new EnumMap<>(PathType.class);
- FilterGroupEntity filterGroupEntity = filterGroupEntityMap.get(groupId);
- allQueryPlan.put(PathType.FILTER_PATH, filterGroupEntity.getQueryPlan());
- List<Filter> filterList = filterGroupEntity.getFilters();
- InitSeriesReaderResponse response = (InitSeriesReaderResponse) ClusterRpcReaderUtils
- .createClusterSeriesReader(groupId, randomPeer, readDataConsistencyLevel,
- allQueryPlan, taskId, filterList);
- handleInitReaderResponse(groupId, allQueryPlan, response);
- }
- }
- }
-
- /**
- * Handle response of initialization with remote query node
- */
- private void handleInitReaderResponse(String groupId, Map<PathType, QueryPlan> allQueryPlan,
- InitSeriesReaderResponse response) {
- /** create cluster series reader **/
- if (allQueryPlan.containsKey(PathType.SELECT_PATH)) {
- QueryPlan plan = allQueryPlan.get(PathType.SELECT_PATH);
- List<Path> paths = plan.getPaths();
- List<TSDataType> seriesType = response.getSeriesDataTypes().get(PathType.SELECT_PATH);
- for (int i = 0; i < paths.size(); i++) {
- Path seriesPath = paths.get(i);
- TSDataType dataType = seriesType.get(i);
- ClusterSelectSeriesReader seriesReader = new ClusterSelectSeriesReader(groupId, seriesPath,
- dataType, this);
- selectSeriesReaders.put(seriesPath, seriesReader);
- }
- }
- if (allQueryPlan.containsKey(PathType.FILTER_PATH)) {
- QueryPlan plan = allQueryPlan.get(PathType.FILTER_PATH);
- List<Path> paths = plan.getPaths();
- List<TSDataType> seriesType = response.getSeriesDataTypes().get(PathType.FILTER_PATH);
- for (int i = 0; i < paths.size(); i++) {
- Path seriesPath = paths.get(i);
- TSDataType dataType = seriesType.get(i);
- ClusterFilterSeriesReader seriesReader = new ClusterFilterSeriesReader(groupId, seriesPath,
- dataType, this);
- if (!filterGroupEntityMap.containsKey(groupId)) {
- filterGroupEntityMap.put(groupId, new FilterGroupEntity(groupId));
- }
- filterGroupEntityMap.get(groupId).addFilterSeriesReader(seriesReader);
- }
- }
- }
-
- @Override
- public void fetchBatchDataForSelectPaths(String groupId) throws RaftConnectionException {
- List<String> fetchDataSeries = new ArrayList<>();
- Map<String, List<Path>> seriesByGroupId;
- Map<Path, ClusterSelectSeriesReader> seriesReaders;
- seriesByGroupId = selectSeriesByGroupId;
- seriesReaders = selectSeriesReaders;
- if (seriesByGroupId.containsKey(groupId)) {
- List<Path> allFilterSeries = seriesByGroupId.get(groupId);
- for (Path series : allFilterSeries) {
- if (seriesReaders.get(series).enableFetchData()) {
- fetchDataSeries.add(series.getFullPath());
- }
- }
- }
- QuerySeriesDataResponse response = ClusterRpcReaderUtils
- .fetchBatchData(groupId, queryNodes.get(groupId), taskId, PathType.SELECT_PATH,
- fetchDataSeries,
- queryRounds++);
- handleFetchDataResponseForSelectPaths(fetchDataSeries, response);
- }
-
- @Override
- public void fetchBatchDataForFilterPaths(String groupId) throws RaftConnectionException {
- QuerySeriesDataResponse response = ClusterRpcReaderUtils
- .fetchBatchData(groupId, queryNodes.get(groupId), taskId, PathType.FILTER_PATH, null,
- queryRounds++);
- handleFetchDataResponseForFilterPaths(groupId, response);
- }
-
-
- @Override
- public void fetchBatchDataByTimestampForAllSelectPaths(List<Long> batchTimestamp)
- throws RaftConnectionException {
- for (Entry<String, List<Path>> entry : selectSeriesByGroupId.entrySet()) {
- String groupId = entry.getKey();
- List<String> fetchDataFilterSeries = new ArrayList<>();
- entry.getValue().forEach(path -> fetchDataFilterSeries.add(path.getFullPath()));
- QuerySeriesDataByTimestampResponse response = ClusterRpcReaderUtils
- .fetchBatchDataByTimestamp(groupId, queryNodes.get(groupId), taskId, queryRounds++,
- batchTimestamp, fetchDataFilterSeries);
- handleFetchDataByTimestampResponseForSelectPaths(fetchDataFilterSeries, response);
- }
- }
-
- /**
- * Handle response of fetching data, and add batch data to corresponding reader.
- */
- private void handleFetchDataByTimestampResponseForSelectPaths(List<String> fetchDataSeries,
- BasicQueryDataResponse response) {
- List<BatchData> batchDataList = response.getSeriesBatchData();
- for (int i = 0; i < fetchDataSeries.size(); i++) {
- String series = fetchDataSeries.get(i);
- BatchData batchData = batchDataList.get(i);
- selectSeriesReaders.get(new Path(series))
- .addBatchData(batchData, true);
- }
- }
-
- /**
- * Handle response of fetching data, and add batch data to corresponding reader.
- */
- private void handleFetchDataResponseForSelectPaths(List<String> fetchDataSeries,
- BasicQueryDataResponse response) {
- List<BatchData> batchDataList = response.getSeriesBatchData();
- for (int i = 0; i < fetchDataSeries.size(); i++) {
- String series = fetchDataSeries.get(i);
- BatchData batchData = batchDataList.get(i);
- selectSeriesReaders.get(new Path(series))
- .addBatchData(batchData, batchData.length() < CLUSTER_CONF.getBatchReadSize());
- }
- }
-
- /**
- * Handle response of fetching data, and add batch data to corresponding reader.
- */
- private void handleFetchDataResponseForFilterPaths(String groupId,
- QuerySeriesDataResponse response) {
- FilterGroupEntity filterGroupEntity = filterGroupEntityMap.get(groupId);
- List<Path> fetchDataSeries = filterGroupEntity.getFilterPaths();
- List<BatchData> batchDataList = response.getSeriesBatchData();
- List<ClusterFilterSeriesReader> filterReaders = filterGroupEntity.getFilterSeriesReaders();
- boolean remoteDataFinish = true;
- for (int i = 0; i < batchDataList.size(); i++) {
- if (batchDataList.get(i).length() != 0) {
- remoteDataFinish = false;
- break;
- }
- }
- for (int i = 0; i < fetchDataSeries.size(); i++) {
- BatchData batchData = batchDataList.get(i);
- if (batchData.length() != 0) {
- filterReaders.get(i).addBatchData(batchData, remoteDataFinish);
- }
- }
- }
-
- @Override
- public QueryPlan getSelectPathQueryPlan(String fullPath) {
- return selectPathPlans.get(fullPath);
- }
-
- @Override
- public void setDataGroupReaderNode(String groupId, PeerId readerNode) {
- queryNodes.put(groupId, readerNode);
- }
-
- @Override
- public PeerId getDataGroupReaderNode(String groupId) {
- return queryNodes.get(groupId);
- }
-
- @Override
- public void releaseQueryResource() throws RaftConnectionException {
- for (Entry<String, PeerId> entry : queryNodes.entrySet()) {
- String groupId = entry.getKey();
- PeerId queryNode = entry.getValue();
- ClusterRpcReaderUtils.releaseRemoteQueryResource(groupId, queryNode, taskId);
- }
- }
-
- public Set<String> getDataGroupUsage() {
- return dataGroupUsage;
- }
-
- public void addDataGroupUsage(String groupId) {
- this.dataGroupUsage.add(groupId);
- }
-
- public String getTaskId() {
- return taskId;
- }
-
- public void setTaskId(String taskId) {
- this.taskId = taskId;
- }
-
- public long getQueryRounds() {
- return queryRounds;
- }
-
- public void setQueryRounds(long queryRounds) {
- this.queryRounds = queryRounds;
- }
-
- public QueryPlan getOriginQueryPlan() {
- return originQueryPlan;
- }
-
- public void setOriginQueryPlan(QueryPlan queryPlan) {
- this.originQueryPlan = queryPlan;
- }
-
- public Map<String, PeerId> getQueryNodes() {
- return queryNodes;
- }
-
- public void setQueryNodes(
- Map<String, PeerId> queryNodes) {
- this.queryNodes = queryNodes;
- }
-
- public Map<String, QueryPlan> getSelectPathPlans() {
- return selectPathPlans;
- }
-
- public void setSelectPathPlans(
- Map<String, QueryPlan> selectPathPlans) {
- this.selectPathPlans = selectPathPlans;
- }
-
- public Map<String, List<Path>> getSelectSeriesByGroupId() {
- return selectSeriesByGroupId;
- }
-
- public void setSelectSeriesByGroupId(
- Map<String, List<Path>> selectSeriesByGroupId) {
- this.selectSeriesByGroupId = selectSeriesByGroupId;
- }
-
- public Map<Path, ClusterSelectSeriesReader> getSelectSeriesReaders() {
- return selectSeriesReaders;
- }
-
- public void setSelectSeriesReaders(
- Map<Path, ClusterSelectSeriesReader> selectSeriesReaders) {
- this.selectSeriesReaders = selectSeriesReaders;
- }
-
- public Map<String, FilterGroupEntity> getFilterGroupEntityMap() {
- return filterGroupEntityMap;
- }
-
- public void setFilterGroupEntityMap(
- Map<String, FilterGroupEntity> filterGroupEntityMap) {
- this.filterGroupEntityMap = filterGroupEntityMap;
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/coordinatornode/FilterGroupEntity.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/coordinatornode/FilterGroupEntity.java
deleted file mode 100644
index 326af11..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/coordinatornode/FilterGroupEntity.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * 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.cluster.query.manager.coordinatornode;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.iotdb.cluster.query.reader.coordinatornode.ClusterFilterSeriesReader;
-import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
-import org.apache.iotdb.tsfile.read.common.Path;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-
-/**
- * Filter entities of a data group, concluding QueryPlan, filters, all filter paths and filter readers
- */
-public class FilterGroupEntity {
-
- /**
- * Group id
- */
- private String groupId;
-
- /**
- * Query plans of filter paths which are divided from queryPlan
- */
- private QueryPlan queryPlan;
-
- /**
- * Filters of filter path.
- */
- private List<Filter> filters;
-
- /**
- *
- * all filter series
- * <p>
- * Note: It may contain multiple series in a complicated tree
- * for example: select * from root.vehicle where d0.s0 > 10 and d0.s0 < 101 or time = 12,
- * filter tree: <code>[[[[root.vehicle.d0.s0:time == 12] || [root.vehicle.d0.s1:time == 12]] || [root.vehicle.d1.s2:time == 12]] || [root.vehicle.d1.s3:time == 12]]</code>
- * </p>
- */
- private List<Path> filterPaths;
-
-
- /**
- * Series reader of filter paths (only contains remote series)
- */
- private List<ClusterFilterSeriesReader> filterSeriesReaders;
-
- public FilterGroupEntity(String groupId) {
- this.groupId = groupId;
- this.filterPaths = new ArrayList<>();
- this.filters = new ArrayList<>();
- this.filterSeriesReaders = new ArrayList<>();
- }
-
- public String getGroupId() {
- return groupId;
- }
-
- public void setGroupId(String groupId) {
- this.groupId = groupId;
- }
-
- public QueryPlan getQueryPlan() {
- return queryPlan;
- }
-
- public void setQueryPlan(QueryPlan queryPlan) {
- this.queryPlan = queryPlan;
- }
-
- public List<Filter> getFilters() {
- return filters;
- }
-
- public void addFilter(Filter filter) {
- this.filters.add(filter);
- }
-
- public List<Path> getFilterPaths() {
- return filterPaths;
- }
-
- public void addFilterPaths(Path filterPath) {
- this.filterPaths.add(filterPath);
- }
-
- public List<ClusterFilterSeriesReader> getFilterSeriesReaders() {
- return filterSeriesReaders;
- }
-
- public void addFilterSeriesReader(ClusterFilterSeriesReader filterSeriesReader) {
- this.filterSeriesReaders.add(filterSeriesReader);
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/coordinatornode/IClusterRpcQueryManager.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/coordinatornode/IClusterRpcQueryManager.java
deleted file mode 100644
index b8e4f5d..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/coordinatornode/IClusterRpcQueryManager.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * 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.cluster.query.manager.coordinatornode;
-
-import java.util.Map;
-import org.apache.iotdb.cluster.exception.RaftConnectionException;
-import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
-
-/**
- * Manage all query series reader resources which fetch data from remote query nodes in coordinator
- * node
- */
-public interface IClusterRpcQueryManager {
-
- /**
- * Add a query
- *
- * @param jobId job id assigned by QueryResourceManager
- * @param physicalPlan physical plan
- */
- void addSingleQuery(long jobId, QueryPlan physicalPlan);
-
- /**
- * Get full task id (local address + job id)
- */
- String createTaskId(long jobId);
-
- /**
- * Get query manager by jobId
- *
- * @param jobId job id assigned by QueryResourceManager
- */
- ClusterRpcSingleQueryManager getSingleQuery(long jobId);
-
- /**
- * Get query manager by taskId
- *
- * @param taskId task id assigned by getAndIncreaTaskId() method
- */
- ClusterRpcSingleQueryManager getSingleQuery(String taskId);
-
- /**
- * Release query resource
- *
- * @param jobId job id
- */
- void releaseQueryResource(long jobId) throws RaftConnectionException;
-
- /**
- * Get all read usage count group by data group id, key is group id, value is usage count
- */
- Map<String, Integer> getAllReadUsage();
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/coordinatornode/IClusterRpcSingleQueryManager.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/coordinatornode/IClusterRpcSingleQueryManager.java
deleted file mode 100644
index c4aec9c..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/coordinatornode/IClusterRpcSingleQueryManager.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * 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.cluster.query.manager.coordinatornode;
-
-import com.alipay.sofa.jraft.entity.PeerId;
-import java.io.IOException;
-import java.util.List;
-import org.apache.iotdb.cluster.exception.RaftConnectionException;
-import org.apache.iotdb.cluster.query.QueryType;
-import org.apache.iotdb.db.exception.PathErrorException;
-import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
-
-/**
- * Manage a single query.
- */
-public interface IClusterRpcSingleQueryManager {
-
- /**
- * Divide physical plan into several sub physical plans according to timeseries full path and
- * create sereis reader.
- *
- * @param queryType query type
- * @param readDataConsistencyLevel consistency level of reading data
- */
- void initQueryResource(QueryType queryType, int readDataConsistencyLevel)
- throws PathErrorException, IOException, RaftConnectionException;
-
- /**
- * <p>
- * Fetch data for select paths. In order to reduce the number of RPC communications, fetching data
- * from remote query node will fetch for all series in the same data group. If the cached data for
- * specific series exceed limit, ignore this fetching data process of the series.
- * </p>
- *
- * @param groupId data group id
- */
- void fetchBatchDataForSelectPaths(String groupId) throws RaftConnectionException;
-
- /**
- * Fetch data for filter path.
- *
- * @param groupId data group id
- */
- void fetchBatchDataForFilterPaths(String groupId) throws RaftConnectionException;
-
- /**
- * Fetch batch data for all select paths by batch timestamp. If target data can be fetched, skip
- * corresponding group id.
- *
- * @param batchTimestamp valid batch timestamp
- */
- void fetchBatchDataByTimestampForAllSelectPaths(List<Long> batchTimestamp)
- throws RaftConnectionException;
-
- /**
- * Get query plan of select path
- *
- * @param fullPath Timeseries full path in select paths
- */
- QueryPlan getSelectPathQueryPlan(String fullPath);
-
- /**
- * Set reader node of a data group
- *
- * @param groupId data group id
- * @param readerNode reader peer id
- */
- void setDataGroupReaderNode(String groupId, PeerId readerNode);
-
- /**
- * Get reader node of a data group by group id
- *
- * @param groupId data group id
- * @return peer id of reader node
- */
- PeerId getDataGroupReaderNode(String groupId);
-
- /**
- * Release query resource in remote query node
- */
- void releaseQueryResource() throws RaftConnectionException;
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/querynode/ClusterLocalQueryManager.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/querynode/ClusterLocalQueryManager.java
deleted file mode 100644
index fe3ac52..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/querynode/ClusterLocalQueryManager.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/**
- * 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.cluster.query.manager.querynode;
-
-import com.alipay.sofa.jraft.util.OnlyForTest;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.InitSeriesReaderRequest;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.QuerySeriesDataByTimestampRequest;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.QuerySeriesDataRequest;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.InitSeriesReaderResponse;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.QuerySeriesDataByTimestampResponse;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.QuerySeriesDataResponse;
-import org.apache.iotdb.db.exception.FileNodeManagerException;
-import org.apache.iotdb.db.exception.PathErrorException;
-import org.apache.iotdb.db.exception.ProcessorException;
-import org.apache.iotdb.db.query.control.QueryResourceManager;
-import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException;
-
-public class ClusterLocalQueryManager implements IClusterLocalQueryManager {
-
- /**
- * Key is task id which is assigned by coordinator node, value is job id which is assigned by
- * query node(local).
- */
- private static final ConcurrentHashMap<String, Long> TASK_ID_MAP_JOB_ID = new ConcurrentHashMap<>();
-
- /**
- * Key is job id, value is manager of a client query.
- */
- private static final ConcurrentHashMap<Long, ClusterLocalSingleQueryManager> SINGLE_QUERY_MANAGER_MAP = new ConcurrentHashMap<>();
-
- private ClusterLocalQueryManager() {
- }
-
- @Override
- public InitSeriesReaderResponse createQueryDataSet(InitSeriesReaderRequest request)
- throws IOException, FileNodeManagerException, PathErrorException, ProcessorException, QueryFilterOptimizationException {
- long jobId = QueryResourceManager.getInstance().assignJobId();
- String taskId = request.getTaskId();
- TASK_ID_MAP_JOB_ID.put(taskId, jobId);
- ClusterLocalSingleQueryManager localQueryManager = new ClusterLocalSingleQueryManager(jobId);
- SINGLE_QUERY_MANAGER_MAP.put(jobId, localQueryManager);
- return localQueryManager.createSeriesReader(request);
- }
-
- @Override
- public QuerySeriesDataResponse readBatchData(QuerySeriesDataRequest request)
- throws IOException {
- long jobId = TASK_ID_MAP_JOB_ID.get(request.getTaskId());
- return SINGLE_QUERY_MANAGER_MAP.get(jobId).readBatchData(request);
- }
-
- @Override
- public QuerySeriesDataByTimestampResponse readBatchDataByTimestamp(
- QuerySeriesDataByTimestampRequest request)
- throws IOException {
- long jobId = TASK_ID_MAP_JOB_ID.get(request.getTaskId());
- return SINGLE_QUERY_MANAGER_MAP.get(jobId).readBatchDataByTimestamp(request);
- }
-
- @Override
- public void close(String taskId) throws FileNodeManagerException {
- if (TASK_ID_MAP_JOB_ID.containsKey(taskId)) {
- SINGLE_QUERY_MANAGER_MAP.remove(TASK_ID_MAP_JOB_ID.remove(taskId)).close();
- }
- }
-
- @Override
- public ClusterLocalSingleQueryManager getSingleQuery(String taskId) {
- long jobId = TASK_ID_MAP_JOB_ID.get(taskId);
- return SINGLE_QUERY_MANAGER_MAP.get(jobId);
- }
-
- public static final ClusterLocalQueryManager getInstance() {
- return ClusterLocalQueryManager.ClusterLocalQueryManagerHolder.INSTANCE;
- }
-
- private static class ClusterLocalQueryManagerHolder {
-
- private static final ClusterLocalQueryManager INSTANCE = new ClusterLocalQueryManager();
-
- private ClusterLocalQueryManagerHolder() {
-
- }
- }
-
- @Override
- public Map<String, Integer> getAllReadUsage() {
- Map<String, Integer> readerUsageMap = new HashMap<>();
- SINGLE_QUERY_MANAGER_MAP.values().forEach(singleQueryManager -> {
- String groupId = singleQueryManager.getGroupId();
- readerUsageMap.put(groupId, readerUsageMap.getOrDefault(groupId, 0) + 1);
- });
- return readerUsageMap;
- }
-
- @OnlyForTest
- public static ConcurrentHashMap<String, Long> getTaskIdMapJobId() {
- return TASK_ID_MAP_JOB_ID;
- }
-
- @OnlyForTest
- public static ConcurrentHashMap<Long, ClusterLocalSingleQueryManager> getSingleQueryManagerMap() {
- return SINGLE_QUERY_MANAGER_MAP;
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/querynode/ClusterLocalSingleQueryManager.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/querynode/ClusterLocalSingleQueryManager.java
deleted file mode 100644
index 37e3c57..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/querynode/ClusterLocalSingleQueryManager.java
+++ /dev/null
@@ -1,335 +0,0 @@
-/**
- * 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.cluster.query.manager.querynode;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ScheduledFuture;
-import org.apache.iotdb.cluster.concurrent.pool.QueryTimerManager;
-import org.apache.iotdb.cluster.config.ClusterConstant;
-import org.apache.iotdb.cluster.query.PathType;
-import org.apache.iotdb.cluster.query.factory.ClusterSeriesReaderFactory;
-import org.apache.iotdb.cluster.query.reader.querynode.AbstractClusterBatchReader;
-import org.apache.iotdb.cluster.query.reader.querynode.ClusterBatchReaderByTimestamp;
-import org.apache.iotdb.cluster.query.reader.querynode.ClusterBatchReaderWithoutTimeGenerator;
-import org.apache.iotdb.cluster.query.reader.querynode.ClusterFilterSeriesBatchReader;
-import org.apache.iotdb.cluster.query.reader.querynode.IClusterFilterSeriesBatchReader;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.InitSeriesReaderRequest;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.QuerySeriesDataByTimestampRequest;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.QuerySeriesDataRequest;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.InitSeriesReaderResponse;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.QuerySeriesDataByTimestampResponse;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.QuerySeriesDataResponse;
-import org.apache.iotdb.db.exception.FileNodeManagerException;
-import org.apache.iotdb.db.exception.PathErrorException;
-import org.apache.iotdb.db.exception.ProcessorException;
-import org.apache.iotdb.db.metadata.MManager;
-import org.apache.iotdb.db.qp.executor.OverflowQPExecutor;
-import org.apache.iotdb.db.qp.executor.QueryProcessExecutor;
-import org.apache.iotdb.db.qp.physical.crud.AggregationPlan;
-import org.apache.iotdb.db.qp.physical.crud.GroupByPlan;
-import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
-import org.apache.iotdb.db.query.context.QueryContext;
-import org.apache.iotdb.db.query.control.QueryResourceManager;
-import org.apache.iotdb.db.query.executor.AbstractExecutorWithoutTimeGenerator;
-import org.apache.iotdb.db.query.reader.IPointReader;
-import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
-import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.common.BatchData;
-import org.apache.iotdb.tsfile.read.common.Path;
-import org.apache.iotdb.tsfile.read.expression.ExpressionType;
-import org.apache.iotdb.tsfile.read.expression.impl.GlobalTimeExpression;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-public class ClusterLocalSingleQueryManager implements IClusterLocalSingleQueryManager {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(ClusterLocalSingleQueryManager.class);
-
- private String groupId;
-
- /**
- * Timer of Query, if the time is up, close query resource.
- */
- private ScheduledFuture<?> queryTimer;
-
- /**
- * Job id assigned by local QueryResourceManager
- */
- private long jobId;
-
- /**
- * Represents the number of query rounds, initial value is -1.
- */
- private long queryRound = -1;
-
- /**
- * Key is series full path, value is reader of select series
- */
- private Map<String, AbstractClusterBatchReader> selectSeriesReaders = new HashMap<>();
-
- /**
- * Filter reader
- */
- private IClusterFilterSeriesBatchReader filterReader;
-
- /**
- * Key is series full path, value is data type of series
- */
- private Map<String, TSDataType> dataTypeMap = new HashMap<>();
-
- /**
- * Cached batch data result
- */
- private List<BatchData> cachedBatchDataResult = new ArrayList<>();
-
- private QueryProcessExecutor queryProcessExecutor = new OverflowQPExecutor();
-
- /**
- * Constructor of ClusterLocalSingleQueryManager
- */
- public ClusterLocalSingleQueryManager(long jobId) {
- this.jobId = jobId;
- queryTimer = QueryTimerManager.getInstance()
- .execute(new QueryTimerRunnable(), ClusterConstant.QUERY_TIMEOUT_IN_QUERY_NODE);
- }
-
- @Override
- public InitSeriesReaderResponse createSeriesReader(InitSeriesReaderRequest request)
- throws IOException, PathErrorException, FileNodeManagerException, ProcessorException, QueryFilterOptimizationException {
- this.groupId = request.getGroupID();
- InitSeriesReaderResponse response = new InitSeriesReaderResponse(groupId);
- QueryContext context = new QueryContext(jobId);
- Map<PathType, QueryPlan> queryPlanMap = request.getAllQueryPlan();
- if (queryPlanMap.containsKey(PathType.SELECT_PATH)) {
- QueryPlan plan = queryPlanMap.get(PathType.SELECT_PATH);
- if (plan instanceof GroupByPlan) {
- throw new UnsupportedOperationException();
- } else if (plan instanceof AggregationPlan) {
- throw new UnsupportedOperationException();
- } else {
- if (plan.getExpression() == null
- || plan.getExpression().getType() == ExpressionType.GLOBAL_TIME) {
- handleSelectReaderWithoutTimeGenerator(plan, context, response);
- } else {
- handleSelectReaderWithTimeGenerator(plan, context, response);
- }
- }
- }
- if (queryPlanMap.containsKey(PathType.FILTER_PATH)) {
- QueryPlan queryPlan = queryPlanMap.get(PathType.FILTER_PATH);
- handleFilterSeriesReader(queryPlan, context, request, response, PathType.FILTER_PATH);
- }
- return response;
- }
-
- /**
- * Handle filter series reader
- *
- * @param plan filter series query plan
- */
- private void handleFilterSeriesReader(QueryPlan plan, QueryContext context,
- InitSeriesReaderRequest request, InitSeriesReaderResponse response, PathType pathType)
- throws PathErrorException, QueryFilterOptimizationException, FileNodeManagerException, ProcessorException, IOException {
- QueryDataSet queryDataSet = queryProcessExecutor
- .processQuery(plan, context);
- List<Path> paths = plan.getPaths();
- List<TSDataType> dataTypes = queryDataSet.getDataTypes();
- for (int i = 0; i < paths.size(); i++) {
- dataTypeMap.put(paths.get(i).getFullPath(), dataTypes.get(i));
- }
- response.getSeriesDataTypes().put(pathType, dataTypes);
- filterReader = new ClusterFilterSeriesBatchReader(queryDataSet, paths, request.getFilterList());
- }
-
- /**
- * Handle select series query with no filter or only global time filter
- *
- * @param plan plan query plan
- * @param context query context
- * @param response response for coordinator node
- */
- private void handleSelectReaderWithoutTimeGenerator(QueryPlan plan, QueryContext context,
- InitSeriesReaderResponse response)
- throws FileNodeManagerException {
- List<Path> paths = plan.getPaths();
- Filter timeFilter = null;
- if (plan.getExpression() != null) {
- timeFilter = ((GlobalTimeExpression) plan.getExpression()).getFilter();
- }
- List<TSDataType> dataTypes = new ArrayList<>();
- QueryResourceManager.getInstance()
- .beginQueryOfGivenQueryPaths(context.getJobId(), plan.getPaths());
- for (int i = 0; i < paths.size(); i++) {
- String fullPath = paths.get(i).getFullPath();
- IPointReader reader = AbstractExecutorWithoutTimeGenerator
- .createSeriesReader(context, paths.get(i), dataTypes, timeFilter);
- selectSeriesReaders
- .put(fullPath, new ClusterBatchReaderWithoutTimeGenerator(dataTypes.get(i), reader));
- dataTypeMap.put(fullPath, dataTypes.get(i));
- }
- response.getSeriesDataTypes().put(PathType.SELECT_PATH, dataTypes);
- }
-
- /**
- * Handle select series query with value filter
- *
- * @param plan plan query plan
- * @param context query context
- * @param response response for coordinator node
- */
- private void handleSelectReaderWithTimeGenerator(QueryPlan plan, QueryContext context,
- InitSeriesReaderResponse response)
- throws PathErrorException, FileNodeManagerException, IOException {
- List<Path> paths = plan.getPaths();
- List<TSDataType> dataTypeList = new ArrayList<>();
- for (int i = 0; i < paths.size(); i++) {
- Path path = paths.get(i);
- EngineReaderByTimeStamp readerByTimeStamp = ClusterSeriesReaderFactory
- .createReaderByTimeStamp(path, context);
- TSDataType dataType = MManager.getInstance().getSeriesType(path.getFullPath());
- selectSeriesReaders
- .put(path.getFullPath(), new ClusterBatchReaderByTimestamp(readerByTimeStamp, dataType));
- dataTypeMap.put(path.getFullPath(), dataType);
- dataTypeList.add(dataType);
- }
- response.getSeriesDataTypes().put(PathType.SELECT_PATH, dataTypeList);
- }
-
- @Override
- public QuerySeriesDataResponse readBatchData(QuerySeriesDataRequest request)
- throws IOException {
- resetQueryTimer();
- QuerySeriesDataResponse response = new QuerySeriesDataResponse(request.getGroupID());
- long targetQueryRounds = request.getQueryRounds();
- if (targetQueryRounds != this.queryRound) {
- this.queryRound = targetQueryRounds;
- PathType pathType = request.getPathType();
- List<String> paths = request.getSeriesPaths();
- List<BatchData> batchDataList;
- if (pathType == PathType.SELECT_PATH) {
- batchDataList = readSelectSeriesBatchData(paths);
- } else {
- batchDataList = readFilterSeriesBatchData();
- }
- cachedBatchDataResult = batchDataList;
- }
- response.setSeriesBatchData(cachedBatchDataResult);
- return response;
- }
-
- @Override
- public QuerySeriesDataByTimestampResponse readBatchDataByTimestamp(
- QuerySeriesDataByTimestampRequest request)
- throws IOException {
- resetQueryTimer();
- QuerySeriesDataByTimestampResponse response = new QuerySeriesDataByTimestampResponse(groupId);
- List<String> fetchDataSeries = request.getFetchDataSeries();
- long targetQueryRounds = request.getQueryRounds();
- if (targetQueryRounds != this.queryRound) {
- this.queryRound = targetQueryRounds;
- List<BatchData> batchDataList = new ArrayList<>();
- for (String series : fetchDataSeries) {
- AbstractClusterBatchReader reader = selectSeriesReaders.get(series);
- batchDataList.add(reader.nextBatch(request.getBatchTimestamp()));
- }
- cachedBatchDataResult = batchDataList;
- }
- response.setSeriesBatchData(cachedBatchDataResult);
- return response;
- }
-
- @Override
- public void resetQueryTimer() {
- queryTimer.cancel(false);
- queryTimer = QueryTimerManager.getInstance()
- .execute(new QueryTimerRunnable(), ClusterConstant.QUERY_TIMEOUT_IN_QUERY_NODE);
- }
-
- /**
- * Read batch data of select series
- *
- * @param paths all series to query
- */
- private List<BatchData> readSelectSeriesBatchData(List<String> paths) throws IOException {
- List<BatchData> batchDataList = new ArrayList<>();
- for (String fullPath : paths) {
- batchDataList.add(selectSeriesReaders.get(fullPath).nextBatch());
- }
- return batchDataList;
- }
-
- /**
- * Read batch data of filter series
- *
- * @return batch data of all filter series
- */
- private List<BatchData> readFilterSeriesBatchData() throws IOException {
- return filterReader.nextBatchList();
- }
-
- public String getGroupId() {
- return groupId;
- }
-
- @Override
- public void close() throws FileNodeManagerException {
- queryTimer.cancel(false);
- QueryResourceManager.getInstance().endQueryForGivenJob(jobId);
- }
-
- public long getJobId() {
- return jobId;
- }
-
- public long getQueryRound() {
- return queryRound;
- }
-
- public Map<String, AbstractClusterBatchReader> getSelectSeriesReaders() {
- return selectSeriesReaders;
- }
-
- public IClusterFilterSeriesBatchReader getFilterReader() {
- return filterReader;
- }
-
- public Map<String, TSDataType> getDataTypeMap() {
- return dataTypeMap;
- }
-
- public class QueryTimerRunnable implements Runnable {
-
- @Override
- public void run() {
- try {
- close();
- } catch (FileNodeManagerException e) {
- LOGGER.error(e.getMessage());
- }
- }
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/querynode/IClusterLocalQueryManager.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/querynode/IClusterLocalQueryManager.java
deleted file mode 100644
index cc0f103..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/querynode/IClusterLocalQueryManager.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * 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.cluster.query.manager.querynode;
-
-import java.io.IOException;
-import java.util.Map;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.InitSeriesReaderRequest;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.QuerySeriesDataByTimestampRequest;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.QuerySeriesDataRequest;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.InitSeriesReaderResponse;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.QuerySeriesDataByTimestampResponse;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.QuerySeriesDataResponse;
-import org.apache.iotdb.db.exception.FileNodeManagerException;
-import org.apache.iotdb.db.exception.PathErrorException;
-import org.apache.iotdb.db.exception.ProcessorException;
-import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException;
-
-/**
- * Manage all local query resources which provide data for coordinator node in cluster query node.
- */
-public interface IClusterLocalQueryManager {
-
- /**
- * Initially create query data set for coordinator node.
- *
- * @param request request for query data from coordinator node
- */
- InitSeriesReaderResponse createQueryDataSet(InitSeriesReaderRequest request)
- throws IOException, FileNodeManagerException, PathErrorException, ProcessorException, QueryFilterOptimizationException;
-
- /**
- * Read batch data of all querying series in request and set response.
- *
- * @param request request of querying series
- */
- QuerySeriesDataResponse readBatchData(QuerySeriesDataRequest request)
- throws IOException;
-
- /**
- * Read batch data of select series by batch timestamp which is used in query with value filter
- * @param request request of querying select paths
- *
- */
- QuerySeriesDataByTimestampResponse readBatchDataByTimestamp(
- QuerySeriesDataByTimestampRequest request) throws IOException;
-
- /**
- * Close query resource of a task
- *
- * @param taskId task id of local single query manager
- */
- void close(String taskId) throws FileNodeManagerException;
-
-
- /**
- * Get query manager by taskId
- *
- * @param taskId task id assigned by ClusterRpcQueryManager
- */
- ClusterLocalSingleQueryManager getSingleQuery(String taskId);
-
- /**
- * Get all read usage count group by data group id, key is group id, value is usage count
- */
- Map<String, Integer> getAllReadUsage();
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/querynode/IClusterLocalSingleQueryManager.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/querynode/IClusterLocalSingleQueryManager.java
deleted file mode 100644
index 318772f..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/manager/querynode/IClusterLocalSingleQueryManager.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * 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.cluster.query.manager.querynode;
-
-import java.io.IOException;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.InitSeriesReaderRequest;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.QuerySeriesDataByTimestampRequest;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.QuerySeriesDataRequest;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.InitSeriesReaderResponse;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.QuerySeriesDataByTimestampResponse;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.QuerySeriesDataResponse;
-import org.apache.iotdb.db.exception.FileNodeManagerException;
-import org.apache.iotdb.db.exception.PathErrorException;
-import org.apache.iotdb.db.exception.ProcessorException;
-import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException;
-
-/**
- * <p>
- * Manage all series reader in a query as a query node, cooperate with coordinator node for a client
- * query
- * </p>
- */
-public interface IClusterLocalSingleQueryManager {
-
- /**
- * Initially create corresponding series readers.
- * @param request request of querying series data
- */
- InitSeriesReaderResponse createSeriesReader(InitSeriesReaderRequest request)
- throws IOException, PathErrorException, FileNodeManagerException, ProcessorException, QueryFilterOptimizationException;
-
- /**
- * <p>
- * Read batch data If query round in cache is equal to target query round, it means that batch
- * data in query node transfer to coordinator fail and return cached batch data.
- * </p>
- * @param request request of querying series data
- *
- */
- QuerySeriesDataResponse readBatchData(QuerySeriesDataRequest request)
- throws IOException;
-
- /**
- * Read batch data of select paths by timestamp
- */
- QuerySeriesDataByTimestampResponse readBatchDataByTimestamp(
- QuerySeriesDataByTimestampRequest request) throws IOException;
-
- /**
- * Reset query timer and restart timer
- */
- void resetQueryTimer();
-
- /**
- * Release query resource
- */
- void close() throws FileNodeManagerException;
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/coordinatornode/AbstractClusterPointReader.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/coordinatornode/AbstractClusterPointReader.java
deleted file mode 100644
index 72c7c70..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/coordinatornode/AbstractClusterPointReader.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * 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.cluster.query.reader.coordinatornode;
-
-import java.io.IOException;
-import org.apache.iotdb.cluster.exception.RaftConnectionException;
-import org.apache.iotdb.db.query.reader.IPointReader;
-import org.apache.iotdb.db.utils.TimeValuePair;
-import org.apache.iotdb.db.utils.TimeValuePairUtils;
-import org.apache.iotdb.tsfile.read.common.BatchData;
-
-/**
- * Cluster point reader
- */
-public abstract class AbstractClusterPointReader implements IPointReader {
-
- /**
- * Current time value pair
- */
- protected TimeValuePair currentTimeValuePair;
-
- /**
- * Current batch data
- */
- protected BatchData currentBatchData;
-
- @Override
- public boolean hasNext() throws IOException {
- if (currentBatchData == null || !currentBatchData.hasNext()) {
- try {
- updateCurrentBatchData();
- } catch (RaftConnectionException e) {
- throw new IOException(e);
- }
- if (currentBatchData == null || !currentBatchData.hasNext()) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Update current batch data. If necessary ,fetch batch data from remote query node
- */
- protected abstract void updateCurrentBatchData() throws RaftConnectionException;
-
- @Override
- public TimeValuePair next() throws IOException {
- if (hasNext()) {
- TimeValuePair timeValuePair = TimeValuePairUtils.getCurrentTimeValuePair(currentBatchData);
- currentTimeValuePair = timeValuePair;
- currentBatchData.next();
- return timeValuePair;
- }
- return null;
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/coordinatornode/ClusterFilterSeriesReader.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/coordinatornode/ClusterFilterSeriesReader.java
deleted file mode 100644
index 805d3af..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/coordinatornode/ClusterFilterSeriesReader.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/**
- * 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.cluster.query.reader.coordinatornode;
-
-import java.io.IOException;
-import java.util.LinkedList;
-import org.apache.iotdb.cluster.exception.RaftConnectionException;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcSingleQueryManager;
-import org.apache.iotdb.db.utils.TimeValuePair;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.common.BatchData;
-import org.apache.iotdb.tsfile.read.common.Path;
-
-/**
- * Filter series reader which is used in coordinator node.
- */
-public class ClusterFilterSeriesReader extends AbstractClusterPointReader {
-
- /**
- * Data group id
- */
- private String groupId;
-
- /**
- * Manager of the whole query
- */
- private ClusterRpcSingleQueryManager queryManager;
-
- /**
- * Series name
- */
- private Path seriesPath;
-
- /**
- * Data type
- */
- private TSDataType dataType;
-
- /**
- * Batch data
- */
- private LinkedList<BatchData> batchDataList;
-
- /**
- * Mark whether remote has data
- */
- private boolean remoteDataFinish;
-
- public ClusterFilterSeriesReader(String groupId, Path seriesPath, TSDataType dataType,
- ClusterRpcSingleQueryManager queryManager) {
- this.groupId = groupId;
- this.seriesPath = seriesPath;
- this.dataType = dataType;
- this.queryManager = queryManager;
- this.batchDataList = new LinkedList<>();
- remoteDataFinish = false;
- }
-
- @Override
- public TimeValuePair current() throws IOException {
- return currentTimeValuePair;
- }
-
- /**
- * Update current batch data. If necessary ,fetch batch data from remote query node
- */
- @Override
- protected void updateCurrentBatchData() throws RaftConnectionException {
- if (batchDataList.isEmpty() && !remoteDataFinish) {
- queryManager.fetchBatchDataForFilterPaths(groupId);
- }
- if (!batchDataList.isEmpty()) {
- currentBatchData = batchDataList.removeFirst();
- }
- }
-
- @Override
- public void close() throws IOException {
- //Do nothing
- }
-
- public Path getSeriesPath() {
- return seriesPath;
- }
-
- public void setSeriesPath(Path seriesPath) {
- this.seriesPath = seriesPath;
- }
-
- public TSDataType getDataType() {
- return dataType;
- }
-
- public void setDataType(TSDataType dataType) {
- this.dataType = dataType;
- }
-
- public BatchData getCurrentBatchData() {
- return currentBatchData;
- }
-
- public void setCurrentBatchData(BatchData currentBatchData) {
- this.currentBatchData = currentBatchData;
- }
-
- public void addBatchData(BatchData batchData, boolean remoteDataFinish) {
- batchDataList.addLast(batchData);
- this.remoteDataFinish = remoteDataFinish;
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/coordinatornode/ClusterSelectSeriesReader.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/coordinatornode/ClusterSelectSeriesReader.java
deleted file mode 100644
index 0a507d5..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/coordinatornode/ClusterSelectSeriesReader.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/**
- * 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.cluster.query.reader.coordinatornode;
-
-import java.io.IOException;
-import java.util.LinkedList;
-import org.apache.iotdb.cluster.config.ClusterDescriptor;
-import org.apache.iotdb.cluster.exception.RaftConnectionException;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcSingleQueryManager;
-import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
-import org.apache.iotdb.db.utils.TimeValuePair;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.common.BatchData;
-import org.apache.iotdb.tsfile.read.common.Path;
-
-/**
- * Select series reader which is used in coordinator node.
- */
-public class ClusterSelectSeriesReader extends AbstractClusterPointReader implements
- EngineReaderByTimeStamp {
-
- /**
- * Data group id
- */
- private String groupId;
-
- /**
- * Manager of the whole query
- */
- private ClusterRpcSingleQueryManager queryManager;
-
- /**
- * Series name
- */
- private Path seriesPath;
-
- /**
- * Data type
- */
- private TSDataType dataType;
-
- /**
- * Batch data
- */
- private LinkedList<BatchData> batchDataList;
-
- /**
- * Mark whether remote has data
- */
- private boolean remoteDataFinish;
-
- public ClusterSelectSeriesReader(String groupId, Path seriesPath, TSDataType dataType,
- ClusterRpcSingleQueryManager queryManager) {
- this.groupId = groupId;
- this.seriesPath = seriesPath;
- this.dataType = dataType;
- this.queryManager = queryManager;
- this.batchDataList = new LinkedList<>();
- this.remoteDataFinish = false;
- }
-
- @Override
- public TimeValuePair current() throws IOException {
- return currentTimeValuePair;
- }
-
- @Override
- public Object getValueInTimestamp(long timestamp) throws IOException {
- if (currentTimeValuePair != null && currentTimeValuePair.getTimestamp() == timestamp) {
- return currentTimeValuePair.getValue().getValue();
- } else if (currentTimeValuePair != null && currentTimeValuePair.getTimestamp() > timestamp) {
- return null;
- }
- while (true) {
- if (hasNext()) {
- next();
- if (currentTimeValuePair.getTimestamp() == timestamp) {
- return currentTimeValuePair.getValue().getValue();
- } else if (currentTimeValuePair.getTimestamp() > timestamp) {
- return null;
- }
- } else {
- return null;
- }
- }
- }
-
- /**
- * Update current batch data. If necessary ,fetch batch data from remote query node
- */
- @Override
- protected void updateCurrentBatchData() throws RaftConnectionException {
- if (batchDataList.isEmpty() && !remoteDataFinish) {
- queryManager.fetchBatchDataForSelectPaths(groupId);
- }
- if (!batchDataList.isEmpty()) {
- currentBatchData = batchDataList.removeFirst();
- }
- }
-
- @Override
- public void close() throws IOException {
- batchDataList = null;
- }
-
- public Path getSeriesPath() {
- return seriesPath;
- }
-
- public void setSeriesPath(Path seriesPath) {
- this.seriesPath = seriesPath;
- }
-
- public TSDataType getDataType() {
- return dataType;
- }
-
- public void setDataType(TSDataType dataType) {
- this.dataType = dataType;
- }
-
- public BatchData getCurrentBatchData() {
- return currentBatchData;
- }
-
- public void setCurrentBatchData(BatchData currentBatchData) {
- this.currentBatchData = currentBatchData;
- }
-
- public void addBatchData(BatchData batchData, boolean remoteDataFinish) {
- batchDataList.addLast(batchData);
- this.remoteDataFinish = remoteDataFinish;
- }
-
- public boolean isRemoteDataFinish() {
- return remoteDataFinish;
- }
-
- public void setRemoteDataFinish(boolean remoteDataFinish) {
- this.remoteDataFinish = remoteDataFinish;
- }
-
- /**
- * Check if this series need to fetch data from remote query node
- */
- public boolean enableFetchData() {
- return !remoteDataFinish
- && batchDataList.size() <= ClusterDescriptor.getInstance().getConfig()
- .getMaxCachedBatchDataListSize();
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/querynode/AbstractClusterBatchReader.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/querynode/AbstractClusterBatchReader.java
deleted file mode 100644
index b0a86bd..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/querynode/AbstractClusterBatchReader.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.cluster.query.reader.querynode;
-
-import java.io.IOException;
-import java.util.List;
-import org.apache.iotdb.db.query.reader.IBatchReader;
-import org.apache.iotdb.tsfile.read.common.BatchData;
-
-/**
- * Cluster batch reader, which provides another method to get batch data by batch timestamp.
- */
-public abstract class AbstractClusterBatchReader implements IBatchReader {
-
- /**
- * Get batch data by batch time
- *
- * @param batchTime valid batch timestamp
- * @return corresponding batch data
- */
- public abstract BatchData nextBatch(List<Long> batchTime) throws IOException;
-
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/querynode/ClusterBatchReaderByTimestamp.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/querynode/ClusterBatchReaderByTimestamp.java
deleted file mode 100644
index b8c36eb..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/querynode/ClusterBatchReaderByTimestamp.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * 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.cluster.query.reader.querynode;
-
-import java.io.IOException;
-import java.util.List;
-import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.common.BatchData;
-
-/**
- * BatchReader by timestamp for cluster which is used in query node.
- */
-public class ClusterBatchReaderByTimestamp extends AbstractClusterBatchReader {
-
- /**
- * Reader
- */
- private EngineReaderByTimeStamp readerByTimeStamp;
-
- /**
- * Data type
- */
- private TSDataType dataType;
-
- public ClusterBatchReaderByTimestamp(
- EngineReaderByTimeStamp readerByTimeStamp,
- TSDataType dataType) {
- this.readerByTimeStamp = readerByTimeStamp;
- this.dataType = dataType;
- }
-
- @Override
- public boolean hasNext() throws IOException {
- return readerByTimeStamp.hasNext();
- }
-
- @Override
- public BatchData nextBatch() throws IOException {
- throw new UnsupportedOperationException(
- "nextBatch() in ClusterBatchReaderByTimestamp is an empty method.");
- }
-
-
- @Override
- public void close() throws IOException {
- // do nothing
- }
-
- @Override
- public BatchData nextBatch(List<Long> batchTime) throws IOException {
- BatchData batchData = new BatchData(dataType, true);
- for(long time: batchTime){
- Object value = readerByTimeStamp.getValueInTimestamp(time);
- if(value != null){
- batchData.putTime(time);
- batchData.putAnObject(value);
- }
- }
- return batchData;
- }
-
- public EngineReaderByTimeStamp getReaderByTimeStamp() {
- return readerByTimeStamp;
- }
-
- public TSDataType getDataType() {
- return dataType;
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/querynode/ClusterBatchReaderWithoutTimeGenerator.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/querynode/ClusterBatchReaderWithoutTimeGenerator.java
deleted file mode 100644
index a59c79c..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/querynode/ClusterBatchReaderWithoutTimeGenerator.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * 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.cluster.query.reader.querynode;
-
-import java.io.IOException;
-import java.util.List;
-import org.apache.iotdb.cluster.config.ClusterConfig;
-import org.apache.iotdb.cluster.config.ClusterDescriptor;
-import org.apache.iotdb.db.query.reader.IPointReader;
-import org.apache.iotdb.db.utils.TimeValuePair;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.common.BatchData;
-
-/**
- * BatchReader without time generator for cluster which is used in query node.
- */
-public class ClusterBatchReaderWithoutTimeGenerator extends AbstractClusterBatchReader {
-
- /**
- * Data type
- */
- private TSDataType dataType;
-
- /**
- * Point reader
- */
- private IPointReader reader;
-
- private static final ClusterConfig CLUSTER_CONF = ClusterDescriptor.getInstance().getConfig();
-
- public ClusterBatchReaderWithoutTimeGenerator(
- TSDataType dataType, IPointReader reader) {
- this.dataType = dataType;
- this.reader = reader;
- }
-
- @Override
- public boolean hasNext() throws IOException {
- return reader.hasNext();
- }
-
- @Override
- public BatchData nextBatch() throws IOException {
- BatchData batchData = new BatchData(dataType, true);
- for (int i = 0; i < CLUSTER_CONF.getBatchReadSize(); i++) {
- if (hasNext()) {
- TimeValuePair pair = reader.next();
- batchData.putTime(pair.getTimestamp());
- batchData.putAnObject(pair.getValue().getValue());
- } else {
- break;
- }
- }
- return batchData;
- }
-
- @Override
- public void close() throws IOException {
- if (reader != null) {
- reader.close();
- }
- }
-
- @Override
- public BatchData nextBatch(List<Long> batchTime) throws IOException {
- throw new IOException(
- "nextBatch(List<Long> batchTime) in ClusterBatchReaderWithoutTimeGenerator is an empty method.");
- }
-
- public TSDataType getDataType() {
- return dataType;
- }
-
- public IPointReader getReader() {
- return reader;
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/querynode/ClusterFilterSeriesBatchReader.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/querynode/ClusterFilterSeriesBatchReader.java
deleted file mode 100644
index 3f21835..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/querynode/ClusterFilterSeriesBatchReader.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/**
- * 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.cluster.query.reader.querynode;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.iotdb.cluster.config.ClusterConfig;
-import org.apache.iotdb.cluster.config.ClusterDescriptor;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.common.BatchData;
-import org.apache.iotdb.tsfile.read.common.Field;
-import org.apache.iotdb.tsfile.read.common.Path;
-import org.apache.iotdb.tsfile.read.common.RowRecord;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
-
-/**
- * Batch reader for all filter paths.
- */
-public class ClusterFilterSeriesBatchReader implements IClusterFilterSeriesBatchReader {
-
- private List<Path> allFilterPath;
-
- private List<Filter> filters;
-
- private QueryDataSet queryDataSet;
-
- private static final ClusterConfig CLUSTER_CONF = ClusterDescriptor.getInstance().getConfig();
-
- public ClusterFilterSeriesBatchReader(QueryDataSet queryDataSet, List<Path> allFilterPath,
- List<Filter> filters) {
- this.queryDataSet = queryDataSet;
- this.allFilterPath = allFilterPath;
- this.filters = filters;
- }
-
- @Override
- public boolean hasNext() throws IOException {
- return queryDataSet.hasNext();
- }
-
- /**
- * Get batch data of all filter series by next batch time which is determined by
- * <code>queryDataSet</code>
- */
- @Override
- public List<BatchData> nextBatchList() throws IOException {
- List<BatchData> batchDataList = new ArrayList<>(allFilterPath.size());
- List<TSDataType> dataTypeList = queryDataSet.getDataTypes();
- for (int i = 0; i < allFilterPath.size(); i++) {
- batchDataList.add(new BatchData(dataTypeList.get(i), true));
- }
- int dataPointCount = 0;
- while(true){
- if(!hasNext() || dataPointCount == CLUSTER_CONF.getBatchReadSize()){
- break;
- }
- if(hasNext() && addTimeValuePair(batchDataList, dataTypeList)){
- dataPointCount++;
- }
- }
- return batchDataList;
- }
-
- /**
- * Add a time-value pair to batch data
- */
- private boolean addTimeValuePair(List<BatchData> batchDataList, List<TSDataType> dataTypeList)
- throws IOException {
- boolean hasField = false;
- RowRecord rowRecord = queryDataSet.next();
- long time = rowRecord.getTimestamp();
- List<Field> fieldList = rowRecord.getFields();
- for (int j = 0; j < allFilterPath.size(); j++) {
- if (!fieldList.get(j).isNull()) {
- BatchData batchData = batchDataList.get(j);
- Object value = fieldList.get(j).getObjectValue(dataTypeList.get(j));
- if (filters.get(j).satisfy(time, value)) {
- hasField = true;
- batchData.putTime(time);
- batchData.putAnObject(value);
- }
- }
- }
- return hasField;
- }
-
- public List<Path> getAllFilterPath() {
- return allFilterPath;
- }
-
- public void setAllFilterPath(List<Path> allFilterPath) {
- this.allFilterPath = allFilterPath;
- }
-
- public QueryDataSet getQueryDataSet() {
- return queryDataSet;
- }
-
- public void setQueryDataSet(QueryDataSet queryDataSet) {
- this.queryDataSet = queryDataSet;
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/querynode/IClusterFilterSeriesBatchReader.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/querynode/IClusterFilterSeriesBatchReader.java
deleted file mode 100644
index 218d68b..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/reader/querynode/IClusterFilterSeriesBatchReader.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.cluster.query.reader.querynode;
-
-import java.io.IOException;
-import java.util.List;
-import org.apache.iotdb.tsfile.read.common.BatchData;
-
-/**
- * Batch reader for filter series which is used in query node.
- */
-public interface IClusterFilterSeriesBatchReader {
-
- boolean hasNext() throws IOException;
-
- /**
- * Get next batch data of all filter series.
- */
- List<BatchData> nextBatchList() throws IOException;
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/timegenerator/ClusterLeafNode.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/timegenerator/ClusterLeafNode.java
deleted file mode 100644
index 39d4be4..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/timegenerator/ClusterLeafNode.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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.cluster.query.timegenerator;
-
-import java.io.IOException;
-import org.apache.iotdb.db.query.reader.IReader;
-import org.apache.iotdb.tsfile.read.query.timegenerator.node.Node;
-import org.apache.iotdb.tsfile.read.query.timegenerator.node.NodeType;
-
-public class ClusterLeafNode implements Node {
-
- private IReader reader;
-
- public ClusterLeafNode(IReader reader) {
- this.reader = reader;
- }
-
- @Override
- public boolean hasNext() throws IOException {
- return reader.hasNext();
- }
-
- @Override
- public long next() throws IOException {
- return reader.next().getTimestamp();
- }
-
- @Override
- public NodeType getType() {
- return NodeType.LEAF;
- }
-
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/timegenerator/ClusterNodeConstructor.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/timegenerator/ClusterNodeConstructor.java
deleted file mode 100644
index 639dce8..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/timegenerator/ClusterNodeConstructor.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/**
- * 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.cluster.query.timegenerator;
-
-import static org.apache.iotdb.tsfile.read.expression.ExpressionType.SERIES;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcSingleQueryManager;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.FilterGroupEntity;
-import org.apache.iotdb.cluster.query.reader.coordinatornode.ClusterFilterSeriesReader;
-import org.apache.iotdb.cluster.utils.QPExecutorUtils;
-import org.apache.iotdb.db.exception.FileNodeManagerException;
-import org.apache.iotdb.db.exception.PathErrorException;
-import org.apache.iotdb.db.query.context.QueryContext;
-import org.apache.iotdb.db.query.timegenerator.AbstractNodeConstructor;
-import org.apache.iotdb.tsfile.read.common.Path;
-import org.apache.iotdb.tsfile.read.expression.IExpression;
-import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression;
-import org.apache.iotdb.tsfile.read.query.timegenerator.node.Node;
-
-public class ClusterNodeConstructor extends AbstractNodeConstructor {
-
- /**
- * Single query manager
- */
- private ClusterRpcSingleQueryManager queryManager;
-
- /**
- * Filter series reader group by group id
- */
- private Map<String, List<ClusterFilterSeriesReader>> filterSeriesReadersByGroupId;
-
- /**
- * Mark filter series reader index group by group id
- */
- private Map<String, Integer> filterSeriesReaderIndex;
-
- public ClusterNodeConstructor(ClusterRpcSingleQueryManager queryManager) {
- this.queryManager = queryManager;
- this.filterSeriesReadersByGroupId = new HashMap<>();
- this.filterSeriesReaderIndex = new HashMap<>();
- this.init(queryManager);
- }
-
- /**
- * Init filter series reader
- */
- private void init(ClusterRpcSingleQueryManager queryManager) {
- Map<String, FilterGroupEntity> filterGroupEntityMap = queryManager.getFilterGroupEntityMap();
- filterGroupEntityMap.forEach(
- (key, value) -> filterSeriesReadersByGroupId.put(key, value.getFilterSeriesReaders()));
- filterSeriesReadersByGroupId.forEach((key, value) -> filterSeriesReaderIndex.put(key, 0));
- }
-
- /**
- * Construct expression node.
- *
- * @param expression expression
- * @return Node object
- * @throws IOException IOException
- * @throws FileNodeManagerException FileNodeManagerException
- */
- @Override
- public Node construct(IExpression expression, QueryContext context)
- throws FileNodeManagerException {
- if (expression.getType() == SERIES) {
- try {
- Path seriesPath = ((SingleSeriesExpression) expression).getSeriesPath();
- String groupId = QPExecutorUtils.getGroupIdByDevice(seriesPath.getDevice());
- if (filterSeriesReadersByGroupId.containsKey(groupId)) {
- List<ClusterFilterSeriesReader> seriesReaders = filterSeriesReadersByGroupId.get(groupId);
- int readerIndex = filterSeriesReaderIndex.get(groupId);
- filterSeriesReaderIndex.put(groupId, readerIndex + 1);
- return new ClusterLeafNode(seriesReaders.get(readerIndex));
- } else {
- queryManager.addDataGroupUsage(groupId);
- return new ClusterLeafNode(generateSeriesReader((SingleSeriesExpression) expression,
- context));
- }
- } catch (IOException | PathErrorException e) {
- throw new FileNodeManagerException(e);
- }
- } else {
- return constructNotSeriesNode(expression, context);
- }
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/timegenerator/ClusterTimeGenerator.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/timegenerator/ClusterTimeGenerator.java
deleted file mode 100644
index f2b72d1..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/timegenerator/ClusterTimeGenerator.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * 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.cluster.query.timegenerator;
-
-import java.io.IOException;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcSingleQueryManager;
-import org.apache.iotdb.db.exception.FileNodeManagerException;
-import org.apache.iotdb.db.query.context.QueryContext;
-import org.apache.iotdb.tsfile.read.common.Path;
-import org.apache.iotdb.tsfile.read.expression.IExpression;
-import org.apache.iotdb.tsfile.read.query.timegenerator.TimeGenerator;
-import org.apache.iotdb.tsfile.read.query.timegenerator.node.Node;
-
-public class ClusterTimeGenerator implements TimeGenerator {
- private IExpression expression;
- private Node operatorNode;
-
- /**
- * Constructor of Cluster TimeGenerator.
- */
- public ClusterTimeGenerator(IExpression expression, QueryContext context,
- ClusterRpcSingleQueryManager queryManager)
- throws FileNodeManagerException {
- this.expression = expression;
- initNode(context, queryManager);
- }
-
- private void initNode(QueryContext context, ClusterRpcSingleQueryManager queryManager)
- throws FileNodeManagerException {
- ClusterNodeConstructor nodeConstructor = new ClusterNodeConstructor(queryManager);
- this.operatorNode = nodeConstructor.construct(expression, context);
- }
-
- @Override
- public boolean hasNext() throws IOException {
- return operatorNode.hasNext();
- }
-
- @Override
- public long next() throws IOException {
- return operatorNode.next();
- }
-
- @Override
- public Object getValue(Path path, long time) throws IOException {
- return null;
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/ClusterRpcReaderUtils.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/ClusterRpcReaderUtils.java
deleted file mode 100644
index 424ba95..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/ClusterRpcReaderUtils.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/**
- * 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.cluster.query.utils;
-
-import com.alipay.sofa.jraft.entity.PeerId;
-import java.util.List;
-import java.util.Map;
-import org.apache.iotdb.cluster.config.ClusterDescriptor;
-import org.apache.iotdb.cluster.exception.RaftConnectionException;
-import org.apache.iotdb.cluster.qp.task.QPTask.TaskState;
-import org.apache.iotdb.cluster.qp.task.QueryTask;
-import org.apache.iotdb.cluster.query.PathType;
-import org.apache.iotdb.cluster.rpc.raft.NodeAsClient;
-import org.apache.iotdb.cluster.rpc.raft.request.BasicRequest;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.CloseSeriesReaderRequest;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.InitSeriesReaderRequest;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.QuerySeriesDataByTimestampRequest;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.QuerySeriesDataRequest;
-import org.apache.iotdb.cluster.rpc.raft.response.BasicResponse;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.QuerySeriesDataByTimestampResponse;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.QuerySeriesDataResponse;
-import org.apache.iotdb.cluster.utils.RaftUtils;
-import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-
-/**
- * Utils for cluster reader which needs to acquire data from remote query node.
- */
-public class ClusterRpcReaderUtils {
-
- /**
- * Count limit to redo a task
- */
- private static final int TASK_MAX_RETRY = ClusterDescriptor.getInstance().getConfig()
- .getQpTaskRedoCount();
-
- private ClusterRpcReaderUtils() {
- }
-
- /**
- * Create cluster series reader
- *
- * @param peerId query node to fetch data
- * @param readDataConsistencyLevel consistency level of read data
- * @param taskId task id assigned by coordinator node
- */
- public static BasicResponse createClusterSeriesReader(String groupId, PeerId peerId,
- int readDataConsistencyLevel, Map<PathType, QueryPlan> allQueryPlan, String taskId,
- List<Filter> filterList) throws RaftConnectionException {
-
- /** handle request **/
- BasicRequest request = InitSeriesReaderRequest
- .createInitialQueryRequest(groupId, taskId, readDataConsistencyLevel,
- allQueryPlan, filterList);
- return handleQueryRequest(request, peerId, 0);
- }
-
- public static QuerySeriesDataResponse fetchBatchData(String groupID, PeerId peerId, String taskId,
- PathType pathType, List<String> fetchDataSeries, long queryRounds)
- throws RaftConnectionException {
- BasicRequest request = QuerySeriesDataRequest
- .createFetchDataRequest(groupID, taskId, pathType, fetchDataSeries, queryRounds);
- return (QuerySeriesDataResponse) handleQueryRequest(request, peerId, 0);
- }
-
- public static QuerySeriesDataByTimestampResponse fetchBatchDataByTimestamp(String groupId,
- PeerId peerId, String taskId, long queryRounds, List<Long> batchTimestamp,
- List<String> fetchDataSeries)
- throws RaftConnectionException {
- BasicRequest request = QuerySeriesDataByTimestampRequest
- .createRequest(groupId, queryRounds, taskId, batchTimestamp, fetchDataSeries);
- return (QuerySeriesDataByTimestampResponse) handleQueryRequest(request, peerId, 0);
- }
-
- /**
- * Release remote query resources
- *
- * @param groupId data group id
- * @param peerId target query node
- * @param taskId unique task id
- */
- public static void releaseRemoteQueryResource(String groupId, PeerId peerId, String taskId)
- throws RaftConnectionException {
-
- BasicRequest request = CloseSeriesReaderRequest.createReleaseResourceRequest(groupId, taskId);
- handleQueryRequest(request, peerId, 0);
- }
-
- /**
- * Send query request to remote node and return response
- *
- * @param request query request
- * @param peerId target remote query node
- * @param taskRetryNum retry num of the request
- * @return Response from remote query node
- */
- private static BasicResponse handleQueryRequest(BasicRequest request, PeerId peerId,
- int taskRetryNum)
- throws RaftConnectionException {
- if (taskRetryNum > TASK_MAX_RETRY) {
- throw new RaftConnectionException(
- String.format("Query request retries reach the upper bound %s",
- TASK_MAX_RETRY));
- }
- NodeAsClient nodeAsClient = RaftUtils.getRaftNodeAsClient();
- QueryTask queryTask = nodeAsClient.syncHandleRequest(request, peerId);
- if (queryTask.getState() == TaskState.FINISH) {
- return queryTask.getBasicResponse();
- } else {
- return handleQueryRequest(request, peerId, taskRetryNum + 1);
- }
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/ExpressionUtils.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/ExpressionUtils.java
deleted file mode 100644
index 0024138..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/ExpressionUtils.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/**
- * 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.cluster.query.utils;
-
-import static org.apache.iotdb.tsfile.read.expression.ExpressionType.AND;
-import static org.apache.iotdb.tsfile.read.expression.ExpressionType.OR;
-import static org.apache.iotdb.tsfile.read.expression.ExpressionType.SERIES;
-import static org.apache.iotdb.tsfile.read.expression.ExpressionType.TRUE;
-
-import java.util.List;
-import java.util.Map;
-import org.apache.iotdb.cluster.query.expression.TrueExpression;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.FilterGroupEntity;
-import org.apache.iotdb.cluster.utils.QPExecutorUtils;
-import org.apache.iotdb.db.exception.PathErrorException;
-import org.apache.iotdb.tsfile.exception.write.UnSupportedDataTypeException;
-import org.apache.iotdb.tsfile.read.common.Path;
-import org.apache.iotdb.tsfile.read.expression.ExpressionType;
-import org.apache.iotdb.tsfile.read.expression.IBinaryExpression;
-import org.apache.iotdb.tsfile.read.expression.IExpression;
-import org.apache.iotdb.tsfile.read.expression.impl.BinaryExpression;
-import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression;
-
-public class ExpressionUtils {
-
- private ExpressionUtils() {
- }
-
- /**
- * Get all series path of expression group by group id
- */
- public static void getAllExpressionSeries(IExpression expression,
- Map<String, FilterGroupEntity> filterGroupEntityMap)
- throws PathErrorException {
- if (expression.getType() == ExpressionType.SERIES) {
- Path path = ((SingleSeriesExpression) expression).getSeriesPath();
- String groupId = QPExecutorUtils.getGroupIdByDevice(path.getDevice());
- if (!filterGroupEntityMap.containsKey(groupId)) {
- filterGroupEntityMap.put(groupId, new FilterGroupEntity(groupId));
- }
- FilterGroupEntity filterGroupEntity = filterGroupEntityMap.get(groupId);
- filterGroupEntity.addFilterPaths(path);
- filterGroupEntity.addFilter(((SingleSeriesExpression) expression).getFilter());
- } else if (expression.getType() == OR || expression.getType() == AND) {
- getAllExpressionSeries(((IBinaryExpression) expression).getLeft(), filterGroupEntityMap);
- getAllExpressionSeries(((IBinaryExpression) expression).getRight(), filterGroupEntityMap);
- } else {
- throw new UnSupportedDataTypeException(
- "Unsupported QueryFilterType when construct OperatorNode: " + expression.getType());
- }
- }
-
- /**
- * Prune filter true by group id
- *
- * @param pathList all paths of a data group
- */
- public static IExpression pruneFilterTree(IExpression expression, List<Path> pathList) {
- if (expression.getType() == SERIES) {
- if (pathList.contains(((SingleSeriesExpression) expression).getSeriesPath())) {
- return expression;
- } else{
- return new TrueExpression();
- }
- } else if(expression.getType() == OR){
- return pruneOrFilterTree(expression, pathList);
- } else if(expression.getType() == AND){
- return pruneAndFilterTree(expression, pathList);
- } else {
- throw new UnSupportedDataTypeException(
- "Unsupported ExpressionType when prune filter tree: " + expression.getType());
- }
- }
-
- /**
- * Prune or filter tree
- *
- * @param expression origin expression
- * @param pathList all series path of the same data group
- */
- private static IExpression pruneOrFilterTree(IExpression expression, List<Path> pathList) {
- IExpression left = pruneFilterTree(((BinaryExpression) expression).getLeft(), pathList);
- IExpression right = pruneFilterTree(((BinaryExpression) expression).getRight(), pathList);
- if (left.getType() == TRUE || right.getType() == TRUE) {
- return new TrueExpression();
- } else {
- ((BinaryExpression) expression).setLeft(left);
- ((BinaryExpression) expression).setRight(right);
- return expression;
- }
- }
-
- /**
- * Prune and filter tree
- *
- * @param expression origin expression
- * @param pathList all series path of the same data group
- */
- private static IExpression pruneAndFilterTree(IExpression expression, List<Path> pathList) {
- IExpression left = pruneFilterTree(((BinaryExpression) expression).getLeft(), pathList);
- IExpression right = pruneFilterTree(((BinaryExpression) expression).getRight(), pathList);
- if (left.getType() == TRUE && right.getType() == TRUE) {
- return new TrueExpression();
- } else if (left.getType() == TRUE) {
- return right;
- } else if (right.getType() == TRUE) {
- return left;
- } else {
- ((BinaryExpression) expression).setLeft(left);
- ((BinaryExpression) expression).setRight(right);
- return expression;
- }
- }
-
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/QueryPlanPartitionUtils.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/QueryPlanPartitionUtils.java
deleted file mode 100644
index be762e1..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/QueryPlanPartitionUtils.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/**
- * 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.cluster.query.utils;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcSingleQueryManager;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.FilterGroupEntity;
-import org.apache.iotdb.cluster.utils.QPExecutorUtils;
-import org.apache.iotdb.db.exception.PathErrorException;
-import org.apache.iotdb.db.qp.physical.crud.AggregationPlan;
-import org.apache.iotdb.db.qp.physical.crud.GroupByPlan;
-import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
-import org.apache.iotdb.tsfile.read.common.Path;
-import org.apache.iotdb.tsfile.read.expression.ExpressionType;
-import org.apache.iotdb.tsfile.read.expression.IExpression;
-
-/**
- * Utils for splitting query plan to several sub query plans by group id.
- */
-public class QueryPlanPartitionUtils {
-
- private QueryPlanPartitionUtils() {
-
- }
-
- /**
- * Split query plan with no filter or with only global time filter by group id
- */
- public static void splitQueryPlanWithoutValueFilter(
- ClusterRpcSingleQueryManager singleQueryManager)
- throws PathErrorException {
- splitQueryPlanBySelectPath(singleQueryManager);
- }
-
- /**
- * Split query plan by select paths
- */
- private static void splitQueryPlanBySelectPath(ClusterRpcSingleQueryManager singleQueryManager)
- throws PathErrorException {
- QueryPlan queryPlan = singleQueryManager.getOriginQueryPlan();
- Map<String, List<Path>> selectSeriesByGroupId = singleQueryManager.getSelectSeriesByGroupId();
- Map<String, QueryPlan> selectPathPlans = singleQueryManager.getSelectPathPlans();
- List<Path> selectPaths = queryPlan.getPaths();
- for (Path path : selectPaths) {
- String groupId = QPExecutorUtils.getGroupIdByDevice(path.getDevice());
- if (!selectSeriesByGroupId.containsKey(groupId)) {
- selectSeriesByGroupId.put(groupId, new ArrayList<>());
- }
- selectSeriesByGroupId.get(groupId).add(path);
- }
- for (Entry<String, List<Path>> entry : selectSeriesByGroupId.entrySet()) {
- String groupId = entry.getKey();
- List<Path> paths = entry.getValue();
- QueryPlan subQueryPlan = new QueryPlan();
- subQueryPlan.setProposer(queryPlan.getProposer());
- subQueryPlan.setPaths(paths);
- subQueryPlan.setExpression(queryPlan.getExpression());
- selectPathPlans.put(groupId, subQueryPlan);
- }
- }
-
- /**
- * Split query plan with filter.
- */
- public static void splitQueryPlanWithValueFilter(
- ClusterRpcSingleQueryManager singleQueryManager) throws PathErrorException {
- QueryPlan queryPlan = singleQueryManager.getOriginQueryPlan();
- if (queryPlan instanceof GroupByPlan) {
- splitGroupByPlan((GroupByPlan) queryPlan, singleQueryManager);
- } else if (queryPlan instanceof AggregationPlan) {
- splitAggregationPlan((AggregationPlan) queryPlan, singleQueryManager);
- } else {
- splitQueryPlan(queryPlan, singleQueryManager);
- }
- }
-
- private static void splitGroupByPlan(GroupByPlan queryPlan,
- ClusterRpcSingleQueryManager singleQueryManager) {
- throw new UnsupportedOperationException();
- }
-
- private static void splitAggregationPlan(AggregationPlan aggregationPlan,
- ClusterRpcSingleQueryManager singleQueryManager) {
- throw new UnsupportedOperationException();
- }
-
- private static void splitQueryPlan(QueryPlan queryPlan,
- ClusterRpcSingleQueryManager singleQueryManager) throws PathErrorException {
- splitQueryPlanBySelectPath(singleQueryManager);
- // split query plan by filter path
- Map<String, FilterGroupEntity> filterGroupEntityMap = singleQueryManager
- .getFilterGroupEntityMap();
- IExpression expression = queryPlan.getExpression();
- ExpressionUtils.getAllExpressionSeries(expression, filterGroupEntityMap);
- for (FilterGroupEntity filterGroupEntity : filterGroupEntityMap.values()) {
- List<Path> filterSeriesList = filterGroupEntity.getFilterPaths();
- // create filter sub query plan
- QueryPlan subQueryPlan = new QueryPlan();
- subQueryPlan.setPaths(filterSeriesList);
- IExpression subExpression = ExpressionUtils
- .pruneFilterTree(expression.clone(), filterSeriesList);
- if (subExpression.getType() != ExpressionType.TRUE) {
- subQueryPlan.setExpression(subExpression);
- }
- filterGroupEntity.setQueryPlan(subQueryPlan);
- }
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/processor/querydata/CloseSeriesReaderSyncProcessor.java b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/processor/querydata/CloseSeriesReaderSyncProcessor.java
deleted file mode 100644
index f6ec67a..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/processor/querydata/CloseSeriesReaderSyncProcessor.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * 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.cluster.rpc.raft.processor.querydata;
-
-import com.alipay.remoting.BizContext;
-import org.apache.iotdb.cluster.query.manager.querynode.ClusterLocalQueryManager;
-import org.apache.iotdb.cluster.rpc.raft.processor.BasicSyncUserProcessor;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.CloseSeriesReaderRequest;
-import org.apache.iotdb.cluster.rpc.raft.response.querydata.QuerySeriesDataResponse;
-
-public class CloseSeriesReaderSyncProcessor extends
- BasicSyncUserProcessor<CloseSeriesReaderRequest> {
-
- @Override
- public Object handleRequest(BizContext bizContext, CloseSeriesReaderRequest request)
- throws Exception {
- String groupId = request.getGroupID();
- QuerySeriesDataResponse response = new QuerySeriesDataResponse(groupId);
- ClusterLocalQueryManager.getInstance().close(request.getTaskId());
- return response;
- }
-
- @Override
- public String interest() {
- return CloseSeriesReaderRequest.class.getName();
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/processor/querydata/InitSeriesReaderSyncProcessor.java b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/processor/querydata/InitSeriesReaderSyncProcessor.java
deleted file mode 100644
index 7474eec..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/processor/querydata/InitSeriesReaderSyncProcessor.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * 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.cluster.rpc.raft.processor.querydata;
-
-import com.alipay.remoting.BizContext;
-import com.alipay.sofa.jraft.Status;
-import org.apache.iotdb.cluster.config.ClusterConstant;
-import org.apache.iotdb.cluster.query.manager.querynode.ClusterLocalQueryManager;
-import org.apache.iotdb.cluster.rpc.raft.processor.BasicSyncUserProcessor;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.InitSeriesReaderRequest;
-import org.apache.iotdb.cluster.utils.QPExecutorUtils;
-import org.apache.iotdb.cluster.utils.RaftUtils;
-import org.apache.iotdb.db.exception.ProcessorException;
-
-public class InitSeriesReaderSyncProcessor extends BasicSyncUserProcessor<InitSeriesReaderRequest> {
-
- @Override
- public Object handleRequest(BizContext bizContext, InitSeriesReaderRequest request)
- throws Exception {
- String groupId = request.getGroupID();
- handleNullRead(request.getReadConsistencyLevel(), groupId);
- return ClusterLocalQueryManager.getInstance().createQueryDataSet(request);
- }
-
- /**
- * It's necessary to do null read while creating query data set with a strong consistency level
- * and local node is not the leader of data group
- *
- * @param readConsistencyLevel read concistency level
- * @param groupId group id
- */
- private void handleNullRead(int readConsistencyLevel, String groupId) throws ProcessorException {
- if (readConsistencyLevel == ClusterConstant.STRONG_CONSISTENCY_LEVEL && !QPExecutorUtils
- .checkDataGroupLeader(groupId)) {
- Status nullReadTaskStatus = Status.OK();
- RaftUtils.handleNullReadToDataGroup(nullReadTaskStatus, groupId);
- if (!nullReadTaskStatus.isOk()) {
- throw new ProcessorException("Null read to data group failed");
- }
- }
- }
-
- @Override
- public String interest() {
- return InitSeriesReaderRequest.class.getName();
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/processor/querydata/QuerySeriesDataByTimestampSyncProcessor.java b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/processor/querydata/QuerySeriesDataByTimestampSyncProcessor.java
deleted file mode 100644
index ae3f057..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/processor/querydata/QuerySeriesDataByTimestampSyncProcessor.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.cluster.rpc.raft.processor.querydata;
-
-import com.alipay.remoting.BizContext;
-import org.apache.iotdb.cluster.query.manager.querynode.ClusterLocalQueryManager;
-import org.apache.iotdb.cluster.rpc.raft.processor.BasicSyncUserProcessor;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.QuerySeriesDataByTimestampRequest;
-
-public class QuerySeriesDataByTimestampSyncProcessor extends BasicSyncUserProcessor<QuerySeriesDataByTimestampRequest> {
-
- @Override
- public Object handleRequest(BizContext bizContext,
- QuerySeriesDataByTimestampRequest request) throws Exception {
- return ClusterLocalQueryManager.getInstance().readBatchDataByTimestamp(request);
- }
-
- @Override
- public String interest() {
- return QuerySeriesDataByTimestampRequest.class.getName();
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/processor/querydata/QuerySeriesDataSyncProcessor.java b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/processor/querydata/QuerySeriesDataSyncProcessor.java
deleted file mode 100644
index 4c8e599..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/processor/querydata/QuerySeriesDataSyncProcessor.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.cluster.rpc.raft.processor.querydata;
-
-import com.alipay.remoting.BizContext;
-import org.apache.iotdb.cluster.query.manager.querynode.ClusterLocalQueryManager;
-import org.apache.iotdb.cluster.rpc.raft.processor.BasicSyncUserProcessor;
-import org.apache.iotdb.cluster.rpc.raft.request.querydata.QuerySeriesDataRequest;
-
-public class QuerySeriesDataSyncProcessor extends
- BasicSyncUserProcessor<QuerySeriesDataRequest> {
-
- @Override
- public Object handleRequest(BizContext bizContext, QuerySeriesDataRequest request)
- throws Exception {
- return ClusterLocalQueryManager.getInstance().readBatchData(request);
- }
-
- @Override
- public String interest() {
- return QuerySeriesDataRequest.class.getName();
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/request/querydata/CloseSeriesReaderRequest.java b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/request/querydata/CloseSeriesReaderRequest.java
deleted file mode 100644
index 1a3cf3c..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/request/querydata/CloseSeriesReaderRequest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * 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.cluster.rpc.raft.request.querydata;
-
-import org.apache.iotdb.cluster.rpc.raft.request.BasicQueryRequest;
-
-/**
- * Release series reader resource in remote query node
- */
-public class CloseSeriesReaderRequest extends BasicQueryRequest {
-
- private static final long serialVersionUID = 1369515842480836991L;
-
- /**
- * Unique task id which is assigned in coordinator node
- */
- private String taskId;
-
- private CloseSeriesReaderRequest(String groupID, String taskId) {
- super(groupID);
- this.taskId = taskId;
- }
-
- public static CloseSeriesReaderRequest createReleaseResourceRequest(String groupId, String taskId) {
- return new CloseSeriesReaderRequest(groupId, taskId);
- }
-
- public String getTaskId() {
- return taskId;
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/request/querydata/InitSeriesReaderRequest.java b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/request/querydata/InitSeriesReaderRequest.java
deleted file mode 100644
index c974e2f..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/request/querydata/InitSeriesReaderRequest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * 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.cluster.rpc.raft.request.querydata;
-
-import java.util.ArrayList;
-import java.util.EnumMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.iotdb.cluster.query.PathType;
-import org.apache.iotdb.cluster.rpc.raft.request.BasicQueryRequest;
-import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-
-/**
- * Initially create corresponding series readers in remote query node
- */
-public class InitSeriesReaderRequest extends BasicQueryRequest {
-
- private static final long serialVersionUID = 8374330837710097285L;
-
- /**
- * Unique task id which is assigned in coordinator node
- */
- private String taskId;
-
- /**
- * Key is series type, value is query plan
- */
- private Map<PathType, QueryPlan> allQueryPlan = new EnumMap<>(PathType.class);
-
- /**
- * Represent all filter of leaf node in filter tree while executing a query with value filter.
- */
- private List<Filter> filterList = new ArrayList<>();
-
-
- private InitSeriesReaderRequest(String groupID, String taskId) {
- super(groupID);
- this.taskId = taskId;
- }
-
- public static InitSeriesReaderRequest createInitialQueryRequest(String groupId, String taskId, int readConsistencyLevel,
- Map<PathType, QueryPlan> allQueryPlan, List<Filter> filterList){
- InitSeriesReaderRequest request = new InitSeriesReaderRequest(groupId, taskId);
- request.setReadConsistencyLevel(readConsistencyLevel);
- request.allQueryPlan = allQueryPlan;
- request.filterList = filterList;
- return request;
- }
-
- public String getTaskId() {
- return taskId;
- }
-
- public void setTaskId(String taskId) {
- this.taskId = taskId;
- }
-
- public Map<PathType, QueryPlan> getAllQueryPlan() {
- return allQueryPlan;
- }
-
- public void setAllQueryPlan(
- Map<PathType, QueryPlan> allQueryPlan) {
- this.allQueryPlan = allQueryPlan;
- }
-
- public List<Filter> getFilterList() {
- return filterList;
- }
-
- public void setFilterList(List<Filter> filterList) {
- this.filterList = filterList;
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/request/querydata/QuerySeriesDataByTimestampRequest.java b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/request/querydata/QuerySeriesDataByTimestampRequest.java
deleted file mode 100644
index 351e6eb..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/request/querydata/QuerySeriesDataByTimestampRequest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * 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.cluster.rpc.raft.request.querydata;
-
-import java.util.List;
-import org.apache.iotdb.cluster.rpc.raft.request.BasicQueryRequest;
-
-public class QuerySeriesDataByTimestampRequest extends BasicQueryRequest {
-
- private static final long serialVersionUID = 4942493162179531133L;
- /**
- * Rounds number of query
- */
- private long queryRounds;
-
- /**
- * Unique task id which is assigned in coordinator node
- */
- private String taskId;
-
- /**
- * Batch valid timestamp
- */
- private List<Long> batchTimestamp;
-
- /**
- * Series to fetch data from remote query node
- */
- private List<String> fetchDataSeries;
-
- private QuerySeriesDataByTimestampRequest(String groupID) {
- super(groupID);
- }
-
- public static QuerySeriesDataByTimestampRequest createRequest(String groupId, long queryRounds, String taskId, List<Long> batchTimestamp, List<String> fetchDataSeries){
- QuerySeriesDataByTimestampRequest request = new QuerySeriesDataByTimestampRequest(groupId);
- request.queryRounds = queryRounds;
- request.taskId = taskId;
- request.batchTimestamp = batchTimestamp;
- request.fetchDataSeries = fetchDataSeries;
- return request;
- }
-
- public long getQueryRounds() {
- return queryRounds;
- }
-
- public void setQueryRounds(long queryRounds) {
- this.queryRounds = queryRounds;
- }
-
- public String getTaskId() {
- return taskId;
- }
-
- public void setTaskId(String taskId) {
- this.taskId = taskId;
- }
-
- public List<Long> getBatchTimestamp() {
- return batchTimestamp;
- }
-
- public void setBatchTimestamp(List<Long> batchTimestamp) {
- this.batchTimestamp = batchTimestamp;
- }
-
- public List<String> getFetchDataSeries() {
- return fetchDataSeries;
- }
-
- public void setFetchDataSeries(List<String> fetchDataSeries) {
- this.fetchDataSeries = fetchDataSeries;
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/request/querydata/QuerySeriesDataRequest.java b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/request/querydata/QuerySeriesDataRequest.java
deleted file mode 100644
index 554b8c1..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/request/querydata/QuerySeriesDataRequest.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * 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.cluster.rpc.raft.request.querydata;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.iotdb.cluster.query.PathType;
-import org.apache.iotdb.cluster.rpc.raft.request.BasicQueryRequest;
-
-/**
- * Read batch data from series reader from remote query node.
- */
-public class QuerySeriesDataRequest extends BasicQueryRequest {
-
- private static final long serialVersionUID = 7132891920951977625L;
-
- /**
- * Rounds number of query
- */
- private long queryRounds;
-
- /**
- * Unique task id which is assigned in coordinator node
- */
- private String taskId;
-
- /**
- * Series type
- */
- private PathType pathType;
-
- /**
- * Key is series type, value is series list
- */
- private List<String> seriesPaths = new ArrayList<>();
-
- private QuerySeriesDataRequest(String groupID, String taskId) {
- super(groupID);
- this.taskId = taskId;
- }
-
- public static QuerySeriesDataRequest createFetchDataRequest(String groupId, String taskId,
- PathType pathType, List<String> seriesPaths, long queryRounds) {
- QuerySeriesDataRequest request = new QuerySeriesDataRequest(groupId, taskId);
- request.pathType = pathType;
- request.seriesPaths = seriesPaths;
- request.queryRounds = queryRounds;
- return request;
- }
-
- public long getQueryRounds() {
- return queryRounds;
- }
-
- public void setQueryRounds(long queryRounds) {
- this.queryRounds = queryRounds;
- }
-
- public String getTaskId() {
- return taskId;
- }
-
- public void setTaskId(String taskId) {
- this.taskId = taskId;
- }
-
- public PathType getPathType() {
- return pathType;
- }
-
- public void setPathType(PathType pathType) {
- this.pathType = pathType;
- }
-
- public List<String> getSeriesPaths() {
- return seriesPaths;
- }
-
- public void setSeriesPaths(List<String> seriesPaths) {
- this.seriesPaths = seriesPaths;
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/response/querydata/InitSeriesReaderResponse.java b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/response/querydata/InitSeriesReaderResponse.java
deleted file mode 100644
index e30a288..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/response/querydata/InitSeriesReaderResponse.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * 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.cluster.rpc.raft.response.querydata;
-
-import java.util.EnumMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.iotdb.cluster.query.PathType;
-import org.apache.iotdb.cluster.rpc.raft.response.BasicQueryDataResponse;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
-
-public class InitSeriesReaderResponse extends BasicQueryDataResponse {
-
- private static final long serialVersionUID = 6298440729566956283L;
-
- private Map<PathType, List<TSDataType>> seriesDataTypes = new EnumMap<>(PathType.class);
-
- /**
- * Series type
- */
- private PathType pathType;
-
- public InitSeriesReaderResponse(String groupId) {
- super(groupId, false, null, null);
- }
-
- public Map<PathType, List<TSDataType>> getSeriesDataTypes() {
- return seriesDataTypes;
- }
-
- public void setSeriesDataTypes(
- Map<PathType, List<TSDataType>> seriesDataTypes) {
- this.seriesDataTypes = seriesDataTypes;
- }
-
- public PathType getPathType() {
- return pathType;
- }
-
- public void setPathType(PathType pathType) {
- this.pathType = pathType;
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/response/querydata/QuerySeriesDataByTimestampResponse.java b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/response/querydata/QuerySeriesDataByTimestampResponse.java
deleted file mode 100644
index f3417b7..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/response/querydata/QuerySeriesDataByTimestampResponse.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.cluster.rpc.raft.response.querydata;
-
-import org.apache.iotdb.cluster.rpc.raft.response.BasicQueryDataResponse;
-
-public class QuerySeriesDataByTimestampResponse extends BasicQueryDataResponse {
-
- private static final long serialVersionUID = -9015865924302417289L;
-
- public QuerySeriesDataByTimestampResponse(String groupId) {
- super(groupId, false, null, null);
- }
-
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/response/querydata/QuerySeriesDataResponse.java b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/response/querydata/QuerySeriesDataResponse.java
deleted file mode 100644
index b4586bd..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/response/querydata/QuerySeriesDataResponse.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * 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.cluster.rpc.raft.response.querydata;
-
-import org.apache.iotdb.cluster.query.PathType;
-import org.apache.iotdb.cluster.rpc.raft.response.BasicQueryDataResponse;
-
-public class QuerySeriesDataResponse extends BasicQueryDataResponse {
-
- private static final long serialVersionUID = -4783032133961145205L;
-
- /**
- * Series type
- */
- private PathType pathType;
-
- public QuerySeriesDataResponse(String groupId) {
- super(groupId, false, null, null);
- }
-
- public PathType getPathType() {
- return pathType;
- }
-
- public void setPathType(PathType pathType) {
- this.pathType = pathType;
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/service/ClusterMonitor.java b/cluster/src/main/java/org/apache/iotdb/cluster/service/ClusterMonitor.java
deleted file mode 100644
index 5e14e0b..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/service/ClusterMonitor.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/**
- * 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.cluster.service;
-
-import com.alipay.sofa.jraft.entity.PeerId;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.iotdb.cluster.utils.RaftUtils;
-import org.apache.iotdb.db.exception.StartupException;
-import org.apache.iotdb.db.service.IService;
-import org.apache.iotdb.db.service.JMXService;
-import org.apache.iotdb.db.service.ServiceType;
-
-public class ClusterMonitor implements ClusterMonitorMBean, IService {
-
- /**
- * Original format = String.format("%s:%s=%s",
- * IoTDBConstant.IOTDB_PACKAGE, IoTDBConstant.JMX_TYPE, getID().getJmxName()
- */
- public static final String MBEAN_NAME = "org.apache.iotdb.service:type=Cluster Monitor";
-
- public static final ClusterMonitor INSTANCE = new ClusterMonitor();
-
- public String getMbeanName() {
- return MBEAN_NAME;
- }
-
- @Override
- public void start() throws StartupException {
- try {
- JMXService.registerMBean(INSTANCE, MBEAN_NAME);
- } catch (Exception e) {
- String errorMessage = String
- .format("Failed to start %s because of %s", this.getID().getName(),
- e.getMessage());
- throw new StartupException(errorMessage);
- }
- }
-
- @Override
- public void stop() {
- JMXService.deregisterMBean(MBEAN_NAME);
- }
-
- @Override
- public ServiceType getID() {
- return ServiceType.CLUSTER_MONITOR_SERVICE;
- }
-
- @Override
- public Map<Integer, String> getPhysicalRing() {
- return RaftUtils.getPhysicalRing();
- }
-
- @Override
- public Map<Integer, String> getVirtualRing() {
- return RaftUtils.getVirtualRing();
- }
-
- @Override
- public Map<String, String> getAllLeaders() {
- Map<String, String> map = new HashMap<>();
- RaftUtils.getGroupLeaderCache().entrySet().forEach(entry -> map.put(entry.getKey(), entry.getValue().toString()));
- return map;
- }
-
- @Override
- public String getDataPartitionOfSG(String sg) {
- PeerId[] nodes = RaftUtils.getDataPartitionOfSG(sg);
- StringBuilder builder = new StringBuilder();
- builder.append(nodes[0].getIp()).append(" (leader)");
- for (int i = 1; i < nodes.length; i++) {
- builder.append(", ").append(nodes[i].getIp());
- }
- return builder.toString();
- }
-
- @Override
- public Map<String[], String[]> getDataPartitonOfNode(String ip) {
- return RaftUtils.getDataPartitionOfNode(ip);
- }
-
- @Override
- public Map<String[], String[]> getDataPartitonOfNode(String ip, int port) {
- return RaftUtils.getDataPartitionOfNode(ip, port);
- }
-
- @Override
- public Map<String, Map<String, Long>> getReplicaLagMap() {
- return RaftUtils.getReplicaLagMap();
- }
-
- @Override
- public Map<String, Integer> getQueryJobNumMap() {
- return RaftUtils.getQueryJobNumMap();
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/service/ClusterMonitorMBean.java b/cluster/src/main/java/org/apache/iotdb/cluster/service/ClusterMonitorMBean.java
deleted file mode 100644
index 5fe4c53..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/service/ClusterMonitorMBean.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * 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.cluster.service;
-
-import java.util.Map;
-
-public interface ClusterMonitorMBean {
-
- /**
- * Get physical hash ring
- *
- * @return key: hash value, value: node ip
- */
- Map<Integer, String> getPhysicalRing();
-
- /**
- * Get virtual hash ring
- *
- * @return key: hash value, value: node ip
- */
- Map<Integer, String> getVirtualRing();
-
- /**
- * Get currents leaders of each data partition
- *
- * @return key: group id, value: leader node ip
- */
- Map<String, String> getAllLeaders();
-
- /**
- * Get data partition information of input storage group in String format. The node ips are split
- * by ',', and the first ip is the currnt leader.
- *
- * @param sg input storage group path
- * @return data partition information in String format
- */
- String getDataPartitionOfSG(String sg);
-
- /**
- * Get data partitions that input node belongs to.
- *
- * @param ip node ip
- * @param port node rpc port
- * @return key: node ips of one data partition, value: storage group paths that belong to this
- * data partition
- */
- Map<String[], String[]> getDataPartitonOfNode(String ip, int port);
- Map<String[], String[]> getDataPartitonOfNode(String ip);
-
- /**
- * Get replica lag for metadata group and each data partition
- *
- * @return key: groupId, value: ip -> replica lag
- */
- Map<String, Map<String, Long>> getReplicaLagMap();
-
- /**
- * Get number of query jobs for each data partition
- *
- * @return key: groupId, value: number of query jobs
- */
- Map<String, Integer> getQueryJobNumMap();
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/service/TSServiceClusterImpl.java b/cluster/src/main/java/org/apache/iotdb/cluster/service/TSServiceClusterImpl.java
index ff716a3..a46087e 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/service/TSServiceClusterImpl.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/service/TSServiceClusterImpl.java
@@ -21,9 +21,7 @@ package org.apache.iotdb.cluster.service;
import java.io.IOException;
import java.sql.Statement;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -32,29 +30,19 @@ import org.apache.iotdb.cluster.exception.ConsistencyLevelException;
import org.apache.iotdb.cluster.qp.executor.ClusterQueryProcessExecutor;
import org.apache.iotdb.cluster.qp.executor.NonQueryExecutor;
import org.apache.iotdb.cluster.qp.executor.QueryMetadataExecutor;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcQueryManager;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.IClusterRpcQueryManager;
import org.apache.iotdb.db.auth.AuthException;
import org.apache.iotdb.db.conf.IoTDBConstant;
-import org.apache.iotdb.db.exception.FileNodeManagerException;
import org.apache.iotdb.db.exception.PathErrorException;
import org.apache.iotdb.db.exception.ProcessorException;
import org.apache.iotdb.db.metadata.Metadata;
import org.apache.iotdb.db.qp.QueryProcessor;
import org.apache.iotdb.db.qp.physical.PhysicalPlan;
-import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
-import org.apache.iotdb.db.query.context.QueryContext;
-import org.apache.iotdb.db.query.control.QueryResourceManager;
import org.apache.iotdb.db.service.TSServiceImpl;
-import org.apache.iotdb.service.rpc.thrift.TSCloseOperationReq;
import org.apache.iotdb.service.rpc.thrift.TSExecuteBatchStatementReq;
import org.apache.iotdb.service.rpc.thrift.TSExecuteBatchStatementResp;
-import org.apache.iotdb.service.rpc.thrift.TSFetchResultsReq;
import org.apache.iotdb.service.rpc.thrift.TS_StatusCode;
-import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.read.common.Path;
-import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
import org.apache.thrift.TException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -70,8 +58,6 @@ public class TSServiceClusterImpl extends TSServiceImpl {
private NonQueryExecutor nonQueryExecutor = new NonQueryExecutor();
private QueryMetadataExecutor queryMetadataExecutor = new QueryMetadataExecutor();
- private IClusterRpcQueryManager queryManager = ClusterRpcQueryManager.getInstance();
-
public TSServiceClusterImpl() throws IOException {
super();
processor = new QueryProcessor(queryDataExecutor);
@@ -272,45 +258,6 @@ public class TSServiceClusterImpl extends TSServiceImpl {
}
@Override
- protected void releaseQueryResource(TSCloseOperationReq req) throws Exception {
- Map<Long, QueryContext> contextMap = contextMapLocal.get();
- if (contextMap == null) {
- return;
- }
- if (req == null || req.queryId == -1) {
- // end query for all the query tokens created by current thread
- for (QueryContext context : contextMap.values()) {
- QueryResourceManager.getInstance().endQueryForGivenJob(context.getJobId());
- queryManager.releaseQueryResource(context.getJobId());
- }
- contextMapLocal.set(new HashMap<>());
- } else {
- long jobId = contextMap.remove(req.queryId).getJobId();
- QueryResourceManager.getInstance().endQueryForGivenJob(jobId);
- queryManager.releaseQueryResource(jobId);
- }
- }
-
- @Override
- protected QueryDataSet createNewDataSet(String statement, int fetchSize, TSFetchResultsReq req)
- throws PathErrorException, QueryFilterOptimizationException, FileNodeManagerException,
- ProcessorException, IOException {
- PhysicalPlan physicalPlan = queryStatus.get().get(statement);
- processor.getExecutor().setFetchSize(fetchSize);
-
- long jobId = QueryResourceManager.getInstance().assignJobId();
- QueryContext context = new QueryContext(jobId);
- initContextMap();
- contextMapLocal.get().put(req.queryId, context);
-
- queryManager.addSingleQuery(jobId, (QueryPlan) physicalPlan);
- QueryDataSet queryDataSet = processor.getExecutor().processQuery((QueryPlan) physicalPlan,
- context);
- queryRet.get().put(statement, queryDataSet);
- return queryDataSet;
- }
-
- @Override
public void handleClientExit() throws TException {
closeClusterService();
closeOperation(null);
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/Host.java b/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/Host.java
deleted file mode 100644
index 21b02be..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/Host.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * 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.cluster.service.nodetool;
-
-import io.airlift.airline.Command;
-import io.airlift.airline.Option;
-import java.util.Map;
-import java.util.Map.Entry;
-import org.apache.iotdb.cluster.service.nodetool.NodeTool.NodeToolCmd;
-import org.apache.iotdb.cluster.service.ClusterMonitorMBean;
-
-@Command(name = "host", description = "Print all data partitions information which specific host belongs to")
-public class Host extends NodeToolCmd {
-
- private static final int DEFAULT_PORT = -1;
-
- @Option(title = "ip", name = {"-i", "--ip"}, description = "Specify the host ip for accurate hosts information")
- private String ip = "127.0.0.1";
-
- @Option(title = "port", name = {"-p", "--port"}, description = "Specify the host port for accurate hosts information")
- private int port = DEFAULT_PORT;
-
- @Option(title = "sg_detail", name = {"-d", "--detail"}, description = "Show path of storage groups")
- private boolean detail = false;
-
- @Override
- public void execute(ClusterMonitorMBean proxy) {
- Map<String[], String[]> map;
- if (port == DEFAULT_PORT) {
- map = proxy.getDataPartitonOfNode(ip);
- } else {
- map = proxy.getDataPartitonOfNode(ip, port);
- }
-
- if (map == null) {
- System.out.println("Can't find the input IP.");
- return;
- }
-
- for (Entry<String[], String[]> entry : map.entrySet()) {
- StringBuilder builder = new StringBuilder();
- String[] ips = entry.getKey();
- String[] sgs = entry.getValue();
- builder.append('(');
- for (int i = 0; i < ips.length; i++) {
- builder.append(ips[i]).append(", ");
- }
- builder.delete(builder.length() - 2, builder.length());
- builder.append(')');
-
- builder.append("\t->\t");
- if (detail) {
- builder.append('(');
- for (int i = 0; i < sgs.length; i++) {
- builder.append(sgs[i]).append(", ");
- }
- if (sgs.length > 0) {
- builder.delete(builder.length() - 2, builder.length());
- }
- builder.append(')');
- } else {
- builder.append(sgs.length);
- }
-
- System.out.println(builder.toString());
- }
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/Lag.java b/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/Lag.java
deleted file mode 100644
index 1cc852b..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/Lag.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * 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.cluster.service.nodetool;
-
-import io.airlift.airline.Command;
-import java.util.Map;
-import java.util.Map.Entry;
-import org.apache.iotdb.cluster.service.nodetool.NodeTool.NodeToolCmd;
-import org.apache.iotdb.cluster.service.ClusterMonitorMBean;
-
-@Command(name = "lag", description = "Print log lag for all groups of connected host")
-public class Lag extends NodeToolCmd {
-
- @Override
- public void execute(ClusterMonitorMBean proxy)
- {
- Map<String, Map<String, Long>> groupMap = proxy.getReplicaLagMap();
- for (Entry<String, Map<String, Long>> entry : groupMap.entrySet()) {
- if (entry.getValue() == null) {
- continue;
- }
- System.out.println(entry.getKey() + ":");
- entry.getValue().forEach((node, lag) -> System.out.println("\t" + node + "\t->\t" + lag));
- }
- }
-}
\ No newline at end of file
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/NodeTool.java b/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/NodeTool.java
deleted file mode 100644
index 64bb52b..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/NodeTool.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/**
- * 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.cluster.service.nodetool;
-
-import static java.lang.String.format;
-
-import com.google.common.base.Throwables;
-import com.google.common.collect.Lists;
-import io.airlift.airline.Cli;
-import io.airlift.airline.Help;
-import io.airlift.airline.Option;
-import io.airlift.airline.OptionType;
-import io.airlift.airline.ParseArgumentsMissingException;
-import io.airlift.airline.ParseArgumentsUnexpectedException;
-import io.airlift.airline.ParseCommandMissingException;
-import io.airlift.airline.ParseCommandUnrecognizedException;
-import io.airlift.airline.ParseOptionConversionException;
-import io.airlift.airline.ParseOptionMissingException;
-import io.airlift.airline.ParseOptionMissingValueException;
-import java.io.IOException;
-import java.util.List;
-import javax.management.JMX;
-import javax.management.MBeanServerConnection;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-import org.apache.iotdb.cluster.service.ClusterMonitor;
-import org.apache.iotdb.cluster.service.ClusterMonitorMBean;
-
-public class NodeTool {
-
- public static void main(String... args) {
- List<Class<? extends Runnable>> commands = Lists.newArrayList(
- Help.class,
- Ring.class,
- StorageGroup.class,
- Host.class,
- Lag.class,
- Query.class
- );
-
- Cli.CliBuilder<Runnable> builder = Cli.builder("nodetool");
-
- builder.withDescription("Manage your IoTDB cluster")
- .withDefaultCommand(Help.class)
- .withCommands(commands);
-
- Cli<Runnable> parser = builder.build();
-
- int status = 0;
- try {
- Runnable parse = parser.parse(args);
- parse.run();
- } catch (IllegalArgumentException |
- IllegalStateException |
- ParseArgumentsMissingException |
- ParseArgumentsUnexpectedException |
- ParseOptionConversionException |
- ParseOptionMissingException |
- ParseOptionMissingValueException |
- ParseCommandMissingException |
- ParseCommandUnrecognizedException e) {
- badUse(e);
- status = 1;
- } catch (Exception e) {
- err(Throwables.getRootCause(e));
- status = 2;
- }
-
- System.exit(status);
- }
-
- private static void badUse(Exception e) {
- System.out.println("nodetool: " + e.getMessage());
- System.out.println("See 'nodetool help' or 'nodetool help <command>'.");
- }
-
- private static void err(Throwable e) {
- System.err.println("error: " + e.getMessage());
- System.err.println("-- StackTrace --");
- System.err.println(Throwables.getStackTraceAsString(e));
- }
-
- public abstract static class NodeToolCmd implements Runnable {
-
- @Option(type = OptionType.GLOBAL, name = {"-h",
- "--host"}, description = "Node hostname or ip address")
- private String host = "127.0.0.1";
-
- @Option(type = OptionType.GLOBAL, name = {"-p",
- "--port"}, description = "Remote jmx agent port number")
- private String port = "31999";
-
- private static final String JMX_URL_FORMAT = "service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi";
-
- @Override
- public void run() {
- try {
- MBeanServerConnection mbsc = connect();
- ObjectName name = new ObjectName(ClusterMonitor.MBEAN_NAME);
- ClusterMonitorMBean clusterMonitorProxy = JMX
- .newMBeanProxy(mbsc, name, ClusterMonitorMBean.class);
- execute(clusterMonitorProxy);
- } catch (MalformedObjectNameException e) {
- e.printStackTrace();
- }
- }
-
- protected abstract void execute(ClusterMonitorMBean probe);
-
- private MBeanServerConnection connect() {
- MBeanServerConnection mbsc = null;
-
- try {
- String jmxURL = String.format(JMX_URL_FORMAT, host, port);
- JMXServiceURL serviceURL = new JMXServiceURL(jmxURL);
- JMXConnector connector = JMXConnectorFactory.connect(serviceURL);
- mbsc = connector.getMBeanServerConnection();
- } catch (IOException e) {
- Throwable rootCause = Throwables.getRootCause(e);
- System.err.println(format("nodetool: Failed to connect to '%s:%s' - %s: '%s'.", host, port,
- rootCause.getClass().getSimpleName(), rootCause.getMessage()));
- System.exit(1);
- }
-
- return mbsc;
- }
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/Query.java b/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/Query.java
deleted file mode 100644
index 2acd2ee..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/Query.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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.cluster.service.nodetool;
-
-import io.airlift.airline.Command;
-import java.util.Map;
-import org.apache.iotdb.cluster.service.nodetool.NodeTool.NodeToolCmd;
-import org.apache.iotdb.cluster.service.ClusterMonitorMBean;
-
-@Command(name = "query", description = "Print number of query jobs for all data partitions of connected host")
-public class Query extends NodeToolCmd {
-
- @Override
- public void execute(ClusterMonitorMBean proxy)
- {
- Map<String, Integer> queryNumMap = proxy.getQueryJobNumMap();
- queryNumMap.forEach((groupId, num) -> System.out.println(groupId + "\t->\t" + num));
- int sum = queryNumMap.values().stream().mapToInt(num -> num).sum();
- System.out.println("Total\t->\t" + sum);
- }
-}
\ No newline at end of file
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/Ring.java b/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/Ring.java
deleted file mode 100644
index 9de9274..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/Ring.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.cluster.service.nodetool;
-
-import io.airlift.airline.Command;
-import io.airlift.airline.Option;
-import java.util.Map;
-import org.apache.iotdb.cluster.service.ClusterMonitorMBean;
-import org.apache.iotdb.cluster.service.nodetool.NodeTool.NodeToolCmd;
-
-@Command(name = "ring", description = "Print information about the hash ring")
-public class Ring extends NodeToolCmd {
- @Option(title = "physical_ring", name = {"-p", "--physical"}, description = "Show physical nodes instead of virtual ones")
- private boolean physical = false;
-
- @Override
- public void execute(ClusterMonitorMBean proxy)
- {
- Map<Integer, String> map = physical ? proxy.getPhysicalRing() : proxy.getVirtualRing();
- map.forEach((hash, ip) -> System.out.println(hash + "\t->\t" + ip));
- }
-}
\ No newline at end of file
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/StorageGroup.java b/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/StorageGroup.java
deleted file mode 100644
index 727e9eb..0000000
--- a/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/StorageGroup.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.cluster.service.nodetool;
-
-import io.airlift.airline.Command;
-import io.airlift.airline.Option;
-import org.apache.iotdb.cluster.service.ClusterMonitorMBean;
-import org.apache.iotdb.cluster.service.nodetool.NodeTool.NodeToolCmd;
-
-@Command(name = "storagegroup", description = "Print all hosts information of specific storage group")
-public class StorageGroup extends NodeToolCmd {
-
- @Option(title = "storage group", name = {"-sg",
- "--storagegroup"}, description = "Specify a storage group for accurate hosts information")
- private String sg = null;
-
- @Override
- public void execute(ClusterMonitorMBean proxy) {
- String nodes = proxy.getDataPartitionOfSG(sg);
- System.out.println(nodes);
- }
-}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java b/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java
index d5486fb..27ea378 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java
@@ -54,7 +54,6 @@ import org.apache.iotdb.cluster.exception.RaftConnectionException;
import org.apache.iotdb.cluster.qp.task.QPTask;
import org.apache.iotdb.cluster.qp.task.QPTask.TaskState;
import org.apache.iotdb.cluster.qp.task.SingleQPTask;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcQueryManager;
import org.apache.iotdb.cluster.rpc.raft.NodeAsClient;
import org.apache.iotdb.cluster.rpc.raft.closure.ResponseClosure;
import org.apache.iotdb.cluster.rpc.raft.impl.RaftNodeAsClientManager;
@@ -572,15 +571,6 @@ public class RaftUtils {
}
/**
- * Get query job number running on each data partition
- *
- * @return key: data partition ID, value: query job number
- */
- public static Map<String, Integer> getQueryJobNumMap() {
- return ClusterRpcQueryManager.getInstance().getAllReadUsage();
- }
-
- /**
* try to get raft rpc client
*/
public static NodeAsClient getRaftNodeAsClient() throws RaftConnectionException {
diff --git a/cluster/src/test/java/org/apache/iotdb/cluster/query/ClusterQueryLargeDataTest.java b/cluster/src/test/java/org/apache/iotdb/cluster/query/ClusterQueryLargeDataTest.java
deleted file mode 100644
index 223f0dc..0000000
--- a/cluster/src/test/java/org/apache/iotdb/cluster/query/ClusterQueryLargeDataTest.java
+++ /dev/null
@@ -1,507 +0,0 @@
-/**
- * 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.cluster.query;
-
-import static org.apache.iotdb.cluster.utils.Utils.insertData;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.iotdb.cluster.config.ClusterConfig;
-import org.apache.iotdb.cluster.config.ClusterDescriptor;
-import org.apache.iotdb.cluster.entity.Server;
-import org.apache.iotdb.cluster.utils.EnvironmentUtils;
-import org.apache.iotdb.cluster.utils.hash.PhysicalNode;
-import org.apache.iotdb.jdbc.Config;
-import org.apache.iotdb.jdbc.IoTDBResultMetadata;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ClusterQueryLargeDataTest {
-
-
- private Server server;
- private static final ClusterConfig CLUSTER_CONFIG = ClusterDescriptor.getInstance().getConfig();
- private static final PhysicalNode localNode = new PhysicalNode(CLUSTER_CONFIG.getIp(),
- CLUSTER_CONFIG.getPort());
-
- private static final String URL = "127.0.0.1:6667/";
-
- private static final String[] createSQLs1 = {
- "SET STORAGE GROUP TO root.vehicle",
- "SET STORAGE GROUP TO root.test",
- "CREATE TIMESERIES root.vehicle.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE",
- "CREATE TIMESERIES root.vehicle.d0.s1 WITH DATATYPE=TEXT, ENCODING=PLAIN",
- "CREATE TIMESERIES root.vehicle.d1.s2 WITH DATATYPE=FLOAT, ENCODING=RLE",
- "CREATE TIMESERIES root.vehicle.d1.s3 WITH DATATYPE=BOOLEAN, ENCODING=PLAIN",
- "CREATE TIMESERIES root.test.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE",
- "CREATE TIMESERIES root.test.d0.s1 WITH DATATYPE=TEXT, ENCODING=PLAIN",
- "CREATE TIMESERIES root.test.d1.g0.s0 WITH DATATYPE=INT32, ENCODING=RLE"
- };
- private static final String[] insertSQLs1 = {
- "insert into root.vehicle.d0(timestamp,s0) values(10,100)",
- "insert into root.vehicle.d0(timestamp,s0,s1) values(12,101,'102')",
- "insert into root.vehicle.d0(timestamp,s1) values(19,'103')",
- "insert into root.vehicle.d1(timestamp,s2) values(11,104.0)",
- "insert into root.vehicle.d1(timestamp,s2,s3) values(15,105.0,true)",
- "insert into root.vehicle.d1(timestamp,s3) values(17,false)",
- "insert into root.vehicle.d0(timestamp,s0) values(20,1000)",
- "insert into root.vehicle.d0(timestamp,s0,s1) values(22,1001,'1002')",
- "insert into root.vehicle.d0(timestamp,s1) values(29,'1003')",
- "insert into root.vehicle.d1(timestamp,s2) values(21,1004.0)",
- "insert into root.vehicle.d1(timestamp,s2,s3) values(25,1005.0,true)",
- "insert into root.vehicle.d1(timestamp,s3) values(27,true)",
- "insert into root.test.d0(timestamp,s0) values(10,106)",
- "insert into root.test.d0(timestamp,s0,s1) values(14,107,'108')",
- "insert into root.test.d0(timestamp,s1) values(16,'109')",
- "insert into root.test.d1.g0(timestamp,s0) values(1,110)",
- "insert into root.test.d0(timestamp,s0) values(30,1006)",
- "insert into root.test.d0(timestamp,s0,s1) values(34,1007,'1008')",
- "insert into root.test.d0(timestamp,s1) values(36,'1090')",
- "insert into root.test.d1.g0(timestamp,s0) values(10,1100)"};
- private static final String[] insertSqls2 = {
- "insert into root.vehicle.d0(timestamp,s0) values(6,120)",
- "insert into root.vehicle.d0(timestamp,s0,s1) values(38,121,'122')",
- "insert into root.vehicle.d0(timestamp,s1) values(9,'123')",
- "insert into root.vehicle.d0(timestamp,s0) values(16,128)",
- "insert into root.vehicle.d0(timestamp,s0,s1) values(18,189,'198')",
- "insert into root.vehicle.d0(timestamp,s1) values(99,'1234')",
- "insert into root.vehicle.d1(timestamp,s2) values(14,1024.0)",
- "insert into root.vehicle.d1(timestamp,s2,s3) values(29,1205.0,true)",
- "insert into root.vehicle.d1(timestamp,s3) values(33,true)",
- "insert into root.test.d0(timestamp,s0) values(15,126)",
- "insert into root.test.d0(timestamp,s0,s1) values(8,127,'128')",
- "insert into root.test.d0(timestamp,s1) values(20,'129')",
- "insert into root.test.d1.g0(timestamp,s0) values(14,430)",
- "insert into root.test.d0(timestamp,s0) values(150,426)",
- "insert into root.test.d0(timestamp,s0,s1) values(80,427,'528')",
- "insert into root.test.d0(timestamp,s1) values(2,'1209')",
- "insert into root.test.d1.g0(timestamp,s0) values(4,330)"};
- private static final String[] createSQLs3 = {
- "SET STORAGE GROUP TO root.iotdb",
- "SET STORAGE GROUP TO root.cluster",
- "CREATE TIMESERIES root.iotdb.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE",
- "CREATE TIMESERIES root.iotdb.d0.s1 WITH DATATYPE=TEXT, ENCODING=PLAIN",
- "CREATE TIMESERIES root.iotdb.d1.s2 WITH DATATYPE=FLOAT, ENCODING=RLE",
- "CREATE TIMESERIES root.iotdb.d1.s3 WITH DATATYPE=BOOLEAN, ENCODING=PLAIN",
- "CREATE TIMESERIES root.cluster.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE",
- "CREATE TIMESERIES root.cluster.d0.s1 WITH DATATYPE=TEXT, ENCODING=PLAIN",
- "CREATE TIMESERIES root.cluster.d1.g0.s0 WITH DATATYPE=INT32, ENCODING=RLE"
- };
- private static final String[] insertSQLs3 = {
- "DELETE FROM root.vehicle WHERE time < 20",
- "DELETE FROM root.test WHERE time < 20",
- "insert into root.iotdb.d0(timestamp,s0) values(3,100)",
- "insert into root.iotdb.d0(timestamp,s0,s1) values(22,101,'102')",
- "insert into root.iotdb.d0(timestamp,s1) values(24,'103')",
- "insert into root.iotdb.d1(timestamp,s2) values(21,104.0)",
- "insert into root.iotdb.d1(timestamp,s2,s3) values(25,105.0,true)",
- "insert into root.iotdb.d1(timestamp,s3) values(27,false)",
- "insert into root.iotdb.d0(timestamp,s0) values(30,1000)",
- "insert into root.iotdb.d0(timestamp,s0,s1) values(202,101,'102')",
- "insert into root.iotdb.d0(timestamp,s1) values(44,'103')",
- "insert into root.iotdb.d1(timestamp,s2) values(1,404.0)",
- "insert into root.iotdb.d1(timestamp,s2,s3) values(250,10.0,true)",
- "insert into root.iotdb.d1(timestamp,s3) values(207,false)",
- "insert into root.cluster.d0(timestamp,s0) values(20,106)",
- "insert into root.cluster.d0(timestamp,s0,s1) values(14,107,'108')",
- "insert into root.cluster.d1.g0(timestamp,s0) values(1,110)",
- "insert into root.cluster.d0(timestamp,s0) values(200,1006)",
- "insert into root.cluster.d0(timestamp,s0,s1) values(1004,1007,'1080')",
- "insert into root.cluster.d1.g0(timestamp,s0) values(1000,910)",
- "insert into root.vehicle.d0(timestamp,s0) values(209,130)",
- "insert into root.vehicle.d0(timestamp,s0,s1) values(206,131,'132')",
- "insert into root.vehicle.d0(timestamp,s1) values(70,'33')",
- "insert into root.vehicle.d1(timestamp,s2) values(204,14.0)",
- "insert into root.vehicle.d1(timestamp,s2,s3) values(29,135.0,false)",
- "insert into root.vehicle.d1(timestamp,s3) values(14,false)",
- "insert into root.test.d0(timestamp,s0) values(19,136)",
- "insert into root.test.d0(timestamp,s0,s1) values(7,137,'138')",
- "insert into root.test.d0(timestamp,s1) values(30,'139')",
- "insert into root.test.d1.g0(timestamp,s0) values(4,150)",
- "insert into root.test.d0(timestamp,s0) values(1900,1316)",
- "insert into root.test.d0(timestamp,s0,s1) values(700,1307,'1038')",
- "insert into root.test.d0(timestamp,s1) values(3000,'1309')",
- "insert into root.test.d1.g0(timestamp,s0) values(400,1050)"
- };
-
- private static final String[] querys1 ={
- "select * from root.vehicle",
- "select * from root.test",
- "select * from root.vehicle,root.test where time = 11 or time = 12",
- "select * from root.vehicle,root.test where d0.s0 > 10 and d0.s1 < 301 or time = 12",
- "select * from root"
- };
- private static final String[] querys2 ={
- "select * from root.vehicle",
- "select * from root.test",
- "select * from root.vehicle,root.test where time = 11 or time = 16",
- "select * from root.vehicle,root.test where d0.s0 > 10 and d0.s1 < 301 or time = 20",
- "select * from root"
- };
- private static final String[] querys3 ={
- "select * from root.vehicle",
- "select * from root.test",
- "select * from root.cluster",
- "select * from root.vehicle,root.test where time = 11 or time = 14",
- "select * from root.vehicle,root.test where d0.s0 > 0 and d0.s1 < 1001 or time = 14",
- "select * from root"
- };
-
- private Map<Integer, List<String>> queryCorrentResults = new HashMap<>();
-
- @Before
- public void setUp() throws Exception {
- EnvironmentUtils.cleanEnv();
- EnvironmentUtils.closeStatMonitor();
- EnvironmentUtils.closeMemControl();
- CLUSTER_CONFIG.createAllPath();
- server = Server.getInstance();
- server.start();
- EnvironmentUtils.envSetUp();
- Class.forName(Config.JDBC_DRIVER_NAME);
- }
-
- @After
- public void tearDown() throws Exception {
- server.stop();
- EnvironmentUtils.cleanEnv();
- }
-
- private void initCorrectResults1(){
- queryCorrentResults.clear();
- queryCorrentResults.put(0, new ArrayList<>());
- queryCorrentResults.put(1, new ArrayList<>());
- queryCorrentResults.put(2, new ArrayList<>());
- queryCorrentResults.put(3, new ArrayList<>());
- queryCorrentResults.put(4, new ArrayList<>());
- List<String> firstQueryRes = queryCorrentResults.get(0);
- firstQueryRes.add("10,100,null,null,null");
- firstQueryRes.add("11,null,null,104.0,null");
- firstQueryRes.add("12,101,102,null,null");
- firstQueryRes.add("15,null,null,105.0,true");
- firstQueryRes.add("17,null,null,null,false");
- firstQueryRes.add("19,null,103,null,null");
- firstQueryRes.add("20,1000,null,null,null");
- firstQueryRes.add("21,null,null,1004.0,null");
- firstQueryRes.add("22,1001,1002,null,null");
- firstQueryRes.add("25,null,null,1005.0,true");
- firstQueryRes.add("27,null,null,null,true");
- firstQueryRes.add("29,null,1003,null,null");
-
- List<String> secondQueryRes = queryCorrentResults.get(1);
- secondQueryRes.add("1,null,null,110");
- secondQueryRes.add("10,106,null,1100");
- secondQueryRes.add("14,107,108,null");
- secondQueryRes.add("16,null,109,null");
- secondQueryRes.add("30,1006,null,null");
- secondQueryRes.add("34,1007,1008,null");
- secondQueryRes.add("36,null,1090,null");
-
- List<String> thirdQueryRes = queryCorrentResults.get(2);
- thirdQueryRes.add("11,null,null,104.0,null,null,null,null");
- thirdQueryRes.add("12,101,102,null,null,null,null,null");
-
- List<String> forthQueryRes = queryCorrentResults.get(3);
- forthQueryRes.add("12,101,102,null,null,null,null,null");
-
- List<String> fifthQueryRes = queryCorrentResults.get(4);
- fifthQueryRes.add("1,null,null,null,null,null,null,110");
- fifthQueryRes.add("10,100,null,null,null,106,null,1100");
- fifthQueryRes.add("11,null,null,104.0,null,null,null,null");
- fifthQueryRes.add("12,101,102,null,null,null,null,null");
- fifthQueryRes.add("14,null,null,null,null,107,108,null");
- fifthQueryRes.add("15,null,null,105.0,true,null,null,null");
- fifthQueryRes.add("16,null,null,null,null,null,109,null");
- fifthQueryRes.add("17,null,null,null,false,null,null,null");
- fifthQueryRes.add("19,null,103,null,null,null,null,null");
- fifthQueryRes.add("20,1000,null,null,null,null,null,null");
- fifthQueryRes.add("21,null,null,1004.0,null,null,null,null");
- fifthQueryRes.add("22,1001,1002,null,null,null,null,null");
- fifthQueryRes.add("25,null,null,1005.0,true,null,null,null");
- fifthQueryRes.add("27,null,null,null,true,null,null,null");
- fifthQueryRes.add("29,null,1003,null,null,null,null,null");
- fifthQueryRes.add("30,null,null,null,null,1006,null,null");
- fifthQueryRes.add("34,null,null,null,null,1007,1008,null");
- fifthQueryRes.add("36,null,null,null,null,null,1090,null");
- }
-
- private void initCorrectResults2(){
- queryCorrentResults.clear();
- queryCorrentResults.put(0, new ArrayList<>());
- queryCorrentResults.put(1, new ArrayList<>());
- queryCorrentResults.put(2, new ArrayList<>());
- queryCorrentResults.put(3, new ArrayList<>());
- queryCorrentResults.put(4, new ArrayList<>());
- List<String> firstQueryRes = queryCorrentResults.get(0);
- firstQueryRes.add("6,120,null,null,null");
- firstQueryRes.add("9,null,123,null,null");
- firstQueryRes.add("10,100,null,null,null");
- firstQueryRes.add("11,null,null,104.0,null");
- firstQueryRes.add("12,101,102,null,null");
- firstQueryRes.add("14,null,null,1024.0,null");
- firstQueryRes.add("15,null,null,105.0,true");
- firstQueryRes.add("16,128,null,null,null");
- firstQueryRes.add("17,null,null,null,false");
- firstQueryRes.add("18,189,198,null,null");
- firstQueryRes.add("19,null,103,null,null");
- firstQueryRes.add("20,1000,null,null,null");
- firstQueryRes.add("21,null,null,1004.0,null");
- firstQueryRes.add("22,1001,1002,null,null");
- firstQueryRes.add("25,null,null,1005.0,true");
- firstQueryRes.add("27,null,null,null,true");
- firstQueryRes.add("29,null,1003,1205.0,true");
- firstQueryRes.add("33,null,null,null,true");
- firstQueryRes.add("38,121,122,null,null");
- firstQueryRes.add("99,null,1234,null,null");
-
- List<String> secondQueryRes = queryCorrentResults.get(1);
- secondQueryRes.add("1,null,null,110");
- secondQueryRes.add("2,null,1209,null");
- secondQueryRes.add("4,null,null,330");
- secondQueryRes.add("8,127,128,null");
- secondQueryRes.add("10,106,null,1100");
- secondQueryRes.add("14,107,108,430");
- secondQueryRes.add("15,126,null,null");
- secondQueryRes.add("16,null,109,null");
- secondQueryRes.add("20,null,129,null");
- secondQueryRes.add("30,1006,null,null");
- secondQueryRes.add("34,1007,1008,null");
- secondQueryRes.add("36,null,1090,null");
- secondQueryRes.add("80,427,528,null");
- secondQueryRes.add("150,426,null,null");
-
- List<String> thirdQueryRes = queryCorrentResults.get(2);
- thirdQueryRes.add("11,null,null,104.0,null,null,null,null");
- thirdQueryRes.add("16,128,null,null,null,null,109,null");
-
- List<String> forthQueryRes = queryCorrentResults.get(3);
- forthQueryRes.add("20,1000,null,null,null,null,129,null");
-
- List<String> fifthQueryRes = queryCorrentResults.get(4);
- fifthQueryRes.add("1,null,null,null,null,null,null,110");
- fifthQueryRes.add("2,null,null,null,null,null,1209,null");
- fifthQueryRes.add("4,null,null,null,null,null,null,330");
- fifthQueryRes.add("6,120,null,null,null,null,null,null");
- fifthQueryRes.add("8,null,null,null,null,127,128,null");
- fifthQueryRes.add("9,null,123,null,null,null,null,null");
- fifthQueryRes.add("10,100,null,null,null,106,null,1100");
- fifthQueryRes.add("11,null,null,104.0,null,null,null,null");
- fifthQueryRes.add("12,101,102,null,null,null,null,null");
- fifthQueryRes.add("14,null,null,1024.0,null,107,108,430");
- fifthQueryRes.add("15,null,null,105.0,true,126,null,null");
- fifthQueryRes.add("16,128,null,null,null,null,109,null");
- fifthQueryRes.add("17,null,null,null,false,null,null,null");
- fifthQueryRes.add("18,189,198,null,null,null,null,null");
- fifthQueryRes.add("19,null,103,null,null,null,null,null");
- fifthQueryRes.add("20,1000,null,null,null,null,129,null");
- fifthQueryRes.add("21,null,null,1004.0,null,null,null,null");
- fifthQueryRes.add("22,1001,1002,null,null,null,null,null");
- fifthQueryRes.add("25,null,null,1005.0,true,null,null,null");
- fifthQueryRes.add("27,null,null,null,true,null,null,null");
- fifthQueryRes.add("29,null,1003,1205.0,true,null,null,null");
- fifthQueryRes.add("30,null,null,null,null,1006,null,null");
- fifthQueryRes.add("33,null,null,null,true,null,null,null");
- fifthQueryRes.add("34,null,null,null,null,1007,1008,null");
- fifthQueryRes.add("36,null,null,null,null,null,1090,null");
- fifthQueryRes.add("38,121,122,null,null,null,null,null");
- fifthQueryRes.add("80,null,null,null,null,427,528,null");
- fifthQueryRes.add("99,null,1234,null,null,null,null,null");
- fifthQueryRes.add("150,null,null,null,null,426,null,null");
- }
-
- private void initCorrectResults3(){
- queryCorrentResults.clear();
- queryCorrentResults.put(0, new ArrayList<>());
- queryCorrentResults.put(1, new ArrayList<>());
- queryCorrentResults.put(2, new ArrayList<>());
- queryCorrentResults.put(3, new ArrayList<>());
- queryCorrentResults.put(4, new ArrayList<>());
- queryCorrentResults.put(5, new ArrayList<>());
- List<String> zeroQueryRes = queryCorrentResults.get(0);
- zeroQueryRes.add("14,null,null,null,false");
- zeroQueryRes.add("20,1000,null,null,null");
- zeroQueryRes.add("21,null,null,1004.0,null");
- zeroQueryRes.add("22,1001,1002,null,null");
- zeroQueryRes.add("25,null,null,1005.0,true");
- zeroQueryRes.add("27,null,null,null,true");
- zeroQueryRes.add("29,null,1003,135.0,false");
- zeroQueryRes.add("33,null,null,null,true");
- zeroQueryRes.add("38,121,122,null,null");
- zeroQueryRes.add("70,null,33,null,null");
- zeroQueryRes.add("99,null,1234,null,null");
- zeroQueryRes.add("204,null,null,14.0,null");
- zeroQueryRes.add("206,131,132,null,null");
- zeroQueryRes.add("209,130,null,null,null");
-
- List<String> firstQueryRes = queryCorrentResults.get(1);
- firstQueryRes.add("4,null,null,150");
- firstQueryRes.add("7,137,138,null");
- firstQueryRes.add("19,136,null,null");
- firstQueryRes.add("20,null,129,null");
- firstQueryRes.add("30,1006,139,null");
- firstQueryRes.add("34,1007,1008,null");
- firstQueryRes.add("36,null,1090,null");
- firstQueryRes.add("80,427,528,null");
- firstQueryRes.add("150,426,null,null");
- firstQueryRes.add("400,null,null,1050");
- firstQueryRes.add("700,1307,1038,null");
- firstQueryRes.add("1900,1316,null,null");
- firstQueryRes.add("3000,null,1309,null");
-
- List<String> secondQueryRes = queryCorrentResults.get(2);
- secondQueryRes.add("1,null,null,110");
- secondQueryRes.add("14,107,108,null");
- secondQueryRes.add("20,106,null,null");
- secondQueryRes.add("200,1006,null,null");
- secondQueryRes.add("1000,null,null,910");
- secondQueryRes.add("1004,1007,1080,null");
-
- List<String> thirdQueryRes = queryCorrentResults.get(3);
- thirdQueryRes.add("14,null,null,null,false,null,null,null");
-
- List<String> forthQueryRes = queryCorrentResults.get(4);
- forthQueryRes.add("14,null,null,null,false,null,null,null");
-
- List<String> fifthQueryRes = queryCorrentResults.get(5);
- fifthQueryRes.add("1,null,null,404.0,null,null,null,null,null,null,null,null,null,null,110");
- fifthQueryRes.add("3,100,null,null,null,null,null,null,null,null,null,null,null,null,null");
- fifthQueryRes.add("4,null,null,null,null,null,null,null,null,null,null,150,null,null,null");
- fifthQueryRes.add("7,null,null,null,null,null,null,null,null,137,138,null,null,null,null");
- fifthQueryRes.add("14,null,null,null,null,null,null,null,false,null,null,null,107,108,null");
- fifthQueryRes.add("19,null,null,null,null,null,null,null,null,136,null,null,null,null,null");
- fifthQueryRes.add("20,null,null,null,null,1000,null,null,null,null,129,null,106,null,null");
- fifthQueryRes.add("21,null,null,104.0,null,null,null,1004.0,null,null,null,null,null,null,null");
- fifthQueryRes.add("22,101,102,null,null,1001,1002,null,null,null,null,null,null,null,null");
- fifthQueryRes.add("24,null,103,null,null,null,null,null,null,null,null,null,null,null,null");
- fifthQueryRes.add("25,null,null,105.0,true,null,null,1005.0,true,null,null,null,null,null,null");
- fifthQueryRes.add("27,null,null,null,false,null,null,null,true,null,null,null,null,null,null");
- fifthQueryRes.add("29,null,null,null,null,null,1003,135.0,false,null,null,null,null,null,null");
- fifthQueryRes.add("30,1000,null,null,null,null,null,null,null,1006,139,null,null,null,null");
- fifthQueryRes.add("33,null,null,null,null,null,null,null,true,null,null,null,null,null,null");
- fifthQueryRes.add("34,null,null,null,null,null,null,null,null,1007,1008,null,null,null,null");
- fifthQueryRes.add("36,null,null,null,null,null,null,null,null,null,1090,null,null,null,null");
- fifthQueryRes.add("38,null,null,null,null,121,122,null,null,null,null,null,null,null,null");
- fifthQueryRes.add("44,null,103,null,null,null,null,null,null,null,null,null,null,null,null");
- fifthQueryRes.add("70,null,null,null,null,null,33,null,null,null,null,null,null,null,null");
- fifthQueryRes.add("80,null,null,null,null,null,null,null,null,427,528,null,null,null,null");
- fifthQueryRes.add("99,null,null,null,null,null,1234,null,null,null,null,null,null,null,null");
- fifthQueryRes.add("150,null,null,null,null,null,null,null,null,426,null,null,null,null,null");
- fifthQueryRes.add("200,null,null,null,null,null,null,null,null,null,null,null,1006,null,null");
- fifthQueryRes.add("202,101,102,null,null,null,null,null,null,null,null,null,null,null,null");
- fifthQueryRes.add("204,null,null,null,null,null,null,14.0,null,null,null,null,null,null,null");
- fifthQueryRes.add("206,null,null,null,null,131,132,null,null,null,null,null,null,null,null");
- fifthQueryRes.add("207,null,null,null,false,null,null,null,null,null,null,null,null,null,null");
- fifthQueryRes.add("209,null,null,null,null,130,null,null,null,null,null,null,null,null,null");
- fifthQueryRes.add("250,null,null,10.0,true,null,null,null,null,null,null,null,null,null,null");
- fifthQueryRes.add("400,null,null,null,null,null,null,null,null,null,null,1050,null,null,null");
- fifthQueryRes.add("700,null,null,null,null,null,null,null,null,1307,1038,null,null,null,null");
- fifthQueryRes.add("1000,null,null,null,null,null,null,null,null,null,null,null,null,null,910");
- fifthQueryRes.add("1004,null,null,null,null,null,null,null,null,null,null,null,1007,1080,null");
- fifthQueryRes.add("1900,null,null,null,null,null,null,null,null,1316,null,null,null,null,null");
- fifthQueryRes.add("3000,null,null,null,null,null,null,null,null,null,1309,null,null,null,null");
- }
-
- @Test
- public void testClusterQueryWithLargeData() throws Exception {
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- Statement statement = connection.createStatement();
-
- //first round
- insertData(connection, createSQLs1, insertSQLs1);
- initCorrectResults1();
- for(int i =0 ; i < querys1.length; i++) {
- String queryStatement = querys1[i];
- boolean hasResultSet = statement.execute(queryStatement);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- IoTDBResultMetadata resultSetMetaData = (IoTDBResultMetadata) resultSet.getMetaData();
- int columnCount = resultSetMetaData.getColumnCount();
- List<String> correctResult = queryCorrentResults.get(i);
- int count = 0;
- while (resultSet.next()) {
- String correctRow = correctResult.get(count++);
- StringBuilder rowRecordBuilder = new StringBuilder();
- for (int j = 1; j < columnCount; j++) {
- rowRecordBuilder.append(resultSet.getString(j)).append(",");
- }
- rowRecordBuilder.append(resultSet.getString(columnCount));
- assertEquals(correctRow, rowRecordBuilder.toString());
- }
- }
-
- // second round
- insertData(connection, new String[]{}, insertSqls2);
- initCorrectResults2();
- for(int i =0 ; i < querys2.length; i++) {
- String queryStatement = querys2[i];
- boolean hasResultSet = statement.execute(queryStatement);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- IoTDBResultMetadata resultSetMetaData = (IoTDBResultMetadata) resultSet.getMetaData();
- int columnCount = resultSetMetaData.getColumnCount();
- List<String> correctResult = queryCorrentResults.get(i);
- int count = 0;
- while (resultSet.next()) {
- String correctRow = correctResult.get(count++);
- StringBuilder rowRecordBuilder = new StringBuilder();
- for (int j = 1; j < columnCount; j++) {
- rowRecordBuilder.append(resultSet.getString(j)).append(",");
- }
- rowRecordBuilder.append(resultSet.getString(columnCount));
- assertEquals(correctRow, rowRecordBuilder.toString());
- }
- }
-
- // third round
- insertData(connection, createSQLs3, insertSQLs3);
- initCorrectResults3();
- for(int i =0 ; i < querys3.length; i++) {
- String queryStatement = querys3[i];
- boolean hasResultSet = statement.execute(queryStatement);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- IoTDBResultMetadata resultSetMetaData = (IoTDBResultMetadata) resultSet.getMetaData();
- int columnCount = resultSetMetaData.getColumnCount();
- List<String> correctResult = queryCorrentResults.get(i);
- int count = 0;
- while (resultSet.next()) {
- String correctRow = correctResult.get(count++);
- StringBuilder rowRecordBuilder = new StringBuilder();
- for (int j = 1; j < columnCount; j++) {
- rowRecordBuilder.append(resultSet.getString(j)).append(",");
- }
- rowRecordBuilder.append(resultSet.getString(columnCount));
- assertEquals(correctRow, rowRecordBuilder.toString());
- }
- }
-
- statement.close();
- }
- }
-}
diff --git a/cluster/src/test/java/org/apache/iotdb/cluster/query/ClusterQueryTest.java b/cluster/src/test/java/org/apache/iotdb/cluster/query/ClusterQueryTest.java
deleted file mode 100644
index f5cc295..0000000
--- a/cluster/src/test/java/org/apache/iotdb/cluster/query/ClusterQueryTest.java
+++ /dev/null
@@ -1,550 +0,0 @@
-/**
- * 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.cluster.query;
-
-import static org.apache.iotdb.cluster.utils.Utils.insertBatchData;
-import static org.apache.iotdb.cluster.utils.Utils.insertData;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.iotdb.cluster.config.ClusterConfig;
-import org.apache.iotdb.cluster.config.ClusterDescriptor;
-import org.apache.iotdb.cluster.entity.Server;
-import org.apache.iotdb.cluster.utils.EnvironmentUtils;
-import org.apache.iotdb.cluster.utils.QPExecutorUtils;
-import org.apache.iotdb.cluster.utils.hash.PhysicalNode;
-import org.apache.iotdb.jdbc.Config;
-import org.apache.iotdb.jdbc.IoTDBResultMetadata;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ClusterQueryTest {
-
- private Server server;
- private static final ClusterConfig CLUSTER_CONFIG = ClusterDescriptor.getInstance().getConfig();
- private static final PhysicalNode localNode = new PhysicalNode(CLUSTER_CONFIG.getIp(),
- CLUSTER_CONFIG.getPort());
-
- private static final String URL = "127.0.0.1:6667/";
-
- private String[] createSQLs = {
- "SET STORAGE GROUP TO root.vehicle",
- "SET STORAGE GROUP TO root.test",
- "CREATE TIMESERIES root.vehicle.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE",
- "CREATE TIMESERIES root.vehicle.d0.s1 WITH DATATYPE=TEXT, ENCODING=PLAIN",
- "CREATE TIMESERIES root.vehicle.d1.s2 WITH DATATYPE=FLOAT, ENCODING=RLE",
- "CREATE TIMESERIES root.vehicle.d1.s3 WITH DATATYPE=BOOLEAN, ENCODING=PLAIN",
- "CREATE TIMESERIES root.test.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE",
- "CREATE TIMESERIES root.test.d0.s1 WITH DATATYPE=TEXT, ENCODING=PLAIN",
- "CREATE TIMESERIES root.test.d1.g0.s0 WITH DATATYPE=INT32, ENCODING=RLE"
-
- };
- private String[] insertSQLs = {
- "insert into root.vehicle.d0(timestamp,s0) values(10,100)",
- "insert into root.vehicle.d0(timestamp,s0,s1) values(12,101,'102')",
- "insert into root.vehicle.d0(timestamp,s1) values(19,'103')",
- "insert into root.vehicle.d1(timestamp,s2) values(11,104.0)",
- "insert into root.vehicle.d1(timestamp,s2,s3) values(15,105.0,true)",
- "insert into root.vehicle.d1(timestamp,s3) values(17,false)",
- "insert into root.vehicle.d0(timestamp,s0) values(20,1000)",
- "insert into root.vehicle.d0(timestamp,s0,s1) values(22,1001,'1002')",
- "insert into root.vehicle.d0(timestamp,s1) values(29,'1003')",
- "insert into root.vehicle.d1(timestamp,s2) values(21,1004.0)",
- "insert into root.vehicle.d1(timestamp,s2,s3) values(25,1005.0,true)",
- "insert into root.vehicle.d1(timestamp,s3) values(27,true)",
- "insert into root.test.d0(timestamp,s0) values(10,106)",
- "insert into root.test.d0(timestamp,s0,s1) values(14,107,'108')",
- "insert into root.test.d0(timestamp,s1) values(16,'109')",
- "insert into root.test.d1.g0(timestamp,s0) values(1,110)",
- "insert into root.test.d0(timestamp,s0) values(30,1006)",
- "insert into root.test.d0(timestamp,s0,s1) values(34,1007,'1008')",
- "insert into root.test.d0(timestamp,s1) values(36,'1090')",
- "insert into root.test.d1.g0(timestamp,s0) values(10,1100)",
- "insert into root.vehicle.d0(timestamp,s0) values(6,120)",
- "insert into root.vehicle.d0(timestamp,s0,s1) values(38,121,'122')",
- "insert into root.vehicle.d0(timestamp,s1) values(9,'123')",
- "insert into root.vehicle.d0(timestamp,s0) values(16,128)",
- "insert into root.vehicle.d0(timestamp,s0,s1) values(18,189,'198')",
- "insert into root.vehicle.d0(timestamp,s1) values(99,'1234')",
- "insert into root.vehicle.d1(timestamp,s2) values(14,1024.0)",
- "insert into root.vehicle.d1(timestamp,s2,s3) values(29,1205.0,true)",
- "insert into root.vehicle.d1(timestamp,s3) values(33,true)",
- "insert into root.test.d0(timestamp,s0) values(15,126)",
- "insert into root.test.d0(timestamp,s0,s1) values(8,127,'128')",
- "insert into root.test.d0(timestamp,s1) values(20,'129')",
- "insert into root.test.d1.g0(timestamp,s0) values(14,430)",
- "insert into root.test.d0(timestamp,s0) values(150,426)",
- "insert into root.test.d0(timestamp,s0,s1) values(80,427,'528')",
- "insert into root.test.d0(timestamp,s1) values(2,'1209')",
- "insert into root.test.d1.g0(timestamp,s0) values(4,330)"
- };
- private String[] queryStatementsWithoutFilter = {
- "select * from root",
- "select * from root.vehicle",
- "select * from root.test",
- "select vehicle.d0.s0, test.d0.s1 from root",
- "select vehicle.d1.s2, vehicle.d1.s3 ,test.d1.g0.s0 from root"
- };
-
- private Map<Integer, List<String>> queryCorrentResultsWithoutFilter = new HashMap<>();
-
- private String[] queryStatementsWithFilter = {
- "select * from root.vehicle where d0.s0 > 10",
- "select * from root.vehicle where d0.s0 < 101",
- "select * from root.vehicle where d0.s0 > 10 and d0.s0 < 101 or time = 12",
- "select * from root.test where d0.s0 > 10",
- "select * from root.test where d0.s0 > 10 and d0.s0 < 200 or d0.s0 = 3",
- "select * from root where vehicle.d0.s0 > 10 and test.d0.s0 < 101 or time = 20",
- };
-
- private Map<Integer, List<String>> queryCorrentResultsWithFilter = new HashMap<>();
-
- @Before
- public void setUp() throws Exception {
- EnvironmentUtils.cleanEnv();
- EnvironmentUtils.closeStatMonitor();
- EnvironmentUtils.closeMemControl();
- CLUSTER_CONFIG.createAllPath();
- server = Server.getInstance();
- server.start();
- EnvironmentUtils.envSetUp();
- Class.forName(Config.JDBC_DRIVER_NAME);
- }
-
- @After
- public void tearDown() throws Exception {
- server.stop();
- EnvironmentUtils.cleanEnv();
- }
-
- private void initCorrectResultsWithoutFilter(){
- queryCorrentResultsWithoutFilter.put(0, new ArrayList<>());
- queryCorrentResultsWithoutFilter.put(1, new ArrayList<>());
- queryCorrentResultsWithoutFilter.put(2, new ArrayList<>());
- queryCorrentResultsWithoutFilter.put(3, new ArrayList<>());
- queryCorrentResultsWithoutFilter.put(4, new ArrayList<>());
- List<String> firstQueryRes = queryCorrentResultsWithoutFilter.get(0);
- firstQueryRes.add("1,null,null,null,null,null,null,110");
- firstQueryRes.add("2,null,null,null,null,null,1209,null");
- firstQueryRes.add("4,null,null,null,null,null,null,330");
- firstQueryRes.add("6,120,null,null,null,null,null,null");
- firstQueryRes.add("8,null,null,null,null,127,128,null");
- firstQueryRes.add("9,null,123,null,null,null,null,null");
- firstQueryRes.add("10,100,null,null,null,106,null,1100");
- firstQueryRes.add("11,null,null,104.0,null,null,null,null");
- firstQueryRes.add("12,101,102,null,null,null,null,null");
- firstQueryRes.add("14,null,null,1024.0,null,107,108,430");
- firstQueryRes.add("15,null,null,105.0,true,126,null,null");
- firstQueryRes.add("16,128,null,null,null,null,109,null");
- firstQueryRes.add("17,null,null,null,false,null,null,null");
- firstQueryRes.add("18,189,198,null,null,null,null,null");
- firstQueryRes.add("19,null,103,null,null,null,null,null");
- firstQueryRes.add("20,1000,null,null,null,null,129,null");
- firstQueryRes.add("21,null,null,1004.0,null,null,null,null");
- firstQueryRes.add("22,1001,1002,null,null,null,null,null");
- firstQueryRes.add("25,null,null,1005.0,true,null,null,null");
- firstQueryRes.add("27,null,null,null,true,null,null,null");
- firstQueryRes.add("29,null,1003,1205.0,true,null,null,null");
- firstQueryRes.add("30,null,null,null,null,1006,null,null");
- firstQueryRes.add("33,null,null,null,true,null,null,null");
- firstQueryRes.add("34,null,null,null,null,1007,1008,null");
- firstQueryRes.add("36,null,null,null,null,null,1090,null");
- firstQueryRes.add("38,121,122,null,null,null,null,null");
- firstQueryRes.add("80,null,null,null,null,427,528,null");
- firstQueryRes.add("99,null,1234,null,null,null,null,null");
- firstQueryRes.add("150,null,null,null,null,426,null,null");
-
- List<String> secondQueryRes = queryCorrentResultsWithoutFilter.get(1);
- secondQueryRes.add("6,120,null,null,null");
- secondQueryRes.add("9,null,123,null,null");
- secondQueryRes.add("10,100,null,null,null");
- secondQueryRes.add("11,null,null,104.0,null");
- secondQueryRes.add("12,101,102,null,null");
- secondQueryRes.add("14,null,null,1024.0,null");
- secondQueryRes.add("15,null,null,105.0,true");
- secondQueryRes.add("16,128,null,null,null");
- secondQueryRes.add("17,null,null,null,false");
- secondQueryRes.add("18,189,198,null,null");
- secondQueryRes.add("19,null,103,null,null");
- secondQueryRes.add("20,1000,null,null,null");
- secondQueryRes.add("21,null,null,1004.0,null");
- secondQueryRes.add("22,1001,1002,null,null");
- secondQueryRes.add("25,null,null,1005.0,true");
- secondQueryRes.add("27,null,null,null,true");
- secondQueryRes.add("29,null,1003,1205.0,true");
- secondQueryRes.add("33,null,null,null,true");
- secondQueryRes.add("38,121,122,null,null");
- secondQueryRes.add("99,null,1234,null,null");
- List<String> thirdQueryRes = queryCorrentResultsWithoutFilter.get(2);
- thirdQueryRes.add("1,null,null,110");
- thirdQueryRes.add("2,null,1209,null");
- thirdQueryRes.add("4,null,null,330");
- thirdQueryRes.add("8,127,128,null");
- thirdQueryRes.add("10,106,null,1100");
- thirdQueryRes.add("14,107,108,430");
- thirdQueryRes.add("15,126,null,null");
- thirdQueryRes.add("16,null,109,null");
- thirdQueryRes.add("20,null,129,null");
- thirdQueryRes.add("30,1006,null,null");
- thirdQueryRes.add("34,1007,1008,null");
- thirdQueryRes.add("36,null,1090,null");
- thirdQueryRes.add("80,427,528,null");
- thirdQueryRes.add("150,426,null,null");
- List<String> forthQueryRes = queryCorrentResultsWithoutFilter.get(3);
- forthQueryRes.add("2,null,1209");
- forthQueryRes.add("6,120,null");
- forthQueryRes.add("8,null,128");
- forthQueryRes.add("10,100,null");
- forthQueryRes.add("12,101,null");
- forthQueryRes.add("14,null,108");
- forthQueryRes.add("16,128,109");
- forthQueryRes.add("18,189,null");
- forthQueryRes.add("20,1000,129");
- forthQueryRes.add("22,1001,null");
- forthQueryRes.add("34,null,1008");
- forthQueryRes.add("36,null,1090");
- forthQueryRes.add("38,121,null");
- forthQueryRes.add("80,null,528");
- List<String> fifthQueryRes = queryCorrentResultsWithoutFilter.get(4);
- fifthQueryRes.add("1,null,null,110");
- fifthQueryRes.add("4,null,null,330");
- fifthQueryRes.add("10,null,null,1100");
- fifthQueryRes.add("11,104.0,null,null");
- fifthQueryRes.add("14,1024.0,null,430");
- fifthQueryRes.add("15,105.0,true,null");
- fifthQueryRes.add("17,null,false,null");
- fifthQueryRes.add("21,1004.0,null,null");
- fifthQueryRes.add("25,1005.0,true,null");
- fifthQueryRes.add("27,null,true,null");
- fifthQueryRes.add("29,1205.0,true,null");
- fifthQueryRes.add("33,null,true,null");
- }
-
- private void initCorrectResultsWithFilter(){
- queryCorrentResultsWithFilter.put(0, new ArrayList<>());
- queryCorrentResultsWithFilter.put(1, new ArrayList<>());
- queryCorrentResultsWithFilter.put(2, new ArrayList<>());
- queryCorrentResultsWithFilter.put(3, new ArrayList<>());
- queryCorrentResultsWithFilter.put(4, new ArrayList<>());
- queryCorrentResultsWithFilter.put(5, new ArrayList<>());
- List<String> firstQueryRes = queryCorrentResultsWithFilter.get(0);
- firstQueryRes.add("6,120,null,null,null");
- firstQueryRes.add("10,100,null,null,null");
- firstQueryRes.add("12,101,102,null,null");
- firstQueryRes.add("16,128,null,null,null");
- firstQueryRes.add("18,189,198,null,null");
- firstQueryRes.add("20,1000,null,null,null");
- firstQueryRes.add("22,1001,1002,null,null");
- firstQueryRes.add("38,121,122,null,null");
-
- List<String> secondQueryRes = queryCorrentResultsWithFilter.get(1);
- secondQueryRes.add("10,100,null,null,null");
- List<String> thirdQueryRes = queryCorrentResultsWithFilter.get(2);
- thirdQueryRes.add("10,100,null,null,null");
- thirdQueryRes.add("12,101,102,null,null");
- List<String> forthQueryRes = queryCorrentResultsWithFilter.get(3);
- forthQueryRes.add("8,127,128,null");
- forthQueryRes.add("10,106,null,1100");
- forthQueryRes.add("14,107,108,430");
- forthQueryRes.add("15,126,null,null");
- forthQueryRes.add("30,1006,null,null");
- forthQueryRes.add("34,1007,1008,null");
- forthQueryRes.add("80,427,528,null");
- forthQueryRes.add("150,426,null,null");
- List<String> fifthQueryRes = queryCorrentResultsWithFilter.get(4);
- fifthQueryRes.add("8,127,128,null");
- fifthQueryRes.add("10,106,null,1100");
- fifthQueryRes.add("14,107,108,430");
- fifthQueryRes.add("15,126,null,null");
- List<String> sixthQueryRes = queryCorrentResultsWithFilter.get(5);
- sixthQueryRes.add("20,1000,null,null,null,null,129,null");
- }
-
- @Test
- public void testLocalQueryWithoutFilter() throws Exception {
- initCorrectResultsWithoutFilter();
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertData(connection, createSQLs, insertSQLs);
- Statement statement = connection.createStatement();
-
- for(int i =0 ; i < queryStatementsWithoutFilter.length; i++) {
- String queryStatement = queryStatementsWithoutFilter[i];
- boolean hasResultSet = statement.execute(queryStatement);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- IoTDBResultMetadata resultSetMetaData = (IoTDBResultMetadata) resultSet.getMetaData();
- int columnCount = resultSetMetaData.getColumnCount();
- List<String> correctResult = queryCorrentResultsWithoutFilter.get(i);
- int count = 0;
- while (resultSet.next()) {
- String correctRow = correctResult.get(count++);
- StringBuilder rowRecordBuilder = new StringBuilder();
- for (int j = 1; j < columnCount; j++) {
- rowRecordBuilder.append(resultSet.getString(j)).append(",");
- }
- rowRecordBuilder.append(resultSet.getString(columnCount));
- assertEquals(correctRow, rowRecordBuilder.toString());
- }
- }
- statement.close();
- }
- }
-
- @Test
- public void testLocalQueryWithFilter() throws Exception {
-
- initCorrectResultsWithFilter();
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertData(connection, createSQLs, insertSQLs);
- Statement statement = connection.createStatement();
-
- for(int i =0 ; i < queryStatementsWithFilter.length; i++) {
- String queryStatement = queryStatementsWithFilter[i];
- boolean hasResultSet = statement.execute(queryStatement);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- IoTDBResultMetadata resultSetMetaData = (IoTDBResultMetadata) resultSet.getMetaData();
- int columnCount = resultSetMetaData.getColumnCount();
- List<String> correctResult = queryCorrentResultsWithFilter.get(i);
- int count = 0;
- while (resultSet.next()) {
- String correctRow = correctResult.get(count++);
- StringBuilder rowRecordBuilder = new StringBuilder();
- for (int j = 1; j < columnCount; j++) {
- rowRecordBuilder.append(resultSet.getString(j)).append(",");
- }
- rowRecordBuilder.append(resultSet.getString(columnCount));
- assertEquals(correctRow, rowRecordBuilder.toString());
- }
- }
- statement.close();
- }
- }
-
- @Test
- public void testRemoteQueryWithoutFilter() throws Exception {
-
- QPExecutorUtils.setLocalNodeAddr("0.0.0.0", 0);
- initCorrectResultsWithoutFilter();
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertData(connection, createSQLs, insertSQLs);
- Statement statement = connection.createStatement();
-
- for(int i =0 ; i < queryStatementsWithoutFilter.length; i++) {
- String queryStatement = queryStatementsWithoutFilter[i];
- boolean hasResultSet = statement.execute(queryStatement);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- IoTDBResultMetadata resultSetMetaData = (IoTDBResultMetadata) resultSet.getMetaData();
- int columnCount = resultSetMetaData.getColumnCount();
- List<String> correctResult = queryCorrentResultsWithoutFilter.get(i);
- int count = 0;
- while (resultSet.next()) {
- String correctRow = correctResult.get(count++);
- StringBuilder rowRecordBuilder = new StringBuilder();
- for (int j = 1; j < columnCount; j++) {
- rowRecordBuilder.append(resultSet.getString(j)).append(",");
- }
- rowRecordBuilder.append(resultSet.getString(columnCount));
- assertEquals(correctRow, rowRecordBuilder.toString());
- }
- }
- QPExecutorUtils.setLocalNodeAddr(localNode.getIp(), localNode.getPort());
- statement.close();
- }
- }
-
- @Test
- public void testRemoteQueryWithFilter() throws Exception {
-
- QPExecutorUtils.setLocalNodeAddr("0.0.0.0", 0);
- initCorrectResultsWithFilter();
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertData(connection, createSQLs, insertSQLs);
- Statement statement = connection.createStatement();
-
- for(int i =0 ; i < queryStatementsWithFilter.length; i++) {
- String queryStatement = queryStatementsWithFilter[i];
- boolean hasResultSet = statement.execute(queryStatement);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- IoTDBResultMetadata resultSetMetaData = (IoTDBResultMetadata) resultSet.getMetaData();
- int columnCount = resultSetMetaData.getColumnCount();
- List<String> correctResult = queryCorrentResultsWithFilter.get(i);
- int count = 0;
- while (resultSet.next()) {
- String correctRow = correctResult.get(count++);
- StringBuilder rowRecordBuilder = new StringBuilder();
- for (int j = 1; j < columnCount; j++) {
- rowRecordBuilder.append(resultSet.getString(j)).append(",");
- }
- rowRecordBuilder.append(resultSet.getString(columnCount));
- assertEquals(correctRow, rowRecordBuilder.toString());
- }
- }
- QPExecutorUtils.setLocalNodeAddr(localNode.getIp(), localNode.getPort());
- statement.close();
- }
- }
-
- @Test
- public void testLocalQueryWithoutFilterByBatch() throws Exception {
- initCorrectResultsWithoutFilter();
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertBatchData(connection, createSQLs, insertSQLs);
- Statement statement = connection.createStatement();
-
- for(int i =0 ; i < queryStatementsWithoutFilter.length; i++) {
- String queryStatement = queryStatementsWithoutFilter[i];
- boolean hasResultSet = statement.execute(queryStatement);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- IoTDBResultMetadata resultSetMetaData = (IoTDBResultMetadata) resultSet.getMetaData();
- int columnCount = resultSetMetaData.getColumnCount();
- List<String> correctResult = queryCorrentResultsWithoutFilter.get(i);
- int count = 0;
- while (resultSet.next()) {
- String correctRow = correctResult.get(count++);
- StringBuilder rowRecordBuilder = new StringBuilder();
- for (int j = 1; j < columnCount; j++) {
- rowRecordBuilder.append(resultSet.getString(j)).append(",");
- }
- rowRecordBuilder.append(resultSet.getString(columnCount));
- assertEquals(correctRow, rowRecordBuilder.toString());
- }
- }
- statement.close();
- }
- }
-
- @Test
- public void testLocalQueryWithFilterByBatch() throws Exception {
-
- initCorrectResultsWithFilter();
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertBatchData(connection, createSQLs, insertSQLs);
- Statement statement = connection.createStatement();
-
- for(int i =0 ; i < queryStatementsWithFilter.length; i++) {
- String queryStatement = queryStatementsWithFilter[i];
- boolean hasResultSet = statement.execute(queryStatement);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- IoTDBResultMetadata resultSetMetaData = (IoTDBResultMetadata) resultSet.getMetaData();
- int columnCount = resultSetMetaData.getColumnCount();
- List<String> correctResult = queryCorrentResultsWithFilter.get(i);
- int count = 0;
- while (resultSet.next()) {
- String correctRow = correctResult.get(count++);
- StringBuilder rowRecordBuilder = new StringBuilder();
- for (int j = 1; j < columnCount; j++) {
- rowRecordBuilder.append(resultSet.getString(j)).append(",");
- }
- rowRecordBuilder.append(resultSet.getString(columnCount));
- assertEquals(correctRow, rowRecordBuilder.toString());
- }
- }
- statement.close();
- }
- }
-
- @Test
- public void testRemoteQueryWithoutFilterByBatch() throws Exception {
-
- QPExecutorUtils.setLocalNodeAddr("0.0.0.0", 0);
- initCorrectResultsWithoutFilter();
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertBatchData(connection, createSQLs, insertSQLs);
- Statement statement = connection.createStatement();
-
- for(int i =0 ; i < queryStatementsWithoutFilter.length; i++) {
- String queryStatement = queryStatementsWithoutFilter[i];
- boolean hasResultSet = statement.execute(queryStatement);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- IoTDBResultMetadata resultSetMetaData = (IoTDBResultMetadata) resultSet.getMetaData();
- int columnCount = resultSetMetaData.getColumnCount();
- List<String> correctResult = queryCorrentResultsWithoutFilter.get(i);
- int count = 0;
- while (resultSet.next()) {
- String correctRow = correctResult.get(count++);
- StringBuilder rowRecordBuilder = new StringBuilder();
- for (int j = 1; j < columnCount; j++) {
- rowRecordBuilder.append(resultSet.getString(j)).append(",");
- }
- rowRecordBuilder.append(resultSet.getString(columnCount));
- assertEquals(correctRow, rowRecordBuilder.toString());
- }
- }
- QPExecutorUtils.setLocalNodeAddr(localNode.getIp(), localNode.getPort());
- statement.close();
- }
- }
-
- @Test
- public void testRemoteQueryWithFilterByBatch() throws Exception {
-
- QPExecutorUtils.setLocalNodeAddr("0.0.0.0", 0);
- initCorrectResultsWithFilter();
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertBatchData(connection, createSQLs, insertSQLs);
- Statement statement = connection.createStatement();
-
- for(int i =0 ; i < queryStatementsWithFilter.length; i++) {
- String queryStatement = queryStatementsWithFilter[i];
- boolean hasResultSet = statement.execute(queryStatement);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- IoTDBResultMetadata resultSetMetaData = (IoTDBResultMetadata) resultSet.getMetaData();
- int columnCount = resultSetMetaData.getColumnCount();
- List<String> correctResult = queryCorrentResultsWithFilter.get(i);
- int count = 0;
- while (resultSet.next()) {
- String correctRow = correctResult.get(count++);
- StringBuilder rowRecordBuilder = new StringBuilder();
- for (int j = 1; j < columnCount; j++) {
- rowRecordBuilder.append(resultSet.getString(j)).append(",");
- }
- rowRecordBuilder.append(resultSet.getString(columnCount));
- assertEquals(correctRow, rowRecordBuilder.toString());
- }
- }
- QPExecutorUtils.setLocalNodeAddr(localNode.getIp(), localNode.getPort());
- statement.close();
- }
- }
-
-}
diff --git a/cluster/src/test/java/org/apache/iotdb/cluster/query/manager/ClusterLocalManagerTest.java b/cluster/src/test/java/org/apache/iotdb/cluster/query/manager/ClusterLocalManagerTest.java
deleted file mode 100644
index c09aaa5..0000000
--- a/cluster/src/test/java/org/apache/iotdb/cluster/query/manager/ClusterLocalManagerTest.java
+++ /dev/null
@@ -1,406 +0,0 @@
-/**
- * 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.cluster.query.manager;
-
-import static org.apache.iotdb.cluster.utils.Utils.insertData;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
-import org.apache.iotdb.cluster.config.ClusterConfig;
-import org.apache.iotdb.cluster.config.ClusterDescriptor;
-import org.apache.iotdb.cluster.entity.Server;
-import org.apache.iotdb.cluster.query.manager.querynode.ClusterLocalQueryManager;
-import org.apache.iotdb.cluster.query.manager.querynode.ClusterLocalSingleQueryManager;
-import org.apache.iotdb.cluster.query.reader.querynode.ClusterBatchReaderByTimestamp;
-import org.apache.iotdb.cluster.query.reader.querynode.ClusterBatchReaderWithoutTimeGenerator;
-import org.apache.iotdb.cluster.query.reader.querynode.ClusterFilterSeriesBatchReader;
-import org.apache.iotdb.cluster.query.reader.querynode.AbstractClusterBatchReader;
-import org.apache.iotdb.cluster.utils.EnvironmentUtils;
-import org.apache.iotdb.cluster.utils.QPExecutorUtils;
-import org.apache.iotdb.cluster.utils.hash.PhysicalNode;
-import org.apache.iotdb.jdbc.Config;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.common.Path;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ClusterLocalManagerTest {
-
- private Server server;
- private static final ClusterConfig CLUSTER_CONFIG = ClusterDescriptor.getInstance().getConfig();
- private static ClusterLocalQueryManager manager = ClusterLocalQueryManager.getInstance();
- private static final PhysicalNode localNode = new PhysicalNode(CLUSTER_CONFIG.getIp(),
- CLUSTER_CONFIG.getPort());
- private static final String URL = "127.0.0.1:6667/";
-
- private String[] createSQLs = {
- "set storage group to root.vehicle",
- "CREATE TIMESERIES root.vehicle.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE",
- "CREATE TIMESERIES root.vehicle.d0.s1 WITH DATATYPE=TEXT, ENCODING=PLAIN",
- "CREATE TIMESERIES root.vehicle.d0.s3 WITH DATATYPE=TEXT, ENCODING=PLAIN"
- };
- private String[] insertSQLs = {
- "insert into root.vehicle.d0(timestamp,s0) values(10,100)",
- "insert into root.vehicle.d0(timestamp,s0,s1) values(12,101,'102')",
- "insert into root.vehicle.d0(timestamp,s3) values(19,'103')",
- "insert into root.vehicle.d0(timestamp,s0,s1) values(22,1031,'3102')",
- "insert into root.vehicle.d0(timestamp,s1) values(192,'1033')"
- };
- private String queryStatementsWithoutFilter = "select * from root.vehicle";
- private String queryStatementsWithFilter = "select * from root.vehicle where d0.s0 > 10 and d0.s0 < 101 or d0.s0 = 3";
-
- @Before
- public void setUp() throws Exception {
- EnvironmentUtils.cleanEnv();
- EnvironmentUtils.closeStatMonitor();
- EnvironmentUtils.closeMemControl();
- QPExecutorUtils.setLocalNodeAddr("0.0.0.0", 0);
- CLUSTER_CONFIG.createAllPath();
- server = Server.getInstance();
- server.start();
- EnvironmentUtils.envSetUp();
- Class.forName(Config.JDBC_DRIVER_NAME);
- }
-
- @After
- public void tearDown() throws Exception {
- server.stop();
- QPExecutorUtils.setLocalNodeAddr(localNode.getIp(), localNode.getPort());
- EnvironmentUtils.cleanEnv();
- }
-
- @Test
- public void testClusterLocalQueryManagerWithoutFilter() throws Exception {
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertData(connection, createSQLs, insertSQLs);
- Statement statement = connection.createStatement();
-
- // first query
- boolean hasResultSet = statement.execute(queryStatementsWithoutFilter);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- ConcurrentHashMap<String, Long> map = ClusterLocalQueryManager.getTaskIdMapJobId();
- assertEquals(1, map.size());
- for (String taskId : map.keySet()) {
- assertNotNull(manager.getSingleQuery(taskId));
- }
-
- // second query
- hasResultSet = statement.execute(queryStatementsWithoutFilter);
- assertTrue(hasResultSet);
- resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- map = ClusterLocalQueryManager.getTaskIdMapJobId();
- assertEquals(2, map.size());
- for (String taskId : map.keySet()) {
- assertNotNull(manager.getSingleQuery(taskId));
- }
-
- // third query
- hasResultSet = statement.execute(queryStatementsWithoutFilter);
- assertTrue(hasResultSet);
- resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- map = ClusterLocalQueryManager.getTaskIdMapJobId();
- assertEquals(3, map.size());
- for (String taskId : map.keySet()) {
- assertNotNull(manager.getSingleQuery(taskId));
- }
- statement.close();
- }
- }
-
- @Test
- public void testClusterLocalQueryManagerWithFilter() throws Exception {
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertData(connection, createSQLs, insertSQLs);
- Statement statement = connection.createStatement();
-
- // first query
- boolean hasResultSet = statement.execute(queryStatementsWithFilter);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- assertEquals(10, resultSet.getLong(1));
- assertEquals(100, resultSet.getInt(2));
- assertNull(resultSet.getString(3));
- assertNull(resultSet.getString(4));
- ConcurrentHashMap<String, Long> map = ClusterLocalQueryManager.getTaskIdMapJobId();
- assertEquals(1, map.size());
- for (String taskId : map.keySet()) {
- assertNotNull(manager.getSingleQuery(taskId));
- }
- assertFalse(resultSet.next());
-
- // second query
- hasResultSet = statement.execute(queryStatementsWithFilter);
- assertTrue(hasResultSet);
- resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- assertEquals(10, resultSet.getLong(1));
- assertEquals(100, resultSet.getInt(2));
- assertNull(resultSet.getString(3));
- assertNull(resultSet.getString(4));
- map = ClusterLocalQueryManager.getTaskIdMapJobId();
- assertEquals(2, map.size());
- for (String taskId : map.keySet()) {
- assertNotNull(manager.getSingleQuery(taskId));
- }
- assertFalse(resultSet.next());
-
- // third query
- hasResultSet = statement.execute(queryStatementsWithFilter);
- assertTrue(hasResultSet);
- resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- assertEquals(10, resultSet.getLong(1));
- assertEquals(100, resultSet.getInt(2));
- assertNull(resultSet.getString(3));
- assertNull(resultSet.getString(4));
- map = ClusterLocalQueryManager.getTaskIdMapJobId();
- assertEquals(3, map.size());
- for (String taskId : map.keySet()) {
- assertNotNull(manager.getSingleQuery(taskId));
- }
- assertFalse(resultSet.next());
-
- statement.close();
- }
- }
-
- @Test
- public void testClusterLocalSingleQueryWithoutFilterManager() throws Exception {
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertData(connection, createSQLs, insertSQLs);
- Statement statement = connection.createStatement();
-
- // first query
- boolean hasResultSet = statement.execute(queryStatementsWithoutFilter);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- ConcurrentHashMap<String, Long> map = ClusterLocalQueryManager.getTaskIdMapJobId();
- assertEquals(1, map.size());
- for (String taskId : map.keySet()) {
- ClusterLocalSingleQueryManager singleQueryManager = manager.getSingleQuery(taskId);
- assertNotNull(singleQueryManager);
- assertEquals((long) map.get(taskId), singleQueryManager.getJobId());
- assertEquals(0, singleQueryManager.getQueryRound());
- assertNull(singleQueryManager.getFilterReader());
- Map<String, AbstractClusterBatchReader> selectSeriesReaders = singleQueryManager
- .getSelectSeriesReaders();
- assertEquals(3, selectSeriesReaders.size());
- Map<String, TSDataType> typeMap = singleQueryManager.getDataTypeMap();
- for (Entry<String, AbstractClusterBatchReader> entry : selectSeriesReaders.entrySet()) {
- String path = entry.getKey();
- TSDataType dataType = typeMap.get(path);
- AbstractClusterBatchReader clusterBatchReader = entry.getValue();
- assertNotNull(((ClusterBatchReaderWithoutTimeGenerator) clusterBatchReader).getReader());
- assertEquals(dataType,
- ((ClusterBatchReaderWithoutTimeGenerator) clusterBatchReader).getDataType());
- }
- }
-
- // second query
- hasResultSet = statement.execute(queryStatementsWithoutFilter);
- assertTrue(hasResultSet);
- resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- map = ClusterLocalQueryManager.getTaskIdMapJobId();
- assertEquals(2, map.size());
- for (String taskId : map.keySet()) {
- ClusterLocalSingleQueryManager singleQueryManager = manager.getSingleQuery(taskId);
- assertNotNull(singleQueryManager);
- assertEquals((long) map.get(taskId), singleQueryManager.getJobId());
- assertEquals(0, singleQueryManager.getQueryRound());
- assertNull(singleQueryManager.getFilterReader());
- Map<String, AbstractClusterBatchReader> selectSeriesReaders = singleQueryManager
- .getSelectSeriesReaders();
- assertEquals(3, selectSeriesReaders.size());
- Map<String, TSDataType> typeMap = singleQueryManager.getDataTypeMap();
- for (Entry<String, AbstractClusterBatchReader> entry : selectSeriesReaders.entrySet()) {
- String path = entry.getKey();
- TSDataType dataType = typeMap.get(path);
- AbstractClusterBatchReader clusterBatchReader = entry.getValue();
- assertNotNull(((ClusterBatchReaderWithoutTimeGenerator) clusterBatchReader).getReader());
- assertEquals(dataType,
- ((ClusterBatchReaderWithoutTimeGenerator) clusterBatchReader).getDataType());
- }
- }
-
- // third query
- hasResultSet = statement.execute(queryStatementsWithoutFilter);
- assertTrue(hasResultSet);
- resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- map = ClusterLocalQueryManager.getTaskIdMapJobId();
- assertEquals(3, map.size());
- for (String taskId : map.keySet()) {
- ClusterLocalSingleQueryManager singleQueryManager = manager.getSingleQuery(taskId);
- assertNotNull(singleQueryManager);
- assertEquals((long) map.get(taskId), singleQueryManager.getJobId());
- assertEquals(0, singleQueryManager.getQueryRound());
- assertNull(singleQueryManager.getFilterReader());
- Map<String, AbstractClusterBatchReader> selectSeriesReaders = singleQueryManager
- .getSelectSeriesReaders();
- assertEquals(3, selectSeriesReaders.size());
- Map<String, TSDataType> typeMap = singleQueryManager.getDataTypeMap();
- for (Entry<String, AbstractClusterBatchReader> entry : selectSeriesReaders.entrySet()) {
- String path = entry.getKey();
- TSDataType dataType = typeMap.get(path);
- AbstractClusterBatchReader clusterBatchReader = entry.getValue();
- assertNotNull(((ClusterBatchReaderWithoutTimeGenerator) clusterBatchReader).getReader());
- assertEquals(dataType,
- ((ClusterBatchReaderWithoutTimeGenerator) clusterBatchReader).getDataType());
- }
- }
- statement.close();
- }
- }
-
- @Test
- public void testClusterLocalSingleQueryWithFilterManager() throws Exception {
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertData(connection, createSQLs, insertSQLs);
- Statement statement = connection.createStatement();
-
- // first query
- boolean hasResultSet = statement.execute(queryStatementsWithFilter);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- ConcurrentHashMap<String, Long> map = ClusterLocalQueryManager.getTaskIdMapJobId();
- assertEquals(1, map.size());
- for (String taskId : map.keySet()) {
- ClusterLocalSingleQueryManager singleQueryManager = manager.getSingleQuery(taskId);
- assertNotNull(singleQueryManager);
- assertEquals((long) map.get(taskId), singleQueryManager.getJobId());
- assertEquals(3, singleQueryManager.getQueryRound());
- ClusterFilterSeriesBatchReader filterReader = (ClusterFilterSeriesBatchReader) singleQueryManager.getFilterReader();
- assertNotNull(filterReader);
- List<Path> allFilterPaths = new ArrayList<>();
- allFilterPaths.add(new Path("root.vehicle.d0.s0"));
- assertTrue(allFilterPaths.containsAll(filterReader.getAllFilterPath()));
- assertNotNull(filterReader.getQueryDataSet());
-
- Map<String, AbstractClusterBatchReader> selectSeriesReaders = singleQueryManager
- .getSelectSeriesReaders();
- assertNotNull(selectSeriesReaders);
- assertEquals(3, selectSeriesReaders.size());
- Map<String, TSDataType> typeMap = singleQueryManager.getDataTypeMap();
- for (Entry<String, AbstractClusterBatchReader> entry : selectSeriesReaders.entrySet()) {
- String path = entry.getKey();
- TSDataType dataType = typeMap.get(path);
- AbstractClusterBatchReader clusterBatchReader = entry.getValue();
- assertNotNull(((ClusterBatchReaderByTimestamp) clusterBatchReader).getReaderByTimeStamp());
- assertEquals(dataType,
- ((ClusterBatchReaderByTimestamp) clusterBatchReader).getDataType());
- }
- }
-
- // second query
- hasResultSet = statement.execute(queryStatementsWithFilter);
- assertTrue(hasResultSet);
- resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- map = ClusterLocalQueryManager.getTaskIdMapJobId();
- assertEquals(2, map.size());
- for (String taskId : map.keySet()) {
- ClusterLocalSingleQueryManager singleQueryManager = manager.getSingleQuery(taskId);
- assertNotNull(singleQueryManager);
- assertEquals((long) map.get(taskId), singleQueryManager.getJobId());
- assertEquals(3, singleQueryManager.getQueryRound());
- ClusterFilterSeriesBatchReader filterReader = (ClusterFilterSeriesBatchReader) singleQueryManager.getFilterReader();
- assertNotNull(filterReader);
- List<Path> allFilterPaths = new ArrayList<>();
- allFilterPaths.add(new Path("root.vehicle.d0.s0"));
- assertTrue(allFilterPaths.containsAll(filterReader.getAllFilterPath()));
- assertNotNull(filterReader.getQueryDataSet());
-
- Map<String, AbstractClusterBatchReader> selectSeriesReaders = singleQueryManager
- .getSelectSeriesReaders();
- assertNotNull(selectSeriesReaders);
- assertEquals(3, selectSeriesReaders.size());
- Map<String, TSDataType> typeMap = singleQueryManager.getDataTypeMap();
- for (Entry<String, AbstractClusterBatchReader> entry : selectSeriesReaders.entrySet()) {
- String path = entry.getKey();
- TSDataType dataType = typeMap.get(path);
- AbstractClusterBatchReader clusterBatchReader = entry.getValue();
- assertNotNull(((ClusterBatchReaderByTimestamp) clusterBatchReader).getReaderByTimeStamp());
- assertEquals(dataType,
- ((ClusterBatchReaderByTimestamp) clusterBatchReader).getDataType());
- }
- }
-
- // third query
- hasResultSet = statement.execute(queryStatementsWithFilter);
- assertTrue(hasResultSet);
- resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- map = ClusterLocalQueryManager.getTaskIdMapJobId();
- assertEquals(3, map.size());
- for (String taskId : map.keySet()) {
- ClusterLocalSingleQueryManager singleQueryManager = manager.getSingleQuery(taskId);
- assertNotNull(singleQueryManager);
- assertEquals((long) map.get(taskId), singleQueryManager.getJobId());
- assertEquals(3, singleQueryManager.getQueryRound());
- ClusterFilterSeriesBatchReader filterReader = (ClusterFilterSeriesBatchReader) singleQueryManager.getFilterReader();
- assertNotNull(filterReader);
- List<Path> allFilterPaths = new ArrayList<>();
- allFilterPaths.add(new Path("root.vehicle.d0.s0"));
- assertTrue(allFilterPaths.containsAll(filterReader.getAllFilterPath()));
- assertNotNull(filterReader.getQueryDataSet());
-
- Map<String, AbstractClusterBatchReader> selectSeriesReaders = singleQueryManager
- .getSelectSeriesReaders();
- assertNotNull(selectSeriesReaders);
- assertEquals(3, selectSeriesReaders.size());
- Map<String, TSDataType> typeMap = singleQueryManager.getDataTypeMap();
- for (Entry<String, AbstractClusterBatchReader> entry : selectSeriesReaders.entrySet()) {
- String path = entry.getKey();
- TSDataType dataType = typeMap.get(path);
- AbstractClusterBatchReader clusterBatchReader = entry.getValue();
- assertNotNull(((ClusterBatchReaderByTimestamp) clusterBatchReader).getReaderByTimeStamp());
- assertEquals(dataType,
- ((ClusterBatchReaderByTimestamp) clusterBatchReader).getDataType());
- }
- }
- statement.close();
- }
- }
-
-}
diff --git a/cluster/src/test/java/org/apache/iotdb/cluster/query/manager/ClusterRpcManagerTest.java b/cluster/src/test/java/org/apache/iotdb/cluster/query/manager/ClusterRpcManagerTest.java
deleted file mode 100644
index b800fbf..0000000
--- a/cluster/src/test/java/org/apache/iotdb/cluster/query/manager/ClusterRpcManagerTest.java
+++ /dev/null
@@ -1,334 +0,0 @@
-/**
- * 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.cluster.query.manager;
-
-import static org.apache.iotdb.cluster.utils.Utils.insertData;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
-import org.apache.iotdb.cluster.config.ClusterConfig;
-import org.apache.iotdb.cluster.config.ClusterDescriptor;
-import org.apache.iotdb.cluster.entity.Server;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcQueryManager;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcSingleQueryManager;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.FilterGroupEntity;
-import org.apache.iotdb.cluster.utils.EnvironmentUtils;
-import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
-import org.apache.iotdb.jdbc.Config;
-import org.apache.iotdb.tsfile.read.common.Path;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ClusterRpcManagerTest {
-
-
- private Server server;
- private static final ClusterConfig CLUSTER_CONFIG = ClusterDescriptor.getInstance().getConfig();
- private static final String LOCAL_ADDR = String
- .format("%s:%d", CLUSTER_CONFIG.getIp(), CLUSTER_CONFIG.getPort());
- private static ClusterRpcQueryManager manager = ClusterRpcQueryManager.getInstance();
-
- private static final String URL = "127.0.0.1:6667/";
-
- private String[] createSQLs = {
- "set storage group to root.vehicle",
- "CREATE TIMESERIES root.vehicle.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE",
- "CREATE TIMESERIES root.vehicle.d0.s1 WITH DATATYPE=TEXT, ENCODING=PLAIN",
- "CREATE TIMESERIES root.vehicle.d0.s3 WITH DATATYPE=TEXT, ENCODING=PLAIN"
- };
- private String[] insertSQLs = {
- "insert into root.vehicle.d0(timestamp,s0) values(10,100)",
- "insert into root.vehicle.d0(timestamp,s0,s1) values(12,101,'102')",
- "insert into root.vehicle.d0(timestamp,s3) values(19,'103')",
- "insert into root.vehicle.d0(timestamp,s0,s1) values(22,1031,'3102')",
- "insert into root.vehicle.d0(timestamp,s1) values(192,'1033')"
- };
- private String queryStatementsWithoutFilter = "select * from root.vehicle";
- private String queryStatementsWithFilter = "select * from root.vehicle where d0.s0 > 10 and d0.s0 < 101 or d0.s0 = 3";
-
- @Before
- public void setUp() throws Exception {
- EnvironmentUtils.cleanEnv();
- EnvironmentUtils.closeStatMonitor();
- EnvironmentUtils.closeMemControl();
- CLUSTER_CONFIG.createAllPath();
- server = Server.getInstance();
- server.start();
- EnvironmentUtils.envSetUp();
- Class.forName(Config.JDBC_DRIVER_NAME);
- }
-
- @After
- public void tearDown() throws Exception {
- server.stop();
- EnvironmentUtils.cleanEnv();
- }
-
- @Test
- public void testClusterRpcQueryManagerWithoutFilter() throws Exception {
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertData(connection, createSQLs, insertSQLs);
- Statement statement = connection.createStatement();
-
- // first query
- boolean hasResultSet = statement.execute(queryStatementsWithoutFilter);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- ConcurrentHashMap<Long, String> map = ClusterRpcQueryManager.getJobIdMapTaskId();
- assertEquals(1, map.size());
- for (String taskId : map.values()) {
- assertNotNull(manager.getSingleQuery(taskId));
- }
- for (long jobId : map.keySet()) {
- assertNotNull(manager.getSingleQuery(jobId));
- }
- for (Entry<Long, String> entry : map.entrySet()) {
- long jobId = entry.getKey();
- String taskId = entry.getValue();
- assertEquals(taskId, String.format("%s:%d", LOCAL_ADDR, jobId));
- }
-
- // second query
- hasResultSet = statement.execute(queryStatementsWithoutFilter);
- assertTrue(hasResultSet);
- resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- map = ClusterRpcQueryManager.getJobIdMapTaskId();
- assertEquals(2, map.size());
- for (String taskId : map.values()) {
- assertNotNull(manager.getSingleQuery(taskId));
- }
- for (long jobId : map.keySet()) {
- assertNotNull(manager.getSingleQuery(jobId));
- }
- for (Entry<Long, String> entry : map.entrySet()) {
- long jobId = entry.getKey();
- String taskId = entry.getValue();
- assertEquals(taskId, String.format("%s:%d", LOCAL_ADDR, jobId));
- }
-
- // third query
- hasResultSet = statement.execute(queryStatementsWithoutFilter);
- assertTrue(hasResultSet);
- resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- map = ClusterRpcQueryManager.getJobIdMapTaskId();
- assertEquals(3, map.size());
- for (String taskId : map.values()) {
- assertNotNull(manager.getSingleQuery(taskId));
- }
- for (long jobId : map.keySet()) {
- assertNotNull(manager.getSingleQuery(jobId));
- }
- for (Entry<Long, String> entry : map.entrySet()) {
- long jobId = entry.getKey();
- String taskId = entry.getValue();
- assertEquals(taskId, String.format("%s:%d", LOCAL_ADDR, jobId));
- }
- statement.close();
- }
- }
-
- @Test
- public void testClusterRpcQueryManagerWithFilter() throws Exception {
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertData(connection, createSQLs, insertSQLs);
- Statement statement = connection.createStatement();
-
- // first query
- boolean hasResultSet = statement.execute(queryStatementsWithFilter);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- assertEquals(10, resultSet.getLong(1));
- assertEquals(100, resultSet.getInt(2));
- assertNull(resultSet.getString(3));
- assertNull(resultSet.getString(4));
- ConcurrentHashMap<Long, String> map = ClusterRpcQueryManager.getJobIdMapTaskId();
- assertEquals(1, map.size());
- for (String taskId : map.values()) {
- assertNotNull(manager.getSingleQuery(taskId));
- }
- for (long jobId : map.keySet()) {
- assertNotNull(manager.getSingleQuery(jobId));
- }
- for (Entry<Long, String> entry : map.entrySet()) {
- long jobId = entry.getKey();
- String taskId = entry.getValue();
- assertEquals(taskId, String.format("%s:%d", LOCAL_ADDR, jobId));
- }
- assertFalse(resultSet.next());
-
- // second query
- hasResultSet = statement.execute(queryStatementsWithFilter);
- assertTrue(hasResultSet);
- resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- assertEquals(10, resultSet.getLong(1));
- assertEquals(100, resultSet.getInt(2));
- assertNull(resultSet.getString(3));
- assertNull(resultSet.getString(4));
- map = ClusterRpcQueryManager.getJobIdMapTaskId();
- assertEquals(2, map.size());
- for (String taskId : map.values()) {
- assertNotNull(manager.getSingleQuery(taskId));
- }
- for (long jobId : map.keySet()) {
- assertNotNull(manager.getSingleQuery(jobId));
- }
- for (Entry<Long, String> entry : map.entrySet()) {
- long jobId = entry.getKey();
- String taskId = entry.getValue();
- assertEquals(taskId, String.format("%s:%d", LOCAL_ADDR, jobId));
- }
- assertFalse(resultSet.next());
-
- // third query
- hasResultSet = statement.execute(queryStatementsWithFilter);
- assertTrue(hasResultSet);
- resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- assertEquals(10, resultSet.getLong(1));
- assertEquals(100, resultSet.getInt(2));
- assertNull(resultSet.getString(3));
- assertNull(resultSet.getString(4));
- map = ClusterRpcQueryManager.getJobIdMapTaskId();
- assertEquals(3, map.size());
- for (String taskId : map.values()) {
- assertNotNull(manager.getSingleQuery(taskId));
- }
- for (long jobId : map.keySet()) {
- assertNotNull(manager.getSingleQuery(jobId));
- }
- for (Entry<Long, String> entry : map.entrySet()) {
- long jobId = entry.getKey();
- String taskId = entry.getValue();
- assertEquals(taskId, String.format("%s:%d", LOCAL_ADDR, jobId));
- }
- assertFalse(resultSet.next());
- statement.close();
- }
- }
-
- @Test
- public void testClusterRpcSingleQueryWithoutFilterManager() throws Exception {
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertData(connection, createSQLs, insertSQLs);
- Statement statement = connection.createStatement();
- boolean hasResultSet = statement.execute(queryStatementsWithoutFilter);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- ConcurrentHashMap<Long, String> map = ClusterRpcQueryManager.getJobIdMapTaskId();
- assertEquals(1, map.size());
- for (String taskId : map.values()) {
- ClusterRpcSingleQueryManager singleManager = manager.getSingleQuery(taskId);
- assertNotNull(singleManager);
- assertEquals(0, singleManager.getQueryRounds());
- assertEquals(taskId, singleManager.getTaskId());
-
- // select path plans
- Map<String, QueryPlan> selectPathPlans = singleManager.getSelectPathPlans();
- assertEquals(1, selectPathPlans.size());
- for (QueryPlan queryPlan : selectPathPlans.values()) {
- List<Path> paths = queryPlan.getPaths();
- List<Path> correctPaths = new ArrayList<>();
- correctPaths.add(new Path("root.vehicle.d0.s0"));
- correctPaths.add(new Path("root.vehicle.d0.s1"));
- correctPaths.add(new Path("root.vehicle.d0.s3"));
- assertEquals(correctPaths, paths);
- assertNull(queryPlan.getExpression());
- }
-
- // select series by group id
- assertEquals(0, singleManager.getSelectSeriesByGroupId().size());
-
- // select series reader
- assertTrue(singleManager
- .getSelectSeriesReaders().isEmpty());
-
- }
- statement.close();
- }
- }
-
- @Test
- public void testClusterRpcSingleQueryWithFilterManager() throws Exception {
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertData(connection, createSQLs, insertSQLs);
- Statement statement = connection.createStatement();
- boolean hasResultSet = statement.execute(queryStatementsWithFilter);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- ConcurrentHashMap<Long, String> map = ClusterRpcQueryManager.getJobIdMapTaskId();
- assertEquals(1, map.size());
- for (String taskId : map.values()) {
- ClusterRpcSingleQueryManager singleManager = manager.getSingleQuery(taskId);
- assertNotNull(singleManager);
- assertEquals(0, singleManager.getQueryRounds());
- assertEquals(taskId, singleManager.getTaskId());
-
- // select path plans
- Map<String, QueryPlan> selectPathPlans = singleManager.getSelectPathPlans();
- assertEquals(1, selectPathPlans.size());
- for (QueryPlan queryPlan : selectPathPlans.values()) {
- List<Path> paths = queryPlan.getPaths();
- List<Path> correctPaths = new ArrayList<>();
- correctPaths.add(new Path("root.vehicle.d0.s0"));
- correctPaths.add(new Path("root.vehicle.d0.s1"));
- correctPaths.add(new Path("root.vehicle.d0.s3"));
- assertEquals(correctPaths, paths);
- assertNotNull(queryPlan.getExpression());
- }
-
- // select series by group id
- assertTrue(singleManager.getSelectSeriesByGroupId().isEmpty());
-
- // select series reader
- assertTrue(singleManager
- .getSelectSeriesReaders().isEmpty());
-
- // filter path plans
- Map<String, FilterGroupEntity> filterGroupEntityMap = singleManager.getFilterGroupEntityMap();
- assertTrue(filterGroupEntityMap.isEmpty());
-
- }
- statement.close();
- }
- }
-}
\ No newline at end of file
diff --git a/cluster/src/test/java/org/apache/iotdb/cluster/query/utils/ExpressionUtilsTest.java b/cluster/src/test/java/org/apache/iotdb/cluster/query/utils/ExpressionUtilsTest.java
deleted file mode 100644
index 84f8f5f..0000000
--- a/cluster/src/test/java/org/apache/iotdb/cluster/query/utils/ExpressionUtilsTest.java
+++ /dev/null
@@ -1,230 +0,0 @@
-/**
- * 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.cluster.query.utils;
-
-import static org.apache.iotdb.cluster.utils.Utils.insertData;
-import static org.junit.Assert.*;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
-import org.apache.iotdb.cluster.config.ClusterConfig;
-import org.apache.iotdb.cluster.config.ClusterDescriptor;
-import org.apache.iotdb.cluster.entity.Server;
-import org.apache.iotdb.cluster.qp.executor.ClusterQueryProcessExecutor;
-import org.apache.iotdb.cluster.query.expression.TrueExpression;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcQueryManager;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcSingleQueryManager;
-import org.apache.iotdb.cluster.utils.EnvironmentUtils;
-import org.apache.iotdb.db.qp.QueryProcessor;
-import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
-import org.apache.iotdb.jdbc.Config;
-import org.apache.iotdb.tsfile.read.common.Path;
-import org.apache.iotdb.tsfile.read.expression.IExpression;
-import org.apache.iotdb.tsfile.read.expression.QueryExpression;
-import org.apache.iotdb.tsfile.read.expression.util.ExpressionOptimizer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ExpressionUtilsTest {
- private Server server;
- private static final ClusterConfig CLUSTER_CONFIG = ClusterDescriptor.getInstance().getConfig();
- private ClusterQueryProcessExecutor queryDataExecutor = new ClusterQueryProcessExecutor();
- private QueryProcessor queryProcessor = new QueryProcessor(queryDataExecutor);
-
- private static final String URL = "127.0.0.1:6667/";
-
- private String[] createSQLs = {
- "set storage group to root.vehicle1",
- "set storage group to root.vehicle2",
- "set storage group to root.vehicle3",
- "CREATE TIMESERIES root.vehicle1.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE",
- "CREATE TIMESERIES root.vehicle1.d0.s1 WITH DATATYPE=INT32, ENCODING=PLAIN",
- "CREATE TIMESERIES root.vehicle2.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE",
- "CREATE TIMESERIES root.vehicle2.d0.s1 WITH DATATYPE=INT32, ENCODING=PLAIN",
- "CREATE TIMESERIES root.vehicle3.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE",
- "CREATE TIMESERIES root.vehicle3.d0.s1 WITH DATATYPE=INT32, ENCODING=PLAIN"
- };
- private String[] insertSQLs = {
- "insert into root.vehicle1.d0(timestamp,s0) values(10,100)",
- "insert into root.vehicle1.d0(timestamp,s0,s1) values(200,100,102)",
- "insert into root.vehicle2.d0(timestamp,s0) values(10,120)",
- "insert into root.vehicle2.d0(timestamp,s0,s1) values(200,300,3102)",
- "insert into root.vehicle3.d0(timestamp,s1) values(100,100)",
- "insert into root.vehicle3.d0(timestamp,s0,s1) values(10,200,200)",
- "insert into root.vehicle3.d0(timestamp,s1) values(300,3000)"
- };
-
- private String[] pruneFilterTreeStatement = {
- "select * from root where vehicle1.d0.s0 > 10 or (vehicle2.d0.s1 < 10001 and vehicle1.d0.s1 = 3)",
- "select * from root where vehicle1.d0.s0 > 10 or (vehicle2.d0.s1 < 10001 and time < 1555938482600)",
- "select * from root where vehicle1.d0.s0 > 10 and not(vehicle2.d0.s1 < 10001 or vehicle1.d0.s1 = 3)"
- };
-
- private static final IExpression[] correntPruneFilterTree = new IExpression[6];
-
- @Before
- public void setUp() throws Exception {
- EnvironmentUtils.cleanEnv();
- EnvironmentUtils.closeStatMonitor();
- EnvironmentUtils.closeMemControl();
- CLUSTER_CONFIG.createAllPath();
- server = Server.getInstance();
- server.start();
- EnvironmentUtils.envSetUp();
- Class.forName(Config.JDBC_DRIVER_NAME);
- }
-
- @After
- public void tearDown() throws Exception {
- server.stop();
- EnvironmentUtils.cleanEnv();
- }
-
- private void initCorrectResult() throws Exception {
-
- // result of prune filter tree
- QueryPlan queryPlan = (QueryPlan) queryProcessor.parseSQLToPhysicalPlan(
- "select vehicle1.d0.s0,vehicle1.d0.s1 from root where vehicle1.d0.s0 > 10 or vehicle1.d0.s1 = 3");
- QueryExpression queryExpression = QueryExpression.create().setSelectSeries(queryPlan.getPaths())
- .setExpression(queryPlan.getExpression());
- IExpression optimizedExpression = ExpressionOptimizer.getInstance()
- .optimize(queryExpression.getExpression(), queryExpression.getSelectedSeries());
- assertEquals(optimizedExpression.toString(), optimizedExpression.clone().toString());
- assertNotSame(optimizedExpression, optimizedExpression.clone());
- queryPlan.setExpression(optimizedExpression);
- correntPruneFilterTree[0] = optimizedExpression;
-
- queryPlan = (QueryPlan) queryProcessor
- .parseSQLToPhysicalPlan("select vehicle1.d0.s0 from root");
- assertNull(queryPlan.getExpression());
- correntPruneFilterTree[1] = new TrueExpression();
-
- queryPlan = (QueryPlan) queryProcessor
- .parseSQLToPhysicalPlan("select vehicle1.d0.s0 from root");
- assertNull(queryPlan.getExpression());
- correntPruneFilterTree[2] = new TrueExpression();
-
- queryPlan = (QueryPlan) queryProcessor
- .parseSQLToPhysicalPlan("select vehicle2.d0.s1 from root");
- assertNull(queryPlan.getExpression());
- correntPruneFilterTree[3] = new TrueExpression();
-
- queryPlan = (QueryPlan) queryProcessor
- .parseSQLToPhysicalPlan("select vehicle1.d0.s0 from root");
- assertNull(queryPlan.getExpression());
- correntPruneFilterTree[4] = new TrueExpression();
-
- queryPlan = (QueryPlan) queryProcessor
- .parseSQLToPhysicalPlan("select vehicle2.d0.s1 from root");
- assertNull(queryPlan.getExpression());
- correntPruneFilterTree[5] = new TrueExpression();
-
- }
-
- @Test
- public void getAllExpressionSeries() {
- }
-
- @Test
- public void pruneFilterTrue() throws Exception{
- QueryPlan queryPlan;
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertData(connection, createSQLs, insertSQLs);
- initCorrectResult();
- }
-
- // first
- queryPlan = (QueryPlan) queryProcessor
- .parseSQLToPhysicalPlan(pruneFilterTreeStatement[0]);
- QueryExpression queryExpression = QueryExpression.create()
- .setSelectSeries(queryPlan.getPaths())
- .setExpression(queryPlan.getExpression());
- IExpression optimizedExpression = ExpressionOptimizer.getInstance()
- .optimize(queryExpression.getExpression(), queryExpression.getSelectedSeries());
- queryPlan.setExpression(optimizedExpression);
- assertEquals(optimizedExpression.toString(), optimizedExpression.clone().toString());
- assertNotSame(optimizedExpression, optimizedExpression.clone());
- List<Path> pathList = new ArrayList<>();
- pathList.add(new Path("root.vehicle1.d0.s0"));
- pathList.add(new Path("root.vehicle1.d0.s1"));
- IExpression pruneExpression = ExpressionUtils.pruneFilterTree(optimizedExpression.clone(), pathList);
- assertEquals(correntPruneFilterTree[0].toString(), pruneExpression.toString());
-
- pathList=new ArrayList<>();
- pathList.add(new Path("root.vehicle2.d0.s1"));
- pruneExpression = ExpressionUtils.pruneFilterTree(optimizedExpression.clone(), pathList);
- assertEquals(correntPruneFilterTree[1].toString(), pruneExpression.toString());
-
- // second
- queryPlan = (QueryPlan) queryProcessor
- .parseSQLToPhysicalPlan(pruneFilterTreeStatement[1]);
- queryExpression = QueryExpression.create()
- .setSelectSeries(queryPlan.getPaths())
- .setExpression(queryPlan.getExpression());
- optimizedExpression = ExpressionOptimizer.getInstance()
- .optimize(queryExpression.getExpression(), queryExpression.getSelectedSeries());
- queryPlan.setExpression(optimizedExpression);
- assertEquals(optimizedExpression.toString(), optimizedExpression.clone().toString());
- assertNotSame(optimizedExpression, optimizedExpression.clone());
- pathList = new ArrayList<>();
- pathList.add(new Path("root.vehicle1.d0.s0"));
- pruneExpression = ExpressionUtils.pruneFilterTree(optimizedExpression.clone(), pathList);
- assertEquals(correntPruneFilterTree[2].toString(), pruneExpression.toString());
-
- pathList=new ArrayList<>();
- pathList.add(new Path("root.vehicle2.d0.s1"));
- pruneExpression = ExpressionUtils.pruneFilterTree(optimizedExpression.clone(), pathList);
- assertEquals(correntPruneFilterTree[3].toString(), pruneExpression.toString());
-
- // third
- queryPlan = (QueryPlan) queryProcessor
- .parseSQLToPhysicalPlan(pruneFilterTreeStatement[1]);
- queryExpression = QueryExpression.create()
- .setSelectSeries(queryPlan.getPaths())
- .setExpression(queryPlan.getExpression());
- optimizedExpression = ExpressionOptimizer.getInstance()
- .optimize(queryExpression.getExpression(), queryExpression.getSelectedSeries());
- queryPlan.setExpression(optimizedExpression);
- assertEquals(optimizedExpression.toString(), optimizedExpression.clone().toString());
- assertNotSame(optimizedExpression, optimizedExpression.clone());
- pathList = new ArrayList<>();
- pathList.add(new Path("root.vehicle1.d0.s0"));
- pathList.add(new Path("root.vehicle1.d0.s1"));
- pruneExpression = ExpressionUtils.pruneFilterTree(optimizedExpression.clone(), pathList);
- assertEquals(correntPruneFilterTree[4].toString(), pruneExpression.toString());
-
- pathList=new ArrayList<>();
- pathList.add(new Path("root.vehicle2.d0.s1"));
- pruneExpression = ExpressionUtils.pruneFilterTree(optimizedExpression.clone(), pathList);
- assertEquals(correntPruneFilterTree[5].toString(), pruneExpression.toString());
-
- }
-
-}
\ No newline at end of file
diff --git a/cluster/src/test/java/org/apache/iotdb/cluster/query/utils/QueryPlanPartitionUtilsTest.java b/cluster/src/test/java/org/apache/iotdb/cluster/query/utils/QueryPlanPartitionUtilsTest.java
deleted file mode 100644
index a0d409b..0000000
--- a/cluster/src/test/java/org/apache/iotdb/cluster/query/utils/QueryPlanPartitionUtilsTest.java
+++ /dev/null
@@ -1,332 +0,0 @@
-/**
- * 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.cluster.query.utils;
-
-import static org.apache.iotdb.cluster.utils.Utils.insertData;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.Statement;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
-import org.apache.iotdb.cluster.config.ClusterConfig;
-import org.apache.iotdb.cluster.config.ClusterDescriptor;
-import org.apache.iotdb.cluster.entity.Server;
-import org.apache.iotdb.cluster.qp.executor.ClusterQueryProcessExecutor;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcQueryManager;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.ClusterRpcSingleQueryManager;
-import org.apache.iotdb.cluster.query.manager.coordinatornode.FilterGroupEntity;
-import org.apache.iotdb.cluster.utils.EnvironmentUtils;
-import org.apache.iotdb.db.qp.QueryProcessor;
-import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
-import org.apache.iotdb.jdbc.Config;
-import org.apache.iotdb.tsfile.read.expression.IExpression;
-import org.apache.iotdb.tsfile.read.expression.QueryExpression;
-import org.apache.iotdb.tsfile.read.expression.util.ExpressionOptimizer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class QueryPlanPartitionUtilsTest {
-
- private Server server;
- private static final ClusterConfig CLUSTER_CONFIG = ClusterDescriptor.getInstance().getConfig();
- private static final String LOCAL_ADDR = String
- .format("%s:%d", CLUSTER_CONFIG.getIp(), CLUSTER_CONFIG.getPort());
- private static ClusterRpcQueryManager manager = ClusterRpcQueryManager.getInstance();
- private ClusterQueryProcessExecutor queryDataExecutor = new ClusterQueryProcessExecutor();
- private QueryProcessor queryProcessor = new QueryProcessor(queryDataExecutor);
-
- private static final String URL = "127.0.0.1:6667/";
-
- private String[] createSQLs = {
- "set storage group to root.vehicle1",
- "set storage group to root.vehicle2",
- "set storage group to root.vehicle3",
- "CREATE TIMESERIES root.vehicle1.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE",
- "CREATE TIMESERIES root.vehicle1.d0.s1 WITH DATATYPE=INT32, ENCODING=PLAIN",
- "CREATE TIMESERIES root.vehicle2.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE",
- "CREATE TIMESERIES root.vehicle2.d0.s1 WITH DATATYPE=INT32, ENCODING=PLAIN",
- "CREATE TIMESERIES root.vehicle3.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE",
- "CREATE TIMESERIES root.vehicle3.d0.s1 WITH DATATYPE=INT32, ENCODING=PLAIN"
- };
- private String[] insertSQLs = {
- "insert into root.vehicle1.d0(timestamp,s0) values(10,100)",
- "insert into root.vehicle1.d0(timestamp,s0,s1) values(200,100,102)",
- "insert into root.vehicle2.d0(timestamp,s0) values(10,120)",
- "insert into root.vehicle2.d0(timestamp,s0,s1) values(200,300,3102)",
- "insert into root.vehicle3.d0(timestamp,s1) values(100,100)",
- "insert into root.vehicle3.d0(timestamp,s0,s1) values(10,200,200)",
- "insert into root.vehicle3.d0(timestamp,s1) values(300,3000)"
- };
-
- private String[] queryStatementsWithoutFilters = {
- "select * from root",
- "select d0.s0 from root.vehicle2, root.vehicle3",
- "select vehicle1.d0.s1, vehicle2.d0.s1 from root"
- };
- private String[] queryStatementsWithFilters = {
- "select * from root where vehicle1.d0.s0 > 10 and (vehicle2.d0.s1 < 10001 or vehicle1.d0.s1 = 3)",
- "select * from root where not(vehicle1.d0.s0 < 10 and vehicle2.d0.s1 > 10001) or vehicle3.d0.s0 = 3",
- "select * from root.vehicle1 where d0.s0 > 10",
- "select * from root.vehicle2 where d0.s0 > 10 and time < 1555938482600",
- };
- private static final Map<Integer, QueryPlan> withoutFilterResults = new HashMap<>(4);
- private static final Map<Integer, QueryPlan> withFilterSelectResults = new HashMap<>(4);
- private static final Map<Integer, QueryPlan> withFilterFilterResults = new HashMap<>(4);
- private static final IExpression[] correntPruneFilterTree = new IExpression[2];
-
- @Before
- public void setUp() throws Exception {
- EnvironmentUtils.cleanEnv();
- EnvironmentUtils.closeStatMonitor();
- EnvironmentUtils.closeMemControl();
- CLUSTER_CONFIG.createAllPath();
- server = Server.getInstance();
- server.start();
- EnvironmentUtils.envSetUp();
- Class.forName(Config.JDBC_DRIVER_NAME);
- }
-
- @After
- public void tearDown() throws Exception {
- server.stop();
- EnvironmentUtils.cleanEnv();
- }
-
- private void initCorrectResult() throws Exception {
-
- QueryPlan queryPlan = (QueryPlan) queryProcessor
- .parseSQLToPhysicalPlan("select * from root.vehicle1,root.vehicle2, root.vehicle3");
- // without filter
- //1
- withoutFilterResults.put(1, queryPlan);
-
- //2
- queryPlan = (QueryPlan) queryProcessor
- .parseSQLToPhysicalPlan("select vehicle2.d0.s0, vehicle3.d0.s0 from root, root");
- withoutFilterResults.put(2, queryPlan);
-
- //3
- queryPlan = (QueryPlan) queryProcessor
- .parseSQLToPhysicalPlan("select vehicle1.d0.s1, vehicle2.d0.s1 from root");
- withoutFilterResults.put(3, queryPlan);
-
- // with filter
- //1
- queryPlan = (QueryPlan) queryProcessor.parseSQLToPhysicalPlan(
- "select * from root where vehicle1.d0.s0 > 10 and (vehicle2.d0.s1 < 10001 or vehicle1.d0.s1 = 3)");
- QueryExpression queryExpression = QueryExpression.create().setSelectSeries(queryPlan.getPaths())
- .setExpression(queryPlan.getExpression());
- IExpression optimizedExpression = ExpressionOptimizer.getInstance()
- .optimize(queryExpression.getExpression(), queryExpression.getSelectedSeries());
- assertEquals(optimizedExpression.toString(), optimizedExpression.clone().toString());
- assertNotSame(optimizedExpression, optimizedExpression.clone());
- queryPlan.setExpression(optimizedExpression);
- withFilterSelectResults.put(1, queryPlan);
-
- queryPlan = (QueryPlan) queryProcessor.parseSQLToPhysicalPlan(
- "select vehicle1.d0.s0,vehicle2.d0.s1,vehicle1.d0.s1 from root where vehicle1.d0.s0 > 10 and (vehicle2.d0.s1 < 101 or vehicle1.d0.s1 = 3)");
- queryExpression = QueryExpression.create().setSelectSeries(queryPlan.getPaths())
- .setExpression(queryPlan.getExpression());
- optimizedExpression = ExpressionOptimizer.getInstance()
- .optimize(queryExpression.getExpression(), queryExpression.getSelectedSeries());
- queryPlan.setExpression(optimizedExpression);
- assertEquals(optimizedExpression.toString(), optimizedExpression.clone().toString());
- assertNotSame(optimizedExpression, optimizedExpression.clone());
- withFilterFilterResults.put(1, queryPlan);
-
- //2
- queryPlan = (QueryPlan) queryProcessor.parseSQLToPhysicalPlan(
- "select * from root where not(vehicle1.d0.s0 < 10 and vehicle2.d0.s1 > 10001) or vehicle3.d0.s0 = 3");
- queryExpression = QueryExpression.create().setSelectSeries(queryPlan.getPaths())
- .setExpression(queryPlan.getExpression());
- optimizedExpression = ExpressionOptimizer.getInstance()
- .optimize(queryExpression.getExpression(), queryExpression.getSelectedSeries());
- queryPlan.setExpression(optimizedExpression);
- assertEquals(optimizedExpression.toString(), optimizedExpression.clone().toString());
- assertNotSame(optimizedExpression, optimizedExpression.clone());
- withFilterSelectResults.put(2, queryPlan);
- queryPlan = (QueryPlan) queryProcessor.parseSQLToPhysicalPlan(
- "select vehicle1.d0.s0,vehicle2.d0.s1,vehicle3.d0.s0 from root where not(vehicle1.d0.s0 > 10 and vehicle2.d0.s1 < 101) and vehicle3.d0.s0 = 3");
- queryExpression = QueryExpression.create().setSelectSeries(queryPlan.getPaths())
- .setExpression(queryPlan.getExpression());
- optimizedExpression = ExpressionOptimizer.getInstance()
- .optimize(queryExpression.getExpression(), queryExpression.getSelectedSeries());
- queryPlan.setExpression(optimizedExpression);
- assertEquals(optimizedExpression.toString(), optimizedExpression.clone().toString());
- assertNotSame(optimizedExpression, optimizedExpression.clone());
- withFilterFilterResults.put(2, queryPlan);
-
- //3
- queryPlan = (QueryPlan) queryProcessor
- .parseSQLToPhysicalPlan("select * from root.vehicle1 where d0.s0 > 10");
- queryExpression = QueryExpression.create().setSelectSeries(queryPlan.getPaths())
- .setExpression(queryPlan.getExpression());
- optimizedExpression = ExpressionOptimizer.getInstance()
- .optimize(queryExpression.getExpression(), queryExpression.getSelectedSeries());
- queryPlan.setExpression(optimizedExpression);
- assertEquals(optimizedExpression.toString(), optimizedExpression.clone().toString());
- assertNotSame(optimizedExpression, optimizedExpression.clone());
- withFilterSelectResults.put(3, queryPlan);
-
- queryPlan = (QueryPlan) queryProcessor.parseSQLToPhysicalPlan(
- "select d0.s0 from root.vehicle1 where d0.s0 > 10");
- queryExpression = QueryExpression.create().setSelectSeries(queryPlan.getPaths())
- .setExpression(queryPlan.getExpression());
- optimizedExpression = ExpressionOptimizer.getInstance()
- .optimize(queryExpression.getExpression(), queryExpression.getSelectedSeries());
- queryPlan.setExpression(optimizedExpression);
- assertEquals(optimizedExpression.toString(), optimizedExpression.clone().toString());
- assertNotSame(optimizedExpression, optimizedExpression.clone());
- withFilterFilterResults.put(3, queryPlan);
-
- //4
- queryPlan = (QueryPlan) queryProcessor
- .parseSQLToPhysicalPlan("select * from root.vehicle2 where d0.s0 > 10 and time < NOW()");
- queryExpression = QueryExpression.create().setSelectSeries(queryPlan.getPaths())
- .setExpression(queryPlan.getExpression());
- optimizedExpression = ExpressionOptimizer.getInstance()
- .optimize(queryExpression.getExpression(), queryExpression.getSelectedSeries());
- queryPlan.setExpression(optimizedExpression);
- assertEquals(optimizedExpression.toString(), optimizedExpression.clone().toString());
- assertNotSame(optimizedExpression, optimizedExpression.clone());
- withFilterSelectResults.put(4, queryPlan);
-
- queryPlan = (QueryPlan) queryProcessor.parseSQLToPhysicalPlan(
- "select d0.s0 from root.vehicle2 where d0.s0 > 10 and time < NOW()");
- queryExpression = QueryExpression.create().setSelectSeries(queryPlan.getPaths())
- .setExpression(queryPlan.getExpression());
- optimizedExpression = ExpressionOptimizer.getInstance()
- .optimize(queryExpression.getExpression(), queryExpression.getSelectedSeries());
- queryPlan.setExpression(optimizedExpression);
- assertEquals(optimizedExpression.toString(), optimizedExpression.clone().toString());
- assertNotSame(optimizedExpression, optimizedExpression.clone());
- withFilterFilterResults.put(4, queryPlan);
- }
-
- @Test
- public void splitQueryPlanWithoutValueFilter() throws Exception{
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertData(connection, createSQLs, insertSQLs);
- initCorrectResult();
- for(int i = 0 ; i < queryStatementsWithoutFilters.length; i++) {
- String queryStatementsWithoutFilter = queryStatementsWithoutFilters[i];
- try(Statement statement = connection.createStatement()) {
- boolean hasResultSet = statement.execute(queryStatementsWithoutFilter);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- ConcurrentHashMap<Long, String> map = ClusterRpcQueryManager.getJobIdMapTaskId();
- assertEquals(1, map.size());
- for (String taskId : map.values()) {
- assertNotNull(manager.getSingleQuery(taskId));
- }
- for (long jobId : map.keySet()) {
- assertNotNull(manager.getSingleQuery(jobId));
- }
- for (Entry<Long, String> entry : map.entrySet()) {
- long jobId = entry.getKey();
- String taskId = entry.getValue();
- assertEquals(taskId, String.format("%s:%d", LOCAL_ADDR, jobId));
- ClusterRpcSingleQueryManager singleQueryManager = ClusterRpcQueryManager.getInstance()
- .getSingleQuery(jobId);
- assertTrue(singleQueryManager.getFilterGroupEntityMap().isEmpty());
- Map<String, QueryPlan> selectPathPlans = singleQueryManager.getSelectPathPlans();
- assertFalse(selectPathPlans.isEmpty());
- for(Entry<String, QueryPlan> entry1: selectPathPlans.entrySet()){
- QueryPlan queryPlan = entry1.getValue();
- QueryPlan correctQueryPlan = withoutFilterResults.get(i + 1);
- assertTrue(correctQueryPlan.getPaths().containsAll(queryPlan.getPaths()));
- assertEquals(correctQueryPlan.getExpression(),queryPlan.getExpression());
- assertEquals(correctQueryPlan.isQuery(), queryPlan.isQuery());
- assertEquals(correctQueryPlan.getOperatorType(), queryPlan.getOperatorType());
- assertEquals(correctQueryPlan.getAggregations(), queryPlan.getAggregations());
- }
- }
- }
- }
- }
- }
-
- @Test
- public void splitQueryPlanWithValueFilter() throws Exception{
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + URL, "root", "root")) {
- insertData(connection, createSQLs, insertSQLs);
- initCorrectResult();
- for(int i = 0 ; i < queryStatementsWithFilters.length; i++) {
- String queryStatementsWithoutFilter = queryStatementsWithFilters[i];
- try(Statement statement = connection.createStatement()) {
- boolean hasResultSet = statement.execute(queryStatementsWithoutFilter);
- assertTrue(hasResultSet);
- ResultSet resultSet = statement.getResultSet();
- assertTrue(resultSet.next());
- ConcurrentHashMap<Long, String> map = ClusterRpcQueryManager.getJobIdMapTaskId();
- assertEquals(1, map.size());
- for (String taskId : map.values()) {
- assertNotNull(manager.getSingleQuery(taskId));
- }
- for (long jobId : map.keySet()) {
- assertNotNull(manager.getSingleQuery(jobId));
- }
- for (Entry<Long, String> entry : map.entrySet()) {
- long jobId = entry.getKey();
- String taskId = entry.getValue();
- assertEquals(taskId, String.format("%s:%d", LOCAL_ADDR, jobId));
- ClusterRpcSingleQueryManager singleQueryManager = ClusterRpcQueryManager.getInstance()
- .getSingleQuery(jobId);
- assertTrue(singleQueryManager.getFilterGroupEntityMap().isEmpty());
- Map<String, QueryPlan> selectPathPlans = singleQueryManager.getSelectPathPlans();
- assertFalse(selectPathPlans.isEmpty());
- for(Entry<String, QueryPlan> entry1 : selectPathPlans.entrySet()) {
- QueryPlan queryPlan = entry1.getValue();
- QueryPlan correctQueryPlan = withFilterSelectResults.get(i + 1);
- assertTrue(correctQueryPlan.getPaths().containsAll(queryPlan.getPaths()));
- assertEquals(correctQueryPlan.getExpression().getType(), queryPlan.getExpression().getType());
- assertEquals(correctQueryPlan.isQuery(), queryPlan.isQuery());
- assertEquals(correctQueryPlan.getOperatorType(), queryPlan.getOperatorType());
- assertEquals(correctQueryPlan.getAggregations(), queryPlan.getAggregations());
- }
- Map<String, FilterGroupEntity> filterGroupEntityMap = singleQueryManager.getFilterGroupEntityMap();
- for (FilterGroupEntity filterGroupEntity:filterGroupEntityMap.values()) {
- QueryPlan queryPlan = filterGroupEntity.getQueryPlan();
- QueryPlan correctQueryPlan = withFilterFilterResults.get(i + 1);
- assertTrue(correctQueryPlan.getPaths().containsAll(queryPlan.getPaths()));
- assertEquals(correctQueryPlan.getExpression().getType(),
- queryPlan.getExpression().getType());
- assertEquals(correctQueryPlan.isQuery(), queryPlan.isQuery());
- assertEquals(correctQueryPlan.getOperatorType(), queryPlan.getOperatorType());
- assertEquals(correctQueryPlan.getAggregations(), queryPlan.getAggregations());
- }
- }
- }
- }
- }
- }
-}
\ No newline at end of file