Skip to content

Day 14 / Mar 18 (Fri)

Scala Topics

  1. Imports and packages
  2. String interpolators (s, f)
  3. this
  4. for-comprehension

Exercise: DataFrame Data Structure (continued)

Developing DataFrame data structure similarly to Spark SQL's DataFrame (that is a type alias of Dataset:

  1. show()
  2. join(right: DataFrame, on: Seq[String]): DataFrame
  3. (extra) select(cols: Seq[String]): DataFrame

Tips

  1. case class DataFrame(rows: Seq[Seq[Any]], colNames: Seq[String])

Exercise: Finding Same Elements in Two Sequences

Write a function that finds the same elements (matches) of two sequences.

  1. Use Seq.intersect.

Exercise: matchById

Write a function that returns the elements at given positions.

def matchById(
  left: Seq[Any],
  right: Seq[Any],
  ids: Seq[Int]): (Seq[Any], Seq[Any]) = ???

Exercise: rowsByMatchesAndIds

Write a function that finds rows (among the rows) with values (matches) at given positions (ids).

def rowsByMatchesAndIds[T](
  rows: Seq[Seq[T]],
  values: Seq[T],
  ids: Seq[Int]): Seq[Seq[T]] = ???

Example

Given the following:

val rows = Seq(
    Seq("zero", true, 8),
    Seq("one", false, 3))
val values = Seq(true, 8)
val ids = Seq(1, 2)

Only Seq("zero", true, 8) row matches values true and 8 at the positions 1 and 2.

assert(rowsByMatchesAndIds(rows, values, ids) == Seq(Seq("zero", true, 8)))

Scala Topics (soon)

  1. for-comprehension and if guard
  2. Partial function (case)
  3. HashMap
Back to top