Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing empty input to getMapValue crashing #9262

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
hyperbolic2346 marked this conversation as resolved.
Show resolved Hide resolved
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