forked from StarRocks/starrocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_binary_in_nested
More file actions
97 lines (77 loc) · 3.26 KB
/
Copy pathtest_binary_in_nested
File metadata and controls
97 lines (77 loc) · 3.26 KB
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
-- name: test_binary_in_nested
-- Verify that BINARY / VARBINARY data inside nested types (STRUCT / ARRAY / MAP)
-- is serialised as a hex-encoded string rather than raw bytes in the MySQL
-- result set, which keeps the JSON-like output well-formed.
create database db_${uuid0};
use db_${uuid0};
-- -----------------------------------------------------------------------
-- STRUCT with BINARY and VARBINARY fields.
-- Both should appear as lowercase hex; STRING field stays as plain text.
-- -----------------------------------------------------------------------
create table t_struct_binary (
id int,
payload struct<bin_field varbinary, str_field varchar(64)>
) duplicate key(id)
distributed by hash(id)
buckets 1
properties('replication_num'='1');
insert into t_struct_binary
select 1, named_struct('bin_field', unhex('DEADBEEF'), 'str_field', 'hello')
union all
select 2, named_struct('bin_field', unhex('CAFE'), 'str_field', 'world')
union all
select 3, named_struct('bin_field', null, 'str_field', 'null_bin');
select id, payload from t_struct_binary order by id;
-- -----------------------------------------------------------------------
-- ARRAY<VARBINARY>: each element should appear as lowercase hex.
-- -----------------------------------------------------------------------
create table t_array_binary (
id int,
bins array<varbinary>
) duplicate key(id)
distributed by hash(id)
buckets 1
properties('replication_num'='1');
insert into t_array_binary values
(1, [unhex('AABB'), unhex('CCDD')]),
(2, [unhex('00'), null]),
(3, null);
select id, bins from t_array_binary order by id;
-- -----------------------------------------------------------------------
-- MAP<VARCHAR, VARBINARY>: values should appear as lowercase hex.
-- -----------------------------------------------------------------------
create table t_map_binary (
id int,
kv map<varchar(32), varbinary>
) duplicate key(id)
distributed by hash(id)
buckets 1
properties('replication_num'='1');
insert into t_map_binary values
(1, map{'k1': unhex('CAFE'), 'k2': unhex('BABE')}),
(2, map{'only': null});
select id, kv from t_map_binary order by id;
-- -----------------------------------------------------------------------
-- Constant nested literals should also be encoded correctly.
-- Use TO_BINARY(..., 'hex') here so the test stays scoped to VARBINARY output
-- without changing UNHEX() semantics in this PR.
-- -----------------------------------------------------------------------
select [to_binary('AABB', 'hex'), null];
select named_struct('bin_field', to_binary('DEADBEEF', 'hex'), 'arr_field',
[to_binary('00', 'hex'), to_binary('01', 'hex')]);
select map{'k1': to_binary('CAFE', 'hex'), 'k2': null};
set binary_encoding_format = 'base64';
select [to_binary('AABB', 'hex'), null];
set binary_encoding_format = 'hex';
set binary_encoding_level = 'all';
select to_binary('AABB', 'hex');
set binary_encoding_format = 'base64';
select to_binary('AABB', 'hex');
set binary_encoding_format = 'raw';
set binary_encoding_level = 'nested';
select [to_binary('414243', 'hex'), null];
set binary_encoding_level = 'all';
select to_binary('414243', 'hex');
set binary_encoding_format = 'hex';
set binary_encoding_level = 'nested';
drop database db_${uuid0};