DataFrame.select(min(substring(col("A"),2,8)),max(substring(col("A"),2,8)),sum(col("B")))
df.withColumn("acc_ip_cnt_percent",col("acc_ip_cnt")/max("acc_ip_cnt"))#相求登录次数累加后百分比例
#拆解为
df.withColumn("max_test",max("acc_ip_cnt")) #也会报同样的错误
>>>
AnalysisException: u"grouping expressions sequence is empty, and '`xxxx`' is not an aggregate function. Wrap '(max(`xxxx`) AS `xxx`) ……
报错提示需要aggregate by信息
①是我用错了,不能使用col("A")来取A列的值再substring,
②withColumn的方法中,max/min/等操作必须要有grouping的信息
解决方案:应该直接用select方法去求得列最大值,例如substring("A",2,8) 取a列的第二个字符起的八位字符,取最大值、最小值做时间字符窜,这样才不会提示需要aggregate by的错误
方法一:如果使用Window窗口相关信息,不报错,但是数据太大(亿级),直接OOM。而且明显加大处理时间不可取
df.select(min("A").over(Window.rowsBetweens(Window.unboundedPreceding