Skip to content

Commit e255873

Browse files
committed
Add GeneratorSuite.
1 parent fcfccee commit e255873

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
*/
17+
18+
package org.apache.spark.sql.catalyst.expressions
19+
20+
import org.apache.spark.SparkFunSuite
21+
import org.apache.spark.sql.catalyst.InternalRow
22+
import org.apache.spark.unsafe.types.UTF8String
23+
24+
class GeneratorSuite extends SparkFunSuite with ExpressionEvalHelper {
25+
private def checkTuple(actual: ExplodeBase, expected: Seq[InternalRow]): Unit = {
26+
assert(actual.eval(null).toSeq === expected)
27+
}
28+
29+
private final val int_array = Seq(1, 2, 3)
30+
private final val str_array = Seq("a", "b", "c")
31+
32+
test("explode") {
33+
val int_correct_answer = Seq(Seq(1), Seq(2), Seq(3))
34+
val str_correct_answer = Seq(
35+
Seq(UTF8String.fromString("a")),
36+
Seq(UTF8String.fromString("b")),
37+
Seq(UTF8String.fromString("c")))
38+
39+
checkTuple(
40+
Explode(CreateArray(int_array.map(Literal(_)))),
41+
int_correct_answer.map(InternalRow.fromSeq(_)))
42+
43+
checkTuple(
44+
Explode(CreateArray(str_array.map(Literal(_)))),
45+
str_correct_answer.map(InternalRow.fromSeq(_)))
46+
}
47+
48+
test("posexplode") {
49+
val int_correct_answer = Seq(Seq(0, 1), Seq(1, 2), Seq(2, 3))
50+
val str_correct_answer = Seq(
51+
Seq(0, UTF8String.fromString("a")),
52+
Seq(1, UTF8String.fromString("b")),
53+
Seq(2, UTF8String.fromString("c")))
54+
55+
checkTuple(
56+
PosExplode(CreateArray(int_array.map(Literal(_)))),
57+
int_correct_answer.map(InternalRow.fromSeq(_)))
58+
59+
checkTuple(
60+
PosExplode(CreateArray(str_array.map(Literal(_)))),
61+
str_correct_answer.map(InternalRow.fromSeq(_)))
62+
}
63+
}

0 commit comments

Comments
 (0)