开发者社区> 问答> 正文

如何从sql(不是DSL)访问Spark嵌套结构字段

如何从sql(不是DSL)访问Spark嵌套结构字段
在下文中sql,需要访问嵌套的语法struct。

具体如下第三行:

collect_list(struct( .. ) )
我已经提出rec.*但这当然不是正确的方法。

select matchMethod, rec.* from

                          (select first(matchMethod) matchMethod,
                            collect_list(struct(rawTp,tp,fp,fn,
                                    precision,recall,weight,F1,
                                    truthGrpId,entityId,
                                    tpIds,fpIds, fnIds,truthIds,actuals)) rec
                               from scoring5
                                  where entityId is not null and truthGrpId is not null
                              group by truthGrpId
                          ) order by rec.truthGrpId, rec.recall desc

这导致:

org.apache.spark.sql.AnalysisException:
Can only star expand struct data types. Attribute: ArrayBuffer(rec);
我们正在使用spark 2.3.X。

展开
收起
社区小助手 2018-12-19 15:57:29 2021 0
1 条回答
写回答
取消 提交回答
  • 社区小助手是spark中国社区的管理员,我会定期更新直播回顾等资料和文章干货,还整合了大家在钉群提出的有关spark的问题及回答。

    目前不支持上述内容。似乎有一些帮助以下列形式出现Spark 2.4:请参阅Jacek Laskowski的回答:

    在任何情况下,我发现使用windowing如下函数更直接的方法:

    select * from
    (select row_number() over (partition by truthGrpId order by recall desc) rownum,*

    from
    (select matchMethod, rawTp,tp,fp,fn,
        precision,recall,weight,F1,
        truthGrpId,entityId,
        tpIds,fpIds, fnIds,truthIds,actuals
      from scoring5
      where entityId is not null and truthGrpId is not null
    ) order by truthGrpId, recall desc

    ) where rownum=1 order by truthGrpId""")

    2019-07-17 23:22:59
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
SQL Server在电子商务中的应用与实践 立即下载
GeoMesa on Spark SQL 立即下载
原生SQL on Hadoop引擎- Apache HAWQ 2.x最新技术解密malili 立即下载