Repository navigation
fix(query): raise type for an if with a temporal arm and a numeric arm - #1487
Open
singaraiona wants to merge 3 commits into
Open
singaraiona wants to merge 3 commits into
singaraiona wants to merge 3 commits into
Conversation
In a query, an if with one temporal arm (DATE, TIME, TIMESTAMP, TIMESPAN) and one numeric arm (BOOL, U8, I16, I32, I64, F32, F64) wrote the temporal arm's raw count (days, ms, ns) beside the numbers, and a computed arm boxed the cells into a LIST. promote_if_type now gives such a pair no common type, as #1481 did for two temporal types, so ray_if refuses it at plan time and every route raises `if: branches mix DATE and I32`. A temporal arm beside a null literal keeps its type; outside a query if is control flow.
…er-group routes An if whose arm the planner cannot compile, such as (at v 0), a TIMESPAN from (- p p), or an if over aggregates under by:, runs one arm per row or per group and boxed the cells into a LIST. eval_expr_per_row_impl and nonagg_eval_per_group_core now check such a LIST for an expression holding an if: a temporal cell beside a numeric or another temporal one raises `if: branches mix ...`, and one temporal type beside null cells only is that type's column, as ray_if makes it for a null literal.
… per-row routes rw_if_cells_check judged any expression holding an if, so an if that only picks an index, (at (enlist d 7) (if c 0 1)), was blamed for the call's mixed cells; it now judges only an expression that is the if. A null cell was taken for a null literal whatever its arm; now only a null of the type of one of the if's null literal arms (through nested ifs in arm position) takes the other arms' type, and a computed null, (at [0Nl] 0), counts as its arm's I64 and raises beside a DATE arm.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
In a query, an
ifwith one temporal arm (DATE, TIME, TIMESTAMP or TIMESPAN) and one numeric arm (BOOL, U8, I16, I32, I64, F32 or F64) wrote the temporal arm's raw count beside the numbers: days for DATE, ms for TIME, ns for TIMESTAMP and TIMESPAN. A computed arm boxed the cells into a LIST instead (#1485). On dev:anton decided on the board (T-843, A) that this raises
type, as #1481 made it for two different temporal arms.Fix
promote_if_type(src/ops/graph.c) now returns fix(query): raise type for an if over two temporal types #1481's "no common type" code for a temporal arm beside a numeric one, in either order.ray_ifapplies the null-literal exception first, so(if c d 0N)stays DATE, then refuses the pair at plan time:if: branches mix DATE and I32. That is one check perifnode.cond, a call around theif,select(keyless,where:,by:, a by: key, an aggregate's argument, awhere:predicate),update(keyless,where:,by:), and parted tables.(at v 0),(count (distinct k)), a TIMESPAN from(- p p), or anifover aggregates underby:. These run one arm per row or per group, and boxed the cells into a LIST (two different temporal types did the same after fix(query): raise type for an if over two temporal types #1481).eval_expr_per_row_implandnonagg_eval_per_group_coreinsrc/ops/query.cnow check that LIST when the expression is itself anif. Anifinside a call, such as(at (enlist d 7) (if c 0 1)), doesn't own the call's values, so the dev LIST stays.if's branches, including those of nestedifs in branch position, are scanned for null literals. A null cell of a null literal's type is that literal. Any other cell counts by its type, including a computed null such as(at [0Nl] 0).if: branches mix ....ray_ifmakes it.(if c (+ t 1000) 0Nd)is now a TIME column with 0Nt instead of a LIST holding 0Nd.ifis control flow and evaluates one arm, which is unchanged.Answers that change: every temporal × numeric pair in a query now raises
type. To get the raw count, cast the arm:(if c (as 'I64 d) i).Tests
test/rfl/query/if_temporal_numeric.rfl(new,@also-unfused) covers:where:, underby:and inupdate;cond, a call, keyless and per-group aggregates, a by: key, awhere:predicate, update withwhere:andby:, and overwriting a column;asforms, a parted table, and control flow outside a query;(at V 0),(count (distinct k)),(- p p),(- t t), anifover aggregates underby:(with groups on both arms), each on a parted table too; the null-literal cases there, including a chain and a nestedif; a computed null, which raises; and anifinsideat, which keeps dev's LIST.got "[10 8767 8768]", and without thequery.ccheck with a LIST at(if (> g 0) d (at V 0)).type, each keeping its intent through theasform or a null literal:test/rfl/query/grouped_if_rowwise.rfl,if_temporal_mix.rfl,if_temporal_null.rflandtest/rfl/ops/pivot_coverage.rfl(the empty-branch cases).test/rfl/arith/temporal_int_arith.rflpinned the LIST for(if c (+ t 1000) 0Nd)and now pins the TIME column.Docs
docs/docs/language/control-flow.md,docs/docs/guides/types.md,docs/docs/language/functions.mdanddocs/docs/reference/all-functions.md: a temporal arm beside a number raisestype, with the(as 'I64 d)form for the raw count.mkdocs build --strictpasses.Fixes #1485