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

Set null-count in linked_column_view conversion operator #13121

Merged
merged 6 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ add_library(
src/unary/nan_ops.cu
src/unary/null_ops.cu
src/utilities/default_stream.cpp
src/utilities/linked_column.cpp
src/utilities/logger.cpp
src/utilities/traits.cpp
src/utilities/type_checks.cpp
Expand Down
38 changes: 8 additions & 30 deletions cpp/include/cudf/detail/utilities/linked_column.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION.
* Copyright (c) 2022-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 @@ -16,9 +16,11 @@

#pragma once

#include <cudf/column/column_view.hpp>
#include <cudf/table/table_view.hpp>

#include <thrust/iterator/transform_iterator.h>
#include <memory>
#include <vector>

namespace cudf::detail {

Expand All @@ -35,30 +37,11 @@ struct linked_column_view : public column_view_base {
linked_column_view(linked_column_view const&) = delete;
linked_column_view& operator=(linked_column_view const&) = delete;

linked_column_view(column_view const& col) : linked_column_view(nullptr, col) {}
linked_column_view(column_view const& col);
davidwendt marked this conversation as resolved.
Show resolved Hide resolved

linked_column_view(linked_column_view* parent, column_view const& col)
: column_view_base(col), parent(parent)
{
children.reserve(col.num_children());
std::transform(
col.child_begin(), col.child_end(), std::back_inserter(children), [&](column_view const& c) {
return std::make_shared<linked_column_view>(this, c);
});
}
linked_column_view(linked_column_view* parent, column_view const& col);

operator column_view() const
{
auto child_it = thrust::make_transform_iterator(
children.begin(), [](auto const& c) { return static_cast<column_view>(*c); });
return column_view(this->type(),
this->size(),
this->head(),
this->null_mask(),
UNKNOWN_NULL_COUNT,
this->offset(),
std::vector<column_view>(child_it, child_it + children.size()));
}
operator column_view() const;

linked_column_view* parent; //!< Pointer to parent of this column. Nullptr if root
LinkedColVector children;
Expand All @@ -70,11 +53,6 @@ struct linked_column_view : public column_view_base {
* @param table table of columns to convert
* @return Vector of converted linked_column_views
*/
inline LinkedColVector table_to_linked_columns(table_view const& table)
{
auto linked_it = thrust::make_transform_iterator(
table.begin(), [](auto const& c) { return std::make_shared<linked_column_view>(c); });
return LinkedColVector(linked_it, linked_it + table.num_columns());
}
LinkedColVector table_to_linked_columns(table_view const& table);

} // namespace cudf::detail
61 changes: 61 additions & 0 deletions cpp/src/utilities/linked_column.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code moved from the .hpp file

* Copyright (c) 2022-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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <cudf/detail/utilities/linked_column.hpp>

#include <thrust/iterator/transform_iterator.h>

namespace cudf::detail {

linked_column_view::linked_column_view(column_view const& col) : linked_column_view(nullptr, col) {}

linked_column_view::linked_column_view(linked_column_view* parent, column_view const& col)
: column_view_base(col), parent(parent)
{
children.reserve(col.num_children());
std::transform(
col.child_begin(), col.child_end(), std::back_inserter(children), [&](column_view const& c) {
return std::make_shared<linked_column_view>(this, c);
});
}

linked_column_view::operator column_view() const
{
auto child_it = thrust::make_transform_iterator(
children.begin(), [](auto const& c) { return static_cast<column_view>(*c); });
return column_view(this->type(),
this->size(),
this->head(),
this->null_mask(),
this->null_count(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only change I see aside from the move (and it looks correct). Please re-request review if there is any other substantive change that I missed.

this->offset(),
std::vector<column_view>(child_it, child_it + children.size()));
}

/**
* @brief Converts all column_views of a table into linked_column_views
*
* @param table table of columns to convert
* @return Vector of converted linked_column_views
*/
davidwendt marked this conversation as resolved.
Show resolved Hide resolved
LinkedColVector table_to_linked_columns(table_view const& table)
{
auto linked_it = thrust::make_transform_iterator(
table.begin(), [](auto const& c) { return std::make_shared<linked_column_view>(c); });
return LinkedColVector(linked_it, linked_it + table.num_columns());
}

} // namespace cudf::detail