Class GroupBy

java.lang.Object
com.querydsl.core.group.GroupBy

public class GroupBy extends Object
GroupBy provides factory methods for ResultTransformer and GroupExpression creation

Example: Group employees by department


 query.transform(
     GroupBy.groupBy(employee.department)
            .as(GroupBy.list(Projections.tuple(employee.id, employee.firstName, employee.lastName))))
 
Author:
sasa, tiwe
  • Constructor Details

    • GroupBy

      protected GroupBy()
  • Method Details

    • groupBy

      public static <K> GroupByBuilder<K> groupBy(Expression<K> key)
      Create a new GroupByBuilder for the given key expression
      Parameters:
      key - key for aggregation
      Returns:
      builder for further specification
    • groupBy

      public static GroupByBuilder<List<?>> groupBy(Expression<?>... keys)
      Create a new GroupByBuilder for the given key expressions
      Parameters:
      keys - keys for aggregation
      Returns:
      builder for further specification
    • min

      public static <E extends Comparable<? super E>> AbstractGroupExpression<E,E> min(Expression<E> expression)
      Create a new aggregating min expression
      Parameters:
      expression - expression for which the minimum value will be used in the group by projection
      Returns:
      wrapper expression
    • sum

      public static <E extends Number> AbstractGroupExpression<E,E> sum(Expression<E> expression)
      Create a new aggregating sum expression
      Parameters:
      expression - expression a for which the accumulated sum will be used in the group by projection
      Returns:
      wrapper expression
    • avg

      public static <E extends Number> AbstractGroupExpression<E,E> avg(Expression<E> expression)
      Create a new aggregating avg expression, uses default MathContext.DECIMAL128 for average calculation
      Parameters:
      expression - expression for which the accumulated average value will be used in the group by projection
      Returns:
      wrapper expression
    • avg

      public static <E extends Number> AbstractGroupExpression<E,E> avg(Expression<E> expression, MathContext mathContext)
      Create a new aggregating avg expression with a user-provided MathContext
      Parameters:
      expression - expression for which the accumulated average value will be used in the group by projection
      mathContext - mathContext for average calculation
      Returns:
      wrapper expression
    • max

      public static <E extends Comparable<? super E>> AbstractGroupExpression<E,E> max(Expression<E> expression)
      Create a new aggregating max expression
      Parameters:
      expression - expression for which the maximum value will be used in the group by projection
      Returns:
      wrapper expression
    • list

      public static <E> AbstractGroupExpression<E,List<E>> list(Expression<E> expression)
      Create a new aggregating list expression
      Parameters:
      expression - values for this expression will be accumulated into a list
      Returns:
      wrapper expression
    • list

      public static <E, F> AbstractGroupExpression<E,List<F>> list(GroupExpression<E,F> groupExpression)
      Create a new aggregating list expression
      Type Parameters:
      E -
      F -
      Parameters:
      groupExpression - values for this expression will be accumulated into a list
      Returns:
      wrapper expression
    • set

      public static <E> AbstractGroupExpression<E,Set<E>> set(Expression<E> expression)
      Create a new aggregating set expression using a backing LinkedHashSet
      Parameters:
      expression - values for this expression will be accumulated into a set
      Returns:
      wrapper expression
    • set

      public static <E, F> GroupExpression<E,Set<F>> set(GroupExpression<E,F> groupExpression)
      Create a new aggregating set expression using a backing LinkedHashSet
      Type Parameters:
      E -
      F -
      Parameters:
      groupExpression - values for this expression will be accumulated into a set
      Returns:
      wrapper expression
    • sortedSet

      public static <E extends Comparable<? super E>> AbstractGroupExpression<E,SortedSet<E>> sortedSet(Expression<E> expression)
      Create a new aggregating set expression using a backing TreeSet
      Parameters:
      expression - values for this expression will be accumulated into a set
      Returns:
      wrapper expression
    • sortedSet

      public static <E, F extends Comparable<? super F>> GroupExpression<E,SortedSet<F>> sortedSet(GroupExpression<E,F> groupExpression)
      Create a new aggregating set expression using a backing TreeSet
      Parameters:
      groupExpression - values for this expression will be accumulated into a set
      Returns:
      wrapper expression
    • sortedSet

      public static <E> AbstractGroupExpression<E,SortedSet<E>> sortedSet(Expression<E> expression, Comparator<? super E> comparator)
      Create a new aggregating set expression using a backing TreeSet using the given comparator
      Parameters:
      expression - values for this expression will be accumulated into a set
      comparator - comparator of the created TreeSet instance
      Returns:
      wrapper expression
    • sortedSet

      public static <E, F> GroupExpression<E,SortedSet<F>> sortedSet(GroupExpression<E,F> groupExpression, Comparator<? super F> comparator)
      Create a new aggregating set expression using a backing TreeSet using the given comparator
      Parameters:
      groupExpression - values for this expression will be accumulated into a set
      comparator - comparator of the created TreeSet instance
      Returns:
      wrapper expression
    • map

      public static <K, V> AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>,Map<K,V>> map(Expression<K> key, Expression<V> value)
      Create a new aggregating map expression using a backing LinkedHashMap
      Parameters:
      key - key for the map entries
      value - value for the map entries
      Returns:
      wrapper expression
    • map

      public static <K, V, T> AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>,Map<T,V>> map(GroupExpression<K,T> key, Expression<V> value)
      Create a new aggregating map expression using a backing LinkedHashMap
      Parameters:
      key - key for the map entries
      value - value for the map entries
      Returns:
      wrapper expression
    • map

      public static <K, V, U> AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>,Map<K,U>> map(Expression<K> key, GroupExpression<V,U> value)
      Create a new aggregating map expression using a backing LinkedHashMap
      Parameters:
      key - key for the map entries
      value - value for the map entries
      Returns:
      wrapper expression
    • map

      public static <K, V, T, U> AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>,Map<T,U>> map(GroupExpression<K,T> key, GroupExpression<V,U> value)
      Create a new aggregating map expression using a backing LinkedHashMap
      Parameters:
      key - key for the map entries
      value - value for the map entries
      Returns:
      wrapper expression
    • sortedMap

      public static <K extends Comparable<? super K>, V> AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>,SortedMap<K,V>> sortedMap(Expression<K> key, Expression<V> value)
      Create a new aggregating map expression using a backing TreeMap
      Parameters:
      key - key for the map entries
      value - value for the map entries
      Returns:
      wrapper expression
    • sortedMap

      public static <K, V, T extends Comparable<? super T>> AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>,SortedMap<T,V>> sortedMap(GroupExpression<K,T> key, Expression<V> value)
      Create a new aggregating map expression using a backing TreeMap
      Parameters:
      key - key for the map entries
      value - value for the map entries
      Returns:
      wrapper expression
    • sortedMap

      public static <K extends Comparable<? super K>, V, U> AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>,SortedMap<K,U>> sortedMap(Expression<K> key, GroupExpression<V,U> value)
      Create a new aggregating map expression using a backing TreeMap
      Parameters:
      key - key for the map entries
      value - value for the map entries
      Returns:
      wrapper expression
    • sortedMap

      public static <K, V, T extends Comparable<? super T>, U> AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>,SortedMap<T,U>> sortedMap(GroupExpression<K,T> key, GroupExpression<V,U> value)
      Create a new aggregating map expression using a backing TreeMap
      Parameters:
      key - key for the map entries
      value - value for the map entries
      Returns:
      wrapper expression
    • sortedMap

      public static <K, V> AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>,SortedMap<K,V>> sortedMap(Expression<K> key, Expression<V> value, Comparator<? super K> comparator)
      Create a new aggregating map expression using a backing TreeMap using the given comparator
      Parameters:
      key - key for the map entries
      value - value for the map entries
      comparator - comparator for the created TreeMap instances
      Returns:
      wrapper expression
    • sortedMap

      public static <K, V, T> AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>,SortedMap<T,V>> sortedMap(GroupExpression<K,T> key, Expression<V> value, Comparator<? super T> comparator)
      Create a new aggregating map expression using a backing TreeMap using the given comparator
      Parameters:
      key - key for the map entries
      value - value for the map entries
      comparator - comparator for the created TreeMap instances
      Returns:
      wrapper expression
    • sortedMap

      public static <K, V, U> AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>,SortedMap<K,U>> sortedMap(Expression<K> key, GroupExpression<V,U> value, Comparator<? super K> comparator)
      Create a new aggregating map expression using a backing TreeMap using the given comparator
      Parameters:
      key - key for the map entries
      value - value for the map entries
      comparator - comparator for the created TreeMap instances
      Returns:
      wrapper expression
    • sortedMap

      public static <K, V, T, U> AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>,SortedMap<T,U>> sortedMap(GroupExpression<K,T> key, GroupExpression<V,U> value, Comparator<? super T> comparator)
      Create a new aggregating map expression using a backing TreeMap using the given comparator
      Parameters:
      key - key for the map entries
      value - value for the map entries
      comparator - comparator for the created TreeMap instances
      Returns:
      wrapper expression