Search in sources :

Example 1 with GeodeConnectionConf

use of org.apache.geode.spark.connector.GeodeConnectionConf in project geode by apache.

the class RDDSaveJavaDemo method main.

public static void main(String[] argv) {
    if (argv.length != 1) {
        System.err.printf("Usage: RDDSaveJavaDemo <locators>\n");
        return;
    }
    SparkConf conf = new SparkConf().setAppName("RDDSaveJavaDemo");
    conf.set(GeodeLocatorPropKey, argv[0]);
    JavaSparkContext sc = new JavaSparkContext(conf);
    List<String> data = new ArrayList<String>();
    data.add("abcdefg");
    data.add("abcdefgh");
    data.add("abcdefghi");
    JavaRDD<String> rdd = sc.parallelize(data);
    GeodeConnectionConf connConf = GeodeConnectionConf.apply(conf);
    PairFunction<String, String, Integer> func = new PairFunction<String, String, Integer>() {

        @Override
        public Tuple2<String, Integer> call(String s) throws Exception {
            return new Tuple2<String, Integer>(s, s.length());
        }
    };
    javaFunctions(rdd).saveToGeode("str_int_region", func, connConf);
    sc.stop();
}
Also used : GeodeConnectionConf(org.apache.geode.spark.connector.GeodeConnectionConf) Tuple2(scala.Tuple2) ArrayList(java.util.ArrayList) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) PairFunction(org.apache.spark.api.java.function.PairFunction) SparkConf(org.apache.spark.SparkConf)

Example 2 with GeodeConnectionConf

use of org.apache.geode.spark.connector.GeodeConnectionConf in project geode by apache.

the class PairRDDSaveJavaDemo method main.

public static void main(String[] argv) {
    if (argv.length != 1) {
        System.err.printf("Usage: PairRDDSaveJavaDemo <locators>\n");
        return;
    }
    SparkConf conf = new SparkConf().setAppName("PairRDDSaveJavaDemo");
    conf.set(GeodeLocatorPropKey, argv[0]);
    JavaSparkContext sc = new JavaSparkContext(conf);
    GeodeConnectionConf connConf = GeodeConnectionConf.apply(conf);
    List<Tuple2<String, String>> data = new ArrayList<>();
    data.add(new Tuple2<>("7", "seven"));
    data.add(new Tuple2<>("8", "eight"));
    data.add(new Tuple2<>("9", "nine"));
    List<Tuple2<String, String>> data2 = new ArrayList<Tuple2<String, String>>();
    data2.add(new Tuple2<>("11", "eleven"));
    data2.add(new Tuple2<>("12", "twelve"));
    data2.add(new Tuple2<>("13", "thirteen"));
    // method 1: generate JavaPairRDD directly
    JavaPairRDD<String, String> rdd1 = sc.parallelizePairs(data);
    javaFunctions(rdd1).saveToGeode("str_str_region", connConf);
    // method 2: convert JavaRDD<Tuple2<K,V>> to JavaPairRDD<K, V>
    JavaRDD<Tuple2<String, String>> rdd2 = sc.parallelize(data2);
    javaFunctions(toJavaPairRDD(rdd2)).saveToGeode("str_str_region", connConf);
    sc.stop();
}
Also used : GeodeConnectionConf(org.apache.geode.spark.connector.GeodeConnectionConf) Tuple2(scala.Tuple2) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) SparkConf(org.apache.spark.SparkConf)

Aggregations

GeodeConnectionConf (org.apache.geode.spark.connector.GeodeConnectionConf)2 SparkConf (org.apache.spark.SparkConf)2 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)2 Tuple2 (scala.Tuple2)2 ArrayList (java.util.ArrayList)1 PairFunction (org.apache.spark.api.java.function.PairFunction)1