You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hu...@apache.org on 2023/11/17 02:42:52 UTC
(iotdb) 01/01: refactor
This is an automated email from the ASF dual-hosted git repository.
hui pushed a commit to branch lmh/refactorFilter
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 85fd0eb3f01e2e1a647883b58b6ca6b2c3031b75
Author: Minghui Liu <li...@foxmail.com>
AuthorDate: Fri Nov 17 10:41:32 2023 +0800
refactor
---
.../java/org/apache/iotdb/tsfile/TsFileRead.java | 4 +-
.../tsfile/TsFileInsertionDataContainer.java | 2 +-
.../protocol/thrift/impl/ClientRPCServiceImpl.java | 4 +-
.../db/queryengine/common/MPPQueryContext.java | 14 +
.../fragment/FragmentInstanceContext.java | 10 +-
.../operator/process/last/LastQueryUtil.java | 8 +-
.../db/queryengine/plan/analyze/Analysis.java | 11 +-
.../queryengine/plan/analyze/AnalyzeVisitor.java | 72 +--
.../plan/analyze/ExpressionAnalyzer.java | 112 ++--
.../queryengine/plan/analyze/ExpressionUtils.java | 55 +-
.../plan/expression/ExpressionFactory.java | 32 +
.../plan/expression/ExpressionType.java | 3 +-
...java => FixedIntervalMultiRangeExpression.java} | 74 ++-
.../plan/expression/unary/InExpression.java | 15 +-
.../plan/expression/unary/IsNullExpression.java | 5 -
.../plan/expression/unary/LikeExpression.java | 25 +-
.../plan/expression/unary/LogicNotExpression.java | 5 -
.../plan/expression/unary/NegationExpression.java | 5 -
.../plan/expression/unary/RegularExpression.java | 25 +-
.../plan/expression/unary/UnaryExpression.java | 2 -
.../plan/expression/visitor/ExpressionVisitor.java | 6 +
.../visitor/TransformToViewExpressionVisitor.java | 10 +-
.../ConvertExpressionToFilterVisitor.java | 404 ++++++++++++
.../ConvertExpressionToTimeFilterVisitor.java | 252 ++++++++
.../visitor/predicate/PredicateVisitor.java | 87 +++
.../visitor/predicate/ReversePredicateVisitor.java | 148 +++++
.../predicate/SchemaCompatibilityValidator.java | 194 ++++++
.../db/queryengine/plan/parser/ASTVisitor.java | 6 +-
.../plan/planner/LocalExecutionPlanContext.java | 4 +
.../plan/planner/LogicalPlanBuilder.java | 66 +-
.../plan/planner/LogicalPlanVisitor.java | 4 -
.../plan/planner/OperatorTreeGenerator.java | 108 ++--
.../distribution/DistributionPlanContext.java | 5 +
.../SimpleFragmentParallelPlanner.java | 4 +-
.../plan/planner/distribution/SourceRewriter.java | 24 +-
.../distribution/WriteFragmentParallelPlanner.java | 4 +-
.../plan/planner/plan/FragmentInstance.java | 21 +-
.../plan/planner/plan/node/PlanGraphPrinter.java | 3 -
.../plan/node/process/last/LastQueryNode.java | 45 +-
.../plan/node/source/AlignedLastQueryScanNode.java | 6 -
.../source/AlignedSeriesAggregationScanNode.java | 47 +-
.../plan/node/source/AlignedSeriesScanNode.java | 100 +--
.../plan/node/source/LastQueryScanNode.java | 6 -
.../node/source/SeriesAggregationScanNode.java | 47 +-
.../node/source/SeriesAggregationSourceNode.java | 30 +-
.../planner/plan/node/source/SeriesScanNode.java | 92 +--
.../planner/plan/node/source/SeriesSourceNode.java | 3 -
.../planner/plan/node/write/DeleteDataNode.java | 2 +-
.../planner/plan/parameter/SeriesScanOptions.java | 6 +-
.../view/visitor/TransformToExpressionVisitor.java | 10 +-
.../read/reader/chunk/MemAlignedPageReader.java | 4 +-
.../read/reader/chunk/MemPageReader.java | 4 +-
.../apache/iotdb/db/utils/TimeValuePairUtils.java | 62 --
.../AlignedSeriesAggregationScanOperatorTest.java | 10 +-
.../operator/RawDataAggregationOperatorTest.java | 5 +-
.../SeriesAggregationScanOperatorTest.java | 10 +-
.../operator/UpdateLastCacheOperatorTest.java | 2 +-
.../db/queryengine/plan/analyze/AnalyzeTest.java | 18 +-
.../plan/analyze/QueryTimePartitionTest.java | 120 ++--
.../plan/plan/FragmentInstanceSerdeTest.java | 4 +-
.../plan/plan/QueryLogicalPlanUtil.java | 43 +-
.../plan/plan/distribution/LastQueryTest.java | 2 +-
.../node/process/AggregationNodeSerdeTest.java | 9 +-
.../node/process/GroupByLevelNodeSerdeTest.java | 11 +-
.../plan/node/process/GroupByTagNodeSerdeTest.java | 9 +-
.../plan/plan/node/process/LimitNodeSerdeTest.java | 2 -
.../plan/node/process/OffsetNodeSerdeTest.java | 2 -
.../plan/plan/node/process/SortNodeSerdeTest.java | 2 -
.../plan/node/process/TimeJoinNodeSerdeTest.java | 4 -
.../source/SeriesAggregationScanNodeSerdeTest.java | 9 +-
.../plan/node/source/SeriesScanNodeSerdeTest.java | 2 -
.../viewExpression/unary/LikeViewExpression.java | 20 +-
.../unary/RegularViewExpression.java | 24 +-
.../apache/iotdb/commons/utils/SerializeUtils.java | 8 -
.../apache/iotdb/tsfile/read/common/TimeRange.java | 2 +-
.../iotdb/tsfile/read/expression/IExpression.java | 9 +-
.../tsfile/read/expression/QueryExpression.java | 17 +-
.../read/expression/impl/BinaryExpression.java | 159 ++---
.../read/expression/impl/GlobalTimeExpression.java | 23 +-
.../expression/impl/SingleSeriesExpression.java | 19 +-
.../read/filter/PredicateRemoveNotRewriter.java | 30 +-
.../iotdb/tsfile/read/filter/TimeFilter.java | 321 ----------
.../iotdb/tsfile/read/filter/ValueFilter.java | 164 -----
.../tsfile/read/filter/basic/BinaryFilter.java | 95 ---
.../BinaryLogicalFilter.java} | 34 +-
.../ColumnCompareFilter.java} | 21 +-
.../ColumnPatternMatchFilter.java} | 27 +-
.../ColumnRangeFilter.java} | 31 +-
.../FilterType.java => basic/ColumnSetFilter.java} | 20 +-
.../iotdb/tsfile/read/filter/basic/Filter.java | 19 -
.../tsfile/read/filter/basic/UnaryFilter.java | 97 ---
.../tsfile/read/filter/factory/FilterFactory.java | 93 +--
.../tsfile/read/filter/factory/TimeFilter.java | 101 +++
.../tsfile/read/filter/factory/ValueFilter.java | 160 +++++
.../filter/operator/{AndFilter.java => And.java} | 30 +-
.../iotdb/tsfile/read/filter/operator/Between.java | 168 -----
.../iotdb/tsfile/read/filter/operator/Eq.java | 115 ----
.../read/filter/{ => operator}/GroupByFilter.java | 71 +--
.../filter/{ => operator}/GroupByMonthFilter.java | 102 +--
.../iotdb/tsfile/read/filter/operator/Gt.java | 113 ----
.../iotdb/tsfile/read/filter/operator/GtEq.java | 113 ----
.../iotdb/tsfile/read/filter/operator/In.java | 153 -----
.../iotdb/tsfile/read/filter/operator/Like.java | 201 ------
.../iotdb/tsfile/read/filter/operator/Lt.java | 113 ----
.../iotdb/tsfile/read/filter/operator/LtEq.java | 113 ----
.../filter/operator/{NotFilter.java => Not.java} | 68 +-
.../iotdb/tsfile/read/filter/operator/NotEq.java | 115 ----
.../filter/operator/{OrFilter.java => Or.java} | 31 +-
.../iotdb/tsfile/read/filter/operator/Regexp.java | 199 ------
.../read/filter/operator/TimeFilterOperators.java | 473 ++++++++++++++
.../read/filter/operator/ValueFilterOperators.java | 684 +++++++++++++++++++++
.../tsfile/read/reader/page/AlignedPageReader.java | 4 +-
.../iotdb/tsfile/read/reader/page/PageReader.java | 4 +-
.../apache/iotdb/tsfile/utils/TimeDuration.java | 11 +-
.../apache/iotdb/tsfile/read/ExpressionTest.java | 61 --
.../iotdb/tsfile/read/ReadInPartitionTest.java | 4 +-
.../org/apache/iotdb/tsfile/read/ReadTest.java | 4 +-
.../iotdb/tsfile/read/TimePlainEncodeReadTest.java | 4 +-
.../apache/iotdb/tsfile/read/TsFileReaderTest.java | 4 +-
.../tsfile/read/filter/FilterSerializeTest.java | 143 -----
.../tsfile/read/filter/GroupByFilterTest.java | 4 +-
.../tsfile/read/filter/GroupByMonthFilterTest.java | 67 +-
.../read/filter/IExpressionOptimizerTest.java | 2 +
.../read/filter/MinTimeMaxTimeFilterTest.java | 9 +-
.../iotdb/tsfile/read/filter/OperatorTest.java | 2 +
.../filter/PredicateRemoveNotRewriterTest.java | 109 ++--
.../tsfile/read/filter/StatisticsFilterTest.java | 4 +-
.../read/query/executor/QueryExecutorTest.java | 4 +-
.../read/query/timegenerator/ReadWriteTest.java | 4 +-
.../timegenerator/TimeGeneratorReadEmptyTest.java | 4 +-
.../timegenerator/TimeGeneratorReadWriteTest.java | 4 +-
.../query/timegenerator/TimeGeneratorTest.java | 4 +-
.../iotdb/tsfile/read/reader/ReaderTest.java | 4 +-
133 files changed, 3415 insertions(+), 3962 deletions(-)
diff --git a/example/tsfile/src/main/java/org/apache/iotdb/tsfile/TsFileRead.java b/example/tsfile/src/main/java/org/apache/iotdb/tsfile/TsFileRead.java
index d2a3fc9ac4d..c7607cd2e63 100644
--- a/example/tsfile/src/main/java/org/apache/iotdb/tsfile/TsFileRead.java
+++ b/example/tsfile/src/main/java/org/apache/iotdb/tsfile/TsFileRead.java
@@ -27,8 +27,8 @@ import org.apache.iotdb.tsfile.read.expression.QueryExpression;
import org.apache.iotdb.tsfile.read.expression.impl.BinaryExpression;
import org.apache.iotdb.tsfile.read.expression.impl.GlobalTimeExpression;
import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
-import org.apache.iotdb.tsfile.read.filter.ValueFilter;
+import org.apache.iotdb.tsfile.read.filter.factory.TimeFilter;
+import org.apache.iotdb.tsfile.read.filter.factory.ValueFilter;
import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
import org.slf4j.Logger;
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/TsFileInsertionDataContainer.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/TsFileInsertionDataContainer.java
index f83bca354ee..4e3ea460bf8 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/TsFileInsertionDataContainer.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/TsFileInsertionDataContainer.java
@@ -35,7 +35,7 @@ import org.apache.iotdb.tsfile.read.TsFileSequenceReader;
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.GlobalTimeExpression;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
+import org.apache.iotdb.tsfile.read.filter.factory.TimeFilter;
import org.apache.iotdb.tsfile.utils.Pair;
import org.apache.iotdb.tsfile.write.record.Tablet;
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/ClientRPCServiceImpl.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/ClientRPCServiceImpl.java
index 98a20ba5074..d5e49c09ecf 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/ClientRPCServiceImpl.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/ClientRPCServiceImpl.java
@@ -168,8 +168,8 @@ import org.apache.iotdb.tsfile.read.TimeValuePair;
import org.apache.iotdb.tsfile.read.common.block.TsBlock;
import org.apache.iotdb.tsfile.read.common.block.TsBlockBuilder;
import org.apache.iotdb.tsfile.read.common.block.column.TsBlockSerde;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.TimeFilter;
import org.apache.iotdb.tsfile.utils.Binary;
import org.apache.iotdb.tsfile.utils.Pair;
import org.apache.iotdb.tsfile.utils.TimeDuration;
@@ -645,7 +645,7 @@ public class ClientRPCServiceImpl implements IClientRPCServiceWithHandler {
"dataRegionList.size() should only be 1 now, current size is " + dataRegionSize);
}
- Filter timeFilter = new TimeFilter.TimeGtEqAndLt(startTime, endTme);
+ Filter timeFilter = TimeFilter.between(startTime, endTme - 1);
QueryId queryId = new QueryId("stub_query");
FragmentInstanceId instanceId =
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/common/MPPQueryContext.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/common/MPPQueryContext.java
index 9791b1d4423..8c0a1926bb3 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/common/MPPQueryContext.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/common/MPPQueryContext.java
@@ -21,8 +21,11 @@ package org.apache.iotdb.db.queryengine.common;
import org.apache.iotdb.common.rpc.thrift.TEndPoint;
import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
+import org.apache.iotdb.db.queryengine.plan.analyze.Analysis;
+import org.apache.iotdb.db.queryengine.plan.analyze.ExpressionUtils;
import org.apache.iotdb.db.queryengine.plan.analyze.QueryType;
import org.apache.iotdb.db.queryengine.plan.analyze.TypeProvider;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
import java.util.LinkedList;
import java.util.List;
@@ -54,6 +57,8 @@ public class MPPQueryContext {
private final TypeProvider typeProvider = new TypeProvider();
+ private Filter globalTimeFilter;
+
public MPPQueryContext(QueryId queryId) {
this.queryId = queryId;
this.endPointBlackList = new LinkedList<>();
@@ -149,4 +154,13 @@ public class MPPQueryContext {
public String getSql() {
return sql;
}
+
+ public void generateGlobalTimeFilter(Analysis analysis) {
+ this.globalTimeFilter =
+ ExpressionUtils.convertExpressionToTimeFilter(analysis.getGlobalTimeFilter());
+ }
+
+ public Filter getGlobalTimeFilter() {
+ return globalTimeFilter;
+ }
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/fragment/FragmentInstanceContext.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/fragment/FragmentInstanceContext.java
index 9da3e51c1b0..7e5dd8ed319 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/fragment/FragmentInstanceContext.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/fragment/FragmentInstanceContext.java
@@ -25,6 +25,8 @@ import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.queryengine.common.FragmentInstanceId;
import org.apache.iotdb.db.queryengine.common.QueryId;
import org.apache.iotdb.db.queryengine.common.SessionInfo;
+import org.apache.iotdb.db.queryengine.plan.expression.Expression;
+import org.apache.iotdb.db.queryengine.plan.expression.visitor.predicate.ConvertExpressionToTimeFilterVisitor;
import org.apache.iotdb.db.storageengine.dataregion.IDataRegionForQuery;
import org.apache.iotdb.db.storageengine.dataregion.read.QueryDataSource;
import org.apache.iotdb.db.storageengine.dataregion.read.control.FileReaderManager;
@@ -109,7 +111,7 @@ public class FragmentInstanceContext extends QueryContext {
FragmentInstanceStateMachine stateMachine,
SessionInfo sessionInfo,
IDataRegionForQuery dataRegion,
- Filter timeFilter,
+ Expression timeFilter,
Map<QueryId, DataNodeQueryContext> dataNodeQueryContextMap) {
FragmentInstanceContext instanceContext =
new FragmentInstanceContext(
@@ -139,14 +141,14 @@ public class FragmentInstanceContext extends QueryContext {
FragmentInstanceStateMachine stateMachine,
SessionInfo sessionInfo,
IDataRegionForQuery dataRegion,
- Filter timeFilter,
+ Expression timeFilter,
Map<QueryId, DataNodeQueryContext> dataNodeQueryContextMap) {
this.id = id;
this.stateMachine = stateMachine;
this.executionEndTime.set(END_TIME_INITIAL_VALUE);
this.sessionInfo = sessionInfo;
this.dataRegion = dataRegion;
- this.timeFilter = timeFilter;
+ this.timeFilter = timeFilter.accept(new ConvertExpressionToTimeFilterVisitor(), null);
this.dataNodeQueryContextMap = dataNodeQueryContextMap;
this.dataNodeQueryContext = dataNodeQueryContextMap.get(id.getQueryId());
}
@@ -329,7 +331,7 @@ public class FragmentInstanceContext extends QueryContext {
// filtered according to timeIndex
selectedDeviceIdSet.size() == 1 ? selectedDeviceIdSet.iterator().next() : null,
this,
- timeFilter != null ? timeFilter.copy() : null);
+ timeFilter);
// used files should be added before mergeLock is unlocked, or they may be deleted by
// running merge
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/last/LastQueryUtil.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/last/LastQueryUtil.java
index c1fcf319bd5..6cf531b7c92 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/last/LastQueryUtil.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/last/LastQueryUtil.java
@@ -31,8 +31,8 @@ import org.apache.iotdb.tsfile.read.TimeValuePair;
import org.apache.iotdb.tsfile.read.common.block.TsBlock;
import org.apache.iotdb.tsfile.read.common.block.TsBlockBuilder;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.operator.Gt;
-import org.apache.iotdb.tsfile.read.filter.operator.GtEq;
+import org.apache.iotdb.tsfile.read.filter.operator.TimeFilterOperators.TimeGt;
+import org.apache.iotdb.tsfile.read.filter.operator.TimeFilterOperators.TimeGtEq;
import org.apache.iotdb.tsfile.utils.Binary;
import com.google.common.collect.ImmutableList;
@@ -166,8 +166,8 @@ public class LastQueryUtil {
public static boolean needUpdateCache(Filter timeFilter) {
// Update the cache only when, the filter is gt (greater than) or ge (greater than or equal to)
- return CACHE_ENABLED && (timeFilter == null || timeFilter instanceof GtEq)
- || (timeFilter instanceof Gt);
+ return CACHE_ENABLED && (timeFilter == null || timeFilter instanceof TimeGtEq)
+ || (timeFilter instanceof TimeGt);
}
public static boolean needUpdateNullEntry(Filter timeFilter) {
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/Analysis.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/Analysis.java
index aca60abcf8c..12b54118e6d 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/Analysis.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/Analysis.java
@@ -178,7 +178,7 @@ public class Analysis {
private boolean hasValueFilter = false;
// a global time filter used in `initQueryDataSource` and filter push down
- private Filter globalTimeFilter;
+ private Expression globalTimeFilter;
// expression of output column to be calculated
private Set<Expression> selectExpressions;
@@ -330,11 +330,11 @@ public class Analysis {
redirectNodeList.add(endPoint);
}
- public Filter getGlobalTimeFilter() {
+ public Expression getGlobalTimeFilter() {
return globalTimeFilter;
}
- public void setGlobalTimeFilter(Filter timeFilter) {
+ public void setGlobalTimeFilter(Expression timeFilter) {
this.globalTimeFilter = timeFilter;
}
@@ -348,9 +348,12 @@ public class Analysis {
public TSDataType getType(Expression expression) {
// NULL_Operand needn't check
- if (expression.getExpressionType() == ExpressionType.NULL) {
+ if (expression.getExpressionType().equals(ExpressionType.NULL)) {
return null;
}
+ if (expression.getExpressionType().equals(ExpressionType.TIMESTAMP)) {
+ return TSDataType.INT64;
+ }
TSDataType type = expressionTypes.get(NodeRef.of(expression));
checkArgument(type != null, "Expression is not analyzed: %s", expression);
return type;
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
index 96e8c9f5a42..3b1749d9ffd 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
@@ -61,6 +61,7 @@ import org.apache.iotdb.db.queryengine.metric.QueryPlanCostMetricSet;
import org.apache.iotdb.db.queryengine.plan.analyze.schema.ISchemaFetcher;
import org.apache.iotdb.db.queryengine.plan.analyze.schema.SchemaValidator;
import org.apache.iotdb.db.queryengine.plan.expression.Expression;
+import org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory;
import org.apache.iotdb.db.queryengine.plan.expression.ExpressionType;
import org.apache.iotdb.db.queryengine.plan.expression.binary.CompareBinaryExpression;
import org.apache.iotdb.db.queryengine.plan.expression.leaf.ConstantOperand;
@@ -137,16 +138,11 @@ import org.apache.iotdb.db.queryengine.plan.statement.sys.ExplainStatement;
import org.apache.iotdb.db.queryengine.plan.statement.sys.ShowQueriesStatement;
import org.apache.iotdb.db.queryengine.plan.statement.sys.ShowVersionStatement;
import org.apache.iotdb.db.schemaengine.template.Template;
-import org.apache.iotdb.db.utils.TimestampPrecisionUtils;
import org.apache.iotdb.rpc.RpcUtils;
import org.apache.iotdb.rpc.TSStatusCode;
import org.apache.iotdb.tsfile.enums.TSDataType;
import org.apache.iotdb.tsfile.read.common.TimeRange;
-import org.apache.iotdb.tsfile.read.filter.GroupByFilter;
-import org.apache.iotdb.tsfile.read.filter.GroupByMonthFilter;
-import org.apache.iotdb.tsfile.read.filter.PredicateRemoveNotRewriter;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
import org.apache.iotdb.tsfile.utils.Pair;
import org.apache.iotdb.tsfile.write.schema.IMeasurementSchema;
@@ -169,7 +165,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
-import java.util.TimeZone;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkState;
@@ -256,7 +251,7 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
analyzeGlobalTimeFilter(analysis, queryStatement);
if (queryStatement.isLastQuery()) {
- return analyzeLastQuery(queryStatement, analysis, schemaTree);
+ return analyzeLastQuery(queryStatement, analysis, schemaTree, context);
}
List<Pair<Expression, String>> outputExpressions;
@@ -327,6 +322,7 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
}
analyzeGroupByTime(analysis, queryStatement);
+ context.generateGlobalTimeFilter(analysis);
analyzeFill(analysis, queryStatement);
@@ -334,7 +330,7 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
analyzeOutput(analysis, queryStatement, outputExpressions);
// fetch partition information
- analyzeDataPartition(analysis, queryStatement, schemaTree);
+ analyzeDataPartition(analysis, queryStatement, schemaTree, context);
} catch (StatementAnalyzeException e) {
throw new StatementAnalyzeException(
@@ -389,17 +385,17 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
}
private void analyzeGlobalTimeFilter(Analysis analysis, QueryStatement queryStatement) {
- Filter globalTimeFilter = null;
+ Expression globalTimeFilter = null;
boolean hasValueFilter = false;
if (queryStatement.getWhereCondition() != null) {
WhereCondition whereCondition = queryStatement.getWhereCondition();
Expression predicate = whereCondition.getPredicate();
- Pair<Filter, Boolean> resultPair =
+ Pair<Expression, Boolean> resultPair =
ExpressionAnalyzer.extractGlobalTimeFilter(predicate, true, true);
globalTimeFilter = resultPair.left;
if (globalTimeFilter != null) {
- globalTimeFilter = PredicateRemoveNotRewriter.rewrite(globalTimeFilter);
+ globalTimeFilter = ExpressionAnalyzer.predicateRemoveNot(globalTimeFilter);
}
hasValueFilter = resultPair.right;
@@ -419,7 +415,10 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
}
private Analysis analyzeLastQuery(
- QueryStatement queryStatement, Analysis analysis, ISchemaTree schemaTree) {
+ QueryStatement queryStatement,
+ Analysis analysis,
+ ISchemaTree schemaTree,
+ MPPQueryContext context) {
if (analysis.hasValueFilter()) {
throw new SemanticException("Only time filters are supported in LAST query");
}
@@ -434,7 +433,7 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
analysis.setRespDatasetHeader(DatasetHeaderFactory.getLastQueryHeader());
// fetch partition information
- analyzeDataPartition(analysis, queryStatement, schemaTree);
+ analyzeDataPartition(analysis, queryStatement, schemaTree, context);
return analysis;
}
@@ -1763,14 +1762,15 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
throw new SemanticException(
"The query time range should be specified in the GROUP BY TIME clause.");
}
- analysis.setGroupByTimeParameter(new GroupByTimeParameter(groupByTimeComponent));
+ GroupByTimeParameter groupByTimeParameter = new GroupByTimeParameter(groupByTimeComponent);
+ analysis.setGroupByTimeParameter(groupByTimeParameter);
- Filter globalTimeFilter = analysis.getGlobalTimeFilter();
- Filter groupByFilter = initGroupByFilter(groupByTimeComponent);
+ Expression globalTimeFilter = analysis.getGlobalTimeFilter();
+ Expression groupByExpression = ExpressionFactory.groupByTime(groupByTimeParameter);
if (globalTimeFilter == null) {
- globalTimeFilter = groupByFilter;
+ globalTimeFilter = groupByExpression;
} else {
- globalTimeFilter = FilterFactory.and(globalTimeFilter, groupByFilter);
+ globalTimeFilter = ExpressionFactory.and(globalTimeFilter, groupByExpression);
}
analysis.setGlobalTimeFilter(globalTimeFilter);
}
@@ -1786,7 +1786,10 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
}
private void analyzeDataPartition(
- Analysis analysis, QueryStatement queryStatement, ISchemaTree schemaTree) {
+ Analysis analysis,
+ QueryStatement queryStatement,
+ ISchemaTree schemaTree,
+ MPPQueryContext context) {
Set<String> deviceSet = new HashSet<>();
if (queryStatement.isAlignByDevice()) {
deviceSet =
@@ -1799,7 +1802,7 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
}
}
DataPartition dataPartition =
- fetchDataPartitionByDevices(deviceSet, schemaTree, analysis.getGlobalTimeFilter());
+ fetchDataPartitionByDevices(deviceSet, schemaTree, context.getGlobalTimeFilter());
analysis.setDataPartitionInfo(dataPartition);
}
@@ -2665,7 +2668,7 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
Collections.singletonList(
new TimeSeriesOperand(showTimeSeriesStatement.getPathPattern())),
schemaTree);
- analyzeDataPartition(analysis, new QueryStatement(), schemaTree);
+ analyzeDataPartition(analysis, new QueryStatement(), schemaTree, context);
}
analysis.setRespDatasetHeader(DatasetHeaderFactory.getShowTimeSeriesHeader());
@@ -2978,33 +2981,6 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
return analysis;
}
- private GroupByFilter initGroupByFilter(GroupByTimeComponent groupByTimeComponent) {
- long startTime =
- groupByTimeComponent.isLeftCRightO()
- ? groupByTimeComponent.getStartTime()
- : groupByTimeComponent.getStartTime() + 1;
- long endTime =
- groupByTimeComponent.isLeftCRightO()
- ? groupByTimeComponent.getEndTime()
- : groupByTimeComponent.getEndTime() + 1;
- if (groupByTimeComponent.getInterval().containsMonth()
- || groupByTimeComponent.getSlidingStep().containsMonth()) {
- return new GroupByMonthFilter(
- groupByTimeComponent.getInterval(),
- groupByTimeComponent.getSlidingStep(),
- startTime,
- endTime,
- TimeZone.getTimeZone("+00:00"),
- TimestampPrecisionUtils.currPrecision);
- } else {
- return new GroupByFilter(
- groupByTimeComponent.getInterval().nonMonthDuration,
- groupByTimeComponent.getSlidingStep().nonMonthDuration,
- startTime,
- endTime);
- }
- }
-
@Override
public Analysis visitSetSchemaTemplate(
SetSchemaTemplateStatement setSchemaTemplateStatement, MPPQueryContext context) {
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ExpressionAnalyzer.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ExpressionAnalyzer.java
index 7089ffa809c..8859b7c59e7 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ExpressionAnalyzer.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ExpressionAnalyzer.java
@@ -29,6 +29,7 @@ import org.apache.iotdb.db.exception.sql.SemanticException;
import org.apache.iotdb.db.queryengine.common.header.ColumnHeader;
import org.apache.iotdb.db.queryengine.common.schematree.ISchemaTree;
import org.apache.iotdb.db.queryengine.plan.expression.Expression;
+import org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory;
import org.apache.iotdb.db.queryengine.plan.expression.ExpressionType;
import org.apache.iotdb.db.queryengine.plan.expression.UnknownExpressionTypeException;
import org.apache.iotdb.db.queryengine.plan.expression.binary.BinaryExpression;
@@ -39,9 +40,9 @@ import org.apache.iotdb.db.queryengine.plan.expression.leaf.TimeSeriesOperand;
import org.apache.iotdb.db.queryengine.plan.expression.leaf.TimestampOperand;
import org.apache.iotdb.db.queryengine.plan.expression.multi.FunctionExpression;
import org.apache.iotdb.db.queryengine.plan.expression.other.CaseWhenThenExpression;
-import org.apache.iotdb.db.queryengine.plan.expression.ternary.BetweenExpression;
import org.apache.iotdb.db.queryengine.plan.expression.ternary.TernaryExpression;
import org.apache.iotdb.db.queryengine.plan.expression.unary.InExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.LogicNotExpression;
import org.apache.iotdb.db.queryengine.plan.expression.unary.UnaryExpression;
import org.apache.iotdb.db.queryengine.plan.expression.visitor.BindTypeForTimeSeriesOperandVisitor;
import org.apache.iotdb.db.queryengine.plan.expression.visitor.CollectAggregationExpressionsVisitor;
@@ -56,13 +57,11 @@ import org.apache.iotdb.db.queryengine.plan.expression.visitor.cartesian.BindSch
import org.apache.iotdb.db.queryengine.plan.expression.visitor.cartesian.ConcatDeviceAndBindSchemaForExpressionVisitor;
import org.apache.iotdb.db.queryengine.plan.expression.visitor.cartesian.ConcatDeviceAndBindSchemaForPredicateVisitor;
import org.apache.iotdb.db.queryengine.plan.expression.visitor.cartesian.ConcatExpressionWithSuffixPathsVisitor;
+import org.apache.iotdb.db.queryengine.plan.expression.visitor.predicate.ReversePredicateVisitor;
import org.apache.iotdb.db.queryengine.plan.statement.component.ResultColumn;
import org.apache.iotdb.db.utils.constant.SqlConstant;
import org.apache.iotdb.tsfile.common.constant.TsFileConstant;
import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
import org.apache.iotdb.tsfile.utils.Pair;
import java.util.ArrayList;
@@ -73,10 +72,6 @@ import java.util.Set;
import java.util.stream.Collectors;
import static org.apache.iotdb.db.queryengine.plan.analyze.ExpressionUtils.checkConstantSatisfy;
-import static org.apache.iotdb.db.queryengine.plan.analyze.ExpressionUtils.constructTimeFilter;
-import static org.apache.iotdb.db.queryengine.plan.analyze.ExpressionUtils.getPairFromBetweenTimeFirst;
-import static org.apache.iotdb.db.queryengine.plan.analyze.ExpressionUtils.getPairFromBetweenTimeSecond;
-import static org.apache.iotdb.db.queryengine.plan.analyze.ExpressionUtils.getPairFromBetweenTimeThird;
public class ExpressionAnalyzer {
@@ -482,13 +477,13 @@ public class ExpressionAnalyzer {
* @param isFirstOr whether it is the first LogicOrExpression encountered
* @return global time filter
*/
- public static Pair<Filter, Boolean> extractGlobalTimeFilter(
+ public static Pair<Expression, Boolean> extractGlobalTimeFilter(
Expression predicate, boolean canRewrite, boolean isFirstOr) {
if (predicate.getExpressionType().equals(ExpressionType.LOGIC_AND)) {
- Pair<Filter, Boolean> leftResultPair =
+ Pair<Expression, Boolean> leftResultPair =
extractGlobalTimeFilter(
((BinaryExpression) predicate).getLeftExpression(), canRewrite, isFirstOr);
- Pair<Filter, Boolean> rightResultPair =
+ Pair<Expression, Boolean> rightResultPair =
extractGlobalTimeFilter(
((BinaryExpression) predicate).getRightExpression(), canRewrite, isFirstOr);
@@ -508,7 +503,7 @@ public class ExpressionAnalyzer {
if (leftResultPair.left != null && rightResultPair.left != null) {
return new Pair<>(
- FilterFactory.and(leftResultPair.left, rightResultPair.left),
+ ExpressionFactory.and(leftResultPair.left, rightResultPair.left),
leftResultPair.right || rightResultPair.right);
} else if (leftResultPair.left != null) {
return new Pair<>(leftResultPair.left, true);
@@ -517,9 +512,9 @@ public class ExpressionAnalyzer {
}
return new Pair<>(null, true);
} else if (predicate.getExpressionType().equals(ExpressionType.LOGIC_OR)) {
- Pair<Filter, Boolean> leftResultPair =
+ Pair<Expression, Boolean> leftResultPair =
extractGlobalTimeFilter(((BinaryExpression) predicate).getLeftExpression(), false, false);
- Pair<Filter, Boolean> rightResultPair =
+ Pair<Expression, Boolean> rightResultPair =
extractGlobalTimeFilter(
((BinaryExpression) predicate).getRightExpression(), false, false);
@@ -531,34 +526,24 @@ public class ExpressionAnalyzer {
.setRightExpression(new ConstantOperand(TSDataType.BOOLEAN, "true"));
}
return new Pair<>(
- FilterFactory.or(leftResultPair.left, rightResultPair.left),
+ ExpressionFactory.or(leftResultPair.left, rightResultPair.left),
leftResultPair.right || rightResultPair.right);
}
return new Pair<>(null, true);
} else if (predicate.getExpressionType().equals(ExpressionType.LOGIC_NOT)) {
- Pair<Filter, Boolean> childResultPair =
+ Pair<Expression, Boolean> childResultPair =
extractGlobalTimeFilter(
((UnaryExpression) predicate).getExpression(), canRewrite, isFirstOr);
if (childResultPair.left != null) {
- return new Pair<>(FilterFactory.not(childResultPair.left), childResultPair.right);
+ return new Pair<>(ExpressionFactory.not(childResultPair.left), childResultPair.right);
}
return new Pair<>(null, true);
} else if (predicate.isCompareBinaryExpression()) {
- Filter timeInLeftFilter =
- constructTimeFilter(
- predicate.getExpressionType(),
- ((BinaryExpression) predicate).getLeftExpression(),
- ((BinaryExpression) predicate).getRightExpression());
- if (timeInLeftFilter != null) {
- return new Pair<>(timeInLeftFilter, false);
- }
- Filter timeInRightFilter =
- constructTimeFilter(
- predicate.getExpressionType(),
- ((BinaryExpression) predicate).getRightExpression(),
- ((BinaryExpression) predicate).getLeftExpression());
- if (timeInRightFilter != null) {
- return new Pair<>(timeInRightFilter, false);
+ Expression leftExpression = ((BinaryExpression) predicate).getLeftExpression();
+ Expression rightExpression = ((BinaryExpression) predicate).getRightExpression();
+ if (checkIsTimeFilter(leftExpression, rightExpression)
+ || checkIsTimeFilter(rightExpression, leftExpression)) {
+ return new Pair<>(predicate, false);
}
return new Pair<>(null, true);
} else if (predicate.getExpressionType().equals(ExpressionType.LIKE)
@@ -568,21 +553,21 @@ public class ExpressionAnalyzer {
Expression firstExpression = ((TernaryExpression) predicate).getFirstExpression();
Expression secondExpression = ((TernaryExpression) predicate).getSecondExpression();
Expression thirdExpression = ((TernaryExpression) predicate).getThirdExpression();
+
+ boolean isTimeFilter = false;
if (firstExpression.getExpressionType().equals(ExpressionType.TIMESTAMP)) {
- return getPairFromBetweenTimeFirst(
- secondExpression, thirdExpression, ((BetweenExpression) predicate).isNotBetween());
+ isTimeFilter = checkBetweenExpressionIsTimeFilter(secondExpression, thirdExpression);
} else if (secondExpression.getExpressionType().equals(ExpressionType.TIMESTAMP)) {
- if (checkConstantSatisfy(firstExpression, thirdExpression)) {
- return getPairFromBetweenTimeSecond((BetweenExpression) predicate, firstExpression);
- } else {
- return new Pair<>(null, true); // TODO return Filter.True/False
- }
+ isTimeFilter =
+ checkConstantSatisfy(firstExpression, thirdExpression)
+ && checkBetweenExpressionIsTimeFilter(predicate, firstExpression);
} else if (thirdExpression.getExpressionType().equals(ExpressionType.TIMESTAMP)) {
- if (checkConstantSatisfy(secondExpression, firstExpression)) {
- return getPairFromBetweenTimeThird((BetweenExpression) predicate, firstExpression);
- } else {
- return new Pair<>(null, true); // TODO return Filter.True/False
- }
+ isTimeFilter =
+ checkConstantSatisfy(secondExpression, firstExpression)
+ && checkBetweenExpressionIsTimeFilter(predicate, firstExpression);
+ }
+ if (isTimeFilter) {
+ return new Pair<>(predicate, false);
}
return new Pair<>(null, true);
} else if (predicate.getExpressionType().equals(ExpressionType.IS_NULL)) {
@@ -590,11 +575,7 @@ public class ExpressionAnalyzer {
} else if (predicate.getExpressionType().equals(ExpressionType.IN)) {
Expression timeExpression = ((InExpression) predicate).getExpression();
if (timeExpression.getExpressionType().equals(ExpressionType.TIMESTAMP)) {
- boolean not = ((InExpression) predicate).isNotIn();
- Set<Long> values =
- ((InExpression) predicate)
- .getValues().stream().map(Long::parseLong).collect(Collectors.toSet());
- return new Pair<>(not ? TimeFilter.notIn(values) : TimeFilter.in(values), false);
+ return new Pair<>(predicate, false);
}
return new Pair<>(null, true);
} else if (predicate.getExpressionType().equals(ExpressionType.TIMESERIES)
@@ -608,6 +589,39 @@ public class ExpressionAnalyzer {
}
}
+ private static boolean checkIsTimeFilter(Expression timeExpression, Expression valueExpression) {
+ return timeExpression.getExpressionType().equals(ExpressionType.TIMESTAMP)
+ && valueExpression instanceof ConstantOperand
+ && ((ConstantOperand) valueExpression).getDataType() == TSDataType.INT64;
+ }
+
+ private static boolean checkBetweenExpressionIsTimeFilter(
+ Expression firstExpression, Expression secondExpression) {
+ return firstExpression instanceof ConstantOperand
+ && secondExpression instanceof ConstantOperand
+ && ((ConstantOperand) firstExpression).getDataType() == TSDataType.INT64
+ && ((ConstantOperand) secondExpression).getDataType() == TSDataType.INT64;
+ }
+
+ public static Expression predicateRemoveNot(Expression predicate) {
+ if (predicate.getExpressionType().equals(ExpressionType.LOGIC_AND)) {
+ return ExpressionFactory.and(
+ predicateRemoveNot(((BinaryExpression) predicate).getLeftExpression()),
+ predicateRemoveNot(((BinaryExpression) predicate).getRightExpression()));
+ } else if (predicate.getExpressionType().equals(ExpressionType.LOGIC_OR)) {
+ return ExpressionFactory.or(
+ predicateRemoveNot(((BinaryExpression) predicate).getLeftExpression()),
+ predicateRemoveNot(((BinaryExpression) predicate).getRightExpression()));
+ } else if (predicate.getExpressionType().equals(ExpressionType.LOGIC_NOT)) {
+ return reversePredicate(((LogicNotExpression) predicate).getExpression());
+ }
+ return predicate;
+ }
+
+ private static Expression reversePredicate(Expression predicate) {
+ return new ReversePredicateVisitor().process(predicate, null);
+ }
+
public static boolean checkIfTimeFilterExist(Expression predicate) {
if (predicate instanceof TernaryExpression) {
return checkIfTimeFilterExist(((TernaryExpression) predicate).getFirstExpression())
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ExpressionUtils.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ExpressionUtils.java
index 61a3962ccec..4fac3b4c47b 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ExpressionUtils.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ExpressionUtils.java
@@ -40,7 +40,6 @@ import org.apache.iotdb.db.queryengine.plan.expression.binary.SubtractionExpress
import org.apache.iotdb.db.queryengine.plan.expression.binary.WhenThenExpression;
import org.apache.iotdb.db.queryengine.plan.expression.leaf.ConstantOperand;
import org.apache.iotdb.db.queryengine.plan.expression.leaf.TimeSeriesOperand;
-import org.apache.iotdb.db.queryengine.plan.expression.leaf.TimestampOperand;
import org.apache.iotdb.db.queryengine.plan.expression.multi.FunctionExpression;
import org.apache.iotdb.db.queryengine.plan.expression.other.CaseWhenThenExpression;
import org.apache.iotdb.db.queryengine.plan.expression.ternary.BetweenExpression;
@@ -52,9 +51,10 @@ import org.apache.iotdb.db.queryengine.plan.expression.unary.LogicNotExpression;
import org.apache.iotdb.db.queryengine.plan.expression.unary.NegationExpression;
import org.apache.iotdb.db.queryengine.plan.expression.unary.RegularExpression;
import org.apache.iotdb.db.queryengine.plan.expression.unary.UnaryExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.visitor.predicate.ConvertExpressionToTimeFilterVisitor;
import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.TimeFilter;
import org.apache.iotdb.tsfile.utils.Pair;
import java.util.ArrayList;
@@ -143,7 +143,8 @@ public class ExpressionUtils {
new LikeExpression(
childExpression,
((LikeExpression) rawExpression).getPatternString(),
- ((LikeExpression) rawExpression).getPattern());
+ ((LikeExpression) rawExpression).getPattern(),
+ ((LikeExpression) rawExpression).isNot());
break;
case LOGIC_NOT:
resultExpression = new LogicNotExpression(childExpression);
@@ -156,7 +157,8 @@ public class ExpressionUtils {
new RegularExpression(
childExpression,
((RegularExpression) rawExpression).getPatternString(),
- ((RegularExpression) rawExpression).getPattern());
+ ((RegularExpression) rawExpression).getPattern(),
+ ((RegularExpression) rawExpression).isNot());
break;
default:
throw new UnknownExpressionTypeException(rawExpression.getExpressionType());
@@ -306,47 +308,6 @@ public class ExpressionUtils {
}
}
- public static Filter constructTimeFilter(
- ExpressionType expressionType, Expression timeExpression, Expression valueExpression) {
- if (timeExpression instanceof TimestampOperand
- && valueExpression instanceof ConstantOperand
- && ((ConstantOperand) valueExpression).getDataType() == TSDataType.INT64) {
- long value = Long.parseLong(((ConstantOperand) valueExpression).getValueString());
- switch (expressionType) {
- case LESS_THAN:
- return TimeFilter.lt(value);
- case LESS_EQUAL:
- return TimeFilter.ltEq(value);
- case GREATER_THAN:
- return TimeFilter.gt(value);
- case GREATER_EQUAL:
- return TimeFilter.gtEq(value);
- case EQUAL_TO:
- return TimeFilter.eq(value);
- case NON_EQUAL:
- return TimeFilter.notEq(value);
- default:
- throw new UnknownExpressionTypeException(expressionType);
- }
- }
- return null;
- }
-
- public static Pair<Filter, Boolean> getPairFromBetweenTimeFirst(
- Expression firstExpression, Expression secondExpression, boolean not) {
- if (firstExpression instanceof ConstantOperand
- && secondExpression instanceof ConstantOperand
- && ((ConstantOperand) firstExpression).getDataType() == TSDataType.INT64
- && ((ConstantOperand) secondExpression).getDataType() == TSDataType.INT64) {
- long value1 = Long.parseLong(((ConstantOperand) firstExpression).getValueString());
- long value2 = Long.parseLong(((ConstantOperand) secondExpression).getValueString());
- return new Pair<>(
- not ? TimeFilter.notBetween(value1, value2) : TimeFilter.between(value1, value2), false);
- } else {
- return new Pair<>(null, true);
- }
- }
-
public static Pair<Filter, Boolean> getPairFromBetweenTimeSecond(
BetweenExpression predicate, Expression expression) {
if (predicate.isNotBetween()) {
@@ -398,4 +359,8 @@ public class ExpressionUtils {
constructBinaryFilterTreeWithAnd(expressions.subList(1, expressions.size())));
}
}
+
+ public static Filter convertExpressionToTimeFilter(Expression expression) {
+ return expression.accept(new ConvertExpressionToTimeFilterVisitor(), null);
+ }
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/ExpressionFactory.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/ExpressionFactory.java
index cd4c396fcdd..ac3d91adda2 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/ExpressionFactory.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/ExpressionFactory.java
@@ -34,11 +34,17 @@ import org.apache.iotdb.db.queryengine.plan.expression.leaf.ConstantOperand;
import org.apache.iotdb.db.queryengine.plan.expression.leaf.TimeSeriesOperand;
import org.apache.iotdb.db.queryengine.plan.expression.leaf.TimestampOperand;
import org.apache.iotdb.db.queryengine.plan.expression.multi.FunctionExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.FixedIntervalMultiRangeExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.InExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.LogicNotExpression;
+import org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.GroupByTimeParameter;
import org.apache.iotdb.tsfile.enums.TSDataType;
+import org.apache.iotdb.tsfile.utils.TimeDuration;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
public class ExpressionFactory {
@@ -139,4 +145,30 @@ public class ExpressionFactory {
public static WhenThenExpression whenThen(Expression whenExpression, Expression thenExpression) {
return new WhenThenExpression(whenExpression, thenExpression);
}
+
+ public static LogicNotExpression not(Expression expression) {
+ return new LogicNotExpression(expression);
+ }
+
+ public static InExpression in(Expression Expression, LinkedHashSet<String> values) {
+ return new InExpression(Expression, false, values);
+ }
+
+ public static FixedIntervalMultiRangeExpression groupByTime(GroupByTimeParameter parameter) {
+ long startTime =
+ parameter.isLeftCRightO() ? parameter.getStartTime() : parameter.getStartTime() + 1;
+ long endTime = parameter.isLeftCRightO() ? parameter.getEndTime() : parameter.getEndTime() + 1;
+ return new FixedIntervalMultiRangeExpression(
+ time(), startTime, endTime, parameter.getInterval(), parameter.getSlidingStep());
+ }
+
+ public static FixedIntervalMultiRangeExpression groupByTime(
+ long startTime, long endTime, long interval, long slidingStep) {
+ return new FixedIntervalMultiRangeExpression(
+ time(),
+ startTime,
+ endTime,
+ new TimeDuration(0, interval),
+ new TimeDuration(0, slidingStep));
+ }
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/ExpressionType.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/ExpressionType.java
index b3c301b39cd..9943d5a0e19 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/ExpressionType.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/ExpressionType.java
@@ -60,7 +60,8 @@ public enum ExpressionType {
CASE_WHEN_THEN((short) 21, (short) 1000), // priority not sure
WHEN_THEN((short) 22, (short) 1000), // priority not sure
- ;
+
+ MULTI_RANGE((short) 23, (short) 400);
private final short type;
private final short priority;
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/IsNullExpression.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/FixedIntervalMultiRangeExpression.java
similarity index 53%
copy from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/IsNullExpression.java
copy to iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/FixedIntervalMultiRangeExpression.java
index 825c4629227..d41af1bc930 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/IsNullExpression.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/FixedIntervalMultiRangeExpression.java
@@ -22,63 +22,71 @@ package org.apache.iotdb.db.queryengine.plan.expression.unary;
import org.apache.iotdb.db.queryengine.plan.expression.Expression;
import org.apache.iotdb.db.queryengine.plan.expression.ExpressionType;
import org.apache.iotdb.db.queryengine.plan.expression.visitor.ExpressionVisitor;
-import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+import org.apache.iotdb.tsfile.utils.TimeDuration;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.nio.ByteBuffer;
+import static com.google.common.base.Preconditions.checkArgument;
-public class IsNullExpression extends UnaryExpression {
- private final boolean isNot;
+public class FixedIntervalMultiRangeExpression extends UnaryExpression {
- public IsNullExpression(Expression expression, boolean isNot) {
- super(expression);
- this.isNot = isNot;
- }
+ // [startTime, endTime]
+ private long startTime;
+ private long endTime;
+
+ // time interval
+ private TimeDuration interval;
+
+ // sliding step
+ private TimeDuration slidingStep;
- public IsNullExpression(ByteBuffer byteBuffer) {
- super(Expression.deserialize(byteBuffer));
- isNot = ReadWriteIOUtils.readBool(byteBuffer);
+ public FixedIntervalMultiRangeExpression(
+ Expression expression,
+ long startTime,
+ long endTime,
+ TimeDuration interval,
+ TimeDuration slidingStep) {
+ super(expression);
+ checkArgument(
+ expression.getExpressionType().equals(ExpressionType.TIMESTAMP),
+ "Only used for representing GROUP BY TIME filter.");
+ this.startTime = startTime;
+ this.endTime = endTime;
+ this.interval = interval;
+ this.slidingStep = slidingStep;
}
- public boolean isNot() {
- return isNot;
+ public long getStartTime() {
+ return startTime;
}
- @Override
- protected String getExpressionStringInternal() {
- return expression.getExpressionString() + " IS " + (isNot ? "NOT " : "") + "NULL";
+ public long getEndTime() {
+ return endTime;
}
- @Override
- public ExpressionType getExpressionType() {
- return ExpressionType.IS_NULL;
+ public TimeDuration getInterval() {
+ return interval;
}
- @Override
- protected Expression constructExpression(Expression childExpression) {
- return new IsNullExpression(childExpression, isNot);
+ public TimeDuration getSlidingStep() {
+ return slidingStep;
}
@Override
- protected void serialize(ByteBuffer byteBuffer) {
- super.serialize(byteBuffer);
- ReadWriteIOUtils.write(isNot, byteBuffer);
+ public ExpressionType getExpressionType() {
+ return ExpressionType.MULTI_RANGE;
}
@Override
- protected void serialize(DataOutputStream stream) throws IOException {
- super.serialize(stream);
- ReadWriteIOUtils.write(isNot, stream);
+ public String getOutputSymbolInternal() {
+ return null;
}
@Override
- public String getOutputSymbolInternal() {
- return expression.getOutputSymbol() + " IS " + (isNot ? "NOT " : "") + "NULL";
+ protected String getExpressionStringInternal() {
+ return null;
}
@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
- return visitor.visitIsNullExpression(this, context);
+ return visitor.visitFixedIntervalMultiRangeExpression(this, context);
}
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/InExpression.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/InExpression.java
index 3bc38bc35ac..e313a4a1356 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/InExpression.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/InExpression.java
@@ -67,15 +67,16 @@ public class InExpression extends UnaryExpression {
@Override
protected String getExpressionStringInternal() {
+ String operator = isNotIn ? " NOT IN (" : " IN (";
StringBuilder stringBuilder = new StringBuilder();
if (expression instanceof FunctionExpression || expression instanceof LeafOperand) {
- stringBuilder.append(expression.getExpressionString()).append(" IN (");
+ stringBuilder.append(expression.getExpressionString()).append(operator);
} else {
stringBuilder
.append('(')
.append(expression.getExpressionString())
.append(')')
- .append(" IN (");
+ .append(operator);
}
return appendValuesToBuild(stringBuilder).toString();
}
@@ -98,11 +99,6 @@ public class InExpression extends UnaryExpression {
return ExpressionType.IN;
}
- @Override
- protected Expression constructExpression(Expression childExpression) {
- return new InExpression(childExpression, isNotIn, values);
- }
-
@Override
protected void serialize(ByteBuffer byteBuffer) {
super.serialize(byteBuffer);
@@ -125,13 +121,14 @@ public class InExpression extends UnaryExpression {
@Override
public String getOutputSymbolInternal() {
+ String operator = isNotIn ? " NOT IN (" : " IN (";
StringBuilder stringBuilder = new StringBuilder();
if (expression instanceof FunctionExpression
|| expression instanceof ConstantOperand
|| expression instanceof TimeSeriesOperand) {
- stringBuilder.append(expression.getOutputSymbol()).append(" IN (");
+ stringBuilder.append(expression.getOutputSymbol()).append(operator);
} else {
- stringBuilder.append('(').append(expression.getOutputSymbol()).append(')').append(" IN (");
+ stringBuilder.append('(').append(expression.getOutputSymbol()).append(')').append(operator);
}
return appendValuesToBuild(stringBuilder).toString();
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/IsNullExpression.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/IsNullExpression.java
index 825c4629227..25d0daaed1d 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/IsNullExpression.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/IsNullExpression.java
@@ -55,11 +55,6 @@ public class IsNullExpression extends UnaryExpression {
return ExpressionType.IS_NULL;
}
- @Override
- protected Expression constructExpression(Expression childExpression) {
- return new IsNullExpression(childExpression, isNot);
- }
-
@Override
protected void serialize(ByteBuffer byteBuffer) {
super.serialize(byteBuffer);
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/LikeExpression.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/LikeExpression.java
index e11056610c7..2c08185f5c6 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/LikeExpression.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/LikeExpression.java
@@ -34,21 +34,27 @@ public class LikeExpression extends UnaryExpression {
private final String patternString;
private final Pattern pattern;
- public LikeExpression(Expression expression, String patternString) {
+ private final boolean isNot;
+
+ public LikeExpression(Expression expression, String patternString, boolean isNot) {
super(expression);
this.patternString = patternString;
+ this.isNot = isNot;
pattern = compile();
}
- public LikeExpression(Expression expression, String patternString, Pattern pattern) {
+ public LikeExpression(
+ Expression expression, String patternString, Pattern pattern, boolean isNot) {
super(expression);
this.patternString = patternString;
this.pattern = pattern;
+ this.isNot = isNot;
}
public LikeExpression(ByteBuffer byteBuffer) {
super(Expression.deserialize(byteBuffer));
patternString = ReadWriteIOUtils.readString(byteBuffer);
+ isNot = ReadWriteIOUtils.readBool(byteBuffer);
pattern = compile();
}
@@ -60,6 +66,10 @@ public class LikeExpression extends UnaryExpression {
return pattern;
}
+ public boolean isNot() {
+ return isNot;
+ }
+
/**
* The main idea of this part comes from
* https://codereview.stackexchange.com/questions/36861/convert-sql-like-to-regex/36864
@@ -118,7 +128,7 @@ public class LikeExpression extends UnaryExpression {
@Override
protected String getExpressionStringInternal() {
- return expression.getExpressionString() + " LIKE '" + pattern + "'";
+ return expression.getExpressionString() + (isNot ? " NOT" : "") + " LIKE '" + pattern + "'";
}
@Override
@@ -126,26 +136,23 @@ public class LikeExpression extends UnaryExpression {
return ExpressionType.LIKE;
}
- @Override
- protected Expression constructExpression(Expression childExpression) {
- return new LikeExpression(childExpression, patternString, pattern);
- }
-
@Override
protected void serialize(ByteBuffer byteBuffer) {
super.serialize(byteBuffer);
ReadWriteIOUtils.write(patternString, byteBuffer);
+ ReadWriteIOUtils.write(isNot, byteBuffer);
}
@Override
protected void serialize(DataOutputStream stream) throws IOException {
super.serialize(stream);
ReadWriteIOUtils.write(patternString, stream);
+ ReadWriteIOUtils.write(isNot, stream);
}
@Override
public String getOutputSymbolInternal() {
- return expression.getOutputSymbol() + " LIKE '" + pattern + "'";
+ return expression.getOutputSymbol() + (isNot ? " NOT" : "") + " LIKE '" + pattern + "'";
}
@Override
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/LogicNotExpression.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/LogicNotExpression.java
index c5496b1006b..69719cfd415 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/LogicNotExpression.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/LogicNotExpression.java
@@ -39,11 +39,6 @@ public class LogicNotExpression extends UnaryExpression {
super(Expression.deserialize(byteBuffer));
}
- @Override
- protected Expression constructExpression(Expression childExpression) {
- return new LogicNotExpression(childExpression);
- }
-
@Override
public String getExpressionStringInternal() {
return expression instanceof FunctionExpression || expression instanceof LeafOperand
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/NegationExpression.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/NegationExpression.java
index 7ff58c72bdb..52df786b486 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/NegationExpression.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/NegationExpression.java
@@ -39,11 +39,6 @@ public class NegationExpression extends UnaryExpression {
super(Expression.deserialize(byteBuffer));
}
- @Override
- protected Expression constructExpression(Expression childExpression) {
- return new NegationExpression(childExpression);
- }
-
@Override
public String getExpressionStringInternal() {
return expression instanceof TimeSeriesOperand
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/RegularExpression.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/RegularExpression.java
index 0bc5b129851..449c2bc21b7 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/RegularExpression.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/RegularExpression.java
@@ -36,21 +36,27 @@ public class RegularExpression extends UnaryExpression {
private final String patternString;
private final Pattern pattern;
- public RegularExpression(Expression expression, String patternString) {
+ private final boolean isNot;
+
+ public RegularExpression(Expression expression, String patternString, boolean isNot) {
super(expression);
this.patternString = patternString;
+ this.isNot = isNot;
pattern = Pattern.compile(patternString);
}
- public RegularExpression(Expression expression, String patternString, Pattern pattern) {
+ public RegularExpression(
+ Expression expression, String patternString, Pattern pattern, boolean isNot) {
super(expression);
this.patternString = patternString;
this.pattern = pattern;
+ this.isNot = isNot;
}
public RegularExpression(ByteBuffer byteBuffer) {
super(Expression.deserialize(byteBuffer));
patternString = ReadWriteIOUtils.readString(byteBuffer);
+ isNot = ReadWriteIOUtils.readBool(byteBuffer);
pattern = Pattern.compile(Validate.notNull(patternString));
}
@@ -62,14 +68,17 @@ public class RegularExpression extends UnaryExpression {
return pattern;
}
- @Override
- protected Expression constructExpression(Expression childExpression) {
- return new RegularExpression(childExpression, patternString, pattern);
+ public boolean isNot() {
+ return isNot;
}
@Override
protected String getExpressionStringInternal() {
- return expression.getExpressionString() + " REGEXP '" + patternString + "'";
+ return expression.getExpressionString()
+ + (isNot ? " NOT" : "")
+ + " REGEXP '"
+ + patternString
+ + "'";
}
@Override
@@ -81,17 +90,19 @@ public class RegularExpression extends UnaryExpression {
protected void serialize(ByteBuffer byteBuffer) {
super.serialize(byteBuffer);
ReadWriteIOUtils.write(patternString, byteBuffer);
+ ReadWriteIOUtils.write(isNot, byteBuffer);
}
@Override
protected void serialize(DataOutputStream stream) throws IOException {
super.serialize(stream);
ReadWriteIOUtils.write(patternString, stream);
+ ReadWriteIOUtils.write(isNot, stream);
}
@Override
public String getOutputSymbolInternal() {
- return expression.getOutputSymbol() + " REGEXP '" + patternString + "'";
+ return expression.getOutputSymbol() + (isNot ? " NOT" : "") + " REGEXP '" + patternString + "'";
}
@Override
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/UnaryExpression.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/UnaryExpression.java
index 89f6ddc543a..71fbd5ffeef 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/UnaryExpression.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/unary/UnaryExpression.java
@@ -94,8 +94,6 @@ public abstract class UnaryExpression extends Expression {
return expression.isMappable(expressionTypes);
}
- protected abstract Expression constructExpression(Expression childExpression);
-
@Override
protected void serialize(ByteBuffer byteBuffer) {
Expression.serialize(expression, byteBuffer);
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/ExpressionVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/ExpressionVisitor.java
index 74efa8615c5..f6737d2ad6a 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/ExpressionVisitor.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/ExpressionVisitor.java
@@ -47,6 +47,7 @@ import org.apache.iotdb.db.queryengine.plan.expression.multi.FunctionExpression;
import org.apache.iotdb.db.queryengine.plan.expression.other.CaseWhenThenExpression;
import org.apache.iotdb.db.queryengine.plan.expression.ternary.BetweenExpression;
import org.apache.iotdb.db.queryengine.plan.expression.ternary.TernaryExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.FixedIntervalMultiRangeExpression;
import org.apache.iotdb.db.queryengine.plan.expression.unary.InExpression;
import org.apache.iotdb.db.queryengine.plan.expression.unary.IsNullExpression;
import org.apache.iotdb.db.queryengine.plan.expression.unary.LikeExpression;
@@ -78,6 +79,11 @@ public abstract class ExpressionVisitor<R, C> {
return visitUnaryExpression(inExpression, context);
}
+ public R visitFixedIntervalMultiRangeExpression(
+ FixedIntervalMultiRangeExpression fixedIntervalMultiRangeExpression, C context) {
+ return visitUnaryExpression(fixedIntervalMultiRangeExpression, context);
+ }
+
public R visitIsNullExpression(IsNullExpression isNullExpression, C context) {
return visitUnaryExpression(isNullExpression, context);
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/TransformToViewExpressionVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/TransformToViewExpressionVisitor.java
index a428848caba..57cdbd537fe 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/TransformToViewExpressionVisitor.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/TransformToViewExpressionVisitor.java
@@ -135,7 +135,10 @@ public class TransformToViewExpressionVisitor extends ExpressionVisitor<ViewExpr
public ViewExpression visitLikeExpression(LikeExpression likeExpression, Void context) {
ViewExpression child = this.process(likeExpression.getExpression(), context);
return new LikeViewExpression(
- child, likeExpression.getPatternString(), likeExpression.getPattern());
+ child,
+ likeExpression.getPatternString(),
+ likeExpression.getPattern(),
+ likeExpression.isNot());
}
@Override
@@ -156,7 +159,10 @@ public class TransformToViewExpressionVisitor extends ExpressionVisitor<ViewExpr
public ViewExpression visitRegularExpression(RegularExpression regularExpression, Void context) {
ViewExpression child = this.process(regularExpression.getExpression(), context);
return new RegularViewExpression(
- child, regularExpression.getPatternString(), regularExpression.getPattern());
+ child,
+ regularExpression.getPatternString(),
+ regularExpression.getPattern(),
+ regularExpression.isNot());
}
// endregion
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/predicate/ConvertExpressionToFilterVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/predicate/ConvertExpressionToFilterVisitor.java
new file mode 100644
index 00000000000..091eb92b8ca
--- /dev/null
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/predicate/ConvertExpressionToFilterVisitor.java
@@ -0,0 +1,404 @@
+/*
+ * 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.db.queryengine.plan.expression.visitor.predicate;
+
+import org.apache.iotdb.db.queryengine.plan.analyze.TypeProvider;
+import org.apache.iotdb.db.queryengine.plan.expression.Expression;
+import org.apache.iotdb.db.queryengine.plan.expression.ExpressionType;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.EqualToExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.GreaterEqualExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.GreaterThanExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LessEqualExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LessThanExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LogicAndExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LogicOrExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.NonEqualExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.leaf.ConstantOperand;
+import org.apache.iotdb.db.queryengine.plan.expression.leaf.TimeSeriesOperand;
+import org.apache.iotdb.db.queryengine.plan.expression.ternary.BetweenExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.FixedIntervalMultiRangeExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.InExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.IsNullExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.LikeExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.LogicNotExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.RegularExpression;
+import org.apache.iotdb.tsfile.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
+import org.apache.iotdb.tsfile.read.filter.factory.TimeFilter;
+import org.apache.iotdb.tsfile.read.filter.factory.ValueFilter;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import static org.apache.iotdb.tsfile.read.filter.operator.Not.CONTAIN_NOT_ERR_MSG;
+
+/**
+ * The supplied predicate expression should also have already been run through {@link
+ * SchemaCompatibilityValidator} to make sure it is compatible with the schema.
+ */
+public class ConvertExpressionToFilterVisitor extends PredicateVisitor<Filter, TypeProvider> {
+
+ @Override
+ public Filter visitInExpression(InExpression inExpression, TypeProvider types) {
+ Expression expression = inExpression.getExpression();
+ TSDataType dataType = types.getType(expression.toString());
+
+ Set<String> values = inExpression.getValues();
+ if (values.size() == 1) {
+ // rewrite 'a in (1)' to 'a = 1' or 'a not in 1' to 'a != 1'
+ Expression rewrittenExpression = rewriteInExpressionToEqual(inExpression, dataType);
+ return rewrittenExpression.accept(this, types);
+ }
+
+ switch (dataType) {
+ case INT32:
+ Set<Integer> intValues = new LinkedHashSet<>();
+ for (String value : values) {
+ intValues.add(Integer.parseInt(value));
+ }
+ return constructInFilter(inExpression, intValues);
+ case INT64:
+ Set<Long> longValues = new LinkedHashSet<>();
+ for (String value : values) {
+ longValues.add(Long.parseLong(value));
+ }
+ return constructInFilter(inExpression, longValues);
+ case FLOAT:
+ Set<Float> floatValues = new LinkedHashSet<>();
+ for (String value : values) {
+ floatValues.add(Float.parseFloat(value));
+ }
+ return constructInFilter(inExpression, floatValues);
+ case DOUBLE:
+ Set<Double> doubleValues = new LinkedHashSet<>();
+ for (String value : values) {
+ doubleValues.add(Double.parseDouble(value));
+ }
+ return constructInFilter(inExpression, doubleValues);
+ case BOOLEAN:
+ Set<Boolean> booleanValues = new LinkedHashSet<>();
+ for (String value : values) {
+ booleanValues.add(Boolean.parseBoolean(value));
+ }
+ return constructInFilter(inExpression, booleanValues);
+ case TEXT:
+ return constructInFilter(inExpression, values);
+ default:
+ throw new UnsupportedOperationException(
+ String.format("Unsupported data type %s", dataType));
+ }
+ }
+
+ @Override
+ public Filter visitFixedIntervalMultiRangeExpression(
+ FixedIntervalMultiRangeExpression fixedIntervalMultiRangeExpression, TypeProvider context) {
+ throw new UnsupportedOperationException("FixedIntervalMultiRangeExpression is not supported");
+ }
+
+ private Expression rewriteInExpressionToEqual(InExpression inExpression, TSDataType dataType) {
+ Set<String> values = inExpression.getValues();
+ if (inExpression.isNotIn()) {
+ return new NonEqualExpression(
+ inExpression.getExpression(), new ConstantOperand(dataType, values.iterator().next()));
+ } else {
+ return new EqualToExpression(
+ inExpression.getExpression(), new ConstantOperand(dataType, values.iterator().next()));
+ }
+ }
+
+ private <T extends Comparable<T>> Filter constructInFilter(
+ InExpression inExpression, Set<T> values) {
+ boolean isNot = inExpression.isNotIn();
+ Expression expression = inExpression.getExpression();
+
+ if (expression.getExpressionType().equals(ExpressionType.TIMESTAMP)) {
+ return isNot ? TimeFilter.in((Set<Long>) values) : TimeFilter.notIn((Set<Long>) values);
+ } else if (expression.getExpressionType().equals(ExpressionType.TIMESERIES)) {
+ String measurement = ((TimeSeriesOperand) expression).getPath().getMeasurement();
+ return isNot ? ValueFilter.in(measurement, values) : ValueFilter.notIn(measurement, values);
+ } else {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Override
+ public Filter visitIsNullExpression(IsNullExpression isNullExpression, TypeProvider types) {
+ Expression expression = isNullExpression.getExpression();
+ if (expression.getExpressionType().equals(ExpressionType.TIMESTAMP)) {
+ throw new UnsupportedOperationException("TIMESTAMP does not support IS NULL");
+ }
+
+ String measurement = ((TimeSeriesOperand) expression).getPath().getMeasurement();
+ boolean isNot = isNullExpression.isNot();
+ return isNot ? ValueFilter.notEq(measurement, null) : ValueFilter.eq(measurement, null);
+ }
+
+ @Override
+ public Filter visitLikeExpression(LikeExpression likeExpression, TypeProvider types) {
+ Expression expression = likeExpression.getExpression();
+ if (expression.getExpressionType().equals(ExpressionType.TIMESTAMP)) {
+ throw new UnsupportedOperationException("TIMESTAMP does not support LIKE");
+ }
+
+ String measurement = ((TimeSeriesOperand) expression).getPath().getMeasurement();
+ String likePattern = likeExpression.getPatternString();
+ boolean isNot = likeExpression.isNot();
+ return isNot
+ ? ValueFilter.notLike(measurement, likePattern)
+ : ValueFilter.like(measurement, likePattern);
+ }
+
+ @Override
+ public Filter visitRegularExpression(RegularExpression regularExpression, TypeProvider types) {
+ Expression expression = regularExpression.getExpression();
+ if (expression.getExpressionType().equals(ExpressionType.TIMESTAMP)) {
+ throw new UnsupportedOperationException("TIMESTAMP does not support REGEXP");
+ }
+
+ String measurement = ((TimeSeriesOperand) expression).getPath().getMeasurement();
+ String regex = regularExpression.getPatternString();
+ boolean isNot = regularExpression.isNot();
+ return isNot
+ ? ValueFilter.notRegexp(measurement, regex)
+ : ValueFilter.regexp(measurement, regex);
+ }
+
+ @Override
+ public Filter visitLogicNotExpression(LogicNotExpression logicNotExpression, TypeProvider types) {
+ throw new IllegalArgumentException(CONTAIN_NOT_ERR_MSG);
+ }
+
+ @Override
+ public Filter visitLogicAndExpression(LogicAndExpression logicAndExpression, TypeProvider types) {
+ return FilterFactory.and(
+ logicAndExpression.getLeftExpression().accept(this, types),
+ logicAndExpression.getRightExpression().accept(this, types));
+ }
+
+ @Override
+ public Filter visitLogicOrExpression(LogicOrExpression logicOrExpression, TypeProvider types) {
+ return FilterFactory.or(
+ logicOrExpression.getLeftExpression().accept(this, types),
+ logicOrExpression.getRightExpression().accept(this, types));
+ }
+
+ @Override
+ public Filter visitEqualToExpression(EqualToExpression equalToExpression, TypeProvider types) {
+ return constructCompareFilter(
+ equalToExpression.getExpressionType(),
+ equalToExpression.getLeftExpression(),
+ equalToExpression.getRightExpression(),
+ types);
+ }
+
+ @Override
+ public Filter visitNonEqualExpression(NonEqualExpression nonEqualExpression, TypeProvider types) {
+ return constructCompareFilter(
+ nonEqualExpression.getExpressionType(),
+ nonEqualExpression.getLeftExpression(),
+ nonEqualExpression.getRightExpression(),
+ types);
+ }
+
+ @Override
+ public Filter visitGreaterThanExpression(
+ GreaterThanExpression greaterThanExpression, TypeProvider types) {
+ return constructCompareFilter(
+ greaterThanExpression.getExpressionType(),
+ greaterThanExpression.getLeftExpression(),
+ greaterThanExpression.getRightExpression(),
+ types);
+ }
+
+ @Override
+ public Filter visitGreaterEqualExpression(
+ GreaterEqualExpression greaterEqualExpression, TypeProvider types) {
+ return constructCompareFilter(
+ greaterEqualExpression.getExpressionType(),
+ greaterEqualExpression.getLeftExpression(),
+ greaterEqualExpression.getRightExpression(),
+ types);
+ }
+
+ @Override
+ public Filter visitLessThanExpression(LessThanExpression lessThanExpression, TypeProvider types) {
+ return constructCompareFilter(
+ lessThanExpression.getExpressionType(),
+ lessThanExpression.getLeftExpression(),
+ lessThanExpression.getRightExpression(),
+ types);
+ }
+
+ @Override
+ public Filter visitLessEqualExpression(
+ LessEqualExpression lessEqualExpression, TypeProvider types) {
+ return constructCompareFilter(
+ lessEqualExpression.getExpressionType(),
+ lessEqualExpression.getLeftExpression(),
+ lessEqualExpression.getRightExpression(),
+ types);
+ }
+
+ private Filter constructCompareFilter(
+ ExpressionType expressionType,
+ Expression leftExpression,
+ Expression rightExpression,
+ TypeProvider types) {
+ if (leftExpression.getExpressionType().equals(ExpressionType.CONSTANT)) {
+ return constructCompareFilter(expressionType, rightExpression, leftExpression, types);
+ }
+
+ TSDataType dataType = types.getType(leftExpression.toString());
+ String valueString = ((ConstantOperand) rightExpression).getValueString();
+
+ if (leftExpression.getExpressionType().equals(ExpressionType.TIMESTAMP)) {
+ return constructTimeCompareFilter(expressionType, valueString);
+ }
+
+ String measurement = ((TimeSeriesOperand) leftExpression).getPath().getMeasurement();
+ switch (dataType) {
+ case INT32:
+ return constructValueCompareFilter(
+ expressionType, measurement, Integer.parseInt(valueString));
+ case INT64:
+ return constructValueCompareFilter(
+ expressionType, measurement, Long.parseLong(valueString));
+ case FLOAT:
+ return constructValueCompareFilter(
+ expressionType, measurement, Float.parseFloat(valueString));
+ case DOUBLE:
+ return constructValueCompareFilter(
+ expressionType, measurement, Double.parseDouble(valueString));
+ case BOOLEAN:
+ return constructValueCompareFilter(
+ expressionType, measurement, Boolean.parseBoolean(valueString));
+ case TEXT:
+ return constructValueCompareFilter(expressionType, measurement, valueString);
+ default:
+ throw new UnsupportedOperationException(
+ String.format("Unsupported data type %s", dataType));
+ }
+ }
+
+ private Filter constructTimeCompareFilter(ExpressionType expressionType, String valueString) {
+ switch (expressionType) {
+ case EQUAL_TO:
+ return TimeFilter.eq(Long.parseLong(valueString));
+ case NON_EQUAL:
+ return TimeFilter.notEq(Long.parseLong(valueString));
+ case GREATER_THAN:
+ return TimeFilter.gt(Long.parseLong(valueString));
+ case GREATER_EQUAL:
+ return TimeFilter.gtEq(Long.parseLong(valueString));
+ case LESS_THAN:
+ return TimeFilter.lt(Long.parseLong(valueString));
+ case LESS_EQUAL:
+ return TimeFilter.ltEq(Long.parseLong(valueString));
+ default:
+ throw new UnsupportedOperationException(
+ String.format("Unsupported expression type %s", expressionType));
+ }
+ }
+
+ private <T extends Comparable<T>> Filter constructValueCompareFilter(
+ ExpressionType expressionType, String measurement, T value) {
+ switch (expressionType) {
+ case EQUAL_TO:
+ return ValueFilter.eq(measurement, value);
+ case NON_EQUAL:
+ return ValueFilter.notEq(measurement, value);
+ case GREATER_THAN:
+ return ValueFilter.gt(measurement, value);
+ case GREATER_EQUAL:
+ return ValueFilter.gtEq(measurement, value);
+ case LESS_THAN:
+ return ValueFilter.lt(measurement, value);
+ case LESS_EQUAL:
+ return ValueFilter.ltEq(measurement, value);
+ default:
+ throw new UnsupportedOperationException(
+ String.format("Unsupported expression type %s", expressionType));
+ }
+ }
+
+ @Override
+ public Filter visitBetweenExpression(BetweenExpression betweenExpression, TypeProvider types) {
+ Expression firstExpression = betweenExpression.getFirstExpression();
+ Expression secondExpression = betweenExpression.getSecondExpression();
+ Expression thirdExpression = betweenExpression.getThirdExpression();
+ boolean isNot = betweenExpression.isNotBetween();
+
+ if (!(secondExpression instanceof ConstantOperand)
+ || !(thirdExpression instanceof ConstantOperand)) {
+ throw new IllegalArgumentException(
+ "The second and third parameters of BETWEEN must be constant");
+ }
+ String minValue = ((ConstantOperand) secondExpression).getValueString();
+ String maxValue = ((ConstantOperand) thirdExpression).getValueString();
+
+ if (firstExpression.getExpressionType().equals(ExpressionType.TIMESTAMP)) {
+ return isNot
+ ? TimeFilter.notBetween(Long.parseLong(minValue), Long.parseLong(maxValue))
+ : TimeFilter.between(Long.parseLong(minValue), Long.parseLong(maxValue));
+ }
+
+ String measurement = ((TimeSeriesOperand) firstExpression).getPath().getMeasurement();
+ TSDataType dataType = types.getType(firstExpression.toString());
+ switch (dataType) {
+ case INT32:
+ return isNot
+ ? ValueFilter.notBetween(
+ measurement, Integer.parseInt(minValue), Integer.parseInt(maxValue))
+ : ValueFilter.between(
+ measurement, Integer.parseInt(minValue), Integer.parseInt(maxValue));
+ case INT64:
+ return isNot
+ ? ValueFilter.notBetween(
+ measurement, Long.parseLong(minValue), Long.parseLong(maxValue))
+ : ValueFilter.between(measurement, Long.parseLong(minValue), Long.parseLong(maxValue));
+ case FLOAT:
+ return isNot
+ ? ValueFilter.notBetween(
+ measurement, Float.parseFloat(minValue), Float.parseFloat(maxValue))
+ : ValueFilter.between(
+ measurement, Float.parseFloat(minValue), Float.parseFloat(maxValue));
+ case DOUBLE:
+ return isNot
+ ? ValueFilter.notBetween(
+ measurement, Double.parseDouble(minValue), Double.parseDouble(maxValue))
+ : ValueFilter.between(
+ measurement, Double.parseDouble(minValue), Double.parseDouble(maxValue));
+ case BOOLEAN:
+ return isNot
+ ? ValueFilter.notBetween(
+ measurement, Boolean.parseBoolean(minValue), Boolean.parseBoolean(maxValue))
+ : ValueFilter.between(
+ measurement, Boolean.parseBoolean(minValue), Boolean.parseBoolean(maxValue));
+ case TEXT:
+ return isNot
+ ? ValueFilter.notBetween(measurement, minValue, maxValue)
+ : ValueFilter.between(measurement, minValue, maxValue);
+ default:
+ throw new UnsupportedOperationException(
+ String.format("Unsupported data type %s", dataType));
+ }
+ }
+}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/predicate/ConvertExpressionToTimeFilterVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/predicate/ConvertExpressionToTimeFilterVisitor.java
new file mode 100644
index 00000000000..f555c4b6abb
--- /dev/null
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/predicate/ConvertExpressionToTimeFilterVisitor.java
@@ -0,0 +1,252 @@
+/*
+ * 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.db.queryengine.plan.expression.visitor.predicate;
+
+import org.apache.iotdb.db.queryengine.plan.expression.Expression;
+import org.apache.iotdb.db.queryengine.plan.expression.ExpressionType;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.EqualToExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.GreaterEqualExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.GreaterThanExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LessEqualExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LessThanExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LogicAndExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LogicOrExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.NonEqualExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.leaf.ConstantOperand;
+import org.apache.iotdb.db.queryengine.plan.expression.ternary.BetweenExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.FixedIntervalMultiRangeExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.InExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.IsNullExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.LikeExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.LogicNotExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.RegularExpression;
+import org.apache.iotdb.db.utils.TimestampPrecisionUtils;
+import org.apache.iotdb.tsfile.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
+import org.apache.iotdb.tsfile.read.filter.factory.TimeFilter;
+import org.apache.iotdb.tsfile.utils.TimeDuration;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.TimeZone;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.iotdb.tsfile.read.filter.operator.Not.CONTAIN_NOT_ERR_MSG;
+
+public class ConvertExpressionToTimeFilterVisitor extends PredicateVisitor<Filter, Void> {
+
+ @Override
+ public Filter visitInExpression(InExpression inExpression, Void context) {
+ Expression expression = inExpression.getExpression();
+ checkArgument(expression.getExpressionType().equals(ExpressionType.TIMESTAMP));
+
+ Set<String> values = inExpression.getValues();
+ if (values.size() == 1) {
+ // rewrite 'time in (1)' to 'time = 1' or 'time not in 1' to 'time != 1'
+ Expression rewrittenExpression = rewriteInExpressionToEqual(inExpression);
+ return rewrittenExpression.accept(this, context);
+ }
+
+ Set<Long> longValues = new LinkedHashSet<>();
+ for (String value : values) {
+ longValues.add(Long.parseLong(value));
+ }
+ return inExpression.isNotIn() ? TimeFilter.in(longValues) : TimeFilter.notIn(longValues);
+ }
+
+ private Expression rewriteInExpressionToEqual(InExpression inExpression) {
+ Set<String> values = inExpression.getValues();
+ if (inExpression.isNotIn()) {
+ return new NonEqualExpression(
+ inExpression.getExpression(),
+ new ConstantOperand(TSDataType.INT64, values.iterator().next()));
+ } else {
+ return new EqualToExpression(
+ inExpression.getExpression(),
+ new ConstantOperand(TSDataType.INT64, values.iterator().next()));
+ }
+ }
+
+ @Override
+ public Filter visitIsNullExpression(IsNullExpression isNullExpression, Void context) {
+ throw new UnsupportedOperationException("TIMESTAMP does not support IS NULL");
+ }
+
+ @Override
+ public Filter visitLikeExpression(LikeExpression likeExpression, Void context) {
+ throw new UnsupportedOperationException("TIMESTAMP does not support LIKE");
+ }
+
+ @Override
+ public Filter visitRegularExpression(RegularExpression regularExpression, Void context) {
+ throw new UnsupportedOperationException("TIMESTAMP does not support REGEXP");
+ }
+
+ @Override
+ public Filter visitLogicNotExpression(LogicNotExpression logicNotExpression, Void context) {
+ throw new IllegalArgumentException(CONTAIN_NOT_ERR_MSG);
+ }
+
+ @Override
+ public Filter visitLogicAndExpression(LogicAndExpression logicAndExpression, Void context) {
+ return FilterFactory.and(
+ logicAndExpression.getLeftExpression().accept(this, context),
+ logicAndExpression.getRightExpression().accept(this, context));
+ }
+
+ @Override
+ public Filter visitLogicOrExpression(LogicOrExpression logicOrExpression, Void context) {
+ return FilterFactory.or(
+ logicOrExpression.getLeftExpression().accept(this, context),
+ logicOrExpression.getRightExpression().accept(this, context));
+ }
+
+ @Override
+ public Filter visitEqualToExpression(EqualToExpression equalToExpression, Void context) {
+ return constructCompareFilter(
+ equalToExpression.getExpressionType(),
+ equalToExpression.getLeftExpression(),
+ equalToExpression.getRightExpression());
+ }
+
+ @Override
+ public Filter visitNonEqualExpression(NonEqualExpression nonEqualExpression, Void context) {
+ return constructCompareFilter(
+ nonEqualExpression.getExpressionType(),
+ nonEqualExpression.getLeftExpression(),
+ nonEqualExpression.getRightExpression());
+ }
+
+ @Override
+ public Filter visitGreaterThanExpression(
+ GreaterThanExpression greaterThanExpression, Void context) {
+ return constructCompareFilter(
+ greaterThanExpression.getExpressionType(),
+ greaterThanExpression.getLeftExpression(),
+ greaterThanExpression.getRightExpression());
+ }
+
+ @Override
+ public Filter visitGreaterEqualExpression(
+ GreaterEqualExpression greaterEqualExpression, Void context) {
+ return constructCompareFilter(
+ greaterEqualExpression.getExpressionType(),
+ greaterEqualExpression.getLeftExpression(),
+ greaterEqualExpression.getRightExpression());
+ }
+
+ @Override
+ public Filter visitLessThanExpression(LessThanExpression lessThanExpression, Void context) {
+ return constructCompareFilter(
+ lessThanExpression.getExpressionType(),
+ lessThanExpression.getLeftExpression(),
+ lessThanExpression.getRightExpression());
+ }
+
+ @Override
+ public Filter visitLessEqualExpression(LessEqualExpression lessEqualExpression, Void context) {
+ return constructCompareFilter(
+ lessEqualExpression.getExpressionType(),
+ lessEqualExpression.getLeftExpression(),
+ lessEqualExpression.getRightExpression());
+ }
+
+ private Filter constructCompareFilter(
+ ExpressionType expressionType, Expression leftExpression, Expression rightExpression) {
+ if (leftExpression.getExpressionType().equals(ExpressionType.CONSTANT)) {
+ return constructCompareFilter(expressionType, rightExpression, leftExpression);
+ }
+
+ checkArgument(leftExpression.getExpressionType().equals(ExpressionType.TIMESTAMP));
+ checkArgument(rightExpression instanceof ConstantOperand);
+ checkArgument(((ConstantOperand) rightExpression).getDataType().equals(TSDataType.INT64));
+
+ long value = Long.parseLong(((ConstantOperand) rightExpression).getValueString());
+
+ switch (expressionType) {
+ case EQUAL_TO:
+ return TimeFilter.eq(value);
+ case NON_EQUAL:
+ return TimeFilter.notEq(value);
+ case GREATER_THAN:
+ return TimeFilter.gt(value);
+ case GREATER_EQUAL:
+ return TimeFilter.gtEq(value);
+ case LESS_THAN:
+ return TimeFilter.lt(value);
+ case LESS_EQUAL:
+ return TimeFilter.ltEq(value);
+ default:
+ throw new UnsupportedOperationException(
+ String.format("Unsupported expression type %s", expressionType));
+ }
+ }
+
+ @Override
+ public Filter visitBetweenExpression(BetweenExpression betweenExpression, Void context) {
+ Expression firstExpression = betweenExpression.getFirstExpression();
+ Expression secondExpression = betweenExpression.getSecondExpression();
+ Expression thirdExpression = betweenExpression.getThirdExpression();
+ boolean isNot = betweenExpression.isNotBetween();
+
+ checkArgument(firstExpression.getExpressionType().equals(ExpressionType.TIMESTAMP));
+ checkArgument(
+ (secondExpression instanceof ConstantOperand)
+ && ((ConstantOperand) secondExpression).getDataType().equals(TSDataType.INT64));
+ checkArgument(
+ (thirdExpression instanceof ConstantOperand)
+ && ((ConstantOperand) thirdExpression).getDataType().equals(TSDataType.INT64));
+
+ long minValue = Long.parseLong(((ConstantOperand) secondExpression).getValueString());
+ long maxValue = Long.parseLong(((ConstantOperand) thirdExpression).getValueString());
+
+ return isNot
+ ? TimeFilter.notBetween(minValue, maxValue)
+ : TimeFilter.between(minValue, maxValue);
+ }
+
+ @Override
+ public Filter visitFixedIntervalMultiRangeExpression(
+ FixedIntervalMultiRangeExpression fixedIntervalMultiRangeExpression, Void context) {
+ long startTime = fixedIntervalMultiRangeExpression.getStartTime();
+ long endTime = fixedIntervalMultiRangeExpression.getEndTime();
+ TimeDuration interval = fixedIntervalMultiRangeExpression.getInterval();
+ TimeDuration slidingStep = fixedIntervalMultiRangeExpression.getSlidingStep();
+
+ if (slidingStep.compareTo(interval) <= 0) {
+ // slidingStep <= interval, full time range
+ return TimeFilter.between(startTime, endTime);
+ } else {
+ if (interval.containsMonth() || slidingStep.containsMonth()) {
+ return TimeFilter.groupByMonth(
+ startTime,
+ endTime,
+ interval,
+ slidingStep,
+ TimeZone.getTimeZone("+00:00"),
+ TimestampPrecisionUtils.currPrecision);
+ } else {
+ return TimeFilter.groupBy(
+ startTime, endTime, interval.nonMonthDuration, slidingStep.nonMonthDuration);
+ }
+ }
+ }
+}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/predicate/PredicateVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/predicate/PredicateVisitor.java
new file mode 100644
index 00000000000..60336b0effd
--- /dev/null
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/predicate/PredicateVisitor.java
@@ -0,0 +1,87 @@
+/*
+ * 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.db.queryengine.plan.expression.visitor.predicate;
+
+import org.apache.iotdb.db.queryengine.plan.expression.Expression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.EqualToExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.GreaterEqualExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.GreaterThanExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LessEqualExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LessThanExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LogicAndExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LogicOrExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.NonEqualExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.ternary.BetweenExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.FixedIntervalMultiRangeExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.InExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.IsNullExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.LikeExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.LogicNotExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.RegularExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.visitor.ExpressionVisitor;
+
+/**
+ * This class provides a visitor of {@link Expression}, which can be extended to create a visitor
+ * which only needs to handle a subset of the available methods.
+ *
+ * @param <R> The return type of the visit operation.
+ * @param <C> The context information during visiting.
+ */
+public abstract class PredicateVisitor<R, C> extends ExpressionVisitor<R, C> {
+
+ @Override
+ public R visitExpression(Expression expression, C context) {
+ throw new IllegalArgumentException(
+ "Unsupported expression type: " + expression.getExpressionType());
+ }
+
+ public abstract R visitInExpression(InExpression inExpression, C context);
+
+ public abstract R visitFixedIntervalMultiRangeExpression(
+ FixedIntervalMultiRangeExpression fixedIntervalMultiRangeExpression, C context);
+
+ public abstract R visitIsNullExpression(IsNullExpression isNullExpression, C context);
+
+ public abstract R visitLikeExpression(LikeExpression likeExpression, C context);
+
+ public abstract R visitRegularExpression(RegularExpression regularExpression, C context);
+
+ public abstract R visitLogicNotExpression(LogicNotExpression logicNotExpression, C context);
+
+ public abstract R visitLogicAndExpression(LogicAndExpression logicAndExpression, C context);
+
+ public abstract R visitLogicOrExpression(LogicOrExpression logicOrExpression, C context);
+
+ public abstract R visitEqualToExpression(EqualToExpression equalToExpression, C context);
+
+ public abstract R visitNonEqualExpression(NonEqualExpression nonEqualExpression, C context);
+
+ public abstract R visitGreaterThanExpression(
+ GreaterThanExpression greaterThanExpression, C context);
+
+ public abstract R visitGreaterEqualExpression(
+ GreaterEqualExpression greaterEqualExpression, C context);
+
+ public abstract R visitLessThanExpression(LessThanExpression lessThanExpression, C context);
+
+ public abstract R visitLessEqualExpression(LessEqualExpression lessEqualExpression, C context);
+
+ public abstract R visitBetweenExpression(BetweenExpression betweenExpression, C context);
+}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/predicate/ReversePredicateVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/predicate/ReversePredicateVisitor.java
new file mode 100644
index 00000000000..4b1dab1d5ee
--- /dev/null
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/predicate/ReversePredicateVisitor.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.queryengine.plan.expression.visitor.predicate;
+
+import org.apache.iotdb.db.queryengine.plan.expression.Expression;
+import org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.EqualToExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.GreaterEqualExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.GreaterThanExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LessEqualExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LessThanExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LogicAndExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LogicOrExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.NonEqualExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.ternary.BetweenExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.FixedIntervalMultiRangeExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.InExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.IsNullExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.LikeExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.LogicNotExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.RegularExpression;
+
+public class ReversePredicateVisitor extends PredicateVisitor<Expression, Void> {
+
+ @Override
+ public Expression visitExpression(Expression expression, Void context) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Expression visitInExpression(InExpression inExpression, Void context) {
+ return new InExpression(
+ inExpression.getExpression(), !inExpression.isNotIn(), inExpression.getValues());
+ }
+
+ @Override
+ public Expression visitFixedIntervalMultiRangeExpression(
+ FixedIntervalMultiRangeExpression fixedIntervalMultiRangeExpression, Void context) {
+ throw new UnsupportedOperationException("GROUP BY TIME doesn't support reverse predicate");
+ }
+
+ @Override
+ public Expression visitIsNullExpression(IsNullExpression isNullExpression, Void context) {
+ return new IsNullExpression(isNullExpression.getExpression(), !isNullExpression.isNot());
+ }
+
+ @Override
+ public Expression visitLikeExpression(LikeExpression likeExpression, Void context) {
+ return new LikeExpression(
+ likeExpression.getExpression(),
+ likeExpression.getPatternString(),
+ likeExpression.getPattern(),
+ !likeExpression.isNot());
+ }
+
+ @Override
+ public Expression visitRegularExpression(RegularExpression regularExpression, Void context) {
+ return new RegularExpression(
+ regularExpression.getExpression(),
+ regularExpression.getPatternString(),
+ regularExpression.getPattern(),
+ !regularExpression.isNot());
+ }
+
+ @Override
+ public Expression visitLogicNotExpression(LogicNotExpression logicNotExpression, Void context) {
+ return logicNotExpression.getExpression();
+ }
+
+ @Override
+ public Expression visitLogicAndExpression(LogicAndExpression logicAndExpression, Void context) {
+ return ExpressionFactory.or(
+ logicAndExpression.getLeftExpression().accept(this, context),
+ logicAndExpression.getRightExpression().accept(this, context));
+ }
+
+ @Override
+ public Expression visitLogicOrExpression(LogicOrExpression logicOrExpression, Void context) {
+ return ExpressionFactory.and(
+ logicOrExpression.getLeftExpression().accept(this, context),
+ logicOrExpression.getRightExpression().accept(this, context));
+ }
+
+ @Override
+ public Expression visitEqualToExpression(EqualToExpression equalToExpression, Void context) {
+ return new NonEqualExpression(
+ equalToExpression.getLeftExpression(), equalToExpression.getRightExpression());
+ }
+
+ @Override
+ public Expression visitNonEqualExpression(NonEqualExpression nonEqualExpression, Void context) {
+ return new EqualToExpression(
+ nonEqualExpression.getLeftExpression(), nonEqualExpression.getRightExpression());
+ }
+
+ @Override
+ public Expression visitGreaterThanExpression(
+ GreaterThanExpression greaterThanExpression, Void context) {
+ return new LessEqualExpression(
+ greaterThanExpression.getLeftExpression(), greaterThanExpression.getRightExpression());
+ }
+
+ @Override
+ public Expression visitGreaterEqualExpression(
+ GreaterEqualExpression greaterEqualExpression, Void context) {
+ return new LessThanExpression(
+ greaterEqualExpression.getLeftExpression(), greaterEqualExpression.getRightExpression());
+ }
+
+ @Override
+ public Expression visitLessThanExpression(LessThanExpression lessThanExpression, Void context) {
+ return new GreaterEqualExpression(
+ lessThanExpression.getLeftExpression(), lessThanExpression.getRightExpression());
+ }
+
+ @Override
+ public Expression visitLessEqualExpression(
+ LessEqualExpression lessEqualExpression, Void context) {
+ return new GreaterThanExpression(
+ lessEqualExpression.getLeftExpression(), lessEqualExpression.getRightExpression());
+ }
+
+ @Override
+ public Expression visitBetweenExpression(BetweenExpression betweenExpression, Void context) {
+ return new BetweenExpression(
+ betweenExpression.getFirstExpression(),
+ betweenExpression.getSecondExpression(),
+ betweenExpression.getThirdExpression(),
+ !betweenExpression.isNotBetween());
+ }
+}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/predicate/SchemaCompatibilityValidator.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/predicate/SchemaCompatibilityValidator.java
new file mode 100644
index 00000000000..8bc84560e49
--- /dev/null
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/expression/visitor/predicate/SchemaCompatibilityValidator.java
@@ -0,0 +1,194 @@
+/*
+ * 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.db.queryengine.plan.expression.visitor.predicate;
+
+import org.apache.iotdb.commons.path.MeasurementPath;
+import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.db.queryengine.plan.expression.Expression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.EqualToExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.GreaterEqualExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.GreaterThanExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LessEqualExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LessThanExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LogicAndExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.LogicOrExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.binary.NonEqualExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.leaf.ConstantOperand;
+import org.apache.iotdb.db.queryengine.plan.expression.leaf.TimeSeriesOperand;
+import org.apache.iotdb.db.queryengine.plan.expression.leaf.TimestampOperand;
+import org.apache.iotdb.db.queryengine.plan.expression.ternary.BetweenExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.FixedIntervalMultiRangeExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.InExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.IsNullExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.LikeExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.LogicNotExpression;
+import org.apache.iotdb.db.queryengine.plan.expression.unary.RegularExpression;
+
+public class SchemaCompatibilityValidator
+ extends PredicateVisitor<Void, SchemaCompatibilityValidator.Context> {
+
+ public static void validate(Expression predicate) {
+ predicate.accept(new SchemaCompatibilityValidator(), new Context());
+ }
+
+ protected static class Context {
+
+ private PartialPath checkedPath;
+ private boolean isAligned;
+
+ public Context() {
+ // needn't init
+ }
+
+ public void check(MeasurementPath path) {
+ if (checkedPath == null) {
+ // init checkedPath
+ isAligned = path.isUnderAlignedEntity();
+ checkedPath = getComparePath(path);
+ } else {
+ if (isAligned != path.isUnderAlignedEntity() || !checkedPath.equals(getComparePath(path))) {
+ throw new IllegalArgumentException(
+ "The paths in the predicate are not compatible with each other.");
+ }
+ }
+ }
+
+ private PartialPath getComparePath(MeasurementPath path) {
+ if (path.isUnderAlignedEntity()) return path.getDevicePath();
+ return path;
+ }
+ }
+
+ @Override
+ public Void visitTimeSeriesOperand(TimeSeriesOperand timeSeriesOperand, Context context) {
+ context.check((MeasurementPath) timeSeriesOperand.getPath());
+ return null;
+ }
+
+ @Override
+ public Void visitTimeStampOperand(TimestampOperand timestampOperand, Context context) {
+ // needn't check
+ return null;
+ }
+
+ @Override
+ public Void visitConstantOperand(ConstantOperand constantOperand, Context context) {
+ // needn't check
+ return null;
+ }
+
+ @Override
+ public Void visitFixedIntervalMultiRangeExpression(
+ FixedIntervalMultiRangeExpression fixedIntervalMultiRangeExpression, Context context) {
+ // needn't check
+ return null;
+ }
+
+ @Override
+ public Void visitInExpression(InExpression inExpression, Context context) {
+ return inExpression.getExpression().accept(this, context);
+ }
+
+ @Override
+ public Void visitIsNullExpression(IsNullExpression isNullExpression, Context context) {
+ return isNullExpression.getExpression().accept(this, context);
+ }
+
+ @Override
+ public Void visitLikeExpression(LikeExpression likeExpression, Context context) {
+ return likeExpression.getExpression().accept(this, context);
+ }
+
+ @Override
+ public Void visitRegularExpression(RegularExpression regularExpression, Context context) {
+ return regularExpression.getExpression().accept(this, context);
+ }
+
+ @Override
+ public Void visitLogicNotExpression(LogicNotExpression logicNotExpression, Context context) {
+ return logicNotExpression.getExpression().accept(this, context);
+ }
+
+ @Override
+ public Void visitLogicAndExpression(LogicAndExpression logicAndExpression, Context context) {
+ logicAndExpression.getLeftExpression().accept(this, context);
+ logicAndExpression.getRightExpression().accept(this, context);
+ return null;
+ }
+
+ @Override
+ public Void visitLogicOrExpression(LogicOrExpression logicOrExpression, Context context) {
+ logicOrExpression.getLeftExpression().accept(this, context);
+ logicOrExpression.getRightExpression().accept(this, context);
+ return null;
+ }
+
+ @Override
+ public Void visitEqualToExpression(EqualToExpression equalToExpression, Context context) {
+ equalToExpression.getLeftExpression().accept(this, context);
+ equalToExpression.getRightExpression().accept(this, context);
+ return null;
+ }
+
+ @Override
+ public Void visitNonEqualExpression(NonEqualExpression nonEqualExpression, Context context) {
+ nonEqualExpression.getLeftExpression().accept(this, context);
+ nonEqualExpression.getRightExpression().accept(this, context);
+ return null;
+ }
+
+ @Override
+ public Void visitGreaterThanExpression(
+ GreaterThanExpression greaterThanExpression, Context context) {
+ greaterThanExpression.getLeftExpression().accept(this, context);
+ greaterThanExpression.getRightExpression().accept(this, context);
+ return null;
+ }
+
+ @Override
+ public Void visitGreaterEqualExpression(
+ GreaterEqualExpression greaterEqualExpression, Context context) {
+ greaterEqualExpression.getLeftExpression().accept(this, context);
+ greaterEqualExpression.getRightExpression().accept(this, context);
+ return null;
+ }
+
+ @Override
+ public Void visitLessThanExpression(LessThanExpression lessThanExpression, Context context) {
+ lessThanExpression.getLeftExpression().accept(this, context);
+ lessThanExpression.getRightExpression().accept(this, context);
+ return null;
+ }
+
+ @Override
+ public Void visitLessEqualExpression(LessEqualExpression lessEqualExpression, Context context) {
+ lessEqualExpression.getLeftExpression().accept(this, context);
+ lessEqualExpression.getRightExpression().accept(this, context);
+ return null;
+ }
+
+ @Override
+ public Void visitBetweenExpression(BetweenExpression betweenExpression, Context context) {
+ betweenExpression.getFirstExpression().accept(this, context);
+ betweenExpression.getSecondExpression().accept(this, context);
+ betweenExpression.getThirdExpression().accept(this, context);
+ return null;
+ }
+}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
index 4750d5e60af..431419e71ac 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
@@ -2904,13 +2904,15 @@ public class ASTVisitor extends IoTDBSqlParserBaseVisitor<Statement> {
private Expression parseRegularExpression(ExpressionContext context, boolean canUseFullPath) {
return new RegularExpression(
parseExpression(context.unaryBeforeRegularOrLikeExpression, canUseFullPath),
- parseStringLiteral(context.STRING_LITERAL().getText()));
+ parseStringLiteral(context.STRING_LITERAL().getText()),
+ false);
}
private Expression parseLikeExpression(ExpressionContext context, boolean canUseFullPath) {
return new LikeExpression(
parseExpression(context.unaryBeforeRegularOrLikeExpression, canUseFullPath),
- parseStringLiteral(context.STRING_LITERAL().getText()));
+ parseStringLiteral(context.STRING_LITERAL().getText()),
+ false);
}
private Expression parseIsNullExpression(ExpressionContext context, boolean canUseFullPath) {
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LocalExecutionPlanContext.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LocalExecutionPlanContext.java
index e8c6910d0d0..0978dfe594c 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LocalExecutionPlanContext.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LocalExecutionPlanContext.java
@@ -291,4 +291,8 @@ public class LocalExecutionPlanContext {
public long getDataRegionTTL() {
return dataRegionTTL;
}
+
+ public Filter getGlobalTimeFilter() {
+ return driverContext.getFragmentInstanceContext().getTimeFilter();
+ }
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LogicalPlanBuilder.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LogicalPlanBuilder.java
index 71c57cbca83..39b225be56f 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LogicalPlanBuilder.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LogicalPlanBuilder.java
@@ -100,11 +100,9 @@ import org.apache.iotdb.db.schemaengine.schemaregion.utils.MetaUtils;
import org.apache.iotdb.db.schemaengine.template.Template;
import org.apache.iotdb.db.utils.SchemaUtils;
import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
import org.apache.iotdb.tsfile.utils.Pair;
import org.apache.iotdb.tsfile.write.schema.IMeasurementSchema;
-import com.google.common.base.Function;
import org.apache.commons.lang3.Validate;
import java.time.ZoneId;
@@ -121,6 +119,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
+import java.util.function.Function;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkArgument;
@@ -184,7 +183,6 @@ public class LogicalPlanBuilder {
public LogicalPlanBuilder planRawDataSource(
Set<Expression> sourceExpressions,
Ordering scanOrder,
- Filter timeFilter,
long offset,
long limit,
boolean lastLevelUseWildcard) {
@@ -197,28 +195,22 @@ public class LogicalPlanBuilder {
for (PartialPath path : groupedPaths) {
if (path instanceof MeasurementPath) {
// non-aligned series
- // TODO: push down value filter
SeriesScanNode seriesScanNode =
new SeriesScanNode(
context.getQueryId().genPlanNodeId(),
(MeasurementPath) path,
scanOrder,
- timeFilter,
- timeFilter,
limit,
offset,
null);
sourceNodeList.add(seriesScanNode);
} else if (path instanceof AlignedPath) {
// aligned series
- // TODO: push down value filter
AlignedSeriesScanNode alignedSeriesScanNode =
new AlignedSeriesScanNode(
context.getQueryId().genPlanNodeId(),
(AlignedPath) path,
scanOrder,
- timeFilter,
- timeFilter,
limit,
offset,
null,
@@ -344,7 +336,6 @@ public class LogicalPlanBuilder {
new LastQueryNode(
context.getQueryId().genPlanNodeId(),
sourceNodeList,
- analysis.getGlobalTimeFilter(),
timeseriesOrdering,
analysis.getLastQueryNonWritableViewSourceExpressionMap() != null);
@@ -382,12 +373,7 @@ public class LogicalPlanBuilder {
planBuilder =
planBuilder
.planRawDataSource(
- sourceExpressions,
- Ordering.DESC,
- analysis.getGlobalTimeFilter(),
- 0,
- 0,
- analysis.isLastLevelUseWildcard())
+ sourceExpressions, Ordering.DESC, 0, 0, analysis.isLastLevelUseWildcard())
.planWhereAndSourceTransform(
null, sourceTransformExpressions, false, zoneId, Ordering.DESC)
.planAggregation(
@@ -412,7 +398,6 @@ public class LogicalPlanBuilder {
public LogicalPlanBuilder planAggregationSource(
AggregationStep curStep,
Ordering scanOrder,
- Filter timeFilter,
GroupByTimeParameter groupByTimeParameter,
Set<Expression> aggregationExpressions,
Set<Expression> sourceTransformExpressions,
@@ -441,7 +426,6 @@ public class LogicalPlanBuilder {
descendingAggregations,
countTimeAggregations,
scanOrder,
- timeFilter,
groupByTimeParameter);
updateTypeProvider(aggregationExpressions);
updateTypeProvider(sourceTransformExpressions);
@@ -460,7 +444,6 @@ public class LogicalPlanBuilder {
public LogicalPlanBuilder planAggregationSourceWithIndexAdjust(
AggregationStep curStep,
Ordering scanOrder,
- Filter timeFilter,
GroupByTimeParameter groupByTimeParameter,
Set<Expression> aggregationExpressions,
Set<Expression> sourceTransformExpressions,
@@ -497,7 +480,6 @@ public class LogicalPlanBuilder {
descendingAggregations,
countTimeAggregations,
scanOrder,
- timeFilter,
groupByTimeParameter);
updateTypeProvider(aggregationExpressions);
updateTypeProvider(sourceTransformExpressions);
@@ -596,7 +578,6 @@ public class LogicalPlanBuilder {
Map<PartialPath, List<AggregationDescriptor>> descendingAggregations,
Map<PartialPath, List<AggregationDescriptor>> countTimeAggregations,
Ordering scanOrder,
- Filter timeFilter,
GroupByTimeParameter groupByTimeParameter) {
List<PlanNode> sourceNodeList = new ArrayList<>();
@@ -615,8 +596,7 @@ public class LogicalPlanBuilder {
pathAggregationsEntry.getKey(),
pathAggregationsEntry.getValue(),
scanOrder,
- groupByTimeParameter,
- timeFilter));
+ groupByTimeParameter));
}
if (needCheckAscending) {
@@ -629,8 +609,7 @@ public class LogicalPlanBuilder {
pathAggregationsEntry.getKey(),
pathAggregationsEntry.getValue(),
scanOrder.reverse(),
- null,
- timeFilter));
+ null));
}
}
return sourceNodeList;
@@ -1097,32 +1076,21 @@ public class LogicalPlanBuilder {
PartialPath selectPath,
List<AggregationDescriptor> aggregationDescriptorList,
Ordering scanOrder,
- GroupByTimeParameter groupByTimeParameter,
- Filter timeFilter) {
+ GroupByTimeParameter groupByTimeParameter) {
if (selectPath instanceof MeasurementPath) { // non-aligned series
- SeriesAggregationScanNode seriesAggregationScanNode =
- new SeriesAggregationScanNode(
- context.getQueryId().genPlanNodeId(),
- (MeasurementPath) selectPath,
- aggregationDescriptorList,
- scanOrder,
- groupByTimeParameter);
- seriesAggregationScanNode.setTimeFilter(timeFilter);
- // TODO: push down value filter
- seriesAggregationScanNode.setValueFilter(timeFilter);
- return seriesAggregationScanNode;
+ return new SeriesAggregationScanNode(
+ context.getQueryId().genPlanNodeId(),
+ (MeasurementPath) selectPath,
+ aggregationDescriptorList,
+ scanOrder,
+ groupByTimeParameter);
} else if (selectPath instanceof AlignedPath) { // aligned series
- AlignedSeriesAggregationScanNode alignedSeriesAggregationScanNode =
- new AlignedSeriesAggregationScanNode(
- context.getQueryId().genPlanNodeId(),
- (AlignedPath) selectPath,
- aggregationDescriptorList,
- scanOrder,
- groupByTimeParameter);
- alignedSeriesAggregationScanNode.setTimeFilter(timeFilter);
- // TODO: push down value filter
- alignedSeriesAggregationScanNode.setValueFilter(timeFilter);
- return alignedSeriesAggregationScanNode;
+ return new AlignedSeriesAggregationScanNode(
+ context.getQueryId().genPlanNodeId(),
+ (AlignedPath) selectPath,
+ aggregationDescriptorList,
+ scanOrder,
+ groupByTimeParameter);
} else {
throw new IllegalArgumentException("unexpected path type");
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LogicalPlanVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LogicalPlanVisitor.java
index a8bf4d38fec..3fb8d8272d9 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LogicalPlanVisitor.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LogicalPlanVisitor.java
@@ -248,7 +248,6 @@ public class LogicalPlanVisitor extends StatementVisitor<PlanNode, MPPQueryConte
.planRawDataSource(
sourceExpressions,
queryStatement.getResultTimeOrder(),
- analysis.getGlobalTimeFilter(),
0,
pushDownLimitToScanNode(queryStatement),
analysis.isLastLevelUseWildcard())
@@ -272,7 +271,6 @@ public class LogicalPlanVisitor extends StatementVisitor<PlanNode, MPPQueryConte
.planRawDataSource(
sourceExpressions,
queryStatement.getResultTimeOrder(),
- analysis.getGlobalTimeFilter(),
0,
0,
analysis.isLastLevelUseWildcard())
@@ -331,7 +329,6 @@ public class LogicalPlanVisitor extends StatementVisitor<PlanNode, MPPQueryConte
? planBuilder.planAggregationSource(
curStep,
queryStatement.getResultTimeOrder(),
- analysis.getGlobalTimeFilter(),
analysis.getGroupByTimeParameter(),
aggregationExpressions,
sourceTransformExpressions,
@@ -341,7 +338,6 @@ public class LogicalPlanVisitor extends StatementVisitor<PlanNode, MPPQueryConte
: planBuilder.planAggregationSourceWithIndexAdjust(
curStep,
queryStatement.getResultTimeOrder(),
- analysis.getGlobalTimeFilter(),
analysis.getGroupByTimeParameter(),
aggregationExpressions,
sourceTransformExpressions,
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/OperatorTreeGenerator.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/OperatorTreeGenerator.java
index 0f99f170725..a23cc3d6d30 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/OperatorTreeGenerator.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/OperatorTreeGenerator.java
@@ -139,6 +139,7 @@ import org.apache.iotdb.db.queryengine.plan.expression.Expression;
import org.apache.iotdb.db.queryengine.plan.expression.leaf.TimeSeriesOperand;
import org.apache.iotdb.db.queryengine.plan.expression.leaf.TimestampOperand;
import org.apache.iotdb.db.queryengine.plan.expression.visitor.ColumnTransformerVisitor;
+import org.apache.iotdb.db.queryengine.plan.expression.visitor.predicate.ConvertExpressionToFilterVisitor;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNode;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanVisitor;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.metedata.read.CountSchemaMergeNode;
@@ -218,8 +219,8 @@ import org.apache.iotdb.tsfile.enums.TSDataType;
import org.apache.iotdb.tsfile.read.TimeValuePair;
import org.apache.iotdb.tsfile.read.common.block.TsBlockBuilder;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.operator.Gt;
-import org.apache.iotdb.tsfile.read.filter.operator.GtEq;
+import org.apache.iotdb.tsfile.read.filter.operator.TimeFilterOperators.TimeGt;
+import org.apache.iotdb.tsfile.read.filter.operator.TimeFilterOperators.TimeGtEq;
import org.apache.iotdb.tsfile.utils.Binary;
import org.apache.iotdb.tsfile.utils.Pair;
@@ -282,14 +283,17 @@ public class OperatorTreeGenerator extends PlanVisitor<Operator, LocalExecutionP
public Operator visitSeriesScan(SeriesScanNode node, LocalExecutionPlanContext context) {
SeriesScanOptions.Builder seriesScanOptionsBuilder = new SeriesScanOptions.Builder();
- Filter timeFilter = node.getTimeFilter();
- Filter valueFilter = node.getValueFilter();
- if (timeFilter != null) {
- seriesScanOptionsBuilder.withGlobalTimeFilter(timeFilter.copy());
- }
- if (valueFilter != null) {
- seriesScanOptionsBuilder.withQueryFilter(valueFilter.copy());
+ Filter globalTimeFilter = context.getGlobalTimeFilter();
+ seriesScanOptionsBuilder.withGlobalTimeFilter(globalTimeFilter);
+
+ Filter pushDownFilter = null;
+ Expression pushDownPredicate = node.getPushDownPredicate();
+ if (pushDownPredicate != null) {
+ pushDownFilter =
+ node.getPushDownPredicate()
+ .accept(new ConvertExpressionToFilterVisitor(), context.getTypeProvider());
}
+ seriesScanOptionsBuilder.withQueryFilter(pushDownFilter);
PartialPath seriesPath = node.getSeriesPath();
seriesScanOptionsBuilder.withAllSensors(
@@ -323,14 +327,19 @@ public class OperatorTreeGenerator extends PlanVisitor<Operator, LocalExecutionP
public Operator visitAlignedSeriesScan(
AlignedSeriesScanNode node, LocalExecutionPlanContext context) {
SeriesScanOptions.Builder seriesScanOptionsBuilder = new SeriesScanOptions.Builder();
- Filter timeFilter = node.getTimeFilter();
- Filter valueFilter = node.getValueFilter();
- if (timeFilter != null) {
- seriesScanOptionsBuilder.withGlobalTimeFilter(timeFilter.copy());
- }
- if (valueFilter != null) {
- seriesScanOptionsBuilder.withQueryFilter(valueFilter.copy());
+
+ Filter globalTimeFilter = context.getGlobalTimeFilter();
+ seriesScanOptionsBuilder.withGlobalTimeFilter(globalTimeFilter);
+
+ Filter pushDownFilter = null;
+ Expression pushDownPredicate = node.getPushDownPredicate();
+ if (pushDownPredicate != null) {
+ pushDownFilter =
+ node.getPushDownPredicate()
+ .accept(new ConvertExpressionToFilterVisitor(), context.getTypeProvider());
}
+ seriesScanOptionsBuilder.withQueryFilter(pushDownFilter);
+
seriesScanOptionsBuilder.withLimit(node.getLimit());
seriesScanOptionsBuilder.withOffset(node.getOffset());
AlignedPath seriesPath = node.getAlignedPath();
@@ -387,17 +396,21 @@ public class OperatorTreeGenerator extends PlanVisitor<Operator, LocalExecutionP
AggregationUtil.calculateMaxAggregationResultSize(
node.getAggregationDescriptorList(), timeRangeIterator, context.getTypeProvider());
- Filter timeFilter = node.getTimeFilter();
- Filter valueFilter = node.getValueFilter();
SeriesScanOptions.Builder scanOptionsBuilder = new SeriesScanOptions.Builder();
+ Filter globalTimeFilter = context.getGlobalTimeFilter();
+ scanOptionsBuilder.withGlobalTimeFilter(globalTimeFilter);
+
+ Filter pushDownFilter = null;
+ Expression pushDownPredicate = node.getPushDownPredicate();
+ if (pushDownPredicate != null) {
+ pushDownFilter =
+ node.getPushDownPredicate()
+ .accept(new ConvertExpressionToFilterVisitor(), context.getTypeProvider());
+ }
+ scanOptionsBuilder.withQueryFilter(pushDownFilter);
+
scanOptionsBuilder.withAllSensors(
context.getAllSensors(seriesPath.getDevice(), seriesPath.getMeasurement()));
- if (timeFilter != null) {
- scanOptionsBuilder.withGlobalTimeFilter(timeFilter.copy());
- }
- if (valueFilter != null) {
- scanOptionsBuilder.withQueryFilter(valueFilter.copy());
- }
OperatorContext operatorContext =
context
@@ -480,16 +493,20 @@ public class OperatorTreeGenerator extends PlanVisitor<Operator, LocalExecutionP
AggregationUtil.calculateMaxAggregationResultSize(
node.getAggregationDescriptorList(), timeRangeIterator, context.getTypeProvider());
- Filter timeFilter = node.getTimeFilter();
- Filter valueFilter = node.getValueFilter();
SeriesScanOptions.Builder scanOptionsBuilder = new SeriesScanOptions.Builder();
- scanOptionsBuilder.withAllSensors(new HashSet<>(seriesPath.getMeasurementList()));
- if (timeFilter != null) {
- scanOptionsBuilder.withGlobalTimeFilter(timeFilter.copy());
- }
- if (valueFilter != null) {
- scanOptionsBuilder.withQueryFilter(valueFilter.copy());
+ Filter globalTimeFilter = context.getGlobalTimeFilter();
+ scanOptionsBuilder.withGlobalTimeFilter(globalTimeFilter);
+
+ Filter pushDownFilter = null;
+ Expression pushDownPredicate = node.getPushDownPredicate();
+ if (pushDownPredicate != null) {
+ pushDownFilter =
+ node.getPushDownPredicate()
+ .accept(new ConvertExpressionToFilterVisitor(), context.getTypeProvider());
}
+ scanOptionsBuilder.withQueryFilter(pushDownFilter);
+
+ scanOptionsBuilder.withAllSensors(new HashSet<>(seriesPath.getMeasurementList()));
OperatorContext operatorContext =
context
@@ -2093,11 +2110,8 @@ public class OperatorTreeGenerator extends PlanVisitor<Operator, LocalExecutionP
updateFilterUsingTTL(context.getLastQueryTimeFilter(), context.getDataRegionTTL()),
timeValuePair)) { // cached last value is not satisfied
- boolean isFilterGtOrGe =
- (context.getLastQueryTimeFilter() instanceof Gt
- || context.getLastQueryTimeFilter() instanceof GtEq);
- // time filter is not > or >=, we still need to read from disk
- if (!isFilterGtOrGe) {
+ if (!isFilterGtOrGe(context.getLastQueryTimeFilter())) {
+ // time filter is not > or >=, we still need to read from disk
return createUpdateLastCacheOperator(node, context, node.getSeriesPath());
} else { // otherwise, we just ignore it and return null
return null;
@@ -2108,6 +2122,10 @@ public class OperatorTreeGenerator extends PlanVisitor<Operator, LocalExecutionP
}
}
+ private boolean isFilterGtOrGe(Filter filter) {
+ return filter instanceof TimeGt || filter instanceof TimeGtEq;
+ }
+
private UpdateLastCacheOperator createUpdateLastCacheOperator(
LastQueryScanNode node, LocalExecutionPlanContext context, MeasurementPath fullPath) {
SeriesAggregationScanOperator lastQueryScan = createLastQueryScanOperator(node, context);
@@ -2244,7 +2262,7 @@ public class OperatorTreeGenerator extends PlanVisitor<Operator, LocalExecutionP
SeriesScanOptions.Builder scanOptionsBuilder = new SeriesScanOptions.Builder();
scanOptionsBuilder.withAllSensors(new HashSet<>(unCachedPath.getMeasurementList()));
if (timeFilter != null) {
- scanOptionsBuilder.withGlobalTimeFilter(timeFilter.copy());
+ scanOptionsBuilder.withGlobalTimeFilter(timeFilter);
}
OperatorContext operatorContext =
@@ -2304,11 +2322,8 @@ public class OperatorTreeGenerator extends PlanVisitor<Operator, LocalExecutionP
updateFilterUsingTTL(context.getLastQueryTimeFilter(), context.getDataRegionTTL()),
timeValuePair)) { // cached last value is not satisfied
- boolean isFilterGtOrGe =
- (context.getLastQueryTimeFilter() instanceof Gt
- || context.getLastQueryTimeFilter() instanceof GtEq);
- // time filter is not > or >=, we still need to read from disk
- if (!isFilterGtOrGe) {
+ if (!isFilterGtOrGe(context.getGlobalTimeFilter())) {
+ // time filter is not > or >=, we still need to read from disk
unCachedMeasurementIndexes.add(i);
}
} else { // cached last value is satisfied, put it into LastCacheScanOperator
@@ -2332,9 +2347,10 @@ public class OperatorTreeGenerator extends PlanVisitor<Operator, LocalExecutionP
@Override
public Operator visitLastQuery(LastQueryNode node, LocalExecutionPlanContext context) {
- context.setLastQueryTimeFilter(node.getTimeFilter());
- context.setNeedUpdateLastCache(LastQueryUtil.needUpdateCache(node.getTimeFilter()));
- context.setNeedUpdateNullEntry(LastQueryUtil.needUpdateNullEntry(node.getTimeFilter()));
+ Filter globalTimeFilter = context.getGlobalTimeFilter();
+ context.setLastQueryTimeFilter(globalTimeFilter);
+ context.setNeedUpdateLastCache(LastQueryUtil.needUpdateCache(globalTimeFilter));
+ context.setNeedUpdateNullEntry(LastQueryUtil.needUpdateNullEntry(globalTimeFilter));
List<Operator> operatorList =
node.getChildren().stream()
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/DistributionPlanContext.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/DistributionPlanContext.java
index 7c1e963d526..c7dc11b8f9f 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/DistributionPlanContext.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/DistributionPlanContext.java
@@ -21,6 +21,7 @@ package org.apache.iotdb.db.queryengine.plan.planner.distribution;
import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
import org.apache.iotdb.db.queryengine.plan.expression.Expression;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
import java.util.Map;
@@ -79,4 +80,8 @@ public class DistributionPlanContext {
public void setColumnNameToExpression(Map<String, Expression> columnNameToExpression) {
this.columnNameToExpression = columnNameToExpression;
}
+
+ public Filter getPartitionTimeFilter() {
+ return queryContext.getGlobalTimeFilter();
+ }
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/SimpleFragmentParallelPlanner.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/SimpleFragmentParallelPlanner.java
index ff24932bca6..b3ba0bf1475 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/SimpleFragmentParallelPlanner.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/SimpleFragmentParallelPlanner.java
@@ -28,6 +28,7 @@ import org.apache.iotdb.db.queryengine.common.DataNodeEndPoints;
import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
import org.apache.iotdb.db.queryengine.common.PlanFragmentId;
import org.apache.iotdb.db.queryengine.plan.analyze.Analysis;
+import org.apache.iotdb.db.queryengine.plan.expression.Expression;
import org.apache.iotdb.db.queryengine.plan.planner.IFragmentParallelPlaner;
import org.apache.iotdb.db.queryengine.plan.planner.plan.FragmentInstance;
import org.apache.iotdb.db.queryengine.plan.planner.plan.PlanFragment;
@@ -41,7 +42,6 @@ import org.apache.iotdb.db.queryengine.plan.statement.crud.QueryStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowTimeSeriesStatement;
import org.apache.iotdb.db.queryengine.plan.statement.sys.ShowQueriesStatement;
import org.apache.iotdb.tsfile.read.common.Path;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
import org.apache.iotdb.tsfile.utils.Pair;
import org.slf4j.Logger;
@@ -135,7 +135,7 @@ public class SimpleFragmentParallelPlanner implements IFragmentParallelPlaner {
}
private void produceFragmentInstance(PlanFragment fragment) {
- Filter timeFilter = analysis.getGlobalTimeFilter();
+ Expression timeFilter = analysis.getGlobalTimeFilter();
FragmentInstance fragmentInstance =
new FragmentInstance(
fragment,
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/SourceRewriter.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/SourceRewriter.java
index 02e160864dd..8bd1903439d 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/SourceRewriter.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/SourceRewriter.java
@@ -121,7 +121,7 @@ public class SourceRewriter extends SimplePlanNodeRewriter<DistributionPlanConte
String device = node.getDevice();
List<TRegionReplicaSet> regionReplicaSets =
- analysis.getPartitionInfo(device, analysis.getGlobalTimeFilter());
+ analysis.getPartitionInfo(device, context.getPartitionTimeFilter());
List<PlanNode> singleDeviceViewList = new ArrayList<>();
for (TRegionReplicaSet tRegionReplicaSet : regionReplicaSets) {
@@ -171,7 +171,7 @@ public class SourceRewriter extends SimplePlanNodeRewriter<DistributionPlanConte
List<TRegionReplicaSet> regionReplicaSets = new ArrayList<>();
for (String queriedDevice : outputDeviceToQueriedDevicesMap.get(outputDevice)) {
regionReplicaSets.addAll(
- analysis.getPartitionInfo(queriedDevice, analysis.getGlobalTimeFilter()));
+ analysis.getPartitionInfo(queriedDevice, context.getPartitionTimeFilter()));
}
deviceViewSplits.add(new DeviceViewSplit(outputDevice, child, regionReplicaSets));
relatedDataRegions.addAll(regionReplicaSets);
@@ -475,11 +475,7 @@ public class SourceRewriter extends SimplePlanNodeRewriter<DistributionPlanConte
public List<PlanNode> visitLastQueryScan(
LastQueryScanNode node, DistributionPlanContext context) {
LastQueryNode mergeNode =
- new LastQueryNode(
- context.queryContext.getQueryId().genPlanNodeId(),
- node.getPartitionTimeFilter(),
- null,
- false);
+ new LastQueryNode(context.queryContext.getQueryId().genPlanNodeId(), null, false);
return processRawSeriesScan(node, context, mergeNode);
}
@@ -487,11 +483,7 @@ public class SourceRewriter extends SimplePlanNodeRewriter<DistributionPlanConte
public List<PlanNode> visitAlignedLastQueryScan(
AlignedLastQueryScanNode node, DistributionPlanContext context) {
LastQueryNode mergeNode =
- new LastQueryNode(
- context.queryContext.getQueryId().genPlanNodeId(),
- node.getPartitionTimeFilter(),
- null,
- false);
+ new LastQueryNode(context.queryContext.getQueryId().genPlanNodeId(), null, false);
return processRawSeriesScan(node, context, mergeNode);
}
@@ -509,7 +501,7 @@ public class SourceRewriter extends SimplePlanNodeRewriter<DistributionPlanConte
SeriesSourceNode node, DistributionPlanContext context) {
List<PlanNode> ret = new ArrayList<>();
List<TRegionReplicaSet> dataDistribution =
- analysis.getPartitionInfo(node.getPartitionPath(), node.getPartitionTimeFilter());
+ analysis.getPartitionInfo(node.getPartitionPath(), context.getPartitionTimeFilter());
if (dataDistribution.size() == 1) {
node.setRegionReplicaSet(dataDistribution.get(0));
ret.add(node);
@@ -540,7 +532,7 @@ public class SourceRewriter extends SimplePlanNodeRewriter<DistributionPlanConte
private List<PlanNode> processSeriesAggregationSource(
SeriesAggregationSourceNode node, DistributionPlanContext context) {
List<TRegionReplicaSet> dataDistribution =
- analysis.getPartitionInfo(node.getPartitionPath(), node.getPartitionTimeFilter());
+ analysis.getPartitionInfo(node.getPartitionPath(), context.getPartitionTimeFilter());
if (dataDistribution.size() == 1) {
node.setRegionReplicaSet(dataDistribution.get(0));
return Collections.singletonList(node);
@@ -763,7 +755,7 @@ public class SourceRewriter extends SimplePlanNodeRewriter<DistributionPlanConte
SeriesSourceNode sourceNode = (SeriesSourceNode) child;
List<TRegionReplicaSet> dataDistribution =
analysis.getPartitionInfo(
- sourceNode.getPartitionPath(), sourceNode.getPartitionTimeFilter());
+ sourceNode.getPartitionPath(), context.getPartitionTimeFilter());
if (dataDistribution.size() > 1) {
// If there is some series which is distributed in multi DataRegions
context.setOneSeriesInMultiRegion(true);
@@ -1274,7 +1266,7 @@ public class SourceRewriter extends SimplePlanNodeRewriter<DistributionPlanConte
List<SeriesAggregationSourceNode> sources,
SeriesAggregationSourceNode child) {
List<TRegionReplicaSet> dataDistribution =
- analysis.getPartitionInfo(child.getPartitionPath(), child.getPartitionTimeFilter());
+ analysis.getPartitionInfo(child.getPartitionPath(), context.getPartitionTimeFilter());
for (TRegionReplicaSet dataRegion : dataDistribution) {
SeriesAggregationSourceNode split = (SeriesAggregationSourceNode) child.clone();
split.setPlanNodeId(context.queryContext.getQueryId().genPlanNodeId());
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/WriteFragmentParallelPlanner.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/WriteFragmentParallelPlanner.java
index 222e3eda395..141ce3ccfd0 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/WriteFragmentParallelPlanner.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/WriteFragmentParallelPlanner.java
@@ -22,13 +22,13 @@ package org.apache.iotdb.db.queryengine.plan.planner.distribution;
import org.apache.iotdb.commons.partition.StorageExecutor;
import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
import org.apache.iotdb.db.queryengine.plan.analyze.Analysis;
+import org.apache.iotdb.db.queryengine.plan.expression.Expression;
import org.apache.iotdb.db.queryengine.plan.planner.IFragmentParallelPlaner;
import org.apache.iotdb.db.queryengine.plan.planner.plan.FragmentInstance;
import org.apache.iotdb.db.queryengine.plan.planner.plan.PlanFragment;
import org.apache.iotdb.db.queryengine.plan.planner.plan.SubPlan;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNode;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.WritePlanNode;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
import java.util.ArrayList;
import java.util.List;
@@ -49,7 +49,7 @@ public class WriteFragmentParallelPlanner implements IFragmentParallelPlaner {
@Override
public List<FragmentInstance> parallelPlan() {
PlanFragment fragment = subPlan.getPlanFragment();
- Filter timeFilter = analysis.getGlobalTimeFilter();
+ Expression timeFilter = analysis.getGlobalTimeFilter();
PlanNode node = fragment.getPlanNodeTree();
if (!(node instanceof WritePlanNode)) {
throw new IllegalArgumentException("PlanNode should be IWritePlanNode in WRITE operation");
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/FragmentInstance.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/FragmentInstance.java
index fcef7b54a5e..00fc2978a50 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/FragmentInstance.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/FragmentInstance.java
@@ -31,9 +31,8 @@ import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.queryengine.common.FragmentInstanceId;
import org.apache.iotdb.db.queryengine.common.SessionInfo;
import org.apache.iotdb.db.queryengine.plan.analyze.QueryType;
+import org.apache.iotdb.db.queryengine.plan.expression.Expression;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeUtil;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
import org.apache.iotdb.tsfile.utils.PublicBAOS;
import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
@@ -61,7 +60,7 @@ public class FragmentInstance implements IConsensusRequest {
private TDataNodeLocation hostDataNode;
- private Filter timeFilter;
+ private final Expression timeFilter;
private final long timeOut;
@@ -83,7 +82,7 @@ public class FragmentInstance implements IConsensusRequest {
public FragmentInstance(
PlanFragment fragment,
FragmentInstanceId id,
- Filter timeFilter,
+ Expression timeFilter,
QueryType type,
long timeOut,
SessionInfo sessionInfo) {
@@ -99,7 +98,7 @@ public class FragmentInstance implements IConsensusRequest {
public FragmentInstance(
PlanFragment fragment,
FragmentInstanceId id,
- Filter timeFilter,
+ Expression timeFilter,
QueryType type,
long timeOut,
SessionInfo sessionInfo,
@@ -111,7 +110,7 @@ public class FragmentInstance implements IConsensusRequest {
public FragmentInstance(
PlanFragment fragment,
FragmentInstanceId id,
- Filter timeFilter,
+ Expression timeFilter,
QueryType type,
long timeOut,
SessionInfo sessionInfo,
@@ -167,11 +166,7 @@ public class FragmentInstance implements IConsensusRequest {
isHighestPriority = highestPriority;
}
- public void setTimeFilter(Filter timeFilter) {
- this.timeFilter = timeFilter;
- }
-
- public Filter getTimeFilter() {
+ public Expression getTimeFilter() {
return timeFilter;
}
@@ -213,7 +208,7 @@ public class FragmentInstance implements IConsensusRequest {
boolean hasSessionInfo = ReadWriteIOUtils.readBool(buffer);
SessionInfo sessionInfo = hasSessionInfo ? SessionInfo.deserializeFrom(buffer) : null;
boolean hasTimeFilter = ReadWriteIOUtils.readBool(buffer);
- Filter timeFilter = hasTimeFilter ? FilterFactory.deserialize(buffer) : null;
+ Expression timeFilter = hasTimeFilter ? Expression.deserialize(buffer) : null;
QueryType queryType = QueryType.values()[ReadWriteIOUtils.readInt(buffer)];
int dataNodeFINum = ReadWriteIOUtils.readInt(buffer);
FragmentInstance fragmentInstance =
@@ -237,7 +232,7 @@ public class FragmentInstance implements IConsensusRequest {
}
ReadWriteIOUtils.write(timeFilter != null, outputStream);
if (timeFilter != null) {
- timeFilter.serialize(outputStream);
+ Expression.serialize(timeFilter, outputStream);
}
ReadWriteIOUtils.write(type.ordinal(), outputStream);
ReadWriteIOUtils.write(dataNodeFINum, outputStream);
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/PlanGraphPrinter.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/PlanGraphPrinter.java
index 5ff7ffef463..9692e0878a3 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/PlanGraphPrinter.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/PlanGraphPrinter.java
@@ -98,7 +98,6 @@ public class PlanGraphPrinter extends PlanVisitor<List<String>, PlanGraphPrinter
List<String> boxValue = new ArrayList<>();
boxValue.add(String.format("SeriesScan-%s", node.getPlanNodeId().getId()));
boxValue.add(String.format("Series: %s", node.getSeriesPath()));
- boxValue.add(String.format("TimeFilter: %s", node.getTimeFilter()));
long limit = node.getLimit(), offset = node.getOffset();
if (limit > 0) {
@@ -119,7 +118,6 @@ public class PlanGraphPrinter extends PlanVisitor<List<String>, PlanGraphPrinter
String.format(
"Series: %s%s",
node.getAlignedPath().getDevice(), node.getAlignedPath().getMeasurementList()));
- boxValue.add(String.format("TimeFilter: %s", node.getTimeFilter()));
long limit = node.getLimit(), offset = node.getOffset();
if (limit > 0) {
@@ -423,7 +421,6 @@ public class PlanGraphPrinter extends PlanVisitor<List<String>, PlanGraphPrinter
public List<String> visitLastQuery(LastQueryNode node, GraphContext context) {
List<String> boxValue = new ArrayList<>();
boxValue.add(String.format("LastQuery-%s", node.getPlanNodeId().getId()));
- boxValue.add(String.format("TimeFilter: %s", node.getTimeFilter()));
return render(node, boxValue, context);
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/process/last/LastQueryNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/process/last/LastQueryNode.java
index 0d6ade61aad..254d27d4e76 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/process/last/LastQueryNode.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/process/last/LastQueryNode.java
@@ -24,8 +24,6 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeType;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanVisitor;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.process.MultiChildProcessNode;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
import javax.annotation.Nullable;
@@ -40,8 +38,6 @@ import static org.apache.iotdb.db.queryengine.plan.planner.plan.node.source.Last
public class LastQueryNode extends MultiChildProcessNode {
- private final Filter timeFilter;
-
// the ordering of timeseries in the result of last query
// which is set to null if there is no need to sort
private Ordering timeseriesOrdering;
@@ -50,12 +46,8 @@ public class LastQueryNode extends MultiChildProcessNode {
private boolean containsLastTransformNode;
public LastQueryNode(
- PlanNodeId id,
- Filter timeFilter,
- @Nullable Ordering timeseriesOrdering,
- boolean containsLastTransformNode) {
+ PlanNodeId id, @Nullable Ordering timeseriesOrdering, boolean containsLastTransformNode) {
super(id);
- this.timeFilter = timeFilter;
this.timeseriesOrdering = timeseriesOrdering;
this.containsLastTransformNode = containsLastTransformNode;
}
@@ -63,11 +55,9 @@ public class LastQueryNode extends MultiChildProcessNode {
public LastQueryNode(
PlanNodeId id,
List<PlanNode> children,
- Filter timeFilter,
@Nullable Ordering timeseriesOrdering,
boolean containsLastTransformNode) {
super(id, children);
- this.timeFilter = timeFilter;
this.timeseriesOrdering = timeseriesOrdering;
this.containsLastTransformNode = containsLastTransformNode;
}
@@ -84,8 +74,7 @@ public class LastQueryNode extends MultiChildProcessNode {
@Override
public PlanNode clone() {
- return new LastQueryNode(
- getPlanNodeId(), timeFilter, timeseriesOrdering, containsLastTransformNode);
+ return new LastQueryNode(getPlanNodeId(), timeseriesOrdering, containsLastTransformNode);
}
@Override
@@ -100,7 +89,7 @@ public class LastQueryNode extends MultiChildProcessNode {
@Override
public String toString() {
- return String.format("LastQueryNode-%s:[TimeFilter: %s]", this.getPlanNodeId(), timeFilter);
+ return String.format("LastQueryNode-%s", this.getPlanNodeId());
}
@Override
@@ -115,13 +104,12 @@ public class LastQueryNode extends MultiChildProcessNode {
return false;
}
LastQueryNode that = (LastQueryNode) o;
- return Objects.equals(timeFilter, that.timeFilter)
- && timeseriesOrdering.equals(that.timeseriesOrdering);
+ return timeseriesOrdering.equals(that.timeseriesOrdering);
}
@Override
public int hashCode() {
- return Objects.hash(super.hashCode(), timeFilter, timeseriesOrdering);
+ return Objects.hash(super.hashCode(), timeseriesOrdering);
}
@Override
@@ -132,12 +120,6 @@ public class LastQueryNode extends MultiChildProcessNode {
@Override
protected void serializeAttributes(ByteBuffer byteBuffer) {
PlanNodeType.LAST_QUERY.serialize(byteBuffer);
- if (timeFilter == null) {
- ReadWriteIOUtils.write((byte) 0, byteBuffer);
- } else {
- ReadWriteIOUtils.write((byte) 1, byteBuffer);
- timeFilter.serialize(byteBuffer);
- }
if (timeseriesOrdering == null) {
ReadWriteIOUtils.write((byte) 0, byteBuffer);
} else {
@@ -149,12 +131,6 @@ public class LastQueryNode extends MultiChildProcessNode {
@Override
protected void serializeAttributes(DataOutputStream stream) throws IOException {
PlanNodeType.LAST_QUERY.serialize(stream);
- if (timeFilter == null) {
- ReadWriteIOUtils.write((byte) 0, stream);
- } else {
- ReadWriteIOUtils.write((byte) 1, stream);
- timeFilter.serialize(stream);
- }
if (timeseriesOrdering == null) {
ReadWriteIOUtils.write((byte) 0, stream);
} else {
@@ -164,17 +140,13 @@ public class LastQueryNode extends MultiChildProcessNode {
}
public static LastQueryNode deserialize(ByteBuffer byteBuffer) {
- Filter timeFilter = null;
- if (ReadWriteIOUtils.readByte(byteBuffer) == 1) {
- timeFilter = FilterFactory.deserialize(byteBuffer);
- }
byte needOrderByTimeseries = ReadWriteIOUtils.readByte(byteBuffer);
Ordering timeseriesOrdering = null;
if (needOrderByTimeseries == 1) {
timeseriesOrdering = Ordering.values()[ReadWriteIOUtils.readInt(byteBuffer)];
}
PlanNodeId planNodeId = PlanNodeId.deserialize(byteBuffer);
- return new LastQueryNode(planNodeId, timeFilter, timeseriesOrdering, false);
+ return new LastQueryNode(planNodeId, timeseriesOrdering, false);
}
@Override
@@ -182,11 +154,6 @@ public class LastQueryNode extends MultiChildProcessNode {
this.children = children;
}
- @Nullable
- public Filter getTimeFilter() {
- return timeFilter;
- }
-
public Ordering getTimeseriesOrdering() {
return timeseriesOrdering;
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/AlignedLastQueryScanNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/AlignedLastQueryScanNode.java
index d4c1c3e5396..496fe275941 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/AlignedLastQueryScanNode.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/AlignedLastQueryScanNode.java
@@ -28,7 +28,6 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeType;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeUtil;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanVisitor;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
import com.google.common.collect.ImmutableList;
@@ -225,9 +224,4 @@ public class AlignedLastQueryScanNode extends LastSeriesSourceNode {
public PartialPath getPartitionPath() {
return seriesPath;
}
-
- @Override
- public Filter getPartitionTimeFilter() {
- return null;
- }
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/AlignedSeriesAggregationScanNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/AlignedSeriesAggregationScanNode.java
index 39f47414c8b..18cbb6c2ef0 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/AlignedSeriesAggregationScanNode.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/AlignedSeriesAggregationScanNode.java
@@ -23,6 +23,7 @@ import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
import org.apache.iotdb.commons.path.AlignedPath;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.path.PathDeserializeUtil;
+import org.apache.iotdb.db.queryengine.plan.expression.Expression;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNode;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeType;
@@ -32,8 +33,6 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.node.process.Aggregatio
import org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.AggregationDescriptor;
import org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.GroupByTimeParameter;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
import com.google.common.collect.ImmutableList;
@@ -82,13 +81,11 @@ public class AlignedSeriesAggregationScanNode extends SeriesAggregationSourceNod
AlignedPath alignedPath,
List<AggregationDescriptor> aggregationDescriptorList,
Ordering scanOrder,
- @Nullable Filter timeFilter,
- @Nullable Filter valueFilter,
+ @Nullable Expression valueFilter,
@Nullable GroupByTimeParameter groupByTimeParameter,
TRegionReplicaSet dataRegionReplicaSet) {
this(id, alignedPath, aggregationDescriptorList, scanOrder, groupByTimeParameter);
- this.timeFilter = timeFilter;
- this.valueFilter = valueFilter;
+ this.pushDownPredicate = valueFilter;
this.regionReplicaSet = dataRegionReplicaSet;
}
@@ -144,8 +141,7 @@ public class AlignedSeriesAggregationScanNode extends SeriesAggregationSourceNod
getAlignedPath(),
getAggregationDescriptorList(),
getScanOrder(),
- getTimeFilter(),
- getValueFilter(),
+ getPushDownPredicate(),
getGroupByTimeParameter(),
getRegionReplicaSet());
}
@@ -172,17 +168,11 @@ public class AlignedSeriesAggregationScanNode extends SeriesAggregationSourceNod
aggregationDescriptor.serialize(byteBuffer);
}
ReadWriteIOUtils.write(scanOrder.ordinal(), byteBuffer);
- if (timeFilter == null) {
+ if (pushDownPredicate == null) {
ReadWriteIOUtils.write((byte) 0, byteBuffer);
} else {
ReadWriteIOUtils.write((byte) 1, byteBuffer);
- timeFilter.serialize(byteBuffer);
- }
- if (valueFilter == null) {
- ReadWriteIOUtils.write((byte) 0, byteBuffer);
- } else {
- ReadWriteIOUtils.write((byte) 1, byteBuffer);
- valueFilter.serialize(byteBuffer);
+ Expression.serialize(pushDownPredicate, byteBuffer);
}
if (groupByTimeParameter == null) {
ReadWriteIOUtils.write((byte) 0, byteBuffer);
@@ -201,17 +191,11 @@ public class AlignedSeriesAggregationScanNode extends SeriesAggregationSourceNod
aggregationDescriptor.serialize(stream);
}
ReadWriteIOUtils.write(scanOrder.ordinal(), stream);
- if (timeFilter == null) {
- ReadWriteIOUtils.write((byte) 0, stream);
- } else {
- ReadWriteIOUtils.write((byte) 1, stream);
- timeFilter.serialize(stream);
- }
- if (valueFilter == null) {
+ if (pushDownPredicate == null) {
ReadWriteIOUtils.write((byte) 0, stream);
} else {
ReadWriteIOUtils.write((byte) 1, stream);
- valueFilter.serialize(stream);
+ Expression.serialize(pushDownPredicate, stream);
}
if (groupByTimeParameter == null) {
ReadWriteIOUtils.write((byte) 0, stream);
@@ -230,14 +214,9 @@ public class AlignedSeriesAggregationScanNode extends SeriesAggregationSourceNod
}
Ordering scanOrder = Ordering.values()[ReadWriteIOUtils.readInt(byteBuffer)];
byte isNull = ReadWriteIOUtils.readByte(byteBuffer);
- Filter timeFilter = null;
- if (isNull == 1) {
- timeFilter = FilterFactory.deserialize(byteBuffer);
- }
- isNull = ReadWriteIOUtils.readByte(byteBuffer);
- Filter valueFilter = null;
+ Expression valueFilter = null;
if (isNull == 1) {
- valueFilter = FilterFactory.deserialize(byteBuffer);
+ valueFilter = Expression.deserialize(byteBuffer);
}
isNull = ReadWriteIOUtils.readByte(byteBuffer);
GroupByTimeParameter groupByTimeParameter = null;
@@ -250,7 +229,6 @@ public class AlignedSeriesAggregationScanNode extends SeriesAggregationSourceNod
alignedPath,
aggregationDescriptorList,
scanOrder,
- timeFilter,
valueFilter,
groupByTimeParameter,
null);
@@ -282,11 +260,6 @@ public class AlignedSeriesAggregationScanNode extends SeriesAggregationSourceNod
return alignedPath;
}
- @Override
- public Filter getPartitionTimeFilter() {
- return timeFilter;
- }
-
@Override
public String toString() {
return String.format(
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/AlignedSeriesScanNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/AlignedSeriesScanNode.java
index 638c1c81e3f..b2297eb54e6 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/AlignedSeriesScanNode.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/AlignedSeriesScanNode.java
@@ -23,6 +23,7 @@ import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
import org.apache.iotdb.commons.path.AlignedPath;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.path.PathDeserializeUtil;
+import org.apache.iotdb.db.queryengine.plan.expression.Expression;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNode;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeType;
@@ -30,8 +31,6 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeUtil;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanVisitor;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.tsfile.common.constant.TsFileConstant;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
import com.google.common.collect.ImmutableList;
@@ -55,11 +54,8 @@ public class AlignedSeriesScanNode extends SeriesSourceNode {
// The default order is TIMESTAMP_ASC, which means "order by timestamp asc"
private Ordering scanOrder = Ordering.ASC;
- // time filter for current series, could be null if it doesn't exist
- @Nullable private Filter timeFilter;
-
- // value filter for current series, could be null if it doesn't exist
- @Nullable private Filter valueFilter;
+ // push down predicate for current series, could be null if it doesn't exist
+ @Nullable private Expression pushDownPredicate;
// Limit for result set. The default value is -1, which means no limit
private long limit;
@@ -90,15 +86,27 @@ public class AlignedSeriesScanNode extends SeriesSourceNode {
PlanNodeId id,
AlignedPath alignedPath,
Ordering scanOrder,
- @Nullable Filter timeFilter,
- @Nullable Filter valueFilter,
long limit,
long offset,
TRegionReplicaSet dataRegionReplicaSet,
boolean lastLevelUseWildcard) {
this(id, alignedPath, scanOrder, lastLevelUseWildcard);
- this.timeFilter = timeFilter;
- this.valueFilter = valueFilter;
+ this.limit = limit;
+ this.offset = offset;
+ this.regionReplicaSet = dataRegionReplicaSet;
+ }
+
+ public AlignedSeriesScanNode(
+ PlanNodeId id,
+ AlignedPath alignedPath,
+ Ordering scanOrder,
+ @Nullable Expression pushDownPredicate,
+ long limit,
+ long offset,
+ TRegionReplicaSet dataRegionReplicaSet,
+ boolean lastLevelUseWildcard) {
+ this(id, alignedPath, scanOrder, lastLevelUseWildcard);
+ this.pushDownPredicate = pushDownPredicate;
this.limit = limit;
this.offset = offset;
this.regionReplicaSet = dataRegionReplicaSet;
@@ -113,21 +121,12 @@ public class AlignedSeriesScanNode extends SeriesSourceNode {
}
@Nullable
- public Filter getTimeFilter() {
- return timeFilter;
- }
-
- public void setTimeFilter(@Nullable Filter timeFilter) {
- this.timeFilter = timeFilter;
- }
-
- @Nullable
- public Filter getValueFilter() {
- return valueFilter;
+ public Expression getPushDownPredicate() {
+ return pushDownPredicate;
}
- public void setValueFilter(@Nullable Filter valueFilter) {
- this.valueFilter = valueFilter;
+ public void setPushDownPredicate(@Nullable Expression pushDownPredicate) {
+ this.pushDownPredicate = pushDownPredicate;
}
public long getLimit() {
@@ -191,8 +190,7 @@ public class AlignedSeriesScanNode extends SeriesSourceNode {
getPlanNodeId(),
getAlignedPath(),
getScanOrder(),
- getTimeFilter(),
- getValueFilter(),
+ getPushDownPredicate(),
getLimit(),
getOffset(),
this.regionReplicaSet,
@@ -219,17 +217,11 @@ public class AlignedSeriesScanNode extends SeriesSourceNode {
PlanNodeType.ALIGNED_SERIES_SCAN.serialize(byteBuffer);
alignedPath.serialize(byteBuffer);
ReadWriteIOUtils.write(scanOrder.ordinal(), byteBuffer);
- if (timeFilter == null) {
- ReadWriteIOUtils.write((byte) 0, byteBuffer);
- } else {
- ReadWriteIOUtils.write((byte) 1, byteBuffer);
- timeFilter.serialize(byteBuffer);
- }
- if (valueFilter == null) {
+ if (pushDownPredicate == null) {
ReadWriteIOUtils.write((byte) 0, byteBuffer);
} else {
ReadWriteIOUtils.write((byte) 1, byteBuffer);
- valueFilter.serialize(byteBuffer);
+ Expression.serialize(pushDownPredicate, byteBuffer);
}
ReadWriteIOUtils.write(limit, byteBuffer);
ReadWriteIOUtils.write(offset, byteBuffer);
@@ -241,17 +233,11 @@ public class AlignedSeriesScanNode extends SeriesSourceNode {
PlanNodeType.ALIGNED_SERIES_SCAN.serialize(stream);
alignedPath.serialize(stream);
ReadWriteIOUtils.write(scanOrder.ordinal(), stream);
- if (timeFilter == null) {
+ if (pushDownPredicate == null) {
ReadWriteIOUtils.write((byte) 0, stream);
} else {
ReadWriteIOUtils.write((byte) 1, stream);
- timeFilter.serialize(stream);
- }
- if (valueFilter == null) {
- ReadWriteIOUtils.write((byte) 0, stream);
- } else {
- ReadWriteIOUtils.write((byte) 1, stream);
- valueFilter.serialize(stream);
+ Expression.serialize(pushDownPredicate, stream);
}
ReadWriteIOUtils.write(limit, stream);
ReadWriteIOUtils.write(offset, stream);
@@ -262,29 +248,16 @@ public class AlignedSeriesScanNode extends SeriesSourceNode {
AlignedPath alignedPath = (AlignedPath) PathDeserializeUtil.deserialize(byteBuffer);
Ordering scanOrder = Ordering.values()[ReadWriteIOUtils.readInt(byteBuffer)];
byte isNull = ReadWriteIOUtils.readByte(byteBuffer);
- Filter timeFilter = null;
+ Expression valueFilter = null;
if (isNull == 1) {
- timeFilter = FilterFactory.deserialize(byteBuffer);
- }
- isNull = ReadWriteIOUtils.readByte(byteBuffer);
- Filter valueFilter = null;
- if (isNull == 1) {
- valueFilter = FilterFactory.deserialize(byteBuffer);
+ valueFilter = Expression.deserialize(byteBuffer);
}
long limit = ReadWriteIOUtils.readLong(byteBuffer);
long offset = ReadWriteIOUtils.readLong(byteBuffer);
boolean queryAllSensors = ReadWriteIOUtils.readBool(byteBuffer);
PlanNodeId planNodeId = PlanNodeId.deserialize(byteBuffer);
return new AlignedSeriesScanNode(
- planNodeId,
- alignedPath,
- scanOrder,
- timeFilter,
- valueFilter,
- limit,
- offset,
- null,
- queryAllSensors);
+ planNodeId, alignedPath, scanOrder, valueFilter, limit, offset, null, queryAllSensors);
}
@Override
@@ -303,8 +276,7 @@ public class AlignedSeriesScanNode extends SeriesSourceNode {
&& offset == that.offset
&& alignedPath.equals(that.alignedPath)
&& scanOrder == that.scanOrder
- && Objects.equals(timeFilter, that.timeFilter)
- && Objects.equals(valueFilter, that.valueFilter)
+ && Objects.equals(pushDownPredicate, that.pushDownPredicate)
&& Objects.equals(queryAllSensors, that.queryAllSensors)
&& Objects.equals(regionReplicaSet, that.regionReplicaSet);
}
@@ -315,8 +287,7 @@ public class AlignedSeriesScanNode extends SeriesSourceNode {
super.hashCode(),
alignedPath,
scanOrder,
- timeFilter,
- valueFilter,
+ pushDownPredicate,
limit,
offset,
regionReplicaSet,
@@ -335,9 +306,4 @@ public class AlignedSeriesScanNode extends SeriesSourceNode {
public PartialPath getPartitionPath() {
return alignedPath;
}
-
- @Override
- public Filter getPartitionTimeFilter() {
- return timeFilter;
- }
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/LastQueryScanNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/LastQueryScanNode.java
index aa89e61bd0a..b1bfc1af008 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/LastQueryScanNode.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/LastQueryScanNode.java
@@ -28,7 +28,6 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeType;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeUtil;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanVisitor;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
import com.google.common.collect.ImmutableList;
@@ -218,11 +217,6 @@ public class LastQueryScanNode extends LastSeriesSourceNode {
return seriesPath;
}
- @Override
- public Filter getPartitionTimeFilter() {
- return null;
- }
-
public String outputPathSymbol() {
if (outputViewPath == null) {
return seriesPath.getFullPath();
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/SeriesAggregationScanNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/SeriesAggregationScanNode.java
index 4d4623eb3d6..8bd9afe2f5d 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/SeriesAggregationScanNode.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/SeriesAggregationScanNode.java
@@ -22,6 +22,7 @@ import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
import org.apache.iotdb.commons.path.MeasurementPath;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.path.PathDeserializeUtil;
+import org.apache.iotdb.db.queryengine.plan.expression.Expression;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNode;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeType;
@@ -31,8 +32,6 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.node.process.Aggregatio
import org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.AggregationDescriptor;
import org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.GroupByTimeParameter;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
import com.google.common.collect.ImmutableList;
@@ -94,13 +93,11 @@ public class SeriesAggregationScanNode extends SeriesAggregationSourceNode {
MeasurementPath seriesPath,
List<AggregationDescriptor> aggregationDescriptorList,
Ordering scanOrder,
- @Nullable Filter timeFilter,
- @Nullable Filter valueFilter,
+ @Nullable Expression valueFilter,
@Nullable GroupByTimeParameter groupByTimeParameter,
TRegionReplicaSet dataRegionReplicaSet) {
this(id, seriesPath, aggregationDescriptorList, scanOrder, groupByTimeParameter);
- this.timeFilter = timeFilter;
- this.valueFilter = valueFilter;
+ this.pushDownPredicate = valueFilter;
this.regionReplicaSet = dataRegionReplicaSet;
}
@@ -135,8 +132,7 @@ public class SeriesAggregationScanNode extends SeriesAggregationSourceNode {
getSeriesPath(),
getAggregationDescriptorList(),
getScanOrder(),
- getTimeFilter(),
- getValueFilter(),
+ getPushDownPredicate(),
getGroupByTimeParameter(),
getRegionReplicaSet());
}
@@ -179,17 +175,11 @@ public class SeriesAggregationScanNode extends SeriesAggregationSourceNode {
aggregationDescriptor.serialize(byteBuffer);
}
ReadWriteIOUtils.write(scanOrder.ordinal(), byteBuffer);
- if (timeFilter == null) {
+ if (pushDownPredicate == null) {
ReadWriteIOUtils.write((byte) 0, byteBuffer);
} else {
ReadWriteIOUtils.write((byte) 1, byteBuffer);
- timeFilter.serialize(byteBuffer);
- }
- if (valueFilter == null) {
- ReadWriteIOUtils.write((byte) 0, byteBuffer);
- } else {
- ReadWriteIOUtils.write((byte) 1, byteBuffer);
- valueFilter.serialize(byteBuffer);
+ Expression.serialize(pushDownPredicate, byteBuffer);
}
if (groupByTimeParameter == null) {
ReadWriteIOUtils.write((byte) 0, byteBuffer);
@@ -208,17 +198,11 @@ public class SeriesAggregationScanNode extends SeriesAggregationSourceNode {
aggregationDescriptor.serialize(stream);
}
ReadWriteIOUtils.write(scanOrder.ordinal(), stream);
- if (timeFilter == null) {
- ReadWriteIOUtils.write((byte) 0, stream);
- } else {
- ReadWriteIOUtils.write((byte) 1, stream);
- timeFilter.serialize(stream);
- }
- if (valueFilter == null) {
+ if (pushDownPredicate == null) {
ReadWriteIOUtils.write((byte) 0, stream);
} else {
ReadWriteIOUtils.write((byte) 1, stream);
- valueFilter.serialize(stream);
+ Expression.serialize(pushDownPredicate, stream);
}
if (groupByTimeParameter == null) {
ReadWriteIOUtils.write((byte) 0, stream);
@@ -237,14 +221,9 @@ public class SeriesAggregationScanNode extends SeriesAggregationSourceNode {
}
Ordering scanOrder = Ordering.values()[ReadWriteIOUtils.readInt(byteBuffer)];
byte isNull = ReadWriteIOUtils.readByte(byteBuffer);
- Filter timeFilter = null;
- if (isNull == 1) {
- timeFilter = FilterFactory.deserialize(byteBuffer);
- }
- isNull = ReadWriteIOUtils.readByte(byteBuffer);
- Filter valueFilter = null;
+ Expression valueFilter = null;
if (isNull == 1) {
- valueFilter = FilterFactory.deserialize(byteBuffer);
+ valueFilter = Expression.deserialize(byteBuffer);
}
isNull = ReadWriteIOUtils.readByte(byteBuffer);
GroupByTimeParameter groupByTimeParameter = null;
@@ -257,7 +236,6 @@ public class SeriesAggregationScanNode extends SeriesAggregationSourceNode {
partialPath,
aggregationDescriptorList,
scanOrder,
- timeFilter,
valueFilter,
groupByTimeParameter,
null);
@@ -289,11 +267,6 @@ public class SeriesAggregationScanNode extends SeriesAggregationSourceNode {
return seriesPath;
}
- @Override
- public Filter getPartitionTimeFilter() {
- return timeFilter;
- }
-
@Override
public String toString() {
return String.format(
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/SeriesAggregationSourceNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/SeriesAggregationSourceNode.java
index 10141648aa2..cadc0735f87 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/SeriesAggregationSourceNode.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/SeriesAggregationSourceNode.java
@@ -19,11 +19,11 @@
package org.apache.iotdb.db.queryengine.plan.planner.plan.node.source;
+import org.apache.iotdb.db.queryengine.plan.expression.Expression;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId;
import org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.AggregationDescriptor;
import org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.GroupByTimeParameter;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
import javax.annotation.Nullable;
@@ -41,11 +41,8 @@ public abstract class SeriesAggregationSourceNode extends SeriesSourceNode {
// The default order is TIMESTAMP_ASC, which means "order by timestamp asc"
protected Ordering scanOrder = Ordering.ASC;
- // time filter for current series, could be null if it doesn't exist
- @Nullable protected Filter timeFilter;
-
// push-downing query filter for current series, could be null if it doesn't exist
- @Nullable protected Filter valueFilter;
+ @Nullable protected Expression pushDownPredicate;
// The parameter of `group by time`
// Its value will be null if there is no `group by time` clause,
@@ -70,21 +67,12 @@ public abstract class SeriesAggregationSourceNode extends SeriesSourceNode {
}
@Nullable
- public Filter getTimeFilter() {
- return timeFilter;
- }
-
- public void setTimeFilter(@Nullable Filter timeFilter) {
- this.timeFilter = timeFilter;
- }
-
- @Nullable
- public Filter getValueFilter() {
- return valueFilter;
+ public Expression getPushDownPredicate() {
+ return pushDownPredicate;
}
- public void setValueFilter(@Nullable Filter valueFilter) {
- this.valueFilter = valueFilter;
+ public void setPushDownPredicate(@Nullable Expression pushDownPredicate) {
+ this.pushDownPredicate = pushDownPredicate;
}
@Nullable
@@ -106,8 +94,7 @@ public abstract class SeriesAggregationSourceNode extends SeriesSourceNode {
SeriesAggregationSourceNode that = (SeriesAggregationSourceNode) o;
return aggregationDescriptorList.equals(that.aggregationDescriptorList)
&& scanOrder == that.scanOrder
- && Objects.equals(timeFilter, that.timeFilter)
- && Objects.equals(valueFilter, that.valueFilter)
+ && Objects.equals(pushDownPredicate, that.pushDownPredicate)
&& Objects.equals(groupByTimeParameter, that.groupByTimeParameter);
}
@@ -117,8 +104,7 @@ public abstract class SeriesAggregationSourceNode extends SeriesSourceNode {
super.hashCode(),
aggregationDescriptorList,
scanOrder,
- timeFilter,
- valueFilter,
+ pushDownPredicate,
groupByTimeParameter);
}
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/SeriesScanNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/SeriesScanNode.java
index 80de00ad962..6451d8999fb 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/SeriesScanNode.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/SeriesScanNode.java
@@ -22,14 +22,13 @@ import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
import org.apache.iotdb.commons.path.MeasurementPath;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.path.PathDeserializeUtil;
+import org.apache.iotdb.db.queryengine.plan.expression.Expression;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNode;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeType;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeUtil;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanVisitor;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
import com.google.common.collect.ImmutableList;
@@ -59,11 +58,8 @@ public class SeriesScanNode extends SeriesSourceNode {
// The default order is TIMESTAMP_ASC, which means "order by timestamp asc"
private Ordering scanOrder = Ordering.ASC;
- // time filter for current series, could be null if doesn't exist
- @Nullable private Filter timeFilter;
-
// value filter for current series, could be null if doesn't exist
- @Nullable private Filter valueFilter;
+ @Nullable private Expression pushDownPredicate;
// Limit for result set. The default value is -1, which means no limit
private long limit;
@@ -88,14 +84,25 @@ public class SeriesScanNode extends SeriesSourceNode {
PlanNodeId id,
MeasurementPath seriesPath,
Ordering scanOrder,
- @Nullable Filter timeFilter,
- @Nullable Filter valueFilter,
long limit,
long offset,
TRegionReplicaSet dataRegionReplicaSet) {
this(id, seriesPath, scanOrder);
- this.timeFilter = timeFilter;
- this.valueFilter = valueFilter;
+ this.limit = limit;
+ this.offset = offset;
+ this.regionReplicaSet = dataRegionReplicaSet;
+ }
+
+ public SeriesScanNode(
+ PlanNodeId id,
+ MeasurementPath seriesPath,
+ Ordering scanOrder,
+ @Nullable Expression pushDownPredicate,
+ long limit,
+ long offset,
+ TRegionReplicaSet dataRegionReplicaSet) {
+ this(id, seriesPath, scanOrder);
+ this.pushDownPredicate = pushDownPredicate;
this.limit = limit;
this.offset = offset;
this.regionReplicaSet = dataRegionReplicaSet;
@@ -146,21 +153,12 @@ public class SeriesScanNode extends SeriesSourceNode {
}
@Nullable
- public Filter getTimeFilter() {
- return timeFilter;
- }
-
- public void setTimeFilter(@Nullable Filter timeFilter) {
- this.timeFilter = timeFilter;
- }
-
- @Nullable
- public Filter getValueFilter() {
- return valueFilter;
+ public Expression getPushDownPredicate() {
+ return pushDownPredicate;
}
- public void setValueFilter(@Nullable Filter valueFilter) {
- this.valueFilter = valueFilter;
+ public void setPushDownPredicate(@Nullable Expression pushDownPredicate) {
+ this.pushDownPredicate = pushDownPredicate;
}
@Override
@@ -184,8 +182,7 @@ public class SeriesScanNode extends SeriesSourceNode {
getPlanNodeId(),
getSeriesPath(),
getScanOrder(),
- getTimeFilter(),
- getValueFilter(),
+ getPushDownPredicate(),
getLimit(),
getOffset(),
this.regionReplicaSet);
@@ -206,17 +203,11 @@ public class SeriesScanNode extends SeriesSourceNode {
PlanNodeType.SERIES_SCAN.serialize(byteBuffer);
seriesPath.serialize(byteBuffer);
ReadWriteIOUtils.write(scanOrder.ordinal(), byteBuffer);
- if (timeFilter == null) {
+ if (pushDownPredicate == null) {
ReadWriteIOUtils.write((byte) 0, byteBuffer);
} else {
ReadWriteIOUtils.write((byte) 1, byteBuffer);
- timeFilter.serialize(byteBuffer);
- }
- if (valueFilter == null) {
- ReadWriteIOUtils.write((byte) 0, byteBuffer);
- } else {
- ReadWriteIOUtils.write((byte) 1, byteBuffer);
- valueFilter.serialize(byteBuffer);
+ Expression.serialize(pushDownPredicate, byteBuffer);
}
ReadWriteIOUtils.write(limit, byteBuffer);
ReadWriteIOUtils.write(offset, byteBuffer);
@@ -227,17 +218,11 @@ public class SeriesScanNode extends SeriesSourceNode {
PlanNodeType.SERIES_SCAN.serialize(stream);
seriesPath.serialize(stream);
ReadWriteIOUtils.write(scanOrder.ordinal(), stream);
- if (timeFilter == null) {
+ if (pushDownPredicate == null) {
ReadWriteIOUtils.write((byte) 0, stream);
} else {
ReadWriteIOUtils.write((byte) 1, stream);
- timeFilter.serialize(stream);
- }
- if (valueFilter == null) {
- ReadWriteIOUtils.write((byte) 0, stream);
- } else {
- ReadWriteIOUtils.write((byte) 1, stream);
- valueFilter.serialize(stream);
+ Expression.serialize(pushDownPredicate, stream);
}
ReadWriteIOUtils.write(limit, stream);
ReadWriteIOUtils.write(offset, stream);
@@ -247,20 +232,14 @@ public class SeriesScanNode extends SeriesSourceNode {
MeasurementPath partialPath = (MeasurementPath) PathDeserializeUtil.deserialize(byteBuffer);
Ordering scanOrder = Ordering.values()[ReadWriteIOUtils.readInt(byteBuffer)];
byte isNull = ReadWriteIOUtils.readByte(byteBuffer);
- Filter timeFilter = null;
- if (isNull == 1) {
- timeFilter = FilterFactory.deserialize(byteBuffer);
- }
- isNull = ReadWriteIOUtils.readByte(byteBuffer);
- Filter valueFilter = null;
+ Expression valueFilter = null;
if (isNull == 1) {
- valueFilter = FilterFactory.deserialize(byteBuffer);
+ valueFilter = Expression.deserialize(byteBuffer);
}
long limit = ReadWriteIOUtils.readLong(byteBuffer);
long offset = ReadWriteIOUtils.readLong(byteBuffer);
PlanNodeId planNodeId = PlanNodeId.deserialize(byteBuffer);
- return new SeriesScanNode(
- planNodeId, partialPath, scanOrder, timeFilter, valueFilter, limit, offset, null);
+ return new SeriesScanNode(planNodeId, partialPath, scanOrder, valueFilter, limit, offset, null);
}
@Override
@@ -288,8 +267,7 @@ public class SeriesScanNode extends SeriesSourceNode {
&& offset == that.offset
&& seriesPath.equals(that.seriesPath)
&& scanOrder == that.scanOrder
- && Objects.equals(timeFilter, that.timeFilter)
- && Objects.equals(valueFilter, that.valueFilter)
+ && Objects.equals(pushDownPredicate, that.pushDownPredicate)
&& Objects.equals(regionReplicaSet, that.regionReplicaSet);
}
@@ -299,8 +277,7 @@ public class SeriesScanNode extends SeriesSourceNode {
super.hashCode(),
seriesPath,
scanOrder,
- timeFilter,
- valueFilter,
+ pushDownPredicate,
limit,
offset,
regionReplicaSet);
@@ -308,11 +285,6 @@ public class SeriesScanNode extends SeriesSourceNode {
@Override
public PartialPath getPartitionPath() {
- return seriesPath;
- }
-
- @Override
- public Filter getPartitionTimeFilter() {
- return timeFilter;
+ return getSeriesPath();
}
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/SeriesSourceNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/SeriesSourceNode.java
index 93bca7cfceb..18ebb71679e 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/SeriesSourceNode.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/source/SeriesSourceNode.java
@@ -21,7 +21,6 @@ package org.apache.iotdb.db.queryengine.plan.planner.plan.node.source;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
public abstract class SeriesSourceNode extends SourceNode {
protected SeriesSourceNode(PlanNodeId id) {
@@ -29,6 +28,4 @@ public abstract class SeriesSourceNode extends SourceNode {
}
public abstract PartialPath getPartitionPath();
-
- public abstract Filter getPartitionTimeFilter();
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/DeleteDataNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/DeleteDataNode.java
index 49582ecf942..65f3ffde475 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/DeleteDataNode.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/DeleteDataNode.java
@@ -35,7 +35,7 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.node.WritePlanNode;
import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.IWALByteBufferView;
import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.WALEntryValue;
import org.apache.iotdb.db.storageengine.dataregion.wal.utils.WALWriteUtils;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
+import org.apache.iotdb.tsfile.read.filter.factory.TimeFilter;
import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
import java.io.DataInputStream;
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/parameter/SeriesScanOptions.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/parameter/SeriesScanOptions.java
index f2238efee2c..953d7d07c5e 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/parameter/SeriesScanOptions.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/parameter/SeriesScanOptions.java
@@ -22,9 +22,9 @@ package org.apache.iotdb.db.queryengine.plan.planner.plan.parameter;
import org.apache.iotdb.commons.path.AlignedPath;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.utils.CommonDateTimeUtils;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.operator.AndFilter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
+import org.apache.iotdb.tsfile.read.filter.factory.TimeFilter;
import org.apache.iotdb.tsfile.read.reader.series.PaginationController;
import java.util.Collections;
@@ -101,7 +101,7 @@ public class SeriesScanOptions {
if (dataTTL != Long.MAX_VALUE) {
if (filter != null) {
filter =
- new AndFilter(filter, TimeFilter.gtEq(CommonDateTimeUtils.currentTime() - dataTTL));
+ FilterFactory.and(filter, TimeFilter.gtEq(CommonDateTimeUtils.currentTime() - dataTTL));
} else {
filter = TimeFilter.gtEq(CommonDateTimeUtils.currentTime() - dataTTL);
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/view/visitor/TransformToExpressionVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/view/visitor/TransformToExpressionVisitor.java
index ae4b13af8ff..6ab95e5b785 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/view/visitor/TransformToExpressionVisitor.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/view/visitor/TransformToExpressionVisitor.java
@@ -150,7 +150,10 @@ public class TransformToExpressionVisitor extends ViewExpressionVisitor<Expressi
public Expression visitLikeExpression(LikeViewExpression likeExpression, Void context) {
Expression child = this.process(likeExpression.getExpression(), context);
return new org.apache.iotdb.db.queryengine.plan.expression.unary.LikeExpression(
- child, likeExpression.getPatternString(), likeExpression.getPattern());
+ child,
+ likeExpression.getPatternString(),
+ likeExpression.getPattern(),
+ likeExpression.isNot());
}
@Override
@@ -171,7 +174,10 @@ public class TransformToExpressionVisitor extends ViewExpressionVisitor<Expressi
public Expression visitRegularExpression(RegularViewExpression regularExpression, Void context) {
Expression child = this.process(regularExpression.getExpression(), context);
return new org.apache.iotdb.db.queryengine.plan.expression.unary.RegularExpression(
- child, regularExpression.getPatternString(), regularExpression.getPattern());
+ child,
+ regularExpression.getPatternString(),
+ regularExpression.getPattern(),
+ regularExpression.isNot());
}
// endregion
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemAlignedPageReader.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemAlignedPageReader.java
index c48b8a06549..26244c5bfb1 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemAlignedPageReader.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemAlignedPageReader.java
@@ -29,7 +29,7 @@ import org.apache.iotdb.tsfile.read.common.BatchDataFactory;
import org.apache.iotdb.tsfile.read.common.block.TsBlock;
import org.apache.iotdb.tsfile.read.common.block.TsBlockBuilder;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.operator.AndFilter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
import org.apache.iotdb.tsfile.read.reader.IAlignedPageReader;
import org.apache.iotdb.tsfile.read.reader.IPageReader;
import org.apache.iotdb.tsfile.read.reader.series.PaginationController;
@@ -255,7 +255,7 @@ public class MemAlignedPageReader implements IPageReader, IAlignedPageReader {
if (valueFilter == null) {
this.valueFilter = filter;
} else {
- valueFilter = new AndFilter(this.valueFilter, filter);
+ valueFilter = FilterFactory.and(this.valueFilter, filter);
}
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemPageReader.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemPageReader.java
index 89d7198faa1..f1c571a5cff 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemPageReader.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemPageReader.java
@@ -30,7 +30,7 @@ import org.apache.iotdb.tsfile.read.common.block.TsBlock;
import org.apache.iotdb.tsfile.read.common.block.TsBlockBuilder;
import org.apache.iotdb.tsfile.read.common.block.column.TimeColumnBuilder;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.operator.AndFilter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
import org.apache.iotdb.tsfile.read.reader.IPageReader;
import org.apache.iotdb.tsfile.read.reader.series.PaginationController;
import org.apache.iotdb.tsfile.utils.Binary;
@@ -333,7 +333,7 @@ public class MemPageReader implements IPageReader {
if (valueFilter == null) {
this.valueFilter = filter;
} else {
- valueFilter = new AndFilter(this.valueFilter, filter);
+ valueFilter = FilterFactory.and(this.valueFilter, filter);
}
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/TimeValuePairUtils.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/TimeValuePairUtils.java
index b263c2f39f0..0e19cd28fb1 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/TimeValuePairUtils.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/TimeValuePairUtils.java
@@ -23,12 +23,6 @@ import org.apache.iotdb.tsfile.enums.TSDataType;
import org.apache.iotdb.tsfile.exception.UnSupportedDataTypeException;
import org.apache.iotdb.tsfile.read.TimeValuePair;
import org.apache.iotdb.tsfile.read.common.BatchData;
-import org.apache.iotdb.tsfile.read.filter.GroupByFilter;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.operator.AndFilter;
-import org.apache.iotdb.tsfile.read.filter.operator.NotFilter;
-import org.apache.iotdb.tsfile.read.filter.operator.OrFilter;
import org.apache.iotdb.tsfile.utils.Binary;
import org.apache.iotdb.tsfile.utils.TsPrimitiveType;
import org.apache.iotdb.tsfile.utils.TsPrimitiveType.TsBinary;
@@ -117,62 +111,6 @@ public class TimeValuePairUtils {
}
}
- public static Intervals extractTimeInterval(Filter filter) {
- if (filter == null) {
- return Intervals.ALL_INTERVAL;
- }
- // and, or, not, value, time, group by
- // eq, neq, gt, gteq, lt, lteq, in
- if (filter instanceof AndFilter) {
- AndFilter andFilter = ((AndFilter) filter);
- Intervals leftIntervals = extractTimeInterval(andFilter.getLeft());
- Intervals rightIntervals = extractTimeInterval(andFilter.getRight());
- return leftIntervals.intersection(rightIntervals);
- } else if (filter instanceof OrFilter) {
- OrFilter orFilter = ((OrFilter) filter);
- Intervals leftIntervals = extractTimeInterval(orFilter.getLeft());
- Intervals rightIntervals = extractTimeInterval(orFilter.getRight());
- return leftIntervals.union(rightIntervals);
- } else if (filter instanceof NotFilter) {
- NotFilter notFilter = ((NotFilter) filter);
- return extractTimeInterval(notFilter.getFilter()).not();
- } else if (filter instanceof TimeFilter.TimeGt) {
- TimeFilter.TimeGt timeGt = ((TimeFilter.TimeGt) filter);
- return new Intervals(((long) timeGt.getValue()) + 1, Long.MAX_VALUE);
- } else if (filter instanceof TimeFilter.TimeGtEq) {
- TimeFilter.TimeGtEq timeGtEq = ((TimeFilter.TimeGtEq) filter);
- return new Intervals(((long) timeGtEq.getValue()), Long.MAX_VALUE);
- } else if (filter instanceof TimeFilter.TimeEq) {
- TimeFilter.TimeEq timeEq = ((TimeFilter.TimeEq) filter);
- return new Intervals(((long) timeEq.getValue()), ((long) timeEq.getValue()));
- } else if (filter instanceof TimeFilter.TimeNotEq) {
- TimeFilter.TimeNotEq timeNotEq = ((TimeFilter.TimeNotEq) filter);
- Intervals intervals = new Intervals();
- intervals.addInterval(Long.MIN_VALUE, (long) timeNotEq.getValue() - 1);
- intervals.addInterval((long) timeNotEq.getValue() + 1, Long.MAX_VALUE);
- return intervals;
- } else if (filter instanceof TimeFilter.TimeLt) {
- TimeFilter.TimeLt timeLt = ((TimeFilter.TimeLt) filter);
- return new Intervals(Long.MIN_VALUE, (long) timeLt.getValue() - 1);
- } else if (filter instanceof TimeFilter.TimeLtEq) {
- TimeFilter.TimeLtEq timeLtEq = ((TimeFilter.TimeLtEq) filter);
- return new Intervals(Long.MIN_VALUE, (long) timeLtEq.getValue());
- } else if (filter instanceof TimeFilter.TimeIn) {
- TimeFilter.TimeIn timeIn = ((TimeFilter.TimeIn) filter);
- Intervals intervals = new Intervals();
- for (Object value : timeIn.getValues()) {
- long time = ((long) value);
- intervals.addInterval(time, time);
- }
- return intervals;
- } else if (filter instanceof GroupByFilter) {
- GroupByFilter groupByFilter = ((GroupByFilter) filter);
- return new Intervals(groupByFilter.getStartTime(), groupByFilter.getEndTime() + 1);
- }
- // value filter
- return Intervals.ALL_INTERVAL;
- }
-
/** All intervals are closed. */
public static class Intervals extends ArrayList<Long> {
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/AlignedSeriesAggregationScanOperatorTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/AlignedSeriesAggregationScanOperatorTest.java
index 0426f0e7704..bb40f0d52b6 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/AlignedSeriesAggregationScanOperatorTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/AlignedSeriesAggregationScanOperatorTest.java
@@ -46,9 +46,9 @@ import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
import org.apache.iotdb.tsfile.enums.TSDataType;
import org.apache.iotdb.tsfile.exception.write.WriteProcessException;
import org.apache.iotdb.tsfile.read.common.block.TsBlock;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.operator.AndFilter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
+import org.apache.iotdb.tsfile.read.filter.factory.TimeFilter;
import org.apache.iotdb.tsfile.utils.TimeDuration;
import org.apache.iotdb.tsfile.write.schema.IMeasurementSchema;
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
@@ -344,7 +344,7 @@ public class AlignedSeriesAggregationScanOperatorTest {
@Test
public void testAggregationWithTimeFilter3() throws Exception {
- Filter timeFilter = new AndFilter(TimeFilter.gtEq(100), TimeFilter.ltEq(399));
+ Filter timeFilter = FilterFactory.and(TimeFilter.gtEq(100), TimeFilter.ltEq(399));
List<Aggregator> aggregators = new ArrayList<>();
for (int i = 0; i < measurementSchemas.size(); i++) {
TSDataType dataType = measurementSchemas.get(i).getType();
@@ -399,7 +399,7 @@ public class AlignedSeriesAggregationScanOperatorTest {
AggregationStep.SINGLE,
inputLocations));
}
- Filter timeFilter = new AndFilter(TimeFilter.gtEq(100), TimeFilter.ltEq(399));
+ Filter timeFilter = FilterFactory.and(TimeFilter.gtEq(100), TimeFilter.ltEq(399));
AlignedSeriesAggregationScanOperator seriesAggregationScanOperator =
initAlignedSeriesAggregationScanOperator(aggregators, timeFilter, true, null);
int count = 0;
@@ -459,7 +459,7 @@ public class AlignedSeriesAggregationScanOperatorTest {
@Test
public void testGroupByWithGlobalTimeFilter() throws Exception {
int[] result = new int[] {0, 80, 100, 80};
- Filter timeFilter = new AndFilter(TimeFilter.gtEq(120), TimeFilter.ltEq(379));
+ Filter timeFilter = FilterFactory.and(TimeFilter.gtEq(120), TimeFilter.ltEq(379));
GroupByTimeParameter groupByTimeParameter =
new GroupByTimeParameter(0, 399, new TimeDuration(0, 100), new TimeDuration(0, 100), true);
List<Aggregator> aggregators = new ArrayList<>();
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/RawDataAggregationOperatorTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/RawDataAggregationOperatorTest.java
index a3c4b395e48..8b84ca70aa3 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/RawDataAggregationOperatorTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/RawDataAggregationOperatorTest.java
@@ -57,8 +57,7 @@ import org.apache.iotdb.tsfile.enums.TSDataType;
import org.apache.iotdb.tsfile.exception.write.WriteProcessException;
import org.apache.iotdb.tsfile.read.common.block.TsBlock;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
-import org.apache.iotdb.tsfile.read.filter.operator.Gt;
+import org.apache.iotdb.tsfile.read.filter.factory.TimeFilter;
import org.apache.iotdb.tsfile.utils.TimeDuration;
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
@@ -949,7 +948,7 @@ public class RawDataAggregationOperatorTest {
Filter timeFilter = null;
if (groupByTimeParameter != null && !groupByTimeParameter.isLeftCRightO()) {
- timeFilter = new Gt<>(0L, FilterType.TIME_FILTER);
+ timeFilter = TimeFilter.gt(0L);
}
SeriesScanOptions.Builder scanOptionsBuilder = new SeriesScanOptions.Builder();
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/SeriesAggregationScanOperatorTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/SeriesAggregationScanOperatorTest.java
index 2081872ac7a..207ffd41b83 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/SeriesAggregationScanOperatorTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/SeriesAggregationScanOperatorTest.java
@@ -44,9 +44,9 @@ import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
import org.apache.iotdb.tsfile.enums.TSDataType;
import org.apache.iotdb.tsfile.exception.write.WriteProcessException;
import org.apache.iotdb.tsfile.read.common.block.TsBlock;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.operator.AndFilter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
+import org.apache.iotdb.tsfile.read.filter.factory.TimeFilter;
import org.apache.iotdb.tsfile.utils.TimeDuration;
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
@@ -291,7 +291,7 @@ public class SeriesAggregationScanOperatorTest {
@Test
public void testAggregationWithTimeFilter3() throws Exception {
- Filter timeFilter = new AndFilter(TimeFilter.gtEq(100), TimeFilter.ltEq(399));
+ Filter timeFilter = FilterFactory.and(TimeFilter.gtEq(100), TimeFilter.ltEq(399));
List<TAggregationType> aggregationTypes = Collections.singletonList(TAggregationType.COUNT);
List<Aggregator> aggregators = new ArrayList<>();
AccumulatorFactory.createAccumulators(
@@ -331,7 +331,7 @@ public class SeriesAggregationScanOperatorTest {
Collections.emptyMap(),
true)
.forEach(o -> aggregators.add(new Aggregator(o, AggregationStep.SINGLE)));
- Filter timeFilter = new AndFilter(TimeFilter.gtEq(100), TimeFilter.ltEq(399));
+ Filter timeFilter = FilterFactory.and(TimeFilter.gtEq(100), TimeFilter.ltEq(399));
SeriesAggregationScanOperator seriesAggregationScanOperator =
initSeriesAggregationScanOperator(aggregators, timeFilter, true, null);
int count = 0;
@@ -384,7 +384,7 @@ public class SeriesAggregationScanOperatorTest {
@Test
public void testGroupByWithGlobalTimeFilter() throws Exception {
int[] result = new int[] {0, 80, 100, 80};
- Filter timeFilter = new AndFilter(TimeFilter.gtEq(120), TimeFilter.ltEq(379));
+ Filter timeFilter = FilterFactory.and(TimeFilter.gtEq(120), TimeFilter.ltEq(379));
GroupByTimeParameter groupByTimeParameter =
new GroupByTimeParameter(0, 399, new TimeDuration(0, 100), new TimeDuration(0, 100), true);
List<TAggregationType> aggregationTypes = Collections.singletonList(TAggregationType.COUNT);
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/UpdateLastCacheOperatorTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/UpdateLastCacheOperatorTest.java
index 13734f6c186..d2a66957ca0 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/UpdateLastCacheOperatorTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/UpdateLastCacheOperatorTest.java
@@ -43,8 +43,8 @@ import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
import org.apache.iotdb.tsfile.enums.TSDataType;
import org.apache.iotdb.tsfile.exception.write.WriteProcessException;
import org.apache.iotdb.tsfile.read.common.block.TsBlock;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.TimeFilter;
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import com.google.common.collect.Sets;
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeTest.java
index 3e65d04fa93..d2998fb1c5a 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeTest.java
@@ -49,9 +49,6 @@ import org.apache.iotdb.db.queryengine.plan.parser.StatementGenerator;
import org.apache.iotdb.db.queryengine.plan.statement.Statement;
import org.apache.iotdb.db.queryengine.plan.statement.crud.QueryStatement;
import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.filter.GroupByFilter;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
-import org.apache.iotdb.tsfile.read.filter.operator.AndFilter;
import org.apache.iotdb.tsfile.utils.Pair;
import org.apache.ratis.thirdparty.com.google.common.collect.ImmutableMap;
@@ -70,6 +67,11 @@ import java.util.List;
import java.util.Map;
import static org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant.DEVICE;
+import static org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory.and;
+import static org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory.groupByTime;
+import static org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory.gt;
+import static org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory.longValue;
+import static org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory.time;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -82,7 +84,7 @@ public class AnalyzeTest {
Analysis actualAnalysis = analyzeSQL(sql);
Analysis expectedAnalysis = new Analysis();
- expectedAnalysis.setGlobalTimeFilter(TimeFilter.gt(100));
+ expectedAnalysis.setGlobalTimeFilter(gt(time(), longValue(100)));
expectedAnalysis.setSelectExpressions(
Sets.newHashSet(
new TimeSeriesOperand(new PartialPath("root.sg.d1.s1")),
@@ -123,7 +125,7 @@ public class AnalyzeTest {
+ "where time >= 100 and s2 >= 10 and s2 != 6;";
actualAnalysis = analyzeSQL(sql);
expectedAnalysis = new Analysis();
- expectedAnalysis.setGlobalTimeFilter(TimeFilter.gtEq(100));
+ expectedAnalysis.setGlobalTimeFilter(gt(time(), longValue(100)));
expectedAnalysis.setSelectExpressions(
Sets.newHashSet(
new TimeSeriesOperand(new PartialPath("root.sg.d1.s1")),
@@ -194,7 +196,7 @@ public class AnalyzeTest {
Analysis expectedAnalysis = new Analysis();
expectedAnalysis.setGlobalTimeFilter(
- new AndFilter(TimeFilter.gt(100), new GroupByFilter(10, 10, 0, 1000)));
+ and(gt(time(), longValue(100)), groupByTime(10, 10, 0, 1000)));
expectedAnalysis.setSelectExpressions(
Sets.newHashSet(
new AdditionExpression(
@@ -281,7 +283,7 @@ public class AnalyzeTest {
Analysis actualAnalysis = analyzeSQL(sql);
Analysis expectedAnalysis = new Analysis();
- expectedAnalysis.setGlobalTimeFilter(TimeFilter.gt(100));
+ expectedAnalysis.setGlobalTimeFilter(gt(time(), longValue(100)));
expectedAnalysis.setSelectExpressions(
Sets.newHashSet(
new TimeSeriesOperand(
@@ -383,7 +385,7 @@ public class AnalyzeTest {
Analysis expectedAnalysis = new Analysis();
expectedAnalysis.setGlobalTimeFilter(
- new AndFilter(TimeFilter.gt(100), new GroupByFilter(10, 10, 0, 1000)));
+ and(gt(time(), longValue(100)), groupByTime(10, 10, 0, 1000)));
expectedAnalysis.setSelectExpressions(
Sets.newHashSet(
new TimeSeriesOperand(
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/analyze/QueryTimePartitionTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/analyze/QueryTimePartitionTest.java
index 67a424e8238..144c09a441e 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/analyze/QueryTimePartitionTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/analyze/QueryTimePartitionTest.java
@@ -21,10 +21,9 @@ package org.apache.iotdb.db.queryengine.plan.analyze;
import org.apache.iotdb.common.rpc.thrift.TTimePartitionSlot;
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.tsfile.read.common.TimeRange;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
-import org.apache.iotdb.tsfile.read.filter.operator.AndFilter;
-import org.apache.iotdb.tsfile.read.filter.operator.NotFilter;
-import org.apache.iotdb.tsfile.read.filter.operator.OrFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
+import org.apache.iotdb.tsfile.read.filter.factory.TimeFilter;
import org.apache.iotdb.tsfile.utils.Pair;
import org.junit.Test;
@@ -42,44 +41,44 @@ public class QueryTimePartitionTest {
@Test
public void testAndTimeFilter() {
- TimeFilter.TimeGt left = TimeFilter.gt(10);
- TimeFilter.TimeLt right = TimeFilter.lt(20);
+ Filter left = TimeFilter.gt(10);
+ Filter right = TimeFilter.lt(20);
// time > 10 and time < 20
- AndFilter andFilter = new AndFilter(left, right);
+ Filter andFilter = FilterFactory.and(left, right);
List<TimeRange> timeRangeList = andFilter.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(11, timeRangeList.get(0).getMin());
assertEquals(19, timeRangeList.get(0).getMax());
// time > 10 and time <= 20
- andFilter = new AndFilter(left, TimeFilter.ltEq(20));
+ andFilter = FilterFactory.and(left, TimeFilter.ltEq(20));
timeRangeList = andFilter.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(11, timeRangeList.get(0).getMin());
assertEquals(20, timeRangeList.get(0).getMax());
// time >= 10 and time <= 20
- andFilter = new AndFilter(TimeFilter.gtEq(10), TimeFilter.ltEq(20));
+ andFilter = FilterFactory.and(TimeFilter.gtEq(10), TimeFilter.ltEq(20));
timeRangeList = andFilter.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(10, timeRangeList.get(0).getMin());
assertEquals(20, timeRangeList.get(0).getMax());
// time <= 20 and time >= 10
- andFilter = new AndFilter(TimeFilter.ltEq(20), TimeFilter.gtEq(10));
+ andFilter = FilterFactory.and(TimeFilter.ltEq(20), TimeFilter.gtEq(10));
timeRangeList = andFilter.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(10, timeRangeList.get(0).getMin());
assertEquals(20, timeRangeList.get(0).getMax());
// time >= 20 and time <= 10
- andFilter = new AndFilter(TimeFilter.gtEq(20), TimeFilter.ltEq(10));
+ andFilter = FilterFactory.and(TimeFilter.gtEq(20), TimeFilter.ltEq(10));
timeRangeList = andFilter.getTimeRanges();
assertEquals(0, timeRangeList.size());
// time >= 20 and time < 20
- andFilter = new AndFilter(TimeFilter.gtEq(20), TimeFilter.lt(20));
+ andFilter = FilterFactory.and(TimeFilter.gtEq(20), TimeFilter.lt(20));
timeRangeList = andFilter.getTimeRanges();
assertEquals(0, timeRangeList.size());
}
@@ -88,7 +87,7 @@ public class QueryTimePartitionTest {
public void testOrTimeFilter() {
// time < 10 or time > 20
- OrFilter filter = new OrFilter(TimeFilter.lt(10), TimeFilter.gt(20));
+ Filter filter = FilterFactory.or(TimeFilter.lt(10), TimeFilter.gt(20));
List<TimeRange> timeRangeList = filter.getTimeRanges();
assertEquals(2, timeRangeList.size());
assertEquals(Long.MIN_VALUE, timeRangeList.get(0).getMin());
@@ -97,7 +96,7 @@ public class QueryTimePartitionTest {
assertEquals(Long.MAX_VALUE, timeRangeList.get(1).getMax());
// time < 10 or time >= 20
- filter = new OrFilter(TimeFilter.lt(10), TimeFilter.gtEq(20));
+ filter = FilterFactory.or(TimeFilter.lt(10), TimeFilter.gtEq(20));
timeRangeList = filter.getTimeRanges();
assertEquals(2, timeRangeList.size());
assertEquals(Long.MIN_VALUE, timeRangeList.get(0).getMin());
@@ -106,7 +105,7 @@ public class QueryTimePartitionTest {
assertEquals(Long.MAX_VALUE, timeRangeList.get(1).getMax());
// time <= 10 or time >= 20
- filter = new OrFilter(TimeFilter.ltEq(10), TimeFilter.gtEq(20));
+ filter = FilterFactory.or(TimeFilter.ltEq(10), TimeFilter.gtEq(20));
timeRangeList = filter.getTimeRanges();
assertEquals(2, timeRangeList.size());
assertEquals(Long.MIN_VALUE, timeRangeList.get(0).getMin());
@@ -115,7 +114,7 @@ public class QueryTimePartitionTest {
assertEquals(Long.MAX_VALUE, timeRangeList.get(1).getMax());
// time >= 20 or time <= 10
- filter = new OrFilter(TimeFilter.gtEq(20), TimeFilter.ltEq(10));
+ filter = FilterFactory.or(TimeFilter.gtEq(20), TimeFilter.ltEq(10));
timeRangeList = filter.getTimeRanges();
assertEquals(2, timeRangeList.size());
assertEquals(Long.MIN_VALUE, timeRangeList.get(0).getMin());
@@ -124,14 +123,14 @@ public class QueryTimePartitionTest {
assertEquals(Long.MAX_VALUE, timeRangeList.get(1).getMax());
// time >= 20 or time >= 10
- filter = new OrFilter(TimeFilter.gtEq(20), TimeFilter.gtEq(10));
+ filter = FilterFactory.or(TimeFilter.gtEq(20), TimeFilter.gtEq(10));
timeRangeList = filter.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(10, timeRangeList.get(0).getMin());
assertEquals(Long.MAX_VALUE, timeRangeList.get(0).getMax());
// time < 20 or time <= 10
- filter = new OrFilter(TimeFilter.lt(20), TimeFilter.ltEq(10));
+ filter = FilterFactory.or(TimeFilter.lt(20), TimeFilter.ltEq(10));
timeRangeList = filter.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(Long.MIN_VALUE, timeRangeList.get(0).getMin());
@@ -142,8 +141,9 @@ public class QueryTimePartitionTest {
public void testAndOrTimeFilter() {
// (time >= 10 and time <= 20) or (time > 30)
- OrFilter filter =
- new OrFilter(new AndFilter(TimeFilter.gtEq(10), TimeFilter.ltEq(20)), TimeFilter.gt(30));
+ Filter filter =
+ FilterFactory.or(
+ FilterFactory.and(TimeFilter.gtEq(10), TimeFilter.ltEq(20)), TimeFilter.gt(30));
List<TimeRange> timeRangeList = filter.getTimeRanges();
assertEquals(2, timeRangeList.size());
assertEquals(10, timeRangeList.get(0).getMin());
@@ -152,8 +152,9 @@ public class QueryTimePartitionTest {
assertEquals(Long.MAX_VALUE, timeRangeList.get(1).getMax());
// (time <= 10 or time > 20) and (time >= 30)
- AndFilter filter1 =
- new AndFilter(new OrFilter(TimeFilter.ltEq(10), TimeFilter.gt(20)), TimeFilter.gtEq(30));
+ Filter filter1 =
+ FilterFactory.and(
+ FilterFactory.or(TimeFilter.ltEq(10), TimeFilter.gt(20)), TimeFilter.gtEq(30));
timeRangeList = filter1.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(30, timeRangeList.get(0).getMin());
@@ -161,7 +162,8 @@ public class QueryTimePartitionTest {
// (time <= 10 or time > 20) and (time <= 30)
filter1 =
- new AndFilter(new OrFilter(TimeFilter.ltEq(10), TimeFilter.gt(20)), TimeFilter.ltEq(30));
+ FilterFactory.and(
+ FilterFactory.or(TimeFilter.ltEq(10), TimeFilter.gt(20)), TimeFilter.ltEq(30));
timeRangeList = filter1.getTimeRanges();
assertEquals(2, timeRangeList.size());
assertEquals(Long.MIN_VALUE, timeRangeList.get(0).getMin());
@@ -171,9 +173,9 @@ public class QueryTimePartitionTest {
// (time >= 10 and time <= 20) or (time < 99 and time > 30)
filter =
- new OrFilter(
- new AndFilter(TimeFilter.gtEq(10), TimeFilter.ltEq(20)),
- new AndFilter(TimeFilter.lt(100), TimeFilter.gt(30)));
+ FilterFactory.or(
+ FilterFactory.and(TimeFilter.gtEq(10), TimeFilter.ltEq(20)),
+ FilterFactory.and(TimeFilter.lt(100), TimeFilter.gt(30)));
timeRangeList = filter.getTimeRanges();
assertEquals(2, timeRangeList.size());
assertEquals(10, timeRangeList.get(0).getMin());
@@ -186,7 +188,7 @@ public class QueryTimePartitionTest {
public void testBetweenTimeFilter() {
// time between 10 and 20
- TimeFilter.TimeBetween filter = TimeFilter.between(10, 20);
+ Filter filter = TimeFilter.between(10, 20);
List<TimeRange> timeRangeList = filter.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(10, timeRangeList.get(0).getMin());
@@ -220,7 +222,7 @@ public class QueryTimePartitionTest {
public void testNotTimeFilter() {
// !(time > 10 and time <= 20)
- NotFilter filter = new NotFilter(new AndFilter(TimeFilter.gt(10), TimeFilter.ltEq(20)));
+ Filter filter = FilterFactory.not(FilterFactory.and(TimeFilter.gt(10), TimeFilter.ltEq(20)));
List<TimeRange> timeRangeList = filter.getTimeRanges();
assertEquals(2, timeRangeList.size());
assertEquals(Long.MIN_VALUE, timeRangeList.get(0).getMin());
@@ -229,7 +231,7 @@ public class QueryTimePartitionTest {
assertEquals(Long.MAX_VALUE, timeRangeList.get(1).getMax());
// !(time > 20 or time <= 10)
- filter = new NotFilter(new OrFilter(TimeFilter.gt(20), TimeFilter.ltEq(10)));
+ filter = FilterFactory.not(FilterFactory.or(TimeFilter.gt(20), TimeFilter.ltEq(10)));
timeRangeList = filter.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(11, timeRangeList.get(0).getMin());
@@ -240,14 +242,14 @@ public class QueryTimePartitionTest {
public void testTimeEqFilter() {
// time = 10
- TimeFilter.TimeEq filter = TimeFilter.eq(10);
+ Filter filter = TimeFilter.eq(10);
List<TimeRange> timeRangeList = filter.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(10, timeRangeList.get(0).getMin());
assertEquals(10, timeRangeList.get(0).getMax());
// !(time = 10)
- NotFilter filter1 = new NotFilter(filter);
+ Filter filter1 = FilterFactory.not(filter);
timeRangeList = filter1.getTimeRanges();
assertEquals(2, timeRangeList.size());
assertEquals(Long.MIN_VALUE, timeRangeList.get(0).getMin());
@@ -260,7 +262,7 @@ public class QueryTimePartitionTest {
public void testTimeNotEqFilter() {
// time != 10
- TimeFilter.TimeNotEq filter = TimeFilter.notEq(10);
+ Filter filter = TimeFilter.notEq(10);
List<TimeRange> timeRangeList = filter.getTimeRanges();
assertEquals(2, timeRangeList.size());
assertEquals(Long.MIN_VALUE, timeRangeList.get(0).getMin());
@@ -269,7 +271,7 @@ public class QueryTimePartitionTest {
assertEquals(Long.MAX_VALUE, timeRangeList.get(1).getMax());
// !(time != 10)
- NotFilter filter1 = new NotFilter(filter);
+ Filter filter1 = FilterFactory.not(filter);
timeRangeList = filter1.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(10, timeRangeList.get(0).getMin());
@@ -280,14 +282,14 @@ public class QueryTimePartitionTest {
public void testTimeGtFilter() {
// time > 10
- TimeFilter.TimeGt filter = TimeFilter.gt(10);
+ Filter filter = TimeFilter.gt(10);
List<TimeRange> timeRangeList = filter.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(11, timeRangeList.get(0).getMin());
assertEquals(Long.MAX_VALUE, timeRangeList.get(0).getMax());
// !(time > 10)
- NotFilter filter1 = new NotFilter(filter);
+ Filter filter1 = FilterFactory.not(filter);
timeRangeList = filter1.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(Long.MIN_VALUE, timeRangeList.get(0).getMin());
@@ -298,14 +300,14 @@ public class QueryTimePartitionTest {
public void testTimeGtEqFilter() {
// time >= 10
- TimeFilter.TimeGtEq filter = TimeFilter.gtEq(10);
+ Filter filter = TimeFilter.gtEq(10);
List<TimeRange> timeRangeList = filter.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(10, timeRangeList.get(0).getMin());
assertEquals(Long.MAX_VALUE, timeRangeList.get(0).getMax());
// !(time >= 10)
- NotFilter filter1 = new NotFilter(filter);
+ Filter filter1 = FilterFactory.not(filter);
timeRangeList = filter1.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(Long.MIN_VALUE, timeRangeList.get(0).getMin());
@@ -316,14 +318,14 @@ public class QueryTimePartitionTest {
public void testTimeLtFilter() {
// time < 10
- TimeFilter.TimeLt filter = TimeFilter.lt(10);
+ Filter filter = TimeFilter.lt(10);
List<TimeRange> timeRangeList = filter.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(Long.MIN_VALUE, timeRangeList.get(0).getMin());
assertEquals(9, timeRangeList.get(0).getMax());
// !(time < 10)
- NotFilter filter1 = new NotFilter(filter);
+ Filter filter1 = FilterFactory.not(filter);
timeRangeList = filter1.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(10, timeRangeList.get(0).getMin());
@@ -334,14 +336,14 @@ public class QueryTimePartitionTest {
public void testTimeLtEqFilter() {
// time <= 10
- TimeFilter.TimeLtEq filter = TimeFilter.ltEq(10);
+ Filter filter = TimeFilter.ltEq(10);
List<TimeRange> timeRangeList = filter.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(Long.MIN_VALUE, timeRangeList.get(0).getMin());
assertEquals(10, timeRangeList.get(0).getMax());
// !(time <= 10)
- NotFilter filter1 = new NotFilter(filter);
+ Filter filter1 = FilterFactory.not(filter);
timeRangeList = filter1.getTimeRanges();
assertEquals(1, timeRangeList.size());
assertEquals(11, timeRangeList.get(0).getMin());
@@ -353,7 +355,7 @@ public class QueryTimePartitionTest {
// time >= 10 and time <= 9
Pair<List<TTimePartitionSlot>, Pair<Boolean, Boolean>> res =
- getTimePartitionSlotList(new AndFilter(TimeFilter.gtEq(10), TimeFilter.ltEq(9)));
+ getTimePartitionSlotList(FilterFactory.and(TimeFilter.gtEq(10), TimeFilter.ltEq(9)));
assertTrue(res.left.isEmpty());
assertFalse(res.right.left);
assertFalse(res.right.right);
@@ -381,7 +383,7 @@ public class QueryTimePartitionTest {
assertFalse(res.right.right);
// time > 10 and time <= 20
- res = getTimePartitionSlotList(new AndFilter(TimeFilter.gt(10), TimeFilter.ltEq(20)));
+ res = getTimePartitionSlotList(FilterFactory.and(TimeFilter.gt(10), TimeFilter.ltEq(20)));
expected = Collections.singletonList(new TTimePartitionSlot(0));
assertEquals(expected.size(), res.left.size());
for (int i = 0; i < expected.size(); i++) {
@@ -394,7 +396,7 @@ public class QueryTimePartitionTest {
// .getConfig().getTimePartitionInterval() * 3 + 1
res =
getTimePartitionSlotList(
- new AndFilter(
+ FilterFactory.and(
TimeFilter.gt(0),
TimeFilter.ltEq(
CommonDescriptor.getInstance().getConfig().getTimePartitionInterval() * 3
@@ -419,7 +421,7 @@ public class QueryTimePartitionTest {
// IoTDBDescriptor.getInstance().getConfig().getTimePartitionInterval() + 1
res =
getTimePartitionSlotList(
- new AndFilter(
+ FilterFactory.and(
TimeFilter.gtEq(
CommonDescriptor.getInstance().getConfig().getTimePartitionInterval() - 1),
TimeFilter.lt(
@@ -459,7 +461,7 @@ public class QueryTimePartitionTest {
// IoTDBDescriptor.getInstance().getConfig().getTimePartitionInterval() + 1
res =
getTimePartitionSlotList(
- new AndFilter(
+ FilterFactory.and(
TimeFilter.gtEq(
CommonDescriptor.getInstance().getConfig().getTimePartitionInterval()),
TimeFilter.ltEq(
@@ -503,40 +505,40 @@ public class QueryTimePartitionTest {
// or (time > IoTDBDescriptor.getInstance().getConfig().getTimePartitionInterval() * 5 + 1 and
// time < IoTDBDescriptor.getInstance().getConfig().getTimePartitionInterval() * 5 + 10)
- OrFilter orFilter1 =
- new OrFilter(
- new AndFilter(
+ Filter orFilter1 =
+ FilterFactory.or(
+ FilterFactory.and(
TimeFilter.gtEq(10),
TimeFilter.lt(
CommonDescriptor.getInstance().getConfig().getTimePartitionInterval())),
- new AndFilter(
+ FilterFactory.and(
TimeFilter.gt(
CommonDescriptor.getInstance().getConfig().getTimePartitionInterval()),
TimeFilter.lt(
CommonDescriptor.getInstance().getConfig().getTimePartitionInterval() * 2
- 100)));
- OrFilter orFilter2 =
- new OrFilter(
+ Filter orFilter2 =
+ FilterFactory.or(
orFilter1,
- new AndFilter(
+ FilterFactory.and(
TimeFilter.gt(
CommonDescriptor.getInstance().getConfig().getTimePartitionInterval() * 2 - 50),
TimeFilter.ltEq(
CommonDescriptor.getInstance().getConfig().getTimePartitionInterval() * 2
- 40)));
- OrFilter orFilter3 =
- new OrFilter(
+ Filter orFilter3 =
+ FilterFactory.or(
orFilter2,
- new AndFilter(
+ FilterFactory.and(
TimeFilter.gt(
CommonDescriptor.getInstance().getConfig().getTimePartitionInterval() * 2 - 20),
TimeFilter.ltEq(
CommonDescriptor.getInstance().getConfig().getTimePartitionInterval() * 3
+ 10)));
- OrFilter orFilter4 =
- new OrFilter(
+ Filter orFilter4 =
+ FilterFactory.or(
orFilter3,
- new AndFilter(
+ FilterFactory.and(
TimeFilter.gt(
CommonDescriptor.getInstance().getConfig().getTimePartitionInterval() * 5 + 1),
TimeFilter.lt(
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/FragmentInstanceSerdeTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/FragmentInstanceSerdeTest.java
index c3eb6c0a05e..add289658ec 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/FragmentInstanceSerdeTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/FragmentInstanceSerdeTest.java
@@ -32,6 +32,7 @@ import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.queryengine.common.PlanFragmentId;
import org.apache.iotdb.db.queryengine.common.SessionInfo;
import org.apache.iotdb.db.queryengine.plan.analyze.QueryType;
+import org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory;
import org.apache.iotdb.db.queryengine.plan.planner.plan.FragmentInstance;
import org.apache.iotdb.db.queryengine.plan.planner.plan.PlanFragment;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNode;
@@ -41,7 +42,6 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.node.process.OffsetNode
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.process.TimeJoinNode;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.source.SeriesScanNode;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
-import org.apache.iotdb.tsfile.read.filter.GroupByFilter;
import com.google.common.collect.ImmutableList;
import org.junit.Test;
@@ -72,7 +72,7 @@ public class FragmentInstanceSerdeTest {
new FragmentInstance(
new PlanFragment(planFragmentId, constructPlanNodeTree()),
planFragmentId.genFragmentInstanceId(),
- new GroupByFilter(1, 2, 3, 4),
+ ExpressionFactory.groupByTime(1, 2, 3, 4),
QueryType.READ,
config.getQueryTimeoutThreshold(),
sessionInfo);
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/QueryLogicalPlanUtil.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/QueryLogicalPlanUtil.java
index f95b9c27d5f..93b57e0cd27 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/QueryLogicalPlanUtil.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/QueryLogicalPlanUtil.java
@@ -54,8 +54,8 @@ import org.apache.iotdb.db.queryengine.plan.statement.component.OrderByKey;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.db.queryengine.plan.statement.component.SortItem;
import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.TimeFilter;
import java.time.ZonedDateTime;
import java.util.ArrayList;
@@ -142,8 +142,7 @@ public class QueryLogicalPlanUtil {
queryId.genPlanNodeId(), (MeasurementPath) schemaMap.get("root.sg.d2.s4"), null));
LastQueryNode lastQueryNode =
- new LastQueryNode(
- queryId.genPlanNodeId(), sourceNodeList, TimeFilter.gt(100), Ordering.ASC, false);
+ new LastQueryNode(queryId.genPlanNodeId(), sourceNodeList, Ordering.ASC, false);
querySQLs.add(sql);
sqlToPlanMap.put(sql, lastQueryNode);
@@ -177,14 +176,6 @@ public class QueryLogicalPlanUtil {
Ordering.ASC,
false));
- for (PlanNode sourceNode : sourceNodeList) {
- if (sourceNode instanceof SeriesScanNode) {
- ((SeriesScanNode) sourceNode).setTimeFilter(TimeFilter.gt(100));
- } else if (sourceNode instanceof AlignedSeriesScanNode) {
- ((AlignedSeriesScanNode) sourceNode).setTimeFilter(TimeFilter.gt(100));
- }
- }
-
TimeJoinNode timeJoinNode =
new TimeJoinNode(queryId.genPlanNodeId(), Ordering.ASC, sourceNodeList);
OffsetNode offsetNode = new OffsetNode(queryId.genPlanNodeId(), timeJoinNode, 10);
@@ -217,8 +208,6 @@ public class QueryLogicalPlanUtil {
queryId.genPlanNodeId(),
(MeasurementPath) schemaMap.get("root.sg.d1.s2"),
Ordering.DESC));
- sourceNodeList.forEach(
- planNode -> ((SeriesScanNode) planNode).setTimeFilter(TimeFilter.gt(100)));
TimeJoinNode timeJoinNode =
new TimeJoinNode(queryId.genPlanNodeId(), Ordering.DESC, sourceNodeList);
@@ -275,8 +264,6 @@ public class QueryLogicalPlanUtil {
queryId.genPlanNodeId(),
(MeasurementPath) schemaMap.get("root.sg.d1.s2"),
Ordering.DESC));
- sourceNodeList1.forEach(
- planNode -> ((SeriesScanNode) planNode).setTimeFilter(TimeFilter.gt(100)));
TimeJoinNode timeJoinNode1 =
new TimeJoinNode(queryId.genPlanNodeId(), Ordering.DESC, sourceNodeList1);
@@ -316,8 +303,6 @@ public class QueryLogicalPlanUtil {
queryId.genPlanNodeId(),
(MeasurementPath) schemaMap.get("root.sg.d2.s4"),
Ordering.DESC));
- sourceNodeList2.forEach(
- planNode -> ((SeriesScanNode) planNode).setTimeFilter(TimeFilter.gt(100)));
TimeJoinNode timeJoinNode2 =
new TimeJoinNode(queryId.genPlanNodeId(), Ordering.DESC, sourceNodeList2);
@@ -479,14 +464,6 @@ public class QueryLogicalPlanUtil {
new TimeSeriesOperand(schemaMap.get("root.sg.d1.s1"))))),
Ordering.DESC,
null));
- sourceNodeList.forEach(
- node -> {
- if (node instanceof SeriesAggregationScanNode) {
- ((SeriesAggregationScanNode) node).setTimeFilter(timeFilter);
- } else {
- ((AlignedSeriesAggregationScanNode) node).setTimeFilter(timeFilter);
- }
- });
TimeJoinNode timeJoinNode =
new TimeJoinNode(queryId.genPlanNodeId(), Ordering.ASC, sourceNodeList);
@@ -593,14 +570,6 @@ public class QueryLogicalPlanUtil {
new TimeSeriesOperand(schemaMap.get("root.sg.d1.s1"))))),
Ordering.DESC,
null));
- sourceNodeList.forEach(
- node -> {
- if (node instanceof SeriesAggregationScanNode) {
- ((SeriesAggregationScanNode) node).setTimeFilter(timeFilter);
- } else {
- ((AlignedSeriesAggregationScanNode) node).setTimeFilter(timeFilter);
- }
- });
GroupByLevelNode groupByLevelNode =
new GroupByLevelNode(
@@ -706,7 +675,6 @@ public class QueryLogicalPlanUtil {
new TimeSeriesOperand(schemaMap.get("root.sg.d1.s1"))))),
Ordering.DESC,
null));
- sourceNodeList1.forEach(node -> ((SeriesAggregationScanNode) node).setTimeFilter(timeFilter));
TimeJoinNode timeJoinNode1 =
new TimeJoinNode(queryId.genPlanNodeId(), Ordering.DESC, sourceNodeList1);
@@ -741,7 +709,6 @@ public class QueryLogicalPlanUtil {
new TimeSeriesOperand(schemaMap.get("root.sg.d2.s1"))))),
Ordering.DESC,
null));
- sourceNodeList2.forEach(node -> ((SeriesAggregationScanNode) node).setTimeFilter(timeFilter));
TimeJoinNode timeJoinNode2 =
new TimeJoinNode(queryId.genPlanNodeId(), Ordering.DESC, sourceNodeList2);
@@ -797,8 +764,6 @@ public class QueryLogicalPlanUtil {
queryId.genPlanNodeId(),
(MeasurementPath) schemaMap.get("root.sg.d1.s2"),
Ordering.DESC));
- sourceNodeList.forEach(
- planNode -> ((SeriesScanNode) planNode).setTimeFilter(TimeFilter.gt(100)));
TimeJoinNode timeJoinNode =
new TimeJoinNode(queryId.genPlanNodeId(), Ordering.DESC, sourceNodeList);
@@ -925,8 +890,6 @@ public class QueryLogicalPlanUtil {
queryId.genPlanNodeId(),
(MeasurementPath) schemaMap.get("root.sg.d1.s2"),
Ordering.DESC));
- sourceNodeList1.forEach(
- planNode -> ((SeriesScanNode) planNode).setTimeFilter(TimeFilter.gt(100)));
TimeJoinNode timeJoinNode1 =
new TimeJoinNode(queryId.genPlanNodeId(), Ordering.DESC, sourceNodeList1);
@@ -983,8 +946,6 @@ public class QueryLogicalPlanUtil {
queryId.genPlanNodeId(),
(MeasurementPath) schemaMap.get("root.sg.d2.s2"),
Ordering.DESC));
- sourceNodeList2.forEach(
- planNode -> ((SeriesScanNode) planNode).setTimeFilter(TimeFilter.gt(100)));
TimeJoinNode timeJoinNode2 =
new TimeJoinNode(queryId.genPlanNodeId(), Ordering.DESC, sourceNodeList2);
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/distribution/LastQueryTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/distribution/LastQueryTest.java
index 13d1586d475..5f675e41f43 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/distribution/LastQueryTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/distribution/LastQueryTest.java
@@ -209,7 +209,7 @@ public class LastQueryTest {
}
PlanNode root =
- new LastQueryNode(context.getQueryId().genPlanNodeId(), sourceNodeList, null, null, false);
+ new LastQueryNode(context.getQueryId().genPlanNodeId(), sourceNodeList, null, false);
return new LogicalQueryPlan(context, root);
}
}
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/AggregationNodeSerdeTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/AggregationNodeSerdeTest.java
index 16ed58eebf9..2474246e037 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/AggregationNodeSerdeTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/AggregationNodeSerdeTest.java
@@ -22,6 +22,7 @@ import org.apache.iotdb.common.rpc.thrift.TAggregationType;
import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.path.MeasurementPath;
import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory;
import org.apache.iotdb.db.queryengine.plan.expression.leaf.TimeSeriesOperand;
import org.apache.iotdb.db.queryengine.plan.plan.node.PlanNodeDeserializeHelper;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId;
@@ -32,8 +33,6 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.AggregationSt
import org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.GroupByTimeParameter;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
-import org.apache.iotdb.tsfile.read.filter.ValueFilter;
import org.apache.iotdb.tsfile.utils.TimeDuration;
import com.google.common.collect.Sets;
@@ -41,6 +40,7 @@ import org.junit.Test;
import java.nio.ByteBuffer;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -63,8 +63,9 @@ public class AggregationNodeSerdeTest {
Collections.singletonList(
new TimeSeriesOperand(new PartialPath("root.sg.d1.s1"))))),
Ordering.ASC,
- TimeFilter.gt(100L),
- ValueFilter.in(Sets.newHashSet("s1", "s2")),
+ ExpressionFactory.in(
+ ExpressionFactory.timeSeries("root.sg.d1.s1"),
+ Sets.newLinkedHashSet(Arrays.asList("s1", "s2"))),
groupByTimeParameter,
null);
AggregationNode aggregationNode =
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/GroupByLevelNodeSerdeTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/GroupByLevelNodeSerdeTest.java
index fd66caf8e12..7e0027c58cc 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/GroupByLevelNodeSerdeTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/GroupByLevelNodeSerdeTest.java
@@ -33,8 +33,6 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.CrossSeriesAg
import org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.GroupByTimeParameter;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
-import org.apache.iotdb.tsfile.read.filter.ValueFilter;
import org.apache.iotdb.tsfile.utils.TimeDuration;
import org.junit.Test;
@@ -46,6 +44,9 @@ import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collections;
+import static org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory.gt;
+import static org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory.longValue;
+import static org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory.time;
import static org.junit.Assert.assertEquals;
public class GroupByLevelNodeSerdeTest {
@@ -65,8 +66,7 @@ public class GroupByLevelNodeSerdeTest {
Collections.singletonList(
new TimeSeriesOperand(new PartialPath("root.sg.d1.s1"))))),
Ordering.ASC,
- TimeFilter.gt(100L),
- ValueFilter.gt(100),
+ gt(time(), longValue(100)),
groupByTimeParameter,
null);
SeriesAggregationScanNode seriesAggregationScanNode2 =
@@ -80,8 +80,7 @@ public class GroupByLevelNodeSerdeTest {
Collections.singletonList(
new TimeSeriesOperand(new PartialPath("root.sg.d2.s1"))))),
Ordering.ASC,
- TimeFilter.gt(100L),
- ValueFilter.gt(100),
+ gt(time(), longValue(100)),
groupByTimeParameter,
null);
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/GroupByTagNodeSerdeTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/GroupByTagNodeSerdeTest.java
index a5c1db56544..a9a7e638536 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/GroupByTagNodeSerdeTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/GroupByTagNodeSerdeTest.java
@@ -34,8 +34,6 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.CrossSeriesAg
import org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.GroupByTimeParameter;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
-import org.apache.iotdb.tsfile.read.filter.ValueFilter;
import org.apache.iotdb.tsfile.utils.TimeDuration;
import org.junit.Assert;
@@ -52,6 +50,10 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import static org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory.gt;
+import static org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory.longValue;
+import static org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory.time;
+
public class GroupByTagNodeSerdeTest {
@Test
@@ -105,8 +107,7 @@ public class GroupByTagNodeSerdeTest {
new MeasurementPath("root.sg.d1.s1", TSDataType.INT32),
Arrays.asList(s1MaxTimePartial, s1AvgTimePartial),
Ordering.ASC,
- TimeFilter.gt(100L),
- ValueFilter.gt(100),
+ gt(time(), longValue(100)),
groupByTimeParameter,
null)),
groupByTimeParameter,
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/LimitNodeSerdeTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/LimitNodeSerdeTest.java
index 4b8df2b394c..afc1f4599e1 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/LimitNodeSerdeTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/LimitNodeSerdeTest.java
@@ -27,7 +27,6 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.node.process.OffsetNode
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.source.SeriesScanNode;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.filter.GroupByFilter;
import org.junit.Test;
@@ -44,7 +43,6 @@ public class LimitNodeSerdeTest {
new PlanNodeId("TestSeriesScanNode"),
new MeasurementPath("root.sg.d1.s1", TSDataType.INT32),
Ordering.DESC,
- new GroupByFilter(1, 2, 3, 4),
null,
100,
100,
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/OffsetNodeSerdeTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/OffsetNodeSerdeTest.java
index 984a4969f82..740a08eaac6 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/OffsetNodeSerdeTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/OffsetNodeSerdeTest.java
@@ -26,7 +26,6 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.node.process.OffsetNode
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.source.SeriesScanNode;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.filter.GroupByFilter;
import org.junit.Test;
@@ -43,7 +42,6 @@ public class OffsetNodeSerdeTest {
new PlanNodeId("TestSeriesScanNode"),
new MeasurementPath("root.sg.d1.s1", TSDataType.INT32),
Ordering.DESC,
- new GroupByFilter(1, 2, 3, 4),
null,
100,
100,
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/SortNodeSerdeTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/SortNodeSerdeTest.java
index 38341b8f940..280225b52ab 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/SortNodeSerdeTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/SortNodeSerdeTest.java
@@ -29,7 +29,6 @@ import org.apache.iotdb.db.queryengine.plan.statement.component.OrderByKey;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.db.queryengine.plan.statement.component.SortItem;
import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.filter.GroupByFilter;
import com.google.common.collect.ImmutableList;
import org.junit.Test;
@@ -47,7 +46,6 @@ public class SortNodeSerdeTest {
new PlanNodeId("TestSeriesScanNode"),
new MeasurementPath("root.sg.d1.s1", TSDataType.INT32),
Ordering.DESC,
- new GroupByFilter(1, 2, 3, 4),
null,
100,
100,
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/TimeJoinNodeSerdeTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/TimeJoinNodeSerdeTest.java
index 72bb9d31648..4d577196cf6 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/TimeJoinNodeSerdeTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/process/TimeJoinNodeSerdeTest.java
@@ -26,8 +26,6 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.node.process.TimeJoinNo
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.source.SeriesScanNode;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
-import org.apache.iotdb.tsfile.read.filter.ValueFilter;
import org.junit.Test;
@@ -43,7 +41,6 @@ public class TimeJoinNodeSerdeTest {
new PlanNodeId("TestSeriesScanNode"),
new MeasurementPath("root.sg.d1.s1", TSDataType.INT32),
Ordering.DESC,
- TimeFilter.gt(100),
null,
100,
100,
@@ -54,7 +51,6 @@ public class TimeJoinNodeSerdeTest {
new MeasurementPath("root.sg.d1.s2", TSDataType.INT32),
Ordering.DESC,
null,
- ValueFilter.gt(100),
100,
100,
null);
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/source/SeriesAggregationScanNodeSerdeTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/source/SeriesAggregationScanNodeSerdeTest.java
index f768ace4d7d..a13301a6bb4 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/source/SeriesAggregationScanNodeSerdeTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/source/SeriesAggregationScanNodeSerdeTest.java
@@ -32,11 +32,8 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.AggregationSt
import org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.GroupByTimeParameter;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
-import org.apache.iotdb.tsfile.read.filter.ValueFilter;
import org.apache.iotdb.tsfile.utils.TimeDuration;
-import com.google.common.collect.Sets;
import org.junit.Test;
import java.nio.ByteBuffer;
@@ -44,6 +41,9 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import static org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory.gt;
+import static org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory.longValue;
+import static org.apache.iotdb.db.queryengine.plan.expression.ExpressionFactory.time;
import static org.junit.Assert.assertEquals;
public class SeriesAggregationScanNodeSerdeTest {
@@ -63,8 +63,7 @@ public class SeriesAggregationScanNodeSerdeTest {
new MeasurementPath("root.sg.d1.s1", TSDataType.BOOLEAN),
aggregationDescriptorList,
Ordering.ASC,
- TimeFilter.gt(100L),
- ValueFilter.in(Sets.newHashSet("s1", "s2")),
+ gt(time(), longValue(100)),
groupByTimeParameter,
null);
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/source/SeriesScanNodeSerdeTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/source/SeriesScanNodeSerdeTest.java
index df1eb954a69..17535d05217 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/source/SeriesScanNodeSerdeTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/plan/node/source/SeriesScanNodeSerdeTest.java
@@ -26,7 +26,6 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.source.SeriesScanNode;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.filter.GroupByFilter;
import org.junit.Test;
@@ -43,7 +42,6 @@ public class SeriesScanNodeSerdeTest {
new PlanNodeId("TestSeriesScanNode"),
new MeasurementPath("root.sg.d1.s1", TSDataType.INT32),
Ordering.DESC,
- new GroupByFilter(1, 2, 3, 4),
null,
100,
100,
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/view/viewExpression/unary/LikeViewExpression.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/view/viewExpression/unary/LikeViewExpression.java
index b52c3c4021d..916f2420327 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/view/viewExpression/unary/LikeViewExpression.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/view/viewExpression/unary/LikeViewExpression.java
@@ -36,21 +36,27 @@ public class LikeViewExpression extends UnaryViewExpression {
private final String patternString;
private final Pattern pattern;
- public LikeViewExpression(ViewExpression expression, String patternString) {
+ private final boolean isNot;
+
+ public LikeViewExpression(ViewExpression expression, String patternString, boolean isNot) {
super(expression);
this.patternString = patternString;
+ this.isNot = isNot;
pattern = this.compile();
}
- public LikeViewExpression(ViewExpression expression, String patternString, Pattern pattern) {
+ public LikeViewExpression(
+ ViewExpression expression, String patternString, Pattern pattern, boolean isNot) {
super(expression);
this.patternString = patternString;
this.pattern = pattern;
+ this.isNot = isNot;
}
public LikeViewExpression(ByteBuffer byteBuffer) {
super(ViewExpression.deserialize(byteBuffer));
patternString = ReadWriteIOUtils.readString(byteBuffer);
+ isNot = ReadWriteIOUtils.readBool(byteBuffer);
pattern = compile();
}
@@ -58,6 +64,7 @@ public class LikeViewExpression extends UnaryViewExpression {
super(ViewExpression.deserialize(inputStream));
try {
patternString = ReadWriteIOUtils.readString(inputStream);
+ isNot = ReadWriteIOUtils.readBool(inputStream);
pattern = compile();
} catch (IOException e) {
throw new RuntimeException(e);
@@ -78,7 +85,8 @@ public class LikeViewExpression extends UnaryViewExpression {
@Override
public String toString(boolean isRoot) {
- String basicString = this.expression.toString(false) + "LIKE " + this.patternString;
+ String basicString =
+ this.expression.toString(false) + (isNot ? "NOT LIKE " : "LIKE ") + this.patternString;
if (isRoot) {
return basicString;
}
@@ -89,12 +97,14 @@ public class LikeViewExpression extends UnaryViewExpression {
protected void serialize(ByteBuffer byteBuffer) {
super.serialize(byteBuffer);
ReadWriteIOUtils.write(patternString, byteBuffer);
+ ReadWriteIOUtils.write(isNot, byteBuffer);
}
@Override
protected void serialize(OutputStream stream) throws IOException {
super.serialize(stream);
ReadWriteIOUtils.write(patternString, stream);
+ ReadWriteIOUtils.write(isNot, stream);
}
// endregion
@@ -106,6 +116,10 @@ public class LikeViewExpression extends UnaryViewExpression {
return pattern;
}
+ public boolean isNot() {
+ return isNot;
+ }
+
/**
* This Method is for un-escaping strings except '\' before special string '%', '_', '\', because
* we need to use '\' to judge whether to replace this to regexp string
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/view/viewExpression/unary/RegularViewExpression.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/view/viewExpression/unary/RegularViewExpression.java
index b5b1f70207e..f7edef2e7a7 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/view/viewExpression/unary/RegularViewExpression.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/view/viewExpression/unary/RegularViewExpression.java
@@ -38,21 +38,27 @@ public class RegularViewExpression extends UnaryViewExpression {
private final String patternString;
private final Pattern pattern;
- public RegularViewExpression(ViewExpression expression, String patternString) {
+ private final boolean isNot;
+
+ public RegularViewExpression(ViewExpression expression, String patternString, boolean isNot) {
super(expression);
this.patternString = patternString;
+ this.isNot = isNot;
pattern = Pattern.compile(patternString);
}
- public RegularViewExpression(ViewExpression expression, String patternString, Pattern pattern) {
+ public RegularViewExpression(
+ ViewExpression expression, String patternString, Pattern pattern, boolean isNot) {
super(expression);
this.patternString = patternString;
this.pattern = pattern;
+ this.isNot = isNot;
}
public RegularViewExpression(ByteBuffer byteBuffer) {
super(ViewExpression.deserialize(byteBuffer));
patternString = ReadWriteIOUtils.readString(byteBuffer);
+ isNot = ReadWriteIOUtils.readBool(byteBuffer);
pattern = Pattern.compile(Validate.notNull(patternString));
}
@@ -60,6 +66,7 @@ public class RegularViewExpression extends UnaryViewExpression {
super(ViewExpression.deserialize(inputStream));
try {
patternString = ReadWriteIOUtils.readString(inputStream);
+ isNot = ReadWriteIOUtils.readBool(inputStream);
pattern = Pattern.compile(Validate.notNull(patternString));
} catch (IOException e) {
throw new RuntimeException(e);
@@ -80,19 +87,26 @@ public class RegularViewExpression extends UnaryViewExpression {
@Override
public String toString(boolean isRoot) {
- return "REGULAR(" + this.expression.toString() + ", " + this.patternString + ")";
+ return (isNot ? "NOT " : "")
+ + "REGULAR("
+ + this.expression.toString()
+ + ", "
+ + this.patternString
+ + ")";
}
@Override
protected void serialize(ByteBuffer byteBuffer) {
super.serialize(byteBuffer);
ReadWriteIOUtils.write(patternString, byteBuffer);
+ ReadWriteIOUtils.write(isNot, byteBuffer);
}
@Override
protected void serialize(OutputStream stream) throws IOException {
super.serialize(stream);
ReadWriteIOUtils.write(patternString, stream);
+ ReadWriteIOUtils.write(isNot, stream);
}
// endregion
public String getPatternString() {
@@ -102,4 +116,8 @@ public class RegularViewExpression extends UnaryViewExpression {
public Pattern getPattern() {
return pattern;
}
+
+ public boolean isNot() {
+ return isNot;
+ }
}
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/SerializeUtils.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/SerializeUtils.java
index d7126b8e185..ced3674ad42 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/SerializeUtils.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/SerializeUtils.java
@@ -24,7 +24,6 @@ import org.apache.iotdb.tsfile.enums.TSDataType;
import org.apache.iotdb.tsfile.read.TimeValuePair;
import org.apache.iotdb.tsfile.read.common.BatchData;
import org.apache.iotdb.tsfile.read.common.BatchData.BatchDataType;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
import org.apache.iotdb.tsfile.utils.Binary;
import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
import org.apache.iotdb.tsfile.utils.TsPrimitiveType;
@@ -508,13 +507,6 @@ public class SerializeUtils {
}
}
- public static ByteBuffer serializeFilter(Filter filter) {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
- filter.serialize(dataOutputStream);
- return ByteBuffer.wrap(byteArrayOutputStream.toByteArray());
- }
-
public static void serializeObject(Object object, DataOutputStream dataOutputStream) {
ReadWriteIOUtils.writeObject(object, dataOutputStream);
}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/TimeRange.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/TimeRange.java
index 77ddb5ad60e..0d16170c89b 100644
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/TimeRange.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/TimeRange.java
@@ -22,7 +22,7 @@ package org.apache.iotdb.tsfile.read.common;
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.GlobalTimeExpression;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
+import org.apache.iotdb.tsfile.read.filter.factory.TimeFilter;
import java.util.ArrayList;
import java.util.Collections;
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/IExpression.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/IExpression.java
index 6cfd38144db..e6bda25dbfd 100644
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/IExpression.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/IExpression.java
@@ -19,14 +19,7 @@
package org.apache.iotdb.tsfile.read.expression;
-import java.io.Serializable;
-import java.nio.ByteBuffer;
-
-public interface IExpression extends Serializable {
+public interface IExpression {
ExpressionType getType();
-
- IExpression clone();
-
- void serialize(ByteBuffer byteBuffer);
}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/QueryExpression.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/QueryExpression.java
index 0ffd923d8ed..1ce2be946d7 100644
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/QueryExpression.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/QueryExpression.java
@@ -22,11 +22,10 @@ package org.apache.iotdb.tsfile.read.expression;
import org.apache.iotdb.tsfile.enums.TSDataType;
import org.apache.iotdb.tsfile.read.common.Path;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-public class QueryExpression implements Serializable {
+public class QueryExpression {
private List<Path> selectedSeries;
private List<TSDataType> dataTypes;
@@ -78,14 +77,12 @@ public class QueryExpression implements Serializable {
@Override
public String toString() {
- StringBuilder stringBuilder =
- new StringBuilder("\n\t[Selected Series]:")
- .append(selectedSeries)
- .append("\n\t[TSDataType]:")
- .append(dataTypes)
- .append("\n\t[expression]:")
- .append(expression);
- return stringBuilder.toString();
+ return "\n\t[Selected Series]:"
+ + selectedSeries
+ + "\n\t[TSDataType]:"
+ + dataTypes
+ + "\n\t[expression]:"
+ + expression;
}
public boolean hasQueryFilter() {
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/impl/BinaryExpression.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/impl/BinaryExpression.java
index d98fcaba3c3..c4721a6e039 100644
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/impl/BinaryExpression.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/impl/BinaryExpression.java
@@ -22,15 +22,10 @@ package org.apache.iotdb.tsfile.read.expression.impl;
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.utils.ReadWriteIOUtils;
-import java.io.Serializable;
-import java.nio.ByteBuffer;
import java.util.Objects;
-public abstract class BinaryExpression implements IBinaryExpression, Serializable {
-
- private static final long serialVersionUID = -711801318534904452L;
+public abstract class BinaryExpression implements IBinaryExpression {
public static AndExpression and(IExpression left, IExpression right) {
return new AndExpression(left, right);
@@ -40,109 +35,74 @@ public abstract class BinaryExpression implements IBinaryExpression, Serializabl
return new OrExpression(left, right);
}
+ protected IExpression left;
+ protected IExpression right;
+
+ protected BinaryExpression(IExpression left, IExpression right) {
+ this.left = left;
+ this.right = right;
+ }
+
@Override
- public abstract IExpression clone();
+ public IExpression getLeft() {
+ return left;
+ }
- protected static class AndExpression extends BinaryExpression {
+ @Override
+ public IExpression getRight() {
+ return right;
+ }
- private IExpression left;
- private IExpression right;
+ @Override
+ public void setLeft(IExpression leftExpression) {
+ this.left = leftExpression;
+ }
- public AndExpression(IExpression left, IExpression right) {
- this.left = left;
- this.right = right;
- }
+ @Override
+ public void setRight(IExpression rightExpression) {
+ this.right = rightExpression;
+ }
- @Override
- public IExpression getLeft() {
- return left;
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
}
- @Override
- public IExpression getRight() {
- return right;
+ if (o == null || getClass() != o.getClass()) {
+ return false;
}
- @Override
- public void setLeft(IExpression leftExpression) {
- this.left = leftExpression;
- }
+ AndExpression that = (AndExpression) o;
+ return Objects.equals(toString(), that.toString());
+ }
- @Override
- public void setRight(IExpression rightExpression) {
- this.right = rightExpression;
- }
+ @Override
+ public int hashCode() {
+ return Objects.hash(toString());
+ }
- @Override
- public ExpressionType getType() {
- return ExpressionType.AND;
- }
+ private static class AndExpression extends BinaryExpression {
- @Override
- public IExpression clone() {
- return new AndExpression(left.clone(), right.clone());
+ public AndExpression(IExpression left, IExpression right) {
+ super(left, right);
}
@Override
- public void serialize(ByteBuffer byteBuffer) {
- ReadWriteIOUtils.write((byte) getType().ordinal(), byteBuffer);
- left.serialize(byteBuffer);
- right.serialize(byteBuffer);
+ public ExpressionType getType() {
+ return ExpressionType.AND;
}
@Override
public String toString() {
return "[" + left + " && " + right + "]";
}
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
-
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- AndExpression that = (AndExpression) o;
- return Objects.equals(toString(), that.toString());
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(toString());
- }
}
- protected static class OrExpression extends BinaryExpression {
-
- private IExpression left;
- private IExpression right;
+ private static class OrExpression extends BinaryExpression {
public OrExpression(IExpression left, IExpression right) {
- this.left = left;
- this.right = right;
- }
-
- @Override
- public IExpression getLeft() {
- return left;
- }
-
- @Override
- public IExpression getRight() {
- return right;
- }
-
- @Override
- public void setLeft(IExpression leftExpression) {
- this.left = leftExpression;
- }
-
- @Override
- public void setRight(IExpression rightExpression) {
- this.right = rightExpression;
+ super(left, right);
}
@Override
@@ -150,40 +110,9 @@ public abstract class BinaryExpression implements IBinaryExpression, Serializabl
return ExpressionType.OR;
}
- @Override
- public IExpression clone() {
- return new OrExpression(left.clone(), right.clone());
- }
-
- @Override
- public void serialize(ByteBuffer byteBuffer) {
- ReadWriteIOUtils.write((byte) getType().ordinal(), byteBuffer);
- left.serialize(byteBuffer);
- right.serialize(byteBuffer);
- }
-
@Override
public String toString() {
return "[" + left + " || " + right + "]";
}
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
-
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- OrExpression that = (OrExpression) o;
- return Objects.equals(toString(), that.toString());
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(toString());
- }
}
}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/impl/GlobalTimeExpression.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/impl/GlobalTimeExpression.java
index 7ef8a26b4a2..3096263b61d 100644
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/impl/GlobalTimeExpression.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/impl/GlobalTimeExpression.java
@@ -20,19 +20,13 @@
package org.apache.iotdb.tsfile.read.expression.impl;
import org.apache.iotdb.tsfile.read.expression.ExpressionType;
-import org.apache.iotdb.tsfile.read.expression.IExpression;
import org.apache.iotdb.tsfile.read.expression.IUnaryExpression;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
-import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
-import java.io.Serializable;
-import java.nio.ByteBuffer;
import java.util.Objects;
-public class GlobalTimeExpression implements IUnaryExpression, Serializable {
+public class GlobalTimeExpression implements IUnaryExpression {
- private static final long serialVersionUID = 1146132942359113670L;
private Filter filter;
public GlobalTimeExpression(Filter filter) {
@@ -54,21 +48,6 @@ public class GlobalTimeExpression implements IUnaryExpression, Serializable {
return ExpressionType.GLOBAL_TIME;
}
- @Override
- public IExpression clone() {
- return new GlobalTimeExpression(filter.copy());
- }
-
- @Override
- public void serialize(ByteBuffer byteBuffer) {
- ReadWriteIOUtils.write((byte) getType().ordinal(), byteBuffer);
- filter.serialize(byteBuffer);
- }
-
- public static GlobalTimeExpression deserialize(ByteBuffer byteBuffer) {
- return new GlobalTimeExpression(FilterFactory.deserialize(byteBuffer));
- }
-
@Override
public String toString() {
return "[" + this.filter + "]";
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/impl/SingleSeriesExpression.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/impl/SingleSeriesExpression.java
index 81f79ca7e3a..ece71630695 100644
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/impl/SingleSeriesExpression.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/expression/impl/SingleSeriesExpression.java
@@ -21,18 +21,13 @@ package org.apache.iotdb.tsfile.read.expression.impl;
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.IUnaryExpression;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
-import java.io.Serializable;
-import java.nio.ByteBuffer;
import java.util.Objects;
-public class SingleSeriesExpression implements IUnaryExpression, Serializable {
+public class SingleSeriesExpression implements IUnaryExpression {
- private static final long serialVersionUID = 7131207370394865228L;
private Path seriesPath;
private Filter filter;
@@ -46,18 +41,6 @@ public class SingleSeriesExpression implements IUnaryExpression, Serializable {
return ExpressionType.SERIES;
}
- @Override
- public IExpression clone() {
- return new SingleSeriesExpression(seriesPath.clone(), filter.copy());
- }
-
- @Override
- public void serialize(ByteBuffer byteBuffer) {
- ReadWriteIOUtils.write((byte) getType().ordinal(), byteBuffer);
- seriesPath.serialize(byteBuffer);
- filter.serialize(byteBuffer);
- }
-
@Override
public Filter getFilter() {
return filter;
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/PredicateRemoveNotRewriter.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/PredicateRemoveNotRewriter.java
index b100d93f5dc..107f697359b 100644
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/PredicateRemoveNotRewriter.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/PredicateRemoveNotRewriter.java
@@ -21,15 +21,14 @@ package org.apache.iotdb.tsfile.read.filter;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import org.apache.iotdb.tsfile.read.filter.operator.AndFilter;
-import org.apache.iotdb.tsfile.read.filter.operator.NotFilter;
-import org.apache.iotdb.tsfile.read.filter.operator.OrFilter;
+import org.apache.iotdb.tsfile.read.filter.operator.And;
+import org.apache.iotdb.tsfile.read.filter.operator.Not;
+import org.apache.iotdb.tsfile.read.filter.operator.Or;
public class PredicateRemoveNotRewriter {
private PredicateRemoveNotRewriter() {
- // forbidden to construct
+ // forbidden construction
}
public static Filter rewrite(Filter filter) {
@@ -37,18 +36,15 @@ public class PredicateRemoveNotRewriter {
}
private static Filter removeNot(Filter filter) {
- FilterSerializeId filterType = filter.getSerializeId();
- switch (filterType) {
- case AND:
- return FilterFactory.and(
- removeNot(((AndFilter) filter).getLeft()), removeNot(((AndFilter) filter).getRight()));
- case OR:
- return FilterFactory.or(
- removeNot(((OrFilter) filter).getLeft()), removeNot(((OrFilter) filter).getRight()));
- case NOT:
- return ((NotFilter) filter).getFilter().reverse();
- default:
- return filter;
+ if (filter instanceof And) {
+ return FilterFactory.and(
+ removeNot(((And) filter).getLeft()), removeNot(((And) filter).getRight()));
+ } else if (filter instanceof Or) {
+ return FilterFactory.or(
+ removeNot(((Or) filter).getLeft()), removeNot(((Or) filter).getRight()));
+ } else if (filter instanceof Not) {
+ return ((Not) filter).getFilter().reverse();
}
+ return filter;
}
}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/TimeFilter.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/TimeFilter.java
deleted file mode 100644
index 33297dfd79b..00000000000
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/TimeFilter.java
+++ /dev/null
@@ -1,321 +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.tsfile.read.filter;
-
-import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
-import org.apache.iotdb.tsfile.read.common.TimeRange;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
-import org.apache.iotdb.tsfile.read.filter.operator.Between;
-import org.apache.iotdb.tsfile.read.filter.operator.Eq;
-import org.apache.iotdb.tsfile.read.filter.operator.Gt;
-import org.apache.iotdb.tsfile.read.filter.operator.GtEq;
-import org.apache.iotdb.tsfile.read.filter.operator.In;
-import org.apache.iotdb.tsfile.read.filter.operator.Lt;
-import org.apache.iotdb.tsfile.read.filter.operator.LtEq;
-import org.apache.iotdb.tsfile.read.filter.operator.NotEq;
-import org.apache.iotdb.tsfile.read.filter.operator.OrFilter;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-public class TimeFilter {
-
- private TimeFilter() {}
-
- public static TimeGt gt(long value) {
- return new TimeGt(value);
- }
-
- public static TimeGtEq gtEq(long value) {
- return new TimeGtEq(value);
- }
-
- public static TimeLt lt(long value) {
- return new TimeLt(value);
- }
-
- public static TimeLtEq ltEq(long value) {
- return new TimeLtEq(value);
- }
-
- public static TimeEq eq(long value) {
- return new TimeEq(value);
- }
-
- public static TimeNotEq notEq(long value) {
- return new TimeNotEq(value);
- }
-
- public static TimeBetween between(long value1, long value2) {
- return new TimeBetween(value1, value2, false);
- }
-
- public static TimeBetween notBetween(long value1, long value2) {
- return new TimeBetween(value1, value2, true);
- }
-
- public static TimeIn in(Set<Long> values) {
- return new TimeIn(values, false);
- }
-
- public static TimeIn notIn(Set<Long> values) {
- return new TimeIn(values, true);
- }
-
- public static class TimeGt extends Gt<Long> {
-
- private TimeGt(long value) {
- super(value, FilterType.TIME_FILTER);
- }
-
- @Override
- public List<TimeRange> getTimeRanges() {
- long left = value;
- if (left != Long.MAX_VALUE) {
- return Collections.singletonList(new TimeRange(left + 1, Long.MAX_VALUE));
- } else {
- return Collections.emptyList();
- }
- }
- }
-
- public static class TimeGtEq extends GtEq<Long> {
-
- private TimeGtEq(long value) {
- super(value, FilterType.TIME_FILTER);
- }
-
- @Override
- public List<TimeRange> getTimeRanges() {
- return Collections.singletonList(new TimeRange(value, Long.MAX_VALUE));
- }
- }
-
- public static class TimeLt extends Lt<Long> {
-
- private TimeLt(long value) {
- super(value, FilterType.TIME_FILTER);
- }
-
- @Override
- public List<TimeRange> getTimeRanges() {
- long right = value;
- if (right != Long.MIN_VALUE) {
- return Collections.singletonList(new TimeRange(Long.MIN_VALUE, right - 1));
- } else {
- return Collections.emptyList();
- }
- }
- }
-
- public static class TimeLtEq extends LtEq<Long> {
-
- private TimeLtEq(long value) {
- super(value, FilterType.TIME_FILTER);
- }
-
- @Override
- public List<TimeRange> getTimeRanges() {
- return Collections.singletonList(new TimeRange(Long.MIN_VALUE, value));
- }
- }
-
- public static class TimeEq extends Eq<Long> {
-
- private TimeEq(long value) {
- super(value, FilterType.TIME_FILTER);
- }
-
- @Override
- public List<TimeRange> getTimeRanges() {
- return Collections.singletonList(new TimeRange(value, value));
- }
- }
-
- public static class TimeNotEq extends NotEq<Long> {
-
- private TimeNotEq(long value) {
- super(value, FilterType.TIME_FILTER);
- }
-
- @Override
- public List<TimeRange> getTimeRanges() {
- long time = value;
- if (time == Long.MIN_VALUE) {
- return Collections.singletonList(new TimeRange(time + 1, Long.MAX_VALUE));
- } else if (time == Long.MAX_VALUE) {
- return Collections.singletonList(new TimeRange(Long.MIN_VALUE, time - 1));
- } else {
- return Arrays.asList(
- new TimeRange(Long.MIN_VALUE, time - 1), new TimeRange(time + 1, Long.MAX_VALUE));
- }
- }
- }
-
- public static class TimeBetween extends Between<Long> {
-
- private TimeBetween(long value1, long value2, boolean not) {
- super(value1, value2, FilterType.TIME_FILTER, not);
- }
-
- @Override
- public List<TimeRange> getTimeRanges() {
- long left = value1;
- long right = value2;
- if (not) {
- List<TimeRange> res = new ArrayList<>();
- if (left != Long.MIN_VALUE) {
- res.add(new TimeRange(Long.MIN_VALUE, left - 1));
- }
- if (right != Long.MAX_VALUE) {
- res.add(new TimeRange(right + 1, Long.MAX_VALUE));
- }
- return res;
- } else {
- return Collections.singletonList(new TimeRange(left, right));
- }
- }
- }
-
- public static class TimeIn extends In<Long> {
-
- private TimeIn(Set<Long> values, boolean not) {
- super(values, FilterType.TIME_FILTER, not);
- }
-
- @Override
- public List<TimeRange> getTimeRanges() {
- if (not) {
- return Collections.singletonList(new TimeRange(Long.MIN_VALUE, Long.MAX_VALUE));
- } else {
- return values.stream()
- .map(
- l -> {
- long time = l;
- return new TimeRange(time, time);
- })
- .collect(Collectors.toList());
- }
- }
- }
-
- /**
- * returns a default time filter by whether it's an ascending query.
- *
- * <p>If the data is read in descending order, we use the largest timestamp to set to the filter,
- * so the filter should be TimeLtEq. If the data is read in ascending order, we use the smallest
- * timestamp to set to the filter, so the filter should be TimeGtEq.
- */
- public static Filter defaultTimeFilter(boolean ascending) {
- return ascending ? TimeFilter.gtEq(Long.MIN_VALUE) : TimeFilter.ltEq(Long.MAX_VALUE);
- }
-
- public static class TimeGtEqAndLt implements Filter {
-
- private long startTime;
-
- private long endTime;
-
- public TimeGtEqAndLt() {}
-
- public TimeGtEqAndLt(long startTime, long endTime) {
- this.startTime = startTime;
- this.endTime = endTime;
- }
-
- @Override
- public boolean satisfy(Statistics statistics) {
- return !(statistics.getEndTime() < startTime || statistics.getStartTime() >= endTime);
- }
-
- @Override
- public boolean allSatisfy(Statistics statistics) {
- return startTime <= statistics.getStartTime() && statistics.getEndTime() < endTime;
- }
-
- @Override
- public boolean satisfy(long time, Object value) {
- return startTime <= time && time < endTime;
- }
-
- @Override
- public boolean satisfyStartEndTime(long startTime, long endTime) {
- return !(endTime < this.startTime || startTime >= this.endTime);
- }
-
- @Override
- public boolean containStartEndTime(long startTime, long endTime) {
- return this.startTime <= startTime && endTime < this.endTime;
- }
-
- @Override
- public Filter copy() {
- return new TimeGtEqAndLt(startTime, endTime);
- }
-
- @Override
- public String toString() {
- return "TimeGtEqAndLt{" + "startTime=" + startTime + ", endTime=" + endTime + '}';
- }
-
- @Override
- public void serialize(DataOutputStream outputStream) {
- try {
- outputStream.write(getSerializeId().ordinal());
- outputStream.writeLong(startTime);
- outputStream.writeLong(endTime);
- } catch (IOException ignored) {
- // ignored
- }
- }
-
- @Override
- public void deserialize(ByteBuffer buffer) {
- startTime = buffer.getLong();
- endTime = buffer.getLong();
- }
-
- @Override
- public FilterSerializeId getSerializeId() {
- return FilterSerializeId.TIME_GTEQ_AND_LT;
- }
-
- @Override
- public List<TimeRange> getTimeRanges() {
- return startTime >= endTime
- ? Collections.emptyList()
- : Collections.singletonList(new TimeRange(startTime, endTime - 1));
- }
-
- @Override
- public Filter reverse() {
- return new OrFilter(new TimeLt(startTime), new TimeGtEq(endTime));
- }
- }
-}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/ValueFilter.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/ValueFilter.java
deleted file mode 100644
index 23d091f547c..00000000000
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/ValueFilter.java
+++ /dev/null
@@ -1,164 +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.tsfile.read.filter;
-
-import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
-import org.apache.iotdb.tsfile.read.filter.operator.Between;
-import org.apache.iotdb.tsfile.read.filter.operator.Eq;
-import org.apache.iotdb.tsfile.read.filter.operator.Gt;
-import org.apache.iotdb.tsfile.read.filter.operator.GtEq;
-import org.apache.iotdb.tsfile.read.filter.operator.In;
-import org.apache.iotdb.tsfile.read.filter.operator.Like;
-import org.apache.iotdb.tsfile.read.filter.operator.Lt;
-import org.apache.iotdb.tsfile.read.filter.operator.LtEq;
-import org.apache.iotdb.tsfile.read.filter.operator.NotEq;
-import org.apache.iotdb.tsfile.read.filter.operator.Regexp;
-
-import java.util.Set;
-
-public class ValueFilter {
-
- private ValueFilter() {}
-
- public static <T extends Comparable<T>> ValueGt<T> gt(T value) {
- return new ValueGt<>(value);
- }
-
- public static <T extends Comparable<T>> ValueGtEq<T> gtEq(T value) {
- return new ValueGtEq<>(value);
- }
-
- public static <T extends Comparable<T>> ValueLt<T> lt(T value) {
- return new ValueLt<>(value);
- }
-
- public static <T extends Comparable<T>> ValueLtEq<T> ltEq(T value) {
- return new ValueLtEq<>(value);
- }
-
- public static <T extends Comparable<T>> ValueEq<T> eq(T value) {
- return new ValueEq<>(value);
- }
-
- public static <T extends Comparable<T>> ValueNotEq<T> notEq(T value) {
- return new ValueNotEq<>(value);
- }
-
- public static <T extends Comparable<T>> ValueBetween<T> between(T value1, T value2) {
- return new ValueBetween<>(value1, value2, false);
- }
-
- public static <T extends Comparable<T>> ValueBetween<T> notBetween(T value1, T value2) {
- return new ValueBetween<>(value1, value2, true);
- }
-
- public static <T extends Comparable<T>> ValueLike<T> like(String value) {
- return new ValueLike<>(value, false);
- }
-
- public static <T extends Comparable<T>> ValueLike<T> notLike(String value) {
- return new ValueLike<>(value, true);
- }
-
- public static <T extends Comparable<T>> ValueRegexp<T> regexp(String value) {
- return new ValueRegexp<>(value, false);
- }
-
- public static <T extends Comparable<T>> ValueRegexp<T> notRegexp(String value) {
- return new ValueRegexp<>(value, true);
- }
-
- public static <T extends Comparable<T>> ValueIn<T> in(Set<T> values) {
- return new ValueIn<>(values, false);
- }
-
- public static <T extends Comparable<T>> ValueIn<T> notIn(Set<T> values) {
- return new ValueIn<>(values, true);
- }
-
- public static class ValueGt<T extends Comparable<T>> extends Gt<T> {
-
- private ValueGt(T value) {
- super(value, FilterType.VALUE_FILTER);
- }
- }
-
- public static class ValueGtEq<T extends Comparable<T>> extends GtEq<T> {
-
- private ValueGtEq(T value) {
- super(value, FilterType.VALUE_FILTER);
- }
- }
-
- public static class ValueLt<T extends Comparable<T>> extends Lt<T> {
-
- private ValueLt(T value) {
- super(value, FilterType.VALUE_FILTER);
- }
- }
-
- public static class ValueLtEq<T extends Comparable<T>> extends LtEq<T> {
-
- private ValueLtEq(T value) {
- super(value, FilterType.VALUE_FILTER);
- }
- }
-
- public static class ValueEq<T extends Comparable<T>> extends Eq<T> {
-
- private ValueEq(T value) {
- super(value, FilterType.VALUE_FILTER);
- }
- }
-
- public static class ValueNotEq<T extends Comparable<T>> extends NotEq<T> {
-
- private ValueNotEq(T value) {
- super(value, FilterType.VALUE_FILTER);
- }
- }
-
- public static class ValueBetween<T extends Comparable<T>> extends Between<T> {
-
- private ValueBetween(T value1, T value2, boolean not) {
- super(value1, value2, FilterType.VALUE_FILTER, not);
- }
- }
-
- public static class ValueLike<T extends Comparable<T>> extends Like<T> {
-
- private ValueLike(String value, boolean not) {
- super(value, FilterType.VALUE_FILTER, not);
- }
- }
-
- public static class ValueRegexp<T extends Comparable<T>> extends Regexp<T> {
- private ValueRegexp(String value, boolean not) {
- super(value, FilterType.VALUE_FILTER, not);
- }
- }
-
- public static class ValueIn<T extends Comparable<T>> extends In<T> {
-
- private ValueIn(Set<T> values, boolean not) {
- super(values, FilterType.VALUE_FILTER, not);
- }
- }
-}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/BinaryFilter.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/BinaryFilter.java
deleted file mode 100755
index ba4eeca8a34..00000000000
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/BinaryFilter.java
+++ /dev/null
@@ -1,95 +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.tsfile.read.filter.basic;
-
-import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.Serializable;
-import java.nio.ByteBuffer;
-import java.util.Objects;
-
-/** Definition for binary filter operations. */
-public abstract class BinaryFilter implements Filter, Serializable {
-
- private static final long serialVersionUID = 1039585564327602465L;
-
- protected Filter left;
- protected Filter right;
-
- protected BinaryFilter() {
- // do nothing
- }
-
- protected BinaryFilter(Filter left, Filter right) {
- this.left = left;
- this.right = right;
- }
-
- public void setLeft(Filter left) {
- this.left = left;
- }
-
- public Filter getLeft() {
- return left;
- }
-
- public void setRight(Filter right) {
- this.right = right;
- }
-
- public Filter getRight() {
- return right;
- }
-
- @Override
- public void serialize(DataOutputStream outputStream) {
- try {
- outputStream.write(getSerializeId().ordinal());
- left.serialize(outputStream);
- right.serialize(outputStream);
- } catch (IOException ignored) {
- // ignore
- }
- }
-
- @Override
- public void deserialize(ByteBuffer buffer) {
- left = FilterFactory.deserialize(buffer);
- right = FilterFactory.deserialize(buffer);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof BinaryFilter)) {
- return false;
- }
- BinaryFilter other = ((BinaryFilter) obj);
- return this.left.equals(other.left)
- && this.right.equals(other.right)
- && this.getSerializeId().equals(other.getSerializeId());
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(left, right, getSerializeId());
- }
-}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterType.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/BinaryLogicalFilter.java
similarity index 53%
copy from iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterType.java
copy to iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/BinaryLogicalFilter.java
index 2b7ad8f9c37..c4bd9548ab1 100644
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterType.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/BinaryLogicalFilter.java
@@ -17,21 +17,37 @@
* under the License.
*/
-package org.apache.iotdb.tsfile.read.filter.factory;
+package org.apache.iotdb.tsfile.read.filter.basic;
-public enum FilterType {
- VALUE_FILTER("value"),
- TIME_FILTER("time"),
- GROUP_BY_FILTER("group by");
+import java.util.Locale;
+import java.util.Objects;
- private String name;
+/* base class for And, Or */
+public abstract class BinaryLogicalFilter implements Filter {
- FilterType(String name) {
- this.name = name;
+ protected final Filter left;
+ protected final Filter right;
+
+ private final String toString;
+
+ protected BinaryLogicalFilter(Filter left, Filter right) {
+ this.left = Objects.requireNonNull(left, "left cannot be null");
+ this.right = Objects.requireNonNull(right, "right cannot be null");
+
+ String name = getClass().getSimpleName().toLowerCase(Locale.ENGLISH);
+ this.toString = name + "(" + left + ", " + right + ")";
+ }
+
+ public Filter getLeft() {
+ return left;
+ }
+
+ public Filter getRight() {
+ return right;
}
@Override
public String toString() {
- return name;
+ return toString;
}
}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterType.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/ColumnCompareFilter.java
similarity index 63%
copy from iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterType.java
copy to iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/ColumnCompareFilter.java
index 2b7ad8f9c37..3d303d0d433 100644
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterType.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/ColumnCompareFilter.java
@@ -17,21 +17,16 @@
* under the License.
*/
-package org.apache.iotdb.tsfile.read.filter.factory;
+package org.apache.iotdb.tsfile.read.filter.basic;
-public enum FilterType {
- VALUE_FILTER("value"),
- TIME_FILTER("time"),
- GROUP_BY_FILTER("group by");
+/* base class for Eq, NotEq, Lt, Gt, LtEq, GtEq */
+public abstract class ColumnCompareFilter<T extends Comparable<T>> implements Filter {
- private String name;
+ protected final T constant;
- FilterType(String name) {
- this.name = name;
- }
-
- @Override
- public String toString() {
- return name;
+ protected ColumnCompareFilter(T constant) {
+ // ValueEq and ValueNotEq allow constant to be null, TimeEq, TimeEq, Lt, Gt, LtEq, GtEq however
+ // do not, so they guard against null in their own constructors.
+ this.constant = constant;
}
}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterType.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/ColumnPatternMatchFilter.java
similarity index 55%
copy from iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterType.java
copy to iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/ColumnPatternMatchFilter.java
index 2b7ad8f9c37..656403e6788 100644
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterType.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/ColumnPatternMatchFilter.java
@@ -17,21 +17,24 @@
* under the License.
*/
-package org.apache.iotdb.tsfile.read.filter.factory;
+package org.apache.iotdb.tsfile.read.filter.basic;
-public enum FilterType {
- VALUE_FILTER("value"),
- TIME_FILTER("time"),
- GROUP_BY_FILTER("group by");
+import java.util.Objects;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
- private String name;
+/* base class for Like, NotLike, Regex, NotRegex */
+public abstract class ColumnPatternMatchFilter implements Filter {
- FilterType(String name) {
- this.name = name;
- }
+ protected final String regex;
+ protected final Pattern pattern;
- @Override
- public String toString() {
- return name;
+ protected ColumnPatternMatchFilter(String regex) {
+ this.regex = Objects.requireNonNull(regex, "regex cannot be null");
+ try {
+ this.pattern = Pattern.compile(regex);
+ } catch (PatternSyntaxException e) {
+ throw new PatternSyntaxException("Regular expression error", regex, e.getIndex());
+ }
}
}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterSerializeId.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/ColumnRangeFilter.java
similarity index 64%
rename from iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterSerializeId.java
rename to iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/ColumnRangeFilter.java
index 912bc9f3360..dc04fb3a6fe 100644
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterSerializeId.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/ColumnRangeFilter.java
@@ -17,23 +17,18 @@
* under the License.
*/
-package org.apache.iotdb.tsfile.read.filter.factory;
+package org.apache.iotdb.tsfile.read.filter.basic;
-public enum FilterSerializeId {
- AND,
- EQ,
- GROUP_BY,
- GROUP_BY_MONTH,
- GT,
- GTEQ,
- LT,
- LTEQ,
- NEQ,
- NOT,
- OR,
- IN,
- REGEXP,
- LIKE,
- BETWEEN,
- TIME_GTEQ_AND_LT
+import java.util.Objects;
+
+/* base class for BetweenAnd, NotBetweenAnd */
+public abstract class ColumnRangeFilter<T extends Comparable<T>> implements Filter {
+
+ protected final T min;
+ protected final T max;
+
+ protected ColumnRangeFilter(T min, T max) {
+ this.min = Objects.requireNonNull(min, "min cannot be null");
+ this.max = Objects.requireNonNull(max, "max cannot be null");
+ }
}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterType.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/ColumnSetFilter.java
similarity index 68%
rename from iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterType.java
rename to iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/ColumnSetFilter.java
index 2b7ad8f9c37..5382a405f72 100644
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterType.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/ColumnSetFilter.java
@@ -17,21 +17,17 @@
* under the License.
*/
-package org.apache.iotdb.tsfile.read.filter.factory;
+package org.apache.iotdb.tsfile.read.filter.basic;
-public enum FilterType {
- VALUE_FILTER("value"),
- TIME_FILTER("time"),
- GROUP_BY_FILTER("group by");
+import java.util.Objects;
+import java.util.Set;
- private String name;
+/* base class for In, NotIn */
+public abstract class ColumnSetFilter<T extends Comparable<T>> implements Filter {
- FilterType(String name) {
- this.name = name;
- }
+ protected final Set<T> candidates;
- @Override
- public String toString() {
- return name;
+ protected ColumnSetFilter(Set<T> candidates) {
+ this.candidates = Objects.requireNonNull(candidates, "candidates cannot be null");
}
}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/Filter.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/Filter.java
index 85fa3a09244..743c7705871 100755
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/Filter.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/Filter.java
@@ -21,11 +21,7 @@ package org.apache.iotdb.tsfile.read.filter.basic;
import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
import org.apache.iotdb.tsfile.read.common.TimeRange;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
-import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;
@@ -70,21 +66,6 @@ public interface Filter {
*/
boolean containStartEndTime(long startTime, long endTime);
- Filter copy();
-
- void serialize(DataOutputStream outputStream);
-
- default void serialize(ByteBuffer buffer) {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
- this.serialize(dataOutputStream);
- buffer.put(byteArrayOutputStream.toByteArray());
- }
-
- void deserialize(ByteBuffer buffer);
-
- FilterSerializeId getSerializeId();
-
default List<TimeRange> getTimeRanges() {
return Collections.emptyList();
}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/UnaryFilter.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/UnaryFilter.java
deleted file mode 100755
index 14e47bd1941..00000000000
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/basic/UnaryFilter.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.tsfile.read.filter.basic;
-
-import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
-import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.Serializable;
-import java.nio.ByteBuffer;
-import java.util.Objects;
-
-/**
- * Definition for unary filter operations.
- *
- * @param <T> comparable data type
- */
-public abstract class UnaryFilter<T extends Comparable<T>> implements Filter, Serializable {
-
- private static final long serialVersionUID = 1431606024929453556L;
- protected T value;
-
- protected FilterType filterType;
-
- protected UnaryFilter() {}
-
- protected UnaryFilter(T value, FilterType filterType) {
- this.value = value;
- this.filterType = filterType;
- }
-
- public T getValue() {
- return value;
- }
-
- public void setValue(T value) {
- this.value = value;
- }
-
- public FilterType getFilterType() {
- return filterType;
- }
-
- @Override
- public abstract String toString();
-
- @Override
- public void serialize(DataOutputStream outputStream) {
- try {
- outputStream.write(getSerializeId().ordinal());
- outputStream.write(filterType.ordinal());
- ReadWriteIOUtils.writeObject(value, outputStream);
- } catch (IOException ignored) {
- // ignored
- }
- }
-
- @Override
- public void deserialize(ByteBuffer buffer) {
- filterType = FilterType.values()[buffer.get()];
- value = (T) ReadWriteIOUtils.readObject(buffer);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof UnaryFilter)) {
- return false;
- }
- UnaryFilter other = ((UnaryFilter) obj);
- return this.value.equals(other.value)
- && this.filterType.equals(other.filterType)
- && this.getSerializeId().equals(other.getSerializeId());
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(value, filterType, getSerializeId());
- }
-}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterFactory.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterFactory.java
index 44848a01967..064c7ac9a77 100644
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterFactory.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/FilterFactory.java
@@ -19,25 +19,10 @@
package org.apache.iotdb.tsfile.read.filter.factory;
-import org.apache.iotdb.tsfile.read.filter.GroupByFilter;
-import org.apache.iotdb.tsfile.read.filter.GroupByMonthFilter;
-import org.apache.iotdb.tsfile.read.filter.TimeFilter;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.operator.AndFilter;
-import org.apache.iotdb.tsfile.read.filter.operator.Between;
-import org.apache.iotdb.tsfile.read.filter.operator.Eq;
-import org.apache.iotdb.tsfile.read.filter.operator.Gt;
-import org.apache.iotdb.tsfile.read.filter.operator.GtEq;
-import org.apache.iotdb.tsfile.read.filter.operator.In;
-import org.apache.iotdb.tsfile.read.filter.operator.Like;
-import org.apache.iotdb.tsfile.read.filter.operator.Lt;
-import org.apache.iotdb.tsfile.read.filter.operator.LtEq;
-import org.apache.iotdb.tsfile.read.filter.operator.NotEq;
-import org.apache.iotdb.tsfile.read.filter.operator.NotFilter;
-import org.apache.iotdb.tsfile.read.filter.operator.OrFilter;
-import org.apache.iotdb.tsfile.read.filter.operator.Regexp;
-
-import java.nio.ByteBuffer;
+import org.apache.iotdb.tsfile.read.filter.operator.And;
+import org.apache.iotdb.tsfile.read.filter.operator.Not;
+import org.apache.iotdb.tsfile.read.filter.operator.Or;
public class FilterFactory {
@@ -45,75 +30,15 @@ public class FilterFactory {
// forbidden construction
}
- public static AndFilter and(Filter left, Filter right) {
- return new AndFilter(left, right);
- }
-
- public static OrFilter or(Filter left, Filter right) {
- return new OrFilter(left, right);
+ public static And and(Filter left, Filter right) {
+ return new And(left, right);
}
- public static NotFilter not(Filter filter) {
- return new NotFilter(filter);
+ public static Or or(Filter left, Filter right) {
+ return new Or(left, right);
}
- public static Filter deserialize(ByteBuffer buffer) {
- FilterSerializeId id = FilterSerializeId.values()[buffer.get()];
-
- Filter filter;
- switch (id) {
- case EQ:
- filter = new Eq<>();
- break;
- case GT:
- filter = new Gt<>();
- break;
- case LT:
- filter = new Lt<>();
- break;
- case OR:
- filter = new OrFilter();
- break;
- case AND:
- filter = new AndFilter();
- break;
- case NEQ:
- filter = new NotEq<>();
- break;
- case NOT:
- filter = new NotFilter();
- break;
- case GTEQ:
- filter = new GtEq<>();
- break;
- case LTEQ:
- filter = new LtEq<>();
- break;
- case IN:
- filter = new In<>();
- break;
- case GROUP_BY:
- filter = new GroupByFilter();
- break;
- case GROUP_BY_MONTH:
- filter = new GroupByMonthFilter();
- break;
- case REGEXP:
- filter = new Regexp<>();
- break;
- case LIKE:
- filter = new Like<>();
- break;
- case BETWEEN:
- filter = new Between<>();
- break;
- case TIME_GTEQ_AND_LT:
- filter = new TimeFilter.TimeGtEqAndLt();
- break;
- default:
- throw new UnsupportedOperationException("Unknown filter type " + id);
- }
- filter.deserialize(buffer);
- return filter;
+ public static Not not(Filter filter) {
+ return new Not(filter);
}
}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/TimeFilter.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/TimeFilter.java
new file mode 100644
index 00000000000..d7e78bec490
--- /dev/null
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/TimeFilter.java
@@ -0,0 +1,101 @@
+/*
+ * 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.tsfile.read.filter.factory;
+
+import org.apache.iotdb.tsfile.read.filter.operator.GroupByFilter;
+import org.apache.iotdb.tsfile.read.filter.operator.GroupByMonthFilter;
+import org.apache.iotdb.tsfile.read.filter.operator.TimeFilterOperators.TimeBetweenAnd;
+import org.apache.iotdb.tsfile.read.filter.operator.TimeFilterOperators.TimeEq;
+import org.apache.iotdb.tsfile.read.filter.operator.TimeFilterOperators.TimeGt;
+import org.apache.iotdb.tsfile.read.filter.operator.TimeFilterOperators.TimeGtEq;
+import org.apache.iotdb.tsfile.read.filter.operator.TimeFilterOperators.TimeIn;
+import org.apache.iotdb.tsfile.read.filter.operator.TimeFilterOperators.TimeLt;
+import org.apache.iotdb.tsfile.read.filter.operator.TimeFilterOperators.TimeLtEq;
+import org.apache.iotdb.tsfile.read.filter.operator.TimeFilterOperators.TimeNotBetweenAnd;
+import org.apache.iotdb.tsfile.read.filter.operator.TimeFilterOperators.TimeNotEq;
+import org.apache.iotdb.tsfile.read.filter.operator.TimeFilterOperators.TimeNotIn;
+import org.apache.iotdb.tsfile.utils.TimeDuration;
+
+import java.util.Set;
+import java.util.TimeZone;
+import java.util.concurrent.TimeUnit;
+
+public class TimeFilter {
+
+ private TimeFilter() {
+ // forbidden construction
+ }
+
+ public static TimeGt gt(long value) {
+ return new TimeGt(value);
+ }
+
+ public static TimeGtEq gtEq(long value) {
+ return new TimeGtEq(value);
+ }
+
+ public static TimeLt lt(long value) {
+ return new TimeLt(value);
+ }
+
+ public static TimeLtEq ltEq(long value) {
+ return new TimeLtEq(value);
+ }
+
+ public static TimeEq eq(long value) {
+ return new TimeEq(value);
+ }
+
+ public static TimeNotEq notEq(long value) {
+ return new TimeNotEq(value);
+ }
+
+ public static TimeBetweenAnd between(long value1, long value2) {
+ return new TimeBetweenAnd(value1, value2);
+ }
+
+ public static TimeNotBetweenAnd notBetween(long value1, long value2) {
+ return new TimeNotBetweenAnd(value1, value2);
+ }
+
+ public static TimeIn in(Set<Long> values) {
+ return new TimeIn(values);
+ }
+
+ public static TimeNotIn notIn(Set<Long> values) {
+ return new TimeNotIn(values);
+ }
+
+ public static GroupByFilter groupBy(
+ long startTime, long endTime, long interval, long slidingStep) {
+ return new GroupByFilter(interval, slidingStep, startTime, endTime);
+ }
+
+ public static GroupByMonthFilter groupByMonth(
+ long startTime,
+ long endTime,
+ TimeDuration interval,
+ TimeDuration slidingStep,
+ TimeZone timeZone,
+ TimeUnit currPrecision) {
+ return new GroupByMonthFilter(
+ interval, slidingStep, startTime, endTime, timeZone, currPrecision);
+ }
+}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/ValueFilter.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/ValueFilter.java
new file mode 100644
index 00000000000..bb0c36d77af
--- /dev/null
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/factory/ValueFilter.java
@@ -0,0 +1,160 @@
+/*
+ * 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.tsfile.read.filter.factory;
+
+import org.apache.iotdb.tsfile.read.filter.operator.ValueFilterOperators.ValueBetweenAnd;
+import org.apache.iotdb.tsfile.read.filter.operator.ValueFilterOperators.ValueEq;
+import org.apache.iotdb.tsfile.read.filter.operator.ValueFilterOperators.ValueGt;
+import org.apache.iotdb.tsfile.read.filter.operator.ValueFilterOperators.ValueGtEq;
+import org.apache.iotdb.tsfile.read.filter.operator.ValueFilterOperators.ValueIn;
+import org.apache.iotdb.tsfile.read.filter.operator.ValueFilterOperators.ValueLike;
+import org.apache.iotdb.tsfile.read.filter.operator.ValueFilterOperators.ValueLt;
+import org.apache.iotdb.tsfile.read.filter.operator.ValueFilterOperators.ValueLtEq;
+import org.apache.iotdb.tsfile.read.filter.operator.ValueFilterOperators.ValueNotBetweenAnd;
+import org.apache.iotdb.tsfile.read.filter.operator.ValueFilterOperators.ValueNotEq;
+import org.apache.iotdb.tsfile.read.filter.operator.ValueFilterOperators.ValueNotIn;
+import org.apache.iotdb.tsfile.read.filter.operator.ValueFilterOperators.ValueNotLike;
+import org.apache.iotdb.tsfile.read.filter.operator.ValueFilterOperators.ValueNotRegexp;
+import org.apache.iotdb.tsfile.read.filter.operator.ValueFilterOperators.ValueRegexp;
+
+import java.util.Set;
+
+public class ValueFilter {
+
+ private ValueFilter() {
+ // forbidden construction
+ }
+
+ private static final String FAKE_MEASUREMENT = "";
+
+ public static <T extends Comparable<T>> ValueGt<T> gt(T value) {
+ return new ValueGt<>(FAKE_MEASUREMENT, value);
+ }
+
+ public static <T extends Comparable<T>> ValueGtEq<T> gtEq(T value) {
+ return new ValueGtEq<>(FAKE_MEASUREMENT, value);
+ }
+
+ public static <T extends Comparable<T>> ValueLt<T> lt(T value) {
+ return new ValueLt<>(FAKE_MEASUREMENT, value);
+ }
+
+ public static <T extends Comparable<T>> ValueLtEq<T> ltEq(T value) {
+ return new ValueLtEq<>(FAKE_MEASUREMENT, value);
+ }
+
+ public static <T extends Comparable<T>> ValueEq<T> eq(T value) {
+ return new ValueEq<>(FAKE_MEASUREMENT, value);
+ }
+
+ public static <T extends Comparable<T>> ValueNotEq<T> notEq(T value) {
+ return new ValueNotEq<>(FAKE_MEASUREMENT, value);
+ }
+
+ public static <T extends Comparable<T>> ValueBetweenAnd<T> between(T value1, T value2) {
+ return new ValueBetweenAnd<>(FAKE_MEASUREMENT, value1, value2);
+ }
+
+ public static <T extends Comparable<T>> ValueNotBetweenAnd<T> notBetween(T value1, T value2) {
+ return new ValueNotBetweenAnd<>(FAKE_MEASUREMENT, value1, value2);
+ }
+
+ public static ValueLike like(String value) {
+ return new ValueLike(FAKE_MEASUREMENT, value);
+ }
+
+ public static ValueNotLike notLike(String value) {
+ return new ValueNotLike(FAKE_MEASUREMENT, value);
+ }
+
+ public static ValueRegexp regexp(String value) {
+ return new ValueRegexp(FAKE_MEASUREMENT, value);
+ }
+
+ public static ValueNotRegexp notRegexp(String value) {
+ return new ValueNotRegexp(FAKE_MEASUREMENT, value);
+ }
+
+ public static <T extends Comparable<T>> ValueIn<T> in(Set<T> values) {
+ return new ValueIn<>(FAKE_MEASUREMENT, values);
+ }
+
+ public static <T extends Comparable<T>> ValueNotIn<T> notIn(Set<T> values) {
+ return new ValueNotIn<>(FAKE_MEASUREMENT, values);
+ }
+
+ public static <T extends Comparable<T>> ValueGt<T> gt(String measurement, T value) {
+ return new ValueGt<>(measurement, value);
+ }
+
+ public static <T extends Comparable<T>> ValueGtEq<T> gtEq(String measurement, T value) {
+ return new ValueGtEq<>(measurement, value);
+ }
+
+ public static <T extends Comparable<T>> ValueLt<T> lt(String measurement, T value) {
+ return new ValueLt<>(measurement, value);
+ }
+
+ public static <T extends Comparable<T>> ValueLtEq<T> ltEq(String measurement, T value) {
+ return new ValueLtEq<>(measurement, value);
+ }
+
+ public static <T extends Comparable<T>> ValueEq<T> eq(String measurement, T value) {
+ return new ValueEq<>(measurement, value);
+ }
+
+ public static <T extends Comparable<T>> ValueNotEq<T> notEq(String measurement, T value) {
+ return new ValueNotEq<>(measurement, value);
+ }
+
+ public static <T extends Comparable<T>> ValueBetweenAnd<T> between(
+ String measurement, T value1, T value2) {
+ return new ValueBetweenAnd<>(measurement, value1, value2);
+ }
+
+ public static <T extends Comparable<T>> ValueNotBetweenAnd<T> notBetween(
+ String measurement, T value1, T value2) {
+ return new ValueNotBetweenAnd<>(measurement, value1, value2);
+ }
+
+ public static ValueLike like(String measurement, String value) {
+ return new ValueLike(measurement, value);
+ }
+
+ public static ValueNotLike notLike(String measurement, String value) {
+ return new ValueNotLike(measurement, value);
+ }
+
+ public static ValueRegexp regexp(String measurement, String value) {
+ return new ValueRegexp(measurement, value);
+ }
+
+ public static ValueNotRegexp notRegexp(String measurement, String value) {
+ return new ValueNotRegexp(measurement, value);
+ }
+
+ public static <T extends Comparable<T>> ValueIn<T> in(String measurement, Set<T> values) {
+ return new ValueIn<>(measurement, values);
+ }
+
+ public static <T extends Comparable<T>> ValueNotIn<T> notIn(String measurement, Set<T> values) {
+ return new ValueNotIn<>(measurement, values);
+ }
+}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/AndFilter.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/And.java
old mode 100755
new mode 100644
similarity index 79%
rename from iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/AndFilter.java
rename to iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/And.java
index ca251dc4d83..ce5708ecf48
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/AndFilter.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/And.java
@@ -21,22 +21,15 @@ package org.apache.iotdb.tsfile.read.filter.operator;
import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
import org.apache.iotdb.tsfile.read.common.TimeRange;
-import org.apache.iotdb.tsfile.read.filter.basic.BinaryFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.BinaryLogicalFilter;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
import java.util.ArrayList;
import java.util.List;
-/** Both the left and right operators of AndExpression must satisfy the condition. */
-public class AndFilter extends BinaryFilter {
+public class And extends BinaryLogicalFilter {
- private static final long serialVersionUID = -8212850098906044102L;
-
- public AndFilter() {}
-
- public AndFilter(Filter left, Filter right) {
+ public And(Filter left, Filter right) {
super(left, right);
}
@@ -67,21 +60,6 @@ public class AndFilter extends BinaryFilter {
&& right.containStartEndTime(startTime, endTime);
}
- @Override
- public String toString() {
- return "(" + left + " && " + right + ")";
- }
-
- @Override
- public Filter copy() {
- return new AndFilter(left.copy(), right.copy());
- }
-
- @Override
- public FilterSerializeId getSerializeId() {
- return FilterSerializeId.AND;
- }
-
@Override
public List<TimeRange> getTimeRanges() {
List<TimeRange> result = new ArrayList<>();
@@ -120,6 +98,6 @@ public class AndFilter extends BinaryFilter {
@Override
public Filter reverse() {
- return FilterFactory.or(left.reverse(), right.reverse());
+ return new Or(left.reverse(), right.reverse());
}
}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Between.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Between.java
deleted file mode 100644
index 098d165c4ce..00000000000
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Between.java
+++ /dev/null
@@ -1,168 +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.tsfile.read.filter.operator;
-
-import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
-import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.Serializable;
-import java.nio.ByteBuffer;
-import java.util.Objects;
-
-public class Between<T extends Comparable<T>> implements Filter, Serializable {
-
- private static final long serialVersionUID = -537390606419370764L;
-
- protected T value1;
-
- protected T value2;
-
- protected boolean not;
-
- protected FilterType filterType;
-
- public Between() {}
-
- public Between(T value1, T value2, FilterType filterType, boolean not) {
- this.value1 = value1;
- this.value2 = value2;
- this.filterType = filterType;
- this.not = not;
- }
-
- @Override
- public boolean satisfy(Statistics statistics) {
- if (filterType == FilterType.TIME_FILTER) {
- return satisfyStartEndTime(statistics.getStartTime(), statistics.getEndTime());
- } else {
- if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
- return true;
- }
- return not
- ? (((T) statistics.getMinValue()).compareTo(value1) < 0
- || ((T) statistics.getMaxValue()).compareTo(value2) > 0)
- : (((T) statistics.getMaxValue()).compareTo(value1) >= 0
- && ((T) statistics.getMinValue()).compareTo(value2) <= 0);
- }
- }
-
- @Override
- public boolean allSatisfy(Statistics statistics) {
- if (filterType == FilterType.TIME_FILTER) {
- return containStartEndTime(statistics.getStartTime(), statistics.getEndTime());
- } else {
- if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
- return false;
- }
- return not
- ? (((T) statistics.getMinValue()).compareTo(value2) > 0
- || ((T) statistics.getMaxValue()).compareTo(value1) < 0)
- : (((T) statistics.getMinValue()).compareTo(value1) >= 0
- && ((T) statistics.getMaxValue()).compareTo(value2) <= 0);
- }
- }
-
- @Override
- public boolean satisfy(long time, Object value) {
- Object v = filterType == FilterType.TIME_FILTER ? time : value;
- return (value1.compareTo((T) v) <= 0 && ((T) v).compareTo(value2) <= 0) ^ not;
- }
-
- @Override
- public boolean satisfyStartEndTime(long startTime, long endTime) {
- if (filterType == FilterType.TIME_FILTER) {
- return not
- ? (startTime < (Long) value1 || endTime > (Long) value2)
- : (endTime >= (Long) value1 && startTime <= (Long) value2);
- } else {
- return true;
- }
- }
-
- @Override
- public boolean containStartEndTime(long startTime, long endTime) {
- if (filterType == FilterType.TIME_FILTER) {
- return not
- ? (startTime > (Long) value2 || endTime < (Long) value1)
- : (startTime >= (Long) value1 && endTime <= (Long) value2);
- } else {
- return false;
- }
- }
-
- @Override
- public void serialize(DataOutputStream outputStream) {
- try {
- outputStream.write(getSerializeId().ordinal());
- outputStream.write(filterType.ordinal());
- ReadWriteIOUtils.write(not, outputStream);
- ReadWriteIOUtils.writeObject(value1, outputStream);
- ReadWriteIOUtils.writeObject(value2, outputStream);
- } catch (IOException ignored) {
- // ignored
- }
- }
-
- @Override
- public void deserialize(ByteBuffer buffer) {
- filterType = FilterType.values()[buffer.get()];
- not = ReadWriteIOUtils.readBool(buffer);
- value1 = (T) ReadWriteIOUtils.readObject(buffer);
- value2 = (T) ReadWriteIOUtils.readObject(buffer);
- }
-
- @Override
- public FilterSerializeId getSerializeId() {
- return FilterSerializeId.BETWEEN;
- }
-
- @Override
- public Filter copy() {
- return new Between<>(value1, value2, filterType, not);
- }
-
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof Between)) {
- return false;
- }
- Between<?> between = (Between<?>) o;
- return not == between.not
- && value1.equals(between.value1)
- && value2.equals(between.value2)
- && filterType == between.filterType;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(value1, value2, not, filterType);
- }
-
- @Override
- public Filter reverse() {
- return new Between<>(value1, value2, filterType, !not);
- }
-}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Eq.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Eq.java
deleted file mode 100755
index 8af71981563..00000000000
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Eq.java
+++ /dev/null
@@ -1,115 +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.tsfile.read.filter.operator;
-
-import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.basic.UnaryFilter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
-
-/**
- * Equals.
- *
- * @param <T> comparable data type
- */
-public class Eq<T extends Comparable<T>> extends UnaryFilter<T> {
-
- private static final long serialVersionUID = -6668083116644568248L;
-
- public Eq() {}
-
- public Eq(T value, FilterType filterType) {
- super(value, filterType);
- }
-
- @Override
- public boolean satisfy(Statistics statistics) {
- if (filterType == FilterType.TIME_FILTER) {
- return satisfyStartEndTime(statistics.getStartTime(), statistics.getEndTime());
- } else {
- if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
- return true;
- }
- return value.compareTo((T) statistics.getMinValue()) >= 0
- && value.compareTo((T) statistics.getMaxValue()) <= 0;
- }
- }
-
- @Override
- public boolean allSatisfy(Statistics statistics) {
- if (filterType == FilterType.TIME_FILTER) {
- return containStartEndTime(statistics.getStartTime(), statistics.getEndTime());
- } else {
- if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
- return false;
- }
- return value.compareTo((T) statistics.getMinValue()) == 0
- && value.compareTo((T) statistics.getMaxValue()) == 0;
- }
- }
-
- @Override
- public boolean satisfy(long time, Object value) {
- Object v = filterType == FilterType.TIME_FILTER ? time : value;
- return this.value.equals(v);
- }
-
- @Override
- public boolean satisfyStartEndTime(long startTime, long endTime) {
- if (filterType == FilterType.TIME_FILTER) {
- long time = (Long) value;
- return time <= endTime && time >= startTime;
- } else {
- return true;
- }
- }
-
- @Override
- public boolean containStartEndTime(long startTime, long endTime) {
- if (filterType == FilterType.TIME_FILTER) {
- long time = (Long) value;
- return time == startTime && time == endTime;
- } else {
- return false;
- }
- }
-
- @Override
- public Filter copy() {
- return new Eq<>(value, filterType);
- }
-
- @Override
- public String toString() {
- return getFilterType() + " == " + value;
- }
-
- @Override
- public FilterSerializeId getSerializeId() {
- return FilterSerializeId.EQ;
- }
-
- @Override
- public Filter reverse() {
- return new NotEq<>(value, filterType);
- }
-}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/GroupByFilter.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/GroupByFilter.java
similarity index 65%
rename from iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/GroupByFilter.java
rename to iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/GroupByFilter.java
index 98bf4fc0332..54dc5e333e2 100644
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/GroupByFilter.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/GroupByFilter.java
@@ -17,24 +17,17 @@
* under the License.
*/
-package org.apache.iotdb.tsfile.read.filter;
+package org.apache.iotdb.tsfile.read.filter.operator;
import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
import org.apache.iotdb.tsfile.read.common.TimeRange;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.Serializable;
-import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;
-import java.util.Objects;
-public class GroupByFilter implements Filter, Serializable {
+public class GroupByFilter implements Filter {
- private static final long serialVersionUID = -1211805021419281440L;
protected long interval;
protected long slidingStep;
protected long startTime;
@@ -47,13 +40,11 @@ public class GroupByFilter implements Filter, Serializable {
this.endTime = endTime;
}
- public GroupByFilter(long startTime, long endTime) {
+ protected GroupByFilter(long startTime, long endTime) {
this.startTime = startTime;
this.endTime = endTime;
}
- public GroupByFilter() {}
-
@Override
public boolean satisfy(Statistics statistics) {
return satisfyStartEndTime(statistics.getStartTime(), statistics.getEndTime());
@@ -105,68 +96,12 @@ public class GroupByFilter implements Filter, Serializable {
return false;
}
- @Override
- public Filter copy() {
- return new GroupByFilter(interval, slidingStep, startTime, endTime);
- }
-
@Override
public String toString() {
return String.format(
"GroupByFilter{[%d, %d], %d, %d}", startTime, endTime, interval, slidingStep);
}
- @Override
- public void serialize(DataOutputStream outputStream) {
- try {
- outputStream.write(getSerializeId().ordinal());
- outputStream.writeLong(interval);
- outputStream.writeLong(slidingStep);
- outputStream.writeLong(startTime);
- outputStream.writeLong(endTime);
- } catch (IOException ignored) {
- // ignored
- }
- }
-
- @Override
- public void deserialize(ByteBuffer buffer) {
- interval = buffer.getLong();
- slidingStep = buffer.getLong();
- startTime = buffer.getLong();
- endTime = buffer.getLong();
- }
-
- @Override
- public FilterSerializeId getSerializeId() {
- return FilterSerializeId.GROUP_BY;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof GroupByFilter)) {
- return false;
- }
- GroupByFilter other = ((GroupByFilter) obj);
- return this.interval == other.interval
- && this.slidingStep == other.slidingStep
- && this.startTime == other.startTime
- && this.endTime == other.endTime;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(interval, slidingStep, startTime, endTime);
- }
-
- public long getStartTime() {
- return startTime;
- }
-
- public long getEndTime() {
- return endTime;
- }
-
@Override
public List<TimeRange> getTimeRanges() {
return startTime >= endTime
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/GroupByMonthFilter.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/GroupByMonthFilter.java
similarity index 62%
rename from iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/GroupByMonthFilter.java
rename to iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/GroupByMonthFilter.java
index 0f0acc53323..ba72d6c4955 100644
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/GroupByMonthFilter.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/GroupByMonthFilter.java
@@ -17,19 +17,12 @@
* under the License.
*/
-package org.apache.iotdb.tsfile.read.filter;
+package org.apache.iotdb.tsfile.read.filter.operator;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
import org.apache.iotdb.tsfile.utils.TimeDuration;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Calendar;
-import java.util.Objects;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
@@ -41,22 +34,20 @@ import static org.apache.iotdb.tsfile.utils.TimeDuration.getConsecutiveTimesInte
* dynamically. Attention: it's only supported to access in ascending order now.
*/
public class GroupByMonthFilter extends GroupByFilter {
- private Calendar calendar = Calendar.getInstance();
+ private final Calendar calendar = Calendar.getInstance();
- private TimeDuration originalSlidingStep;
- private TimeDuration originalInterval;
+ private final TimeDuration originalSlidingStep;
+ private final TimeDuration originalInterval;
// These fields will be serialized to remote nodes, as other fields may be updated during process
private TimeZone timeZone;
- private long originalStartTime;
- private long originalEndTime;
+ private final long originalStartTime;
+ private final long originalEndTime;
- private TimeUnit currPrecision;
+ private final TimeUnit currPrecision;
private long[] startTimes;
- public GroupByMonthFilter() {}
-
public GroupByMonthFilter(
TimeDuration interval,
TimeDuration slidingStep,
@@ -79,22 +70,6 @@ public class GroupByMonthFilter extends GroupByFilter {
initMonthGroupByParameters(timeZone);
}
- public GroupByMonthFilter(GroupByMonthFilter filter) {
- super(filter.interval, filter.slidingStep, filter.startTime, filter.endTime);
- originalStartTime = filter.originalStartTime;
- originalEndTime = filter.originalEndTime;
- originalSlidingStep = filter.originalSlidingStep;
- originalInterval = filter.originalInterval;
- calendar = Calendar.getInstance();
- calendar.setTimeZone(filter.calendar.getTimeZone());
- calendar.setTimeInMillis(filter.calendar.getTimeInMillis());
- timeZone = filter.timeZone;
- currPrecision = filter.currPrecision;
- // the value in this array will not be changed, so we can copy reference directly
- startTimes = filter.startTimes;
- }
-
- // TODO: time descending order
@Override
public boolean satisfy(long time, Object value) {
if (time < originalStartTime || time >= endTime) {
@@ -126,11 +101,6 @@ public class GroupByMonthFilter extends GroupByFilter {
}
}
- @Override
- public Filter copy() {
- return new GroupByMonthFilter(this);
- }
-
private boolean satisfyCurrentInterval(long startTime, long endTime) {
if (endTime < this.startTime || startTime >= this.endTime) {
return false;
@@ -152,40 +122,6 @@ public class GroupByMonthFilter extends GroupByFilter {
}
}
- @Override
- public void serialize(DataOutputStream outputStream) {
- try {
- outputStream.write(getSerializeId().ordinal());
- originalInterval.serialize(outputStream);
- originalSlidingStep.serialize(outputStream);
- ReadWriteIOUtils.write(originalStartTime, outputStream);
- ReadWriteIOUtils.write(originalEndTime, outputStream);
- ReadWriteIOUtils.write(currPrecision.ordinal(), outputStream);
- ReadWriteIOUtils.write(timeZone.getID(), outputStream);
- } catch (IOException ignored) {
- // ignored
- }
- }
-
- @Override
- public void deserialize(ByteBuffer buffer) {
- originalInterval = TimeDuration.deserialize(buffer);
- originalSlidingStep = TimeDuration.deserialize(buffer);
- if (!originalInterval.containsMonth()) {
- this.interval = originalInterval.nonMonthDuration;
- }
- if (!originalSlidingStep.containsMonth()) {
- this.slidingStep = originalSlidingStep.nonMonthDuration;
- }
- originalStartTime = ReadWriteIOUtils.readLong(buffer);
- originalEndTime = ReadWriteIOUtils.readLong(buffer);
- currPrecision = TimeUnit.values()[ReadWriteIOUtils.readInt(buffer)];
- timeZone = TimeZone.getTimeZone(ReadWriteIOUtils.readString(buffer));
- startTime = originalStartTime;
- endTime = originalEndTime;
- initMonthGroupByParameters(timeZone);
- }
-
private boolean isContainedByCurrentInterval(long startTime, long endTime) {
if (startTime < this.startTime || endTime > this.endTime) {
return false;
@@ -194,25 +130,6 @@ public class GroupByMonthFilter extends GroupByFilter {
}
}
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof GroupByMonthFilter)) {
- return false;
- }
- GroupByMonthFilter other = (GroupByMonthFilter) obj;
- return this.originalInterval.equals(other.originalInterval)
- && this.originalSlidingStep.equals(other.originalSlidingStep)
- && this.originalStartTime == other.originalStartTime
- && this.originalEndTime == other.originalEndTime
- && this.currPrecision == other.currPrecision
- && this.timeZone.equals(other.timeZone);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(originalInterval, originalSlidingStep, originalStartTime, originalEndTime);
- }
-
private void initMonthGroupByParameters(TimeZone timeZone) {
calendar.setTimeZone(timeZone);
this.timeZone = timeZone;
@@ -263,9 +180,4 @@ public class GroupByMonthFilter extends GroupByFilter {
- startTime;
}
}
-
- @Override
- public FilterSerializeId getSerializeId() {
- return FilterSerializeId.GROUP_BY_MONTH;
- }
}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Gt.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Gt.java
deleted file mode 100755
index 003d9814e56..00000000000
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Gt.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.tsfile.read.filter.operator;
-
-import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.basic.UnaryFilter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
-
-/**
- * Greater than filter.
- *
- * @param <T> comparable data type
- */
-public class Gt<T extends Comparable<T>> extends UnaryFilter<T> {
-
- private static final long serialVersionUID = -2088181659871608986L;
-
- public Gt() {}
-
- public Gt(T value, FilterType filterType) {
- super(value, filterType);
- }
-
- @Override
- public boolean satisfy(Statistics statistics) {
- if (filterType == FilterType.TIME_FILTER) {
- return satisfyStartEndTime(statistics.getStartTime(), statistics.getEndTime());
- } else {
- if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
- return true;
- }
- return value.compareTo((T) statistics.getMaxValue()) < 0;
- }
- }
-
- @Override
- public boolean allSatisfy(Statistics statistics) {
- if (filterType == FilterType.TIME_FILTER) {
- return containStartEndTime(statistics.getStartTime(), statistics.getEndTime());
- } else {
- if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
- return false;
- }
- return value.compareTo((T) statistics.getMinValue()) < 0;
- }
- }
-
- @Override
- public boolean satisfy(long time, Object value) {
- Object v = filterType == FilterType.TIME_FILTER ? time : value;
- return this.value.compareTo((T) v) < 0;
- }
-
- @Override
- public boolean satisfyStartEndTime(long startTime, long endTime) {
- if (filterType == FilterType.TIME_FILTER) {
- long time = (Long) value;
- return time < endTime;
- } else {
- return true;
- }
- }
-
- @Override
- public boolean containStartEndTime(long startTime, long endTime) {
- if (filterType == FilterType.TIME_FILTER) {
- long time = (Long) value;
- return startTime > time;
- } else {
- return false;
- }
- }
-
- @Override
- public Filter copy() {
- return new Gt<>(value, filterType);
- }
-
- @Override
- public String toString() {
- return getFilterType() + " > " + value;
- }
-
- @Override
- public FilterSerializeId getSerializeId() {
- return FilterSerializeId.GT;
- }
-
- @Override
- public Filter reverse() {
- return new LtEq<>(value, filterType);
- }
-}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/GtEq.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/GtEq.java
deleted file mode 100755
index 1ae60ddcd0e..00000000000
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/GtEq.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.tsfile.read.filter.operator;
-
-import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.basic.UnaryFilter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
-
-/**
- * Greater than or Equals filter.
- *
- * @param <T> comparable data type
- */
-public class GtEq<T extends Comparable<T>> extends UnaryFilter<T> {
-
- private static final long serialVersionUID = -2088181659871608986L;
-
- public GtEq(T value, FilterType filterType) {
- super(value, filterType);
- }
-
- public GtEq() {}
-
- @Override
- public boolean satisfy(Statistics statistics) {
- if (filterType == FilterType.TIME_FILTER) {
- return satisfyStartEndTime(statistics.getStartTime(), statistics.getEndTime());
- } else {
- if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
- return true;
- }
- return value.compareTo((T) statistics.getMaxValue()) <= 0;
- }
- }
-
- @Override
- public boolean allSatisfy(Statistics statistics) {
- if (filterType == FilterType.TIME_FILTER) {
- return containStartEndTime(statistics.getStartTime(), statistics.getEndTime());
- } else {
- if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
- return false;
- }
- return value.compareTo((T) statistics.getMinValue()) <= 0;
- }
- }
-
- @Override
- public boolean satisfy(long time, Object value) {
- Object v = filterType == FilterType.TIME_FILTER ? time : value;
- return this.value.compareTo((T) v) <= 0;
- }
-
- @Override
- public boolean satisfyStartEndTime(long startTime, long endTime) {
- if (filterType == FilterType.TIME_FILTER) {
- long time = (Long) value;
- return time <= endTime;
- } else {
- return true;
- }
- }
-
- @Override
- public boolean containStartEndTime(long startTime, long endTime) {
- if (filterType == FilterType.TIME_FILTER) {
- long time = (Long) value;
- return startTime >= time;
- } else {
- return false;
- }
- }
-
- @Override
- public Filter copy() {
- return new GtEq<>(value, filterType);
- }
-
- @Override
- public String toString() {
- return getFilterType() + " >= " + value;
- }
-
- @Override
- public FilterSerializeId getSerializeId() {
- return FilterSerializeId.GTEQ;
- }
-
- @Override
- public Filter reverse() {
- return new Lt<>(value, filterType);
- }
-}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/In.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/In.java
deleted file mode 100644
index 3699b2da110..00000000000
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/In.java
+++ /dev/null
@@ -1,153 +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.tsfile.read.filter.operator;
-
-import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
-import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.Serializable;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
-
-/**
- * in clause.
- *
- * @param <T> comparable data type
- */
-public class In<T extends Comparable<T>> implements Filter, Serializable {
-
- private static final long serialVersionUID = 8572705136773595399L;
-
- protected Set<T> values;
-
- protected boolean not;
-
- protected FilterType filterType;
-
- public In() {}
-
- public In(Set<T> values, FilterType filterType, boolean not) {
- this.values = values;
- this.filterType = filterType;
- this.not = not;
- }
-
- @Override
- public boolean satisfy(Statistics statistics) {
- return true;
- }
-
- @Override
- public boolean allSatisfy(Statistics statistics) {
- return false;
- }
-
- @Override
- public boolean satisfy(long time, Object value) {
- Object v = filterType == FilterType.TIME_FILTER ? time : value;
- return this.values.contains(v) != not;
- }
-
- @Override
- public boolean satisfyStartEndTime(long startTime, long endTime) {
- return true;
- }
-
- @Override
- public boolean containStartEndTime(long startTime, long endTime) {
- return false;
- }
-
- @Override
- public Filter copy() {
- return new In<>(new HashSet<>(values), filterType, not);
- }
-
- @Override
- public void serialize(DataOutputStream outputStream) {
- try {
- outputStream.write(getSerializeId().ordinal());
- outputStream.write(filterType.ordinal());
- ReadWriteIOUtils.write(not, outputStream);
- ReadWriteIOUtils.write(values.size(), outputStream);
- for (T value : values) {
- ReadWriteIOUtils.writeObject(value, outputStream);
- }
- } catch (IOException ignored) {
- // ignored
- }
- }
-
- @Override
- public void deserialize(ByteBuffer buffer) {
- filterType = FilterType.values()[buffer.get()];
- not = ReadWriteIOUtils.readBool(buffer);
- int size = ReadWriteIOUtils.readInt(buffer);
- values = new HashSet<>(size);
- for (int i = 0; i < size; i++) {
- values.add((T) ReadWriteIOUtils.readObject(buffer));
- }
- }
-
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof In)) {
- return false;
- }
- In<?> in = (In<?>) o;
- return in.filterType == filterType && in.values.equals(values) && in.not == not;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(values, not, filterType);
- }
-
- @Override
- public String toString() {
- List<T> valueList = new ArrayList<>(values);
- Collections.sort(valueList);
- return filterType + (not ? " not in " : " in ") + valueList;
- }
-
- @Override
- public FilterSerializeId getSerializeId() {
- return FilterSerializeId.IN;
- }
-
- @Override
- public Filter reverse() {
- return new In<>(new HashSet<>(values), filterType, !not);
- }
-
- public Set<T> getValues() {
- return values;
- }
-}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Like.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Like.java
deleted file mode 100644
index 4e2112549c3..00000000000
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Like.java
+++ /dev/null
@@ -1,201 +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.tsfile.read.filter.operator;
-
-import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
-import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.Serializable;
-import java.nio.ByteBuffer;
-import java.util.Objects;
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
-
-/**
- * Like.
- *
- * @param <T> comparable data type
- */
-public class Like<T extends Comparable<T>> implements Filter, Serializable {
-
- private static final long serialVersionUID = 2171102599229260789L;
-
- protected String value;
-
- protected FilterType filterType;
-
- protected Pattern pattern;
-
- protected boolean not;
-
- public Like() {}
-
- /**
- * The main idea of this part comes from
- * https://codereview.stackexchange.com/questions/36861/convert-sql-like-to-regex/36864
- *
- * @throws PatternSyntaxException if the regex expression's syntax is invalid
- */
- public Like(String value, FilterType filterType, boolean not) {
- this.value = value;
- this.filterType = filterType;
- this.not = not;
- try {
- String unescapeValue = unescapeString(value);
- String specialRegexStr = ".^$*+?{}[]|()";
- StringBuilder patternStrBuild = new StringBuilder();
- patternStrBuild.append("^");
- for (int i = 0; i < unescapeValue.length(); i++) {
- String ch = String.valueOf(unescapeValue.charAt(i));
- if (specialRegexStr.contains(ch)) {
- ch = "\\" + unescapeValue.charAt(i);
- }
- if ((i == 0)
- || (i > 0 && !"\\".equals(String.valueOf(unescapeValue.charAt(i - 1))))
- || (i >= 2
- && "\\\\"
- .equals(
- patternStrBuild.substring(
- patternStrBuild.length() - 2, patternStrBuild.length())))) {
- String replaceStr = ch.replace("%", ".*?").replace("_", ".");
- patternStrBuild.append(replaceStr);
- } else {
- patternStrBuild.append(ch);
- }
- }
- patternStrBuild.append("$");
- this.pattern = Pattern.compile(patternStrBuild.toString());
- } catch (PatternSyntaxException e) {
- throw new PatternSyntaxException("Regular expression error", value, e.getIndex());
- }
- }
-
- @Override
- public boolean satisfy(Statistics statistics) {
- return true;
- }
-
- @Override
- public boolean allSatisfy(Statistics statistics) {
- return false;
- }
-
- @Override
- public boolean satisfy(long time, Object value) {
- if (filterType != FilterType.VALUE_FILTER) {
- throw new UnsupportedOperationException("");
- }
- return not != pattern.matcher(value.toString()).find();
- }
-
- @Override
- public boolean satisfyStartEndTime(long startTime, long endTime) {
- return true;
- }
-
- @Override
- public boolean containStartEndTime(long startTime, long endTime) {
- return false;
- }
-
- @Override
- public Filter copy() {
- return new Like<>(value, filterType, not);
- }
-
- @Override
- public void serialize(DataOutputStream outputStream) {
- try {
- outputStream.write(getSerializeId().ordinal());
- outputStream.write(filterType.ordinal());
- ReadWriteIOUtils.write(value, outputStream);
- ReadWriteIOUtils.write(not, outputStream);
- } catch (IOException ignored) {
- // ignore
- }
- }
-
- @Override
- public void deserialize(ByteBuffer buffer) {
- filterType = FilterType.values()[buffer.get()];
- value = ReadWriteIOUtils.readString(buffer);
- not = ReadWriteIOUtils.readBool(buffer);
- }
-
- @Override
- public String toString() {
- return filterType + (not ? " not like " : " like ") + value;
- }
-
- @Override
- public FilterSerializeId getSerializeId() {
- return FilterSerializeId.LIKE;
- }
-
- @Override
- public Filter reverse() {
- return new Like<>(value, filterType, !not);
- }
-
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof Like)) {
- return false;
- }
- Like<?> like = (Like<?>) o;
- return not == like.not && value.equals(like.value) && filterType == like.filterType;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(value, filterType, not);
- }
-
- /**
- * This Method is for unescaping strings except '\' before special string '%', '_', '\', because
- * we need to use '\' to judege whether to replace this to regexp string
- */
- private String unescapeString(String value) {
- StringBuilder out = new StringBuilder();
- int curIndex = 0;
- for (; curIndex < value.length(); curIndex++) {
- String ch = String.valueOf(value.charAt(curIndex));
- if ("\\".equals(ch)) {
- if (curIndex < value.length() - 1) {
- String nextChar = String.valueOf(value.charAt(curIndex + 1));
- if ("%".equals(nextChar) || "_".equals(nextChar) || "\\".equals(nextChar)) {
- out.append(ch);
- }
- if ("\\".equals(nextChar)) {
- curIndex++;
- }
- }
- } else {
- out.append(ch);
- }
- }
- return out.toString();
- }
-}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Lt.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Lt.java
deleted file mode 100755
index 4ade012aaf4..00000000000
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Lt.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.tsfile.read.filter.operator;
-
-import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.basic.UnaryFilter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
-
-/**
- * less than.
- *
- * @param <T> comparable data type
- */
-public class Lt<T extends Comparable<T>> extends UnaryFilter<T> {
-
- private static final long serialVersionUID = -2088181659871608986L;
-
- public Lt() {}
-
- public Lt(T value, FilterType filterType) {
- super(value, filterType);
- }
-
- @Override
- public boolean satisfy(Statistics statistics) {
- if (filterType == FilterType.TIME_FILTER) {
- return satisfyStartEndTime(statistics.getStartTime(), statistics.getEndTime());
- } else {
- if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
- return true;
- }
- return value.compareTo((T) statistics.getMinValue()) > 0;
- }
- }
-
- @Override
- public boolean allSatisfy(Statistics statistics) {
- if (filterType == FilterType.TIME_FILTER) {
- return containStartEndTime(statistics.getStartTime(), statistics.getEndTime());
- } else {
- if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
- return false;
- }
- return value.compareTo((T) statistics.getMaxValue()) > 0;
- }
- }
-
- @Override
- public boolean satisfy(long time, Object value) {
- Object v = filterType == FilterType.TIME_FILTER ? time : value;
- return this.value.compareTo((T) v) > 0;
- }
-
- @Override
- public boolean satisfyStartEndTime(long startTime, long endTime) {
- if (filterType == FilterType.TIME_FILTER) {
- long time = (Long) value;
- return time > startTime;
- } else {
- return true;
- }
- }
-
- @Override
- public boolean containStartEndTime(long startTime, long endTime) {
- if (filterType == FilterType.TIME_FILTER) {
- long time = (Long) value;
- return endTime < time;
- } else {
- return false;
- }
- }
-
- @Override
- public Filter copy() {
- return new Lt<>(value, filterType);
- }
-
- @Override
- public String toString() {
- return getFilterType() + " < " + value;
- }
-
- @Override
- public FilterSerializeId getSerializeId() {
- return FilterSerializeId.LT;
- }
-
- @Override
- public Filter reverse() {
- return new GtEq<>(value, filterType);
- }
-}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/LtEq.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/LtEq.java
deleted file mode 100755
index 3d957a8e544..00000000000
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/LtEq.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.tsfile.read.filter.operator;
-
-import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.basic.UnaryFilter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
-
-/**
- * Less than or Equals.
- *
- * @param <T> comparable data type
- */
-public class LtEq<T extends Comparable<T>> extends UnaryFilter<T> {
-
- private static final long serialVersionUID = -2088181659871608986L;
-
- public LtEq(T value, FilterType filterType) {
- super(value, filterType);
- }
-
- public LtEq() {}
-
- @Override
- public boolean satisfy(Statistics statistics) {
- if (filterType == FilterType.TIME_FILTER) {
- return satisfyStartEndTime(statistics.getStartTime(), statistics.getEndTime());
- } else {
- if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
- return true;
- }
- return value.compareTo((T) statistics.getMinValue()) >= 0;
- }
- }
-
- @Override
- public boolean allSatisfy(Statistics statistics) {
- if (filterType == FilterType.TIME_FILTER) {
- return containStartEndTime(statistics.getStartTime(), statistics.getEndTime());
- } else {
- if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
- return false;
- }
- return value.compareTo((T) statistics.getMaxValue()) >= 0;
- }
- }
-
- @Override
- public boolean satisfy(long time, Object value) {
- Object v = filterType == FilterType.TIME_FILTER ? time : value;
- return this.value.compareTo((T) v) >= 0;
- }
-
- @Override
- public boolean satisfyStartEndTime(long startTime, long endTime) {
- if (filterType == FilterType.TIME_FILTER) {
- long time = (Long) value;
- return time >= startTime;
- } else {
- return true;
- }
- }
-
- @Override
- public boolean containStartEndTime(long startTime, long endTime) {
- if (filterType == FilterType.TIME_FILTER) {
- long time = (Long) value;
- return endTime <= time;
- } else {
- return false;
- }
- }
-
- @Override
- public Filter copy() {
- return new LtEq<>(value, filterType);
- }
-
- @Override
- public String toString() {
- return getFilterType() + " <= " + value;
- }
-
- @Override
- public FilterSerializeId getSerializeId() {
- return FilterSerializeId.LTEQ;
- }
-
- @Override
- public Filter reverse() {
- return new Gt<>(value, filterType);
- }
-}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/NotFilter.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Not.java
old mode 100755
new mode 100644
similarity index 65%
rename from iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/NotFilter.java
rename to iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Not.java
index 538d26a47e4..3b4d738f36d
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/NotFilter.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Not.java
@@ -22,29 +22,22 @@ package org.apache.iotdb.tsfile.read.filter.operator;
import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
import org.apache.iotdb.tsfile.read.common.TimeRange;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.Serializable;
-import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
-public class NotFilter implements Filter, Serializable {
+public class Not implements Filter {
- private static final long serialVersionUID = 584860326604020881L;
- private Filter that;
+ private final Filter filter;
+ private final String toString;
public static final String CONTAIN_NOT_ERR_MSG =
"This predicate contains a not! Did you forget to run this predicate through PredicateRemoveNotRewriter? ";
- public NotFilter() {}
-
- public NotFilter(Filter that) {
- this.that = that;
+ public Not(Filter filter) {
+ this.filter = Objects.requireNonNull(filter, "filter cannot be null");
+ this.toString = "not(" + filter + ")";
}
@Override
@@ -59,7 +52,7 @@ public class NotFilter implements Filter, Serializable {
@Override
public boolean satisfy(long time, Object value) {
- return !that.satisfy(time, value);
+ return !filter.satisfy(time, value);
}
@Override
@@ -72,57 +65,18 @@ public class NotFilter implements Filter, Serializable {
throw new UnsupportedOperationException(CONTAIN_NOT_ERR_MSG + this);
}
- @Override
- public Filter copy() {
- return new NotFilter(that.copy());
- }
-
public Filter getFilter() {
- return this.that;
+ return this.filter;
}
@Override
public String toString() {
- return "not (" + that + ")";
- }
-
- @Override
- public void serialize(DataOutputStream outputStream) {
- try {
- outputStream.write(getSerializeId().ordinal());
- that.serialize(outputStream);
- } catch (IOException ignored) {
- // ignored
- }
- }
-
- @Override
- public void deserialize(ByteBuffer buffer) {
- that = FilterFactory.deserialize(buffer);
- }
-
- @Override
- public FilterSerializeId getSerializeId() {
- return FilterSerializeId.NOT;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof NotFilter)) {
- return false;
- }
- NotFilter other = ((NotFilter) obj);
- return this.that.equals(other.that);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(that);
+ return toString;
}
@Override
public List<TimeRange> getTimeRanges() {
- List<TimeRange> list = that.getTimeRanges();
+ List<TimeRange> list = filter.getTimeRanges();
if (list.isEmpty()) {
return list;
}
@@ -146,6 +100,6 @@ public class NotFilter implements Filter, Serializable {
@Override
public Filter reverse() {
- return that;
+ return filter;
}
}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/NotEq.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/NotEq.java
deleted file mode 100755
index 68691ded3eb..00000000000
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/NotEq.java
+++ /dev/null
@@ -1,115 +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.tsfile.read.filter.operator;
-
-import org.apache.iotdb.tsfile.enums.TSDataType;
-import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.basic.UnaryFilter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
-
-/**
- * NotFilter Equals.
- *
- * @param <T> comparable data type
- */
-public class NotEq<T extends Comparable<T>> extends UnaryFilter<T> {
-
- private static final long serialVersionUID = 2574090797476500965L;
-
- public NotEq() {}
-
- public NotEq(T value, FilterType filterType) {
- super(value, filterType);
- }
-
- @Override
- public boolean satisfy(Statistics statistics) {
- if (filterType == FilterType.TIME_FILTER) {
- return satisfyStartEndTime(statistics.getStartTime(), statistics.getEndTime());
- } else {
- if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
- return true;
- }
- return !(value.compareTo((T) statistics.getMinValue()) == 0
- && value.compareTo((T) statistics.getMaxValue()) == 0);
- }
- }
-
- @Override
- public boolean allSatisfy(Statistics statistics) {
- if (filterType == FilterType.TIME_FILTER) {
- return containStartEndTime(statistics.getStartTime(), statistics.getEndTime());
- } else {
- if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
- return false;
- }
- return value.compareTo((T) statistics.getMinValue()) < 0
- || value.compareTo((T) statistics.getMaxValue()) > 0;
- }
- }
-
- @Override
- public boolean satisfy(long time, Object value) {
- Object v = filterType == FilterType.TIME_FILTER ? time : value;
- return !this.value.equals(v);
- }
-
- @Override
- public boolean satisfyStartEndTime(long startTime, long endTime) {
- if (filterType == FilterType.TIME_FILTER) {
- long time = (Long) value;
- return time != startTime || time != endTime;
- } else {
- return true;
- }
- }
-
- @Override
- public boolean containStartEndTime(long startTime, long endTime) {
- if (filterType == FilterType.TIME_FILTER) {
- long time = (Long) value;
- return time < startTime || time > endTime;
- } else {
- return false;
- }
- }
-
- @Override
- public Filter copy() {
- return new NotEq<>(value, filterType);
- }
-
- @Override
- public String toString() {
- return getFilterType() + " != " + value;
- }
-
- @Override
- public FilterSerializeId getSerializeId() {
- return FilterSerializeId.NEQ;
- }
-
- @Override
- public Filter reverse() {
- return new Eq<>(value, filterType);
- }
-}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/OrFilter.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Or.java
old mode 100755
new mode 100644
similarity index 81%
rename from iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/OrFilter.java
rename to iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Or.java
index b5f781f3a04..3f3e299147a
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/OrFilter.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Or.java
@@ -21,37 +21,19 @@ package org.apache.iotdb.tsfile.read.filter.operator;
import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
import org.apache.iotdb.tsfile.read.common.TimeRange;
-import org.apache.iotdb.tsfile.read.filter.basic.BinaryFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.BinaryLogicalFilter;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-/** Either of the left and right operators of AndExpression must satisfy the condition. */
-public class OrFilter extends BinaryFilter implements Serializable {
+public class Or extends BinaryLogicalFilter {
- private static final long serialVersionUID = -968055896528472694L;
-
- public OrFilter() {}
-
- public OrFilter(Filter left, Filter right) {
+ public Or(Filter left, Filter right) {
super(left, right);
}
- @Override
- public String toString() {
- return "(" + left + " || " + right + ")";
- }
-
- @Override
- public Filter copy() {
- return new OrFilter(left.copy(), right.copy());
- }
-
@Override
public boolean satisfy(Statistics statistics) {
return left.satisfy(statistics) || right.satisfy(statistics);
@@ -79,11 +61,6 @@ public class OrFilter extends BinaryFilter implements Serializable {
|| right.containStartEndTime(startTime, endTime);
}
- @Override
- public FilterSerializeId getSerializeId() {
- return FilterSerializeId.OR;
- }
-
@Override
public List<TimeRange> getTimeRanges() {
List<TimeRange> result = new ArrayList<>();
@@ -148,6 +125,6 @@ public class OrFilter extends BinaryFilter implements Serializable {
@Override
public Filter reverse() {
- return FilterFactory.and(left.reverse(), right.reverse());
+ return new And(left.reverse(), right.reverse());
}
}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Regexp.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Regexp.java
deleted file mode 100644
index f3d516f4041..00000000000
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/Regexp.java
+++ /dev/null
@@ -1,199 +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.tsfile.read.filter.operator;
-
-import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
-import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
-import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterSerializeId;
-import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
-import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.Serializable;
-import java.nio.ByteBuffer;
-import java.util.Objects;
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
-
-/**
- * Regexp.
- *
- * @param <T> comparable data type
- */
-public class Regexp<T extends Comparable<T>> implements Filter, Serializable {
-
- private static final long serialVersionUID = -1168073851950524983L;
-
- protected String value;
-
- protected FilterType filterType;
-
- protected Pattern pattern;
-
- protected boolean not;
-
- public Regexp() {}
-
- public Regexp(String value, FilterType filterType, boolean not) {
- this.value = value;
- this.filterType = filterType;
- this.not = not;
- try {
- this.pattern = Pattern.compile(this.value);
- } catch (PatternSyntaxException e) {
- throw new PatternSyntaxException("Regular expression error", value, e.getIndex());
- }
- }
-
- @Override
- public boolean satisfy(Statistics statistics) {
- return true;
- }
-
- @Override
- public boolean allSatisfy(Statistics statistics) {
- return false;
- }
-
- @Override
- public boolean satisfy(long time, Object value) {
- if (filterType != FilterType.VALUE_FILTER) {
- throw new UnsupportedOperationException("");
- }
- return not != pattern.matcher(new MatcherInput(value.toString(), new AccessCount())).find();
- }
-
- @Override
- public boolean satisfyStartEndTime(long startTime, long endTime) {
- return true;
- }
-
- @Override
- public boolean containStartEndTime(long startTime, long endTime) {
- return false;
- }
-
- @Override
- public Filter copy() {
- return new Regexp<>(value, filterType, not);
- }
-
- @Override
- public void serialize(DataOutputStream outputStream) {
- try {
- outputStream.write(getSerializeId().ordinal());
- outputStream.write(filterType.ordinal());
- ReadWriteIOUtils.write(value, outputStream);
- ReadWriteIOUtils.write(not, outputStream);
- } catch (IOException ignored) {
- // ignore
- }
- }
-
- @Override
- public void deserialize(ByteBuffer buffer) {
- filterType = FilterType.values()[buffer.get()];
- value = ReadWriteIOUtils.readString(buffer);
- not = ReadWriteIOUtils.readBool(buffer);
- if (value != null) {
- try {
- this.pattern = Pattern.compile(value);
- } catch (PatternSyntaxException e) {
- throw new PatternSyntaxException("Regular expression error", value, e.getIndex());
- }
- }
- }
-
- @Override
- public String toString() {
- return filterType + (not ? " not match " : " match ") + value;
- }
-
- @Override
- public FilterSerializeId getSerializeId() {
- return FilterSerializeId.REGEXP;
- }
-
- @Override
- public Filter reverse() {
- return new Regexp<>(value, filterType, !not);
- }
-
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof Regexp)) {
- return false;
- }
- Regexp<?> regexp = (Regexp<?>) o;
- return not == regexp.not && value.equals(regexp.value) && filterType == regexp.filterType;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(value, filterType, not);
- }
-
- public static class AccessCount {
- private int count;
- private final int accessThreshold =
- TSFileDescriptor.getInstance().getConfig().getPatternMatchingThreshold();
-
- public void check() throws IllegalStateException {
- if (this.count++ > accessThreshold) {
- throw new IllegalStateException("Pattern access threshold exceeded");
- }
- }
- }
-
- public static class MatcherInput implements CharSequence {
-
- private final CharSequence value;
-
- private final AccessCount access;
-
- public MatcherInput(CharSequence value, AccessCount access) {
- this.value = value;
- this.access = access;
- }
-
- @Override
- public char charAt(int index) {
- this.access.check();
- return this.value.charAt(index);
- }
-
- @Override
- public CharSequence subSequence(int start, int end) {
- return new MatcherInput(this.value.subSequence(start, end), this.access);
- }
-
- @Override
- public int length() {
- return this.value.length();
- }
-
- @Override
- public String toString() {
- return this.value.toString();
- }
- }
-}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/TimeFilterOperators.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/TimeFilterOperators.java
new file mode 100644
index 00000000000..74bfb70cadf
--- /dev/null
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/TimeFilterOperators.java
@@ -0,0 +1,473 @@
+/*
+ * 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.tsfile.read.filter.operator;
+
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.common.TimeRange;
+import org.apache.iotdb.tsfile.read.filter.basic.ColumnCompareFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.ColumnRangeFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.ColumnSetFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.TimeFilter;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * These are the time column operators in a filter predicate expression tree. They are constructed
+ * by using the methods in {@link TimeFilter}
+ */
+public final class TimeFilterOperators {
+
+ private TimeFilterOperators() {
+ // forbidden construction
+ }
+
+ // base class for TimeEq, TimeNotEq, TimeLt, TimeGt, TimeLtEq, TimeGtEq
+ abstract static class TimeColumnCompareFilter extends ColumnCompareFilter<Long> {
+
+ private final String toString;
+
+ // constant cannot be null
+ protected TimeColumnCompareFilter(Long constant) {
+ super(Objects.requireNonNull(constant, "constant cannot be null"));
+
+ String name = getClass().getSimpleName().toLowerCase(Locale.ENGLISH);
+ this.toString = name + "(Time, " + constant + ")";
+ }
+
+ @Override
+ public String toString() {
+ return toString;
+ }
+
+ @Override
+ public boolean satisfy(Statistics statistics) {
+ return satisfyStartEndTime(statistics.getStartTime(), statistics.getEndTime());
+ }
+
+ @Override
+ public boolean allSatisfy(Statistics statistics) {
+ return containStartEndTime(statistics.getStartTime(), statistics.getEndTime());
+ }
+ }
+
+ public static final class TimeEq extends TimeColumnCompareFilter {
+
+ // constant can be null
+ public TimeEq(Long constant) {
+ super(constant);
+ }
+
+ @Override
+ public boolean satisfy(long time, Object value) {
+ return constant.equals(time);
+ }
+
+ @Override
+ public boolean satisfyStartEndTime(long startTime, long endTime) {
+ return constant <= endTime && constant >= startTime;
+ }
+
+ @Override
+ public boolean containStartEndTime(long startTime, long endTime) {
+ return constant == startTime && constant == endTime;
+ }
+
+ @Override
+ public List<TimeRange> getTimeRanges() {
+ return Collections.singletonList(new TimeRange(constant, constant));
+ }
+
+ @Override
+ public Filter reverse() {
+ return new TimeNotEq(constant);
+ }
+ }
+
+ public static final class TimeNotEq extends TimeColumnCompareFilter {
+
+ public TimeNotEq(Long constant) {
+ super(constant);
+ }
+
+ @Override
+ public boolean satisfy(long time, Object value) {
+ return !constant.equals(time);
+ }
+
+ @Override
+ public boolean satisfyStartEndTime(long startTime, long endTime) {
+ return constant != startTime || constant != endTime;
+ }
+
+ @Override
+ public boolean containStartEndTime(long startTime, long endTime) {
+ return constant < startTime || constant > endTime;
+ }
+
+ @Override
+ public List<TimeRange> getTimeRanges() {
+ long time = constant;
+ if (time == Long.MIN_VALUE) {
+ return Collections.singletonList(new TimeRange(time + 1, Long.MAX_VALUE));
+ } else if (time == Long.MAX_VALUE) {
+ return Collections.singletonList(new TimeRange(Long.MIN_VALUE, time - 1));
+ } else {
+ return Arrays.asList(
+ new TimeRange(Long.MIN_VALUE, time - 1), new TimeRange(time + 1, Long.MAX_VALUE));
+ }
+ }
+
+ @Override
+ public Filter reverse() {
+ return new TimeEq(constant);
+ }
+ }
+
+ public static final class TimeLt extends TimeColumnCompareFilter {
+
+ public TimeLt(Long constant) {
+ super(constant);
+ }
+
+ @Override
+ public boolean satisfy(long time, Object value) {
+ return time < constant;
+ }
+
+ @Override
+ public boolean satisfyStartEndTime(long startTime, long endTime) {
+ return startTime < constant;
+ }
+
+ @Override
+ public boolean containStartEndTime(long startTime, long endTime) {
+ return endTime < constant;
+ }
+
+ @Override
+ public List<TimeRange> getTimeRanges() {
+ long right = constant;
+ if (right != Long.MIN_VALUE) {
+ return Collections.singletonList(new TimeRange(Long.MIN_VALUE, right - 1));
+ } else {
+ return Collections.emptyList();
+ }
+ }
+
+ @Override
+ public Filter reverse() {
+ return new TimeGtEq(constant);
+ }
+ }
+
+ public static final class TimeLtEq extends TimeColumnCompareFilter {
+
+ public TimeLtEq(Long constant) {
+ super(constant);
+ }
+
+ @Override
+ public boolean satisfy(long time, Object value) {
+ return time <= constant;
+ }
+
+ @Override
+ public boolean satisfyStartEndTime(long startTime, long endTime) {
+ return constant >= startTime;
+ }
+
+ @Override
+ public boolean containStartEndTime(long startTime, long endTime) {
+ return endTime <= constant;
+ }
+
+ @Override
+ public List<TimeRange> getTimeRanges() {
+ return Collections.singletonList(new TimeRange(Long.MIN_VALUE, constant));
+ }
+
+ @Override
+ public Filter reverse() {
+ return new TimeGt(constant);
+ }
+ }
+
+ public static final class TimeGt extends TimeColumnCompareFilter {
+
+ public TimeGt(Long constant) {
+ super(constant);
+ }
+
+ @Override
+ public boolean satisfy(long time, Object value) {
+ return time > constant;
+ }
+
+ @Override
+ public boolean satisfyStartEndTime(long startTime, long endTime) {
+ return constant < endTime;
+ }
+
+ @Override
+ public boolean containStartEndTime(long startTime, long endTime) {
+ return startTime > constant;
+ }
+
+ @Override
+ public List<TimeRange> getTimeRanges() {
+ long left = constant;
+ if (left != Long.MAX_VALUE) {
+ return Collections.singletonList(new TimeRange(left + 1, Long.MAX_VALUE));
+ } else {
+ return Collections.emptyList();
+ }
+ }
+
+ @Override
+ public Filter reverse() {
+ return new TimeLtEq(constant);
+ }
+ }
+
+ public static final class TimeGtEq extends TimeColumnCompareFilter {
+
+ public TimeGtEq(Long constant) {
+ super(constant);
+ }
+
+ @Override
+ public boolean satisfy(long time, Object value) {
+ return time >= constant;
+ }
+
+ @Override
+ public boolean satisfyStartEndTime(long startTime, long endTime) {
+ return constant <= endTime;
+ }
+
+ @Override
+ public boolean containStartEndTime(long startTime, long endTime) {
+ return startTime >= constant;
+ }
+
+ @Override
+ public List<TimeRange> getTimeRanges() {
+ return Collections.singletonList(new TimeRange(constant, Long.MAX_VALUE));
+ }
+
+ @Override
+ public Filter reverse() {
+ return new TimeLt(constant);
+ }
+ }
+
+ // base class for TimeBetweenAnd, TimeNotBetweenAnd
+ abstract static class TimeColumnRangeFilter extends ColumnRangeFilter<Long> {
+
+ private final String toString;
+
+ // constant cannot be null
+ protected TimeColumnRangeFilter(Long min, Long max) {
+ super(min, max);
+
+ String name = getClass().getSimpleName().toLowerCase(Locale.ENGLISH);
+ this.toString = name + "(Time, " + min + ", " + max + ")";
+ }
+
+ @Override
+ public String toString() {
+ return toString;
+ }
+
+ @Override
+ public boolean satisfy(Statistics statistics) {
+ return satisfyStartEndTime(statistics.getStartTime(), statistics.getEndTime());
+ }
+
+ @Override
+ public boolean allSatisfy(Statistics statistics) {
+ return containStartEndTime(statistics.getStartTime(), statistics.getEndTime());
+ }
+ }
+
+ public static final class TimeBetweenAnd extends TimeColumnRangeFilter {
+
+ public TimeBetweenAnd(Long min, Long max) {
+ super(min, max);
+ }
+
+ @Override
+ public boolean satisfy(long time, Object value) {
+ return time >= min && time <= max;
+ }
+
+ @Override
+ public boolean satisfyStartEndTime(long startTime, long endTime) {
+ return startTime <= max && endTime >= min;
+ }
+
+ @Override
+ public boolean containStartEndTime(long startTime, long endTime) {
+ return startTime >= min && endTime <= max;
+ }
+
+ @Override
+ public List<TimeRange> getTimeRanges() {
+ return Collections.singletonList(new TimeRange(min, max));
+ }
+
+ @Override
+ public Filter reverse() {
+ return new TimeNotBetweenAnd(min, max);
+ }
+ }
+
+ public static final class TimeNotBetweenAnd extends TimeColumnRangeFilter {
+
+ public TimeNotBetweenAnd(Long min, Long max) {
+ super(min, max);
+ }
+
+ @Override
+ public boolean satisfy(long time, Object value) {
+ return time < min || time > max;
+ }
+
+ @Override
+ public boolean satisfyStartEndTime(long startTime, long endTime) {
+ return startTime < min && endTime > max;
+ }
+
+ @Override
+ public boolean containStartEndTime(long startTime, long endTime) {
+ return startTime > max || endTime < min;
+ }
+
+ @Override
+ public List<TimeRange> getTimeRanges() {
+ List<TimeRange> res = new ArrayList<>();
+ if (min != Long.MIN_VALUE) {
+ res.add(new TimeRange(Long.MIN_VALUE, min - 1));
+ }
+ if (max != Long.MAX_VALUE) {
+ res.add(new TimeRange(max + 1, Long.MAX_VALUE));
+ }
+ return res;
+ }
+
+ @Override
+ public Filter reverse() {
+ return new TimeBetweenAnd(min, max);
+ }
+ }
+
+ // base class for TimeIn, TimeNotIn
+ abstract static class TimeColumnSetFilter extends ColumnSetFilter<Long> {
+
+ private final String toString;
+
+ protected TimeColumnSetFilter(Set<Long> candidates) {
+ super(candidates);
+
+ String name = getClass().getSimpleName().toLowerCase(Locale.ENGLISH);
+ this.toString = name + "(Time, " + candidates + ")";
+ }
+
+ @Override
+ public String toString() {
+ return toString;
+ }
+
+ @Override
+ public boolean satisfy(Statistics statistics) {
+ return satisfyStartEndTime(statistics.getStartTime(), statistics.getEndTime());
+ }
+
+ @Override
+ public boolean allSatisfy(Statistics statistics) {
+ return containStartEndTime(statistics.getStartTime(), statistics.getEndTime());
+ }
+
+ @Override
+ public boolean satisfyStartEndTime(long startTime, long endTime) {
+ return true;
+ }
+
+ @Override
+ public boolean containStartEndTime(long startTime, long endTime) {
+ return false;
+ }
+ }
+
+ public static final class TimeIn extends TimeColumnSetFilter {
+
+ public TimeIn(Set<Long> candidates) {
+ super(candidates);
+ }
+
+ @Override
+ public boolean satisfy(long time, Object value) {
+ return candidates.contains(time);
+ }
+
+ @Override
+ public List<TimeRange> getTimeRanges() {
+ List<TimeRange> res = new ArrayList<>();
+ for (long time : candidates) {
+ res.add(new TimeRange(time, time));
+ }
+ return res;
+ }
+
+ @Override
+ public Filter reverse() {
+ return new TimeNotIn(candidates);
+ }
+ }
+
+ public static final class TimeNotIn extends TimeColumnSetFilter {
+
+ public TimeNotIn(Set<Long> candidates) {
+ super(candidates);
+ }
+
+ @Override
+ public boolean satisfy(long time, Object value) {
+ return !candidates.contains(time);
+ }
+
+ @Override
+ public List<TimeRange> getTimeRanges() {
+ return Collections.singletonList(new TimeRange(Long.MIN_VALUE, Long.MAX_VALUE));
+ }
+
+ @Override
+ public Filter reverse() {
+ return new TimeIn(candidates);
+ }
+ }
+}
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/ValueFilterOperators.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/ValueFilterOperators.java
new file mode 100644
index 00000000000..10bc4ba7d69
--- /dev/null
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/filter/operator/ValueFilterOperators.java
@@ -0,0 +1,684 @@
+/*
+ * 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.tsfile.read.filter.operator;
+
+import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
+import org.apache.iotdb.tsfile.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.filter.basic.ColumnCompareFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.ColumnPatternMatchFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.ColumnRangeFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.ColumnSetFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.ValueFilter;
+
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * These are the value column operators in a filter predicate expression tree. They are constructed
+ * by using the methods in {@link ValueFilter}
+ */
+public final class ValueFilterOperators {
+
+ private ValueFilterOperators() {
+ // forbidden construction
+ }
+
+ // base class for ValueEq, ValueNotEq, ValueLt, ValueGt, ValueLtEq, ValueGtEq
+ abstract static class ValueColumnCompareFilter<T extends Comparable<T>>
+ extends ColumnCompareFilter<T> {
+
+ protected final String measurement;
+ private final String toString;
+
+ protected ValueColumnCompareFilter(String measurement, T constant) {
+ super(constant);
+ this.measurement = Objects.requireNonNull(measurement, "measurement cannot be null");
+
+ String name = getClass().getSimpleName().toLowerCase(Locale.ENGLISH);
+ this.toString = name + "(" + measurement + ", " + constant + ")";
+ }
+
+ public String getMeasurement() {
+ return measurement;
+ }
+
+ @Override
+ public String toString() {
+ return toString;
+ }
+
+ @Override
+ public boolean satisfyStartEndTime(long startTime, long endTime) {
+ return true;
+ }
+
+ @Override
+ public boolean containStartEndTime(long startTime, long endTime) {
+ return false;
+ }
+ }
+
+ public static final class ValueEq<T extends Comparable<T>> extends ValueColumnCompareFilter<T> {
+
+ // constant can be null
+ public ValueEq(String measurement, T constant) {
+ super(measurement, constant);
+ }
+
+ @Override
+ public boolean satisfy(Statistics statistics) {
+ if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
+ return true;
+ }
+ return constant.compareTo((T) statistics.getMinValue()) >= 0
+ && constant.compareTo((T) statistics.getMaxValue()) <= 0;
+ }
+
+ @Override
+ public boolean allSatisfy(Statistics statistics) {
+ if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
+ return false;
+ }
+ return constant.compareTo((T) statistics.getMinValue()) == 0
+ && constant.compareTo((T) statistics.getMaxValue()) == 0;
+ }
+
+ @Override
+ public boolean satisfy(long time, Object value) {
+ return constant.equals(value);
+ }
+
+ @Override
+ public Filter reverse() {
+ return new ValueNotEq<>(measurement, constant);
+ }
+ }
+
+ public static final class ValueNotEq<T extends Comparable<T>>
+ extends ValueColumnCompareFilter<T> {
+
+ // constant can be null
+ public ValueNotEq(String measurement, T constant) {
+ super(measurement, constant);
+ }
+
+ @Override
+ public boolean satisfy(Statistics statistics) {
+ if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
+ return true;
+ }
+ return !(constant.compareTo((T) statistics.getMinValue()) == 0
+ && constant.compareTo((T) statistics.getMaxValue()) == 0);
+ }
+
+ @Override
+ public boolean allSatisfy(Statistics statistics) {
+ if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
+ return false;
+ }
+ return constant.compareTo((T) statistics.getMinValue()) < 0
+ || constant.compareTo((T) statistics.getMaxValue()) > 0;
+ }
+
+ @Override
+ public boolean satisfy(long time, Object value) {
+ return !constant.equals(value);
+ }
+
+ @Override
+ public Filter reverse() {
+ return new ValueEq<>(measurement, constant);
+ }
+ }
+
+ public static final class ValueLt<T extends Comparable<T>> extends ValueColumnCompareFilter<T> {
+
+ // constant cannot be null
+ public ValueLt(String measurement, T constant) {
+ super(measurement, Objects.requireNonNull(constant, "constant cannot be null"));
+ }
+
+ @Override
+ public boolean satisfy(Statistics statistics) {
+ if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
+ return true;
+ }
+ return constant.compareTo((T) statistics.getMinValue()) > 0;
+ }
+
+ @Override
+ public boolean allSatisfy(Statistics statistics) {
+ if (statistics.getType() == TSDataType.TEXT || statistics.getType() == TSDataType.BOOLEAN) {
+ return false;
+ }
+ return constant.compareTo((T) statistics.getMaxValue()) > 0;
+ }
+
+ @Override
+ public boolean satisfy(long time, Object value) {
+ return constant.compareTo((T) value) > 0;
+ }
+
+ @Override
+ public Filter reverse() {
+ return new ValueGtEq<>(measurement, constant);
+ }
+ }
+
+ public static final class ValueLtEq<T extends Comparable<T>> extends ValueColumnCompareFilter<T> {
+
+ // constant cannot be null
+ public ValueLtEq(String measurement, T constant) {
+ super(measurement, Objects.requireNonNull(constant, "constant cannot be null"));
... 1335 lines suppressed ...