简体   繁体   English

如何将pyspark.sql.dataframe.DataFrame转换回databricks笔记本中的sql表

[英]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.DataFramedataframe = 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.

相关问题 将pyspark.sql.dataframe.DataFrame类型转换为Dictionary - Convert pyspark.sql.dataframe.DataFrame type Dataframe to Dictionary 尝试在 Databricks 环境中合并或连接两个 pyspark.sql.dataframe.DataFrame - Trying to Merge or Concat two pyspark.sql.dataframe.DataFrame in Databricks Environment 如何将SQL表转换为pyspark / python数据结构并在databricks笔记本中返回sql - How to convert sql table into a pyspark/python data structure and return back to sql in databricks notebook Pyspark:依靠 pyspark.sql.dataframe.DataFrame 需要很长时间 - Pyspark: count on pyspark.sql.dataframe.DataFrame takes long time Pyspark:如何从 pyspark.sql.dataframe.DataFrame 中选择唯一的 ID 数据? - Pyspark: how to select unique ID data from a pyspark.sql.dataframe.DataFrame? 写一个pyspark.sql.dataframe.DataFrame不丢失信息 - Write a pyspark.sql.dataframe.DataFrame without losing information Pyspark:如何将在线.gz日志文件加载到pyspark.sql.dataframe.DataFrame中 - Pyspark: how to load online .gz log file into pyspark.sql.dataframe.DataFrame 如何在不使用 pandas on spark API 的情况下为 pyspark.sql.dataframe.DataFrame 编写这个 pandas 逻辑? - How to write this pandas logic for pyspark.sql.dataframe.DataFrame without using pandas on spark API? difference between pyspark.pandas.frame.DataFrame and pyspark.sql.dataframe.DataFrame and their conversion - difference between pyspark.pandas.frame.DataFrame and pyspark.sql.dataframe.DataFrame and their conversion 有没有办法将 Pandas 数据框转换为 Databricks 中 sql 中的表视图? - Is there a way to convert a pandas dataframe into a table view in sql in Databricks?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM