Home > Backend Development > Golang > How Do I Convert a Parquet Int96 Timestamp to a Go Timestamp?

How Do I Convert a Parquet Int96 Timestamp to a Go Timestamp?

Mary-Kate Olsen
Release: 2024-12-21 17:41:10
Original
899 people have browsed it

How Do I Convert a Parquet Int96 Timestamp to a Go Timestamp?

Casting Int96 Timestamp from Parquet to Go

To cast an int96 value representing a timestamp from a Parquet file to a Go timestamp, follow these steps:

  1. Separate the Int96 Value: The int96 timestamp is a 12-byte array consisting of two parts:

    • First 8 bytes: Time in nanoseconds, stored in reversed byte order
    • Last 4 bytes: Date as a Julian day number
  2. Parse Time from First 8 Bytes:

    • Reverse the bytes to get the correct time value (0x000029324BFD6000 in the given example)
    • Divide the value by 10^9 to convert nanoseconds to seconds (45296 seconds in this case)
  3. Extract Date from Last 4 Bytes:

    • Reverse the bytes to get the Julian day number (0x00256859 in the example)
    • Use a library or calculate manually to convert the Julian day number to a Go timestamp (2000-01-01 12:34:56 in this case)
  4. Compose Timestamp: Combine the parsed time and date to create a Go timestamp representing the original int96 value.

Note: The int96 timestamp in Parquet is not measured from the epoch but from midnight. Keep this in mind when converting to a Go timestamp.

The above is the detailed content of How Do I Convert a Parquet Int96 Timestamp to a Go Timestamp?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template