Snowflake Provider Integration with Airflow
Architecture Diagram
Formal Definitions
Detailed Explanation
Snowflake Integration Overview
The Snowflake provider enables Airflow to execute SQL, load data, and manage Snowflake resources. It supports COPY INTO operations, Snowpipe management, and data transfer between Snowflake and cloud storage.
Key Insight: Snowpipe auto-ingestion reduces Airflow's role to trigger and monitor. Let Snowflake handle continuous loading for better efficiency.
Operator Selection Guide
| Operator | Use Case | Key Parameters |
|---|---|---|
| SnowflakeOperator | Execute SQL | sql, snowflake_conn_id |
| SnowflakeToGCSOperator | Export to GCS | gcs_bucket, sql |
| GCSToSnowflakeOperator | Load from GCS | bucket, prefix, table |
| SnowflakeCopyFromExternalStage | COPY INTO | table, stage, file_format |
| SnowflakeSensor | Wait for condition | sql, poke_interval |
COPY INTO Options
| Option | Description | Common Values |
|---|---|---|
| FILE_FORMAT | File type specification | TYPE = 'PARQUET', TYPE = 'CSV' |
| PATTERN | Regex for file matching | PATTERN = '.*\\.parquet' |
| ON_ERROR | Error handling strategy | SKIP_FILE, CONTINUE, ABORT_STATEMENT |
| FORCE | Reload existing files | FORCE = TRUE |
| PURGE | Delete files after load | PURGE = TRUE |
Connection Setup
Basic SQL Execution
GCS to Snowflake Loading
Pre/Post Operator Pattern
Multi-Warehouse Pattern
Key Concepts Table
| Operator | Purpose | Key Parameters |
|---|---|---|
| SnowflakeOperator | Execute SQL | sql, snowflake_conn_id |
| SnowflakeToGCSOperator | Export to GCS | snowflake_conn_id, gcs_bucket, sql |
| GCSToSnowflakeOperator | Load from GCS | bucket, prefix, table, stage |
| SnowflakeCopyFromExternalStage | COPY INTO | table, stage, file_format |
| SnowflakePrePostOperator | Pre/post hooks | sql, pre_query, post_query |
| SnowflakeSensor | Wait for condition | sql, poke_interval |
COPY INTO Options
| Option | Description | Example |
|---|---|---|
| FILE_FORMAT | File type specification | TYPE = 'PARQUET' |
| PATTERN | Regex for file matching | PATTERN = '.*\\.parquet' |
| ON_ERROR | Error handling strategy | SKIP_FILE, CONTINUE, ABORT_STATEMENT |
| FORCE | Reload existing files | FORCE = TRUE |
| SIZE_LIMIT | Max bytes per load | SIZE_LIMIT = 1073741824 |
| PURGE | Delete files after load | PURGE = TRUE |
| RETURN_FAILED_ONLY | Return only failed files | RETURN_FAILED_ONLY = TRUE |
Best Practices
Data Loading
- Use named stages for reusable external connections â avoid embedded credentials.
- Set
ON_ERRORappropriately:SKIP_FILEfor bad files,CONTINUEfor partial loads. - Partition large COPY INTO operations with
SIZE_LIMITto avoid single large transactions. - Use
PURGE = TRUEto clean up files after successful load.
Monitoring and Cost
- Set
QUERY_TAGfor monitoring and cost attribution per Airflow DAG. - Monitor Snowpipe status with
SHOW PIPESandSYSTEM$PIPE_STATUS.
Security and Performance
- Use key-pair authentication for production â avoid password-based connections.
- Leverage clustering keys for frequently joined/filtered columns.
Cost Optimization
| Strategy | Savings | Implementation |
|---|---|---|
| Suspend idle warehouses | 60-80% | ALTER WAREHOUSE ... SUSPEND |
| Use scaling policy | 30-50% | Set AUTO_SUSPEND and AUTO_RESUME |
| Query tagging | Attribution | SET QUERY_TAG = 'airflow_etl' |
| Clustering keys | 2-10x | CLUSTER BY (column) |
See Also
- BigQuery Provider â Google BigQuery integration patterns
- Databricks Provider â Databricks cluster and job management
- Operators and Hooks â Operator lifecycle and hook architecture
- XCom Communications â Task communication and data passing