Skip to content

Commit 0f245d0

Browse files
committed
Add test
1 parent 16e8c65 commit 0f245d0

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed
Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,56 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
117
package org.apache.spark.sql.catalyst.expressions
218

3-
/**
4-
* Created by hvanhovell on 8/25/16.
5-
*/
6-
class ObjectExpressionSuite {
19+
import org.apache.spark.SparkFunSuite
20+
import org.apache.spark.sql.catalyst.InternalRow
21+
import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
22+
import org.apache.spark.sql.catalyst.util.{ArrayBasedMapData, GenericArrayData}
23+
24+
class ObjectExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
25+
test("MapObjects should make copies of unsafe-backed data") {
26+
// test UnsafeRow-backed data
27+
val structEncoder = ExpressionEncoder[Array[(java.lang.Integer, java.lang.Integer)]]()
28+
val structInputRow = InternalRow.fromSeq(Seq(Array((1, 2), (3, 4))))
29+
val structExpected = new GenericArrayData(
30+
Array(InternalRow.fromSeq(Seq(1, 2)), InternalRow.fromSeq(Seq(3, 4))))
31+
checkEvalutionWithUnsafeProjection(
32+
structEncoder.serializer.head, structExpected, structInputRow)
33+
34+
// test UnsafeArray-backed data
35+
val arrayEncoder = ExpressionEncoder[Array[Array[Int]]]()
36+
val arrayInputRow = InternalRow.fromSeq(Seq(Array(Array(1, 2), Array(3, 4))))
37+
val arrayExpected = new GenericArrayData(
38+
Array(new GenericArrayData(Array(1, 2)), new GenericArrayData(Array(3, 4))))
39+
checkEvalutionWithUnsafeProjection(
40+
arrayEncoder.serializer.head, arrayExpected, arrayInputRow)
741

42+
// test UnsafeMap-backed data
43+
val mapEncoder = ExpressionEncoder[Array[Map[Int, Int]]]()
44+
val mapInputRow = InternalRow.fromSeq(Seq(Array(
45+
Map(1 -> 100, 2 -> 200), Map(3 -> 300, 4 -> 400))))
46+
val mapExpected = new GenericArrayData(Seq(
47+
new ArrayBasedMapData(
48+
new GenericArrayData(Array(1, 2)),
49+
new GenericArrayData(Array(100, 200))),
50+
new ArrayBasedMapData(
51+
new GenericArrayData(Array(3, 4)),
52+
new GenericArrayData(Array(300, 400)))))
53+
checkEvalutionWithUnsafeProjection(
54+
mapEncoder.serializer.head, mapExpected, mapInputRow)
55+
}
856
}

0 commit comments

Comments
 (0)