Skip to content

Instantly share code, notes, and snippets.

@corneliouzbett
Created March 19, 2019 12:00
Show Gist options
  • Save corneliouzbett/c2845a678540789d720524b131ccd94b to your computer and use it in GitHub Desktop.
Save corneliouzbett/c2845a678540789d720524b131ccd94b to your computer and use it in GitHub Desktop.
// Create the dataframe
val df = Seq("Red", "Green", "Blue").map(Tuple1.apply).toDF("color")
df.createOrReplaceTempView("data")
val df4 = sql(""" select *, case when color = 'green' then 1 else 0 end as Green_ind from data """)
df4.show()
df4:org.apache.spark.sql.DataFrame = [color: string, Green_ind: integer]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment