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

Rename columns to valid namedtuple attributes + ensure Row.fields are retrieved as tuple #36949

Merged

Conversation

Joffreybvn
Copy link
Contributor

@Joffreybvn Joffreybvn commented Jan 22, 2024

Fix for #36839, #36838 and a similar issue in the ODBCHook.

With this PR:

  • When columns are named with a reserved Python keywords, or contains invalid characters (like ( or @) that cannot be used in an attribute name, the columns get renamed.
  • The fields attribute is retrieved as tuple even when the Databricks.Row object is created in two steps.

Note: Having columns being rename is not an issue, as users should use the tuple API. Namedtuple is there for backward compatibility during the transition to tuples.


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@Joffreybvn
Copy link
Contributor Author

Joffreybvn commented Jan 22, 2024

ODBCHook has the same issue (#36838). But it's a typing.NamedTuple there (instead of a collection.namedtuple). Which do not support rename=True. Thus I'll refactor the hook to use the collection.namedtuple too.

@Joffreybvn Joffreybvn changed the title Rename columns to valid namedtuple attributes Rename columns to valid namedtuple attributes + ensure Row.fields are retrieved as tuple Jan 22, 2024
@potiuk potiuk merged commit c0f7601 into apache:main Jan 23, 2024
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants