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();
}
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();
}
Aggregations