蜂巢表架构:
c_date date
c_timestamp timestamp
这是文本表
蜂巢表数据:
hive> select * from all_datetime_types;
OK
0001-01-01 0001-01-01 00:00:00.000000001
9999-12-31 9999-12-31 23:59:59.999999999
火花工作后获得的csv:
c_date,c_timestamp
0001-01-01 00:00:00.0,0001-01-01 00:00:00.0
9999-12-31 00:00:00.0,9999-12-31 23:59:59.999
Issues:
日期类型中添加了
-
00:00:00.0
-
timestamp被截断为毫秒精度
实用代码:
SparkConf conf = new SparkConf(true).setMaster("yarn-cluster").setAppName("SAMPLE_APP");
SparkContext sc = new SparkContext(conf);
HiveContext hc = new HiveContext(sc);
DataFrame df = hc.table("testdb.all_datetime_types");
df.printSchema();
DataFrameWriter writer = df.repartition(1).write();
writer.format("com.databricks.spark.csv").option("header", "true").save(outputHdfsFile);
我知道 dateFormat
选项 . 但是 date
和 timestamp
列在Hive中可以有不同的格式 .
Can I simply covert all columns to String?
2 回答
您可以使用spark中的
timestampFormat
选项指定时间戳格式 .Spark支持高达纳秒的Timestamp精度 . 您可以尝试映射日期和时间戳列,如下所示,