我有這樣一段代碼:
val df = resultsDf
.withColumn("data_exploded"/span>, explode(col("data_item"/span>))
.groupBy("data_id","data_count")
.agg(
count(lit(1)).as("aggDataCount") 。
sum(當(col("data_exploded.amount")==="A",col("data_exploded. positive_amount")).否則(lit(0)).as("aggAmount")
)
lit(0)是指位置為0的索引,還是指數字0的字面價值?我在https://mungingdata. com/apache-spark/spark-sql-function/#:~:text=The lit() function creates,spanish_hi column to the DataFrame. &text=The lit() function especially useful when boolean comparisons說:"lit()函式從一個字面值中創建一個Column物件。" 這個定義讓我覺得它不是指一個索引位置,而是指一個字面值,如數字或字串。然而,count(lit(1)).as("aggDataCount")中的用法在我看來是指一個列的索引位置。謝謝你。
uj5u.com熱心網友回復:
lit(1)意味著字面價值1
count(lit(1)).as("aggDataCount")是一種計算行數的方法(每一行都有一個值為1的列,并對這個列求和)
uj5u.com熱心網友回復:
在火花中lit代表字面價值。
lit(0)--> 把0作為一列的值,lit(1) --> 表示把1作為一列的值。
在你上面顯示的代碼中,他們在2列上應用了一個聚合,并從count(lit(1))中保留了多少行的計數,超過一個條件。
下一個lit(0)是在otherwise子句中,這就像一個else條件。lit(0)將在列中添加0作為一個字面值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/309124.html
標籤:
