Reviewed by Aditya Kumar · Last reviewed 2026-08-08
To filter out records with null values in user id , the most direct approach in SQL is using the WHERE user id IS NOT NULL clause. In PySpark, you would use df.filter(col('user id').isNotNull()) or…
This easy-level SQL question appears frequently in data engineering interviews at companies like Meesho. While less common, it tests deeper understanding that distinguishes strong candidates. Mastering the underlying concepts (spark, sql) will help you answer variations of this question confidently.
Start by clearly defining the core concept being asked about. Interviewers want to see that you understand the fundamentals before diving into implementation details. Structure your answer with a definition, then explain the practical application with a concise example. The expert answer includes a code example that demonstrates the implementation pattern.
To filter out records with null values in user_id, the most direct approach in SQL is using the WHERE user_id IS NOT NULL clause. In PySpark, you would use df.filter(col('user_id').isNotNull()) or the more general df.na.drop(subset=['user_id']).
Null values represent missing, unknown, or inapplicable data. Filtering them out ensures data integrity for operations that strictly require a valid user_id, such as joins, aggregations, or user-specific analytics. In SQL, IS NOT NULL is the standard and most performant way to check for the absence of a null value. PySpark's isNotNull() provides explicit column-level filtering, while na.drop() is a convenience method that can drop rows based on nulls in a specified subset of columns, offering a concise way to handle multiple columns.
SELECT
user_id,
event_timestamp,
event_type
FROM
your_events_table
WHERE
user_id IS NOT NULL;
Dropping records is a destructive operation, so it's crucial to implement robust data quality practices. Always log the count of records dropped and the total count processed. This provides an audit trail and helps monitor data quality trends over time, which can be stored in a metadata catalog or data quality dashboard. Validate the business impact by comparing key metrics or downstream reports before and after the filter to ensure the removal doesn't skew results or break dependencies. Consider quarantining the dropped records into a separate table or file (e.g., in a data lake, perhaps using Delta Lake for ACID properties) for further analysis. This allows you to investigate the root cause of the nulls and differentiate between truly invalid data and potentially recoverable data.
For long-term prevention, assert a NOT NULL constraint on the user_id column in your downstream schema definitions. This could be in your data warehouse DDL (e.g., CREATE TABLE ... user_id VARCHAR NOT NULL), or enforced through data transformation tools like dbt models, which can include schema tests. This proactive measure enforces data quality at the point of ingestion or transformation, preventing invalid records from entering the system in the first place.
In the interview, also mention the importance of logging, validating business impact, and implementing schema-level constraints to prevent recurrence.
Red Flag: Dropping without measuring—might lose 30% of data. Pro-Move: 'We log dropped count; alert if >5%—caught a bug where mobile app sent null for 2 hours.'
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 SQL interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.