Skip to content

Commit 4b1c7d8

Browse files
committed
Patterns
1 parent daa867b commit 4b1c7d8

5 files changed

+21
-211
lines changed

SM ASCII IDs.md renamed to Patterns ASCII IDs.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
layout: default
33
title: ASCII IDs
4-
nav_order: 4
5-
parent: String Manipulation
6-
permalink: /strings/ascii-id
4+
nav_order: 7
5+
parent: Design Patterns
6+
permalink: /patterns/ascii-id
77
---
88

99
The following query generates random eight-character-long ASCII IDs (*id_counts*.*id_counter* pieces) using the specified alphabet (*char_templates*). The dash and underscore characters extend the alphanumeric alphabet to 64 characters allowing the selection of the six least significant bits from a random 64-bit number via bitwise AND (instead of *mod*). The *ids* block generates a 64-bit integer representation of the same ID. Saving character code before grouping in *ascii_ids* would not work because the query optimizer tends to rerun the query, executing the *random* function and generating the character and character code independently. The intermediate table aggregation operation prevents this optimization.
@@ -16,20 +16,20 @@ WITH
1616
ascii_ids AS (
1717
SELECT group_concat(substr(char_template, (random() & 63) + 1, 1), '') AS ascii_id, "key"/8 AS counter
1818
FROM char_templates, json_templates, json_each(json_templates.json_template) AS terms
19-
GROUP BY counter
20-
),
21-
ids AS (
22-
SELECT counter, ascii_id,
23-
(unicode(substr(ascii_id, 1, 1)) << 8*7) +
24-
(unicode(substr(ascii_id, 2, 1)) << 8*6) +
25-
(unicode(substr(ascii_id, 3, 1)) << 8*5) +
26-
(unicode(substr(ascii_id, 4, 1)) << 8*4) +
27-
(unicode(substr(ascii_id, 5, 1)) << 8*3) +
28-
(unicode(substr(ascii_id, 6, 1)) << 8*2) +
29-
(unicode(substr(ascii_id, 7, 1)) << 8*1) +
30-
(unicode(substr(ascii_id, 8, 1)) << 8*0) AS bin_id
31-
FROM ascii_ids
32-
)
19+
GROUP BY counter
20+
),
21+
ids AS (
22+
SELECT counter, ascii_id,
23+
(unicode(substr(ascii_id, 1, 1)) << 8*7) +
24+
(unicode(substr(ascii_id, 2, 1)) << 8*6) +
25+
(unicode(substr(ascii_id, 3, 1)) << 8*5) +
26+
(unicode(substr(ascii_id, 4, 1)) << 8*4) +
27+
(unicode(substr(ascii_id, 5, 1)) << 8*3) +
28+
(unicode(substr(ascii_id, 6, 1)) << 8*2) +
29+
(unicode(substr(ascii_id, 7, 1)) << 8*1) +
30+
(unicode(substr(ascii_id, 8, 1)) << 8*0) AS bin_id
31+
FROM ascii_ids
32+
)
3333
SELECT * FROM ids;
3434
~~~
3535

SM Fixed-Width Values.md renamed to Patterns Fixed-Width Values.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
layout: default
33
title: Fixed-Width Values
4-
nav_order: 3
5-
parent: String Manipulation
6-
permalink: /strings/split-fwv
4+
nav_order: 6
5+
parent: Design Patterns
6+
permalink: /patterns/split-fwv
77
---
88

99
### Context
@@ -18,7 +18,7 @@ where the key term is node ASCII ID, and the value term is node path/prefix, not
1818

1919
### Splitting fixed-width value strings
2020

21-
Like in the case of [DSV][] strings, the following query iscontext-specific, but the notes below should help adapt it to other needs.
21+
The following query is context-specific, but the notes below should help adapt it to other needs.
2222

2323
<a name="FWV-Query"></a>
2424
~~~sql

SM Black Boxed Queries.md

-108
This file was deleted.

SM Delimiter-Separated Values.md

-75
This file was deleted.

SM String Manipulation.md

-7
This file was deleted.

0 commit comments

Comments
 (0)