Skip to content

Working with unstructured files through directory tables and Cortex

Snowflake handles unstructured data (images, PDFs, logs, audio, etc.) by storing files in internal or external stages and referencing them via scoped, unscoped, or directory-table file URLs without moving the underlying bytes into table storage. Access and processing rely on FILE data type columns, directory tables, and Snowflake functions/UDFs (including Java/Python) that can read file bytes for parsing, tagging, or feeding into downstream ML/document AI pipelines.

1 · Learn the must-know

  • Directory tables (enabled via DIRECTORY = (ENABLE = TRUE) on a stage) provide a queryable file-level metadata catalog (relative path, size, last modified, file URL) but do not store file content itself.
  • File URLs come in three types: scoped URLs (temporary, encoded, tied to a session/user, expire after use or 24 hours), file URLs (permanent, require stage privileges), and pre-signed URLs (temporary, no login required, generated via GET_PRESIGNED_URL)—choose based on sharing/security needs.
  • The FILE data type (a Snowflake-native semi-structured type) lets you store file references in table columns and pass them to functions/UDFs for content processing without duplicating storage.
  • Built-in functions like BUILD_SCOPED_FILE_URL, BUILD_STAGE_FILE_URL, and GET_PRESIGNED_URL generate the appropriate URL type; directory tables must be refreshed (manually or via auto-refresh for cloud storage) to reflect newly added/removed files.
  • Java and Python UDFs/UDTFs can accept a FILE type argument and use the SnowflakeFile class (or similar) to stream file contents for custom parsing logic (e.g., extracting text from PDFs or metadata from images).
  • Unstructured data processing typically integrates with Snowpark (for programmatic file handling in Python/Java/Scala) and can feed into Snowflake Cortex functions for document AI, OCR-like extraction, or LLM-based analysis of file contents.

3 · Keep going