import org.apache.spark.sql.expressions.Window val departmentById = Window .partitionBy("department") .orderBy("id") .rangeBetween(Window.unboundedPreceding, Window.unboundedFollowing)