DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • A Scalable Framework for Enterprise Salesforce Optimization: Turning Outcomes Into an Operating System
  • Performance Optimization Techniques in Flutter 3.41 for Mobile App Development
  • Stop Burning Money on AI Inference: A Cloud-Agnostic Guide to Serverless Cost Optimization
  • Why Image Optimization in Modern Applications Matters More Than You Think

Trending

  • Improving DAG Failure Detection in Airflow Using AI Techniques
  • Metadata Driven Data Engineering: Declarative Pipeline Orchestration in Lakeflow
  • Conversational Risk Accumulation: Stateful Guardrails Beyond Single-Turn LLM Checks
  • Securing LLM Applications: Beyond the New OWASP LLM Top 10
  1. DZone
  2. Software Design and Architecture
  3. Performance
  4. Understanding the Optimized Logical Plan in Spark

Understanding the Optimized Logical Plan in Spark

Logical plans are applied by Spark's optimizer for query optimization. Read on for a brief overview of the logical plans, their types, and much more.

By 
Anubhav Tarar user avatar
Anubhav Tarar
·
May. 17, 17 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
52.7K Views

Join the DZone community and get the full member experience.

Join For Free

A logical plan is a tree that represents both schema and data. These trees are manipulated and optimized by catalyst framework.

There are three types of logical plans:

  1. Parsed logical plan.

  2. Analyzed logical plan.

  3. Optimized logical plan.

Analyzed logical plans go through a series of rules to resolve. Then, the optimized logical plan is produced. The optimized logical plan normally allows Spark to plug in a set of optimization rules. You can plug in your own rules for the optimized logical plan.

This optimized logical plan is converted to a physical plan for further execution. These plans lie inside the DataFrame API. Now, let's run an example to see these plans and observe the differences between them.

spark.png

Using our RDD, we created a DataFrame with column names c1, c2, and c3 and data values 1 to 100. To see the plan of a DataFrame, we will be using the explain command. If you run it without the true argument, it gives only the physical plan. The physical plan is always an RDD.

To see all three plans, run the explain command with a true argument.

explain also shows the physical logical plan:

spark2.png

If we have a look here, all plans look the same. Then, what is the difference between the optimized logical plan and analyzed logical plan? Now, run this example with two filters:

spark3.png

Here is the actual difference:

== Analyzed Logical Plan ==
c1: string, c2: string, c3: string
Filter NOT (cast(c2#14 as double) = cast(0 as double))
+- Filter NOT (cast(c1#13 as double) = cast(0 as double))
+- LogicalRDD [c1#13, c2#14, c3#15]== Optimized Logical Plan ==
Filter (((isnotnull(c1#13) && NOT (cast(c1#13 as double) = 0.0)) && isnotnull(c2#14)) && NOT (cast(c2#14 as double) = 0.0))
+- LogicalRDD [c1#13, c2#14, c3#15]

In the optimized logical plan, Spark does optimization itself. It sees that there is no need for two filters. Instead, the same task can be done with only one filter using the and operator, so it does execution in one filter.

optimization

Published at DZone with permission of Anubhav Tarar. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • A Scalable Framework for Enterprise Salesforce Optimization: Turning Outcomes Into an Operating System
  • Performance Optimization Techniques in Flutter 3.41 for Mobile App Development
  • Stop Burning Money on AI Inference: A Cloud-Agnostic Guide to Serverless Cost Optimization
  • Why Image Optimization in Modern Applications Matters More Than You Think

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook