Hive 在Pyspark数据帧中保留时间戳类型
我正在将Hive 在Pyspark数据帧中保留时间戳类型,hive,pyspark,Hive,Pyspark,我正在将Pandas数据帧t的内容写入Pyspark中的一个配置单元表 t有一列Request\u time\u local,类型为pandas.tslib.Timestamp: In: print t.loc[0,'Request_time_local'] Out: 2016-12-09 13:01:27 col_name | data_type request_time_local | timestamp 配置单元表有一列request\u time\u
Pandas
数据帧t
的内容写入Pyspark
中的一个配置单元表
t
有一列Request\u time\u local
,类型为pandas.tslib.Timestamp
:
In: print t.loc[0,'Request_time_local']
Out: 2016-12-09 13:01:27
col_name | data_type
request_time_local | timestamp
配置单元表有一列request\u time\u local
,类型为timestamp
:
In: print t.loc[0,'Request_time_local']
Out: 2016-12-09 13:01:27
col_name | data_type
request_time_local | timestamp
我将t
转换为Pyspark数据帧
以写入蜂窝:
t_rdd = spark.createDataFrame(t)
t_rdd.registerTempTable("temp_result")
我的表中未填充request\u time\u local
列,但所有其他列都已填充
转换为Pyspark数据帧时,request\u time\u local
是一个bigint
unix时间戳:
spark.createDataFrame(t)
DataFrame[request_time_local: bigint, ...]
我通过将Pyspark数据帧
转换回pandas来检查这一点
t_check = t_rdd.toPandas()
In: print t_check.loc[0,'Request_time_local']
Out: 1481288487000000000
我想知道:
1) request\u time\u local
未能填充,因为我正在将bigint
从Pyspark数据帧写入配置单元表列中的timestamp
2) 是否有办法在Pyspark数据帧
中保留时间戳
类型,以便与配置单元表列类型兼容
(我意识到这里的一个解决方案是将配置单元列更改为int
并写入unix时间戳。)您可以尝试:
from pyspark.sql.functions import col
spark.createDataFrame(t) \
.withColumn("parsed", (col("Request_time_local") / 1000**3).cast("timestamp"))
您可以尝试:
from pyspark.sql.functions import col
spark.createDataFrame(t) \
.withColumn("parsed", (col("Request_time_local") / 1000**3).cast("timestamp"))