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: 

Access same createorreplacetempview("viewname") by multiple functions.

vk217
Contributor

I have several functions accessing the same createorreplacetempview("viewname"). Does this cause any issues with multiple functions accessing it in a distributed environment?

def get_data_sql(spark_session, data_frame, data_element):
        data_frame.createOrReplaceTempView("data")
        return spark_session.sql(
        f"""
        SELECT id, {data_element} FROM  data
        """
        )

Then I have these two functions calling the above function like this.

def get_key(spark_session, data_frame):
        return  get_data_sql(
               spark_session,data_frame,key
        )
def get_value(spark_session, data_frame):
        return  get_data_sql(
               spark_session,data_frame,value
        )

Should I be creating the temporary view in each of the calling functions with a separate name to avoid contention/clash?

My understanding is the once the view is created it lasts for the whole session and there would be no issues with multiple access in a distributed environment.

1 REPLY 1

Aviral-Bhardwaj
Esteemed Contributor III

there is two type of views

one is global view - it will be available for whole cluster and notebook but it will removed after cluster restart

and another is Temp view- that will be available for only notebook level, and other notebook will not able to see that.

I hope you will get little bit idea on this

Thanks

Aviral Bhardwaj

AviralBhardwaj

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