Skip to content

Commit a723974

Browse files
authored
feat: Add more test for nested types combinations (#1632)
1 parent f4bde1c commit a723974

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

spark/src/test/scala/org/apache/comet/exec/CometNativeReaderSuite.scala

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,96 @@ class CometNativeReaderSuite extends CometTestBase with AdaptiveSparkPlanHelper
143143
|""".stripMargin,
144144
"select c0 from tbl")
145145
}
146+
147+
test("native reader - read MAP of value ARRAY fields") {
148+
testSingleLineQuery(
149+
"""
150+
|select map('a', array(1), 'c', array(3)) as c0 union all
151+
|select map('b', array(2))
152+
|""".stripMargin,
153+
"select c0 from tbl")
154+
}
155+
156+
test("native reader - read MAP of value STRUCT fields") {
157+
testSingleLineQuery(
158+
"""
159+
|select map('a', named_struct('f0', 0, 'f1', 'foo'), 'b', named_struct('f0', 1, 'f1', 'bar')) as c0 union all
160+
|select map('c', named_struct('f2', 0, 'f1', 'baz')) as c0
161+
|""".stripMargin,
162+
"select c0 from tbl")
163+
}
164+
165+
test("native reader - read MAP of value MAP fields") {
166+
testSingleLineQuery(
167+
"""
168+
|select map('a', map('a1', 1, 'b1', 2), 'b', map('a2', 2, 'b2', 3)) as c0 union all
169+
|select map('c', map('a3', 3, 'b3', 4))
170+
|""".stripMargin,
171+
"select c0 from tbl")
172+
}
173+
174+
/*
175+
org.apache.spark.SparkException: Job aborted due to stage failure: Task 1 in stage 171.0 failed 1 times, most recent failure:
176+
Lost task 1.0 in stage 171.0 (TID 179) (knode0099.cngya03.pie.silu.net executor driver): org.apache.comet.CometNativeException: called `Result::unwrap()`
177+
on an `Err` value: InvalidArgumentError("Incorrect datatype for StructArray field \"m0\", expected Map(Field { name: \"entries\",
178+
data_type: Struct([Field { name: \"key\", data_type: Utf8, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} },
179+
Field { name: \"value\", data_type: Int32, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }]),
180+
nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, false) got Map(Field { name: \"entries\", d
181+
ata_type: Struct([Field { name: \"key\", data_type: Utf8, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} },
182+
Field { name: \"value\", data_type: Int32, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, false)")
183+
184+
*/
185+
ignore("native reader - read STRUCT of MAP fields") {
186+
testSingleLineQuery(
187+
"""
188+
|select named_struct('m0', map('a', 1)) as c0 union all
189+
|select named_struct('m1', map('b', 2))
190+
|""".stripMargin,
191+
"select c0 from tbl")
192+
}
193+
194+
test("native reader - read ARRAY of MAP fields") {
195+
testSingleLineQuery(
196+
"""
197+
|select array(map('a', 1), map('b', 2)) as c0 union all
198+
|select array(map('c', 3))
199+
|""".stripMargin,
200+
"select c0 from tbl")
201+
}
202+
203+
test("native reader - read ARRAY of MAP of ARRAY value fields") {
204+
testSingleLineQuery(
205+
"""
206+
|select array(map('a', array(1, 2, 3), 'b', array(2, 3, 4)), map('c', array(4, 5, 6), 'd', array(7, 8, 9))) as c0 union all
207+
|select array(map('x', array(1, 2, 3), 'y', array(2, 3, 4)), map('c', array(4, 5, 6), 'z', array(7, 8, 9)))
208+
|""".stripMargin,
209+
"select c0 from tbl")
210+
}
211+
212+
test("native reader - read STRUCT of MAP of STRUCT value fields") {
213+
testSingleLineQuery(
214+
"""
215+
|select named_struct('m0', map('a', named_struct('f0', 1)), 'm1', map('b', named_struct('f1', 1))) as c0 union all
216+
|select named_struct('m0', map('c', named_struct('f2', 1)), 'm1', map('d', named_struct('f3', 1))) as c0
217+
|""".stripMargin,
218+
"select c0 from tbl")
219+
}
220+
221+
test("native reader - read MAP of ARRAY of MAP fields") {
222+
testSingleLineQuery(
223+
"""
224+
|select map('a', array(map(1, 'a', 2, 'b'), map(1, 'a', 2, 'b'))) as c0 union all
225+
|select map('b', array(map(1, 'a', 2, 'b'), map(1, 'a', 2, 'b'))) as c0
226+
|""".stripMargin,
227+
"select c0 from tbl")
228+
}
229+
230+
test("native reader - read MAP of STRUCT of MAP fields") {
231+
testSingleLineQuery(
232+
"""
233+
|select map('a', named_struct('f0', map(1, 'b')), 'b', named_struct('f0', map(1, 'b'))) as c0 union all
234+
|select map('c', named_struct('f0', map(1, 'b'))) as c0
235+
|""".stripMargin,
236+
"select c0 from tbl")
237+
}
146238
}

0 commit comments

Comments
 (0)