rida-format 0.2.0__tar.gz → 0.3.0__tar.gz
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.
- {rida_format-0.2.0 → rida_format-0.3.0}/CHANGELOG.md +65 -0
- {rida_format-0.2.0/src/rida_format.egg-info → rida_format-0.3.0}/PKG-INFO +79 -21
- {rida_format-0.2.0 → rida_format-0.3.0}/RIDA-FORMAT.md +22 -1
- {rida_format-0.2.0 → rida_format-0.3.0}/RIDA-README.md +78 -20
- {rida_format-0.2.0 → rida_format-0.3.0}/docs/rida-metadata.html +0 -4
- {rida_format-0.2.0 → rida_format-0.3.0}/pyproject.toml +1 -1
- {rida_format-0.2.0 → rida_format-0.3.0}/src/rida/__init__.py +323 -22
- {rida_format-0.2.0 → rida_format-0.3.0/src/rida_format.egg-info}/PKG-INFO +79 -21
- {rida_format-0.2.0 → rida_format-0.3.0}/tests/fixture_spec.py +4 -2
- {rida_format-0.2.0 → rida_format-0.3.0}/tests/test_rida.py +306 -36
- {rida_format-0.2.0 → rida_format-0.3.0}/LICENSE +0 -0
- {rida_format-0.2.0 → rida_format-0.3.0}/MANIFEST.in +0 -0
- {rida_format-0.2.0 → rida_format-0.3.0}/setup.cfg +0 -0
- {rida_format-0.2.0 → rida_format-0.3.0}/src/rida/__main__.py +0 -0
- {rida_format-0.2.0 → rida_format-0.3.0}/src/rida_format.egg-info/SOURCES.txt +0 -0
- {rida_format-0.2.0 → rida_format-0.3.0}/src/rida_format.egg-info/dependency_links.txt +0 -0
- {rida_format-0.2.0 → rida_format-0.3.0}/src/rida_format.egg-info/entry_points.txt +0 -0
- {rida_format-0.2.0 → rida_format-0.3.0}/src/rida_format.egg-info/top_level.txt +0 -0
- {rida_format-0.2.0 → rida_format-0.3.0}/tests/fixtures/golden-source-dictionary.json +0 -0
- {rida_format-0.2.0 → rida_format-0.3.0}/tests/fixtures/golden-source-sequential.json +0 -0
- {rida_format-0.2.0 → rida_format-0.3.0}/tests/fixtures/golden-v1-dictionary-dense.rida +0 -0
- {rida_format-0.2.0 → rida_format-0.3.0}/tests/fixtures/golden-v1-dictionary-sparse.rida +0 -0
- {rida_format-0.2.0 → rida_format-0.3.0}/tests/fixtures/golden-v1-sequential-dense.rida +0 -0
- {rida_format-0.2.0 → rida_format-0.3.0}/tests/fixtures/golden-v1-sequential-sparse.rida +0 -0
- {rida_format-0.2.0 → rida_format-0.3.0}/tests/make_fixtures.py +0 -0
|
@@ -2,6 +2,71 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to the RIDA library and container format.
|
|
4
4
|
|
|
5
|
+
## 0.3.0
|
|
6
|
+
|
|
7
|
+
No file-format change: 0.3.0 reads every file 0.1.1 could read, and still writes
|
|
8
|
+
the same catalog and data bytes. One metadata key was removed (see below).
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
* `get_many(record_id, fields)` and `get_record(record_id)` on both readers.
|
|
13
|
+
A record's values sit next to each other in the data region, so nearby fields
|
|
14
|
+
are fetched in **one** range request. Since a CDN request costs about 660 bytes
|
|
15
|
+
of response headers (measured against Bunny), merging fields is a big win for
|
|
16
|
+
multi-field reads: a whole 34-field record is one request instead of 34.
|
|
17
|
+
* `MERGE_GAP_LIMIT` (660 bytes) — two fields are merged into one request when the
|
|
18
|
+
bytes between them cost less than the request header they save.
|
|
19
|
+
* `rida fields <file-or-url>` prints the field names a file stores, so a caller
|
|
20
|
+
knows which key to ask for. `--json` prints just the array.
|
|
21
|
+
* `rida.open_reader(target)` opens a local path or an http(s) URL.
|
|
22
|
+
* 13 new tests, including merge/no-merge request counting over a real range server.
|
|
23
|
+
|
|
24
|
+
### Removed
|
|
25
|
+
|
|
26
|
+
* **`reader_url` — breaking change.** Gone from the CLI (`--reader-url`), from
|
|
27
|
+
`build()`, and from the metadata written into new files. It pointed at an
|
|
28
|
+
end-user app that does not exist, while RIDA's audience reads the file with its
|
|
29
|
+
own code. Metadata is additive, so files from 0.1.x and 0.2.x still open
|
|
30
|
+
normally and simply carry an extra key that readers ignore.
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
|
|
34
|
+
* `docs/rida-metadata.html` no longer builds a download link from metadata.
|
|
35
|
+
* The RIDA 1 compatibility test now compares the catalog and the data region byte
|
|
36
|
+
for byte (both still identical) and asserts that metadata differs only by the
|
|
37
|
+
removed key.
|
|
38
|
+
|
|
39
|
+
## 0.2.1
|
|
40
|
+
|
|
41
|
+
No file-format change: 0.2.1 reads and writes exactly what 0.2.0 did, and files
|
|
42
|
+
from 0.1.1 onwards stay readable.
|
|
43
|
+
|
|
44
|
+
### Fixed
|
|
45
|
+
|
|
46
|
+
* **Remote reads no longer open a fresh connection for every range request.**
|
|
47
|
+
`RemoteRidaFile` now keeps one HTTP(S) connection per calling thread and
|
|
48
|
+
reuses it, which removes a full TLS handshake from every lookup. Measured
|
|
49
|
+
against Bunny CDN on the 27,647-record Musnad Ahmed file, average lookup time
|
|
50
|
+
fell from **89.0 ms to 25.9 ms** (median 76.9 ms to 20.9 ms). The 0.2.0
|
|
51
|
+
behaviour is still available with `keepalive=False` or `--no-keepalive`.
|
|
52
|
+
|
|
53
|
+
### Added
|
|
54
|
+
|
|
55
|
+
* `RemoteRidaFile` is now a context manager and has `close()`. Closing only drops
|
|
56
|
+
the sockets; a later read opens a new one.
|
|
57
|
+
* `RemoteRidaFile(keepalive=False)` and `rida remote-get --no-keepalive`.
|
|
58
|
+
* Seven new tests, and the test range server now speaks HTTP/1.1 so connection
|
|
59
|
+
reuse is covered: reuse, reconnect after a dropped socket, redirect fallback,
|
|
60
|
+
thread sharing, context-manager use, `keepalive=False`, and non-HTTP URLs.
|
|
61
|
+
|
|
62
|
+
### Changed
|
|
63
|
+
|
|
64
|
+
* Before reusing an idle connection, RIDA checks the socket and reconnects when
|
|
65
|
+
the server has already closed it, so a dead keep-alive socket cannot waste a
|
|
66
|
+
round trip.
|
|
67
|
+
* A server that answers with a redirect hands that request back to `urllib`, so
|
|
68
|
+
redirecting URLs keep working instead of failing on the raw connection path.
|
|
69
|
+
|
|
5
70
|
## 0.2.0
|
|
6
71
|
|
|
7
72
|
### Format
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rida-format
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Range Indexed Data Access (RIDA) static data format and library
|
|
5
5
|
Author: Syed Ali Hamza Chishty
|
|
6
6
|
Maintainer-email: Qasra Foundation <admin@qasra.org>
|
|
@@ -21,7 +21,7 @@ Description-Content-Type: text/markdown
|
|
|
21
21
|
License-File: LICENSE
|
|
22
22
|
Dynamic: license-file
|
|
23
23
|
|
|
24
|
-
# RIDA Python library — 0.
|
|
24
|
+
# RIDA Python library — 0.3.0
|
|
25
25
|
|
|
26
26
|
RIDA means **Range Indexed Data Access**. It is an installable Python library
|
|
27
27
|
and terminal tool that builds one `.rida` file from a collection of JSON
|
|
@@ -35,7 +35,7 @@ records. The file contains:
|
|
|
35
35
|
The reader loads the catalog once and then reads only the requested field bytes.
|
|
36
36
|
It works locally and over an HTTP server that supports byte-range requests.
|
|
37
37
|
|
|
38
|
-
RIDA 0.
|
|
38
|
+
RIDA 0.3.0 writes the **RIDA 2** layout by default: every stored field value is
|
|
39
39
|
its own gzip member. A reader still fetches exactly one value range, then
|
|
40
40
|
inflates that one member. On a 27,647-record, 34-field hadith dataset the data
|
|
41
41
|
region drops from 191,378,148 to 110,924,973 bytes, and the average stored value
|
|
@@ -127,7 +127,6 @@ Build a RIDA file. The command asks for confirmation unless `--yes` is supplied:
|
|
|
127
127
|
rida build users.json users.rida \
|
|
128
128
|
--title "Users dataset" \
|
|
129
129
|
--description "Public sample data" \
|
|
130
|
-
--reader-url "https://example.com/rida-explorer" \
|
|
131
130
|
--yes
|
|
132
131
|
```
|
|
133
132
|
|
|
@@ -229,6 +228,7 @@ rida build "/path/to/musnad-ahmed" musnad-ahmed.rida \
|
|
|
229
228
|
|
|
230
229
|
```sh
|
|
231
230
|
rida inspect users.rida
|
|
231
|
+
rida fields users.rida
|
|
232
232
|
rida get users.rida ali city
|
|
233
233
|
```
|
|
234
234
|
|
|
@@ -236,6 +236,21 @@ rida get users.rida ali city
|
|
|
236
236
|
value and exits with status 1 and a one-line message if the record ID or field
|
|
237
237
|
name does not exist.
|
|
238
238
|
|
|
239
|
+
`fields` answers "which key do I ask for?" — the field names live inside the file,
|
|
240
|
+
so nothing has to be guessed or documented separately:
|
|
241
|
+
|
|
242
|
+
```text
|
|
243
|
+
$ rida fields users.rida
|
|
244
|
+
Records: 27,647
|
|
245
|
+
Fields: 34
|
|
246
|
+
1 hadith_id
|
|
247
|
+
2 book
|
|
248
|
+
3 chapter_id
|
|
249
|
+
...
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
It also accepts an http(s) URL, and `--json` prints just the array.
|
|
253
|
+
|
|
239
254
|
## Check a file for damage
|
|
240
255
|
|
|
241
256
|
Reading one field never hashes the whole data region, so a normal lookup trusts
|
|
@@ -266,7 +281,7 @@ rida verify users.rida
|
|
|
266
281
|
|
|
267
282
|
## Where RIDA can read data
|
|
268
283
|
|
|
269
|
-
RIDA 0.
|
|
284
|
+
RIDA 0.3.0 can read a `.rida` file from the local computer or from a direct
|
|
270
285
|
HTTP/HTTPS file URL. For remote reads, RIDA sends ordinary HTTP byte-range
|
|
271
286
|
requests; it does not use a cloud-provider SDK. This makes it compatible with
|
|
272
287
|
object storage that returns the requested bytes as HTTP `206 Partial Content`
|
|
@@ -334,6 +349,41 @@ own cache entry automatically, because the header no longer matches.
|
|
|
334
349
|
|
|
335
350
|
Network reads fail after `--timeout` seconds (default 30) instead of hanging.
|
|
336
351
|
|
|
352
|
+
### Connection reuse
|
|
353
|
+
|
|
354
|
+
A range request sent over a fresh TLS connection pays a full handshake, which on
|
|
355
|
+
a CDN costs several times more than the lookup itself. The remote reader
|
|
356
|
+
therefore keeps one HTTP(S) connection open per reading thread and reuses it, so
|
|
357
|
+
a warm lookup spends its time on the value, not on the handshake.
|
|
358
|
+
|
|
359
|
+
Measured against Bunny CDN on the 27,647-record Musnad Ahmed file:
|
|
360
|
+
|
|
361
|
+
| | average | median |
|
|
362
|
+
| --- | ---: | ---: |
|
|
363
|
+
| 0.2.1 with connection reuse (default) | **25.9 ms** | 20.9 ms |
|
|
364
|
+
| 0.2.0, fresh connection per lookup | 89.0 ms | 76.9 ms |
|
|
365
|
+
|
|
366
|
+
Use `--no-keepalive`, or `keepalive=False` in Python, to get the old behaviour.
|
|
367
|
+
|
|
368
|
+
### Asking for several fields at once
|
|
369
|
+
|
|
370
|
+
A request header costs more than a small payload. Measured against Bunny, every
|
|
371
|
+
response carries about **660 bytes of headers**, while a stored field value in
|
|
372
|
+
the Musnad Ahmed set averages a few hundred bytes. Many small single-field
|
|
373
|
+
lookups therefore spend most of their bytes on headers.
|
|
374
|
+
|
|
375
|
+
Because a record's values are stored next to each other, `get_many` and
|
|
376
|
+
`get_record` fetch several fields in one range request:
|
|
377
|
+
|
|
378
|
+
| | Requests | Bunny bill |
|
|
379
|
+
| --- | ---: | ---: |
|
|
380
|
+
| A whole 34-field record, field by field | 34 | ~26,800 B |
|
|
381
|
+
| The same record with `get_record()` | **1** | ~5,000 B |
|
|
382
|
+
|
|
383
|
+
Two fields are merged into one request when the bytes between them are cheaper
|
|
384
|
+
than the request header they save (`MERGE_GAP_LIMIT`, 660 bytes), and stay
|
|
385
|
+
separate otherwise — a field asked on its own is still exactly one request.
|
|
386
|
+
|
|
337
387
|
## Use from Python
|
|
338
388
|
|
|
339
389
|
```python
|
|
@@ -344,26 +394,31 @@ report = rida.scan("users.json")
|
|
|
344
394
|
print(report.recommended_mode) # "dense" or "sparse"
|
|
345
395
|
|
|
346
396
|
# Build once. The source JSON stays unchanged.
|
|
347
|
-
rida.build(
|
|
348
|
-
"users.json",
|
|
349
|
-
"users.rida",
|
|
350
|
-
title="Users dataset",
|
|
351
|
-
reader_url="https://example.com/rida-explorer",
|
|
352
|
-
)
|
|
397
|
+
rida.build("users.json", "users.rida", title="Users dataset")
|
|
353
398
|
|
|
354
399
|
# Read only one stored value from a local RIDA file.
|
|
355
400
|
with rida.RidaFile("users.rida") as data:
|
|
356
401
|
print(data.get("ali", "city"))
|
|
357
402
|
|
|
403
|
+
# Read several fields, or the whole record, in one request.
|
|
404
|
+
with rida.RidaFile("users.rida") as data:
|
|
405
|
+
print(data.get_many("ali", ["name", "city"]))
|
|
406
|
+
print(data.get_record("ali"))
|
|
407
|
+
|
|
358
408
|
# Check the whole file against its stored digests.
|
|
359
409
|
print(rida.verify("users.rida")["ok"])
|
|
360
410
|
|
|
361
|
-
# The same
|
|
411
|
+
# The same lookups work against an R2/public URL with Range support.
|
|
362
412
|
remote = rida.RemoteRidaFile("https://data.example.com/users.rida")
|
|
363
413
|
print(remote.get("fatima", "languages"))
|
|
414
|
+
print(remote.get_many("fatima", ["languages", "city"]))
|
|
364
415
|
print(remote.cache_hit) # True when the cached catalog was reused
|
|
365
416
|
```
|
|
366
417
|
|
|
418
|
+
`get_many` raises `KeyError` for a field name the file does not have, so a typo
|
|
419
|
+
never passes silently. A field the file has but this record lacks is simply left
|
|
420
|
+
out of the returned dictionary.
|
|
421
|
+
|
|
367
422
|
A desktop app or another Python program can show the same stages in its own
|
|
368
423
|
interface by passing a callback:
|
|
369
424
|
|
|
@@ -379,10 +434,12 @@ Useful names:
|
|
|
379
434
|
| Name | Purpose |
|
|
380
435
|
| --- | --- |
|
|
381
436
|
| `rida.build`, `rida.scan` | Build or analyse input; `value_codec=` and `memory_mode=` select behaviour |
|
|
382
|
-
| `rida.
|
|
383
|
-
| `rida.
|
|
437
|
+
| `rida.open_reader` | Open a local path or an http(s) URL with one call |
|
|
438
|
+
| `rida.RidaFile` | Local reader: `get`, `get_many`, `get_record`, `verify_data()` |
|
|
439
|
+
| `rida.RemoteRidaFile` | HTTP byte-range reader: same lookups, plus `cache_hit`, `timeout=`, `cache_dir=`, `keepalive=`, `close()` |
|
|
384
440
|
| `rida.verify` | Full integrity report for a local file |
|
|
385
441
|
| `rida.inspect_metadata` | Header and metadata as a dictionary |
|
|
442
|
+
| `rida.MERGE_GAP_LIMIT` | How many skipped bytes still beat a request header (660) |
|
|
386
443
|
| `rida.VALUE_CODECS` | `("gzip-per-field", "plain")` |
|
|
387
444
|
| `rida.clear_remote_cache`, `rida.remote_cache_directory` | Manage the catalog cache |
|
|
388
445
|
|
|
@@ -395,16 +452,17 @@ python3 -m unittest discover -s tests -v
|
|
|
395
452
|
The suite needs no third-party packages and does not use the network. It starts
|
|
396
453
|
its own local range server for the remote tests. `tests/fixtures` contains RIDA
|
|
397
454
|
1 files written by the published 0.1.1 library; the suite checks that this
|
|
398
|
-
version still reads them and still reproduces
|
|
399
|
-
`--value-codec plain
|
|
400
|
-
`tests/make_fixtures.py` pointed at an older library.
|
|
455
|
+
version still reads them, and still reproduces their catalog and data bytes with
|
|
456
|
+
`--value-codec plain` (metadata now differs by the one removed key). Regenerate
|
|
457
|
+
those fixtures only with `tests/make_fixtures.py` pointed at an older library.
|
|
401
458
|
|
|
402
459
|
## Current scope
|
|
403
460
|
|
|
404
|
-
RIDA 0.
|
|
405
|
-
|
|
406
|
-
full-text search indexes are not
|
|
407
|
-
JavaScript reader or a persistent catalog
|
|
461
|
+
RIDA 0.3.0 implements primary lookup — `record ID + field name → value` — plus
|
|
462
|
+
multi-field reads (`get_many`, `get_record`) and a whole-file integrity check.
|
|
463
|
+
Optional exact-match, numeric-range, and Unicode full-text search indexes are not
|
|
464
|
+
part of this release, and neither is a JavaScript reader or a persistent catalog
|
|
465
|
+
cache for the browser.
|
|
408
466
|
|
|
409
467
|
## License
|
|
410
468
|
|
|
@@ -59,7 +59,7 @@ RIDA 2 adds one key to what RIDA 1 wrote:
|
|
|
59
59
|
|
|
60
60
|
```json
|
|
61
61
|
{"format":"RIDA","format_version":2,"title":"musnad-ahmed","description":"",
|
|
62
|
-
"open_with":"RIDA Explorer","
|
|
62
|
+
"open_with":"RIDA Explorer","encoding":"UTF-8","index_mode":"dense",
|
|
63
63
|
"record_count":27647,"field_count":34,"record_id_mode":"sequential_numeric",
|
|
64
64
|
"catalog_codec":"lzma","value_codec":"gzip-per-field"}
|
|
65
65
|
```
|
|
@@ -67,6 +67,9 @@ RIDA 2 adds one key to what RIDA 1 wrote:
|
|
|
67
67
|
* RIDA 1 metadata has no `value_codec` key, which is read as `"plain"`.
|
|
68
68
|
* `format_version` must equal the header version, and `value_codec` must match
|
|
69
69
|
the codec implied by the magic. A mismatch is an error, not a repair.
|
|
70
|
+
* Metadata is **additive**: readers ignore keys they do not know. Files written by
|
|
71
|
+
0.1.x and 0.2.x also carry a `reader_url` key, which 0.3.0 stopped writing and
|
|
72
|
+
every reader simply ignores.
|
|
70
73
|
|
|
71
74
|
## 4. Catalog
|
|
72
75
|
|
|
@@ -193,8 +196,26 @@ A reader needs at most three requests for a cold lookup:
|
|
|
193
196
|
2. `bytes=128-(128 + metadata_length + catalog_length - 1)` — metadata and catalog.
|
|
194
197
|
3. the requested value range.
|
|
195
198
|
|
|
199
|
+
These requests travel over one reused connection per reading thread, because a
|
|
200
|
+
fresh TLS handshake per lookup costs several times more than the lookup itself.
|
|
201
|
+
A redirecting URL falls back to a plain follow-redirect request path.
|
|
202
|
+
|
|
196
203
|
With a warm local catalog cache (see below) step 2 disappears.
|
|
197
204
|
|
|
205
|
+
### Asking for several fields at once
|
|
206
|
+
|
|
207
|
+
Because a record's values are contiguous in the data region (§4.1), a reader can
|
|
208
|
+
ask for several fields of one record in a single range request: take the lowest
|
|
209
|
+
wanted offset and the highest wanted offset plus its length, and one request
|
|
210
|
+
covers them all. Any fields in between arrive as well.
|
|
211
|
+
|
|
212
|
+
That trade is usually worth it, because a CDN response header costs far more than
|
|
213
|
+
a few hundred bytes of payload: Bunny sends about 660 bytes of headers on every
|
|
214
|
+
response, while the average stored value here is a few hundred bytes. The reader
|
|
215
|
+
merges two fields when the bytes between them are cheaper than the header they
|
|
216
|
+
save, and keeps them separate otherwise. Fetching a whole 34-field record in one
|
|
217
|
+
request is therefore far cheaper than 34 single-field requests.
|
|
218
|
+
|
|
198
219
|
## 8. Local catalog cache (optional, not part of the format)
|
|
199
220
|
|
|
200
221
|
The catalog cache is a reader-side convenience, not a second file format.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# RIDA Python library — 0.
|
|
1
|
+
# RIDA Python library — 0.3.0
|
|
2
2
|
|
|
3
3
|
RIDA means **Range Indexed Data Access**. It is an installable Python library
|
|
4
4
|
and terminal tool that builds one `.rida` file from a collection of JSON
|
|
@@ -12,7 +12,7 @@ records. The file contains:
|
|
|
12
12
|
The reader loads the catalog once and then reads only the requested field bytes.
|
|
13
13
|
It works locally and over an HTTP server that supports byte-range requests.
|
|
14
14
|
|
|
15
|
-
RIDA 0.
|
|
15
|
+
RIDA 0.3.0 writes the **RIDA 2** layout by default: every stored field value is
|
|
16
16
|
its own gzip member. A reader still fetches exactly one value range, then
|
|
17
17
|
inflates that one member. On a 27,647-record, 34-field hadith dataset the data
|
|
18
18
|
region drops from 191,378,148 to 110,924,973 bytes, and the average stored value
|
|
@@ -104,7 +104,6 @@ Build a RIDA file. The command asks for confirmation unless `--yes` is supplied:
|
|
|
104
104
|
rida build users.json users.rida \
|
|
105
105
|
--title "Users dataset" \
|
|
106
106
|
--description "Public sample data" \
|
|
107
|
-
--reader-url "https://example.com/rida-explorer" \
|
|
108
107
|
--yes
|
|
109
108
|
```
|
|
110
109
|
|
|
@@ -206,6 +205,7 @@ rida build "/path/to/musnad-ahmed" musnad-ahmed.rida \
|
|
|
206
205
|
|
|
207
206
|
```sh
|
|
208
207
|
rida inspect users.rida
|
|
208
|
+
rida fields users.rida
|
|
209
209
|
rida get users.rida ali city
|
|
210
210
|
```
|
|
211
211
|
|
|
@@ -213,6 +213,21 @@ rida get users.rida ali city
|
|
|
213
213
|
value and exits with status 1 and a one-line message if the record ID or field
|
|
214
214
|
name does not exist.
|
|
215
215
|
|
|
216
|
+
`fields` answers "which key do I ask for?" — the field names live inside the file,
|
|
217
|
+
so nothing has to be guessed or documented separately:
|
|
218
|
+
|
|
219
|
+
```text
|
|
220
|
+
$ rida fields users.rida
|
|
221
|
+
Records: 27,647
|
|
222
|
+
Fields: 34
|
|
223
|
+
1 hadith_id
|
|
224
|
+
2 book
|
|
225
|
+
3 chapter_id
|
|
226
|
+
...
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
It also accepts an http(s) URL, and `--json` prints just the array.
|
|
230
|
+
|
|
216
231
|
## Check a file for damage
|
|
217
232
|
|
|
218
233
|
Reading one field never hashes the whole data region, so a normal lookup trusts
|
|
@@ -243,7 +258,7 @@ rida verify users.rida
|
|
|
243
258
|
|
|
244
259
|
## Where RIDA can read data
|
|
245
260
|
|
|
246
|
-
RIDA 0.
|
|
261
|
+
RIDA 0.3.0 can read a `.rida` file from the local computer or from a direct
|
|
247
262
|
HTTP/HTTPS file URL. For remote reads, RIDA sends ordinary HTTP byte-range
|
|
248
263
|
requests; it does not use a cloud-provider SDK. This makes it compatible with
|
|
249
264
|
object storage that returns the requested bytes as HTTP `206 Partial Content`
|
|
@@ -311,6 +326,41 @@ own cache entry automatically, because the header no longer matches.
|
|
|
311
326
|
|
|
312
327
|
Network reads fail after `--timeout` seconds (default 30) instead of hanging.
|
|
313
328
|
|
|
329
|
+
### Connection reuse
|
|
330
|
+
|
|
331
|
+
A range request sent over a fresh TLS connection pays a full handshake, which on
|
|
332
|
+
a CDN costs several times more than the lookup itself. The remote reader
|
|
333
|
+
therefore keeps one HTTP(S) connection open per reading thread and reuses it, so
|
|
334
|
+
a warm lookup spends its time on the value, not on the handshake.
|
|
335
|
+
|
|
336
|
+
Measured against Bunny CDN on the 27,647-record Musnad Ahmed file:
|
|
337
|
+
|
|
338
|
+
| | average | median |
|
|
339
|
+
| --- | ---: | ---: |
|
|
340
|
+
| 0.2.1 with connection reuse (default) | **25.9 ms** | 20.9 ms |
|
|
341
|
+
| 0.2.0, fresh connection per lookup | 89.0 ms | 76.9 ms |
|
|
342
|
+
|
|
343
|
+
Use `--no-keepalive`, or `keepalive=False` in Python, to get the old behaviour.
|
|
344
|
+
|
|
345
|
+
### Asking for several fields at once
|
|
346
|
+
|
|
347
|
+
A request header costs more than a small payload. Measured against Bunny, every
|
|
348
|
+
response carries about **660 bytes of headers**, while a stored field value in
|
|
349
|
+
the Musnad Ahmed set averages a few hundred bytes. Many small single-field
|
|
350
|
+
lookups therefore spend most of their bytes on headers.
|
|
351
|
+
|
|
352
|
+
Because a record's values are stored next to each other, `get_many` and
|
|
353
|
+
`get_record` fetch several fields in one range request:
|
|
354
|
+
|
|
355
|
+
| | Requests | Bunny bill |
|
|
356
|
+
| --- | ---: | ---: |
|
|
357
|
+
| A whole 34-field record, field by field | 34 | ~26,800 B |
|
|
358
|
+
| The same record with `get_record()` | **1** | ~5,000 B |
|
|
359
|
+
|
|
360
|
+
Two fields are merged into one request when the bytes between them are cheaper
|
|
361
|
+
than the request header they save (`MERGE_GAP_LIMIT`, 660 bytes), and stay
|
|
362
|
+
separate otherwise — a field asked on its own is still exactly one request.
|
|
363
|
+
|
|
314
364
|
## Use from Python
|
|
315
365
|
|
|
316
366
|
```python
|
|
@@ -321,26 +371,31 @@ report = rida.scan("users.json")
|
|
|
321
371
|
print(report.recommended_mode) # "dense" or "sparse"
|
|
322
372
|
|
|
323
373
|
# Build once. The source JSON stays unchanged.
|
|
324
|
-
rida.build(
|
|
325
|
-
"users.json",
|
|
326
|
-
"users.rida",
|
|
327
|
-
title="Users dataset",
|
|
328
|
-
reader_url="https://example.com/rida-explorer",
|
|
329
|
-
)
|
|
374
|
+
rida.build("users.json", "users.rida", title="Users dataset")
|
|
330
375
|
|
|
331
376
|
# Read only one stored value from a local RIDA file.
|
|
332
377
|
with rida.RidaFile("users.rida") as data:
|
|
333
378
|
print(data.get("ali", "city"))
|
|
334
379
|
|
|
380
|
+
# Read several fields, or the whole record, in one request.
|
|
381
|
+
with rida.RidaFile("users.rida") as data:
|
|
382
|
+
print(data.get_many("ali", ["name", "city"]))
|
|
383
|
+
print(data.get_record("ali"))
|
|
384
|
+
|
|
335
385
|
# Check the whole file against its stored digests.
|
|
336
386
|
print(rida.verify("users.rida")["ok"])
|
|
337
387
|
|
|
338
|
-
# The same
|
|
388
|
+
# The same lookups work against an R2/public URL with Range support.
|
|
339
389
|
remote = rida.RemoteRidaFile("https://data.example.com/users.rida")
|
|
340
390
|
print(remote.get("fatima", "languages"))
|
|
391
|
+
print(remote.get_many("fatima", ["languages", "city"]))
|
|
341
392
|
print(remote.cache_hit) # True when the cached catalog was reused
|
|
342
393
|
```
|
|
343
394
|
|
|
395
|
+
`get_many` raises `KeyError` for a field name the file does not have, so a typo
|
|
396
|
+
never passes silently. A field the file has but this record lacks is simply left
|
|
397
|
+
out of the returned dictionary.
|
|
398
|
+
|
|
344
399
|
A desktop app or another Python program can show the same stages in its own
|
|
345
400
|
interface by passing a callback:
|
|
346
401
|
|
|
@@ -356,10 +411,12 @@ Useful names:
|
|
|
356
411
|
| Name | Purpose |
|
|
357
412
|
| --- | --- |
|
|
358
413
|
| `rida.build`, `rida.scan` | Build or analyse input; `value_codec=` and `memory_mode=` select behaviour |
|
|
359
|
-
| `rida.
|
|
360
|
-
| `rida.
|
|
414
|
+
| `rida.open_reader` | Open a local path or an http(s) URL with one call |
|
|
415
|
+
| `rida.RidaFile` | Local reader: `get`, `get_many`, `get_record`, `verify_data()` |
|
|
416
|
+
| `rida.RemoteRidaFile` | HTTP byte-range reader: same lookups, plus `cache_hit`, `timeout=`, `cache_dir=`, `keepalive=`, `close()` |
|
|
361
417
|
| `rida.verify` | Full integrity report for a local file |
|
|
362
418
|
| `rida.inspect_metadata` | Header and metadata as a dictionary |
|
|
419
|
+
| `rida.MERGE_GAP_LIMIT` | How many skipped bytes still beat a request header (660) |
|
|
363
420
|
| `rida.VALUE_CODECS` | `("gzip-per-field", "plain")` |
|
|
364
421
|
| `rida.clear_remote_cache`, `rida.remote_cache_directory` | Manage the catalog cache |
|
|
365
422
|
|
|
@@ -372,16 +429,17 @@ python3 -m unittest discover -s tests -v
|
|
|
372
429
|
The suite needs no third-party packages and does not use the network. It starts
|
|
373
430
|
its own local range server for the remote tests. `tests/fixtures` contains RIDA
|
|
374
431
|
1 files written by the published 0.1.1 library; the suite checks that this
|
|
375
|
-
version still reads them and still reproduces
|
|
376
|
-
`--value-codec plain
|
|
377
|
-
`tests/make_fixtures.py` pointed at an older library.
|
|
432
|
+
version still reads them, and still reproduces their catalog and data bytes with
|
|
433
|
+
`--value-codec plain` (metadata now differs by the one removed key). Regenerate
|
|
434
|
+
those fixtures only with `tests/make_fixtures.py` pointed at an older library.
|
|
378
435
|
|
|
379
436
|
## Current scope
|
|
380
437
|
|
|
381
|
-
RIDA 0.
|
|
382
|
-
|
|
383
|
-
full-text search indexes are not
|
|
384
|
-
JavaScript reader or a persistent catalog
|
|
438
|
+
RIDA 0.3.0 implements primary lookup — `record ID + field name → value` — plus
|
|
439
|
+
multi-field reads (`get_many`, `get_record`) and a whole-file integrity check.
|
|
440
|
+
Optional exact-match, numeric-range, and Unicode full-text search indexes are not
|
|
441
|
+
part of this release, and neither is a JavaScript reader or a persistent catalog
|
|
442
|
+
cache for the browser.
|
|
385
443
|
|
|
386
444
|
## License
|
|
387
445
|
|
|
@@ -72,9 +72,6 @@
|
|
|
72
72
|
if (metadata.value_codec && metadata.value_codec !== layout.codec) {
|
|
73
73
|
throw new Error("The RIDA metadata disagrees with the file header.");
|
|
74
74
|
}
|
|
75
|
-
const reader = metadata.reader_url
|
|
76
|
-
? `<a href="${escapeHtml(metadata.reader_url)}" target="_blank" rel="noopener">Download / open RIDA Explorer</a>`
|
|
77
|
-
: "RIDA Explorer is required, but this file has no reader URL.";
|
|
78
75
|
result.innerHTML = `
|
|
79
76
|
<h2>${escapeHtml(metadata.title || file.name)}</h2>
|
|
80
77
|
<p>${escapeHtml(metadata.description || "No description supplied.")}</p>
|
|
@@ -86,7 +83,6 @@
|
|
|
86
83
|
<dt>Index mode</dt><dd>${escapeHtml(metadata.index_mode || "Unknown")}</dd>
|
|
87
84
|
<dt>Encoding</dt><dd>${escapeHtml(metadata.encoding || "UTF-8")}</dd>
|
|
88
85
|
<dt>File size</dt><dd>${escapeHtml(file.size.toLocaleString())} bytes</dd>
|
|
89
|
-
<dt>Open this file</dt><dd>${reader}</dd>
|
|
90
86
|
</dl>`;
|
|
91
87
|
} catch (error) {
|
|
92
88
|
result.innerHTML = `<p class="error">${escapeHtml(error.message)}</p>`;
|