<?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 Basavaraj Dharegonnavar on Medium]]></title>
        <description><![CDATA[Stories by Basavaraj Dharegonnavar on Medium]]></description>
        <link>https://medium.com/@basavarajd119?source=rss-d85c9e7d95c1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*gTxFwZuYTZO5FdOF.</url>
            <title>Stories by Basavaraj Dharegonnavar on Medium</title>
            <link>https://medium.com/@basavarajd119?source=rss-d85c9e7d95c1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 16:06:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@basavarajd119/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[Apache Spark 4.2: What’s New and What Data Engineers Should Know in 2026]]></title>
            <link>https://medium.com/@basavarajd119/apache-spark-4-2-whats-new-and-what-data-engineers-should-know-in-2026-9f002fc1619c?source=rss-d85c9e7d95c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f002fc1619c</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[hadoop]]></category>
            <category><![CDATA[pyspark]]></category>
            <dc:creator><![CDATA[Basavaraj Dharegonnavar]]></dc:creator>
            <pubDate>Mon, 26 Oct 2026 18:11:37 GMT</pubDate>
            <atom:updated>2026-10-26T18:11:37.420Z</atom:updated>
            <content:encoded><![CDATA[<p>Apache Spark continues to evolve to meet the demands of modern data engineering.</p><p>In this article, we’ll explore some important developments in Apache Spark 4.2:</p><ul><li><strong>Change Data Capture (CDC):</strong> Read row-level changes in batch and streaming workloads.</li><li><strong>Automatic CDC processing:</strong> Explore how Spark Declarative Pipelines can simplify change processing and Type 1 upserts.</li><li><strong>Arrow-optimized Python UDFs:</strong> Understand how Arrow improves data exchange between Python and Spark’s execution engine.</li><li><strong>Geospatial data types:</strong> Explore native support for geometry and geography data.</li><li><strong>Data Source V2 improvements:</strong> Understand transaction management, schema evolution, and partition statistics.</li></ul><h3>Why does this matter?</h3><p>Data engineers need to build pipelines that process changing data efficiently, handle schema changes safely, and scale as data volumes increase.</p><p>Understanding new Spark capabilities helps us evaluate whether they can simplify existing pipelines and reduce custom code.</p><p><strong>Key takeaway:</strong> Modern data engineering is not just about processing large datasets. It’s about building reliable, scalable, and maintainable data platforms.</p><p><strong>Official reference:</strong> <a href="https://spark.apache.org/releases/spark-release-4-2-0?utm_source=chatgpt.com">Apache Spark 4.2.0 Release Notes</a></p><h3><strong>Delta Lake vs Apache Iceberg vs Apache Hudi: Which Table Format Should Data Engineers Choose in 2026?</strong></h3><p>Cover these concepts:</p><ul><li>What is an open table format?</li><li>ACID transactions on cloud object storage.</li><li>Schema evolution and time travel.</li><li>Handling inserts, updates, and deletes.</li><li>Streaming and incremental ingestion.</li><li>Catalog integration and multi-engine compatibility.</li><li>How to select a format for a particular workload.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*pcGClMlWRbwsycXGN7oyfA.png" /></figure><p>These are broad distinctions, not absolute limitations. All three projects offer overlapping capabilities, so evaluate your workload, catalog, engine compatibility, and operational requirements before choosing one.</p><p>Official references:</p><ul><li><a href="https://docs.delta.io/?utm_source=chatgpt.com">Delta Lake Documentation</a></li><li><a href="https://iceberg.apache.org/?utm_source=chatgpt.com">Apache Iceberg Documentation</a></li><li><a href="https://hudi.apache.org/?utm_source=chatgpt.com">Apache Hudi Documentation</a></li></ul><p>Happy Reading!!!!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f002fc1619c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Cheat Memory Map]]></title>
            <link>https://medium.com/@basavarajd119/sql-cheat-memory-map-39fb68d14ae8?source=rss-d85c9e7d95c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/39fb68d14ae8</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[data-engineering]]></category>
            <dc:creator><![CDATA[Basavaraj Dharegonnavar]]></dc:creator>
            <pubDate>Tue, 25 Aug 2026 18:00:23 GMT</pubDate>
            <atom:updated>2026-08-25T18:00:23.759Z</atom:updated>
            <content:encoded><![CDATA[<p>SQL<br>│<br>├── DATABASE<br>│ ├── CREATE<br>│ ├── ALTER<br>│ └── DROP<br>│<br>├── TABLE<br>│ ├── CREATE<br>│ ├── ALTER<br>│ ├── TRUNCATE<br>│ └── DROP<br>│<br>├── DATA<br>│ ├── INSERT<br>│ ├── SELECT<br>│ ├── UPDATE<br>│ └── DELETE<br>│<br>├── FILTERING<br>│ ├── WHERE<br>│ ├── IN<br>│ ├── BETWEEN<br>│ ├── LIKE<br>│ └── IS NULL<br>│<br>├── AGGREGATION<br>│ ├── COUNT<br>│ ├── SUM<br>│ ├── AVG<br>│ ├── MIN<br>│ ├── MAX<br>│ ├── GROUP BY<br>│ └── HAVING<br>│<br>├── JOINS<br>│ ├── INNER<br>│ ├── LEFT<br>│ ├── RIGHT<br>│ ├── FULL<br>│ ├── CROSS<br>│ └── SELF<br>│<br>├── ADVANCED<br>│ ├── SUBQUERY<br>│ ├── CTE<br>│ ├── RECURSIVE CTE<br>│ ├── VIEW<br>│ ├── INDEX<br>│ ├── CASE<br>│ └── EXISTS<br>│<br>├── WINDOW FUNCTIONS<br>│ ├── ROW_NUMBER<br>│ ├── RANK<br>│ ├── DENSE_RANK<br>│ ├── LAG<br>│ ├── LEAD<br>│ └── SUM OVER<br>│<br>└── DATABASE DESIGN<br> ├── PRIMARY KEY<br> ├── FOREIGN KEY<br> ├── CONSTRAINTS<br> ├── NORMALIZATION<br> ├── TRANSACTIONS<br> └── ACID</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39fb68d14ae8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[1️⃣ SQL Questions]]></title>
            <link>https://towardsdev.com/1%EF%B8%8F%E2%83%A3-sql-questions-79fdc5368724?source=rss-d85c9e7d95c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/79fdc5368724</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[sql-server]]></category>
            <dc:creator><![CDATA[Basavaraj Dharegonnavar]]></dc:creator>
            <pubDate>Mon, 19 Jan 2026 14:58:24 GMT</pubDate>
            <atom:updated>2026-01-19T14:58:24.642Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XL1Fs00WqhrKpTIw" /><figcaption>Photo by <a href="https://unsplash.com/@sunder_2k25?utm_source=medium&amp;utm_medium=referral">Sunder Muthukumaran</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Q1. Find the second highest salary from an Employee table.<br>Table: Employee(emp_id, name, salary)<br>Answer (SQL):</h3><p>-- Using LIMIT (MySQL / Postgres)<br>SELECT salary <br>FROM Employee<br>ORDER BY salary DESC<br>OFFSET 1 LIMIT 1;</p><p>-- Using Dense_Rank<br>SELECT salary<br>FROM (<br> SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) as rnk<br> FROM Employee<br>) t<br>WHERE rnk = 2;</p><p>Key Tip: Know both window functions and subquery approaches.</p><p>Q2. How to find duplicate rows in a table?</p><p>SELECT col1, col2, COUNT(*) as cnt<br>FROM table_name<br>GROUP BY col1, col2<br>HAVING COUNT(*) &gt; 1;</p><p>2️⃣ Hive / Hadoop Questions</p><p>Q1 How to optimize Hive queries?</p><ul><li>Use partitioning &amp; bucketing</li><li>Avoid SELECT *</li><li>Use vectorized query execution</li><li>Use ORC/Parquet file formats</li><li>Enable Tez or Spark execution engine</li></ul><p>3️⃣ PySpark / Spark Questions</p><p>Q1. How to remove duplicate rows in PySpark?<br>Answer:</p><p>from pyspark.sql import SparkSession</p><p>spark = SparkSession.builder.appName(&quot;Duplicates&quot;).getOrCreate()<br>df = spark.read.csv(&quot;data.csv&quot;, header=True)</p><p># Remove duplicates<br>df_clean = df.dropDuplicates()</p><p>Q2. How to handle null values in Spark?</p><p>from pyspark.sql.functions import col</p><p># Replace nulls in a column<br>df_filled = df.na.fill({&#39;column_name&#39;: &#39;default_value&#39;})</p><p># Drop rows with nulls<br>df_dropped = df.na.drop()</p><p>Q3. Spark mergeSchema issue – AnalysisException fix</p><p># Read multiple Parquet files with different schemas<br>spark.read.option(&quot;mergeSchema&quot;, &quot;true&quot;).parquet(&quot;data/&quot;)<br># Fix: Ensure all columns exist and same data type, or cast explicitly</p><p>4️⃣ Scenario / Real-Time Questions</p><p>Q1. CSV null count is less than DB null count. Why?<br>Answer:<br>Empty strings &quot;&quot; in CSV converted to NULL in DB.<br>Whitespaces &quot; &quot; in CSV considered non-null.<br>Data type mismatch or missing columns.<br>ETL transformation logic may convert blanks to NULL.<br>Fix: Normalize CSV before loading (PySpark snippet):</p><p>from pyspark.sql.functions import col, when, trim</p><p>df_clean = df.select([when(trim(col(c)) == &quot;&quot;, None).otherwise(col(c)).alias(c) for c in df.columns])</p><p>Q2. Difference between Hive and Spark in processing?</p><p>Answer:<br>Hive: Batch processing, slower, uses MapReduce / Tez<br>Spark: In-memory, faster, supports batch + streaming<br>Hive good for large historical data, Spark good for real-time pipelines</p><p>Q3. How do you optimize a slow ETL job?<br>Answer:<br>Partition / bucket tables<br>Use columnar file formats (Parquet / ORC)<br>Cache intermediate data in Spark<br>Use vectorized operations / pushdown filters<br>Avoid shuffles where possible</p><p>Thanks for reading…!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79fdc5368724" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/1%EF%B8%8F%E2%83%A3-sql-questions-79fdc5368724">1️⃣ SQL Questions</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Optimizing PySpark with Adaptive Query Execution (AQE)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://towardsdev.com/optimizing-pyspark-with-adaptive-query-execution-aqe-2e3c0297e7e8?source=rss-d85c9e7d95c1------2"><img src="https://cdn-images-1.medium.com/max/633/1*UhSjJ_HvNl_gdU9QSy_elg.png" width="633"></a></p><p class="medium-feed-snippet">&#x1F4A1; What Is Adaptive Query Execution?</p><p class="medium-feed-link"><a href="https://towardsdev.com/optimizing-pyspark-with-adaptive-query-execution-aqe-2e3c0297e7e8?source=rss-d85c9e7d95c1------2">Continue reading on Towards Dev »</a></p></div>]]></description>
            <link>https://towardsdev.com/optimizing-pyspark-with-adaptive-query-execution-aqe-2e3c0297e7e8?source=rss-d85c9e7d95c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e3c0297e7e8</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[pyspark]]></category>
            <category><![CDATA[aqe]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[spark-optimization]]></category>
            <dc:creator><![CDATA[Basavaraj Dharegonnavar]]></dc:creator>
            <pubDate>Wed, 09 Jul 2025 16:51:01 GMT</pubDate>
            <atom:updated>2025-07-18T13:00:09.764Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[ 10 Must-Know PySpark Concepts for 2025]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">Big data keeps getting bigger, but PySpark stays one of the best tools to tackle it&#x200A;&#x2014;&#x200A;if you know how to use it right!jllllll
Here&#x2019;s a&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@basavarajd119/10-must-know-pyspark-concepts-for-2025-1aaf13c78213?source=rss-d85c9e7d95c1------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@basavarajd119/10-must-know-pyspark-concepts-for-2025-1aaf13c78213?source=rss-d85c9e7d95c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1aaf13c78213</guid>
            <dc:creator><![CDATA[Basavaraj Dharegonnavar]]></dc:creator>
            <pubDate>Sat, 05 Jul 2025 08:33:38 GMT</pubDate>
            <atom:updated>2025-07-11T19:30:09.475Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Important features introduced in Apache Spark 3.x.]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-link"><a href="https://towardsdev.com/important-features-introduced-in-apache-spark-3-x-ada0a74116c8?source=rss-d85c9e7d95c1------2">Continue reading on Towards Dev »</a></p></div>]]></description>
            <link>https://towardsdev.com/important-features-introduced-in-apache-spark-3-x-ada0a74116c8?source=rss-d85c9e7d95c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ada0a74116c8</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[hadoop]]></category>
            <category><![CDATA[pyspark]]></category>
            <dc:creator><![CDATA[Basavaraj Dharegonnavar]]></dc:creator>
            <pubDate>Sat, 28 Jun 2025 17:52:34 GMT</pubDate>
            <atom:updated>2025-07-18T12:34:54.622Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[ Essential PySpark Concepts Every Data Engineer Should Know]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-link"><a href="https://towardsdev.com/essential-pyspark-concepts-every-data-engineer-should-know-2a1fafeba4e9?source=rss-d85c9e7d95c1------2">Continue reading on Towards Dev »</a></p></div>]]></description>
            <link>https://towardsdev.com/essential-pyspark-concepts-every-data-engineer-should-know-2a1fafeba4e9?source=rss-d85c9e7d95c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a1fafeba4e9</guid>
            <dc:creator><![CDATA[Basavaraj Dharegonnavar]]></dc:creator>
            <pubDate>Sat, 28 Jun 2025 17:48:30 GMT</pubDate>
            <atom:updated>2025-07-18T12:32:47.130Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Hive Managed Table vs. External Table]]></title>
            <link>https://medium.com/@basavarajd119/hive-managed-table-vs-external-table-9470a82694bc?source=rss-d85c9e7d95c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/9470a82694bc</guid>
            <category><![CDATA[hive]]></category>
            <category><![CDATA[big-data]]></category>
            <dc:creator><![CDATA[Basavaraj Dharegonnavar]]></dc:creator>
            <pubDate>Wed, 05 Feb 2025 16:51:38 GMT</pubDate>
            <atom:updated>2025-02-05T16:51:38.729Z</atom:updated>
            <content:encoded><![CDATA[<p>Hive supports two types of tables: <strong>Managed (Internal) Tables</strong> and <strong>External Tables</strong>. The key difference between them is how Hive handles the table data.</p><h3>1. Managed (Internal) Table</h3><p>A <strong>managed table</strong> is fully controlled by Hive. When you create a managed table, Hive stores both the <strong>metadata</strong> (table structure) and <strong>data</strong> in its warehouse directory (default: /user/hive/warehouse/).</p><h3>Key Features:</h3><ul><li>Hive <strong>manages both the schema and the data</strong>.</li><li>By default, tables created in Hive are <strong>managed tables</strong>.</li><li>When you <strong>drop a managed table</strong>, both the <strong>table schema and data are deleted</strong>.</li><li>Data is stored under the Hive warehouse directory (hive.metastore.warehouse.dir).</li><li>Useful when Hive is the <strong>only system managing the data</strong>.</li></ul><h3>Syntax to Create a Managed Table:</h3><p>CREATE TABLE managed_table (<br> id INT,<br> name STRING<br>) STORED AS PARQUET;</p><p>Data will be stored in /user/hive/warehouse/managed_table/.</p><h3>Dropping a Managed Table:</h3><p>DROP TABLE managed_table;</p><ul><li>This <strong>removes both the table structure and its data</strong> from the filesystem.</li></ul><h3>2. External Table</h3><p>An <strong>external table</strong> allows Hive to store only the <strong>schema (metadata)</strong> while the actual data <strong>resides outside</strong> Hive’s warehouse directory (e.g., HDFS, S3, or other storage locations).</p><h3>Key Features:</h3><ul><li>Hive <strong>manages only the metadata</strong>, but the <strong>data remains at the specified location</strong>.</li><li>When you <strong>drop an external table, the table schema is deleted, but the data remains</strong>.</li><li>Useful when <strong>data is shared between multiple applications or is already managed externally</strong>.</li></ul><h3>Syntax to Create an External Table:</h3><p>CREATE EXTERNAL TABLE external_table (<br> id INT,<br> name STRING<br>) STORED AS PARQUET<br>LOCATION ‘/data/external_table/’;</p><p>The data is stored at /data/external_table/, <strong>outside the Hive warehouse</strong>.</p><h3>Dropping an External Table:</h3><p>DROP TABLE external_table;</p><ul><li><strong>Only removes the table metadata</strong>, but the actual data in /data/external_table/ remains.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*3vEB8_AoNQqhIYgfaxDmPQ.jpeg" /></figure><h3>When to Use Which?</h3><p><strong>Use a Managed Table</strong> when:</p><ul><li>Hive is the <strong>only system</strong> managing the data.</li><li>You want Hive to <strong>handle cleanup</strong> when the table is dropped.</li></ul><p><strong>Use an External Table</strong> when:</p><ul><li>You have <strong>pre-existing data</strong> stored outside Hive.</li><li>Multiple systems (Spark, Presto, etc.) need access to the same data.</li><li>You <strong>do not</strong> want Hive to delete the data when dropping the table.</li></ul><p>Enjoy Reading !!!!!!!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9470a82694bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Partitions and Bucketing in hive]]></title>
            <link>https://medium.com/@basavarajd119/partitions-and-bucketing-in-hive-1c8ea697b271?source=rss-d85c9e7d95c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c8ea697b271</guid>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[hive]]></category>
            <dc:creator><![CDATA[Basavaraj Dharegonnavar]]></dc:creator>
            <pubDate>Tue, 14 Jan 2025 17:01:01 GMT</pubDate>
            <atom:updated>2025-01-14T17:01:01.311Z</atom:updated>
            <content:encoded><![CDATA[<p>In Hive, partitions and bucketing are two important concepts used to organize large datasets in a way that improves query performance. Both help to divide the data into smaller chunks based on certain criteria, but they work in different ways.</p><h3>1. Partitions in Hive</h3><p>Partitioning in Hive is a way of dividing a table into smaller, more manageable pieces based on the values of one or more columns. Each partition corresponds to a specific value or set of values of the partitioning column(s).</p><h4>How Partitions Work:</h4><ul><li>Hive stores each partition in a separate directory in HDFS.</li><li>A partition is typically based on the value of a column, such as date, region, or product_category.</li><li>Partitioning helps reduce the amount of data that needs to be scanned for queries that filter on the partitioned column.</li></ul><h4>Example:</h4><p>Suppose you have a table with sales data, and you want to partition it by the year and month columns.</p><p>CREATE TABLE sales_data (<br> product_id INT,<br> amount DOUBLE,<br> customer_id INT<br>)<br>PARTITIONED BY (year INT, month INT);</p><p>In this case, the data would be organized into partitions based on year and month, so that when querying for a specific month or year, Hive only needs to scan the relevant partition.</p><h4>Partitioning Benefits:</h4><ul><li><strong>Improved query performance:</strong> Queries that filter on partition columns can skip non-relevant partitions.</li><li><strong>Efficient data management:</strong> You can add or remove partitions easily, without affecting the rest of the table.</li></ul><h4>Creating Partitions:</h4><p>You can add partitions to an existing table using the ALTER command:</p><p>ALTER TABLE sales_data ADD PARTITION (year=2025, month=01);</p><h3>2. Bucketing in Hive</h3><p>Bucketing divides data into a fixed number of equal-sized files or “buckets,” based on the hash value of a specific column. Bucketing is typically used when you want to distribute data evenly across a set number of files for better query performance in some scenarios (e.g., when joining large datasets).</p><h4>How Bucketing Works:</h4><ul><li>The data is distributed into a fixed number of buckets, defined by the CLUSTERED BY clause.</li><li>A hash function is applied to the bucketed column, and the result determines which bucket a record will go into.</li></ul><h4>Example:</h4><p>Suppose you have a table with user data and you want to bucket the table by user_id into 10 buckets:</p><p>CREATE TABLE users (<br> user_id INT,<br> user_name STRING,<br> email STRING<br>)<br>CLUSTERED BY (user_id) INTO 10 BUCKETS;</p><p>Here, Hive will distribute the rows into 10 buckets based on the hash value of user_id.</p><h4>Bucketing Benefits:</h4><ul><li><strong>Efficient joins:</strong> When two tables are bucketed by the same column, Hive can perform optimized joins without shuffling the data.</li><li><strong>Parallel processing:</strong> Buckets can be processed in parallel, which can speed up queries.</li></ul><h4>Bucketing vs. Partitioning:</h4><ul><li><strong>Partitioning</strong> is ideal for organizing data based on specific column values that you query frequently (e.g., year, month).</li><li><strong>Bucketing</strong> is better for evenly distributing data based on a column’s values, especially when performing joins on the bucketed column.</li></ul><h3>Combining Partitioning and Bucketing:</h3><p>You can use both partitioning and bucketing together. For example, you might partition a table by year and month and then bucket each partition by user_id.</p><p>CREATE TABLE sales_data (<br> product_id INT,<br> amount DOUBLE,<br> customer_id INT<br>)<br>PARTITIONED BY (year INT, month INT)<br>CLUSTERED BY (customer_id) INTO 10 BUCKETS;</p><p>This approach allows you to both partition the data for efficient filtering and bucket it for efficient joins.</p><h3>Conclusion:</h3><ul><li><strong>Partitioning</strong> helps to divide the data into separate directories for efficient filtering based on column values.</li><li><strong>Bucketing</strong> organizes the data into a set number of buckets to optimize joins and distribute the data evenly.</li></ul><p>Both techniques can significantly improve query performance by reducing the amount of data scanned and enabling more efficient data processing.</p><p>Enjoy Reading..!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c8ea697b271" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling corrupt data in pyspark]]></title>
            <link>https://towardsdev.com/handling-corrupt-data-in-pyspark-868f413ed45b?source=rss-d85c9e7d95c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/868f413ed45b</guid>
            <category><![CDATA[pyspark]]></category>
            <category><![CDATA[big-data]]></category>
            <dc:creator><![CDATA[Basavaraj Dharegonnavar]]></dc:creator>
            <pubDate>Sat, 26 Oct 2024 18:48:47 GMT</pubDate>
            <atom:updated>2024-10-28T15:35:44.904Z</atom:updated>
            <content:encoded><![CDATA[<p>Handling corrupt data in PySpark is crucial for reliable data processing, especially when working with large datasets. Here are some common methods to handle corrupt or malformed data:</p><p>1. Using badRecordsPath Option (for JSON and CSV files)</p><p>PySpark provides the badRecordsPath option, which can be used when reading data from files (like JSON or CSV) to capture corrupt records separately instead of failing the job.</p><p>Example:</p><pre>df = spark.read.option(&quot;badRecordsPath&quot;, &quot;/path/to/bad/records&quot;) \<br> .csv(&quot;/path/to/input/file.csv&quot;)</pre><p>Corrupt records will be saved to the specified path, allowing the rest of the data to be processed.</p><p>2. Using mode Option (like DROPMALFORMED or PERMISSIVE)</p><p>PySpark’s mode option can handle corrupted data based on the specified mode:</p><p>DROPMALFORMED: Discards rows that contain malformed data.</p><p>PERMISSIVE: Loads malformed rows and fills missing values with null.</p><p>FAILFAST: Throws an error if any corrupt record is found.</p><p>Example:</p><pre>df = spark.read.option(&quot;mode&quot;, &quot;DROPMALFORMED&quot;).json(&quot;/path/to/file.json&quot;)</pre><p>3. Using schema Option</p><p>Providing an explicit schema when reading data helps Spark detect records that don’t match the schema as corrupt.</p><p>Example:</p><p>from pyspark.sql.types import StructType, StructField, StringType, IntegerType</p><pre>schema = StructType([<br> StructField(&quot;name&quot;, StringType(), True),<br> StructField(&quot;age&quot;, IntegerType(), True)<br>])<br>df = spark.read.schema(schema).json(&quot;/path/to/file.json&quot;)</pre><p>4. Using filter and isNotNull() Functions</p><p>After loading the data, use filters and conditions to remove records with missing or corrupt values.</p><p>Example:</p><pre>df = df.filter(df[&quot;column_name&quot;].isNotNull())</pre><p>5. Using try-except within UDFs for Data Cleaning</p><p>If specific columns have corrupt data, use a UDF to handle errors. For example, when parsing strings to dates or converting data types.</p><p>Example:</p><pre>from pyspark.sql.functions import udf<br>from pyspark.sql.types import StringType</pre><pre>def safe_parse(value):<br> try:<br> # Perform parsing or transformation<br> return str(int(value))<br> except ValueError:<br> return None</pre><pre>parse_udf = udf(safe_parse, StringType())<br>df = df.withColumn(&quot;parsed_column&quot;, parse_udf(df[&quot;column_to_parse&quot;]))</pre><p>6. Logging and Alerting</p><p>Set up logging to capture information about corrupt records for further inspection.</p><p>For Spark applications, enable event logging or use a logging library to capture malformed data details during processing.</p><p>7. Using dropna() and fillna() for Null and NaN Values</p><p>Sometimes, corrupt data may present as null or NaN. Use dropna() to remove rows with nulls or fillna() to replace them.</p><p>Example:</p><pre>df = df.dropna(subset=[&quot;column_name&quot;])<br>df = df.fillna({&quot;column_name&quot;: 0})</pre><p>Example of Handling Corrupt Data Using Multiple Options</p><p>Here&#39;s a practical example combining several methods:</p><p>from pyspark.sql.types import StructType, StructField, StringType, IntegerType</p><pre>schema = StructType([<br> StructField(&quot;name&quot;, StringType(), True),<br> StructField(&quot;age&quot;, IntegerType(), True),<br> StructField(&quot;country&quot;, StringType(), True)<br>])</pre><pre>df = spark.read.option(&quot;mode&quot;, &quot;PERMISSIVE&quot;) \<br> .schema(schema) \<br> .json(&quot;/path/to/data.json&quot;)</pre><pre># Dropping rows where &#39;age&#39; is null (possible corrupt data)<br>df_cleaned = df.filter(df[&quot;age&quot;].isNotNull())</pre><p>These approaches help mitigate the impact of corrupt data in PySpark, allowing for more resilient data processing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=868f413ed45b" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/handling-corrupt-data-in-pyspark-868f413ed45b">Handling corrupt data in pyspark</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>