io.datakernel.aggregation.ot.AggregationStructure Maven / Gradle / Ivy
package io.datakernel.aggregation.ot;
import io.datakernel.aggregation.ChunkIdCodec;
import io.datakernel.aggregation.fieldtype.FieldType;
import io.datakernel.aggregation.measure.Measure;
import io.datakernel.util.Initializable;
import java.util.*;
import static io.datakernel.util.Preconditions.checkArgument;
@SuppressWarnings("rawtypes")
public final class AggregationStructure implements Initializable {
private final ChunkIdCodec> chunkIdCodec;
private final Map keyTypes = new LinkedHashMap<>();
private final Map measureTypes = new LinkedHashMap<>();
private final List partitioningKey = new ArrayList<>();
private final Map measures = new LinkedHashMap<>();
private AggregationStructure(ChunkIdCodec> chunkIdCodec) {
this.chunkIdCodec = chunkIdCodec;
}
public static AggregationStructure create(ChunkIdCodec> chunkIdCodec) {
return new AggregationStructure(chunkIdCodec);
}
public AggregationStructure withKey(String keyId, FieldType type) {
checkArgument(!keyTypes.containsKey(keyId), "Key '%s' has already been added", keyId);
keyTypes.put(keyId, type);
return this;
}
public AggregationStructure withMeasure(String measureId, Measure aggregateFunction) {
checkArgument(!measureTypes.containsKey(measureId), "Measure '%s' has already been added", measureId);
measureTypes.put(measureId, aggregateFunction.getFieldType());
measures.put(measureId, aggregateFunction);
return this;
}
public AggregationStructure withIgnoredMeasure(String measureId, FieldType measureType) {
checkArgument(!measureTypes.containsKey(measureId), "Measure '%s' has already been added", measureId);
measureTypes.put(measureId, measureType);
return this;
}
public AggregationStructure withPartitioningKey(List partitioningKey) {
this.partitioningKey.addAll(partitioningKey);
return this;
}
public ChunkIdCodec> getChunkIdCodec() {
return chunkIdCodec;
}
public AggregationStructure withPartitioningKey(String... partitioningKey) {
this.partitioningKey.addAll(Arrays.asList(partitioningKey));
return this;
}
public List getKeys() {
return new ArrayList<>(keyTypes.keySet());
}
public List getMeasures() {
return new ArrayList<>(measures.keySet());
}
public Map getKeyTypes() {
return keyTypes;
}
public Map getMeasureTypes() {
return measureTypes;
}
public Measure getMeasure(String field) {
return measures.get(field);
}
public FieldType getKeyType(String key) {
return keyTypes.get(key);
}
public FieldType getMeasureType(String field) {
return measureTypes.get(field);
}
public List getPartitioningKey() {
return partitioningKey;
}
}