From ef5ba4cee31a5f335314b5ceec9d0db473aef7a0 Mon Sep 17 00:00:00 2001 From: Mike Wilson Date: Wed, 22 Sep 2021 14:31:11 -0400 Subject: [PATCH] Fixing empty input to getMapValue crashing (#9262) 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: https://github.com/rapidsai/cudf/pull/9262 --- java/src/main/native/src/map_lookup.cu | 6 +++++- .../test/java/ai/rapids/cudf/ColumnVectorTest.java | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/java/src/main/native/src/map_lookup.cu b/java/src/main/native/src/map_lookup.cu index ad791747713..683651799e7 100644 --- a/java/src/main/native/src/map_lookup.cu +++ b/java/src/main/native/src/map_lookup.cu @@ -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. @@ -183,6 +183,10 @@ std::unique_ptr 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. diff --git a/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java b/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java index 0643776a546..d1af0d9a2f6 100644 --- a/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java +++ b/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java @@ -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 list1 = Arrays.asList(new HostColumnVector.StructData("a", "b"));