LoginSignup
1
1

More than 5 years have passed since last update.

Window Functions in Spark SQL using HiveQL

Posted at

SparkでHiveContextを用いてwindow functionを使用するサンプル。

build.sbt

...
libraryDependencies ++= Seq(
  "org.apache.spark" %% "spark-core" % "1.5.2" % "provided",
  "org.apache.spark" %% "spark-sql" % "1.5.2" % "provided",
  "org.apache.spark" %% "spark-hive" % "1.5.2" % "provided"
)
...

scalaサンプル

import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.hive.HiveContext
...

val conf = new SparkConf()
val sc = new SparkContext(conf)

val sqlContext = new HiveContext(sc)
import sqlContext.implicits._

val src = sqlContext.read.json(test_data)
src.registerTempTable("test")

val r = sqlContext.sql("select id, time, row_number() over(partition by id order by time) num from test")
...
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1