Skip to content
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: 46 additions & 46 deletions datafusion-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion datafusion/common/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4965,7 +4965,8 @@ mod tests {
.unwrap()
.and_hms_nano_opt(hour, minute, second, nanosec)
.unwrap()
.timestamp_nanos(),
.timestamp_nanos_opt()
.unwrap(),
),
None,
))
Expand Down
6 changes: 4 additions & 2 deletions datafusion/core/src/physical_plan/metrics/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,13 @@ impl MetricValue {
Self::Time { time, .. } => time.value(),
Self::StartTimestamp(timestamp) => timestamp
.value()
.map(|ts| ts.timestamp_nanos() as usize)
.and_then(|ts| ts.timestamp_nanos_opt())
.map(|nanos| nanos as usize)
.unwrap_or(0),
Self::EndTimestamp(timestamp) => timestamp
.value()
.map(|ts| ts.timestamp_nanos() as usize)
.and_then(|ts| ts.timestamp_nanos_opt())
Copy link
Contributor

@tustvold tustvold Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct, it will convert a panic into 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't expect that the metrics would produce timestamps that can't be converted to nanoseconds so it is somehwhat a theoretical difference.

I could see the argument being made to preserve the existing behavior (panic if somehow the values can't be represented as a timestamp) but I also think returning 0 rather than panic'ing in that case (what this PR does) is also reasonable

.map(|nanos| nanos as usize)
.unwrap_or(0),
}
}
Expand Down
10 changes: 7 additions & 3 deletions datafusion/core/src/physical_plan/sorts/sort_preserving_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ mod tests {
use crate::physical_plan::coalesce_partitions::CoalescePartitionsExec;
use crate::physical_plan::expressions::col;
use crate::physical_plan::memory::MemoryExec;
use crate::physical_plan::metrics::MetricValue;
use crate::physical_plan::metrics::{MetricValue, Timestamp};
use crate::physical_plan::sorts::sort::SortExec;
use crate::physical_plan::stream::RecordBatchReceiverStream;
use crate::physical_plan::{collect, common};
Expand Down Expand Up @@ -939,11 +939,11 @@ mod tests {
metrics.iter().for_each(|m| match m.value() {
MetricValue::StartTimestamp(ts) => {
saw_start = true;
assert!(ts.value().unwrap().timestamp_nanos() > 0);
assert!(nanos_from_timestamp(ts) > 0);
}
MetricValue::EndTimestamp(ts) => {
saw_end = true;
assert!(ts.value().unwrap().timestamp_nanos() > 0);
assert!(nanos_from_timestamp(ts) > 0);
}
_ => {}
});
Expand All @@ -952,6 +952,10 @@ mod tests {
assert!(saw_end);
}

fn nanos_from_timestamp(ts: &Timestamp) -> i64 {
ts.value().unwrap().timestamp_nanos_opt().unwrap()
}

#[tokio::test]
async fn test_drop_cancel() -> Result<()> {
let task_ctx = Arc::new(TaskContext::default());
Expand Down
3 changes: 2 additions & 1 deletion datafusion/core/tests/parquet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ fn make_timestamp_batch(offset: Duration) -> RecordBatch {
offset_nanos
+ t.parse::<chrono::NaiveDateTime>()
.unwrap()
.timestamp_nanos()
.timestamp_nanos_opt()
.unwrap()
})
})
.collect::<Vec<_>>();
Expand Down
Loading