Skip to content

Instantly share code, notes, and snippets.

import org.apache.spark.sql.Column
def treeFold(
  columns: List[Column],
  initialValue: Column,
  op: (Column, Column) => Column
): Column = {
  if (columns.isEmpty) {
    initialValue
  } else if (columns.length == 1) {
@IvanVergiliev
IvanVergiliev / exponential_tree_transform
Created June 21, 2021 16:01
Exponential Tree Transformation Complexity
f(H) =
  f(H - 1) // for the first transform call
  +
  f(H - 1) // for the second transform call
= 2 * f(H - 1) =
= 2 * 2 * f(H - 2) = ... = 2 ^ (H - 1) * f(1) // unfolding further
@IvanVergiliev
IvanVergiliev / predicate_fold.scala
Created June 21, 2021 16:04
Fold a list of predicates
val andPredicates: Array[Column] = parseAndPredicates(...)
val compositePredicate: Column = andPredicates.foldLeft(lit(true))((x, y) => x && y)