<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Zeppelin 0.6 - How to registerAsTable the data which can be showed with &amp;quot;%table&amp;quot; using pyspark in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Zeppelin-0-6-How-to-registerAsTable-the-data-which-can-be/m-p/151083#M36071</link>
    <description>&lt;P&gt;registerAsTempTable is a spark function which will allow you to write SQL against your dataframe. Essentially it's a way to give the dataframe variable a name in the context of SQL. &lt;/P&gt;&lt;P&gt;If what you're looking to do is display the data from a programmatic dataframe in a %pyspark paragraph in the same way it does in say a %sql paragraph, your'e on the right track. However, you need to make sure that the data is separated by tabs, and rows end with a new line. You also need a new line between the header and the content. So:&lt;/P&gt;&lt;PRE&gt;final_table_text = "\n".join(table_text_list)
output = final_table_text.map(lambda x: "\t".join(x))
print "%table\n%s" % (output)&lt;/PRE&gt;&lt;P&gt;Note that the output and tab insertion can also be done within spark, before collecting your results if you want it to happen across the whole cluster, which may or may not be quicker depending on the size of the data. &lt;/P&gt;&lt;P&gt;Note also that this won't automatically limit the number of results in the way that the %sql paragraph does, so you may want to be a little careful about blowing out the browser RAM unless you put your own limits on the dataframe, or use take(n) instead of collect to retrieve the data for display.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jul 2016 17:02:40 GMT</pubDate>
    <dc:creator>sball</dc:creator>
    <dc:date>2016-07-27T17:02:40Z</dc:date>
    <item>
      <title>Zeppelin 0.6 - How to registerAsTable the data which can be showed with "%table" using pyspark</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Zeppelin-0-6-How-to-registerAsTable-the-data-which-can-be/m-p/151082#M36070</link>
      <description>&lt;P&gt;I am using pyspark to print filtered data as table.&lt;/P&gt;&lt;PRE&gt;final_table_text = "\n".join(table_text_list)
table_prefix='%table'
print """%s %s"""% (table_prefix,final_table_text)
&lt;/PRE&gt;&lt;P&gt;The first line  in table_text_list is table header&lt;/P&gt;&lt;P&gt;Now i want to do some order by on this data, for which one way which i thought of was to use registerAsTable.&lt;/P&gt;&lt;P&gt;There there a way through which if i specify the line separator and the column separator, I can use registerAsTable&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2016 16:26:58 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Zeppelin-0-6-How-to-registerAsTable-the-data-which-can-be/m-p/151082#M36070</guid>
      <dc:creator>pankaj_singh</dc:creator>
      <dc:date>2016-07-27T16:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: Zeppelin 0.6 - How to registerAsTable the data which can be showed with "%table" using pyspark</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Zeppelin-0-6-How-to-registerAsTable-the-data-which-can-be/m-p/151083#M36071</link>
      <description>&lt;P&gt;registerAsTempTable is a spark function which will allow you to write SQL against your dataframe. Essentially it's a way to give the dataframe variable a name in the context of SQL. &lt;/P&gt;&lt;P&gt;If what you're looking to do is display the data from a programmatic dataframe in a %pyspark paragraph in the same way it does in say a %sql paragraph, your'e on the right track. However, you need to make sure that the data is separated by tabs, and rows end with a new line. You also need a new line between the header and the content. So:&lt;/P&gt;&lt;PRE&gt;final_table_text = "\n".join(table_text_list)
output = final_table_text.map(lambda x: "\t".join(x))
print "%table\n%s" % (output)&lt;/PRE&gt;&lt;P&gt;Note that the output and tab insertion can also be done within spark, before collecting your results if you want it to happen across the whole cluster, which may or may not be quicker depending on the size of the data. &lt;/P&gt;&lt;P&gt;Note also that this won't automatically limit the number of results in the way that the %sql paragraph does, so you may want to be a little careful about blowing out the browser RAM unless you put your own limits on the dataframe, or use take(n) instead of collect to retrieve the data for display.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2016 17:02:40 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Zeppelin-0-6-How-to-registerAsTable-the-data-which-can-be/m-p/151083#M36071</guid>
      <dc:creator>sball</dc:creator>
      <dc:date>2016-07-27T17:02:40Z</dc:date>
    </item>
    <item>
      <title>Re: Zeppelin 0.6 - How to registerAsTable the data which can be showed with "%table" using pyspark</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Zeppelin-0-6-How-to-registerAsTable-the-data-which-can-be/m-p/151084#M36072</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/104/sball.html" nodeid="104"&gt;@Simon Elliston Ball&lt;/A&gt;
&lt;/P&gt;&lt;P&gt;Thanks for information, I have a connecting issue&lt;/P&gt;&lt;P&gt;When i try to query the table it does not return me the rows. Is i am doing something wrong&lt;/P&gt;&lt;PRE&gt;result_schema = StructType([StructField("ID", StringType(), False),StructField("COMPONENT", StringType(),False),StructField("TOTAL_TESTS", IntegerType(), False)
myrdd = sc.parallelize([final_table_text])
df=sqlContext.createDataFrame(myrdd,result_schema)
df.registerTempTable("result_query")
abc=sqlContext.sql("select * from result_query")
print abc
&lt;/PRE&gt;&lt;P&gt;The output is : DataFrame[ID: string, COMPONENT: string, TOTAL_TESTS: int]&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2016 19:52:08 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Zeppelin-0-6-How-to-registerAsTable-the-data-which-can-be/m-p/151084#M36072</guid>
      <dc:creator>pankaj_singh</dc:creator>
      <dc:date>2016-07-27T19:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: Zeppelin 0.6 - How to registerAsTable the data which can be showed with "%table" using pyspark</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Zeppelin-0-6-How-to-registerAsTable-the-data-which-can-be/m-p/151085#M36073</link>
      <description>&lt;P&gt;missed to add .show to abc&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2016 19:16:52 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Zeppelin-0-6-How-to-registerAsTable-the-data-which-can-be/m-p/151085#M36073</guid>
      <dc:creator>pankaj_singh</dc:creator>
      <dc:date>2016-07-29T19:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Zeppelin 0.6 - How to registerAsTable the data which can be showed with "%table" using pyspark</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Zeppelin-0-6-How-to-registerAsTable-the-data-which-can-be/m-p/151086#M36074</link>
      <description>&lt;P&gt;not sure what is in final_table_text, but almost certain you don't mean to parallelise to get it from the driver. You should really be using the dataframe read api to distribute it in a case like this. &lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2016 19:19:55 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Zeppelin-0-6-How-to-registerAsTable-the-data-which-can-be/m-p/151086#M36074</guid>
      <dc:creator>sball</dc:creator>
      <dc:date>2016-07-29T19:19:55Z</dc:date>
    </item>
  </channel>
</rss>

