We often need to create datasets or Dataframes in real applications. The following is an example of creating rows and a dataset in a Java application:
// initialize first SQLContext SQLContext sqlContext = ... StructType schemata = DataTypes.createStructType( new StructField[]{ createStructField("NAME", StringType, false), createStructField("STRING_VALUE", StringType, false), createStructField("NUM_VALUE", IntegerType, false), }); Row r1 = RowFactory.create("name1", "value1", 1); Row r2 = RowFactory.create("name2", "value2", 2); List<Row> rowList = ImmutableList.of(r1, r2); Dataset<Row> data = sqlContext.createDataFrame(rowList, schemata);
+-----+------------+---------+ | NAME|STRING_VALUE|NUM_VALUE| +-----+------------+---------+ |name1| value1| 1| |name2| value2| 2| +-----+------------+---------+
source share