This is the code to run simple SQL queries over Spark Streaming.
import org.apache.spark.streaming.{Seconds, StreamingC
Well, I would like to sum up the workaround we arrived on after the discussion in the answer by Spiro. His suggestion to first create an empty table and then inserting RDDs into it was bang on. The only problem is that Spark doesn't allow to insert into tables yet. Here is what can be done:
First, create an RDD that has the same schema as the one you're expecting from your stream:
import sqlContext.createSchemaRDD
val d1=sc.parallelize(Array(("a",10),("b",3))).map(e=>Rec(e._1,e._2))
Then save it as a Parquet File
d1.saveAsParquetFile("/home/p1.parquet")
Now, load the parquet file and register it as table using the registerAsTable() method.
val parquetFile = sqlContext.parquetFile("/home/p1.parquet")
parquetFile.registerAsTable("data")
Now, when you receive your stream, just apply a foreachRDD() on your stream and keep inserting the individual RDDs in the table created above using the insertInto() method
dStream.foreachRDD(rdd=>{
rdd.insertInto("data")
})
This insertInto() works fine and allows the data to be collected into a table. Now you can do the same for any number of streams and then run your queries.