-
Notifications
You must be signed in to change notification settings - Fork 286
Expand file tree
/
Copy pathLateralViewExplode.scala
More file actions
31 lines (24 loc) · 934 Bytes
/
LateralViewExplode.scala
File metadata and controls
31 lines (24 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package hiveql
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.hive.HiveContext
import org.apache.spark.{SparkConf, SparkContext}
// TODO: no longer runs
object LateralViewExplode {
def main (args: Array[String]) {
val spark =
SparkSession.builder()
.appName("HiveQL-LateralViewExplode")
.master("local[4]")
.enableHiveSupport()
.getOrCreate()
val transactions = spark.read.json("src/main/resources/data/mixed.json")
transactions.printSchema()
transactions.createOrReplaceTempView("transactions")
val data1 = spark.sql("SELECT id, u.oid FROM transactions LATERAL VIEW explode(orders) t AS u")
data1.schema.printTreeString()
data1.foreach(r => println(r))
val data2 = spark.sql("SELECT id, u.oid, u.SKU FROM transactions LATERAL VIEW explode(orders) t AS u")
data2.schema.printTreeString()
data2.foreach(r => println(r))
}
}