Snowpro Advanced Architect · Free Practice Question Hard

Question 7

A data platform team wants to standardize a complex calculation that involves multiple steps and intermediate results, which are then combined into a final scalar value. This calculation will be used repeatedly in SELECT statements across various reports. Which of the following is the most efficient and reusable way to encapsulate this logic in Snowflake?
  • A Use a Stored Procedure to perform the calculation and return the result.
  • B Create a Scalar User-Defined Function (UDF).
  • C Create a standard view with the calculation.
  • D Define it as a Dynamic Table.
  • E Implement it as a Python UDTF.
Reveal correct answer

Correct answer: B

Explanation

✅ Create a Scalar User-Defined Function (UDF).

Explanation:

A Scalar User-Defined Function (UDF) is the most efficient and reusable way to encapsulate complex calculations that involve multiple steps and intermediate results, while ensuring consistent execution across various reports.

  • Encapsulates logic in a reusable function → Can be called in SELECT statements without repeating complex calculations.

  • Optimized for performance → Executes within Snowflake’s engine, leveraging pushdown optimizations.

  • Supports multiple programming languages → Can be implemented in SQL, JavaScript, Python, or Java, depending on complexity.


❌ Why the other options are incorrect?

Create a standard view with the calculation.
→ Incorrect, because views do not encapsulate logic efficiently for repeated execution; they simply store query definitions.

Use a Stored Procedure to perform the calculation and return the result.
→ Incorrect, because Stored Procedures are designed for procedural execution, not inline calculations within SELECT statements.

Implement it as a Python UDTF.
→ Incorrect, because UDTFs return table-like results, whereas a scalar UDF returns a single value.

Define it as a Dynamic Table.
→ Incorrect, because Dynamic Tables are used for continuous transformations, not reusable scalar calculations.


For more details, check the official Snowflake documentation on UDFs.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need