-
- All Superinterfaces:
Collectable<T>
- All Known Implementing Classes:
WindowImpl
public interface Window<T> extends Collectable<T>
A window containing the data for its partition, to perform calculations upon.Window functions as exposed in this type are inspired by their counterparts in SQL. They include:
Ranking functions
Ranking functions are useful to determine the "rank" of any given row within the partition, given a specific ordering. The following table explains individual ranking functions:Function Description rowNumber()
The distinct row number of the row within the partition, counting from 0
.rank()
The rank with gaps of a row within the partition, counting from 0
.denseRank()
The rank without gaps of a row within the partition, counting from 0
.percentRank()
Relative rank of a row: rank()
/Collectable.count()
.ntile(long)
Divides the partition in equal buckets and assigns values between 0
andbuckets - 1
.lead()
Gets the value after the current row. lag()
Gets the value before the current row. firstValue()
Gets the first value in the window. lastValue()
Gets the last value in the window. nthValue(long)
Gets the nth value in the window, counting from 0
.Note: In Java, indexes are always counted from
0
, not from1
as in SQL. This means that the above ranking functions also rank rows from zero. This is particularly true for:Aggregate functions
Each aggregate function fromSeq
or fromAgg
is also available as an aggregate function on the window. For instance,Collectable.count()
is the same as callingSeq.count()
onwindow()
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description long
denseRank()
The dense rank of the current row within the partition.java.util.Optional<T>
firstValue()
The first value in the window.<U> java.util.Optional<U>
firstValue(java.util.function.Function<? super T,? extends U> function)
The first value in the window.java.util.Optional<T>
lag()
The previous value in the window.java.util.Optional<T>
lag(long lag)
The previous value bylag
in the window.java.util.Optional<T>
lastValue()
The last value in the window.<U> java.util.Optional<U>
lastValue(java.util.function.Function<? super T,? extends U> function)
The last value in the window.java.util.Optional<T>
lead()
The next value in the window.java.util.Optional<T>
lead(long lead)
The next value bylead
in the window.java.util.Optional<T>
nthValue(long n)
The nth value in the window.<U> java.util.Optional<U>
nthValue(long n, java.util.function.Function<? super T,? extends U> function)
The nth value in the window.long
ntile(long buckets)
The bucket number ("ntile") of the current row within the partition.static <T> WindowSpecification<T>
of()
static <T> WindowSpecification<T>
of(long lower, long upper)
static <T> WindowSpecification<T>
of(java.util.Comparator<? super T> orderBy)
static <T> WindowSpecification<T>
of(java.util.Comparator<? super T> orderBy, long lower, long upper)
static <T,U>
WindowSpecification<T>of(java.util.function.Function<? super T,? extends U> partitionBy)
static <T,U>
WindowSpecification<T>of(java.util.function.Function<? super T,? extends U> partitionBy, long lower, long upper)
static <T,U>
WindowSpecification<T>of(java.util.function.Function<? super T,? extends U> partitionBy, java.util.Comparator<? super T> orderBy)
static <T,U>
WindowSpecification<T>of(java.util.function.Function<? super T,? extends U> partitionBy, java.util.Comparator<? super T> orderBy, long lower, long upper)
double
percentRank()
The precent rank of the current row within the partition.long
rank()
The rank of the current row within the partition.long
rowNumber()
The row number of the current row within the partition.T
value()
The value of the current row in the window.Seq<T>
window()
Stream all elements in the window.-
Methods inherited from interface org.jooq.lambda.Collectable
allMatch, anyMatch, avg, avg, avgDouble, avgInt, avgLong, bitAnd, bitAnd, bitAndInt, bitAndLong, bitOr, bitOr, bitOrInt, bitOrLong, collect, collect, collect, collect, collect, collect, collect, collect, collect, collect, collect, collect, collect, collect, collect, collect, commonPrefix, commonSuffix, count, count, countDistinct, countDistinct, countDistinctBy, countDistinctBy, max, max, max, max, maxAll, maxAll, maxAll, maxAll, maxAllBy, maxAllBy, maxBy, maxBy, median, median, medianBy, medianBy, min, min, min, min, minAll, minAll, minAll, minAll, minAllBy, minAllBy, minBy, minBy, mode, modeAll, modeAllBy, modeBy, noneMatch, percentile, percentile, percentileBy, percentileBy, sum, sum, sumDouble, sumInt, sumLong, toCollection, toList, toList, toMap, toMap, toSet, toSet, toString, toString, toUnmodifiableList, toUnmodifiableSet
-
-
-
-
Method Detail
-
of
static <T> WindowSpecification<T> of()
-
of
static <T> WindowSpecification<T> of(long lower, long upper)
-
of
static <T> WindowSpecification<T> of(java.util.Comparator<? super T> orderBy)
-
of
static <T> WindowSpecification<T> of(java.util.Comparator<? super T> orderBy, long lower, long upper)
-
of
static <T,U> WindowSpecification<T> of(java.util.function.Function<? super T,? extends U> partitionBy)
-
of
static <T,U> WindowSpecification<T> of(java.util.function.Function<? super T,? extends U> partitionBy, long lower, long upper)
-
of
static <T,U> WindowSpecification<T> of(java.util.function.Function<? super T,? extends U> partitionBy, java.util.Comparator<? super T> orderBy)
-
of
static <T,U> WindowSpecification<T> of(java.util.function.Function<? super T,? extends U> partitionBy, java.util.Comparator<? super T> orderBy, long lower, long upper)
-
value
T value()
The value of the current row in the window.
-
rowNumber
long rowNumber()
The row number of the current row within the partition.// (1, 2, 3, 4, 5) Seq.of(1, 2, 4, 2, 3).window().map(w -> w.rowNumber());
-
rank
long rank()
The rank of the current row within the partition.// (1, 2, 2, 4, 5) Seq.of(1, 2, 2, 3, 4).window(naturalOrder()).map(w -> w.rank());
-
denseRank
long denseRank()
The dense rank of the current row within the partition.// (1, 2, 2, 3, 4) Seq.of(1, 2, 2, 3, 4).window(naturalOrder()).map(w -> w.denseRank());
-
percentRank
double percentRank()
The precent rank of the current row within the partition.// (0.0, 0.25, 0.25, 0.75, 1.0) Seq.of(1, 2, 2, 3, 4).window(naturalOrder()).map(w -> w.percentRank());
-
ntile
long ntile(long buckets)
The bucket number ("ntile") of the current row within the partition.// (0, 0, 1, 1, 2) Seq.of(1, 2, 2, 3, 4).window(naturalOrder()).map(w -> w.ntile(3));
-
lead
java.util.Optional<T> lead()
The next value in the window.This is the same as calling
lead(1)
// (2, 2, 3, 4, empty) Seq.of(1, 2, 2, 3, 4).window().map(w -> w.lead());
-
lead
java.util.Optional<T> lead(long lead)
The next value bylead
in the window.// (2, 2, 3, 4, empty) Seq.of(1, 2, 2, 3, 4).window().map(w -> w.lead());
-
lag
java.util.Optional<T> lag()
The previous value in the window.This is the same as calling
lag(1)
// (empty, 1, 2, 2, 3) Seq.of(1, 2, 2, 3, 4).window().map(w -> w.lag());
-
lag
java.util.Optional<T> lag(long lag)
The previous value bylag
in the window.// (empty, 1, 2, 2, 3) Seq.of(1, 2, 2, 3, 4).window().map(w -> w.lag());
-
firstValue
java.util.Optional<T> firstValue()
The first value in the window.// (1, 1, 1, 1, 1) Seq.of(1, 2, 4, 2, 3).window().map(w -> w.firstValue());
-
firstValue
<U> java.util.Optional<U> firstValue(java.util.function.Function<? super T,? extends U> function)
The first value in the window.// (1, 1, 1, 1, 1) Seq.of(1, 2, 4, 2, 3).window().map(w -> w.firstValue());
-
lastValue
java.util.Optional<T> lastValue()
The last value in the window.// (3, 3, 3, 3, 3) Seq.of(1, 2, 4, 2, 3).window().map(w -> w.lastValue());
-
lastValue
<U> java.util.Optional<U> lastValue(java.util.function.Function<? super T,? extends U> function)
The last value in the window.// (3, 3, 3, 3, 3) Seq.of(1, 2, 4, 2, 3).window().map(w -> w.lastValue());
-
nthValue
java.util.Optional<T> nthValue(long n)
The nth value in the window.// (4, 4, 4, 4, 4) Seq.of(1, 2, 4, 2, 3).window().map(w -> w.nthValue(2));
-
nthValue
<U> java.util.Optional<U> nthValue(long n, java.util.function.Function<? super T,? extends U> function)
The nth value in the window.// (4, 4, 4, 4, 4) Seq.of(1, 2, 4, 2, 3).window().map(w -> w.nthValue(2));
-
-