-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from neeleshkumar-mannur/patch-4
Added Java code for Chapter 4
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
code/Structured_APIs_Chapter_4_Structured_API_Overview.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Row> 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()); | ||
} | ||
|
||
} | ||
} |