Reviewed by Aditya Kumar · Last reviewed 2026-03-24
Two distinct operations: (1) **Drop columns that are entirely null** (no non-null values): null_cols = [c for c in df.columns if df.filter(col(c).isNotNull()).count() == 0]; df = df.drop(*null_cols). **Caveat**: count() triggers a full scan—expensive on large tables. (2) **Drop...
This medium-level Spark/Big Data question appears frequently in data engineering interviews at companies like Datametica, Globant. While less common, it tests deeper understanding that distinguishes strong candidates. Mastering the underlying concepts (partition, spark) will help you answer variations of this question confidently.
Break this problem into components. Identify the core trade-offs involved, then walk the interviewer through your reasoning step by step. Demonstrate awareness of edge cases and production considerations - this is what separates good answers from great ones.
Two distinct operations: (1) Drop columns that are entirely null (no non-null values): null_cols = [c for c in df.columns if df.filter(col(c).isNotNull()).count() == 0]; df = df.drop(*null_cols). Caveat: count() triggers a full scan—expensive on large tables. (2) Drop rows with null in specified columns: df.dropna(subset=["col1", "col2"]). Scalability: The column-null check is O(partitions × columns) and can be costly; consider sampling or inferring from schema/sample. Production logic: Log dropped columns for audit; use schema evolution if columns appear conditionally (e.g., A/B test variants). Why not drop all null columns blindly: Some columns are legitimately sparse (e.g., optional fields); dropping removes signal. Best practice: Define critical vs. optional columns in config; drop only optional all-null columns; validate with data quality checks.
Red Flag: Running count() per column on a 1TB table to find null columns—that's 100+ full scans. Pro-Move: 'We use a sampled DataFrame (limit 100K) for null-column detection, or rely on Delta/Parquet stats when available, to avoid full scans.'
Some links below are affiliate links. If you buy through them we may earn a small commission at no extra cost to you — it helps keep DataEngPrep free.
According to DataEngPrep.tech, this is one of the most frequently asked Spark/Big Data interview questions, reported at 2 companies. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.