我有一个列名称为“ product / price”的表,我想在sparksql中创建现有表的副本时将其重命名为product_price。
创建表newtable作为选择产品/价格,并将其作为product_price 现有表格
这给了我错误“分析异常错误:无法解析'产品'
我也尝试过如下操作:
创建表newtable作为select'product / price'作为product_price 从现有表中
这确实会更改列名,但其中的所有值也会更改为product_price。
答案 0 :(得分:0)
// select `product/price` as product_price .... to your column ?
//
val d1 = Seq("test", "Test1", "test2").toDF("product/price")
d1.show(false)
// +-------------+
// |product/price|
// +-------------+
// |test |
// |Test1 |
// |test2 |
// +-------------+
val d2 = d1.withColumnRenamed("product/price", "product_price")
d2.show(false)
// +-------------+
// |product_price|
// +-------------+
// |test |
// |Test1 |
// |test2 |
// +-------------+