<?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>topic How can I create a Table from a CSV file with first column with data in dictionary format (JSON like)? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-can-i-create-a-table-from-a-csv-file-with-first-column-with/m-p/29460#M21186</link>
    <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I have a csv file with the first column containing data in dictionary form (keys: value). [see below] &lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0693f000007OoIpAAK"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2541i6D8093FC5A2E058B/image-size/large?v=v2&amp;amp;px=999" role="button" title="0693f000007OoIpAAK" alt="0693f000007OoIpAAK" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I tried to create a table by uploading the csv file directly to databricks but the file can't be read. Is there a way for me to flatten or convert the first column to excel table with each key as column name and values in rows?&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Sep 2016 07:41:37 GMT</pubDate>
    <dc:creator>tripplehay777</dc:creator>
    <dc:date>2016-09-01T07:41:37Z</dc:date>
    <item>
      <title>How can I create a Table from a CSV file with first column with data in dictionary format (JSON like)?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-can-i-create-a-table-from-a-csv-file-with-first-column-with/m-p/29460#M21186</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I have a csv file with the first column containing data in dictionary form (keys: value). [see below] &lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0693f000007OoIpAAK"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2541i6D8093FC5A2E058B/image-size/large?v=v2&amp;amp;px=999" role="button" title="0693f000007OoIpAAK" alt="0693f000007OoIpAAK" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I tried to create a table by uploading the csv file directly to databricks but the file can't be read. Is there a way for me to flatten or convert the first column to excel table with each key as column name and values in rows?&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 07:41:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-can-i-create-a-table-from-a-csv-file-with-first-column-with/m-p/29460#M21186</guid>
      <dc:creator>tripplehay777</dc:creator>
      <dc:date>2016-09-01T07:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a Table from a CSV file with first column with data in dictionary format (JSON like)?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-can-i-create-a-table-from-a-csv-file-with-first-column-with/m-p/29461#M21187</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;B&gt;&lt;/B&gt;
&lt;P&gt;This is apparently a known issue, databricks has their own csv format handler which can handle this&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/databricks/spark-csv" target="test_blank"&gt;https://github.com/databricks/spark-csv&lt;/A&gt;&lt;/P&gt;
&lt;B&gt;&lt;/B&gt;
&lt;B&gt;SQL API&lt;/B&gt;
&lt;P&gt;CSV data source for Spark can infer data types:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;CREATE TABLE cars
USING com.databricks.spark.csv
OPTIONS (path "cars.csv", header "true", inferSchema "true")&lt;/CODE&gt;&lt;/PRE&gt; 
&lt;P&gt;You can also specify column names and types in DDL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;CREATE TABLE cars (yearMade double, carMake string, carModel string, comments string, blank string)
USING com.databricks.spark.csv
OPTIONS (path "cars.csv", header "true")&lt;/CODE&gt;&lt;/PRE&gt; 
&lt;B&gt;Scala API&lt;/B&gt;
&lt;P&gt;Spark 1.4+:&lt;/P&gt;
&lt;P&gt;Automatically infer schema (data types), otherwise everything is assumed string:&lt;/P&gt;import org.apache.spark.sql.SQLContext
&lt;P&gt;&lt;/P&gt; 
&lt;P&gt;val sqlContext = new SQLContext(sc) val df = sqlContext.read .format("com.databricks.spark.csv") .option("header", "true") // Use first line of all files as header .option("inferSchema", "true") // Automatically infer data types .load("cars.csv")&lt;/P&gt; 
&lt;P&gt;val selectedData = df.select("year", "model") selectedData.write .format("com.databricks.spark.csv") .option("header", "true") &lt;/P&gt;
&lt;P&gt; .save("newcars.csv")&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 19:37:19 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-can-i-create-a-table-from-a-csv-file-with-first-column-with/m-p/29461#M21187</guid>
      <dc:creator>MaxStruever</dc:creator>
      <dc:date>2019-08-15T19:37:19Z</dc:date>
    </item>
  </channel>
</rss>

