Describe the bug
I can not create a PrimitiveArray that has a DataType::Timestamp with a timezone other than None
To Reproduce
I am trying to pretty print an array that has timestamps using UTC time.
So instead of 1970-01-01 00:00:00.000000100 I want to print something more like the following (note the Z, in RFC3339): 1970-01-01T00:00:00.000000100Z
To do so I figured I would "simply" create a new array that had a Timestamp type with the timezone set to UTC
TimestampNanosecondArray is defined like this:
pub type TimestampNanosecondArray = PrimitiveArray<TimestampNanosecondType>;
And TimestampNanosecondType is (effectively) something like
struct TimestampNanosecondType {}
impl ArrowPrimitiveType for TimestampNanosecondType {
type Native = i64;
const DATA_TYPE = DataType::Timestamp(TimeUnit::Nanosecond, None)
}
So I figured I would make a PrimitiveArray<SOME_TYPE_THAT_HAD_MY_TIMEZONE_SPECIFIED>
struct TimestampUtcNanosecondType {}
impl ArrowPrimitiveType for TimestampUtcNanosecondType {
type Native = i64;
const DATA_TYPE: DataType = DataType::Timestamp(TimeUnit::Nanosecond, Some("+00:00".to_string()));
}
Uhoh! The compiler doesn't like that because it needs a const String which you can't have....
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> src/main.rs:38:80
|
38 | const DATA_TYPE: DataType = DataType::Timestamp(TimeUnit::Nanosecond, Some("+00:00".to_string()));
| ^^^^^^^^^^^^^^^^^^^^
So I conclude it is basically impossible to create an array with a timezone other than None
Expected behavior
I expect to be able to create an array using a timezone
Proposal
Proposal:
Change DataType::Timestamp from
Timestamp(TimeUnit, Option<String>),
to
Timestamp(TimeUnit, Option<&static str>),
Additional context
FWIW I also tried using lazy_static but it doesn't provide a const String (only a static String)
I view this as a potential first step towards handling timestamps properly in arrow and datafusion: apache/datafusion#686
Describe the bug
I can not create a
PrimitiveArraythat has aDataType::Timestampwith a timezone other thanNoneTo Reproduce
I am trying to pretty print an array that has timestamps using UTC time.
So instead of
1970-01-01 00:00:00.000000100I want to print something more like the following (note the Z, in RFC3339):1970-01-01T00:00:00.000000100ZTo do so I figured I would "simply" create a new array that had a Timestamp type with the timezone set to UTC
TimestampNanosecondArrayis defined like this:And
TimestampNanosecondTypeis (effectively) something likeSo I figured I would make a
PrimitiveArray<SOME_TYPE_THAT_HAD_MY_TIMEZONE_SPECIFIED>Uhoh! The compiler doesn't like that because it needs a
const Stringwhich you can't have....So I conclude it is basically impossible to create an array with a timezone other than
NoneExpected behavior
I expect to be able to create an array using a timezone
Proposal
Proposal:
Change
DataType::Timestampfromto
Additional context
FWIW I also tried using
lazy_staticbut it doesn't provide aconst String(only astatic String)I view this as a potential first step towards handling timestamps properly in arrow and datafusion: apache/datafusion#686