Running SQL Queries Programmatically
The sql function on a SparkSession enables applications to run SQL queries programmatically and returns the result as a DataFrame.
1
df.createOrReplaceTempView("people")
2
spark.sql("select * from people").show()
3
/*
4
+----+-------+
5
| age| name|
6
+----+-------+
7
|null|Michael|
8
| 30| Andy|
9
| 19| Justin|
10
+----+-------+
11
*/
Copied!
Last modified 1yr ago
Copy link