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

feat(python, rust): timestampNtz support #2236

Merged
merged 22 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
pass all python tests
  • Loading branch information
ion-elgreco committed Mar 5, 2024
commit 31de5d1931cff3e98c0a08706e58ac444b392083
6 changes: 1 addition & 5 deletions crates/core/src/kernel/expressions/scalars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,10 @@ impl Scalar {
"false".to_string()
}
}
Self::TimestampNtz(ts) => {
Self::TimestampNtz(ts) | Self::Timestamp(ts) => {
let ts = Utc.timestamp_micros(*ts).single().unwrap();
ts.format("%Y-%m-%d %H:%M:%S%.6f").to_string()
}
Self::Timestamp(ts) => {
let ts = Utc.timestamp_micros(*ts).single().unwrap();
ts.format("%Y-%m-%d %H:%M:%S%.6fZ").to_string()
}
Self::Date(days) => {
let date = Utc.from_utc_datetime(
&NaiveDateTime::from_timestamp_opt(*days as i64 * 24 * 3600, 0).unwrap(),
Expand Down
1 change: 1 addition & 0 deletions python/deltalake/_internal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class PrimitiveType:
* "binary",
* "date",
* "timestamp",
* "timestampNtz",
* "decimal(<precision>, <scale>)"

Args:
Expand Down
12 changes: 7 additions & 5 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,14 +1163,16 @@ fn scalar_to_py(value: &Scalar, py_date: &PyAny, py: Python) -> PyResult<PyObjec
Long(val) => val.to_object(py),
Float(val) => val.to_object(py),
Double(val) => val.to_object(py),
// TODO: Since PyArrow 13.0.0, casting string -> timestamp fails if it ends with "Z"
// and the target type is timezone naive. The serialization does not produce "Z",
// but we need to consider timezones when doing timezone ntz.
Timestamp(_) | TimestampNtz(_) => {
Timestamp(_) => {
// We need to manually append 'Z' add to end so that pyarrow can cast the
// the scalar value to pa.timestamp("us","UTC")
let value = value.serialize();
format!("{}Z", value).to_object(py)
}
TimestampNtz(_) => {
let value = value.serialize();
value.to_object(py)
}

// NOTE: PyArrow 13.0.0 lost the ability to cast from string to date32, so
// we have to implement that manually.
Date(_) => {
Expand Down