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

Type inheritance for functions based on args #674

Merged
merged 6 commits into from
Nov 7, 2022

Conversation

10bas10
Copy link
Contributor

@10bas10 10bas10 commented Nov 7, 2022

Made a new function to support type inheritance for specific functions that should only inherit from specific attributes. The function allows one of the following parameters:

  • A string and that will refer to an entry within the args dictionary, the array of expressions or its single expression will be included in the inheritance of datatypes;
  • An expression;
  • An list of expressions.

From the list of expressions applicable, the datatype will be inherited.

Copy link
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

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

Just a few comments. We should add some tests that cover other argument types too; for instance we should check the case where we have a list of expressions or a single expression, instead of just strings.

This seems like a reasonable addition, thanks for the PR!

sqlglot/optimizer/annotate_types.py Outdated Show resolved Hide resolved
sqlglot/optimizer/annotate_types.py Outdated Show resolved Hide resolved
sqlglot/optimizer/annotate_types.py Outdated Show resolved Hide resolved
sqlglot/optimizer/annotate_types.py Outdated Show resolved Hide resolved
@10bas10
Copy link
Contributor Author

10bas10 commented Nov 7, 2022

Just a few comments. We should add some tests that cover other argument types too; for instance we should check the case where we have a list of expressions or a single expression, instead of just strings.

I could also clean that part out as I dont see a usecase yet for it. What do you think?

@georgesittas
Copy link
Collaborator

georgesittas commented Nov 7, 2022

I could also clean that part out as I dont see a usecase yet for it. What do you think?

Yes, that could work too. I initially thought that strings would probably suffice for this function.

sqlglot/optimizer/annotate_types.py Outdated Show resolved Hide resolved
@tobymao tobymao merged commit 1147eb2 into tobymao:main Nov 7, 2022
@10bas10 10bas10 deleted the 10bas10/annotate_types_custom branch December 15, 2022 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants