You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2026/04/24 23:47:40 UTC

(iotdb) branch master updated: Refactor: extract shared table-model PlanNode and Operator code from datanode (#17526)

This is an automated email from the ASF dual-hosted git repository.

JackieTien97 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 89f855c777a Refactor: extract shared table-model PlanNode and Operator code from datanode (#17526)
89f855c777a is described below

commit 89f855c777a7bde38c6beb85909eb489c6145783
Author: shuwenwei <55...@users.noreply.github.com>
AuthorDate: Sat Apr 25 07:47:32 2026 +0800

    Refactor: extract shared table-model PlanNode and Operator code from datanode (#17526)
---
 .../org/apache/iotdb/mqtt/MPPPublishHandler.java   |    8 +-
 external-service-impl/rest/pom.xml                 |    6 +
 .../table/v1/handler/ExceptionHandler.java         |    6 +-
 .../table/v1/handler/ExecuteStatementHandler.java  |    4 +-
 .../table/v1/handler/QueryDataSetHandler.java      |    4 +-
 .../v1/handler/StatementConstructionHandler.java   |    2 +-
 .../protocol/table/v1/impl/RestApiServiceImpl.java |    7 +-
 .../rest/protocol/v1/handler/ExceptionHandler.java |    4 +-
 .../v1/handler/StatementConstructionHandler.java   |    2 +-
 .../rest/protocol/v2/handler/ExceptionHandler.java |    4 +-
 .../v2/handler/StatementConstructionHandler.java   |    2 +-
 .../rest/protocol/v2/impl/RestApiServiceImpl.java  |    2 +-
 integration-test/pom.xml                           |    5 +
 .../org/apache/iotdb/it/env/cluster/EnvUtils.java  |    2 +-
 .../constant/BuiltinAggregationFunctionEnum.java   |    9 +-
 .../it/partition/IoTDBTimePartitionIT.java         |    2 +-
 .../confignode/it/procedure/IoTDBProcedureIT.java  |    2 +-
 .../it/db/it/IoTDBAuthenticationTableIT.java       |   23 +-
 .../db/it/IoTDBMultiTAGsWithAttributesTableIT.java |    8 +-
 .../it/db/it/udf/IoTDBSQLFunctionManagementIT.java |    2 +-
 .../scalar/IoTDBCastFunctionTableIT.java           |    2 +-
 .../scalar/IoTDBFormatFunctionTableIT.java         |   25 +-
 .../it/query/old/query/IoTDBArithmeticTableIT.java |    2 +-
 .../query/old/query/IoTDBGreatestLeastTableIT.java |   23 +-
 .../view/old/query/IoTDBArithmeticTableViewIT.java |    2 +-
 iotdb-client/cli/pom.xml                           |    5 +
 .../apache/iotdb/tool/data/AbstractDataTool.java   |    4 +-
 iotdb-core/calc-commons/pom.xml                    |  275 ++
 .../src/main/codegen/config.fmpp                   |    0
 .../src/main/codegen/dataModel/AllDataType.tdd     |    0
 .../src/main/codegen/dataModel/CompareType.tdd     |    0
 .../src/main/codegen/dataModel/DecimalDataType.tdd |    0
 .../codegen/dataModel/MathematicalDataType.tdd     |    0
 .../codegen/dataModel/MathematicalOperator.tdd     |    0
 .../ArithmeticBinaryColumnTransformer.ftl          |  419 ++
 .../templates/ArithmeticColumnTransformerApi.ftl   |  230 +
 .../templates/ArithmeticUnaryColumnTransformer.ftl |   85 +
 .../src/main/codegen/templates/ModeAccumulator.ftl |  203 +
 .../src/main/codegen/templates/constantFill.ftl    |   81 +
 .../src/main/codegen/templates/linearFill.ftl      |  122 +
 .../src/main/codegen/templates/previousFill.ftl    |  109 +
 .../templates/previousFillWithTimeDuration.ftl     |  130 +
 .../calc/exception/MemoryNotEnoughException.java   |   31 +
 .../calc/exception/QueryProcessException.java      |   45 +
 .../calc/execution/aggregation/Accumulator.java    |   97 +
 .../execution/aggregation/VarianceAccumulator.java |  282 ++
 .../calc/execution/operator/AbstractOperator.java  |  110 +
 .../execution/operator/CommonOperatorContext.java  |  149 +
 .../execution/operator/GroupedTopNBuilder.java     |   32 +
 .../operator/GroupedTopNRowNumberAccumulator.java  |  483 +++
 .../operator/GroupedTopNRowNumberBuilder.java      |  192 +
 .../iotdb/calc/execution/operator/IdRegistry.java  |   76 +
 .../iotdb/calc/execution/operator/Operator.java    |  134 +
 .../operator/RowIdComparisonStrategy.java          |   24 +
 .../calc/execution/operator/RowIdHashStrategy.java |   27 +
 .../calc/execution/operator/RowReference.java      |   45 +
 .../operator/RowReferenceTsBlockManager.java       |  386 ++
 .../SimpleTsBlockWithPositionComparator.java       |   52 +
 .../operator/TsBlockWithPositionComparator.java    |   26 +
 .../process/AbstractConsumeAllOperator.java        |  192 +
 .../operator/process/AbstractFillOperator.java     |  128 +
 .../process/AbstractLinearFillOperator.java        |  275 ++
 .../operator/process/AbstractSortOperator.java     |  369 ++
 .../process/AggregationMergeSortOperator.java      |  304 ++
 .../operator/process/AssignUniqueIdOperator.java   |  141 +
 .../operator/process/CollectOperator.java          |  140 +
 .../operator/process/EnforceSingleRowOperator.java |  123 +
 .../operator/process/FilterAndProjectOperator.java |  443 ++
 .../execution/operator/process/LimitOperator.java  |  116 +
 .../operator/process/MappingCollectOperator.java   |   81 +
 .../operator/process/MergeSortOperator.java        |  272 ++
 .../execution/operator/process/OffsetOperator.java |  117 +
 .../process/PatternRecognitionOperator.java        |  460 ++
 .../process/PreviousFillWithGroupOperator.java     |  213 +
 .../operator/process/ProcessOperator.java          |   24 +
 .../execution/operator/process/SortOperator.java   |   87 +
 .../operator/process/TableFillOperator.java        |   56 +
 .../operator/process/TableLinearFillOperator.java  |   72 +
 .../process/TableLinearFillWithGroupOperator.java  |  171 +
 .../operator/process/TableMergeSortOperator.java   |   56 +
 .../operator/process/TableSortOperator.java        |   63 +
 .../operator/process/TableStreamSortOperator.java  |  220 +
 .../operator/process/TableTopKOperator.java        |   58 +
 .../execution/operator/process/TopKOperator.java   |  427 ++
 .../execution/operator/process/ValuesOperator.java |  120 +
 .../execution/operator/process/fill/IFill.java     |   29 +
 .../operator/process/fill/IFillFilter.java         |   30 +
 .../operator/process/fill/ILinearFill.java         |   65 +
 .../filter/AbstractMonthIntervalFillFilter.java    |   41 +
 .../fill/filter/FixedIntervalFillFilter.java       |   39 +
 .../fill/filter/MonthIntervalMSFillFilter.java     |   45 +
 .../fill/filter/MonthIntervalNSFillFilter.java     |   51 +
 .../fill/filter/MonthIntervalUSFillFilter.java     |   52 +
 .../process/fill/identity/IdentityFill.java        |   37 +
 .../process/fill/identity/IdentityLinearFill.java  |   50 +
 .../operator/process/fill/linear/LinearFill.java   |  257 ++
 .../process/function/PartitionRecognizer.java      |  207 +
 .../function/TableFunctionLeafOperator.java        |  140 +
 .../process/function/TableFunctionOperator.java    |  297 ++
 .../process/function/partition/PartitionCache.java |  122 +
 .../process/function/partition/PartitionState.java |   62 +
 .../operator/process/function/partition/Slice.java |  256 ++
 .../process/gapfill/AbstractGapFillOperator.java   |  241 ++
 .../gapfill/AbstractGapFillWGroupOperator.java     |   62 +
 .../gapfill/AbstractGapFillWoGroupOperator.java    |   52 +
 .../process/gapfill/GapFillWGroupWMoOperator.java  |   71 +
 .../process/gapfill/GapFillWGroupWoMoOperator.java |   68 +
 .../process/gapfill/GapFillWoGroupWMoOperator.java |   57 +
 .../gapfill/GapFillWoGroupWoMoOperator.java        |   53 +
 .../join/SimpleNestedLoopCrossJoinOperator.java    |  254 ++
 .../process/join/merge/MergeSortComparator.java    |  122 +
 .../process/join/merge/SortKeyComparator.java      |   55 +
 .../comparator/AscBinaryTypeJoinKeyComparator.java |   97 +
 .../AscBooleanTypeJoinKeyComparator.java           |   95 +
 .../comparator/AscDoubleTypeJoinKeyComparator.java |   92 +
 .../comparator/AscFloatTypeJoinKeyComparator.java  |   91 +
 .../comparator/AscIntTypeJoinKeyComparator.java    |   91 +
 .../AscLongTypeIgnoreEqualJoinKeyComparator.java   |   95 +
 .../comparator/AscLongTypeJoinKeyComparator.java   |   91 +
 .../DescBinaryTypeJoinKeyComparator.java           |   97 +
 .../DescBooleanTypeJoinKeyComparator.java          |   94 +
 .../DescDoubleTypeJoinKeyComparator.java           |   92 +
 .../comparator/DescFloatTypeJoinKeyComparator.java |   92 +
 .../comparator/DescIntTypeJoinKeyComparator.java   |   91 +
 .../DescLongTypeIgnoreEqualJoinKeyComparator.java  |   95 +
 .../comparator/DescLongTypeJoinKeyComparator.java  |   91 +
 .../join/merge/comparator/JoinKeyComparator.java   |   63 +
 .../merge/comparator/JoinKeyComparatorFactory.java |   94 +
 .../process/rowpattern/LogicalIndexNavigation.java |  203 +
 .../rowpattern/PatternAggregationTracker.java      |  156 +
 .../process/rowpattern/PatternAggregator.java      |  178 +
 .../process/rowpattern/PatternAggregators.java     |   74 +
 .../rowpattern/PatternPartitionExecutor.java       |  427 ++
 .../rowpattern/PatternVariableRecognizer.java      |  151 +
 .../rowpattern/PhysicalAggregationPointer.java     |   32 +
 .../process/rowpattern/PhysicalValueAccessor.java  |   22 +
 .../process/rowpattern/PhysicalValuePointer.java   |   53 +
 .../rowpattern/expression/ArithmeticOperator.java  |   82 +
 .../rowpattern/expression/BinaryComputation.java   |   41 +
 .../rowpattern/expression/BinaryOperator.java      |   31 +
 .../rowpattern/expression/CastComputation.java     |   82 +
 .../rowpattern/expression/ComparisonOperator.java  |  167 +
 .../process/rowpattern/expression/Computation.java |  222 +
 .../rowpattern/expression/ConstantComputation.java |   35 +
 .../rowpattern/expression/LogicalOperator.java     |   55 +
 .../rowpattern/expression/NaryComputation.java     |   42 +
 .../rowpattern/expression/NaryOperator.java        |   32 +
 .../expression/PatternExpressionComputation.java   |  173 +
 .../expression/ReferenceComputation.java           |   39 +
 .../process/rowpattern/matcher/ArrayView.java      |   55 +
 .../operator/process/rowpattern/matcher/Done.java  |   45 +
 .../process/rowpattern/matcher/Instruction.java    |   62 +
 .../process/rowpattern/matcher/IntList.java        |   82 +
 .../process/rowpattern/matcher/IntMultimap.java    |  112 +
 .../process/rowpattern/matcher/IntStack.java       |   60 +
 .../matcher/IrRowPatternToProgramRewriter.java     |  264 ++
 .../operator/process/rowpattern/matcher/Jump.java  |   60 +
 .../process/rowpattern/matcher/MatchEnd.java       |   45 +
 .../process/rowpattern/matcher/MatchLabel.java     |   60 +
 .../process/rowpattern/matcher/MatchResult.java    |   49 +
 .../process/rowpattern/matcher/MatchStart.java     |   45 +
 .../process/rowpattern/matcher/Matcher.java        |  267 ++
 .../rowpattern/matcher/PatternCaptures.java        |   66 +
 .../process/rowpattern/matcher/Program.java        |   83 +
 .../operator/process/rowpattern/matcher/Save.java  |   45 +
 .../operator/process/rowpattern/matcher/Split.java |   69 +
 .../operator/process/window/RowNumberOperator.java |  214 +
 .../process/window/TableWindowOperator.java        |  315 ++
 .../process/window/TopKRankingOperator.java        |  278 ++
 .../process/window/function/WindowFunction.java    |   45 +
 .../window/function/WindowFunctionFactory.java     |   67 +
 .../aggregate/AggregationWindowFunction.java       |  113 +
 .../function/aggregate/WindowAggregator.java       |  132 +
 .../window/function/rank/CumeDistFunction.java     |   52 +
 .../window/function/rank/DenseRankFunction.java    |   52 +
 .../window/function/rank/NTileFunction.java        |   67 +
 .../window/function/rank/PercentRankFunction.java  |   63 +
 .../process/window/function/rank/RankFunction.java |   57 +
 .../window/function/rank/RankWindowFunction.java   |   66 +
 .../window/function/rank/RowNumberFunction.java    |   41 +
 .../window/function/value/FirstValueFunction.java  |   64 +
 .../process/window/function/value/LagFunction.java |  121 +
 .../window/function/value/LastValueFunction.java   |   64 +
 .../window/function/value/LeadFunction.java        |  122 +
 .../window/function/value/NthValueFunction.java    |   84 +
 .../window/function/value/ValueWindowFunction.java |   52 +
 .../process/window/partition/Partition.java        |  237 +
 .../window/partition/PartitionExecutor.java        |  219 +
 .../process/window/partition/frame/Frame.java      |   26 +
 .../process/window/partition/frame/FrameInfo.java  |  203 +
 .../window/partition/frame/GroupsFrame.java        |  238 ++
 .../process/window/partition/frame/RangeFrame.java |  630 +++
 .../process/window/partition/frame/RowsFrame.java  |  104 +
 .../operator/process/window/utils/ColumnList.java  |  141 +
 .../operator/process/window/utils/Range.java       |   38 +
 .../process/window/utils/RowComparator.java        |  266 ++
 .../AbstractAsofMergeSortJoinOperator.java         |  198 +
 .../relational/AbstractMergeSortJoinOperator.java  |  606 +++
 .../relational/AsofMergeSortInnerJoinOperator.java |  127 +
 .../relational/AsofMergeSortLeftJoinOperator.java  |  140 +
 .../source/relational/MarkDistinctOperator.java    |  166 +
 .../relational/MergeSortFullOuterJoinOperator.java |  255 ++
 .../relational/MergeSortInnerJoinOperator.java     |  168 +
 .../relational/MergeSortLeftJoinOperator.java      |  163 +
 .../relational/MergeSortSemiJoinOperator.java      |  228 +
 .../AbstractApproxMostFrequentAccumulator.java     |   62 +
 .../AbstractApproxPercentileAccumulator.java       |  174 +
 .../relational/aggregation/AccumulatorFactory.java |  683 +++
 .../relational/aggregation/AggregationMask.java    |  204 +
 .../aggregation/AggregationOperator.java           |  155 +
 .../ApproxCountDistinctAccumulator.java            |  274 ++
 .../aggregation/ApproxPercentileAccumulator.java   |  124 +
 .../ApproxPercentileWithWeightAccumulator.java     |  180 +
 .../relational/aggregation/AvgAccumulator.java     |  338 ++
 .../BinaryApproxMostFrequentAccumulator.java       |  135 +
 .../BlobApproxMostFrequentAccumulator.java         |   44 +
 .../BooleanApproxMostFrequentAccumulator.java      |  134 +
 .../relational/aggregation/CountAccumulator.java   |  126 +
 .../aggregation/CountAllAccumulator.java           |   97 +
 .../relational/aggregation/CountIfAccumulator.java |  113 +
 .../DoubleApproxMostFrequentAccumulator.java       |  134 +
 .../relational/aggregation/ExtremeAccumulator.java |  363 ++
 .../relational/aggregation/FirstAccumulator.java   |  564 +++
 .../relational/aggregation/FirstByAccumulator.java |  625 +++
 .../aggregation/FirstByDescAccumulator.java        |  191 +
 .../aggregation/FirstDescAccumulator.java          |  172 +
 .../FloatApproxMostFrequentAccumulator.java        |  134 +
 .../IntApproxMostFrequentAccumulator.java          |  134 +
 .../relational/aggregation/LastAccumulator.java    |  538 +++
 .../relational/aggregation/LastByAccumulator.java  |  608 +++
 .../aggregation/LastByDescAccumulator.java         |  244 ++
 .../aggregation/LastDescAccumulator.java           |  197 +
 .../LongApproxMostFrequentAccumulator.java         |  133 +
 .../aggregation/MaskedRecordIterator.java          |   40 +
 .../relational/aggregation/MaxAccumulator.java     |  420 ++
 .../relational/aggregation/MinAccumulator.java     |  420 ++
 .../relational/aggregation/RecordIterator.java     |  201 +
 .../relational/aggregation/SumAccumulator.java     |  301 ++
 .../relational/aggregation/TableAccumulator.java   |   64 +
 .../relational/aggregation/TableAggregator.java    |  147 +
 .../aggregation/TableMaxByAccumulator.java         |   73 +
 .../aggregation/TableMaxMinByBaseAccumulator.java  |  532 +++
 .../aggregation/TableMinByAccumulator.java         |   73 +
 .../aggregation/TableModeAccumulator.java          |  751 ++++
 .../aggregation/TableVarianceAccumulator.java      |  410 ++
 .../UserDefinedAggregateFunctionAccumulator.java   |  153 +
 .../source/relational/aggregation/Utils.java       |  137 +
 .../ApproxMostFrequentBucketDeserializer.java      |   26 +
 .../ApproxMostFrequentBucketSerializer.java        |   26 +
 .../aggregation/approximate/Counter.java           |   76 +
 .../aggregation/approximate/DoublyLinkedList.java  |  178 +
 .../approximate/ExternalizableUtil.java            |   36 +
 .../aggregation/approximate/HyperLogLog.java       |  252 ++
 .../approximate/HyperLogLogStateFactory.java       |   93 +
 .../relational/aggregation/approximate/ITopK.java  |   48 +
 .../aggregation/approximate/ListNode2.java         |   47 +
 .../relational/aggregation/approximate/Pair.java   |   61 +
 .../aggregation/approximate/SpaceSaving.java       |  152 +
 .../approximate/SpaceSavingByteCalculator.java     |   26 +
 .../approximate/SpaceSavingStateFactory.java       |   95 +
 .../aggregation/approximate/StreamSummary.java     |  299 ++
 .../aggregation/approximate/TDigest.java           |  920 ++++
 ...stractGroupedApproxMostFrequentAccumulator.java |   72 +
 ...AbstractGroupedApproxPercentileAccumulator.java |  159 +
 ...BinaryGroupedApproxMostFrequentAccumulator.java |  110 +
 .../BlobGroupedApproxMostFrequentAccumulator.java  |   45 +
 ...ooleanGroupedApproxMostFrequentAccumulator.java |  109 +
 ...DoubleGroupedApproxMostFrequentAccumulator.java |  109 +
 .../FloatGroupedApproxMostFrequentAccumulator.java |  109 +
 .../aggregation/grouped/GroupedAccumulator.java    |   52 +
 .../aggregation/grouped/GroupedAggregator.java     |  114 +
 .../GroupedApproxCountDistinctAccumulator.java     |  320 ++
 .../GroupedApproxPercentileAccumulator.java        |  149 +
 ...oupedApproxPercentileWithWeightAccumulator.java |  203 +
 .../aggregation/grouped/GroupedAvgAccumulator.java |  248 ++
 .../grouped/GroupedCountAccumulator.java           |   92 +
 .../grouped/GroupedCountAllAccumulator.java        |   87 +
 .../grouped/GroupedCountIfAccumulator.java         |   93 +
 .../grouped/GroupedExtremeAccumulator.java         |  412 ++
 .../grouped/GroupedFirstAccumulator.java           |  654 +++
 .../grouped/GroupedFirstByAccumulator.java         |  731 ++++
 .../grouped/GroupedLastAccumulator.java            |  654 +++
 .../grouped/GroupedLastByAccumulator.java          |  729 ++++
 .../aggregation/grouped/GroupedMaxAccumulator.java |  505 +++
 .../grouped/GroupedMaxByAccumulator.java           |   60 +
 .../grouped/GroupedMaxMinByBaseAccumulator.java    |  866 ++++
 .../aggregation/grouped/GroupedMinAccumulator.java |  505 +++
 .../grouped/GroupedMinByAccumulator.java           |   60 +
 .../grouped/GroupedModeAccumulator.java            |  600 +++
 .../aggregation/grouped/GroupedSumAccumulator.java |  213 +
 .../GroupedUserDefinedAggregateAccumulator.java    |  161 +
 .../grouped/GroupedVarianceAccumulator.java        |  325 ++
 .../grouped/HashAggregationOperator.java           |  225 +
 .../IntGroupedApproxMostFrequentAccumulator.java   |  109 +
 .../LongGroupedApproxMostFrequentAccumulator.java  |  109 +
 .../grouped/StreamingAggregationOperator.java      |  288 ++
 .../grouped/StreamingHashAggregationOperator.java  |  354 ++
 .../aggregation/grouped/array/BigArrays.java       |   62 +
 .../aggregation/grouped/array/BinaryBigArray.java  |   82 +
 .../aggregation/grouped/array/BooleanBigArray.java |  166 +
 .../aggregation/grouped/array/ByteBigArray.java    |  162 +
 .../aggregation/grouped/array/DoubleBigArray.java  |  175 +
 .../aggregation/grouped/array/FloatBigArray.java   |  175 +
 .../grouped/array/HyperLogLogBigArray.java         |   89 +
 .../grouped/array/IntArrayFIFOQueue.java           |  201 +
 .../aggregation/grouped/array/IntBigArray.java     |  192 +
 .../aggregation/grouped/array/IntBigArrays.java    |  194 +
 .../aggregation/grouped/array/IntComparator.java   |   33 +
 .../aggregation/grouped/array/LongBigArray.java    |  196 +
 .../grouped/array/LongBigArrayFIFOQueue.java       |  197 +
 .../aggregation/grouped/array/MapBigArray.java     |   94 +
 .../aggregation/grouped/array/ObjectBigArray.java  |  189 +
 .../aggregation/grouped/array/ShortBigArray.java   |  186 +
 .../grouped/array/SpaceSavingBigArray.java         |   98 +
 .../aggregation/grouped/array/TDigestBigArray.java |   80 +
 .../grouped/builder/HashAggregationBuilder.java    |   41 +
 .../builder/InMemoryHashAggregationBuilder.java    |  275 ++
 .../relational/ColumnTransformerBuilder.java       | 1974 +++++++++
 .../iotdb/calc/metric/QueryExecutionMetricSet.java |  224 +
 .../calc/plan/planner/CommonOperatorUtils.java     |  189 +
 .../planner/ITableOperatorGeneratorContext.java    |   30 +
 .../calc/plan/planner/TableOperatorGenerator.java  | 2280 ++++++++++
 .../planner/memory/MemoryReservationManager.java   |   75 +
 .../relational/metadata/CommonMetadataUtils.java   |  190 +
 .../plan/relational/metadata/ITypeMetadata.java    |   29 +
 .../planner/CastToBlobLiteralVisitor.java          |   90 +
 .../planner/CastToBooleanLiteralVisitor.java       |   88 +
 .../planner/CastToDateLiteralVisitor.java          |   90 +
 .../planner/CastToDoubleLiteralVisitor.java        |   88 +
 .../planner/CastToFloatLiteralVisitor.java         |   88 +
 .../planner/CastToInt32LiteralVisitor.java         |   88 +
 .../planner/CastToInt64LiteralVisitor.java         |   88 +
 .../planner/CastToStringLiteralVisitor.java        |   95 +
 .../planner/CastToTimestampLiteralVisitor.java     |   97 +
 .../ir/GlobalTimePredicateExtractVisitor.java      |  308 ++
 .../plan/relational/utils/matching/Capture.java    |   43 +
 .../plan/relational/utils/matching/Captures.java   |   86 +
 .../relational/utils/matching/DefaultPrinter.java  |   77 +
 .../calc/plan/relational/utils/matching/Match.java |   66 +
 .../plan/relational/utils/matching/Pattern.java    |  120 +
 .../relational/utils/matching/PatternVisitor.java  |   46 +
 .../plan/relational/utils/matching/Property.java   |   89 +
 .../relational/utils/matching/PropertyPattern.java |   51 +
 .../utils/matching/pattern/CapturePattern.java     |   53 +
 .../utils/matching/pattern/EqualsPattern.java      |   53 +
 .../utils/matching/pattern/FilterPattern.java      |   55 +
 .../utils/matching/pattern/TypeOfPattern.java      |   59 +
 .../utils/matching/pattern/WithPattern.java        |   65 +
 .../AbstractTemporaryQueryDataFileService.java     |  149 +
 .../ITemporaryQueryDataFileServiceProvider.java    |   25 +
 .../dag/adapter/PointCollectorAdaptor.java         |   97 +
 .../AbstractCaseWhenThenColumnTransformer.java     |  233 +
 .../transformation/dag/column/ColumnCache.java     |   62 +
 .../dag/column/ColumnTransformer.java              |  118 +
 .../dag/column/FailFunctionColumnTransformer.java  |   62 +
 .../column/TableCaseWhenThenColumnTransformer.java |   43 +
 .../column/TreeCaseWhenThenColumnTransformer.java  |   64 +
 .../ArithmeticAdditionColumnTransformer.java       |   36 +
 .../binary/ArithmeticBinaryColumnTransformer.java  |   78 +
 .../ArithmeticDivisionColumnTransformer.java       |   36 +
 .../binary/ArithmeticModuloColumnTransformer.java  |   36 +
 .../ArithmeticMultiplicationColumnTransformer.java |   37 +
 .../ArithmeticSubtractionColumnTransformer.java    |   36 +
 .../dag/column/binary/BinaryColumnTransformer.java |   98 +
 .../binary/CompareBinaryColumnTransformer.java     |  127 +
 .../binary/CompareEqualToColumnTransformer.java    |   48 +
 .../CompareGreaterEqualColumnTransformer.java      |   36 +
 .../CompareGreaterThanColumnTransformer.java       |   36 +
 .../binary/CompareLessEqualColumnTransformer.java  |   36 +
 .../binary/CompareLessThanColumnTransformer.java   |   36 +
 .../binary/CompareNonEqualColumnTransformer.java   |   48 +
 .../dag/column/binary/HmacColumnTransformer.java   |  108 +
 .../dag/column/binary/Like2ColumnTransformer.java  |   92 +
 .../column/binary/LogicAndColumnTransformer.java   |  125 +
 .../binary/LogicBinaryColumnTransformer.java       |   42 +
 .../column/binary/LogicOrColumnTransformer.java    |  126 +
 .../binary/factory/HmacStrategiesFactory.java      |   93 +
 .../dag/column/binary/strategies/HmacStrategy.java |   25 +
 .../dag/column/leaf/ConstantColumnTransformer.java |   54 +
 .../dag/column/leaf/IdentityColumnTransformer.java |   58 +
 .../dag/column/leaf/LeafColumnTransformer.java     |   42 +
 .../dag/column/leaf/NullColumnTransformer.java     |   41 +
 .../dag/column/leaf/TimeColumnTransformer.java     |   51 +
 .../AbstractGreatestLeastColumnTransformer.java    |  114 +
 .../multi/BinaryGreatestColumnTransformer.java     |   58 +
 .../column/multi/BinaryLeastColumnTransformer.java |   58 +
 .../multi/BooleanGreatestColumnTransformer.java    |   57 +
 .../multi/BooleanLeastColumnTransformer.java       |   54 +
 .../column/multi/CoalesceColumnTransformer.java    |   74 +
 .../multi/DoubleGreatestColumnTransformer.java     |   57 +
 .../column/multi/DoubleLeastColumnTransformer.java |   57 +
 .../multi/FloatGreatestColumnTransformer.java      |   57 +
 .../column/multi/FloatLeastColumnTransformer.java  |   57 +
 .../multi/InBinaryMultiColumnTransformer.java      |   59 +
 .../multi/InBooleanMultiColumnTransformer.java     |   58 +
 .../multi/InDoubleMultiColumnTransformer.java      |   58 +
 .../multi/InFloatMultiColumnTransformer.java       |   58 +
 .../multi/InInt32MultiColumnTransformer.java       |   58 +
 .../multi/InInt64MultiColumnTransformer.java       |   58 +
 .../dag/column/multi/InMultiColumnTransformer.java |   66 +
 .../multi/Int32GreatestColumnTransformer.java      |   57 +
 .../column/multi/Int32LeastColumnTransformer.java  |   57 +
 .../multi/Int64GreatestColumnTransformer.java      |   57 +
 .../column/multi/Int64LeastColumnTransformer.java  |   57 +
 .../multi/LogicalAndMultiColumnTransformer.java    |  122 +
 .../multi/LogicalMultiColumnTransformer.java       |   44 +
 .../multi/LogicalOrMultiColumnTransformer.java     |  122 +
 .../column/multi/MappableUDFColumnTransformer.java |   99 +
 .../dag/column/multi/MultiColumnTransformer.java   |   99 +
 .../column/ternary/BetweenColumnTransformer.java   |  123 +
 .../ternary/CompareTernaryColumnTransformer.java   |   39 +
 .../dag/column/ternary/Like3ColumnTransformer.java |  105 +
 .../dag/column/ternary/LpadColumnTransformer.java  |   92 +
 .../dag/column/ternary/RpadColumnTransformer.java  |   92 +
 .../column/ternary/TernaryColumnTransformer.java   |  113 +
 .../dag/column/ternary/utils/BytePaddingUtils.java |   87 +
 .../udf/UserDefineScalarFunctionTransformer.java   |  108 +
 .../unary/ArithmeticNegationColumnTransformer.java |   65 +
 .../dag/column/unary/InColumnTransformer.java      |  269 ++
 .../dag/column/unary/IsNullColumnTransformer.java  |   55 +
 .../dag/column/unary/LikeColumnTransformer.java    |   74 +
 .../column/unary/LogicNotColumnTransformer.java    |   65 +
 .../dag/column/unary/RegularColumnTransformer.java |   87 +
 .../dag/column/unary/UnaryColumnTransformer.java   |   75 +
 .../column/unary/scalar/AbsColumnTransformer.java  |   71 +
 .../scalar/AbstractBitwise2ColumnTransformer.java  |   71 +
 .../scalar/AbstractBitwiseColumnTransformer.java   |   62 +
 .../AbstractCastFunctionColumnTransformer.java     |  406 ++
 .../scalar/AbstractLengthColumnTransformer.java    |   60 +
 .../column/unary/scalar/AcosColumnTransformer.java |   68 +
 .../column/unary/scalar/AsinColumnTransformer.java |   68 +
 .../column/unary/scalar/AtanColumnTransformer.java |   68 +
 .../unary/scalar/BitCount2ColumnTransformer.java   |   76 +
 .../unary/scalar/BitCountColumnTransformer.java    |   68 +
 .../unary/scalar/BitwiseAnd2ColumnTransformer.java |   44 +
 .../unary/scalar/BitwiseAndColumnTransformer.java  |   42 +
 .../scalar/BitwiseLeftShift2ColumnTransformer.java |   60 +
 .../scalar/BitwiseLeftShiftColumnTransformer.java  |   47 +
 .../unary/scalar/BitwiseNotColumnTransformer.java  |   63 +
 .../unary/scalar/BitwiseOr2ColumnTransformer.java  |   44 +
 .../unary/scalar/BitwiseOrColumnTransformer.java   |   42 +
 .../BitwiseRightShift2ColumnTransformer.java       |   60 +
 ...wiseRightShiftArithmetic2ColumnTransformer.java |   65 +
 ...twiseRightShiftArithmeticColumnTransformer.java |   49 +
 .../scalar/BitwiseRightShiftColumnTransformer.java |   47 +
 .../unary/scalar/BitwiseXor2ColumnTransformer.java |   44 +
 .../unary/scalar/BitwiseXorColumnTransformer.java  |   42 +
 .../unary/scalar/BlobLengthColumnTransformer.java  |   37 +
 .../scalar/BytesToDoubleColumnTransformer.java     |   78 +
 .../scalar/BytesToFloatColumnTransformer.java      |   79 +
 .../unary/scalar/BytesToIntColumnTransformer.java  |   81 +
 .../unary/scalar/BytesToLongColumnTransformer.java |   80 +
 .../dag/column/unary/scalar/CRC32Transformer.java  |   61 +
 .../scalar/CastFunctionColumnTransformer.java      |   79 +
 .../column/unary/scalar/CeilColumnTransformer.java |   68 +
 .../unary/scalar/Concat2ColumnTransformer.java     |   81 +
 .../unary/scalar/ConcatColumnTransformer.java      |   81 +
 .../unary/scalar/ConcatMultiColumnTransformer.java |   90 +
 .../column/unary/scalar/CosColumnTransformer.java  |   68 +
 .../column/unary/scalar/CoshColumnTransformer.java |   68 +
 .../scalar/DateBinFunctionColumnTransformer.java   |  231 +
 .../unary/scalar/DegreesColumnTransformer.java     |   68 +
 .../column/unary/scalar/DiffColumnTransformer.java |   86 +
 .../scalar/DiffFunctionColumnTransformer.java      |   92 +
 .../scalar/DoubleToBytesColumnTransformer.java     |   61 +
 .../unary/scalar/EndsWith2ColumnTransformer.java   |   75 +
 .../unary/scalar/EndsWithColumnTransformer.java    |   65 +
 .../column/unary/scalar/ExpColumnTransformer.java  |   68 +
 .../column/unary/scalar/ExtractTransformer.java    |  106 +
 .../scalar/FloatToBytesColumnTransformer.java      |   61 +
 .../unary/scalar/FloorColumnTransformer.java       |   68 +
 .../unary/scalar/FormatColumnTransformer.java      |  122 +
 .../scalar/GenericCodecColumnTransformer.java      |   92 +
 .../scalar/HmacConstantKeyColumnTransformer.java   |   68 +
 .../unary/scalar/IntToBytesColumnTransformer.java  |   62 +
 .../unary/scalar/LTrim2ColumnTransformer.java      |   74 +
 .../unary/scalar/LTrimColumnTransformer.java       |   82 +
 .../unary/scalar/LengthColumnTransformer.java      |   37 +
 .../column/unary/scalar/LnColumnTransformer.java   |   68 +
 .../unary/scalar/Log10ColumnTransformer.java       |   68 +
 .../unary/scalar/LongToBytesColumnTransformer.java |   60 +
 .../unary/scalar/LowerColumnTransformer.java       |   59 +
 .../scalar/ObjectLengthColumnTransformer.java      |   37 +
 .../unary/scalar/RTrim2ColumnTransformer.java      |   74 +
 .../unary/scalar/RTrimColumnTransformer.java       |   82 +
 .../unary/scalar/RadiansColumnTransformer.java     |   68 +
 .../unary/scalar/RegexpLike2ColumnTransformer.java |   72 +
 .../unary/scalar/RegexpLikeColumnTransformer.java  |   64 +
 .../unary/scalar/Replace2ColumnTransformer.java    |   94 +
 .../unary/scalar/Replace3ColumnTransformer.java    |  110 +
 .../scalar/ReplaceFunctionColumnTransformer.java   |   77 +
 .../unary/scalar/RoundColumnTransformer.java       |  105 +
 .../scalar/RoundFunctionColumnTransformer.java     |   94 +
 .../column/unary/scalar/SignColumnTransformer.java |   68 +
 .../column/unary/scalar/SinColumnTransformer.java  |   68 +
 .../column/unary/scalar/SinhColumnTransformer.java |   68 +
 .../column/unary/scalar/SqrtColumnTransformer.java |   68 +
 .../unary/scalar/StartsWith2ColumnTransformer.java |   73 +
 .../unary/scalar/StartsWithColumnTransformer.java  |   73 +
 .../unary/scalar/Strcmp2ColumnTransformer.java     |   72 +
 .../unary/scalar/StrcmpColumnTransformer.java      |   62 +
 .../unary/scalar/Strpos2ColumnTransformer.java     |   72 +
 .../unary/scalar/StrposColumnTransformer.java      |   62 +
 .../unary/scalar/SubString2ColumnTransformer.java  |   86 +
 .../unary/scalar/SubString3ColumnTransformer.java  |  129 +
 .../unary/scalar/SubStringColumnTransformer.java   |   92 +
 .../column/unary/scalar/TanColumnTransformer.java  |   68 +
 .../column/unary/scalar/TanhColumnTransformer.java |   68 +
 .../unary/scalar/Trim2ColumnTransformer.java       |   74 +
 .../column/unary/scalar/TrimColumnTransformer.java |   94 +
 .../scalar/TryCastFunctionColumnTransformer.java   |   85 +
 .../unary/scalar/UpperColumnTransformer.java       |   60 +
 .../scalar/factory/CodecStrategiesFactory.java     |  138 +
 .../factory/NumericCodecStrategiesFactory.java     |  169 +
 .../unary/scalar/inteface/CodecStrategy.java       |   27 +
 .../dag/column/unary/scalar/util/HexUtils.java     |   86 +
 .../unary/scalar/util/SpookyHashV2Utils.java       |  603 +++
 .../unary/scalar/util/TransformerDebugUtils.java   |   62 +
 .../dag/udf/UDFParametersFactory.java              |   55 +
 .../calc/transformation/dag/udf/UDTFExecutor.java  |  300 ++
 .../calc/transformation/dag/util/BitwiseUtils.java |  210 +
 .../transformation/dag/util/CastFunctionUtils.java |  354 ++
 .../dag/util/CommonTransformUtils.java             |   51 +
 .../transformation/dag/util/InputRowUtils.java     |   67 +
 .../calc/transformation/datastructure/Cache.java   |   68 +
 .../datastructure/SerializableList.java            |  167 +
 .../iterator/ListForwardIterator.java              |   28 +
 .../iterator/RowListForwardIterator.java           |  100 +
 .../iterator/TVListForwardIterator.java            |  108 +
 .../row/ElasticSerializableRowList.java            |  485 +++
 .../datastructure/row/SerializableRowList.java     |  374 ++
 .../tv/ElasticSerializableBinaryTVList.java        |  205 +
 .../tv/ElasticSerializableTVList.java              |  287 ++
 .../datastructure/tv/SerializableTVList.java       |  402 ++
 .../datastructure/util/BinaryUtils.java            |   48 +
 .../org/apache/iotdb/calc/utils/HeapTraversal.java |   64 +
 .../iotdb/calc/utils/IObjectFileService.java       |   38 +
 .../calc/utils/IObjectFileServiceProvider.java     |   25 +
 .../org/apache/iotdb/calc/utils/IObjectPath.java   |   65 +
 .../apache/iotdb/calc/utils/ObjectTypeUtils.java   |  178 +
 .../iotdb/calc/utils/constant/SqlConstant.java     |  125 +
 .../calc/utils/datastructure/MergeSortHeap.java    |  117 +
 .../calc/utils/datastructure/MergeSortKey.java     |   45 +
 .../iotdb/calc/utils/datastructure/SortKey.java    |   33 +
 .../apache/iotdb/calc/utils/sort/DiskSpiller.java  |  184 +
 .../iotdb/calc/utils/sort/FileSpillerReader.java   |  155 +
 .../apache/iotdb/calc/utils/sort/MemoryReader.java |   61 +
 .../iotdb/calc/utils/sort/SortBufferManager.java   |   88 +
 .../apache/iotdb/calc/utils/sort/SortReader.java   |   51 +
 .../iotdb/calc/utils/sort/TableDiskSpiller.java    |   48 +
 .../iotdb/calc/utils/sort/TreeDiskSpiller.java     |   44 +
 iotdb-core/confignode/pom.xml                      |    5 +
 .../iotdb/confignode/conf/ConfigNodeConfig.java    |    2 +
 .../consensus/request/ConfigPhysicalPlan.java      |    2 +-
 .../consensus/request/read/ttl/ShowTTLPlan.java    |    2 +-
 .../response/pipe/task/PipeTableResp.java          |    2 +-
 .../statemachine/ConfigRegionStateMachine.java     |    2 +-
 .../iotdb/confignode/manager/ProcedureManager.java |    2 +-
 .../sink/payload/PipeTransferConfigPlanReq.java    |    2 +-
 .../source/PipeConfigTreePatternParseVisitor.java  |    2 +-
 .../persistence/schema/ClusterSchemaInfo.java      |    2 +-
 .../confignode/persistence/schema/ConfigMTree.java |    2 +-
 .../impl/region/AddRegionPeerProcedure.java        |    2 +-
 .../impl/region/ReconstructRegionProcedure.java    |    2 +-
 .../impl/region/RegionMigrateProcedure.java        |    2 +-
 .../impl/region/RemoveRegionPeerProcedure.java     |    2 +-
 .../org/apache/iotdb/consensus/IConsensus.java     |    2 +-
 .../org/apache/iotdb/consensus/IStateMachine.java  |    2 +-
 .../request/BatchIndexedConsensusRequest.java      |    3 +-
 .../common/request/ByteBufferConsensusRequest.java |    3 +-
 .../DeserializedBatchIndexedConsensusRequest.java  |    9 +-
 .../common/request/IConsensusRequest.java          |   47 -
 .../common/request/IndexedConsensusRequest.java    |   13 +-
 .../common/request/IoTConsensusRequest.java        |    2 +-
 .../apache/iotdb/consensus/iot/IoTConsensus.java   |    2 +-
 .../consensus/iot/IoTConsensusServerImpl.java      |    2 +-
 .../iot/log/GetConsensusReqReaderPlan.java         |    2 +-
 .../service/IoTConsensusRPCServiceProcessor.java   |    2 +-
 .../iotdb/consensus/pipe/IoTConsensusV2.java       |    2 +-
 .../consensus/pipe/IoTConsensusV2ServerImpl.java   |    2 +-
 .../ratis/ApplicationStateMachineProxy.java        |    2 +-
 .../iotdb/consensus/ratis/RatisConsensus.java      |    2 +-
 .../iotdb/consensus/ratis/RequestMessage.java      |    2 +-
 .../iotdb/consensus/simple/SimpleConsensus.java    |    2 +-
 .../simple/SimpleConsensusServerImpl.java          |    2 +-
 .../apache/iotdb/consensus/EmptyStateMachine.java  |    2 +-
 .../iotdb/consensus/iot/util/TestStateMachine.java |    2 +-
 .../iotdb/consensus/ratis/RecoverReadTest.java     |    2 +-
 .../apache/iotdb/consensus/ratis/TestUtils.java    |    2 +-
 .../consensus/simple/SimpleConsensusTest.java      |    2 +-
 iotdb-core/datanode/pom.xml                        |   14 +-
 .../ArithmeticBinaryColumnTransformer.ftl          |  419 --
 .../templates/ArithmeticColumnTransformerApi.ftl   |  230 -
 .../templates/ArithmeticUnaryColumnTransformer.ftl |   85 -
 .../src/main/codegen/templates/ModeAccumulator.ftl |  203 -
 .../src/main/codegen/templates/constantFill.ftl    |   81 -
 .../src/main/codegen/templates/linearFill.ftl      |  122 -
 .../src/main/codegen/templates/previousFill.ftl    |  109 -
 .../templates/previousFillWithTimeDuration.ftl     |  130 -
 .../java/org/apache/iotdb/db/conf/IoTDBConfig.java |   70 +-
 .../org/apache/iotdb/db/conf/IoTDBDescriptor.java  |   55 +-
 .../consensus/statemachine/BaseStateMachine.java   |    6 +-
 .../dataregion/DataExecutionVisitor.java           |    6 +-
 .../dataregion/DataRegionStateMachine.java         |    4 +-
 .../IoTConsensusDataRegionStateMachine.java        |    6 +-
 .../schemaregion/SchemaExecutionVisitor.java       |    4 +-
 .../schemaregion/SchemaRegionStateMachine.java     |    4 +-
 .../iotdb/db/exception/BatchProcessException.java  |    2 +-
 .../LoadAnalyzeTableColumnDisorderException.java   |    2 +-
 .../db/exception/query/OutOfTTLException.java      |    2 +-
 .../db/exception/query/QueryProcessException.java  |   45 -
 .../exception/sql/ColumnCreationFailException.java |    3 +-
 .../iotdb/db/exception/sql/SemanticException.java  |   42 -
 .../db/pipe/agent/task/PipeDataNodeTaskAgent.java  |    2 +-
 .../agent/task/subtask/sink/PipeSinkSubtask.java   |    2 +-
 .../common/deletion/PipeDeleteDataNodeEvent.java   |    2 +-
 .../event/common/heartbeat/PipeHeartbeatEvent.java |    2 +-
 .../schema/PipeSchemaRegionSnapshotEvent.java      |    2 +-
 .../schema/PipeSchemaRegionWritePlanEvent.java     |    4 +-
 .../processor/aggregate/AggregateProcessor.java    |    2 +-
 .../processor/TumblingWindowingProcessor.java      |    4 +-
 .../tumbling/TumblingTimeSamplingProcessor.java    |    2 +-
 .../legacy/IoTDBLegacyPipeReceiverAgent.java       |    2 +-
 .../protocol/legacy/loader/DeletionLoader.java     |    2 +-
 .../protocol/legacy/loader/TsFileLoader.java       |    2 +-
 .../protocol/thrift/IoTDBDataNodeReceiver.java     |   13 +-
 .../transform/converter/ValueConverter.java        |    6 +-
 .../statement/PipeConvertedInsertRowStatement.java |    2 +-
 .../visitor/PipePlanToStatementVisitor.java        |    8 +-
 .../visitor/PipeStatementExceptionVisitor.java     |    2 +-
 .../PipeStatementTablePatternParseVisitor.java     |    4 +-
 .../evolvable/request/PipeTransferPlanNodeReq.java |    4 +-
 .../request/PipeTransferTabletBinaryReq.java       |    2 +-
 .../request/IoTConsensusV2DeleteNodeReq.java       |    2 +-
 .../request/IoTConsensusV2TabletBinaryReq.java     |    2 +-
 .../request/IoTConsensusV2TabletInsertNodeReq.java |    2 +-
 .../sink/protocol/opcua/server/OpcUaNameSpace.java |    4 +-
 .../sink/protocol/writeback/WriteBackSink.java     |    8 +-
 .../builder/PipeTableModelTsFileBuilderV2.java     |    2 +-
 .../util/builder/PipeTreeModelTsFileBuilderV2.java |    2 +-
 .../source/dataregion/IoTDBDataRegionSource.java   |    4 +-
 ...istoricalDataRegionTsFileAndDeletionSource.java |    2 +-
 .../realtime/PipeRealtimeDataRegionSource.java     |    2 +-
 .../schemaregion/IoTDBSchemaRegionSource.java      |   12 +-
 .../PipePlanTablePatternParseVisitor.java          |    4 +-
 .../PipePlanTablePrivilegeParseVisitor.java        |    4 +-
 .../PipePlanTreePatternParseVisitor.java           |    4 +-
 .../PipePlanTreePrivilegeParseVisitor.java         |    4 +-
 .../PipeTableStatementToPlanVisitor.java           |    8 +-
 .../PipeTreeStatementToPlanVisitor.java            |    4 +-
 .../schemaregion/SchemaRegionListeningFilter.java  |    4 +-
 .../schemaregion/SchemaRegionListeningQueue.java   |    2 +-
 .../db/protocol/client/DataNodeInternalClient.java |    2 +-
 .../an/DataNodeTableFunctionAINodeService.java     |   50 +
 ...DataNodeTableFunctionAINodeServiceProvider.java |   32 +
 .../iotdb/db/protocol/session/IClientSession.java  |   45 +-
 .../db/protocol/session/PreparedStatementInfo.java |    2 +-
 .../iotdb/db/protocol/session/SessionManager.java  |   25 +-
 .../protocol/thrift/impl/ClientRPCServiceImpl.java |   60 +-
 .../impl/DataNodeInternalRPCServiceImpl.java       |   12 +-
 .../thrift/impl/NativeStatementRequest.java        |    2 +-
 .../db/queryengine/common/ConnectionInfo.java      |   64 -
 .../db/queryengine/common/MPPQueryContext.java     |   13 +-
 .../iotdb/db/queryengine/common/NodeRef.java       |   63 -
 .../iotdb/db/queryengine/common/QueryId.java       |    2 +-
 .../db/queryengine/common/ResultNodeContext.java   |    2 +-
 .../iotdb/db/queryengine/common/SessionInfo.java   |  197 -
 .../queryengine/common/header/DatasetHeader.java   |    4 +-
 .../common/schematree/ClusterSchemaTree.java       |    2 +-
 .../exception/MemoryNotEnoughException.java        |   31 -
 .../execution/MemoryEstimationHelper.java          |  138 -
 .../execution/aggregation/Accumulator.java         |   97 -
 .../execution/aggregation/AccumulatorFactory.java  |    8 +
 .../execution/aggregation/AvgAccumulator.java      |    2 +
 .../execution/aggregation/CountAccumulator.java    |    2 +
 .../execution/aggregation/CountIfAccumulator.java  |    2 +
 .../aggregation/CountTimeAccumulator.java          |    2 +
 .../execution/aggregation/ExtremeAccumulator.java  |    2 +
 .../aggregation/FirstValueAccumulator.java         |    2 +
 .../aggregation/LastValueAccumulator.java          |    2 +
 .../aggregation/MaxMinByBaseAccumulator.java       |    2 +
 .../execution/aggregation/MaxTimeAccumulator.java  |    2 +
 .../execution/aggregation/MaxValueAccumulator.java |    2 +
 .../execution/aggregation/MinTimeAccumulator.java  |    2 +
 .../execution/aggregation/MinValueAccumulator.java |    2 +
 .../execution/aggregation/SumAccumulator.java      |    2 +
 .../aggregation/TimeDurationAccumulator.java       |    2 +
 .../execution/aggregation/TreeAggregator.java      |    9 +-
 .../execution/aggregation/UDAFAccumulator.java     |    5 +-
 .../execution/aggregation/VarianceAccumulator.java |  282 --
 .../EmptyQueueSlidingWindowAggregator.java         |    4 +-
 .../MonotonicQueueSlidingWindowAggregator.java     |    4 +-
 .../NormalQueueSlidingWindowAggregator.java        |    4 +-
 .../slidingwindow/SlidingWindowAggregator.java     |    4 +-
 .../SlidingWindowAggregatorFactory.java            |    6 +-
 .../SmoothQueueSlidingWindowAggregator.java        |    4 +-
 .../timerangeiterator/AggrWindowIterator.java      |    4 +-
 .../TableDateBinTimeRangeIterator.java             |    2 +-
 .../TimeRangeIteratorFactory.java                  |    2 +-
 .../queryengine/execution/driver/DataDriver.java   |    6 +-
 .../execution/driver/DataDriverContext.java        |    2 +-
 .../db/queryengine/execution/driver/Driver.java    |    8 +-
 .../execution/driver/DriverContext.java            |    2 +-
 .../queryengine/execution/driver/SchemaDriver.java |    2 +-
 .../execution/executor/RegionWriteExecutor.java    |   83 +-
 .../fragment/FakedFragmentInstanceContext.java     |    2 +-
 .../fragment/FragmentInstanceContext.java          |   19 +-
 .../fragment/FragmentInstanceExecution.java        |    2 +-
 .../fragment/FragmentInstanceManager.java          |    6 +-
 .../INodeCommonFragmentInstanceContext.java        |   32 +
 .../execution/operator/AbstractOperator.java       |  110 -
 .../execution/operator/AggregationUtil.java        |    2 +-
 .../execution/operator/EmptyDataOperator.java      |    3 +-
 .../execution/operator/ExplainAnalyzeOperator.java |    9 +-
 .../execution/operator/GroupedTopNBuilder.java     |   32 -
 .../operator/GroupedTopNRowNumberAccumulator.java  |  483 ---
 .../operator/GroupedTopNRowNumberBuilder.java      |  192 -
 .../queryengine/execution/operator/IdRegistry.java |   76 -
 .../queryengine/execution/operator/Operator.java   |  134 -
 .../execution/operator/OperatorContext.java        |  130 +-
 .../operator/RowIdComparisonStrategy.java          |   24 -
 .../execution/operator/RowIdHashStrategy.java      |   27 -
 .../execution/operator/RowReference.java           |   45 -
 .../operator/RowReferenceTsBlockManager.java       |  386 --
 .../SimpleTsBlockWithPositionComparator.java       |   52 -
 .../operator/TsBlockWithPositionComparator.java    |   26 -
 .../process/AbstractConsumeAllOperator.java        |  191 -
 .../operator/process/AbstractFillOperator.java     |  127 -
 .../operator/process/AbstractIntoOperator.java     |    3 +-
 .../process/AbstractLinearFillOperator.java        |  275 --
 .../operator/process/AbstractSortOperator.java     |  369 --
 .../operator/process/AbstractTreeIntoOperator.java |    4 +-
 .../process/ActiveRegionScanMergeOperator.java     |    5 +-
 .../process/AggregationMergeSortOperator.java      |  304 --
 .../operator/process/AggregationOperator.java      |    5 +-
 .../operator/process/AssignUniqueIdOperator.java   |  142 -
 .../operator/process/CollectOperator.java          |  140 -
 .../operator/process/ColumnInjectOperator.java     |    5 +-
 .../operator/process/DeviceViewIntoOperator.java   |    6 +-
 .../operator/process/DeviceViewOperator.java       |    5 +-
 .../operator/process/EnforceSingleRowOperator.java |  123 -
 .../operator/process/FilterAndProjectOperator.java |  443 --
 .../process/InsertTabletStatementGenerator.java    |    2 +-
 .../execution/operator/process/LimitOperator.java  |  116 -
 .../operator/process/MappingCollectOperator.java   |   79 -
 .../operator/process/MergeSortOperator.java        |  272 --
 .../execution/operator/process/OffsetOperator.java |  117 -
 .../process/PatternRecognitionOperator.java        |  464 --
 .../process/PreviousFillWithGroupOperator.java     |  213 -
 .../operator/process/ProcessOperator.java          |   24 -
 .../operator/process/ProjectOperator.java          |    5 +-
 .../process/RawDataAggregationOperator.java        |    4 +-
 .../operator/process/SingleDeviceViewOperator.java |    5 +-
 .../process/SingleInputAggregationOperator.java    |    3 +-
 .../process/SlidingWindowAggregationOperator.java  |    4 +-
 .../execution/operator/process/SortOperator.java   |   87 -
 .../operator/process/TableFillOperator.java        |   53 -
 .../TableInsertTabletStatementGenerator.java       |    2 +-
 .../operator/process/TableIntoOperator.java        |    8 +-
 .../operator/process/TableLinearFillOperator.java  |   72 -
 .../process/TableLinearFillWithGroupOperator.java  |  171 -
 .../operator/process/TableMergeSortOperator.java   |   56 -
 .../operator/process/TableSortOperator.java        |   63 -
 .../operator/process/TableStreamSortOperator.java  |  220 -
 .../operator/process/TableTopKOperator.java        |   57 -
 .../operator/process/TagAggregationOperator.java   |    5 +-
 .../execution/operator/process/TopKOperator.java   |  427 --
 .../operator/process/TransformOperator.java        |   13 +-
 .../operator/process/TreeFillOperator.java         |    7 +-
 .../TreeInsertTabletStatementGenerator.java        |    2 +-
 .../operator/process/TreeIntoOperator.java         |    6 +-
 .../operator/process/TreeLinearFillOperator.java   |    9 +-
 .../operator/process/TreeMergeSortOperator.java    |    5 +-
 .../operator/process/TreeSortOperator.java         |    7 +-
 .../operator/process/TreeTopKOperator.java         |    5 +-
 .../execution/operator/process/ValuesOperator.java |  120 -
 .../operator/process/ai/InferenceOperator.java     |    8 +-
 .../operator/process/copyto/CopyToOptions.java     |    4 +-
 .../process/copyto/TableCopyToOperator.java        |    6 +-
 .../process/copyto/tsfile/CopyToTsFileOptions.java |   10 +-
 .../execution/operator/process/fill/IFill.java     |   29 -
 .../operator/process/fill/IFillFilter.java         |   30 -
 .../operator/process/fill/ILinearFill.java         |   65 -
 .../filter/AbstractMonthIntervalFillFilter.java    |   41 -
 .../fill/filter/FixedIntervalFillFilter.java       |   39 -
 .../fill/filter/MonthIntervalMSFillFilter.java     |   45 -
 .../fill/filter/MonthIntervalNSFillFilter.java     |   51 -
 .../fill/filter/MonthIntervalUSFillFilter.java     |   52 -
 .../process/fill/identity/IdentityFill.java        |   37 -
 .../process/fill/identity/IdentityLinearFill.java  |   50 -
 .../operator/process/fill/linear/LinearFill.java   |  257 --
 .../process/function/PartitionRecognizer.java      |  207 -
 .../function/TableFunctionLeafOperator.java        |  140 -
 .../process/function/TableFunctionOperator.java    |  297 --
 .../process/function/partition/PartitionCache.java |  122 -
 .../process/function/partition/PartitionState.java |   62 -
 .../operator/process/function/partition/Slice.java |  256 --
 .../process/gapfill/AbstractGapFillOperator.java   |  239 --
 .../gapfill/AbstractGapFillWGroupOperator.java     |   62 -
 .../gapfill/AbstractGapFillWoGroupOperator.java    |   52 -
 .../process/gapfill/GapFillWGroupWMoOperator.java  |   71 -
 .../process/gapfill/GapFillWGroupWoMoOperator.java |   68 -
 .../process/gapfill/GapFillWoGroupWMoOperator.java |   57 -
 .../gapfill/GapFillWoGroupWoMoOperator.java        |   53 -
 .../process/join/FullOuterTimeJoinOperator.java    |    6 +-
 .../process/join/HorizontallyConcatOperator.java   |    6 +-
 .../process/join/InnerTimeJoinOperator.java        |    8 +-
 .../process/join/LeftOuterTimeJoinOperator.java    |    6 +-
 .../join/SimpleNestedLoopCrossJoinOperator.java    |  258 --
 .../join/TableLeftOuterTimeJoinOperator.java       |    4 +-
 .../process/join/merge/MergeSortComparator.java    |  145 -
 .../join/merge/MergeSortComparatorUtils.java       |   55 +
 .../process/join/merge/MultiColumnMerger.java      |    2 +-
 .../join/merge/NonOverlappedMultiColumnMerger.java |    2 +-
 .../process/join/merge/SingleColumnMerger.java     |    2 +-
 .../process/join/merge/SortKeyComparator.java      |   55 -
 .../comparator/AscBinaryTypeJoinKeyComparator.java |   97 -
 .../AscBooleanTypeJoinKeyComparator.java           |   95 -
 .../comparator/AscDoubleTypeJoinKeyComparator.java |   92 -
 .../comparator/AscFloatTypeJoinKeyComparator.java  |   91 -
 .../comparator/AscIntTypeJoinKeyComparator.java    |   91 -
 .../AscLongTypeIgnoreEqualJoinKeyComparator.java   |   95 -
 .../comparator/AscLongTypeJoinKeyComparator.java   |   91 -
 .../DescBinaryTypeJoinKeyComparator.java           |   97 -
 .../DescBooleanTypeJoinKeyComparator.java          |   94 -
 .../DescDoubleTypeJoinKeyComparator.java           |   92 -
 .../comparator/DescFloatTypeJoinKeyComparator.java |   92 -
 .../comparator/DescIntTypeJoinKeyComparator.java   |   91 -
 .../DescLongTypeIgnoreEqualJoinKeyComparator.java  |   95 -
 .../comparator/DescLongTypeJoinKeyComparator.java  |   91 -
 .../join/merge/comparator/JoinKeyComparator.java   |   63 -
 .../merge/comparator/JoinKeyComparatorFactory.java |   94 -
 .../last/AbstractUpdateLastCacheOperator.java      |    4 +-
 .../last/AlignedUpdateLastCacheOperator.java       |    4 +-
 .../AlignedUpdateViewPathLastCacheOperator.java    |    2 +-
 .../process/last/LastQueryCollectOperator.java     |    6 +-
 .../process/last/LastQueryMergeOperator.java       |    6 +-
 .../operator/process/last/LastQueryOperator.java   |    6 +-
 .../process/last/LastQuerySortOperator.java        |    6 +-
 .../process/last/LastQueryTransformOperator.java   |    6 +-
 .../operator/process/last/LastQueryUtil.java       |    2 +-
 .../process/last/UpdateLastCacheOperator.java      |    4 +-
 .../last/UpdateViewPathLastCacheOperator.java      |    2 +-
 .../process/rowpattern/LogicalIndexNavigation.java |  189 -
 .../rowpattern/PatternAggregationTracker.java      |  156 -
 .../process/rowpattern/PatternAggregator.java      |  178 -
 .../process/rowpattern/PatternAggregators.java     |   74 -
 .../rowpattern/PatternPartitionExecutor.java       |  427 --
 .../rowpattern/PatternVariableRecognizer.java      |  151 -
 .../rowpattern/PhysicalAggregationPointer.java     |   32 -
 .../process/rowpattern/PhysicalValueAccessor.java  |   22 -
 .../process/rowpattern/PhysicalValuePointer.java   |   53 -
 .../rowpattern/expression/ArithmeticOperator.java  |   82 -
 .../rowpattern/expression/BinaryComputation.java   |   41 -
 .../rowpattern/expression/BinaryOperator.java      |   31 -
 .../rowpattern/expression/CastComputation.java     |   82 -
 .../rowpattern/expression/ComparisonOperator.java  |  167 -
 .../process/rowpattern/expression/Computation.java |  222 -
 .../rowpattern/expression/ConstantComputation.java |   35 -
 .../rowpattern/expression/LogicalOperator.java     |   55 -
 .../rowpattern/expression/NaryComputation.java     |   42 -
 .../rowpattern/expression/NaryOperator.java        |   32 -
 .../expression/PatternExpressionComputation.java   |  173 -
 .../expression/ReferenceComputation.java           |   39 -
 .../process/rowpattern/matcher/ArrayView.java      |   55 -
 .../operator/process/rowpattern/matcher/Done.java  |   45 -
 .../process/rowpattern/matcher/Instruction.java    |   62 -
 .../process/rowpattern/matcher/IntList.java        |   82 -
 .../process/rowpattern/matcher/IntMultimap.java    |  112 -
 .../process/rowpattern/matcher/IntStack.java       |   60 -
 .../matcher/IrRowPatternToProgramRewriter.java     |  264 --
 .../operator/process/rowpattern/matcher/Jump.java  |   60 -
 .../process/rowpattern/matcher/MatchEnd.java       |   45 -
 .../process/rowpattern/matcher/MatchLabel.java     |   60 -
 .../process/rowpattern/matcher/MatchResult.java    |   49 -
 .../process/rowpattern/matcher/MatchStart.java     |   45 -
 .../process/rowpattern/matcher/Matcher.java        |  267 --
 .../rowpattern/matcher/PatternCaptures.java        |   66 -
 .../process/rowpattern/matcher/Program.java        |   83 -
 .../operator/process/rowpattern/matcher/Save.java  |   45 -
 .../operator/process/rowpattern/matcher/Split.java |   69 -
 .../operator/process/window/RowNumberOperator.java |  214 -
 .../process/window/TableWindowOperator.java        |  318 --
 .../process/window/TopKRankingOperator.java        |  278 --
 .../process/window/function/WindowFunction.java    |   45 -
 .../window/function/WindowFunctionFactory.java     |   67 -
 .../aggregate/AggregationWindowFunction.java       |  113 -
 .../function/aggregate/WindowAggregator.java       |  126 -
 .../window/function/rank/CumeDistFunction.java     |   52 -
 .../window/function/rank/DenseRankFunction.java    |   52 -
 .../window/function/rank/NTileFunction.java        |   67 -
 .../window/function/rank/PercentRankFunction.java  |   63 -
 .../process/window/function/rank/RankFunction.java |   57 -
 .../window/function/rank/RankWindowFunction.java   |   66 -
 .../window/function/rank/RowNumberFunction.java    |   41 -
 .../window/function/value/FirstValueFunction.java  |   64 -
 .../process/window/function/value/LagFunction.java |  121 -
 .../window/function/value/LastValueFunction.java   |   64 -
 .../window/function/value/LeadFunction.java        |  122 -
 .../window/function/value/NthValueFunction.java    |   84 -
 .../window/function/value/ValueWindowFunction.java |   52 -
 .../process/window/partition/Partition.java        |  237 -
 .../window/partition/PartitionExecutor.java        |  219 -
 .../process/window/partition/frame/Frame.java      |   26 -
 .../process/window/partition/frame/FrameInfo.java  |  203 -
 .../window/partition/frame/GroupsFrame.java        |  238 --
 .../process/window/partition/frame/RangeFrame.java |  630 ---
 .../process/window/partition/frame/RowsFrame.java  |  104 -
 .../operator/process/window/utils/ColumnList.java  |  141 -
 .../operator/process/window/utils/Range.java       |   38 -
 .../process/window/utils/RowComparator.java        |  266 --
 .../schema/CountGroupByLevelMergeOperator.java     |    6 +-
 .../schema/CountGroupByLevelScanOperator.java      |    4 +-
 .../operator/schema/CountMergeOperator.java        |    6 +-
 .../schema/NodeManageMemoryMergeOperator.java      |    6 +-
 .../operator/schema/NodePathsConvertOperator.java  |    6 +-
 .../operator/schema/NodePathsCountOperator.java    |    6 +-
 .../operator/schema/SchemaCountOperator.java       |    4 +-
 .../operator/schema/SchemaFetchMergeOperator.java  |    6 +-
 .../operator/schema/SchemaFetchScanOperator.java   |    4 +-
 .../operator/schema/SchemaQueryMergeOperator.java  |    6 +-
 .../schema/SchemaQueryOrderByHeatOperator.java     |    6 +-
 .../operator/schema/SchemaQueryScanOperator.java   |    4 +-
 .../schema/source/DeviceAttributeUpdater.java      |    6 +-
 .../schema/source/DeviceBlackListConstructor.java  |    4 +-
 .../schema/source/DevicePredicateFilter.java       |    4 +-
 .../schema/source/DevicePredicateHandler.java      |    6 +-
 .../operator/schema/source/DeviceUpdater.java      |    4 +-
 .../operator/sink/IdentitySinkOperator.java        |    4 +-
 .../operator/sink/ShuffleHelperOperator.java       |    4 +-
 .../execution/operator/sink/SinkOperator.java      |    2 +-
 .../AbstractRegionScanDataSourceOperator.java      |    2 +-
 .../AbstractSeriesAggregationScanOperator.java     |    2 +-
 .../operator/source/AbstractSourceOperator.java    |    4 +-
 .../source/ActiveDeviceRegionScanOperator.java     |    2 +-
 .../source/ActiveTimeSeriesRegionScanOperator.java |    2 +-
 .../AlignedSeriesAggregationScanOperator.java      |    4 +-
 .../operator/source/AlignedSeriesScanOperator.java |    4 +-
 .../operator/source/ExchangeOperator.java          |    4 +-
 .../operator/source/LastCacheScanOperator.java     |    4 +-
 .../source/SeriesAggregationScanOperator.java      |    4 +-
 .../operator/source/SeriesScanOperator.java        |    4 +-
 .../operator/source/ShowDiskUsageOperator.java     |    4 +-
 .../operator/source/ShowQueriesOperator.java       |   10 +-
 .../execution/operator/source/SourceOperator.java  |    4 +-
 .../relational/AbstractAggTableScanOperator.java   |   23 +-
 .../AbstractAsofMergeSortJoinOperator.java         |  198 -
 .../AbstractDefaultAggTableScanOperator.java       |    4 +-
 .../relational/AbstractMergeSortJoinOperator.java  |  609 ---
 .../relational/AbstractTableScanOperator.java      |   21 +-
 .../relational/AsofMergeSortInnerJoinOperator.java |  127 -
 .../relational/AsofMergeSortLeftJoinOperator.java  |  140 -
 .../source/relational/CteScanOperator.java         |    6 +-
 .../relational/DeviceIteratorScanOperator.java     |   10 +-
 .../InformationSchemaContentSupplierFactory.java   |   26 +-
 .../InformationSchemaTableScanOperator.java        |    4 +-
 .../relational/LastQueryAggTableScanOperator.java  |   16 +-
 .../source/relational/MarkDistinctOperator.java    |  170 -
 .../MeasurementToTableViewAdaptorUtils.java        |    4 +-
 .../relational/MergeSortFullOuterJoinOperator.java |  256 --
 .../relational/MergeSortInnerJoinOperator.java     |  168 -
 .../relational/MergeSortLeftJoinOperator.java      |  163 -
 .../relational/MergeSortSemiJoinOperator.java      |  228 -
 ...onAlignedDeviceViewAggregationScanOperator.java |    8 +-
 .../relational/TreeToTableViewAdaptorOperator.java |    8 +-
 .../AbstractApproxMostFrequentAccumulator.java     |   57 -
 .../AbstractApproxPercentileAccumulator.java       |  169 -
 .../relational/aggregation/AccumulatorFactory.java |  683 ---
 .../relational/aggregation/AggregationMask.java    |  204 -
 .../aggregation/AggregationOperator.java           |  159 -
 .../ApproxCountDistinctAccumulator.java            |  269 --
 .../aggregation/ApproxPercentileAccumulator.java   |  119 -
 .../ApproxPercentileWithWeightAccumulator.java     |  175 -
 .../relational/aggregation/AvgAccumulator.java     |  338 --
 .../BinaryApproxMostFrequentAccumulator.java       |  130 -
 .../BlobApproxMostFrequentAccumulator.java         |   39 -
 .../BooleanApproxMostFrequentAccumulator.java      |  129 -
 .../relational/aggregation/CountAccumulator.java   |  126 -
 .../aggregation/CountAllAccumulator.java           |   97 -
 .../relational/aggregation/CountIfAccumulator.java |  113 -
 .../DoubleApproxMostFrequentAccumulator.java       |  129 -
 .../relational/aggregation/ExtremeAccumulator.java |  363 --
 .../relational/aggregation/FirstAccumulator.java   |  564 ---
 .../relational/aggregation/FirstByAccumulator.java |  625 ---
 .../aggregation/FirstByDescAccumulator.java        |  191 -
 .../aggregation/FirstDescAccumulator.java          |  172 -
 .../FloatApproxMostFrequentAccumulator.java        |  129 -
 .../IntApproxMostFrequentAccumulator.java          |  129 -
 .../relational/aggregation/LastAccumulator.java    |  538 ---
 .../relational/aggregation/LastByAccumulator.java  |  608 ---
 .../aggregation/LastByDescAccumulator.java         |  244 --
 .../aggregation/LastDescAccumulator.java           |  197 -
 .../LongApproxMostFrequentAccumulator.java         |  128 -
 .../aggregation/MaskedRecordIterator.java          |   40 -
 .../relational/aggregation/MaxAccumulator.java     |  420 --
 .../relational/aggregation/MinAccumulator.java     |  420 --
 .../relational/aggregation/RecordIterator.java     |  201 -
 .../relational/aggregation/SumAccumulator.java     |  301 --
 .../relational/aggregation/TableAccumulator.java   |   64 -
 .../relational/aggregation/TableAggregator.java    |  142 -
 .../aggregation/TableMaxByAccumulator.java         |   73 -
 .../aggregation/TableMaxMinByBaseAccumulator.java  |  532 ---
 .../aggregation/TableMinByAccumulator.java         |   73 -
 .../aggregation/TableModeAccumulator.java          |  751 ----
 .../aggregation/TableVarianceAccumulator.java      |  410 --
 .../UserDefinedAggregateFunctionAccumulator.java   |  153 -
 .../source/relational/aggregation/Utils.java       |  137 -
 .../ApproxMostFrequentBucketDeserializer.java      |   21 -
 .../ApproxMostFrequentBucketSerializer.java        |   21 -
 .../aggregation/approximate/Counter.java           |   71 -
 .../aggregation/approximate/DoublyLinkedList.java  |  173 -
 .../approximate/ExternalizableUtil.java            |   31 -
 .../aggregation/approximate/HyperLogLog.java       |  247 --
 .../approximate/HyperLogLogStateFactory.java       |   88 -
 .../relational/aggregation/approximate/ITopK.java  |   43 -
 .../aggregation/approximate/ListNode2.java         |   42 -
 .../relational/aggregation/approximate/Pair.java   |   56 -
 .../aggregation/approximate/SpaceSaving.java       |  147 -
 .../approximate/SpaceSavingByteCalculator.java     |   21 -
 .../approximate/SpaceSavingStateFactory.java       |   90 -
 .../aggregation/approximate/StreamSummary.java     |  294 --
 .../aggregation/approximate/TDigest.java           |  915 ----
 ...stractGroupedApproxMostFrequentAccumulator.java |   67 -
 ...AbstractGroupedApproxPercentileAccumulator.java |  154 -
 ...BinaryGroupedApproxMostFrequentAccumulator.java |  105 -
 .../BlobGroupedApproxMostFrequentAccumulator.java  |   40 -
 ...ooleanGroupedApproxMostFrequentAccumulator.java |  104 -
 ...DoubleGroupedApproxMostFrequentAccumulator.java |  104 -
 .../FloatGroupedApproxMostFrequentAccumulator.java |  104 -
 .../aggregation/grouped/GroupedAccumulator.java    |   52 -
 .../aggregation/grouped/GroupedAggregator.java     |  111 -
 .../GroupedApproxCountDistinctAccumulator.java     |  315 --
 .../GroupedApproxPercentileAccumulator.java        |  144 -
 ...oupedApproxPercentileWithWeightAccumulator.java |  198 -
 .../aggregation/grouped/GroupedAvgAccumulator.java |  248 --
 .../grouped/GroupedCountAccumulator.java           |   92 -
 .../grouped/GroupedCountAllAccumulator.java        |   87 -
 .../grouped/GroupedCountIfAccumulator.java         |   93 -
 .../grouped/GroupedExtremeAccumulator.java         |  412 --
 .../grouped/GroupedFirstAccumulator.java           |  654 ---
 .../grouped/GroupedFirstByAccumulator.java         |  731 ----
 .../grouped/GroupedLastAccumulator.java            |  654 ---
 .../grouped/GroupedLastByAccumulator.java          |  729 ----
 .../aggregation/grouped/GroupedMaxAccumulator.java |  505 ---
 .../grouped/GroupedMaxByAccumulator.java           |   60 -
 .../grouped/GroupedMaxMinByBaseAccumulator.java    |  866 ----
 .../aggregation/grouped/GroupedMinAccumulator.java |  505 ---
 .../grouped/GroupedMinByAccumulator.java           |   60 -
 .../grouped/GroupedModeAccumulator.java            |  600 ---
 .../aggregation/grouped/GroupedSumAccumulator.java |  213 -
 .../GroupedUserDefinedAggregateAccumulator.java    |  161 -
 .../grouped/GroupedVarianceAccumulator.java        |  325 --
 .../grouped/HashAggregationOperator.java           |  229 -
 .../IntGroupedApproxMostFrequentAccumulator.java   |  104 -
 .../LongGroupedApproxMostFrequentAccumulator.java  |  104 -
 .../grouped/StreamingAggregationOperator.java      |  289 --
 .../grouped/StreamingHashAggregationOperator.java  |  358 --
 .../aggregation/grouped/UpdateMemory.java          |   32 -
 .../aggregation/grouped/array/BigArrays.java       |   62 -
 .../aggregation/grouped/array/BinaryBigArray.java  |   82 -
 .../aggregation/grouped/array/BooleanBigArray.java |  166 -
 .../aggregation/grouped/array/ByteBigArray.java    |  162 -
 .../aggregation/grouped/array/DoubleBigArray.java  |  175 -
 .../aggregation/grouped/array/FloatBigArray.java   |  175 -
 .../grouped/array/HyperLogLogBigArray.java         |   84 -
 .../grouped/array/IntArrayFIFOQueue.java           |  201 -
 .../aggregation/grouped/array/IntBigArray.java     |  192 -
 .../aggregation/grouped/array/IntBigArrays.java    |  194 -
 .../aggregation/grouped/array/IntComparator.java   |   33 -
 .../aggregation/grouped/array/LongBigArray.java    |  196 -
 .../grouped/array/LongBigArrayFIFOQueue.java       |  197 -
 .../aggregation/grouped/array/MapBigArray.java     |   94 -
 .../aggregation/grouped/array/ObjectBigArray.java  |  189 -
 .../aggregation/grouped/array/ShortBigArray.java   |  186 -
 .../grouped/array/SpaceSavingBigArray.java         |   93 -
 .../aggregation/grouped/array/TDigestBigArray.java |   75 -
 .../grouped/builder/HashAggregationBuilder.java    |   41 -
 .../builder/InMemoryHashAggregationBuilder.java    |  275 --
 .../grouped/hash/CombineHashFunction.java          |   37 -
 .../aggregation/grouped/hash/FlatGroupByHash.java  |  210 -
 .../aggregation/grouped/hash/FlatHash.java         |  605 ---
 .../aggregation/grouped/hash/FlatHashStrategy.java |   55 -
 .../aggregation/grouped/hash/GroupByHash.java      |   61 -
 .../aggregation/grouped/hash/HashStrategy.java     |  225 -
 .../aggregation/grouped/hash/MarkDistinctHash.java |   90 -
 .../grouped/hash/NoChannelGroupByHash.java         |   72 -
 .../grouped/hash/VariableWidthData.java            |  197 -
 .../aggregation/grouped/hash/XxHash64.java         |  276 --
 .../window/ainode/InferenceWindowParameter.java    |    2 +-
 .../relational/ColumnTransformerBuilder.java       | 1985 ---------
 .../execution/schedule/DriverScheduler.java        |    4 +-
 .../execution/schedule/DriverTaskThread.java       |    4 +-
 .../execution/schedule/IDriverScheduler.java       |    4 +-
 .../metric/QueryExecutionMetricSet.java            |  224 -
 .../iotdb/db/queryengine/plan/Coordinator.java     |   38 +-
 .../db/queryengine/plan/analyze/Analysis.java      |    2 +-
 .../db/queryengine/plan/analyze/AnalyzeUtils.java  |   20 +-
 .../queryengine/plan/analyze/AnalyzeVisitor.java   |    8 +-
 .../plan/analyze/ExpressionAnalyzer.java           |    8 +-
 .../plan/analyze/ExpressionTypeAnalyzer.java       |    6 +-
 .../plan/analyze/GroupByLevelHelper.java           |    2 +-
 .../queryengine/plan/analyze/PredicateUtils.java   |   12 +-
 .../queryengine/plan/analyze/SelectIntoUtils.java  |    2 +-
 .../plan/analyze/TemplatedAggregationAnalyze.java  |    6 +-
 .../queryengine/plan/analyze/TemplatedAnalyze.java |    2 +-
 .../db/queryengine/plan/analyze/TemplatedInfo.java |    2 +-
 .../db/queryengine/plan/analyze/TypeProvider.java  |    7 +-
 .../plan/analyze/load/LoadTsFileAnalyzer.java      |   12 +-
 .../analyze/load/LoadTsFileTableSchemaCache.java   |   10 +-
 .../load/TreeSchemaAutoCreatorAndVerifier.java     |    4 +-
 .../analyze/schema/AutoCreateSchemaExecutor.java   |    2 +-
 .../analyze/schema/ClusterSchemaFetchExecutor.java |    2 +-
 .../plan/analyze/schema/SchemaValidator.java       |    4 +-
 .../plan/execution/IQueryExecution.java            |    4 +-
 .../queryengine/plan/execution/QueryExecution.java |    8 +-
 .../plan/execution/config/ConfigExecution.java     |    4 +-
 .../execution/config/TableConfigTaskVisitor.java   |  196 +-
 .../execution/config/TreeConfigTaskVisitor.java    |    2 +-
 .../config/executor/ClusterConfigTaskExecutor.java |   11 +-
 .../config/executor/IConfigTaskExecutor.java       |    5 +-
 .../config/metadata/GetTimeSlotListTask.java       |    2 +-
 .../config/metadata/ShowFunctionsTask.java         |   10 +-
 .../execution/config/metadata/ShowRegionTask.java  |    2 +-
 .../metadata/relational/DeleteDeviceTask.java      |    2 +-
 .../metadata/relational/ShowCreateViewTask.java    |    2 +-
 .../plan/execution/config/session/PrepareTask.java |    2 +-
 .../config/session/PreparedStatementHelper.java    |    4 +-
 .../session/PreparedStatementMemoryManager.java    |    2 +-
 .../config/session/SetSqlDialectTask.java          |    6 +-
 .../execution/config/sys/pipe/ShowPipeTask.java    |    2 +-
 .../memory/StatementMemorySourceVisitor.java       |    2 +-
 .../TableModelStatementMemorySourceVisitor.java    |   10 +-
 .../db/queryengine/plan/expression/Expression.java |    6 +-
 .../plan/expression/ExpressionFactory.java         |    2 +-
 .../plan/expression/binary/BinaryExpression.java   |    8 +-
 .../plan/expression/leaf/ConstantOperand.java      |    2 +-
 .../plan/expression/leaf/LeafOperand.java          |    4 +-
 .../plan/expression/leaf/NullOperand.java          |    2 +-
 .../plan/expression/leaf/TimeSeriesOperand.java    |    4 +-
 .../plan/expression/leaf/TimestampOperand.java     |    2 +-
 .../plan/expression/multi/FunctionExpression.java  |   13 +-
 .../plan/expression/multi/FunctionType.java        |   28 -
 .../multi/builtin/BuiltInScalarFunctionHelper.java |    4 +-
 .../multi/builtin/helper/CastFunctionHelper.java   |  335 +-
 .../multi/builtin/helper/DiffFunctionHelper.java   |    6 +-
 .../builtin/helper/ReplaceFunctionHelper.java      |   10 +-
 .../multi/builtin/helper/RoundFunctionHelper.java  |    8 +-
 .../builtin/helper/SubStringFunctionHelper.java    |   14 +-
 .../expression/other/CaseWhenThenExpression.java   |    8 +-
 .../expression/other/GroupByTimeExpression.java    |    6 +-
 .../plan/expression/ternary/BetweenExpression.java |    2 +-
 .../plan/expression/ternary/TernaryExpression.java |    6 +-
 .../plan/expression/unary/InExpression.java        |    2 +-
 .../plan/expression/unary/IsNullExpression.java    |    2 +-
 .../plan/expression/unary/LikeExpression.java      |   11 +-
 .../plan/expression/unary/LogicNotExpression.java  |    2 +-
 .../plan/expression/unary/NegationExpression.java  |    2 +-
 .../plan/expression/unary/RegularExpression.java   |    2 +-
 .../plan/expression/unary/UnaryExpression.java     |    6 +-
 .../BindTypeForTimeSeriesOperandVisitor.java       |    2 +-
 .../visitor/ColumnTransformerVisitor.java          |   66 +-
 .../visitor/CompleteMeasurementSchemaVisitor.java  |    2 +-
 .../visitor/CountTimeAggregationAmountVisitor.java |    4 +-
 .../visitor/IntermediateLayerVisitor.java          |    6 +-
 .../expression/visitor/ReconstructVisitor.java     |    2 +-
 .../cartesian/BindSchemaForExpressionVisitor.java  |    4 +-
 .../cartesian/BindSchemaForPredicateVisitor.java   |    4 +-
 ...catDeviceAndBindSchemaForExpressionVisitor.java |    6 +-
 .../ConcatDeviceAndBindSchemaForHavingVisitor.java |    2 +-
 ...ncatDeviceAndBindSchemaForPredicateVisitor.java |    2 +-
 .../ConcatExpressionWithSuffixPathsVisitor.java    |    2 +-
 .../predicate/ConvertPredicateToFilterVisitor.java |    2 +-
 .../ConvertPredicateToTimeFilterVisitor.java       |    2 +-
 .../plan/optimization/AggregationPushDown.java     |   16 +-
 .../plan/optimization/ColumnInjectionPushDown.java |   10 +-
 .../plan/optimization/LimitOffsetPushDown.java     |   12 +-
 .../OrderByExpressionWithLimitChangeToTopK.java    |   10 +-
 .../plan/optimization/PlanOptimizer.java           |    2 +-
 .../plan/optimization/PredicatePushDown.java       |   10 +-
 .../db/queryengine/plan/parser/ASTVisitor.java     |   94 +-
 .../plan/parser/StatementGenerator.java            |    6 +-
 .../planner/DataNodeTableOperatorGenerator.java    | 2090 +++++++++
 .../plan/planner/LocalExecutionPlanContext.java    |   15 +-
 .../plan/planner/LocalExecutionPlanner.java        |   14 +-
 .../plan/planner/LogicalPlanBuilder.java           |   12 +-
 .../plan/planner/LogicalPlanVisitor.java           |    2 +-
 .../queryengine/plan/planner/LogicalPlanner.java   |    2 +-
 .../plan/planner/OperatorGeneratorUtil.java        |    2 +-
 .../plan/planner/OperatorTreeGenerator.java        |  219 +-
 .../plan/planner/PipelineDriverFactory.java        |    2 +-
 .../plan/planner/SubPlanTypeExtractor.java         |    2 +-
 .../plan/planner/TableOperatorGenerator.java       | 4520 --------------------
 .../plan/planner/TemplatedLogicalPlan.java         |    4 +-
 .../plan/planner/TemplatedLogicalPlanBuilder.java  |    2 +-
 .../planner/distribution/DistributionPlanner.java  |    4 +-
 .../planner/distribution/ExchangeNodeAdder.java    |    8 +-
 .../planner/distribution/NodeGroupContext.java     |    6 +-
 .../SimpleFragmentParallelPlanner.java             |    4 +-
 .../plan/planner/distribution/SourceRewriter.java  |   24 +-
 .../distribution/WriteFragmentParallelPlanner.java |    2 +-
 .../ConsumeAllChildrenPipelineMemoryEstimator.java |    2 +-
 ...umeChildrenOneByOnePipelineMemoryEstimator.java |    2 +-
 .../memory/FakedMemoryReservationManager.java      |    2 +
 .../planner/memory/MemoryReservationManager.java   |   75 -
 .../NotThreadSafeMemoryReservationManager.java     |    1 +
 .../planner/memory/PipelineMemoryEstimator.java    |    2 +-
 .../memory/PipelineMemoryEstimatorFactory.java     |    4 +-
 .../plan/AbstractFragmentParallelPlanner.java      |    4 +-
 .../plan/planner/plan/FragmentInstance.java        |    4 +-
 .../plan/planner/plan/LogicalQueryPlan.java        |    2 +-
 .../plan/planner/plan/PlanFragment.java            |   14 +-
 .../plan/planner/plan/TableModelTimePredicate.java |    2 +-
 .../plan/planner/plan/TimePredicate.java           |    2 +-
 .../plan/planner/plan/node/BaseSourceRewriter.java |    4 +-
 .../plan/node/DataNodePlanNodeDeserializer.java    |  502 +++
 .../node/DataNodePlanNodeDeserializerProvider.java |   30 +
 .../plan/planner/plan/node/ExplainAnalyzeNode.java |    9 +-
 .../planner/plan/node/IPartitionRelatedNode.java   |   26 -
 .../plan/planner/plan/node/PlanGraphPrinter.java   |   87 +-
 .../plan/planner/plan/node/PlanNode.java           |  222 -
 .../plan/planner/plan/node/PlanNodeId.java         |   83 -
 .../plan/planner/plan/node/PlanNodeType.java       |  788 ----
 .../plan/planner/plan/node/PlanNodeUtil.java       |    1 +
 .../plan/planner/plan/node/PlanVisitor.java        |  468 +-
 .../plan/planner/plan/node/SimplePlanVisitor.java  |    4 +-
 .../plan/planner/plan/node/WritePlanNode.java      |    3 +
 .../plan/node/load/LoadSingleTsFileNode.java       |    4 +-
 .../planner/plan/node/load/LoadTsFileNode.java     |    4 +-
 .../plan/node/load/LoadTsFilePieceNode.java        |    6 +-
 .../metadata/read/AbstractSchemaMergeNode.java     |    6 +-
 .../node/metadata/read/CountSchemaMergeNode.java   |   11 +-
 .../metadata/read/DeviceSchemaFetchScanNode.java   |   11 +-
 .../plan/node/metadata/read/DevicesCountNode.java  |    6 +-
 .../node/metadata/read/DevicesSchemaScanNode.java  |    6 +-
 .../metadata/read/LevelTimeSeriesCountNode.java    |    6 +-
 .../metadata/read/LogicalViewSchemaScanNode.java   |    6 +-
 .../read/NodeManagementMemoryMergeNode.java        |   13 +-
 .../node/metadata/read/NodePathsConvertNode.java   |   13 +-
 .../node/metadata/read/NodePathsCountNode.java     |   13 +-
 .../metadata/read/NodePathsSchemaScanNode.java     |    6 +-
 .../metadata/read/PathsUsingTemplateScanNode.java  |    6 +-
 .../node/metadata/read/SchemaFetchMergeNode.java   |   11 +-
 .../node/metadata/read/SchemaFetchScanNode.java    |    6 +-
 .../node/metadata/read/SchemaQueryMergeNode.java   |   11 +-
 .../metadata/read/SchemaQueryOrderByHeatNode.java  |   13 +-
 .../node/metadata/read/SchemaQueryScanNode.java    |   11 +-
 .../metadata/read/SeriesSchemaFetchScanNode.java   |   11 +-
 .../node/metadata/read/TableDeviceSourceNode.java  |    8 +-
 .../node/metadata/read/TimeSeriesCountNode.java    |    6 +-
 .../metadata/read/TimeSeriesSchemaScanNode.java    |    6 +-
 .../node/metadata/write/ActivateTemplateNode.java  |   11 +-
 .../write/AlterEncodingCompressorNode.java         |   11 +-
 .../node/metadata/write/AlterTimeSeriesNode.java   |   11 +-
 .../metadata/write/BatchActivateTemplateNode.java  |   11 +-
 .../write/ConstructSchemaBlackListNode.java        |   11 +-
 .../write/CreateAlignedTimeSeriesNode.java         |   11 +-
 .../metadata/write/CreateMultiTimeSeriesNode.java  |   11 +-
 .../node/metadata/write/CreateTimeSeriesNode.java  |   11 +-
 .../metadata/write/DeactivateTemplateNode.java     |   11 +-
 .../node/metadata/write/DeleteTimeSeriesNode.java  |   11 +-
 .../write/InternalBatchActivateTemplateNode.java   |   11 +-
 .../write/InternalCreateMultiTimeSeriesNode.java   |   11 +-
 .../write/InternalCreateTimeSeriesNode.java        |   11 +-
 .../metadata/write/PreDeactivateTemplateNode.java  |   11 +-
 .../write/RollbackPreDeactivateTemplateNode.java   |   11 +-
 .../write/RollbackSchemaBlackListNode.java         |   11 +-
 .../metadata/write/view/AlterLogicalViewNode.java  |   11 +-
 .../view/ConstructLogicalViewBlackListNode.java    |   11 +-
 .../metadata/write/view/CreateLogicalViewNode.java |   11 +-
 .../metadata/write/view/DeleteLogicalViewNode.java |   11 +-
 .../view/RollbackLogicalViewBlackListNode.java     |   11 +-
 .../plan/node/pipe/PipeEnrichedDeleteDataNode.java |   11 +-
 .../plan/node/pipe/PipeEnrichedInsertNode.java     |   11 +-
 .../node/pipe/PipeEnrichedNonWritePlanNode.java    |   11 +-
 .../plan/node/pipe/PipeEnrichedWritePlanNode.java  |   11 +-
 .../plan/node/pipe/PipeOperateSchemaQueueNode.java |   11 +-
 .../plan/node/process/AI/InferenceNode.java        |   13 +-
 .../node/process/ActiveRegionScanMergeNode.java    |   12 +-
 .../node/process/AggregationMergeSortNode.java     |   12 +-
 .../planner/plan/node/process/AggregationNode.java |   12 +-
 .../planner/plan/node/process/CollectNode.java     |   12 +-
 .../plan/node/process/ColumnInjectNode.java        |   12 +-
 .../planner/plan/node/process/DeviceMergeNode.java |   12 +-
 .../plan/node/process/DeviceViewIntoNode.java      |   12 +-
 .../planner/plan/node/process/DeviceViewNode.java  |   17 +-
 .../planner/plan/node/process/ExchangeNode.java    |   14 +-
 .../plan/planner/plan/node/process/FillNode.java   |   12 +-
 .../plan/planner/plan/node/process/FilterNode.java |   16 +-
 .../plan/node/process/GroupByLevelNode.java        |   12 +-
 .../planner/plan/node/process/GroupByTagNode.java  |   12 +-
 .../plan/node/process/HorizontallyConcatNode.java  |   12 +-
 .../plan/planner/plan/node/process/IntoNode.java   |   12 +-
 .../plan/planner/plan/node/process/LimitNode.java  |   12 +-
 .../planner/plan/node/process/MergeSortNode.java   |   12 +-
 .../plan/node/process/MultiChildProcessNode.java   |   85 -
 .../plan/planner/plan/node/process/OffsetNode.java |   12 +-
 .../planner/plan/node/process/ProcessNode.java     |   30 -
 .../planner/plan/node/process/ProjectNode.java     |   17 +-
 .../plan/node/process/RawDataAggregationNode.java  |   12 +-
 .../plan/node/process/SingleChildProcessNode.java  |   92 -
 .../plan/node/process/SingleDeviceViewNode.java    |   17 +-
 .../node/process/SlidingWindowAggregationNode.java |   12 +-
 .../plan/planner/plan/node/process/SortNode.java   |   12 +-
 .../plan/planner/plan/node/process/TopKNode.java   |   12 +-
 .../planner/plan/node/process/TransformNode.java   |   12 +-
 .../plan/node/process/TwoChildProcessNode.java     |  101 -
 .../node/process/join/FullOuterTimeJoinNode.java   |   13 +-
 .../plan/node/process/join/InnerTimeJoinNode.java  |   13 +-
 .../node/process/join/LeftOuterTimeJoinNode.java   |   13 +-
 .../node/process/last/LastQueryCollectNode.java    |   13 +-
 .../plan/node/process/last/LastQueryMergeNode.java |   13 +-
 .../plan/node/process/last/LastQueryNode.java      |   15 +-
 .../node/process/last/LastQueryTransformNode.java  |   13 +-
 .../planner/plan/node/sink/IdentitySinkNode.java   |   11 +-
 .../plan/node/sink/MultiChildrenSinkNode.java      |    4 +-
 .../planner/plan/node/sink/ShuffleSinkNode.java    |   11 +-
 .../plan/planner/plan/node/sink/SinkNode.java      |    4 +-
 .../source/AlignedSeriesAggregationScanNode.java   |   16 +-
 .../plan/node/source/AlignedSeriesScanNode.java    |   16 +-
 .../plan/node/source/DeviceRegionScanNode.java     |   11 +-
 .../plan/node/source/LastQueryScanNode.java        |   13 +-
 .../plan/node/source/LastSeriesSourceNode.java     |    2 +-
 .../planner/plan/node/source/RegionScanNode.java   |    8 +-
 .../node/source/SeriesAggregationScanNode.java     |   13 +-
 .../node/source/SeriesAggregationSourceNode.java   |    7 +-
 .../planner/plan/node/source/SeriesScanNode.java   |   13 +-
 .../plan/node/source/SeriesScanSourceNode.java     |    9 +-
 .../planner/plan/node/source/SeriesSourceNode.java |    3 +-
 .../plan/node/source/ShowDiskUsageNode.java        |   11 +-
 .../planner/plan/node/source/ShowQueriesNode.java  |   11 +-
 .../plan/planner/plan/node/source/SourceNode.java  |   37 -
 .../plan/node/source/TimeseriesRegionScanNode.java |   11 +-
 .../plan/node/source/VirtualSourceNode.java        |    4 +-
 .../plan/node/write/AbstractDeleteDataNode.java    |    4 +-
 .../ContinuousSameSearchIndexSeparatorNode.java    |    6 +-
 .../planner/plan/node/write/DeleteDataNode.java    |   11 +-
 .../plan/node/write/InsertMultiTabletsNode.java    |   11 +-
 .../plan/planner/plan/node/write/InsertNode.java   |    4 +-
 .../planner/plan/node/write/InsertRowNode.java     |   11 +-
 .../planner/plan/node/write/InsertRowsNode.java    |   11 +-
 .../plan/node/write/InsertRowsOfOneDeviceNode.java |   11 +-
 .../planner/plan/node/write/InsertTabletNode.java  |   13 +-
 .../plan/planner/plan/node/write/ObjectNode.java   |   13 +-
 .../plan/node/write/RelationalDeleteDataNode.java  |   11 +-
 .../plan/node/write/RelationalInsertRowNode.java   |    9 +-
 .../plan/node/write/RelationalInsertRowsNode.java  |    9 +-
 .../node/write/RelationalInsertTabletNode.java     |    9 +-
 .../plan/planner/plan/node/write/SearchNode.java   |    2 +-
 .../plan/parameter/AggregationDescriptor.java      |    9 +-
 .../CrossSeriesAggregationDescriptor.java          |    2 +-
 .../parameter/DeviceViewIntoPathDescriptor.java    |    2 +-
 .../planner/plan/parameter/FillDescriptor.java     |    2 +-
 .../planner/plan/parameter/GroupByParameter.java   |    2 +-
 .../plan/parameter/GroupByTimeParameter.java       |    2 +-
 .../plan/planner/plan/parameter/InputLocation.java |   72 -
 .../planner/plan/parameter/IntoPathDescriptor.java |    2 +-
 .../plan/planner/plan/parameter/OutputColumn.java  |    2 +
 .../relational/analyzer/AggregationAnalyzer.java   |  135 +-
 .../plan/relational/analyzer/Analysis.java         |   71 +-
 .../plan/relational/analyzer/Analyzer.java         |   11 +-
 .../relational/analyzer/CanonicalizationAware.java |    4 +-
 .../relational/analyzer/ExpressionAnalysis.java    |   13 +-
 .../relational/analyzer/ExpressionAnalyzer.java    |  254 +-
 .../relational/analyzer/ExpressionTreeUtils.java   |   14 +-
 .../plan/relational/analyzer/Field.java            |    2 +-
 .../plan/relational/analyzer/NodeRef.java          |   63 -
 .../analyzer/PatternRecognitionAnalysis.java       |    9 +-
 .../analyzer/PatternRecognitionAnalyzer.java       |   31 +-
 .../plan/relational/analyzer/RelationId.java       |    3 +-
 .../plan/relational/analyzer/RelationType.java     |    2 +-
 .../plan/relational/analyzer/Scope.java            |   14 +-
 .../analyzer/ScopeReferenceExtractor.java          |    5 +-
 .../relational/analyzer/StatementAnalyzer.java     |  408 +-
 .../analyzer/StatementAnalyzerFactory.java         |    4 +-
 .../predicate/ConvertPredicateToFilterVisitor.java |   86 +-
 .../ConvertPredicateToTimeFilterVisitor.java       |   58 +-
 .../PredicateCombineIntoTableScanChecker.java      |   58 +-
 .../PredicatePushIntoMetadataChecker.java          |  139 +-
 .../predicate/PredicatePushIntoScanChecker.java    |   54 +-
 .../analyzer/predicate/PredicateVisitor.java       |   52 +-
 .../schema/CheckSchemaPredicateVisitor.java        |   29 +-
 .../ConvertSchemaPredicateToFilterVisitor.java     |   60 +-
 .../schema/ExtractPredicateColumnNameVisitor.java  |   57 +-
 .../tablefunction/TableArgumentAnalysis.java       |    8 +-
 .../plan/relational/function/BoundSignature.java   |  129 -
 .../plan/relational/function/FunctionId.java       |   70 -
 .../plan/relational/function/FunctionKind.java     |   45 -
 .../function/InterpretedFunctionInvoker.java       |   83 -
 .../function/LongVariableConstraint.java           |   64 -
 .../plan/relational/function/OperatorType.java     |   67 -
 .../function/ResolvedFunctionCallBuilder.java      |   58 -
 .../plan/relational/function/Signature.java        |  213 -
 .../function/TableBuiltinTableFunction.java        |   97 -
 .../function/TypeVariableConstraint.java           |  192 -
 .../function/arithmetic/AdditionResolver.java      |   97 -
 .../function/arithmetic/DivisionResolver.java      |   81 -
 .../function/arithmetic/ModulusResolver.java       |   81 -
 .../arithmetic/MultiplicationResolver.java         |   81 -
 .../function/arithmetic/SubtractionResolver.java   |   89 -
 .../function/tvf/ClassifyTableFunction.java        |  387 --
 .../function/tvf/ForecastTableFunction.java        |  550 ---
 .../function/tvf/PatternMatchTableFunction.java    |  283 --
 .../function/tvf/TableFunctionUtils.java           |   74 -
 .../relational/function/tvf/match/MatchConfig.java |   34 -
 .../function/tvf/match/QetchAlgorithm.java         |  683 ---
 .../function/tvf/match/model/MatchState.java       |  233 -
 .../function/tvf/match/model/PatternSegment.java   |  285 --
 .../relational/function/tvf/match/model/Point.java |   42 -
 .../function/tvf/match/model/RegexMatchState.java  |  388 --
 .../function/tvf/match/model/Section.java          |  238 --
 .../plan/relational/metadata/ColumnMetadata.java   |  213 -
 .../plan/relational/metadata/ColumnSchema.java     |  188 -
 .../relational/metadata/FunctionNullability.java   |  118 -
 .../plan/relational/metadata/Metadata.java         |   23 +-
 .../plan/relational/metadata/MetadataUtil.java     |    7 +-
 .../metadata/OperatorNotFoundException.java        |    4 +-
 .../plan/relational/metadata/ResolvedFunction.java |  145 -
 .../plan/relational/metadata/TableMetadata.java    |    3 +
 .../relational/metadata/TableMetadataImpl.java     |  456 +-
 .../plan/relational/metadata/TableSchema.java      |  239 --
 .../relational/metadata/TreeDeviceViewSchema.java  |    2 +
 .../metadata/fetcher/SchemaPredicateUtil.java      |    8 +-
 .../metadata/fetcher/TableDeviceSchemaFetcher.java |    2 +-
 .../fetcher/TableDeviceSchemaValidator.java        |    2 +-
 .../fetcher/TableHeaderSchemaValidator.java        |   16 +-
 .../plan/relational/planner/Assignments.java       |  261 --
 .../planner/CastToBlobLiteralVisitor.java          |   90 -
 .../planner/CastToBooleanLiteralVisitor.java       |   88 -
 .../planner/CastToDateLiteralVisitor.java          |   90 -
 .../planner/CastToDoubleLiteralVisitor.java        |   88 -
 .../planner/CastToFloatLiteralVisitor.java         |   88 -
 .../planner/CastToInt32LiteralVisitor.java         |   88 -
 .../planner/CastToInt64LiteralVisitor.java         |   88 -
 .../planner/CastToStringLiteralVisitor.java        |   95 -
 .../planner/CastToTimestampLiteralVisitor.java     |   97 -
 .../plan/relational/planner/CteMaterializer.java   |   16 +-
 .../planner/DataOrganizationSpecification.java     |  106 -
 .../plan/relational/planner/EqualityInference.java |    7 +-
 .../relational/planner/ExpressionExtractor.java    |   14 +-
 .../planner/ExpressionSymbolInliner.java           |    5 +-
 .../planner/IrExpressionInterpreter.java           |  109 +-
 .../plan/relational/planner/IrTypeAnalyzer.java    |  151 +-
 .../plan/relational/planner/LiteralEncoder.java    |   28 +-
 .../relational/planner/LiteralInterpreter.java     |   50 +-
 .../relational/planner/NoOpSymbolResolver.java     |    2 +
 .../plan/relational/planner/NodeAndMappings.java   |    3 +-
 .../plan/relational/planner/OrderingScheme.java    |  137 -
 .../relational/planner/OrderingTranslator.java     |    3 +-
 .../plan/relational/planner/PlanBuilder.java       |   10 +-
 .../plan/relational/planner/PlanNodeSearcher.java  |    2 +-
 .../plan/relational/planner/PlannerContext.java    |    2 +-
 .../plan/relational/planner/PredicateUtils.java    |   22 +-
 .../plan/relational/planner/QueryPlanner.java      |  101 +-
 .../plan/relational/planner/RelationPlan.java      |    3 +-
 .../plan/relational/planner/RelationPlanner.java   |  192 +-
 .../plan/relational/planner/ScopeAware.java        |    6 +-
 .../relational/planner/SimplePlanRewriter.java     |    4 +-
 .../plan/relational/planner/SortOrder.java         |   50 -
 .../plan/relational/planner/SubqueryPlanner.java   |   46 +-
 .../plan/relational/planner/Symbol.java            |  100 -
 .../plan/relational/planner/SymbolAllocator.java   |    9 +-
 .../plan/relational/planner/SymbolResolver.java    |    2 +
 .../plan/relational/planner/SymbolsExtractor.java  |   32 +-
 .../relational/planner/TableLogicalPlanner.java    |   38 +-
 .../plan/relational/planner/TableModelPlanner.java |   10 +-
 .../plan/relational/planner/TranslationMap.java    |   29 +-
 .../planner/distribute/AddExchangeNodes.java       |    8 +-
 .../planner/distribute/SubPlanGenerator.java       |    4 +-
 .../distribute/TableDistributedPlanGenerator.java  |  102 +-
 .../distribute/TableDistributedPlanner.java        |    8 +-
 .../distribute/TableModelQueryFragmentPlanner.java |    6 +-
 .../TableModelTypeProviderExtractor.java           |   36 +-
 .../planner/ir/DefaultTraversalVisitor.java        |   72 +-
 .../planner/ir/DeterminismEvaluator.java           |    6 +-
 .../planner/ir/ExpressionNodeInliner.java          |    2 +-
 .../relational/planner/ir/ExpressionRewriter.java  |   70 +-
 .../planner/ir/ExpressionTreeRewriter.java         |  123 +-
 .../ExtractCommonPredicatesExpressionRewriter.java |    6 +-
 .../ir/GapFillStartAndEndTimeExtractVisitor.java   |   44 +-
 .../ir/GlobalTimePredicateExtractVisitor.java      |  312 --
 .../plan/relational/planner/ir/IrUtils.java        |   24 +-
 .../planner/ir/NormalizeOrExpressionRewriter.java  |   14 +-
 ...ithUncorrelatedScalarSubqueryReconstructor.java |   36 +-
 .../planner/ir/ReplaceSymbolInExpression.java      |    8 +-
 .../planner/ir/SubExpressionExtractor.java         |    4 +-
 .../planner/iterative/GroupReference.java          |   92 -
 .../planner/iterative/IterativeOptimizer.java      |   15 +-
 .../plan/relational/planner/iterative/Lookup.java  |    3 +-
 .../plan/relational/planner/iterative/Memo.java    |    3 +-
 .../plan/relational/planner/iterative/Plans.java   |    5 +-
 .../plan/relational/planner/iterative/Rule.java    |    8 +-
 .../relational/planner/iterative/RuleIndex.java    |    4 +-
 .../iterative/rule/AggregationDecorrelation.java   |    6 +-
 .../rule/CanonicalizeExpressionRewriter.java       |   28 +-
 .../rule/EliminateLimitProjectWithTableScan.java   |   12 +-
 .../rule/EliminateLimitWithTableScan.java          |   10 +-
 .../iterative/rule/EvaluateEmptyIntersect.java     |   12 +-
 .../iterative/rule/ExpressionRewriteRuleSet.java   |   22 +-
 .../iterative/rule/GatherAndMergeWindows.java      |   24 +-
 .../planner/iterative/rule/ImplementExceptAll.java |   26 +-
 .../rule/ImplementExceptDistinctAsUnion.java       |   20 +-
 .../iterative/rule/ImplementIntersectAll.java      |   20 +-
 .../rule/ImplementIntersectDistinctAsUnion.java    |   20 +-
 .../rule/ImplementPatternRecognition.java          |   16 +-
 .../rule/ImplementTableFunctionSource.java         |   20 +-
 .../planner/iterative/rule/InlineProjections.java  |   22 +-
 .../planner/iterative/rule/MergeExcept.java        |    8 +-
 .../planner/iterative/rule/MergeFilters.java       |   10 +-
 .../planner/iterative/rule/MergeIntersect.java     |    8 +-
 .../rule/MergeLimitOverProjectWithMergeSort.java   |   18 +-
 .../rule/MergeLimitOverProjectWithSort.java        |   18 +-
 .../iterative/rule/MergeLimitWithMergeSort.java    |   16 +-
 .../planner/iterative/rule/MergeLimitWithSort.java |   16 +-
 .../planner/iterative/rule/MergeLimits.java        |   10 +-
 .../planner/iterative/rule/MergeUnion.java         |    8 +-
 .../MultipleDistinctAggregationToMarkDistinct.java |   12 +-
 .../planner/iterative/rule/OptimizeRowPattern.java |   12 +-
 .../iterative/rule/ProjectOffPushDownRule.java     |   14 +-
 .../iterative/rule/PruneAggregationColumns.java    |    6 +-
 .../rule/PruneAggregationSourceColumns.java        |    8 +-
 .../planner/iterative/rule/PruneApplyColumns.java  |    6 +-
 .../iterative/rule/PruneApplyCorrelation.java      |    8 +-
 .../iterative/rule/PruneApplySourceColumns.java    |   10 +-
 .../iterative/rule/PruneAssignUniqueIdColumns.java |    6 +-
 .../planner/iterative/rule/PruneCopyToColumns.java |    4 +-
 .../iterative/rule/PruneCorrelatedJoinColumns.java |   10 +-
 .../rule/PruneCorrelatedJoinCorrelation.java       |    8 +-
 .../iterative/rule/PruneDistinctAggregation.java   |   16 +-
 .../rule/PruneEnforceSingleRowColumns.java         |    6 +-
 .../iterative/rule/PruneExceptSourceColumns.java   |    8 +-
 .../iterative/rule/PruneExplainAnalyzeColumns.java |    4 +-
 .../planner/iterative/rule/PruneFillColumns.java   |    6 +-
 .../planner/iterative/rule/PruneFilterColumns.java |    6 +-
 .../iterative/rule/PruneGapFillColumns.java        |    6 +-
 .../rule/PruneIntersectSourceColumns.java          |    8 +-
 .../iterative/rule/PruneJoinChildrenColumns.java   |    8 +-
 .../planner/iterative/rule/PruneJoinColumns.java   |    6 +-
 .../planner/iterative/rule/PruneLimitColumns.java  |    6 +-
 .../iterative/rule/PruneMarkDistinctColumns.java   |    6 +-
 .../planner/iterative/rule/PruneOffsetColumns.java |    6 +-
 .../iterative/rule/PruneOutputSourceColumns.java   |    6 +-
 .../rule/PrunePatternRecognitionSourceColumns.java |   14 +-
 .../iterative/rule/PruneProjectColumns.java        |    6 +-
 .../planner/iterative/rule/PruneSortColumns.java   |    6 +-
 .../rule/PruneTableFunctionProcessorColumns.java   |    8 +-
 .../PruneTableFunctionProcessorSourceColumns.java  |   10 +-
 .../iterative/rule/PruneTableScanColumns.java      |    6 +-
 .../planner/iterative/rule/PruneTopKColumns.java   |    6 +-
 .../planner/iterative/rule/PruneUnionColumns.java  |    6 +-
 .../iterative/rule/PruneUnionSourceColumns.java    |    8 +-
 .../planner/iterative/rule/PruneWindowColumns.java |    6 +-
 .../iterative/rule/PushDownFilterIntoWindow.java   |   26 +-
 .../iterative/rule/PushDownLimitIntoWindow.java    |   18 +-
 .../rule/PushDownNegationsExpressionRewriter.java  |   20 +-
 .../rule/PushDownOffsetIntoTableScan.java          |   10 +-
 .../iterative/rule/PushLimitThroughOffset.java     |   12 +-
 .../iterative/rule/PushLimitThroughProject.java    |   14 +-
 .../iterative/rule/PushLimitThroughUnion.java      |   14 +-
 .../iterative/rule/PushProjectionThroughUnion.java |   22 +-
 .../iterative/rule/PushTopKThroughUnion.java       |   16 +-
 .../iterative/rule/RemoveDuplicateConditions.java  |    4 +-
 .../iterative/rule/RemoveEmptyExceptBranches.java  |   18 +-
 .../iterative/rule/RemoveEmptyUnionBranches.java   |   14 +-
 .../rule/RemoveRedundantEnforceSingleRowNode.java  |    6 +-
 .../iterative/rule/RemoveRedundantExists.java      |   18 +-
 .../rule/RemoveRedundantIdentityProjections.java   |    6 +-
 .../iterative/rule/RemoveRedundantWindow.java      |    8 +-
 .../iterative/rule/RemoveTrivialFilters.java       |   12 +-
 .../rule/RemoveUnreferencedScalarApplyNodes.java   |    6 +-
 .../rule/RemoveUnreferencedScalarSubqueries.java   |   14 +-
 .../iterative/rule/ReplaceWindowWithRowNumber.java |   10 +-
 .../planner/iterative/rule/SetOperationMerge.java  |   12 +-
 .../iterative/rule/SetOperationNodeTranslator.java |   54 +-
 .../iterative/rule/SimplifyCountOverConstant.java  |   32 +-
 .../iterative/rule/SimplifyExpressions.java        |    8 +-
 .../rule/SingleDistinctAggregationToGroupBy.java   |   14 +-
 ...orrelatedDistinctAggregationWithProjection.java |   32 +-
 ...elatedDistinctAggregationWithoutProjection.java |   28 +-
 ...mCorrelatedGlobalAggregationWithProjection.java |   38 +-
 ...rrelatedGlobalAggregationWithoutProjection.java |   38 +-
 ...CorrelatedGroupedAggregationWithProjection.java |   32 +-
 ...relatedGroupedAggregationWithoutProjection.java |   28 +-
 .../rule/TransformCorrelatedJoinToJoin.java        |   20 +-
 .../rule/TransformCorrelatedScalarSubquery.java    |   46 +-
 .../rule/TransformExistsApplyToCorrelatedJoin.java |   46 +-
 .../TransformFilteringSemiJoinToInnerJoin.java     |   32 +-
 ...mUncorrelatedInPredicateSubqueryToSemiJoin.java |   12 +-
 .../rule/TransformUncorrelatedSubqueryToJoin.java  |   28 +-
 .../relational/planner/iterative/rule/Util.java    |   20 +-
 .../relational/planner/node/AggregationNode.java   |  767 ----
 .../planner/node/AggregationTableScanNode.java     |   29 +-
 .../node/AggregationTreeDeviceViewScanNode.java    |   18 +-
 .../AlignedAggregationTreeDeviceViewScanNode.java  |   18 +-
 .../plan/relational/planner/node/ApplyNode.java    |  246 --
 .../relational/planner/node/AssignUniqueId.java    |   97 -
 .../relational/planner/node/ChildReplacer.java     |    2 +-
 .../plan/relational/planner/node/CollectNode.java  |  131 -
 .../plan/relational/planner/node/CopyToNode.java   |   13 +-
 .../planner/node/CorrelatedJoinNode.java           |  170 -
 .../plan/relational/planner/node/CteScanNode.java  |   17 +-
 .../planner/node/DeviceTableScanNode.java          |   15 +-
 .../planner/node/EnforceSingleRowNode.java         |   86 -
 .../plan/relational/planner/node/ExceptNode.java   |   99 -
 .../plan/relational/planner/node/ExchangeNode.java |   15 +-
 .../planner/node/ExplainAnalyzeNode.java           |   13 +-
 .../plan/relational/planner/node/FillNode.java     |   50 -
 .../plan/relational/planner/node/FilterNode.java   |  115 -
 .../plan/relational/planner/node/GapFillNode.java  |  230 -
 .../plan/relational/planner/node/GroupNode.java    |  104 -
 .../node/InformationSchemaTableScanNode.java       |   17 +-
 .../relational/planner/node/IntersectNode.java     |   98 -
 .../plan/relational/planner/node/IntoNode.java     |   17 +-
 .../plan/relational/planner/node/JoinNode.java     |  531 ---
 .../plan/relational/planner/node/LimitNode.java    |  133 -
 .../relational/planner/node/LinearFillNode.java    |  146 -
 .../relational/planner/node/MarkDistinctNode.java  |  162 -
 .../plan/relational/planner/node/Measure.java      |   95 -
 .../relational/planner/node/MergeSortNode.java     |  141 -
 ...onAlignedAggregationTreeDeviceViewScanNode.java |   19 +-
 .../plan/relational/planner/node/OffsetNode.java   |  111 -
 .../plan/relational/planner/node/OutputNode.java   |  154 -
 .../planner/node/PatternRecognitionNode.java       |  384 --
 .../plan/relational/planner/node/Patterns.java     |   45 +-
 .../relational/planner/node/PreviousFillNode.java  |  193 -
 .../plan/relational/planner/node/ProjectNode.java  |  130 -
 .../relational/planner/node/RowNumberNode.java     |  215 -
 .../plan/relational/planner/node/RowsPerMatch.java |  127 -
 .../plan/relational/planner/node/SemiJoinNode.java |  181 -
 .../relational/planner/node/SetOperationNode.java  |  138 -
 .../relational/planner/node/SkipToPosition.java    |   47 -
 .../plan/relational/planner/node/SortNode.java     |  131 -
 .../relational/planner/node/StreamSortNode.java    |  120 -
 ...bleDiskUsageInformationSchemaTableScanNode.java |   12 +-
 .../relational/planner/node/TableFunctionNode.java |  371 --
 .../planner/node/TableFunctionProcessorNode.java   |  295 --
 .../relational/planner/node/TableScanNode.java     |   19 +-
 .../plan/relational/planner/node/TopKNode.java     |  173 -
 .../relational/planner/node/TopKRankingNode.java   |  208 -
 .../node/TreeAlignedDeviceViewScanNode.java        |   15 +-
 .../planner/node/TreeDeviceViewScanNode.java       |   13 +-
 .../node/TreeNonAlignedDeviceViewScanNode.java     |   15 +-
 .../plan/relational/planner/node/UnionNode.java    |  126 -
 .../relational/planner/node/ValueFillNode.java     |  106 -
 .../plan/relational/planner/node/ValuesNode.java   |  236 -
 .../plan/relational/planner/node/WindowNode.java   |  606 ---
 .../node/schema/AbstractTableDeviceQueryNode.java  |    6 +-
 .../schema/AbstractTableDevicesDeletionNode.java   |    4 +-
 ...ctTableSchemaQueryAttributeSecurityVisitor.java |    4 +-
 .../schema/ConstructTableDevicesBlackListNode.java |   11 +-
 .../node/schema/CreateOrUpdateTableDeviceNode.java |   11 +-
 .../planner/node/schema/DeleteTableDeviceNode.java |   11 +-
 .../schema/DeleteTableDevicesInBlackListNode.java  |   11 +-
 .../schema/RollbackTableDevicesBlackListNode.java  |   11 +-
 .../node/schema/TableAttributeColumnDropNode.java  |   11 +-
 .../TableDeviceAttributeCommitUpdateNode.java      |   11 +-
 .../schema/TableDeviceAttributeUpdateNode.java     |   17 +-
 .../planner/node/schema/TableDeviceFetchNode.java  |   11 +-
 .../node/schema/TableDeviceQueryCountNode.java     |   13 +-
 .../node/schema/TableDeviceQueryScanNode.java      |   13 +-
 .../node/schema/TableNodeLocationAddNode.java      |   11 +-
 .../node/schema/TableSchemaQueryWriteVisitor.java  |    2 +-
 .../optimizations/AdaptivePlanOptimizer.java       |    4 +-
 .../CheckSubqueryNodesAreRewritten.java            |   10 +-
 .../planner/optimizations/JoinUtils.java           |   10 +-
 .../planner/optimizations/ParallelizeGrouping.java |   32 +-
 .../optimizations/PlanNodeDecorrelator.java        |   40 +-
 .../planner/optimizations/PlanOptimizer.java       |    4 +-
 .../PushAggregationIntoTableScan.java              |   18 +-
 .../PushLimitOffsetIntoTableScan.java              |   38 +-
 .../optimizations/PushPredicateIntoTableScan.java  |   72 +-
 .../optimizations/QueryCardinalityUtil.java        |   20 +-
 .../planner/optimizations/SortElimination.java     |   22 +-
 .../planner/optimizations/SymbolMapper.java        |   50 +-
 .../TransformAggregationToStreamable.java          |   30 +-
 ...mQuantifiedComparisonApplyToCorrelatedJoin.java |   60 +-
 .../optimizations/TransformSortToStreamSort.java   |   20 +-
 .../optimizations/UnaliasSymbolReferences.java     |   80 +-
 .../relational/planner/optimizations/Util.java     |   22 +-
 .../planner/rowpattern/AggregationLabelSet.java    |  100 -
 .../rowpattern/AggregationValuePointer.java        |  161 -
 .../planner/rowpattern/ClassifierValuePointer.java |   70 -
 .../rowpattern/ExpressionAndValuePointers.java     |  250 --
 .../planner/rowpattern/IrAlternation.java          |   99 -
 .../relational/planner/rowpattern/IrAnchor.java    |   87 -
 .../planner/rowpattern/IrConcatenation.java        |  100 -
 .../relational/planner/rowpattern/IrEmpty.java     |   62 -
 .../relational/planner/rowpattern/IrExclusion.java |   79 -
 .../relational/planner/rowpattern/IrLabel.java     |   85 -
 .../rowpattern/IrPatternAlternationOptimizer.java  |  141 -
 .../planner/rowpattern/IrPermutation.java          |   96 -
 .../planner/rowpattern/IrQuantified.java           |   88 -
 .../planner/rowpattern/IrQuantifier.java           |  126 -
 .../planner/rowpattern/IrRowPattern.java           |  119 -
 .../planner/rowpattern/IrRowPatternFlattener.java  |  206 -
 .../planner/rowpattern/IrRowPatternVisitor.java    |   68 -
 .../planner/rowpattern/LogicalIndexPointer.java    |  167 -
 .../rowpattern/MatchNumberValuePointer.java        |   45 -
 .../relational/planner/rowpattern/Patterns.java    |   83 -
 .../planner/rowpattern/RowPatternToIrRewriter.java |  148 -
 .../planner/rowpattern/ScalarValuePointer.java     |   82 -
 .../planner/rowpattern/ValuePointer.java           |   17 -
 .../rowpattern/RowPatternToIrRewriter.java         |  158 +
 .../plan/relational/security/Identity.java         |   51 -
 .../plan/relational/sql/ParameterExtractor.java    |   23 +-
 .../sql/ast/AbstractQueryDeviceWithCache.java      |    4 +
 .../relational/sql/ast/AbstractTraverseDevice.java |    9 +-
 .../plan/relational/sql/ast/AddColumn.java         |   11 +-
 .../plan/relational/sql/ast/AliasedRelation.java   |  126 -
 .../plan/relational/sql/ast/AllColumns.java        |  143 -
 .../plan/relational/sql/ast/AllRows.java           |   76 -
 .../relational/sql/ast/AlterColumnDataType.java    |   13 +-
 .../plan/relational/sql/ast/AlterDB.java           |    6 +-
 .../plan/relational/sql/ast/AlterPipe.java         |    7 +-
 .../plan/relational/sql/ast/AnchorPattern.java     |   94 -
 .../sql/ast/ArithmeticBinaryExpression.java        |  154 -
 .../sql/ast/ArithmeticUnaryExpression.java         |  155 -
 .../plan/relational/sql/ast/AsofJoinOn.java        |   13 +-
 .../sql/ast/AstMemoryEstimationHelper.java         |  123 -
 .../plan/relational/sql/ast/AstVisitor.java        |  673 +--
 .../plan/relational/sql/ast/BetweenPredicate.java  |  141 -
 .../plan/relational/sql/ast/BinaryLiteral.java     |  156 -
 .../plan/relational/sql/ast/BooleanLiteral.java    |  122 -
 .../queryengine/plan/relational/sql/ast/Cast.java  |  171 -
 .../plan/relational/sql/ast/ClearCache.java        |    8 +-
 .../relational/sql/ast/CoalesceExpression.java     |  131 -
 .../plan/relational/sql/ast/ColumnDefinition.java  |   11 +-
 .../plan/relational/sql/ast/Columns.java           |  107 -
 .../relational/sql/ast/ComparisonExpression.java   |  225 -
 .../plan/relational/sql/ast/CopyTo.java            |    9 +-
 .../plan/relational/sql/ast/CountDevice.java       |    8 +-
 .../plan/relational/sql/ast/CountStatement.java    |   11 +-
 .../plan/relational/sql/ast/CreateDB.java          |    6 +-
 .../relational/sql/ast/CreateExternalService.java  |   10 +-
 .../plan/relational/sql/ast/CreateFunction.java    |   10 +-
 .../plan/relational/sql/ast/CreateIndex.java       |   12 +-
 .../plan/relational/sql/ast/CreateModel.java       |    9 +-
 .../relational/sql/ast/CreateOrUpdateDevice.java   |    9 +-
 .../plan/relational/sql/ast/CreatePipe.java        |    7 +-
 .../plan/relational/sql/ast/CreatePipePlugin.java  |    7 +-
 .../plan/relational/sql/ast/CreateTable.java       |   11 +-
 .../plan/relational/sql/ast/CreateTopic.java       |    7 +-
 .../plan/relational/sql/ast/CreateTraining.java    |    9 +-
 .../plan/relational/sql/ast/CreateView.java        |    9 +-
 .../plan/relational/sql/ast/CurrentDatabase.java   |   86 -
 .../plan/relational/sql/ast/CurrentTime.java       |  127 -
 .../plan/relational/sql/ast/CurrentUser.java       |   86 -
 .../plan/relational/sql/ast/DataType.java          |   28 -
 .../plan/relational/sql/ast/DataTypeParameter.java |   34 -
 .../plan/relational/sql/ast/DatabaseStatement.java |    4 +
 .../plan/relational/sql/ast/Deallocate.java        |   11 +-
 .../plan/relational/sql/ast/DecimalLiteral.java    |  114 -
 .../sql/ast/DefaultExpressionTraversalVisitor.java |    4 +-
 .../sql/ast/DefaultTraversalVisitor.java           |  197 +-
 .../plan/relational/sql/ast/Delete.java            |   11 +-
 .../plan/relational/sql/ast/DeleteDevice.java      |   23 +-
 .../relational/sql/ast/DereferenceExpression.java  |  164 -
 .../plan/relational/sql/ast/DescribeTable.java     |   11 +-
 .../plan/relational/sql/ast/DoubleLiteral.java     |  121 -
 .../plan/relational/sql/ast/DropColumn.java        |   12 +-
 .../plan/relational/sql/ast/DropDB.java            |   11 +-
 .../relational/sql/ast/DropExternalService.java    |   10 +-
 .../plan/relational/sql/ast/DropFunction.java      |   10 +-
 .../plan/relational/sql/ast/DropIndex.java         |   12 +-
 .../plan/relational/sql/ast/DropModel.java         |    9 +-
 .../plan/relational/sql/ast/DropPipe.java          |    7 +-
 .../plan/relational/sql/ast/DropPipePlugin.java    |    7 +-
 .../plan/relational/sql/ast/DropSubscription.java  |    7 +-
 .../plan/relational/sql/ast/DropTable.java         |   11 +-
 .../plan/relational/sql/ast/DropTopic.java         |    7 +-
 .../plan/relational/sql/ast/EmptyPattern.java      |   79 -
 .../plan/relational/sql/ast/Except.java            |  119 -
 .../plan/relational/sql/ast/ExcludedPattern.java   |   90 -
 .../plan/relational/sql/ast/Execute.java           |   12 +-
 .../plan/relational/sql/ast/ExecuteImmediate.java  |   12 +-
 .../plan/relational/sql/ast/ExistsPredicate.java   |   92 -
 .../plan/relational/sql/ast/Explain.java           |   10 +-
 .../plan/relational/sql/ast/ExplainAnalyze.java    |   10 +-
 .../plan/relational/sql/ast/Expression.java        |  178 -
 .../plan/relational/sql/ast/ExtendRegion.java      |    9 +-
 .../plan/relational/sql/ast/Extract.java           |  150 -
 .../plan/relational/sql/ast/FetchDevice.java       |    9 +-
 .../plan/relational/sql/ast/FieldReference.java    |   91 -
 .../queryengine/plan/relational/sql/ast/Fill.java  |  184 -
 .../plan/relational/sql/ast/FloatLiteral.java      |  117 -
 .../queryengine/plan/relational/sql/ast/Flush.java |    5 +-
 .../plan/relational/sql/ast/FrameBound.java        |  152 -
 .../plan/relational/sql/ast/FunctionCall.java      |  358 --
 .../plan/relational/sql/ast/GenericDataType.java   |  123 -
 .../plan/relational/sql/ast/GenericLiteral.java    |  144 -
 .../plan/relational/sql/ast/GroupBy.java           |  111 -
 .../plan/relational/sql/ast/GroupingElement.java   |   36 -
 .../plan/relational/sql/ast/GroupingSets.java      |  128 -
 .../plan/relational/sql/ast/Identifier.java        |  189 -
 .../plan/relational/sql/ast/IfExpression.java      |  119 -
 .../plan/relational/sql/ast/InListExpression.java  |  122 -
 .../plan/relational/sql/ast/InPredicate.java       |  118 -
 .../plan/relational/sql/ast/Insert.java            |   12 +-
 .../plan/relational/sql/ast/InsertRow.java         |    7 +-
 .../plan/relational/sql/ast/InsertRows.java        |    7 +-
 .../plan/relational/sql/ast/InsertTablet.java      |    7 +-
 .../plan/relational/sql/ast/Intersect.java         |  103 -
 .../relational/sql/ast/IsNotNullPredicate.java     |  108 -
 .../plan/relational/sql/ast/IsNullPredicate.java   |  108 -
 .../queryengine/plan/relational/sql/ast/Join.java  |  178 -
 .../plan/relational/sql/ast/JoinCriteria.java      |   39 -
 .../plan/relational/sql/ast/JoinOn.java            |   84 -
 .../plan/relational/sql/ast/JoinUsing.java         |   81 -
 .../plan/relational/sql/ast/KillQuery.java         |   10 +-
 .../plan/relational/sql/ast/LikePredicate.java     |  163 -
 .../queryengine/plan/relational/sql/ast/Limit.java |  107 -
 .../plan/relational/sql/ast/Literal.java           |   47 -
 .../plan/relational/sql/ast/LoadConfiguration.java |    5 +-
 .../plan/relational/sql/ast/LoadModel.java         |    9 +-
 .../plan/relational/sql/ast/LoadTsFile.java        |   11 +-
 .../plan/relational/sql/ast/LogicalExpression.java |  159 -
 .../plan/relational/sql/ast/LongLiteral.java       |  148 -
 .../plan/relational/sql/ast/MeasureDefinition.java |  102 -
 .../plan/relational/sql/ast/MigrateRegion.java     |   10 +-
 .../plan/relational/sql/ast/NaturalJoin.java       |   60 -
 .../queryengine/plan/relational/sql/ast/Node.java  |   78 -
 .../plan/relational/sql/ast/NodeLocation.java      |   68 -
 .../plan/relational/sql/ast/NotExpression.java     |  108 -
 .../plan/relational/sql/ast/NullIfExpression.java  |   99 -
 .../plan/relational/sql/ast/NullLiteral.java       |   92 -
 .../plan/relational/sql/ast/NumericParameter.java  |   99 -
 .../plan/relational/sql/ast/Offset.java            |  105 -
 .../relational/sql/ast/OneOrMoreQuantifier.java    |   43 -
 .../plan/relational/sql/ast/OrderBy.java           |  129 -
 .../plan/relational/sql/ast/Parameter.java         |   93 -
 .../relational/sql/ast/PatternAlternation.java     |   92 -
 .../relational/sql/ast/PatternConcatenation.java   |   92 -
 .../relational/sql/ast/PatternPermutation.java     |   92 -
 .../plan/relational/sql/ast/PatternQuantifier.java |   82 -
 .../sql/ast/PatternRecognitionRelation.java        |  227 -
 .../plan/relational/sql/ast/PatternVariable.java   |   90 -
 .../plan/relational/sql/ast/PipeEnriched.java      |    9 +-
 .../plan/relational/sql/ast/PipeStatement.java     |    3 +
 .../plan/relational/sql/ast/Prepare.java           |   11 +-
 .../plan/relational/sql/ast/ProcessingMode.java    |   88 -
 .../plan/relational/sql/ast/Property.java          |   11 +-
 .../plan/relational/sql/ast/QualifiedName.java     |  247 --
 .../sql/ast/QuantifiedComparisonExpression.java    |  136 -
 .../plan/relational/sql/ast/QuantifiedPattern.java |  102 -
 .../queryengine/plan/relational/sql/ast/Query.java |  211 -
 .../plan/relational/sql/ast/QueryBody.java         |   34 -
 .../relational/sql/ast/QuerySpecification.java     |  210 -
 .../plan/relational/sql/ast/RangeQuantifier.java   |  107 -
 .../plan/relational/sql/ast/ReconstructRegion.java |    9 +-
 .../plan/relational/sql/ast/Relation.java          |   32 -
 .../sql/ast/RelationalAuthorStatement.java         |    8 +-
 .../plan/relational/sql/ast/RemoveAINode.java      |    9 +-
 .../plan/relational/sql/ast/RemoveConfigNode.java  |    9 +-
 .../plan/relational/sql/ast/RemoveDataNode.java    |    9 +-
 .../plan/relational/sql/ast/RemoveRegion.java      |    9 +-
 .../plan/relational/sql/ast/RenameColumn.java      |   13 +-
 .../plan/relational/sql/ast/RenameTable.java       |   13 +-
 .../queryengine/plan/relational/sql/ast/Row.java   |  121 -
 .../plan/relational/sql/ast/RowPattern.java        |   31 -
 .../relational/sql/ast/SearchedCaseExpression.java |  162 -
 .../plan/relational/sql/ast/Select.java            |  110 -
 .../plan/relational/sql/ast/SelectItem.java        |   27 -
 .../plan/relational/sql/ast/SetColumnComment.java  |   12 +-
 .../plan/relational/sql/ast/SetConfiguration.java  |    5 +-
 .../plan/relational/sql/ast/SetOperation.java      |   42 -
 .../plan/relational/sql/ast/SetProperties.java     |   11 +-
 .../plan/relational/sql/ast/SetSqlDialect.java     |   17 +-
 .../plan/relational/sql/ast/SetSystemStatus.java   |    5 +-
 .../plan/relational/sql/ast/SetTableComment.java   |   11 +-
 .../plan/relational/sql/ast/ShowAIDevices.java     |    9 +-
 .../plan/relational/sql/ast/ShowAINodes.java       |   10 +-
 .../plan/relational/sql/ast/ShowAvailableUrls.java |    9 +-
 .../plan/relational/sql/ast/ShowCluster.java       |   10 +-
 .../plan/relational/sql/ast/ShowClusterId.java     |   10 +-
 .../plan/relational/sql/ast/ShowConfigNodes.java   |   10 +-
 .../plan/relational/sql/ast/ShowConfiguration.java |    5 +-
 .../relational/sql/ast/ShowCurrentDatabase.java    |   10 +-
 .../relational/sql/ast/ShowCurrentSqlDialect.java  |   10 +-
 .../relational/sql/ast/ShowCurrentTimestamp.java   |   10 +-
 .../plan/relational/sql/ast/ShowCurrentUser.java   |   10 +-
 .../plan/relational/sql/ast/ShowDB.java            |   10 +-
 .../plan/relational/sql/ast/ShowDataNodes.java     |   10 +-
 .../plan/relational/sql/ast/ShowDevice.java        |   11 +-
 .../relational/sql/ast/ShowExternalService.java    |   11 +-
 .../plan/relational/sql/ast/ShowFunctions.java     |   10 +-
 .../plan/relational/sql/ast/ShowIndex.java         |   11 +-
 .../plan/relational/sql/ast/ShowLoadedModels.java  |    9 +-
 .../plan/relational/sql/ast/ShowModels.java        |    9 +-
 .../plan/relational/sql/ast/ShowPipePlugins.java   |    7 +-
 .../plan/relational/sql/ast/ShowPipes.java         |    7 +-
 .../relational/sql/ast/ShowQueriesStatement.java   |   11 +-
 .../plan/relational/sql/ast/ShowRegions.java       |    8 +-
 .../plan/relational/sql/ast/ShowStatement.java     |   13 +-
 .../plan/relational/sql/ast/ShowSubscriptions.java |    7 +-
 .../plan/relational/sql/ast/ShowTables.java        |   11 +-
 .../plan/relational/sql/ast/ShowTopics.java        |    7 +-
 .../plan/relational/sql/ast/ShowVariables.java     |   10 +-
 .../plan/relational/sql/ast/ShowVersion.java       |   10 +-
 .../relational/sql/ast/SimpleCaseExpression.java   |  181 -
 .../plan/relational/sql/ast/SimpleGroupBy.java     |  101 -
 .../plan/relational/sql/ast/SingleColumn.java      |  154 -
 .../plan/relational/sql/ast/SkipTo.java            |  145 -
 .../plan/relational/sql/ast/SortItem.java          |  157 -
 .../relational/sql/ast/StackableAstVisitor.java    |    6 +-
 .../relational/sql/ast/StartExternalService.java   |   10 +-
 .../plan/relational/sql/ast/StartPipe.java         |    7 +-
 .../plan/relational/sql/ast/StartRepairData.java   |    5 +-
 .../plan/relational/sql/ast/Statement.java         |   68 -
 .../relational/sql/ast/StopExternalService.java    |   10 +-
 .../plan/relational/sql/ast/StopPipe.java          |    7 +-
 .../plan/relational/sql/ast/StopRepairData.java    |    5 +-
 .../plan/relational/sql/ast/StringLiteral.java     |  123 -
 .../relational/sql/ast/SubqueryExpression.java     |   91 -
 .../relational/sql/ast/SubscriptionStatement.java  |    3 +
 .../plan/relational/sql/ast/SubsetDefinition.java  |  104 -
 .../plan/relational/sql/ast/SymbolReference.java   |   98 -
 .../queryengine/plan/relational/sql/ast/Table.java |  100 -
 .../relational/sql/ast/TableExpressionType.java    |   67 -
 .../relational/sql/ast/TableFunctionArgument.java  |  106 -
 .../sql/ast/TableFunctionInvocation.java           |  106 -
 .../sql/ast/TableFunctionTableArgument.java        |  138 -
 .../plan/relational/sql/ast/TableSubquery.java     |   97 -
 .../relational/sql/ast/TimeDurationLiteral.java    |  109 -
 .../plan/relational/sql/ast/TimeRange.java         |    4 +
 .../queryengine/plan/relational/sql/ast/Trim.java  |  153 -
 .../plan/relational/sql/ast/TypeParameter.java     |   90 -
 .../queryengine/plan/relational/sql/ast/Union.java |  103 -
 .../plan/relational/sql/ast/UnloadModel.java       |    9 +-
 .../plan/relational/sql/ast/Update.java            |   11 +-
 .../plan/relational/sql/ast/UpdateAssignment.java  |   10 +-
 .../queryengine/plan/relational/sql/ast/Use.java   |   11 +-
 .../plan/relational/sql/ast/Values.java            |   94 -
 .../relational/sql/ast/VariableDefinition.java     |  102 -
 .../relational/sql/ast/ViewFieldDefinition.java    |    9 +-
 .../plan/relational/sql/ast/WhenClause.java        |  124 -
 .../plan/relational/sql/ast/Window.java            |   30 -
 .../plan/relational/sql/ast/WindowDefinition.java  |  101 -
 .../plan/relational/sql/ast/WindowFrame.java       |  157 -
 .../plan/relational/sql/ast/WindowReference.java   |  108 -
 .../relational/sql/ast/WindowSpecification.java    |  224 -
 .../queryengine/plan/relational/sql/ast/With.java  |  111 -
 .../plan/relational/sql/ast/WithQuery.java         |  160 -
 .../relational/sql/ast/WrappedInsertStatement.java |    8 +-
 .../plan/relational/sql/ast/WrappedStatement.java  |    2 +
 .../relational/sql/ast/ZeroOrMoreQuantifier.java   |   43 -
 .../relational/sql/ast/ZeroOrOneQuantifier.java    |   43 -
 .../plan/relational/sql/parser/AstBuilder.java     |  299 +-
 .../sql/parser/CaseInsensitiveStream.java          |   85 -
 .../plan/relational/sql/parser/ErrorHandler.java   |    2 +
 .../relational/sql/parser/ParsingException.java    |   69 -
 .../plan/relational/sql/parser/SqlParser.java      |   12 +-
 .../plan/relational/sql/rewrite/ShowRewrite.java   |   38 +-
 .../relational/sql/rewrite/StatementRewrite.java   |   10 +-
 .../plan/relational/sql/util/AstUtil.java          |   16 +-
 .../relational/sql/util/DataNodeSqlFormatter.java  | 1095 +++++
 .../relational/sql/util/ExpressionFormatter.java   |  791 ----
 .../plan/relational/sql/util/QueryUtil.java        |   56 +-
 .../relational/sql/util/ReservedIdentifiers.java   |   49 -
 .../relational/sql/util/RowPatternFormatter.java   |  143 -
 .../plan/relational/sql/util/SqlFormatter.java     | 1767 --------
 .../plan/relational/type/InternalTypeManager.java  |  147 -
 .../plan/relational/type/NamedTypeSignature.java   |   79 -
 .../plan/relational/type/ParameterKind.java        |   27 -
 .../plan/relational/type/RowFieldName.java         |   63 -
 .../plan/relational/type/StandardTypes.java        |   55 -
 .../plan/relational/type/TypeCoercion.java         |    2 +
 .../queryengine/plan/relational/type/TypeId.java   |   66 -
 .../plan/relational/type/TypeManager.java          |   37 -
 .../relational/type/TypeNotFoundException.java     |   43 -
 .../plan/relational/type/TypeSignature.java        |  207 -
 .../relational/type/TypeSignatureParameter.java    |  175 -
 .../relational/type/TypeSignatureTranslator.java   |  113 -
 .../plan/relational/utils/NodeUtils.java           |    4 +-
 .../relational/utils/ResultColumnAppender.java     |  145 -
 .../plan/relational/utils/TypeUtil.java            |  513 ---
 .../plan/relational/utils/matching/Capture.java    |   43 -
 .../plan/relational/utils/matching/Captures.java   |   86 -
 .../relational/utils/matching/DefaultPrinter.java  |   77 -
 .../plan/relational/utils/matching/Match.java      |   66 -
 .../plan/relational/utils/matching/Pattern.java    |  120 -
 .../relational/utils/matching/PatternVisitor.java  |   46 -
 .../plan/relational/utils/matching/Property.java   |   89 -
 .../relational/utils/matching/PropertyPattern.java |   51 -
 .../utils/matching/pattern/CapturePattern.java     |   53 -
 .../utils/matching/pattern/EqualsPattern.java      |   53 -
 .../utils/matching/pattern/FilterPattern.java      |   55 -
 .../utils/matching/pattern/TypeOfPattern.java      |   59 -
 .../utils/matching/pattern/WithPattern.java        |   65 -
 .../plan/scheduler/ClusterScheduler.java           |    4 +-
 .../scheduler/FragmentInstanceDispatcherImpl.java  |    6 +-
 .../scheduler/load/LoadTsFileDispatcherImpl.java   |    4 +-
 .../db/queryengine/plan/statement/Statement.java   |    4 +-
 .../plan/statement/component/FillComponent.java    |    1 +
 .../plan/statement/component/FillPolicy.java       |   33 -
 .../plan/statement/component/IntoComponent.java    |    2 +-
 .../plan/statement/crud/InsertBaseStatement.java   |   10 +-
 .../crud/InsertMultiTabletsStatement.java          |    2 +-
 .../plan/statement/crud/InsertRowStatement.java    |    8 +-
 .../crud/InsertRowsOfOneDeviceStatement.java       |    4 +-
 .../plan/statement/crud/InsertRowsStatement.java   |    6 +-
 .../plan/statement/crud/InsertTabletStatement.java |    8 +-
 .../plan/statement/crud/LoadTsFileStatement.java   |    4 +-
 .../plan/statement/crud/QueryStatement.java        |    4 +-
 .../plan/statement/literal/BinaryLiteral.java      |    2 +-
 .../metadata/CreateContinuousQueryStatement.java   |    2 +-
 .../metadata/view/CreateLogicalViewStatement.java  |    2 +-
 .../plan/statement/pipe/PipeEnrichedStatement.java |    4 +-
 .../statement/sys/SetConfigurationStatement.java   |    2 +-
 .../plan/statement/sys/SetSqlDialectStatement.java |    8 +-
 .../plan/udf/BuiltinAggregationFunction.java       |  142 -
 .../plan/udf/BuiltinScalarFunction.java            |   67 -
 .../udf/BuiltinTimeSeriesGeneratingFunction.java   |  180 -
 .../db/queryengine/plan/udf/TableUDFUtils.java     |   65 -
 .../db/queryengine/plan/udf/TreeUDFUtils.java      |    1 +
 .../queryengine/plan/udf/UDFManagementService.java |  296 --
 .../db/queryengine/plan/udf/UDTFForecast.java      |  272 --
 .../FragmentInstanceStatisticsDrawer.java          |    2 +-
 .../transformation/api/LayerRowWindowReader.java   |    2 +-
 ...izableRowRecordListBackedMultiColumnWindow.java |    2 +-
 ...wRecordListBackedMultiColumnWindowIterator.java |    2 +-
 ...ticSerializableTVListBackedSingleColumnRow.java |    2 +-
 ...SerializableTVListBackedSingleColumnWindow.java |    2 +-
 ...ableTVListBackedSingleColumnWindowIterator.java |    2 +-
 .../dag/adapter/PointCollectorAdaptor.java         |   97 -
 .../dag/builder/EvaluationDAGBuilder.java          |    4 +-
 .../AbstractCaseWhenThenColumnTransformer.java     |  233 -
 .../transformation/dag/column/ColumnCache.java     |   62 -
 .../dag/column/ColumnTransformer.java              |  118 -
 .../dag/column/FailFunctionColumnTransformer.java  |   62 -
 .../column/TableCaseWhenThenColumnTransformer.java |   43 -
 .../column/TreeCaseWhenThenColumnTransformer.java  |   64 -
 .../ArithmeticAdditionColumnTransformer.java       |   36 -
 .../binary/ArithmeticBinaryColumnTransformer.java  |   78 -
 .../ArithmeticDivisionColumnTransformer.java       |   36 -
 .../binary/ArithmeticModuloColumnTransformer.java  |   36 -
 .../ArithmeticMultiplicationColumnTransformer.java |   37 -
 .../ArithmeticSubtractionColumnTransformer.java    |   36 -
 .../dag/column/binary/BinaryColumnTransformer.java |   98 -
 .../binary/CompareBinaryColumnTransformer.java     |  127 -
 .../binary/CompareEqualToColumnTransformer.java    |   48 -
 .../CompareGreaterEqualColumnTransformer.java      |   36 -
 .../CompareGreaterThanColumnTransformer.java       |   36 -
 .../binary/CompareLessEqualColumnTransformer.java  |   36 -
 .../binary/CompareLessThanColumnTransformer.java   |   36 -
 .../binary/CompareNonEqualColumnTransformer.java   |   48 -
 .../dag/column/binary/HmacColumnTransformer.java   |  108 -
 .../dag/column/binary/Like2ColumnTransformer.java  |   92 -
 .../column/binary/LogicAndColumnTransformer.java   |  125 -
 .../binary/LogicBinaryColumnTransformer.java       |   42 -
 .../column/binary/LogicOrColumnTransformer.java    |  126 -
 .../binary/factory/HmacStrategiesFactory.java      |   93 -
 .../dag/column/binary/strategies/HmacStrategy.java |   25 -
 .../dag/column/leaf/ConstantColumnTransformer.java |   54 -
 .../dag/column/leaf/IdentityColumnTransformer.java |   58 -
 .../dag/column/leaf/LeafColumnTransformer.java     |   42 -
 .../dag/column/leaf/NullColumnTransformer.java     |   41 -
 .../dag/column/leaf/TimeColumnTransformer.java     |   51 -
 .../AbstractGreatestLeastColumnTransformer.java    |  109 -
 .../multi/BinaryGreatestColumnTransformer.java     |   53 -
 .../column/multi/BinaryLeastColumnTransformer.java |   53 -
 .../multi/BooleanGreatestColumnTransformer.java    |   52 -
 .../multi/BooleanLeastColumnTransformer.java       |   49 -
 .../column/multi/CoalesceColumnTransformer.java    |   74 -
 .../multi/DoubleGreatestColumnTransformer.java     |   52 -
 .../column/multi/DoubleLeastColumnTransformer.java |   52 -
 .../multi/FloatGreatestColumnTransformer.java      |   52 -
 .../column/multi/FloatLeastColumnTransformer.java  |   52 -
 .../multi/InBinaryMultiColumnTransformer.java      |   59 -
 .../multi/InBooleanMultiColumnTransformer.java     |   58 -
 .../multi/InDoubleMultiColumnTransformer.java      |   58 -
 .../multi/InFloatMultiColumnTransformer.java       |   58 -
 .../multi/InInt32MultiColumnTransformer.java       |   58 -
 .../multi/InInt64MultiColumnTransformer.java       |   58 -
 .../dag/column/multi/InMultiColumnTransformer.java |   66 -
 .../multi/Int32GreatestColumnTransformer.java      |   52 -
 .../column/multi/Int32LeastColumnTransformer.java  |   52 -
 .../multi/Int64GreatestColumnTransformer.java      |   52 -
 .../column/multi/Int64LeastColumnTransformer.java  |   52 -
 .../multi/LogicalAndMultiColumnTransformer.java    |  122 -
 .../multi/LogicalMultiColumnTransformer.java       |   44 -
 .../multi/LogicalOrMultiColumnTransformer.java     |  122 -
 .../column/multi/MappableUDFColumnTransformer.java |   99 -
 .../dag/column/multi/MultiColumnTransformer.java   |   99 -
 .../column/ternary/BetweenColumnTransformer.java   |  123 -
 .../ternary/CompareTernaryColumnTransformer.java   |   39 -
 .../dag/column/ternary/Like3ColumnTransformer.java |  105 -
 .../dag/column/ternary/LpadColumnTransformer.java  |   92 -
 .../dag/column/ternary/RpadColumnTransformer.java  |   92 -
 .../column/ternary/TernaryColumnTransformer.java   |  113 -
 .../dag/column/ternary/utils/BytePaddingUtils.java |   87 -
 .../udf/UserDefineScalarFunctionTransformer.java   |  108 -
 .../unary/ArithmeticNegationColumnTransformer.java |   65 -
 .../dag/column/unary/InColumnTransformer.java      |  269 --
 .../dag/column/unary/IsNullColumnTransformer.java  |   55 -
 .../dag/column/unary/LikeColumnTransformer.java    |   74 -
 .../column/unary/LogicNotColumnTransformer.java    |   65 -
 .../dag/column/unary/RegularColumnTransformer.java |   87 -
 .../dag/column/unary/UnaryColumnTransformer.java   |   75 -
 .../column/unary/scalar/AbsColumnTransformer.java  |   71 -
 .../scalar/AbstractBitwise2ColumnTransformer.java  |   71 -
 .../scalar/AbstractBitwiseColumnTransformer.java   |   62 -
 .../AbstractCastFunctionColumnTransformer.java     |  406 --
 .../scalar/AbstractLengthColumnTransformer.java    |   60 -
 .../column/unary/scalar/AcosColumnTransformer.java |   68 -
 .../column/unary/scalar/AsinColumnTransformer.java |   68 -
 .../column/unary/scalar/AtanColumnTransformer.java |   68 -
 .../unary/scalar/BitCount2ColumnTransformer.java   |   76 -
 .../unary/scalar/BitCountColumnTransformer.java    |   68 -
 .../unary/scalar/BitwiseAnd2ColumnTransformer.java |   44 -
 .../unary/scalar/BitwiseAndColumnTransformer.java  |   42 -
 .../scalar/BitwiseLeftShift2ColumnTransformer.java |   60 -
 .../scalar/BitwiseLeftShiftColumnTransformer.java  |   47 -
 .../unary/scalar/BitwiseNotColumnTransformer.java  |   63 -
 .../unary/scalar/BitwiseOr2ColumnTransformer.java  |   44 -
 .../unary/scalar/BitwiseOrColumnTransformer.java   |   42 -
 .../BitwiseRightShift2ColumnTransformer.java       |   60 -
 ...wiseRightShiftArithmetic2ColumnTransformer.java |   65 -
 ...twiseRightShiftArithmeticColumnTransformer.java |   49 -
 .../scalar/BitwiseRightShiftColumnTransformer.java |   47 -
 .../unary/scalar/BitwiseXor2ColumnTransformer.java |   44 -
 .../unary/scalar/BitwiseXorColumnTransformer.java  |   42 -
 .../unary/scalar/BlobLengthColumnTransformer.java  |   37 -
 .../scalar/BytesToDoubleColumnTransformer.java     |   78 -
 .../scalar/BytesToFloatColumnTransformer.java      |   79 -
 .../unary/scalar/BytesToIntColumnTransformer.java  |   81 -
 .../unary/scalar/BytesToLongColumnTransformer.java |   80 -
 .../dag/column/unary/scalar/CRC32Transformer.java  |   61 -
 .../scalar/CastFunctionColumnTransformer.java      |   79 -
 .../column/unary/scalar/CeilColumnTransformer.java |   68 -
 .../unary/scalar/Concat2ColumnTransformer.java     |   81 -
 .../unary/scalar/ConcatColumnTransformer.java      |   81 -
 .../unary/scalar/ConcatMultiColumnTransformer.java |   90 -
 .../column/unary/scalar/CosColumnTransformer.java  |   68 -
 .../column/unary/scalar/CoshColumnTransformer.java |   68 -
 .../scalar/DateBinFunctionColumnTransformer.java   |  231 -
 .../unary/scalar/DegreesColumnTransformer.java     |   68 -
 .../column/unary/scalar/DiffColumnTransformer.java |   86 -
 .../scalar/DiffFunctionColumnTransformer.java      |   92 -
 .../scalar/DoubleToBytesColumnTransformer.java     |   61 -
 .../unary/scalar/EndsWith2ColumnTransformer.java   |   75 -
 .../unary/scalar/EndsWithColumnTransformer.java    |   65 -
 .../column/unary/scalar/ExpColumnTransformer.java  |   68 -
 .../column/unary/scalar/ExtractTransformer.java    |  106 -
 .../scalar/FloatToBytesColumnTransformer.java      |   61 -
 .../unary/scalar/FloorColumnTransformer.java       |   68 -
 .../unary/scalar/FormatColumnTransformer.java      |  117 -
 .../scalar/GenericCodecColumnTransformer.java      |   92 -
 .../scalar/HmacConstantKeyColumnTransformer.java   |   68 -
 .../unary/scalar/IntToBytesColumnTransformer.java  |   62 -
 .../unary/scalar/LTrim2ColumnTransformer.java      |   74 -
 .../unary/scalar/LTrimColumnTransformer.java       |   82 -
 .../unary/scalar/LengthColumnTransformer.java      |   37 -
 .../column/unary/scalar/LnColumnTransformer.java   |   68 -
 .../unary/scalar/Log10ColumnTransformer.java       |   68 -
 .../unary/scalar/LongToBytesColumnTransformer.java |   60 -
 .../unary/scalar/LowerColumnTransformer.java       |   59 -
 .../scalar/ObjectLengthColumnTransformer.java      |   37 -
 .../unary/scalar/RTrim2ColumnTransformer.java      |   74 -
 .../unary/scalar/RTrimColumnTransformer.java       |   82 -
 .../unary/scalar/RadiansColumnTransformer.java     |   68 -
 .../unary/scalar/RegexpLike2ColumnTransformer.java |   72 -
 .../unary/scalar/RegexpLikeColumnTransformer.java  |   64 -
 .../unary/scalar/Replace2ColumnTransformer.java    |   94 -
 .../unary/scalar/Replace3ColumnTransformer.java    |  110 -
 .../scalar/ReplaceFunctionColumnTransformer.java   |   77 -
 .../unary/scalar/RoundColumnTransformer.java       |  105 -
 .../scalar/RoundFunctionColumnTransformer.java     |   94 -
 .../column/unary/scalar/SignColumnTransformer.java |   68 -
 .../column/unary/scalar/SinColumnTransformer.java  |   68 -
 .../column/unary/scalar/SinhColumnTransformer.java |   68 -
 .../column/unary/scalar/SqrtColumnTransformer.java |   68 -
 .../unary/scalar/StartsWith2ColumnTransformer.java |   73 -
 .../unary/scalar/StartsWithColumnTransformer.java  |   73 -
 .../unary/scalar/Strcmp2ColumnTransformer.java     |   72 -
 .../unary/scalar/StrcmpColumnTransformer.java      |   62 -
 .../unary/scalar/Strpos2ColumnTransformer.java     |   72 -
 .../unary/scalar/StrposColumnTransformer.java      |   62 -
 .../unary/scalar/SubString2ColumnTransformer.java  |   86 -
 .../unary/scalar/SubString3ColumnTransformer.java  |  129 -
 .../unary/scalar/SubStringColumnTransformer.java   |   92 -
 .../column/unary/scalar/TanColumnTransformer.java  |   68 -
 .../column/unary/scalar/TanhColumnTransformer.java |   68 -
 .../unary/scalar/Trim2ColumnTransformer.java       |   74 -
 .../column/unary/scalar/TrimColumnTransformer.java |   94 -
 .../scalar/TryCastFunctionColumnTransformer.java   |   85 -
 .../unary/scalar/UpperColumnTransformer.java       |   60 -
 .../scalar/factory/CodecStrategiesFactory.java     |  138 -
 .../factory/NumericCodecStrategiesFactory.java     |  169 -
 .../unary/scalar/inteface/CodecStrategy.java       |   27 -
 .../dag/column/unary/scalar/util/HexUtils.java     |   86 -
 .../unary/scalar/util/SpookyHashV2Utils.java       |  603 ---
 .../unary/scalar/util/TransformerDebugUtils.java   |   62 -
 .../dag/input/ConstantInputReader.java             |    2 +-
 .../dag/input/QueryDataSetInputLayer.java          |    6 +-
 .../dag/input/TsBlockInputDataSet.java             |    2 +-
 .../intermediate/ConstantIntermediateLayer.java    |    2 +-
 .../dag/intermediate/IntermediateLayer.java        |    2 +-
 .../dag/intermediate/MultiInputLayer.java          |    6 +-
 .../SingleInputMultiReferenceLayer.java            |    4 +-
 .../SingleInputSingleReferenceLayer.java           |    4 +-
 .../transformation/dag/memory/SafetyLine.java      |    2 +-
 .../binary/ArithmeticBinaryTransformer.java        |    2 +-
 .../dag/transformer/binary/BinaryTransformer.java  |    2 +-
 .../binary/CompareBinaryTransformer.java           |    2 +-
 .../binary/CompareEqualToTransformer.java          |    5 +-
 .../binary/CompareGreaterEqualTransformer.java     |    5 +-
 .../binary/CompareGreaterThanTransformer.java      |    5 +-
 .../binary/CompareLessEqualTransformer.java        |    5 +-
 .../binary/CompareLessThanTransformer.java         |    5 +-
 .../binary/CompareNonEqualTransformer.java         |    5 +-
 .../multi/MappableUDFQueryRowTransformer.java      |    2 +-
 .../transformer/multi/UDFQueryRowTransformer.java  |    2 +-
 .../multi/UDFQueryRowWindowTransformer.java        |    2 +-
 .../dag/transformer/multi/UDFQueryTransformer.java |    2 +-
 .../multi/UniversalUDFQueryTransformer.java        |    6 +-
 .../transformer/ternary/BetweenTransformer.java    |    6 +-
 .../ternary/CompareTernaryTransformer.java         |    2 +-
 .../transformer/ternary/TernaryTransformer.java    |    2 +-
 .../unary/ArithmeticNegationTransformer.java       |    2 +-
 .../dag/transformer/unary/InTransformer.java       |    2 +-
 .../dag/transformer/unary/IsNullTransformer.java   |    2 +-
 .../dag/transformer/unary/LikeTransformer.java     |    2 +-
 .../dag/transformer/unary/LogicNotTransformer.java |    2 +-
 .../dag/transformer/unary/RegularTransformer.java  |    2 +-
 .../transformer/unary/TransparentTransformer.java  |    2 +-
 .../dag/transformer/unary/UnaryTransformer.java    |    2 +-
 .../unary/scalar/CastFunctionTransformer.java      |   22 +-
 .../unary/scalar/DiffFunctionTransformer.java      |    2 +-
 .../unary/scalar/RoundFunctionTransformer.java     |    2 +-
 .../scalar/SubStringFunctionColumnTransformer.java |    4 +-
 .../unary/scalar/SubStringFunctionTransformer.java |    2 +-
 .../dag/udf/UDAFInformationInferrer.java           |    5 +-
 .../dag/udf/UDFParametersFactory.java              |   55 -
 .../transformation/dag/udf/UDTFContext.java        |    5 +-
 .../transformation/dag/udf/UDTFExecutor.java       |  300 --
 .../dag/udf/UDTFInformationInferrer.java           |    5 +-
 .../transformation/dag/util/BitwiseUtils.java      |  210 -
 .../transformation/dag/util/InputRowUtils.java     |   67 -
 .../transformation/dag/util/LayerCacheUtils.java   |    4 +-
 .../transformation/dag/util/TransformUtils.java    |   10 +-
 .../transformation/dag/util/TypeUtils.java         |    2 +-
 .../transformation/datastructure/Cache.java        |   68 -
 .../datastructure/SerializableList.java            |  167 -
 .../iterator/ListForwardIterator.java              |   28 -
 .../iterator/RowListForwardIterator.java           |  100 -
 .../iterator/TVListForwardIterator.java            |  108 -
 .../row/ElasticSerializableRowList.java            |  485 ---
 .../datastructure/row/SerializableRowList.java     |  374 --
 .../tv/ElasticSerializableBinaryTVList.java        |  205 -
 .../tv/ElasticSerializableTVList.java              |  287 --
 .../datastructure/tv/SerializableTVList.java       |  402 --
 .../datastructure/util/BinaryUtils.java            |   48 -
 .../GeneralRegionAttributeSecurityService.java     |    2 +-
 .../schemaregion/impl/SchemaRegionMemoryImpl.java  |   24 +-
 .../visitor/SchemaRegionPlanDeserializer.java      |    2 +-
 .../visitor/SchemaRegionPlanSerializer.java        |    2 +-
 .../reader/impl/TimeseriesReaderWithViewFetch.java |    2 +-
 .../schemaregion/utils/ResourceByPathUtils.java    |    4 +-
 .../view/visitor/TransformToExpressionVisitor.java |   27 +-
 .../db/schemaengine/table/DataNodeTableCache.java  |    4 +-
 .../table/DataNodeTreeViewSchemaUtils.java         |    2 +-
 .../schemaengine/table/InformationSchemaUtils.java |    2 +-
 .../java/org/apache/iotdb/db/service/DataNode.java |    7 +-
 ...aNodeTemporaryQueryDataFileServiceProvider.java |   32 +
 .../db/service/TemporaryQueryDataFileService.java  |  105 +-
 .../db/service/metrics/DataNodeMetricsHelper.java  |    2 +-
 .../metrics/IoTDBInternalLocalReporter.java        |    4 +-
 .../db/storageengine/dataregion/DataRegion.java    |   14 +-
 .../dataregion/IDataRegionForQuery.java            |    2 +-
 .../db/storageengine/dataregion/IObjectPath.java   |   65 -
 .../dataregion/VirtualDataRegion.java              |    2 +-
 .../dataregion/memtable/AbstractMemTable.java      |    2 +-
 .../memtable/AbstractWritableMemChunk.java         |    4 +-
 .../dataregion/memtable/IMemTable.java             |    2 +-
 .../dataregion/memtable/ReadOnlyMemChunk.java      |    2 +-
 .../dataregion/memtable/TsFileProcessor.java       |    6 +-
 .../modification/TableDeletionEntry.java           |    2 +-
 .../dataregion/modification/TreeDeletionEntry.java |    2 +-
 .../read/reader/chunk/DiskAlignedChunkLoader.java  |    2 +-
 .../read/reader/chunk/DiskChunkLoader.java         |    2 +-
 .../read/reader/common/PriorityMergeReader.java    |    2 +-
 .../DataRegionTableSizeQueryContext.java           |    2 +-
 .../dataregion/wal/buffer/WALEntry.java            |    4 +-
 .../storageengine/dataregion/wal/node/WALNode.java |    4 +-
 .../load/active/ActiveLoadPathHelper.java          |    2 +-
 .../load/config/LoadTsFileConfigurator.java        |    2 +-
 ...ertedInsertTabletStatementExceptionVisitor.java |    6 +-
 ...leStatementDataTypeConvertExecutionVisitor.java |    2 +-
 ...ertedInsertTabletStatementExceptionVisitor.java |    2 +-
 .../converter/LoadTsFileDataTypeConverter.java     |    5 +-
 .../apache/iotdb/db/tools/IoTDBDataDirViewer.java  |    2 +-
 .../iotdb/db/tools/TsFileResourcePrinter.java      |    2 +-
 .../db/trigger/executor/TriggerFireVisitor.java    |    4 +-
 .../org/apache/iotdb/db/utils/CommonUtils.java     |   10 +-
 .../iotdb/db/utils/DataNodeDateTimeUtils.java      |  259 ++
 .../iotdb/db/utils/DataNodeObjectFileService.java  |  134 +
 .../utils/DataNodeObjectFileServiceProvider.java   |   31 +
 .../org/apache/iotdb/db/utils/DateTimeUtils.java   |  958 -----
 .../apache/iotdb/db/utils/ErrorHandlingUtils.java  |    4 +-
 .../org/apache/iotdb/db/utils/HeapTraversal.java   |   64 -
 .../org/apache/iotdb/db/utils/ObjectTypeUtils.java |  252 --
 .../org/apache/iotdb/db/utils/SchemaUtils.java     |    2 +-
 .../iotdb/db/utils/TimestampPrecisionUtils.java    |  100 -
 .../apache/iotdb/db/utils/TypeInferenceUtils.java  |    4 +-
 .../iotdb/db/utils/constant/SqlConstant.java       |  125 -
 .../apache/iotdb/db/utils/cte/CteDataStore.java    |  109 -
 .../apache/iotdb/db/utils/cte/MemoryReader.java    |    1 +
 .../db/utils/datastructure/MergeSortHeap.java      |  117 -
 .../iotdb/db/utils/datastructure/MergeSortKey.java |   45 -
 .../iotdb/db/utils/datastructure/SortKey.java      |   33 -
 .../apache/iotdb/db/utils/sort/DiskSpiller.java    |  184 -
 .../iotdb/db/utils/sort/FileSpillerReader.java     |  155 -
 .../apache/iotdb/db/utils/sort/MemoryReader.java   |   61 -
 .../iotdb/db/utils/sort/SortBufferManager.java     |   88 -
 .../org/apache/iotdb/db/utils/sort/SortReader.java |   51 -
 .../iotdb/db/utils/sort/TableDiskSpiller.java      |   47 -
 .../iotdb/db/utils/sort/TreeDiskSpiller.java       |   44 -
 ....service.ITemporaryQueryDataFileServiceProvider |    1 +
 ...che.iotdb.calc.utils.IObjectFileServiceProvider |    1 +
 ...planner.plan.node.IPlanNodeDeserializerProvider |    1 +
 ...al.function.ITableFunctionAINodeServiceProvider |    1 +
 .../dataregion/DataRegionStateMachineTest.java     |    2 +-
 .../metadata/mtree/schemafile/SchemaFileTest.java  |    3 +-
 .../SchemaRegionSimpleRecoverTest.java             |    8 +-
 .../schemaRegion/SchemaRegionTestUtil.java         |    2 +-
 .../db/pipe/consensus/DeletionRecoverTest.java     |    2 +-
 .../db/pipe/consensus/DeletionResourceTest.java    |    2 +-
 .../pipe/event/PipeTabletInsertionEventTest.java   |    2 +-
 .../pipe/sink/PipeDataNodeThriftRequestTest.java   |    2 +-
 .../PipePlanTablePatternParseVisitorTest.java      |    4 +-
 .../PipePlanTreePatternParseVisitorTest.java       |    2 +-
 .../db/pipe/source/PipeRealtimeExtractTest.java    |    2 +-
 .../source/SchemaRegionListeningQueueTest.java     |    2 +-
 .../org/apache/iotdb/db/qp/sql/ASTVisitorTest.java |    4 +-
 .../queryengine/common/schematree/NodeRefTest.java |    2 +-
 .../db/queryengine/execution/DataDriverTest.java   |   14 +-
 .../execution/aggregation/AccumulatorTest.java     |    1 +
 .../executor/RegionWriteExecutorTest.java          |    2 +-
 .../fragment/FragmentInstanceExecutionTest.java    |    4 +-
 .../operator/AggregationMergeSortOperatorTest.java |   10 +-
 .../operator/AggregationOperatorTest.java          |    7 +-
 .../AlignedSeriesAggregationScanOperatorTest.java  |    4 +-
 .../operator/AlignedSeriesScanOperatorTest.java    |    4 +-
 .../execution/operator/CteScanOperatorTest.java    |    8 +-
 .../operator/DeviceIteratorScanOperatorTest.java   |    3 +-
 .../operator/DeviceViewIntoOperatorTest.java       |    5 +-
 .../execution/operator/DeviceViewOperatorTest.java |    3 +-
 .../execution/operator/ExchangeOperatorTest.java   |    2 +-
 .../execution/operator/FillOperatorTest.java       |   13 +-
 .../operator/HorizontallyConcatOperatorTest.java   |    2 +-
 .../operator/LastQueryMergeOperatorTest.java       |    3 +-
 .../execution/operator/LastQueryOperatorTest.java  |    2 +-
 .../operator/LastQueryTreeSortOperatorTest.java    |    2 +-
 .../execution/operator/LimitOperatorTest.java      |    6 +-
 .../operator/MergeTreeSortOperatorTest.java        |   29 +-
 .../execution/operator/MultiColumnMergerTest.java  |    2 +-
 ...nAlignedTreeDeviceViewScanOperatorTreeTest.java |   30 +-
 .../NonOverlappedMultiColumnMergerTest.java        |    2 +-
 .../execution/operator/OffsetOperatorTest.java     |    8 +-
 .../execution/operator/OperatorMemoryTest.java     |   29 +-
 .../operator/RawDataAggregationOperatorTest.java   |    6 +-
 .../SeriesAggregationScanOperatorTest.java         |    2 +-
 .../execution/operator/SeriesScanOperatorTest.java |    2 +-
 .../execution/operator/SingleColumnMergerTest.java |    2 +-
 .../operator/SingleDeviceViewOperatorTest.java     |    4 +-
 .../SlidingWindowAggregationOperatorTest.java      |    4 +-
 .../operator/SortOperatorSortBranchTest.java       |   18 +-
 .../execution/operator/TransformOperatorTest.java  |    7 +-
 .../execution/operator/TreeIntoOperatorTest.java   |    5 +-
 .../operator/TreeLinearFillOperatorTest.java       |   11 +-
 .../execution/operator/TreeSortOperatorTest.java   |   14 +-
 .../execution/operator/TreeTopKOperatorTest.java   |   21 +-
 .../operator/UpdateLastCacheOperatorTest.java      |    2 +-
 .../operator/ViewFromTreeAdaptorOperatorTest.java  |    9 +-
 .../process/TableStreamSortOperatorTest.java       |   31 +-
 .../operator/process/ValuesOperatorTest.java       |    8 +-
 .../fill/filter/MonthIntervalFillFilterTest.java   |    4 +
 .../gapfill/GapFillWGroupWMoOperatorTest.java      |   19 +-
 .../gapfill/GapFillWGroupWoMoOperatorTest.java     |   19 +-
 .../gapfill/GapFillWoGroupWMoOperatorTest.java     |   16 +-
 .../gapfill/GapFillWoGroupWoMoOperatorTest.java    |   15 +-
 .../process/join/InnerTimeJoinOperatorTest.java    |    4 +-
 .../join/LeftOuterTimeJoinOperatorTest.java        |    2 +-
 .../rowpattern/IrRowPatternOptimizationTest.java   |   26 +-
 .../operator/process/rowpattern/MatcherTest.java   |   36 +-
 .../process/rowpattern/PatternExpressionTest.java  |   10 +-
 .../process/tvf/TableFunctionOperatorTest.java     |   10 +-
 .../process/window/RowNumberOperatorTest.java      |   10 +-
 .../process/window/TableWindowOperatorTest.java    |   16 +-
 .../window/TableWindowOperatorTestUtils.java       |   22 +-
 .../process/window/TopKRankingOperatorTest.java    |   14 +-
 .../process/window/function/FunctionTestUtils.java |   13 +-
 .../aggregate/AggregationWindowFunctionTest.java   |   22 +-
 .../window/function/rank/CumeDistFunctionTest.java |    9 +-
 .../function/rank/DenseRankFunctionTest.java       |    9 +-
 .../window/function/rank/NTileFunctionTest.java    |   18 +-
 .../function/rank/PercentRankFunctionTest.java     |    9 +-
 .../window/function/rank/RankFunctionTest.java     |    9 +-
 .../function/rank/RowNumberFunctionTest.java       |    9 +-
 .../function/value/FirstValueFunctionTest.java     |   14 +-
 .../window/function/value/LagFunctionTest.java     |   24 +-
 .../function/value/LastValueFunctionTest.java      |   14 +-
 .../window/function/value/LeadFunctionTest.java    |   24 +-
 .../function/value/NthValueFunctionTest.java       |   20 +-
 .../window/partition/frame/FrameTestUtils.java     |   13 +-
 .../window/partition/frame/GroupsFrameTest.java    |    1 +
 .../window/partition/frame/RangeFrameTest.java     |    3 +-
 .../window/partition/frame/RowsFrameTest.java      |    1 +
 .../schema/CountGroupByLevelMergeOperatorTest.java |    2 +-
 .../operator/schema/SchemaCountOperatorTest.java   |    2 +-
 .../schema/SchemaQueryScanOperatorTest.java        |    2 +-
 .../operator/sink/IdentitySinkOperatorTest.java    |    2 +-
 .../sink/SinkOperatorDownStreamNodeIdTest.java     |   11 +-
 .../source/relational/TableScanOperatorTest.java   |    4 +-
 .../execution/schedule/DriverSchedulerTest.java    |    2 +-
 .../ConvertPredicateToTimeFilterTest.java          |    2 +-
 .../queryengine/plan/analyze/AnalyzeFailTest.java  |    2 +-
 .../db/queryengine/plan/analyze/AnalyzeTest.java   |    2 +-
 .../plan/optimization/AggregationPushDownTest.java |    2 +-
 .../optimization/ColumnInjectionPushDownTest.java  |    4 +-
 .../plan/optimization/LimitOffsetPushDownTest.java |    6 +-
 .../plan/optimization/OptimizationTestUtil.java    |    2 +-
 .../plan/optimization/PredicatePushDownTest.java   |    2 +-
 .../plan/optimization/TestPlanBuilder.java         |    6 +-
 .../plan/parser/StatementGeneratorTest.java        |    8 +-
 .../queryengine/plan/planner/ExpressionTest.java   |    2 +-
 .../plan/planner/FragmentInstanceSerdeTest.java    |    6 +-
 .../plan/planner/PipelineBuilderTest.java          |    6 +-
 .../distribution/AggregationAlignByDeviceTest.java |    2 +-
 .../distribution/AggregationDistributionTest.java  |    4 +-
 .../distribution/AggregationTableScanTest.java     |   24 +-
 .../AlignByDeviceOrderByLimitOffsetTest.java       |    2 +-
 .../AlignByTimeOrderByLimitOffsetTest.java         |    2 +-
 .../planner/distribution/AlignedByDeviceTest.java  |    2 +-
 .../distribution/DistributionPlannerBasicTest.java |   12 +-
 .../distribution/DistributionPlannerCycleTest.java |    2 +-
 .../plan/planner/distribution/LastQueryTest.java   |    4 +-
 .../distribution/NoDataRegionPlanningTest.java     |    2 +-
 .../distribution/RegionScanPlanningTest.java       |    2 +-
 .../plan/planner/distribution/Util.java            |    2 +-
 .../plan/planner/distribution/Util2.java           |    2 +-
 .../logical/DataQueryLogicalPlannerTest.java       |    2 +-
 .../planner/logical/LogicalPlannerTestUtil.java    |    4 +-
 .../logical/RegionScanLogicalPlannerTest.java      |    6 +-
 .../logical/SchemaQueryLogicalPlannerTest.java     |    4 +-
 .../plan/planner/node/PlanGraphPrinterTest.java    |    2 +-
 .../planner/node/PlanNodeDeserializeHelper.java    |    4 +-
 .../plan/planner/node/load/LoadTsFileNodeTest.java |    2 +-
 .../read/DeviceSchemaFetchScanNodeTest.java        |    4 +-
 .../read/DeviceSchemaScanNodeSerdeTest.java        |    2 +-
 .../NodeManagementMemoryMergeNodeSerdeTest.java    |    2 +-
 .../read/PathsUsingTemplateScanNodeTest.java       |    4 +-
 .../metadata/read/SchemaCountNodeSerdeTest.java    |    2 +-
 .../metadata/read/SchemaFetchMergeNodeTest.java    |    4 +-
 .../read/SeriesSchemaFetchScanNodeTest.java        |    4 +-
 .../read/TimeSeriesSchemaScanNodeSerdeTest.java    |    2 +-
 .../metadata/write/MetadataWriteNodeSerDeTest.java |    6 +-
 .../pipe/PipeEnrichedDeleteDataNodeSerdeTest.java  |    6 +-
 .../node/pipe/PipeEnrichedInsertNodeSerdeTest.java |    4 +-
 .../PipeEnrichedNonWritePlanNodeSerdeTest.java     |    6 +-
 .../pipe/PipeEnrichedWritePlanNodeSerdeTest.java   |    6 +-
 .../node/process/AggregationNodeSerdeTest.java     |    2 +-
 .../node/process/DeviceViewNodeSerdeTest.java      |    2 +-
 .../node/process/ExchangeNodeSerdeTest.java        |    2 +-
 .../planner/node/process/FillNodeSerdeTest.java    |    4 +-
 .../planner/node/process/FilterNodeSerdeTest.java  |    2 +-
 .../node/process/GroupByLevelNodeSerdeTest.java    |    2 +-
 .../node/process/GroupByTagNodeSerdeTest.java      |    2 +-
 .../planner/node/process/IntoNodeSerdeTest.java    |    6 +-
 .../planner/node/process/LimitNodeSerdeTest.java   |    2 +-
 .../planner/node/process/OffsetNodeSerdeTest.java  |    2 +-
 .../process/SingleDeviceViewNodeSerdeTest.java     |    2 +-
 .../planner/node/process/SortNodeSerdeTest.java    |    2 +-
 .../node/process/TimeJoinNodeSerdeTest.java        |    4 +-
 .../planner/node/process/WindowNodeSerdeTest.java  |   28 +-
 .../node/sink/IdentitySinkNodeSerdeTest.java       |    2 +-
 .../node/sink/ShuffleSinkHandleNodeSerdeTest.java  |    2 +-
 .../source/SeriesAggregationScanNodeSerdeTest.java |    4 +-
 .../node/source/SeriesScanNodeSerdeTest.java       |    4 +-
 .../planner/node/source/SourceNodeSerdeTest.java   |    6 +-
 ...nuousSameSearchIndexSeparatorNodeSerDeTest.java |    4 +-
 .../node/write/DeleteDataNodeSerdeTest.java        |    6 +-
 .../write/InsertMultiTabletsNodeSerdeTest.java     |    4 +-
 .../planner/node/write/InsertRowNodeSerdeTest.java |    4 +-
 .../node/write/InsertRowsNodeSerdeTest.java        |    4 +-
 .../write/InsertRowsOfOneDeviceNodeSerdeTest.java  |    4 +-
 .../node/write/InsertTabletNodeSerdeTest.java      |    4 +-
 .../planner/node/write/WritePlanNodeSplitTest.java |    2 +-
 .../IPlanVisitorInheritanceConstraintTest.java     |  284 ++
 .../node/write/RelationalDeleteDataNodeTest.java   |    6 +-
 .../analyzer/AggregationCornerCaseTest.java        |   22 +-
 .../plan/relational/analyzer/AggregationTest.java  |   26 +-
 .../plan/relational/analyzer/AnalyzerTest.java     |   39 +-
 .../analyzer/AsofInnerJoinOperatorTest.java        |   14 +-
 .../plan/relational/analyzer/AsofJoinTest.java     |   16 +-
 .../plan/relational/analyzer/AuthTest.java         |   16 +-
 .../plan/relational/analyzer/DistinctTest.java     |    2 +-
 .../relational/analyzer/ExtractExpressionTest.java |    4 +-
 .../relational/analyzer/InsertIntoQueryTest.java   |   10 +-
 .../plan/relational/analyzer/JoinTest.java         |   44 +-
 .../analyzer/LimitOffsetPushDownTest.java          |   18 +-
 .../analyzer/PushAggregationThroughUnionTest.java  |    6 +-
 .../analyzer/RowPatternRecognitionTest.java        |   34 +-
 .../plan/relational/analyzer/SortTest.java         |   18 +-
 .../plan/relational/analyzer/SubQueryTest.java     |   16 +-
 .../plan/relational/analyzer/TSBSMetadata.java     |   33 +-
 .../plan/relational/analyzer/TSBSTest.java         |   34 +-
 .../relational/analyzer/TableFunctionTest.java     |   18 +-
 .../plan/relational/analyzer/TestMetadata.java     |   47 +-
 .../plan/relational/analyzer/TestPlanBuilder.java  |   22 +-
 .../plan/relational/analyzer/TestUtils.java        |   21 +-
 .../plan/relational/analyzer/TreeViewTest.java     |    6 +-
 .../relational/planner/CorrelatedSubqueryTest.java |   14 +-
 .../relational/planner/CteMaterializerTest.java    |   16 +-
 .../plan/relational/planner/CteSubqueryTest.java   |    8 +-
 .../plan/relational/planner/ExampleTest.java       |   28 +-
 .../planner/PatternRecognitionNodeSerdeTest.java   |   41 +-
 .../plan/relational/planner/PlanTester.java        |   14 +-
 .../relational/planner/PredicateUtilsTest.java     |    8 +-
 .../planner/UncorrelatedSubqueryTest.java          |   24 +-
 .../AggregationDeviceTableScanMatcher.java         |    8 +-
 .../planner/assertions/AggregationFunction.java    |    6 +-
 .../assertions/AggregationFunctionMatcher.java     |    8 +-
 .../assertions/AggregationFunctionProvider.java    |    8 +-
 .../planner/assertions/AggregationMatcher.java     |    8 +-
 .../planner/assertions/AggregationStepMatcher.java |    6 +-
 .../planner/assertions/AliasMatcher.java           |    8 +-
 .../planner/assertions/AliasPresent.java           |    6 +-
 .../planner/assertions/AsofJoinClauseProvider.java |    6 +-
 .../planner/assertions/AssignUniqueIdMatcher.java  |    8 +-
 .../assertions/BaseStrictSymbolsMatcher.java       |    6 +-
 .../planner/assertions/ColumnReference.java        |   10 +-
 .../planner/assertions/CteScanMatcher.java         |    6 +-
 .../planner/assertions/DeviceTableScanMatcher.java |    4 +-
 .../planner/assertions/EquiJoinClauseProvider.java |    2 +-
 .../planner/assertions/ExchangeNodeMatcher.java    |    8 +-
 .../planner/assertions/ExpressionMatcher.java      |   10 +-
 .../planner/assertions/ExpressionVerifier.java     |  124 +-
 .../planner/assertions/FilterMatcher.java          |    8 +-
 .../planner/assertions/GroupMatcher.java           |    6 +-
 .../assertions/IdentityProjectionMatcher.java      |    6 +-
 .../InformationSchemaTableScanMatcher.java         |    4 +-
 .../relational/planner/assertions/JoinMatcher.java |   10 +-
 .../planner/assertions/LimitMatcher.java           |    8 +-
 .../planner/assertions/MarkDistinctMatcher.java    |    6 +-
 .../relational/planner/assertions/MatchResult.java |    2 +-
 .../relational/planner/assertions/Matcher.java     |    4 +-
 .../planner/assertions/NotPlanNodeMatcher.java     |    4 +-
 .../planner/assertions/OffsetMatcher.java          |    6 +-
 .../planner/assertions/OutputMatcher.java          |    8 +-
 .../relational/planner/assertions/PlanAssert.java  |   10 +-
 .../planner/assertions/PlanMatchPattern.java       |   80 +-
 .../planner/assertions/PlanMatchingVisitor.java    |   14 +-
 .../planner/assertions/PlanNodeMatcher.java        |    4 +-
 .../planner/assertions/PlanTestSymbol.java         |    2 +-
 .../planner/assertions/PredicateMatcher.java       |    4 +-
 .../planner/assertions/RvalueMatcher.java          |    8 +-
 .../planner/assertions/SemiJoinMatcher.java        |    6 +-
 .../relational/planner/assertions/SortMatcher.java |    6 +-
 .../planner/assertions/SpecificationProvider.java  |    6 +-
 .../assertions/StrictAssignedSymbolsMatcher.java   |    8 +-
 .../planner/assertions/StrictSymbolsMatcher.java   |    6 +-
 .../relational/planner/assertions/SymbolAlias.java |    2 +-
 .../planner/assertions/SymbolAliases.java          |    8 +-
 .../assertions/TableFunctionProcessorMatcher.java  |   11 +-
 .../planner/assertions/TableScanMatcher.java       |    8 +-
 .../relational/planner/assertions/TopKMatcher.java |    6 +-
 .../plan/relational/planner/assertions/Util.java   |    4 +-
 .../planner/assertions/WindowFunctionMatcher.java  |   10 +-
 .../informationschema/CurrentQueriesTest.java      |    8 +-
 .../predicate/TablePredicateConversionTest.java    |   14 +-
 .../relational/sql/AstMemoryEstimatorTest.java     |    2 +-
 .../sql/ast/SqlParserErrorHandlerTest.java         |    2 +-
 .../relational/sql/parser/AuthorStatementTest.java |    3 +-
 .../plan/statement/InsertStatementTest.java        |   10 +-
 .../plan/statement/QueryStatementTest.java         |    2 +-
 .../plan/statement/StatementTestUtils.java         |    6 +-
 .../builder/EvaluationDAGBuilderTest.java          |    6 +-
 ...meticAndCompareBinaryColumnTransformerTest.java |   13 +-
 .../binary/LogicBinaryColumnTransformerTest.java   |    5 +-
 .../binary/hmac/HmacMd5ColumnTransformerTest.java  |   12 +-
 .../binary/hmac/HmacSha1ColumnTransformerTest.java |   12 +-
 .../hmac/HmacSha256ColumnTransformerTest.java      |   12 +-
 .../hmac/HmacSha512ColumnTransformerTest.java      |   12 +-
 .../column/ternary/LpadColumnTransformerTest.java  |    5 +-
 .../column/ternary/RpadColumnTransformerTest.java  |    5 +-
 .../column/unary/UnaryColumnTransformerTest.java   |    9 +-
 .../scalar/BlobLengthColumnTransformerTest.java    |    3 +-
 .../column/unary/scalar/DateBinFunctionTest.java   |    2 +-
 .../FromBigEndian32ColumnTransformerTest.java      |    8 +-
 .../FromBigEndian64ColumnTransformerTest.java      |    8 +-
 ...omIEEE754_32BigEndianColumnTransformerTest.java |    8 +-
 ...omIEEE754_64BigEndianColumnTransformerTest.java |    8 +-
 .../FromLittleEndian32ColumnTransformerTest.java   |    8 +-
 .../FromLittleEndian64ColumnTransformerTest.java   |    8 +-
 .../ToBigEndian32ColumnTransformerTest.java        |    6 +-
 .../ToBigEndian64ColumnTransformerTest.java        |    6 +-
 ...ToIEEE754_32BigEndianColumnTransformerTest.java |    6 +-
 ...ToIEEE754_64BigEndianColumnTransformerTest.java |    6 +-
 .../ToLittleEndian32ColumnTransformerTest.java     |    6 +-
 .../ToLittleEndian64ColumnTransformerTest.java     |    6 +-
 .../unary/scalar/ReverseColumnTransformerTest.java |    5 +-
 .../FromBase32ColumnTransformerTest.java           |    8 +-
 .../FromBase64ColumnTransformerTest.java           |    8 +-
 .../FromBase64UrlColumnTransformerTest.java        |    8 +-
 .../ToBase32ColumnTransformerTest.java             |    6 +-
 .../ToBase64ColumnTransformerTest.java             |    6 +-
 .../ToBase64UrlColumnTransformerTest.java          |    6 +-
 .../scalar/hashing/Crc32ColumnTransformerTest.java |    4 +-
 .../scalar/hashing/Md5ColumnTransformerTest.java   |    6 +-
 .../hashing/Murmur3ColumnTransformerTest.java      |    6 +-
 .../scalar/hashing/Sha1ColumnTransformerTest.java  |    6 +-
 .../hashing/Sha256ColumnTransformerTest.java       |    6 +-
 .../hashing/Sha512ColumnTransformerTest.java       |    6 +-
 .../SpookyHashV2_32ColumnTransformerTest.java      |    6 +-
 .../SpookyHashV2_64ColumnTransformerTest.java      |    6 +-
 .../hashing/XxHash64ColumnTransformerTest.java     |    6 +-
 .../hexEncoding/FromHexColumnTransformerTest.java  |    6 +-
 .../hexEncoding/ToHexColumnTransformerTest.java    |    6 +-
 .../transformation/dag/util/BitwiseUtilsTest.java  |   19 +-
 .../ElasticSerializableRowListTest.java            |    7 +-
 .../ElasticSerializableTVListTest.java             |    5 +-
 .../transformation/datastructure/LRUCache.java     |    2 +
 .../datastructure/SerializableRowListTest.java     |    2 +-
 .../datastructure/SerializableTVListTest.java      |    2 +-
 .../DataNodeInternalRPCServiceImplTest.java        |    2 +-
 .../storageengine/dataregion/DataRegionTest.java   |    4 +-
 .../db/storageengine/dataregion/TTLQueryTest.java  |    2 +-
 .../iotdb/db/storageengine/dataregion/TTLTest.java |    4 +-
 ...eCrossSpaceCompactionWithFastPerformerTest.java |    2 +-
 ...sSpaceCompactionWithReadPointPerformerTest.java |    2 +-
 .../InnerSeqCompactionWithFastPerformerTest.java   |    2 +-
 ...nerSeqCompactionWithReadChunkPerformerTest.java |    2 +-
 .../settle/SettleCompactionTaskTest.java           |    1 -
 .../settle/SettleRequestHandlerTest.java           |    2 +-
 .../memtable/AlignedTVListIteratorTest.java        |    2 +-
 .../memtable/MemChunkDeserializeTest.java          |    2 +-
 .../dataregion/memtable/MemTableTestUtils.java     |    2 +-
 .../memtable/NonAlignedTVListIteratorTest.java     |    2 +-
 .../dataregion/memtable/PrimitiveMemTableTest.java |    8 +-
 .../dataregion/memtable/TsFileProcessorTest.java   |    2 +-
 .../dataregion/wal/WALManagerTest.java             |    2 +-
 .../storageengine/dataregion/wal/WALTestUtils.java |    4 +-
 .../wal/allocation/ElasticStrategyTest.java        |    2 +-
 .../wal/allocation/FirstCreateStrategyTest.java    |    2 +-
 .../wal/allocation/RoundRobinStrategyTest.java     |    2 +-
 .../dataregion/wal/buffer/WALBufferCommonTest.java |    4 +-
 .../wal/compression/WALCompressionTest.java        |    2 +-
 .../dataregion/wal/io/WALFileTest.java             |    2 +-
 .../wal/node/ConsensusReqReaderTest.java           |    6 +-
 .../dataregion/wal/node/WALFakeNodeTest.java       |    2 +-
 .../dataregion/wal/node/WALNodeTest.java           |    2 +-
 .../wal/node/WalDeleteOutdatedNewTest.java         |    2 +-
 .../wal/recover/WALRecoverManagerTest.java         |    4 +-
 .../wal/recover/WALRepairWriterTest.java           |    2 +-
 .../wal/recover/file/TsFilePlanRedoerTest.java     |    2 +-
 .../file/UnsealedTsFileRecoverPerformerTest.java   |    2 +-
 .../rescon/memory/TimePartitionManagerTest.java    |    2 +-
 .../db/trigger/executor/TriggerExecuteTest.java    |    2 +-
 .../apache/iotdb/db/utils/DateTimeUtilsTest.java   |  153 +-
 .../apache/iotdb/db/utils/EnvironmentUtils.java    |    2 +-
 .../iotdb/db/utils/ErrorHandlingUtilsTest.java     |    4 +-
 .../org/apache/iotdb/db/utils/MemUtilsTest.java    |    2 +-
 .../org/apache/iotdb/db/utils/SchemaUtilsTest.java |    2 +-
 .../db/utils/TimestampPrecisionUtilsTest.java      |    2 +
 .../iotdb/db/utils/TypeInferenceUtilsTest.java     |    2 +-
 .../db/utils/datastructure/MergeSortHeapTest.java  |    7 +-
 .../apache/iotdb/db/utils/sort/SortUtilTest.java   |   13 +-
 iotdb-core/node-commons/pom.xml                    |   14 +
 .../apache/iotdb/commons/conf/CommonConfig.java    |   79 +
 .../iotdb/commons/exception/SemanticException.java |   41 +
 .../commons/queryengine/common/ConnectionInfo.java |   57 +
 .../iotdb/commons/queryengine/common/NodeRef.java  |   63 +
 .../commons/queryengine/common/SessionInfo.java    |  196 +
 .../commons/queryengine/common/SqlDialect.java     |   61 +
 .../execution/MemoryEstimationHelper.java          |  138 +
 .../aggregation/grouped/UpdateMemory.java          |   32 +
 .../grouped/hash/CombineHashFunction.java          |   37 +
 .../aggregation/grouped/hash/FlatGroupByHash.java  |  210 +
 .../aggregation/grouped/hash/FlatHash.java         |  605 +++
 .../aggregation/grouped/hash/FlatHashStrategy.java |   55 +
 .../aggregation/grouped/hash/GroupByHash.java      |   61 +
 .../aggregation/grouped/hash/HashStrategy.java     |  225 +
 .../aggregation/grouped/hash/MarkDistinctHash.java |   90 +
 .../grouped/hash/NoChannelGroupByHash.java         |   72 +
 .../grouped/hash/VariableWidthData.java            |  197 +
 .../aggregation/grouped/hash/XxHash64.java         |  276 ++
 .../plan/analyze/ITableTypeProvider.java           |   36 +
 .../plan/expression/multi/FunctionType.java        |   28 +
 .../plan/node/CommonPlanNodeDeserializer.java      |  146 +
 .../planner/plan/node/ICoreQueryPlanVisitor.java   |  232 +
 .../planner/plan/node/IPartitionRelatedNode.java   |   26 +
 .../planner/plan/node/IPlanNodeDeserializer.java   |   34 +
 .../plan/node/IPlanNodeDeserializerProvider.java   |   24 +
 .../plan/planner/plan/node/IPlanVisitor.java       |   42 +
 .../plan/planner/plan/node/PlanNode.java           |  217 +
 .../plan/planner/plan/node/PlanNodeId.java         |   83 +
 .../plan/planner/plan/node/PlanNodeType.java       |  259 ++
 .../plan/node/process/MultiChildProcessNode.java   |   85 +
 .../planner/plan/node/process/ProcessNode.java     |   30 +
 .../plan/node/process/SingleChildProcessNode.java  |   92 +
 .../plan/node/process/TwoChildProcessNode.java     |  101 +
 .../plan/planner/plan/node/source/SourceNode.java  |   37 +
 .../plan/planner/plan/parameter/InputLocation.java |   72 +
 .../plan/relational/analyzer/NodeRef.java          |   63 +
 .../plan/relational/function/BoundSignature.java   |  129 +
 .../plan/relational/function/FunctionId.java       |   70 +
 .../plan/relational/function/FunctionKind.java     |   45 +
 .../function/ITableFunctionAINodeService.java      |   28 +
 .../ITableFunctionAINodeServiceProvider.java       |   25 +
 .../relational/function/ITableFunctionFactory.java |   28 +
 .../function/InterpretedFunctionInvoker.java       |   83 +
 .../function/LongVariableConstraint.java           |   64 +
 .../plan/relational/function/OperatorType.java     |   67 +
 .../function/ResolvedFunctionCallBuilder.java      |   58 +
 .../plan/relational/function/Signature.java        |  213 +
 .../function/TableBuiltinTableFunction.java        |   97 +
 .../relational/function/TableFunctionFactory.java  |   39 +
 .../function/TypeVariableConstraint.java           |  192 +
 .../function/arithmetic/AdditionResolver.java      |   97 +
 .../function/arithmetic/DivisionResolver.java      |   81 +
 .../function/arithmetic/ModulusResolver.java       |   81 +
 .../arithmetic/MultiplicationResolver.java         |   81 +
 .../function/arithmetic/SubtractionResolver.java   |   89 +
 .../function/tvf/ClassifyTableFunction.java        |  379 ++
 .../function/tvf/ForecastTableFunction.java        |  541 +++
 .../function/tvf/PatternMatchTableFunction.java    |  283 ++
 .../function/tvf/TableFunctionUtils.java           |   74 +
 .../relational/function/tvf/match/MatchConfig.java |   34 +
 .../function/tvf/match/QetchAlgorithm.java         |  683 +++
 .../function/tvf/match/model/MatchState.java       |  233 +
 .../function/tvf/match/model/PatternSegment.java   |  285 ++
 .../relational/function/tvf/match/model/Point.java |   42 +
 .../function/tvf/match/model/RegexMatchState.java  |  388 ++
 .../function/tvf/match/model/Section.java          |  238 ++
 .../plan/relational/metadata/ColumnMetadata.java   |  213 +
 .../plan/relational/metadata/ColumnSchema.java     |  188 +
 .../relational/metadata/FunctionNullability.java   |  118 +
 .../plan/relational/metadata/ResolvedFunction.java |  145 +
 .../plan/relational/metadata/TableSchema.java      |  239 ++
 .../plan/relational/planner/Assignments.java       |  261 ++
 .../planner/DataOrganizationSpecification.java     |  106 +
 .../plan/relational/planner/OrderingScheme.java    |  137 +
 .../plan/relational/planner/SortOrder.java         |   50 +
 .../plan/relational/planner/Symbol.java            |  100 +
 .../planner/iterative/GroupReference.java          |   93 +
 .../relational/planner/node/AggregationNode.java   |  734 ++++
 .../plan/relational/planner/node/ApplyNode.java    |  247 ++
 .../relational/planner/node/AssignUniqueId.java    |   98 +
 .../plan/relational/planner/node/CollectNode.java  |  132 +
 .../planner/node/CorrelatedJoinNode.java           |  171 +
 .../planner/node/EnforceSingleRowNode.java         |   87 +
 .../plan/relational/planner/node/ExceptNode.java   |  100 +
 .../plan/relational/planner/node/FillNode.java     |   51 +
 .../plan/relational/planner/node/FilterNode.java   |  116 +
 .../plan/relational/planner/node/GapFillNode.java  |  231 +
 .../plan/relational/planner/node/GroupNode.java    |  105 +
 .../relational/planner/node/IntersectNode.java     |   99 +
 .../plan/relational/planner/node/JoinNode.java     |  532 +++
 .../plan/relational/planner/node/LimitNode.java    |  134 +
 .../relational/planner/node/LinearFillNode.java    |  147 +
 .../relational/planner/node/MarkDistinctNode.java  |  163 +
 .../plan/relational/planner/node/Measure.java      |   95 +
 .../relational/planner/node/MergeSortNode.java     |  142 +
 .../plan/relational/planner/node/OffsetNode.java   |  112 +
 .../plan/relational/planner/node/OutputNode.java   |  155 +
 .../planner/node/PatternRecognitionNode.java       |  385 ++
 .../relational/planner/node/PreviousFillNode.java  |  194 +
 .../plan/relational/planner/node/ProjectNode.java  |  131 +
 .../relational/planner/node/RowNumberNode.java     |  216 +
 .../plan/relational/planner/node/RowsPerMatch.java |  127 +
 .../plan/relational/planner/node/SemiJoinNode.java |  182 +
 .../relational/planner/node/SetOperationNode.java  |  138 +
 .../relational/planner/node/SkipToPosition.java    |   47 +
 .../plan/relational/planner/node/SortNode.java     |  132 +
 .../relational/planner/node/StreamSortNode.java    |  121 +
 .../relational/planner/node/TableFunctionNode.java |  372 ++
 .../planner/node/TableFunctionProcessorNode.java   |  296 ++
 .../plan/relational/planner/node/TopKNode.java     |  174 +
 .../relational/planner/node/TopKRankingNode.java   |  209 +
 .../plan/relational/planner/node/UnionNode.java    |  127 +
 .../relational/planner/node/ValueFillNode.java     |  107 +
 .../plan/relational/planner/node/ValuesNode.java   |  237 +
 .../plan/relational/planner/node/WindowNode.java   |  607 +++
 .../planner/rowpattern/AggregationLabelSet.java    |  100 +
 .../rowpattern/AggregationValuePointer.java        |  147 +
 .../planner/rowpattern/ClassifierValuePointer.java |   70 +
 .../rowpattern/ExpressionAndValuePointers.java     |  250 ++
 .../planner/rowpattern/IrAlternation.java          |   99 +
 .../relational/planner/rowpattern/IrAnchor.java    |   87 +
 .../planner/rowpattern/IrConcatenation.java        |  100 +
 .../relational/planner/rowpattern/IrEmpty.java     |   62 +
 .../relational/planner/rowpattern/IrExclusion.java |   79 +
 .../relational/planner/rowpattern/IrLabel.java     |   85 +
 .../rowpattern/IrPatternAlternationOptimizer.java  |  141 +
 .../planner/rowpattern/IrPermutation.java          |   96 +
 .../planner/rowpattern/IrQuantified.java           |   88 +
 .../planner/rowpattern/IrQuantifier.java           |  126 +
 .../planner/rowpattern/IrRowPattern.java           |  119 +
 .../planner/rowpattern/IrRowPatternFlattener.java  |  206 +
 .../planner/rowpattern/IrRowPatternVisitor.java    |   68 +
 .../planner/rowpattern/LogicalIndexPointer.java    |  154 +
 .../rowpattern/MatchNumberValuePointer.java        |   45 +
 .../relational/planner/rowpattern/Patterns.java    |   83 +
 .../planner/rowpattern/ScalarValuePointer.java     |   82 +
 .../planner/rowpattern/ValuePointer.java           |   22 +
 .../plan/relational/security/Identity.java         |   51 +
 .../plan/relational/sql/ast/AliasedRelation.java   |  126 +
 .../plan/relational/sql/ast/AllColumns.java        |  143 +
 .../plan/relational/sql/ast/AllRows.java           |   76 +
 .../plan/relational/sql/ast/AnchorPattern.java     |   94 +
 .../sql/ast/ArithmeticBinaryExpression.java        |  154 +
 .../sql/ast/ArithmeticUnaryExpression.java         |  155 +
 .../sql/ast/AstMemoryEstimationHelper.java         |  123 +
 .../plan/relational/sql/ast/BetweenPredicate.java  |  141 +
 .../plan/relational/sql/ast/BinaryLiteral.java     |  156 +
 .../plan/relational/sql/ast/BooleanLiteral.java    |  122 +
 .../queryengine/plan/relational/sql/ast/Cast.java  |  171 +
 .../relational/sql/ast/CoalesceExpression.java     |  131 +
 .../plan/relational/sql/ast/Columns.java           |  107 +
 .../relational/sql/ast/CommonQueryAstVisitor.java  |  476 +++
 .../relational/sql/ast/ComparisonExpression.java   |  225 +
 .../plan/relational/sql/ast/CurrentDatabase.java   |   86 +
 .../plan/relational/sql/ast/CurrentTime.java       |  127 +
 .../plan/relational/sql/ast/CurrentUser.java       |   86 +
 .../plan/relational/sql/ast/DataType.java          |   28 +
 .../plan/relational/sql/ast/DataTypeParameter.java |   34 +
 .../plan/relational/sql/ast/DecimalLiteral.java    |  114 +
 .../relational/sql/ast/DereferenceExpression.java  |  164 +
 .../plan/relational/sql/ast/DoubleLiteral.java     |  121 +
 .../plan/relational/sql/ast/EmptyPattern.java      |   79 +
 .../plan/relational/sql/ast/Except.java            |  119 +
 .../plan/relational/sql/ast/ExcludedPattern.java   |   90 +
 .../plan/relational/sql/ast/ExistsPredicate.java   |   92 +
 .../plan/relational/sql/ast/Expression.java        |  182 +
 .../plan/relational/sql/ast/Extract.java           |  150 +
 .../plan/relational/sql/ast/FieldReference.java    |   91 +
 .../queryengine/plan/relational/sql/ast/Fill.java  |  184 +
 .../plan/relational/sql/ast/FloatLiteral.java      |  117 +
 .../plan/relational/sql/ast/FrameBound.java        |  152 +
 .../plan/relational/sql/ast/FunctionCall.java      |  358 ++
 .../plan/relational/sql/ast/GenericDataType.java   |  123 +
 .../plan/relational/sql/ast/GenericLiteral.java    |  144 +
 .../plan/relational/sql/ast/GroupBy.java           |  111 +
 .../plan/relational/sql/ast/GroupingElement.java   |   36 +
 .../plan/relational/sql/ast/GroupingSets.java      |  128 +
 .../plan/relational/sql/ast/IAstVisitor.java       |   22 +
 .../plan/relational/sql/ast/Identifier.java        |  189 +
 .../plan/relational/sql/ast/IfExpression.java      |  119 +
 .../plan/relational/sql/ast/InListExpression.java  |  122 +
 .../plan/relational/sql/ast/InPredicate.java       |  118 +
 .../plan/relational/sql/ast/Intersect.java         |  103 +
 .../relational/sql/ast/IsNotNullPredicate.java     |  108 +
 .../plan/relational/sql/ast/IsNullPredicate.java   |  108 +
 .../queryengine/plan/relational/sql/ast/Join.java  |  178 +
 .../plan/relational/sql/ast/JoinCriteria.java      |   39 +
 .../plan/relational/sql/ast/JoinOn.java            |   84 +
 .../plan/relational/sql/ast/JoinUsing.java         |   81 +
 .../plan/relational/sql/ast/LikePredicate.java     |  163 +
 .../queryengine/plan/relational/sql/ast/Limit.java |  107 +
 .../plan/relational/sql/ast/Literal.java           |   47 +
 .../plan/relational/sql/ast/LogicalExpression.java |  159 +
 .../plan/relational/sql/ast/LongLiteral.java       |  148 +
 .../plan/relational/sql/ast/MeasureDefinition.java |  102 +
 .../plan/relational/sql/ast/NaturalJoin.java       |   60 +
 .../queryengine/plan/relational/sql/ast/Node.java  |   83 +
 .../plan/relational/sql/ast/NodeLocation.java      |   68 +
 .../plan/relational/sql/ast/NotExpression.java     |  108 +
 .../plan/relational/sql/ast/NullIfExpression.java  |   99 +
 .../plan/relational/sql/ast/NullLiteral.java       |   92 +
 .../plan/relational/sql/ast/NumericParameter.java  |   99 +
 .../plan/relational/sql/ast/Offset.java            |  105 +
 .../relational/sql/ast/OneOrMoreQuantifier.java    |   43 +
 .../plan/relational/sql/ast/OrderBy.java           |  129 +
 .../plan/relational/sql/ast/Parameter.java         |   93 +
 .../relational/sql/ast/PatternAlternation.java     |   92 +
 .../relational/sql/ast/PatternConcatenation.java   |   92 +
 .../relational/sql/ast/PatternPermutation.java     |   92 +
 .../plan/relational/sql/ast/PatternQuantifier.java |   82 +
 .../sql/ast/PatternRecognitionRelation.java        |  227 +
 .../plan/relational/sql/ast/PatternVariable.java   |   90 +
 .../plan/relational/sql/ast/ProcessingMode.java    |   88 +
 .../plan/relational/sql/ast/QualifiedName.java     |  247 ++
 .../sql/ast/QuantifiedComparisonExpression.java    |  137 +
 .../plan/relational/sql/ast/QuantifiedPattern.java |  102 +
 .../queryengine/plan/relational/sql/ast/Query.java |  211 +
 .../plan/relational/sql/ast/QueryBody.java         |   34 +
 .../relational/sql/ast/QuerySpecification.java     |  210 +
 .../plan/relational/sql/ast/RangeQuantifier.java   |  107 +
 .../plan/relational/sql/ast/Relation.java          |   32 +
 .../queryengine/plan/relational/sql/ast/Row.java   |  121 +
 .../plan/relational/sql/ast/RowPattern.java        |   31 +
 .../relational/sql/ast/SearchedCaseExpression.java |  162 +
 .../plan/relational/sql/ast/Select.java            |  110 +
 .../plan/relational/sql/ast/SelectItem.java        |   27 +
 .../plan/relational/sql/ast/SetOperation.java      |   42 +
 .../relational/sql/ast/SimpleCaseExpression.java   |  181 +
 .../plan/relational/sql/ast/SimpleGroupBy.java     |  101 +
 .../plan/relational/sql/ast/SingleColumn.java      |  154 +
 .../plan/relational/sql/ast/SkipTo.java            |  145 +
 .../plan/relational/sql/ast/SortItem.java          |  157 +
 .../plan/relational/sql/ast/Statement.java         |   68 +
 .../plan/relational/sql/ast/StringLiteral.java     |  123 +
 .../relational/sql/ast/SubqueryExpression.java     |   91 +
 .../plan/relational/sql/ast/SubsetDefinition.java  |  104 +
 .../plan/relational/sql/ast/SymbolReference.java   |   98 +
 .../queryengine/plan/relational/sql/ast/Table.java |  100 +
 .../relational/sql/ast/TableExpressionType.java    |   67 +
 .../relational/sql/ast/TableFunctionArgument.java  |  106 +
 .../sql/ast/TableFunctionInvocation.java           |  106 +
 .../sql/ast/TableFunctionTableArgument.java        |  138 +
 .../plan/relational/sql/ast/TableSubquery.java     |   97 +
 .../relational/sql/ast/TimeDurationLiteral.java    |  109 +
 .../queryengine/plan/relational/sql/ast/Trim.java  |  153 +
 .../plan/relational/sql/ast/TypeParameter.java     |   90 +
 .../queryengine/plan/relational/sql/ast/Union.java |  103 +
 .../plan/relational/sql/ast/Values.java            |   94 +
 .../relational/sql/ast/VariableDefinition.java     |  102 +
 .../plan/relational/sql/ast/WhenClause.java        |  124 +
 .../plan/relational/sql/ast/Window.java            |   30 +
 .../plan/relational/sql/ast/WindowDefinition.java  |  101 +
 .../plan/relational/sql/ast/WindowFrame.java       |  157 +
 .../plan/relational/sql/ast/WindowReference.java   |  108 +
 .../relational/sql/ast/WindowSpecification.java    |  224 +
 .../queryengine/plan/relational/sql/ast/With.java  |  111 +
 .../plan/relational/sql/ast/WithQuery.java         |  160 +
 .../relational/sql/ast/ZeroOrMoreQuantifier.java   |   43 +
 .../relational/sql/ast/ZeroOrOneQuantifier.java    |   43 +
 .../sql/parser/CaseInsensitiveStream.java          |   85 +
 .../relational/sql/parser/ParsingException.java    |   69 +
 .../sql/util/CommonQuerySqlFormatter.java          |  705 +++
 .../relational/sql/util/ExpressionFormatter.java   |  795 ++++
 .../relational/sql/util/ReservedIdentifiers.java   |   84 +
 .../relational/sql/util/RowPatternFormatter.java   |  143 +
 .../plan/relational/type/InternalTypeManager.java  |  147 +
 .../plan/relational/type/NamedTypeSignature.java   |   79 +
 .../plan/relational/type/ParameterKind.java        |   27 +
 .../plan/relational/type/RowFieldName.java         |   63 +
 .../plan/relational/type/StandardTypes.java        |   55 +
 .../queryengine/plan/relational/type/TypeId.java   |   66 +
 .../plan/relational/type/TypeManager.java          |   38 +
 .../relational/type/TypeNotFoundException.java     |   43 +
 .../plan/relational/type/TypeSignature.java        |  207 +
 .../relational/type/TypeSignatureParameter.java    |  175 +
 .../relational/type/TypeSignatureTranslator.java   |  113 +
 .../relational/utils/ResultColumnAppender.java     |  145 +
 .../plan/relational/utils/TypeUtil.java            |  513 +++
 .../plan/statement/component/FillPolicy.java       |   33 +
 .../plan/udf/BuiltinAggregationFunction.java       |  142 +
 .../plan/udf/BuiltinScalarFunction.java            |   67 +
 .../udf/BuiltinTimeSeriesGeneratingFunction.java   |  180 +
 .../queryengine/plan/udf/TableUDFUtils.java        |   93 +
 .../queryengine/plan/udf/UDFManagementService.java |  296 ++
 .../commons/queryengine/plan/udf/UDTFForecast.java |  259 ++
 .../commons/queryengine/utils/DateTimeUtils.java   |  732 ++++
 .../queryengine/utils/TimestampPrecisionUtils.java |  100 +
 .../queryengine/utils/cte/CteDataStore.java        |  109 +
 .../iotdb/commons/request/IConsensusRequest.java   |   47 +
 iotdb-core/pom.xml                                 |    1 +
 2958 files changed, 126597 insertions(+), 123391 deletions(-)

diff --git a/external-service-impl/mqtt/src/main/java/org/apache/iotdb/mqtt/MPPPublishHandler.java b/external-service-impl/mqtt/src/main/java/org/apache/iotdb/mqtt/MPPPublishHandler.java
index 395447e9734..6e8ce1fd7cb 100644
--- a/external-service-impl/mqtt/src/main/java/org/apache/iotdb/mqtt/MPPPublishHandler.java
+++ b/external-service-impl/mqtt/src/main/java/org/apache/iotdb/mqtt/MPPPublishHandler.java
@@ -21,11 +21,12 @@ package org.apache.iotdb.mqtt;
 import org.apache.iotdb.common.rpc.thrift.TSStatus;
 import org.apache.iotdb.commons.conf.IoTDBConstant.ClientVersion;
 import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.commons.queryengine.common.SqlDialect;
+import org.apache.iotdb.commons.queryengine.utils.TimestampPrecisionUtils;
 import org.apache.iotdb.commons.schema.table.column.TsTableColumnCategory;
 import org.apache.iotdb.db.auth.AuthorityChecker;
 import org.apache.iotdb.db.conf.IoTDBConfig;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
-import org.apache.iotdb.db.protocol.session.IClientSession;
 import org.apache.iotdb.db.protocol.session.MqttClientSession;
 import org.apache.iotdb.db.protocol.session.SessionManager;
 import org.apache.iotdb.db.queryengine.plan.Coordinator;
@@ -42,7 +43,6 @@ import org.apache.iotdb.db.queryengine.plan.relational.sql.parser.SqlParser;
 import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertRowStatement;
 import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertTabletStatement;
 import org.apache.iotdb.db.utils.CommonUtils;
-import org.apache.iotdb.db.utils.TimestampPrecisionUtils;
 import org.apache.iotdb.rpc.TSStatusCode;
 import org.apache.iotdb.service.rpc.thrift.TSProtocolVersion;
 
@@ -105,7 +105,7 @@ public class MPPPublishHandler extends AbstractInterceptHandler {
           ZoneId.systemDefault().toString(),
           TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V3,
           ClientVersion.V_1_0,
-          useTableInsert ? IClientSession.SqlDialect.TABLE : IClientSession.SqlDialect.TREE);
+          useTableInsert ? SqlDialect.TABLE : SqlDialect.TREE);
       sessionManager.registerSessionForMqtt(session);
       clientIdToSessionMap.put(msg.getClientID(), session);
     }
@@ -173,7 +173,7 @@ public class MPPPublishHandler extends AbstractInterceptHandler {
       TimestampPrecisionUtils.checkTimestampPrecision(message.getTimestamp());
       InsertTabletStatement insertTabletStatement = constructInsertTabletStatement(message);
       session.setDatabaseName(message.getDatabase().toLowerCase());
-      session.setSqlDialect(IClientSession.SqlDialect.TABLE);
+      session.setSqlDialect(SqlDialect.TABLE);
       long queryId = sessionManager.requestQueryId();
       SqlParser relationSqlParser = new SqlParser();
       Metadata metadata = LocalExecutionPlanner.getInstance().metadata;
diff --git a/external-service-impl/rest/pom.xml b/external-service-impl/rest/pom.xml
index 63b2443a8e0..9c3473a01c5 100644
--- a/external-service-impl/rest/pom.xml
+++ b/external-service-impl/rest/pom.xml
@@ -116,6 +116,12 @@
             <version>2.0.7-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.iotdb</groupId>
+            <artifactId>calc-commons</artifactId>
+            <version>2.0.7-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.iotdb</groupId>
             <artifactId>iotdb-session</artifactId>
diff --git a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/ExceptionHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/ExceptionHandler.java
index 61e64465a06..57d78a527dc 100644
--- a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/ExceptionHandler.java
+++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/ExceptionHandler.java
@@ -17,17 +17,17 @@
 
 package org.apache.iotdb.rest.protocol.table.v1.handler;
 
+import org.apache.iotdb.calc.exception.QueryProcessException;
 import org.apache.iotdb.commons.auth.AuthException;
 import org.apache.iotdb.commons.exception.IllegalPathException;
 import org.apache.iotdb.commons.exception.IoTDBException;
 import org.apache.iotdb.commons.exception.MetadataException;
+import org.apache.iotdb.commons.exception.SemanticException;
 import org.apache.iotdb.commons.exception.auth.AccessDeniedException;
+import org.apache.iotdb.commons.queryengine.plan.relational.sql.parser.ParsingException;
 import org.apache.iotdb.db.exception.StorageEngineException;
 import org.apache.iotdb.db.exception.metadata.DatabaseNotSetException;
-import org.apache.iotdb.db.exception.query.QueryProcessException;
-import org.apache.iotdb.db.exception.sql.SemanticException;
 import org.apache.iotdb.db.exception.sql.StatementAnalyzeException;
-import org.apache.iotdb.db.queryengine.plan.relational.sql.parser.ParsingException;
 import org.apache.iotdb.rest.protocol.model.ExecutionStatus;
 import org.apache.iotdb.rpc.TSStatusCode;
 
diff --git a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/ExecuteStatementHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/ExecuteStatementHandler.java
index 4fa749dd567..5ec75c0d4ce 100644
--- a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/ExecuteStatementHandler.java
+++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/ExecuteStatementHandler.java
@@ -17,11 +17,12 @@
 
 package org.apache.iotdb.rest.protocol.table.v1.handler;
 
+import org.apache.iotdb.commons.queryengine.plan.relational.sql.ast.Query;
+import org.apache.iotdb.commons.queryengine.plan.relational.sql.ast.Statement;
 import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.CountDevice;
 import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.DescribeTable;
 import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Explain;
 import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ExplainAnalyze;
-import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Query;
 import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.RelationalAuthorStatement;
 import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowAIDevices;
 import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowAINodes;
@@ -49,7 +50,6 @@ import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowTables;
 import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowTopics;
 import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowVariables;
 import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowVersion;
-import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Statement;
 import org.apache.iotdb.db.queryengine.plan.relational.type.AuthorRType;
 
 import java.util.HashSet;
diff --git a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/QueryDataSetHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/QueryDataSetHandler.java
index ec22f478b8b..6aa4d028cec 100644
--- a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/QueryDataSetHandler.java
+++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/QueryDataSetHandler.java
@@ -18,10 +18,10 @@
 package org.apache.iotdb.rest.protocol.table.v1.handler;
 
 import org.apache.iotdb.commons.exception.IoTDBException;
+import org.apache.iotdb.commons.queryengine.plan.relational.sql.ast.Query;
+import org.apache.iotdb.commons.queryengine.plan.relational.sql.ast.Statement;
 import org.apache.iotdb.db.queryengine.common.header.DatasetHeader;
 import org.apache.iotdb.db.queryengine.plan.execution.IQueryExecution;
-import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Query;
-import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Statement;
 import org.apache.iotdb.rest.protocol.model.ExecutionStatus;
 import org.apache.iotdb.rest.protocol.table.v1.model.QueryDataSet;
 import org.apache.iotdb.rpc.TSStatusCode;
diff --git a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/StatementConstructionHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/StatementConstructionHandler.java
index b7f712c41f7..e4f9c23c69a 100644
--- a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/StatementConstructionHandler.java
+++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/StatementConstructionHandler.java
@@ -19,10 +19,10 @@ package org.apache.iotdb.rest.protocol.table.v1.handler;
 
 import org.apache.iotdb.commons.exception.IllegalPathException;
 import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.commons.queryengine.utils.TimestampPrecisionUtils;
 import org.apache.iotdb.commons.schema.table.column.TsTableColumnCategory;
 import org.apache.iotdb.db.exception.WriteProcessRejectException;
 import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertTabletStatement;
-import org.apache.iotdb.db.utils.TimestampPrecisionUtils;
 import org.apache.iotdb.rest.protocol.table.v1.model.InsertTabletRequest;
 
 import org.apache.tsfile.enums.ColumnCategory;
diff --git a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/impl/RestApiServiceImpl.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/impl/RestApiServiceImpl.java
index e66cb88a6e1..2d0a363c339 100644
--- a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/impl/RestApiServiceImpl.java
+++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/impl/RestApiServiceImpl.java
@@ -18,6 +18,8 @@
 package org.apache.iotdb.rest.protocol.table.v1.impl;
 
 import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.queryengine.common.SqlDialect;
+import org.apache.iotdb.commons.queryengine.plan.relational.sql.ast.Statement;
 import org.apache.iotdb.db.conf.IoTDBConfig;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor;
@@ -31,7 +33,6 @@ import org.apache.iotdb.db.queryengine.plan.execution.IQueryExecution;
 import org.apache.iotdb.db.queryengine.plan.planner.LocalExecutionPlanner;
 import org.apache.iotdb.db.queryengine.plan.relational.metadata.Metadata;
 import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Insert;
-import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Statement;
 import org.apache.iotdb.db.queryengine.plan.relational.sql.parser.SqlParser;
 import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertTabletStatement;
 import org.apache.iotdb.db.utils.CommonUtils;
@@ -155,7 +156,7 @@ public class RestApiServiceImpl extends RestApiService {
           StatementConstructionHandler.constructInsertTabletStatement(insertTabletRequest);
       IClientSession clientSession = SESSION_MANAGER.getCurrSession();
       clientSession.setDatabaseName(insertTabletRequest.getDatabase());
-      clientSession.setSqlDialect(IClientSession.SqlDialect.TABLE);
+      clientSession.setSqlDialect(SqlDialect.TABLE);
       queryId = SESSION_MANAGER.requestQueryId();
       Metadata metadata = LocalExecutionPlanner.getInstance().metadata;
 
@@ -285,7 +286,7 @@ public class RestApiServiceImpl extends RestApiService {
       clientSession.setDatabaseName(sql.getDatabase());
     }
 
-    clientSession.setSqlDialect(IClientSession.SqlDialect.TABLE);
+    clientSession.setSqlDialect(SqlDialect.TABLE);
     return relationSqlParser.createStatement(
         sql.getSql(), clientSession.getZoneId(), clientSession);
   }
diff --git a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/ExceptionHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/ExceptionHandler.java
index 6edcb57ab4d..761b01d7c6d 100644
--- a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/ExceptionHandler.java
+++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/ExceptionHandler.java
@@ -17,15 +17,15 @@
 
 package org.apache.iotdb.rest.protocol.v1.handler;
 
+import org.apache.iotdb.calc.exception.QueryProcessException;
 import org.apache.iotdb.commons.auth.AuthException;
 import org.apache.iotdb.commons.exception.IllegalPathException;
 import org.apache.iotdb.commons.exception.IoTDBException;
 import org.apache.iotdb.commons.exception.MetadataException;
+import org.apache.iotdb.commons.exception.SemanticException;
 import org.apache.iotdb.commons.exception.auth.AccessDeniedException;
 import org.apache.iotdb.db.exception.StorageEngineException;
 import org.apache.iotdb.db.exception.metadata.DatabaseNotSetException;
-import org.apache.iotdb.db.exception.query.QueryProcessException;
-import org.apache.iotdb.db.exception.sql.SemanticException;
 import org.apache.iotdb.db.exception.sql.StatementAnalyzeException;
 import org.apache.iotdb.rest.protocol.v1.model.ExecutionStatus;
 import org.apache.iotdb.rpc.TSStatusCode;
diff --git a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/StatementConstructionHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/StatementConstructionHandler.java
index 65ec7a966f1..74f679ec611 100644
--- a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/StatementConstructionHandler.java
+++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/StatementConstructionHandler.java
@@ -18,11 +18,11 @@
 package org.apache.iotdb.rest.protocol.v1.handler;
 
 import org.apache.iotdb.commons.exception.MetadataException;
+import org.apache.iotdb.commons.queryengine.utils.TimestampPrecisionUtils;
 import org.apache.iotdb.commons.utils.PathUtils;
 import org.apache.iotdb.db.exception.WriteProcessRejectException;
 import org.apache.iotdb.db.queryengine.plan.analyze.cache.schema.DataNodeDevicePathCache;
 import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertTabletStatement;
-import org.apache.iotdb.db.utils.TimestampPrecisionUtils;
 import org.apache.iotdb.rest.protocol.v1.model.InsertTabletRequest;
 
 import org.apache.tsfile.enums.TSDataType;
diff --git a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/ExceptionHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/ExceptionHandler.java
index 931ec0cec00..2a5d1d4416a 100644
--- a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/ExceptionHandler.java
+++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/ExceptionHandler.java
@@ -17,15 +17,15 @@
 
 package org.apache.iotdb.rest.protocol.v2.handler;
 
+import org.apache.iotdb.calc.exception.QueryProcessException;
 import org.apache.iotdb.commons.auth.AuthException;
 import org.apache.iotdb.commons.exception.IllegalPathException;
 import org.apache.iotdb.commons.exception.IoTDBException;
 import org.apache.iotdb.commons.exception.MetadataException;
+import org.apache.iotdb.commons.exception.SemanticException;
 import org.apache.iotdb.commons.exception.auth.AccessDeniedException;
 import org.apache.iotdb.db.exception.StorageEngineException;
 import org.apache.iotdb.db.exception.metadata.DatabaseNotSetException;
-import org.apache.iotdb.db.exception.query.QueryProcessException;
-import org.apache.iotdb.db.exception.sql.SemanticException;
 import org.apache.iotdb.db.exception.sql.StatementAnalyzeException;
 import org.apache.iotdb.rest.protocol.model.ExecutionStatus;
 import org.apache.iotdb.rpc.TSStatusCode;
diff --git a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/StatementConstructionHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/StatementConstructionHandler.java
index 6668244e9e4..729517bf500 100644
--- a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/StatementConstructionHandler.java
+++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/StatementConstructionHandler.java
@@ -18,6 +18,7 @@
 package org.apache.iotdb.rest.protocol.v2.handler;
 
 import org.apache.iotdb.commons.exception.MetadataException;
+import org.apache.iotdb.commons.queryengine.utils.TimestampPrecisionUtils;
 import org.apache.iotdb.commons.utils.PathUtils;
 import org.apache.iotdb.db.exception.WriteProcessRejectException;
 import org.apache.iotdb.db.exception.metadata.DataTypeMismatchException;
@@ -25,7 +26,6 @@ import org.apache.iotdb.db.queryengine.plan.analyze.cache.schema.DataNodeDeviceP
 import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertRowStatement;
 import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertRowsStatement;
 import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertTabletStatement;
-import org.apache.iotdb.db.utils.TimestampPrecisionUtils;
 import org.apache.iotdb.rest.protocol.utils.InsertRowDataUtils;
 import org.apache.iotdb.rest.protocol.v2.model.InsertRecordsRequest;
 import org.apache.iotdb.rest.protocol.v2.model.InsertTabletRequest;
diff --git a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/impl/RestApiServiceImpl.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/impl/RestApiServiceImpl.java
index e0ac81ee92f..2f39d6cc79d 100644
--- a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/impl/RestApiServiceImpl.java
+++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/impl/RestApiServiceImpl.java
@@ -19,13 +19,13 @@ package org.apache.iotdb.rest.protocol.v2.impl;
 
 import org.apache.iotdb.common.rpc.thrift.TSStatus;
 import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.commons.queryengine.common.SessionInfo;
 import org.apache.iotdb.db.conf.IoTDBConfig;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor;
 import org.apache.iotdb.db.protocol.session.IClientSession;
 import org.apache.iotdb.db.protocol.session.SessionManager;
 import org.apache.iotdb.db.protocol.thrift.OperationType;
-import org.apache.iotdb.db.queryengine.common.SessionInfo;
 import org.apache.iotdb.db.queryengine.plan.Coordinator;
 import org.apache.iotdb.db.queryengine.plan.analyze.ClusterPartitionFetcher;
 import org.apache.iotdb.db.queryengine.plan.analyze.IPartitionFetcher;
diff --git a/integration-test/pom.xml b/integration-test/pom.xml
index 072bc905caa..c61509ed2c8 100644
--- a/integration-test/pom.xml
+++ b/integration-test/pom.xml
@@ -129,6 +129,11 @@
             <artifactId>node-commons</artifactId>
             <version>2.0.7-SNAPSHOT</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.iotdb</groupId>
+            <artifactId>calc-commons</artifactId>
+            <version>2.0.7-SNAPSHOT</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.iotdb</groupId>
             <artifactId>iotdb-thrift-commons</artifactId>
diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/EnvUtils.java b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/EnvUtils.java
index faa593fb57c..51fd05d8eaf 100644
--- a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/EnvUtils.java
+++ b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/EnvUtils.java
@@ -31,11 +31,11 @@ import java.util.Map;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
+import static org.apache.iotdb.commons.queryengine.utils.DateTimeUtils.convertLongToDate;
 import static org.apache.iotdb.consensus.ConsensusFactory.IOT_CONSENSUS;
 import static org.apache.iotdb.consensus.ConsensusFactory.IOT_CONSENSUS_V2;
 import static org.apache.iotdb.consensus.ConsensusFactory.RATIS_CONSENSUS;
 import static org.apache.iotdb.consensus.ConsensusFactory.SIMPLE_CONSENSUS;
-import static org.apache.iotdb.db.utils.DateTimeUtils.convertLongToDate;
 import static org.apache.iotdb.it.env.cluster.ClusterConstant.CLUSTER_CONFIGURATIONS;
 import static org.apache.iotdb.it.env.cluster.ClusterConstant.DEFAULT_CONFIG_NODE_NUM;
 import static org.apache.iotdb.it.env.cluster.ClusterConstant.DEFAULT_DATA_NODE_NUM;
diff --git a/integration-test/src/main/java/org/apache/iotdb/itbase/constant/BuiltinAggregationFunctionEnum.java b/integration-test/src/main/java/org/apache/iotdb/itbase/constant/BuiltinAggregationFunctionEnum.java
index 85721cfb7a1..15c8a532b2b 100644
--- a/integration-test/src/main/java/org/apache/iotdb/itbase/constant/BuiltinAggregationFunctionEnum.java
+++ b/integration-test/src/main/java/org/apache/iotdb/itbase/constant/BuiltinAggregationFunctionEnum.java
@@ -19,6 +19,8 @@
 
 package org.apache.iotdb.itbase.constant;
 
+import org.apache.iotdb.commons.queryengine.plan.udf.BuiltinAggregationFunction;
+
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
@@ -56,11 +58,8 @@ public enum BuiltinAggregationFunctionEnum {
 
   private static final Set<String> NATIVE_FUNCTION_NAMES =
       new HashSet<>(
-          Arrays.stream(
-                  org.apache.iotdb.db.queryengine.plan.udf.BuiltinAggregationFunction.values())
-              .map(
-                  org.apache.iotdb.db.queryengine.plan.udf.BuiltinAggregationFunction
-                      ::getFunctionName)
+          Arrays.stream(BuiltinAggregationFunction.values())
+              .map(BuiltinAggregationFunction::getFunctionName)
               .collect(Collectors.toList()));
 
   public static Set<String> getNativeFunctionNames() {
diff --git a/integration-test/src/test/java/org/apache/iotdb/confignode/it/partition/IoTDBTimePartitionIT.java b/integration-test/src/test/java/org/apache/iotdb/confignode/it/partition/IoTDBTimePartitionIT.java
index 469d6974cb5..470e68de651 100644
--- a/integration-test/src/test/java/org/apache/iotdb/confignode/it/partition/IoTDBTimePartitionIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/confignode/it/partition/IoTDBTimePartitionIT.java
@@ -19,6 +19,7 @@
 
 package org.apache.iotdb.confignode.it.partition;
 
+import org.apache.iotdb.calc.utils.constant.SqlConstant;
 import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient;
 import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.commons.schema.SchemaConstant;
@@ -28,7 +29,6 @@ import org.apache.iotdb.confignode.rpc.thrift.TGetDatabaseReq;
 import org.apache.iotdb.confignode.rpc.thrift.TShowDatabaseResp;
 import org.apache.iotdb.consensus.ConsensusFactory;
 import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowDatabaseStatement;
-import org.apache.iotdb.db.utils.constant.SqlConstant;
 import org.apache.iotdb.it.env.EnvFactory;
 import org.apache.iotdb.it.framework.IoTDBTestRunner;
 import org.apache.iotdb.itbase.category.ClusterIT;
diff --git a/integration-test/src/test/java/org/apache/iotdb/confignode/it/procedure/IoTDBProcedureIT.java b/integration-test/src/test/java/org/apache/iotdb/confignode/it/procedure/IoTDBProcedureIT.java
index bae794807f3..ddfd3e93333 100644
--- a/integration-test/src/test/java/org/apache/iotdb/confignode/it/procedure/IoTDBProcedureIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/confignode/it/procedure/IoTDBProcedureIT.java
@@ -19,6 +19,7 @@
 
 package org.apache.iotdb.confignode.it.procedure;
 
+import org.apache.iotdb.calc.utils.constant.SqlConstant;
 import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient;
 import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.commons.schema.SchemaConstant;
@@ -28,7 +29,6 @@ import org.apache.iotdb.confignode.rpc.thrift.TGetDatabaseReq;
 import org.apache.iotdb.confignode.rpc.thrift.TShowDatabaseResp;
 import org.apache.iotdb.confignode.rpc.thrift.TTestOperation;
 import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowDatabaseStatement;
-import org.apache.iotdb.db.utils.constant.SqlConstant;
 import org.apache.iotdb.it.env.EnvFactory;
 import org.apache.iotdb.it.framework.IoTDBTestRunner;
 import org.apache.iotdb.itbase.category.ClusterIT;
diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBAuthenticationTableIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBAuthenticationTableIT.java
index 0565ff9e6fd..6795f3ee901 100644
--- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBAuthenticationTableIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBAuthenticationTableIT.java
@@ -1,15 +1,20 @@
 /*
- * Licensed 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
+ * 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
+ *      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.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
  */
 
 package org.apache.iotdb.relational.it.db.it;
diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBMultiTAGsWithAttributesTableIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBMultiTAGsWithAttributesTableIT.java
index 7b959696068..5e18a8468c7 100644
--- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBMultiTAGsWithAttributesTableIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBMultiTAGsWithAttributesTableIT.java
@@ -35,12 +35,12 @@ import java.sql.Connection;
 import java.sql.Statement;
 import java.util.Arrays;
 
+import static org.apache.iotdb.commons.queryengine.plan.relational.planner.node.JoinNode.JoinType.FULL;
+import static org.apache.iotdb.commons.queryengine.plan.relational.planner.node.JoinNode.JoinType.INNER;
+import static org.apache.iotdb.commons.queryengine.plan.relational.planner.node.JoinNode.JoinType.LEFT;
+import static org.apache.iotdb.commons.queryengine.plan.relational.planner.node.JoinNode.JoinType.RIGHT;
 import static org.apache.iotdb.db.it.utils.TestUtils.tableAssertTestFail;
 import static org.apache.iotdb.db.it.utils.TestUtils.tableResultSetEqualTest;
-import static org.apache.iotdb.db.queryengine.plan.relational.planner.node.JoinNode.JoinType.FULL;
-import static org.apache.iotdb.db.queryengine.plan.relational.planner.node.JoinNode.JoinType.INNER;
-import static org.apache.iotdb.db.queryengine.plan.relational.planner.node.JoinNode.JoinType.LEFT;
-import static org.apache.iotdb.db.queryengine.plan.relational.planner.node.JoinNode.JoinType.RIGHT;
 import static org.junit.Assert.fail;
 
 /** In this IT, table has more than one TAGs and Attributes. */
diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/udf/IoTDBSQLFunctionManagementIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/udf/IoTDBSQLFunctionManagementIT.java
index 769567860e1..f414171cf46 100644
--- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/udf/IoTDBSQLFunctionManagementIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/udf/IoTDBSQLFunctionManagementIT.java
@@ -18,9 +18,9 @@
  */
 package org.apache.iotdb.relational.it.db.it.udf;
 
+import org.apache.iotdb.commons.queryengine.plan.relational.function.TableBuiltinTableFunction;
 import org.apache.iotdb.commons.udf.builtin.relational.TableBuiltinAggregationFunction;
 import org.apache.iotdb.commons.udf.builtin.relational.TableBuiltinScalarFunction;
-import org.apache.iotdb.db.queryengine.plan.relational.function.TableBuiltinTableFunction;
 import org.apache.iotdb.it.env.EnvFactory;
 import org.apache.iotdb.it.framework.IoTDBTestRunner;
 import org.apache.iotdb.itbase.category.TableClusterIT;
diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBCastFunctionTableIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBCastFunctionTableIT.java
index 62c6b84f37a..94a4157deb2 100644
--- a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBCastFunctionTableIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBCastFunctionTableIT.java
@@ -19,7 +19,7 @@
 
 package org.apache.iotdb.relational.it.query.old.builtinfunction.scalar;
 
-import org.apache.iotdb.db.utils.DateTimeUtils;
+import org.apache.iotdb.commons.queryengine.utils.DateTimeUtils;
 import org.apache.iotdb.it.env.EnvFactory;
 import org.apache.iotdb.it.framework.IoTDBTestRunner;
 import org.apache.iotdb.itbase.category.TableClusterIT;
diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBFormatFunctionTableIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBFormatFunctionTableIT.java
index 4f5d53c1dd8..dd25f0ee18c 100644
--- a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBFormatFunctionTableIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBFormatFunctionTableIT.java
@@ -1,20 +1,25 @@
 /*
- * Licensed 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
+ * 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
+ *      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.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
  */
 
 package org.apache.iotdb.relational.it.query.old.builtinfunction.scalar;
 
-import org.apache.iotdb.db.utils.DateTimeUtils;
+import org.apache.iotdb.commons.queryengine.utils.DateTimeUtils;
 import org.apache.iotdb.it.env.EnvFactory;
 import org.apache.iotdb.it.framework.IoTDBTestRunner;
 import org.apache.iotdb.itbase.category.TableClusterIT;
diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/query/IoTDBArithmeticTableIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/query/IoTDBArithmeticTableIT.java
index 43e1302db12..c4961da8222 100644
--- a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/query/IoTDBArithmeticTableIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/query/IoTDBArithmeticTableIT.java
@@ -19,7 +19,7 @@
 
 package org.apache.iotdb.relational.it.query.old.query;
 
-import org.apache.iotdb.db.utils.DateTimeUtils;
+import org.apache.iotdb.commons.queryengine.utils.DateTimeUtils;
 import org.apache.iotdb.it.env.EnvFactory;
 import org.apache.iotdb.it.framework.IoTDBTestRunner;
 import org.apache.iotdb.itbase.category.TableClusterIT;
diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/query/IoTDBGreatestLeastTableIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/query/IoTDBGreatestLeastTableIT.java
index 32e5067d8c6..3b2ec28cc4b 100644
--- a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/query/IoTDBGreatestLeastTableIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/query/IoTDBGreatestLeastTableIT.java
@@ -1,15 +1,20 @@
 /*
- * Licensed 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
+ * 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
+ *      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.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
  */
 
 package org.apache.iotdb.relational.it.query.old.query;
diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/old/query/IoTDBArithmeticTableViewIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/old/query/IoTDBArithmeticTableViewIT.java
index e8a19eb2c59..296a63cc678 100644
--- a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/old/query/IoTDBArithmeticTableViewIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/old/query/IoTDBArithmeticTableViewIT.java
@@ -19,7 +19,7 @@
 
 package org.apache.iotdb.relational.it.query.view.old.query;
 
-import org.apache.iotdb.db.utils.DateTimeUtils;
+import org.apache.iotdb.commons.queryengine.utils.DateTimeUtils;
 import org.apache.iotdb.it.env.EnvFactory;
 import org.apache.iotdb.it.framework.IoTDBTestRunner;
 import org.apache.iotdb.itbase.category.TableClusterIT;
diff --git a/iotdb-client/cli/pom.xml b/iotdb-client/cli/pom.xml
index d8c48f7863f..e727adb57bf 100644
--- a/iotdb-client/cli/pom.xml
+++ b/iotdb-client/cli/pom.xml
@@ -64,6 +64,11 @@
             <artifactId>iotdb-server</artifactId>
             <version>2.0.7-SNAPSHOT</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.iotdb</groupId>
+            <artifactId>calc-commons</artifactId>
+            <version>2.0.7-SNAPSHOT</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.iotdb</groupId>
             <artifactId>isession</artifactId>
diff --git a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/AbstractDataTool.java b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/AbstractDataTool.java
index f5f11bc8d51..11695d786b8 100644
--- a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/AbstractDataTool.java
+++ b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/AbstractDataTool.java
@@ -19,15 +19,15 @@
 
 package org.apache.iotdb.tool.data;
 
+import org.apache.iotdb.calc.utils.constant.SqlConstant;
 import org.apache.iotdb.cli.type.ExitType;
 import org.apache.iotdb.cli.utils.CliContext;
 import org.apache.iotdb.cli.utils.IoTPrinter;
 import org.apache.iotdb.cli.utils.JlineUtils;
 import org.apache.iotdb.commons.exception.IllegalPathException;
+import org.apache.iotdb.commons.queryengine.utils.DateTimeUtils;
 import org.apache.iotdb.commons.schema.column.ColumnHeaderConstant;
 import org.apache.iotdb.commons.utils.PathUtils;
-import org.apache.iotdb.db.utils.DateTimeUtils;
-import org.apache.iotdb.db.utils.constant.SqlConstant;
 import org.apache.iotdb.exception.ArgsErrorException;
 import org.apache.iotdb.isession.SessionDataSet;
 import org.apache.iotdb.rpc.IoTDBConnectionException;
diff --git a/iotdb-core/calc-commons/pom.xml b/iotdb-core/calc-commons/pom.xml
new file mode 100644
index 00000000000..170604d15fc
--- /dev/null
+++ b/iotdb-core/calc-commons/pom.xml
@@ -0,0 +1,275 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.iotdb</groupId>
+        <artifactId>iotdb-core</artifactId>
+        <version>2.0.7-SNAPSHOT</version>
+    </parent>
+    <artifactId>calc-commons</artifactId>
+    <name>IoTDB: Core: Calc Commons</name>
+    <description>Common modules of the server and stream node</description>
+    <properties>
+        <calc.it.skip>${calc.test.skip}</calc.it.skip>
+        <calc.test.skip>false</calc.test.skip>
+        <calc.ut.skip>${calc.test.skip}</calc.ut.skip>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.iotdb</groupId>
+            <artifactId>service-rpc</artifactId>
+            <version>2.0.7-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tsfile</groupId>
+            <artifactId>common</artifactId>
+            <version>${tsfile.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tsfile</groupId>
+            <artifactId>tsfile</artifactId>
+            <version>${tsfile.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.iotdb</groupId>
+            <artifactId>node-commons</artifactId>
+            <version>2.0.7-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.iotdb</groupId>
+            <artifactId>iotdb-thrift-commons</artifactId>
+            <version>2.0.7-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.iotdb</groupId>
+            <artifactId>udf-api</artifactId>
+            <version>2.0.7-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.iotdb</groupId>
+            <artifactId>metrics-interface</artifactId>
+            <version>2.0.7-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.iotdb</groupId>
+            <artifactId>pipe-api</artifactId>
+            <version>2.0.7-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>io.airlift</groupId>
+            <artifactId>units</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.code.findbugs</groupId>
+            <artifactId>jsr305</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>at.yawk.lz4</groupId>
+            <artifactId>lz4-java</artifactId>
+        </dependency>
+    </dependencies>
+    <build>
+        <plugins>
+            <!--
+         Generate an OSGI compatible MANIFEST file.
+       -->
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <exportScr>true</exportScr>
+                    <instructions>
+                        <_include>-bnd.bnd</_include>
+                        <_removeheaders>Bnd-LastModified,Built-By</_removeheaders>
+                        <Embed-Dependency>dependencies</Embed-Dependency>
+                    </instructions>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>bundle-manifest</id>
+                        <phase>process-classes</phase>
+                        <goals>
+                            <goal>manifest</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <!--
+              Use the MANIFEST file generated by the maven-bundle-plugin.
+            -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
+                        <manifest>
+                            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
+                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+                        </manifest>
+                    </archive>
+                </configuration>
+            </plugin>
+            <!--using `mvn test` to run UT, `mvn verify` to run ITs
+            Reference: https://antoniogoncalves.org/2012/12/13/lets-turn-integration-tests-with-maven-to-a-first-class-citizen/-->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <skipTests>${calc.ut.skip}</skipTests>
+                    <reuseForks>false</reuseForks>
+                    <runOrder>random</runOrder>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <!-- copy all templates/data in the same location to compile them at once -->
+                        <id>copy-fmpp-resources</id>
+                        <goals>
+                            <goal>copy-resources</goal>
+                        </goals>
+                        <phase>initialize</phase>
+                        <configuration>
+                            <outputDirectory>${project.build.directory}/codegen</outputDirectory>
+                            <resources>
+                                <resource>
+                                    <directory>src/main/codegen</directory>
+                                    <filtering>false</filtering>
+                                </resource>
+                            </resources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <!-- generate sources from fmpp -->
+                <groupId>org.apache.drill.tools</groupId>
+                <artifactId>drill-fmpp-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>generate-fmpp</id>
+                        <goals>
+                            <goal>generate</goal>
+                        </goals>
+                        <phase>generate-sources</phase>
+                        <configuration>
+                            <config>${project.build.directory}/codegen/config.fmpp</config>
+                            <output>${project.build.directory}/generated-sources/freemarker</output>
+                            <templates>${project.build.directory}/codegen/templates</templates>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-failsafe-plugin</artifactId>
+                <configuration>
+                    <skipTests>${calc.test.skip}</skipTests>
+                    <skipITs>${calc.it.skip}</skipITs>
+                    <reuseForks>false</reuseForks>
+                    <runOrder>random</runOrder>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>run-integration-tests</id>
+                        <phase>integration-test</phase>
+                        <goals>
+                            <goal>integration-test</goal>
+                            <goal>verify</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+    <profiles>
+        <profile>
+            <id>skipCalcTests</id>
+            <activation>
+                <property>
+                    <name>skipTests</name>
+                    <value>true</value>
+                </property>
+            </activation>
+            <properties>
+                <calc.it.skip>true</calc.it.skip>
+                <calc.test.skip>true</calc.test.skip>
+                <calc.ut.skip>true</calc.ut.skip>
+            </properties>
+        </profile>
+        <profile>
+            <id>skipUT_CalcTests</id>
+            <activation>
+                <property>
+                    <name>skipUTs</name>
+                    <value>true</value>
+                </property>
+            </activation>
+            <properties>
+                <calc.ut.skip>true</calc.ut.skip>
+            </properties>
+        </profile>
+        <profile>
+            <id>get-jar-with-dependencies</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-assembly-plugin</artifactId>
+                        <configuration>
+                            <descriptorRefs>
+                                <descriptorRef>jar-with-dependencies</descriptorRef>
+                            </descriptorRefs>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <id>make-assembly</id>
+                                <!-- bind to the packaging phase -->
+                                <goals>
+                                    <goal>single</goal>
+                                </goals>
+                                <!-- this is used for inheritance merges -->
+                                <phase>package</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+</project>
diff --git a/iotdb-core/datanode/src/main/codegen/config.fmpp b/iotdb-core/calc-commons/src/main/codegen/config.fmpp
similarity index 100%
rename from iotdb-core/datanode/src/main/codegen/config.fmpp
rename to iotdb-core/calc-commons/src/main/codegen/config.fmpp
diff --git a/iotdb-core/datanode/src/main/codegen/dataModel/AllDataType.tdd b/iotdb-core/calc-commons/src/main/codegen/dataModel/AllDataType.tdd
similarity index 100%
rename from iotdb-core/datanode/src/main/codegen/dataModel/AllDataType.tdd
rename to iotdb-core/calc-commons/src/main/codegen/dataModel/AllDataType.tdd
diff --git a/iotdb-core/datanode/src/main/codegen/dataModel/CompareType.tdd b/iotdb-core/calc-commons/src/main/codegen/dataModel/CompareType.tdd
similarity index 100%
rename from iotdb-core/datanode/src/main/codegen/dataModel/CompareType.tdd
rename to iotdb-core/calc-commons/src/main/codegen/dataModel/CompareType.tdd
diff --git a/iotdb-core/datanode/src/main/codegen/dataModel/DecimalDataType.tdd b/iotdb-core/calc-commons/src/main/codegen/dataModel/DecimalDataType.tdd
similarity index 100%
rename from iotdb-core/datanode/src/main/codegen/dataModel/DecimalDataType.tdd
rename to iotdb-core/calc-commons/src/main/codegen/dataModel/DecimalDataType.tdd
diff --git a/iotdb-core/datanode/src/main/codegen/dataModel/MathematicalDataType.tdd b/iotdb-core/calc-commons/src/main/codegen/dataModel/MathematicalDataType.tdd
similarity index 100%
rename from iotdb-core/datanode/src/main/codegen/dataModel/MathematicalDataType.tdd
rename to iotdb-core/calc-commons/src/main/codegen/dataModel/MathematicalDataType.tdd
diff --git a/iotdb-core/datanode/src/main/codegen/dataModel/MathematicalOperator.tdd b/iotdb-core/calc-commons/src/main/codegen/dataModel/MathematicalOperator.tdd
similarity index 100%
rename from iotdb-core/datanode/src/main/codegen/dataModel/MathematicalOperator.tdd
rename to iotdb-core/calc-commons/src/main/codegen/dataModel/MathematicalOperator.tdd
diff --git a/iotdb-core/calc-commons/src/main/codegen/templates/ArithmeticBinaryColumnTransformer.ftl b/iotdb-core/calc-commons/src/main/codegen/templates/ArithmeticBinaryColumnTransformer.ftl
new file mode 100644
index 00000000000..48beb26fedb
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/codegen/templates/ArithmeticBinaryColumnTransformer.ftl
@@ -0,0 +1,419 @@
+/*
+ * 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.
+ */
+<@pp.dropOutputFile />
+<#list mathematicalOperator.binaryOperators as operator>
+<#list mathematicalDataType.types as first>
+<#list mathematicalDataType.types as second>
+<#--Parting line-->
+<#assign className = "${first.type?replace('Type','')}${operator.name}${second.type?replace('Type','')}ColumnTransformer">
+
+<#--Main Part-->
+<#if (first.instance == "DATE" || first.instance == "TIMESTAMP") && (second.instance == "INT" || second.instance == "LONG")><#if operator.name == "Addition" || operator.name == "Subtraction">
+<@pp.changeOutputFile name="/org/apache/iotdb/calc/transformation/dag/column/binary/${className}.java" />
+<#--Date + int || Date + long || Timestamp + int || Timestamp + long-->
+<#--Date - int || Date - long || Timestamp - int || Timestamp - long-->
+package org.apache.iotdb.calc.transformation.dag.column.binary;
+
+import org.apache.iotdb.commons.exception.IoTDBRuntimeException;
+import org.apache.iotdb.calc.transformation.dag.column.ColumnTransformer;
+import org.apache.iotdb.commons.queryengine.utils.DateTimeUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.read.common.type.Type;
+import org.apache.tsfile.utils.DateUtils;
+
+import java.time.ZoneId;
+
+<#if first.instance == "DATE">
+import java.time.format.DateTimeParseException;
+
+import static org.apache.iotdb.rpc.TSStatusCode.DATE_OUT_OF_RANGE;
+</#if>
+<#if first.dataType == "int" || second.dataType == "int" || first.dataType == "long" || second.dataType == "long">
+import static org.apache.iotdb.rpc.TSStatusCode.NUMERIC_VALUE_OUT_OF_RANGE;
+</#if>
+
+public class ${className} extends BinaryColumnTransformer {
+
+  private static ZoneId zoneId;
+
+  public ${className}(
+    Type returnType, ColumnTransformer leftTransformer, ColumnTransformer rightTransformer, ZoneId zoneId) {
+    super(returnType, leftTransformer, rightTransformer);
+    this.zoneId = zoneId;
+  }
+
+  @Override
+  protected void doTransform(
+      Column leftColumn, Column rightColumn, ColumnBuilder builder, int positionCount) {
+    for (int i = 0; i < positionCount; i++) {
+      if (!leftColumn.isNull(i) && !rightColumn.isNull(i)) {
+        returnType.write${first.dataType?cap_first}(
+            builder,
+            transform(
+                leftTransformer.getType().get${first.dataType?cap_first}(leftColumn, i),
+                rightTransformer.getType().get${second.dataType?cap_first}(rightColumn, i)));
+      } else {
+        builder.appendNull();
+      }
+    }
+  }
+
+  @Override
+  protected void doTransform(
+      Column leftColumn,
+      Column rightColumn,
+      ColumnBuilder builder,
+      int positionCount,
+      boolean[] selection){
+    for (int i = 0; i < positionCount; i++) {
+      if (!leftColumn.isNull(i) && !rightColumn.isNull(i) && selection[i]) {
+        returnType.write${first.dataType?cap_first}(
+            builder,
+            transform(
+                leftTransformer.getType().get${first.dataType?cap_first}(leftColumn, i),
+                rightTransformer.getType().get${second.dataType?cap_first}(rightColumn, i)));
+      } else {
+        builder.appendNull();
+      }
+    }
+  }
+
+  @Override
+  protected void checkType() {
+    // do nothing
+  }
+
+  public static ${first.dataType} transform(${first.dataType} left, ${second.dataType} right) {
+    <#switch operator.name>
+    <#case "Addition">
+    <#if first.instance == "DATE">
+    <#--Date + int || Date + long-->
+    try{
+      long timestamp =
+          Math.addExact(
+              DateTimeUtils.correctPrecision(DateUtils.parseIntToTimestamp(left,zoneId)), right);
+      return DateUtils.parseDateExpressionToInt(
+          DateTimeUtils.convertToLocalDate(timestamp, zoneId));
+    }catch (ArithmeticException e){
+      throw new IoTDBRuntimeException(
+          String.format("long ${operator.name} overflow: %s + %s", left, right),
+          NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+          true);
+    }catch (DateTimeParseException e) {
+      throw new IoTDBRuntimeException(
+          "Year must be between 1000 and 9999.",
+          DATE_OUT_OF_RANGE.getStatusCode(),
+          true);
+    }
+    <#else>
+    <#--Timestamp + int || Timestamp + long-->
+    try{
+      return Math.addExact(left, right);
+    }catch (ArithmeticException e){
+      throw new IoTDBRuntimeException(String.format("long ${operator.name} overflow: %s + %s", left, right),NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),true);
+    }
+    </#if>
+    <#break>
+    <#case "Subtraction">
+    <#if first.instance == "DATE">
+    <#--Date - int || Date - long-->
+    try{
+      long timestamp =
+          Math.subtractExact(
+              DateTimeUtils.correctPrecision(DateUtils.parseIntToTimestamp(left, zoneId)), right);
+      return DateUtils.parseDateExpressionToInt(
+          DateTimeUtils.convertToLocalDate(timestamp, zoneId));
+    }catch (ArithmeticException e){
+      throw new IoTDBRuntimeException(
+          String.format("long ${operator.name} overflow: %s - %s", left, right),
+          NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+          true);
+    }catch (DateTimeParseException e) {
+      throw new IoTDBRuntimeException(
+          "Year must be between 1000 and 9999.",
+          DATE_OUT_OF_RANGE.getStatusCode(),
+          true);
+    }
+    <#else>
+    <#--Timestamp - int || Timestamp - long-->
+    try{
+      return Math.subtractExact(left, right);
+    }catch (ArithmeticException e){
+      throw new IoTDBRuntimeException(
+          String.format("long ${operator.name} overflow: %s - %s", left, right),
+          NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+          true);
+    }
+    </#if>
+    <#break>
+    </#switch>
+  }
+}
+</#if>
+<#elseif (second.instance == "DATE" || second.instance =="TIMESTAMP") && (first.instance == "INT" || first.instance == "LONG")>
+  <#if operator.name == "Addition">
+<#--int + Date || long + Date || int + Timestamp || long + Timestamp-->
+<@pp.changeOutputFile name="/org/apache/iotdb/calc/transformation/dag/column/binary/${className}.java" />
+package org.apache.iotdb.calc.transformation.dag.column.binary;
+
+import org.apache.iotdb.commons.exception.IoTDBRuntimeException;
+import org.apache.iotdb.calc.transformation.dag.column.ColumnTransformer;
+import org.apache.iotdb.commons.queryengine.utils.DateTimeUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.read.common.type.Type;
+import org.apache.tsfile.utils.DateUtils;
+
+import java.time.ZoneId;
+<#if second.instance == "DATE">
+import java.time.format.DateTimeParseException;
+</#if>
+
+<#if first.dataType == "int" || second.dataType == "int" || first.dataType == "long" || second.dataType == "long">
+<#if second.instance == "DATE">
+import static org.apache.iotdb.rpc.TSStatusCode.DATE_OUT_OF_RANGE;
+</#if>
+import static org.apache.iotdb.rpc.TSStatusCode.NUMERIC_VALUE_OUT_OF_RANGE;
+</#if>
+
+public class ${className} extends BinaryColumnTransformer {
+
+  private static ZoneId zoneId;
+
+  public ${className}(
+    Type returnType, ColumnTransformer leftTransformer, ColumnTransformer rightTransformer, ZoneId zoneId) {
+    super(returnType, leftTransformer, rightTransformer);
+    this.zoneId = zoneId;
+  }
+
+  @Override
+  protected void doTransform(
+      Column leftColumn, Column rightColumn, ColumnBuilder builder, int positionCount) {
+    for (int i = 0; i < positionCount; i++) {
+      if (!leftColumn.isNull(i) && !rightColumn.isNull(i)) {
+        returnType.write${second.dataType?cap_first}(
+            builder,
+            transform(
+                leftTransformer.getType().get${first.dataType?cap_first}(leftColumn, i),
+                rightTransformer.getType().get${second.dataType?cap_first}(rightColumn, i)));
+      } else {
+        builder.appendNull();
+      }
+    }
+  }
+
+  @Override
+  protected void doTransform(
+      Column leftColumn,
+      Column rightColumn,
+      ColumnBuilder builder,
+      int positionCount,
+      boolean[] selection){
+    for (int i = 0; i < positionCount; i++) {
+      if (!leftColumn.isNull(i) && !rightColumn.isNull(i) && selection[i]) {
+        returnType.write${second.dataType?cap_first}(
+            builder,
+            transform(
+                leftTransformer.getType().get${first.dataType?cap_first}(leftColumn, i),
+                rightTransformer.getType().get${second.dataType?cap_first}(rightColumn, i)));
+      } else {
+        builder.appendNull();
+      }
+    }
+  }
+
+  @Override
+  protected void checkType() {
+    // do nothing
+  }
+
+  public static ${second.dataType} transform(${first.dataType} left, ${second.dataType} right) {
+    <#if second.instance == "DATE">
+    try{
+      long timestamp = Math.addExact(left,DateTimeUtils.correctPrecision(DateUtils.parseIntToTimestamp(right, zoneId)));
+      return DateUtils.parseDateExpressionToInt(DateTimeUtils.convertToLocalDate(timestamp, zoneId));
+    }catch (ArithmeticException e){
+      throw new IoTDBRuntimeException(
+          String.format("long ${operator.name} overflow: %s + %s", left, right),
+          NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+          true);
+    }catch (DateTimeParseException e) {
+      throw new IoTDBRuntimeException(
+          "Year must be between 1000 and 9999.",
+          DATE_OUT_OF_RANGE.getStatusCode(),
+          true);
+    }
+    <#else>
+    try{
+      return Math.addExact(left, right);
+    }catch (ArithmeticException e){
+      throw new IoTDBRuntimeException(
+          String.format("long ${operator.name} overflow: %s + %s", left, right),
+          NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+          true);
+    }
+    </#if>
+  }
+}
+</#if>
+<#elseif first.instance != "DATE" && first.instance != "TIMESTAMP" && second.instance != "DATE" && second.instance != "TIMESTAMP">
+<@pp.changeOutputFile name="/org/apache/iotdb/calc/transformation/dag/column/binary/${className}.java" />
+<#--int、long、float、double with + - * / %-->
+<#--assign resultType-->
+<#if first.dataType == "double" || second.dataType == "double">
+  <#assign resultType = "double" />
+<#elseif first.dataType == "float" || second.dataType == "float">
+  <#assign resultType = "float" />
+<#elseif first.dataType == "long" || second.dataType == "long">
+  <#assign resultType = "long" />
+<#else>
+  <#assign resultType = "int" />
+</#if>
+<#--Parting line-->
+package org.apache.iotdb.calc.transformation.dag.column.binary;
+
+import org.apache.iotdb.commons.exception.IoTDBRuntimeException;
+import org.apache.iotdb.commons.exception.SemanticException;
+import org.apache.iotdb.calc.transformation.dag.column.ColumnTransformer;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.read.common.type.Type;
+
+<#if operator.name == "Division" || operator.name == "Modulus">
+import static org.apache.iotdb.rpc.TSStatusCode.DIVISION_BY_ZERO;
+</#if>
+<#if first.dataType == "int" || second.dataType == "int" || first.dataType == "long" || second.dataType == "long">
+import static org.apache.iotdb.rpc.TSStatusCode.NUMERIC_VALUE_OUT_OF_RANGE;
+</#if>
+
+public class ${className} extends BinaryColumnTransformer {
+  public ${className}(
+    Type returnType, ColumnTransformer leftTransformer, ColumnTransformer rightTransformer) {
+    super(returnType, leftTransformer, rightTransformer);
+  }
+
+  @Override
+  protected void doTransform(
+      Column leftColumn, Column rightColumn, ColumnBuilder builder, int positionCount) {
+    for (int i = 0; i < positionCount; i++) {
+      if (!leftColumn.isNull(i) && !rightColumn.isNull(i)) {
+        returnType.write${resultType?cap_first}(
+            builder,
+            transform(
+                leftTransformer.getType().get${first.dataType?cap_first}(leftColumn, i),
+                rightTransformer.getType().get${second.dataType?cap_first}(rightColumn, i)));
+      } else {
+        builder.appendNull();
+      }
+    }
+  }
+
+  @Override
+  protected void doTransform(
+      Column leftColumn,
+      Column rightColumn,
+      ColumnBuilder builder,
+      int positionCount,
+      boolean[] selection){
+    for (int i = 0; i < positionCount; i++) {
+      if (!leftColumn.isNull(i) && !rightColumn.isNull(i) && selection[i]) {
+        returnType.write${resultType?cap_first}(
+            builder,
+            transform(
+                leftTransformer.getType().get${first.dataType?cap_first}(leftColumn, i),
+                rightTransformer.getType().get${second.dataType?cap_first}(rightColumn, i)));
+      } else {
+        builder.appendNull();
+      }
+    }
+  }
+
+  @Override
+  protected void checkType() {
+    // do nothing
+  }
+
+  public static ${resultType} transform(${first.dataType} left, ${second.dataType} right) {
+    <#if (first.dataType == "int" || first.dataType == "long") && (second.dataType == "int" || second.dataType =="long")>
+    <#switch operator.name>
+    <#case "Addition">
+    try{
+      return Math.addExact(left, right);
+    }catch (ArithmeticException e){
+      throw new IoTDBRuntimeException(
+          String.format("${resultType} ${operator.name} overflow: %s + %s", left, right),
+          NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+          false);
+    }
+    <#break>
+    <#case "Subtraction">
+    try{
+      return Math.subtractExact(left, right);
+    }catch (ArithmeticException e){
+      throw new IoTDBRuntimeException(
+          String.format("${resultType} ${operator.name} overflow: %s - %s", left, right),
+          NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+          false);
+    }
+    <#break>
+    <#case "Multiplication">
+    try{
+      return Math.multiplyExact(left, right);
+    }catch (ArithmeticException e){
+      throw new IoTDBRuntimeException(
+          String.format("${resultType} ${operator.name} overflow: %s * %s", left, right),
+          NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+          true);
+    }
+    <#break>
+    <#case "Division">
+    try{
+      if (left == <#if first.dataType == "int">Integer.MIN_VALUE<#elseif first.dataType == "long">Long.MIN_VALUE</#if> && right == -1) {
+        throw new IoTDBRuntimeException(
+          String.format("${resultType} overflow: %s / %s", left, right),
+          NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+          true);
+      }
+      return left / right;
+    }catch (ArithmeticException e){
+      throw new IoTDBRuntimeException("Division by zero",DIVISION_BY_ZERO.getStatusCode(),true);
+    }
+    <#break>
+    <#case "Modulus">
+    try{
+      return left % right;
+    }catch (ArithmeticException e){
+      throw new IoTDBRuntimeException("Division by zero",DIVISION_BY_ZERO.getStatusCode(),true);
+    }
+    <#break>
+    </#switch>
+    <#else>
+    return left ${operator.symbol} right;
+    </#if>
+  }
+}
+</#if>
+<#--Parting line-->
+</#list>
+</#list>
+</#list>
\ No newline at end of file
diff --git a/iotdb-core/calc-commons/src/main/codegen/templates/ArithmeticColumnTransformerApi.ftl b/iotdb-core/calc-commons/src/main/codegen/templates/ArithmeticColumnTransformerApi.ftl
new file mode 100644
index 00000000000..f4aac11f133
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/codegen/templates/ArithmeticColumnTransformerApi.ftl
@@ -0,0 +1,230 @@
+/*
+ * 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.
+ */
+
+<@pp.dropOutputFile />
+<@pp.changeOutputFile name="/org/apache/iotdb/calc/transformation/dag/column/binary/ArithmeticColumnTransformerApi.java" />
+package org.apache.iotdb.calc.transformation.dag.column.binary;
+
+import org.apache.tsfile.read.common.type.Type;
+
+import org.apache.iotdb.commons.queryengine.plan.relational.function.arithmetic.AdditionResolver;
+import org.apache.iotdb.commons.queryengine.plan.relational.function.arithmetic.DivisionResolver;
+import org.apache.iotdb.commons.queryengine.plan.relational.function.arithmetic.ModulusResolver;
+import org.apache.iotdb.commons.queryengine.plan.relational.function.arithmetic.MultiplicationResolver;
+import org.apache.iotdb.commons.queryengine.plan.relational.function.arithmetic.SubtractionResolver;
+import org.apache.iotdb.calc.transformation.dag.column.ColumnTransformer;
+import org.apache.iotdb.calc.transformation.dag.column.unary.DoubleNegationColumnTransformer;
+import org.apache.iotdb.calc.transformation.dag.column.unary.FloatNegationColumnTransformer;
+import org.apache.iotdb.calc.transformation.dag.column.unary.IntNegationColumnTransformer;
+import org.apache.iotdb.calc.transformation.dag.column.unary.LongNegationColumnTransformer;
+import org.apache.iotdb.calc.transformation.dag.column.unary.TimestampNegationColumnTransformer;
+
+import java.time.ZoneId;
+import java.util.Arrays;
+import java.util.List;
+
+public class ArithmeticColumnTransformerApi {
+  <#list mathematicalOperator.binaryOperators as operator>
+
+  public static ColumnTransformer get${operator.name}Transformer(
+      ColumnTransformer leftTransformer, ColumnTransformer rightTransformer, ZoneId zoneId) {
+    switch (leftTransformer.getType().getTypeEnum()) {
+      case INT32:
+        return getInt${operator.name}Transformer(leftTransformer, rightTransformer, zoneId);
+      case INT64:
+        return getLong${operator.name}Transformer(leftTransformer, rightTransformer, zoneId);
+      case FLOAT:
+        return getFloat${operator.name}Transformer(leftTransformer, rightTransformer, zoneId);
+      case DOUBLE:
+        return getDouble${operator.name}Transformer(leftTransformer, rightTransformer, zoneId);
+      <#if operator.name == "Addition" || operator.name == "Subtraction">
+      case DATE:
+        return getDate${operator.name}Transformer(leftTransformer, rightTransformer, zoneId);
+      case TIMESTAMP:
+        return getTimestamp${operator.name}Transformer(leftTransformer, rightTransformer, zoneId);
+      </#if>
+      default:
+        throw new UnsupportedOperationException("Unsupported Type");
+    }
+  }
+  </#list>
+
+  public static ColumnTransformer getNegationTransformer(ColumnTransformer columnTransformer) {
+    switch (columnTransformer.getType().getTypeEnum()) {
+      case INT32:
+        return new IntNegationColumnTransformer(
+            columnTransformer.getType(), columnTransformer);
+      case INT64:
+        return new LongNegationColumnTransformer(
+            columnTransformer.getType(), columnTransformer);
+      case FLOAT:
+        return new FloatNegationColumnTransformer(
+            columnTransformer.getType(), columnTransformer);
+      case DOUBLE:
+        return new DoubleNegationColumnTransformer(
+            columnTransformer.getType(), columnTransformer);
+      case TIMESTAMP:
+        return new TimestampNegationColumnTransformer(
+            columnTransformer.getType(), columnTransformer);
+      default:
+        throw new UnsupportedOperationException("Unsupported Type");
+    }
+  }
+  <#-- Parting line -->
+  <#list mathematicalOperator.binaryOperators as operator>
+  <#list mathematicalDataType.types as first>
+    <#assign firstType =  first.type?replace("Type","")>
+  <#-- The getTransformer method without Date and Timesatmp -->
+  <#if firstType != "Date" && firstType != "Timestamp">
+
+  private static ColumnTransformer get${firstType}${operator.name}Transformer(
+      ColumnTransformer leftTransformer, ColumnTransformer rightTransformer, ZoneId zoneId) {
+    List<? extends Type> argumentTypes =
+    Arrays.asList(leftTransformer.getType(), rightTransformer.getType());
+    switch (rightTransformer.getType().getTypeEnum()) {
+      case INT32:
+        return new ${firstType}${operator.name}IntColumnTransformer(
+            ${operator.name}Resolver.checkConditions(argumentTypes).get(),
+            leftTransformer,
+            rightTransformer);
+      case INT64:
+        return new ${firstType}${operator.name}LongColumnTransformer(
+            ${operator.name}Resolver.checkConditions(argumentTypes).get(),
+            leftTransformer,
+            rightTransformer);
+      case FLOAT:
+        return new ${firstType}${operator.name}FloatColumnTransformer(
+            ${operator.name}Resolver.checkConditions(argumentTypes).get(),
+            leftTransformer,
+            rightTransformer);
+      case DOUBLE:
+        return new ${firstType}${operator.name}DoubleColumnTransformer(
+            ${operator.name}Resolver.checkConditions(argumentTypes).get(),
+            leftTransformer,
+            rightTransformer);
+      <#if operator.name == "Addition" && (firstType == "Int" || firstType == "Long")>
+      case DATE:
+        return new ${firstType}${operator.name}DateColumnTransformer(
+            ${operator.name}Resolver.checkConditions(argumentTypes).get(),
+            leftTransformer,
+            rightTransformer,
+            zoneId);
+      case TIMESTAMP:
+        return new ${firstType}${operator.name}TimestampColumnTransformer(
+            ${operator.name}Resolver.checkConditions(argumentTypes).get(),
+            leftTransformer,
+            rightTransformer,
+            zoneId);
+      </#if>
+      default:
+        throw new UnsupportedOperationException("Unsupported Type");
+    }
+  }
+  </#if>
+  </#list>
+  </#list>
+
+  private static ColumnTransformer getDateAdditionTransformer(
+      ColumnTransformer leftTransformer, ColumnTransformer rightTransformer, ZoneId zoneId) {
+    List<? extends Type> argumentTypes =
+    Arrays.asList(leftTransformer.getType(), rightTransformer.getType());
+    switch (rightTransformer.getType().getTypeEnum()) {
+      case INT32:
+        return new DateAdditionIntColumnTransformer(
+            AdditionResolver.checkConditions(argumentTypes).get(),
+            leftTransformer,
+            rightTransformer,
+            zoneId);
+      case INT64:
+        return new DateAdditionLongColumnTransformer(
+            AdditionResolver.checkConditions(argumentTypes).get(),
+            leftTransformer,
+            rightTransformer,
+            zoneId);
+      default:
+        throw new UnsupportedOperationException("Unsupported Type");
+    }
+  }
+
+  private static ColumnTransformer getTimestampAdditionTransformer(
+      ColumnTransformer leftTransformer, ColumnTransformer rightTransformer, ZoneId zoneId) {
+    List<? extends Type> argumentTypes =
+    Arrays.asList(leftTransformer.getType(), rightTransformer.getType());
+    switch (rightTransformer.getType().getTypeEnum()) {
+      case INT32:
+        return new TimestampAdditionIntColumnTransformer(
+            AdditionResolver.checkConditions(argumentTypes).get(),
+            leftTransformer,
+            rightTransformer,
+            zoneId);
+      case INT64:
+        return new TimestampAdditionLongColumnTransformer(
+            AdditionResolver.checkConditions(argumentTypes).get(),
+            leftTransformer,
+            rightTransformer,
+            zoneId);
+      default:
+        throw new UnsupportedOperationException("Unsupported Type");
+    }
+  }
+
+  private static ColumnTransformer getDateSubtractionTransformer(
+      ColumnTransformer leftTransformer, ColumnTransformer rightTransformer, ZoneId zoneId) {
+    List<? extends Type> argumentTypes =
+    Arrays.asList(leftTransformer.getType(), rightTransformer.getType());
+    switch (rightTransformer.getType().getTypeEnum()) {
+      case INT32:
+        return new DateSubtractionIntColumnTransformer(
+            AdditionResolver.checkConditions(argumentTypes).get(),
+            leftTransformer,
+            rightTransformer,
+            zoneId);
+      case INT64:
+        return new DateSubtractionLongColumnTransformer(
+            AdditionResolver.checkConditions(argumentTypes).get(),
+            leftTransformer,
+            rightTransformer,
+            zoneId);
+      default:
+        throw new UnsupportedOperationException("Unsupported Type");
+    }
+  }
+
+  private static ColumnTransformer getTimestampSubtractionTransformer(
+      ColumnTransformer leftTransformer, ColumnTransformer rightTransformer, ZoneId zoneId) {
+    List<? extends Type> argumentTypes =
+    Arrays.asList(leftTransformer.getType(), rightTransformer.getType());
+    switch (rightTransformer.getType().getTypeEnum()) {
+      case INT32:
+        return new TimestampSubtractionIntColumnTransformer(
+            AdditionResolver.checkConditions(argumentTypes).get(),
+            leftTransformer,
+            rightTransformer,
+            zoneId);
+      case INT64:
+        return new TimestampSubtractionLongColumnTransformer(
+            AdditionResolver.checkConditions(argumentTypes).get(),
+            leftTransformer,
+            rightTransformer,
+            zoneId);
+      default:
+        throw new UnsupportedOperationException("Unsupported Type");
+    }
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/codegen/templates/ArithmeticUnaryColumnTransformer.ftl b/iotdb-core/calc-commons/src/main/codegen/templates/ArithmeticUnaryColumnTransformer.ftl
new file mode 100644
index 00000000000..1c71ecb7690
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/codegen/templates/ArithmeticUnaryColumnTransformer.ftl
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+
+<@pp.dropOutputFile />
+<#list mathematicalDataType.types as type>
+  <#assign newType = type.type?replace("Type","")>
+  <#assign className = "${newType}NegationColumnTransformer">
+<#if newType != "Date">
+  <@pp.changeOutputFile name="/org/apache/iotdb/calc/transformation/dag/column/unary/${className}.java" />
+package org.apache.iotdb.calc.transformation.dag.column.unary;
+
+import org.apache.iotdb.commons.exception.IoTDBRuntimeException;
+import org.apache.iotdb.calc.transformation.dag.column.ColumnTransformer;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.read.common.type.Type;
+
+import static org.apache.iotdb.rpc.TSStatusCode.NUMERIC_VALUE_OUT_OF_RANGE;
+
+public class ${className} extends UnaryColumnTransformer {
+
+  public ${className}(
+    Type returnType, ColumnTransformer childColumnTransformer) {
+    super(returnType, childColumnTransformer);
+  }
+
+  @Override
+  protected void doTransform(
+      Column column, ColumnBuilder columnBuilder) {
+    for (int i = 0, n = column.getPositionCount(); i < n; i++) {
+      if (!column.isNull(i)) {
+        returnType.write${type.dataType?cap_first}(
+            columnBuilder, transform(childColumnTransformer.getType().get${type.dataType?cap_first}(column, i)));
+      } else {
+        columnBuilder.appendNull();
+      }
+    }
+  }
+
+  @Override
+  protected void doTransform(
+      Column column, ColumnBuilder columnBuilder, boolean[] selection) {
+    for (int i = 0, n = column.getPositionCount(); i < n; i++) {
+      if (selection[i] && !column.isNull(i)) {
+        returnType.write${type.dataType?cap_first}(
+            columnBuilder, transform(childColumnTransformer.getType().get${type.dataType?cap_first}(column, i)));
+      } else {
+        columnBuilder.appendNull();
+      }
+    }
+  }
+
+  @Override
+  protected void checkType() {
+    // do nothing
+  }
+
+  public static ${type.dataType} transform(${type.dataType} value){
+    <#if type.dataType == "int" || type.dataType == "long">
+    if(value == <#if type.dataType == "int">Integer<#else>Long</#if>.MIN_VALUE){
+      throw new IoTDBRuntimeException(String.format("The %s is out of range of ${type.dataType}.", value), NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(), true);
+    }
+    </#if>
+    return -value;
+  }
+}
+</#if>
+</#list>
diff --git a/iotdb-core/calc-commons/src/main/codegen/templates/ModeAccumulator.ftl b/iotdb-core/calc-commons/src/main/codegen/templates/ModeAccumulator.ftl
new file mode 100644
index 00000000000..c881219a97c
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/codegen/templates/ModeAccumulator.ftl
@@ -0,0 +1,203 @@
+/*
+ * 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.
+ */
+<@pp.dropOutputFile />
+
+<#list allDataTypes.types as type>
+
+    <#assign className = "${type.dataType?cap_first}ModeAccumulator">
+    <@pp.changeOutputFile name="/org/apache/iotdb/calc/execution/aggregation/${className}.java" />
+
+package org.apache.iotdb.calc.execution.aggregation;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.iotdb.commons.conf.CommonDescriptor;
+import org.apache.tsfile.external.commons.collections4.comparators.ComparatorChain;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.file.metadata.statistics.Statistics;
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.utils.Binary;
+import org.apache.tsfile.utils.BitMap;
+import org.apache.tsfile.utils.Pair;
+import org.apache.tsfile.utils.ReadWriteIOUtils;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/*
+* This class is generated using freemarker and the ${.template_name} template.
+*/
+@SuppressWarnings("unused")
+public class ${className} implements Accumulator {
+  // pair left records count of element, pair right records min time of element
+  private final Map<${type.javaBoxName}, Pair<Long, Long>> countMap = new HashMap<>();
+
+  <#if type.dataType != "boolean">
+  private final int MAP_SIZE_THRESHOLD = CommonDescriptor.getInstance().getConfig().getModeMapSizeThreshold();
+
+  </#if>
+  @Override
+  public void addInput(Column[] column, BitMap bitMap) {
+    int count = column[0].getPositionCount();
+    for (int i = 0; i < count; i++) {
+      if (bitMap != null && !bitMap.isMarked(i)) {
+        continue;
+      }
+      if (!column[1].isNull(i)) {
+          final long time = column[0].getLong(i);
+        countMap.compute(
+            column[1].get${type.dataType?cap_first}(i),
+            (k, v) ->
+                v == null ? new Pair<>(1L, time) : new Pair<>(v.left + 1, Math.min(v.right, time)));
+        <#if type.dataType != "boolean">
+
+        if (countMap.size() > MAP_SIZE_THRESHOLD) {
+          throw new RuntimeException(
+              String.format(
+                  "distinct values has exceeded the threshold %s when calculate Mode",
+                  MAP_SIZE_THRESHOLD));
+        }
+        </#if>
+      }
+    }
+  }
+
+  @Override
+  public void addIntermediate(Column[] partialResult) {
+    checkArgument(partialResult.length == 1, "partialResult of Mode should be 1");
+    checkArgument(!partialResult[0].isNull(0), "partialResult of Mode should not be null");
+    deserializeAndMergeCountMap(partialResult[0].getBinary(0));
+  }
+
+  @Override
+  public void addStatistics(Statistics statistics) {
+    throw new UnsupportedOperationException(getClass().getName());
+  }
+
+  @Override
+  public void setFinal(Column finalResult) {
+    if (finalResult.isNull(0)) {
+      return;
+    }
+
+    // Step of ModeAccumulator is STATIC,
+    // countMap only need to record one entry which key is finalResult
+    countMap.put(finalResult.get${type.dataType?cap_first}(0), new Pair<>(0L, Long.MIN_VALUE));
+  }
+
+  @Override
+  public void outputIntermediate(ColumnBuilder[] tsBlockBuilder) {
+    tsBlockBuilder[0].writeBinary(serializeCountMap());
+  }
+
+  @Override
+  public void outputFinal(ColumnBuilder tsBlockBuilder) {
+    if (countMap.isEmpty()) {
+      tsBlockBuilder.appendNull();
+    } else {
+      tsBlockBuilder.write${type.dataType?cap_first}(
+          Collections.max(
+                  countMap.entrySet(),
+                  Map.Entry.comparingByValue(
+                      new ComparatorChain<>(
+                          ImmutableList.of(
+                              (v1, v2) -> v1.left.compareTo(v2.left),
+                              (v1, v2) -> v2.right.compareTo(v1.right)))))
+              .getKey());
+    }
+  }
+
+  @Override
+  public void reset() {
+    countMap.clear();
+  }
+
+  @Override
+  public boolean hasFinalResult() {
+    return false;
+  }
+
+  @Override
+  public TSDataType[] getIntermediateType() {
+    return new TSDataType[] {TSDataType.TEXT};
+  }
+
+  @Override
+  public TSDataType getFinalType() {
+    return ${type.tsDataType};
+  }
+
+  private Binary serializeCountMap() {
+    ByteArrayOutputStream stream = new ByteArrayOutputStream();
+    try {
+      ReadWriteIOUtils.write(countMap.size(), stream);
+      for (Map.Entry<${type.javaBoxName}, Pair<Long, Long>> entry : countMap.entrySet()) {
+        ReadWriteIOUtils.write(entry.getKey(), stream);
+        ReadWriteIOUtils.write(entry.getValue().left, stream);
+        ReadWriteIOUtils.write(entry.getValue().right, stream);
+      }
+    } catch (IOException e) {
+      // Totally memory operation. This case won't happen.
+    }
+    return new Binary(stream.toByteArray());
+  }
+
+  private void deserializeAndMergeCountMap(Binary partialResult) {
+    InputStream stream = new ByteArrayInputStream(partialResult.getValues());
+    try {
+      int size = ReadWriteIOUtils.readInt(stream);
+      for (int i = 0; i < size; i++) {
+        countMap.compute(
+            ReadWriteIOUtils.read${type.dataType?cap_first}(stream),
+            (k, v) -> {
+              try {
+                return v == null
+                    ? new Pair<>(
+                        ReadWriteIOUtils.readLong(stream), ReadWriteIOUtils.readLong(stream))
+                    : new Pair<>(
+                        v.left + ReadWriteIOUtils.readLong(stream),
+                        Math.min(v.right, ReadWriteIOUtils.readLong(stream)));
+              } catch (IOException e) {
+                throw new RuntimeException(e);
+              }
+            });
+        <#if type.dataType != "boolean">
+
+        if (countMap.size() > MAP_SIZE_THRESHOLD) {
+          throw new RuntimeException(
+              String.format(
+                  "distinct values has exceeded the threshold %s when calculate Mode",
+                  MAP_SIZE_THRESHOLD));
+        }
+        </#if>
+      }
+    } catch (IOException e) {
+      // Totally memory operation. This case won't happen.
+    }
+  }
+}
+
+</#list>
\ No newline at end of file
diff --git a/iotdb-core/calc-commons/src/main/codegen/templates/constantFill.ftl b/iotdb-core/calc-commons/src/main/codegen/templates/constantFill.ftl
new file mode 100644
index 00000000000..88d01849ba9
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/codegen/templates/constantFill.ftl
@@ -0,0 +1,81 @@
+/*
+* 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.
+*/
+<@pp.dropOutputFile />
+
+<#list allDataTypes.types as type>
+
+  <#assign className = "${type.dataType?cap_first}ConstantFill">
+  <@pp.changeOutputFile name="/org/apache/iotdb/calc/execution/operator/process/fill/constant/${className}.java" />
+package org.apache.iotdb.calc.execution.operator.process.fill.constant;
+
+import org.apache.iotdb.calc.execution.operator.process.fill.IFill;
+import org.apache.tsfile.read.common.block.column.${type.column};
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.read.common.block.column.RunLengthEncodedColumn;
+<#if type.dataType == "Binary">
+import org.apache.tsfile.utils.Binary;
+</#if>
+
+import java.util.Optional;
+
+/*
+* This class is generated using freemarker and the ${.template_name} template.
+*/
+@SuppressWarnings("unused")
+public class ${className} implements IFill {
+
+  // fill value
+  private final ${type.dataType} value;
+  // used for constructing RunLengthEncodedColumn, size of it must be 1
+  private final ${type.dataType}[] valueArray;
+
+  public ${className}(${type.dataType} value) {
+    this.value = value;
+    this.valueArray = new ${type.dataType}[] {value};
+  }
+
+  @Override
+  public Column fill(Column timeColumn, Column valueColumn) {
+    int size = valueColumn.getPositionCount();
+    // if this valueColumn doesn't have any null value, or it's empty, just return itself;
+    if (!valueColumn.mayHaveNull() || size == 0) {
+      return valueColumn;
+    }
+    // if its values are all null
+    if (valueColumn instanceof RunLengthEncodedColumn) {
+      return new RunLengthEncodedColumn(new ${type.column}(1, Optional.empty(), valueArray), size);
+    } else {
+      ${type.dataType}[] array = new ${type.dataType}[size];
+      for (int i = 0; i < size; i++) {
+        if (valueColumn.isNull(i)) {
+          array[i] = value;
+        } else {
+          array[i] = valueColumn.get${type.dataType?cap_first}(i);
+        }
+      }
+      return new ${type.column}(size, Optional.empty(), array);
+    }
+  }
+
+  @Override
+  public void reset() {
+    // do nothing
+  }
+}
+
+</#list>
diff --git a/iotdb-core/calc-commons/src/main/codegen/templates/linearFill.ftl b/iotdb-core/calc-commons/src/main/codegen/templates/linearFill.ftl
new file mode 100644
index 00000000000..301708018b6
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/codegen/templates/linearFill.ftl
@@ -0,0 +1,122 @@
+/*
+* 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.
+*/
+<@pp.dropOutputFile />
+
+<#list decimalDataTypes.types as type>
+
+  <#assign className = "${type.dataType?cap_first}LinearFill">
+  <@pp.changeOutputFile name="/org/apache/iotdb/calc/execution/operator/process/fill/linear/${className}.java" />
+package org.apache.iotdb.calc.execution.operator.process.fill.linear;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.read.common.block.column.${type.column};
+import org.apache.tsfile.read.common.block.column.${type.column}Builder;
+
+
+import java.util.Optional;
+
+/*
+* This class is generated using freemarker and the ${.template_name} template.
+*/
+@SuppressWarnings("unused")
+public class ${className} extends LinearFill {
+
+  // previous value
+  private ${type.dataType} previousValue;
+  // next non-null value whose time is closest to the current TsBlock's endTime
+  private ${type.dataType} nextValue;
+
+  private ${type.dataType} nextValueInCurrentColumn;
+
+  @Override
+  void fillValue(Column column, int index, Object array) {
+    ((${type.dataType}[]) array)[index] = column.get${type.dataType?cap_first}(index);
+  }
+
+  @Override
+  void fillValue(Object array, int index, double factor) {
+    ((${type.dataType}[]) array)[index] = getFilledValue(factor);
+  }
+
+  @Override
+  Object createValueArray(int size) {
+    return new ${type.dataType}[size];
+  }
+
+  @Override
+  Column createNullValueColumn() {
+    return ${type.column}Builder.NULL_VALUE_BLOCK;
+  }
+
+  @Override
+  Column createFilledValueColumn(double[] factors, Optional<boolean[]> valueIsNull) {
+    int size = factors.length;
+    ${type.dataType}[] filledValue = new ${type.dataType}[size];
+
+    if (valueIsNull.isPresent()) {
+      // has null value
+      boolean[] isNull = valueIsNull.get();
+      for (int i = 0; i < size; i++) {
+        if (!isNull[i]) {
+          filledValue[i] = getFilledValue(factors[i]);
+        }
+      }
+    } else {
+      for (int i = 0; i < size; i++) {
+        filledValue[i] = getFilledValue(factors[i]);
+      }
+    }
+    return new ${type.column}(size, valueIsNull, filledValue);
+  }
+
+  @Override
+  Column createFilledValueColumn(Object array, boolean[] isNull, boolean hasNullValue, int size) {
+    if (hasNullValue) {
+      return new ${type.column}(size, Optional.of(isNull), (${type.dataType}[]) array);
+    } else {
+      return new ${type.column}(size, Optional.empty(), (${type.dataType}[]) array);
+    }
+  }
+
+  @Override
+  void updatePreviousValue(Column column, int index) {
+    previousValue = column.get${type.dataType?cap_first}(index);
+  }
+
+  @Override
+  void updateNextValue(Column nextValueColumn, int index) {
+    this.nextValue = nextValueColumn.get${type.dataType?cap_first}(index);
+  }
+
+  @Override
+  void updateNextValueInCurrentColumn(Column nextValueColumn, int index) {
+    this.nextValueInCurrentColumn = nextValueColumn.get${type.dataType?cap_first}(index);
+  }
+
+  @Override
+  void updateNextValueInCurrentColumn() {
+    this.nextValueInCurrentColumn = this.nextValue;
+  }
+
+  private ${type.dataType} getFilledValue(double factor) {
+    return (${type.dataType}) (previousValue + (nextValueInCurrentColumn - previousValue) * factor);
+  }
+}
+
+</#list>
diff --git a/iotdb-core/calc-commons/src/main/codegen/templates/previousFill.ftl b/iotdb-core/calc-commons/src/main/codegen/templates/previousFill.ftl
new file mode 100644
index 00000000000..e15f0893540
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/codegen/templates/previousFill.ftl
@@ -0,0 +1,109 @@
+/*
+* 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.
+*/
+<@pp.dropOutputFile />
+
+<#list allDataTypes.types as type>
+
+  <#assign className = "${type.dataType?cap_first}PreviousFill">
+  <@pp.changeOutputFile name="/org/apache/iotdb/calc/execution/operator/process/fill/previous/${className}.java" />
+package org.apache.iotdb.calc.execution.operator.process.fill.previous;
+
+import org.apache.iotdb.calc.execution.operator.process.fill.IFill;
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.read.common.block.column.${type.column};
+import org.apache.tsfile.read.common.block.column.${type.column}Builder;
+import org.apache.tsfile.read.common.block.column.RunLengthEncodedColumn;
+<#if type.dataType == "Binary">
+  import org.apache.tsfile.utils.Binary;
+</#if>
+
+import java.util.Optional;
+
+/*
+* This class is generated using freemarker and the ${.template_name} template.
+*/
+@SuppressWarnings("unused")
+// PreviousFill without time duration parameter
+public class ${className} implements IFill {
+
+  // previous value
+  private ${type.dataType} value;
+  // previous time
+  private long previousTime;
+  // whether previous value is null
+  private boolean previousIsNull = true;
+
+  @Override
+  public Column fill(Column timeColumn, Column valueColumn) {
+    int size = valueColumn.getPositionCount();
+    // if this valueColumn is empty, just return itself;
+    if (size == 0) {
+      return valueColumn;
+    }
+    // if this valueColumn doesn't have any null value, record the last value, and then return
+    // itself.
+    if (!valueColumn.mayHaveNull()) {
+      previousIsNull = false;
+      // update the value using last non-null value
+      previousTime = timeColumn.getLong(size - 1);
+      value = valueColumn.get${type.dataType?cap_first}(size - 1);
+      return valueColumn;
+    }
+    // if its values are all null
+    if (valueColumn instanceof RunLengthEncodedColumn) {
+      if (previousIsNull) {
+        return new RunLengthEncodedColumn(${type.column}Builder.NULL_VALUE_BLOCK, size);
+      } else {
+        return new RunLengthEncodedColumn(
+            new ${type.column}(1, Optional.empty(), new ${type.dataType}[] {value}), size);
+      }
+    }
+
+    ${type.dataType}[] array = new ${type.dataType}[size];
+    boolean[] isNull = new boolean[size];
+    // have null value
+    boolean hasNullValue = false;
+    for (int i = 0; i < size; i++) {
+      if (valueColumn.isNull(i)) {
+        if (previousIsNull) {
+          isNull[i] = true;
+          hasNullValue = true;
+        } else {
+          array[i] = value;
+        }
+      } else {
+        array[i] = valueColumn.get${type.dataType?cap_first}(i);
+        previousTime = timeColumn.getLong(i);
+        value = array[i];
+        previousIsNull = false;
+      }
+    }
+    if (hasNullValue) {
+      return new ${type.column}(size, Optional.of(isNull), array);
+    } else {
+      return new ${type.column}(size, Optional.empty(), array);
+    }
+  }
+
+  @Override
+  public void reset() {
+    previousIsNull = true;
+  }
+}
+</#list>
diff --git a/iotdb-core/calc-commons/src/main/codegen/templates/previousFillWithTimeDuration.ftl b/iotdb-core/calc-commons/src/main/codegen/templates/previousFillWithTimeDuration.ftl
new file mode 100644
index 00000000000..22b0ff91efa
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/codegen/templates/previousFillWithTimeDuration.ftl
@@ -0,0 +1,130 @@
+/*
+* 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.
+*/
+<@pp.dropOutputFile />
+
+<#list allDataTypes.types as type>
+
+    <#assign className = "${type.dataType?cap_first}PreviousFillWithTimeDuration">
+    <@pp.changeOutputFile name="/org/apache/iotdb/calc/execution/operator/process/fill/previous/${className}.java" />
+package org.apache.iotdb.calc.execution.operator.process.fill.previous;
+
+import org.apache.iotdb.calc.execution.operator.process.fill.IFill;
+import org.apache.iotdb.calc.execution.operator.process.fill.IFillFilter;
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.read.common.block.column.${type.column};
+import org.apache.tsfile.read.common.block.column.${type.column}Builder;
+import org.apache.tsfile.read.common.block.column.RunLengthEncodedColumn;
+<#if type.dataType == "Binary">
+    import org.apache.tsfile.utils.Binary;
+</#if>
+
+import java.util.Optional;
+
+/*
+* This class is generated using freemarker and the ${.template_name} template.
+*/
+@SuppressWarnings("unused")
+// PreviousFill without time duration parameter
+public class ${className} implements IFill {
+
+  // previous value
+  private ${type.dataType} value;
+  // previous time
+  private long previousTime;
+  // whether previous value is null
+  private boolean previousIsNull = true;
+
+  private final IFillFilter filter;
+
+  public ${className}(IFillFilter filter) {
+    this.filter = filter;
+  }
+
+  @Override
+  public Column fill(Column timeColumn, Column valueColumn) {
+    int size = valueColumn.getPositionCount();
+    // if this valueColumn is empty, just return itself;
+    if (size == 0) {
+      return valueColumn;
+    }
+    // if this valueColumn doesn't have any null value, record the last value, and then return itself.
+    if (!valueColumn.mayHaveNull()) {
+      if (!timeColumn.mayHaveNull()) {
+        previousIsNull = false;
+        // update the value using last non-null value
+        previousTime = timeColumn.getLong(size - 1);
+        value = valueColumn.get${type.dataType?cap_first}(size - 1);
+      } else {
+        // find the row that last helper column is not null
+        for (int i = size - 1; i >= 0; i--) {
+          if (!timeColumn.isNull(i)) {
+            previousIsNull = false;
+            // update the value using last non-null value
+            previousTime = timeColumn.getLong(size - 1);
+            value = valueColumn.get${type.dataType?cap_first}(size - 1);
+            break;
+          }
+        }
+      }
+      return valueColumn;
+    }
+    // if its values are all null
+    if (valueColumn instanceof RunLengthEncodedColumn) {
+      if (previousIsNull) {
+        return new RunLengthEncodedColumn(${type.column}Builder.NULL_VALUE_BLOCK, size);
+      } else if (!timeColumn.mayHaveNull() && filter.needFill(timeColumn.getLong(size - 1), previousTime)) {
+        return new RunLengthEncodedColumn(new ${type.column}(1, Optional.empty(), new ${type.dataType}[] {value}), size);
+      }
+    }
+
+    ${type.dataType}[] array = new ${type.dataType}[size];
+    boolean[] isNull = new boolean[size];
+    // have null value
+    boolean hasNullValue = false;
+    for (int i = 0; i < size; i++) {
+      boolean helperColumnIsNull = timeColumn.isNull(i);
+      if (valueColumn.isNull(i)) {
+        if (previousIsNull || helperColumnIsNull || !filter.needFill(timeColumn.getLong(i), previousTime)) {
+          isNull[i] = true;
+          hasNullValue = true;
+        } else {
+          array[i] = value;
+        }
+      } else {
+        array[i] = valueColumn.get${type.dataType?cap_first}(i);
+        if (!helperColumnIsNull) {
+          previousTime = timeColumn.getLong(i);
+          value = array[i];
+          previousIsNull = false;
+        }
+      }
+    }
+    if (hasNullValue) {
+      return new ${type.column}(size, Optional.of(isNull), array);
+    } else {
+      return new ${type.column}(size, Optional.empty(), array);
+    }
+  }
+
+  @Override
+  public void reset() {
+    previousIsNull = true;
+  }
+}
+</#list>
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/exception/MemoryNotEnoughException.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/exception/MemoryNotEnoughException.java
new file mode 100644
index 00000000000..1a2924916de
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/exception/MemoryNotEnoughException.java
@@ -0,0 +1,31 @@
+/*
+ * 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.calc.exception;
+
+import org.apache.iotdb.commons.exception.IoTDBRuntimeException;
+
+import static org.apache.iotdb.rpc.TSStatusCode.QUERY_EXECUTION_MEMORY_NOT_ENOUGH;
+
+public class MemoryNotEnoughException extends IoTDBRuntimeException {
+
+  public MemoryNotEnoughException(String message) {
+    super(message, QUERY_EXECUTION_MEMORY_NOT_ENOUGH.getStatusCode());
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/exception/QueryProcessException.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/exception/QueryProcessException.java
new file mode 100644
index 00000000000..3d9753c4275
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/exception/QueryProcessException.java
@@ -0,0 +1,45 @@
+/*
+ * 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.calc.exception;
+
+import org.apache.iotdb.commons.exception.IoTDBException;
+import org.apache.iotdb.commons.exception.IoTDBRuntimeException;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+public class QueryProcessException extends IoTDBException {
+
+  private static final long serialVersionUID = -683191083844850054L;
+
+  public QueryProcessException(String message) {
+    super(message, TSStatusCode.QUERY_PROCESS_ERROR.getStatusCode());
+  }
+
+  public QueryProcessException(String message, int errorCode) {
+    super(message, errorCode);
+  }
+
+  public QueryProcessException(IoTDBException e) {
+    super(e, e.getErrorCode(), e.isUserException());
+  }
+
+  public QueryProcessException(IoTDBRuntimeException e) {
+    super(e, e.getErrorCode(), e.isUserException());
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/aggregation/Accumulator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/aggregation/Accumulator.java
new file mode 100644
index 00000000000..38b0c535393
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/aggregation/Accumulator.java
@@ -0,0 +1,97 @@
+/*
+ * 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.calc.execution.aggregation;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.file.metadata.statistics.Statistics;
+import org.apache.tsfile.utils.BitMap;
+
+public interface Accumulator {
+
+  /**
+   * Column should be like: |Time | Value |
+   *
+   * <p>IgnoringNull is required when considering the row where the value of controlColumn is null
+   *
+   * <p>bitMap is required for group-by framework. When needed(eq. controlColumn is null), bitMap
+   * can guide accumulator to skip some rows
+   */
+  void addInput(Column[] columns, BitMap bitMap);
+
+  /**
+   * Sliding window constantly add and remove partial result in the window. Aggregation functions
+   * need to implement this method to support sliding window feature.
+   */
+  default void removeIntermediate(Column[] partialResult) {
+    throw new UnsupportedOperationException(
+        "This type of accumulator does not support remove input!");
+  }
+
+  /**
+   * For aggregation function like COUNT, SUM, partialResult should be single; But for AVG,
+   * last_value, it should be double column with dictionary order.
+   */
+  void addIntermediate(Column[] partialResult);
+
+  /**
+   * This method can only be used in seriesAggregateScanOperator, it will use different statistics
+   * based on the type of Accumulator.
+   */
+  void addStatistics(Statistics statistics);
+
+  /**
+   * Attention: setFinal should be invoked only once, and addInput() and addIntermediate() are not
+   * allowed again.
+   */
+  void setFinal(Column finalResult);
+
+  /**
+   * For aggregation function like COUNT, SUM, partialResult should be single, so its output column
+   * is single too; But for AVG(COUNT and SUM), LAST_VALUE(LAST_VALUE and MAX_TIME), the output
+   * columns should be double in dictionary order.
+   */
+  void outputIntermediate(ColumnBuilder[] tsBlockBuilder);
+
+  /** Final result is single column for any aggregation function. */
+  void outputFinal(ColumnBuilder tsBlockBuilder);
+
+  void reset();
+
+  /**
+   * This method can only be used in seriesAggregateScanOperator. For first_value or last_value in
+   * decreasing order, we can get final result by the first record.
+   */
+  boolean hasFinalResult();
+
+  TSDataType[] getIntermediateType();
+
+  TSDataType getFinalType();
+
+  /**
+   * The return value equals to the length of tsBlockBuilder in {@link
+   * #outputIntermediate(ColumnBuilder[])}}. Currently only aggregation `Avg, FirstValue, LastValue,
+   * TimeDuration` will return 2.
+   */
+  default int getPartialResultSize() {
+    return 1;
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/aggregation/VarianceAccumulator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/aggregation/VarianceAccumulator.java
new file mode 100644
index 00000000000..48972749c3a
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/aggregation/VarianceAccumulator.java
@@ -0,0 +1,282 @@
+/*
+ * 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.calc.execution.aggregation;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.file.metadata.statistics.Statistics;
+import org.apache.tsfile.utils.Binary;
+import org.apache.tsfile.utils.BitMap;
+import org.apache.tsfile.utils.BytesUtils;
+import org.apache.tsfile.write.UnSupportedDataTypeException;
+
+import java.util.Arrays;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+public class VarianceAccumulator implements Accumulator {
+  public enum VarianceType {
+    STDDEV_POP,
+    STDDEV_SAMP,
+    VAR_POP,
+    VAR_SAMP,
+  }
+
+  private final TSDataType seriesDataType;
+
+  private final VarianceType varianceType;
+
+  private long count;
+  private double mean;
+  private double m2;
+
+  public VarianceAccumulator(TSDataType seriesDataType, VarianceType varianceType) {
+    this.seriesDataType = seriesDataType;
+    this.varianceType = varianceType;
+  }
+
+  @Override
+  public void addInput(Column[] columns, BitMap bitMap) {
+    switch (seriesDataType) {
+      case INT32:
+        addIntInput(columns, bitMap);
+        return;
+      case INT64:
+        addLongInput(columns, bitMap);
+        return;
+      case FLOAT:
+        addFloatInput(columns, bitMap);
+        return;
+      case DOUBLE:
+        addDoubleInput(columns, bitMap);
+        return;
+      case TEXT:
+      case BLOB:
+      case OBJECT:
+      case BOOLEAN:
+      case DATE:
+      case STRING:
+      case TIMESTAMP:
+      default:
+        throw new UnSupportedDataTypeException(
+            String.format("Unsupported data type in aggregation variance : %s", seriesDataType));
+    }
+  }
+
+  @Override
+  public void addIntermediate(Column[] partialResult) {
+    checkArgument(partialResult.length == 1, "partialResult of variance should be 1");
+    if (partialResult[0].isNull(0)) {
+      return;
+    }
+    byte[] bytes = partialResult[0].getBinary(0).getValues();
+    long intermediateCount = BytesUtils.bytesToLong(bytes, Long.BYTES);
+    double intermediateMean = BytesUtils.bytesToDouble(bytes, Long.BYTES);
+    double intermediateM2 = BytesUtils.bytesToDouble(bytes, (Long.BYTES + Double.BYTES));
+
+    long newCount = count + intermediateCount;
+    double newMean = ((intermediateCount * intermediateMean) + (count * mean)) / newCount;
+    double delta = intermediateMean - mean;
+
+    m2 = m2 + intermediateM2 + delta * delta * intermediateCount * count / newCount;
+    count = newCount;
+    mean = newMean;
+  }
+
+  @Override
+  public void removeIntermediate(Column[] input) {
+    checkArgument(input.length == 1, "Input of variance should be 1");
+    if (input[0].isNull(0)) {
+      return;
+    }
+    // Deserialize
+    byte[] bytes = input[0].getBinary(0).getValues();
+    long intermediateCount = BytesUtils.bytesToLong(bytes, Long.BYTES);
+    double intermediateMean = BytesUtils.bytesToDouble(bytes, Long.BYTES);
+    double intermediateM2 = BytesUtils.bytesToDouble(bytes, (Long.BYTES + Double.BYTES));
+    // Remove from state
+    long newCount = count - intermediateCount;
+    double newMean = ((count * mean) - (intermediateCount * intermediateMean)) / newCount;
+    double delta = intermediateMean - mean;
+
+    m2 = m2 - intermediateM2 - delta * delta * intermediateCount * count / newCount;
+    count = newCount;
+    mean = newMean;
+  }
+
+  @Override
+  public void addStatistics(Statistics statistics) {
+    throw new UnsupportedOperationException(getClass().getName());
+  }
+
+  @Override
+  public void setFinal(Column finalResult) {
+    reset();
+    if (finalResult.isNull(0)) {
+      return;
+    }
+    count = 1;
+    double value = finalResult.getDouble(0);
+    mean = value;
+    m2 = value * value;
+  }
+
+  @Override
+  public void outputIntermediate(ColumnBuilder[] columnBuilders) {
+    checkArgument(columnBuilders.length == 1, "partialResult of variance should be 1");
+    if (count == 0) {
+      columnBuilders[0].appendNull();
+    } else {
+      byte[] bytes = serialize();
+      columnBuilders[0].writeBinary(new Binary(bytes));
+    }
+  }
+
+  private byte[] serialize() {
+    byte[] countBytes = BytesUtils.longToBytes(count);
+    byte[] meanBytes = BytesUtils.doubleToBytes(mean);
+    byte[] m2Bytes = BytesUtils.doubleToBytes(m2);
+
+    return BytesUtils.concatByteArrayList(Arrays.asList(countBytes, meanBytes, m2Bytes));
+  }
+
+  @Override
+  public void outputFinal(ColumnBuilder columnBuilder) {
+    switch (varianceType) {
+      case STDDEV_POP:
+        if (count == 0) {
+          columnBuilder.appendNull();
+        } else {
+          columnBuilder.writeDouble(Math.sqrt(m2 / count));
+        }
+        break;
+      case STDDEV_SAMP:
+        if (count < 2) {
+          columnBuilder.appendNull();
+        } else {
+          columnBuilder.writeDouble(Math.sqrt(m2 / (count - 1)));
+        }
+        break;
+      case VAR_POP:
+        if (count == 0) {
+          columnBuilder.appendNull();
+        } else {
+          columnBuilder.writeDouble(m2 / count);
+        }
+        break;
+      case VAR_SAMP:
+        if (count < 2) {
+          columnBuilder.appendNull();
+        } else {
+          columnBuilder.writeDouble(m2 / (count - 1));
+        }
+        break;
+      default:
+        throw new EnumConstantNotPresentException(VarianceType.class, varianceType.name());
+    }
+  }
+
+  @Override
+  public void reset() {
+    count = 0;
+    mean = 0.0;
+    m2 = 0.0;
+  }
+
+  @Override
+  public boolean hasFinalResult() {
+    return false;
+  }
+
+  @Override
+  public TSDataType[] getIntermediateType() {
+    return new TSDataType[] {TSDataType.TEXT};
+  }
+
+  @Override
+  public TSDataType getFinalType() {
+    return TSDataType.DOUBLE;
+  }
+
+  private void addIntInput(Column[] columns, BitMap bitmap) {
+    int size = columns[0].getPositionCount();
+    for (int i = 0; i < size; i++) {
+      if (bitmap != null && !bitmap.isMarked(i)) {
+        continue;
+      }
+      if (!columns[1].isNull(i)) {
+        int value = columns[1].getInt(i);
+        count++;
+        double delta = value - mean;
+        mean += delta / count;
+        m2 += delta * (value - mean);
+      }
+    }
+  }
+
+  private void addLongInput(Column[] columns, BitMap bitmap) {
+    int size = columns[0].getPositionCount();
+    for (int i = 0; i < size; i++) {
+      if (bitmap != null && !bitmap.isMarked(i)) {
+        continue;
+      }
+      if (!columns[1].isNull(i)) {
+        long value = columns[1].getLong(i);
+        count++;
+        double delta = value - mean;
+        mean += delta / count;
+        m2 += delta * (value - mean);
+      }
+    }
+  }
+
+  private void addFloatInput(Column[] columns, BitMap bitmap) {
+    int size = columns[0].getPositionCount();
+    for (int i = 0; i < size; i++) {
+      if (bitmap != null && !bitmap.isMarked(i)) {
+        continue;
+      }
+      if (!columns[1].isNull(i)) {
+        float value = columns[1].getFloat(i);
+        count++;
+        double delta = value - mean;
+        mean += delta / count;
+        m2 += delta * (value - mean);
+      }
+    }
+  }
+
+  private void addDoubleInput(Column[] columns, BitMap bitmap) {
+    int size = columns[0].getPositionCount();
+    for (int i = 0; i < size; i++) {
+      if (bitmap != null && !bitmap.isMarked(i)) {
+        continue;
+      }
+      if (!columns[1].isNull(i)) {
+        double value = columns[1].getDouble(i);
+        count++;
+        double delta = value - mean;
+        mean += delta / count;
+        m2 += delta * (value - mean);
+      }
+    }
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/AbstractOperator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/AbstractOperator.java
new file mode 100644
index 00000000000..cc09d7fe971
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/AbstractOperator.java
@@ -0,0 +1,110 @@
+/*
+ * 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.calc.execution.operator;
+
+import org.apache.tsfile.common.conf.TSFileDescriptor;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class AbstractOperator implements Operator {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AbstractOperator.class);
+  protected CommonOperatorContext operatorContext;
+
+  protected long maxReturnSize =
+      TSFileDescriptor.getInstance().getConfig().getMaxTsBlockSizeInBytes();
+  protected int maxTupleSizeOfTsBlock = -1;
+  protected TsBlock resultTsBlock;
+  protected TsBlock retainedTsBlock;
+  protected int startOffset = 0;
+
+  public void initializeMaxTsBlockLength(TsBlock tsBlock) {
+    if (maxTupleSizeOfTsBlock != -1) {
+      return;
+    }
+    // oneTupleSize should be greater than 0 to avoid division by zero
+    long oneTupleSize =
+        Math.max(
+            1,
+            (tsBlock.getSizeInBytes() - tsBlock.getTotalInstanceSize())
+                / tsBlock.getPositionCount());
+    if (oneTupleSize > maxReturnSize) {
+      // make sure at least one-tuple-at-a-time
+      this.maxTupleSizeOfTsBlock = 1;
+      LOGGER.warn(
+          "Only one tuple can be sent each time caused by limited memory, oneTupleSize: {}B, maxReturnSize: {}B",
+          oneTupleSize,
+          maxReturnSize);
+    } else {
+      this.maxTupleSizeOfTsBlock = (int) (maxReturnSize / oneTupleSize);
+    }
+    if (LOGGER.isDebugEnabled()) {
+      LOGGER.debug("maxTupleSizeOfTsBlock is:{}", maxTupleSizeOfTsBlock);
+    }
+  }
+
+  public TsBlock checkTsBlockSizeAndGetResult() {
+    if (resultTsBlock == null) {
+      throw new IllegalArgumentException("Result tsBlock cannot be null");
+    } else if (resultTsBlock.isEmpty()) {
+      TsBlock res = resultTsBlock;
+      resultTsBlock = null;
+      return res;
+    }
+    if (maxTupleSizeOfTsBlock == -1) {
+      initializeMaxTsBlockLength(resultTsBlock);
+    }
+
+    if (resultTsBlock.getPositionCount() <= maxTupleSizeOfTsBlock) {
+      TsBlock res = resultTsBlock;
+      resultTsBlock = null;
+      return res;
+    } else {
+      retainedTsBlock = resultTsBlock;
+      resultTsBlock = null;
+      return getResultFromRetainedTsBlock();
+    }
+  }
+
+  public TsBlock getResultFromRetainedTsBlock() {
+    TsBlock res;
+    if (maxTupleSizeOfTsBlock == -1) {
+      initializeMaxTsBlockLength(retainedTsBlock);
+    }
+    if (retainedTsBlock.getPositionCount() - startOffset <= maxTupleSizeOfTsBlock) {
+      res = retainedTsBlock.subTsBlock(startOffset);
+      retainedTsBlock = null;
+      startOffset = 0;
+    } else {
+      res = retainedTsBlock.getRegion(startOffset, maxTupleSizeOfTsBlock);
+      startOffset += maxTupleSizeOfTsBlock;
+    }
+    if (LOGGER.isDebugEnabled()) {
+      LOGGER.debug("Current tsBlock size is : {}", res.getRetainedSizeInBytes());
+    }
+    return res;
+  }
+
+  @Override
+  public CommonOperatorContext getOperatorContext() {
+    return operatorContext;
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/CommonOperatorContext.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/CommonOperatorContext.java
new file mode 100644
index 00000000000..2c99fa5d777
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/CommonOperatorContext.java
@@ -0,0 +1,149 @@
+/*
+ * 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.calc.execution.operator;
+
+import org.apache.iotdb.calc.plan.planner.memory.MemoryReservationManager;
+import org.apache.iotdb.commons.conf.CommonDescriptor;
+import org.apache.iotdb.commons.queryengine.plan.planner.plan.node.PlanNodeId;
+import org.apache.iotdb.commons.utils.TestOnly;
+
+import io.airlift.units.Duration;
+import org.apache.tsfile.utils.Accountable;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Contains common information about {@link Operator} execution.
+ *
+ * <p>Not thread-safe.
+ */
+public abstract class CommonOperatorContext implements Accountable {
+
+  protected static Duration maxRunTime =
+      new Duration(
+          CommonDescriptor.getInstance().getConfig().getDriverTaskExecutionTimeSliceInMs(),
+          TimeUnit.MILLISECONDS);
+
+  protected final int operatorId;
+  // It seems it's never used.
+  protected final PlanNodeId planNodeId;
+  protected String operatorType;
+
+  protected long totalExecutionTimeInNanos = 0L;
+  protected long nextCalledCount = 0L;
+  protected long hasNextCalledCount = 0L;
+
+  // SpecifiedInfo is used to record some custom information for the operator,
+  // which will be shown in the result of EXPLAIN ANALYZE to analyze the query.
+  protected final Map<String, Object> specifiedInfo = new ConcurrentHashMap<>();
+  protected long output = 0;
+  protected long estimatedMemorySize;
+
+  protected CommonOperatorContext(int operatorId, PlanNodeId planNodeId, String operatorType) {
+    this.operatorId = operatorId;
+    this.planNodeId = planNodeId;
+    this.operatorType = operatorType;
+  }
+
+  public int getOperatorId() {
+    return operatorId;
+  }
+
+  public String getOperatorType() {
+    return operatorType;
+  }
+
+  public void setOperatorType(String operatorType) {
+    this.operatorType = operatorType;
+  }
+
+  public static Duration getMaxRunTime() {
+    return maxRunTime;
+  }
+
+  @TestOnly
+  public Duration getMaxRunTimeForTest() {
+    return maxRunTime;
+  }
+
+  public static void setMaxRunTime(Duration maxRunTime) {
+    CommonOperatorContext.maxRunTime = maxRunTime;
+  }
+
+  public PlanNodeId getPlanNodeId() {
+    return planNodeId;
+  }
+
+  public abstract MemoryReservationManager getMemoryReservationContext();
+
+  public abstract int getFragmentId();
+
+  public abstract int getPipelineId();
+
+  public void recordExecutionTime(long executionTimeInNanos) {
+    this.totalExecutionTimeInNanos += executionTimeInNanos;
+  }
+
+  public void recordNextCalled() {
+    this.nextCalledCount++;
+  }
+
+  public void recordHasNextCalled() {
+    this.hasNextCalledCount++;
+  }
+
+  public long getTotalExecutionTimeInNanos() {
+    return totalExecutionTimeInNanos;
+  }
+
+  public long getNextCalledCount() {
+    return nextCalledCount;
+  }
+
+  public long getHasNextCalledCount() {
+    return hasNextCalledCount;
+  }
+
+  public void setEstimatedMemorySize(long estimatedMemorySize) {
+    this.estimatedMemorySize = estimatedMemorySize;
+  }
+
+  public long getEstimatedMemorySize() {
+    return estimatedMemorySize;
+  }
+
+  public void addOutputRows(long outputRows) {
+    this.output += outputRows;
+  }
+
+  public long getOutputRows() {
+    return output;
+  }
+
+  public void recordSpecifiedInfo(String key, String value) {
+    specifiedInfo.put(key, value);
+  }
+
+  public Map<String, Object> getSpecifiedInfo() {
+    return specifiedInfo;
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/GroupedTopNBuilder.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/GroupedTopNBuilder.java
new file mode 100644
index 00000000000..79118650766
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/GroupedTopNBuilder.java
@@ -0,0 +1,32 @@
+/*
+ * 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.calc.execution.operator;
+
+import org.apache.tsfile.read.common.block.TsBlock;
+
+import java.util.Iterator;
+
+public interface GroupedTopNBuilder {
+  void addTsBlock(TsBlock tsBlock);
+
+  Iterator<TsBlock> getResult();
+
+  long getEstimatedSizeInBytes();
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/GroupedTopNRowNumberAccumulator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/GroupedTopNRowNumberAccumulator.java
new file mode 100644
index 00000000000..284e325ff5a
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/GroupedTopNRowNumberAccumulator.java
@@ -0,0 +1,483 @@
+/*
+ * 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.calc.execution.operator;
+
+import org.apache.iotdb.calc.execution.operator.source.relational.aggregation.grouped.array.LongBigArray;
+import org.apache.iotdb.calc.execution.operator.source.relational.aggregation.grouped.array.LongBigArrayFIFOQueue;
+import org.apache.iotdb.calc.utils.HeapTraversal;
+
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.function.LongConsumer;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Verify.verify;
+import static java.util.Objects.requireNonNull;
+
+public class GroupedTopNRowNumberAccumulator {
+  private static final long INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(GroupedTopNRowNumberAccumulator.class);
+  private static final long UNKNOWN_INDEX = -1;
+
+  private final GroupIdToHeapBuffer groupIdToHeapBuffer = new GroupIdToHeapBuffer();
+  private final HeapNodeBuffer heapNodeBuffer = new HeapNodeBuffer();
+  private final HeapTraversal heapTraversal = new HeapTraversal();
+
+  private final RowIdComparisonStrategy strategy;
+  private final int topN;
+  private final LongConsumer rowIdEvictionListener;
+
+  public GroupedTopNRowNumberAccumulator(
+      RowIdComparisonStrategy strategy, int topN, LongConsumer rowIdEvictionListener) {
+    this.strategy = requireNonNull(strategy, "strategy is null");
+    checkArgument(topN > 0, "topN must be greater than zero");
+    this.topN = topN;
+    this.rowIdEvictionListener =
+        requireNonNull(rowIdEvictionListener, "rowIdEvictionListener is null");
+  }
+
+  public long sizeOf() {
+    return INSTANCE_SIZE
+        + groupIdToHeapBuffer.sizeOf()
+        + heapNodeBuffer.sizeOf()
+        + heapTraversal.sizeOf();
+  }
+
+  public int findFirstPositionToAdd(
+      TsBlock newTsBlock,
+      int groupCount,
+      int[] groupIds,
+      TsBlockWithPositionComparator comparator,
+      RowReferenceTsBlockManager tsBlockManager) {
+    int currentTotalGroups = groupIdToHeapBuffer.getTotalGroups();
+    groupIdToHeapBuffer.allocateGroupIfNeeded(groupCount);
+
+    for (int position = 0; position < newTsBlock.getPositionCount(); position++) {
+      int groupId = groupIds[position];
+      if (groupId >= currentTotalGroups || calculateRootRowNumber(groupId) < topN) {
+        return position;
+      }
+      long heapRootNodeIndex = groupIdToHeapBuffer.getHeapRootNodeIndex(groupId);
+      if (heapRootNodeIndex == UNKNOWN_INDEX) {
+        return position;
+      }
+      long rowId = heapNodeBuffer.getRowId(heapRootNodeIndex);
+      TsBlock rightTsBlock = tsBlockManager.getTsBlock(rowId);
+      int rightPosition = tsBlockManager.getPosition(rowId);
+      if (comparator.compareTo(newTsBlock, position, rightTsBlock, rightPosition) < 0) {
+        return position;
+      }
+    }
+    return -1;
+  }
+
+  /**
+   * Add the specified row to this accumulator.
+   *
+   * <p>This may trigger row eviction callbacks if other rows have to be evicted to make space.
+   *
+   * @return true if this row was incorporated, false otherwise
+   */
+  public boolean add(int groupId, RowReference rowReference) {
+    groupIdToHeapBuffer.allocateGroupIfNeeded(groupId);
+
+    long heapRootNodeIndex = groupIdToHeapBuffer.getHeapRootNodeIndex(groupId);
+    if (heapRootNodeIndex == UNKNOWN_INDEX || calculateRootRowNumber(groupId) < topN) {
+      heapInsert(groupId, rowReference.allocateRowId());
+      return true;
+    }
+    if (rowReference.compareTo(strategy, heapNodeBuffer.getRowId(heapRootNodeIndex)) < 0) {
+      heapPopAndInsert(groupId, rowReference.allocateRowId(), rowIdEvictionListener);
+      return true;
+    }
+    return false;
+  }
+
+  /**
+   * Drain the contents of groupId from this accumulator to the provided output row ID buffer.
+   *
+   * <p>Rows will be presented in increasing rank order. Draining will not trigger any row eviction
+   * callbacks. After this method completion, the Accumulator will contain zero rows for the
+   * specified groupId.
+   *
+   * @return number of rows deposited to the output buffer
+   */
+  public long drainTo(int groupId, LongBigArray rowIdOutput) {
+    long heapSize = groupIdToHeapBuffer.getHeapSize(groupId);
+    rowIdOutput.ensureCapacity(heapSize);
+    // Heap is inverted to output order, so insert back to front
+    for (long i = heapSize - 1; i >= 0; i--) {
+      rowIdOutput.set(i, peekRootRowId(groupId));
+      // No eviction listener needed because this is an explicit caller directive to extract data
+      heapPop(groupId, null);
+    }
+    return heapSize;
+  }
+
+  private long calculateRootRowNumber(int groupId) {
+    return groupIdToHeapBuffer.getHeapSize(groupId);
+  }
+
+  private long peekRootRowId(int groupId) {
+    long heapRootNodeIndex = groupIdToHeapBuffer.getHeapRootNodeIndex(groupId);
+    checkArgument(heapRootNodeIndex != UNKNOWN_INDEX, "No root to peek");
+    return heapNodeBuffer.getRowId(heapRootNodeIndex);
+  }
+
+  private long getChildIndex(long heapNodeIndex, HeapTraversal.Child child) {
+    return child == HeapTraversal.Child.LEFT
+        ? heapNodeBuffer.getLeftChildHeapIndex(heapNodeIndex)
+        : heapNodeBuffer.getRightChildHeapIndex(heapNodeIndex);
+  }
+
+  private void setChildIndex(long heapNodeIndex, HeapTraversal.Child child, long newChildIndex) {
+    if (child == HeapTraversal.Child.LEFT) {
+      heapNodeBuffer.setLeftChildHeapIndex(heapNodeIndex, newChildIndex);
+    } else {
+      heapNodeBuffer.setRightChildHeapIndex(heapNodeIndex, newChildIndex);
+    }
+  }
+
+  /**
+   * Pop the root node off the group ID's max heap.
+   *
+   * @param contextEvictionListener optional callback for the root node that gets popped off
+   */
+  private void heapPop(int groupId, LongConsumer contextEvictionListener) {
+    long heapRootNodeIndex = groupIdToHeapBuffer.getHeapRootNodeIndex(groupId);
+    checkArgument(heapRootNodeIndex != UNKNOWN_INDEX, "Group ID has an empty heap");
+
+    long lastNodeIndex = heapDetachLastInsertionLeaf(groupId);
+    long lastRowId = heapNodeBuffer.getRowId(lastNodeIndex);
+    heapNodeBuffer.deallocate(lastNodeIndex);
+
+    if (lastNodeIndex == heapRootNodeIndex) {
+      // The root is the last node remaining
+      if (contextEvictionListener != null) {
+        contextEvictionListener.accept(lastRowId);
+      }
+    } else {
+      // Pop the root and insert lastRowId back into the heap to ensure a balanced tree
+      heapPopAndInsert(groupId, lastRowId, contextEvictionListener);
+    }
+  }
+
+  /**
+   * Detaches (but does not deallocate) the leaf in the bottom right-most position in the heap.
+   *
+   * <p>Given the fixed insertion order, the bottom right-most leaf will correspond to the last leaf
+   * node inserted into the balanced heap.
+   *
+   * @return leaf node index that was detached from the heap
+   */
+  private long heapDetachLastInsertionLeaf(int groupId) {
+    long heapRootNodeIndex = groupIdToHeapBuffer.getHeapRootNodeIndex(groupId);
+    long heapSize = groupIdToHeapBuffer.getHeapSize(groupId);
+
+    long previousNodeIndex = UNKNOWN_INDEX;
+    HeapTraversal.Child childPosition = null;
+    long currentNodeIndex = heapRootNodeIndex;
+
+    heapTraversal.resetWithPathTo(heapSize);
+    while (!heapTraversal.isTarget()) {
+      previousNodeIndex = currentNodeIndex;
+      childPosition = heapTraversal.nextChild();
+      currentNodeIndex = getChildIndex(currentNodeIndex, childPosition);
+      verify(currentNodeIndex != UNKNOWN_INDEX, "Target node must exist");
+    }
+
+    // Detach the last insertion leaf node, but do not deallocate yet
+    if (previousNodeIndex == UNKNOWN_INDEX) {
+      // Last insertion leaf was the root node
+      groupIdToHeapBuffer.setHeapRootNodeIndex(groupId, UNKNOWN_INDEX);
+      groupIdToHeapBuffer.setHeapSize(groupId, 0);
+    } else {
+      setChildIndex(previousNodeIndex, childPosition, UNKNOWN_INDEX);
+      groupIdToHeapBuffer.addHeapSize(groupId, -1);
+    }
+
+    return currentNodeIndex;
+  }
+
+  /**
+   * Inserts a new row into the heap for the specified group ID.
+   *
+   * <p>The technique involves traversing the heap from the root to a new bottom left-priority leaf
+   * position, potentially swapping heap nodes along the way to find the proper insertion position
+   * for the new row. Insertions always fill the left child before the right, and fill up an entire
+   * heap level before moving to the next level.
+   */
+  private void heapInsert(int groupId, long newRowId) {
+    long heapRootNodeIndex = groupIdToHeapBuffer.getHeapRootNodeIndex(groupId);
+    if (heapRootNodeIndex == UNKNOWN_INDEX) {
+      // Heap is currently empty, so this will be the first node
+      heapRootNodeIndex = heapNodeBuffer.allocateNewNode(newRowId);
+
+      groupIdToHeapBuffer.setHeapRootNodeIndex(groupId, heapRootNodeIndex);
+      groupIdToHeapBuffer.setHeapSize(groupId, 1);
+      return;
+    }
+
+    long previousHeapNodeIndex = UNKNOWN_INDEX;
+    HeapTraversal.Child childPosition = null;
+    long currentHeapNodeIndex = heapRootNodeIndex;
+
+    heapTraversal.resetWithPathTo(groupIdToHeapBuffer.getHeapSize(groupId) + 1);
+    while (!heapTraversal.isTarget()) {
+      long currentRowId = heapNodeBuffer.getRowId(currentHeapNodeIndex);
+      if (strategy.compare(newRowId, currentRowId) > 0) {
+        // Swap the row values
+        heapNodeBuffer.setRowId(currentHeapNodeIndex, newRowId);
+
+        newRowId = currentRowId;
+      }
+
+      previousHeapNodeIndex = currentHeapNodeIndex;
+      childPosition = heapTraversal.nextChild();
+      currentHeapNodeIndex = getChildIndex(currentHeapNodeIndex, childPosition);
+    }
+
+    verify(
+        previousHeapNodeIndex != UNKNOWN_INDEX && childPosition != null,
+        "heap must have at least one node before starting traversal");
+    verify(currentHeapNodeIndex == UNKNOWN_INDEX, "New child shouldn't exist yet");
+
+    long newHeapNodeIndex = heapNodeBuffer.allocateNewNode(newRowId);
+
+    //  Link the new child to the parent
+    setChildIndex(previousHeapNodeIndex, childPosition, newHeapNodeIndex);
+
+    groupIdToHeapBuffer.incrementHeapSize(groupId);
+  }
+
+  /**
+   * Pop the root node off the group ID's max heap and insert the newRowId.
+   *
+   * <p>These two operations are more efficient if performed together. The technique involves
+   * swapping the new row into the root position, and applying a heap down bubbling operation to
+   * heap-ify.
+   *
+   * @param contextEvictionListener optional callback for the root node that gets popped off
+   */
+  private void heapPopAndInsert(int groupId, long newRowId, LongConsumer contextEvictionListener) {
+    long heapRootNodeIndex = groupIdToHeapBuffer.getHeapRootNodeIndex(groupId);
+    checkState(heapRootNodeIndex != UNKNOWN_INDEX, "popAndInsert() requires at least a root node");
+
+    // Clear contents of the root node to create a vacancy for another row
+    long poppedRowId = heapNodeBuffer.getRowId(heapRootNodeIndex);
+
+    long currentNodeIndex = heapRootNodeIndex;
+    while (true) {
+      long maxChildNodeIndex = heapNodeBuffer.getLeftChildHeapIndex(currentNodeIndex);
+      if (maxChildNodeIndex == UNKNOWN_INDEX) {
+        // Left is always inserted before right, so a missing left child means there can't be a
+        // right child,
+        // which means this must already be a leaf position.
+        break;
+      }
+      long maxChildRowId = heapNodeBuffer.getRowId(maxChildNodeIndex);
+
+      long rightChildNodeIndex = heapNodeBuffer.getRightChildHeapIndex(currentNodeIndex);
+      if (rightChildNodeIndex != UNKNOWN_INDEX) {
+        long rightRowId = heapNodeBuffer.getRowId(rightChildNodeIndex);
+        if (strategy.compare(rightRowId, maxChildRowId) > 0) {
+          maxChildNodeIndex = rightChildNodeIndex;
+          maxChildRowId = rightRowId;
+        }
+      }
+
+      if (strategy.compare(newRowId, maxChildRowId) >= 0) {
+        // New row is greater than or equal to both children, so the heap invariant is satisfied by
+        // inserting the
+        // new row at this position
+        break;
+      }
+
+      // Swap the max child row value into the current node
+      heapNodeBuffer.setRowId(currentNodeIndex, maxChildRowId);
+
+      // Max child now has an unfilled vacancy, so continue processing with that as the current node
+      currentNodeIndex = maxChildNodeIndex;
+    }
+
+    heapNodeBuffer.setRowId(currentNodeIndex, newRowId);
+
+    if (contextEvictionListener != null) {
+      contextEvictionListener.accept(poppedRowId);
+    }
+  }
+
+  /**
+   * Buffer abstracting a mapping from group ID to a heap. The group ID provides the index for all
+   * operations.
+   */
+  private static class GroupIdToHeapBuffer {
+    private static final long INSTANCE_SIZE =
+        RamUsageEstimator.shallowSizeOfInstance(GroupIdToHeapBuffer.class);
+
+    /*
+     *  Memory layout:
+     *  [LONG] heapNodeIndex1,
+     *  [LONG] heapNodeIndex2,
+     *  ...
+     */
+    // Since we have a single element per group, this array is effectively indexed on group ID
+    private final LongBigArray heapIndexBuffer = new LongBigArray(UNKNOWN_INDEX);
+
+    /*
+     *  Memory layout:
+     *  [LONG] heapSize1,
+     *  [LONG] heapSize2,
+     *  ...
+     */
+    // Since we have a single element per group, this array is effectively indexed on group ID
+    private final LongBigArray sizeBuffer = new LongBigArray(0);
+
+    private int totalGroups;
+
+    public void allocateGroupIfNeeded(int groupId) {
+      if (totalGroups > groupId) {
+        return;
+      }
+      // Group IDs generated by GroupByHash are always generated consecutively starting from 0, so
+      // observing a
+      // group ID N means groups [0, N] inclusive must exist.
+      totalGroups = groupId + 1;
+      heapIndexBuffer.ensureCapacity(totalGroups);
+      sizeBuffer.ensureCapacity(totalGroups);
+    }
+
+    public int getTotalGroups() {
+      return totalGroups;
+    }
+
+    public long getHeapRootNodeIndex(int groupId) {
+      return heapIndexBuffer.get(groupId);
+    }
+
+    public void setHeapRootNodeIndex(int groupId, long heapNodeIndex) {
+      heapIndexBuffer.set(groupId, heapNodeIndex);
+    }
+
+    public long getHeapSize(int groupId) {
+      return sizeBuffer.get(groupId);
+    }
+
+    public void setHeapSize(int groupId, long count) {
+      sizeBuffer.set(groupId, count);
+    }
+
+    public void addHeapSize(int groupId, long delta) {
+      sizeBuffer.add(groupId, delta);
+    }
+
+    public void incrementHeapSize(int groupId) {
+      sizeBuffer.increment(groupId);
+    }
+
+    public long sizeOf() {
+      return INSTANCE_SIZE + heapIndexBuffer.sizeOf() + sizeBuffer.sizeOf();
+    }
+  }
+
+  /**
+   * Buffer abstracting storage of nodes in the heap. Nodes are referenced by their node index for
+   * operations.
+   */
+  private static class HeapNodeBuffer {
+    private static final long INSTANCE_SIZE =
+        RamUsageEstimator.shallowSizeOfInstance(HeapNodeBuffer.class);
+    private static final int POSITIONS_PER_ENTRY = 3;
+    private static final int LEFT_CHILD_HEAP_INDEX_OFFSET = 1;
+    private static final int RIGHT_CHILD_HEAP_INDEX_OFFSET = 2;
+
+    /*
+     *  Memory layout:
+     *  [LONG] rowId1, [LONG] leftChildNodeIndex1, [LONG] rightChildNodeIndex1,
+     *  [LONG] rowId2, [LONG] leftChildNodeIndex2, [LONG] rightChildNodeIndex2,
+     *  ...
+     */
+    private final LongBigArray buffer = new LongBigArray();
+
+    private final LongBigArrayFIFOQueue emptySlots = new LongBigArrayFIFOQueue();
+
+    private long capacity;
+
+    /**
+     * Allocates storage for a new heap node.
+     *
+     * @return index referencing the node
+     */
+    public long allocateNewNode(long rowId) {
+      long newHeapIndex;
+      if (!emptySlots.isEmpty()) {
+        newHeapIndex = emptySlots.dequeueLong();
+      } else {
+        newHeapIndex = capacity;
+        capacity++;
+        buffer.ensureCapacity(capacity * POSITIONS_PER_ENTRY);
+      }
+
+      setRowId(newHeapIndex, rowId);
+      setLeftChildHeapIndex(newHeapIndex, UNKNOWN_INDEX);
+      setRightChildHeapIndex(newHeapIndex, UNKNOWN_INDEX);
+
+      return newHeapIndex;
+    }
+
+    public void deallocate(long index) {
+      emptySlots.enqueue(index);
+    }
+
+    public long getActiveNodeCount() {
+      return capacity - emptySlots.longSize();
+    }
+
+    public long getRowId(long index) {
+      return buffer.get(index * POSITIONS_PER_ENTRY);
+    }
+
+    public void setRowId(long index, long rowId) {
+      buffer.set(index * POSITIONS_PER_ENTRY, rowId);
+    }
+
+    public long getLeftChildHeapIndex(long index) {
+      return buffer.get(index * POSITIONS_PER_ENTRY + LEFT_CHILD_HEAP_INDEX_OFFSET);
+    }
+
+    public void setLeftChildHeapIndex(long index, long childHeapIndex) {
+      buffer.set(index * POSITIONS_PER_ENTRY + LEFT_CHILD_HEAP_INDEX_OFFSET, childHeapIndex);
+    }
+
+    public long getRightChildHeapIndex(long index) {
+      return buffer.get(index * POSITIONS_PER_ENTRY + RIGHT_CHILD_HEAP_INDEX_OFFSET);
+    }
+
+    public void setRightChildHeapIndex(long index, long childHeapIndex) {
+      buffer.set(index * POSITIONS_PER_ENTRY + RIGHT_CHILD_HEAP_INDEX_OFFSET, childHeapIndex);
+    }
+
+    public long sizeOf() {
+      return INSTANCE_SIZE + buffer.sizeOf() + emptySlots.sizeOf();
+    }
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/GroupedTopNRowNumberBuilder.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/GroupedTopNRowNumberBuilder.java
new file mode 100644
index 00000000000..78c01ef14c0
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/GroupedTopNRowNumberBuilder.java
@@ -0,0 +1,192 @@
+/*
+ * 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.calc.execution.operator;
+
+import org.apache.iotdb.calc.execution.operator.source.relational.aggregation.grouped.array.LongBigArray;
+import org.apache.iotdb.commons.queryengine.execution.operator.source.relational.aggregation.grouped.hash.GroupByHash;
+
+import com.google.common.collect.AbstractIterator;
+import com.google.common.collect.ImmutableList;
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.tsfile.read.common.block.column.RunLengthEncodedColumn;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.Iterator;
+import java.util.List;
+
+import static org.apache.iotdb.calc.plan.planner.CommonOperatorUtils.TIME_COLUMN_TEMPLATE;
+
+public class GroupedTopNRowNumberBuilder implements GroupedTopNBuilder {
+  private static final long INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(GroupedTopNRowNumberBuilder.class);
+
+  private final List<TSDataType> sourceTypes;
+  private final boolean produceRowNumber;
+  private final int[] groupByChannels;
+  private final GroupByHash groupByHash;
+  private final RowReferenceTsBlockManager tsBlockManager = new RowReferenceTsBlockManager();
+  private final GroupedTopNRowNumberAccumulator groupedTopNRowNumberAccumulator;
+  private final TsBlockWithPositionComparator comparator;
+
+  private int effectiveGroupCount = 0;
+
+  public GroupedTopNRowNumberBuilder(
+      List<TSDataType> sourceTypes,
+      TsBlockWithPositionComparator comparator,
+      int topN,
+      boolean produceRowNumber,
+      int[] groupByChannels,
+      GroupByHash groupByHash) {
+    this.sourceTypes = sourceTypes;
+    this.produceRowNumber = produceRowNumber;
+    this.groupByChannels = groupByChannels;
+    this.groupByHash = groupByHash;
+    this.comparator = comparator;
+
+    this.groupedTopNRowNumberAccumulator =
+        new GroupedTopNRowNumberAccumulator(
+            (leftRowId, rightRowId) -> {
+              TsBlock leftTsBlock = tsBlockManager.getTsBlock(leftRowId);
+              int leftPosition = tsBlockManager.getPosition(leftRowId);
+              TsBlock rightTsBlock = tsBlockManager.getTsBlock(rightRowId);
+              int rightPosition = tsBlockManager.getPosition(rightRowId);
+              return comparator.compareTo(leftTsBlock, leftPosition, rightTsBlock, rightPosition);
+            },
+            topN,
+            tsBlockManager::dereference);
+  }
+
+  @Override
+  public void addTsBlock(TsBlock tsBlock) {
+    int[] groupIds;
+    if (groupByChannels.length == 0) {
+      groupIds = new int[tsBlock.getPositionCount()];
+      if (tsBlock.getPositionCount() > 0) {
+        effectiveGroupCount = 1;
+      }
+    } else {
+      groupIds = groupByHash.getGroupIds(tsBlock.getColumns(groupByChannels));
+      effectiveGroupCount = groupByHash.getGroupCount();
+    }
+
+    processTsBlock(tsBlock, effectiveGroupCount, groupIds);
+  }
+
+  @Override
+  public Iterator<TsBlock> getResult() {
+    return new ResultIterator();
+  }
+
+  @Override
+  public long getEstimatedSizeInBytes() {
+    return INSTANCE_SIZE
+        + groupByHash.getEstimatedSize()
+        + tsBlockManager.sizeOf()
+        + groupedTopNRowNumberAccumulator.sizeOf();
+  }
+
+  private void processTsBlock(TsBlock newTsBlock, int groupCount, int[] groupIds) {
+    int firstPositionToAdd =
+        groupedTopNRowNumberAccumulator.findFirstPositionToAdd(
+            newTsBlock, groupCount, groupIds, comparator, tsBlockManager);
+    if (firstPositionToAdd < 0) {
+      return;
+    }
+
+    try (RowReferenceTsBlockManager.LoadCursor loadCursor =
+        tsBlockManager.add(newTsBlock, firstPositionToAdd)) {
+      for (int position = firstPositionToAdd;
+          position < newTsBlock.getPositionCount();
+          position++) {
+        int groupId = groupIds[position];
+        loadCursor.advance();
+        groupedTopNRowNumberAccumulator.add(groupId, loadCursor);
+      }
+    }
+
+    tsBlockManager.compactIfNeeded();
+  }
+
+  private class ResultIterator extends AbstractIterator<TsBlock> {
+    private final TsBlockBuilder tsBlockBuilder;
+    private final int groupIdCount = effectiveGroupCount;
+    private int currentGroupId = -1;
+    private final LongBigArray rowIdOutput = new LongBigArray();
+    private long currentGroupSize;
+    private int currentIndexInGroup;
+
+    ResultIterator() {
+      ImmutableList.Builder<TSDataType> sourceTypesBuilders =
+          ImmutableList.<TSDataType>builder().addAll(sourceTypes);
+      if (produceRowNumber) {
+        sourceTypesBuilders.add(TSDataType.INT64);
+      }
+      tsBlockBuilder = new TsBlockBuilder(sourceTypesBuilders.build());
+    }
+
+    @Override
+    protected TsBlock computeNext() {
+      tsBlockBuilder.reset();
+      while (!tsBlockBuilder.isFull()) {
+        while (currentIndexInGroup >= currentGroupSize) {
+          if (currentGroupId + 1 >= groupIdCount) {
+            if (tsBlockBuilder.isEmpty()) {
+              return endOfData();
+            }
+            return tsBlockBuilder.build(
+                new RunLengthEncodedColumn(
+                    TIME_COLUMN_TEMPLATE, tsBlockBuilder.getPositionCount()));
+          }
+          currentGroupId++;
+          currentGroupSize = groupedTopNRowNumberAccumulator.drainTo(currentGroupId, rowIdOutput);
+          currentIndexInGroup = 0;
+        }
+
+        long rowId = rowIdOutput.get(currentIndexInGroup);
+        TsBlock tsBlock = tsBlockManager.getTsBlock(rowId);
+        int position = tsBlockManager.getPosition(rowId);
+        for (int i = 0; i < sourceTypes.size(); i++) {
+          ColumnBuilder builder = tsBlockBuilder.getColumnBuilder(i);
+          Column column = tsBlock.getColumn(i);
+          builder.write(column, position);
+        }
+        if (produceRowNumber) {
+          ColumnBuilder builder = tsBlockBuilder.getColumnBuilder(sourceTypes.size());
+          builder.writeLong(currentIndexInGroup + 1);
+        }
+        tsBlockBuilder.declarePosition();
+        currentIndexInGroup++;
+
+        // Deference the row for hygiene, but no need to compact them at this point
+        tsBlockManager.dereference(rowId);
+      }
+
+      if (tsBlockBuilder.isEmpty()) {
+        return endOfData();
+      }
+      return tsBlockBuilder.build(
+          new RunLengthEncodedColumn(TIME_COLUMN_TEMPLATE, tsBlockBuilder.getPositionCount()));
+    }
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/IdRegistry.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/IdRegistry.java
new file mode 100644
index 00000000000..bb5abd17ddd
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/IdRegistry.java
@@ -0,0 +1,76 @@
+/*
+ * 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.calc.execution.operator;
+
+import org.apache.iotdb.calc.execution.operator.source.relational.aggregation.grouped.array.IntArrayFIFOQueue;
+
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.HashMap;
+import java.util.function.IntFunction;
+
+public class IdRegistry<T> {
+  private static final long INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(IdRegistry.class);
+
+  private final HashMap<Integer, T> objects = new HashMap<>();
+  private final IntFIFOQueue emptySlots = new IntFIFOQueue();
+
+  /**
+   * Provides a new ID referencing the provided object.
+   *
+   * @return ID referencing the provided object
+   */
+  public T allocateId(IntFunction<T> factory) {
+    T result;
+    if (emptySlots.size() != 0) {
+      int id = emptySlots.dequeueInt();
+      result = factory.apply(id);
+      objects.put(id, result);
+    } else {
+      result = factory.apply(objects.size());
+      objects.put(objects.size(), result);
+    }
+    return result;
+  }
+
+  public void deallocate(int id) {
+    objects.remove(id);
+    emptySlots.enqueue(id);
+  }
+
+  public T get(int id) {
+    return objects.get(id);
+  }
+
+  /** Does not include the sizes of the referenced objects themselves. */
+  public long sizeOf() {
+    return INSTANCE_SIZE + RamUsageEstimator.sizeOfMap(objects) + emptySlots.sizeOf();
+  }
+
+  private static class IntFIFOQueue extends IntArrayFIFOQueue {
+    private static final long INSTANCE_SIZE =
+        RamUsageEstimator.shallowSizeOfInstance(IntFIFOQueue.class);
+
+    public long sizeOf() {
+      return INSTANCE_SIZE + RamUsageEstimator.sizeOf(array);
+    }
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/Operator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/Operator.java
new file mode 100644
index 00000000000..a2c937e0bb7
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/Operator.java
@@ -0,0 +1,134 @@
+/*
+ * 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.calc.execution.operator;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.utils.Accountable;
+
+import static com.google.common.util.concurrent.Futures.immediateVoidFuture;
+
+public interface Operator extends AutoCloseable, Accountable {
+
+  ListenableFuture<?> NOT_BLOCKED = immediateVoidFuture();
+
+  CommonOperatorContext getOperatorContext();
+
+  /**
+   * Returns a future that will be completed when the operator becomes unblocked. If the operator is
+   * not blocked, this method should return {@code NOT_BLOCKED}.
+   */
+  @SuppressWarnings("squid:S1452")
+  default ListenableFuture<?> isBlocked() {
+    return NOT_BLOCKED;
+  }
+
+  default TsBlock nextWithTimer() throws Exception {
+    CommonOperatorContext context = getOperatorContext();
+    long startTime = System.nanoTime();
+    TsBlock output = null;
+    try {
+      output = next();
+    } finally {
+      context.recordExecutionTime(System.nanoTime() - startTime);
+      if (output != null) {
+        context.addOutputRows(output.getPositionCount());
+      }
+      context.recordNextCalled();
+    }
+    return output;
+  }
+
+  /**
+   * Gets next tsBlock from this operator. If no data is currently available, return null.
+   *
+   * @throws Exception Error happened while fetching next batch
+   */
+  @SuppressWarnings("squid:S112")
+  TsBlock next() throws Exception;
+
+  default boolean hasNextWithTimer() throws Exception {
+    CommonOperatorContext context = getOperatorContext();
+    long startTime = System.nanoTime();
+
+    try {
+      return hasNext();
+    } finally {
+      context.recordExecutionTime(System.nanoTime() - startTime);
+      context.recordHasNextCalled();
+    }
+  }
+
+  default long calculateMaxPeekMemoryWithCounter() {
+    long maxPeekMemory = calculateMaxPeekMemory();
+    getOperatorContext().setEstimatedMemorySize(maxPeekMemory);
+    return maxPeekMemory;
+  }
+
+  /**
+   * return true if the operator has more data, otherwise false.
+   *
+   * @throws Exception Error happened while judging whether there exists next batch
+   */
+  @SuppressWarnings("squid:S112")
+  boolean hasNext() throws Exception;
+
+  /**
+   * The close method cleans up the resources occupied by this Operator. This method will always be
+   * called before releasing the Operator reference.
+   *
+   * <p><b>Note:</b> If this Operator has child Operators, please ensure that child operators are
+   * also closed.
+   *
+   * @throws Exception An exception occurred during the close operation.
+   */
+  @Override
+  void close() throws Exception;
+
+  /**
+   * Is this operator completely finished processing and no more output TsBlock will be produced.
+   *
+   * @throws Exception Error happened while judging whether operator is finished
+   */
+  @SuppressWarnings("squid:S112")
+  boolean isFinished() throws Exception;
+
+  /**
+   * We should also consider the memory used by its children operator, so the calculation logic may
+   * be like: long estimatedOfCurrentOperator = XXXXX; return max(estimatedOfCurrentOperator,
+   * child1.calculateMaxPeekMemory(), child2.calculateMaxPeekMemory(), ....).
+   *
+   * <p>Each operator's MaxPeekMemory should also take retained size of each child operator into
+   * account.
+   *
+   * @return estimated max memory footprint that the Operator Tree(rooted from this operator) will
+   *     use while doing its own read processing
+   */
+  long calculateMaxPeekMemory();
+
+  /** return estimated max memory footprint for returned TsBlock when calling operator.next(). */
+  long calculateMaxReturnSize();
+
+  /**
+   * return each operator's retained size(including all its children's retained size) after calling
+   * its next() method.
+   */
+  long calculateRetainedSizeAfterCallingNext();
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/RowIdComparisonStrategy.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/RowIdComparisonStrategy.java
new file mode 100644
index 00000000000..02b28466efa
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/RowIdComparisonStrategy.java
@@ -0,0 +1,24 @@
+/*
+ * 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.calc.execution.operator;
+
+public interface RowIdComparisonStrategy {
+  int compare(long leftRowId, long rightRowId);
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/RowIdHashStrategy.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/RowIdHashStrategy.java
new file mode 100644
index 00000000000..984efa9a96c
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/RowIdHashStrategy.java
@@ -0,0 +1,27 @@
+/*
+ * 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.calc.execution.operator;
+
+/** Hash strategy that evaluates over row IDs */
+public interface RowIdHashStrategy {
+  boolean equals(long leftRowId, long rightRowId);
+
+  long hashCode(long rowId);
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/RowReference.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/RowReference.java
new file mode 100644
index 00000000000..b56c9f8983f
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/RowReference.java
@@ -0,0 +1,45 @@
+/*
+ * 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.calc.execution.operator;
+
+/**
+ * Reference to a row.
+ *
+ * <p>Note: RowReference gives us the ability to defer row ID generation (which can be expensive in
+ * tight loops).
+ */
+public interface RowReference {
+  /**
+   * Compares the referenced row to the specified row ID using the provided RowIdComparisonStrategy.
+   */
+  int compareTo(RowIdComparisonStrategy strategy, long rowId);
+
+  /**
+   * Checks equality of the referenced row with the specified row ID using the provided
+   * RowIdHashStrategy.
+   */
+  boolean equals(RowIdHashStrategy strategy, long rowId);
+
+  /** Calculates the hash of the referenced row using the provided RowIdHashStrategy. */
+  long hash(RowIdHashStrategy strategy);
+
+  /** Allocate a stable row ID that can be used to reference this row at a future point. */
+  long allocateRowId();
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/RowReferenceTsBlockManager.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/RowReferenceTsBlockManager.java
new file mode 100644
index 00000000000..dd81ab2f55f
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/RowReferenceTsBlockManager.java
@@ -0,0 +1,386 @@
+/*
+ * 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.calc.execution.operator;
+
+import org.apache.iotdb.calc.execution.operator.source.relational.aggregation.grouped.array.IntBigArray;
+import org.apache.iotdb.calc.execution.operator.source.relational.aggregation.grouped.array.LongBigArrayFIFOQueue;
+
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Verify.verify;
+
+public class RowReferenceTsBlockManager {
+  private static final long INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(RowReferenceTsBlockManager.class);
+  private static final long TSBLOCK_ACCOUNTING_INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(TsBlockAccounting.class);
+  private static final int RESERVED_ROW_ID_FOR_CURSOR = -1;
+
+  private final IdRegistry<TsBlockAccounting> tsBlocks = new IdRegistry<>();
+  private final RowIdBuffer rowIdBuffer = new RowIdBuffer();
+  private final HashSet<Integer> compactionCandidates = new HashSet<>();
+
+  private LoadCursor currentCursor;
+  private long tsBlockBytes;
+
+  public LoadCursor add(TsBlock tsBlock) {
+    return add(tsBlock, 0);
+  }
+
+  public LoadCursor add(TsBlock tsBlock, int startingPosition) {
+    checkState(currentCursor == null, "Cursor still active");
+    checkArgument(
+        startingPosition >= 0 && startingPosition <= tsBlock.getPositionCount(),
+        "invalid startingPosition: %s",
+        startingPosition);
+
+    TsBlockAccounting tsBlockAccounting =
+        tsBlocks.allocateId(id -> new TsBlockAccounting(id, tsBlock));
+
+    tsBlockAccounting.lockTsBlock();
+    currentCursor =
+        new LoadCursor(
+            tsBlockAccounting,
+            startingPosition,
+            () -> {
+              // Initiate additional actions on close
+              checkState(currentCursor != null);
+              tsBlockAccounting.unlockTsBlock();
+              tsBlockAccounting.loadTsBlockLoadIfNeeded();
+              // Account for tsBlock size after lazy loading (which can change the tsBlock size)
+              tsBlockBytes += tsBlockAccounting.sizeOf();
+              currentCursor = null;
+
+              checkTsBlockMaintenance(tsBlockAccounting);
+            });
+
+    return currentCursor;
+  }
+
+  public void dereference(long rowId) {
+    TsBlockAccounting tsBlockAccounting = tsBlocks.get(rowIdBuffer.getTsBlockId(rowId));
+    tsBlockAccounting.dereference(rowId);
+    checkTsBlockMaintenance(tsBlockAccounting);
+  }
+
+  private void checkTsBlockMaintenance(TsBlockAccounting tsBlockAccounting) {
+    int tsBlockId = tsBlockAccounting.getTsBlockId();
+    if (tsBlockAccounting.isPruneEligible()) {
+      compactionCandidates.remove(tsBlockId);
+      tsBlocks.deallocate(tsBlockId);
+      tsBlockBytes -= tsBlockAccounting.sizeOf();
+    } else if (tsBlockAccounting.isCompactionEligible()) {
+      compactionCandidates.add(tsBlockId);
+    }
+  }
+
+  public TsBlock getTsBlock(long rowId) {
+    if (isCursorRowId(rowId)) {
+      checkState(currentCursor != null, "No active cursor");
+      return currentCursor.getTsBlock();
+    }
+    int tsBlockId = rowIdBuffer.getTsBlockId(rowId);
+    return tsBlocks.get(tsBlockId).getTsBlock();
+  }
+
+  public int getPosition(long rowId) {
+    if (isCursorRowId(rowId)) {
+      checkState(currentCursor != null, "No active cursor");
+      // rowId for cursors only reference the single current position
+      return currentCursor.getCurrentPosition();
+    }
+    return rowIdBuffer.getPosition(rowId);
+  }
+
+  private static boolean isCursorRowId(long rowId) {
+    return rowId == RESERVED_ROW_ID_FOR_CURSOR;
+  }
+
+  public void compactIfNeeded() {
+    for (int tsBlockId : compactionCandidates) {
+      TsBlockAccounting tsBlockAccounting = tsBlocks.get(tsBlockId);
+      tsBlockBytes -= tsBlockAccounting.sizeOf();
+      tsBlockAccounting.compact();
+      tsBlockBytes += tsBlockAccounting.sizeOf();
+    }
+    compactionCandidates.clear();
+  }
+
+  public long sizeOf() {
+    return INSTANCE_SIZE
+        + tsBlockBytes
+        + tsBlocks.sizeOf()
+        + rowIdBuffer.sizeOf()
+        + RamUsageEstimator.sizeOfHashSet(compactionCandidates);
+  }
+
+  /**
+   * Cursor that allows callers to advance through the registered page and dictate whether a
+   * specific position should be preserved with a stable row ID. Row ID generation can be expensive
+   * in tight loops, so this allows callers to quickly skip positions that won't be needed.
+   */
+  public static final class LoadCursor implements RowReference, AutoCloseable {
+    private final TsBlockAccounting tsBlockAccounting;
+    private final Runnable closeCallback;
+
+    private int currentPosition;
+
+    private LoadCursor(
+        TsBlockAccounting tsBlockAccounting, int startingPosition, Runnable closeCallback) {
+      this.tsBlockAccounting = tsBlockAccounting;
+      this.currentPosition = startingPosition - 1;
+      this.closeCallback = closeCallback;
+    }
+
+    private TsBlock getTsBlock() {
+      return tsBlockAccounting.getTsBlock();
+    }
+
+    private int getCurrentPosition() {
+      checkState(currentPosition >= 0, "Not yet advanced");
+      return currentPosition;
+    }
+
+    public boolean advance() {
+      if (currentPosition >= tsBlockAccounting.getTsBlock().getPositionCount() - 1) {
+        return false;
+      }
+      currentPosition++;
+      return true;
+    }
+
+    @Override
+    public int compareTo(RowIdComparisonStrategy strategy, long rowId) {
+      checkState(currentPosition >= 0, "Not yet advanced");
+      return strategy.compare(RESERVED_ROW_ID_FOR_CURSOR, rowId);
+    }
+
+    @Override
+    public boolean equals(RowIdHashStrategy strategy, long rowId) {
+      checkState(currentPosition >= 0, "Not yet advanced");
+      return strategy.equals(RESERVED_ROW_ID_FOR_CURSOR, rowId);
+    }
+
+    @Override
+    public long hash(RowIdHashStrategy strategy) {
+      checkState(currentPosition >= 0, "Not yet advanced");
+      return strategy.hashCode(RESERVED_ROW_ID_FOR_CURSOR);
+    }
+
+    @Override
+    public long allocateRowId() {
+      checkState(currentPosition >= 0, "Not yet advanced");
+      return tsBlockAccounting.referencePosition(currentPosition);
+    }
+
+    @Override
+    public void close() {
+      closeCallback.run();
+    }
+  }
+
+  private final class TsBlockAccounting {
+    private static final int COMPACTION_MIN_FILL_MULTIPLIER = 2;
+
+    private final int tsBlockId;
+    private TsBlock tsBlock;
+    private boolean isTsBlockLoaded;
+    private long[] rowIds;
+    // Start off locked to give the caller time to declare which rows to reference
+    private boolean lockedTsBlock = true;
+    private int activePositions;
+
+    public TsBlockAccounting(int tsBlockId, TsBlock tsBlock) {
+      this.tsBlockId = tsBlockId;
+      this.tsBlock = tsBlock;
+      rowIds = new long[tsBlock.getPositionCount()];
+      Arrays.fill(rowIds, RowIdBuffer.UNKNOWN_ID);
+    }
+
+    /** Record the position as referenced and return a corresponding stable row ID */
+    public long referencePosition(int position) {
+      long rowId = rowIds[position];
+      if (rowId == RowIdBuffer.UNKNOWN_ID) {
+        rowId = rowIdBuffer.allocateRowId(tsBlockId, position);
+        rowIds[position] = rowId;
+        activePositions++;
+      }
+      return rowId;
+    }
+
+    /**
+     * Locks the current TsBlock so that it can't be compacted (thus allowing for stable
+     * position-based access).
+     */
+    public void lockTsBlock() {
+      lockedTsBlock = true;
+    }
+
+    /** Unlocks the current TsBlock so that it becomes eligible for compaction. */
+    public void unlockTsBlock() {
+      lockedTsBlock = false;
+    }
+
+    public int getTsBlockId() {
+      return tsBlockId;
+    }
+
+    public TsBlock getTsBlock() {
+      return tsBlock;
+    }
+
+    /** Dereferences the row ID from this TsBlock. */
+    public void dereference(long rowId) {
+      int position = rowIdBuffer.getPosition(rowId);
+      checkArgument(rowId == rowIds[position], "rowId does not match this TsBlock");
+      rowIds[position] = RowIdBuffer.UNKNOWN_ID;
+      activePositions--;
+      rowIdBuffer.deallocate(rowId);
+    }
+
+    public boolean isPruneEligible() {
+      // Pruning is only allowed if the TsBlock is unlocked
+      return !lockedTsBlock && activePositions == 0;
+    }
+
+    public boolean isCompactionEligible() {
+      // Compaction is only allowed if the TsBlock is unlocked
+      return !lockedTsBlock
+          && activePositions * COMPACTION_MIN_FILL_MULTIPLIER < tsBlock.getPositionCount();
+    }
+
+    public void loadTsBlockLoadIfNeeded() {
+      if (!isTsBlockLoaded && activePositions > 0) {
+        //        tsBlock = tsBlock.getLoadedPage();
+        isTsBlockLoaded = true;
+      }
+    }
+
+    public void compact() {
+      checkState(!lockedTsBlock, "Should not attempt compaction when TsBlock is locked");
+
+      if (activePositions == tsBlock.getPositionCount()) {
+        return;
+      }
+
+      loadTsBlockLoadIfNeeded();
+
+      int newIndex = 0;
+      int[] positionsToKeep = new int[activePositions];
+      long[] newRowIds = new long[activePositions];
+      for (int i = 0; i < tsBlock.getPositionCount() && newIndex < positionsToKeep.length; i++) {
+        long rowId = rowIds[i];
+        positionsToKeep[newIndex] = i;
+        newRowIds[newIndex] = rowId;
+        newIndex += rowId == RowIdBuffer.UNKNOWN_ID ? 0 : 1;
+      }
+      verify(newIndex == activePositions);
+      for (int i = 0; i < newRowIds.length; i++) {
+        rowIdBuffer.setPosition(newRowIds[i], i);
+      }
+
+      // Compact TsBlock
+      //      page = page.copyPositions(positionsToKeep, 0, positionsToKeep.length);
+      rowIds = newRowIds;
+    }
+
+    public long sizeOf() {
+      // Getting the size of a TsBlock forces a lazy TsBlock to be loaded, so only provide the size
+      // after
+      // an explicit decision to load
+      long loadedTsBlockSize = isTsBlockLoaded ? tsBlock.getSizeInBytes() : 0;
+      return TSBLOCK_ACCOUNTING_INSTANCE_SIZE
+          + loadedTsBlockSize
+          + RamUsageEstimator.sizeOf(rowIds);
+    }
+  }
+
+  /**
+   * Buffer abstracting a mapping between row IDs and their associated TsBlock IDs and positions.
+   */
+  private static class RowIdBuffer {
+    public static final long UNKNOWN_ID = -1;
+    private static final long INSTANCE_SIZE =
+        RamUsageEstimator.shallowSizeOfInstance(RowIdBuffer.class);
+
+    /*
+     *  Memory layout:
+     *  [INT] TsBlockId1, [INT] position1,
+     *  [INT] TsBlockId2, [INT] position2,
+     *  ...
+     */
+    private final IntBigArray buffer = new IntBigArray();
+
+    private final LongBigArrayFIFOQueue emptySlots = new LongBigArrayFIFOQueue();
+
+    private long capacity;
+
+    /**
+     * Provides a new row ID referencing the provided TsBlock position.
+     *
+     * @return ID referencing the provided TsBlock position
+     */
+    public long allocateRowId(int tsBlockId, int position) {
+      long newRowId;
+      if (!emptySlots.isEmpty()) {
+        newRowId = emptySlots.dequeueLong();
+      } else {
+        newRowId = capacity;
+        capacity++;
+        buffer.ensureCapacity(capacity * 2);
+      }
+
+      setTsBlockId(newRowId, tsBlockId);
+      setPosition(newRowId, position);
+
+      return newRowId;
+    }
+
+    public void deallocate(long rowId) {
+      emptySlots.enqueue(rowId);
+    }
+
+    public int getTsBlockId(long rowId) {
+      return buffer.get(rowId * 2);
+    }
+
+    public void setTsBlockId(long rowId, int tsBlockId) {
+      buffer.set(rowId * 2, tsBlockId);
+    }
+
+    public int getPosition(long rowId) {
+      return buffer.get(rowId * 2 + 1);
+    }
+
+    public void setPosition(long rowId, int position) {
+      buffer.set(rowId * 2 + 1, position);
+    }
+
+    public long sizeOf() {
+      return INSTANCE_SIZE + buffer.sizeOf() + emptySlots.sizeOf();
+    }
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/SimpleTsBlockWithPositionComparator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/SimpleTsBlockWithPositionComparator.java
new file mode 100644
index 00000000000..8cab1352032
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/SimpleTsBlockWithPositionComparator.java
@@ -0,0 +1,52 @@
+/*
+ * 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.calc.execution.operator;
+
+import org.apache.iotdb.calc.execution.operator.process.join.merge.MergeSortComparator;
+import org.apache.iotdb.calc.utils.datastructure.MergeSortKey;
+import org.apache.iotdb.calc.utils.datastructure.SortKey;
+import org.apache.iotdb.commons.queryengine.plan.relational.planner.SortOrder;
+
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.block.TsBlock;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+
+public class SimpleTsBlockWithPositionComparator implements TsBlockWithPositionComparator {
+  private final Comparator<SortKey> comparator;
+
+  public SimpleTsBlockWithPositionComparator(
+      List<TSDataType> types, List<Integer> sortChannels, List<SortOrder> sortOrders) {
+    List<TSDataType> sortedTypes = new ArrayList<>();
+    for (Integer sortChannel : sortChannels) {
+      sortedTypes.add(types.get(sortChannel));
+    }
+    this.comparator =
+        MergeSortComparator.getComparatorForTable(sortOrders, sortChannels, sortedTypes);
+  }
+
+  @Override
+  public int compareTo(TsBlock left, int leftPosition, TsBlock right, int rightPosition) {
+    return comparator.compare(
+        new MergeSortKey(left, leftPosition), new MergeSortKey(right, rightPosition));
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/TsBlockWithPositionComparator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/TsBlockWithPositionComparator.java
new file mode 100644
index 00000000000..e8b50d7ab73
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/TsBlockWithPositionComparator.java
@@ -0,0 +1,26 @@
+/*
+ * 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.calc.execution.operator;
+
+import org.apache.tsfile.read.common.block.TsBlock;
+
+public interface TsBlockWithPositionComparator {
+  int compareTo(TsBlock left, int leftPosition, TsBlock right, int rightPosition);
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AbstractConsumeAllOperator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AbstractConsumeAllOperator.java
new file mode 100644
index 00000000000..c774023ca90
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AbstractConsumeAllOperator.java
@@ -0,0 +1,192 @@
+/*
+ * 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.calc.execution.operator.process;
+
+import org.apache.iotdb.calc.execution.operator.AbstractOperator;
+import org.apache.iotdb.calc.execution.operator.CommonOperatorContext;
+import org.apache.iotdb.calc.execution.operator.Operator;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.apache.tsfile.read.common.block.TsBlock;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static com.google.common.util.concurrent.Futures.successfulAsList;
+
+/** ConsumeAllOperator will consume all children's result every time. */
+public abstract class AbstractConsumeAllOperator extends AbstractOperator
+    implements ProcessOperator {
+  protected final List<Operator> children;
+  protected final int inputOperatorsCount;
+
+  /** TsBlock from child operator. Only one cache now. */
+  protected TsBlock[] inputTsBlocks;
+
+  protected final boolean[] canCallNext;
+  protected int readyChildIndex;
+
+  /** Index of the child that is currently fetching input */
+  protected int currentChildIndex = 0;
+
+  /** Indicate whether we found an empty child input in one loop */
+  protected boolean hasEmptyChildInput = false;
+
+  protected AbstractConsumeAllOperator(
+      CommonOperatorContext operatorContext, List<Operator> children) {
+    this.operatorContext = operatorContext;
+    this.children = children;
+    this.inputOperatorsCount = children.size();
+    this.inputTsBlocks = new TsBlock[inputOperatorsCount];
+    this.canCallNext = new boolean[inputOperatorsCount];
+    for (int i = 0; i < inputOperatorsCount; i++) {
+      canCallNext[i] = false;
+    }
+  }
+
+  @Override
+  public ListenableFuture<?> isBlocked() {
+    boolean hasReadyChild = false;
+    readyChildIndex = 0;
+    List<ListenableFuture<?>> listenableFutures = new ArrayList<>();
+    for (int i = 0; i < inputOperatorsCount; i++) {
+      if (!isEmpty(i) || children.get(i) == null) {
+        continue;
+      }
+      ListenableFuture<?> blocked = children.get(i).isBlocked();
+      if (blocked.isDone()) {
+        hasReadyChild = true;
+        canCallNext[i] = true;
+        readyChildIndex = i;
+      } else {
+        listenableFutures.add(blocked);
+      }
+    }
+    return (hasReadyChild || listenableFutures.isEmpty())
+        ? NOT_BLOCKED
+        : successfulAsList(listenableFutures);
+  }
+
+  /**
+   * Try to cache one result of each child.
+   *
+   * @return true if results of all children are ready. Return false if some children is blocked or
+   *     return null.
+   * @throws Exception errors happened while getting tsblock from children
+   */
+  protected boolean prepareInput() throws Exception {
+    // start stopwatch
+    long maxRuntime = operatorContext.getMaxRunTime().roundTo(TimeUnit.NANOSECONDS);
+    long start = System.nanoTime();
+
+    while (System.nanoTime() - start < maxRuntime && currentChildIndex < inputOperatorsCount) {
+      if (canSkipCurrentChild(currentChildIndex)) {
+        currentChildIndex++;
+        continue;
+      }
+      if (canCallNext[currentChildIndex]) {
+        if (children.get(currentChildIndex).hasNextWithTimer()) {
+          inputTsBlocks[currentChildIndex] = getNextTsBlock(currentChildIndex);
+          canCallNext[currentChildIndex] = false;
+          // child operator has next but return an empty TsBlock which means that it may not
+          // finish calculation in given time slice.
+          // In such case, TimeJoinOperator can't go on calculating, so we just return null.
+          // We can also use the while loop here to continuously call the hasNext() and next()
+          // methods of the child operator until its hasNext() returns false or the next() gets
+          // the data that is not empty, but this will cause the execution time of the while loop
+          // to be uncontrollable and may exceed all allocated time slice
+          if (isEmpty(currentChildIndex)) {
+            hasEmptyChildInput = true;
+          } else {
+            processCurrentInputTsBlock(currentChildIndex);
+          }
+        } else {
+          handleFinishedChild(currentChildIndex);
+        }
+      } else {
+        hasEmptyChildInput = true;
+      }
+      currentChildIndex++;
+    }
+
+    if (currentChildIndex == inputOperatorsCount) {
+      // start a new loop
+      currentChildIndex = 0;
+      if (!hasEmptyChildInput) {
+        // all children are ready now
+        return true;
+      } else {
+        // In a new loop, previously empty child input could be non-empty now, and we can skip the
+        // children that have generated input
+        hasEmptyChildInput = false;
+      }
+    }
+    return false;
+  }
+
+  /** If the tsBlock is null or has no more data in the tsBlock, return true; else return false. */
+  protected boolean isEmpty(int index) {
+    return inputTsBlocks[index] == null || inputTsBlocks[index].isEmpty();
+  }
+
+  // region helper function used in prepareInput, the subclass can have its own implementation
+
+  /**
+   * @param currentChildIndex the index of the child
+   * @return true if we can skip the currentChild in prepareInput
+   */
+  protected boolean canSkipCurrentChild(int currentChildIndex) {
+    return !isEmpty(currentChildIndex) || children.get(currentChildIndex) == null;
+  }
+
+  /**
+   * @param currentInputIndex index of the input TsBlock
+   */
+  protected void processCurrentInputTsBlock(int currentInputIndex) {
+    // do nothing here, the subclass have its own implementation
+  }
+
+  /**
+   * @param currentChildIndex the index of the child
+   * @throws Exception Potential Exception thrown by Operator.close()
+   */
+  protected void handleFinishedChild(int currentChildIndex) throws Exception {
+    children.get(currentChildIndex).close();
+    children.set(currentChildIndex, null);
+  }
+
+  // endregion
+
+  @Override
+  public void close() throws Exception {
+    for (Operator child : children) {
+      if (child != null) {
+        child.close();
+      }
+    }
+    // friendly for gc
+    inputTsBlocks = null;
+  }
+
+  protected TsBlock getNextTsBlock(int childIndex) throws Exception {
+    return children.get(childIndex).nextWithTimer();
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AbstractFillOperator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AbstractFillOperator.java
new file mode 100644
index 00000000000..e354c6e9e62
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AbstractFillOperator.java
@@ -0,0 +1,128 @@
+/*
+ * 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.calc.execution.operator.process;
+
+import org.apache.iotdb.calc.execution.operator.CommonOperatorContext;
+import org.apache.iotdb.calc.execution.operator.Operator;
+import org.apache.iotdb.calc.execution.operator.process.fill.IFill;
+import org.apache.iotdb.commons.queryengine.execution.MemoryEstimationHelper;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
+/** Used for previous and constant value fill. */
+public abstract class AbstractFillOperator implements ProcessOperator {
+
+  private static final long INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(AbstractFillOperator.class);
+  private final CommonOperatorContext operatorContext;
+  private final IFill[] fillArray;
+  private final Operator child;
+  private final int outputColumnCount;
+
+  protected AbstractFillOperator(
+      CommonOperatorContext operatorContext, IFill[] fillArray, Operator child) {
+    this.operatorContext = requireNonNull(operatorContext, "operatorContext is null");
+    checkArgument(
+        fillArray != null && fillArray.length > 0, "fillArray should not be null or empty");
+    this.fillArray = fillArray;
+    this.child = requireNonNull(child, "child operator is null");
+    this.outputColumnCount = fillArray.length;
+  }
+
+  @Override
+  public CommonOperatorContext getOperatorContext() {
+    return operatorContext;
+  }
+
+  @Override
+  public ListenableFuture<?> isBlocked() {
+    return child.isBlocked();
+  }
+
+  @Override
+  public TsBlock next() throws Exception {
+    TsBlock block = child.nextWithTimer();
+    if (block == null) {
+      return null;
+    }
+
+    checkArgument(
+        outputColumnCount == block.getValueColumnCount(),
+        "outputColumnCount is not equal to value column count of child operator's TsBlock");
+
+    Column[] valueColumns = new Column[outputColumnCount];
+
+    for (int i = 0; i < outputColumnCount; i++) {
+      valueColumns[i] = fillArray[i].fill(getHelperColumn(block), block.getColumn(i));
+    }
+
+    return TsBlock.wrapBlocksWithoutCopy(
+        block.getPositionCount(), block.getTimeColumn(), valueColumns);
+  }
+
+  protected abstract Column getHelperColumn(TsBlock tsBlock);
+
+  @Override
+  public boolean hasNext() throws Exception {
+    return child.hasNextWithTimer();
+  }
+
+  @Override
+  public void close() throws Exception {
+    child.close();
+  }
+
+  @Override
+  public boolean isFinished() throws Exception {
+    return child.isFinished();
+  }
+
+  @Override
+  public long calculateMaxPeekMemory() {
+    // while doing constant and previous fill, we may need to copy the corresponding column if there
+    // exists null values
+    // so the max peek memory may be double
+    return 2 * child.calculateMaxPeekMemory() + child.calculateRetainedSizeAfterCallingNext();
+  }
+
+  @Override
+  public long calculateRetainedSizeAfterCallingNext() {
+    // we can safely ignore one line cached in IFill
+    return child.calculateRetainedSizeAfterCallingNext();
+  }
+
+  @Override
+  public long calculateMaxReturnSize() {
+    return child.calculateMaxReturnSize();
+  }
+
+  @Override
+  public long ramBytesUsed() {
+    return INSTANCE_SIZE
+        + MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(child)
+        + MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(operatorContext);
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AbstractLinearFillOperator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AbstractLinearFillOperator.java
new file mode 100644
index 00000000000..2e523d1bf4c
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AbstractLinearFillOperator.java
@@ -0,0 +1,275 @@
+/*
+ * 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.calc.execution.operator.process;
+
+import org.apache.iotdb.calc.execution.operator.CommonOperatorContext;
+import org.apache.iotdb.calc.execution.operator.Operator;
+import org.apache.iotdb.calc.execution.operator.process.fill.ILinearFill;
+import org.apache.iotdb.commons.queryengine.execution.MemoryEstimationHelper;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
+public abstract class AbstractLinearFillOperator implements ProcessOperator {
+
+  private static final long INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(AbstractLinearFillOperator.class);
+  private final CommonOperatorContext operatorContext;
+  protected final ILinearFill[] fillArray;
+  private final Operator child;
+  protected final int outputColumnCount;
+  private final List<TsBlock> cachedTsBlock;
+
+  private final List<Long> cachedRowIndex;
+
+  private final List<Integer> cachedLastRowIndexForNonNullHelperColumn;
+
+  private long currentRowIndex = 0;
+  // next TsBlock Index for each Column
+  private final int[] nextTsBlockIndex;
+
+  /**
+   * indicate whether we can call child.next(). it's used to make sure that child.next() will only
+   * be called once in AbstractLinearFillOperator.next().
+   */
+  private boolean canCallNext;
+
+  // indicate whether there is more TsBlock for child operator
+  protected boolean noMoreTsBlock;
+
+  protected AbstractLinearFillOperator(
+      CommonOperatorContext operatorContext, ILinearFill[] fillArray, Operator child) {
+    this.operatorContext = requireNonNull(operatorContext, "operatorContext is null");
+    checkArgument(
+        fillArray != null && fillArray.length > 0, "fillArray should not be null or empty");
+    this.fillArray = fillArray;
+    this.child = requireNonNull(child, "child operator is null");
+    this.outputColumnCount = fillArray.length;
+    this.cachedTsBlock = new ArrayList<>();
+    this.cachedRowIndex = new ArrayList<>();
+    this.cachedLastRowIndexForNonNullHelperColumn = new ArrayList<>();
+    this.nextTsBlockIndex = new int[outputColumnCount];
+    Arrays.fill(this.nextTsBlockIndex, 1);
+    this.canCallNext = false;
+    this.noMoreTsBlock = true;
+  }
+
+  @Override
+  public CommonOperatorContext getOperatorContext() {
+    return operatorContext;
+  }
+
+  @Override
+  public ListenableFuture<?> isBlocked() {
+    return child.isBlocked();
+  }
+
+  @SuppressWarnings("squid:S3776")
+  @Override
+  public TsBlock next() throws Exception {
+
+    // make sure we call child.next() at most once
+    if (cachedTsBlock.isEmpty() && !tryToGetNextTsBlock()) {
+      return null;
+    }
+
+    TsBlock tempResult = null;
+    while (tempResult == null && !cachedTsBlock.isEmpty()) {
+      TsBlock originTsBlock = cachedTsBlock.get(0);
+      long currentEndRowIndex =
+          cachedRowIndex.get(0) + cachedLastRowIndexForNonNullHelperColumn.get(0);
+      // Step 1: judge whether we can fill current TsBlock, if TsBlock that we can get is not
+      // enough,
+      // we just return null
+      for (int columnIndex = 0; columnIndex < outputColumnCount; columnIndex++) {
+        // current valueColumn can't be filled using current information
+        if (fillArray[columnIndex].needPrepareForNext(
+            currentEndRowIndex,
+            originTsBlock.getColumn(columnIndex),
+            cachedLastRowIndexForNonNullHelperColumn.get(0))) {
+          // current cached TsBlock is not enough to fill this column
+          while (!isCachedTsBlockEnough(columnIndex, currentEndRowIndex)) {
+            // if we failed to get next TsBlock
+            if (!tryToGetNextTsBlock()) {
+              // there is no more TsBlock for current group, so we have to fill this Column
+              if (noMoreTsBlockForCurrentGroup()) {
+                // break the while-loop, continue to judge next Column
+                break;
+              } else {
+                // there is still more TsBlock, so current calculation is not finished, and we just
+                // return null
+                return buildFinalResult(tempResult);
+              }
+            }
+          }
+        }
+      }
+      // Step 2: fill current TsBlock
+      originTsBlock = cachedTsBlock.remove(0);
+      long startRowIndex = cachedRowIndex.remove(0);
+      cachedLastRowIndexForNonNullHelperColumn.remove(0);
+      resetFill();
+
+      Column[] columns = new Column[outputColumnCount];
+      for (int i = 0; i < outputColumnCount; i++) {
+        columns[i] =
+            fillArray[i].fill(
+                getHelperColumn(originTsBlock), originTsBlock.getColumn(i), startRowIndex);
+      }
+      tempResult = append(originTsBlock.getPositionCount(), originTsBlock.getTimeColumn(), columns);
+      for (int i = 0; i < outputColumnCount; i++) {
+        // make sure nextTsBlockIndex for each column >= 1
+        nextTsBlockIndex[i] = Math.max(1, nextTsBlockIndex[i] - 1);
+      }
+    }
+    return buildFinalResult(tempResult);
+  }
+
+  boolean noMoreTsBlockForCurrentGroup() {
+    return noMoreTsBlock;
+  }
+
+  protected abstract Column getHelperColumn(TsBlock tsBlock);
+
+  // -1 means all values of helper column in @param{tsBlock} are null
+  protected abstract Integer getLastRowIndexForNonNullHelperColumn(TsBlock tsBlock);
+
+  TsBlock append(int length, Column timeColumn, Column[] valueColumns) {
+    return new TsBlock(length, timeColumn, valueColumns);
+  }
+
+  TsBlock buildFinalResult(TsBlock tempResult) {
+    return tempResult;
+  }
+
+  void resetFill() {
+    // do nothing
+  }
+
+  @Override
+  public boolean hasNext() throws Exception {
+    // if child.hasNext() return false, it means that there is no more tsBlocks
+    noMoreTsBlock = !child.hasNextWithTimer();
+    // if there is more tsBlock, we can call child.next() once
+    canCallNext = !noMoreTsBlock;
+    return !cachedTsBlock.isEmpty() || !noMoreTsBlock;
+  }
+
+  @Override
+  public void close() throws Exception {
+    child.close();
+  }
+
+  @Override
+  public boolean isFinished() throws Exception {
+    return cachedTsBlock.isEmpty() && child.isFinished();
+  }
+
+  @Override
+  public long calculateMaxPeekMemory() {
+    // while doing linear fill, we may need to copy the corresponding column if there exists null
+    // values, and we may also need to cache next TsBlock to get next not null value
+    // so the max peek memory may be triple or more, here we just use 3 as the estimated factor
+    // because in most cases, we will get next not null value in next TsBlock
+    return 3 * child.calculateMaxPeekMemory() + child.calculateRetainedSizeAfterCallingNext();
+  }
+
+  @Override
+  public long calculateMaxReturnSize() {
+    return child.calculateMaxReturnSize();
+  }
+
+  @Override
+  public long calculateRetainedSizeAfterCallingNext() {
+    // we can safely ignore two lines cached in LinearFill
+    return child.calculateRetainedSizeAfterCallingNext();
+  }
+
+  @Override
+  public long ramBytesUsed() {
+    return INSTANCE_SIZE
+        + MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(child)
+        + MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(operatorContext)
+        + RamUsageEstimator.sizeOf(nextTsBlockIndex);
+  }
+
+  /**
+   * Judge whether we can use current cached TsBlock to fill Column.
+   *
+   * @param columnIndex index for column which need to be filled
+   * @param currentEndRowIndex row index for endTime of column which need to be filled
+   * @return true if current cached TsBlock is enough to fill Column at columnIndex, otherwise
+   *     false.
+   */
+  private boolean isCachedTsBlockEnough(int columnIndex, long currentEndRowIndex) {
+    // next TsBlock has already been in the cachedTsBlock
+    while (nextTsBlockIndex[columnIndex] < cachedTsBlock.size()) {
+      TsBlock nextTsBlock = cachedTsBlock.get(nextTsBlockIndex[columnIndex]);
+      long startRowIndex = cachedRowIndex.get(nextTsBlockIndex[columnIndex]);
+      nextTsBlockIndex[columnIndex]++;
+      if (fillArray[columnIndex].prepareForNext(
+          startRowIndex,
+          currentEndRowIndex,
+          getHelperColumn(nextTsBlock),
+          nextTsBlock.getColumn(columnIndex))) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  /**
+   * Try to get next TsBlock
+   *
+   * @return true if we succeed to get next TsBlock and add it into cachedTsBlock, otherwise false
+   * @throws Exception errors happened while getting next batch data
+   */
+  private boolean tryToGetNextTsBlock() throws Exception {
+    if (canCallNext) { // if we can call child.next(), we call that and cache it in
+      // cachedTsBlock
+      canCallNext = false;
+      TsBlock nextTsBlock = child.nextWithTimer();
+      // child operator's calculation is not finished, so we just return null
+      if (nextTsBlock == null || nextTsBlock.isEmpty()) {
+        return false;
+      } else { // otherwise, we cache it
+        updateCachedData(nextTsBlock);
+        return true;
+      }
+    }
+    return false;
+  }
+
+  void updateCachedData(TsBlock tsBlock) {
+    cachedTsBlock.add(tsBlock);
+    cachedRowIndex.add(currentRowIndex);
+    cachedLastRowIndexForNonNullHelperColumn.add(getLastRowIndexForNonNullHelperColumn(tsBlock));
+    currentRowIndex += tsBlock.getPositionCount();
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AbstractSortOperator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AbstractSortOperator.java
new file mode 100644
index 00000000000..82d0b94b334
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AbstractSortOperator.java
@@ -0,0 +1,369 @@
+/*
+ * 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.calc.execution.operator.process;
+
+import org.apache.iotdb.calc.execution.operator.CommonOperatorContext;
+import org.apache.iotdb.calc.execution.operator.Operator;
+import org.apache.iotdb.calc.utils.datastructure.MergeSortHeap;
+import org.apache.iotdb.calc.utils.datastructure.MergeSortKey;
+import org.apache.iotdb.calc.utils.datastructure.SortKey;
+import org.apache.iotdb.calc.utils.sort.DiskSpiller;
+import org.apache.iotdb.calc.utils.sort.MemoryReader;
+import org.apache.iotdb.calc.utils.sort.SortBufferManager;
+import org.apache.iotdb.calc.utils.sort.SortReader;
+import org.apache.iotdb.commons.conf.CommonDescriptor;
+import org.apache.iotdb.commons.exception.IoTDBException;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.common.conf.TSFileDescriptor;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.tsfile.read.common.block.column.TimeColumnBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+public abstract class AbstractSortOperator implements ProcessOperator {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AbstractSortOperator.class);
+
+  protected final CommonOperatorContext operatorContext;
+  protected final Operator inputOperator;
+  protected final TsBlockBuilder tsBlockBuilder;
+
+  // Use to output the result in memory.
+  // Because the memory may be larger than tsBlockBuilder's max size
+  // so the data may be return in multiple times.
+  private int curRow = -1;
+
+  private List<SortKey> cachedData;
+  private final Comparator<SortKey> comparator;
+  private long cachedBytes;
+  private final DiskSpiller diskSpiller;
+  private SortBufferManager sortBufferManager;
+
+  // For mergeSort
+
+  private MergeSortHeap mergeSortHeap;
+  private List<SortReader> sortReaders;
+  protected boolean[] noMoreData;
+
+  private final int maxReturnSize =
+      TSFileDescriptor.getInstance().getConfig().getMaxTsBlockSizeInBytes();
+
+  protected long prepareUntilReadyCost = 0;
+  protected long dataSize = 0;
+  private long sortCost = 0;
+
+  AbstractSortOperator(
+      CommonOperatorContext operatorContext,
+      Operator inputOperator,
+      List<TSDataType> dataTypes,
+      DiskSpiller diskSpiller,
+      Comparator<SortKey> comparator) {
+    this.operatorContext = operatorContext;
+    this.inputOperator = inputOperator;
+    this.tsBlockBuilder = new TsBlockBuilder(dataTypes);
+    this.cachedData = new ArrayList<>();
+    this.comparator = comparator;
+    this.cachedBytes = 0;
+    this.diskSpiller = diskSpiller;
+    this.sortBufferManager =
+        new SortBufferManager(
+            TSFileDescriptor.getInstance().getConfig().getMaxTsBlockSizeInBytes(),
+            CommonDescriptor.getInstance().getConfig().getSortBufferSize());
+  }
+
+  protected void buildResult() throws IoTDBException {
+    if (diskSpiller.hasSpilledData()) {
+      try {
+        prepareSortReaders();
+        mergeSort();
+      } catch (Exception e) {
+        clear();
+        throw e;
+      }
+    } else {
+      if (curRow == -1) {
+        long startTime = System.nanoTime();
+        cachedData.sort(comparator);
+        sortCost += System.nanoTime() - startTime;
+        curRow = 0;
+      }
+      buildTsBlockInMemory();
+    }
+  }
+
+  @Override
+  public CommonOperatorContext getOperatorContext() {
+    return operatorContext;
+  }
+
+  @Override
+  public ListenableFuture<?> isBlocked() {
+    return inputOperator.isBlocked();
+  }
+
+  private void recordMetrics() {
+    operatorContext.recordSpecifiedInfo("prepareCost/ns", Long.toString(prepareUntilReadyCost));
+    operatorContext.recordSpecifiedInfo("sortedDataSize", Long.toString(dataSize));
+    operatorContext.recordSpecifiedInfo("sortCost/ns", Long.toString(sortCost));
+    int spilledFileSize = diskSpiller.getFileSize();
+    if (spilledFileSize > 0) {
+      operatorContext.recordSpecifiedInfo(
+          "merge sort branch", Integer.toString(diskSpiller.getFileSize() + 1));
+    }
+  }
+
+  private void prepareSortReaders() throws IoTDBException {
+    if (sortReaders != null) {
+      return;
+    }
+    sortReaders = new ArrayList<>();
+    if (cachedBytes != 0) {
+      cachedData.sort(comparator);
+      if (sortBufferManager.allocate(cachedBytes)) {
+        sortReaders.add(
+            new MemoryReader(
+                cachedData.stream().map(MergeSortKey::new).collect(Collectors.toList())));
+      } else {
+        sortBufferManager.allocateOneSortBranch();
+        diskSpiller.spillSortedData(cachedData);
+        cachedData = null;
+      }
+    }
+    sortReaders.addAll(diskSpiller.getReaders(sortBufferManager));
+    // if reader is finished
+    noMoreData = new boolean[sortReaders.size()];
+  }
+
+  protected void cacheTsBlock(TsBlock tsBlock) throws IoTDBException {
+    long bytesSize = tsBlock.getSizeInBytes();
+    if (bytesSize + cachedBytes < sortBufferManager.getSortBufferSize()) {
+      cachedBytes += bytesSize;
+      for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+        cachedData.add(new MergeSortKey(tsBlock, i));
+      }
+    } else {
+      cachedData.sort(comparator);
+      spill();
+      cachedData.clear();
+      cachedBytes = bytesSize;
+      for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+        cachedData.add(new MergeSortKey(tsBlock, i));
+      }
+    }
+  }
+
+  private void spill() throws IoTDBException {
+    // if current memory cannot put this tsBlock, an exception will be thrown in spillSortedData()
+    // because there should be at least tsBlockBuilderStatus.DEFAULT_MAX_TSBLOCK_SIZE_IN_BYTES for
+    // one branch.
+    sortBufferManager.allocateOneSortBranch();
+    diskSpiller.spillSortedData(cachedData);
+  }
+
+  private void buildTsBlockInMemory() {
+    TimeColumnBuilder timeColumnBuilder = tsBlockBuilder.getTimeColumnBuilder();
+    ColumnBuilder[] valueColumnBuilders = tsBlockBuilder.getValueColumnBuilders();
+    for (int i = curRow; i < cachedData.size(); i++) {
+      SortKey sortKey = cachedData.get(i);
+      TsBlock tsBlock = sortKey.tsBlock;
+      appendTime(timeColumnBuilder, tsBlock.getTimeByIndex(sortKey.rowIndex));
+      for (int j = 0; j < valueColumnBuilders.length; j++) {
+        if (tsBlock.getColumn(j).isNull(sortKey.rowIndex)) {
+          valueColumnBuilders[j].appendNull();
+          continue;
+        }
+        valueColumnBuilders[j].write(tsBlock.getColumn(j), sortKey.rowIndex);
+      }
+      tsBlockBuilder.declarePosition();
+      curRow++;
+      if (tsBlockBuilder.isFull()) {
+        break;
+      }
+    }
+  }
+
+  private void mergeSort() throws IoTDBException {
+
+    // 1. fill the input from each reader
+    initMergeSortHeap();
+
+    long startTime = System.nanoTime();
+    long maxRuntime = operatorContext.getMaxRunTime().roundTo(TimeUnit.NANOSECONDS);
+
+    // 2. do merge sort until one TsBlock is consumed up
+    TimeColumnBuilder timeBuilder = tsBlockBuilder.getTimeColumnBuilder();
+    ColumnBuilder[] valueColumnBuilders = tsBlockBuilder.getValueColumnBuilders();
+    while (!mergeSortHeap.isEmpty()) {
+
+      MergeSortKey mergeSortKey = mergeSortHeap.poll();
+      TsBlock targetBlock = mergeSortKey.tsBlock;
+      appendTime(timeBuilder, targetBlock.getTimeByIndex(mergeSortKey.rowIndex));
+      for (int i = 0; i < valueColumnBuilders.length; i++) {
+        if (targetBlock.getColumn(i).isNull(mergeSortKey.rowIndex)) {
+          valueColumnBuilders[i].appendNull();
+          continue;
+        }
+        valueColumnBuilders[i].write(targetBlock.getColumn(i), mergeSortKey.rowIndex);
+      }
+      tsBlockBuilder.declarePosition();
+
+      int readerIndex = mergeSortKey.inputChannelIndex;
+      mergeSortKey = readNextMergeSortKey(readerIndex);
+      if (mergeSortKey != null) {
+        mergeSortHeap.push(mergeSortKey);
+      } else {
+        noMoreData[readerIndex] = true;
+        sortReaders.get(readerIndex).releaseMemory();
+      }
+
+      // break if time is out or tsBlockBuilder is full or sortBuffer is not enough
+      if (System.nanoTime() - startTime > maxRuntime || tsBlockBuilder.isFull()) {
+        break;
+      }
+    }
+    sortCost += System.nanoTime() - startTime;
+  }
+
+  protected abstract void appendTime(TimeColumnBuilder timeBuilder, long time);
+
+  private void initMergeSortHeap() throws IoTDBException {
+    if (mergeSortHeap == null) {
+      mergeSortHeap = new MergeSortHeap(sortReaders.size(), comparator);
+      for (int i = 0; i < sortReaders.size(); i++) {
+        SortReader sortReader = sortReaders.get(i);
+        if (sortReader.hasNext()) {
+          MergeSortKey mergeSortKey = sortReader.next();
+          mergeSortKey.inputChannelIndex = i;
+          mergeSortHeap.push(mergeSortKey);
+        } else {
+          noMoreData[i] = true;
+          sortReader.releaseMemory();
+        }
+      }
+    }
+  }
+
+  private MergeSortKey readNextMergeSortKey(int readerIndex) throws IoTDBException {
+    SortReader sortReader = sortReaders.get(readerIndex);
+    if (sortReader.hasNext()) {
+      MergeSortKey mergeSortKey = sortReader.next();
+      mergeSortKey.inputChannelIndex = readerIndex;
+      return mergeSortKey;
+    }
+    return null;
+  }
+
+  private boolean hasMoreData() {
+    if (noMoreData == null) {
+      return true;
+    }
+    for (boolean noMore : noMoreData) {
+      if (!noMore) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  public void clear() {
+    if (!diskSpiller.hasSpilledData()) {
+      return;
+    }
+    try {
+      if (sortReaders != null) {
+        for (SortReader sortReader : sortReaders) {
+          sortReader.close();
+        }
+      }
+      sortReaders = null;
+      diskSpiller.reset();
+    } catch (Exception e) {
+      LOGGER.warn("Fail to close fileChannel", e);
+    }
+  }
+
+  @Override
+  public boolean hasNext() throws Exception {
+    return inputOperator.hasNextWithTimer() || hasMoreSortedData();
+  }
+
+  protected boolean hasMoreSortedData() {
+    return (!diskSpiller.hasSpilledData()
+            && ((curRow == -1 && !cachedData.isEmpty())
+                || (curRow != -1 && curRow != cachedData.size())))
+        || (diskSpiller.hasSpilledData() && hasMoreData());
+  }
+
+  @Override
+  public void close() throws Exception {
+    recordMetrics();
+    cachedData = null;
+    clear();
+    inputOperator.close();
+  }
+
+  @Override
+  public boolean isFinished() throws Exception {
+    return !this.hasNextWithTimer();
+  }
+
+  @Override
+  public long calculateMaxPeekMemory() {
+    return inputOperator.calculateMaxPeekMemoryWithCounter()
+        + inputOperator.calculateRetainedSizeAfterCallingNext()
+        + sortBufferManager.getSortBufferSize();
+  }
+
+  @Override
+  public long calculateMaxReturnSize() {
+    return maxReturnSize;
+  }
+
+  @Override
+  public long calculateRetainedSizeAfterCallingNext() {
+    return inputOperator.calculateRetainedSizeAfterCallingNext()
+        + sortBufferManager.getSortBufferSize();
+  }
+
+  protected void resetSortRelatedResource() {
+    curRow = -1;
+    cachedData = new ArrayList<>();
+    cachedBytes = 0;
+    clear();
+    sortBufferManager =
+        new SortBufferManager(
+            sortBufferManager.getMaxTsBlockSizeInBytes(), sortBufferManager.getSortBufferSize());
+    if (mergeSortHeap != null && !mergeSortHeap.isEmpty()) {
+      throw new IllegalStateException("mergeSortHeap should be empty!");
+    }
+    mergeSortHeap = null;
+    noMoreData = null;
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AggregationMergeSortOperator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AggregationMergeSortOperator.java
new file mode 100644
index 00000000000..6f106d680df
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AggregationMergeSortOperator.java
@@ -0,0 +1,304 @@
+/*
+ * 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.calc.execution.operator.process;
+
+import org.apache.iotdb.calc.execution.aggregation.Accumulator;
+import org.apache.iotdb.calc.execution.operator.CommonOperatorContext;
+import org.apache.iotdb.calc.execution.operator.Operator;
+import org.apache.iotdb.calc.utils.datastructure.MergeSortHeap;
+import org.apache.iotdb.calc.utils.datastructure.MergeSortKey;
+import org.apache.iotdb.calc.utils.datastructure.SortKey;
+import org.apache.iotdb.commons.queryengine.execution.MemoryEstimationHelper;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.common.conf.TSFileDescriptor;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.tsfile.read.common.block.column.TimeColumnBuilder;
+import org.apache.tsfile.utils.Binary;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static com.google.common.util.concurrent.Futures.successfulAsList;
+
+public class AggregationMergeSortOperator extends AbstractConsumeAllOperator {
+
+  private static final long INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(AggregationMergeSortOperator.class);
+
+  private final List<Accumulator> accumulators;
+
+  private final List<TSDataType> dataTypes;
+
+  private final TsBlockBuilder tsBlockBuilder;
+
+  private final boolean[] noMoreTsBlocks;
+
+  private final MergeSortHeap mergeSortHeap;
+
+  private final boolean hasGroupBy;
+
+  private boolean finished;
+
+  private Binary lastDevice;
+
+  private long lastTime;
+
+  public AggregationMergeSortOperator(
+      CommonOperatorContext operatorContext,
+      List<Operator> children,
+      List<TSDataType> dataTypes,
+      List<Accumulator> accumulators,
+      boolean hasGroupBy,
+      Comparator<SortKey> comparator) {
+    super(operatorContext, children);
+    this.dataTypes = dataTypes;
+    this.tsBlockBuilder = new TsBlockBuilder(dataTypes);
+    this.noMoreTsBlocks = new boolean[this.inputOperatorsCount];
+    this.accumulators = accumulators;
+    this.hasGroupBy = hasGroupBy;
+    this.mergeSortHeap = new MergeSortHeap(inputOperatorsCount, comparator);
+  }
+
+  @Override
+  public TsBlock next() throws Exception {
+    long startTime = System.nanoTime();
+    long maxRuntime = operatorContext.getMaxRunTime().roundTo(TimeUnit.NANOSECONDS);
+
+    // init all element in inputTsBlocks
+    if (!prepareInput()) {
+      return null;
+    }
+
+    tsBlockBuilder.reset();
+    while (!mergeSortHeap.isEmpty()) {
+      MergeSortKey mergeSortKey = mergeSortHeap.poll();
+      TsBlock targetBlock = mergeSortKey.tsBlock;
+      int rowIndex = mergeSortKey.rowIndex;
+      Binary currentDevice = targetBlock.getColumn(0).getBinary(rowIndex);
+      long currentTime = targetBlock.getTimeByIndex(rowIndex);
+      if (lastDevice != null && (!currentDevice.equals(lastDevice) || currentTime != lastTime)) {
+        outputResultToTsBlock();
+      }
+
+      lastDevice = currentDevice;
+      lastTime = currentTime;
+
+      int cnt = 1;
+      for (Accumulator accumulator : accumulators) {
+        if (accumulator.getPartialResultSize() == 2) {
+          Column first =
+              hasGroupBy
+                  ? targetBlock.getColumn(cnt++).subColumn(rowIndex)
+                  : targetBlock.getColumn(cnt++);
+          Column second =
+              hasGroupBy
+                  ? targetBlock.getColumn(cnt++).subColumn(rowIndex)
+                  : targetBlock.getColumn(cnt++);
+          accumulator.addIntermediate(new Column[] {first, second});
+        } else {
+          Column column =
+              hasGroupBy
+                  ? targetBlock.getColumn(cnt++).subColumn(rowIndex)
+                  : targetBlock.getColumn(cnt++);
+          accumulator.addIntermediate(new Column[] {column});
+        }
+      }
+
+      if (mergeSortKey.rowIndex == mergeSortKey.tsBlock.getPositionCount() - 1) {
+        inputTsBlocks[mergeSortKey.inputChannelIndex] = null;
+        break;
+      } else {
+        mergeSortKey.rowIndex++;
+        mergeSortHeap.push(mergeSortKey);
+      }
+
+      // break if time is out or tsBlockBuilder is full
+      if (System.nanoTime() - startTime > maxRuntime || tsBlockBuilder.isFull()) {
+        break;
+      }
+    }
+
+    if (mergeSortHeap.isEmpty()) {
+      outputResultToTsBlock();
+    }
+
+    return tsBlockBuilder.getPositionCount() > 0 ? tsBlockBuilder.build() : null;
+  }
+
+  private void outputResultToTsBlock() {
+    TimeColumnBuilder timeBuilder = tsBlockBuilder.getTimeColumnBuilder();
+    ColumnBuilder[] valueColumnBuilders = tsBlockBuilder.getValueColumnBuilders();
+    timeBuilder.writeLong(lastTime);
+    valueColumnBuilders[0].writeBinary(lastDevice);
+    for (int i = 1; i < dataTypes.size(); i++) {
+      accumulators.get(i - 1).outputFinal(valueColumnBuilders[i]);
+    }
+    tsBlockBuilder.declarePosition();
+    accumulators.forEach(Accumulator::reset);
+    lastDevice = null;
+  }
+
+  @Override
+  public boolean hasNext() throws Exception {
+    if (finished) {
+      return false;
+    }
+
+    for (int i = 0; i < inputOperatorsCount; i++) {
+      if (isInputNotEmpty(i)) {
+        return true;
+      } else if (!noMoreTsBlocks[i]) {
+        if (!canCallNext[i] || children.get(i).hasNextWithTimer()) {
+          return true;
+        } else {
+          handleFinishedChild(i);
+        }
+      }
+    }
+
+    return false;
+  }
+
+  @Override
+  public ListenableFuture<?> isBlocked() {
+    boolean hasReadyChild = false;
+    List<ListenableFuture<?>> listenableFutures = new ArrayList<>();
+
+    for (int i = 0; i < inputOperatorsCount; i++) {
+      if (noMoreTsBlocks[i] || isInputNotEmpty(i) || children.get(i) == null) {
+        continue;
+      }
+      ListenableFuture<?> blocked = children.get(i).isBlocked();
+      if (blocked.isDone()) {
+        hasReadyChild = true;
+        // only when not blocked, canCallNext[i] equals true
+        canCallNext[i] = true;
+      } else {
+        listenableFutures.add(blocked);
+      }
+    }
+
+    return (hasReadyChild || listenableFutures.isEmpty())
+        ? NOT_BLOCKED
+        : successfulAsList(listenableFutures);
+  }
+
+  @Override
+  public boolean isFinished() throws Exception {
+    if (finished) {
+      return true;
+    }
+
+    finished = true;
+    for (int i = 0; i < inputOperatorsCount; i++) {
+      if (!noMoreTsBlocks[i] || isInputNotEmpty(i)) {
+        finished = false;
+        break;
+      }
+    }
+    return finished;
+  }
+
+  @Override
+  public void close() throws Exception {
+    for (int i = 0; i < inputOperatorsCount; i++) {
+      final Operator operator = children.get(i);
+      if (operator != null) {
+        operator.close();
+      }
+    }
+  }
+
+  @Override
+  protected void handleFinishedChild(int currentChildIndex) throws Exception {
+    // invoking this method when children.get(currentChildIndex).hasNext return false
+    noMoreTsBlocks[currentChildIndex] = true;
+    inputTsBlocks[currentChildIndex] = null;
+    children.get(currentChildIndex).close();
+    children.set(currentChildIndex, null);
+  }
+
+  @Override
+  protected boolean canSkipCurrentChild(int currentChildIndex) {
+    return noMoreTsBlocks[currentChildIndex]
+        || !isEmpty(currentChildIndex)
+        || children.get(currentChildIndex) == null;
+  }
+
+  @Override
+  protected void processCurrentInputTsBlock(int currentInputIndex) {
+    mergeSortHeap.push(new MergeSortKey(inputTsBlocks[currentInputIndex], 0, currentInputIndex));
+  }
+
+  @Override
+  public long calculateMaxPeekMemory() {
+    long maxPeekMemory = TSFileDescriptor.getInstance().getConfig().getPageSizeInByte();
+    // inputTsBlocks will cache all the tsBlocks returned by inputOperators
+    for (Operator operator : children) {
+      maxPeekMemory += operator.calculateMaxReturnSize();
+      maxPeekMemory += operator.calculateRetainedSizeAfterCallingNext();
+    }
+    for (Operator operator : children) {
+      maxPeekMemory = Math.max(maxPeekMemory, operator.calculateMaxPeekMemory());
+    }
+    return Math.max(maxPeekMemory, calculateMaxReturnSize());
+  }
+
+  @Override
+  public long calculateMaxReturnSize() {
+    return TSFileDescriptor.getInstance().getConfig().getMaxTsBlockSizeInBytes();
+  }
+
+  @Override
+  public long calculateRetainedSizeAfterCallingNext() {
+    long currentRetainedSize = 0;
+    long minChildReturnSize = Long.MAX_VALUE;
+    for (Operator child : children) {
+      long maxReturnSize = child.calculateMaxReturnSize();
+      minChildReturnSize = Math.min(minChildReturnSize, maxReturnSize);
+      currentRetainedSize += (maxReturnSize + child.calculateRetainedSizeAfterCallingNext());
+    }
+    return currentRetainedSize - minChildReturnSize;
+  }
+
+  @Override
+  public long ramBytesUsed() {
+    return INSTANCE_SIZE
+        + RamUsageEstimator.sizeOf(noMoreTsBlocks)
+        + children.stream()
+            .mapToLong(MemoryEstimationHelper::getEstimatedSizeOfAccountableObject)
+            .sum()
+        + MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(operatorContext)
+        + RamUsageEstimator.sizeOf(canCallNext)
+        + tsBlockBuilder.getRetainedSizeInBytes();
+  }
+
+  private boolean isInputNotEmpty(int index) {
+    return inputTsBlocks[index] != null && !inputTsBlocks[index].isEmpty();
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AssignUniqueIdOperator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AssignUniqueIdOperator.java
new file mode 100644
index 00000000000..f7faaadc0a5
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/AssignUniqueIdOperator.java
@@ -0,0 +1,141 @@
+/*
+ * 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.calc.execution.operator.process;
+
+import org.apache.iotdb.calc.execution.operator.CommonOperatorContext;
+import org.apache.iotdb.calc.execution.operator.Operator;
+import org.apache.iotdb.commons.queryengine.execution.MemoryEstimationHelper;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.common.conf.TSFileDescriptor;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.read.common.block.column.LongColumnBuilder;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Verify.verify;
+
+public class AssignUniqueIdOperator implements ProcessOperator {
+  private static final long INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(AssignUniqueIdOperator.class);
+
+  private static final long ROW_IDS_PER_REQUEST = 1L << 20L;
+  private static final long MAX_ROW_ID = 1L << 40L;
+
+  private final CommonOperatorContext operatorContext;
+  private final Operator child;
+
+  private final AtomicLong rowIdPool = new AtomicLong();
+  private final long uniqueValueMask;
+
+  private long rowIdCounter;
+  private long maxRowIdCounterValue;
+
+  public AssignUniqueIdOperator(CommonOperatorContext operatorContext, Operator child) {
+    this.operatorContext = operatorContext;
+    this.child = child;
+
+    this.uniqueValueMask =
+        (((long) operatorContext.getFragmentId()) << 54)
+            | (((long) operatorContext.getPipelineId()) << 40);
+    requestValues();
+  }
+
+  @Override
+  public ListenableFuture<?> isBlocked() {
+    return child.isBlocked();
+  }
+
+  @Override
+  public TsBlock next() throws Exception {
+    TsBlock tsBlock = child.nextWithTimer();
+    if (tsBlock == null || tsBlock.isEmpty()) {
+      return null;
+    }
+    return tsBlock.appendValueColumns(new Column[] {generateIdColumn(tsBlock.getPositionCount())});
+  }
+
+  @Override
+  public boolean hasNext() throws Exception {
+    return child.hasNext();
+  }
+
+  @Override
+  public void close() throws Exception {
+    if (child != null) {
+      child.close();
+    }
+  }
+
+  @Override
+  public boolean isFinished() throws Exception {
+    return child.isFinished();
+  }
+
+  @Override
+  public long calculateMaxPeekMemory() {
+    return child.calculateMaxPeekMemory();
+  }
+
+  @Override
+  public long calculateMaxReturnSize() {
+    return child.calculateMaxReturnSize()
+        + (long) Long.SIZE * TSFileDescriptor.getInstance().getConfig().getMaxTsBlockLineNumber();
+  }
+
+  @Override
+  public long calculateRetainedSizeAfterCallingNext() {
+    return child.calculateRetainedSizeAfterCallingNext();
+  }
+
+  @Override
+  public long ramBytesUsed() {
+    return INSTANCE_SIZE
+        + MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(child)
+        + MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(operatorContext);
+  }
+
+  @Override
+  public CommonOperatorContext getOperatorContext() {
+    return operatorContext;
+  }
+
+  private Column generateIdColumn(int positionCount) {
+    LongColumnBuilder columnBuilder = new LongColumnBuilder(null, positionCount);
+    for (int currentPosition = 0; currentPosition < positionCount; currentPosition++) {
+      if (rowIdCounter >= maxRowIdCounterValue) {
+        requestValues();
+      }
+      long rowId = rowIdCounter++;
+      verify((rowId & uniqueValueMask) == 0, "RowId and uniqueValue mask overlaps");
+      columnBuilder.writeLong(uniqueValueMask | rowId);
+    }
+    return columnBuilder.build();
+  }
+
+  private void requestValues() {
+    rowIdCounter = rowIdPool.getAndAdd(ROW_IDS_PER_REQUEST);
+    maxRowIdCounterValue = Math.min(rowIdCounter + ROW_IDS_PER_REQUEST, MAX_ROW_ID);
+    checkState(rowIdCounter < MAX_ROW_ID, "Unique row id exceeds a limit: %s", MAX_ROW_ID);
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/CollectOperator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/CollectOperator.java
new file mode 100644
index 00000000000..921d273d04e
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/CollectOperator.java
@@ -0,0 +1,140 @@
+/*
+ * 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.calc.execution.operator.process;
+
+import org.apache.iotdb.calc.execution.operator.CommonOperatorContext;
+import org.apache.iotdb.calc.execution.operator.Operator;
+import org.apache.iotdb.commons.queryengine.execution.MemoryEstimationHelper;
+import org.apache.iotdb.commons.utils.TestOnly;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.List;
+
+public class CollectOperator implements ProcessOperator {
+  private static final long INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(CollectOperator.class);
+
+  private final CommonOperatorContext operatorContext;
+  protected final List<Operator> children;
+  private boolean inited = false;
+
+  protected int currentIndex;
+
+  public CollectOperator(CommonOperatorContext operatorContext, List<Operator> children) {
+    this.operatorContext = operatorContext;
+    this.children = children;
+    this.currentIndex = 0;
+  }
+
+  @Override
+  public boolean hasNext() throws Exception {
+    return currentIndex < children.size();
+  }
+
+  @Override
+  public TsBlock next() throws Exception {
+    if (children.get(currentIndex).hasNextWithTimer()) {
+      return children.get(currentIndex).nextWithTimer();
+    } else {
+      closeCurrentChild(currentIndex);
+      currentIndex++;
+      return null;
+    }
+  }
+
+  protected void closeCurrentChild(int index) throws Exception {
+    children.get(index).close();
+    children.set(index, null);
+  }
+
+  @Override
+  public ListenableFuture<?> isBlocked() {
+    if (!inited) {
+      inited = true;
+      for (Operator child : children) {
+        child.isBlocked();
+      }
+    }
+    if (currentIndex >= children.size()) {
+      return NOT_BLOCKED;
+    }
+    return children.get(currentIndex).isBlocked();
+  }
+
+  @Override
+  public boolean isFinished() throws Exception {
+    return currentIndex >= children.size();
+  }
+
+  @Override
+  public CommonOperatorContext getOperatorContext() {
+    return operatorContext;
+  }
+
+  @Override
+  public void close() throws Exception {
+    for (int i = currentIndex, n = children.size(); i < n; i++) {
+      Operator currentChild = children.get(i);
+      if (currentChild != null) {
+        closeCurrentChild(i);
+      }
+    }
+  }
+
+  @Override
+  public long calculateMaxPeekMemory() {
+    long maxPeekMemory = 0;
+    for (Operator child : children) {
+      maxPeekMemory = Math.max(maxPeekMemory, child.calculateMaxPeekMemoryWithCounter());
+    }
+    return maxPeekMemory;
+  }
+
+  @Override
+  public long calculateMaxReturnSize() {
+    long maxReturnSize = 0;
+    for (Operator child : children) {
+      maxReturnSize = Math.max(maxReturnSize, child.calculateMaxReturnSize());
+    }
+    return maxReturnSize;
+  }
+
+  @Override
+  public long calculateRetainedSizeAfterCallingNext() {
+    return 0L;
+  }
+
+  @TestOnly
+  public List<Operator> getChildren() {
+    return children;
+  }
+
+  @Override
+  public long ramBytesUsed() {
+    return INSTANCE_SIZE
+        + children.stream()
+            .mapToLong(MemoryEstimationHelper::getEstimatedSizeOfAccountableObject)
+            .sum()
+        + MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(operatorContext);
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/EnforceSingleRowOperator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/EnforceSingleRowOperator.java
new file mode 100644
index 00000000000..6a300c2cdfe
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/EnforceSingleRowOperator.java
@@ -0,0 +1,123 @@
+/*
+ * 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.calc.execution.operator.process;
+
+import org.apache.iotdb.calc.execution.operator.CommonOperatorContext;
+import org.apache.iotdb.calc.execution.operator.Operator;
+import org.apache.iotdb.commons.exception.SemanticException;
+import org.apache.iotdb.commons.queryengine.execution.MemoryEstimationHelper;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.apache.tsfile.common.conf.TSFileDescriptor;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+public class EnforceSingleRowOperator implements ProcessOperator {
+  private static final long INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(EnforceSingleRowOperator.class);
+
+  private static final String MULTIPLE_ROWS_ERROR_MESSAGE =
+      "Scalar sub-query has returned multiple rows.";
+
+  private static final String NO_RESULT_ERROR_MESSAGE = "Scalar sub-query does not have output.";
+
+  private final CommonOperatorContext operatorContext;
+  private final Operator child;
+
+  private boolean finished = false;
+
+  public EnforceSingleRowOperator(CommonOperatorContext operatorContext, Operator child) {
+    this.operatorContext = operatorContext;
+    this.child = child;
+  }
+
+  @Override
+  public ListenableFuture<?> isBlocked() {
+    return child.isBlocked();
+  }
+
+  @Override
+  public TsBlock next() throws Exception {
+    TsBlock tsBlock = child.nextWithTimer();
+    if (tsBlock == null || tsBlock.isEmpty()) {
+      return tsBlock;
+    }
+    if (tsBlock.getPositionCount() > 1 || finished) {
+      throw new SemanticException(MULTIPLE_ROWS_ERROR_MESSAGE);
+    }
+    finished = true;
+    return tsBlock;
+  }
+
+  @Override
+  public boolean hasNext() throws Exception {
+    return !isFinished();
+  }
+
+  @Override
+  public void close() throws Exception {
+    if (child != null) {
+      child.close();
+    }
+  }
+
+  @Override
+  public boolean isFinished() throws Exception {
+    boolean childFinished = child.isFinished();
+    if (childFinished && !finished) {
+      // finished == false means the child has no result returned up to now, but we need at least
+      // one result.
+      throw new SemanticException(NO_RESULT_ERROR_MESSAGE);
+    }
+    // Even if finished == true, we can not return true here, we need to call child.next() to check
+    // if child has more data.
+    // For example, if the child is a TableScanOperator with a filter, childFinished = false does
+    // not mean that the child can produce more data.(see the isFinished() of TableScanOperator)
+    return childFinished;
+  }
+
+  @Override
+  public long calculateMaxPeekMemory() {
+    return child.calculateMaxPeekMemory();
+  }
+
+  @Override
+  public long calculateMaxReturnSize() {
+    return child.calculateMaxReturnSize()
+        / TSFileDescriptor.getInstance().getConfig().getMaxTsBlockLineNumber();
+  }
+
+  @Override
+  public long calculateRetainedSizeAfterCallingNext() {
+    return child.calculateRetainedSizeAfterCallingNext();
+  }
+
+  @Override
+  public long ramBytesUsed() {
+    return INSTANCE_SIZE
+        + MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(child)
+        + MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(operatorContext);
+  }
+
+  @Override
+  public CommonOperatorContext getOperatorContext() {
+    return operatorContext;
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/FilterAndProjectOperator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/FilterAndProjectOperator.java
new file mode 100644
index 00000000000..16e0cd7b330
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/FilterAndProjectOperator.java
@@ -0,0 +1,443 @@
+/*
+ * 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.calc.execution.operator.process;
+
+import org.apache.iotdb.calc.execution.operator.CommonOperatorContext;
+import org.apache.iotdb.calc.execution.operator.Operator;
+import org.apache.iotdb.calc.transformation.dag.column.AbstractCaseWhenThenColumnTransformer;
+import org.apache.iotdb.calc.transformation.dag.column.ColumnTransformer;
+import org.apache.iotdb.calc.transformation.dag.column.FailFunctionColumnTransformer;
+import org.apache.iotdb.calc.transformation.dag.column.binary.BinaryColumnTransformer;
+import org.apache.iotdb.calc.transformation.dag.column.leaf.IdentityColumnTransformer;
+import org.apache.iotdb.calc.transformation.dag.column.leaf.LeafColumnTransformer;
+import org.apache.iotdb.calc.transformation.dag.column.multi.MappableUDFColumnTransformer;
+import org.apache.iotdb.calc.transformation.dag.column.multi.MultiColumnTransformer;
+import org.apache.iotdb.calc.transformation.dag.column.ternary.TernaryColumnTransformer;
+import org.apache.iotdb.calc.transformation.dag.column.unary.UnaryColumnTransformer;
+import org.apache.iotdb.commons.queryengine.execution.MemoryEstimationHelper;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.common.conf.TSFileDescriptor;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.tsfile.read.common.block.column.RunLengthEncodedColumn;
+import org.apache.tsfile.read.common.block.column.TimeColumnBuilder;
+import org.apache.tsfile.utils.Pair;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.OptionalInt;
+
+public class FilterAndProjectOperator implements ProcessOperator {
+
+  private static final long INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(FilterAndProjectOperator.class);
+
+  private final Operator inputOperator;
+
+  private final List<LeafColumnTransformer> filterLeafColumnTransformerList;
+
+  private final ColumnTransformer filterOutputTransformer;
+
+  private final List<ColumnTransformer> commonTransformerList;
+
+  private final List<LeafColumnTransformer> projectLeafColumnTransformerList;
+
+  private final List<ColumnTransformer> projectOutputTransformerList;
+
+  private final TsBlockBuilder filterTsBlockBuilder;
+
+  private final boolean hasNonMappableUDF;
+
+  private final CommonOperatorContext operatorContext;
+
+  // false when we only need to do projection
+  private final boolean hasFilter;
+
+  private long filteredRowCount = 0;
+
+  @SuppressWarnings("squid:S107")
+  public FilterAndProjectOperator(
+      CommonOperatorContext operatorContext,
+      Operator inputOperator,
+      List<TSDataType> filterOutputDataTypes,
+      List<LeafColumnTransformer> filterLeafColumnTransformerList,
+      ColumnTransformer filterOutputTransformer,
+      List<ColumnTransformer> commonTransformerList,
+      List<LeafColumnTransformer> projectLeafColumnTransformerList,
+      List<ColumnTransformer> projectOutputTransformerList,
+      boolean hasNonMappableUDF,
+      boolean hasFilter) {
+    this.operatorContext = operatorContext;
+    this.inputOperator = inputOperator;
+    this.filterLeafColumnTransformerList = filterLeafColumnTransformerList;
+    this.filterOutputTransformer = filterOutputTransformer;
+    this.commonTransformerList = commonTransformerList;
+    this.projectLeafColumnTransformerList = projectLeafColumnTransformerList;
+    this.projectOutputTransformerList = projectOutputTransformerList;
+    this.hasNonMappableUDF = hasNonMappableUDF;
+    this.filterTsBlockBuilder = new TsBlockBuilder(8, filterOutputDataTypes);
+    this.hasFilter = hasFilter;
+  }
+
+  public FilterAndProjectOperator(
+      FilterAndProjectOperator filterAndProjectOperator, Operator inputOperator) {
+    this.operatorContext = filterAndProjectOperator.operatorContext;
+    this.filterLeafColumnTransformerList = filterAndProjectOperator.filterLeafColumnTransformerList;
+    this.filterOutputTransformer = filterAndProjectOperator.filterOutputTransformer;
+    this.commonTransformerList = filterAndProjectOperator.commonTransformerList;
+    this.projectLeafColumnTransformerList =
+        filterAndProjectOperator.projectLeafColumnTransformerList;
+    this.projectOutputTransformerList = filterAndProjectOperator.projectOutputTransformerList;
+    this.hasNonMappableUDF = filterAndProjectOperator.hasNonMappableUDF;
+    this.hasFilter = filterAndProjectOperator.hasFilter;
+    this.filterTsBlockBuilder = filterAndProjectOperator.filterTsBlockBuilder;
+    this.inputOperator = inputOperator;
+  }
+
+  @Override
+  public CommonOperatorContext getOperatorContext() {
+    return operatorContext;
+  }
+
+  @Override
+  public TsBlock next() throws Exception {
+    TsBlock input = inputOperator.nextWithTimer();
+    if (input == null) {
+      return null;
+    }
+
+    if (!hasFilter) {
+      return getTransformedTsBlock(input);
+    }
+
+    long inputRowCount = input.getPositionCount();
+    TsBlock filterResult = getFilterTsBlock(input);
+    filteredRowCount += inputRowCount - filterResult.getPositionCount();
+    operatorContext.recordSpecifiedInfo("Filtered Rows", Long.toString(filteredRowCount));
+
+    // contains non-mappable udf, we leave calculation for TransformOperator
+    if (hasNonMappableUDF) {
+      return filterResult;
+    }
+    return getTransformedTsBlock(filterResult);
+  }
+
+  /**
+   * Return the TsBlock that contains both initial input columns and columns of common
+   * subexpressions after filtering.
+   */
+  private TsBlock getFilterTsBlock(TsBlock input) {
+    final Column originTimeColumn = input.getTimeColumn();
+    final int positionCount = originTimeColumn.getPositionCount();
+    // feed Filter ColumnTransformer, including TimeStampColumnTransformer and constant
+    for (LeafColumnTransformer leafColumnTransformer : filterLeafColumnTransformerList) {
+      leafColumnTransformer.initFromTsBlock(input);
+    }
+
+    filterOutputTransformer.tryEvaluate();
+
+    Column filterColumn = filterOutputTransformer.getColumn();
+
+    // reuse this builder
+    filterTsBlockBuilder.reset();
+
+    List<Column> resultColumns = new ArrayList<>();
+    for (int i = 0, n = input.getValueColumnCount(); i < n; i++) {
+      resultColumns.add(input.getColumn(i));
+    }
+
+    if (!hasNonMappableUDF) {
+      // get result of calculated common sub expressions
+      for (ColumnTransformer columnTransformer : commonTransformerList) {
+        // CASE WHEN clause would clear all its cache
+        // evaluate again to acquire cache
+        columnTransformer.tryEvaluate();
+        resultColumns.add(columnTransformer.getColumn());
+      }
+    }
+
+    final ColumnBuilder[] columnBuilders = filterTsBlockBuilder.getValueColumnBuilders();
+    if (originTimeColumn instanceof RunLengthEncodedColumn) {
+      int rowCount =
+          constructFilteredTsBlock(resultColumns, filterColumn, columnBuilders, positionCount);
+      filterTsBlockBuilder.declarePositions(rowCount);
+
+      return filterTsBlockBuilder.build(originTimeColumn.getRegion(0, rowCount));
+
+    } else {
+      final TimeColumnBuilder timeBuilder = filterTsBlockBuilder.getTimeColumnBuilder();
+      int rowCount =
+          constructFilteredTsBlock(
+              resultColumns,
+              timeBuilder,
+              filterColumn,
+              originTimeColumn,
+              columnBuilders,
+              positionCount);
+
+      filterTsBlockBuilder.declarePositions(rowCount);
+      return filterTsBlockBuilder.build();
+    }
+  }
+
+  private static int constructFilteredTsBlock(
+      List<Column> resultColumns,
+      TimeColumnBuilder timeBuilder,
+      Column filterColumn,
+      Column originTimeColumn,
+      ColumnBuilder[] columnBuilders,
+      int positionCount) {
+    // construct result TsBlock of filter
+    int rowCount = 0;
+    for (int i = 0, n = resultColumns.size(); i < n; i++) {
+      Column curColumn = resultColumns.get(i);
+      for (int j = 0; j < positionCount; j++) {
+        if (satisfy(filterColumn, j)) {
+          if (i == 0) {
+            rowCount++;
+            timeBuilder.writeLong(originTimeColumn.getLong(j));
+          }
+          if (curColumn.isNull(j)) {
+            columnBuilders[i].appendNull();
+          } else {
+            columnBuilders[i].write(curColumn, j);
+          }
+        }
+      }
+    }
+    return rowCount;
+  }
+
+  public static int constructFilteredTsBlock(
+      List<Column> resultColumns,
+      Column filterColumn,
+      ColumnBuilder[] columnBuilders,
+      int positionCount) {
+    // construct result TsBlock of filter
+    int rowCount = 0;
+    for (int i = 0, n = resultColumns.size(); i < n; i++) {
+      Column curColumn = resultColumns.get(i);
+      for (int j = 0; j < positionCount; j++) {
+        if (satisfy(filterColumn, j)) {
+          if (i == 0) {
+            rowCount++;
+          }
+          if (curColumn.isNull(j)) {
+            columnBuilders[i].appendNull();
+          } else {
+            columnBuilders[i].write(curColumn, j);
+          }
+        }
+      }
+    }
+    return rowCount;
+  }
+
+  public static boolean satisfy(Column filterColumn, int rowIndex) {
+    return !filterColumn.isNull(rowIndex) && filterColumn.getBoolean(rowIndex);
+  }
+
+  private TsBlock getTransformedTsBlock(TsBlock input) {
+    final Column originTimeColumn = input.getTimeColumn();
+    final int positionCount = originTimeColumn.getPositionCount();
+    // feed pre calculated data
+    for (LeafColumnTransformer leafColumnTransformer : projectLeafColumnTransformerList) {
+      leafColumnTransformer.initFromTsBlock(input);
+    }
+
+    List<Column> resultColumns = new ArrayList<>();
+    for (ColumnTransformer columnTransformer : projectOutputTransformerList) {
+      columnTransformer.tryEvaluate();
+      resultColumns.add(columnTransformer.getColumn());
+    }
+    return TsBlock.wrapBlocksWithoutCopy(
+        positionCount, originTimeColumn, resultColumns.toArray(new Column[0]));
+  }
+
+  @Override
+  public boolean hasNext() throws Exception {
+    return inputOperator.hasNextWithTimer();
+  }
+
+  @Override
+  public boolean isFinished() throws Exception {
+    return inputOperator.isFinished();
+  }
+
+  @Override
+  public ListenableFuture<?> isBlocked() {
+    return inputOperator.isBlocked();
+  }
+
+  @Override
+  public void close() throws Exception {
+    for (ColumnTransformer columnTransformer : projectOutputTransformerList) {
+      columnTransformer.close();
+    }
+    if (filterOutputTransformer != null) {
+      filterOutputTransformer.close();
+    }
+    inputOperator.close();
+  }
+
+  @Override
+  public long calculateMaxPeekMemory() {
+    long maxPeekMemory = inputOperator.calculateMaxReturnSize();
+    int maxCachedColumn = 0;
+    // Only do projection, calculate max cached column size of calc tree
+    if (!hasFilter) {
+      for (int i = 0; i < projectOutputTransformerList.size(); i++) {
+        ColumnTransformer c = projectOutputTransformerList.get(i);
+        maxCachedColumn = Math.max(maxCachedColumn, 1 + i + getMaxLevelOfColumnTransformerTree(c));
+      }
+      return Math.max(
+              maxPeekMemory,
+              (long) maxCachedColumn
+                  * TSFileDescriptor.getInstance().getConfig().getPageSizeInByte())
+          + inputOperator.calculateRetainedSizeAfterCallingNext();
+    }
+
+    // has Filter
+    maxCachedColumn =
+        Math.max(
+            1 + getMaxLevelOfColumnTransformerTree(filterOutputTransformer),
+            1 + commonTransformerList.size());
+    if (!hasNonMappableUDF) {
+      for (int i = 0; i < projectOutputTransformerList.size(); i++) {
+        ColumnTransformer c = projectOutputTransformerList.get(i);
+        maxCachedColumn = Math.max(maxCachedColumn, 1 + i + getMaxLevelOfColumnTransformerTree(c));
+      }
+    }
+    return Math.max(
+            maxPeekMemory,
+            (long) maxCachedColumn * TSFileDescriptor.getInstance().getConfig().getPageSizeInByte())
+        + inputOperator.calculateRetainedSizeAfterCallingNext();
+  }
+
+  @Override
+  public long calculateMaxReturnSize() {
+    // time + all value columns
+    if (!hasFilter || !hasNonMappableUDF) {
+      return (long) (1 + projectOutputTransformerList.size())
+          * TSFileDescriptor.getInstance().getConfig().getPageSizeInByte();
+    } else {
+      return (long) (1 + filterTsBlockBuilder.getValueColumnBuilders().length)
+          * TSFileDescriptor.getInstance().getConfig().getPageSizeInByte();
+    }
+  }
+
+  @Override
+  public long calculateRetainedSizeAfterCallingNext() {
+    return inputOperator.calculateRetainedSizeAfterCallingNext();
+  }
+
+  private int getMaxLevelOfColumnTransformerTree(ColumnTransformer columnTransformer) {
+    if (columnTransformer instanceof LeafColumnTransformer) {
+      // Time column is always calculated, we ignore it here. Constant column is ignored.
+      if (columnTransformer instanceof IdentityColumnTransformer) {
+        return 1;
+      } else {
+        return 0;
+      }
+    } else if (columnTransformer instanceof UnaryColumnTransformer) {
+      return Math.max(
+          2,
+          getMaxLevelOfColumnTransformerTree(
+              ((UnaryColumnTransformer) columnTransformer).getChildColumnTransformer()));
+    } else if (columnTransformer instanceof BinaryColumnTransformer) {
+      int childMaxLevel =
+          Math.max(
+              getMaxLevelOfColumnTransformerTree(
+                  ((BinaryColumnTransformer) columnTransformer).getLeftTransformer()),
+              getMaxLevelOfColumnTransformerTree(
+                  ((BinaryColumnTransformer) columnTransformer).getRightTransformer()));
+      return Math.max(3, childMaxLevel);
+    } else if (columnTransformer instanceof TernaryColumnTransformer) {
+      int childMaxLevel =
+          Math.max(
+              getMaxLevelOfColumnTransformerTree(
+                  ((TernaryColumnTransformer) columnTransformer).getFirstColumnTransformer()),
+              Math.max(
+                  getMaxLevelOfColumnTransformerTree(
+                      ((TernaryColumnTransformer) columnTransformer).getSecondColumnTransformer()),
+                  getMaxLevelOfColumnTransformerTree(
+                      ((TernaryColumnTransformer) columnTransformer).getThirdColumnTransformer())));
+      return Math.max(4, childMaxLevel);
+    } else if (columnTransformer instanceof MultiColumnTransformer) {
+      int childrenCount = ((MultiColumnTransformer) columnTransformer).getChildren().size();
+      OptionalInt childMaxLevel =
+          ((MultiColumnTransformer) columnTransformer)
+              .getChildren().stream().mapToInt(this::getMaxLevelOfColumnTransformerTree).max();
+
+      return Math.max(childrenCount + 1, childMaxLevel.orElse(childrenCount + 1));
+    } else if (columnTransformer instanceof MappableUDFColumnTransformer) {
+      int childMaxLevel = 0;
+      for (ColumnTransformer c :
+          ((MappableUDFColumnTransformer) columnTransformer).getInputColumnTransformers()) {
+        childMaxLevel = Math.max(childMaxLevel, getMaxLevelOfColumnTransformerTree(c));
+      }
+      return Math.max(
+          1
+              + ((MappableUDFColumnTransformer) columnTransformer)
+                  .getInputColumnTransformers()
+                  .length,
+          childMaxLevel);
+    } else if (columnTransformer instanceof AbstractCaseWhenThenColumnTransformer) {
+      int childMaxLevel = 0;
+      int childCount = 0;
+      for (Pair<ColumnTransformer, ColumnTransformer> whenThenColumnTransformer :
+          ((AbstractCaseWhenThenColumnTransformer) columnTransformer)
+              .getWhenThenColumnTransformers()) {
+        childMaxLevel =
+            Math.max(
+                childMaxLevel, getMaxLevelOfColumnTransformerTree(whenThenColumnTransformer.left));
+        childMaxLevel =
+            Math.max(
+                childMaxLevel, getMaxLevelOfColumnTransformerTree(whenThenColumnTransformer.right));
+        childCount++;
+      }
+      childMaxLevel =
+          Math.max(
+              childMaxLevel,
+              getMaxLevelOfColumnTransformerTree(
+                  ((AbstractCaseWhenThenColumnTransformer) columnTransformer)
+                      .getElseTransformer()));
+      childMaxLevel = Math.max(childMaxLevel, childCount + 2);
+      return childMaxLevel;
+    } else if (columnTransformer instanceof FailFunctionColumnTransformer) {
+      return 0;
+    } else {
+      throw new UnsupportedOperationException("Unsupported ColumnTransformer");
+    }
+  }
+
+  @Override
+  public long ramBytesUsed() {
+    return INSTANCE_SIZE
+        + MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(inputOperator)
+        + MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(operatorContext)
+        + filterTsBlockBuilder.getRetainedSizeInBytes();
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/LimitOperator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/LimitOperator.java
new file mode 100644
index 00000000000..9f21dcf86a6
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/LimitOperator.java
@@ -0,0 +1,116 @@
+/*
+ * 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.calc.execution.operator.process;
+
+import org.apache.iotdb.calc.execution.operator.CommonOperatorContext;
+import org.apache.iotdb.calc.execution.operator.Operator;
+import org.apache.iotdb.commons.queryengine.execution.MemoryEstimationHelper;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
+public class LimitOperator implements ProcessOperator {
+
+  private static final long INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(LimitOperator.class);
+  private final CommonOperatorContext operatorContext;
+  private long remainingLimit;
+  private final Operator child;
+
+  public LimitOperator(CommonOperatorContext operatorContext, long limit, Operator child) {
+    this.operatorContext = requireNonNull(operatorContext, "operatorContext is null");
+    checkArgument(limit >= 0, "limit must be at least zero");
+    this.remainingLimit = limit;
+    this.child = requireNonNull(child, "child operator is null");
+  }
+
+  public LimitOperator(LimitOperator limitOperator, Operator child) {
+    this.operatorContext = limitOperator.operatorContext;
+    this.remainingLimit = limitOperator.remainingLimit;
+    this.child = child;
+  }
+
+  @Override
+  public CommonOperatorContext getOperatorContext() {
+    return operatorContext;
+  }
+
+  @Override
+  public ListenableFuture<?> isBlocked() {
+    return child.isBlocked();
+  }
+
+  @Override
+  public TsBlock next() throws Exception {
+    TsBlock block = child.nextWithTimer();
+    if (block == null) {
+      return null;
+    }
+    TsBlock res = block;
+    if (block.getPositionCount() <= remainingLimit) {
+      remainingLimit -= block.getPositionCount();
+    } else {
+      res = block.getRegion(0, (int) remainingLimit);
+      remainingLimit = 0;
+    }
+    return res;
+  }
+
+  @Override
+  public boolean hasNext() throws Exception {
+    return remainingLimit > 0 && child.hasNextWithTimer();
+  }
+
+  @Override
+  public void close() throws Exception {
+    child.close();
+  }
+
+  @Override
+  public boolean isFinished() throws Exception {
+    return remainingLimit == 0 || child.isFinished();
+  }
+
+  @Override
+  public long calculateMaxPeekMemory() {
+    return child.calculateMaxPeekMemoryWithCounter();
+  }
+
+  @Override
+  public long calculateMaxReturnSize() {
+    return child.calculateMaxReturnSize();
+  }
+
+  @Override
+  public long calculateRetainedSizeAfterCallingNext() {
+    return child.calculateRetainedSizeAfterCallingNext();
+  }
+
+  @Override
+  public long ramBytesUsed() {
+    return INSTANCE_SIZE
+        + MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(child)
+        + MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(operatorContext);
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/MappingCollectOperator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/MappingCollectOperator.java
new file mode 100644
index 00000000000..8bc1c18e9e6
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/MappingCollectOperator.java
@@ -0,0 +1,81 @@
+/*
+ * 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.calc.execution.operator.process;
+
+import org.apache.iotdb.calc.execution.operator.CommonOperatorContext;
+import org.apache.iotdb.calc.execution.operator.Operator;
+import org.apache.iotdb.calc.plan.planner.CommonOperatorUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.read.common.block.column.RunLengthEncodedColumn;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.List;
+
+public class MappingCollectOperator extends CollectOperator {
+  protected static final long INSTANCE_SIZE =
+      RamUsageEstimator.shallowSizeOfInstance(MappingCollectOperator.class);
+
+  // record mapping for each child
+  private final List<List<Integer>> mappings;
+
+  private final int outputColumnsCount;
+
+  public MappingCollectOperator(
+      CommonOperatorContext operatorContext,
+      List<Operator> children,
+      List<List<Integer>> mappings) {
+    super(operatorContext, children);
+    this.mappings = mappings;
+    outputColumnsCount = mappings.get(0).size();
+  }
+
+  @Override
+  public TsBlock next() throws Exception {
+    if (children.get(currentIndex).hasNextWithTimer()) {
+      TsBlock tsBlock = children.get(currentIndex).nextWithTimer();
+      if (tsBlock == null) {
+        return null;
+      } else {
+        Column[] columns = new Column[outputColumnsCount];
+        List<Integer> mapping = mappings.get(currentIndex);
+        for (int i = 0; i < columns.length; i++) {
+          columns[i] = tsBlock.getColumn(mapping.get(i));
+        }
+        return TsBlock.wrapBlocksWithoutCopy(
+            tsBlock.getPositionCount(),
+            new RunLengthEncodedColumn(
+                CommonOperatorUtils.TIME_COLUMN_TEMPLATE, tsBlock.getPositionCount()),
+            columns);
+      }
+    } else {
+      closeCurrentChild(currentIndex);
+      currentIndex++;
+      return null;
+    }
+  }
+
+  protected void closeCurrentChild(int index) throws Exception {
+    children.get(index).close();
+    children.set(index, null);
+    mappings.set(index, null);
+  }
+}
diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/MergeSortOperator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/MergeSortOperator.java
new file mode 100644
index 00000000000..613d3f549d7
--- /dev/null
+++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/MergeSortOperator.java
@@ -0,0 +1,272 @@
+/*
+ * 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
... 283126 lines suppressed ...