数据框字符串到 Hive table Bigint - 如何转换
Dataframe string to Hive table Bigint - How to convert
Spark:1.6、Scala、Hive
我有一个数据框DF.printschema
root
|-- rundatetime: string (nullable = true)
|-- day_cunt: String (nullable = true)
|-- my_key: integer (nullable = true)
DF.show()
rundatetime |day_cunt | my_key
2017-04-21 11:00:06 | 5 |10
2017-04-21 12:10:06 | 15 |1000
我的蜂巢 table 是
rundatetime String,
day_cunt BigInt,
my_key Int
Stored as Parquet;
如何将数据帧值保存到 Hive table?请注意 DF 和 hive table 数据类型不同。
BigInt
不是 Spark DataFrames
的 supported data type。
您可以通过将 day_count
转换为 Long
来创建中间数据框:
val newDF = df.select($"rundatetime", $"day_count".cast("Long"), $"my_key")
使用 cast("BigInt")
进行转换不会引发错误,但实际上只会转换为 Long
数据类型。
Spark:1.6、Scala、Hive
我有一个数据框DF.printschema
root
|-- rundatetime: string (nullable = true)
|-- day_cunt: String (nullable = true)
|-- my_key: integer (nullable = true)
DF.show()
rundatetime |day_cunt | my_key
2017-04-21 11:00:06 | 5 |10
2017-04-21 12:10:06 | 15 |1000
我的蜂巢 table 是
rundatetime String,
day_cunt BigInt,
my_key Int
Stored as Parquet;
如何将数据帧值保存到 Hive table?请注意 DF 和 hive table 数据类型不同。
BigInt
不是 Spark DataFrames
的 supported data type。
您可以通过将 day_count
转换为 Long
来创建中间数据框:
val newDF = df.select($"rundatetime", $"day_count".cast("Long"), $"my_key")
使用 cast("BigInt")
进行转换不会引发错误,但实际上只会转换为 Long
数据类型。