<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Abhishek Patil on Medium]]></title>
        <description><![CDATA[Stories by Abhishek Patil on Medium]]></description>
        <link>https://medium.com/@rohanpatil4526?source=rss-d965f9d320e1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*gGrsvHAAw_4sAM8K</url>
            <title>Stories by Abhishek Patil on Medium</title>
            <link>https://medium.com/@rohanpatil4526?source=rss-d965f9d320e1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 14:35:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rohanpatil4526/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Deep Dive Into Databricks Z-Ordering]]></title>
            <link>https://medium.com/@rohanpatil4526/deep-dive-into-databricks-z-ordering-e3fa93125935?source=rss-d965f9d320e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3fa93125935</guid>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[databricks]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data-engineering]]></category>
            <dc:creator><![CDATA[Abhishek Patil]]></dc:creator>
            <pubDate>Sat, 08 Jun 2024 11:20:31 GMT</pubDate>
            <atom:updated>2024-06-08T11:31:04.885Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*Oueop9gaLIQJ5v5nlpqIPA.png" /></figure><p>When we run certain queries on a delta table, databricks doesn’t scan all the files. Instead, it skips some files that are not relevant based on the logic (takes advantage of information like minimum and maximum values, null counts, and total records per page) only to check the required files and get the data accordingly. This process is known as data skipping and is crucial in the optimization technique. The More the files skipped while scanning, the better the query performance.</p><h4>What is Z-Ordering?</h4><p>Z-Ordering is a technique to co-locate related information in the same set of files. This behavior drastically reduces the amount of data that Delta Lake on Databricks needs to read. To implement Z-Ordering on the data, we need to specify the columns to order in the <em>ZORDER BY</em> clause.</p><pre>OPTIMIZE sales_order<br>ZORDER date;</pre><h4>Z-Ordering Vs Partitioning</h4><p>If you expect a column to be commonly used in query predicates and if that column has high cardinality (that is, a large number of distinct values), then go by <strong><em>Z-Ordering</em></strong> and use ZORDER BY. You can specify multiple columns for ZORDER BY as a comma-separated list.</p><p>If you expect a column to be commonly used in query predicates and if that column has low cardinality (that is, less distinct values), then go by <strong><em>Partitioning.</em></strong></p><h4>Example Use Case</h4><p>Suppose I have a flight dataset loaded into a dataframe and saved into a delta table <em>flights.</em></p><pre>flights = spark.read.format(&quot;csv&quot;).option(&quot;header&quot;, &quot;true&quot;).option(&quot;inferSchema&quot;, &quot;true&quot;.load(&quot;/databricks-datasets/asa/airlines/2008.csv&quot;)<br>display(flights)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OKV1bSDcsYXj54Iw4SUuCA.png" /></figure><p>Now when we are performing this query as below</p><pre>%sql<br>SELECT count(*) as Flights, Dest, Month from flights WHERE DayofMonth = 5 GROUP BY Month, Dest</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jyzPfy3dzm0RlH0-kCeulA.png" /></figure><p>Next, we can run the following OPTIMZE combined with Z-ORDER command on the column that we want to filter, which is DayofMonth. Note that Z-Order optimizations work best on columns that have high cardinality.</p><pre>%sql<br>OPTIMIZE flights ZORDER BY (DayofMonth)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*raSI75ypYbe9YTVvCTVfIA.png" /></figure><p>Now when the same query is run again, this time we can see that it only took approximately 39 seconds to complete, which is around a 70% improvement in the optimized query speed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oHYOdVwpzE4YepWtNHbqZg.png" /></figure><h4>Rules to keep in mind</h4><p>The following rules are important to keep in mind while planning a query optimization strategy based on partition boundaries and Z-order:</p><ul><li>Z-order works in tandem with the OPTIMIZE command. You cannot combine files across partition boundaries, and so Z-order clustering can only occur within a partition. For unpartitioned tables, files can be combined across the entire table.</li><li>Partitioning works well only for low or known cardinality fields (for example, date fields or physical locations), but not for fields with high cardinality such as timestamps. Z-order works for all fields, including high cardinality fields and fields that may grow infinitely (for example, timestamps or the customer ID in a transactions or orders table).</li><li>You cannot Z-order on fields used for partitioning.</li><li>Databricks recommends you do not partition or z-order tables that contains less than a terabyte of data (like fact or transaction tables)</li></ul><h4>Conclusion</h4><p>We can always use both partitioning and z-ordering in one table unless it is the same column according to the requirements to make the query run faster on the table. Choosing the right partition column and the right z-ordering column will be the key factor for speeding up the respective queries.</p><p>Key Note: By using Delta Lake and Databricks Runtime 11.3 LTS or above, unpartitioned tables you create benefit automatically from <a href="https://www.databricks.com/blog/2022/11/18/introducing-ingestion-time-clustering-dbr-112.html">ingestion time clustering</a>. Ingestion time provides similar query benefits to partitioning strategies based on datetime fields without any need to optimize or tune your data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3fa93125935" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an end to end data pipeline for live streaming using Azure IoT Hub and Function App.]]></title>
            <link>https://medium.com/@rohanpatil4526/building-an-end-to-end-data-pipeline-for-live-streaming-using-azure-iot-hub-and-function-app-2914930d320f?source=rss-d965f9d320e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/2914930d320f</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[live-streaming]]></category>
            <dc:creator><![CDATA[Abhishek Patil]]></dc:creator>
            <pubDate>Sun, 02 Apr 2023 04:58:03 GMT</pubDate>
            <atom:updated>2023-04-02T05:59:08.376Z</atom:updated>
            <content:encoded><![CDATA[<p>Azure IoT Hub is a managed service hosted in the cloud that acts as a central message hub for communication between an IoT application and its attached devices. You can connect millions of devices and their backend solutions reliably and securely. Almost any device can be connected to an IoT hub.</p><h4><em>What is edge computing?</em></h4><p><em>Edge computing takes place at or near the physical location of either the user or the source of the data. By placing computing services closer to these locations, users benefit from faster, more reliable services with better user experiences, while companies benefit by being better able to support latency-sensitive applications, identify trends, and offer better products and services.</em></p><p><a href="https://www.redhat.com/en/topics/edge-computing/iot-edge-computing-need-to-work-together#:~:text=An%20IoT%20device%20is%20a,data%20is%20collected%20and%20processed.">Link for reference</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/0*dd09M3izDUC3KLo3" /></figure><p>Here, we will be showing streaming of data from those edge devices using Azure technologies like Azure IoT Hub which is specifically design for IoT devices, Azure Function app which will be useful for the transformation of the semi-structured data that we get, and others like Azure SQL, Postgres or others for storage of the data.</p><p>Due to limitations in the subscription for our Azure account(students version), we were not able to fully utilize the services and thus the performance issues were quite significant. This will not be the case in the paid subscription. However , we can fully understand the capabilities that one can have in Azure and understand the end to end data pipeline that we can built for live streaming of data.</p><h4><strong>Setting up an IoT Hub</strong></h4><p>The steps to create the Azure IoT Hub</p><ul><li>Create an Azure account and log in to the Azure portal</li><li>Create a new IoT Hub resource and select the desired settings, such as the pricing tier, resource group, and region</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1eQ-H5LlFJ9O41pS" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ee09Z0a__LfGUyAp" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*o0j4mwirPkg0bs7W" /></figure><ul><li>Once the IoT Hub is created, select it and navigate to the “Shared access policies” section</li><li>Create a new policy with “service connect” and “device connect” permissions</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gCt8EDO9FlYGRb8G46E7jA.png" /></figure><p>Now, our IoT Hub is ready here. We can now connect this created hub with the edge devices and can get the required data from there .</p><p>We, now, can register the device that we have to connect . For this task, it has two options as you can see in the image, viz. <em>Devices </em>and <em>IoT Edge</em> .</p><ul><li>If some device has directly provision to throw the messages to cloud , we can click on the <em>Devices </em>tab in the left vertical panel and then create, and then supply the required connection string.</li><li>If some device is not capable to throw messages to Azure or, there is need to deploy the customs modules, we can use the <em>IoT Edge</em> provided by the Azure and install the IoT Edge runtime on the device.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pCMQw4uKpUI9wYySWOPsmw.png" /></figure><p><strong>Register a device:</strong> After creating the IoT Hub, you need to register a device to it. You can register a device using the Azure portal or using code. In this case, we will register a simulated device that sends temperature readings.</p><h4>Creating the IoT Edge device</h4><p>Here, we don’t have edge devices as these are costly and used in the industrial applications . So, thus , for testing we will be considering one Linux virtual machine, which will be acting as the edge device/simulator for us .</p><p>Now, before jumping into the device , first, lets create the device in the Azure IoT Hub for connecting our device as shown in image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*e2oAR25t1wE7RFg8" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vbzyPCmQ37B6iri4" /></figure><p>Here, as you can see , we have created the device name sensor1. The device is ready now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*labViuQPMn8tl8fe" /></figure><p>When the device is created , we will get two modules, which are created automatically with it , <em>Edge Agent</em> and <em>Edge Hub</em> . Each of them has its significance and is basically, used to run the edge runtime on the device . This can be seen as in below image. Also, we can note down the primary connection string from here , which , later we will be using it to connect the device to the Azure IoT Hub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FAa7JZ6zCcnNueYW" /></figure><h4>Setting up Temperature Sensor Module</h4><p>Now, as we are not having any meter to connect to the edge gateway, we will be installing a dummy data module which is provided by the Azure which is called the <em>Temperature Sensor Module</em>. This module emits the dummy data like the real sensor. Azure has specifically created this module for testing purpose.</p><p>For this , we will have to click on the <em>Set Modules</em> tab which can be seen in the picture and then from the Market place section , we can directly install it .</p><p><em>Note: Some legacy edge gateways doesn’t have the capability to communicate in the MQTT/ AMQP protocol. For that, Azure has provided the readymade module name Modbus which after implementing on the device, readily converts Modbus to MQTT.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vXGL5RqP6R5fon2R" /></figure><p>You can see the <em>Simulated Temperature Sensor </em>Module in the image below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zFmUvuq6ru5aYF2cxSeYxA.png" /></figure><p>Now, lets install it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3oEAS3mBJoTAvBil" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Gtsza8sj7f_4RiYm" /></figure><h3>IoT Hub is Ready…</h3><p>Our IoT Hub is ready with the required modules in it that we will be needing to connect with our device. Now, lets connect this Iot Hub with the Linux virtual machine that we will be using as a edge gateway.</p><p>I have created the virtual machine with the OS as ubuntu 18.04. As this machine is not capable of throwing messages directly, we will need to install the Azure IoT edge runtime on the machine. The steps according to the OS is provided by the Microsoft for the installation.</p><p><a href="https://learn.microsoft.com/en-us/azure/iot-edge/how-to-provision-single-device-linux-symmetric?view=iotedge-1.4&amp;tabs=azure-portal%2Cubuntu">Link to install IoTEdge runtime</a></p><p>After installation of Azure IoTEdge runtime , the config file will be formed by the name config.toml in the installation path and thus, for connecting our IoT Hub with the device, we have to give our connection string that we have noted earlier in the configuration file as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/0*8kdioLRvjo1P0goa" /></figure><p>Now , lets check if the IoT Edge runtime is installed successfully on our machine.</p><p>We can check this by using the command — <strong>sudo iotedge check</strong></p><p>This command will run and check if everything is in the right place as shown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/0*HqbctZv9Qf_Phokv" /></figure><p>It looks like we have successfully connected the device with Azure IoT Hub.</p><p>We can see our respective module here as shown through the commands as shown in the figure and also can see the logs for the temperature sensor that we are getting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FuoHVGtxKCpTxo3p" /></figure><h4>Creating a function to the IoT Hub</h4><p>As we can see here , the data is in semi-structured format and thus, we will have to do some pre-processing over the data. For Serverless computation , Azure provides the service know as Function App, where we can write the code in Python, Java, JavaScript (NodeJS). Here, there are different triggers available for the function. There is specific trigger also available for IoT Hub on which the function will run, whenever the data will come to the Hub.</p><p>After selecting the Event Hub trigger, select the IoT Hub trigger and mention the name of our IoT Hub, which in our case, will be <em>temperaturesensor1 .</em>Now, give the details ,like Event Hub name as the name that you get in the shared access policies that are present in the IoT Edge as well as the connection string. You can keep the consumer group as Default or create one.</p><p>Click create and the function will be created . Now, we can navigate to the function that is created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2KH0PjR5KP8od61P" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gkCuQ1wLbjuIKwMJ" /></figure><p>Here , inside the function , we can code as we want and fetch the results from any kind of unstructured data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6HdlRf9Chmok4pr2" /></figure><p>Here, as you can see, we are getting the data from the temperature sensor ,which is a live data coming every 5 seconds. We can write code , do transformations accordingly and fetch the results as needed, per message coming and thus, can append that results to various targets like any RDBMS , visualize it in Power BI, and others.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*E-74cVxZXnNTLm4g" /></figure><h4>Integrating with Other Sources</h4><p>We can integrate this transformed results to various targets such as Azure SQL for storing, visualize a live stream by connecting it to tools like Power BI, analyze through Databricks where we can write the machine learning code and do predictive analysis, from the Integration tab in the Function as shown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aUN_cZFLPEM_OcSm" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SsSUEhSRP-wDNx1WU6PkJg.png" /></figure><p>We can integrate this function with several connectors as shown above like Blob storage, or others.</p><p>In today’s modern world, live streaming data pipelines have become increasingly important due to the rapid growth of real-time data-driven applications and services.</p><ul><li>Real-time insights: Live streaming data pipelines enable organizations to analyze and act on data in real-time, providing insights into trends, events, and anomalies as they happen. This allows organizations to make more informed decisions and respond quickly to changing business conditions.</li><li>Enhanced customer experience: Live streaming data pipelines can help organizations improve the customer experience by providing real-time insights into customer behavior and preferences. This can be used to personalize interactions and provide more relevant and timely offers and recommendations.</li><li>Operational efficiency: Live streaming data pipelines can help organizations improve operational efficiency by providing real-time monitoring and alerting capabilities. This can help organizations quickly identify and address issues, such as system failures or security breaches, before they escalate.</li><li>Competitive advantage: Live streaming data pipelines can provide a competitive advantage by enabling organizations to respond quickly to changes in the market, customer preferences, or business conditions. This can help organizations stay ahead of the competition and identify new opportunities for growth and innovation.</li></ul><p>Overall, live streaming data pipelines have become an essential component of modern data-driven organizations, enabling them to gain real-time insights, improve the customer experience, enhance operational efficiency, and gain a competitive advantage.</p><p><em>In order to keep this article short and simple, I have just given an overview and idea about the capabilities in the Azure featuring around IoT devices.</em></p><blockquote><em>If you have reached this far, thank you for reading this blog. I hope you found it insightful 😀 . Please do follow.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2914930d320f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>