【问题标题】:DATE-TIME / TIMESTAMP field in parquet file shown as numbers in Parquet file viewersParquet 文件中的 DATE-TIME / TIMESTAMP 字段在 Parquet 文件查看器中显示为数字
【发布时间】:2021-10-14 21:16:00
【问题描述】:

假设我有一个 data.frame/tibble 如下:

library(readr)
library(arrow)

# testFyl was originally read from a csv file with readr::read_csv()

testFyl <- structure(list(
  BILL_NO = c("36/2015-16", "39/15-16", "771", "254", "731", "610", "200", "23 /2015-16", "21/2015-16", "30/15-16"),
  BILL_DT_TIME = structure(c(1438021800, 1436898600, 1438021800, 1436293800, 1437935400, 1437589800, 1436207400, 1438108200, 1437676200, 1437330600), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
  BILL_DT = structure(c(16643, 16630, 16643, 16623, 16642, 16638, 16622, 16644, 16639, 16635), class = "Date")),
  spec = structure(list(cols = list(BILL_NO = structure(list(), class = c("collector_character", "collector")), BILL_DT_TIME = structure(list(format = ""), class = c("collector_datetime", "collector")), BILL_DT = structure(list(format = ""), class = c("collector_date", "collector"))), default = structure(list(), class = c("collector_guess", "collector")), delim = ","), class = "col_spec"), row.names = c(NA, -10L), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"))

testFyl 看起来像:

# A tibble: 10 x 3
   BILL_NO     BILL_DT_TIME        BILL_DT   
   <chr>       <dttm>              <date>    
 1 36/2015-16  2015-07-27 18:30:00 2015-07-27
 2 39/15-16    2015-07-14 18:30:00 2015-07-14
 3 771         2015-07-27 18:30:00 2015-07-27
 4 254         2015-07-07 18:30:00 2015-07-07
 5 731         2015-07-26 18:30:00 2015-07-26
 6 610         2015-07-22 18:30:00 2015-07-22
 7 200         2015-07-06 18:30:00 2015-07-06
 8 23 /2015-16 2015-07-28 18:30:00 2015-07-28
 9 21/2015-16  2015-07-23 18:30:00 2015-07-23
10 30/15-16    2015-07-19 18:30:00 2015-07-19

请注意,BILL_DT 列与 BILL_DT_TIME 列具有相同的日期,但已删除时间信息。

现在,用parquet 格式写这个表格

write_parquet(testFyl, "testFyl.parquet")

在将这个parquet 文件读回 R 时,使用

read_parquet("testFyl.parquet")

一切都很好。正如预期的那样,该表与上面完全相同。

但是,当我使用以下两个外部 parquet 文件查看工具加载此 parquet 文件时,它们以我不理解的格式显示日期:

1. ParquetViewer来自https://github.com/mukunku/ParquetViewer

这里,BILL_DT_TIME 列显示的数字对我来说很奇怪。

2。大数据文件查看器来自https://github.com/Eugene-Mark/bigdata-file-viewer

在这里,BILL_DT_TIME 和 BILL_DT 列显示了我不明白的数字。这些数字在使用 dput 函数保存 data.frame 时显示。

看到 ParquetViewer 中的date-time(奇怪)和date(可理解)列,似乎可以对 R 环境中的date-time 列进行一些格式化,然后以parquet 格式导出它,以便它将在 ParquetViewer 中正确显示。谁能帮我弄清楚?

编辑: 同时,我在 github https://github.com/mukunku/ParquetViewer/issues/40

提出了一个问题(功能请求)

Edit2: 开发人员已慷慨更新 ParquetViewer,以以人类可理解的格式显示时间戳。这样这个问题就解决了。

【问题讨论】:

    标签: r parquet apache-arrow


    【解决方案1】:

    这种格式称为“时间戳”。 这是一个以微秒表示的 Unix 时间戳。

    https://www.epochconverter.com/

    https://github.com/apache/parquet-format/blob/master/LogicalTypes.md

    当前用于这些格式的 GUI 查看器应用程序非常有限。

    【讨论】:

    • R 将时间戳保存为自 1970 年 1 月 1 日以来的秒数这一事实已经从我的脑海中消失了——也许是因为到目前为止,时间对我的工作来说微不足道,而我一直只使用日期组件- 始终以人类可理解的格式正确显示。
    猜你喜欢
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多