-
Notifications
You must be signed in to change notification settings - Fork 984
/
TestComplexTypeReader.java
237 lines (193 loc) · 7.42 KB
/
TestComplexTypeReader.java
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.drill.exec.vector.complex.writer;
import org.apache.drill.BaseTestQuery;
import org.junit.Test;
public class TestComplexTypeReader extends BaseTestQuery{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestComplexTypeReader.class);
@Test
// Repeated map (map) -> json.
public void testX() throws Exception{
test("select convert_to(z[0], 'JSON') from cp.`jsoninput/input2.json`;");
}
@Test
//map -> json.
public void testX2() throws Exception{
test("select convert_to(x, 'JSON') from cp.`jsoninput/input2.json`;");
}
@Test
//Map (mapfield) -> json.
public void testX3() throws Exception{
test("select convert_to(tbl.x.y, 'JSON') from cp.`jsoninput/input2.json` tbl;");
}
@Test
//float value -> json
public void testX4() throws Exception{
test("select convert_to(`float`, 'JSON') from cp.`jsoninput/input2.json`;");
}
@Test
//integer value -> json
public void testX5() throws Exception{
test("select convert_to(`integer`, 'JSON') from cp.`jsoninput/input2.json`;");
}
@Test
// repeated map -> json.
public void testX6() throws Exception{
test("select convert_to(z, 'JSON') from cp.`jsoninput/input2.json`;");
}
@Test
//repeated list (Repeated BigInt) -> json
public void testX7() throws Exception{
test("select convert_to(rl[1], 'JSON') from cp.`jsoninput/input2.json`;");
}
@Test
//repeated list (Repeated BigInt) -> json
public void testX8() throws Exception{
test("select convert_to(rl[0][1], 'JSON') from cp.`jsoninput/input2.json`;");
}
@Test
//repeated list -> json
public void testX9() throws Exception{
test("select convert_to(rl, 'JSON') from cp.`jsoninput/input2.json`;");
}
@Test
public void testY() throws Exception{
test("select z[0] from cp.`jsoninput/input2.json`;");
}
@Test
public void testY2() throws Exception{
test("select x from cp.`jsoninput/input2.json`;");
}
@Test
public void testY3() throws Exception{
test("select tbl.x.y from cp.`jsoninput/input2.json` tbl;");
}
@Test
public void testY6() throws Exception{
test("select z from cp.`jsoninput/input2.json`;");
}
@Test
//repeated list (Repeated BigInt)
public void testZ() throws Exception{
test("select rl[1] from cp.`jsoninput/input2.json`;");
}
@Test
//repeated list (Repeated BigInt ( BigInt) ) )
public void testZ1() throws Exception{
test("select rl[0][1] from cp.`jsoninput/input2.json`;");
}
@Test
//repeated list (Repeated BigInt ( BigInt) ) ). The first index is out of boundary
public void testZ2() throws Exception{
test("select rl[1000][1] from cp.`jsoninput/input2.json`;");
}
@Test
//repeated list (Repeated BigInt ( BigInt) ) ). The second index is out of boundary
public void testZ3() throws Exception{
test("select rl[0][1000] from cp.`jsoninput/input2.json`;");
}
@Test
//repeated list. The repeated list is asked for twice, hence requires copying (evaluation in ProjectRecordBatch)
public void testZ4() throws Exception{
test("select rl, rl from cp.`jsoninput/input2.json`;");
}
@Test
//repeated map --> Json. It will go beyond the buffer of size 256 allocated in setup.
public void testA0() throws Exception{
test(" select convert_to(types, 'JSON') from cp.`jsoninput/vvtypes.json`;");
}
@Test
//repeated map (map) --> Json.
public void testA1() throws Exception{
test(" select convert_to(types[1], 'JSON') from cp.`jsoninput/vvtypes.json`;");
}
@Test
//repeated map (map (repeated map) ) --> Json.
public void testA2() throws Exception{
test(" select convert_to(types[1].minor, 'JSON') from cp.`jsoninput/vvtypes.json`;");
}
@Test
//repeated map (map( repeated map (map (varchar)))) --> Json.
public void testA3() throws Exception{
test(" select convert_to(types[1].minor[0].valueHolder, 'JSON') from cp.`jsoninput/vvtypes.json`;");
}
@Test
//Two complex type functions in SELECT clause : repeated map (map) --> Json,
public void testA4() throws Exception{
test(" select convert_to(types[1], 'JSON'), convert_to(modes[2], 'JSON') from cp.`jsoninput/vvtypes.json`;");
}
@Test
//repeated map (map) .
public void testB1() throws Exception{
test(" select types[1] from cp.`jsoninput/vvtypes.json`;");
}
@Test
//repeated map (map (repeated map) ).
public void testB2() throws Exception{
test(" select types[1].minor from cp.`jsoninput/vvtypes.json`;");
}
@Test
//repeated map (map( repeated map (map (varchar)))).
public void testB3() throws Exception{
test(" select types[1].minor[0].valueholder from cp.`jsoninput/vvtypes.json`;");
}
@Test // DRILL-1250
//repeated scalar values evaluation.
public void test_repeatedList() throws Exception{
test("select l, l from cp.`jsoninput/input2.json`;");
}
@Test
public void testKeyValueGen() throws Exception {
test("select kvgen(x) from cp.`jsoninput/input2.json`");
test("select kvgen(bigintegercol), kvgen(float8col) from cp.`jsoninput/input3.json`");
}
@Test
// Functions tests kvgen functionality where the 'value' part of the map is complex
public void testKVGenWithComplexValues() throws Exception {
// test where 'value' is a list of integers
test("select kvgen(a) from cp.`jsoninput/kvgen_complex_input.json`");
// test where 'value' is a repeated list of floats
test("select kvgen(c) from cp.`jsoninput/kvgen_complex_input.json`");
// test where 'value' is a map
test("select kvgen(e) from cp.`jsoninput/kvgen_complex_input.json`");
// test where 'value' is a repeated list of maps
test("select kvgen(i) from cp.`jsoninput/kvgen_complex_input.json`");
// test where 'value' is a map that contains a list
test("select kvgen(m) from cp.`jsoninput/kvgen_complex_input.json`");
// test where 'value' is a map that contains a map
test("select kvgen(p) from cp.`jsoninput/kvgen_complex_input.json`");
}
@Test
// Test SplitUpComplexExpressions rule which splits complex expression into multiple projects
public void testComplexAndSimpleColumnSelection() throws Exception {
test("select t.a.b, kvgen(t.a.c) from cp.`jsoninput/input4.json` t");
}
@Test
public void testNestedFlatten() throws Exception {
test("select flatten(rl) from cp.`jsoninput/input2.json`");
}
@Test //DRILL-2872.
public void testRepeatedJson() throws Exception {
final String query="select cast(convert_to(interests, 'JSON') as varchar(0)) as interests from dfs.`/Users/pchandra/work/data/test/complex_student.json`";
testBuilder()
.sqlQuery(query)
.unOrdered()
.jsonBaselineFile("drill-2872-result.json")
.go();
}
}