我有一段代码:
val df = resultsDf
.withColumn("data_exploded", explode(col("data_item")))
.groupBy("data_id","data_count")
.agg(
count(lit(1)).as("aggDataCount"),
sum(when(col("data_exploded.amount")==="A",col("data_exploded.positive_amount")).otherwise(lit(0))).as("aggAmount")
)lit(0)是引用位置0的索引,还是引用数字0的文字值?我在The `lit()` function creates a Column object out of a literal value." That definition makes me think that it is not referring to an index position but to a literal value such as a number or String. However, the usage in `count(lit(1)).as("aggDataCount中看到的定义对我来说就像是指一列的索引位置。谢谢。
发布于 2021-09-07 15:41:10
lit(1)表示文字值1
count(lit(1)).as("aggDataCount")是一种计算行数的方法(每行都有一个值为1的列,并对该列求和)
发布于 2021-09-07 15:52:45
在spark lit中表示字面值。
lit(0)-->放0作为列的值,lit(1) -->表示放1作为列的值。
在上面显示的代码中,他们在2列上应用了聚合,并在一个条件上保留了count(lit(1))中的多少行的计数。
下一个lit(0)在else子句中,它类似于else条件。lit(0)将在列中添加0作为文字值。
https://stackoverflow.com/questions/69090842
复制相似问题