-   Notifications  You must be signed in to change notification settings 
- Fork 107
 feat: pass parent to get_node_properties and add support for create aggregate with order by #72 
 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
   Merged  
     Merged  
 Changes from 1 commit
 Commits 
  Show all changes 
  2 commits   Select commit Hold shift + click to select a range 
  File filter
Filter by extension
Conversations
 Failed to load comments.  
    Loading  
 Jump to
  Jump to file  
  Failed to load files.  
    Loading  
 Diff view
Diff view
There are no files selected for viewing
   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   
        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   
        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   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| CREATE AGGREGATE aggregate1 (int4) (sfunc = sfunc1, stype = stype1); | ||
| CREATE AGGREGATE aggregate1 (int4, bool) (sfunc = sfunc1, stype = stype1); | ||
| CREATE AGGREGATE aggregate1 (*) (sfunc = sfunc1, stype = stype1); | ||
| CREATE AGGREGATE aggregate1 (int4) (sfunc = sfunc1, stype = stype1, finalfunc_extra, mfinalfuncextra); | ||
| CREATE AGGREGATE aggregate1 (int4) (sfunc = sfunc1, stype = stype1, finalfunc_modify = read_only, parallel = restricted); | ||
| CREATE AGGREGATE percentile_disc (float8 ORDER BY anyelement) (sfunc = ordered_set_transition, stype = internal, finalfunc = percentile_disc_final, finalfunc_extra); | ||
| CREATE AGGREGATE custom_aggregate (float8 ORDER BY column1, column2) (sfunc = sfunc1, stype = stype1); | ||
|  | ||
|  | ||
|  | 
 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.    
 
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cvng I tried it myself and even though I figured how to know what tokens to add, it does still fail because the
ORDER BYtokens must be part of either theListnode or the lastFunctionParameternode.as of now, I don't see a way around this other than passing the
node_graphand figuring out the nodes for theFunctionParameterfrom its parents...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its not a big deal, but I hoped that the AST is "clean enough" for this to not be required...
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
other valuable option: skip the
Listnode entirely in the parser and put its children directly beneath theDefineStmtnode. Could get messy though since theListnode is also used elsewhere, so this has to be done only for children ofDefineStmt.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@psteinroe I'm not confortable enough with the AST to know what a proper solution should be. It the test in #69 passes with the same output?
As of my understanding, I would go with solution 3 (direct children to
DefineStmt) - based on the docs - aggregate withorder byis kind of a special case(also, I'm not sure this syntax exists elsewhere)
I let you close the previous PR if you think this is a better approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just by reading this, one could think that the
order byis before / parent (same thing) of the list?https://github.com/postgres/postgres/blob/REL_15_STABLE/src/backend/parser/gram.y#L8355
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it should be part of the
Listnode. we should then pass the parent AST node somehow, and for aListnode, check if the parent is aDefineStmt, and do the same checks as I implemented for theDefineStmt. passing the node_graph will not be sufficient since we need the sibling token to be resolved first which cannot be guaranteed. we could also just always pass the entireDefineStmt/ root node.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keeping around a notion of context / parent node for some children is what you suggest? this looks like the approach taken by other parsers working with the Postgres AST - if I fully understand
also is it reasonable to have
order bydirect child ofDefineStmtthis case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, at least within
get_node_properties. I will add a pr early next week for this.no, because its between two second-level children. we would have to close and re-open the list node which is not a valid. and ignoring the List is also not a great solution.