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

[C++] Enable Array creation from Scalar #40318

Closed
vyasr opened this issue Mar 2, 2024 · 5 comments
Closed

[C++] Enable Array creation from Scalar #40318

vyasr opened this issue Mar 2, 2024 · 5 comments

Comments

@vyasr
Copy link
Contributor

vyasr commented Mar 2, 2024

Describe the enhancement requested

Currently creating an ArrowArray from a Scalar requires going through the Builder interface. While this is fine as a general solution, a common special case is the creation of an Array from a single Scalar (possibly copying that Scalar N times). Abstracting out the handling of different types could be helpful for this case. If there is interest in this feature, there is code that I wrote for this task in cudf that could easily be extracted into arrow C++ (we're likely to remove that functionality from libcudf).

Concretely, this would be something like an API with the signature:

arrow::Array from_scalar(arrow::Scalar const& input, size_type N=1)

Apologies if there is such a function somewhere in the C++ and I missed it.

Component(s)

C++

@kou kou changed the title Enable Array creation from Scalar [C++] Enable Array creation from Scalar Mar 3, 2024
@kou
Copy link
Member

kou commented Mar 3, 2024

It seems that we have arrow::MakeArrayFromScalar():

/// \brief Create an Array instance whose slots are the given scalar
/// \param[in] scalar the value with which to fill the array
/// \param[in] length the array length
/// \param[in] pool the memory pool to allocate memory from
ARROW_EXPORT
Result<std::shared_ptr<Array>> MakeArrayFromScalar(
const Scalar& scalar, int64_t length, MemoryPool* pool = default_memory_pool());

Could you take a look at it?

@vyasr
Copy link
Contributor Author

vyasr commented Mar 4, 2024

That looks exactly like what I was envisioning. I've tested it and it works just as I'd expect. I can't find that function anywhere in the C++ documentation, though. Could we add it somewhere? Perhaps to a factories section on the Arrays page similar to the one that exists for Scalars?

@kou
Copy link
Member

kou commented Mar 5, 2024

It makes sense. Could you work on this?

@vyasr
Copy link
Contributor Author

vyasr commented Mar 5, 2024

@kou yup! I opened #40373 for this.

pitrou pushed a commit that referenced this issue Mar 7, 2024
### Rationale for this change

These factory functions are generally useful and available, so documenting them helps external users find them without having to search the source code.

### What changes are included in this PR?

This PR adds the array factories in arrow/array/util.h into a doxygen group for array factories and adds that group to the Sphinx C++ API documentation.

### Are these changes tested?

I built the docs locally to verify.

### Are there any user-facing changes?

Nothing to the API, only docs.

* GitHub Issue: #40318

Authored-by: Vyas Ramasubramani <vyasr@nvidia.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
@pitrou pitrou added this to the 16.0.0 milestone Mar 7, 2024
@pitrou
Copy link
Member

pitrou commented Mar 7, 2024

Issue resolved by pull request 40373
#40373

@pitrou pitrou closed this as completed Mar 7, 2024
thisisnic pushed a commit to thisisnic/arrow that referenced this issue Mar 8, 2024
…che#40373)

### Rationale for this change

These factory functions are generally useful and available, so documenting them helps external users find them without having to search the source code.

### What changes are included in this PR?

This PR adds the array factories in arrow/array/util.h into a doxygen group for array factories and adds that group to the Sphinx C++ API documentation.

### Are these changes tested?

I built the docs locally to verify.

### Are there any user-facing changes?

Nothing to the API, only docs.

* GitHub Issue: apache#40318

Authored-by: Vyas Ramasubramani <vyasr@nvidia.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants