Repository navigation
Commit 6a35df0
authored
fix(common-utils): honor open, exclusive and non-numeric range bounds (#2779)
## Summary
`SQLSerializer.range()` serializes every Lucene range as an inclusive `BETWEEN` over `parseFloat`'d bounds. Three documented range forms compile to SQL that ClickHouse rejects or silently answers wrong (checked on ClickHouse 26.7.1):
| Search | Compiles to | Result |
| :-- | :-- | :-- |
| `Duration:[* TO 500]` | `Duration BETWEEN '*' AND 500` | Code 53 `TYPE_MISMATCH: Cannot convert string '*' to type UInt64` |
| `Duration:{100 TO 500}` | `Duration BETWEEN 100 AND 500` | returns 100 and 500, which the user excluded |
| `Timestamp:[2024-01-01 TO 2024-06-01]` | `Timestamp BETWEEN 2024 AND 2024` | 0 rows |
Three causes: `*` is never recognised as an unbounded side; the ranged-term node's `inclusive` flag is never read, so `{}`, `[}` and `{]` all come out inclusive; and `Number.parseFloat('2024-01-01')` stops at the first `-`.
`range()` now takes `inclusive` from the node and picks `>`/`>=` and `<`/`<=` from it, drops a bound that is `*`, and falls back to `isNotNull()` when both sides are open — the same expression `field:*` already emits. `attemptToParseNumber` uses `Number()`, so a bound converts only when the whole string is numeric; a date bound reaches ClickHouse as a quoted string and is coerced to the column type. A closed inclusive range still emits `BETWEEN`, and every bound `parseFloat` consumed in full — `Infinity` and `1e400` included — converts to the same number it did before, so only the bounds it was truncating change. `EnglishSerializer.range` takes the same flag, so the search bar no longer describes an exclusive range as inclusive.
Tests: 17 cases in `queryParser.test.ts` — SQL for open, exclusive, half-open, negated, map-key and date ranges, plus the English explanation. 15 fail without the source change and pass with it; two pin the unchanged `[100 TO 500]` output. `packages/common-utils`: 1604 tests passing, `ci:lint` 0 errors and the warning count unchanged. (Two `packages/app` hook suites fail on my machine identically with and without this diff.)
The in-app syntax reference documents ranges as numeric, so if you'd rather they stay numeric-only, say the word and I'll drop the `parseFloat` half — the `*` and `{}` halves stand on their own.
### Screenshots or video
N/A — non-UI change.
### How to test on Vercel preview
N/A — non-UI change (`packages/common-utils` query compiler).
### References
- Linear Issue: N/A — external contribution, no Linear ticket
- Related PRs: none1 parent 16bdb40 commit 6a35df0
3 files changed
Lines changed: 193 additions & 6 deletions
File tree
- .changeset
- packages/common-utils/src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
665 | 665 | | |
666 | 666 | | |
667 | 667 | | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
668 | 798 | | |
669 | 799 | | |
670 | 800 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
197 | 198 | | |
198 | 199 | | |
199 | 200 | | |
| 201 | + | |
200 | 202 | | |
201 | 203 | | |
202 | 204 | | |
| |||
396 | 398 | | |
397 | 399 | | |
398 | 400 | | |
| 401 | + | |
| 402 | + | |
399 | 403 | | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
400 | 412 | | |
401 | 413 | | |
402 | | - | |
| 414 | + | |
403 | 415 | | |
404 | 416 | | |
405 | 417 | | |
| |||
685 | 697 | | |
686 | 698 | | |
687 | 699 | | |
688 | | - | |
| 700 | + | |
689 | 701 | | |
690 | 702 | | |
691 | 703 | | |
| |||
717 | 729 | | |
718 | 730 | | |
719 | 731 | | |
| 732 | + | |
720 | 733 | | |
721 | 734 | | |
722 | 735 | | |
| |||
732 | 745 | | |
733 | 746 | | |
734 | 747 | | |
735 | | - | |
736 | | - | |
737 | | - | |
738 | | - | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
739 | 783 | | |
740 | 784 | | |
741 | 785 | | |
| |||
1981 | 2025 | | |
1982 | 2026 | | |
1983 | 2027 | | |
| 2028 | + | |
1984 | 2029 | | |
1985 | 2030 | | |
1986 | 2031 | | |
| |||
0 commit comments