forked from locationtech/geowave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Aggregation.java
114 lines (100 loc) · 3.72 KB
/
Aggregation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* Copyright (c) 2013-2020 Contributors to the Eclipse Foundation
*
* <p> See the NOTICE file distributed with this work for additional information regarding copyright
* ownership. All rights reserved. This program and the accompanying materials are made available
* under the terms of the Apache License, Version 2.0 which accompanies this distribution and is
* available at http://www.apache.org/licenses/LICENSE-2.0.txt
*/
package org.locationtech.geowave.core.store.api;
import org.locationtech.geowave.core.index.Mergeable;
import org.locationtech.geowave.core.index.persist.Persistable;
/**
* An Aggregation function that mathematically represents any commutative monoid (ie. a function
* that is both commutative and associative). For some data stores Aggregations will be run
* distributed on the server within the scope of iterating through the results for maximum
* efficiency. A third party Aggregation can be used, but if serverside processing is enabled, the
* third party Aggregation implementation must also be on the server classpath.
*
* @param <P> input type for the aggregation
* @param <R> result type for the aggregation
* @param <T> data type of the entries for the aggregation
*/
public interface Aggregation<P extends Persistable, R, T> extends Persistable {
/**
* Returns a persistable object for any parameters that must be persisted to properly compute the
* aggregation
*
* @return A persistable object for any parameters that must be persisted to properly compute the
* aggregation
*/
P getParameters();
/**
* Sets the parameters based on what has been persisted
*
* @param parameters the persisted parameters for this aggregation function
*/
void setParameters(P parameters);
/**
* Get the current result of the aggregation. This must be mergeable and it is the responsibility
* of the caller to merge separate results if desired. It is the responsibility of the aggregation
* to start with a new instance of the result at the beginning of any aggregation.
*
* @return the current result of the aggregation
*/
R getResult();
/**
* Merge two aggregation results into a single result
*
* @param result1 the first result
* @param result2 the second result
* @return the merged result
*/
default R merge(final R result1, final R result2) {
if (result1 == null) {
return result2;
} else if (result2 == null) {
return result1;
} else if ((result1 instanceof Mergeable) && (result2 instanceof Mergeable)) {
((Mergeable) result1).merge((Mergeable) result2);
return result1;
}
return null;
}
/**
* This is responsible for writing the result to binary
*
* @param result the result value
* @return the binary representing this value
*/
byte[] resultToBinary(R result);
/**
* This is responsible for reading the result from binary
*
* @param binary the binary representing this result
* @return the result value
*/
R resultFromBinary(byte[] binary);
/** this will be called if the result should be reset to its default value */
void clearResult();
/**
* Update the aggregation result using the new entry provided
*
* @param entry the new entry to compute an updated aggregation result on
*/
void aggregate(T entry);
/**
* Because the serialization of aggregation is just the function without the parameters or the
* result, its expected that this is empty
*/
@Override
default byte[] toBinary() {
return new byte[0];
}
/**
* Because the serialization of aggregation is just the function without the parameters or the
* result, its expected that there's nothing to deserialize
*/
@Override
default void fromBinary(byte[] bytes) {}
}