java.lang.Object
dev.frostlake.functions.BuiltInFunction
dev.frostlake.functions.scalar.context.SeqFn

public class SeqFn extends BuiltInFunction
SEQ1 / SEQ2 / SEQ4 / SEQ8 — the row's 0-based ordinal, wrapped to the function's integer width.

One class for all four because they differ only in that width: the digit in the name is the number of BYTES, so SEQ1 counts in 8 bits and SEQ8 in 64. Measured live:

   SEQ1()   NUMBER(3,0)    SEQ2()   NUMBER(5,0)
   SEQ4()   NUMBER(10,0)   SEQ8()   NUMBER(19,0)
 

The optional argument is a SIGN, 0 or 1, and it decides what happens at the top of the range rather than where counting starts — every form starts at 0. With the default 0 the count stays non-negative and wraps at the signed maximum; with 1 it wraps the way a two's-complement integer of that width does. Measured over 260 rows for SEQ1 and 70000 for SEQ2:

   SEQ1()    … 125 126 127 0 1 …          SEQ1(1)   … 125 126 127 -128 -127 …
   SEQ2()    … 32766 32767 0 1 …          SEQ2(1)   … 32766 32767 -32768 -32767 …
   SEQ2()  min 0 max 32767, 32768 values  SEQ2(1) min -32768 max 32767, 65536 values
 

The sign does NOT change the declared type: SEQ1(1) is still NUMBER(3,0), wide enough for -128 either way.

Frostlake is contiguous where Snowflake only promises to be distinct. Live, the values come from whatever unit of parallelism produced the row: over a 16-row join the account returned 16 rows numbered between 7 and 127, not 0..15, which is why Snowflake's own documentation says not to use SEQ as a key generator and to reach for ROW_NUMBER instead. That artefact is not reproducible — it is not even stable run to run — so Frostlake numbers rows 0, 1, 2, … in the order the operator produces them. Every single-source shape agrees with live; a query that depends on the gaps is depending on something Snowflake does not promise.

  • Constructor Details

    • SeqFn

      public SeqFn(String name, int bytes)
      Parameters:
      name - the Snowflake spelling, whose trailing digit is bytes
      bytes - the width in bytes: 1, 2, 4 or 8
  • Method Details

    • evaluate

      public Object evaluate(List<Object> args)
      Description copied from class: BuiltInFunction
      Computes the function's result over its already-evaluated argument values. A SQL NULL argument arrives as Java null, and returning null makes the SQL result NULL.
      Specified by:
      evaluate in class BuiltInFunction
      Parameters:
      args - the argument values, in call order
      Returns:
      the function's value for these arguments, or null for SQL NULL
    • getMinArgCount

      public int getMinArgCount()
      Description copied from class: BuiltInFunction
      The fewest arguments a call to this function may pass; fewer is an argument-count error.
      Specified by:
      getMinArgCount in class BuiltInFunction
      Returns:
      the minimum accepted argument count
    • getMaxArgCount

      public int getMaxArgCount()
      Description copied from class: BuiltInFunction
      The most arguments a call to this function may pass; Integer.MAX_VALUE marks a variadic function (see BuiltInFunction.isVariadic()).
      Specified by:
      getMaxArgCount in class BuiltInFunction
      Returns:
      the maximum accepted argument count