explain select * from t1 union all select * from t1
view 每次执行都会有新的值产生
从 执行计划上看view 就是用的不同的值参与随机
== Physical Plan ==
Union
:- *(1) Project [random(-3323905141429424159) AS a#44]
: +- *(1) Scan OneRowRelation[]
+- *(2) Project [random(5605563624691597816) AS a#46]
+- *(2) Scan OneRowRelation[]
------------------------------------------------ temporary table
create temporary table t1 as ( select random() as a ); -- explain select * from t1 union all select * from t1
查看执行计划拿到的是一个临时的数据, 固定的结果值
== Physical Plan ==
Union
:- Scan hive work_table.spark_temp_application_1677888387085_9802_t1 [a#80], HiveTableRelation [`work_table`.`spark_temp_application_1677888387085_9802_t1`, org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, Data Cols: [a#80], Partition Cols: []]
+- Scan hive work_table.spark_temp_application_1677888387085_9802_t1 [a#81], HiveTableRelation [`work_table`.`spark_temp_application_1677888387085_9802_t1`, org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, Data Cols: [a#81], Partition Cols: []]
总结 临时表会落表数据, view 重用的是代码段.