The Markdown parser omits `TableCell` nodes for empty cells, so
`collectNodesOfType` returns fewer cells than columns.
The indexer mapped cells to headers by array index, causing all cells
after an empty one to shift left.
The HTML renderer already solved this: its `TableRow` case walks the
children and injects empty `TableCell` nodes between consecutive
`TableDelimiter` nodes with no cell in between.
This patch extracts that same normalization logic into a reusable
`normalizeTableRow` helper and applies it to each row before collecting
cells.
The original index-based cell-to-header mapping then works correctly
without any positional arithmetic. I feel like this is more elegant
solution to the issue.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
For example, with the following table:
```markdown
| a | b | c |
| --- | --- | --- |
| 1 | | 3 |
| 1 | 2 | 3 |
| a | b | c |
| a | b | |
| | b | c |
| x | | |
| | | z |
```
the following query results in dataset with shifted columns
when cells are empty:
```lua
from
index.tag 'table'
where
page == 'test'
order by
pos asc
select {
a, b, c
}
```
This is now fixed and gives correct results:
|0 |1 |2 |
|--|--|--|
|1 | |3 |
|1 |2 |3 |
|a |b |c |
|a |b | |
| |b |c |
|x | | |
| | |z |
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
Items from `index.tag` are stored as plain JS objects when no metatable
is defined. The `group by` clause wraps rows in `LuaTable` (`key`,
`group`) but leaves the individual `group` items as plain JS objects.
This causes `t.keys is not a function` errors when passing `row.group`
to APIs like `template.each` that expect `LuaTable` instances.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
Evaluate all `order by` expressions once per item in a decorate pass,
then compare cached keys during sort. Reduces Lua eval calls from
*O(kn log n)* to *O(kn)* where *k* is the number of sort keys.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
- Add iterative async stable merge sort (*O(n log n)*).
- Replace Quicksort with the new merge sort (kept Quicksort for tables).
- Update documentation (reorganize for logical flow, add SWO section
with invalid comparator example that really throws).
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* support for custom comparators in LIQ `order by` clauses via the
`using` keyword.
* `using` is mutually exclusive with `asc`/`desc` and accepts either
a *named function* or an *inline anonymous function*. The comparator
receives two values and returns true if the first should come before the
second.
* `nulls first`/ `nulls last` works independently of `using`.
* `using` is now a reserved keyword (`kw`; this cannot be avoided but
the chance to collide with user scripts is negligable),
* documentation updated + polished a little
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
Implements `filter(where <cond>)` for aggregate functions in LIQ
queries which allows per-row conditional filtering within grouped
aggregates. Also extends test suite and documentation.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
The new null-aware ordering in `orderByCompare` changed the default
placement of undefined values for descending sorts to `nulls first` (SQL
standard). This caused Space Lua scripts without a `-- priority:`
comment to load before the `Std` library scripts and breaking the boot
sequence for user scripts ran before `schema`, `config`, `widget` and
other core definitions were available.
Add explicit `nulls: "last"` to the reload query so scripts without
priority always load last, matching the documented behavior.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
Extend the `order by` clause with optional `nulls first` and `nulls
last` modifiers following standard SQL semantics. Each sort key can
independently specify where `nil` values should appear in the result. By
default, ascending sorts place nulls last and descending sorts place
nulls first. An explicit nulls first or nulls last overrides this
default. The `asc` keyword is also now accepted as an explicit
alternative to the default ascending direction. Documentation and tests
were updated accordingly.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>