3

For the purposes of comparison, suppose we have a table "T" with two columns "A","B". We also have a hiveContext operating in some HDFS database. We make a data frame:

In theory, which of the following is faster:

sqlContext.sql("SELECT A,SUM(B) FROM T GROUP BY A")

or

df.groupBy("A").sum("B")

where "df" is a dataframe referring to T. For these simple kinds of aggregate operations, is there any reason why one should prefer one method over the other?

2 Answers 2

5

No, these should boil down to the same execution plan. Underneath the Spark SQL engine is using the same optimization engine, the catalyst optimizer. You can always check this yourself by looking at the spark UI, or even calling explain on the resultant DataFrame.

Sign up to request clarification or add additional context in comments.

Comments

4

Spark developers have made great effort to optimise. The performance between DataFrame Scala and DataFrame SQL is undistinguishable. Even for DataFrame Python, the differ is when collect data to driver.

It opens a new world

It doesn't have to be one vs. another

We can just choose what ever way we comfortable with

The performance comparison published by databricks enter image description here

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.