CreateView Logical Operator¶
CreateView is a BinaryCommand logical operator that represents CREATE VIEW SQL statement to create a persisted (non-temporary) view.
CreateViewCommand
CreateViewCommand logical operator is used to represent CREATE TEMPORARY VIEW SQL statements.
CreateView is resolved into CreateViewCommand logical operator by ResolveSessionCatalog logical analysis rule.
Demo¶
scala> sql("SHOW VIEWS").show(truncate=false)
+---------+---------+-----------+
|namespace|viewName |isTemporary|
+---------+---------+-----------+
|default |demo_view|false |
| |demo_view|true |
+---------+---------+-----------+
sql("""
CREATE OR REPLACE TEMPORARY VIEW nums_view
COMMENT 'A view over nums table'
AS
SELECT *
FROM nums
""")
scala> sql("DESC EXTENDED nums_view").show(truncate=false)
+--------+---------+-------+
|col_name|data_type|comment|
+--------+---------+-------+
|n |int |NULL |
+--------+---------+-------+
Let's cache the view. It does not seem to change anything, though.
"Why?!", you ask? This is likely because of Delta Lake sitting under the covers.
Creating Instance¶
CreateView takes the following to be created:
- Child LogicalPlan
- User-specified columns (
Seq[(String, Option[String])]) - Optional Comment
- Properties (
Map[String, String]) - Optional "Original Text"
- Logical Query Plan
-
allowExistingflag -
replaceflag
CreateView is created when:
SparkSqlAstBuilderis requested to parse a CREATE VIEW statement