Skip to content

Commit

Permalink
Fixing empty input to getMapValue crashing (#9262)
Browse files Browse the repository at this point in the history
This changes the calls in java/cudf to check for an empty input and return an empty result instead of crashing.

Fixes #9253

Authors:
  - Mike Wilson (https://github.com/hyperbolic2346)

Approvers:
  - Jason Lowe (https://github.com/jlowe)

URL: #9262
  • Loading branch information
hyperbolic2346 authored Sep 22, 2021
1 parent 20a04bc commit ef5ba4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion java/src/main/native/src/map_lookup.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -183,6 +183,10 @@ std::unique_ptr<column> map_lookup(column_view const &map_column, string_scalar
// Defensive checks.
map_input_check(map_column, stream);

if (map_column.size() == 0) {
return make_empty_column(cudf::data_type{cudf::type_id::STRING});
}

lists_column_view lcv{map_column};
column_view structs_column = lcv.get_sliced_child(stream);
// Two-pass plan: construct gather map, and then gather() on structs_column.child(1). Plan A.
Expand Down
11 changes: 11 additions & 0 deletions java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5412,6 +5412,17 @@ void testGetMapValue() {
}
}

@Test
void testGetMapValueEmptyInput() {
HostColumnVector.StructType structType = new HostColumnVector.StructType(true, Arrays.asList(new HostColumnVector.BasicType(true, DType.STRING),
new HostColumnVector.BasicType(true, DType.STRING)));
try (ColumnVector cv = ColumnVector.fromLists(new HostColumnVector.ListType(true, structType));
ColumnVector res = cv.getMapValue(Scalar.fromString("a"));
ColumnVector expected = ColumnVector.fromStrings()) {
assertColumnsAreEqual(expected, res);
}
}

@Test
void testGetMapKeyExistence() {
List<HostColumnVector.StructData> list1 = Arrays.asList(new HostColumnVector.StructData("a", "b"));
Expand Down

0 comments on commit ef5ba4c

Please sign in to comment.