本文整理汇总了Scala中org.apache.spark.sql.functions.count类的典型用法代码示例。如果您正苦于以下问题:Scala count类的具体用法?Scala count怎么用?Scala count使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了count类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: NumberOfRowsConstraint
//设置package包名称以及导入依赖的类
package be.dataminded.wharlord.constraints
import org.apache.spark.sql.functions.count
import org.apache.spark.sql.{Column, DataFrame}
case class NumberOfRowsConstraint(expected: Column) extends Constraint {
val fun: (DataFrame) => NumberOfRowsConstraintResult = (df: DataFrame) => {
val countDf = df.agg(count(new Column("*")).as(NumberOfRowsConstraint.countKey))
val actual = countDf.collect().map(_.getLong(0)).apply(0)
val satisfied = countDf.select(expected).collect().map(_.getBoolean(0)).apply(0)
NumberOfRowsConstraintResult(
constraint = this,
actual = actual,
status = if (satisfied) ConstraintSuccess else ConstraintFailure
)
}
}
object NumberOfRowsConstraint {
private[constraints] val countKey: String = "count"
def apply(expected: Column => Column): NumberOfRowsConstraint = {
new NumberOfRowsConstraint(expected(new Column(countKey)))
}
}
case class NumberOfRowsConstraintResult(constraint: NumberOfRowsConstraint,
actual: Long,
status: ConstraintStatus) extends ConstraintResult[NumberOfRowsConstraint] {
val message: String = {
val expected = constraint.expected
status match {
case ConstraintSuccess => s"The number of rows satisfies $expected."
case ConstraintFailure => s"The actual number of rows $actual does not satisfy $expected."
case _ => throw IllegalConstraintResultException(this)
}
}
}