Often we might want to store the spark Data frame as the table and query it, to convert Data frame into temporary view that is available for only that spark session, we use registerTempTable or createOrReplaceTempView (Spark > = 2.0) on our spark Dataframe.
createorReplaceTempView is used when you want to store the table for a particular spark session.
createOrReplaceTempView creates (or replaces if that view name already exists) a lazily evaluated "view" that you can then use like a hive table in Spark SQL. It does not persist to memory unless you cache the dataset that underpins the view.
scala> val s = Seq(1,2,3,4).toDF("num")
s: org.apache.spark.sql.DataFrame = [num: int]
res6: org.apache.spark.sql.DataFrame = [num: int]
res7: org.apache.spark.sql.Dataset[org.apache.spark.sql.Row] = [num: int]
res8: Long = 4
The data is cached fully only after the .count call.
Relevant quote (comparing to persistent table): "Unlike the createOrReplaceTempView command, saveAsTable will materialize the contents of the DataFrame and create a pointer to the data in the Hive metastore." https://spark.apache.org/docs/latest/sql-programming-guide.html#saving-to-persistent-tables
If you wish to learn Spark visit this Spark Tutorial.