[C++] random function can't actually be used
- Dominant language
- C++
- Stars
- 17.1k
- Forks
- 4.3k
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 91
Description
random() is currently implemented as a nullary function. It doesn't let you specify the number of values you want to generate because it's designed to generate however many the given ExecBatch has. The only option RandomOptions takes seems to be an optional seed value. Unfortunately, the result is that the function is not usable, AFAICT.
Calling the compute function directly, you get 0 values (all examples from R):
```Java
library(arrow)
call_function("random")
# Array
#
# []
```
Calling it from within an ExecPlan, it errors because it is not a proper scalar function, despite what the filenames say (scalar_random.cc, etc.):
```Java
library(arrow)
library(dplyr)
mtcars %>%
arrow_table() %>%
mutate(x = arrow_random()) %>%
collect()
# Error in `collect()`:
# ! Invalid: ExecuteScalarExpression cannot Execute non-scalar expression Array[double]
```
**Reporter**: [Neal Richardson](https://issues.apache.org/jira/browse/ARROW-17974) / @nealrichardson
**Note**: *This issue was originally created as [ARROW-17974](https://issues.apache.org/jira/browse/ARROW-17974). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*
Contributor guide
Research direction
Start with the random implementation in scalar_random.cc and inspect RandomOptions, then reproduce both call_function("random") and the ExecPlan example shown in the issue. Compare the function's nullary and scalar execution paths. Done means random can produce a requested number of values and works within the demonstrated ExecPlan usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, r
- Domain
- backend, data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100