cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
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

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.