![](/img/trans.png)
[英]Scala - Spark - How to transform a dataframe containing one string column to a DF with columns with the rigth type?
[英]How to concatenate two string columns or a literal to string column using 1.4 DF API (Scala)
當我嘗試使用“ +”函數將兩個字符串列或一個文字與一個字符串列連接在一起時,結果始終為null。
auction.select(col("item") ) show
+----+
|item|
+----+
|xbox|
+----+
因此,該列就可以了。 但是+運算符總是產生null。 我在1.4 API中找不到concat
函數。
auction.select(col("item") + col("item")) show
+-------------+
|(item + item)|
+-------------+
| null|
+-------------+
文字也是如此
auction.select(lit("Blue ") + col("item")) show
+--------------+
|(Blue + item)|
+--------------+
| null|
+--------------+
您始終可以將DataFrame注冊為表,然后通過SQL查詢它:
auction.registerTempTable("auction")
val concatenated = sqlContext.sql("SELECT CONCAT(item, ' ', item) FROM auction")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.