SampleStage

public final class SampleStage extends Stage


Performs a pseudo-random sampling of the input documents.

The documents produced from this stage are non-deterministic, running the same query over the same dataset multiple times will produce different results. There are two different ways to dictate how the sample is calculated either by specifying a target output size, or by specifying a target percentage of the input size.

Summary

Nested types

public static class SampleStage.Companion
public final class SampleStage.Mode
public static class SampleStage.Mode.Companion

Public methods

boolean
equals(Object other)
int
static final @NonNull SampleStage
withDocLimit(int results)

Creates SampleStage with the specified number of results returned.

static final @NonNull SampleStage
withPercentage(double percentage)

Creates SampleStage with size limited to percentage of prior stages results.

Inherited methods

From com.google.firebase.firestore.pipeline.Stage
final @NonNull SampleStage
final @NonNull SampleStage
withOption(@NonNull String key, boolean value)

Specify named Boolean parameter

final @NonNull SampleStage
withOption(@NonNull String key, double value)

Specify named Double parameter

final @NonNull SampleStage

Specify named Field parameter

final @NonNull SampleStage
withOption(@NonNull String key, long value)

Specify named Long parameter

final @NonNull SampleStage

Specify named String parameter

Public methods

equals

public boolean equals(Object other)

hashCode

public int hashCode()

withDocLimit

public static final @NonNull SampleStage withDocLimit(int results)

Creates SampleStage with the specified number of results returned.

The results parameter represents the number of results to produce and must be a non-negative integer value. If the previous stage produces less than the specified number, the entire previous results are returned. If the previous stage produces more than the specified number, this stage samples the specified number of documents from the previous stage, with equal probability for each result.

Parameters
int results

The number of documents to emit.

Returns
@NonNull SampleStage

SampleStage with specified documents.

withPercentage

public static final @NonNull SampleStage withPercentage(double percentage)

Creates SampleStage with size limited to percentage of prior stages results.

The percentage parameter is the target percentage (between 0.0 & 1.0) of the number of input documents to produce. Each input document is independently selected against the given percentage. As a result the output size will be approximately documents * percentage.

Parameters
double percentage

The percentage of the prior stages documents to emit.

Returns
@NonNull SampleStage

SampleStage with specified percentage.