SnowPro Associate: Platform Question 316
Single answer● PARSE_DOCUMENT functionA data engineering team stores vendor contracts as PDF files in an internal stage. They want to use Snowflake SQL to extract the document content into a structured representation so analysts can later query fields from the output. The team wants a solution that reads the staged file directly during query execution without first copying the file into a table. Which approach best meets this requirement?
- A
Call PARSE_DOCUMENT with a scoped file URL for the staged PDF so Snowflake can parse the document and return a structured result.
- B
Use GET_PRESIGNED_URL on the stage and pass that URL to PARSE_JSON to convert the PDF into VARIANT.
- C
Load the PDF into a VARCHAR column with COPY INTO, then call TO_VARIANT on the column to extract the document structure.
- D
Use FLATTEN directly on the staged PDF file path because FLATTEN can parse semi-structured and document files stored in stages.
Show answer and explanation
Correct answer: A
Explanation
The key requirement is to parse a staged document file directly at query time, without first loading it into a table. PARSE_DOCUMENT is the Snowflake function intended for this document-parsing use case. In practice, Snowflake document-processing patterns commonly use stage-based file references, including scoped file URLs, to securely access staged files from SQL functions. The main misconceptions tested here are: confusing document parsing with JSON parsing (PARSE_JSON), assuming type conversion functions such as TO_VARIANT perform extraction, and assuming FLATTEN can parse files rather than only expand already parsed semi-structured values. For exam purposes, remember that PARSE_DOCUMENT is used to transform supported document files into a structured result, and downstream SQL functions can then be applied to that result.
- A. Correct.
Correct. PARSE_DOCUMENT is designed to parse supported document files and return a structured representation that can be processed in Snowflake. A common pattern is to reference the staged file through a scoped file URL so the function can access the file securely at query time without first loading it into a table.
- B. Incorrect.
Incorrect. PARSE_JSON only parses text containing valid JSON; it does not parse binary document formats such as PDFs. Although stage URLs are used with file access patterns, a presigned URL passed to PARSE_JSON would not convert a PDF into structured document output.
- C. Incorrect.
Incorrect. COPY INTO is used to load data into Snowflake tables, but simply loading a PDF into VARCHAR is not a valid or practical way to extract document structure. TO_VARIANT only wraps an existing SQL value as VARIANT; it does not perform document parsing or content extraction from a PDF.
- D. Incorrect.
Incorrect. FLATTEN works on ARRAY, OBJECT, or VARIANT values that already contain semi-structured data. It cannot parse a raw PDF file directly from a stage path. Someone might choose this option because FLATTEN is commonly used after parsing JSON, but it is not itself a document parser.