com.hazelcast.mapreduce.aggregation.Aggregations Maven / Gradle / Ivy
/*
* Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.
*
* 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
*
* 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 com.hazelcast.mapreduce.aggregation;
import com.hazelcast.mapreduce.Collator;
import com.hazelcast.mapreduce.CombinerFactory;
import com.hazelcast.mapreduce.Mapper;
import com.hazelcast.mapreduce.ReducerFactory;
import com.hazelcast.mapreduce.aggregation.impl.AggType;
import com.hazelcast.mapreduce.aggregation.impl.BigDecimalAvgAggregation;
import com.hazelcast.mapreduce.aggregation.impl.BigDecimalMaxAggregation;
import com.hazelcast.mapreduce.aggregation.impl.BigDecimalMinAggregation;
import com.hazelcast.mapreduce.aggregation.impl.BigDecimalSumAggregation;
import com.hazelcast.mapreduce.aggregation.impl.BigIntegerAvgAggregation;
import com.hazelcast.mapreduce.aggregation.impl.BigIntegerMaxAggregation;
import com.hazelcast.mapreduce.aggregation.impl.BigIntegerMinAggregation;
import com.hazelcast.mapreduce.aggregation.impl.BigIntegerSumAggregation;
import com.hazelcast.mapreduce.aggregation.impl.ComparableMaxAggregation;
import com.hazelcast.mapreduce.aggregation.impl.ComparableMinAggregation;
import com.hazelcast.mapreduce.aggregation.impl.CountAggregation;
import com.hazelcast.mapreduce.aggregation.impl.DistinctValuesAggregation;
import com.hazelcast.mapreduce.aggregation.impl.DoubleAvgAggregation;
import com.hazelcast.mapreduce.aggregation.impl.DoubleMaxAggregation;
import com.hazelcast.mapreduce.aggregation.impl.DoubleMinAggregation;
import com.hazelcast.mapreduce.aggregation.impl.DoubleSumAggregation;
import com.hazelcast.mapreduce.aggregation.impl.IntegerAvgAggregation;
import com.hazelcast.mapreduce.aggregation.impl.IntegerMaxAggregation;
import com.hazelcast.mapreduce.aggregation.impl.IntegerMinAggregation;
import com.hazelcast.mapreduce.aggregation.impl.IntegerSumAggregation;
import com.hazelcast.mapreduce.aggregation.impl.LongAvgAggregation;
import com.hazelcast.mapreduce.aggregation.impl.LongMaxAggregation;
import com.hazelcast.mapreduce.aggregation.impl.LongMinAggregation;
import com.hazelcast.mapreduce.aggregation.impl.LongSumAggregation;
import com.hazelcast.spi.annotation.Beta;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Map;
import java.util.Set;
/**
* This class is used to access the Hazelcast predefined set of aggregations in a type-safe
* way.
* @since 3.3
*/
@Beta
public final class Aggregations {
private Aggregations() {
}
/**
* Returns an aggregation for counting all supplied values.
* This aggregation is similar to: SELECT COUNT(*) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the count of all supplied elements
*/
public static Aggregation count() {
return new AggregationAdapter(new CountAggregation());
}
/**
* Returns an aggregation for selecting all distinct values.
* This aggregation is similar to: SELECT DISTINCT * FROM x
*
* @param the input key type
* @param the supplied value type
* @param the type of all distinct values
* @return a {@link java.util.Set} containing all distinct values
*/
public static Aggregation> distinctValues() {
AggType, Set, Set> aggType;
aggType = new DistinctValuesAggregation();
return new AggregationAdapter>(aggType);
}
/**
* Returns an aggregation to calculate the integer average of all supplied values.
* This aggregation is similar to: SELECT AVG(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the average over all supplied values
*/
public static Aggregation integerAvg() {
return new AggregationAdapter(new IntegerAvgAggregation());
}
/**
* Returns an aggregation to calculate the integer sum of all supplied values.
* This aggregation is similar to: SELECT SUM(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the sum over all supplied values
*/
public static Aggregation integerSum() {
return new AggregationAdapter(new IntegerSumAggregation());
}
/**
* Returns an aggregation to find the integer minimum of all supplied values.
* This aggregation is similar to: SELECT MIN(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the minimum value over all supplied values
*/
public static Aggregation integerMin() {
return new AggregationAdapter(new IntegerMinAggregation());
}
/**
* Returns an aggregation to find the integer maximum of all supplied values.
* This aggregation is similar to: SELECT MAX(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the maximum value over all supplied values
*/
public static Aggregation integerMax() {
return new AggregationAdapter(new IntegerMaxAggregation());
}
/**
* Returns an aggregation to calculate the long average of all supplied values.
* This aggregation is similar to: SELECT AVG(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the average over all supplied values
*/
public static Aggregation longAvg() {
return new AggregationAdapter(new LongAvgAggregation());
}
/**
* Returns an aggregation to calculate the long sum of all supplied values.
* This aggregation is similar to: SELECT SUM(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the sum over all supplied values
*/
public static Aggregation longSum() {
return new AggregationAdapter(new LongSumAggregation());
}
/**
* Returns an aggregation to find the long minimum of all supplied values.
* This aggregation is similar to: SELECT MIN(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the minimum value over all supplied values
*/
public static Aggregation longMin() {
return new AggregationAdapter(new LongMinAggregation());
}
/**
* Returns an aggregation to find the long maximum of all supplied values.
* This aggregation is similar to: SELECT MAX(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the maximum value over all supplied values
*/
public static Aggregation longMax() {
return new AggregationAdapter(new LongMaxAggregation());
}
/**
* Returns an aggregation to calculate the double average of all supplied values.
* This aggregation is similar to: SELECT AVG(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the average over all supplied values
*/
public static Aggregation doubleAvg() {
return new AggregationAdapter(new DoubleAvgAggregation());
}
/**
* Returns an aggregation to calculate the double sum of all supplied values.
* This aggregation is similar to: SELECT SUM(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the sum over all supplied values
*/
public static Aggregation doubleSum() {
return new AggregationAdapter(new DoubleSumAggregation());
}
/**
* Returns an aggregation to find the double minimum of all supplied values.
* This aggregation is similar to: SELECT MIN(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the minimum value over all supplied values
*/
public static Aggregation doubleMin() {
return new AggregationAdapter(new DoubleMinAggregation());
}
/**
* Returns an aggregation to find the double maximum of all supplied values.
* This aggregation is similar to: SELECT MAX(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the maximum value over all supplied values
*/
public static Aggregation doubleMax() {
return new AggregationAdapter(new DoubleMaxAggregation());
}
/**
* Returns an aggregation to calculate the {@link java.math.BigDecimal} average
* of all supplied values.
* This aggregation is similar to: SELECT AVG(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the average over all supplied values
*/
public static Aggregation bigDecimalAvg() {
return new AggregationAdapter(new BigDecimalAvgAggregation());
}
/**
* Returns an aggregation to calculate the {@link java.math.BigDecimal} sum
* of all supplied values.
* This aggregation is similar to: SELECT SUM(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the sum over all supplied values
*/
public static Aggregation bigDecimalSum() {
return new AggregationAdapter(new BigDecimalSumAggregation());
}
/**
* Returns an aggregation to find the {@link java.math.BigDecimal} minimum
* of all supplied values.
* This aggregation is similar to: SELECT MIN(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the minimum value over all supplied values
*/
public static Aggregation bigDecimalMin() {
return new AggregationAdapter(new BigDecimalMinAggregation());
}
/**
* Returns an aggregation to find the {@link java.math.BigDecimal} maximum
* of all supplied values.
* This aggregation is similar to: SELECT MAX(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the maximum value over all supplied values
*/
public static Aggregation bigDecimalMax() {
return new AggregationAdapter(new BigDecimalMaxAggregation());
}
/**
* Returns an aggregation to calculate the {@link java.math.BigInteger} average
* of all supplied values.
* This aggregation is similar to: SELECT AVG(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the average over all supplied values
*/
public static Aggregation bigIntegerAvg() {
return new AggregationAdapter(new BigIntegerAvgAggregation());
}
/**
* Returns an aggregation to calculate the {@link java.math.BigInteger} sum
* of all supplied values.
* This aggregation is similar to: SELECT SUM(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the sum over all supplied values
*/
public static Aggregation bigIntegerSum() {
return new AggregationAdapter(new BigIntegerSumAggregation());
}
/**
* Returns an aggregation to find the {@link java.math.BigInteger} minimum
* of all supplied values.
* This aggregation is similar to: SELECT MIN(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the minimum value over all supplied values
*/
public static Aggregation bigIntegerMin() {
return new AggregationAdapter(new BigIntegerMinAggregation());
}
/**
* Returns an aggregation to find the {@link java.math.BigInteger} maximum
* of all supplied values.
* This aggregation is similar to: SELECT MAX(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the maximum value over all supplied values
*/
public static Aggregation bigIntegerMax() {
return new AggregationAdapter(new BigIntegerMaxAggregation());
}
/**
* Returns an aggregation to find the minimum value of all supplied
* {@link java.lang.Comparable} implementing values.
* This aggregation is similar to: SELECT MIN(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the minimum value over all supplied values
*/
public static Aggregation comparableMin() {
return new AggregationAdapter(new ComparableMinAggregation());
}
/**
* Returns an aggregation to find the maximum value of all supplied
* {@link java.lang.Comparable} implementing values.
* This aggregation is similar to: SELECT MAX(value) FROM x
*
* @param the input key type
* @param the supplied value type
* @return the maximum value over all supplied values
*/
public static Aggregation comparableMax() {
return new AggregationAdapter(new ComparableMaxAggregation());
}
/**
* Adapter class from internal {@link com.hazelcast.mapreduce.aggregation.impl.AggType}
* to public API {@link com.hazelcast.mapreduce.aggregation.Aggregation}s. It is used to
* make the internal aggregations implementation more type-safe while exporting only necessary
* types to the public API.
*
* @param the input key type
* @param the supplied value type
* @param the result value type
*/
private static final class AggregationAdapter
implements Aggregation {
private final AggType internalAggregationType;
private AggregationAdapter(AggType internalAggregationType) {
this.internalAggregationType = internalAggregationType;
}
@Override
public Collator getCollator() {
return internalAggregationType.getCollator();
}
@Override
public Mapper getMapper(Supplier supplier) {
return internalAggregationType.getMapper(supplier);
}
@Override
public CombinerFactory getCombinerFactory() {
return internalAggregationType.getCombinerFactory();
}
@Override
public ReducerFactory getReducerFactory() {
return internalAggregationType.getReducerFactory();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy