cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

FutureWarning: Deprecated in 3.0.0. Use SparkSession.builder.getOrCreate() instead.

Andrei_Radulesc
Contributor III

I'm trying to get rid of the warning below:

/databricks/spark/python/pyspark/sql/context.py:117: FutureWarning: Deprecated in 3.0.0. Use SparkSession.builder.getOrCreate() instead.

In my setup, I have a front-end notebook that gets parameters from the user, and that needs to create a dataframe based on those parameters. The code to create the dataframe is common with other notebooks, and is implemented in a regular python file:

def get_df(days_old: int = None) -> DataFrame:

   sc = SparkSession.builder.getOrCreate()

   sqlc = SQLContext(sc)

   df = sqlc.table(f"prod.some_schema.some_table")

return df

If I were to call sqlc.table() directly in the notebook, I would not have to create the Spark session and the SQL context. But if I call it from within a regular python file, I have to get the Spark session and SQL context - and I can't figure out how to do that w/o this FutureWarning.

1 ACCEPTED SOLUTION

Accepted Solutions

Andrei_Radulesc
Contributor III

That fixes it. Thanks. I need to do

spark = SparkSession.builder.getOrCreate()

df = spark.table("prod.some_schema.some_table")

instead of

sc = SparkSession.builder.getOrCreate()

   sqlc = SQLContext(sc)

   df = sqlc.table(f"prod.some_schema.some_table")

View solution in original post

2 REPLIES 2

Andrei_Radulesc
Contributor III

It just seems to me I already call SparkSession.builder.getOrCreate() , and still get the warning.

Andrei_Radulesc
Contributor III

That fixes it. Thanks. I need to do

spark = SparkSession.builder.getOrCreate()

df = spark.table("prod.some_schema.some_table")

instead of

sc = SparkSession.builder.getOrCreate()

   sqlc = SQLContext(sc)

   df = sqlc.table(f"prod.some_schema.some_table")

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group