@@ -16,6 +16,7 @@ The CREATE script incorporates the following components:
16
16
17
17
~~~ sql
18
18
WITH
19
+ -- ---------------------------- PROLOGUE ------------------------------
19
20
json_ops(ops) AS (
20
21
VALUES
21
22
(json(
34
35
json_extract(value, ' $.path_new' ) AS path_new
35
36
FROM json_ops AS jo, json_each(jo .ops ) AS terms
36
37
),
38
+ /* *******************************************************************/
39
+ -- ------------------------- ANCESTOR LIST ----------------------------
37
40
levels AS (
38
41
SELECT opid, path_new AS path , length(path_new) - length(replace(path_new, ' /' , ' ' )) AS depth
39
42
FROM base_ops
54
57
GROUP BY asc_path
55
58
ORDER BY opid, asc_path
56
59
),
60
+ /* *******************************************************************/
57
61
path_terms AS (
58
62
SELECT
59
63
row_number() OVER (ORDER BY opid, asc_path) AS counter,
62
66
LEFT JOIN categories AS cats ON asc_path = cats .path
63
67
WHERE cats .ascii_id IS NULL
64
68
),
69
+ -- ----------------------- ASCII ID GENERATOR -------------------------
65
70
id_counts(id_counter) AS (SELECT count (* ) FROM path_terms),
66
71
json_templates AS (SELECT ' [' || replace(hex(zeroblob(id_counter* 8 / 2 - 1 )), ' 0' , ' 0,' ) || ' 0,0]' AS json_template FROM id_counts),
67
72
char_templates(char_template) AS (VALUES (' -0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_' )),
82
87
(unicode(substr(ascii_id, 8 , 1 )) << 8 * 0 ) AS bin_id
83
88
FROM ascii_ids
84
89
),
90
+ /* *******************************************************************/
85
91
new_nodes AS (
86
92
SELECT bin_id AS id, asc_name AS name, asc_prefix AS prefix
87
93
FROM path_terms, ids USING (counter)
0 commit comments