Skip to content

Commit b3052df

Browse files
Pipe: Added max / min function to aggregate-processor (#15459) (#15469)
Co-authored-by: Steve Yurong Su <rong@apache.org>
1 parent 3d08001 commit b3052df

7 files changed

Lines changed: 270 additions & 11 deletions

File tree

integration-test/src/test/java/org/apache/iotdb/pipe/it/single/IoTDBPipeAggregateIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public void testAggregator() throws Exception {
6666
processorAttributes.put("output.database", "root.testdb");
6767
processorAttributes.put(
6868
"output.measurements", "Avg1, peak1, rms1, var1, skew1, kurt1, ff1, cf1, pf1");
69-
processorAttributes.put("operators", "avg, peak, rms, var, skew, kurt, ff, cf, pf, cE");
69+
processorAttributes.put(
70+
"operators", "avg, peak, rms, var, skew, kurt, ff, cf, pf, cE, max, min");
7071
processorAttributes.put("sliding.seconds", "60");
7172

7273
connectorAttributes.put("sink", "write-back-sink");
@@ -115,7 +116,7 @@ public void testAggregator() throws Exception {
115116
env,
116117
"select count(*) from root.testdb.** group by level=1",
117118
"count(root.testdb.*.*.*.*),",
118-
Collections.singleton("20,"));
119+
Collections.singleton("24,"));
119120

120121
// Test manually renamed timeSeries count
121122
TestUtils.assertDataEventuallyOnEnv(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.db.pipe.processor.aggregate.operator.aggregatedresult.standardstatistics;
21+
22+
import org.apache.iotdb.db.pipe.processor.aggregate.operator.aggregatedresult.AggregatedResultOperator;
23+
import org.apache.iotdb.db.pipe.processor.aggregate.operator.intermediateresult.CustomizedReadableIntermediateResults;
24+
25+
import org.apache.tsfile.enums.TSDataType;
26+
import org.apache.tsfile.utils.Pair;
27+
28+
import java.util.Collections;
29+
import java.util.Map;
30+
import java.util.Set;
31+
32+
public class MaxValueOperator implements AggregatedResultOperator {
33+
@Override
34+
public String getName() {
35+
return "max";
36+
}
37+
38+
@Override
39+
public void configureSystemParameters(final Map<String, String> systemParams) {
40+
// Do nothing
41+
}
42+
43+
@Override
44+
public Set<String> getDeclaredIntermediateValueNames() {
45+
return Collections.singleton("max");
46+
}
47+
48+
@Override
49+
public Pair<TSDataType, Object> terminateWindow(
50+
final TSDataType measurementDataType,
51+
final CustomizedReadableIntermediateResults intermediateResults) {
52+
return new Pair<>(measurementDataType, intermediateResults.getObject("max"));
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.db.pipe.processor.aggregate.operator.aggregatedresult.standardstatistics;
21+
22+
import org.apache.iotdb.db.pipe.processor.aggregate.operator.aggregatedresult.AggregatedResultOperator;
23+
import org.apache.iotdb.db.pipe.processor.aggregate.operator.intermediateresult.CustomizedReadableIntermediateResults;
24+
25+
import org.apache.tsfile.enums.TSDataType;
26+
import org.apache.tsfile.utils.Pair;
27+
28+
import java.util.Collections;
29+
import java.util.Map;
30+
import java.util.Set;
31+
32+
public class MinValueOperator implements AggregatedResultOperator {
33+
@Override
34+
public String getName() {
35+
return "min";
36+
}
37+
38+
@Override
39+
public void configureSystemParameters(final Map<String, String> systemParams) {
40+
// Do nothing
41+
}
42+
43+
@Override
44+
public Set<String> getDeclaredIntermediateValueNames() {
45+
return Collections.singleton("min");
46+
}
47+
48+
@Override
49+
public Pair<TSDataType, Object> terminateWindow(
50+
final TSDataType measurementDataType,
51+
final CustomizedReadableIntermediateResults intermediateResults) {
52+
return new Pair<>(measurementDataType, intermediateResults.getObject("min"));
53+
}
54+
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/processor/aggregate/operator/intermediateresult/sametype/numeric/AbsoluteMaxOperator.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,46 +26,46 @@ public String getName() {
2626
}
2727

2828
@Override
29-
public boolean initAndGetIsSupport(int initialInput, long initialTimestamp) {
29+
public boolean initAndGetIsSupport(final int initialInput, final long initialTimestamp) {
3030
intValue = Math.abs(initialInput);
3131
return super.initAndGetIsSupport(initialInput, initialTimestamp);
3232
}
3333

3434
@Override
35-
public boolean initAndGetIsSupport(long initialInput, long initialTimestamp) {
35+
public boolean initAndGetIsSupport(final long initialInput, final long initialTimestamp) {
3636
longValue = Math.abs(initialInput);
3737
return super.initAndGetIsSupport(initialInput, initialTimestamp);
3838
}
3939

4040
@Override
41-
public boolean initAndGetIsSupport(float initialInput, long initialTimestamp) {
41+
public boolean initAndGetIsSupport(final float initialInput, final long initialTimestamp) {
4242
floatValue = Math.abs(initialInput);
4343
return super.initAndGetIsSupport(initialInput, initialTimestamp);
4444
}
4545

4646
@Override
47-
public boolean initAndGetIsSupport(double initialInput, long initialTimestamp) {
47+
public boolean initAndGetIsSupport(final double initialInput, final long initialTimestamp) {
4848
doubleValue = Math.abs(initialInput);
4949
return super.initAndGetIsSupport(initialInput, initialTimestamp);
5050
}
5151

5252
@Override
53-
public void updateValue(int input, long timestamp) {
53+
public void updateValue(final int input, final long timestamp) {
5454
intValue = Math.max(intValue, Math.abs(input));
5555
}
5656

5757
@Override
58-
public void updateValue(long input, long timestamp) {
58+
public void updateValue(final long input, final long timestamp) {
5959
longValue = Math.max(longValue, Math.abs(input));
6060
}
6161

6262
@Override
63-
public void updateValue(float input, long timestamp) {
63+
public void updateValue(final float input, final long timestamp) {
6464
floatValue = Math.max(floatValue, Math.abs(input));
6565
}
6666

6767
@Override
68-
public void updateValue(double input, long timestamp) {
68+
public void updateValue(final double input, final long timestamp) {
6969
doubleValue = Math.max(doubleValue, Math.abs(input));
7070
}
7171
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.db.pipe.processor.aggregate.operator.intermediateresult.sametype.numeric;
21+
22+
public class MaxOperator extends AbstractSameTypeNumericOperator {
23+
@Override
24+
public String getName() {
25+
return "max";
26+
}
27+
28+
@Override
29+
public boolean initAndGetIsSupport(int initialInput, long initialTimestamp) {
30+
intValue = initialInput;
31+
return super.initAndGetIsSupport(initialInput, initialTimestamp);
32+
}
33+
34+
@Override
35+
public boolean initAndGetIsSupport(long initialInput, long initialTimestamp) {
36+
longValue = initialInput;
37+
return super.initAndGetIsSupport(initialInput, initialTimestamp);
38+
}
39+
40+
@Override
41+
public boolean initAndGetIsSupport(final float initialInput, final long initialTimestamp) {
42+
floatValue = initialInput;
43+
return super.initAndGetIsSupport(initialInput, initialTimestamp);
44+
}
45+
46+
@Override
47+
public boolean initAndGetIsSupport(final double initialInput, final long initialTimestamp) {
48+
doubleValue = initialInput;
49+
return super.initAndGetIsSupport(initialInput, initialTimestamp);
50+
}
51+
52+
@Override
53+
public void updateValue(final int input, final long timestamp) {
54+
intValue = Math.max(intValue, input);
55+
}
56+
57+
@Override
58+
public void updateValue(final long input, final long timestamp) {
59+
longValue = Math.max(longValue, input);
60+
}
61+
62+
@Override
63+
public void updateValue(final float input, final long timestamp) {
64+
floatValue = Math.max(floatValue, input);
65+
}
66+
67+
@Override
68+
public void updateValue(final double input, final long timestamp) {
69+
doubleValue = Math.max(doubleValue, input);
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.db.pipe.processor.aggregate.operator.intermediateresult.sametype.numeric;
21+
22+
public class MinOperator extends AbstractSameTypeNumericOperator {
23+
@Override
24+
public String getName() {
25+
return "min";
26+
}
27+
28+
@Override
29+
public boolean initAndGetIsSupport(final int initialInput, final long initialTimestamp) {
30+
intValue = initialInput;
31+
return super.initAndGetIsSupport(initialInput, initialTimestamp);
32+
}
33+
34+
@Override
35+
public boolean initAndGetIsSupport(final long initialInput, final long initialTimestamp) {
36+
longValue = initialInput;
37+
return super.initAndGetIsSupport(initialInput, initialTimestamp);
38+
}
39+
40+
@Override
41+
public boolean initAndGetIsSupport(final float initialInput, final long initialTimestamp) {
42+
floatValue = initialInput;
43+
return super.initAndGetIsSupport(initialInput, initialTimestamp);
44+
}
45+
46+
@Override
47+
public boolean initAndGetIsSupport(final double initialInput, final long initialTimestamp) {
48+
doubleValue = initialInput;
49+
return super.initAndGetIsSupport(initialInput, initialTimestamp);
50+
}
51+
52+
@Override
53+
public void updateValue(final int input, final long timestamp) {
54+
intValue = Math.min(intValue, input);
55+
}
56+
57+
@Override
58+
public void updateValue(final long input, final long timestamp) {
59+
longValue = Math.min(longValue, input);
60+
}
61+
62+
@Override
63+
public void updateValue(final float input, final long timestamp) {
64+
floatValue = Math.min(floatValue, input);
65+
}
66+
67+
@Override
68+
public void updateValue(final double input, final long timestamp) {
69+
doubleValue = Math.min(doubleValue, input);
70+
}
71+
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/processor/aggregate/operator/processor/StandardStatisticsOperatorProcessor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import org.apache.iotdb.db.pipe.processor.aggregate.operator.aggregatedresult.standardstatistics.CrestFactorOperator;
2626
import org.apache.iotdb.db.pipe.processor.aggregate.operator.aggregatedresult.standardstatistics.FormFactorOperator;
2727
import org.apache.iotdb.db.pipe.processor.aggregate.operator.aggregatedresult.standardstatistics.KurtosisOperator;
28+
import org.apache.iotdb.db.pipe.processor.aggregate.operator.aggregatedresult.standardstatistics.MaxValueOperator;
29+
import org.apache.iotdb.db.pipe.processor.aggregate.operator.aggregatedresult.standardstatistics.MinValueOperator;
2830
import org.apache.iotdb.db.pipe.processor.aggregate.operator.aggregatedresult.standardstatistics.PeakOperator;
2931
import org.apache.iotdb.db.pipe.processor.aggregate.operator.aggregatedresult.standardstatistics.PulseFactorOperator;
3032
import org.apache.iotdb.db.pipe.processor.aggregate.operator.aggregatedresult.standardstatistics.RootMeanSquareOperator;
@@ -33,6 +35,8 @@
3335
import org.apache.iotdb.db.pipe.processor.aggregate.operator.intermediateresult.IntermediateResultOperator;
3436
import org.apache.iotdb.db.pipe.processor.aggregate.operator.intermediateresult.sametype.numeric.AbsoluteMaxOperator;
3537
import org.apache.iotdb.db.pipe.processor.aggregate.operator.intermediateresult.sametype.numeric.IntegralPoweredSumOperator;
38+
import org.apache.iotdb.db.pipe.processor.aggregate.operator.intermediateresult.sametype.numeric.MaxOperator;
39+
import org.apache.iotdb.db.pipe.processor.aggregate.operator.intermediateresult.sametype.numeric.MinOperator;
3640
import org.apache.iotdb.db.pipe.processor.aggregate.operator.intermediateresult.specifictype.doubletype.FractionPoweredSumOperator;
3741
import org.apache.iotdb.db.pipe.processor.aggregate.operator.intermediateresult.specifictype.integertype.CountOperator;
3842

@@ -54,6 +58,8 @@ public Set<AggregatedResultOperator> getAggregatorOperatorSet() {
5458
new FormFactorOperator(),
5559
new KurtosisOperator(),
5660
new PeakOperator(),
61+
new MaxValueOperator(),
62+
new MinValueOperator(),
5763
new PulseFactorOperator(),
5864
new RootMeanSquareOperator(),
5965
new SkewnessOperator(),
@@ -71,6 +77,8 @@ public Set<Supplier<IntermediateResultOperator>> getIntermediateResultOperatorSu
7177
() -> new IntegralPoweredSumOperator(1),
7278
() -> new IntegralPoweredSumOperator(2),
7379
() -> new IntegralPoweredSumOperator(3),
74-
() -> new IntegralPoweredSumOperator(4))));
80+
() -> new IntegralPoweredSumOperator(4),
81+
MaxOperator::new,
82+
MinOperator::new)));
7583
}
7684
}

0 commit comments

Comments
 (0)