Skip to content

Commit 1407498

Browse files
committed
fix: support map_keys
1 parent e19d937 commit 1407498

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

native/core/src/execution/planner.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3082,9 +3082,6 @@ mod tests {
30823082
let (mut scans, datafusion_plan) =
30833083
planner.create_plan(&projection, &mut vec![], 1).unwrap();
30843084

3085-
// Feed the data into plan
3086-
//scans[0].set_input_batch(input_batch);
3087-
30883085
// Start executing the plan in a separate thread
30893086
// The plan waits for incoming batches and emitting result as input comes
30903087
let mut stream = datafusion_plan.native_plan.execute(0, task_ctx).unwrap();
@@ -3240,11 +3237,11 @@ mod tests {
32403237
select map(named_struct('a', 1, 'b', 'n', 'c', 'x'), named_struct('a', 1, 'b', 'n', 'c', 'x')) m
32413238
*/
32423239
#[tokio::test]
3243-
async fn test_nested_types_map_keys_by_index() -> Result<(), DataFusionError> {
3240+
async fn test_nested_types_map_keys() -> Result<(), DataFusionError> {
32443241
let session_ctx = SessionContext::new();
32453242

32463243
// generate test data in the temp folder
3247-
let test_data = "select map([named_struct('a', 1, 'b', 'n', 'c', 'x')], [named_struct('a', 1, 'b', 'n', 'c', 'x')]) c0";
3244+
let test_data = "select map([named_struct('a', 1, 'b', 'n', 'c', 'x')], [named_struct('a', 2, 'b', 'm', 'c', 'y')]) c0";
32483245
let tmp_dir = TempDir::new()?;
32493246
let test_path = tmp_dir.path().to_str().unwrap().to_string();
32503247

@@ -3254,7 +3251,7 @@ mod tests {
32543251
.create_physical_plan()
32553252
.await?;
32563253

3257-
// Write parquet file into temp folder
3254+
// Write a parquet file into temp folder
32583255
session_ctx
32593256
.write_parquet(plan, test_path.clone(), None)
32603257
.await?;
@@ -3334,7 +3331,7 @@ mod tests {
33343331
"+------------------------------+",
33353332
"| c0 |",
33363333
"+------------------------------+",
3337-
"| {{b: n}: {a: 1, b: n, c: x}} |",
3334+
"| {{b: n}: {a: 2, b: m, c: y}} |",
33383335
"+------------------------------+",
33393336
];
33403337
assert_batches_eq!(expected, &[actual.clone()]);

spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,7 @@ object QueryPlanSerde extends Logging with CometExprShim {
20472047
case mk: MapKeys =>
20482048
val childExpr = exprToProtoInternal(mk.child, inputs, binding)
20492049
scalarFunctionExprToProto("map_keys", childExpr)
2050+
// commented out because of correctness issue https://github.com/apache/datafusion-comet/issues/1789
20502051
// case mv: MapValues =>
20512052
// val childExpr = exprToProtoInternal(mv.child, inputs, binding)
20522053
// scalarFunctionExprToProto("map_values", childExpr)

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,25 +304,30 @@ class CometNativeReaderSuite extends CometTestBase with AdaptiveSparkPlanHelper
304304
"select c0[0].a, c0[0].a from tbl")
305305
}
306306

307-
test("native reader - select nested field from a complex map key using map_keys") {
307+
test("native reader - select nested field from a complex map[struct, struct] using map_keys") {
308308
testSingleLineQuery(
309309
"""
310-
| select map(str0, str0) c0 from
310+
| select map(str0, str1) c0 from
311311
| (
312-
| select named_struct('a', cast(1 as long), 'b', cast(2 as long), 'c', cast(3 as long)) str0 union all
313-
| select named_struct('a', cast(3 as long), 'b', cast(4 as long), 'c', cast(5 as long)) str0
312+
| select named_struct('a', cast(1 as long), 'b', cast(2 as long), 'c', cast(3 as long)) str0,
313+
| named_struct('x', cast(8 as long), 'y', cast(9 as long), 'z', cast(0 as long)) str1 union all
314+
| select named_struct('a', cast(3 as long), 'b', cast(4 as long), 'c', cast(5 as long)) str0,
315+
| named_struct('x', cast(6 as long), 'y', cast(7 as long), 'z', cast(8 as long)) str1
314316
| )
315317
|""".stripMargin,
316318
"select map_keys(c0).b from tbl")
317319
}
318320

319-
// test("native reader - select nested field from a complex map key using map_values") {
321+
// commented out because of correctness issue https://github.com/apache/datafusion-comet/issues/1789
322+
// test("native reader - select nested field from a complex map[struct, struct] using map_values") {
320323
// testSingleLineQuery(
321324
// """
322-
// | select map(str0, str0) c0 from
325+
// | select map(str0, str1) c0 from
323326
// | (
324-
// | select named_struct('a', cast(1 as long), 'b', cast(2 as long), 'c', cast(3 as long)) str0 union all
325-
// | select named_struct('a', cast(3 as long), 'b', cast(4 as long), 'c', cast(5 as long)) str0
327+
// | select named_struct('a', cast(1 as long), 'b', cast(2 as long), 'c', cast(3 as long)) str0,
328+
// | named_struct('x', cast(8 as long), 'y', cast(9 as long), 'z', cast(0 as long)) str1 union all
329+
// | select named_struct('a', cast(3 as long), 'b', cast(4 as long), 'c', cast(5 as long)) str0,
330+
// | named_struct('x', cast(6 as long), 'y', cast(7 as long), 'z', cast(8 as long)) str1
326331
// | )
327332
// |""".stripMargin,
328333
// "select map_values(c0).b from tbl")

0 commit comments

Comments
 (0)