Hi,
I tried with 2.1.0 and 2.2.SNAPSHOT versions and it seems that when I have nested schema, spark-sql is not able to read the data.
public class SimpleApp {
public static void main(String[] args) {
SparkConf conf = new SparkConf().setAppName("es").setMaster("local");
JavaSparkContext jsc = new JavaSparkContext(conf);
JavaRDD<Map<String, Object>> esRDD1 = JavaEsSpark.esRDD(jsc, "myindex/test").values();
for (Map<String, Object> obj : esRDD1.collect()) {
System.out.println(obj); // prints all rows
}
SQLContext sql = new SQLContext(jsc);
DataFrame test = JavaEsSparkSQL.esDF(sql, "myindex/test");
test.printSchema(); // prints without nested fields
test.show(); // fails to read nested fields
}}
Data in myindex/test
{id=1, ts=2, timestamp=1424987184887}
{id=2, ts=21, session={user=foo, name=bar}, timestamp=1424987184887}
test.printSchema prints:
root
|-- id: long (nullable = true)
|-- timestamp: string (nullable = true)
|-- ts: long (nullable = true)
test.show() throws this exception
15/06/30 17:13:32 ERROR Executor: Exception in task 2.0 in stage 2.0 (TID 8)
org.elasticsearch.hadoop.EsHadoopIllegalStateException: Field 'session' not found; typically this occurs with arrays which are not mapped as single value
at org.elasticsearch.spark.sql.RowValueReader$class.rowOrder(RowValueReader.scala:26)
at org.elasticsearch.spark.sql.ScalaRowValueReader.rowOrder(ScalaEsRowValueReader.scala:13)
at org.elasticsearch.spark.sql.ScalaRowValueReader.createMap(ScalaEsRowValueReader.scala:32)
at org.elasticsearch.hadoop.serialization.ScrollReader.map(ScrollReader.java:620)
at org.elasticsearch.hadoop.serialization.ScrollReader.read(ScrollReader.java:559)
at org.elasticsearch.hadoop.serialization.ScrollReader.map(ScrollReader.java:636)
at org.elasticsearch.hadoop.serialization.ScrollReader.read(ScrollReader.java:559)
at org.elasticsearch.hadoop.serialization.ScrollReader.readHitAsMap(ScrollReader.java:358)
at org.elasticsearch.hadoop.serialization.ScrollReader.readHit(ScrollReader.java:293)
at org.elasticsearch.hadoop.serialization.ScrollReader.read(ScrollReader.java:188)
at org.elasticsearch.hadoop.serialization.ScrollReader.read(ScrollReader.java:167)
at org.elasticsearch.hadoop.rest.RestRepository.scroll(RestRepository.java:403)
at org.elasticsearch.hadoop.rest.ScrollQuery.hasNext(ScrollQuery.java:76)
at org.elasticsearch.spark.rdd.AbstractEsRDDIterator.hasNext(AbstractEsRDDIterator.scala:43)
at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327)
at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327)
at scala.collection.Iterator$$anon$10.hasNext(Iterator.scala:308)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:103)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:47)
at scala.collection.TraversableOnce$class.to(TraversableOnce.scala:273)
at scala.collection.AbstractIterator.to(Iterator.scala:1157)
at scala.collection.TraversableOnce$class.toBuffer(TraversableOnce.scala:265)
at scala.collection.AbstractIterator.toBuffer(Iterator.scala:1157)
at scala.collection.TraversableOnce$class.toArray(TraversableOnce.scala:252)
at scala.collection.AbstractIterator.toArray(Iterator.scala:1157)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$3.apply(SparkPlan.scala:143)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$3.apply(SparkPlan.scala:143)
at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1765)
at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1765)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:63)
at org.apache.spark.scheduler.Task.run(Task.scala:70)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:213)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
15/06/30 17:13:32 INFO TaskSetManager: Starting task 3.0 in stage 2.0 (TID 9, localhost, ANY, 3328 bytes)
15/06/30 17:13:32 INFO Executor: Running task 3.0 in stage 2.0 (TID 9)
15/06/30 17:13:32 WARN TaskSetManager: Lost task 2.0 in stage 2.0 (TID 8, localhost): org.elasticsearch.hadoop.EsHadoopIllegalStateException: Field 'session' not found; typically this occurs with arrays which are not mapped as single value
at org.elasticsearch.spark.sql.RowValueReader$class.rowOrder(RowValueReader.scala:26)
at org.elasticsearch.spark.sql.ScalaRowValueReader.rowOrder(ScalaEsRowValueReader.scala:13)
at org.elasticsearch.spark.sql.ScalaRowValueReader.createMap(ScalaEsRowValueReader.scala:32)
at org.elasticsearch.hadoop.serialization.ScrollReader.map(ScrollReader.java:620)
at org.elasticsearch.hadoop.serialization.ScrollReader.read(ScrollReader.java:559)
at org.elasticsearch.hadoop.serialization.ScrollReader.map(ScrollReader.java:636)
at org.elasticsearch.hadoop.serialization.ScrollReader.read(ScrollReader.java:559)
at org.elasticsearch.hadoop.serialization.ScrollReader.readHitAsMap(ScrollReader.java:358)
at org.elasticsearch.hadoop.serialization.ScrollReader.readHit(ScrollReader.java:293)
at org.elasticsearch.hadoop.serialization.ScrollReader.read(ScrollReader.java:188)
at org.elasticsearch.hadoop.serialization.ScrollReader.read(ScrollReader.java:167)
at org.elasticsearch.hadoop.rest.RestRepository.scroll(RestRepository.java:403)
at org.elasticsearch.hadoop.rest.ScrollQuery.hasNext(ScrollQuery.java:76)
at org.elasticsearch.spark.rdd.AbstractEsRDDIterator.hasNext(AbstractEsRDDIterator.scala:43)
at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327)
at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327)
at scala.collection.Iterator$$anon$10.hasNext(Iterator.scala:308)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:103)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:47)
at scala.collection.TraversableOnce$class.to(TraversableOnce.scala:273)
at scala.collection.AbstractIterator.to(Iterator.scala:1157)
at scala.collection.TraversableOnce$class.toBuffer(TraversableOnce.scala:265)
at scala.collection.AbstractIterator.toBuffer(Iterator.scala:1157)
at scala.collection.TraversableOnce$class.toArray(TraversableOnce.scala:252)
at scala.collection.AbstractIterator.toArray(Iterator.scala:1157)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$3.apply(SparkPlan.scala:143)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$3.apply(SparkPlan.scala:143)
at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1765)
at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1765)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:63)
at org.apache.spark.scheduler.Task.run(Task.scala:70)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:213)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
15/06/30 17:13:32 ERROR TaskSetManager: Task 2 in stage 2.0 failed 1 times; aborting job
15/06/30 17:13:32 INFO Executor: Finished task 3.0 in stage 2.0 (TID 9). 628 bytes result sent to driver
15/06/30 17:13:32 INFO TaskSchedulerImpl: Cancelling stage 2
15/06/30 17:13:32 INFO TaskSchedulerImpl: Removed TaskSet 2.0, whose tasks have all completed, from pool
15/06/30 17:13:32 INFO TaskSchedulerImpl: Stage 2 was cancelled
15/06/30 17:13:32 INFO TaskSetManager: Finished task 3.0 in stage 2.0 (TID 9) in 7 ms on localhost (3/4)
15/06/30 17:13:32 INFO DAGScheduler: ResultStage 2 (show at SimpleApp.java:30) failed in 0.043 s
15/06/30 17:13:32 INFO TaskSchedulerImpl: Removed TaskSet 2.0, whose tasks have all completed, from pool
15/06/30 17:13:32 INFO DAGScheduler: Job 2 failed: show at SimpleApp.java:30, took 0.050427 s
Exception in thread "main" org.apache.spark.SparkException: Job aborted due to stage failure: Task 2 in stage 2.0 failed 1 times, most recent failure: Lost task 2.0 in stage 2.0 (TID 8, localhost): org.elasticsearch.hadoop.EsHadoopIllegalStateException: Field 'session' not found; typically this occurs with arrays which are not mapped as single value
at org.elasticsearch.spark.sql.RowValueReader$class.rowOrder(RowValueReader.scala:26)
at org.elasticsearch.spark.sql.ScalaRowValueReader.rowOrder(ScalaEsRowValueReader.scala:13)
at org.elasticsearch.spark.sql.ScalaRowValueReader.createMap(ScalaEsRowValueReader.scala:32)
at org.elasticsearch.hadoop.serialization.ScrollReader.map(ScrollReader.java:620)
at org.elasticsearch.hadoop.serialization.ScrollReader.read(ScrollReader.java:559)
at org.elasticsearch.hadoop.serialization.ScrollReader.map(ScrollReader.java:636)
at org.elasticsearch.hadoop.serialization.ScrollReader.read(ScrollReader.java:559)
at org.elasticsearch.hadoop.serialization.ScrollReader.readHitAsMap(ScrollReader.java:358)
at org.elasticsearch.hadoop.serialization.ScrollReader.readHit(ScrollReader.java:293)
at org.elasticsearch.hadoop.serialization.ScrollReader.read(ScrollReader.java:188)
at org.elasticsearch.hadoop.serialization.ScrollReader.read(ScrollReader.java:167)
at org.elasticsearch.hadoop.rest.RestRepository.scroll(RestRepository.java:403)
at org.elasticsearch.hadoop.rest.ScrollQuery.hasNext(ScrollQuery.java:76)
at org.elasticsearch.spark.rdd.AbstractEsRDDIterator.hasNext(AbstractEsRDDIterator.scala:43)
at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327)
at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327)
at scala.collection.Iterator$$anon$10.hasNext(Iterator.scala:308)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:103)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:47)
at scala.collection.TraversableOnce$class.to(TraversableOnce.scala:273)
at scala.collection.AbstractIterator.to(Iterator.scala:1157)
at scala.collection.TraversableOnce$class.toBuffer(TraversableOnce.scala:265)
at scala.collection.AbstractIterator.toBuffer(Iterator.scala:1157)
at scala.collection.TraversableOnce$class.toArray(TraversableOnce.scala:252)
at scala.collection.AbstractIterator.toArray(Iterator.scala:1157)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$3.apply(SparkPlan.scala:143)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$3.apply(SparkPlan.scala:143)
at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1765)
at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1765)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:63)
at org.apache.spark.scheduler.Task.run(Task.scala:70)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:213)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Driver stacktrace:
at org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1266)
at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1257)
at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1256)
at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
at org.apache.spark.scheduler.DAGScheduler.abortStage(DAGScheduler.scala:1256)
at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:730)
at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:730)
at scala.Option.foreach(Option.scala:236)
at org.apache.spark.scheduler.DAGScheduler.handleTaskSetFailed(DAGScheduler.scala:730)
at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1450)
at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1411)
at org.apache.spark.util.EventLoop$$anon$1.run(EventLoop.scala:48)
15/06/30 17:13:32 INFO SparkContext: Invoking stop() from shutdown hook