Add alias method to DataFrame for improved column name resolution#93
Open
georgemgichuru wants to merge 1 commit into
Open
Add alias method to DataFrame for improved column name resolution#93georgemgichuru wants to merge 1 commit into
georgemgichuru wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds DataFrame-level aliasing by introducing a new DataFrame::alias() API that wraps the existing logical plan in a Spark Connect SubqueryAlias relation, enabling qualified column references (useful for disambiguation in patterns like self-joins).
Changes:
- Added
DataFrame::alias(const std::string&)declaration and Doxygen documentation indataframe.h. - Implemented
DataFrame::alias()indataframe.cppby constructing aSubqueryAliasplan node over the current plan.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/dataframe.h | Declares the new alias() API and documents intended usage. |
| src/dataframe.cpp | Implements alias() by building a SubqueryAlias-wrapped logical plan. |
| * @example | ||
| * auto df1 = df.alias("a"); | ||
| * auto df2 = df.alias("b"); | ||
| * auto joined = df1.join(df2, col("a.id") == col("b.id")); |
Comment on lines
+440
to
+448
| * @param alias_name The string alias to apply to this DataFrame. | ||
| * @return A new DataFrame containing the aliased logical plan. | ||
| * | ||
| * @example | ||
| * auto df1 = df.alias("a"); | ||
| * auto df2 = df.alias("b"); | ||
| * auto joined = df1.join(df2, col("a.id") == col("b.id")); | ||
| */ | ||
| DataFrame alias(const std::string& alias_name) const; |
Comment on lines
+1177
to
+1186
| Plan plan; | ||
| auto* subquery_alias = plan.mutable_root()->mutable_subquery_alias(); | ||
|
|
||
| if (this->plan_.has_root()) | ||
| { | ||
| subquery_alias->mutable_input()->CopyFrom(this->plan_.root()); | ||
| } | ||
|
|
||
| subquery_alias->set_alias(alias_name); | ||
|
|
Comment on lines
+1172
to
+1174
| /* | ||
| *@brief aliasing support for dataframes | ||
| * */ |
Comment on lines
+1175
to
+1187
| DataFrame DataFrame::alias(const std::string& alias_name) const | ||
| { | ||
| Plan plan; | ||
| auto* subquery_alias = plan.mutable_root()->mutable_subquery_alias(); | ||
|
|
||
| if (this->plan_.has_root()) | ||
| { | ||
| subquery_alias->mutable_input()->CopyFrom(this->plan_.root()); | ||
| } | ||
|
|
||
| subquery_alias->set_alias(alias_name); | ||
|
|
||
| return DataFrame(stub_, plan, session_id_, user_id_); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces aliasing support to the
DataFrameclass, making it easier to handle column name ambiguities, especially during self-joins. The main change is the addition of analiasmethod, along with its documentation and implementation.Aliasing support for DataFrames:
aliasmethod to theDataFrameclass indataframe.h, including detailed documentation and usage example. This method returns a newDataFramewith an alias set, which is useful for resolving column ambiguities in operations like self-joins.aliasmethod indataframe.cpp, constructing a new logical plan with a subquery alias node that wraps the current DataFrame's plan and sets the provided alias name.