
Answer-first summary for fast verification
Answer: preds.write.mode("append").saveAsTable("churn_preds")
The requirement is to save predictions to a Delta Lake table with historical tracking and minimal compute costs. Option A uses `saveAsTable` with append mode, which creates/updates a managed Delta Lake table in the metastore. This ensures each day's predictions are added without overwriting previous data, enabling historical comparisons. Option B writes to a path in Delta format but does not register the table in the metastore, making it less accessible for querying via SQL. Since the question specifies a Delta Lake *table*, Option A is correct as it handles both storage and metadata registration efficiently.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
The data science team has created and logged a production model using MLflow. The following code correctly imports and applies the production model to output the predictions as a new DataFrame named preds with the schema "customer_id LONG, predictions DOUBLE, date DATE".
from pyspark.sql.functions import current_date
model = mlflow.pyfunc.spark_udf(spark, model_uri="models:/churn/prod")
df = spark.table("customers")
columns = ["account_age", "time_since_last_seen", "app_rating"]
preds = (df.select(
"customer_id",
model(*columns).alias("predictions"),
current_date().alias("date")))
from pyspark.sql.functions import current_date
model = mlflow.pyfunc.spark_udf(spark, model_uri="models:/churn/prod")
df = spark.table("customers")
columns = ["account_age", "time_since_last_seen", "app_rating"]
preds = (df.select(
"customer_id",
model(*columns).alias("predictions"),
current_date().alias("date")))
The data science team would like predictions saved to a Delta Lake table with the ability to compare all predictions across time. Churn predictions will be made at most once per day.
Which code block accomplishes this task while minimizing potential compute costs?
A
preds.write.mode("append").saveAsTable("churn_preds")
B
preds.write.format("delta").save("/preds/churn_preds")
No comments yet.