Skip to content

Instantly share code, notes, and snippets.

View ganeshchand's full-sized avatar

Ganesh Chand ganeshchand

View GitHub Profile
/**
* 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
@marmbrus
marmbrus / gist:15e72f7bc22337cf6653
Created November 27, 2014 03:10
Parallel list files on S3 with Spark
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))
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
@mariussoutier
mariussoutier / Mail.scala
Created August 23, 2012 12:13
Sending mails fluently in Scala
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
@kencoba
kencoba / Builder.scala
Created February 21, 2012 05:43
Builder pattern (Design patterns in Scala)
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