Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into build_for_wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
jondo2010 committed Oct 24, 2022
2 parents 37bc573 + 22e742b commit da40737
Show file tree
Hide file tree
Showing 21 changed files with 1,073 additions and 512 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/arrow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ on:
- arrow-buffer/**
- arrow-data/**
- arrow-schema/**
- arrow-select/**
- arrow-integration-test/**
- .github/**

Expand Down Expand Up @@ -61,6 +62,8 @@ jobs:
run: cargo test -p arrow-schema --all-features
- name: Test arrow-array with all features
run: cargo test -p arrow-array --all-features
- name: Test arrow-select with all features
run: cargo test -p arrow-select --all-features
- name: Test arrow-integration-test with all features
run: cargo test -p arrow-integration-test --all-features
- name: Test arrow
Expand Down Expand Up @@ -193,13 +196,15 @@ jobs:
run: |
rustup component add clippy
- name: Clippy arrow-buffer with all features
run: cargo clippy -p arrow-buffer --all-features
run: cargo clippy -p arrow-buffer --all-targets --all-features
- name: Clippy arrow-data with all features
run: cargo clippy -p arrow-data --all-features
run: cargo clippy -p arrow-data --all-targets --all-features
- name: Clippy arrow-schema with all features
run: cargo clippy -p arrow-schema --all-features
run: cargo clippy -p arrow-schema --all-targets --all-features
- name: Clippy arrow-array with all features
run: cargo clippy -p arrow-array --all-features
run: cargo clippy -p arrow-array --all-targets --all-features
- name: Clippy arrow-select with all features
run: cargo clippy -p arrow-select --all-targets --all-features
- name: Clippy arrow
run: |
cargo clippy -p arrow --features=prettyprint,csv,ipc,test_utils,ffi,ipc_compression,dyn_cmp_dict,dyn_arith_dict --all-targets -- -D warnings
1 change: 1 addition & 0 deletions .github/workflows/arrow_flight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ on:
- arrow-buffer/**
- arrow-data/**
- arrow-schema/**
- arrow-select/**
- arrow-flight/**
- .github/**

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/dev_pr/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ arrow:
- arrow-buffer/**/*
- arrow-data/**/*
- arrow-schema/**/*
- arrow-select/**/*

arrow-flight:
- arrow-flight/**/*
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ on:
- arrow-buffer/**
- arrow-data/**
- arrow-schema/**
- arrow-select/**
- arrow-pyarrow-integration-testing/**
- arrow-integration-test/**
- arrow-integration-testing/**
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/miri.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ on:
- arrow-buffer/**
- arrow-data/**
- arrow-schema/**
- arrow-select/**
- .github/**

jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/parquet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ on:
- arrow-buffer/**
- arrow-data/**
- arrow-schema/**
- arrow-select/**
- parquet/**
- .github/**

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ members = [
"arrow-integration-test",
"arrow-integration-testing",
"arrow-schema",
"arrow-select",
"parquet",
"parquet_derive",
"parquet_derive_test",
Expand Down
19 changes: 16 additions & 3 deletions arrow-array/src/array/primitive_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1362,11 +1362,24 @@ mod tests {
}

#[test]
#[should_panic(expected = "invalid time")]
fn test_time32second_invalid_neg() {
// The panic should come from chrono, not from arrow
// chrono::NaiveDatetime::from_timestamp_opt returns None while input is invalid
let arr: PrimitiveArray<Time32SecondType> = vec![-7201, -60054].into();
println!("{:?}", arr);
assert_eq!(
"PrimitiveArray<Time32(Second)>\n[\n null,\n null,\n]",
format!("{:?}", arr)
)
}

#[test]
fn test_timestamp_micros_out_of_range() {
// replicate the issue from https://github.com/apache/arrow-datafusion/issues/3832
let arr: PrimitiveArray<TimestampMicrosecondType> =
vec![9065525203050843594].into();
assert_eq!(
"PrimitiveArray<Timestamp(Microsecond, None)>\n[\n null,\n]",
format!("{:?}", arr)
)
}

#[test]
Expand Down
76 changes: 38 additions & 38 deletions arrow-array/src/temporal_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ pub const EPOCH_DAYS_FROM_CE: i32 = 719_163;

/// converts a `i32` representing a `date32` to [`NaiveDateTime`]
#[inline]
pub fn date32_to_datetime(v: i32) -> NaiveDateTime {
NaiveDateTime::from_timestamp(v as i64 * SECONDS_IN_DAY, 0)
pub fn date32_to_datetime(v: i32) -> Option<NaiveDateTime> {
NaiveDateTime::from_timestamp_opt(v as i64 * SECONDS_IN_DAY, 0)
}

/// converts a `i64` representing a `date64` to [`NaiveDateTime`]
#[inline]
pub fn date64_to_datetime(v: i64) -> NaiveDateTime {
pub fn date64_to_datetime(v: i64) -> Option<NaiveDateTime> {
let (sec, milli_sec) = split_second(v, MILLISECONDS);

NaiveDateTime::from_timestamp(
NaiveDateTime::from_timestamp_opt(
// extract seconds from milliseconds
sec,
// discard extracted seconds and convert milliseconds to nanoseconds
Expand All @@ -56,15 +56,15 @@ pub fn date64_to_datetime(v: i64) -> NaiveDateTime {

/// converts a `i32` representing a `time32(s)` to [`NaiveDateTime`]
#[inline]
pub fn time32s_to_time(v: i32) -> NaiveTime {
NaiveTime::from_num_seconds_from_midnight(v as u32, 0)
pub fn time32s_to_time(v: i32) -> Option<NaiveTime> {
NaiveTime::from_num_seconds_from_midnight_opt(v as u32, 0)
}

/// converts a `i32` representing a `time32(ms)` to [`NaiveDateTime`]
#[inline]
pub fn time32ms_to_time(v: i32) -> NaiveTime {
pub fn time32ms_to_time(v: i32) -> Option<NaiveTime> {
let v = v as i64;
NaiveTime::from_num_seconds_from_midnight(
NaiveTime::from_num_seconds_from_midnight_opt(
// extract seconds from milliseconds
(v / MILLISECONDS) as u32,
// discard extracted seconds and convert milliseconds to
Expand All @@ -75,8 +75,8 @@ pub fn time32ms_to_time(v: i32) -> NaiveTime {

/// converts a `i64` representing a `time64(us)` to [`NaiveDateTime`]
#[inline]
pub fn time64us_to_time(v: i64) -> NaiveTime {
NaiveTime::from_num_seconds_from_midnight(
pub fn time64us_to_time(v: i64) -> Option<NaiveTime> {
NaiveTime::from_num_seconds_from_midnight_opt(
// extract seconds from microseconds
(v / MICROSECONDS) as u32,
// discard extracted seconds and convert microseconds to
Expand All @@ -87,8 +87,8 @@ pub fn time64us_to_time(v: i64) -> NaiveTime {

/// converts a `i64` representing a `time64(ns)` to [`NaiveDateTime`]
#[inline]
pub fn time64ns_to_time(v: i64) -> NaiveTime {
NaiveTime::from_num_seconds_from_midnight(
pub fn time64ns_to_time(v: i64) -> Option<NaiveTime> {
NaiveTime::from_num_seconds_from_midnight_opt(
// extract seconds from nanoseconds
(v / NANOSECONDS) as u32,
// discard extracted seconds
Expand All @@ -98,16 +98,16 @@ pub fn time64ns_to_time(v: i64) -> NaiveTime {

/// converts a `i64` representing a `timestamp(s)` to [`NaiveDateTime`]
#[inline]
pub fn timestamp_s_to_datetime(v: i64) -> NaiveDateTime {
NaiveDateTime::from_timestamp(v, 0)
pub fn timestamp_s_to_datetime(v: i64) -> Option<NaiveDateTime> {
NaiveDateTime::from_timestamp_opt(v, 0)
}

/// converts a `i64` representing a `timestamp(ms)` to [`NaiveDateTime`]
#[inline]
pub fn timestamp_ms_to_datetime(v: i64) -> NaiveDateTime {
pub fn timestamp_ms_to_datetime(v: i64) -> Option<NaiveDateTime> {
let (sec, milli_sec) = split_second(v, MILLISECONDS);

NaiveDateTime::from_timestamp(
NaiveDateTime::from_timestamp_opt(
// extract seconds from milliseconds
sec,
// discard extracted seconds and convert milliseconds to nanoseconds
Expand All @@ -117,10 +117,10 @@ pub fn timestamp_ms_to_datetime(v: i64) -> NaiveDateTime {

/// converts a `i64` representing a `timestamp(us)` to [`NaiveDateTime`]
#[inline]
pub fn timestamp_us_to_datetime(v: i64) -> NaiveDateTime {
pub fn timestamp_us_to_datetime(v: i64) -> Option<NaiveDateTime> {
let (sec, micro_sec) = split_second(v, MICROSECONDS);

NaiveDateTime::from_timestamp(
NaiveDateTime::from_timestamp_opt(
// extract seconds from microseconds
sec,
// discard extracted seconds and convert microseconds to nanoseconds
Expand All @@ -130,10 +130,10 @@ pub fn timestamp_us_to_datetime(v: i64) -> NaiveDateTime {

/// converts a `i64` representing a `timestamp(ns)` to [`NaiveDateTime`]
#[inline]
pub fn timestamp_ns_to_datetime(v: i64) -> NaiveDateTime {
pub fn timestamp_ns_to_datetime(v: i64) -> Option<NaiveDateTime> {
let (sec, nano_sec) = split_second(v, NANOSECONDS);

NaiveDateTime::from_timestamp(
NaiveDateTime::from_timestamp_opt(
// extract seconds from nanoseconds
sec, // discard extracted seconds
nano_sec,
Expand Down Expand Up @@ -172,14 +172,14 @@ pub fn duration_ns_to_duration(v: i64) -> Duration {
/// Converts an [`ArrowPrimitiveType`] to [`NaiveDateTime`]
pub fn as_datetime<T: ArrowPrimitiveType>(v: i64) -> Option<NaiveDateTime> {
match T::DATA_TYPE {
DataType::Date32 => Some(date32_to_datetime(v as i32)),
DataType::Date64 => Some(date64_to_datetime(v)),
DataType::Date32 => date32_to_datetime(v as i32),
DataType::Date64 => date64_to_datetime(v),
DataType::Time32(_) | DataType::Time64(_) => None,
DataType::Timestamp(unit, _) => match unit {
TimeUnit::Second => Some(timestamp_s_to_datetime(v)),
TimeUnit::Millisecond => Some(timestamp_ms_to_datetime(v)),
TimeUnit::Microsecond => Some(timestamp_us_to_datetime(v)),
TimeUnit::Nanosecond => Some(timestamp_ns_to_datetime(v)),
TimeUnit::Second => timestamp_s_to_datetime(v),
TimeUnit::Millisecond => timestamp_ms_to_datetime(v),
TimeUnit::Microsecond => timestamp_us_to_datetime(v),
TimeUnit::Nanosecond => timestamp_ns_to_datetime(v),
},
// interval is not yet fully documented [ARROW-3097]
DataType::Interval(_) => None,
Expand All @@ -199,14 +199,14 @@ pub fn as_time<T: ArrowPrimitiveType>(v: i64) -> Option<NaiveTime> {
// safe to immediately cast to u32 as `self.value(i)` is positive i32
let v = v as u32;
match unit {
TimeUnit::Second => Some(time32s_to_time(v as i32)),
TimeUnit::Millisecond => Some(time32ms_to_time(v as i32)),
TimeUnit::Second => time32s_to_time(v as i32),
TimeUnit::Millisecond => time32ms_to_time(v as i32),
_ => None,
}
}
DataType::Time64(unit) => match unit {
TimeUnit::Microsecond => Some(time64us_to_time(v)),
TimeUnit::Nanosecond => Some(time64ns_to_time(v)),
TimeUnit::Microsecond => time64us_to_time(v),
TimeUnit::Nanosecond => time64ns_to_time(v),
_ => None,
},
DataType::Timestamp(_, _) => as_datetime::<T>(v).map(|datetime| datetime.time()),
Expand Down Expand Up @@ -241,51 +241,51 @@ mod tests {
fn negative_input_timestamp_ns_to_datetime() {
assert_eq!(
timestamp_ns_to_datetime(-1),
NaiveDateTime::from_timestamp(-1, 999_999_999)
NaiveDateTime::from_timestamp_opt(-1, 999_999_999)
);

assert_eq!(
timestamp_ns_to_datetime(-1_000_000_001),
NaiveDateTime::from_timestamp(-2, 999_999_999)
NaiveDateTime::from_timestamp_opt(-2, 999_999_999)
);
}

#[test]
fn negative_input_timestamp_us_to_datetime() {
assert_eq!(
timestamp_us_to_datetime(-1),
NaiveDateTime::from_timestamp(-1, 999_999_000)
NaiveDateTime::from_timestamp_opt(-1, 999_999_000)
);

assert_eq!(
timestamp_us_to_datetime(-1_000_001),
NaiveDateTime::from_timestamp(-2, 999_999_000)
NaiveDateTime::from_timestamp_opt(-2, 999_999_000)
);
}

#[test]
fn negative_input_timestamp_ms_to_datetime() {
assert_eq!(
timestamp_ms_to_datetime(-1),
NaiveDateTime::from_timestamp(-1, 999_000_000)
NaiveDateTime::from_timestamp_opt(-1, 999_000_000)
);

assert_eq!(
timestamp_ms_to_datetime(-1_001),
NaiveDateTime::from_timestamp(-2, 999_000_000)
NaiveDateTime::from_timestamp_opt(-2, 999_000_000)
);
}

#[test]
fn negative_input_date64_to_datetime() {
assert_eq!(
date64_to_datetime(-1),
NaiveDateTime::from_timestamp(-1, 999_000_000)
NaiveDateTime::from_timestamp_opt(-1, 999_000_000)
);

assert_eq!(
date64_to_datetime(-1_001),
NaiveDateTime::from_timestamp(-2, 999_000_000)
NaiveDateTime::from_timestamp_opt(-2, 999_000_000)
);
}

Expand Down
51 changes: 51 additions & 0 deletions arrow-select/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

[package]
name = "arrow-select"
version = "25.0.0"
description = "Selection kernels for arrow arrays"
homepage = "https://github.com/apache/arrow-rs"
repository = "https://github.com/apache/arrow-rs"
authors = ["Apache Arrow <[email protected]>"]
license = "Apache-2.0"
keywords = ["arrow"]
include = [
"benches/*.rs",
"src/**/*.rs",
"Cargo.toml",
]
edition = "2021"
rust-version = "1.62"

[lib]
name = "arrow_select"
path = "src/lib.rs"
bench = false

[dependencies]
arrow-buffer = { version = "25.0.0", path = "../arrow-buffer" }
arrow-data = { version = "25.0.0", path = "../arrow-data" }
arrow-schema = { version = "25.0.0", path = "../arrow-schema" }
arrow-array = { version = "25.0.0", path = "../arrow-array" }
num = { version = "0.4", default-features = false, features = ["std"] }

[features]
default = []

[dev-dependencies]
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"] }
Loading

0 comments on commit da40737

Please sign in to comment.