Giter VIP home page Giter VIP logo

Comments (6)

lelit avatar lelit commented on June 12, 2024 1

I'm closing this, as there isn't much I can do, other that inventing that other layer, a big effort with uncertain advantage.

from pglast.

lelit avatar lelit commented on June 12, 2024

Out of curiosity, can you show a sample statement that exhibits the problem?
In general, though, I'd prefer to avoid fiddling with parser's output... but let's see.

from pglast.

tscholak avatar tscholak commented on June 12, 2024

Sure, no problem:

  1. Example where rexpr is a dict:
SELECT count(*) FROM head WHERE age  >  56
[
  {
    "RawStmt": {
      "stmt": {
        "SelectStmt": {
          "targetList": [
            {
              "ResTarget": {
                "val": {
                  "FuncCall": {
                    "funcname": [
                      {
                        "String": {
                          "str": "count"
                        }
                      }
                    ],
                    "agg_star": true,
                    "location": 7
                  }
                },
                "location": 7
              }
            }
          ],
          "fromClause": [
            {
              "RangeVar": {
                "relname": "head",
                "inh": true,
                "relpersistence": "p",
                "location": 21
              }
            }
          ],
          "whereClause": {
            "A_Expr": {
              "kind": 0,
              "name": [
                {
                  "String": {
                    "str": ">"
                  }
                }
              ],
              "lexpr": {
                "ColumnRef": {
                  "fields": [
                    {
                      "String": {
                        "str": "age"
                      }
                    }
                  ],
                  "location": 32
                }
              },
              "rexpr": {
                "A_Const": {
                  "val": {
                    "Integer": {
                      "ival": 56
                    }
                  },
                  "location": 40
                }
              },
              "location": 37
            }
          },
          "op": 0
        }
      }
    }
  }
]
  1. Example where rexpr is a list:
SELECT avg(num_employees) FROM department WHERE ranking BETWEEN 10 AND 15
[
  {
    "RawStmt": {
      "stmt": {
        "SelectStmt": {
          "targetList": [
            {
              "ResTarget": {
                "val": {
                  "FuncCall": {
                    "funcname": [
                      {
                        "String": {
                          "str": "avg"
                        }
                      }
                    ],
                    "args": [
                      {
                        "ColumnRef": {
                          "fields": [
                            {
                              "String": {
                                "str": "num_employees"
                              }
                            }
                          ],
                          "location": 11
                        }
                      }
                    ],
                    "location": 7
                  }
                },
                "location": 7
              }
            }
          ],
          "fromClause": [
            {
              "RangeVar": {
                "relname": "department",
                "inh": true,
                "relpersistence": "p",
                "location": 31
              }
            }
          ],
          "whereClause": {
            "A_Expr": {
              "kind": 11,
              "name": [
                {
                  "String": {
                    "str": "BETWEEN"
                  }
                }
              ],
              "lexpr": {
                "ColumnRef": {
                  "fields": [
                    {
                      "String": {
                        "str": "ranking"
                      }
                    }
                  ],
                  "location": 48
                }
              },
              "rexpr": [
                {
                  "A_Const": {
                    "val": {
                      "Integer": {
                        "ival": 10
                      }
                    },
                    "location": 64
                  }
                },
                {
                  "A_Const": {
                    "val": {
                      "Integer": {
                        "ival": 15
                      }
                    },
                    "location": 71
                  }
                }
              ],
              "location": 56
            }
          },
          "op": 0
        }
      }
    }
  }
]

I'd prefer to avoid fiddling with parser's output

In general, I would agree. 👍

from pglast.

tscholak avatar tscholak commented on June 12, 2024

In the pglast code, this is solved by case matching the kind: https://github.com/aiham/pglast/blob/master/pglast/printers/dml.py#L120

from pglast.

lelit avatar lelit commented on June 12, 2024

Thank you, I see. And what do you do on that? I mean, what would be your ideal way to deal with the polymorphic nature of that "value"?
The problem is that the "knowledge" of the "concrete shape" of the value must be obviously coded somewhere... one idea (without much thinking, really!) would be having a way to implement an higher level AST, that is, using a machinery similar to the "printers" that instead of a serialized, textual representation of the "low level" syntax would produce more usable/generic nodes...

from pglast.

tscholak avatar tscholak commented on June 12, 2024

one idea (without much thinking, really!) would be having a way to implement an higher level AST

I think this is possible, but would require converting the A_Expr constructor into an A_Expr ADT with a set of constructors, one for each A_Expr kind. For instance:

A_Expr = A_Expr_Op(Val* name, Expr lexpr, Expr? rexpr)
       | A_Expr_Between(Val* name, Expr lexpr, Expr rexpr1, Expr rexpr2)
       | ...

something like that, where Type* means multiple cardinality, Type? means optional cardinality, and Type means single cardinality.

from pglast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.