Skip to content

Instantly share code, notes, and snippets.

@ghalimi
Created January 16, 2023 16:57
Show Gist options
  • Save ghalimi/55730dd74884b8a95980a8cad51c99b7 to your computer and use it in GitHub Desktop.
Save ghalimi/55730dd74884b8a95980a8cad51c99b7 to your computer and use it in GitHub Desktop.
# query -> SELECT * FROM table
{
"select_query" : {
"select_node" : {
"projection_list": [
{
"type": "star_expression"
}
],
"from_clause": [
{
"type": "tableref",
"table_name": "table"
}
]
}
}
}
@AurelienRibon
Copy link

AurelienRibon commented Jan 16, 2023

It would be easier if all nodes used a type, like what ESTree does in JavaScript (AST standard for most JS parsers, including the builtin Firefox one).

A tree traverser can then be implemented easily just like a huge switch/case on that type property.

{
  "type": "select_query",
  "query": {
    "type": "select_node",
    "projection_list": [
      {
        "type": "star_expression"
      }
    ],
    "from_clause": [
      {
        "type": "tableref",
        "table_name": "table"
      }
    ]
  }
}

@Maxxen
Copy link

Maxxen commented Jan 16, 2023

Yes! I was having ESTree in mind as well when we were talking about this, the example snippet Is just something Mark whipped out in 30 sec as an example when we were discussing this before the meeting. Don't worry, I'll try to make it traversal friendly!

@AurelienRibon
Copy link

Awesome, thanks !

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