[英]How can I convert a pyspark.sql.dataframe.DataFrame back to a sql table in databricks notebook
I created a dataframe of type pyspark.sql.dataframe.DataFrame
by executing the following line: dataframe = sqlContext.sql("select * from my_data_table")
我通过执行以下行创建了一个类型为pyspark.sql.dataframe.DataFrame
的dataframe = sqlContext.sql("select * from my_data_table")
: dataframe = sqlContext.sql("select * from my_data_table")
How can I convert this back to a sparksql table that I can run sql queries on? 我怎样才能将它转换回我可以运行sql查询的sparksql表?
You can create your table by using createReplaceTempView . 您可以使用createReplaceTempView创建表。 In your case it would be like: 在你的情况下,它会像:
dataframe.createOrReplaceTempView("mytable")
After this you can query your mytable
using SQL . 在此之后,您可以使用SQL查询mytable
。
If your a spark version is ≤ 1.6.2 you can use registerTempTable 如果你的火花版本≤1.6.2你可以使用registerTempTable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.