<?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 Sandeep Arikarevula on Medium]]></title>
        <description><![CDATA[Stories by Sandeep Arikarevula on Medium]]></description>
        <link>https://medium.com/@sandeeparikarevula?source=rss-0e388a4558a4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*FOpltjiUSawBy-M_</url>
            <title>Stories by Sandeep Arikarevula on Medium</title>
            <link>https://medium.com/@sandeeparikarevula?source=rss-0e388a4558a4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 05:43:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sandeeparikarevula/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[Efficient Data Management with Partitioned Parquet Files: A Daily Data Append and Cleanup Strategy]]></title>
            <link>https://medium.com/@sandeeparikarevula/efficient-data-management-with-partitioned-parquet-files-a-daily-data-append-and-cleanup-strategy-3aabe6e5df13?source=rss-0e388a4558a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3aabe6e5df13</guid>
            <category><![CDATA[repartition]]></category>
            <category><![CDATA[data-partitioning]]></category>
            <category><![CDATA[databricks]]></category>
            <category><![CDATA[pyspark]]></category>
            <category><![CDATA[parquet]]></category>
            <dc:creator><![CDATA[Sandeep Arikarevula]]></dc:creator>
            <pubDate>Wed, 19 Jun 2024 13:57:18 GMT</pubDate>
            <atom:updated>2024-06-19T13:57:18.223Z</atom:updated>
            <content:encoded><![CDATA[<p>This narrative outlines a method for efficiently storing and managing data in a partitioned Parquet file, where each partition corresponds to a unique run identifier, referred to as the ‘Datakey’ column in our context.</p><p>Imagine a situation where you receive daily data, with each day’s batch tagged by a distinct Datakey identifier. Your objective is to append this data to an existing Parquet file. At some point, you decide to purge specific historical data that is no longer required. How would you go about this? One might consider reading the entire Parquet file, excising the unwanted rows, and then rewriting the file.</p><p>While this approach may seem logical, it becomes impractical and resource-intensive if the cleanup operation is to be performed frequently. Reading and rewriting the entire file just to remove certain entries is inefficient.</p><p>A more effective solution is to utilize a partitioned Parquet file structure, where the data is segmented by the datakey column. This allows for the isolation of each day’s data within the same file, facilitating easier management and deletion of data without affecting the rest of the dataset.</p><p>To illustrate, let’s examine a simple example. Suppose we have a dataframe, df1, which contains the data slated for processing today, and is assigned the datakey ID of 1111.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*PW8P93AM8VKhZZG96sYBBA.png" /></figure><p>Let’s proceed with repartitioning the dataframe df1 by the ‘DataKey’ column. Since today’s data is uniformly tagged with the DataKey ID 1111, this operation will result in a single partition. We will then write this partitioned data to a Parquet file in append mode, as our goal is to continuously add new data each day to the same file. By applying the partitionBy method on the ‘DataKey’ column, we ensure that the data is organized into separate partitions within the Parquet file, each corresponding to a different day’s data.</p><pre>final_df = df1.repartition(&#39;DataKey&#39;)<br>final_df.write.partitionBy(&#39;DataKey&#39;).mode(&quot;append&quot;).parquet(&quot;/mnt/adls_dhb/data/tdf_si_dhb_external_poc_tobedeleted/output&quot;)</pre><p>Now that we have successfully processed and stored df1 with the DataKey ID 1111, let’s assume we have received a new batch of data. This new data is loaded into a dataframe called df2, and it is associated with a different DataKey ID, specifically 2222. Just as we did with df1, we will repartition df2 based on the ‘DataKey’ column. Given that all entries in df2 share the same DataKey ID of 2222, this will also result in a single partition. We will then append this new partition to our existing Parquet file, using the same append mode and partitionBy method on the ‘DataKey’ column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*8Ct8k5kGJ_KwN6h9TmVvOA.png" /></figure><p>If you execute the same piece of code as below for df2 a new partition will be created in the same parquet file inside output folder.</p><pre>final_df = df2.repartition(&#39;DataKey&#39;)<br>final_df.write.partitionBy(&#39;DataKey&#39;).mode(&quot;append&quot;).parquet(&quot;/mnt/adls_dhb/data/tdf_si_dhb_external_poc_tobedeleted/output&quot;)</pre><p>Here’s what the output folder looks like after df1 and df2 gets loaded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*t1jWMaNFlqOWu1r-tvkQBQ.png" /></figure><p>Hooray! Now we have partitions created. That means we can either read entire parquet file by pointing to output folder or point to individual Datakey folder to read/delete that specific partition without having to access entire file and write it back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yMJy8XJlcJH0aIf855Je7g.png" /></figure><p>This process ensures that each day’s data is stored in a distinct partition within the Parquet file, labeled by its unique DataKey ID. By maintaining this partitioned structure, we facilitate efficient data management, allowing for easy access to specific data subsets and straightforward removal of obsolete data without affecting the rest of the file.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3aabe6e5df13" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Indexing on SQL tables]]></title>
            <link>https://medium.com/@sandeeparikarevula/indexing-on-sql-tables-df6a1406a9e7?source=rss-0e388a4558a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/df6a1406a9e7</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[sql-index]]></category>
            <category><![CDATA[sql-optimization]]></category>
            <category><![CDATA[sql-indexing]]></category>
            <dc:creator><![CDATA[Sandeep Arikarevula]]></dc:creator>
            <pubDate>Wed, 05 Jun 2024 10:17:59 GMT</pubDate>
            <atom:updated>2024-06-05T10:17:59.955Z</atom:updated>
            <content:encoded><![CDATA[<h3>What are Indexes in SQL?</h3><p>Indexes in SQL are specialized lookup tables that are used by the database search engine to accelerate data retrieval.</p><p>In simple terms, an index in SQL is a tool used to quickly identify rows with specific column values. If there were no indexes, the SQL server would have to start with the first row and then go through the entire table until it discovers the relevant rows. This method is known as a full-table scan and can be highly inefficient for large tables.</p><h3>Why Indexes in SQL are Used?</h3><ul><li><strong>Improved Query Performance:</strong> The primary reason for using indexes is to accelerate query processing. Indexes can drastically reduce the amount of data the server needs to examine.</li><li><strong>Efficient Data Access:</strong> Indexes provide a quick way to access row data for SELECT statements. This is particularly beneficial for tables with a large number of rows.</li><li><strong>Sorting and Grouping Speed:</strong> Indexes improve the speed of data retrieval operations by providing a sorted version of the data, which is faster to process for ORDER BY and GROUP BY operations.</li><li><strong>Unique Constraints: </strong>Indexes can be used to enforce uniqueness for columns to ensure that no two rows of a table have duplicate values in a particular column or a combination of columns.</li><li><strong>Optimized Join Operations:</strong> In databases with multiple tables, indexes improve the speed of join operations by quickly locating the joining rows in each table.</li></ul><p><strong>Note:</strong></p><p>Apart from these advantages of Indexes in SQL, they have some limitations too, like:</p><ul><li><strong>Overuse of Indexes:</strong> While indexes speed up data retrieval, they can slow down data input, through INSERT, UPDATE, and DELETE statements. Each index needs to be updated when data is modified.</li><li><strong>Storage Space: </strong>Indexes consume additional disk space.</li><li><strong>Maintenance Overhead: </strong>Indexes need to be maintained and rebuilt over time, which can add overhead to database maintenance routines.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df6a1406a9e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Types of SQL Indexes]]></title>
            <link>https://medium.com/@sandeeparikarevula/types-of-sql-indexes-8ec3107795ef?source=rss-0e388a4558a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ec3107795ef</guid>
            <category><![CDATA[sql-indexing]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[sql-query-performance]]></category>
            <category><![CDATA[query-optimization]]></category>
            <category><![CDATA[optimize-sql]]></category>
            <dc:creator><![CDATA[Sandeep Arikarevula]]></dc:creator>
            <pubDate>Wed, 05 Jun 2024 10:03:54 GMT</pubDate>
            <atom:updated>2024-06-05T10:03:54.922Z</atom:updated>
            <content:encoded><![CDATA[<p>There are many types of SQL Indexes out of which four major types (Primary Key Index, Unique Key Index, Clustered and Non Clustered Indexes) are discussed below along with examples and use cases:</p><h3>Primary Key Index</h3><p>A primary key is a field or a combination of fields in a database table that uniquely identifies each record (row) in that table. A primary key index is an automatically generated index associated with the primary key column(s) to enhance data retrieval and enforce data uniqueness.</p><p>Importance of Primary Key Index</p><ul><li><strong>Data Uniqueness: </strong>The primary key index enforces the uniqueness constraint on the designated column(s). i.e., no two records in the table can have the same values in the primary key column(s). It prevents duplicate records, ensuring data accuracy.</li><li><strong>Data Retrieval Efficiency:</strong> By creating a primary key index, the database management system (DBMS) generates a data structure that allows for rapid data retrieval. Instead of scanning the entire table, the DBMS can use the primary key index to pinpoint the exact location of a specific record, significantly improving query performance.</li><li><strong>Join Operations:</strong> Primary keys are often used in join operations, where data from multiple tables is combined. The primary key index ensures quick and efficient matching of records during these operations, reducing processing time.</li></ul><p><strong>Use Cases:</strong></p><ul><li><strong>Identification: </strong>Primary keys are commonly used to identify records in a table uniquely. For example, in an “Employees” table, the employee ID might serve as the primary key, allowing each employee to uniquely identify by their ID.</li><li><strong>Relationships:</strong> Primary keys are essential when establishing relationships between tables in a relational database. They serve as foreign keys in related tables, ensuring referential integrity.</li><li><strong>Data Integrity: </strong>Primary keys guarantee data integrity by preventing the insertion of duplicate records, ensuring that each record is unique.</li></ul><h3>Unique Key Index</h3><p>A unique index in a relational database is a data structure that enforces the uniqueness constraint on one or more columns within a table. Its primary purpose is to ensure that values stored in the indexed column(s) are unique across all records in the table.</p><p>Role in Maintaining Unique Values:</p><ul><li>A unique index serves as a safeguard against duplicate data entries. It ensures that the data integrity of a table is maintained by preventing the insertion of rows with duplicate values in the indexed column(s).</li><li>When a unique index is created on a column, the database management system (DBMS) automatically checks for duplicate values whenever a new record is inserted, or an existing record is updated in the table.</li><li>If an insertion or update operation would result in a duplicate value in the indexed column(s), the DBMS raises an error, and the operation is rejected, thereby preventing the introduction of duplicate data.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*JSWRwBOtUD9lNizpsSypQg.png" /></figure><p><strong>Use Cases:</strong></p><ul><li>Email Addresses: In a user database, using a unique index on the email address column ensures that each user has a unique email, preventing multiple accounts with the same email.</li><li>Identification Numbers: When storing identification numbers like social security or passport numbers, a unique index ensures that no two individuals share the same identifier within the database.</li><li>Product SKUs: Unique indexes can be applied to product SKU (Stock Keeping Unit) columns to prevent duplicate SKUs in an inventory database.</li><li>Membership IDs: In a membership system, unique indexes on membership IDs guarantee that each member has a distinct identification number.</li><li>Invoice Numbers: In financial systems, unique indexes on invoice numbers ensure that each invoice is uniquely identified, avoiding billing errors.</li></ul><h3>Clustered Index</h3><p>A clustered index sorts and stores the rows of a table based on the values in one or more specified columns. Each table can have only one clustered index, and the choice of the clustering column(s) significantly impacts how data is stored and retrieved.</p><p>Importance of Clustered Index</p><ul><li><strong>Physical Data Organization:</strong> The primary purpose of a clustered index is to physically order the data rows in the table based on the values in the indexed column(s). This arrangement allows for efficient data retrieval when queries request data in the same order as the clustered index.</li><li><strong>Optimized Data Retrieval:</strong> Clustered indexes are particularly useful for improving query performance when selecting, sorting, or filtering data based on the columns included in the clustered index. They eliminate the need for a separate data lookup process, as the data rows are already stored in the desired order.</li><li><strong>Sequential Access:</strong> When queries involve range scans or retrieving a range of data values, a clustered index is highly efficient. It allows for sequential access, reducing disk I/O operations and enhancing query speed.</li></ul><p><strong>Use Cases of Clustered Index</strong></p><ul><li><strong>Primary Key: </strong>A common use of a clustered index is to define it on the primary key column(s). This ensures that the table’s data is physically ordered according to the primary key values, facilitating fast retrieval of specific records.</li><li><strong>Date and Time Data: </strong>In tables where date and time information is critical, a clustered index on a timestamp column allows for efficient retrieval of data based on chronological order.</li><li><strong>Sequential Data: </strong>For tables that store sequentially generated data, such as transaction logs or sequential invoice numbers, a clustered index can optimize the retrieval of data in chronological or sequential order.</li></ul><h3>Non-Clustered Index</h3><p>A non-clustered index is a type of index used in relational databases to improve the efficiency of data retrieval operations. Unlike clustered indexes, which affect the physical order of data rows within a table, non-clustered indexes create separate data structures to allow fast access to specific data subsets. This means that non-clustered indexes do not rearrange the physical organization of data, but rather create a separate structure to facilitate quicker access to the data.</p><p>Importance of Non-Clustered Index</p><ul><li><strong>Faster Data Retrieval: </strong>Non-clustered indexes significantly improve query performance by allowing the database management system (DBMS) to quickly locate and retrieve specific data rows based on the indexed column(s).</li><li><strong>Reduced Disk I/O:</strong> Non-clustered indexes reduce the need for full table scans when querying data. This leads to fewer disk input/output (I/O) operations, resulting in faster query execution.</li><li><strong>Support for Multiple Indexes: </strong>Unlike clustered indexes, which limit a table to one, non-clustered indexes can be created on multiple columns, enabling efficient retrieval for various query patterns.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*wmj8trfstmLmSbF9tmHmRA.png" /></figure><p><strong>All SQL Indexes — Types, Uses, Advantages, Disadvantages, and Scenarios</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*_FlwwPG2fU_S21lRMP_jgg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ec3107795ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Run multiple notebooks in parallel in Databricks.]]></title>
            <link>https://medium.com/@sandeeparikarevula/run-multiple-notebooks-in-parallel-in-databricks-211aace6cdfe?source=rss-0e388a4558a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/211aace6cdfe</guid>
            <category><![CDATA[threadpoolexecutor]]></category>
            <category><![CDATA[databricks]]></category>
            <category><![CDATA[data-engineer]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Sandeep Arikarevula]]></dc:creator>
            <pubDate>Sun, 07 Apr 2024 09:13:48 GMT</pubDate>
            <atom:updated>2024-06-19T14:12:15.527Z</atom:updated>
            <content:encoded><![CDATA[<p>We all know that we could run a databricks notebook from existing notebook cell. Below is the syntax:</p><blockquote>dbutils.notebook.run(“notebook-name”, 60, {“argument”: “data”, “argument2”: “data2”, …})</blockquote><p>There could be scenarios where we need to call a notebook run in a traditional loop (for, while loop etc) which will run sequentially. But what if you want to call multiple notebook runs parallelly ??</p><p>Here’s how you can do it with <strong>‘<em>concurrent.futures.ThreadPoolExecutor</em>’</strong>.</p><pre>try:<br><br><br>    import concurrent.futures<br>    <br>    csv_files_list = [&#39;sample1.csv&#39;, &#39;sample2.csv&#39;, &#39;sample3.csv&#39;]<br><br>    def process_csv_file(csv_file_name, p_id):<br>        return dbutils.notebook.run(<br>            &quot;/my_path_to_the_notebook/create_table_from_csv&quot;,<br>            0,<br>            {<br>                &quot;pid&quot;: p_id,<br>                &quot;source_file&quot;: csv_file_name,<br>            }<br>        )<br><br><br>    csv_tables_list = []<br><br><br>    # Use ThreadPoolExecutor to run the notebook executions in parallel<br>    with concurrent.futures.ThreadPoolExecutor() as executor:<br>        <br>        # Submit each execution task to the executor and store the Future object in a list<br>        futures = [executor.submit(process_csv_file, csv_file_name, p_id) for csv_file_name in csv_files_list]<br><br>        # Wait for all tasks to complete and get their results<br>        for future in concurrent.futures.as_completed(futures):<br>            csv_table_name_created = future.result()<br>            csv_tables_list.append(csv_table_name_created)<br><br>    # Print list of csv delta tables created<br>    print(csv_tables_list)<br><br><br>except Exception as Error:<br>    raise Exception(&quot;[Error] Failed in CSV to table creation step...&quot;,Error)</pre><h4>Step by step explanation of above code:</h4><ol><li>Importing Modules: The code starts with importing the concurrent.futures module, which provides a high-level interface for asynchronously executing callables.</li><li>Defining CSV Files List: A list called csv_files_list is defined, containing the names of CSV files to be processed.</li><li>Defining the Task Function: The function process_csv_file is defined. This function takes two arguments: csv_file_name and p_id. It appears that this function executes a Databricks notebook (create_table_from_csv) using dbutils.notebook.run. The csv_file_name and p_id are passed as parameters to the notebook. Imagine this is a simple function which reads csv file from input parameter and create a delta table and returns the name of the new table created.</li><li>Initializing Result List: An empty list csv_tables_list is created to store the results of the processing.</li><li>Executing Tasks Concurrently: The ThreadPoolExecutor is used to run the tasks in parallel. The submit method is used to submit each task (process_csv_file) to the executor, and a list comprehension is employed to create a list of futures representing these tasks.</li><li>Waiting for Tasks to Complete: The as_completed function from concurrent.futures is used to iterate over the futures as they are completed. The result of each completed task is retrieved using the result method of the future object, and it is appended to the csv_tables_list.</li><li>Printing Results: Finally, the list of newly created CSV tables names is printed.</li><li>Error Handling: The code includes error handling using a try-except block. If any exceptions occur during the execution of the try block, they will be caught, and an exception with a custom error message will be raised.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=211aace6cdfe" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>