Skip to content

Commit

Permalink
Set null-count in linked_column_view conversion operator (#13121)
Browse files Browse the repository at this point in the history
Removes the `UNKNOWN_NULL_COUNT` usage in the `linked_column_view::column_view()` conversion operator. The null-count is copied from the parent instance. The `linked_column_view` class was reworked to move the C++ function definitions from the header file to a new .cpp file.

Contributes to: #11968

Authors:
  - David Wendt (https://github.com/davidwendt)

Approvers:
  - Vyas Ramasubramani (https://github.com/vyasr)
  - Nghia Truong (https://github.com/ttnghia)

URL: #13121
  • Loading branch information
davidwendt authored Apr 14, 2023
1 parent 891698d commit e6cb2d0
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 34 deletions.
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,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
59 changes: 25 additions & 34 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 @@ -28,40 +30,34 @@ using LinkedColPtr = std::shared_ptr<linked_column_view>;
using LinkedColVector = std::vector<LinkedColPtr>;

/**
* @brief column_view with the added member pointer to the parent of this column.
*
* @brief A column_view class with pointer to parent's column_view
*/
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) {}
/**
* @brief Construct from column_view
*
* @param col column_view to wrap
*/
linked_column_view(column_view const& col);

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);
});
}
/**
* @brief Construct from column_view with it's parent
*
* @param parent Pointer to the column_view's parent column_view
* @param col column_view to wrap
*/
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()));
}
/**
* @brief Conversion operator to cast this instance to it's column_view
*/
operator column_view() const;

linked_column_view* parent; //!< Pointer to parent of this column. Nullptr if root
LinkedColVector children;
linked_column_view* parent; ///< Pointer to parent of this column; nullptr if root
LinkedColVector children; ///< Vector of children of this instance
};

/**
Expand All @@ -70,11 +66,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
55 changes: 55 additions & 0 deletions cpp/src/utilities/linked_column.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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(),
this->offset(),
std::vector<column_view>(child_it, child_it + children.size()));
}

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

0 comments on commit e6cb2d0

Please sign in to comment.