@@ -10,6 +10,10 @@ behavior via the standard `CreateMaterializedView` gRPC method.
1010
1111### 1. Creating a CMV
1212
13+ There are two ways to create a CMV in the emulator:
14+
15+ #### Option A: gRPC (recommended, matches production)
16+
1317Use the standard Go admin client, pointed at the emulator:
1418
1519``` go
@@ -32,6 +36,45 @@ ORDER BY region, account_id, ts, typ, item_id, src_key`,
3236The emulator parses the SQL to extract the key transformation config. The same code works
3337against both production Bigtable and the emulator.
3438
39+ #### Option B: ` --cmv-config ` flag (local testing convenience)
40+
41+ For local testing without writing client code, pass a JSON config file at startup:
42+
43+ ``` bash
44+ ./little_bigtable --port 9000 --db-file /tmp/lbt.db --cmv-config /path/to/cmv_config.json
45+ ```
46+
47+ The JSON file is an array of CMV config objects:
48+
49+ ``` json
50+ [
51+ {
52+ "source_table" : " events" ,
53+ "view_id" : " events_by_account" ,
54+ "key_separator" : " #" ,
55+ "key_mapping" : [3 , 4 , 1 , 2 , 0 ],
56+ "append_source_key" : true ,
57+ "include_families" : [" cf1" ]
58+ }
59+ ]
60+ ```
61+
62+ | Field | Description |
63+ | ---| ---|
64+ | ` source_table ` | Table ID of the source table (not the fully-qualified name) |
65+ | ` view_id ` | Table ID to use for the CMV shadow table |
66+ | ` key_separator ` | Delimiter used in the composite row key |
67+ | ` key_mapping ` | Ordered list of 0-based source key component indices for the CMV key |
68+ | ` append_source_key ` | If true, appends the full original source key as the final component |
69+ | ` include_families ` | Column families to copy; omit or leave empty to include all |
70+
71+ > ** Note:** The ` --cmv-config ` approach registers CMVs directly without going through SQL
72+ > parsing. It is intended for local testing only. In production (and for full emulator
73+ > fidelity), use ` CreateMaterializedView ` via the gRPC client.
74+
75+ > ** Persistence:** CMV registrations loaded via either approach are in-memory only. If the
76+ > emulator restarts, CMVs must be re-registered (or the ` --cmv-config ` flag re-supplied).
77+
3578### 2. Write-time Sync
3679
3780When data is written to a source table (via MutateRow, MutateRows, CheckAndMutateRow,
@@ -59,16 +102,18 @@ row, err := table.ReadRow(ctx, "region-a#account-42#...")
59102## What's Changed
60103
61104### New Files
62- - ` bttest/cmv.go ` — CMV config types, SQL parser, key transformation logic
105+ - ` bttest/cmv.go ` — CMV config types, registry, key transformation logic
106+ - ` bttest/sql_parse.go ` — SQL parser for extracting CMV config from a ` CreateMaterializedView ` query
63107- ` bttest/cmv_test.go ` — Tests for key transformation, write sync, delete propagation
108+ - ` bttest/sql_parse_test.go ` — Tests for the SQL parser
64109
65110### Modified Files
66- - ` little_bigtable.go ` — Version bump to 0.2.0
111+ - ` little_bigtable.go ` — Version bump to 0.2.0; added ` --cmv-config ` flag
67112- ` bttest/inmem.go ` — Added ` cmvs ` field to server struct, CMV registration,
68113 shadow table creation, write-time sync hooks in MutateRow/MutateRows/
69114 CheckAndMutateRow/ReadModifyWriteRow/DropRowRange
70115- ` bttest/instance_server.go ` — Implemented CreateMaterializedView, GetMaterializedView,
71- ListMaterializedViews, DeleteMaterializedView
116+ ListMaterializedViews, UpdateMaterializedView (DeletionProtection only), DeleteMaterializedView
72117
73118## Known Limitations
74119
@@ -80,8 +125,8 @@ row, err := table.ReadRow(ctx, "region-a#account-42#...")
80125 creation are not reflected in the CMV table.
81126- ** Backfill** : Data written to the source table before the CMV is registered is not
82127 retroactively copied.
83- - ** Persistence** : CMV registrations are in-memory only. If the emulator restarts, CMVs
84- must be re-registered via ` CreateMaterializedView ` .
128+ - ** Persistence** : CMV registrations are in-memory only and do not survive a restart.
129+ Re-register via ` CreateMaterializedView ` or re-supply ` --cmv-config ` on each startup .
85130
86131## Example: Key Transformation
87132
0 commit comments