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

Improve the output of the enhanced Arel AST #113

Open
mvgijssel opened this issue Jul 30, 2019 · 0 comments
Open

Improve the output of the enhanced Arel AST #113

mvgijssel opened this issue Jul 30, 2019 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@mvgijssel
Copy link
Collaborator

mvgijssel commented Jul 30, 2019

Currently for SELECT * FROM posts the following enhanced AST is printed. This is a huge amount of lines for a simple statement and there's probably some compacting that can be done here.

For example

  • Do not render SQL?
  • Make scalar nodes (true, false, string, etc) more compact
    • not render parent
    • not render at all?

Let's see what can be removed but still resulting in a useful printed AST.

Secondly, the paths printed in the inspect are absolute and full paths. It is useful is the path that's printed is related to the current node and not the absolute path relative to the root node.

node.ast.cores

This can also be an opportunity to reuse the to_sql_and_binds for to_sql added in #128.

=> <Node(Arel::SelectManager) []
  sql = SELECT * FROM "posts"
  parent = nil
  ast =
    <Node(Arel::Nodes::SelectStatement) ['ast']
      sql = SELECT * FROM "posts"
      parent = Node(Arel::SelectManager)
      cores =
        <Node(Array) ['ast', 'cores']
          sql = SELECT * FROM "posts"
          parent = Node(Arel::Nodes::SelectStatement)
          0 =
            <Node(Arel::Nodes::SelectCore) ['ast', 'cores', 0]
              sql = SELECT * FROM "posts"
              parent = Node(Array)
              source =
                <Node(Arel::Nodes::JoinSource) ['ast', 'cores', 0, 'source']
                  sql = "posts"
                  parent = Node(Arel::Nodes::SelectCore)
                  left =
                    <Node(Arel::Table) ['ast', 'cores', 0, 'source', 'left']
                      sql = "posts"
                      parent = Node(Arel::Nodes::JoinSource)
                      name =
                        <Node(String) ['ast', 'cores', 0, 'source', 'left', 'name']
                          parent = Node(Arel::Table)
                          value = "posts">
                      only =
                        <Node(FalseClass) ['ast', 'cores', 0, 'source', 'left', 'only']
                          parent = Node(Arel::Table)
                          value = false>
                      schema_name =
                        <Node(NilClass) ['ast', 'cores', 0, 'source', 'left', 'schema_name']
                          parent = Node(Arel::Table)
                          value = nil>
                      relpersistence =
                        <Node(String) ['ast', 'cores', 0, 'source', 'left', 'relpersistence']
                          parent = Node(Arel::Table)
                          value = "p">
                    >
                  right =
                    <Node(Array) ['ast', 'cores', 0, 'source', 'right']
                      parent = Node(Arel::Nodes::JoinSource)
                      value = nil>
                >
              projections =
                <Node(Array) ['ast', 'cores', 0, 'projections']
                  sql = *
                  parent = Node(Arel::Nodes::SelectCore)
                  0 =
                    <Node(Arel::Nodes::UnqualifiedColumn) ['ast', 'cores', 0, 'projections', 0]
                      sql = *
                      parent = Node(Array)
                      expr =
                        <Node(Arel::Attributes::Attribute) ['ast', 'cores', 0, 'projections', 0, 'expr']
                          sql = *
                          parent = Node(Arel::Nodes::UnqualifiedColumn)
                          relation =
                            <Node(NilClass) ['ast', 'cores', 0, 'projections', 0, 'expr', 'relation']
                              parent = Node(Arel::Attributes::Attribute)
                              value = nil>
                          name =
                            <Node(Arel::Nodes::SqlLiteral) ['ast', 'cores', 0, 'projections', 0, 'expr', 'name']
                              parent = Node(Arel::Attributes::Attribute)
                              value = "*">
                        >
                    >
                >
              wheres =
                <Node(Array) ['ast', 'cores', 0, 'wheres']
                  parent = Node(Arel::Nodes::SelectCore)
                  value = nil>
              windows =
                <Node(Array) ['ast', 'cores', 0, 'windows']
                  parent = Node(Arel::Nodes::SelectCore)
                  value = nil>
              into =
                <Node(NilClass) ['ast', 'cores', 0, 'into']
                  parent = Node(Arel::Nodes::SelectCore)
                  value = nil>
            >
        >
      limit =
        <Node(NilClass) ['ast', 'limit']
          parent = Node(Arel::Nodes::SelectStatement)
          value = nil>
      orders =
        <Node(Array) ['ast', 'orders']
          parent = Node(Arel::Nodes::SelectStatement)
          value = nil>
      offset =
        <Node(NilClass) ['ast', 'offset']
          parent = Node(Arel::Nodes::SelectStatement)
          value = nil>
      lock =
        <Node(NilClass) ['ast', 'lock']
          parent = Node(Arel::Nodes::SelectStatement)
          value = nil>
      with =
        <Node(NilClass) ['ast', 'with']
          parent = Node(Arel::Nodes::SelectStatement)
          value = nil>
      union =
        <Node(NilClass) ['ast', 'union']
          parent = Node(Arel::Nodes::SelectStatement)
          value = nil>
      values_lists =
        <Node(NilClass) ['ast', 'values_lists']
          parent = Node(Arel::Nodes::SelectStatement)
          value = nil>
    >
>
@mvgijssel mvgijssel added the enhancement New feature or request label Jul 30, 2019
@mvgijssel mvgijssel added this to the 0.5.0 milestone Jul 30, 2019
@mvgijssel mvgijssel changed the title Make the output of the enhanced AST inspector more dense Improve the output of the enhanced Arel AST Aug 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant