Posts

Master Jobs, Stages, and Tasks for Data Engineering Interviews

Image
Mastering Spark execution internals is a "must-have" skill for Data Engineers. Whether you are prepping for an interview or debugging a slow production pipeline, understanding how Spark breaks down your code is the key to performance tuning. Spark applications follow a strict hierarchy: Jobs > Stages > Tasks . Let’s break down exactly how this works. 1. High-Level Architecture Before we dive into the code, let’s look at the components that manage the execution: Driver: The brain. It converts your code into a Directed Acyclic Graph (DAG) and schedules tasks. DAG Scheduler: Splits the graph into Stages based on "shuffles." Task Scheduler: Sends the individual Tasks to the executors. Executors: The workers that actually run the tasks in parallel. 2. Real-World Code Walkthrough: The "Wide" Transformation Let’s analyze a common scenario: reading data, filtering, grouping, and saving. # 1. Read Data (Narrow) df = sp...

Optimizing SQL queries

Image
  🚀 Optimizing SQL queries is crucial for improving database performance and ensuring efficient use of resources. 👉 Few SQL query optimization techniques are as below: ✅ Index Optimization ➡️ Ensure indexes are created on columns that are frequently used in 'WHERE' clauses, 'JOIN' conditions and as part of 'ORDER BY' clauses. ➡️Use composite indexes for columns that are frequently queried together. ➡️Regularly analyze and rebuild fragmented indexes. ✅ Query Refactoring ➡️ Break complex queries into simpler subqueries or use common table expressions (CTEs). ➡️ Avoid unnecessary columns in the 'SELECT' clause to reduce the data processed. ✅ Join Optimization ➡️ Use the appropriate type of join (INNER JOIN, LEFT JOIN, etc.) based on the requirements. ➡️ Ensure join columns are indexed to speed up the join operation. ➡️ Consider the join order, starting with the smallest table. ✅ Use of Proper Data Types ➡️ Choose the most efficient data type for your col...
                                                         Data Modelling - Star vs Snowflake Schema!! Today, we'll dive into data modeling concepts, specifically focusing on star and snowflake schemas.   In a star schema , we have a central fact table surrounded by dimension tables. The fact table contains quantitative data, usually numerical metrics or measures, while the dimension tables contain descriptive attributes that provide context to the measures. The fact table is connected to the dimension tables through foreign key relationships, forming a star-like shape. In a snowflake schema , the dimension tables are normalized, meaning that they are further broken down into multiple related tables. This results in a more complex network of relationships, resembling the branches of a snowflake. While this norma...

Data Cleaning in SQL

                                                                              1. Import Data: First, import the Excel data into a SQL database table using a tool like SQL Server Management Studio.  2. Identify Missing Values: Use SQL queries to identify any missing or null values in the dataset. This helps in understanding the extent of missing data and planning for imputation or removal. 3. Remove Duplicates: Utilize SQL's 'DISTINCT' keyword or 'GROUP BY' clause to identify and remove duplicate rows from the dataset. This ensures that each observation is unique. 4. Standardize Data Formats: Use SQL functions like UPPER, LOWER, TRIM, etc., to standardize text formats and remove leading or trailing spaces. This ensures consistency in the data. 5. C...

File Format in PySpark

When working with PySpark, understanding different file formats for data ingestion is key to efficient data processing. Here are some common file formats supported by PySpark: 1️⃣ CSV (Comma-Separated Values): CSV files are widely used for tabular data. PySpark provides easy-to-use methods for reading and writing CSV files, making it simple to work with structured data. 2️⃣ Parquet: Parquet is a columnar storage format that is highly efficient for analytics workloads. PySpark's native support for Parquet enables fast reading and writing of large datasets, making it ideal for big data applications. 3️⃣ JSON (JavaScript Object Notation): JSON is a popular format for semi-structured data. PySpark can easily handle JSON files, making it convenient for working with data that may have varying schema. 4️⃣ Avro: Avro is a binary serialization format that provides rich data structures and schema evolution capabilities. PySpark supports Avro files, allowing for efficient data exchange be...

RDD vs DATAFRAME vs DATASET

Image
  Spark - RDD, Dataframe and Dataset!! Let's start with RDDs (Resilient Distributed Datasets).  Q  Explain what an RDD is and its role in distributed computing? RDD : An RDD is a fundamental data structure in Apache Spark, designed to handle large-scale data processing across clusters. It represents an immutable, partitioned collection of records that can be operated on in parallel. RDDs provide fault tolerance through lineage information, enabling recomputation of lost data partitions. Q  How does Spark's RDD differ from traditional data structures like arrays or lists?  Unlike arrays or lists, RDDs are distributed across multiple nodes in a cluster, allowing for parallel processing and fault tolerance. RDDs are immutable, meaning their contents cannot be changed once created. Operations on RDDs are lazily evaluated, allowing Spark to optimize execution plans and perform transformations efficiently. Q  Moving on to dataframes in Spark. What is a dataf...