Skip to content

Conversation

@jonahgao
Copy link
Member

Which issue does this PR close?

Closes #14112.

Rationale for this change

The new alias() method applies an alias to an existing DataFrame by wrapping a SubqueryAlias. It is useful for implementing self-joins.

What changes are included in this PR?

Are these changes tested?

Yes

Are there any user-facing changes?

New API.

@github-actions github-actions bot added the core Core DataFusion crate label Jan 14, 2025
assert_batches_eq!(expected, &result_df.collect().await.unwrap());
}

#[tokio::test]
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @jonahgao, nice PR, I would also add a test with some edge cases like nested alias, empty string alias

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in af5136b

#[tokio::test]
async fn test_alias_empty() -> Result<()> {
let df = create_test_table("test").await?.alias("")?;
let expected = "SubqueryAlias: [a:Utf8, b:Int32]\
Copy link
Member Author

Choose a reason for hiding this comment

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

We allow creating TableReference from empty str.

.alias("alias1")?
.alias("alias2")?;
let expected = "SubqueryAlias: alias2 [a:Utf8, b:Int32, one:Int32]\
\n SubqueryAlias: alias1 [a:Utf8, b:Int32, one:Int32]\
Copy link
Member Author

Choose a reason for hiding this comment

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

This layer is redundant, but SubqueryAliases won’t appear in the physical plan

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @jonahgao -- looks good to me

Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

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

lgtm thanks @jonahgao

@comphead comphead merged commit 89d6f0e into apache:main Jan 15, 2025
25 checks passed
@jonahgao
Copy link
Member Author

Thanks @comphead @alamb for the review

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

Labels

core Core DataFusion crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can no longer easily join duplicate schemas as of version 43

3 participants