“表达式不存在于组中,也不是聚合函数".这是怎么了 [英] "expression is neither present in the group by, nor is it an aggregate function" what is wrong here?

查看:209
本文介绍了“表达式不存在于组中,也不是聚合函数".这是怎么了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在数据框上应用以下数据透视

I am trying to apply a pivot on my dataframe as below

val pivot_company_model_vals_df =  company_model_vals_df.groupBy("company_id","id","date")
                          .pivot("code")
                          .agg( when( col("data_item_value_numeric").isNotNull,  
      first("numeric")).otherwise(first("value")) )

错误

         org.apache.spark.sql.AnalysisException: expression '`data_item_value_numeric`' is neither present in the group by, nor is it an aggregate function. 

您能帮我在这里做错什么吗? 谢谢

Could you please help me what am I doing wrong here? Thank you

推荐答案

问题已将first像下面的.agg( first(when一样移动:

Issue fixed moving the first like below .agg( first(when:

val pivot_company_model_vals_df =  company_model_vals_df.groupBy("company_id","model_id","data_date")
                          .pivot("code")
                          .agg( first(when( col("data_item_value_numeric").isNotNull,  
      col("numeric")).otherwise(col("_string")) ) )

这篇关于“表达式不存在于组中,也不是聚合函数".这是怎么了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆