By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Data transformation is the backbone of any ML pipeline—cleaning, enriching, and structuring raw data into features ready for training or inference. In GCP, this means choosing between Cloud Dataprep (no-code ETL), Dataflow (serverless stream/batch processing), and Spark on Dataproc (managed big data clusters) to handle everything from real-time fraud detection (streaming) to large-scale feature engineering for recommendation systems (batch). For example, a retail company might use Dataflow to process clickstream data in real time, Dataproc to join historical purchase records with user profiles, and Dataprep to clean and normalize the final dataset before training a demand-forecasting model.
groupBy
join
Goal: Process streaming transactions, enrich with user profiles, and generate features for a fraud model.
user_id
amount
timestamp
Configure a Dataflow streaming job (Apache Beam) to read from Pub/Sub: python pipeline_options = PipelineOptions(streaming=True) with beam.Pipeline(options=pipeline_options) as p: transactions = (p | "Read from PubSub" >> beam.io.ReadFromPubSub(topic="projects/my-project/topics/transactions") | "Parse JSON" >> beam.Map(lambda x: json.loads(x)) )
python pipeline_options = PipelineOptions(streaming=True) with beam.Pipeline(options=pipeline_options) as p: transactions = (p | "Read from PubSub" >> beam.io.ReadFromPubSub(topic="projects/my-project/topics/transactions") | "Parse JSON" >> beam.Map(lambda x: json.loads(x)) )
Enrich with Batch Data
Join streaming transactions with BigQuery (user profiles, historical fraud rates) using beam.io.ReadFromBigQuery: python user_profiles = (p | "Read User Profiles" >> beam.io.ReadFromBigQuery( query="SELECT user_id, risk_score FROM `my-project.users.profiles`", use_standard_sql=True) ) enriched = ({'transactions': transactions, 'profiles': user_profiles} | "Join" >> beam.CoGroupByKey() )
beam.io.ReadFromBigQuery
python user_profiles = (p | "Read User Profiles" >> beam.io.ReadFromBigQuery( query="SELECT user_id, risk_score FROM `my-project.users.profiles`", use_standard_sql=True) ) enriched = ({'transactions': transactions, 'profiles': user_profiles} | "Join" >> beam.CoGroupByKey() )
Transform and Window Data
python windowed = (enriched | "Window" >> beam.WindowInto(beam.window.FixedWindows(60)) | "Aggregate" >> beam.CombinePerKey(CombineFn()) )
Use TensorFlow Transform (TFT) for scaling/normalization if preparing data for a TF model: python | "TFT Preprocess" >> beam.ParDo(PreprocessFn())
python | "TFT Preprocess" >> beam.ParDo(PreprocessFn())
Write to Feature Store or BigQuery
python | "Write to Feature Store" >> beam.io.WriteToFeatureStore( project="my-project", location="us-central1", feature_group="fraud_features" )
For batch training, write to BigQuery or Cloud Storage (Parquet/CSV).
Deploy and Monitor
beam.Map(lambda x: x)
When to use TFT: Only if you’re using TensorFlow and need consistent preprocessing between training and serving. For PyTorch or scikit-learn, use Dataflow/Spark.
Key Constraints
BigQuery ML: Can train simple models (linear regression, k-means) inside BigQuery, but for deep learning, export data to Vertex AI.
Tricky Scenarios
beam.WindowInto(..., allowed_lateness=Duration(minutes=5))
Why: Dataproc isn’t designed for streaming, and Dataprep is for interactive use.
A data scientist wants to preprocess a 500GB dataset for a TensorFlow model. The preprocessing includes normalizing numerical features and one-hot encoding categoricals. Which GCP service should they use to ensure the same transforms are applied during inference?
Why: TFT ensures preprocessing logic is consistent between training and serving.
A team is running a PySpark job on Dataproc to join two large tables (1TB and 500GB). The job is slow and fails due to memory errors. What’s the most likely cause, and how can they fix it?
spark.executor.memory
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.