mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-12-03 07:55:25 +00:00
* feat(promql): read second, microsecond and nanosecond time indexes natively The native route declined every selector over a time index that is not in milliseconds. The existing plan wraps such a scan in a cast projection, so the decline surfaced as selector_plan_is_not_a_table_scan, and the region's raw series preflight refused the unit as well. The raw series path now hands ticks over in the stored unit, and each raw input of the native tree records that unit. Evaluation keeps the existing plan's semantics: windows and lookbacks are decided on the stored ticks, a kernel reads the time truncated toward zero to milliseconds after the offset, and samples less than a millisecond apart remain distinct samples. Since every bound is a whole millisecond, deciding membership on ceil(tick) in milliseconds is exact, so the evaluators keep a window time beside the payload only for microsecond and nanosecond inputs. Scan filters are built in the stored unit. Histogram fields and range modifiers over a sub-millisecond time index still decline. The append-mode decline is kept and renamed to append_mode_table. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): decline a discovered selector over mixed time index units Logical metrics on different physical tables can store their time index in different units, while the union a nameless selector reads is one native input bound to one unit. The union took the first source's unit and read the other sources' ticks in it, so a series stored in microseconds next to one in milliseconds dropped out of its windows. Such a selector now declines. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * feat(promql): run native PromQL over file-engine tables File-engine tables have no raw series scanner, so the native route declined them and they fell back to the legacy planner. Read such a table through a new RowSeriesSource node: an ordinary scan, filtered by the selector's matchers and time range, hash-partitioned by tags and sorted by (tags, time index, fields), then cut into explicit-label raw series chunks with Float64 values. The node declares its input distribution and ordering, so the physical optimizer inserts the repartition and a spillable SortExec. It stays above the merge scan, so it runs on the frontend in both standalone and distributed mode. Rows sharing labels and a timestamp keep one sample, as Prometheus storage does: the row whose field values sort lowest (nulls last). Non-string tags and histogram fields keep the existing plan. The cluster test builder can now pass the local file sandbox to datanodes and install frontend-only plugins, so the distributed case is covered. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * feat(promql): read file-engine tags as Prometheus label values A row source now reads every tag column as text with NULL read as '', so a NULL and an empty tag are one series from the start and an empty value carries no label, as in Prometheus. Rows of that series at one timestamp keep one sample by the existing rule. Matchers apply to the text form above the scan, so an integer tag matches "200" but not "0200". This drops the row_source_tag_is_not_a_string decline. The legacy planner fails on such a table with "Unsupported tag column type: Int64". Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * feat(promql): read native histogram fields from file-engine tables A row source passes a native histogram field on as histogram samples, converted with the same histogram_samples_from_arrow the mito raw scan uses, instead of casting every field to Float64. This drops the row_source_reads_floats_only decline, so the fixture of the sqlness case promql/delta_exponential_histogram runs natively; the integration test mirrors its statements and answers. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * feat(promql): read second-precision file-engine time indexes natively The existing scan plan already promotes a second-precision time index to milliseconds through a projection, which is exact. A row source now reads that projection instead of declining, and pushes the time range into the scan only when the scan's time index is in milliseconds. Microsecond and nanosecond time indexes still keep the existing plan. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): decline file-engine tables with a `__name__` tag column A row source dropped a tag column named `__name__` from its labels, sort key and partition key, so rows that differed only in that column merged into one series and lost samples. Mito's raw scan refuses such a tag. Decline it at planning time instead, and make RowSeriesSource reject the tag rather than filter it out. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): dedupe file-engine samples per field A row source reduced rows sharing labels and a timestamp to one whole row picked by the first field, so a NULL in another field of that row dropped the value a discarded row held there. Each field is its own value series: at a duplicated timestamp every field now keeps its own lowest non-null value (NaN above numbers, histograms by struct order). The sort key drops the fields, and the rows of the last timestamp of a batch are held back until the next batch, so every duplicated timestamp is reduced within one batch. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * feat(promql): read microsecond and nanosecond file-engine time indexes natively A row source read its time index through the existing plan's cast to milliseconds, which truncates a finer one, so it declined microsecond and nanosecond time indexes. It now reads the column as stored, as the raw series scan does, and the input it feeds is bound to the time index's unit. Evaluation then follows the rules mito tables already have: windows and lookbacks are decided on the stored ticks, a kernel reads the time truncated to milliseconds, and samples less than a millisecond apart stay distinct. Histogram fields and range modifiers over such a time index decline as they do for mito. The time range is pushed into the scan in the stored unit for pruning. A second-precision time index takes the same path. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): decline every table with a `__name__` tag column The native route names each series it reads by its table and has no label to read a tag column named `__name__` as. Only file-engine tables were declined; a mito table with such a column ran natively and lost the column: two series that differ only in it came back as two rows with one label set, and `sum by (__name__)` folded them into one. The existing plan reads the column's values as the metric name instead. Such a schema has no Prometheus reading: a series has one `__name__`, and the table name already is the metric name. Decline it on every engine so the statement keeps the existing plan's answer. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): keep a window open until its last millisecond has been read A sample finer than a millisecond is placed in the window ending at the millisecond above it. A chunk that ends on such a sample has not read the rest of that millisecond, so treating that millisecond as settled closed the window before a later sample in the same millisecond arrived in the next chunk. Settle only up to the millisecond the last sample lies in, rounded down. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): select only an exact sample under a zero lookback A zero lookback admits only a sample exactly at the instant. The window time of a sample less than a millisecond before the instant rounds up to the instant, so the native selection picked it where the existing route returns nothing. Compare the stored tick with the instant when the lookback is zero, on the grid and anchored paths. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test(promql): cover zero lookback on microsecond and nanosecond file-engine tables A zero lookback selects only a sample stored exactly at the instant. A row source hands its time index over as stored, so a sample 0.5ms before the instant shares that instant's window time and was selected. The exact-match rule from the time index precision branch covers the row source as well; these cases pin it for file-engine tables in both precisions and check that legacy gives the same answer. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test(promql): cover a stale marker in the second field of a wide file-engine table A Parquet file-engine table with a microsecond time index and two DOUBLE fields: a row whose first field is valid and whose second holds a stale marker is selected on both routes, and a row stale in the first field is dropped on both, as the existing plan reads staleness from the first field only. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> --------- Signed-off-by: Dennis Zhuang <killme2008@gmail.com>