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

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

DDD
Release: 2024-12-20 05:29:17
Original
747 people have browsed it

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

Converting an Int96 Timestamp from Parquet to Go

The task at hand involves transforming a 12-byte int96 timestamp stored in Parquet format into a Go-compatible timestamp. The int96 format accommodates timestamps as an ordered array of 12 bytes, where the first 8 bytes represent time in nanoseconds and the remaining 4 bytes symbolize the date in Julian Day Number.

Detailed Conversion Process:

  1. Reverse the Order of Time Bytes: Int96 timestamps utilize reverse byte order. Therefore, the time bytes (the first 8) should be reversed.
  2. Calculate Time in Nanoseconds: Interpret the reversed time bytes as an integer to determine the time in nanoseconds.
  3. Obtain the Julian Day Number: Reverse the remaining 4 bytes to obtain the Julian Day Number.
  4. Convert Julian Day Number to Date: Use a library or function to convert the Julian Day Number to a date object.

Example:

Consider an int96 timestamp as a 12-byte array: [128 76 69 116 64 7 0 0 48 131 37 0]

  1. Reverse the time bytes: [0 0 0 0 29 32 4B FD 60]
  2. Convert to nanoseconds: 0x60FD4B3229000000 = 45296 * 10^9 nanoseconds
  3. Reverse the date bytes: [0 25 68 59]
  4. Convert to Julian Day Number: 0x59682500 = 2451545
  5. Convert to Date: Using a suitable library/function, convert the Julian Day Number to the corresponding date, which in this case is 2000-01-01

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

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template