Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Enable to_json_string for physical plan #3023

Merged
merged 2 commits into from
Oct 15, 2024
Merged

Conversation

colin-ho
Copy link
Contributor

@colin-ho colin-ho commented Oct 8, 2024

#2977

Allows physical plan to be serialized to be json strings. The script below shows how you can extract the sql queries from read sql.

import daft
import json

def create_conn():
    return create_engine('sqlite:///test_database.db').connect()

df = daft.read_sql("SELECT * FROM test_data", create_conn, partition_col="id", num_partitions=3)
physical_plan_scheduler = df._builder.to_physical_plan_scheduler(
    daft.context.get_context().daft_execution_config
)

physical_plan_dict = json.loads(physical_plan_scheduler.to_json_string())

# collect all sql queries
sql_queries = []
for task in physical_plan_dict['TabularScan']['scan_tasks']:
    sql_queries.append(task['file_format_config']['Database']['sql'])
print(sql_queries)

['SELECT * FROM (SELECT * FROM test_data) AS subquery WHERE id >= 1 AND id < 34', 'SELECT * FROM (SELECT * FROM test_data) AS subquery WHERE id >= 34 AND id < 67', 'SELECT * FROM (SELECT * FROM test_data) AS subquery WHERE id >= 67 AND id <= 100']

Copy link

codspeed-hq bot commented Oct 8, 2024

CodSpeed Performance Report

Merging #3023 will not alter performance

Comparing colin/physical-plan-json (0de3933) with main (31e0de2)

Summary

✅ 17 untouched benchmarks

Copy link

codecov bot commented Oct 8, 2024

Codecov Report

Attention: Patch coverage is 16.66667% with 5 lines in your changes missing coverage. Please review.

Project coverage is 78.44%. Comparing base (3f37a69) to head (0de3933).
Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
src/daft-scheduler/src/scheduler.rs 0.00% 4 Missing ⚠️
daft/plan_scheduler/physical_plan_scheduler.py 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main    #3023    +/-   ##
========================================
  Coverage   78.43%   78.44%            
========================================
  Files         603      610     +7     
  Lines       71504    72007   +503     
========================================
+ Hits        56086    56487   +401     
- Misses      15418    15520   +102     
Files with missing lines Coverage Δ
daft/logical/builder.py 89.61% <ø> (ø)
daft/plan_scheduler/physical_plan_scheduler.py 54.90% <50.00%> (-0.21%) ⬇️
src/daft-scheduler/src/scheduler.rs 92.85% <0.00%> (-0.61%) ⬇️

... and 66 files with indirect coverage changes

@jaehyeon-kim
Copy link

Hi @colin-ho and @jaychia

Can this PR be reviewed?

@colin-ho colin-ho requested a review from jaychia October 15, 2024 17:30
Copy link
Contributor

@jaychia jaychia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also note that df._builder.to_physical_plan_scheduler is not a stable API, since it does access a private method in the dataframe.

In general I don't think we have any plans to make this a user-accessible feature via a stable user API

@colin-ho colin-ho merged commit e93dd94 into main Oct 15, 2024
41 of 42 checks passed
@colin-ho colin-ho deleted the colin/physical-plan-json branch October 15, 2024 20:37
@jaehyeon-kim
Copy link

@jaychia

Thanks for the reminder. At least, I can get started building the sql connector.

@colin-ho

Thank you so much for adding the feature. Can you please inform me when it may be released?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants