forked from MaterializeInc/materialize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encode.slt
112 lines (85 loc) · 2.82 KB
/
encode.slt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
# Tests for the `encode` and `decode` functions.
mode cockroach
statement ok
CREATE TABLE unencoded (val bytea)
statement ok
INSERT INTO unencoded VALUES (NULL), ('\x00fffe65'), ('a'), ('ab'), ('abc'), ('abcd')
# ==> base64 format
query TT
SELECT encode(val, 'base64'), decode(encode(val, 'base64'), 'base64') FROM unencoded ORDER BY val
----
AP/+ZQ== [0,␠255,␠254,␠101]
YQ== a
YWI= ab
YWJj abc
YWJjZA== abcd
NULL NULL
# base64 special case: test that the encoded output is wrapped at 76 characters.
mode standard
query T multiline
SELECT encode('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz', 'base64')
----
YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5emFiY2Rl
ZmdoaWprbG1ub3BxcnN0dXZ3eHl6YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXphYmNkZWZnaGlq
a2xtbm9wcXJzdHV2d3h5emFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6
EOF
mode cockroach
query error invalid base64 end sequence
SELECT decode('a', 'base64')
query error unexpected "=" while decoding base64 sequence
SELECT decode('=', 'base64')
query error invalid symbol "@" found while decoding base64 sequence
SELECT decode('aaa@', 'base64')
query error invalid symbol "\\u\{2\}" found while decoding base64 sequence
SELECT decode(e'aaa\u0002', 'base64')
# ==> hex format
query TT
SELECT encode(val, 'hex'), decode(encode(val, 'hex'), 'hex') FROM unencoded ORDER BY val
----
00fffe65 [0,␠255,␠254,␠101]
61 a
6162 ab
616263 abc
61626364 abcd
NULL NULL
# hex special case: encoded bytes can be separated by whitespace.
query T
SELECT decode(E'41 42\t43', 'hex')
----
ABC
# Though individual digits within a byte cannot.
query error invalid hexadecimal digit: " "
SELECT decode('a a', 'hex')
query error invalid hexadecimal digit: "x"
SELECT decode('xx', 'hex')
query error invalid hexadecimal data: odd number of digits
SELECT decode('0', 'hex')
# ==> escape format
query TT
SELECT encode(val, 'escape'), decode(encode(val, 'escape'), 'escape') FROM unencoded ORDER BY val
----
\000\377\376e [0,␠255,␠254,␠101]
a a
ab ab
abc abc
abcd abcd
NULL NULL
query error invalid input syntax for type bytea
SELECT decode('\9', 'escape')
# checks https://github.com/MaterializeInc/materialize/issues/11369
query T
SELECT encode('se', 'base64')
----
c2U=
query T
SELECT decode(encode('se', 'base64'), 'base64')
----
se