/**
 * Load some tweets stored as JSON data and explore them.
 */
package com.oreilly.learningsparkexamples.java;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;
import org.apache.spark.sql.api.java.JavaSQLContext;
import org.apache.spark.sql.api.java.JavaSchemaRDD;
import org.apache.spark.sql.api.java.Row;

public class SparkSQLTwitter {
  public static void main(String[] args) {
    String inputFile = args[0];
    SparkConf conf = new SparkConf();
    JavaSparkContext sc = new JavaSparkContext(conf);
    JavaSQLContext sqlCtx = new JavaSQLContext(sc);
    JavaSchemaRDD input = sqlCtx.jsonFile(inputFile);
    // Print the schema
    input.printSchema();
    // Register the input schema RDD
    input.registerTempTable("tweets");
    // Select tweets based on the retweetCount
    JavaSchemaRDD topTweets = sqlCtx.sql("SELECT text, retweetCount FROM tweets ORDER BY retweetCount LIMIT 10");
    List<Row> result = topTweets.collect();
    for (Row row : result) {
      System.out.println(row.get(0));
    }
    JavaRDD<String> topTweetText = topTweets.map(new Function<Row, String>() {
        public String call(Row row) {
          return row.getString(0);
        }});
    System.out.println(topTweetText.collect());
    sc.stop();
  }
}

@@ -133,16 +133,44 @@
 Arrays;%0A
+import java.util.ArrayList;%0A
 import j
@@ -1474,24 +1474,431 @@
 collect());%0A
+    // Create a person and turn it into a Schema RDD%0A    ArrayList%3CHappyPerson%3E peopleList = new ArrayList%3CHappyPerson%3E();%0A    peopleList.add(new HappyPerson(%22holden%22, %22coffee%22));%0A    JavaRDD%3CHappyPerson%3E happyPeopleRDD = sc.parallelize(peopleList);%0A    JavaSchemaRDD happyPeopleSchemaRDD = sqlCtx.applySchema(happyPeopleRDD, HappyPerson.class);%0A    happyPeopleSchemaRDD.registerTempTable(%22happy_people%22);%0A%0A
     sc.stop(

Add a JavaBean based Spark SQL example