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

Replace message parsing with throwing more specific exceptions #12426

Merged
merged 27 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
02aba24
Update concatenate.
vyasr Dec 19, 2022
d06315f
Changes for lists.py.
vyasr Dec 19, 2022
e5e4b43
Fix cases in string.py.
vyasr Dec 19, 2022
f3a12eb
Fix error.
vyasr Dec 19, 2022
9a9f5ac
Add support for a custom exception handler.
vyasr Feb 6, 2023
deaf060
Add new dtype_error and support it in Python.
vyasr Feb 6, 2023
4cd3acd
Fix copyrights.
vyasr Feb 6, 2023
65c7f1f
Use dtype errors for type/scale issues in lists.
vyasr Feb 6, 2023
88ac435
Make dtype_error a std::logic_error instead of a std::runtime_error.
vyasr Feb 6, 2023
ea7a94a
Remove unnecessary extra includes.
vyasr Feb 6, 2023
160a57d
Add missing exception handlers.
vyasr Feb 6, 2023
e04b0bd
Add Java mapping for dtype_error.
vyasr Feb 6, 2023
ed978aa
Update developer documentation.
vyasr Feb 6, 2023
336282b
Fix bug in JNI mapping.
vyasr Feb 6, 2023
ccdd557
Change dtype_error to inherit from std::invalid_argument.
vyasr Feb 6, 2023
96294dc
Update EXPECT_THROWs in C++ tests.
vyasr Feb 7, 2023
fa1ad10
Fix remaining tests.
vyasr Feb 7, 2023
586dd76
Document all new throws.
vyasr Feb 7, 2023
bdc5ef8
Merge branch 'branch-23.04' into feat/no_message_parsing
vyasr Feb 7, 2023
8bd8a7f
Merge remote-tracking branch 'origin/branch-23.04' into feat/no_messa…
vyasr Feb 23, 2023
82dbaa1
Rename dtype_error to data_type_error and fix all stdexcept includes.
vyasr Feb 23, 2023
bb9d5b3
Address remaining C++ reviews.
vyasr Feb 23, 2023
4f456aa
Move exception handler from _lib/cpp to _lib.
vyasr Feb 23, 2023
f935728
Update cpp/include/cudf/utilities/error.hpp
vyasr Feb 23, 2023
491557b
Remove outdated throw messages.
vyasr Feb 24, 2023
6ffcc8a
Merge remote-tracking branch 'origin/branch-23.04' into feat/no_messa…
vyasr Feb 24, 2023
7b5131b
Merge branch 'branch-23.04' into feat/no_message_parsing
vyasr Feb 25, 2023
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
5 changes: 4 additions & 1 deletion cpp/include/cudf/binaryop.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022, NVIDIA CORPORATION.
* Copyright (c) 2019-2023, 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 @@ -108,6 +108,7 @@ enum class binary_operator : int32_t {
* @throw cudf::logic_error if @p output_type dtype isn't fixed-width
* @throw cudf::logic_error if @p output_type dtype isn't boolean for comparison and logical
* operations.
* @throw cudf::data_type_error if the operation is not supported for the types of @p lhs and @p rhs
*/
std::unique_ptr<column> binary_operation(
scalar const& lhs,
Expand Down Expand Up @@ -136,6 +137,7 @@ std::unique_ptr<column> binary_operation(
* @throw cudf::logic_error if @p output_type dtype isn't fixed-width
* @throw cudf::logic_error if @p output_type dtype isn't boolean for comparison and logical
* operations.
* @throw cudf::data_type_error if the operation is not supported for the types of @p lhs and @p rhs
*/
std::unique_ptr<column> binary_operation(
column_view const& lhs,
Expand Down Expand Up @@ -163,6 +165,7 @@ std::unique_ptr<column> binary_operation(
* @throw cudf::logic_error if @p output_type dtype isn't boolean for comparison and logical
* operations.
* @throw cudf::logic_error if @p output_type dtype isn't fixed-width
* @throw cudf::data_type_error if the operation is not supported for the types of @p lhs and @p rhs
*/
std::unique_ptr<column> binary_operation(
column_view const& lhs,
Expand Down
10 changes: 5 additions & 5 deletions cpp/include/cudf/concatenate.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, NVIDIA CORPORATION.
* Copyright (c) 2020-2023, 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 @@ -50,8 +50,8 @@ rmm::device_buffer concatenate_masks(
/**
* @brief Concatenates multiple columns into a single column.
*
* @throws cudf::logic_error
* If types of the input columns mismatch
* @throws cudf::logic_error If types of the input columns mismatch
* @throws std::overflow_error If the the total number of output rows exceeds cudf::size_type
*
* @param columns_to_concat host_span of column views to be concatenated into a single column
* @param mr Device memory resource used to allocate the returned column's device memory
Expand Down Expand Up @@ -80,8 +80,8 @@ std::unique_ptr<column> concatenate(
* column_view tc1 = (t->view()).column(1); //Contains {0,1,2,3,4,5,6,7}
* ```
*
* @throws cudf::logic_error
* If number of columns mismatch
* @throws cudf::logic_error If number of columns mismatch
* @throws std::overflow_error If the the total number of output rows exceeds cudf::size_type
*
* @param tables_to_concat host_span of table views to be concatenated into a single table
* @param mr Device memory resource used to allocate the returned table's device memory
Expand Down
8 changes: 4 additions & 4 deletions cpp/include/cudf/lists/combine.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, NVIDIA CORPORATION.
* Copyright (c) 2021-2023, 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 @@ -80,10 +80,10 @@ std::unique_ptr<column> concatenate_rows(
* r is [ {1, 2, 3, 4, 5}, {6, 7, 8, 9} ]
* @endcode
*
* @throws cudf::logic_error if the input column is not at least two-level depth lists column (i.e.,
* each row must be a list of list).
* @throws std::invalid_argument if the input column is not at least two-level depth lists column
* (i.e., each row must be a list of list).
vyasr marked this conversation as resolved.
Show resolved Hide resolved
* @throws cudf::logic_error if the input lists column contains nested typed entries that are not
* lists.
* lists.
*
* @param input The lists column containing lists of list elements to concatenate.
* @param null_policy The parameter to specify whether a null list element will be ignored from
Expand Down
5 changes: 3 additions & 2 deletions cpp/include/cudf/lists/contains.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, NVIDIA CORPORATION.
* Copyright (c) 2021-2023, 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 @@ -129,6 +129,7 @@ enum class duplicate_find_option : int32_t {
* @throw cudf::logic_error If `search_key` type does not match the element type in `lists`
* @throw cudf::logic_error If `search_key` is of a nested type, or `lists` contains nested
* elements (LIST, STRUCT)
* @throw cudf::data_type_error If `search_keys` type does not match the element type in `lists`
vyasr marked this conversation as resolved.
Show resolved Hide resolved
*/
std::unique_ptr<column> index_of(
cudf::lists_column_view const& lists,
Expand Down Expand Up @@ -163,8 +164,8 @@ std::unique_ptr<column> index_of(
* @return std::unique_ptr<column> INT32 column of `n` rows with the location of the `search_key`
*
* @throw cudf::logic_error If `search_keys` does not match `lists` in its number of rows
* @throw cudf::logic_error If `search_keys` type does not match the element type in `lists`
* @throw cudf::logic_error If `lists` or `search_keys` contains nested elements (LIST, STRUCT)
* @throw cudf::data_type_error If `search_keys` type does not match the element type in `lists`
vyasr marked this conversation as resolved.
Show resolved Hide resolved
*/
std::unique_ptr<column> index_of(
cudf::lists_column_view const& lists,
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/cudf/lists/gather.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, NVIDIA CORPORATION.
* Copyright (c) 2021-2023, 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 @@ -43,7 +43,7 @@ namespace lists {
* @endcode
*
* @throws cudf::logic_error if `gather_map_list` size is not same as `source_column` size.
* @throws cudf::logic_error if gather_map contains null values.
* @throws std::invalid_argument if gather_map contains null values.
ttnghia marked this conversation as resolved.
Show resolved Hide resolved
* @throws cudf::logic_error if gather_map is not list column of an index type.
*
* If indices in `gather_map_list` are outside the range `[-n, n)`, where `n` is the number of
Expand Down
4 changes: 3 additions & 1 deletion cpp/include/cudf/strings/json.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, NVIDIA CORPORATION.
* Copyright (c) 2021-2023, 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 @@ -160,6 +160,8 @@ class get_json_object_options {
* @param options Options for controlling the behavior of the function
* @param mr Resource for allocating device memory.
* @return New strings column containing the retrieved json object strings
*
* @throw std::invalid_argument if provided an invalid operator or an empty name
*/
std::unique_ptr<cudf::column> get_json_object(
cudf::strings_column_view const& col,
Expand Down
25 changes: 24 additions & 1 deletion cpp/include/cudf/utilities/error.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022, NVIDIA CORPORATION.
* Copyright (c) 2019-2023, 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 @@ -84,6 +84,29 @@ struct cuda_error : public std::runtime_error {
struct fatal_cuda_error : public cuda_error {
using cuda_error::cuda_error; // Inherit constructors
};

/**
* @brief Exception thrown when an operation is attempted on an unsupported dtype.
*
* This exception should be thrown when an operation is attempted on an
* unsupported data_type. This exception should not be thrown directly and is
* instead thrown by the CUDF_EXPECTS or CUDF_FAIL macros.
*/
struct data_type_error : public std::invalid_argument {
/**
* @brief Constructs a data_type_error with the error message.
*
* @param message Message to be associated with the exception
*/
data_type_error(char const* const message) : std::invalid_argument(message) {}

/**
* @brief Construct a new data_type_error object with error message
*
* @param message Message to be associated with the exception
*/
data_type_error(std::string const& message) : std::invalid_argument(message) {}
};
/** @} */

} // namespace cudf
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/binaryop/binaryop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ std::unique_ptr<column> binary_operation(LhsType const& lhs,
return cudf::binops::compiled::string_null_min_max(lhs, rhs, op, output_type, stream, mr);

if (not cudf::binops::compiled::is_supported_operation(output_type, lhs.type(), rhs.type(), op))
CUDF_FAIL("Unsupported operator for these types");
CUDF_FAIL("Unsupported operator for these types", cudf::data_type_error);

if (cudf::is_fixed_point(lhs.type()) or cudf::is_fixed_point(rhs.type())) {
cudf::binops::compiled::fixed_point_binary_operation_validation(
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/binaryop/compiled/equality_ops.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, NVIDIA CORPORATION.
* Copyright (c) 2021-2023, 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 All @@ -26,7 +26,8 @@ void dispatch_equality_op(mutable_column_view& out,
rmm::cuda_stream_view stream)
{
CUDF_EXPECTS(op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL,
"Unsupported operator for these types");
"Unsupported operator for these types",
cudf::data_type_error);
auto common_dtype = get_common_type(out.type(), lhs.type(), rhs.type());
auto outd = mutable_column_device_view::create(out, stream);
auto lhsd = column_device_view::create(lhs, stream);
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/binaryop/compiled/struct_binary_ops.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ void apply_struct_equality_op(mutable_column_view& out,
{
CUDF_EXPECTS(op == binary_operator::EQUAL || op == binary_operator::NOT_EQUAL ||
op == binary_operator::NULL_EQUALS,
"Unsupported operator for these types");
"Unsupported operator for these types",
cudf::data_type_error);

auto tlhs = table_view{{lhs}};
auto trhs = table_view{{rhs}};
Expand Down
11 changes: 7 additions & 4 deletions cpp/src/copying/concatenate.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, NVIDIA CORPORATION.
* Copyright (c) 2020-2023, 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 @@ -228,7 +228,8 @@ std::unique_ptr<column> fused_concatenate(host_span<column_view const> views,
auto const output_size = std::get<3>(device_views);

CUDF_EXPECTS(output_size <= static_cast<std::size_t>(std::numeric_limits<size_type>::max()),
"Total number of concatenated rows exceeds size_type range");
"Total number of concatenated rows exceeds size_type range",
std::overflow_error);

// Allocate output
auto const policy = has_nulls ? mask_policy::ALWAYS : mask_policy::NEVER;
Expand Down Expand Up @@ -398,7 +399,8 @@ void traverse_children::operator()<cudf::string_view>(host_span<column_view cons
});
// note: output text must include "exceeds size_type range" for python error handling
CUDF_EXPECTS(total_char_count <= static_cast<size_t>(std::numeric_limits<size_type>::max()),
"Total number of concatenated chars exceeds size_type range");
"Total number of concatenated chars exceeds size_type range",
std::overflow_error);
}

template <>
Expand Down Expand Up @@ -469,7 +471,8 @@ void bounds_and_type_check(host_span<column_view const> cols, rmm::cuda_stream_v
});
// note: output text must include "exceeds size_type range" for python error handling
CUDF_EXPECTS(total_row_count <= static_cast<size_t>(std::numeric_limits<size_type>::max()),
"Total number of concatenated rows exceeds size_type range");
"Total number of concatenated rows exceeds size_type range",
std::overflow_error);

// traverse children
cudf::type_dispatcher(cols.front().type(), traverse_children{}, cols, stream);
Expand Down
8 changes: 5 additions & 3 deletions cpp/src/lists/combine/concatenate_list_elements.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, NVIDIA CORPORATION.
* Copyright (c) 2021-2023, 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 @@ -257,11 +257,13 @@ std::unique_ptr<column> concatenate_list_elements(column_view const& input,
rmm::mr::device_memory_resource* mr)
{
auto type = input.type(); // Column that is lists of lists.
CUDF_EXPECTS(type.id() == type_id::LIST, "Input column must be a lists column.");
CUDF_EXPECTS(
type.id() == type_id::LIST, "Input column must be a lists column.", std::invalid_argument);

auto col = lists_column_view(input).child(); // Rows, which are lists.
type = col.type();
CUDF_EXPECTS(type.id() == type_id::LIST, "Rows of the input column must be lists.");
CUDF_EXPECTS(
type.id() == type_id::LIST, "Rows of the input column must be lists.", std::invalid_argument);

col = lists_column_view(col).child(); // The last level entries what we need to check.
type = col.type();
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/lists/contains.cu
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ struct dispatch_index_of {
auto const child = lists.child();

CUDF_EXPECTS(child.type() == search_keys.type(),
"Type/Scale of search key does not match list column element type.");
"Type/Scale of search key does not match list column element type.",
cudf::data_type_error);
CUDF_EXPECTS(search_keys.type().id() != type_id::EMPTY, "Type cannot be empty.");

auto constexpr search_key_is_scalar = std::is_same_v<SearchKeyType, cudf::scalar>;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/lists/copying/segmented_gather.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, NVIDIA CORPORATION.
* Copyright (c) 2020-2023, 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 @@ -38,7 +38,7 @@ std::unique_ptr<column> segmented_gather(lists_column_view const& value_column,
{
CUDF_EXPECTS(is_index_type(gather_map.child().type()),
"Gather map should be list column of index type");
CUDF_EXPECTS(!gather_map.has_nulls(), "Gather map contains nulls");
CUDF_EXPECTS(!gather_map.has_nulls(), "Gather map contains nulls", std::invalid_argument);
CUDF_EXPECTS(value_column.size() == gather_map.size(),
"Gather map and list column should be same size");

Expand Down
7 changes: 4 additions & 3 deletions cpp/src/strings/json/json_path.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, NVIDIA CORPORATION.
* Copyright (c) 2021-2023, 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 @@ -588,7 +588,7 @@ class path_state : private parser {
return path_operator{path_operator_type::CHILD_WILDCARD};
} break;

default: CUDF_FAIL("Unrecognized JSONPath operator"); break;
default: CUDF_FAIL("Unrecognized JSONPath operator", std::invalid_argument); break;
}
return {path_operator_type::ERROR};
}
Expand Down Expand Up @@ -624,7 +624,8 @@ class path_state : private parser {
}

// an empty name is not valid
CUDF_EXPECTS(name.size_bytes() > 0, "Invalid empty name in JSONPath query string");
CUDF_EXPECTS(
name.size_bytes() > 0, "Invalid empty name in JSONPath query string", std::invalid_argument);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/tests/binaryop/binop-compiled-fixed_point-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ TYPED_TEST(FixedPointCompiledTest, FixedPointBinaryOpThrows)
auto const col = fp_wrapper<RepType>{{100, 300, 500, 700}, scale_type{-2}};
auto const non_bool_type = cudf::data_type{cudf::type_to_id<decimalXX>(), -2};
EXPECT_THROW(cudf::binary_operation(col, col, cudf::binary_operator::LESS, non_bool_type),
cudf::logic_error);
cudf::data_type_error);
}

TYPED_TEST(FixedPointCompiledTest, FixedPointBinaryOpModSimple)
Expand Down
Loading