@thi.ng/column-store 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +428 -0
- package/api.d.ts +101 -0
- package/api.js +18 -0
- package/bitmap.d.ts +35 -0
- package/bitmap.js +104 -0
- package/columns/acolumn.d.ts +19 -0
- package/columns/acolumn.js +55 -0
- package/columns/array.d.ts +19 -0
- package/columns/array.js +62 -0
- package/columns/dict-array.d.ts +25 -0
- package/columns/dict-array.js +79 -0
- package/columns/dict.d.ts +25 -0
- package/columns/dict.js +82 -0
- package/columns/plain.d.ts +17 -0
- package/columns/plain.js +42 -0
- package/columns/typedarray.d.ts +22 -0
- package/columns/typedarray.js +84 -0
- package/index.d.ts +5 -0
- package/index.js +4 -0
- package/internal/checks.d.ts +8 -0
- package/internal/checks.js +15 -0
- package/internal/replace.d.ts +5 -0
- package/internal/replace.js +16 -0
- package/internal/serialize.d.ts +7 -0
- package/internal/serialize.js +8 -0
- package/package.json +127 -0
- package/query.d.ts +43 -0
- package/query.js +271 -0
- package/table.d.ts +51 -0
- package/table.js +176 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
<!-- This file is generated - DO NOT EDIT! -->
|
|
2
|
+
<!-- Please see: https://github.com/thi-ng/umbrella/blob/develop/CONTRIBUTING.md#changes-to-readme-files -->
|
|
3
|
+
# 
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@thi.ng/column-store)
|
|
6
|
+

|
|
7
|
+
[](https://mastodon.thi.ng/@toxi)
|
|
8
|
+
|
|
9
|
+
> [!NOTE]
|
|
10
|
+
> This is one of 214 standalone projects, maintained as part
|
|
11
|
+
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
|
+
> and anti-framework.
|
|
13
|
+
>
|
|
14
|
+
> 🚀 Please help me to work full-time on these projects by [sponsoring me on
|
|
15
|
+
> GitHub](https://github.com/sponsors/postspectacular). Thank you! ❤️
|
|
16
|
+
|
|
17
|
+
- [About](#about)
|
|
18
|
+
- [Column storage](#column-storage)
|
|
19
|
+
- [Column types](#column-types)
|
|
20
|
+
- [Custom column types](#custom-column-types)
|
|
21
|
+
- [Cardinality](#cardinality)
|
|
22
|
+
- [Default values](#default-values)
|
|
23
|
+
- [Flags](#flags)
|
|
24
|
+
- [FLAG_BITMAP](#flag_bitmap)
|
|
25
|
+
- [FLAG_DICT](#flag_dict)
|
|
26
|
+
- [FLAG_UNIQUE](#flag_unique)
|
|
27
|
+
- [FLAG_RLE](#flag_rle)
|
|
28
|
+
- [Custom flags](#custom-flags)
|
|
29
|
+
- [Query engine](#query-engine)
|
|
30
|
+
- [Built-in operators](#built-in-operators)
|
|
31
|
+
- [OR](#or)
|
|
32
|
+
- [AND](#and)
|
|
33
|
+
- [Negation](#negation)
|
|
34
|
+
- [Predicate-based matchers](#predicate-based-matchers)
|
|
35
|
+
- [Custom operators](#custom-operators)
|
|
36
|
+
- [Result aggregation](#result-aggregation)
|
|
37
|
+
- [Query ranges](#query-ranges)
|
|
38
|
+
- [Status](#status)
|
|
39
|
+
- [Installation](#installation)
|
|
40
|
+
- [Dependencies](#dependencies)
|
|
41
|
+
- [API](#api)
|
|
42
|
+
- [Basic usage](#basic-usage)
|
|
43
|
+
- [Authors](#authors)
|
|
44
|
+
- [License](#license)
|
|
45
|
+
|
|
46
|
+
## About
|
|
47
|
+
|
|
48
|
+
In-memory column store database with customizable column types, extensible query engine, bitfield indexing for query acceleration, JSON serialization with optional RLE compression.
|
|
49
|
+
|
|
50
|
+
## Column storage
|
|
51
|
+
|
|
52
|
+
### Column types
|
|
53
|
+
|
|
54
|
+
The current built-in column types only support numeric or string values, though
|
|
55
|
+
support for other JSON-serializable types is planned. For better memory
|
|
56
|
+
utilization, numeric data can (and should) be stored in typed array columns.
|
|
57
|
+
|
|
58
|
+
Some column types support storing multiple values per row as tuples. See
|
|
59
|
+
[cardinality section](#cardinality) below for further detail.
|
|
60
|
+
|
|
61
|
+
Note: Booleans and `BigInt`s are still unsupported, but being worked on...
|
|
62
|
+
|
|
63
|
+
| **Column type** | **Description** | **Tuples supported** | **RLE serialization** |
|
|
64
|
+
|-----------------|---------------------|----------------------|-----------------------|
|
|
65
|
+
| `num` | JS numbers | ✅ | ✅ <sup>(1)</sup> |
|
|
66
|
+
| `str` | JS strings (UTF-16) | ✅ | ✅ <sup>(1)</sup> |
|
|
67
|
+
| `u8` | 8bit unsigned int | ❌ | ✅ |
|
|
68
|
+
| `i8` | 8bit signed int | ❌ | ✅ |
|
|
69
|
+
| `u16` | 16bit unsigned int | ❌ | ✅ |
|
|
70
|
+
| `i16` | 16bit signed int | ❌ | ✅ |
|
|
71
|
+
| `u32` | 32bit unsigned int | ❌ | ✅ |
|
|
72
|
+
| `i32` | 32bit signed int | ❌ | ✅ |
|
|
73
|
+
| `f32` | 32bit float | ❌ | ❌ |
|
|
74
|
+
| `f64` | 64bit float | ❌ | ❌ |
|
|
75
|
+
|
|
76
|
+
- <sup>(1)</sup> only if `FLAG_DICT` is enabled, [further information](#flag_rle)
|
|
77
|
+
|
|
78
|
+
### Custom column types
|
|
79
|
+
|
|
80
|
+
The system already supports custom column type implementations via the
|
|
81
|
+
[`IColumn`](https://docs.thi.ng/umbrella/column-store/interfaces/IColumn.html)
|
|
82
|
+
and
|
|
83
|
+
[`ColumnTypeSpec`](https://docs.thi.ng/umbrella/column-store/interfaces/ColumnTypeSpec.html)
|
|
84
|
+
interfaces.
|
|
85
|
+
|
|
86
|
+
Custom column types and their implementations can be registered via
|
|
87
|
+
[`registerColumnType()`](https://docs.thi.ng/umbrella/column-store/functions/registerColumnType.html).
|
|
88
|
+
|
|
89
|
+
### Cardinality
|
|
90
|
+
|
|
91
|
+
Columns can store zero, one or tuples of multiple values per row. Acceptable
|
|
92
|
+
min/max ranges can be defined via the
|
|
93
|
+
[`cardinality`](https://docs.thi.ng/umbrella/column-store/interfaces/ColumnSpec.html#cardinality)
|
|
94
|
+
key of the column spec. The following presets are provided:
|
|
95
|
+
|
|
96
|
+
| **Preset** | **Value** | **Description** |
|
|
97
|
+
|-------------|------------------|---------------------------------------------|
|
|
98
|
+
| `REQUIRED` | `[1, 1]` | Required single value (default) |
|
|
99
|
+
| `OPTIONAL` | `[0, 1]` | Optional single value (present or not) |
|
|
100
|
+
| `ONE_PLUS` | `[1, (2**32)-1]` | One or more values (always expects tuples) |
|
|
101
|
+
| `ZERO_PLUS` | `[0, (2**32)-1]` | Zero or more values (always expects tuples) |
|
|
102
|
+
|
|
103
|
+
### Default values
|
|
104
|
+
|
|
105
|
+
Default values can be specified for columns with a minimum cardinality of 1 or
|
|
106
|
+
more (aka required values). When a row is added or updated, any `null`ish values
|
|
107
|
+
for such columns in the row record will then be replaced with their default
|
|
108
|
+
values. If a column with required values has no configured default value, an
|
|
109
|
+
error will be thrown when attempting to add/update an incomplete record.
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
// example column spec with default value
|
|
113
|
+
{
|
|
114
|
+
type: "str",
|
|
115
|
+
cardinality: [1, 1],
|
|
116
|
+
default: "todo",
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**Note:** Typed array backed columns **do no** support optional values and
|
|
121
|
+
therefore require either a cardinality of `[1,1]` or `[0,1]` with a default.
|
|
122
|
+
|
|
123
|
+
### Flags
|
|
124
|
+
|
|
125
|
+
Generally applicable to all column types, the following numeric flags can be
|
|
126
|
+
assigned and combined (into bitmasks) to customize the storage & indexing
|
|
127
|
+
behavior.
|
|
128
|
+
|
|
129
|
+
#### FLAG_BITMAP
|
|
130
|
+
|
|
131
|
+
(Value: 0x01)
|
|
132
|
+
|
|
133
|
+
The column will construct & maintain additional bitfields for each unique value
|
|
134
|
+
stored in the column. These bitfields record which values are stored in which
|
|
135
|
+
rows and are utilized by the [query engine](#query-engine) to massively
|
|
136
|
+
accelerate complex searches.
|
|
137
|
+
|
|
138
|
+
#### FLAG_DICT
|
|
139
|
+
|
|
140
|
+
(Value: 0x02)
|
|
141
|
+
|
|
142
|
+
Dictionary encoded storage. Recommended for (non-numeric) data with a relatively
|
|
143
|
+
small (though not necessarily fixed) set of possible values. Instead of storing
|
|
144
|
+
values directly, only numeric IDs will be stored. The original (de-duplicated)
|
|
145
|
+
values are stored in a dictionary alongside the column data.
|
|
146
|
+
|
|
147
|
+
Note: Not supported by typedarray-backed column types.
|
|
148
|
+
|
|
149
|
+
#### FLAG_UNIQUE
|
|
150
|
+
|
|
151
|
+
(Value: 0x04)
|
|
152
|
+
|
|
153
|
+
Only applicable for tuple-based columns to enforce Set-like semantics (per row),
|
|
154
|
+
i.e. values of each tuple will be deduplicated (e.g. for tagging).
|
|
155
|
+
|
|
156
|
+
Note: Not supported by typedarray-backed column types.
|
|
157
|
+
|
|
158
|
+
#### FLAG_RLE
|
|
159
|
+
|
|
160
|
+
(Value: 0x08)
|
|
161
|
+
|
|
162
|
+
This flag enables bitwise [Run-length encoding](https://thi.ng/rle-pack) in the
|
|
163
|
+
JSON serialization of a column, potentially leading to dramatic file size
|
|
164
|
+
savings, esp. for dictionary-based data.
|
|
165
|
+
|
|
166
|
+
Only applicable to these column types & configurations:
|
|
167
|
+
|
|
168
|
+
- typedarray-based integer columns (see [table](#column-types))
|
|
169
|
+
- dictionary-based single value columns (if the min. cardinality is zero, a
|
|
170
|
+
default value **must** be supplied)
|
|
171
|
+
|
|
172
|
+
#### Custom flags
|
|
173
|
+
|
|
174
|
+
The lower 16bit of the 32bit `flags` integer are reserved for built-ins and
|
|
175
|
+
future extension of this package. However, the upper 16 bits can be freely used
|
|
176
|
+
for custom flags, i.e. in conjunction with [custom column
|
|
177
|
+
types](#custom-column-types).
|
|
178
|
+
|
|
179
|
+
## Query engine
|
|
180
|
+
|
|
181
|
+
The query engine is highly extensible and can be used for executing arbitrarily
|
|
182
|
+
complex queries.
|
|
183
|
+
|
|
184
|
+
The system allows predefining queries, which are then only evaluated and produce
|
|
185
|
+
up-to-date results via the standard JS iterable mechanism (i.e. queries
|
|
186
|
+
implement `[Symbol.iterator]`).
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
// predefine query
|
|
190
|
+
const query = table.query().or("name", ["alice", "bob"]);
|
|
191
|
+
|
|
192
|
+
// actually (re)execute query
|
|
193
|
+
for(let result of query) { ... }
|
|
194
|
+
|
|
195
|
+
// ..or using slice operator
|
|
196
|
+
const results = [...query];
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
TODO see code examples below
|
|
200
|
+
|
|
201
|
+
### Built-in operators
|
|
202
|
+
|
|
203
|
+
The query engine works by applying a number of [query
|
|
204
|
+
terms](https://docs.thi.ng/umbrella/column-store/interfaces/QueryTerm.html) in
|
|
205
|
+
series, with each step intersecting its results with the results of the previous
|
|
206
|
+
step(s), thereby narrowing down the result set.
|
|
207
|
+
|
|
208
|
+
By default, individual query terms operate on a single column, but can also can
|
|
209
|
+
also apply to multiple. Terms are supplied either as array given to the
|
|
210
|
+
[`Query`](https://docs.thi.ng/umbrella/column-store/classes/Query.html)
|
|
211
|
+
constructor, via the fluent API of the `Query` class and/or via
|
|
212
|
+
[`.addTerm()`](https://docs.thi.ng/umbrella/column-store/classes/Query.html#addterm).
|
|
213
|
+
|
|
214
|
+
#### OR
|
|
215
|
+
|
|
216
|
+
Optionally optimized via [`FLAG_BITMAP`](#flag_bitmap) presence on column. One
|
|
217
|
+
or more values can be provided.
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
query.or("column-name", "option");
|
|
221
|
+
|
|
222
|
+
query.or("column-name", ["option1", "option2",...]);
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
#### AND
|
|
226
|
+
|
|
227
|
+
Optionally optimized via [`FLAG_BITMAP`](#flag_bitmap) presence on column. One
|
|
228
|
+
or more values can be provided.
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
query.and("column-name", "option");
|
|
232
|
+
|
|
233
|
+
query.and("column-name", ["option1", "option2",...]);
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
#### Negation
|
|
237
|
+
|
|
238
|
+
Optionally optimized via [`FLAG_BITMAP`](#flag_bitmap) presence on column.
|
|
239
|
+
Negation is available via `nand` & `nor`. For negation of single values either
|
|
240
|
+
can be used, otherwise the behavior is:
|
|
241
|
+
|
|
242
|
+
- [`nand`](https://docs.thi.ng/umbrella/column-store/classes/Query.html#nand):
|
|
243
|
+
select rows same as [`and`](#and), then negate results
|
|
244
|
+
- [`nor`](https://docs.thi.ng/umbrella/column-store/classes/Query.html#nor):
|
|
245
|
+
select rows same as [`or`](#or), then negate results
|
|
246
|
+
|
|
247
|
+
#### Predicate-based matchers
|
|
248
|
+
|
|
249
|
+
- [`matchColumn`](https://docs.thi.ng/umbrella/column-store/classes/Query.html#matchcolumn):
|
|
250
|
+
apply predicate to column value
|
|
251
|
+
- [`matchRow`](https://docs.thi.ng/umbrella/column-store/classes/Query.html#matchrow):
|
|
252
|
+
apply predicate to full row
|
|
253
|
+
- [`matchPartialRow`](https://docs.thi.ng/umbrella/column-store/classes/Query.html#matchpartialrow):
|
|
254
|
+
apply predicate to partial row (only selected columns)
|
|
255
|
+
|
|
256
|
+
### Custom operators
|
|
257
|
+
|
|
258
|
+
Custom query operators can be registered via
|
|
259
|
+
[`registerQueryOp()`](https://docs.thi.ng/umbrella/column-store/functions/registerQueryOp.html).
|
|
260
|
+
|
|
261
|
+
### Result aggregation
|
|
262
|
+
|
|
263
|
+
TODO
|
|
264
|
+
|
|
265
|
+
### Query ranges
|
|
266
|
+
|
|
267
|
+
TODO
|
|
268
|
+
|
|
269
|
+
## Status
|
|
270
|
+
|
|
271
|
+
**ALPHA** - bleeding edge / work-in-progress
|
|
272
|
+
|
|
273
|
+
[Search or submit any issues for this package](https://github.com/thi-ng/umbrella/issues?q=%5Bcolumn-store%5D+in%3Atitle)
|
|
274
|
+
|
|
275
|
+
## Installation
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
yarn add @thi.ng/column-store
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
ESM import:
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
import * as cs from "@thi.ng/column-store";
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Browser ESM import:
|
|
288
|
+
|
|
289
|
+
```html
|
|
290
|
+
<script type="module" src="https://esm.run/@thi.ng/column-store"></script>
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
[JSDelivr documentation](https://www.jsdelivr.com/)
|
|
294
|
+
|
|
295
|
+
For Node.js REPL:
|
|
296
|
+
|
|
297
|
+
```js
|
|
298
|
+
const cs = await import("@thi.ng/column-store");
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 4.11 KB
|
|
302
|
+
|
|
303
|
+
## Dependencies
|
|
304
|
+
|
|
305
|
+
- [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
|
|
306
|
+
- [@thi.ng/bidir-index](https://github.com/thi-ng/umbrella/tree/develop/packages/bidir-index)
|
|
307
|
+
- [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
|
|
308
|
+
- [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
|
|
309
|
+
- [@thi.ng/rle-pack](https://github.com/thi-ng/umbrella/tree/develop/packages/rle-pack)
|
|
310
|
+
|
|
311
|
+
Note: @thi.ng/api is in _most_ cases a type-only import (not used at runtime)
|
|
312
|
+
|
|
313
|
+
## API
|
|
314
|
+
|
|
315
|
+
[Generated API docs](https://docs.thi.ng/umbrella/column-store/)
|
|
316
|
+
|
|
317
|
+
### Basic usage
|
|
318
|
+
|
|
319
|
+
```ts tangle:export/readme-1.ts
|
|
320
|
+
import {
|
|
321
|
+
Table,
|
|
322
|
+
FLAG_BITMAP,
|
|
323
|
+
FLAG_DICT,
|
|
324
|
+
FLAG_UNIQUE,
|
|
325
|
+
} from "@thi.ng/column-store";
|
|
326
|
+
|
|
327
|
+
const table = new Table({
|
|
328
|
+
// ID column stores 8bit ints (typed array)
|
|
329
|
+
id: { type: "u8" },
|
|
330
|
+
// Type column stores indexed strings
|
|
331
|
+
type: { type: "str", flags: FLAG_DICT },
|
|
332
|
+
// Tags column stores array of strings (max. 10) with set-semantics
|
|
333
|
+
// and bitmap optimized for query acceleration
|
|
334
|
+
tags: {
|
|
335
|
+
type: "str",
|
|
336
|
+
// min/max number of values per row (default is: [1,1])
|
|
337
|
+
cardinality: [0, 10],
|
|
338
|
+
// flag to define column behavior (flags explained above)
|
|
339
|
+
flags: FLAG_DICT | FLAG_UNIQUE | FLAG_BITMAP,
|
|
340
|
+
// default value(s) assigned if missing when row is added
|
|
341
|
+
default: ["unsorted"],
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
// add data/rows
|
|
346
|
+
table.addRows([
|
|
347
|
+
{ id: 100, type: "img", tags: ["a", "a", "c", "b"] },
|
|
348
|
+
{ id: 101, type: "video", tags: ["a", "d", "b"] },
|
|
349
|
+
{ id: 102, type: "img" },
|
|
350
|
+
{ id: 103, type: "video" },
|
|
351
|
+
{ id: 104, type: "img", tags: ["b", "c", "d"] },
|
|
352
|
+
]);
|
|
353
|
+
|
|
354
|
+
// pre-define a query, here to select images which have an `unsorted` tag...
|
|
355
|
+
// the fluent API shown is merely syntax sugar for creating/appending query terms.
|
|
356
|
+
// queries can have an arbitrary number of terms (which are executed in series)
|
|
357
|
+
const unsortedImages = table.query().where("type", "img").and("tags", "unsorted");
|
|
358
|
+
|
|
359
|
+
// queries are iterables and only execute when the iterator is consumed
|
|
360
|
+
console.log([...unsortedImages]);
|
|
361
|
+
// [ { id: 102, type: "img", tags: [ "unsorted" ] } ]
|
|
362
|
+
|
|
363
|
+
// select items with `a` OR `b` tags, intersect with those which have `c` AND `d` tags
|
|
364
|
+
const complexTagQuery = table.query().or("tags", ["a", "b"]).and("tags", ["c", "d"]);
|
|
365
|
+
console.log([...complexTagQuery]);
|
|
366
|
+
// [ { id: 104, type: "img", tags: [ "b", "c", "d" ] } ]
|
|
367
|
+
|
|
368
|
+
// query using custom predicates
|
|
369
|
+
console.log([...table.query().matchColumn("id", (id) => id > 102)]);
|
|
370
|
+
// [
|
|
371
|
+
// { id: 103, type: "img", tags: [ "unsorted" ] },
|
|
372
|
+
// { id: 104, type: "img", tags: [ "b", "c", "d" ] }
|
|
373
|
+
// ]
|
|
374
|
+
|
|
375
|
+
// serialize table to JSON
|
|
376
|
+
console.log(JSON.stringify(table, null, "\t"));
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
Serialized table (can be loaded again via `Table.load()`):
|
|
380
|
+
|
|
381
|
+
```json
|
|
382
|
+
{
|
|
383
|
+
"schema": {
|
|
384
|
+
"id": { "cardinality": [1, 1], "flags": 0, "type": "u8" },
|
|
385
|
+
"type": { "cardinality": [1, 1], "flags": 1, "type": "str" },
|
|
386
|
+
"tags": { "cardinality": [0, 10], "flags": 7, "type": "str", "default": ["unsorted"] }
|
|
387
|
+
},
|
|
388
|
+
"columns": {
|
|
389
|
+
"id": {
|
|
390
|
+
"values": [100, 101, 102, 103, 104]
|
|
391
|
+
},
|
|
392
|
+
"type": {
|
|
393
|
+
"dict": {
|
|
394
|
+
"index": ["img", "video"],
|
|
395
|
+
"next": 2
|
|
396
|
+
},
|
|
397
|
+
"values": [0, 1, 0, 1, 0]
|
|
398
|
+
},
|
|
399
|
+
"tags": {
|
|
400
|
+
"dict": {
|
|
401
|
+
"index": ["a", "c", "b", "d", "unsorted"],
|
|
402
|
+
"next": 5
|
|
403
|
+
},
|
|
404
|
+
"values": [[0, 1, 2], [0, 3, 2], [4], [4], [2, 1, 3]]
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
"length": 5
|
|
408
|
+
}
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
## Authors
|
|
412
|
+
|
|
413
|
+
- [Karsten Schmidt](https://thi.ng)
|
|
414
|
+
|
|
415
|
+
If this project contributes to an academic publication, please cite it as:
|
|
416
|
+
|
|
417
|
+
```bibtex
|
|
418
|
+
@misc{thing-column-store,
|
|
419
|
+
title = "@thi.ng/column-store",
|
|
420
|
+
author = "Karsten Schmidt",
|
|
421
|
+
note = "https://thi.ng/column-store",
|
|
422
|
+
year = 2025
|
|
423
|
+
}
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
## License
|
|
427
|
+
|
|
428
|
+
© 2025 - 2026 Karsten Schmidt // Apache License 2.0
|