Class SetEvaluator

java.lang.Object
io.trino.operator.window.pattern.SetEvaluator

public class SetEvaluator extends Object
This class returns a set of positions to aggregate over for an aggregate function in row pattern matching context. Aggregations in row pattern matching context have RUNNING or FINAL semantics, and they apply only to rows matched with certain pattern variables. For example, for a match "A B A A B", the aggregation `sum(B.x)` only applies to the second and the last position.

This evaluator is stateful. It requires a reset for every new match. The method `resolveNewPositions()` returns a portion of positions corresponding to the new portion of the match since the last call. It is thus assumed that a sequence of calls since the instance creation or `reset()` applies to the same match (i.e. the `matchedLabels` passed as an argument to one call is prefix of `matchedLabels` passed in the next call).

Also, a full list of positions for a current match is kept, and it can be obtained via the `getAllPositions()` method. This is for the purpose comparing pattern matching threads in ThreadEquivalence.

  • Constructor Details

    • SetEvaluator

      public SetEvaluator(Set<Integer> labels, boolean running)
  • Method Details

    • reset

      public void reset()
    • resolveNewPositions

      public ArrayView resolveNewPositions(int currentRow, ArrayView matchedLabels, int partitionStart, int patternStart)
      This method is used for resolving positions for aggregation: - During pattern matching. In this case, the evaluated label has been appended to `matchedLabels` - When computing row pattern measures after a non-empty match is found. Search is limited up to the current row in case of RUNNING semantics and to the entire match in case of FINAL semantics.

      TODO If `evaluated` exceeds `aggregated`, we could reuse the pre-evaluated positions. For that, we need to keep count of all previously returned positions from the `aggregated` prefix.

      Returns:
      array of new matching positions since the last call, relative to partition start
    • getAllPositions

      public ArrayView getAllPositions(ArrayView labels)
    • copy

      public SetEvaluator copy()
    • getAllPositionsSizeInBytes

      public long getAllPositionsSizeInBytes()