Skip to content

Add support for inline column alias in CREATE VIEW - #3209

Merged
andygrove merged 5 commits into
apache:masterfrom
spaceandtimefdn:dalto-3108
Aug 23, 2022
Merged

Add support for inline column alias in CREATE VIEW#3209
andygrove merged 5 commits into
apache:masterfrom
spaceandtimefdn:dalto-3108

Conversation

@DaltonModlin

@DaltonModlinDaltonModlin commented Aug 19, 2022

Copy link
Copy Markdown
Contributor
  • Add columns argument to planner::query_to_plan
  • Add columns argument to planner::query_to_plan_with_alias
  • Add test query_view_with_alias to view.rs
  • Add test query_view_with_inline_alias to view.rs

Resolves#3108

fix(planner): Updated Statement::CreateView logic

  • Added match for empty columns vector to determine optional value

Closes#3108

Rationale for this change

Enables part of TPCH Query 15.

What changes are included in this PR?

Added capability for inline column aliases in sql queries.

Are there any user-facing changes?

Added capability for inline column aliases in sql queries.

- Add columns argument to planner::query_to_plan
- Add columns argument to planner::query_to_plan_with_alias
- Add test query_view_with_alias to view.rs
- Add test query_view_with_inline_alias to view.rs
Resolves #3108
fix(planner): Updated Statement::CreateView logic
- Added match for empty columns vector to determine optional value
@github-actionsgithub-actionsBot added core Core DataFusion crate sql SQL Planner labels Aug 19, 2022
}

#[tokio::test]
async fn query_view_with_inline_alias() -> Result<()> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice tests 👍

Comment threaddatafusion/sql/src/planner.rs Outdated
Comment threaddatafusion/sql/src/planner.rs Outdated
Comment threaddatafusion/sql/src/planner.rs Outdated
Co-authored-by: Andy Grove <andygrove73@gmail.com>
@andygroveandygrove changed the title feat(planner): Add support for inline column aliasfeat(planner): Add support for inline column alias in CREATE VIEWAug 19, 2022
@andygroveandygrove changed the title feat(planner): Add support for inline column alias in CREATE VIEWAdd support for inline column alias in CREATE VIEWAug 19, 2022
Comment threaddatafusion/sql/src/planner.rs Outdated
Co-authored-by: Andy Grove <andygrove73@gmail.com>

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @DaltonModlin -- I think this is looking good. I think @andygrove 's suggestion on moving the code around would make the code better, but I also think it could be done as a follow on. 👍

Comment threaddatafusion/core/src/datasource/view.rs Outdated
Comment threaddatafusion/core/src/datasource/view.rs Outdated
@codecov-commenter

codecov-commenter commented Aug 20, 2022

Copy link
Copy Markdown

Codecov Report

Merging #3209 (cfec7a7) into master (3df9f80) will decrease coverage by 0.02%.
The diff coverage is 83.88%.

❗ Current head cfec7a7 differs from pull request most recent head 26bab55. Consider uploading reports for the commit 26bab55 to get more accurate results

@@ Coverage Diff @@## master #3209 +/- ##
==========================================
- Coverage 85.85% 85.83% -0.03% 
==========================================
Files 291 291 Lines 52899 52947 +48 ==========================================
+ Hits 45416 45446 +30 - Misses 7483 7501 +18 
Impacted FilesCoverage Δ
datafusion/core/src/physical_plan/planner.rs80.88% <0.00%> (-0.17%)⬇️
datafusion/expr/src/utils.rs90.02% <0.00%> (-0.74%)⬇️
datafusion/proto/src/logical_plan.rs17.35% <0.00%> (-0.07%)⬇️
datafusion/sql/src/planner.rs80.44% <62.85%> (-0.19%)⬇️
datafusion/expr/src/logical_plan/plan.rs78.17% <66.66%> (+0.40%)⬆️
datafusion/core/src/datasource/view.rs86.42% <84.61%> (-0.42%)⬇️
.../physical-expr/src/aggregate/array_agg_distinct.rs79.41% <89.47%> (-0.78%)⬇️
datafusion/expr/src/operator.rs95.23% <92.30%> (-0.77%)⬇️
datafusion/common/src/scalar.rs84.58% <100.00%> (-0.16%)⬇️
datafusion/optimizer/src/simplify_expressions.rs84.00% <100.00%> (+0.06%)⬆️
... and 11 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

- Move column handling logic from query_to_plan to create view
- Remove columns argument from query_to_plan and query_to_plan_with_alias
- Remove unecessary information schema table check from create view alias tests

@andygroveandygrove left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks @DaltonModlin!

Comment on lines +204 to +207
.map_err(|e| {
context!("Failed to apply alias to inline projection.\n", e)
})?
.build()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is fine and no need to change this but just an FYI really, you can avoid having multiple map_err like this:

Suggested change
.map_err(|e| {
context!("Failed to apply alias to inline projection.\n", e)
})?
.build()
.and_then(|builder| builder.build())

@andygrove
andygrove merged commit c72f547 into apache:masterAug 23, 2022
@ursabot

Copy link
Copy Markdown

Benchmark runs are scheduled for baseline = f974e88 and contender = c72f547. c72f547 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coreCore DataFusion cratesqlSQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow inline column aliases for create view

5 participants

@DaltonModlin@codecov-commenter@ursabot@alamb@andygrove