Record Class DownsampleNode

java.lang.Object
java.lang.Record
com.darkcollective.relix.ast.DownsampleNode
Record Components:
timestampColumn - the input column of type TIMESTAMP to bucket; never null
interval - the bucket width — ISO-8601 or shorthand; never null
function - the consolidation function; never null
groupingKeys - optional additional grouping columns (PER clause); never null
maxRows - optional limit on the number of output buckets (FOR n ROWS)
input - the source relation; never null
location - source position of this node; never null
All Implemented Interfaces:
RelNode

public record DownsampleNode(String timestampColumn, String interval, ConsolidationFunction function, List<String> groupingKeys, OptionalLong maxRows, RelNode input, SourceLocation location) extends Record implements RelNode
Time-series downsampling (DOWNSAMPLE) — groups input rows into fixed-width time buckets and consolidates numeric columns within each bucket using the chosen ConsolidationFunction.

Syntax:

   DOWNSAMPLE ts BY '5m'  USING AVG (Metrics)
   DOWNSAMPLE ts BY '1h'  USING MAX PER host (NetworkData)
   DOWNSAMPLE ts BY 'P1D' USING SUM PER region FOR 30 ROWS (Events)
 

The timestampColumn must be of type TIMESTAMP in the input schema. The interval accepts ISO-8601 duration strings (PT5M, PT1H, P1D) as well as shorthand notation (5m, 1h, 1d).

Output schema: groupingKeys columns (same types) + bucket: TIMESTAMP + consolidated columns. For ConsolidationFunction.COUNT the consolidated column is a single count: NUMBER; for all other functions each NUMBER column that is not the timestamp column and not a grouping key becomes <fn>_<colname>: NUMBER (e.g. avg_value, sum_amount).

When maxRows is present, only the N most-recent buckets are emitted (sort by bucket DESC, take N).

Materialisation: MaterializationMode.BAG (groups all rows before emitting).

  • Constructor Details

  • Method Details

    • accept

      public <R> R accept(RelNodeVisitor<R> visitor)
      Specified by:
      accept in interface RelNode
    • parseIntervalSeconds

      public static long parseIntervalSeconds(String interval)
      Parses the interval string to a number of seconds.

      Supports shorthand notation (5m, 1h, 30s, 2d, 1w) and ISO-8601 duration strings (PT5M, PT1H, P1D).

      Parameters:
      interval - the interval string; never null
      Returns:
      the interval width in seconds; always positive
      Throws:
      IllegalArgumentException - if the string is not a recognised format or is non-positive
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • timestampColumn

      public String timestampColumn()
      Returns the value of the timestampColumn record component.
      Returns:
      the value of the timestampColumn record component
    • interval

      public String interval()
      Returns the value of the interval record component.
      Returns:
      the value of the interval record component
    • function

      public ConsolidationFunction function()
      Returns the value of the function record component.
      Returns:
      the value of the function record component
    • groupingKeys

      public List<String> groupingKeys()
      Returns the value of the groupingKeys record component.
      Returns:
      the value of the groupingKeys record component
    • maxRows

      public OptionalLong maxRows()
      Returns the value of the maxRows record component.
      Returns:
      the value of the maxRows record component
    • input

      public RelNode input()
      Returns the value of the input record component.
      Returns:
      the value of the input record component
    • location

      public SourceLocation location()
      Returns the value of the location record component.
      Specified by:
      location in interface RelNode
      Returns:
      the value of the location record component