Dataframe字符串到配置单元表bigint-如何转换

whhtz7ly  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(339)

Spark:1.6,scala,Hive
我有一个Dataframedf.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

我的 hive table是

rundatetime String,
day_cunt    BigInt,
my_key      Int
Stored as Parquet;

如何将Dataframe值保存到配置单元表?请注意df和hive表数据类型不同。

gywdnpxw

gywdnpxw1#

BigInt 不支持的数据类型 Spark DataFrames .
您可以通过强制转换 day_countLong :

val newDF = df.select($"rundatetime", $"day_count".cast("Long"), $"my_key")

铸造 cast("BigInt") 不会抛出错误,但实际上只是向 Long 数据类型。

相关问题