Skip to content

Commit 5339bf2

Browse files
committed
feat: Add Hash Index Exact-Match Lookup example and update workflows
1 parent 36fb153 commit 5339bf2

6 files changed

Lines changed: 772 additions & 15 deletions

File tree

.github/workflows/test-python-examples.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ on:
2525
description: "Glob pattern(s) for examples to run (space-separated, relative to bindings/python/examples)."
2626
required: false
2727
type: string
28-
default: "0[1-9]_*.py 1[0-7]_*.py"
28+
default: "0[1-9]_*.py 1[0-9]_*.py"
2929
build-version:
3030
description: "Override package version (PEP 440) for build.sh"
3131
required: false
@@ -37,10 +37,10 @@ on:
3737
examples:
3838
description: "Glob pattern(s) for examples to run (space-separated, relative to bindings/python/examples)."
3939
required: false
40-
default: "0[1-9]_*.py 1[0-7]_*.py"
40+
default: "0[1-9]_*.py 1[0-9]_*.py"
4141

4242
env:
43-
EXAMPLES: ${{ inputs.examples || '0[1-9]_*.py 1[0-7]_*.py' }}
43+
EXAMPLES: ${{ inputs.examples || '0[1-9]_*.py 1[0-9]_*.py' }}
4444

4545
permissions:
4646
contents: read
@@ -402,6 +402,12 @@ jobs:
402402
timeout_duration=900
403403
example_jvm_args=""
404404
;;
405+
"19_hash_index_exact_match.py")
406+
example_args=""
407+
example_name="$example (hash index exact-match workflow)"
408+
timeout_duration=900
409+
example_jvm_args=""
410+
;;
405411
*)
406412
example_args=""
407413
example_name="$example"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# 19 - Hash Index Exact-Match Lookup Workflow
2+
3+
[View source code]({{ config.repo_url }}/blob/{{ config.extra.version_tag }}/bindings/python/examples/19_hash_index_exact_match.py){ .md-button }
4+
5+
This example demonstrates a fuller HASH index workflow that mirrors several of the
6+
behaviors already covered by the Java engine tests:
7+
8+
- creating a unique HASH index with `UNIQUE_HASH`
9+
- creating non-unique HASH indexes with `NOTUNIQUE_HASH`
10+
- creating composite HASH indexes for multi-column exact matches
11+
- inserting deterministic product and warehouse inventory records
12+
- running equality lookups against single-property and composite HASH indexes
13+
- inspecting HASH index metadata from the Python schema API
14+
- verifying missing-key behavior
15+
- updating indexed values and verifying HASH index maintenance
16+
- showing duplicate-key rejection plus rollback semantics
17+
- closing and reopening the database to verify index persistence
18+
19+
## Run
20+
21+
From `bindings/python/examples`:
22+
23+
```bash
24+
python3 19_hash_index_exact_match.py
25+
```
26+
27+
With a custom database path:
28+
29+
```bash
30+
python3 19_hash_index_exact_match.py --db-path ./my_test_databases/hash_index_demo
31+
```
32+
33+
## Notes
34+
35+
- The example is intentionally SQL-first.
36+
- HASH indexes are the right fit for exact-match predicates such as `sku = ?`, `category
37+
= ?`, or `(warehouse = ? AND sku = ?)`.
38+
- For range predicates or ordered scans, prefer `UNIQUE` / `NOTUNIQUE` `LSM_TREE`
39+
indexes instead.
40+
- If the packaged runtime does not include HASH index support, the script prints a short
41+
explanation and exits.
42+
- The example intentionally includes a reopen phase so persisted HASH index metadata and
43+
exact-match lookups are exercised in a fresh database session.
44+
45+
## Why This Example Exists
46+
47+
The Java engine already has focused HASH index coverage for:
48+
49+
- SQL creation via `UNIQUE_HASH` and `NOTUNIQUE_HASH`
50+
- unique and non-unique lookup behavior
51+
- composite HASH keys
52+
- missing-key behavior
53+
- duplicate-key rejection
54+
- persistence across reopen
55+
56+
This Python example mirrors that behavior with the public bindings API so the examples
57+
set includes a dedicated exact-match index workflow.

bindings/python/docs/examples/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ Four-way graph-ingest comparison. Repository guidance from these experiments is
6464
**[17 - Time Series End-to-End](17_timeseries_end_to_end.md)**
6565
SQL-first time-series workflow covering type creation, tagged inserts, range queries, and hourly bucket aggregation.
6666

67+
**[19 - Hash Index Exact-Match Lookup Workflow](19_hash_index_exact_match.md)**
68+
SQL-first HASH index workflow covering unique and non-unique exact-match lookups, schema inspection, and duplicate-key rejection.
69+
6770
## Quick Start
6871

6972
**⚠️ Important: Always run examples from the `examples/` directory.**
@@ -87,6 +90,7 @@ python 01_simple_document_store.py
8790
10. **Hybrid Queries** (13) - Combined SQL, graph, and vector workflow
8891
11. **Lifecycle And Ingest Benchmarks** (14/15/16) - Embedded lifecycle timing and ingest comparisons
8992
12. **Time Series SQL Workflow** (17) - Tagged samples, range queries, and bucket aggregation from Python
93+
13. **Hash Index Workflow** (19) - Exact-match HASH indexes, missing-key behavior, and duplicate protection
9094

9195
---
9296

0 commit comments

Comments
 (0)