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

Show Enum-object representation instead of just constant. #60

Closed
wants to merge 2 commits into from

Conversation

1844144
Copy link

@1844144 1844144 commented Aug 24, 2020

Hello, when I am printing ast-tree I need to see what enum class and value are used. For example:
if you are using OR expression - it will display

...
'boolop': 1
...

after my modification it will show:

'boolop': <BoolExprType.OR_EXPR: 1>

.

Small example for select * from some_table where name='Bob' AND lastname='Alice'

[
<RawStmt>
    'stmt': <SelectStmt>
        'targetList': [
            <ResTarget>
                'val': <ColumnRef>
                    'fields': [
                        <A_Star>
                        ]
                    'location': <7>
                'location': <7>
            ]
        'fromClause': [
            <RangeVar>
                'relname': <'some_table'>
                'inh': <True>
                'relpersistence': <'p'>
                'location': <14>
            ]
        'whereClause': <BoolExpr>
            'boolop': <BoolExprType.AND_EXPR: 0>
            'args': [
                <A_Expr>
                    'kind': <A_Expr_Kind.AEXPR_OP: 0>
                    'name': [
                        <String>
                            'str': <'='>
                        ]
                    'lexpr': <ColumnRef>
                        'fields': [
                            <String>
                                'str': <'name'>
                            ]
                        'location': <32>
                    'rexpr': <A_Const>
                        'val': <String>
                            'str': <'Bob'>
                        'location': <37>
                    'location': <36>
                <A_Expr>
                    'kind': <A_Expr_Kind.AEXPR_OP: 0>
                    'name': [
                        <String>
                            'str': <'='>
                        ]
                    'lexpr': <ColumnRef>
                        'fields': [
                            <String>
                                'str': <'lastname'>
                            ]
                        'location': <47>
                    'rexpr': <A_Const>
                        'val': <String>
                            'str': <'Alice'>
                        'location': <56>
                    'location': <55>
                ]
            'location': <43>
        'op': <SetOperation.SETOP_NONE: 0>
]

@lelit
Copy link
Owner

lelit commented Aug 25, 2020

Interesting, thank you. I will give a better look in the following days.

@lelit lelit mentioned this pull request Feb 10, 2021
@lelit
Copy link
Owner

lelit commented Mar 20, 2021

FYI, in current v3 this is the outcome:

# echo "select * from some_table where name='Bob' AND lastname='Alice'" | pgpp -t
[{'@': 'RawStmt',
  'stmt': {'@': 'SelectStmt',
           'all': False,
           'fromClause': ({'@': 'RangeVar',
                           'inh': True,
                           'location': 14,
                           'relname': 'some_table',
                           'relpersistence': 'p'},),
           'limitOption': {'#': 'LimitOption',
                           'name': 'LIMIT_OPTION_DEFAULT',
                           'value': 0},
           'op': {'#': 'SetOperation', 'name': 'SETOP_NONE', 'value': 0},
           'targetList': ({'@': 'ResTarget',
                           'location': 7,
                           'val': {'@': 'ColumnRef',
                                   'fields': ({'@': 'A_Star'},),
                                   'location': 7}},),
           'whereClause': {'@': 'BoolExpr',
                           'args': ({'@': 'A_Expr',
                                     'kind': {'#': 'A_Expr_Kind',
                                              'name': 'AEXPR_OP',
                                              'value': 0},
                                     'lexpr': {'@': 'ColumnRef',
                                               'fields': ({'@': 'String',
                                                           'val': 'name'},),
                                               'location': 31},
                                     'location': 35,
                                     'name': ({'@': 'String', 'val': '='},),
                                     'rexpr': {'@': 'A_Const',
                                               'location': 36,
                                               'val': {'@': 'String',
                                                       'val': 'Bob'}}},
                                    {'@': 'A_Expr',
                                     'kind': {'#': 'A_Expr_Kind',
                                              'name': 'AEXPR_OP',
                                              'value': 0},
                                     'lexpr': {'@': 'ColumnRef',
                                               'fields': ({'@': 'String',
                                                           'val': 'lastname'},),
                                               'location': 46},
                                     'location': 54,
                                     'name': ({'@': 'String', 'val': '='},),
                                     'rexpr': {'@': 'A_Const',
                                               'location': 55,
                                               'val': {'@': 'String',
                                                       'val': 'Alice'}}}),
                           'boolop': {'#': 'BoolExprType',
                                      'name': 'AND_EXPR',
                                      'value': 0},
                           'location': 42}},
  'stmt_len': 0,
  'stmt_location': 0}]

As you can see, enums now appears as a dictionary with a # key pointing to the enum class name, and both the name and the value are present.

@lelit
Copy link
Owner

lelit commented Apr 28, 2021

I hope v3 representation is clear enough.

@lelit lelit closed this Apr 28, 2021
@1844144
Copy link
Author

1844144 commented Apr 28, 2021 via email

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.

None yet

2 participants