如何使用scala将过滤器从apache.spark.sql应用于RelationalGroupedDataSet类?

发布于 2025-02-07 10:26:59 字数 735 浏览 3 评论 0原文

我试图找到一个过滤器函数(获取列表类型对象,并且功能st函数应为输入列表元素的类型,并应返回一个bool值,并且这两个函数的过滤器的输出包含原始列表该函数在元素上返回true的元素)。

当我尝试应用过滤器时,我会出现错误。是否有任何方法可以将过滤器应用于RelationalGroupedDataSet? (我在附带的文档中找不到任何内容: https://spark.apache.org/docs/2.4.4/api/java/java/org/org/apache/spark/sql/sql/relationalgroupeddataset.html

)对于我应该如何访问关系群的特定列值?

谢谢!

原始呼叫

错误消息

I was trying to find a filter function (takes a List type object and a function s.t. the function should be of type of the input list elements and should return a bool value, and the output of the filter of these two functions contains the original list element in which the function returns true on the element).

When I try to apply filter, I get an error. Are there any ways to apply filter to a RelationalGroupedDataset? (I wasn't able to find any in the attached docs: https://spark.apache.org/docs/2.4.4/api/java/org/apache/spark/sql/RelationalGroupedDataset.html)

Also, is there proper notation for how I should be accessing a specific column value for a RelationalGroupedDataset?

Thanks!

Original Call

Error Message

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终难遇 2025-02-14 10:26:59

这是一个例子:

df.groupBy("department")
  .agg(
    sum("salary").as("sum_salary"),
    avg("salary").as("avg_salary"),
    sum("bonus").as("sum_bonus"),
    max("bonus").as("max_bonus"))
  .where(col("sum_bonus") >= 50000)
  .show(false)

它应该为您提供指导。

Here is is an example:

df.groupBy("department")
  .agg(
    sum("salary").as("sum_salary"),
    avg("salary").as("avg_salary"),
    sum("bonus").as("sum_bonus"),
    max("bonus").as("max_bonus"))
  .where(col("sum_bonus") >= 50000)
  .show(false)

It should give you guidance.

左岸枫 2025-02-14 10:26:59

尝试将:_*添加到Groupby中:

def showGroupByDesc(df: DataFrame, cols: Column*): Unit = {
  df.groupBy(cols:_*).count().sort($"count".desc).show()
}

这是一种特殊的语法,用于将参数传递给Scala中的Varargs函数。

没有:_*编译器正在寻找接受seq [列]的函数,并且找不到它。

您可以在此处使用varargs阅读更多有关varargs的信息。

Try to add :_* to passed cols into groupBy:

def showGroupByDesc(df: DataFrame, cols: Column*): Unit = {
  df.groupBy(cols:_*).count().sort(
quot;count".desc).show()
}

it's a special syntax for passing arguments to varargs functions in scala.

Without :_* compiler is looking for function which accepts Seq[Column] and will not found it.

You can read more about functions with varargs here for example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文