From 065fab63ca2b639bc0b121c00c7229eec2e01b98 Mon Sep 17 00:00:00 2001 From: Neeleshkumar Mannur Date: Sun, 7 Oct 2018 22:59:01 +0530 Subject: [PATCH] Added Java code for Chapter 4 The last statement of ByteType didn't have a purpose in the Java code. Thus, I have not added it. --- ...PIs_Chapter_4_Structured_API_Overview.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 code/Structured_APIs_Chapter_4_Structured_API_Overview.java diff --git a/code/Structured_APIs_Chapter_4_Structured_API_Overview.java b/code/Structured_APIs_Chapter_4_Structured_API_Overview.java new file mode 100644 index 0000000..888a540 --- /dev/null +++ b/code/Structured_APIs_Chapter_4_Structured_API_Overview.java @@ -0,0 +1,24 @@ +This Java code was contributed by @neeleshkumar-mannur + +import org.apache.spark.sql.Dataset; +import org.apache.spark.sql.Row; +import org.apache.spark.sql.SparkSession; + +public class Structured_APIs_Chapter_4_Structured_API_Overview { + public static void main(String[] args) { + SparkSession spark = SparkSession + .builder() + .master("local[*]") + .appName("Chapter4StructuredAPIOverview") + .getOrCreate(); + + Dataset df = spark.range(500).toDF("number"); + df.select(df.col("number").plus(10)).show(); + + Object [] dataObjects = (Object[])spark.range(2).toDF().collect(); + for(Object object: dataObjects) { + System.out.println(object.toString()); + } + + } +}