本文整理汇总了Scala中org.apache.spark.sql.functions.lit类的典型用法代码示例。如果您正苦于以下问题:Scala lit类的具体用法?Scala lit怎么用?Scala lit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了lit类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: naturalKeyColumns
//设置package包名称以及导入依赖的类
package org.alghimo.spark.dimensionalModelling
import org.apache.spark.sql._
import org.apache.spark.sql.expressions.Window
import org.apache.spark.sql.functions.{lit, max, row_number}
def naturalKeyColumns: Seq[String]
def enrichedDimensionsToDimensions(enrichedDims: EnrichedDimensions, refreshDimensionTable: Boolean = false): Dimensions = {
val dimensions = dimensionTable(refreshDimensionTable)
val maxSk = dimensions.select(max(surrogateKeyColumn)).as[Long].collect().head
val rankWindow = Window.partitionBy().orderBy(naturalKeyColumns.head, naturalKeyColumns.tail:_*)
enrichedDims
.withColumn(surrogateKeyColumnName, lit(maxSk) + (row_number() over rankWindow))
.withColumn(startTimestampColumnName, timestampColumn)
.withColumn(endTimestampColumnName, lit(null).cast("timestamp"))
.withColumn(isCurrentColumnName, lit(true))
.selectExpr(dimensions.columns:_*)
.as[DIM]
}
def keepOnlyMostRecentEvents(enrichedDimensions: EnrichedDimensions): EnrichedDimensions = {
val naturalKeyWindow = Window.partitionBy(naturalKeyColumns.map(new Column(_)):_*).orderBy(timestampColumn.desc)
enrichedDimensions
.withColumn("row_num", row_number() over naturalKeyWindow)
.filter("row_num = 1")
.drop("row_num")
.as[ENRICHED_DIM]
}
}