@@ -18,9 +18,13 @@ The following UDFs are includes:
18
18
` xxhash `
19
19
- [ IP Functions] ( #ip-address-functions ) for interop: ` ip_validate ` ,
20
20
` ip_to_canonical ` , ` ip_to_ipv4_mapped `
21
+ - [ String Operations] ( #string-operations ) : Calculations such as Levenshtein
22
+ edit distance, including limited and normalized versions.
21
23
- [ Jsonify] ( #jsonify ) : convert any data to JSON
22
24
- [ Lipsum] ( #lipsum ) : generate random text
23
25
26
+ See the relevant section for more information.
27
+
24
28
### UUID
25
29
26
30
Provide UUID functions similar to the Postges [ ` uuid-osp ` ] package:
@@ -34,6 +38,29 @@ Provide UUID functions similar to the Postges [`uuid-osp`] package:
34
38
35
39
See the [ UUID Readme] ( /udf-uuid/README.md ) for more information
36
40
41
+ #### Usage
42
+
43
+ ``` text
44
+ note: type uuid is type string
45
+ uuid_generate_v1() -> uuid
46
+ uuid_generate_v1mc() -> uuid
47
+ uuid_generate_v4() -> uuid
48
+ uuid_generate_v6([node_addr: string]) -> uuid
49
+ uuid_generate_v7() -> uuid
50
+ uuid_nil() -> uuid
51
+ uuid_max() -> uuid
52
+ uuid_ns_dns() -> string
53
+ uuid_ns_url() -> string
54
+ uuid_ns_oid() -> string
55
+ uuid_ns_x500() -> string
56
+ uuid_is_valid(uuid: uuid) -> boolean
57
+ uuid_to_bin(uuid: uuid) -> bytes
58
+ uuid_from_bin() -> uuid
59
+ bin_from_uuid() -> uuid
60
+ ```
61
+
62
+ #### Examples
63
+
37
64
``` text
38
65
MariaDB [(none)]> select uuid_generate_v6();
39
66
+--------------------------------------+
@@ -54,7 +81,7 @@ MariaDB [(none)]> select hex(uuid_to_bin(uuid_generate_v4()));
54
81
55
82
[ `uuid-osp` ] : https://www.postgresql.org/docs/current/uuid-ossp.html
56
83
57
- ## Hash Algorithms
84
+ ### Hash Algorithms
58
85
59
86
This library provides the following functions:
60
87
@@ -68,11 +95,54 @@ This library provides the following functions:
68
95
- ` xxhash3 ` , ` xxhash32 ` , ` xxhash64 ` , ` xxhash ` (` xxhash ` is an alias for
69
96
` xxhash64 ` )
70
97
71
- All of these return hex strings by defaulti . ` _bin ` functions are also
98
+ All of these return hex strings by default . ` _bin ` functions are also
72
99
provided that return the binary result without going through hexification,
73
100
suitable for storage in a ` BINARY(X) ` column.
74
101
75
102
103
+ #### Usage
104
+
105
+ ``` text
106
+ blake2b512(a: any [, ...]) -> string
107
+ blake2b512_bin(a: any [, ...]) -> bytes
108
+ blake2s512(a: any [, ...]) -> string
109
+ blake2s512_bin(a: any [, ...]) -> bytes
110
+ blake3(a: any [, ...]) -> string
111
+ blake3_bin(a: any [, ...]) -> bytes
112
+ blake3_thd(a: any [, ...]) -> string
113
+ blake3_thd_bin(a: any [, ...]) -> bytes
114
+ md5_u(a: any [, ...]) -> string
115
+ md5_u_bin(a: any [, ...]) -> bytes
116
+ sha1_u(a: any [, ...]) -> string
117
+ sha1_u_bin(a: any [, ...]) -> bytes
118
+ sha224(a: any [, ...]) -> string
119
+ sha224_bin(a: any [, ...]) -> bytes
120
+ sha256(a: any [, ...]) -> string
121
+ sha256_bin(a: any [, ...]) -> bytes
122
+ sha384(a: any [, ...]) -> string
123
+ sha384_bin(a: any [, ...]) -> bytes
124
+ sha512(a: any [, ...]) -> string
125
+ sha512_bin(a: any [, ...]) -> bytes
126
+ keccak224(a: any [, ...]) -> string
127
+ keccak224_bin(a: any [, ...]) -> bytes
128
+ keccak256(a: any [, ...]) -> string
129
+ keccak256_bin(a: any [, ...]) -> bytes
130
+ sha3_224(a: any [, ...]) -> string
131
+ sha3_224_bin(a: any [, ...]) -> bytes
132
+ sha3_256(a: any [, ...]) -> string
133
+ sha3_256_bin(a: any [, ...]) -> bytes
134
+ sha3_384(a: any [, ...]) -> string
135
+ sha3_384_bin(a: any [, ...]) -> bytes
136
+ sha3_512(a: any [, ...]) -> string
137
+ sha3_512_bin(a: any [, ...]) -> bytes
138
+ xxhash(a: any [, ...]) -> integer
139
+ xxhash3(a: any [, ...]) -> integer
140
+ xxhash32(a: any [, ...]) -> integer
141
+ xxhash64(a: any [, ...]) -> integer
142
+ ```
143
+
144
+ #### Examples
145
+
76
146
``` text
77
147
MariaDB [(none)]> select blake3("Hello, world!");
78
148
+------------------------------------------------------------------+
@@ -114,15 +184,67 @@ MariaDB [(none)]> select xxhash('Hello, ', 0x77, 'orld', '!');
114
184
115
185
Note that in SQL, all integers are an ` i64 ` , all floats are a ` f64 ` , and all
116
186
decimals are represented as a string to the UDF API. This library hashes these
117
- types as their little endian representation. (You only need to worry about this
118
- if you have very obscure platform compatibility requirements, and strings and
119
- blobs are always unambiguous).
187
+ types as their little endian representation on all platforms. (You only need
188
+ to worry about this if you have very obscure platform compatibility
189
+ requirements. Strings and blobs are always unambiguous).
190
+
191
+ ### String Operationg
192
+
193
+ Provide the function ` levenshtein ` , which calculates the levenshtein edit
194
+ distance between two strings. There is also ` levenshtein_normalized ` that
195
+ returns a value between 0.0 (identical) and 1.0 (significantly different).
196
+
197
+ If a limit is provided as a third argument, the operation will terminate if
198
+ that limit is exceeded. This can help to improve performance if filtering
199
+ dissimilar strings.
200
+
201
+ These algorithms provide a _ byte_ edit distance, rather than unicode chars or
202
+ graphemes. These options may be added in the future.
203
+
204
+ These algorithms are implemented by the [ ` rapidfuzz ` ] crate.
205
+
206
+ [ ` rapidfuzz ` ] : https://crates.io/crates/rapidfuzz )
207
+
208
+ #### Usage
209
+
210
+ ``` text
211
+ levenshtein(a: str, b: str [, limit: integer]) -> integer;
212
+ levenshtein_normalized(a: str, b: str [, limit: real]) -> real;
213
+ ```
214
+
215
+ #### Example
216
+
217
+ ``` text
218
+ MariaDB [(none)]> SELECT levenshtein('foo', 'moose'), levenshtein_normalized('foo', 'moos');
219
+ +-----------------------------+---------------------------------------+
220
+ | levenshtein('foo', 'moose') | levenshtein_normalized('foo', 'moos') |
221
+ +-----------------------------+---------------------------------------+
222
+ | 3 | 0.5 |
223
+ +-----------------------------+---------------------------------------+
224
+ 1 row in set (0.001 sec)
225
+
226
+ MariaDB [(none)]> SELECT levenshtein('foo', 'moose', 2), levenshtein_normalized('foo', 'moos', 0.3);
227
+ +--------------------------------+--------------------------------------------+
228
+ | levenshtein('foo', 'moose', 2) | levenshtein_normalized('foo', 'moos', 0.3) |
229
+ +--------------------------------+--------------------------------------------+
230
+ | 2 | 0.3 |
231
+ +--------------------------------+--------------------------------------------+
232
+ 1 row in set (0.001 sec)
233
+ ```
120
234
121
235
### Jsonify
122
236
123
237
Provide the function ` jsonify ` , which quickly creates JSON output for any given
124
238
inputs.
125
239
240
+ #### Usage
241
+
242
+ ``` text
243
+ jsonify(a: any [, ...]) -> string
244
+ ```
245
+
246
+ #### Examples
247
+
126
248
``` text
127
249
MariaDB [db]> select jsonify(qty, cost, class) from t1 limit 4;
128
250
+-------------------------------------+
@@ -155,6 +277,14 @@ MariaDB [db]> select jsonify(uuid() as uuid, qty as quantity, cost) from t1 limi
155
277
156
278
Uses the [ lipsum crate] to generate lipsum strings with a specified word count.
157
279
280
+ #### Usage
281
+
282
+ ``` text
283
+ lipsum(count: integer [, seed: integer]) -> string
284
+ ```
285
+
286
+ #### Examples
287
+
158
288
159
289
``` text
160
290
MariaDB [(none)]> select lipsum(10);
@@ -168,7 +298,7 @@ MariaDB [(none)]> select lipsum(10);
168
298
169
299
[ lipsum crate ] : https://docs.rs/lipsum/latest/lipsum/
170
300
171
- ## IP Address Functions
301
+ ### IP Address Functions
172
302
173
303
We provide three IP functions:
174
304
@@ -177,7 +307,18 @@ We provide three IP functions:
177
307
- ` ip_to_ipv6_mapped ` which converts ipv4 addresses to their ipv6 form (e.g.
178
308
for interop with the ` INET6 ` data type)
179
309
- ` ip_to_canonical ` which reverses the mapping operation
310
+
311
+ #### Usage
312
+
313
+ ``` text
314
+ ip_validate(ip: string) -> string
315
+ ip_to_canonical(ip: string) -> string
316
+ ip_to_ipv6_mapped(ip: string) -> string
180
317
```
318
+
319
+ #### Examples
320
+
321
+ ``` text
181
322
MariaDB [db]> select
182
323
-> input,
183
324
-> ip_validate(input),
@@ -205,11 +346,12 @@ The desired files can be copied to the plugin directory (usually
205
346
` /usr/lib/mysql/plugin ` ) and selectively loaded:
206
347
207
348
``` sql
349
+ -- **** Hash functions ****
208
350
CREATE OR REPLACE FUNCTION blake2b512 RETURNS string SONAME ' libudf_hash.so' ;
209
351
CREATE OR REPLACE FUNCTION blake2s256 RETURNS string SONAME ' libudf_hash.so' ;
210
352
CREATE OR REPLACE FUNCTION blake3 RETURNS string SONAME ' libudf_hash.so' ;
211
353
CREATE OR REPLACE FUNCTION blake3_thd RETURNS string SONAME ' libudf_hash.so' ;
212
- -- the md5 and sha functions have builtin versions
354
+ -- the md5 and sha functions have builtin versions, hence the `_u` suffix
213
355
CREATE OR REPLACE FUNCTION md5_u RETURNS string SONAME ' libudf_hash.so' ;
214
356
CREATE OR REPLACE FUNCTION sha1_u RETURNS string SONAME ' libudf_hash.so' ;
215
357
CREATE OR REPLACE FUNCTION sha224 RETURNS string SONAME ' libudf_hash.so' ;
@@ -221,7 +363,6 @@ CREATE OR REPLACE FUNCTION keccak256 RETURNS string SONAME 'libudf_hash.so';
221
363
CREATE OR REPLACE FUNCTION sha3_224 RETURNS string SONAME ' libudf_hash.so' ;
222
364
CREATE OR REPLACE FUNCTION sha3_256 RETURNS string SONAME ' libudf_hash.so' ;
223
365
CREATE OR REPLACE FUNCTION sha3_384 RETURNS string SONAME ' libudf_hash.so' ;
224
- CREATE OR REPLACE FUNCTION sha3_384_bin RETURNS string SONAME ' libudf_hash.so' ;
225
366
CREATE OR REPLACE FUNCTION sha3_512 RETURNS string SONAME ' libudf_hash.so' ;
226
367
CREATE OR REPLACE FUNCTION xxhash RETURNS integer SONAME ' libudf_hash.so' ;
227
368
CREATE OR REPLACE FUNCTION xxhash3 RETURNS integer SONAME ' libudf_hash.so' ;
@@ -245,36 +386,41 @@ CREATE OR REPLACE FUNCTION keccak224_bin RETURNS string SONAME 'libudf_hash.so';
245
386
CREATE OR REPLACE FUNCTION keccak256_bin RETURNS string SONAME ' libudf_hash.so' ;
246
387
CREATE OR REPLACE FUNCTION sha3_224_bin RETURNS string SONAME ' libudf_hash.so' ;
247
388
CREATE OR REPLACE FUNCTION sha3_256_bin RETURNS string SONAME ' libudf_hash.so' ;
389
+ CREATE OR REPLACE FUNCTION sha3_384_bin RETURNS string SONAME ' libudf_hash.so' ;
248
390
CREATE OR REPLACE FUNCTION sha3_512_bin RETURNS string SONAME ' libudf_hash.so' ;
249
391
250
- -- JSON creation function
251
- CREATE FUNCTION jsonify RETURNS string SONAME ' libudf_jsonify.so' ;
252
-
253
- -- IP functions
254
- CREATE FUNCTION ip_validate RETURNS string SONAME ' libudf_net.so' ;
255
- CREATE FUNCTION ip_to_canonical RETURNS string SONAME ' libudf_net.so' ;
256
- CREATE FUNCTION ip_to_ipv6_mapped RETURNS string SONAME ' libudf_net.so' ;
257
-
258
- -- random string generation
259
- CREATE FUNCTION lipsum RETURNS string SONAME ' libudf_lipsum.so' ;
260
-
261
- -- UUID interfaces
262
- CREATE FUNCTION uuid_generate_v1 RETURNS string SONAME ' libudf_uuid.so' ;
263
- CREATE FUNCTION uuid_generate_v1mc RETURNS string SONAME ' libudf_uuid.so' ;
264
- CREATE FUNCTION uuid_generate_v4 RETURNS string SONAME ' libudf_uuid.so' ;
265
- CREATE FUNCTION uuid_generate_v6 RETURNS string SONAME ' libudf_uuid.so' ;
266
- CREATE FUNCTION uuid_generate_v7 RETURNS string SONAME ' libudf_uuid.so' ;
267
- CREATE FUNCTION uuid_nil RETURNS string SONAME ' libudf_uuid.so' ;
268
- CREATE FUNCTION uuid_max RETURNS string SONAME ' libudf_uuid.so' ;
269
- CREATE FUNCTION uuid_ns_dns RETURNS string SONAME ' libudf_uuid.so' ;
270
- CREATE FUNCTION uuid_ns_url RETURNS string SONAME ' libudf_uuid.so' ;
271
- CREATE FUNCTION uuid_ns_oid RETURNS string SONAME ' libudf_uuid.so' ;
272
- CREATE FUNCTION uuid_ns_x500 RETURNS string SONAME ' libudf_uuid.so' ;
273
- CREATE FUNCTION uuid_is_valid RETURNS integer SONAME ' libudf_uuid.so' ;
274
- CREATE FUNCTION uuid_to_bin RETURNS string SONAME ' libudf_uuid.so' ;
275
- CREATE FUNCTION uuid_from_bin RETURNS string SONAME ' libudf_uuid.so' ;
392
+ -- **** JSON creation function ****
393
+ CREATE OR REPLACE FUNCTION jsonify RETURNS string SONAME ' libudf_jsonify.so' ;
394
+
395
+ -- **** IP functions ****
396
+ CREATE OR REPLACE FUNCTION ip_validate RETURNS string SONAME ' libudf_net.so' ;
397
+ CREATE OR REPLACE FUNCTION ip_to_canonical RETURNS string SONAME ' libudf_net.so' ;
398
+ CREATE OR REPLACE FUNCTION ip_to_ipv6_mapped RETURNS string SONAME ' libudf_net.so' ;
399
+
400
+ -- **** string operation functions ****
401
+ CREATE OR REPLACE FUNCTION levenshtein RETURNS integer SONAME ' libudf_stringops.so'
402
+ CREATE OR REPLACE FUNCTION levenshtein_normalized RETURNS real SONAME ' libudf_stringops.so'
403
+
404
+ -- **** random string generation ****
405
+ CREATE OR REPLACE FUNCTION lipsum RETURNS string SONAME ' libudf_lipsum.so' ;
406
+
407
+ -- **** UUID interfaces ****
408
+ CREATE OR REPLACE FUNCTION uuid_generate_v1 RETURNS string SONAME ' libudf_uuid.so' ;
409
+ CREATE OR REPLACE FUNCTION uuid_generate_v1mc RETURNS string SONAME ' libudf_uuid.so' ;
410
+ CREATE OR REPLACE FUNCTION uuid_generate_v4 RETURNS string SONAME ' libudf_uuid.so' ;
411
+ CREATE OR REPLACE FUNCTION uuid_generate_v6 RETURNS string SONAME ' libudf_uuid.so' ;
412
+ CREATE OR REPLACE FUNCTION uuid_generate_v7 RETURNS string SONAME ' libudf_uuid.so' ;
413
+ CREATE OR REPLACE FUNCTION uuid_nil RETURNS string SONAME ' libudf_uuid.so' ;
414
+ CREATE OR REPLACE FUNCTION uuid_max RETURNS string SONAME ' libudf_uuid.so' ;
415
+ CREATE OR REPLACE FUNCTION uuid_ns_dns RETURNS string SONAME ' libudf_uuid.so' ;
416
+ CREATE OR REPLACE FUNCTION uuid_ns_url RETURNS string SONAME ' libudf_uuid.so' ;
417
+ CREATE OR REPLACE FUNCTION uuid_ns_oid RETURNS string SONAME ' libudf_uuid.so' ;
418
+ CREATE OR REPLACE FUNCTION uuid_ns_x500 RETURNS string SONAME ' libudf_uuid.so' ;
419
+ CREATE OR REPLACE FUNCTION uuid_is_valid RETURNS integer SONAME ' libudf_uuid.so' ;
420
+ CREATE OR REPLACE FUNCTION uuid_to_bin RETURNS string SONAME ' libudf_uuid.so' ;
421
+ CREATE OR REPLACE FUNCTION uuid_from_bin RETURNS string SONAME ' libudf_uuid.so' ;
276
422
-- `bin_to_uuid` and 'uuid_from_bin' are aliases
277
- CREATE FUNCTION bin_to_uuid RETURNS string SONAME ' libudf_uuid.so' ;
423
+ CREATE OR REPLACE FUNCTION bin_to_uuid RETURNS string SONAME ' libudf_uuid.so' ;
278
424
```
279
425
280
426
Note that Windows ` .dll ` s are built but have not been tested - please open an
@@ -305,14 +451,14 @@ docker build . --tag mdb-udf-suite-img
305
451
# run it in the background
306
452
docker run --rm -d \
307
453
-e MARIADB_ROOT_PASSWORD=example \
308
- --name mdb_udf_suite \
454
+ --name mdb-udf-suite \
309
455
mdb-udf-suite-img
310
456
311
457
# Enter a SQL shell
312
- docker exec -it mdb_udf_suite mariadb -pexample
458
+ docker exec -it mdb-udf-suite mariadb -pexample
313
459
314
460
# Stop the server when done
315
- docker stop mdb_udf_suite
461
+ docker stop mdb-udf-suite
316
462
```
317
463
318
464
The UDFs can then be loaded using the ` CREATE FUNCTION ` statements above.
0 commit comments