Skip to content

Instantly share code, notes, and snippets.

@dgadiraju
Last active September 4, 2019 02:05
Show Gist options
  • Save dgadiraju/b4054aa4b36fc4cdad0ef515b4a7d830 to your computer and use it in GitHub Desktop.
Save dgadiraju/b4054aa4b36fc4cdad0ef515b4a7d830 to your computer and use it in GitHub Desktop.
val orders = sc.textFile("/public/retail_db/orders")
// Get COMPLETE orders
orders.
filter(o => o.split(",")(3) == "COMPLETE").
take(10).
foreach(println)
// Get COMPLETE or CLOSED orders
orders.
filter(o => o.split(",")(3) == "COMPLETE" || o.split(",")(3) == "CLOSED").
take(10).
foreach(println)
orders.
filter(o => List("COMPLETE", "CLOSED").contains(o.split(",")(3))).
take(10).
foreach(println)
// Get COMPLETE or CLOSED or any PENDING type orders
orders.
filter(o => {
List("COMPLETE", "CLOSED").
contains(o.split(",")(3)) ||
o.split(",")(3).contains("PENDING")
}).
take(10).
foreach(println)
// Get all the COMPLETE or CLOSED orders placed on 2013 August 15
orders.
filter(o => {
List("COMPLETE", "CLOSED").
contains(o.split(",")(3)) &&
o.split(",")(1).startsWith("2013-08-15")
}).
take(10).
foreach(println)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment