简体   繁体   English

聚合函数 Spark SQL

[英]aggregate function Spark SQL

I am working with Pyspark 2.2 rn, my code crashes by this function and I don't understand why it's crashed on ->我正在使用 Pyspark 2.2 rn,我的代码被这个函数崩溃了,我不明白为什么它会崩溃->

code代码

import Pyspark.sql.functions as F
t.withColumns('column_name',
              F.expr("aggregate(column, '', (acc, x) -> acc || concat(x, 4) ','))"))

error like - "extraneous input '>' expecting 'all of sql functions'"错误,例如 - “外部输入 '>' 期望 '所有 sql 函数'”

ty for ur help求你的帮助

Three suggestions.三个建议。

  1. Remove the ',')) : those parentheses are unmatched.删除',')) :这些括号是不匹配的。

  2. Use either …||… or concat(…,…) ;使用…||…concat(…,…) ; no need for both.两者都不需要。

  3. Because the column expression contains > and the column is not aliased, spark is trying to turn the expression itself into the column name, but column names cannot contain > , as the OP's error message alludes to.因为列表达式包含>并且列没有别名,spark 试图将表达式本身转换为列名,但列名不能包含> ,正如 OP 的错误消息所暗示的那样。

    Solution: Alias the column.解决方案:别名列。

    (See screenshot. Yes, the screenshot uses spark SQL instead of pyspark, but the OP's issue is with the spark SQL snippet within the pyspark.) (见屏幕截图。是的,屏幕截图使用 spark SQL 而不是 pyspark,但 OP 的问题在于 pyspark 中的 spark SQL 片段。)

具有函数聚合的 Spark SQL 列必须具有别名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM