火花 - HiveContext |错误的时间戳(减去 4 小时)
Spark - HiveContext | Wrong Timestamps (substracts 4 hours)
我尝试使用 SparkSQL (HiveContext) 做一些 ETL,我注意到时间戳有些不一致。
假设我们有一个 table 存储为镶木地板,有两列:时间戳、事件。
如果我使用 Hue 中的 Hive 编辑器查询此 table,一切正常。
SELECT * FROM mytable ORDER BY timestamp
使用 hiveContext.sql(query) 执行完全相同的查询将给出与 Hue 相同的结果,但具有(时间戳 - 4 小时)。
另一个例子,假设我们有这个 table:
Timestamp | event
--------------------------------------------------
'year-month-day 00:00:00' | "evt0"
'year-month-day 01:00:00' | "evt1"
'year-month-day 02:00:00' | "evt2"
'year-month-day 03:00:00' | "evt3"
'year-month-day 04:00:00' | "evt4"
'year-month-day 05:00:00' | "evt5"
'year-month-day 06:00:00' | "evt6"
'year-month-day 07:00:00' | "evt7"
'year-month-day 08:00:00' | "evt8"
我们运行 使用 Spark 和 HiveContext 进行以下查询:
SELECT * FROM mytable
WHERE timestamp BETWEEN 'year-month-day 00:00:00' AND 'year-month-day 08:00:00'
ORDER BY timestamp
结果:
Timestamp | event
--------------------------------------------------
'year-month-day 00:00:00' | "evt4"
'year-month-day 01:00:00' | "evt5"
'year-month-day 02:00:00' | "evt6"
'year-month-day 03:00:00' | "evt7"
'year-month-day 04:00:00' | "evt8"
当Hive 将时间戳值存储为Parquet 格式时,它会将本地时间转换为UTC 时间,当它读取数据时,它会转换回本地时间。看起来你们这里的当地时间是东部时间,因此有 4 小时的时差。使用 Hive 和 Parque 组合,您可能需要根据所需时区修改时间更改。我不是很清楚,Hue returns 是如何同时出现的。
我尝试使用 SparkSQL (HiveContext) 做一些 ETL,我注意到时间戳有些不一致。
假设我们有一个 table 存储为镶木地板,有两列:时间戳、事件。 如果我使用 Hue 中的 Hive 编辑器查询此 table,一切正常。
SELECT * FROM mytable ORDER BY timestamp
使用 hiveContext.sql(query) 执行完全相同的查询将给出与 Hue 相同的结果,但具有(时间戳 - 4 小时)。
另一个例子,假设我们有这个 table:
Timestamp | event
--------------------------------------------------
'year-month-day 00:00:00' | "evt0"
'year-month-day 01:00:00' | "evt1"
'year-month-day 02:00:00' | "evt2"
'year-month-day 03:00:00' | "evt3"
'year-month-day 04:00:00' | "evt4"
'year-month-day 05:00:00' | "evt5"
'year-month-day 06:00:00' | "evt6"
'year-month-day 07:00:00' | "evt7"
'year-month-day 08:00:00' | "evt8"
我们运行 使用 Spark 和 HiveContext 进行以下查询:
SELECT * FROM mytable
WHERE timestamp BETWEEN 'year-month-day 00:00:00' AND 'year-month-day 08:00:00'
ORDER BY timestamp
结果:
Timestamp | event
--------------------------------------------------
'year-month-day 00:00:00' | "evt4"
'year-month-day 01:00:00' | "evt5"
'year-month-day 02:00:00' | "evt6"
'year-month-day 03:00:00' | "evt7"
'year-month-day 04:00:00' | "evt8"
当Hive 将时间戳值存储为Parquet 格式时,它会将本地时间转换为UTC 时间,当它读取数据时,它会转换回本地时间。看起来你们这里的当地时间是东部时间,因此有 4 小时的时差。使用 Hive 和 Parque 组合,您可能需要根据所需时区修改时间更改。我不是很清楚,Hue returns 是如何同时出现的。