WindowSpec

@Beta
public final class WindowSpec


Specification defining how documents are partitioned, ordered, and bounded for window functions in com.google.firebase.firestore.Pipeline.addWindowFields.

Window Functions SDK features are in preview until the backend feature launches. Look for launch announcement at: https://docs.cloud.google.com/firestore/docs/release-notes

Sorting and Window Frames:

  • For document-based (documents) window frames, sort is optional; if no sort expressions are specified, documents are processed in incoming stream (fetch) order. WindowBound.CURRENT refers strictly to the current document's position (documents with tied sort values are not included).

  • For range-based (range) window frames, at least one sort expression is required. WindowBound.CURRENT is peer-inclusive (like SQL CURRENT ROW in RANGE mode): it includes all documents whose sort value(s) tie with the current document, making it semantically equivalent to an offset of 0. Range frames bounded only by WindowBound.CURRENT and/or WindowBound.UNBOUNDED (with no numeric or time offsets) may use multiple sort orderings and non-numeric sort values (such as strings or booleans, provided no unit is set). Range frames with numeric or time offsets require exactly one sort ordering.

  • When no explicit documents or range frame is specified, omitting sort defaults the window frame to documents(WindowBound.UNBOUNDED, WindowBound.UNBOUNDED), whereas specifying sort changes the default window frame to range(WindowBound.UNBOUNDED, WindowBound.CURRENT).

Summary

Public constructors

Creates an empty window spec: a single global partition covering the entire result set, with no sort and no explicit frame (defaulting to documents(WindowBound.UNBOUNDED, WindowBound.UNBOUNDED)).

Public methods

final @NonNull WindowSpec
documents(@NonNull Object preceding, @NonNull Object following)

Specify a document-count frame with bounds of mixed or heterogeneous types, e.g. (Int, WindowBound) or (Int, Expression).

final @NonNull WindowSpec
documents(@NonNull Expression preceding, @NonNull Expression following)

Specifies a document-count based window frame.

final @NonNull WindowSpec
documents(int preceding, int following)

Specifies a document-count based window frame.

final @NonNull WindowSpec
documents(@NonNull WindowBound preceding, @NonNull WindowBound following)

Specifies a document-count frame using symbolic bounds, e.g. (WindowBound.UNBOUNDED, WindowBound.CURRENT).

boolean
equals(Object other)
int
final @NonNull WindowSpec
partition(
    @NonNull Expression expression,
    @NonNull Object additionalExpressions
)

Specify partition group columns.

final @NonNull WindowSpec
partition(@NonNull String fieldName, @NonNull Object additionalExpressions)
final @NonNull WindowSpec
range(@NonNull Object preceding, @NonNull Object following)

Specify a range frame with bounds of mixed or heterogeneous types, e.g. (Int, WindowBound) or (Int, Expression).

final @NonNull WindowSpec
range(double preceding, double following)

Specify a numeric range frame with fractional bounds.

final @NonNull WindowSpec
range(@NonNull Expression preceding, @NonNull Expression following)

Specifies a range-value based window frame.

final @NonNull WindowSpec
range(int preceding, int following)

Specifies a range-value based window frame with numeric offsets.

final @NonNull WindowSpec
range(@NonNull WindowBound preceding, @NonNull WindowBound following)

Specifies a range frame using symbolic bounds, e.g. (WindowBound.UNBOUNDED, WindowBound.CURRENT).

final @NonNull WindowSpec
range(
    @NonNull Object preceding,
    @NonNull Object following,
    @NonNull Expression unit
)

Specify a range frame with bounds of mixed or heterogeneous types and a time unit.

final @NonNull WindowSpec
range(
    @NonNull Object preceding,
    @NonNull Object following,
    @NonNull String unit
)

Specify a range frame with bounds of mixed or heterogeneous types and a time unit.

final @NonNull WindowSpec
range(double preceding, double following, @NonNull Expression unit)

Specify a numeric range frame with fractional bounds and a time unit.

final @NonNull WindowSpec
range(double preceding, double following, @NonNull String unit)

Specify a numeric range frame with fractional bounds and a time unit.

final @NonNull WindowSpec
range(
    @NonNull Expression preceding,
    @NonNull Expression following,
    @NonNull Expression unit
)

Specifies a range-value based window frame with a time unit.

final @NonNull WindowSpec
range(
    @NonNull Expression preceding,
    @NonNull Expression following,
    @NonNull String unit
)

Specifies a range-value based window frame with a time unit.

final @NonNull WindowSpec
range(int preceding, int following, @NonNull Expression unit)

Specifies a range-value based window frame with a time unit.

final @NonNull WindowSpec
range(int preceding, int following, @NonNull String unit)

Specifies a range-value based window frame with a time unit.

final @NonNull WindowSpec
range(
    @NonNull WindowBound preceding,
    @NonNull WindowBound following,
    @NonNull Expression unit
)

Specifies a range frame using symbolic bounds and a time unit.

final @NonNull WindowSpec
range(
    @NonNull WindowBound preceding,
    @NonNull WindowBound following,
    @NonNull String unit
)

Specifies a range frame using symbolic bounds and a time unit.

final @NonNull WindowSpec

Specifies the sort order of documents within each partition.

final @NonNull WindowSpec
sort(@NonNull Ordering order, @NonNull Ordering additionalOrders)

Specifies the sort order of documents within each partition.

Public constructors

WindowSpec

public WindowSpec()

Creates an empty window spec: a single global partition covering the entire result set, with no sort and no explicit frame (defaulting to documents(WindowBound.UNBOUNDED, WindowBound.UNBOUNDED)).

Public methods

documents

public final @NonNull WindowSpec documents(@NonNull Object preceding, @NonNull Object following)

Specify a document-count frame with bounds of mixed or heterogeneous types, e.g. (Int, WindowBound) or (Int, Expression). Invalid combinations are encoded and rejected by the backend.

sort is optional for document-based window frames; if no sort expressions are specified, documents are processed in incoming stream (fetch) order.

Parameters
@NonNull Object preceding

The start of the window frame relative to the current document (e.g. an integer offset, WindowBound, or Expression). A positive integer (e.g. 2) includes up to that many documents before the current document. A negative integer (e.g. -1) indicates a boundary following the current document, enabling frames that start after the current document.

@NonNull Object following

The end of the window frame relative to the current document (e.g. an integer offset, WindowBound, or Expression). A positive integer (e.g. 2) includes up to that many documents after the current document. A negative integer (e.g. -1) indicates a boundary preceding the current document, enabling frames that end before the current document (e.g. excluding the current document).

Returns
@NonNull WindowSpec

A new WindowSpec with the specified document-count frame.

documents

public final @NonNull WindowSpec documents(@NonNull Expression preceding, @NonNull Expression following)

Specifies a document-count based window frame.

sort is optional for document-based window frames; if no sort expressions are specified, documents are processed in incoming stream (fetch) order.

Parameters
@NonNull Expression preceding

The start of the window frame relative to the current document. A positive integer (e.g. 2) includes up to that many documents before the current document. A negative integer (e.g. -1) indicates a boundary following the current document, enabling frames that start after the current document.

@NonNull Expression following

The end of the window frame relative to the current document. A positive integer (e.g. 2) includes up to that many documents after the current document. A negative integer (e.g. -1) indicates a boundary preceding the current document, enabling frames that end before the current document (e.g. excluding the current document).

Returns
@NonNull WindowSpec

A new WindowSpec with the specified document-count frame.

documents

public final @NonNull WindowSpec documents(int preceding, int following)

Specifies a document-count based window frame.

sort is optional for document-based window frames; if no sort expressions are specified, documents are processed in incoming stream (fetch) order.

Parameters
int preceding

The start of the window frame relative to the current document. A positive integer (e.g. 2) includes up to that many documents before the current document. A negative integer (e.g. -1) indicates a boundary following the current document, enabling frames that start after the current document.

int following

The end of the window frame relative to the current document. A positive integer (e.g. 2) includes up to that many documents after the current document. A negative integer (e.g. -1) indicates a boundary preceding the current document, enabling frames that end before the current document (e.g. excluding the current document).

Returns
@NonNull WindowSpec

A new WindowSpec with the specified document-count frame.

documents

public final @NonNull WindowSpec documents(@NonNull WindowBound preceding, @NonNull WindowBound following)

Specifies a document-count frame using symbolic bounds, e.g. (WindowBound.UNBOUNDED, WindowBound.CURRENT).

In a documents frame, WindowBound.CURRENT refers strictly to the current document's position (documents with tied sort values are not included). sort is optional for document-based window frames; if no sort expressions are specified, documents are processed in incoming stream (fetch) order.

Parameters
@NonNull WindowBound preceding

The symbolic lower boundary (WindowBound.UNBOUNDED or WindowBound.CURRENT ). For numeric offsets (where a positive integer such as 2 includes up to that many documents before the current document, and a negative integer such as -1 indicates a boundary following the current document, enabling frames that start after the current document), use the (Int, Int) or (Any, Any) overload.

@NonNull WindowBound following

The symbolic upper boundary (WindowBound.UNBOUNDED or WindowBound.CURRENT ). For numeric offsets (where a positive integer such as 2 includes up to that many documents after the current document, and a negative integer such as -1 indicates a boundary preceding the current document, enabling frames that end before the current document), use the (Int, Int) or (Any, Any) overload.

Returns
@NonNull WindowSpec

A new WindowSpec with the specified document-count frame.

equals

public boolean equals(Object other)

hashCode

public int hashCode()

partition

public final @NonNull WindowSpec partition(
    @NonNull Expression expression,
    @NonNull Object additionalExpressions
)

Specify partition group columns.

partition

public final @NonNull WindowSpec partition(@NonNull String fieldName, @NonNull Object additionalExpressions)

range

public final @NonNull WindowSpec range(@NonNull Object preceding, @NonNull Object following)

Specify a range frame with bounds of mixed or heterogeneous types, e.g. (Int, WindowBound) or (Int, Expression). Invalid combinations are encoded and rejected by the backend.

Range frames with numeric offsets require a single sort expression; range frames bounded only by WindowBound.CURRENT and/or WindowBound.UNBOUNDED allow one or more sort expressions and non-numeric sort values.

Parameters
@NonNull Object preceding

The lower bound offset relative to the current document's sort value (e.g. a numeric offset, WindowBound, or Expression). A positive offset subtracts from the current document's sort value (looking into the past). A negative offset adds to the current document's sort value (shifting the lower boundary past the current document).

@NonNull Object following

The upper bound offset relative to the current document's sort value (e.g. a numeric offset, WindowBound, or Expression). A positive offset adds to the current document's sort value (looking into the future). A negative offset subtracts from the current document's sort value (shifting the upper boundary before the current document).

Returns
@NonNull WindowSpec

A new WindowSpec with the specified range frame.

range

public final @NonNull WindowSpec range(double preceding, double following)

Specify a numeric range frame with fractional bounds.

Only meaningful for value-based (non-time) range frames, e.g. when sorting by a price or score. The backend rejects fractional offsets for time-based range frames. Range frames with numeric offsets require a single numeric sort expression.

Parameters
double preceding

The lower bound offset relative to the current document's sort value. A positive offset subtracts from the current document's sort value (looking into the past). A negative offset adds to the current document's sort value (shifting the lower boundary past the current document).

double following

The upper bound offset relative to the current document's sort value. A positive offset adds to the current document's sort value (looking into the future). A negative offset subtracts from the current document's sort value (shifting the upper boundary before the current document).

Returns
@NonNull WindowSpec

A new WindowSpec with the specified range frame.

range

public final @NonNull WindowSpec range(@NonNull Expression preceding, @NonNull Expression following)

Specifies a range-value based window frame.

Range frames with numeric offsets require a single sort expression; range frames bounded only by WindowBound.CURRENT and/or WindowBound.UNBOUNDED allow one or more sort expressions and non-numeric sort values.

Parameters
@NonNull Expression preceding

The lower bound offset relative to the current document's sort value. A positive offset subtracts from the current document's sort value (looking into the past). A negative offset adds to the current document's sort value (shifting the lower boundary past the current document).

@NonNull Expression following

The upper bound offset relative to the current document's sort value. A positive offset adds to the current document's sort value (looking into the future). A negative offset subtracts from the current document's sort value (shifting the upper boundary before the current document).

Returns
@NonNull WindowSpec

A new WindowSpec with the specified range frame.

range

public final @NonNull WindowSpec range(int preceding, int following)

Specifies a range-value based window frame with numeric offsets.

Range frames with numeric offsets require a single numeric sort expression. An offset of 0 is peer-inclusive (equivalent to WindowBound.CURRENT in a range frame).

Parameters
int preceding

The lower bound offset relative to the current document's sort value. A positive offset subtracts from the current document's sort value (looking into the past). A negative offset adds to the current document's sort value (shifting the lower boundary past the current document).

int following

The upper bound offset relative to the current document's sort value. A positive offset adds to the current document's sort value (looking into the future). A negative offset subtracts from the current document's sort value (shifting the upper boundary before the current document).

Returns
@NonNull WindowSpec

A new WindowSpec with the specified range frame.

range

public final @NonNull WindowSpec range(@NonNull WindowBound preceding, @NonNull WindowBound following)

Specifies a range frame using symbolic bounds, e.g. (WindowBound.UNBOUNDED, WindowBound.CURRENT).

In a range frame, WindowBound.CURRENT is peer-inclusive (like SQL CURRENT ROW in RANGE mode): it includes all documents whose sort value(s) tie with the current document, making it semantically equivalent to an offset of 0. Because both bounds are symbolic ( WindowBound.CURRENT / WindowBound.UNBOUNDED) with no time unit, one or more sort orderings and non-numeric sort values (such as strings or booleans) are supported.

Parameters
@NonNull WindowBound preceding

The symbolic lower boundary (WindowBound.UNBOUNDED or WindowBound.CURRENT ). For numeric offsets (where a positive offset subtracts from the current document's sort value, looking into the past, and a negative offset adds to the current document's sort value, shifting the lower boundary past the current document), use the numeric or (Any, Any) overload.

@NonNull WindowBound following

The symbolic upper boundary (WindowBound.UNBOUNDED or WindowBound.CURRENT ). For numeric offsets (where a positive offset adds to the current document's sort value, looking into the future, and a negative offset subtracts from the current document's sort value, shifting the upper boundary before the current document), use the numeric or (Any, Any) overload.

Returns
@NonNull WindowSpec

A new WindowSpec with the specified range frame.

range

public final @NonNull WindowSpec range(
    @NonNull Object preceding,
    @NonNull Object following,
    @NonNull Expression unit
)

Specify a range frame with bounds of mixed or heterogeneous types and a time unit.

Supported unit values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "month", "quarter", and "year".

Range frames with numeric or time offsets require a single timestamp sort expression (a unit on a string or boolean sort field is rejected by the backend).

Parameters
@NonNull Object preceding

The lower bound offset relative to the current document's sort value (e.g. a numeric offset, WindowBound, or Expression). A positive offset subtracts from the current document's sort value (looking into the past). A negative offset adds to the current document's sort value (shifting the lower boundary past the current document).

@NonNull Object following

The upper bound offset relative to the current document's sort value (e.g. a numeric offset, WindowBound, or Expression). A positive offset adds to the current document's sort value (looking into the future). A negative offset subtracts from the current document's sort value (shifting the upper boundary before the current document).

@NonNull Expression unit

The time unit expression for the range offsets.

Returns
@NonNull WindowSpec

A new WindowSpec with the specified range frame.

range

public final @NonNull WindowSpec range(
    @NonNull Object preceding,
    @NonNull Object following,
    @NonNull String unit
)

Specify a range frame with bounds of mixed or heterogeneous types and a time unit.

Supported unit values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "month", "quarter", and "year".

Range frames with numeric or time offsets require a single timestamp sort expression (a unit on a string or boolean sort field is rejected by the backend).

Parameters
@NonNull Object preceding

The lower bound offset relative to the current document's sort value (e.g. a numeric offset, WindowBound, or Expression). A positive offset subtracts from the current document's sort value (looking into the past). A negative offset adds to the current document's sort value (shifting the lower boundary past the current document).

@NonNull Object following

The upper bound offset relative to the current document's sort value (e.g. a numeric offset, WindowBound, or Expression). A positive offset adds to the current document's sort value (looking into the future). A negative offset subtracts from the current document's sort value (shifting the upper boundary before the current document).

@NonNull String unit

The time unit for the range offsets.

Returns
@NonNull WindowSpec

A new WindowSpec with the specified range frame.

range

public final @NonNull WindowSpec range(double preceding, double following, @NonNull Expression unit)

Specify a numeric range frame with fractional bounds and a time unit.

Supported unit values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "month", "quarter", and "year".

Range frames with numeric or time offsets require a single sort expression.

Parameters
double preceding

The lower bound offset relative to the current document's sort value. A positive offset subtracts from the current document's sort value (looking into the past). A negative offset adds to the current document's sort value (shifting the lower boundary past the current document).

double following

The upper bound offset relative to the current document's sort value. A positive offset adds to the current document's sort value (looking into the future). A negative offset subtracts from the current document's sort value (shifting the upper boundary before the current document).

@NonNull Expression unit

The time unit expression for the range offsets.

Returns
@NonNull WindowSpec

A new WindowSpec with the specified range frame.

range

public final @NonNull WindowSpec range(double preceding, double following, @NonNull String unit)

Specify a numeric range frame with fractional bounds and a time unit.

Supported unit values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "month", "quarter", and "year".

Range frames with numeric or time offsets require a single sort expression.

Parameters
double preceding

The lower bound offset relative to the current document's sort value. A positive offset subtracts from the current document's sort value (looking into the past). A negative offset adds to the current document's sort value (shifting the lower boundary past the current document).

double following

The upper bound offset relative to the current document's sort value. A positive offset adds to the current document's sort value (looking into the future). A negative offset subtracts from the current document's sort value (shifting the upper boundary before the current document).

@NonNull String unit

The time unit for the range offsets.

Returns
@NonNull WindowSpec

A new WindowSpec with the specified range frame.

range

public final @NonNull WindowSpec range(
    @NonNull Expression preceding,
    @NonNull Expression following,
    @NonNull Expression unit
)

Specifies a range-value based window frame with a time unit.

Supported unit values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "month", "quarter", and "year".

Range frames with numeric or time offsets require a single timestamp sort expression (a unit on a string or boolean sort field is rejected by the backend).

Parameters
@NonNull Expression preceding

The lower bound offset relative to the current document's sort value. A positive offset subtracts from the current document's sort value (looking into the past). A negative offset adds to the current document's sort value (shifting the lower boundary past the current document).

@NonNull Expression following

The upper bound offset relative to the current document's sort value. A positive offset adds to the current document's sort value (looking into the future). A negative offset subtracts from the current document's sort value (shifting the upper boundary before the current document).

@NonNull Expression unit

The time unit expression for the range offsets.

Returns
@NonNull WindowSpec

A new WindowSpec with the specified range frame.

range

public final @NonNull WindowSpec range(
    @NonNull Expression preceding,
    @NonNull Expression following,
    @NonNull String unit
)

Specifies a range-value based window frame with a time unit.

Supported unit values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "month", "quarter", and "year".

Range frames with numeric or time offsets require a single timestamp sort expression (a unit on a string or boolean sort field is rejected by the backend).

Parameters
@NonNull Expression preceding

The lower bound offset relative to the current document's sort value. A positive offset subtracts from the current document's sort value (looking into the past). A negative offset adds to the current document's sort value (shifting the lower boundary past the current document).

@NonNull Expression following

The upper bound offset relative to the current document's sort value. A positive offset adds to the current document's sort value (looking into the future). A negative offset subtracts from the current document's sort value (shifting the upper boundary before the current document).

@NonNull String unit

The time unit for the range offsets.

Returns
@NonNull WindowSpec

A new WindowSpec with the specified range frame.

range

public final @NonNull WindowSpec range(int preceding, int following, @NonNull Expression unit)

Specifies a range-value based window frame with a time unit.

Supported unit values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "month", "quarter", and "year".

Range frames with time offsets require a single timestamp sort expression (a unit on a string or boolean sort field is rejected by the backend).

Parameters
int preceding

The lower bound offset relative to the current document's sort value. A positive offset subtracts from the current document's sort value (looking into the past). A negative offset adds to the current document's sort value (shifting the lower boundary past the current document).

int following

The upper bound offset relative to the current document's sort value. A positive offset adds to the current document's sort value (looking into the future). A negative offset subtracts from the current document's sort value (shifting the upper boundary before the current document).

@NonNull Expression unit

The time unit expression for the range offsets.

Returns
@NonNull WindowSpec

A new WindowSpec with the specified range frame.

range

public final @NonNull WindowSpec range(int preceding, int following, @NonNull String unit)

Specifies a range-value based window frame with a time unit.

Supported unit values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "month", "quarter", and "year".

Range frames with time offsets require a single timestamp sort expression (a unit on a string or boolean sort field is rejected by the backend).

Parameters
int preceding

The lower bound offset relative to the current document's sort value. A positive offset subtracts from the current document's sort value (looking into the past). A negative offset adds to the current document's sort value (shifting the lower boundary past the current document).

int following

The upper bound offset relative to the current document's sort value. A positive offset adds to the current document's sort value (looking into the future). A negative offset subtracts from the current document's sort value (shifting the upper boundary before the current document).

@NonNull String unit

The time unit for the range offsets.

Returns
@NonNull WindowSpec

A new WindowSpec with the specified range frame.

range

public final @NonNull WindowSpec range(
    @NonNull WindowBound preceding,
    @NonNull WindowBound following,
    @NonNull Expression unit
)

Specifies a range frame using symbolic bounds and a time unit.

Supported unit values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "month", "quarter", and "year".

In a range frame, WindowBound.CURRENT is peer-inclusive. Specifying a time unit requires a timestamp sort expression (a unit on a string or boolean sort field is rejected by the backend).

Parameters
@NonNull WindowBound preceding

The symbolic lower boundary (WindowBound.UNBOUNDED or WindowBound.CURRENT ). For numeric offsets (where a positive offset subtracts from the current document's sort value, looking into the past, and a negative offset adds to the current document's sort value, shifting the lower boundary past the current document), use the (Any, Any, Expression) overload.

@NonNull WindowBound following

The symbolic upper boundary (WindowBound.UNBOUNDED or WindowBound.CURRENT ). For numeric offsets (where a positive offset adds to the current document's sort value, looking into the future, and a negative offset subtracts from the current document's sort value, shifting the upper boundary before the current document), use the (Any, Any, Expression) overload.

@NonNull Expression unit

The time unit expression for the range frame.

Returns
@NonNull WindowSpec

A new WindowSpec with the specified range frame.

range

public final @NonNull WindowSpec range(
    @NonNull WindowBound preceding,
    @NonNull WindowBound following,
    @NonNull String unit
)

Specifies a range frame using symbolic bounds and a time unit.

Supported unit values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "month", "quarter", and "year".

In a range frame, WindowBound.CURRENT is peer-inclusive. Specifying a time unit requires a timestamp sort expression (a unit on a string or boolean sort field is rejected by the backend).

Parameters
@NonNull WindowBound preceding

The symbolic lower boundary (WindowBound.UNBOUNDED or WindowBound.CURRENT ). For numeric offsets (where a positive offset subtracts from the current document's sort value, looking into the past, and a negative offset adds to the current document's sort value, shifting the lower boundary past the current document), use the (Any, Any, String) overload.

@NonNull WindowBound following

The symbolic upper boundary (WindowBound.UNBOUNDED or WindowBound.CURRENT ). For numeric offsets (where a positive offset adds to the current document's sort value, looking into the future, and a negative offset subtracts from the current document's sort value, shifting the upper boundary before the current document), use the (Any, Any, String) overload.

@NonNull String unit

The time unit for the range frame.

Returns
@NonNull WindowSpec

A new WindowSpec with the specified range frame.

sort

public final @NonNull WindowSpec sort(@NonNull List<@NonNull Ordering> orders)

Specifies the sort order of documents within each partition.

  • For document-based (documents) window frames, sort is optional; if no sort expressions are specified, documents are processed in incoming stream (fetch) order.

  • For range-based (range) window frames, at least one sort expression is required. Range frames whose bounds are only WindowBound.CURRENT and/or WindowBound.UNBOUNDED may use multiple sort orderings and non-numeric sort values (strings, booleans, provided no time unit is set), whereas range frames with numeric or time offsets require a single sort ordering.

  • Setting sort without an explicit documents or range frame changes the default window frame from documents(WindowBound.UNBOUNDED, WindowBound.UNBOUNDED) (when sort is omitted) to range(WindowBound.UNBOUNDED, WindowBound.CURRENT) (when sort is specified).

sort

public final @NonNull WindowSpec sort(@NonNull Ordering order, @NonNull Ordering additionalOrders)

Specifies the sort order of documents within each partition.

  • For document-based (documents) window frames, sort is optional; if no sort expressions are specified, documents are processed in incoming stream (fetch) order.

  • For range-based (range) window frames, at least one sort expression is required. Range frames whose bounds are only WindowBound.CURRENT and/or WindowBound.UNBOUNDED may use multiple sort orderings and non-numeric sort values (strings, booleans, provided no time unit is set), whereas range frames with numeric or time offsets require a single sort ordering.

  • Setting sort without an explicit documents or range frame changes the default window frame from documents(WindowBound.UNBOUNDED, WindowBound.UNBOUNDED) (when sort is omitted) to range(WindowBound.UNBOUNDED, WindowBound.CURRENT) (when sort is specified).