<?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 Bhargavi Katta on Medium]]></title>
        <description><![CDATA[Stories by Bhargavi Katta on Medium]]></description>
        <link>https://medium.com/@bhargavi.katta97?source=rss-2d8e588f7067------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*SE7ytF4gvdm5dg7s</url>
            <title>Stories by Bhargavi Katta on Medium</title>
            <link>https://medium.com/@bhargavi.katta97?source=rss-2d8e588f7067------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 14:37:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bhargavi.katta97/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[Repartition() vs Coalesce() in PySpark]]></title>
            <link>https://medium.com/@bhargavi.katta97/repartition-vs-coalesce-in-pyspark-ec821807e82d?source=rss-2d8e588f7067------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec821807e82d</guid>
            <dc:creator><![CDATA[Bhargavi Katta]]></dc:creator>
            <pubDate>Tue, 29 Apr 2025 18:29:44 GMT</pubDate>
            <atom:updated>2025-04-29T18:29:44.188Z</atom:updated>
            <content:encoded><![CDATA[<p>When working with big data in PySpark, how your data is <strong>partitioned</strong> matters — a lot. Poor partitioning can slow down jobs, overload executors, or waste resources. Two common operations used to tune partitioning are <strong>repartition()</strong> and <strong>coalesce()</strong>, but they serve different purposes.</p><h3>What is Partitioning in PySpark?</h3><p>In Spark, data is split into <strong>partitions</strong> and distributed across worker nodes. These partitions form the basis of parallelism.</p><ul><li>More partitions = more parallelism (to a point)</li><li>Fewer partitions = less overhead, but possible skew and bottlenecks</li></ul><h3>repartition(numPartitions)</h3><h3>✅ What it does:</h3><ul><li><strong>Increases or decreases</strong> the number of partitions.</li><li><strong>Shuffles data</strong> across the cluster (expensive).</li><li>Creates <strong>even-sized partitions</strong> by default.</li></ul><h3>✅ When to use:</h3><ul><li>When you <strong>increase</strong> the number of partitions (e.g., before a wide transformation).</li><li>When existing partitions are <strong>imbalanced or skewed</strong>.</li><li>Before writing large datasets in <strong>parallel</strong>.</li></ul><h3>✅ Pros:</h3><ul><li>Avoids data skew.</li><li>Improves performance for parallel processing.</li></ul><h3>⚠️ Cons:</h3><ul><li><strong>Triggers a full shuffle</strong> (expensive).</li><li>Increases execution time and resource usage.</li></ul><h3>coalesce(numPartitions)</h3><h3>✅ What it does:</h3><ul><li><strong>Reduces</strong> the number of partitions.</li><li><strong>Avoids shuffle</strong> by combining adjacent partitions.</li></ul><h3>✅ When to use:</h3><ul><li>When you’re <strong>writing a small dataset</strong> (e.g., CSV or JSON).</li><li>When you want to <strong>optimize output files</strong> (e.g., combine many tiny files).</li><li>When you’re certain that <strong>no shuffling is required</strong>.</li></ul><h3>✅ Pros:</h3><ul><li><strong>Much faster</strong> than repartition because no shuffle.</li><li>Saves <strong>I/O and storage</strong> costs (fewer files).</li></ul><h3>⚠️ Cons:</h3><ul><li>Can create <strong>uneven partition sizes</strong> (some may be too big).</li><li>May cause <strong>skew</strong> if used blindly.</li></ul><h3>When Should a Data Engineer Use Each?</h3><p><strong>Scenario | Use</strong><br>Increasing partitions before a join/aggregation | <strong>repartition()</strong><br>Reducing partitions before saving to storage | <strong>coalesce()</strong><br>Outputting to a single file | <strong>coalesce(1)</strong><br>Balancing uneven partitions | <strong>repartition()</strong><br>Reducing many small output files to fewer files | <strong>coalesce()</strong></p><h3>sample code:</h3><p>from pyspark.sql import SparkSession</p><p># Step 1: Start Spark Session<br>spark = SparkSession.builder \<br> .appName(“Repartition_vs_Coalesce_Example”) \<br> .getOrCreate()</p><p># Step 2: Read data (example CSV file)<br>df = spark.read.option(“header”, True).csv(“/path/to/your/input.csv”)</p><p># Step 3: Check original number of partitions<br>print(“Original partitions:”, df.rdd.getNumPartitions())</p><p># Step 4: Repartition (increase partitions)<br>df_repartitioned = df.repartition(100) # Change to 100 partitions<br>print(“Partitions after repartition:”, df_repartitioned.rdd.getNumPartitions())</p><p># Example: repartition based on a column (if needed)<br># df_repartitioned = df.repartition(‘customer_id’)</p><p># Step 5: Perform some transformations (optional)<br># Example: select few columns<br>df_transformed = df_repartitioned.select(“column1”, “column2”)</p><p># Step 6: Coalesce (reduce partitions before writing)<br>df_coalesced = df_transformed.coalesce(10) # Reduce to 10 partitions<br>print(“Partitions after coalesce:”, df_coalesced.rdd.getNumPartitions())</p><p># Step 7: Write final output<br>df_coalesced.write.mode(‘overwrite’).parquet(“/path/to/your/output_folder/”)</p><p># Step 8: Stop Spark session<br>spark.stop()</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec821807e82d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google recently made an announcement regarding its machine unlearning challenge, aimed at…]]></title>
            <link>https://medium.com/@bhargavi.katta97/google-recently-made-an-announcement-regarding-its-machine-unlearning-challenge-aimed-at-8fc634770ac9?source=rss-2d8e588f7067------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fc634770ac9</guid>
            <dc:creator><![CDATA[Bhargavi Katta]]></dc:creator>
            <pubDate>Tue, 25 Jul 2023 21:05:08 GMT</pubDate>
            <atom:updated>2023-07-25T21:05:08.156Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong><em>Exciting Development in Privacy Protection: Google’s Machine Unlearning Challenge</em></strong></blockquote><p>Google recently made an announcement regarding its machine unlearning challenge, aimed at addressing a critical privacy concern. The challenge centers around a realistic scenario where a certain subset of training images needs to be forgotten after the initial model training. This is to safeguard the privacy and rights of individuals associated with the data.</p><p>When a user deletes their account on Google, data from databases can be easily deleted. However, the challenge arises when it comes to erasing user information from all machine learning (ML) models that were trained using this data.</p><p>Fully erasing the influence of the data in question is no simple task. Mere deletion from the databases is insufficient, as it necessitates eliminating any traces of that data’s impact on other artifacts, including the trained ML models.</p><p>Retraining the model by excluding the affected customers’ data may seem like an option, but this approach is impractical due to the computational expenses involved. Creating a new model every time a group of users deletes their accounts is simply not feasible.</p><p>Also, how to determine if the unlearning process has been successful? One way is to measure the accuracy of the “forgot set,” which comprises the data to be cleansed. The objective is to ensure that the model performs poorly on this specific data, indicating successful removal of its influence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*Lhbl_-rGNn_Y3i1fHTVk-w.png" /></figure><p>In a nutshell, the unlearning challenge introduces a fresh perspective. The focus is on making efficient adjustments to eliminate the influence of the requested data, ensuring enhanced privacy protection in machine learning environments.</p><p>This development marks a significant step towards reinforcing privacy rights while advancing the domain of machine learning. Google’s initiative serves as an inspiration to the industry, encouraging innovative approaches for responsible and privacy-conscious AI practices.</p><p>Source: <a href="https://ai.googleblog.com/2023/06/announcing-first-machine-unlearning.html">https://ai.googleblog.com/2023/06/announcing-first-machine-unlearning.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fc634770ac9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>