Temporary view

Spark SQL provides all the capabilities of processing a SQL query by using a temporary view. All the data and metadata information of a temporary view is dropped once the session or application ends. The result of queries in a temporary view is returned as Dataset<Row>.

deptDf.createOrReplaceTempView("dept");
Dataset<Row> result = sparkSession.sql("select dname,loc from dept where deptno > 20" );
result.show();

Temporary views are accessible within the same session and will throw an error if accessed from another session. The following example will throw an exception Table or view not found: dept, since we are trying to access the temporary view from a new session.

deptDf.createOrReplaceTempView("dept");
Dataset<Row> result = sparkSession.sql("select loc,count(loc) from dept where deptno > 10 group by loc" );

In the following section we will discuss how we can avoid such an error and also share data across sessions using a global temporary view.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.136.186