Scala 使用spark sql查询时,时间戳字段将失去精度
使用Spark SQL从Scala 使用spark sql查询时,时间戳字段将失去精度,scala,apache-spark,hive,apache-spark-sql,Scala,Apache Spark,Hive,Apache Spark Sql,使用Spark SQL从Hive Metastore查询同一个表时,时间戳字段将失去精度 我的表格描述如下: col_name data_type comment id bigint null name string null joined_time timestamp null 使用配置单元QL,我获得了joined\u time毫秒精度值。 配置单元QL结果: select * from employees; 1 foo 2016-07
Hive Metastore
查询同一个表时,时间戳字段将失去精度
我的表格描述如下:
col_name data_type comment
id bigint null
name string null
joined_time timestamp null
使用配置单元QL,我获得了joined\u time
毫秒精度值。
配置单元QL结果:
select * from employees;
1 foo 2016-07-04 02:12:10.0
2 bar 2016-07-04 02:12:10.0
在使用sparksql
时,我会丢失精度,最长可达几分钟。e、 g:
val result = sqlContext.sql("select * from employees")
result.show()
1 foo 2016-07-04 02:12:...
2 bar 2016-07-04 02:12:...
它并没有失去精确性。它刚刚截断了显示 由于Spark 1.6,您可以使用
result.show(false)
现在使用时间戳:
sqlContext.sql("select current_timestamp()").show
// +--------------------+
// | _c0|
// +--------------------+
// |2017-02-10 14:40:...|
// +--------------------+
sqlContext.sql("select current_timestamp()").show(false)
// +-----------------------+
// |_c0 |
// +-----------------------+
// |2017-02-10 14:40:14.038|
// +-----------------------+
它并没有失去精确性。我刚刚截断了显示器。您可以使用result.show(false)@eliasah显示它。没有带布尔参数的show方法。它表示错误:需要类型不匹配。您是哪个版本的spark?我每天都使用它:)我在cloudera-quick-start-vm-5.4.2中使用spark 1.3.0,对于spark数据帧,请参见
sqlContext.sql("select current_timestamp()").show
// +--------------------+
// | _c0|
// +--------------------+
// |2017-02-10 14:40:...|
// +--------------------+
sqlContext.sql("select current_timestamp()").show(false)
// +-----------------------+
// |_c0 |
// +-----------------------+
// |2017-02-10 14:40:14.038|
// +-----------------------+