<?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: IoT hub with kafka connector - how to decode the enqueued timestamp and device id in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/iot-hub-with-kafka-connector-how-to-decode-the-enqueued/m-p/75241#M34906</link>
    <description>&lt;P&gt;&lt;A href="https://github.com/Azure/azure-event-hubs-for-kafka/issues/56#issuecomment-1432006831" target="_blank"&gt;https://github.com/Azure/azure-event-hubs-for-kafka/issues/56#issuecomment-1432006831&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jun 2024 19:46:48 GMT</pubDate>
    <dc:creator>Erik</dc:creator>
    <dc:date>2024-06-20T19:46:48Z</dc:date>
    <item>
      <title>IoT hub with kafka connector - how to decode the enqueued timestamp and device id</title>
      <link>https://community.databricks.com/t5/data-engineering/iot-hub-with-kafka-connector-how-to-decode-the-enqueued/m-p/74807#M34795</link>
      <description>&lt;P&gt;I'm reading data from the default endpoint of an IoT hub in azure using the kafka connector in Databricks.&amp;nbsp; Most data items are straight forward, but the device id and the timestamp I haven't been able to properly decode&lt;/P&gt;&lt;P&gt;For example, the key-value map of the headers&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;{"key": "iothub-enqueuedtime", "value": "gwAAAZAMsGjg"}&amp;nbsp; should be a recent timestamp.&amp;nbsp; Any ideas on how to decode this, using pyspark?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2024 08:29:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/iot-hub-with-kafka-connector-how-to-decode-the-enqueued/m-p/74807#M34795</guid>
      <dc:creator>Pálmi</dc:creator>
      <dc:date>2024-06-18T08:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: IoT hub with kafka connector - how to decode the enqueued timestamp and device id</title>
      <link>https://community.databricks.com/t5/data-engineering/iot-hub-with-kafka-connector-how-to-decode-the-enqueued/m-p/75237#M34903</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/9"&gt;@Retired_mod&lt;/a&gt;&amp;nbsp;, thanks for your reply.&amp;nbsp; The iothub-enqueuedtime does not (directly ) cast into a timestamp, but an unix timestamp with milliseconds&amp;nbsp; is somewhere in there&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; pyspark.sql &lt;/SPAN&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; SparkSession&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; pyspark.sql.functions &lt;/SPAN&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; col, from_json, explode, get_json_object, schema_of_json&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; pyspark.sql.functions &lt;/SPAN&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; col, explode, expr, unbase64, from_unixtime,&lt;/SPAN&gt;&lt;SPAN&gt;hex&lt;/SPAN&gt;&lt;SPAN&gt;,length&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;df &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; spark.read.&lt;/SPAN&gt;&lt;SPAN&gt;format&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"delta"&lt;/SPAN&gt;&lt;SPAN&gt;).&lt;/SPAN&gt;&lt;SPAN&gt;table&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"iot_ps2"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#df.display()&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df2&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;df.&lt;/SPAN&gt;&lt;SPAN&gt;select&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"headers"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df2.&lt;/SPAN&gt;&lt;SPAN&gt;display&lt;/SPAN&gt;&lt;SPAN&gt;()&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;# Explode the array of structs into individual rows&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df_exploded &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; df.&lt;/SPAN&gt;&lt;SPAN&gt;withColumn&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"json_item"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;explode&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;col&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"headers"&lt;/SPAN&gt;&lt;SPAN&gt;)))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;# Filter rows to get only the 'iothub-enqueuedtime' key&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df_filtered &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; df_exploded&lt;/SPAN&gt;&lt;SPAN&gt;.filter&lt;/SPAN&gt;&lt;SPAN&gt;(col(&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;json_item&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;key&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;) &lt;/SPAN&gt;&lt;SPAN&gt;==&lt;/SPAN&gt; &lt;SPAN&gt;"iothub-enqueuedtime"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df3&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;df_filtered.&lt;/SPAN&gt;&lt;SPAN&gt;select&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"json_item.key"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;"json_item.value"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df3&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;df3.&lt;/SPAN&gt;&lt;SPAN&gt;withColumn&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"str_value"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;expr&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"cast(value as STRING)"&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df3&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;df3.&lt;/SPAN&gt;&lt;SPAN&gt;withColumn&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"hex"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;expr&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"hex(str_value)"&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df3.&lt;/SPAN&gt;&lt;SPAN&gt;display&lt;/SPAN&gt;&lt;SPAN&gt;()&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;looking at the hex code it is possible to determine that the 6 rightmost bytes "01 90 36 4C 1B 5C" turn into a unix timestamp with milliseconds. That leaves 3 unknown bytes&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I'm hoping that a more straightforward way is available&lt;/DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Plmi_0-1718906244920.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/8846i84577B4B4D8519D0/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="Plmi_0-1718906244920.png" alt="Plmi_0-1718906244920.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 20 Jun 2024 18:03:38 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/iot-hub-with-kafka-connector-how-to-decode-the-enqueued/m-p/75237#M34903</guid>
      <dc:creator>Pálmi</dc:creator>
      <dc:date>2024-06-20T18:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: IoT hub with kafka connector - how to decode the enqueued timestamp and device id</title>
      <link>https://community.databricks.com/t5/data-engineering/iot-hub-with-kafka-connector-how-to-decode-the-enqueued/m-p/75241#M34906</link>
      <description>&lt;P&gt;&lt;A href="https://github.com/Azure/azure-event-hubs-for-kafka/issues/56#issuecomment-1432006831" target="_blank"&gt;https://github.com/Azure/azure-event-hubs-for-kafka/issues/56#issuecomment-1432006831&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2024 19:46:48 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/iot-hub-with-kafka-connector-how-to-decode-the-enqueued/m-p/75241#M34906</guid>
      <dc:creator>Erik</dc:creator>
      <dc:date>2024-06-20T19:46:48Z</dc:date>
    </item>
  </channel>
</rss>

