Day 14 / Mar 18 (Fri)¶
Scala Topics¶
- Imports and packages
- String interpolators (
s,f) this- for-comprehension
Exercise: DataFrame Data Structure (continued)¶
Developing DataFrame data structure similarly to Spark SQL's DataFrame (that is a type alias of Dataset:
show()join(right: DataFrame, on: Seq[String]): DataFrame- (extra)
select(cols: Seq[String]): DataFrame
Tips¶
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.
- 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)¶
- for-comprehension and
ifguard - Partial function (
case) HashMap