alamb opened a new issue #597:
URL: https://github.com/apache/arrow-rs/issues/597


   **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:
   ```rust
   pub type TimestampNanosecondArray = PrimitiveArray<TimestampNanosecondType>;
   ```
   
   And `TimestampNanosecondType` is (effectively) something like
   ```rust
   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>`
   
   ```rust
   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
   ```rust
   Timestamp(TimeUnit, Option<String>),
   ```
   to
   ```rust
   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: https://github.com/apache/arrow-datafusion/issues/686


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to