Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1859fa3
[VARKA-348] Compile every decimal output root through the decimal val…
Nov 20, 2026
7c4152c
[VARKA-348] Add the decimal value outputs' coverage rows, refinement …
Nov 20, 2026
926799f
[VARKA-348] Run the decimal output store over decimal leaves in its s…
Nov 20, 2026
79aa490
[VARKA-348] Mark the decimal baseline's value sections as fused whole
Nov 20, 2026
7bd655e
[VARKA-348] Record two repository lessons and add a bare cast output
Nov 20, 2026
21a7579
[VARKA-348] Regenerate the generated files after the rebase
Nov 22, 2026
ae2b2e3
[VARKA-348] Mark least and try_subtract, decline a mismatched output …
Nov 22, 2026
27e3dde
[VARKA-348] Check a decimal store output in the slot lane and refine …
Nov 22, 2026
14a5ff4
Merge remote-tracking branch 'origin/master' into varka-348-decimal-c…
Nov 22, 2026
902d5bf
[VARKA-348] Regenerate the decimal refinement with the eight value rows
Nov 22, 2026
f9494f5
[VARKA-348] Regenerate the emitted bytes, the width audit and the doc…
Nov 22, 2026
783d10c
[VARKA-348] Restore the pair's owed value forms, skip unreachable dec…
Nov 22, 2026
fcb8202
[VARKA-348] State why the long suite's sums, negation and abs cannot …
Nov 22, 2026
a206157
Merge remote-tracking branch 'origin/master' into varka-348-decimal-c…
Nov 22, 2026
124050b
Merge remote-tracking branch 'origin/master' into varka-348-decimal-c…
Nov 22, 2026
00e3aaa
Merge remote-tracking branch 'origin/master' into varka-348-decimal-c…
Nov 22, 2026
f80de83
Regenerate the generated files after merging master
Nov 22, 2026
fe9e577
[VARKA-348] Compare a decimal value with a typed zero on the right si…
Nov 22, 2026
1274ec5
[VARKA-348] Record the ANSI form's false-AND finding in the plan
Nov 22, 2026
0fd7962
[VARKA-348] Describe the decimal stand-in and comparand, score predic…
Nov 22, 2026
d227a01
Merge origin/master into varka-348-decimal-compare-r
Nov 22, 2026
a7b2938
Merge origin/master into varka-348-decimal-compare-r
Nov 23, 2026
9325255
Regenerate the generated files after merging master
Nov 23, 2026
69349cb
Regenerate the generated files after merging master
Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SKILLS.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,7 @@ the pre-commit hook also checks. Groups below are in file order.
* [The fork's CI queue is a job inside the Build, and the check sync rides the push](sql/varka/skills/working-in-this-repo.md#the-forks-ci-queue-is-a-job-inside-the-build-and-the-check-sync-rides-the-push)
* [GitHub Actions facts the CI queue cost a run each to learn](sql/varka/skills/working-in-this-repo.md#github-actions-facts-the-ci-queue-cost-a-run-each-to-learn)
* [`varka_regen_generated.sh --all` does not regenerate the golden corpus](sql/varka/skills/working-in-this-repo.md#varka_regen_generatedsh---all-does-not-regenerate-the-golden-corpus)
* [The pre-commit hook refuses a census claim that `coverage.json` cannot show yet](sql/varka/skills/working-in-this-repo.md#the-pre-commit-hook-refuses-a-census-claim-that-coveragejson-cannot-show-yet)
* [The quote check reads a plan section numbered 10.1x as a measurement](sql/varka/skills/working-in-this-repo.md#the-quote-check-reads-a-plan-section-numbered-101x-as-a-measurement)

<!-- END generated contents -->
21 changes: 17 additions & 4 deletions docs/sql-varka.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ An entry is a function or operator of the census; a type counts *fused* for it o
| `LongType` (`bigint`) | LONG | 85 | 60 | 2 | plumbing 5, semantics 18 | 0 | 90 |
| `FloatType` (`float`) | FLOAT | 66 | 36 | 2 | plumbing 5, semantics 23 | 0 | 62 |
| `DoubleType` (`double`) | DOUBLE | 102 | 54 | 2 | plumbing 4, semantics 24, ulp 18 | 0 | 82 |
| `DecimalType` (`dec`) | LONG, words per value: 1 to precision 18, 2 to precision 38 | 66 | 2 | 9 | plumbing 12, semantics 43 | 3 | 85: 60 to precision 18, 25 at precision 19 to 38 |
| `DecimalType` (`dec`) | LONG, words per value: 1 to precision 18, 2 to precision 38 | 66 | 2 | 26 | plumbing 3, semantics 35 | 3 | 93: 68 to precision 18, 25 at precision 19 to 38 |
| `DateType` (`date`) | INT | 63 | 49 | 1 | plumbing 1, semantics 12 | 0 | 107 |
| `TimestampNTZType` (`ntz`) | LONG | 54 | 49 | 0 | plumbing 1, semantics 4 | 0 | 75 |
| `TimeType` (`time`) | LONG | 49 | 34 | 3 | plumbing 1, semantics 11 | 0 | 47 |
Expand All @@ -304,9 +304,9 @@ One row per section of Spark's function registry, and per family of the operator

| Family | Entries | Every type | Some type | In part | Types owed | Rows |
| :--- | ---: | ---: | ---: | ---: | :--- | :--- |
| conditional | 11 | 1 | 11 | 1 | float, dec | 329, 331, 338, 341, 348, 359 |
| conditional | 11 | 1 | 11 | 10 | float, dec | 329, 331, 338, 341, 348, 359 |
| predicate | 16 | 6 | 15 | 8 | bool, dec | 27, 329, 331, 336, 338, 341, 347, 348, 359, 497 |
| math | 59 | 17 | 33 | 0 | bool, byte, short, int, bigint, float, double, dec, time, ym, dt | 30, 95, 103, 104, 329, 330, 333, 341, 342, 344, 346, 348, 349, 351, 356, 357, 358, 359, 360, 361, 362, 363, 367, 577, 621 |
| math | 59 | 17 | 33 | 8 | bool, byte, short, int, bigint, float, double, dec, time, ym, dt | 30, 95, 103, 104, 329, 330, 333, 341, 342, 344, 346, 348, 349, 351, 356, 357, 358, 359, 360, 361, 362, 363, 367, 577, 621 |
| bitwise | 13 | 13 | 13 | 0 | | |
| datetime | 41 | 27 | 36 | 0 | byte, short, int, bigint, float, double, dec, ntz, time, ym, dt | 103, 329, 339, 340, 343, 351 |
| hash | 2 | 0 | 0 | 0 | bool, byte, short, int, bigint, float, double, dec, date, ntz, time, ym, dt | 337, 359, 368 |
Expand Down Expand Up @@ -1530,6 +1530,19 @@ The *Switches* column names the family switches that keep the row off Varka, eac
| `-(d9 + d9b) = d9s4` | `predicate` | | the negation of a sum, compared at DECIMAL(12, 4) | not emitted: a filter's condition in a kernel driven at a 64-bit lane (BIGINT, DOUBLE, TIMESTAMP_NTZ, TIME, day-time interval, DECIMAL), on an x86 host whose 64-bit species have two lanes or fewer: C2 lowers no mask there, and the selection would run the Vector API's Java fallback |
| `try_multiply(d8, d9) IS NULL` | `predicate` | | null only where an operand is: no product within 18 digits overflows, so TRY's null past the precision never fires | not emitted: a filter's condition in a kernel driven at a 64-bit lane (BIGINT, DOUBLE, TIMESTAMP_NTZ, TIME, day-time interval, DECIMAL), on an x86 host whose 64-bit species have two lanes or fewer: C2 lowers no mask there, and the selection would run the Vector API's Java fallback |

#### DECIMAL values

| Expression | Switches | Domain | Notes | 128-bit lanes |
|---|---|---|---|---|
| `CASE WHEN d9 < d9b THEN d9 ELSE d9b END` | `predicate`, `condition` | | a DECIMAL(9, 2) choice, the comparison and the blend on the long lane | per-lane: compare to mask, mask cast, other, blend, mask logic, mask broadcast, mask test |
| `if(d9 < d9b, d18, d18b)` | `predicate`, `condition` | | a DECIMAL(18, 2) choice under a DECIMAL(9, 2) condition | per-lane: compare to mask, mask cast, other, blend, mask logic, mask broadcast, mask test |
| `coalesce(d9, d9s4)` | `condition` | | DECIMAL(11, 4): d9 times 10^2, then the first valid operand | per-lane: compare to mask, mask cast, other, blend, mask logic, mask broadcast, mask test |
| `greatest(d18, d18b)` | `intArithmetic` | | the null-skipping pick, of one scale | per-lane: compare to mask, mask cast, other, blend, mask logic, mask broadcast, mask test |
| `least(d9, d9s4)` | `intArithmetic` | | the null-skipping pick at DECIMAL(11, 4), d9 carrying its rescale | per-lane: compare to mask, mask cast, other, blend, mask logic, mask broadcast, mask test |
| `-d18` | none | | a negation, which cannot overflow: an unscaled value within 18 digits is never the long lane's minimum | per-lane: compare to mask, mask cast, other, blend, mask logic, mask broadcast, mask test |
| `abs(d18)` | none | | a compare with zero, a negation and a blend; the lanewise ABS is the decimalAbsLanewise option | per-lane: compare to mask, mask cast, other, blend, mask logic, mask broadcast, mask test |
| `try_subtract(d9, d9s4)` | none | | DECIMAL(12, 4), row 349's difference stored by the same path: no difference within 18 digits overflows, so TRY's null never fires | per-lane: compare to mask, mask cast, other, blend, mask logic, mask broadcast, mask test |

#### Time arithmetic

| Expression | Switches | Domain | Notes | 128-bit lanes |
Expand Down Expand Up @@ -1578,7 +1591,7 @@ operands (a row counts once for each type it reads):
| `bool` | 39 | 0 | 0 | 0 | 13 | 0 | 26 |
| `byte` | 57 | 0 | 0 | 0 | 0 | 8 | 49 |
| `date` | 128 | 17 | 0 | 0 | 1 | 0 | 110 |
| `dec` | 85 | 1 | 42 | 12 | 0 | 0 | 30 |
| `dec` | 93 | 1 | 50 | 12 | 0 | 0 | 30 |
| `double` | 97 | 0 | 0 | 1 | 0 | 0 | 96 |
| `dt` | 36 | 2 | 0 | 4 | 0 | 0 | 30 |
| `float` | 63 | 0 | 0 | 0 | 0 | 0 | 63 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@
* lowers the scale or the integral digits, or one from an integral type (row 350); a negative
* scale (the milestone plan's 2.8); and every operator no arm here claims yet.
*
* <p>A decimal-valued output root is compiled by {@link #output}, which the projection's root
* binding calls, and admitted by {@link #outputRoot}.
* <p>A decimal-valued output root is any {@link #value}, compiled by {@link #output}, which the
* projection's root binding calls, and admitted by {@link #outputRoot}.
*/
final class VarkaDecimalCompiler {

Expand Down Expand Up @@ -208,6 +208,12 @@ static Optional<Scaled> value(Expression e, VarkaSlotTable inputs, VarkaSlotTabl
return switch (e) {
case BoundReference br -> column(br, type, inputs, sink);
case Cast c -> cast(c, type, inputs, literals, sink);
// The two decimal-valued TIME functions (VARKA-157 2.3), under the TIME family's switch,
// which this path never reaches through compileNode: each is within its precision for
// every time of day.
case StaticInvoke si when VarkaTimeCompiler.isDecimalProducer(si) ->
VarkaNodeCompiler.inFamily(VarkaFamily.TIME,
() -> VarkaTimeCompiler.decimalProducer(si, inputs, literals, sink), si, sink);
// Neither can fail or leave the precision, |-u| = |u| (VARKA-348 0.5), so both wrap: the
// one overflowing long, Long.MIN_VALUE, is outside every decimal's bound.
case UnaryMinus m -> value(m.child(), inputs, literals, sink)
Expand Down Expand Up @@ -886,13 +892,11 @@ private static Optional<List<VarkaVectorIR>> compiledOperands(Expression whole,
}

/**
* A decimal-valued output root, or empty with the reason noted (`VARKA-157.md` 2.1): the
* output's type is asked first, so a precision above 18 or a negative scale declines naming its
* row at plan time, whatever the expression; then the value is compiled and wrapped by
* {@link #outputRoot}. The producers today are the two decimal-valued {@code TIME} functions
* ({@code VarkaTimeCompiler.decimalProducer}); every other decimal value as an output declines
* naming row 348, whose values ({@link #value}) reach this method's {@link #widened} when its
* part 348b admits them.
* A decimal-valued output root, or empty with the reason noted (`VARKA-157.md` 2.1,
* `VARKA-348.md` 2.4): the output's type is asked first, so a precision above 18 or a negative
* scale declines naming its row at plan time, whatever the expression; then the value is
* compiled by {@link #value}, as under a comparison, and wrapped by {@link #widened}. Every
* form {@link #value} builds is within its type's precision, so the store needs no check.
*/
static Optional<VarkaVectorIR> output(Expression e, VarkaSlotTable inputs,
VarkaSlotTable literals, DeclineSink sink) {
Expand All @@ -901,29 +905,27 @@ static Optional<VarkaVectorIR> output(Expression e, VarkaSlotTable inputs,
if (refused.isPresent()) {
return sink.decline(refused.get(), e);
}
if (e instanceof StaticInvoke si && VarkaTimeCompiler.isDecimalProducer(si)) {
// The producers are the TIME family's nodes, and this path never passes through
// compileNode, so it asks the family's switch and notes the family itself.
return VarkaNodeCompiler.inFamily(VarkaFamily.TIME, () ->
VarkaTimeCompiler.decimalProducer(si, inputs, literals, sink)
.flatMap(v -> widened(e, v, sink)), e, sink);
// Bracketed as a comparison's operands are, so the choice conditions it keeps are dropped
// before the entry's tables can be rolled back to its marks.
sink.enterDecimal();
try {
return value(e, inputs, literals, sink).flatMap(v -> widened(e, v, sink));
} finally {
sink.exitDecimal();
}
return sink.decline("a " + type.simpleString() + " value as a projection's output: the "
+ "decimal store writes it, and the values it admits are the TIME functions "
+ "time_to_seconds and extract(SECOND ...); the others are row 348's", e);
}

/**
* The output root of a compiled decimal {@code value} of {@code whole}: at the output type's
* scale, which every producer builds, and then {@link #outputRoot}. A value at another scale is
* a producer's error, not a decline.
* scale, which every producer builds, and then {@link #outputRoot}. A value at another scale, or
* of a wider precision, declines with its types named: the store does not rescale.
*/
private static Optional<VarkaVectorIR> widened(Expression whole, Scaled value,
DeclineSink sink) {
DecimalType type = (DecimalType) whole.dataType();
if (value.type().scale() != type.scale() || value.type().precision() > type.precision()) {
throw VarkaErrors.illegalState("a decimal output of " + type.simpleString()
+ " over a value of " + value.type().simpleString() + ": " + whole);
return sink.decline("a decimal output of " + type.simpleString() + " over a value of "
+ value.type().simpleString() + ", which the store does not rescale", whole);
}
return outputRoot(whole, value.unscaled(), sink);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,12 @@ static VarkaFamilyArm arm(
// constructors refuse a tree that mixes it with the int lane anyway.
// A decimal column is never a long column, whatever lane the registry gives it
// (VARKA-347): its sixteen-byte slots are read by its own leaf, with the check Spark's
// reader makes. Under a comparison or a null test, a decimal value - the column, a
// rescale, a negation, abs, a choice or a pick over it (VARKA-348), a sum, a difference or
// a product (VARKA-349) - is built by VarkaDecimalCompiler, so a decimal column reaching
// here declines, ahead of the long column's arm below, which would read the slots as
// eight-byte longs: with the registry's reason where it has one (a precision or scale off
// the lane), and otherwise as a value outside a
// condition - an output, row 348's (348b), or the operand of a cast to an integral
// reader makes. Under a comparison or a null test and as a decimal output, a decimal
// value - the column, a rescale, a negation, abs, a choice or a pick over it (VARKA-348),
// a sum, a difference or a product (VARKA-349) - is built by VarkaDecimalCompiler, so a
// decimal column reaching here declines, ahead of the long column's arm below, which would
// read the slots as eight-byte longs: with the registry's reason where it has one (a
// precision or scale off the lane), and otherwise as the operand of a cast to an integral
// or a floating type, rows 350 and 366. Above 18 digits the value is two words
// (VARKA-359), whose operators beyond the comparisons and null tests are later rows'.
case BoundReference br when br.dataType() instanceof DecimalType d ->
Expand All @@ -247,8 +246,8 @@ static VarkaFamilyArm arm(
? "its comparisons and null tests fuse; its negation, abs and choices are row "
+ "359's, its +, - and * rows 360 to 363, a decimal output its two-word "
+ "store, row 359's"
: "its comparisons, null tests and the values they read fuse, +, - and * "
+ "among them; a decimal output is row 348's")
: "its comparisons, null tests, the values they read and a decimal output "
+ "of them fuse, +, - and * among them")
+ ", its casts to other types rows 350 and 366"), br);
case BoundReference br
when VarkaTypes.lane(br.dataType()).orElse(null) == LaneType.LONG ->
Expand Down Expand Up @@ -602,14 +601,14 @@ private static String timeNotLoweredYet(String label) {
}

/**
* The reason the two decimal-valued {@code TIME} expressions decline below a root: at an output
* root they fuse through the decimal store ({@link #decimalProducer}), and as the operand of
* another expression their value is a decimal operand, which row 348 consumes
* (`VARKA-157.md` 2.1).
* The reason the two decimal-valued {@code TIME} expressions decline where a non-decimal
* operator reads them: as an output root and as a decimal operand they are
* {@code VarkaDecimalCompiler.value}'s ({@link #decimalProducer}), and the casts of a decimal
* to another type are rows 350 and 366.
*/
private static String decimalOperandNotYet(String label) {
return label + " returns a decimal, which fuses as a projection's output; as the operand of "
+ "another expression its value is row 348's";
return label + " returns a decimal, which fuses as a projection's output and as a decimal "
+ "operand; its casts to other types are rows 350 and 366";
}

/** The two {@code TIME} functions whose value is a decimal (`VARKA-157.md` 2.3). */
Expand All @@ -623,10 +622,10 @@ static boolean isDecimalProducer(StaticInvoke si) {
}

/**
* The unscaled value of a decimal-valued {@code TIME} function at an output root, or empty with
* the reason noted (`VARKA-157.md` 2.3). Both are non-negative and within their precision for
* every time of day, so neither needs a guard, and every divisor is proven in
* {@code long_divide.smt2}.
* The unscaled value of a decimal-valued {@code TIME} function, at an output root or as a
* decimal operand, or empty with the reason noted (`VARKA-157.md` 2.3). Both are non-negative
* and within their precision for every time of day, so neither needs a guard, and every divisor
* is proven in {@code long_divide.smt2}.
*
* <ul>
* <li>{@code time_to_seconds(t)}, a {@code DECIMAL(14, 6)}: {@code (n + 500) / 1000}, Spark's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.sql.catalyst.expressions.codegen.varka;

import java.math.BigInteger;
import java.util.Set;

import org.apache.spark.sql.types.DataTypes;
import org.apache.spark.sql.types.DecimalType;
Expand Down Expand Up @@ -72,4 +73,17 @@ protected ConformanceType type() {
protected BigInteger[] decimalSlots() {
return VALUES;
}

/**
* The operators the census marks fused in part for {@code dec} because the long fuses them and
* the pair does not: the values, each a projection's output at this suite's
* {@code DECIMAL(30, 4)}, which is row 359's two-word store - the choices, {@code greatest},
* {@code least}, the negation and {@code abs} (row 348), and the sums and differences (row 349;
* the pair's are row 360's).
*/
@Override
protected Set<String> declinesInPart() {
return Set.of("if", "when", "coalesce", "nullif", "greatest", "negative", "abs", "+", "-",
"try_add", "least", "try_subtract");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.sql.catalyst.expressions.codegen.varka;

import java.math.BigInteger;
import java.util.Set;

import org.apache.spark.sql.types.DataTypes;
import org.apache.spark.sql.types.DecimalType;
Expand All @@ -33,8 +34,11 @@
*
* <p>The values are the precision's bounds and their neighbours and zero and one each way. The
* census marks the comparisons and {@code IN} fused in part for {@code dec}: this representation
* fuses them at every scale (rows 348 and 497), the pair at one, so both are checked here; every
* other form the census owes must decline.
* fuses them at every scale (rows 348 and 497), the pair at one, so both are checked here. So it
* marks the values this representation stores and the pair does not: the choices,
* {@code greatest}, {@code least}, the negation and {@code abs} (row 348), and the sums and
* differences (row 349), each checked here as a projection's output. Every other form the census
* owes must decline.
*
* <p>In its own JVM, as the long-lane suites are ({@link VarkaSpeciesGuard}).
*/
Expand All @@ -61,4 +65,14 @@ protected ConformanceType type() {
protected BigInteger[] decimalSlots() {
return VALUES;
}

/**
* The sum and difference of two values within 10 digits fit the result type's 11, and the
* negation and {@code abs} stay within the operand's 10, so Spark never raises on them, whatever
* the mode; only the product, past 18 digits, leaves the long.
*/
@Override
protected boolean overflowReachable(String register) {
return !Set.of("+", "-", "negative", "abs", "try_add", "try_subtract").contains(register);
}
}
Loading