Skip to content

Add creator from Iterator of i128 to get the decimalarray #1009

Description

@liukun4515

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
From this comments in the datafusion.
apache/datafusion#1394 (comment)

apache/datafusion#1394

Creating an DecimalArray from an array of Option<i128> using DecimalBuilder is quite painful (see apache/datafusion#1394)

Ideally it would be possible to do something similar to the PrimitiveArrays, such as https://docs.rs/arrow/6.3.0/arrow/array/type.UInt32Array.html#example-using-collect

// get an iterator over `Option<i128>`
let data: Vec<Option<i128>> = ....;
let array: DecimalArray = data.into_iter().collect();

Describe the solution you'd like
However, since DecimalArray has precision and scale in its DataType, we need some way to specify that.

One thought, would be a function such as (for precision 20 and scale 5):

let array = DecimalArray::from_iter_and_scale(20, 5, data.iter())

An alternate might be something more like:

// creates a decimal array with default precision 32 and scale 0 (could be something else)
let array: DecimalArray = data.into_iter().collect();
// consume the existing array and make a new one with a different declared precision and scale
let array = array.with_precision_and_scale(20, 5);

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementAny new improvement worthy of a entry in the changelog

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions