<?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 Re: Avro Deserialization from Event Hub capture and Autoloader in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/avro-deserialization-from-event-hub-capture-and-autoloader/m-p/16979#M11064</link>
    <description>&lt;P&gt;You can build your schema like this...&lt;/P&gt;&lt;P&gt;schema = spark.read.json(capture_tmp.rdd.map(lambda row: row.&lt;I&gt;columnNamewithValue&lt;/I&gt;)).schema&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, df.withColumn('new_col', from_json(col('&lt;I&gt;yourcolumnname&lt;/I&gt;'), schema))&lt;/P&gt;</description>
    <pubDate>Thu, 15 Dec 2022 06:10:53 GMT</pubDate>
    <dc:creator>UmaMahesh1</dc:creator>
    <dc:date>2022-12-15T06:10:53Z</dc:date>
    <item>
      <title>Avro Deserialization from Event Hub capture and Autoloader</title>
      <link>https://community.databricks.com/t5/data-engineering/avro-deserialization-from-event-hub-capture-and-autoloader/m-p/16974#M11059</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am getting data from Event Hub capture in Avro format and using Auto Loader to process it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get into the point where I can read the Avro by casting the Body into a string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1005i4C17E8C973D58170/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;Now I wanted to deserialized the Body column so it will in table format. Managed to do this by constructing a json_schema using StructType() and used the json_schema  within the from_json() function which then I do a writeStream into a delta table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1002iEE918BEDCBF00CA7/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question. Is there a way that I can deserialize the Avro data without constructing a schema? Event Hub schema registry is one option that I am looking at but not sure how to do that within Autoloader using PySpark.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Gil&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 05:07:10 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/avro-deserialization-from-event-hub-capture-and-autoloader/m-p/16974#M11059</guid>
      <dc:creator>Gilg</dc:creator>
      <dc:date>2022-12-14T05:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: Avro Deserialization from Event Hub capture and Autoloader</title>
      <link>https://community.databricks.com/t5/data-engineering/avro-deserialization-from-event-hub-capture-and-autoloader/m-p/16975#M11060</link>
      <description>&lt;P&gt;Does your cluster has schema registry service ?  If yes, you need not provide schema explicitly. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 05:37:10 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/avro-deserialization-from-event-hub-capture-and-autoloader/m-p/16975#M11060</guid>
      <dc:creator>UmaMahesh1</dc:creator>
      <dc:date>2022-12-14T05:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: Avro Deserialization from Event Hub capture and Autoloader</title>
      <link>https://community.databricks.com/t5/data-engineering/avro-deserialization-from-event-hub-capture-and-autoloader/m-p/16976#M11061</link>
      <description>&lt;P&gt;If you still want to go with the above approach and don't want to provide schema manually, then you can fetch a tiny batch with 1 record and build the schema into a variable using a .schema option. Once done, you can add a new Body column by providing the schema in the previous variable using the same way from_json. Now since this will be in json format, you can anyways use explode function and do stuff.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 05:43:46 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/avro-deserialization-from-event-hub-capture-and-autoloader/m-p/16976#M11061</guid>
      <dc:creator>UmaMahesh1</dc:creator>
      <dc:date>2022-12-14T05:43:46Z</dc:date>
    </item>
    <item>
      <title>Re: Avro Deserialization from Event Hub capture and Autoloader</title>
      <link>https://community.databricks.com/t5/data-engineering/avro-deserialization-from-event-hub-capture-and-autoloader/m-p/16978#M11063</link>
      <description>&lt;P&gt;Hi @Uma Maheswara Rao Desula​&amp;nbsp;. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I do the .schema even for a tiny batch. It will only get the schema of the original Avro. ie System columns generated plus the Body column where it holds the actual data . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1000iA134C03C4C14336B/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 02:03:32 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/avro-deserialization-from-event-hub-capture-and-autoloader/m-p/16978#M11063</guid>
      <dc:creator>Gilg</dc:creator>
      <dc:date>2022-12-15T02:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: Avro Deserialization from Event Hub capture and Autoloader</title>
      <link>https://community.databricks.com/t5/data-engineering/avro-deserialization-from-event-hub-capture-and-autoloader/m-p/16979#M11064</link>
      <description>&lt;P&gt;You can build your schema like this...&lt;/P&gt;&lt;P&gt;schema = spark.read.json(capture_tmp.rdd.map(lambda row: row.&lt;I&gt;columnNamewithValue&lt;/I&gt;)).schema&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, df.withColumn('new_col', from_json(col('&lt;I&gt;yourcolumnname&lt;/I&gt;'), schema))&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 06:10:53 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/avro-deserialization-from-event-hub-capture-and-autoloader/m-p/16979#M11064</guid>
      <dc:creator>UmaMahesh1</dc:creator>
      <dc:date>2022-12-15T06:10:53Z</dc:date>
    </item>
  </channel>
</rss>

