Skip to content

Snowpark Connect for Spark

Snowpark Connect provides a PySpark DataFrame API that executes natively on Snowflake. This is NOT Apache Spark - DataFrame operations are translated to Snowflake SQL, providing a familiar API without requiring a Spark cluster.

Features

  • PySpark Compatibility - Familiar DataFrame API for Spark developers
  • No Cluster Required - Executes on Snowflake’s native engine
  • Instant Startup - No cluster provisioning delay
  • Snowflake Optimization - Benefits from Snowflake’s query optimizer
  • Credit-Based Billing - Standard Snowflake warehouse credits

Important Limitations

Unlike Apache Spark, Snowpark Connect has some limitations:

FeatureSnowpark ConnectApache Spark
RDD APIsNot supportedFull support
DataFrame.hint()No-opOptimizer hints
DataFrame.repartition()No-opPartition control
UDFsSnowpark UDFs onlyPython/Scala UDFs
StreamingNot supportedStructured Streaming

Installation

Terminal window
uv add benchbox --extra cloud-spark-snowflake

This installs snowflake-snowpark-python and PySpark.

Prerequisites

  1. Snowflake account with active warehouse
  2. Credentials configured:
    • Username/password authentication
    • Key-pair authentication
    • OAuth (browser-based)

Configuration

Credentials

Pass credentials to SnowparkConnectAdapter in the Python API (see below). benchbox run has no way to supply them for this platform: account, user, and password are not --platform-option keys, and the adapter does not read SNOWFLAKE_* environment variables or the credentials saved by benchbox setup --platform snowflake.

CLI Usage

Without credentials, the CLI is limited to dry runs that preview the queries:

Terminal window
benchbox run --platform snowpark-connect --benchmark tpch --dry-run ./preview \
--platform-option compute_resource=BENCHMARK_WH

Platform Options

The Set with column shows how to set each option: a --platform-option key on benchbox run, or a SnowparkConnectAdapter argument in the Python API. In the Python API, the warehouse arguments are named warehouse and warehouse_size.

OptionSet withDefaultDescription
accountPython APIrequiredSnowflake account identifier
userPython APIrequiredSnowflake username
passwordPython API-Password (required unless using key auth)
compute_resource--platform-optionCOMPUTE_WHNamed compute resource (Snowflake warehouse; deprecated alias: warehouse, removed in 0.6.0)
databasePython APIBENCHBOXDatabase name
schemaPython APIPUBLICSchema name
rolePython API-Role to use for session
authenticatorPython API-Auth method (snowflake, externalbrowser, oauth)
private_key_pathPython API-Path to private key for key-pair auth
compute_size--platform-optionMEDIUMCompute size for scaling (deprecated alias: warehouse_size, removed in 0.6.0)

Python API

from benchbox.platforms.snowpark_connect import SnowparkConnectAdapter
adapter = SnowparkConnectAdapter(
account="xy12345.us-east-1",
user="my_user",
password="my_password",
warehouse="COMPUTE_WH",
database="BENCHBOX",
)
adapter.create_connection()
adapter.create_schema("tpch_benchmark")
result = adapter.execute_query("SELECT COUNT(*) FROM lineitem")
df = adapter.get_dataframe("lineitem")
result = adapter.execute_dataframe(df.filter(df["l_quantity"] > 30).limit(10))
adapter.close()

The example initializes the adapter with credentials, then creates the session (no Spark cluster is needed). It creates a schema and executes a SQL query. It then uses the DataFrame API and closes the session.

Execution Model

Snowpark Connect uses a fundamentally different execution model than Spark:

  1. Session Start - Create Snowpark session (instant, no cluster)
  2. DataFrame Operations - Build DataFrame expression tree
  3. Translation - Operations translated to Snowflake SQL
  4. Execution - SQL runs on Snowflake warehouse
  5. Results - Data returned directly

When to Use Snowpark Connect

Good fit:

  • Teams familiar with PySpark who use Snowflake
  • Existing Snowflake warehouse investments
  • DataFrame-based analytics without cluster management
  • Quick ad-hoc analysis with PySpark syntax

Consider alternatives:

  • Need RDD APIs → Apache Spark
  • Need Spark Streaming → Databricks/EMR
  • Need full Spark UDF support → Apache Spark
  • Need partition control → Apache Spark

Authentication

Password Authentication

adapter = SnowparkConnectAdapter(
account="xy12345.us-east-1",
user="my_user",
password="my_password",
)

Key-Pair Authentication

adapter = SnowparkConnectAdapter(
account="xy12345.us-east-1",
user="my_user",
private_key_path="/path/to/rsa_key.p8",
private_key_passphrase="optional_passphrase",
)

Browser-Based SSO

adapter = SnowparkConnectAdapter(
account="xy12345.us-east-1",
user="my_user",
authenticator="externalbrowser",
)

Cost Estimation

Snowpark Connect uses standard Snowflake credit consumption:

Warehouse SizeCredits/HourTypical $/Credit
X-Small1$2-4
Small2$2-4
Medium4$2-4
Large8$2-4
X-Large16$2-4
Scale FactorData SizeEst. RuntimeEst. Cost*
0.01~10 MB~5 min~$0.05
1.0~1 GB~30 min~$0.50
10.0~10 GB~2 hours~$4.00
100.0~100 GB~6 hours~$20.00

*Estimates based on Medium warehouse. Actual costs vary by contract.

Comparison with Other Platforms

AspectSnowpark ConnectSnowflake SQLDatabricks Spark
APIPySpark DataFrameSQLPySpark/SQL
ClusterNone (Snowflake)None (Snowflake)Spark cluster
RDD SupportNoN/AYes
StartupInstantInstantMinutes
BillingCreditsCreditsDBU + compute
Use CaseDataFrame + SnowflakeSQL + SnowflakeFull Spark

Troubleshooting

Common Issues

Account identifier format:

  • Format: xy12345.region or xy12345.region.cloud
  • Example: xy12345.us-east-1 or xy12345.us-east-1.aws
  • Don’t include .snowflakecomputing.com

Warehouse not found:

  • Verify warehouse exists: SHOW WAREHOUSES;
  • Check permissions on warehouse
  • Warehouse may be suspended (auto-resumes on first query)

Authentication errors:

  • Verify account identifier is correct
  • Check username and password
  • For key-pair: ensure private key format is correct (PKCS#8)

Permission denied:

  • Check role has necessary privileges
  • Verify database and schema access
  • Check warehouse usage permission