diff --git a/SKILLS.md b/SKILLS.md index c660eec5b9e9..3a57a0722cce 100644 --- a/SKILLS.md +++ b/SKILLS.md @@ -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) diff --git a/docs/sql-varka.md b/docs/sql-varka.md index 16aec604dec5..4103f2d13170 100644 --- a/docs/sql-varka.md +++ b/docs/sql-varka.md @@ -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 | @@ -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 | @@ -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 | @@ -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 | diff --git a/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/VarkaDecimalCompiler.java b/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/VarkaDecimalCompiler.java index d44b2d6bd89b..2e657149a744 100644 --- a/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/VarkaDecimalCompiler.java +++ b/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/VarkaDecimalCompiler.java @@ -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. * - *

A decimal-valued output root is compiled by {@link #output}, which the projection's root - * binding calls, and admitted by {@link #outputRoot}. + *

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 { @@ -208,6 +208,12 @@ static Optional 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) @@ -886,13 +892,11 @@ private static Optional> 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 output(Expression e, VarkaSlotTable inputs, VarkaSlotTable literals, DeclineSink sink) { @@ -901,29 +905,27 @@ static Optional 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 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); } diff --git a/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/VarkaTimeCompiler.java b/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/VarkaTimeCompiler.java index f58852d7e465..bb12f09c991b 100644 --- a/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/VarkaTimeCompiler.java +++ b/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/VarkaTimeCompiler.java @@ -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 -> @@ -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 -> @@ -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). */ @@ -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}. * *