@@ -0,0 +1,2317 @@
+package com.springboot.spark.starter.basic.dataframe;%0D%0A%0D%0Aimport java.io.Serializable;%0D%0Aimport java.util.Arrays;%0D%0A%0D%0Aimport org.apache.spark.SparkConf;%0D%0Aimport org.apache.spark.api.java.JavaRDD;%0D%0Aimport org.apache.spark.api.java.JavaSparkContext;%0D%0Aimport org.apache.spark.api.java.function.Function;%0D%0Aimport org.apache.spark.sql.Dataset;%0D%0Aimport org.apache.spark.sql.Row;%0D%0Aimport org.apache.spark.sql.SparkSession;%0D%0A%0D%0Apublic class CreateDatasetUsingRDD implements Serializable %7B%0D%0A%0D%0A  private static final long serialVersionUID = 5924321403879655951L;%0D%0A%0D%0A  private final static SparkConf sparkConf = new SparkConf() //%0D%0A      .setAppName(CreateDatasetUsingRDD.class.getName()) //%0D%0A      .setMaster(%22local%22) //%0D%0A  ; //%0D%0A%0D%0A  public final static JavaSparkContext sc = new JavaSparkContext(sparkConf);%0D%0A%0D%0A  public void using() %7B%0D%0A%0D%0A    JavaRDD%3CInteger%3E rdd = sc.parallelize(Arrays.asList(1, 2, 3, 4, 4));%0D%0A    JavaRDD%3CFoo%3E map = rdd.map(new Function%3CInteger, Foo%3E() %7B%0D%0A      private static final long serialVersionUID = -4542297399325584941L;%0D%0A%0D%0A      @Override%0D%0A      public Foo call(Integer v1) throws Exception %7B%0D%0A        return new Foo(%22K_%22 + v1, String.valueOf(v1));%0D%0A      %7D%0D%0A    %7D);%0D%0A    SparkSession sparkSession = SparkSession.builder().sparkContext(sc.sc())%0D%0A        .appName(CreateDatasetUsingRDD.class.getName()).getOrCreate();%0D%0A    Dataset%3CRow%3E dataset = sparkSession.createDataFrame(map, Foo.class);%0D%0A    System.err.println(%22Output Result:%22);%0D%0A    dataset.show();%0D%0A    // +---+-----+%0D%0A    // %7Ckey%7Cvalue%7C%0D%0A    // +---+-----+%0D%0A    // %7CK_1%7C 1%7C%0D%0A    // %7CK_2%7C 2%7C%0D%0A    // %7CK_3%7C 3%7C%0D%0A    // %7CK_4%7C 4%7C%0D%0A    // %7CK_4%7C 4%7C%0D%0A    // +---+-----+%0D%0A  %7D%0D%0A%0D%0A  public static void main(String%5B%5D args) %7B%0D%0A    new CreateDatasetUsingRDD().using();%0D%0A    sc.close();%0D%0A  %7D%0D%0A%0D%0A  public static class Foo implements Serializable %7B%0D%0A    private static final long serialVersionUID = -8986913670248430476L;%0D%0A%0D%0A    private String key;%0D%0A    private String value;%0D%0A%0D%0A    public Foo(String key, String value) %7B%0D%0A      this.key = key;%0D%0A      this.value = value;%0D%0A    %7D%0D%0A%0D%0A    public String getKey() %7B%0D%0A      return key;%0D%0A    %7D%0D%0A%0D%0A    public void setKey(String key) %7B%0D%0A      this.key = key;%0D%0A    %7D%0D%0A%0D%0A    public String getValue() %7B%0D%0A      return value;%0D%0A    %7D%0D%0A%0D%0A    public void setValue(String value) %7B%0D%0A      this.value = value;%0D%0A    %7D%0D%0A%0D%0A  %7D%0D%0A%0D%0A%7D%0D%0A

create dataset using RDD.