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

GH-44795: [C++] Use arrow::util::span<T> on BooleanBuilder APIs instead of std::vector<T>& #44813

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

raulcd
Copy link
Member

@raulcd raulcd commented Nov 22, 2024

Rationale for this change

arrow::util::span (a backport of C++20 std::span) is more generally applicable than std::vector, so any public API currently accepting a vector const-ref argument should instead accept a span argument.

What changes are included in this PR?

BooleanBuilder accepts arrow::util::span instead of std::vector on its API

Are these changes tested?

Via CI

Are there any user-facing changes?

Yes, from std::vector& to arrow::util::span.

@raulcd
Copy link
Member Author

raulcd commented Nov 22, 2024

I created a second PR to investigate further what is going on but it seems like it's not able to convert from std::vector<bool>& to arrow::util::span<bool> so there might be an issue on our implementation of arrow::util::span

@raulcd
Copy link
Member Author

raulcd commented Nov 27, 2024

This is the error I get:

code/arrow/cpp/src/arrow/array/builder_primitive.h:474:46:
        note:   no known conversion for argument 1 from ‘std::vector<bool>’ to ‘arrow::util::span<bool>’
  474 |   Status AppendValues(const util::span<bool> values);
      |                       ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~

when trying to convert on this test:

  BooleanBuilder builder;
  std::vector<bool> zeros(length);
  ASSERT_OK(builder.AppendValues(zeros));

@bkietz my C++ skills aren't great but shouldn't we be able to use std::vector<bool> for our utill::span<bool>?

@pitrou
Copy link
Member

pitrou commented Nov 27, 2024

@raulcd That's because std::vector<bool> is special, so you cannot replace it with a span like that. Sorry!

@@ -105,12 +105,12 @@ Status BooleanBuilder::AppendValues(const uint8_t* values, int64_t length,
return Status::OK();
}

Status BooleanBuilder::AppendValues(const std::vector<uint8_t>& values,
Status BooleanBuilder::AppendValues(const util::span<uint8_t> values,
Copy link
Member

Choose a reason for hiding this comment

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

So, const std::vector<T>& should be replaced with util::span<const T>, not const util::span<T> (because a span's constness doesn't propagate to the elements it points to, unlike vector).

/// (0). Equal in length to values
/// \return Status
Status AppendValues(const uint8_t* values, int64_t length,
const std::vector<bool>& is_valid);

/// \brief Append a sequence of elements in one shot
/// \param[in] values a std::vector of bytes
/// \param[in] is_valid an std::vector<bool> indicating valid (1) or null
/// \param[in] values an arrow::util::span of bytes
Copy link
Member

Choose a reason for hiding this comment

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

Can just say "a span of bytes" IMHO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants