what is difference between registerTempTable
and registerDataFrameAsTable
method in Spark SQL and which is better in which scenario.
There is a new createGlobalTempView
which can used to register cross-session views:
Its lifetime is the lifetime of the Spark application, i.e. it will be automatically dropped when the application terminates. It's tied to a system preserved database
_global_temp
, and we must use the qualified name to refer a global temp view, e.g.SELECT * FROM _global_temp.view1
.
registerTempTable
has been deprecated in favor of createTempView
and createOrReplaceTempView
with the former one throwing and exception if the view already exists.
While there is no practical difference between these two there is a difference in execution strategy:
SQLContext.registerDataFrameAsTable
calls registerDataFrameAsTable
method on JVM SQL contextDataFrame.registerTempTable
calls registerTempTable
on JVM data frame, which calls registerDataFrameAsTable
method on JVM SQL contextDataFrame.registerTempTable
calls registerDataFrameAsTable
method on SQL contextSQLContext.registerDataFrameAsTable
is a private method not accessible outside org.apache.spark.sql
package.To keep things simple it is probably a good idea to stick to registerTempTable
as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With