0
spark.sql("Select acts.accountname, acts.county_state,loc.Town, acts.country from assure_crm_accounts acts inner join assure_crm_accountlocation loc on acts.GPAddressCode = loc.GPAddressCode").show(30, False)

I run into error when I use multiple line query using PySpark, is there a way to run multiple line queries using a single command?

1
  • Maybe it's handy to write it on 1 line, then after that use auto-reformatting shortcut in you editor. Then you see what's the best syntax! Commented Jan 20, 2020 at 16:27

2 Answers 2

5

You can also use triple quotes to write multiline string sql query as below:

spark.sql("""
Select acts.accountname, acts.county_state,loc.Town, acts.country 
from assure_crm_accounts acts 
inner join assure_crm_accountlocation loc 
on acts.GPAddressCode = loc.GPAddressCode
"""
)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for this - it is the only reference I've found that doesn't require the \ character (which is a real pain for very large SQL statements).
3

Just put " \" at the end of each line:

spark.sql("Select acts.accountname, acts.county_state,loc.Town, acts.country from \
assure_crm_accounts acts inner join assure_crm_accountlocation loc on \
acts.GPAddressCode = loc.GPAddressCode").show(30, False)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.