A data engineer wants to write a Spark job that creates a new managed table. If the table already exists, the job should fail and not modify anything.
Which save mode and method should be used?
Suggested Answer: A
Get Premium Databricks Certified Associate Developer for Apache Spark 3.5 Questions
as Interactive Web-Based Practice Test or PDF
Real Exam Format
Detailed Explanations
Instant Access
Get Your Practice Test
The method saveAsTable() creates a new table and optionally fails if the table exists.
From Spark documentation:
'The mode 'ErrorIfExists' (default) will throw an error if the table already exists.'
Thus:
Option A is correct.
Option B (Overwrite) would overwrite existing data --- not acceptable here.
Option C and D use save(), which doesn't create a managed table with metadata in the metastore.
Final Answer: A
17 comments · newest first
MI
Michael
21 days ago
Yeah, A is the way to go. No surprises!
PA
Pa
27 days ago
A is clear and straightforward. I support that.
EM
Emilio
1 month ago
D seems redundant. We need to create a table, not just save.
BR
Brandon
1 month ago
C is interesting too, but it won't create a table if it exists.
RE
Reiko
1 month ago
But we want to avoid changes if it exists. A is safer.
CH
Chau
2 months ago
I prefer B. Overwrite can be useful sometimes.
VE
Veta
2 months ago
Agreed, A makes sense. No accidental overwrites.
LA
Laquanda
2 months ago
I think A is the best choice. It fails if the table exists.
JA
Jackie
2 months ago
I thought mode Ignore was an option too, but it doesn't fit this case.
MA
Maile
2 months ago
B is definitely wrong, it would overwrite the table!
KE
Kenneth
2 months ago
Wait, can you really use save with mode ErrorIfExists?
GL
Glory
3 months ago
Totally agree, it prevents accidental overwrites.
EU
Eulah
3 months ago
A) saveAsTable with mode ErrorIfExists is the right choice!
LE
Levi
3 months ago
I feel like ErrorIfExists is definitely the way to go, but I’m a bit confused about the difference between save and saveAsTable in this context.
SA
Sabra
3 months ago
I recall that using mode Ignore would just skip the creation if the table exists, which isn't what we want here.
CA
Carey
3 months ago
I'm not entirely sure, but I remember a practice question where we used Overwrite, and it modified the table. That doesn't seem right for this case.
YU
Yuette
3 months ago
I think the answer might be A) saveAsTable with mode ErrorIfExists, since it specifically mentions failing if the table exists.