PySpark with Snowflake, Databricks, and Hive Integration
Connecting PySpark to the Modern Data Ecosystem
At DataVerse Labs, different teams use different data stores:
- Analytics team โ Snowflake
- Machine learning team โ Databricks
- Data warehouse team โ Hive
PySpark acts as the unifying engine across these platforms, allowing teams to exchange data seamlessly.
This chapter shows you how to connect PySpark with Snowflake, Databricks, and Hive, with clean examples and real input/output.
1. Snowflake Integration with PySparkโ
Snowflake is widely used for cloud analytics and BI dashboards.
PySpark integrates using the Snowflake Spark Connector.
1.1 Installing the Snowflake Connectorโ
--packages net.snowflake:snowflake-jdbc:3.13.30,net.snowflake:spark-snowflake_2.12:2.12.0-spark_3.4
1.2 Reading from Snowflakeโ
Example โ Loading Customer Table
sf_options = {
"sfURL": "account.snowflakecomputing.com",
"sfUser": "USER",
"sfPassword": "PASSWORD",
"sfDatabase": "DV_DB",
"sfSchema": "PUBLIC",
"sfWarehouse": "COMPUTE_WH"
}
df_sf = spark.read \
.format("snowflake") \
.options(**sf_options) \
.option("dbtable", "CUSTOMERS") \
.load()
df_sf.show()
Output Example
+---------+----------+--------+
|cust_id |name |country |
+---------+----------+--------+
|C101 |John Doe |USA |
|C102 |Maria Lee |Canada |
|C103 |Ishan Rao |India |
+---------+----------+--------+
1.3 Writing to Snowflakeโ
df_sf.write \
.format("snowflake") \
.options(**sf_options) \
.option("dbtable", "CUSTOMERS_BACKUP") \
.mode("overwrite") \
.save()
2. Databricks Integration with PySparkโ
Databricks is a managed platform for Spark with built-in:
- Optimized runtimes
- MLFlow
- Delta Lake
- Collaboration notebooks
You integrate PySpark with Databricks using:
โ Databricks Connect
โ DBFS data access
โ Delta Lake
2.1 Databricks Connect Setupโ
Databricks Connect allows you to run PySpark from your laptop and execute on a remote cluster.
pip install databricks-connect==14.0.*