#The value triple: eod, missing data and errors
Every answer in eLucid8 is a triple: its kind, its value and its timestamp. This page gives every rule about the three, each with a small program and its answers, and the conformance cases that test it. Other pages link here for these rules. The examples are read as How to read the examples says: the comment lines under each program give its inputs' rows and its answers.
#The triple
Reads as: an answer is data, eod or an error, with the time of the newest data it was computed from.
Means: a value has an answer at every point. Each answer has three parts:
| part | what it is |
|---|---|
| kind | data, eod or error |
| value | for data, a number, a boolean, a text or a collection; for eod, nothing; for an error, its error kind and its origin, the point where it started (its dimensions in the order its value declares them) |
| timestamp | the time, in milliseconds, of the newest data the answer was computed from; 0 when it read no data with a time |
Example:
-- file triple.el8
-- Doubled readings, their total, and where readings are missing.
reading = input("reading", t : 5)
doubled = reading * 2
total = sum reading over (t : 5) end
gap = iserror(reading, "missing")
-- table reading = t,value,ts; 0,4,1000; 1,,2000; 3,6,3000; 4,2,4000
-- expect doubled[t = 0] = 8, at time 1000 ms
-- expect doubled[t = 1] = error missing from reading[t = 1]: input reading has no data at this point, at time 2000 ms
-- expect doubled[t = 2] = error missing from reading[t = 2]: input reading has no data at this point
-- expect doubled[t = 5] = eod
-- expect total = 12, at time 4000 ms
-- expect gap[t = 1] = true, at time 2000 ms
Answers:
| point | kind | value | timestamp | why |
|---|---|---|---|---|
doubled[t = 0] | data | 8 | 1000 ms | the row at t = 0 |
doubled[t = 1] | error | missing, from reading[t = 1] | 2000 ms | an empty cell in a row with a time |
doubled[t = 2] | error | missing, from reading[t = 2] | 0 | no row, so no time |
doubled[t = 5] | eod | 0 | outside the bound t : 5 | |
total | data | 12 | 4000 ms | the two missing points left out, and counted in a warning |
gap[t = 1] | data | true | 2000 ms | iserror gives data, with its operand's timestamp |
Check:
- What kind is it? eod means the point is outside the data. An error means something went wrong inside the data, and says what and where.
- If an error, where did it start? Its origin names a value and a point. Why? in the playground, or
elucid8 run --why, leads there. - How new is it? An answer about 9:00 with a timestamp after 9:00 read data from its own future. An answer at timestamp 0 read no data with a time, or only data at a clock's tick 0.
- What did an aggregate leave out? The warning beside the answer counts the missing points (
aggregates left out 2 missing points of input reading).
Rules:
- Every point of every value has exactly one answer, of exactly one kind.
- An error's error kind is one of
missing,late,failed,division,non-finite,empty,assert,type,index,data,raisedandversion(Errors). An error passed on keeps the error kind and origin of the error where it started. - The timestamp of an answer computed from others is the latest timestamp among what it read, by the rules of Values and timestamps. Data read from an input has its row's time, or its clock's time.
- eod, missing data and other errors are different answers, and nothing turns one into another by itself. A program turns one into another only by writing it:
default,iseod,iserror,if. - Caches, compiled loops, threads and memory management never change an answer's kind, value or timestamp.
Tested by the conformance cases (Conformance) error-kinds, column-gap-time-zero and data-ends-finite.
#eod: end of data
Reads as: eod is "end of data": there is no data at this point, because the point is outside the data.
Means: a point is eod past an input's data, outside a bound, below 0, and wherever a program writes eod. Inside the data, a point with no usable value is never eod: it is missing data.
Example:
-- file eod.el8
-- Where eod arises: past the last row, below 0, outside a bound, and where the program says so.
reading = input("reading", t : inf)
change = reading - reading[t = #t - 1]
ended = iseod(reading)
first_two = restrict reading to (t : 2) end
none = eod
both = eod + error("sensor fault")
-- table reading = t,value,ts; 0,4,1000; 1,7,2000; 2,5,3000
-- expect reading[t = 3] = eod
-- expect ended[t = 3] = true
-- expect change[t = 0] = eod, at time 1000 ms
-- expect change[t = 1] = 3, at time 2000 ms
-- expect first_two[t = 2] = eod
-- expect none = eod
-- expect both = eod
Answers:
| point | kind | timestamp | why |
|---|---|---|---|
reading[t = 3] | eod | 0 | past the last row along t, declared inf |
ended[t = 3] | data: true | 0 | iseod tests for eod |
change[t = 0] | eod | 1000 ms | reading[t = -1] is below 0; the timestamp is that of reading[t = 0], also read |
change[t = 1] | data: 3 | 2000 ms | 7 − 4 |
first_two[t = 2] | eod | 0 | outside the bound t : 2 |
none | eod | 0 | the program writes eod |
both | eod | 0 | eod wins over an error |
Check:
- eod where you expected data: is the point past the data's last row, outside a bound, or below 0?
elucid8 infolists each value's dimensions and bounds. - eod at every point: a search by time compared a position with a time (
asof.q quote at #t end), or the data begin later than the program reads. Query the first point and press Why?.
Rules:
- eod arises only in these places: past the last row along an input's dimension declared
inf(Where data ends); outside an input's bound or list; outside arestrict … to … end; at a coordinate below 0; and where the program writeseod. - Operators and functions are strict: an operand that is eod makes the result eod.
if,and,orandfbylook only at the operands they use. - eod wins over an error: where an operator's operands include eod and an error, the result is eod.
- eod has timestamp 0 where it arises, and takes the timestamp of everything read where it is passed on.
iseod(e)is true whereeis eod and false elsewhere.default(e, v)isvwhereeis eod andeelsewhere.- A data file holds eod only as the last row of a line along a dimension declared
inf(a celleod). Inside a fixed range the reader refuses aneodcell (What is refused). - A query that leaves out a dimension of its value gives eod at every point, with a warning naming the dimension. From 0.26.0 such a query is refused (What is refused).
Tested by data-ends-finite, data-ends-c4 and dc7-restrict.
#Errors
Reads as: an error is an answer that says what went wrong and where it started.
Means: an error has an error kind and an origin. Operators pass it on unchanged, so the error at an answer is the error at its origin.
Example:
-- file error-kinds.el8
-- Errors a program makes, the origin an error keeps, and testing and filling by kind.
reading = input("reading", t : 4)
ratio = 10 / reading
doubled = ratio * 2
big = exp(reading * 1000)
positive = reading assert reading > 0
fault = restrict if #t == 3 then error("sensor fault") else reading to (t : 4) end
nothing = mean reading over (t : 3 .. 2) end
is_division = iserror(doubled, "division")
safe = default(doubled, 0, "division")
-- table reading = t,value; 0,2; 1,0; 2,-1; 3,5
-- expect doubled[t = 0] = 10
-- expect ratio[t = 1] = error division: division by zero
-- expect doubled[t = 1] = error division from ratio[t = 1]: division by zero
-- expect big[t = 0] = error non-finite: exp gave Infinity (non-finite)
-- expect positive[t = 2] = error assert: assert failed: reading > 0 was false
-- expect fault[t = 3] = error raised: sensor fault
-- expect nothing = error empty: mean of no elements
-- expect is_division[t = 1] = true
-- expect safe[t = 1] = 0
Answers:
| point | kind | error kind | origin |
|---|---|---|---|
doubled[t = 0] | data: 10 | ||
ratio[t = 1] | error | division | ratio[t = 1] |
doubled[t = 1] | error | division | ratio[t = 1] (read through one link) |
big[t = 0] | error | non-finite | big[t = 0] |
positive[t = 2] | error | assert | positive[t = 2] |
fault[t = 3] | error | raised | fault[t = 3] |
nothing | error | empty | nothing |
is_division[t = 1] | data: true | ||
safe[t = 1] | data: 0 |
The error kinds:
| error kind | where it arises |
|---|---|
missing | an input's point inside the data with no usable value (Missing data) |
late | an input answered on demand answered after its deadline (Data services) |
failed | an input answered on demand failed (Data services), or an input's connector failed |
division | division by zero (/, div, mod) |
non-finite | an operation whose result is infinite or not a number |
empty | mean, min, max, argmax, argmin or a statistic of no elements (Aggregates); head or tail of the empty list |
assert | e assert p where p is false or eod |
type | a value of the wrong sort where it is used: 1 + "a", if 3 then …, not 1, a coordinate or bound that is not one |
index | a list position before the start or past the end of the list (L elt 5), or a record without the field |
data | a data file's error: … cell, or an error read back from a file that does not carry its kind |
raised | error("…") written in the program |
version | the version of an input that a pinned query asks for is no longer available |
Check:
- Which error kind? Test it with
iserror(e, "division"). A program that fills errors fills one kind at a time,default(e, v, "division"), so the other kinds still show. - Where did it start? The origin.
doubled[t = 1]above did not divide;ratio[t = 1]did.
Rules:
- Operators and functions are strict: an operand that is an error makes the result that error, keeping its error kind and its origin. Of two errors among an operator's operands, the first in the order written is the result. eod wins over an error.
iserror(e)is true whereeis an error;iserror(e, k)where it is an error of kindk. Both give data withe's timestamp.kis a text written in place, one of the eight error kinds; anything else is refused by the compiler.default(e, v, k)isvwhereeis an error of kindk(or, withkwritten"eod", whereeis eod), andeeverywhere else. To fill eod and missing data both:default(default(e, v), v, "missing").- An error's timestamp is the latest of what it read, as for data.
Tested by error-kinds, long-chain and strict-detector-0.
#Missing data
Reads as: missing data is "a reading that should be here, and is not".
Means: missing data is an error of kind missing. It arises only where an input is read, at a point inside the data with no usable value.
Example: the triple above: reading has no row at t = 2 and an empty cell at t = 1, so both are missing data, and doubled there is that error, from reading.
Rules:
- Missing data arises at these points, each with the message
input reading has no data at this point(the input's name), and the timestamp given:- a point with no row, inside the data: timestamp 0, because it has no time;
- an empty or null cell (an empty CSV field, JSON
null, an Arrow or Parquet null, SQL NULL; pandasNoneandNAthrough the Python package): its row's time; - a point with no row on an input whose times come from a clock (
"time": {"dimension": "hour", "everyMs": 3600000}): the time its clock gives that point (below), 0 at a tick whose clock time is 0, which is a time like any other; - an input answered on demand that answers "nothing here": timestamp 0.
- Missing data is an error like any other: operators pass it on,
iserror(e, "missing")tests it,default(e, v, "missing")fills it, and a deployment can fill it withfill. - Aggregates leave missing data out and count it (Aggregates). A search takes it as a candidate only when it has a time (Direct reads and searches).
- Written to CSV, the value cell of missing data is empty and its kind column says
error missing, so the file reads back as written; eod's kind column sayseod, and another error's its kind (error division), with the cause in the message column. With--csv-words, the value column alone: missing data an empty field, eodeod, every other errorerror: ….
A clocked input. With times from a clock, a point with no row is missing at its clock time: the reading was due then, and nothing came.
temp = input("temp", hour : 6)
day_total = sum temp over (hour : 6) end
temp.csv:
hour,value
0,10
1,11
3,13
deploy.json:
{
"format": "elucid8-deploy/2",
"inputs": {
"temp": { "from": "temp.csv", "time": { "dimension": "hour", "everyMs": 3600000 } }
}
}
elucid8 run --query 'temp[hour = 2]' --query day_total gives:
elucid8 run: warning: query 2 (day_total): aggregates left out 3 missing points of input temp
{"name":"temp","context":{"hour":2},"outcome":{"kind":"error","error":"missing","message":"input temp has no data at this point","origin":{"name":"temp","context":{"hour":2}},"ts":7200000}}
{"name":"day_total","context":{},"outcome":{"kind":"value","value":34,"ts":18000000}}
| point | kind | value | timestamp |
|---|---|---|---|
temp[hour = 1] | data | 11 | 3,600,000 ms (hour 1) |
temp[hour = 2] | error | missing, from temp[hour = 2] | 7,200,000 ms (hour 2) |
temp[hour = 4], temp[hour = 5] | error | missing | hours 4 and 5 |
temp[hour = 6] | eod | 0: outside the bound hour : 6 | |
day_total | data | 34 | 18,000,000 ms: hours 2, 4 and 5 left out, and counted |
Tested by column-gap-time-zero, clock-gap-asof, clock-gap-window, clock-gap-default and dropouts.
#Data services: late and failed
Means: an input answered on demand (a model, a web API, a simulated service) gives an error of kind late when its answer comes after its deadline, and of kind failed when it fails. The error's timestamp is when the call ended: the deadline, or the failure.
Example:
-- file service-kinds.el8
-- A service that answers too late, and one that sometimes fails.
reading = input("reading", t : 4)
model = input("model", n : inf)
score = model[n = reading]
flaky = input("flaky", n : inf)
checked = flaky[n = reading]
was_late = iserror(score, "late")
did_fail = iserror(checked, "failed")
-- data reading = 10 * #t
-- service model: answers formula x1; takes 30 ms; deadline 20 ms
-- service flaky: answers formula x1; takes 5 ms; fails 50% with overloaded; seed 5; deadline 20 ms
-- expect score[t = 1] = error late from model[n = 10]: late (30 ms > deadline 20 ms), at time 20 ms
-- expect was_late[t = 1] = true, at time 20 ms
-- expect checked[t = 0] = 0, at time 5 ms
-- expect checked[t = 1] = error failed from flaky[n = 10]: service error: overloaded, at time 5 ms
-- expect did_fail[t = 1] = true, at time 5 ms
Rules: a service's deadline, retries and reuse are its settings (Data services). A late answer is never a value. Each attempt is recorded, and a recorded run replays exactly.
Tested by job-services and services-v02.
#Where data ends
Reads as: along a dimension declared inf, the data say where they end; inside a fixed range or a list, every point is a reading that should be there.
Means: whether a point with no row is eod or missing depends on how the input declares the dimension: past the data's end it is eod; inside the data it is missing.
Example:
-- file data-ends.el8
-- The same rows over t declared inf, over t : 5 and over a list.
open = input("open", t : inf)
fixed = input("fixed", t : 5)
listed = input("listed", t : {0, 1, 3, 7})
-- table open = t,value; 0,1; 1,2; 3,4
-- table fixed = t,value; 0,1; 1,2; 3,4
-- table listed = t,value; 0,1; 1,2; 3,4
-- expect open[t = 2] = error missing: input open has no data at this point
-- expect open[t = 4] = eod
-- expect fixed[t = 4] = error missing: input fixed has no data at this point
-- expect fixed[t = 5] = eod
-- expect listed[t = 7] = error missing: input listed has no data at this point
-- expect listed[t = 2] = eod
Answers:
| point | kind | why |
|---|---|---|
open[t = 2] | error missing | a gap among the rows, before the last row along t (t = 3) |
open[t = 4] | eod | past the last row along t |
fixed[t = 4] | error missing | inside t : 5, which has no end of data |
fixed[t = 5] | eod | outside the bound |
listed[t = 7] | error missing | in the list, with no row |
listed[t = 2] | eod | not in the list |
Rules:
- Every dimension of an input says its extent:
t : inf(the data decide where it ends),t : 10ort : 3 .. 9(a fixed range), ort : {…}(a list of numbers or texts). A dimension named alone is refused by the compiler. - Data end only along a dimension declared
infwhose coordinates are whole numbers. Along such a dimensiont, the last row alongtis the greatest coordinate the input's data list along it (a row whose value cell is empty counts). A point with no row past it is eod, timestamp 0. - Every other point with no row, inside the bound and lists, is missing data. So a gap among the rows is missing; along
t : infthe points after the last row are eod; insidet : 10they are missing. - The last row is the input's, over all its lines. A sensor that missed the last reading has missing data there, because another sensor's row reaches it (Direct reads and searches).
"ragged": truein the input's entry indeploy.jsonmakes each line (the input's other coordinates fixed) end at its own last row along each dimension declaredinf, for data whose lines have different lengths. A line with no row ends before 0. It is refused on an input with no dimension declaredinf.- Along a dimension of texts or real numbers there is no order of rows and so no end: a coordinate the data do not list is missing data, inside its list.
An input with no rows (an empty file, or a header only) needs no rule of its own. Along a dimension declared inf, every point is past the end, so eod. Inside a fixed range, every point is a reading that should be there, so missing data.
pen = input("pen", t : inf)
box = input("box", t : 3)
With pen.csv and box.csv each holding only the header t,value, pen[t = 0] is eod, and box[t = 0] to box[t = 2] are missing data. elucid8 check warns about both:
warning: input "pen" has no rows (pen.csv): every point is eod along t, declared inf
warning: input "box" has no rows (box.csv): every point inside its bounds is missing data
The playground differs in one case: an input whose card has no rows at all is an error at every point, so that a misspelt input answered on demand says so.
Tested by data-ends-finite, data-ends-ragged, data-ends-q47, data-ends-c4 and data-ends-fill.
#Filling gaps: fill
Reads as: "fill": {"missing": 0} is "where this input has no reading inside the data, read 0".
Means: fill is a setting of an input, in its entry in deploy.json. Every point of the input that is missing data where it is read reads the value given instead. A filled point is data.
Example: sales is filled with 0 ("fill": {"missing": 0} in deploy.json; the line -- fill sales = 0 gives the same setting here), raw is the same rows without a fill.
-- file fill.el8
-- The same rows with a fill of 0, without one, and filled in the program.
sales = input("sales", day : inf)
raw = input("raw", day : inf)
n = count sales over (day : 0 .. 3) end
n_raw = count raw over (day : 0 .. 3) end
total = sum sales over (day : 0 .. 3) end
total_raw = sum raw over (day : 0 .. 3) end
in_program = default(raw, 0, "missing")
-- table sales = day,value; 0,5; 2,7; 3,1
-- table raw = day,value; 0,5; 2,7; 3,1
-- fill sales = 0
-- expect sales[day = 1] = 0
-- expect sales[day = 4] = eod
-- expect raw[day = 1] = error missing: input raw has no data at this point
-- expect n = 4
-- expect n_raw = 3
-- expect total = 13
-- expect total_raw = 13
-- expect in_program[day = 1] = 0
-- expect in_program[day = 4] = eod
Answers:
| point | answer | why |
|---|---|---|
sales[day = 1] | 0 | no row inside the data: the fill |
sales[day = 4] | eod | past the last row along day: a fill never reaches past the data |
raw[day = 1] | error missing | no fill |
n, n_raw | 4, 3 | a filled point is counted; a missing one is left out (with a warning) |
total, total_raw | 13, 13 | adding 0 changes no sum |
in_program[day = 1] | 0 | default(…, "missing") in the program gives what fill gives |
Check: a fill hides gaps. Ask whether a missing reading means "nothing happened" (a fill of 0 is right: no sales that day) or "we do not know" (leave fill out: an aggregate then says how many it left out).
Rules:
"fill": {"missing": v}:vis a number,true,falseor a text ("0"is the text0), or an object by coordinate of one of the input's dimensions declared with a list or a count,{"missing": {"kind": 0, "key": ""}}, where"*"names every coordinate not named, and a coordinate not named with no"*"stays missing data.- Leaving
fillout is the default: a point with no row inside the data is missing data. - A filled point is data: operators combine it, aggregates count and fold it, and searches and windows take it as a candidate.
iserror(x, "missing")is false there. - A fill keeps the timestamp of what it fills: on a clocked input, the clock's time at that point; an empty cell, its row's time; otherwise 0.
default(x, v, "missing")in the program gives the same timestamps. - A fill reaches only points inside the data. Past the last row along a dimension declared
inf(with"ragged": true, past each line's own last row) a point is eod, whateverfillsays. missingis the only kind a deployment fills. eod is end of data, never filled by a deployment (default(x, v)in the program gives a value past the data); other errors are the program's to fill (default(x, v, "late")).
Tested by fill-plain, fill-by-coordinate, data-ends-fill, clock-gap-default and the fill-sparse-… cases.
#Aggregates
Reads as: sum reading over (t : 6) end is "the sum of reading over t from 0 to 5, missing points left out".
Means: every aggregate (over a region, a neighbourhood or a window) leaves out its missing elements, and counts them. If every element it had was missing, the result is missing. With no elements at all, it gives its ordinary answer: 0, or an error of kind empty where there is none.
Example:
-- file aggregates.el8
-- Sums and counts over readings with gaps, and over nothing.
reading = input("reading", t : 6)
total = sum reading over (t : 6) end
quiet = sum reading over (t : 6) skip missing end
n = count reading over (t : 6) end
gaps = sum (if iserror(reading, "missing") then 1 else 0) over (t : 6) end
all_missing = sum reading over (t : 2 .. 3) end
none = sum reading over (t : 3 .. 2) end
none_mean = mean reading over (t : 3 .. 2) end
-- table reading = t,value,ts; 0,1,1000; 1,2,2000; 4,5,5000; 5,6,6000
-- expect total = 14, at time 6000 ms
-- expect quiet = 14, at time 6000 ms
-- expect n = 4, at time 6000 ms
-- expect gaps = 2, at time 6000 ms
-- expect all_missing = error missing from reading[t = 2]: input reading has no data at this point
-- expect none = 0
-- expect none_mean = error empty: mean of no elements
Answers:
| point | answer | why |
|---|---|---|
total | 14, at 6000 ms | 1 + 2 + 5 + 6; t = 2 and 3 left out, with the warning aggregates left out 2 missing points of input reading |
quiet | 14, at 6000 ms | the same answer; skip missing written, so no warning |
n | 4 | count counts the elements kept |
gaps | 2 | missing points are counted with iserror, never with count |
all_missing | error missing, from reading[t = 2] | every element was missing: the first of them |
none | 0 | no elements: the ordinary sum |
none_mean | error empty | the mean of no elements has no answer |
Rules:
- An aggregate leaves out each element that is missing data: not counted, not folded, its timestamp still counted.
meanandcountare over what is kept. - A query counts the missing points its aggregates left out, each point once, and reports them per input in a warning (
aggregates left out 3 missing points of input reading) and inskippedMissingin the query's report (elucid8 run --report,serve's replies). skip missingwritten on an aggregate makes it quiet: the same answer, the points still counted inskippedMissing, but not in the warning.- If every element it had was missing, the result is missing: the first missing element in the aggregate's order, with the aggregate's timestamp.
- With no elements at all:
sum,approx_sumandcountgive 0,listgives[]andcollect{};mean,approx_mean,min,max,argmax,argmin,variance,sample_varianceandstddevgive an error of kindempty(mean of no elements), whichiserror(x, "empty")tests anddefault(x, v, "empty")fills.sample_varianceof one element is an error of kindfailed(sample variance of one element). - An aggregate's elements are the points it would fold: not the positions a filter leaves out, not the positions past a bound or below 0, and, with
skip eod, not the eod ones. - Otherwise an eod element makes the result eod (eod wins), unless
skip eodis written; and another error element makes the result that error, the first in the aggregate's order. - A window takes missing data at its time like an aggregate: a clocked sensor that sent nothing in a window has only missing elements there, so the window's sum is missing; an input with a time column and no rows in the window has an empty window, so its sum is 0.
- To leave errors out of an aggregate, filter them:
if not iserror(temp)after the region, orif not iserror(temp, "data")for one error kind. eod is never a marker for "leave this out":if iserror(temp) then eod else tempsays the data end where a reading was faulty, and every reader of that value sees an end of data there.
Leaving out errors: missing points are left out by themselves; other errors only where the program filters them out.
-- file faulty.el8
-- The mean of 8 readings: an empty cell at t = 2, no row at t = 4, a fault at t = 6.
temp = input("temp", t : 8)
all = mean temp over (t : 8) end
clean = mean temp over (t : 8) if not iserror(temp) end
-- table temp = t,value; 0,15; 1,15.5; 2,; 3,16.5; 5,17; 6,error: sensor fault; 7,18
-- expect all = error data from temp[t = 6]: sensor fault
-- expect clean = 16.4
| point | answer | why |
|---|---|---|
all | error data, from temp[t = 6] | the two missing points left out, with a warning; the fault is the first error left, so it is the result |
clean | 16.4 | the mean of the five readings: the filter leaves out the fault and the two missing points, so there is no warning |
Tested by gaps-skipped-counts, skip-missing-quiet, aggregate-region-all-missing, aggregate-region-empty, aggregate-window-clock-all-missing, aggregate-window-clock-one-reading and aggregate-window-column-empty.
#Direct reads and searches
Reads as: a direct read, reading[sensor = 1, t = 3], asks "is there a reading here?". A search, asof.t reading[sensor = 1] at 3500 end, asks "what has arrived on this line, as of 3500?".
Means: a direct read of a point inside the data with no row gives missing data. A search along a dimension declared inf looks only as far as its own line's data have arrived: up to that line's last row.
Example: sensor 0 has rows to t = 3, sensor 1 only to t = 1. kept holds the same rows, with "ragged": true (the line -- ragged kept here).
-- file lines.el8
-- A line that stops early: read directly, searched, and read as ragged.
reading = input("reading", sensor : 2, t : inf)
kept = input("kept", sensor : 2, t : inf)
now_1 = reading[sensor = 1, t = 3]
known_1 = asof.t reading[sensor = 1] at 3500 end
last_1 = latest.t reading[sensor = 1] at 3500 end
ragged_1 = kept[sensor = 1, t = 3]
-- table reading = sensor,t,value,ts; 0,0,10,0; 1,0,20,0; 0,1,11,1000; 1,1,21,1000; 0,2,12,2000; 0,3,13,3000
-- table kept = sensor,t,value,ts; 0,0,10,0; 1,0,20,0; 0,1,11,1000; 1,1,21,1000; 0,2,12,2000; 0,3,13,3000
-- ragged kept
-- expect now_1 = error missing from reading[sensor = 1, t = 3]: input reading has no data at this point
-- expect known_1 = 21, at time 1000 ms
-- expect last_1 = 1, at time 1000 ms
-- expect ragged_1 = eod
-- expect reading[sensor = 1, t = 4] = eod
Answers:
| point | answer | why |
|---|---|---|
now_1 | error missing, from reading[sensor = 1, t = 3] | inside the data (sensor 0's row reaches t = 3), and sensor 1 has no row there |
known_1 | 21, at 1000 ms | the search on sensor 1's line stops at its last row, t = 1 |
last_1 | 1 | latest gives the position: sensor 1's last row |
ragged_1 | eod | with "ragged": true, sensor 1's line ends at its own last row |
reading[sensor = 1, t = 4] | eod | past the input's last row along t |
The difference between now_1 and known_1 is intended. A direct read asks about one point, and a reading due there that did not come is missing. A search asks what has arrived on a line, and a feed that has not reported yet has not sent anything to find.
Searches over a gap (asof, hold, latest, after):
-- file search-gaps.el8
-- An empty cell with a time is a candidate; a point with no row is not.
quote = input("quote", q : 4)
at_gap = asof.q quote at 9500 end
known = asof.q quote at 9500 skip missing end
early = asof.q quote at 500 end
-- table quote = q,value,ts; 0,100,1000; 1,101,4000; 2,,6000
-- expect quote[q = 3] = error missing: input quote has no data at this point
-- expect at_gap = error missing from quote[q = 2]: input quote has no data at this point, at time 6000 ms
-- expect known = 101, at time 4000 ms
-- expect early = eod
| point | answer | why |
|---|---|---|
quote[q = 3] | error missing, timestamp 0 | no row inside q : 4 |
at_gap | error missing, from quote[q = 2], at 6000 ms | the empty cell at 6000 is the latest candidate; q = 3 has no time, so it is no candidate |
known | 101, at 4000 ms | skip missing passes over the empty cell |
early | eod | no candidate at or before 500 |
A stale hold: hold.t x at T within M end with no candidate in its window (T − M, T], but candidates both before it and after T (the readings stopped, then started again), is missing data: an error of kind missing (hold: no data within 2000 ms before 9000) at the time of the newest reading before the window. With readings at 1,000, 2,000 and 9,500 ms, hold.t x at 9000 within 2000 end is that error, at 2,000 ms. A window wholly before the first reading or after the newest is outside the data: eod. So a live answer, which reads the data present, gives eod for a stale hold at a stream's newest tick, and missing data at the same point once a later reading arrives. asof … within M and latest … within M are the same (asof: no data within …, latest: no data within …).
Rules:
- A direct read of an input (
x[t = 4], orxat the current point) gives the row's value, missing data inside the data with no usable value, or eod outside the data (Where data ends). - A search along a dimension declared
infreaches as far as the lines it reads have rows, at the same other coordinates: the earliest of those lines' last rows. A line that stops early is searched to its own last row, and other lines are not affected. - A line the data never list has had nothing arrive: a search there gives eod.
- With a fill, the points after a line's own last row are not candidates of a search: a feed that has not reported yet is not read as zeros. A direct read of the same points gives the fill.
- Missing data with no time (a point with no row, timestamp 0, on an input with a time column or no times) is never a candidate, whether or not
skip missingis written. - Missing data with a time (an empty cell in a row with a time, or a point with no row on a clocked input, at its tick's time, 0 included) is a candidate at its time, an error like any other: the search's answer is that error when it is the candidate chosen, unless
skip missingis written, which passes over it.skip eodpasses over eod candidates. - A window is an aggregate: it leaves out missing candidates always (Aggregates).
- A window over a line chosen at run time counts the read that picks the line in each element's time, written inline or through a named value alike. It follows from the general rule that a value's time includes what chose it:
quotes[sym = trade_sym]is stamped with the later of the quote's time andtrade_sym's. Incount quotes[sym = trade_sym] over (q : window.q 60000 at time(trade_sym)) end, each quote is judged at the later of its own time and the trade's. With A's quotes at 1,000, 50,000 and 80,000 ms and a trade of A at 100,000 ms, the count is 3, stamped 100,000 ms, and so iscount picked over … endwithpicked = quotes[sym = trade_sym]: naming a part of a program never changes its answer. To judge each element by its own time, aggregate first, then select:(count quotes over (q : window.q 60000 at time(trade_sym)) end)[sym = trade_sym]gives 2, stamped 100,000 ms, as does the window over the line named,count quotes[sym = "A"] over … end. The same holds forhold … within M:hold.q quotes[sym = trade_sym] at time(trade_sym) within 10000 endgives 12 (the quote at 80,000 ms, judged at 100,000), while hold first, then select,(hold.q quotes at time(trade_sym) within 10000 end)[sym = trade_sym], gives eod (no quote of A in the 10 s before the trade).asofandlatesthave no lower edge and give the same answer either way. The law: selecting a line commutes with a window orwithinwhen the index's timestamp is 0 (a constant or a coordinate). - From 0.26.0,
time(e)hase's bounds, so a search over it is accepted where a search overeis: with quotes at 1,000, 2,500 and 4,000 ms overq : inf,asof.q time(quotes) at 3000 endgives 2,500. Releases before 0.26.0 refuse it (v must be bounded along q).
Tested by gaps-search-window, gaps-hold-skip-missing, clock-gap-asof, column-gap-time-zero, reach-chosen-missing, reach-chosen-trades, chosen-line-substitution and fill-sparse-searches.
#What is refused
A mismatch between a program and its setup is not a gap in the data. It is refused where it is read, with a message naming what to change, and no answer is computed.
A file that does not fit the program. A file with no column (CSV) or field (JSON lines) named after one of an input's dimensions, and a file for an input with no dimensions that holds other than one value, are refused by
elucid8 check,runandserve(exit code 3). Fortemp = input("temp", hour : 6)and a file with columnst,value:elucid8: input temp (temp.csv): no column hour, a dimension of temp; its columns are t, value"missing"in an input's entry. The setting isfill;"missing"is refused with the form to write:elucid8: deploy.json: inputs.temp.missing: write "fill": {"missing": 0}, not "missing"A fill of eod. eod is end of data, never a fill:
elucid8: deploy.json: inputs.temp.fill.eod: eod is end of data, never filled here. For points with no row inside the data, write "fill": {"missing": 0}; past the data, write default(temp, 0) in the programAn
eodcell inside a fixed range, or anywhere but the last row of a line along a dimension declaredinf.From 0.26.0, a query that leaves out a dimension of its value (
grid[x = 0]for agridoverxandy) is refused, naming the dimension. Releases before 0.26.0 give eod at every point with a warning.
The Command reference gives every message.
#Summary
| kind | means | where it arises | in an aggregate | in a search | test with | fill with |
|---|---|---|---|---|---|---|
| eod | the point is outside the data | past the last row along inf; outside a bound or list; below 0; eod | the result is eod, unless skip eod | no candidate | iseod(x) | default(x, v) in the program |
| missing (an error) | a reading inside the data is not there | no row inside the data; an empty cell; "nothing here" | left out and counted; all missing: missing | a candidate only with a time; skip missing passes over it | iserror(x, "missing") | "fill" in deploy.json, or default(x, v, "missing") |
| other errors | something went wrong, at its origin | late, failed, division, non-finite, empty, assert, type, index, data, raised, version | the first in order is the result; if not iserror(x) after the region leaves them out | the candidate chosen gives it | iserror(x, "late"), … | default(x, v, "late"), … |
#How answers are written
The same triple, for doubled in the triple example, by elucid8 run as JSON lines:
{"name":"doubled","context":{"t":0},"outcome":{"kind":"value","value":8,"ts":1000}}
{"name":"doubled","context":{"t":1},"outcome":{"kind":"error","error":"missing","message":"input reading has no data at this point","origin":{"name":"reading","context":{"t":1}},"via":{"length":1,"path":[{"name":"reading","context":{"t":1}}]},"ts":2000}}
{"name":"doubled","context":{"t":5},"outcome":{"kind":"eod","ts":0}}
and as CSV, with --timestamps:
name,t,doubled_value,doubled_kind,doubled_message,doubled_ts
doubled,0,8,value,,1000
doubled,1,,error missing,input reading has no data at this point,2000
doubled,2,,error missing,input reading has no data at this point,0
doubled,3,12,value,,3000
doubled,4,4,value,,4000
doubled,5,,eod,,0
| written as | kind | error kind and origin | timestamp |
|---|---|---|---|
JSON lines (run, serve, the MCP tools' rows) | outcome.kind: value, eod or error | outcome.error, the error kind (missing, late, failed, division, non-finite, empty, assert, type, index, data, raised, version), with message; origin, the point where it started, as {"name", "context"} | ts, always written |
| CSV | <value>_kind: value, eod, or error and its kind (error missing); <value>_value holds data only | <value>_kind and <value>_message; <value>_origin with --triple | <value>_ts, with --timestamps |
| Arrow, Parquet, NumPy, Zarr, frames | <value>_kind: 0 data, 1 eod, 2 error | <value>_error, the error's record as JSON (error, message, origin, detail, via) | <value>_ts |
| the playground | the answer line: the value, eod, or Error via reading[t = 1]: … | in the words | timestamp … ms under the answer |
Output formats gives each format in full.