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:
-
Reverse the Order of Time Bytes: Int96 timestamps utilize reverse byte order. Therefore, the time bytes (the first 8) should be reversed.
-
Calculate Time in Nanoseconds: Interpret the reversed time bytes as an integer to determine the time in nanoseconds.
-
Obtain the Julian Day Number: Reverse the remaining 4 bytes to obtain the Julian Day Number.
-
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]
- Reverse the time bytes: [0 0 0 0 29 32 4B FD 60]
- Convert to nanoseconds: 0x60FD4B3229000000 = 45296 * 10^9 nanoseconds
- Reverse the date bytes: [0 25 68 59]
- Convert to Julian Day Number: 0x59682500 = 2451545
- 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!
Statement: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