blob: b4ec109a5923bcd80f97ad178cb60fe91d5faa5f [file] [log] [blame]
package demo;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.sql.DataFrame;
import org.apache.spark.sql.SQLContext;
import static io.pivotal.gemfire.spark.connector.javaapi.GemFireJavaUtil.*;
/**
* This Spark application demonstrates how to get region data from GemFire using GemFire
* OQL Java API. The result is a Spark DataFrame.
* <p>
* In order to run it, you will need to start a GemFire cluster, and run demo PairRDDSaveJavaDemo
* first to create some data in the region.
* <p>
* Once you compile and package the demo, the jar file basic-demos_2.10-0.5.0.jar
* should be generated under gemfire-spark-demos/basic-demos/target/scala-2.10/.
* Then run the following command to start a Spark job:
* <pre>
* <path to spark>/bin/spark-submit --master=local[2] --class demo.OQLJavaDemo \
* <path to>/basic-demos_2.10-0.5.0.jar <locator host>:<port>
* </pre>
*/
public class OQLJavaDemo {
public static void main(String[] argv) {
if (argv.length != 1) {
System.err.printf("Usage: OQLJavaDemo <locators>\n");
return;
}
SparkConf conf = new SparkConf().setAppName("OQLJavaDemo");
conf.set(GemFireLocatorPropKey, argv[0]); // "192.168.1.47[10335]"
JavaSparkContext sc = new JavaSparkContext(conf);
SQLContext sqlContext = new org.apache.spark.sql.SQLContext(sc);
DataFrame df = javaFunctions(sqlContext).gemfireOQL("select * from /str_str_region");
System.out.println("======= DataFrame =======\n");
df.show();
sc.stop();
}
}