Package dev.frostlake.executor
Class ValueComparisons
java.lang.Object
dev.frostlake.executor.ValueComparisons
Stateless value/ordering comparison helpers extracted from
QueryExecutor. These are pure
functions used by sort, DISTINCT, and column-resolution logic across query stages; none of them
read engine instance state.-
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectcanonicalGroupKeyValue(Object value) Canonicalize one grouping-key value so equal numbers with different runtime types land in the same bucket: Integer 1, Long 1, Double 1.0 and BigDecimal 1.00 must form one group (mixed representations arise from VARIANT casts, set-operation branches and literal folding).static intcompareForExtreme(Object v1, Object v2) The comparison an EXTREME uses — MIN, MAX, GREATEST and LEAST — which differs fromcompareValues(java.lang.Object, java.lang.Object)in one cell:-0.0and0.0are a TIE, so whichever was seen first is kept.static intcompareOrderKey(Object v1, Object v2, boolean ascending, Boolean nullsFirst) Compare two ORDER BY key values, returning the final (already ASC/DESC-adjusted) ordering.static intcompareValues(Object v1, Object v2) static intfindColumnIndex(Table table, String columnName) LikegetColumnIndex(dev.frostlake.metastore.model.Table, java.lang.String)but answers -1 instead of throwing — for callers probing whether a text is a bare column at all (the throw built a stack trace per probe).static intgetColumnIndex(Table table, String columnName) static booleanTrue when s matches \d+\.static ObjectnormalizeValueForDistinct(Object value) Normalize a value for DISTINCT comparison.static BooleanNULLS FIRST → TRUE, NULLS LAST → FALSE, unspecified → null, for an ORDER BY item.
-
Method Details
-
findColumnIndex
LikegetColumnIndex(dev.frostlake.metastore.model.Table, java.lang.String)but answers -1 instead of throwing — for callers probing whether a text is a bare column at all (the throw built a stack trace per probe). -
getColumnIndex
-
normalizeValueForDistinct
Normalize a value for DISTINCT comparison. Converts numbers to Double for consistent comparison (e.g., 1 == 1.0). -
canonicalGroupKeyValue
Canonicalize one grouping-key value so equal numbers with different runtime types land in the same bucket: Integer 1, Long 1, Double 1.0 and BigDecimal 1.00 must form one group (mixed representations arise from VARIANT casts, set-operation branches and literal folding). Unlike the join-key normalizer this must not over-group — the bucket IS the grouping decision, with no downstream re-confirmation — so only exact-value numeric canonicalization is applied; strings, temporals and booleans pass through unchanged. Integral values becomeLong, everything else a trailing-zero-strippedBigDecimal, both of which honor equals/hashCode. -
compareValues
-
compareForExtreme
The comparison an EXTREME uses — MIN, MAX, GREATEST and LEAST — which differs fromcompareValues(java.lang.Object, java.lang.Object)in one cell:-0.0and0.0are a TIE, so whichever was seen first is kept. Live answers-0forGREATEST(-0.0::FLOAT, 0.0::FLOAT)and forMAXover the same pair in that order, and0for either written the other way round; a sort-style comparator that puts-0first would pick the wrong one half the time.- Parameters:
v1- one valuev2- the other- Returns:
- negative, zero (a tie) or positive
-
nullsFirstFlag
NULLS FIRST → TRUE, NULLS LAST → FALSE, unspecified → null, for an ORDER BY item. -
compareOrderKey
Compare two ORDER BY key values, returning the final (already ASC/DESC-adjusted) ordering. NULL placement follows an explicit NULLS FIRST/LAST whennullsFirstis non-null, otherwise the Snowflake default: NULLS LAST for ASC, NULLS FIRST for DESC. -
isNumericDotted
True when s matches \d+\.\d+ (a numeric literal like 1.5), to tell it from a qualified name.
-