@@ -21,13 +21,17 @@ import java.nio.ByteBuffer
21
21
import java .nio .charset .StandardCharsets
22
22
import java .sql .Date
23
23
import java .sql .Time
24
+ import java .util .Optional
24
25
25
26
import scala .collection .JavaConverters ._
26
27
27
28
import io .trino .client .ClientStandardTypes ._
28
29
import io .trino .client .ClientTypeSignature
30
+ import io .trino .client .ClientTypeSignatureParameter
29
31
import io .trino .client .Column
32
+ import io .trino .client .NamedClientTypeSignature
30
33
import io .trino .client .Row
34
+ import io .trino .client .RowFieldName
31
35
import org .apache .hive .service .rpc .thrift .TProtocolVersion
32
36
33
37
import org .apache .kyuubi .KyuubiFunSuite
@@ -38,6 +42,28 @@ class RowSetSuite extends KyuubiFunSuite {
38
42
39
43
final private val UUID_PREFIX = " 486bb66f-1206-49e3-993f-0db68f3cd8"
40
44
45
+ lazy val arrayTypeSignature : ClientTypeSignature = new ClientTypeSignature (
46
+ ARRAY ,
47
+ List (ClientTypeSignatureParameter .ofType(new ClientTypeSignature (DOUBLE ))).asJava)
48
+
49
+ lazy val mapTypeSignature : ClientTypeSignature = new ClientTypeSignature (
50
+ MAP ,
51
+ List (
52
+ ClientTypeSignatureParameter .ofType(new ClientTypeSignature (INTEGER )),
53
+ ClientTypeSignatureParameter .ofType(new ClientTypeSignature (DOUBLE ))).asJava)
54
+
55
+ lazy val rowTypeSignature : ClientTypeSignature = new ClientTypeSignature (
56
+ ROW ,
57
+ List (
58
+ ClientTypeSignatureParameter .ofNamedType(
59
+ new NamedClientTypeSignature (
60
+ Optional .of(new RowFieldName (" foo" )),
61
+ new ClientTypeSignature (VARCHAR ))),
62
+ ClientTypeSignatureParameter .ofNamedType(
63
+ new NamedClientTypeSignature (
64
+ Optional .of(new RowFieldName (" bar" )),
65
+ mapTypeSignature))).asJava)
66
+
41
67
def genRow (value : Int ): List [_] = {
42
68
val boolVal = value % 3 match {
43
69
case 0 => true
@@ -61,7 +87,9 @@ class RowSetSuite extends KyuubiFunSuite {
61
87
val arrVal = Array .fill(value)(doubleVal).toList.asJava
62
88
val mapVal = Map (value -> doubleVal).asJava
63
89
val jsonVal = s """ {" $value": $value} """
64
- val rowVal = Row .builder().addField(value.toString, value).build()
90
+ val rowVal = Row .builder()
91
+ .addField(" " , value.toString)
92
+ .addField(" " , mapVal).build()
65
93
val ipVal = s " ${value}. ${value}. ${value}. ${value}"
66
94
val uuidVal = java.util.UUID .fromString(
67
95
s " $UUID_PREFIX${uuidSuffix(value)}" )
@@ -106,16 +134,20 @@ class RowSetSuite extends KyuubiFunSuite {
106
134
column(" m" , VARBINARY ),
107
135
column(" n" , VARCHAR ),
108
136
column(" o" , CHAR ),
109
- column(" p" , ROW ),
110
- column(" q" , ARRAY ),
111
- column(" r" , MAP ),
137
+ column(" p" , ROW , rowTypeSignature ),
138
+ column(" q" , ARRAY , arrayTypeSignature ),
139
+ column(" r" , MAP , mapTypeSignature ),
112
140
column(" s" , JSON ),
113
141
column(" t" , IPADDRESS ),
114
142
column(" u" , UUID ))
115
143
116
144
private val rows : Seq [List [_]] = (0 to 10 ).map(genRow) ++ Seq (List .fill(21 )(null ))
117
145
118
- def column (name : String , tp : String ): Column = new Column (name, tp, new ClientTypeSignature (tp))
146
+ def column (name : String , tp : String ): Column = column(name, tp, new ClientTypeSignature (tp))
147
+
148
+ def column (name : String , tp : String , signature : ClientTypeSignature ): Column = {
149
+ new Column (name, tp, signature)
150
+ }
119
151
120
152
def uuidSuffix (value : Int ): String = if (value > 9 ) value.toString else s " f $value"
121
153
@@ -164,7 +196,7 @@ class RowSetSuite extends KyuubiFunSuite {
164
196
dateCol.getValues.asScala.zipWithIndex.foreach {
165
197
case (b, 11 ) => assert(b.isEmpty)
166
198
case (b, i) =>
167
- assert(b === toHiveString(( Date .valueOf(s " 2018-11- ${i + 1 }" ), DATE )))
199
+ assert(b === toHiveString(Date .valueOf(s " 2018-11- ${i + 1 }" ), new ClientTypeSignature ( DATE )))
168
200
}
169
201
170
202
val decCol = cols.next().getStringVal
@@ -200,7 +232,8 @@ class RowSetSuite extends KyuubiFunSuite {
200
232
val timeCol = cols.next().getStringVal
201
233
timeCol.getValues.asScala.zipWithIndex.foreach {
202
234
case (b, 11 ) => assert(b.isEmpty)
203
- case (b, i) => assert(b === toHiveString((Time .valueOf(s " 13:33: ${i + 1 }" ), TIME )))
235
+ case (b, i) => assert(b ===
236
+ toHiveString(Time .valueOf(s " 13:33: ${i + 1 }" ), new ClientTypeSignature (TIME )))
204
237
}
205
238
206
239
val binCol = cols.next().getBinaryVal
@@ -224,43 +257,48 @@ class RowSetSuite extends KyuubiFunSuite {
224
257
val rowCol = cols.next().getStringVal
225
258
rowCol.getValues.asScala.zipWithIndex.foreach {
226
259
case (b, 11 ) => assert(b.isEmpty)
227
- case (b, i) => assert(b ===
228
- toHiveString((Row .builder().addField(i.toString, i).build(), ROW )))
260
+ case (b, i) => assert(b === toHiveString(
261
+ Row .builder().addField(" " , i.toString).addField(
262
+ " " ,
263
+ Map (i -> java.lang.Double .valueOf(s " $i. $i" )).asJava).build(),
264
+ rowTypeSignature))
229
265
}
230
266
231
267
val arrCol = cols.next().getStringVal
232
268
arrCol.getValues.asScala.zipWithIndex.foreach {
233
269
case (b, 11 ) => assert(b === " " )
234
270
case (b, i) => assert(b === toHiveString(
235
- (Array .fill(i)(java.lang.Double .valueOf(s " $i. $i" )).toList.asJava, ARRAY )))
271
+ Array .fill(i)(java.lang.Double .valueOf(s " $i. $i" )).toList.asJava,
272
+ arrayTypeSignature))
236
273
}
237
274
238
275
val mapCol = cols.next().getStringVal
239
276
mapCol.getValues.asScala.zipWithIndex.foreach {
240
277
case (b, 11 ) => assert(b === " " )
241
278
case (b, i) => assert(b === toHiveString(
242
- (Map (i -> java.lang.Double .valueOf(s " $i. $i" )).asJava, MAP )))
279
+ Map (i -> java.lang.Double .valueOf(s " $i. $i" )).asJava,
280
+ mapTypeSignature))
243
281
}
244
282
245
283
val jsonCol = cols.next().getStringVal
246
284
jsonCol.getValues.asScala.zipWithIndex.foreach {
247
285
case (b, 11 ) => assert(b === " " )
248
286
case (b, i) => assert(b ===
249
- toHiveString(( s """ {" $i": $i} """ , JSON )))
287
+ toHiveString(s """ {" $i": $i} """ , new ClientTypeSignature ( JSON )))
250
288
}
251
289
252
290
val ipCol = cols.next().getStringVal
253
291
ipCol.getValues.asScala.zipWithIndex.foreach {
254
292
case (b, 11 ) => assert(b === " " )
255
293
case (b, i) => assert(b ===
256
- toHiveString(( s " ${i}. ${i}. ${i}. ${i}" , IPADDRESS )))
294
+ toHiveString(s " ${i}. ${i}. ${i}. ${i}" , new ClientTypeSignature ( IPADDRESS )))
257
295
}
258
296
259
297
val uuidCol = cols.next().getStringVal
260
298
uuidCol.getValues.asScala.zipWithIndex.foreach {
261
299
case (b, 11 ) => assert(b === " " )
262
300
case (b, i) => assert(b ===
263
- toHiveString(( s " $UUID_PREFIX${uuidSuffix(i)}" , UUID )))
301
+ toHiveString(s " $UUID_PREFIX${uuidSuffix(i)}" , new ClientTypeSignature ( UUID )))
264
302
}
265
303
}
266
304
@@ -308,10 +346,12 @@ class RowSetSuite extends KyuubiFunSuite {
308
346
assert(r9.get(14 ).getStringVal.getValue === String .format(s " %10s " , 8 .toString))
309
347
310
348
val r10 = iter.next().getColVals
349
+ val mapStr =
350
+ Map (9 -> 9.9d ).map { case (key, value) => s " $key: $value" }.toSeq.mkString(" {" , " ," , " }" )
311
351
assert(r10.get(15 ).getStringVal.getValue ===
312
- toHiveString(( Row .builder().addField( 9 .toString, 9 ).build(), ROW ) ))
352
+ String .format( " {foo= \" %s \" ,bar=%s} " , " 9 " , mapStr ))
313
353
assert(r10.get(16 ).getStringVal.getValue === Array .fill(9 )(9.9d ).mkString(" [" , " ," , " ]" ))
314
- assert(r10.get(17 ).getStringVal.getValue === toHiveString(( Map ( 9 -> 9.9d ).asJava, MAP )) )
354
+ assert(r10.get(17 ).getStringVal.getValue === mapStr )
315
355
assert(r10.get(18 ).getStringVal.getValue === " {\" 9\" : 9}" )
316
356
assert(r10.get(19 ).getStringVal.getValue === " 9.9.9.9" )
317
357
assert(r10.get(20 ).getStringVal.getValue === s " $UUID_PREFIX${uuidSuffix(9 )}" )
0 commit comments