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

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

Closed
liukun4515 opened this issue Dec 5, 2021 · 6 comments · Fixed by #1223
Closed

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

liukun4515 opened this issue Dec 5, 2021 · 6 comments · Fixed by #1223
Assignees
Labels
enhancement Any new improvement worthy of a entry in the changelog

Comments

@liukun4515
Copy link
Contributor

liukun4515 commented Dec 5, 2021

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.

@liukun4515 liukun4515 added the enhancement Any new improvement worthy of a entry in the changelog label Dec 5, 2021
@liukun4515
Copy link
Contributor Author

Please assign this to me.

@alamb
Copy link
Contributor

alamb commented Dec 7, 2021

Hi @liukun4515 -- thanks for the ticket; I added some more description to this ticket and some ideas which hopefully would help.

@liukun4515
Copy link
Contributor Author

Hi @liukun4515 -- thanks for the ticket; I added some more description to this ticket and some ideas which hopefully would help.

Thank you.
I think the decimal type is more complex than other types, I will start this task when the tasks in the datafusion ends.

@alamb
Copy link
Contributor

alamb commented Dec 9, 2021

BTW the more I tried playing around with this, the nicer I think it would be to be able to do something like

    let array : DecimalArray = vec![1,2,3].into()
        .with_precision(10)
        .with_scale(5);

@liukun4515
Copy link
Contributor Author

liukun4515 commented Dec 10, 2021

BTW the more I tried playing around with this, the nicer I think it would be to be able to do something like

Yes, we can follow the usage of other primitive arrays to implement the necessary function first.

@alamb alamb added good first issue Good for newcomers and removed good first issue Good for newcomers labels Dec 21, 2021
@alamb alamb changed the title Add creator from array of i128 to get the decimalarray Add creator from Iterator of i128 to get the decimalarray Jan 17, 2022
@alamb
Copy link
Contributor

alamb commented Jan 23, 2022

i took a crack at this in #1223

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Any new improvement worthy of a entry in the changelog
Projects
None yet
2 participants