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

Interval is out of spec #187

Closed
Tracked by #3148
alamb opened this issue Apr 26, 2021 · 2 comments
Closed
Tracked by #3148

Interval is out of spec #187

alamb opened this issue Apr 26, 2021 · 2 comments
Labels
arrow Changes to the arrow crate

Comments

@alamb
Copy link
Contributor

alamb commented Apr 26, 2021

Note: migrated from original JIRA: https://issues.apache.org/jira/browse/ARROW-11645

The DataType interval is currently implemented as a i32 or i64. However, that is incorrect and does not follow the spec.
{code:java}
// DAY_TIME - Indicates the number of elapsed days and milliseconds,
// stored as 2 contiguous 32-bit integers (8-bytes in total). Support
// of this IntervalUnit is not required for full arrow compatibility.
{code}
See [https://github.com/apache/arrow/blob/master/format/Schema.fbs]

E.g. I think that IntervalDayTimeType should be a struct(i32,i32) with a C representation or something, which is how it is defined in the spec.

This would also make it easier to read from and write to, as we do not need to transmute or bitmask the values to get the correct values.

@waitingkuo
Copy link
Contributor

@alamb is it solved?

make_type!(
IntervalDayTimeType,
i64,
DataType::Interval(IntervalUnit::DayTime)
);

impl IntervalDayTimeType {
/// Creates a IntervalDayTimeType::Native
///
/// # Arguments
///
/// * `days` - The number of days (+/-) represented in this interval
/// * `millis` - The number of milliseconds (+/-) represented in this interval
pub fn make_value(
days: i32,
millis: i32,
) -> <IntervalDayTimeType as ArrowPrimitiveType>::Native {
/*
https://github.com/apache/arrow/blob/02c8598d264c839a5b5cf3109bfd406f3b8a6ba5/cpp/src/arrow/type.h#L1433
struct DayMilliseconds {
int32_t days = 0;
int32_t milliseconds = 0;
...
}
64 56 48 40 32 24 16 8 0
+-------+-------+-------+-------+-------+-------+-------+-------+
| days | milliseconds |
+-------+-------+-------+-------+-------+-------+-------+-------+
*/
let m = millis as u64 & u32::MAX as u64;
let d = (days as u64 & u32::MAX as u64) << 32;
(m | d) as <IntervalDayTimeType as ArrowPrimitiveType>::Native
}
/// Turns a IntervalDayTimeType into a tuple of (days, milliseconds)
///
/// # Arguments
///
/// * `i` - The IntervalDayTimeType to convert
pub fn to_parts(
i: <IntervalDayTimeType as ArrowPrimitiveType>::Native,
) -> (i32, i32) {
let days = (i >> 32) as i32;
let ms = i as i32;
(days, ms)
}
}

@alamb
Copy link
Contributor Author

alamb commented Aug 16, 2022

I agree this issue is not tracking anything actionable anymore. Thanks for the spot @waitingkuo

@alamb alamb closed this as completed Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

No branches or pull requests

2 participants