1919
2020package org .apache .iotdb .db .queryengine .execution .aggregation ;
2121
22- import org .apache .iotdb .db .queryengine .metric .QueryExecutionMetricSet ;
2322import org .apache .iotdb .db .queryengine .plan .planner .plan .parameter .AggregationStep ;
2423import org .apache .iotdb .db .queryengine .plan .planner .plan .parameter .InputLocation ;
2524
3433import java .util .List ;
3534
3635import static com .google .common .base .Preconditions .checkArgument ;
37- import static org .apache .iotdb .db .queryengine .metric .QueryExecutionMetricSet .AGGREGATION_FROM_RAW_DATA ;
38- import static org .apache .iotdb .db .queryengine .metric .QueryExecutionMetricSet .AGGREGATION_FROM_STATISTICS ;
3936
4037public class Aggregator {
4138
4239 protected final Accumulator accumulator ;
4340 // In some intermediate result input, inputLocation[] should include two columns
4441 protected List <InputLocation []> inputLocationList ;
4542 protected final AggregationStep step ;
46- protected static final QueryExecutionMetricSet QUERY_EXECUTION_METRICS =
47- QueryExecutionMetricSet .getInstance ();
4843
4944 // Used for SeriesAggregateScanOperator
5045 public Aggregator (Accumulator accumulator , AggregationStep step ) {
@@ -64,57 +59,44 @@ public Aggregator(
6459
6560 // Used for SeriesAggregateScanOperator and RawDataAggregateOperator
6661 public void processTsBlock (TsBlock tsBlock , BitMap bitMap ) {
67- long startTime = System .nanoTime ();
68- try {
69- checkArgument (
70- step .isInputRaw (),
71- "Step in SeriesAggregateScanOperator and RawDataAggregateOperator can only process raw input" );
72- for (InputLocation [] inputLocations : inputLocationList ) {
73- Column [] timeAndValueColumn = new Column [1 + inputLocations .length ];
74- timeAndValueColumn [0 ] = tsBlock .getTimeColumn ();
75- for (int i = 0 ; i < inputLocations .length ; i ++) {
76- checkArgument (
77- inputLocations [i ].getTsBlockIndex () == 0 ,
78- "RawDataAggregateOperator can only process one tsBlock input." );
79- int index = inputLocations [i ].getValueColumnIndex ();
80- // for count_time, time column is also its value column
81- // for max_by, the input column can also be time column.
82- timeAndValueColumn [1 + i ] =
83- index == -1 ? timeAndValueColumn [0 ] : tsBlock .getColumn (index );
84- }
85- accumulator .addInput (timeAndValueColumn , bitMap );
62+ checkArgument (
63+ step .isInputRaw (),
64+ "Step in SeriesAggregateScanOperator and RawDataAggregateOperator can only process raw input" );
65+ for (InputLocation [] inputLocations : inputLocationList ) {
66+ Column [] timeAndValueColumn = new Column [1 + inputLocations .length ];
67+ timeAndValueColumn [0 ] = tsBlock .getTimeColumn ();
68+ for (int i = 0 ; i < inputLocations .length ; i ++) {
69+ checkArgument (
70+ inputLocations [i ].getTsBlockIndex () == 0 ,
71+ "RawDataAggregateOperator can only process one tsBlock input." );
72+ int index = inputLocations [i ].getValueColumnIndex ();
73+ // for count_time, time column is also its value column
74+ // for max_by, the input column can also be time column.
75+ timeAndValueColumn [1 + i ] = index == -1 ? timeAndValueColumn [0 ] : tsBlock .getColumn (index );
8676 }
87- } finally {
88- QUERY_EXECUTION_METRICS .recordExecutionCost (
89- AGGREGATION_FROM_RAW_DATA , System .nanoTime () - startTime );
77+ accumulator .addInput (timeAndValueColumn , bitMap );
9078 }
9179 }
9280
9381 // Used for AggregateOperator
9482 public void processTsBlocks (TsBlock [] tsBlock ) {
95- long startTime = System .nanoTime ();
96- try {
97- checkArgument (!step .isInputRaw (), "Step in AggregateOperator cannot process raw input" );
98- if (step .isInputFinal ()) {
99- checkArgument (inputLocationList .size () == 1 , "Final output can only be single column" );
100- Column finalResult =
101- tsBlock [inputLocationList .get (0 )[0 ].getTsBlockIndex ()].getColumn (
102- inputLocationList .get (0 )[0 ].getValueColumnIndex ());
103- accumulator .setFinal (finalResult );
104- } else {
105- for (InputLocation [] inputLocations : inputLocationList ) {
106- Column [] columns = new Column [inputLocations .length ];
107- for (int i = 0 ; i < inputLocations .length ; i ++) {
108- columns [i ] =
109- tsBlock [inputLocations [i ].getTsBlockIndex ()].getColumn (
110- inputLocations [i ].getValueColumnIndex ());
111- }
112- accumulator .addIntermediate (columns );
83+ checkArgument (!step .isInputRaw (), "Step in AggregateOperator cannot process raw input" );
84+ if (step .isInputFinal ()) {
85+ checkArgument (inputLocationList .size () == 1 , "Final output can only be single column" );
86+ Column finalResult =
87+ tsBlock [inputLocationList .get (0 )[0 ].getTsBlockIndex ()].getColumn (
88+ inputLocationList .get (0 )[0 ].getValueColumnIndex ());
89+ accumulator .setFinal (finalResult );
90+ } else {
91+ for (InputLocation [] inputLocations : inputLocationList ) {
92+ Column [] columns = new Column [inputLocations .length ];
93+ for (int i = 0 ; i < inputLocations .length ; i ++) {
94+ columns [i ] =
95+ tsBlock [inputLocations [i ].getTsBlockIndex ()].getColumn (
96+ inputLocations [i ].getValueColumnIndex ());
11397 }
98+ accumulator .addIntermediate (columns );
11499 }
115- } finally {
116- QUERY_EXECUTION_METRICS .recordExecutionCost (
117- AGGREGATION_FROM_RAW_DATA , System .nanoTime () - startTime );
118100 }
119101 }
120102
@@ -128,16 +110,10 @@ public void outputResult(ColumnBuilder[] columnBuilder) {
128110
129111 /** Used for SeriesAggregateScanOperator. */
130112 public void processStatistics (Statistics timeStatistics , Statistics [] valueStatistics ) {
131- long startTime = System .nanoTime ();
132- try {
133- for (InputLocation [] inputLocations : inputLocationList ) {
134- int valueIndex = inputLocations [0 ].getValueColumnIndex ();
135- // valueIndex == -1 means it is count_time, we need to use timeStatistics
136- accumulator .addStatistics (valueIndex == -1 ? timeStatistics : valueStatistics [valueIndex ]);
137- }
138- } finally {
139- QUERY_EXECUTION_METRICS .recordExecutionCost (
140- AGGREGATION_FROM_STATISTICS , System .nanoTime () - startTime );
113+ for (InputLocation [] inputLocations : inputLocationList ) {
114+ int valueIndex = inputLocations [0 ].getValueColumnIndex ();
115+ // valueIndex == -1 means it is count_time, we need to use timeStatistics
116+ accumulator .addStatistics (valueIndex == -1 ? timeStatistics : valueStatistics [valueIndex ]);
141117 }
142118 }
143119
0 commit comments