This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Author: github.com/ganeshchand | |
* Date: 03/04/2021 | |
* Specifying schema when reading different source format is mandatory or optional depending on which DataFrameReader you are using. | |
* spark.read() is a batch DataFrame reader | |
* spark.readStream() is a streaming DataFrame reader | |
* Let's write a quick test to test which reader enforces us to specify schema on read | |
*/ | |
// step1: Let's generate test dataset for csv, json, parquet, orc and delta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.hadoop.fs.{FileSystem, Path} | |
import org.apache.hadoop.conf.Configuration | |
case class S3File(path: String, isDir: Boolean, size: Long) { | |
def children = listFiles(path) | |
} | |
def listFiles(path: String): Seq[S3File] = { | |
val fs = FileSystem.get(new java.net.URI(path), new Configuration()) | |
fs.listStatus(new Path(path)).map(s => S3File(s.getPath.toString, s.isDir, s.getLen)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ScalaJSExample extends js.JSApp{ | |
def main() = { | |
val xs = Seq(1, 2, 3) | |
println(xs.toString) | |
val ys = Seq(4, 5, 6) | |
println(ys.toString) | |
val zs = for{ | |
x <- xs | |
y <- ys | |
} yield x * y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package object mail { | |
implicit def stringToSeq(single: String): Seq[String] = Seq(single) | |
implicit def liftToOption[T](t: T): Option[T] = Some(t) | |
sealed abstract class MailType | |
case object Plain extends MailType | |
case object Rich extends MailType | |
case object MultiPart extends MailType |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Product | |
abstract class PizzaBuilder { | |
var dough: String | |
var sauce: String | |
var topping: String | |
def withDough(dough: String): PizzaBuilder | |
def withSauce(sauce: String): PizzaBuilder | |
def withTopping(topping: String): PizzaBuilder |