0

can someone please suggest me how to use filter while joining 2 dataframes in spark scala.I am trying below code.

    var name="abcd"
    var last_name="xyz"

    val df3 = df1.join(df2, df1("id") === df2("id"))
    .filter(df1("name")==='${name}').
    filter(df1("last_name")==='${last_name}')
    .drop(df1("name"))
    .drop(df2("name"))

But getting multiple error.

enter image description here

1 Answer 1

2

Spark is not like java's JDBC APIs where we need wrap string with single quotes for where condition. Can you simple try using name variable w/o any quotes and $ sign

    var name="abcd"
    var last_name="xyz"
    val df3 = df1.join(df2, df1("id") === df2("id"))
    .filter(df1("name")===name && df1("last_name")===last_name)
    .drop(df1("name"))
    .drop(df2("name"))
Sign up to request clarification or add additional context in comments.

2 Comments

Yes it worked for adding multiple filter condition do i need to use multiple filter or i can use &&?
please use && for multiple filters

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.