0

I have small snippet of code in pyspark.

# save data frame as temp table 
df.createOrReplaceTempView("my_table")

# save data frame as csv
df.write.format("csv").save("my_csv")

Now the 1st command executes then only 2nd will execute.

Is there a way where I can trigger both these commands in parallel i.e I want both commands to execute at the same time

1 Answer 1

2

You can use python multiprocessing

from multiprocessing import Process

def create_temp_view(df):
    df.createOrReplaceTempView("my_table")

def write_df(df):
    df.write.mode("overwrite").format("csv").save("my_csv")


p1 = Process(create_temp_view(df))
p1.start()
p2 = Process(write_df(df))
p2.start()
p1.join()
p2.join()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.