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

Port tests in timestamp.rs to sqllogictest #8859

Merged
merged 3 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 0 additions & 92 deletions datafusion/core/tests/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use arrow::{
util::display::array_value_to_string,
};
use chrono::prelude::*;
use chrono::Duration;

use datafusion::datasource::TableProvider;
use datafusion::error::{DataFusionError, Result};
Expand Down Expand Up @@ -84,7 +83,6 @@ pub mod references;
pub mod repartition;
pub mod select;
mod sql_api;
pub mod timestamp;

fn create_join_context(
column_left: &str,
Expand Down Expand Up @@ -583,96 +581,6 @@ async fn register_alltypes_parquet(ctx: &SessionContext) {
.unwrap();
}

fn make_timestamp_table<A>() -> Result<Arc<MemTable>>
where
A: ArrowTimestampType<Native = i64>,
{
make_timestamp_tz_table::<A>(None)
}

fn make_timestamp_tz_table<A>(tz: Option<Arc<str>>) -> Result<Arc<MemTable>>
where
A: ArrowTimestampType<Native = i64>,
{
let schema = Arc::new(Schema::new(vec![
Field::new("ts", DataType::Timestamp(A::UNIT, tz.clone()), false),
Field::new("value", DataType::Int32, true),
]));

let divisor = match A::UNIT {
TimeUnit::Nanosecond => 1,
TimeUnit::Microsecond => 1000,
TimeUnit::Millisecond => 1_000_000,
TimeUnit::Second => 1_000_000_000,
};

let timestamps = vec![
1599572549190855000i64 / divisor, // 2020-09-08T13:42:29.190855+00:00
1599568949190855000 / divisor, // 2020-09-08T12:42:29.190855+00:00
1599565349190855000 / divisor, // 2020-09-08T11:42:29.190855+00:00
]; // 2020-09-08T11:42:29.190855+00:00

let array = PrimitiveArray::<A>::from_iter_values(timestamps).with_timezone_opt(tz);

let data = RecordBatch::try_new(
schema.clone(),
vec![
Arc::new(array),
Arc::new(Int32Array::from(vec![Some(1), Some(2), Some(3)])),
],
)?;
let table = MemTable::try_new(schema, vec![vec![data]])?;
Ok(Arc::new(table))
}

fn make_timestamp_tz_sub_table<A>(
tz1: Option<Arc<str>>,
tz2: Option<Arc<str>>,
) -> Result<Arc<MemTable>>
where
A: ArrowTimestampType<Native = i64>,
{
let schema = Arc::new(Schema::new(vec![
Field::new("ts1", DataType::Timestamp(A::UNIT, tz1.clone()), false),
Field::new("ts2", DataType::Timestamp(A::UNIT, tz2.clone()), false),
Field::new("val", DataType::Int32, true),
]));

let divisor = match A::UNIT {
TimeUnit::Nanosecond => 1,
TimeUnit::Microsecond => 1000,
TimeUnit::Millisecond => 1_000_000,
TimeUnit::Second => 1_000_000_000,
};

let timestamps1 = vec![
1_678_892_420_000_000_000i64 / divisor, //2023-03-15T15:00:20.000_000_000
1_678_892_410_000_000_000i64 / divisor, //2023-03-15T15:00:10.000_000_000
1_678_892_430_000_000_000i64 / divisor, //2023-03-15T15:00:30.000_000_000
];
let timestamps2 = vec![
1_678_892_400_000_000_000i64 / divisor, //2023-03-15T15:00:00.000_000_000
1_678_892_400_000_000_000i64 / divisor, //2023-03-15T15:00:00.000_000_000
1_678_892_400_000_000_000i64 / divisor, //2023-03-15T15:00:00.000_000_000
];

let array1 =
PrimitiveArray::<A>::from_iter_values(timestamps1).with_timezone_opt(tz1);
let array2 =
PrimitiveArray::<A>::from_iter_values(timestamps2).with_timezone_opt(tz2);

let data = RecordBatch::try_new(
schema.clone(),
vec![
Arc::new(array1),
Arc::new(array2),
Arc::new(Int32Array::from(vec![Some(1), Some(2), Some(3)])),
],
)?;
let table = MemTable::try_new(schema, vec![vec![data]])?;
Ok(Arc::new(table))
}

/// Return a new table provider that has a single Int32 column with
/// values between `seq_start` and `seq_end`
pub fn table_with_sequence(
Expand Down
Loading
Loading