Package dev.frostlake.functions.window
Class WindowFunctionHelper
java.lang.Object
dev.frostlake.functions.window.WindowFunctionHelper
Shared logic for Snowflake window functions.
All methods work on pre-sorted partition row lists.
-
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectAVG over the frame, ignoring nulls; null when there are no non-null values.static ObjectSeesum(List, boolean)— the same declared-VARIANT rule applied to a window AVG.static ObjectAVG over a window frame given as the partials its FLOAT sum is read in, at a cumulative window's scale or a non-cumulative one's — seeAggregateNumerics.windowAvg(List, boolean, boolean, boolean).static intcompareValues(Object a, Object b) static doubleCUME_DIST — fraction of rows with order value<=current; ranges (0, 1].static ObjectfirstValue(List<Object> frameValues, boolean ignoreNulls) FIRST_VALUE(expr) — value of expr in the first row of the window frame.static intstatic ObjectLAST_VALUE(expr) — value of expr in the last row of the window frame.static ObjectMAX over the frame (bycompareValues(java.lang.Object, java.lang.Object)), ignoring nulls; preserves the element's type.static ObjectMIN over the frame (bycompareValues(java.lang.Object, java.lang.Object)), ignoring nulls; preserves the element's type.static ObjectnonCumulativeAvg(List<Object> values, boolean variantArgument) AVG over a NON-CUMULATIVE window, which declares three decimals wider than its input rather than six and TRUNCATES to that scale — seeAggregateNumerics.nonCumulativeWindowAvg(Iterable, boolean).static ObjectNTH_VALUE(expr, n) — value of expr in the nth row of the partition (1-based).static longNTILE(n) — divides the sorted partition into n equal buckets, returns bucket number (1-based).static doublePERCENT_RANK — (rank - 1) / (N - 1); ranges [0, 1].static ObjectratioToReport(Object currentValue, List<Object> allValues) RATIO_TO_REPORT(expr) — value / SUM(value over partition).static ObjectSUM over the frame, ignoring nulls; null when the frame has no non-null values (SQL SUM semantics).static ObjectThe declared-VARIANT-argument flavour — live,SUM(v:b) OVER ()is DOUBLE (SYSTEM$TYPEOF FLOAT) exactly like the grouped form, even over whole-number JSON values.static ObjectSUM over a window frame given as the partials its FLOAT sum is read in — seeAggregateNumerics.windowSum(List, boolean, boolean).static double
-
Method Details
-
ntile
NTILE(n) — divides the sorted partition into n equal buckets, returns bucket number (1-based). -
percentRank
PERCENT_RANK — (rank - 1) / (N - 1); ranges [0, 1]. -
cumeDist
CUME_DIST — fraction of rows with order value<=current; ranges (0, 1]. -
ratioToReport
RATIO_TO_REPORT(expr) — value / SUM(value over partition). -
firstValue
FIRST_VALUE(expr) — value of expr in the first row of the window frame. With RESPECT NULLS (Snowflake's default) the first row's value is returned even if it is NULL; with IGNORE NULLS the first non-null value is returned (null if the frame has none). -
lastValue
LAST_VALUE(expr) — value of expr in the last row of the window frame. RESPECT NULLS (default) returns the last row's value even if NULL; IGNORE NULLS returns the last non-null value. -
nthValue
NTH_VALUE(expr, n) — value of expr in the nth row of the partition (1-based). -
indexOf
-
compareValues
-
toDouble
-
sum
SUM over the frame, ignoring nulls; null when the frame has no non-null values (SQL SUM semantics). -
sum
The declared-VARIANT-argument flavour — live,SUM(v:b) OVER ()is DOUBLE (SYSTEM$TYPEOF FLOAT) exactly like the grouped form, even over whole-number JSON values. -
avg
AVG over the frame, ignoring nulls; null when there are no non-null values. Shares the grouped AVG's Snowflake typing: fixed-point inputs average to a scale-(max input scale + 6) BigDecimal, any double/VARIANT input keeps the double average. -
avg
Seesum(List, boolean)— the same declared-VARIANT rule applied to a window AVG. -
nonCumulativeAvg
AVG over a NON-CUMULATIVE window, which declares three decimals wider than its input rather than six and TRUNCATES to that scale — seeAggregateNumerics.nonCumulativeWindowAvg(Iterable, boolean). -
sum
SUM over a window frame given as the partials its FLOAT sum is read in — seeAggregateNumerics.windowSum(List, boolean, boolean). -
avg
public static Object avg(List<List<Object>> partials, boolean variantArgument, boolean nonCumulative, boolean rowWise) AVG over a window frame given as the partials its FLOAT sum is read in, at a cumulative window's scale or a non-cumulative one's — seeAggregateNumerics.windowAvg(List, boolean, boolean, boolean). -
min
MIN over the frame (bycompareValues(java.lang.Object, java.lang.Object)), ignoring nulls; preserves the element's type. -
max
MAX over the frame (bycompareValues(java.lang.Object, java.lang.Object)), ignoring nulls; preserves the element's type.
-