Skip to content

Commit b882d45

Browse files
authored
Fix generate_interval_case in integration test (#1446)
* Fix generate_interval_case * Fix
1 parent 724eb0c commit b882d45

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

arrow/src/compute/kernels/cast.rs

+32
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,20 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
228228
IntervalUnit::DayTime => true,
229229
IntervalUnit::MonthDayNano => false, // Native type is i128
230230
}
231+
},
232+
(Int32, Interval(to_type)) => {
233+
match to_type{
234+
IntervalUnit::YearMonth => true,
235+
IntervalUnit::DayTime => false,
236+
IntervalUnit::MonthDayNano => false,
237+
}
238+
},
239+
(Int64, Interval(to_type)) => {
240+
match to_type{
241+
IntervalUnit::YearMonth => false,
242+
IntervalUnit::DayTime => true,
243+
IntervalUnit::MonthDayNano => false,
244+
}
231245
}
232246
(_, _) => false,
233247
}
@@ -1131,6 +1145,24 @@ pub fn cast_with_options(
11311145
from_type, to_type,
11321146
))),
11331147
},
1148+
(Int32, Interval(to_type)) => match to_type {
1149+
IntervalUnit::YearMonth => {
1150+
cast_array_data::<IntervalYearMonthType>(array, Interval(to_type.clone()))
1151+
}
1152+
_ => Err(ArrowError::CastError(format!(
1153+
"Casting from {:?} to {:?} not supported",
1154+
from_type, to_type,
1155+
))),
1156+
},
1157+
(Int64, Interval(to_type)) => match to_type {
1158+
IntervalUnit::DayTime => {
1159+
cast_array_data::<IntervalDayTimeType>(array, Interval(to_type.clone()))
1160+
}
1161+
_ => Err(ArrowError::CastError(format!(
1162+
"Casting from {:?} to {:?} not supported",
1163+
from_type, to_type,
1164+
))),
1165+
},
11341166
(_, _) => Err(ArrowError::CastError(format!(
11351167
"Casting from {:?} to {:?} not supported",
11361168
from_type, to_type,

integration-testing/src/lib.rs

+33
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,39 @@ fn array_from_json(
202202
Value::String(s) => {
203203
s.parse().expect("Unable to parse string as i64")
204204
}
205+
Value::Object(ref map)
206+
if map.contains_key("days")
207+
&& map.contains_key("milliseconds") =>
208+
{
209+
match field.data_type() {
210+
DataType::Interval(IntervalUnit::DayTime) => {
211+
let days = map.get("days").unwrap();
212+
let milliseconds = map.get("milliseconds").unwrap();
213+
214+
match (days, milliseconds) {
215+
(Value::Number(d), Value::Number(m)) => {
216+
let mut bytes = [0_u8; 8];
217+
let m = (m.as_i64().unwrap() as i32)
218+
.to_le_bytes();
219+
let d = (d.as_i64().unwrap() as i32)
220+
.to_le_bytes();
221+
222+
let c = [d, m].concat();
223+
bytes.copy_from_slice(c.as_slice());
224+
i64::from_le_bytes(bytes)
225+
}
226+
_ => panic!(
227+
"Unable to parse {:?} as interval daytime",
228+
value
229+
),
230+
}
231+
}
232+
_ => panic!(
233+
"Unable to parse {:?} as interval daytime",
234+
value
235+
),
236+
}
237+
}
205238
_ => panic!("Unable to parse {:?} as number", value),
206239
}),
207240
_ => b.append_null(),

0 commit comments

Comments
 (0)