Skip to content

how to get the table names from BinaryOperationExpr of where clause #1291

Description

@baichuanyang

Question

Hi.

i would like to parse a kind of query like:

select * from a inner join b on a.col1 == b.col1 inner join c on b.col2 == c.col2 where a.col3 = 1 and b.col4 = 5

and i got two *ast.BinaryOperationExpr of the where clause a.col3 = 1 and b.col4 = 5. however, that expression only contained *ast.ColumnNameExpr and *driver.ValueExpr and ignored the *ast.TableSource.

may i know how to get the table names?

thanks

Activity

  1. lance6716 commented on Aug 3, 2021

    @lance6716
    Contributor

    you can take a look at type ColumnName

    parser/ast/expressions.go

    Lines 558 to 569 in 94275e8

    // ColumnNameExpr represents a column name expression.
    type ColumnNameExpr struct {
    exprNode
    // Name is the referenced column name.
    Name *ColumnName
    // Refer is the result field the column name refers to.
    // The value of Refer.Expr is used as the value of the expression.
    Refer *ResultField
    }

  2. cjphaha commented on Oct 9, 2021

    @cjphaha

    you can take a look at type ColumnName

    parser/ast/expressions.go

    Lines 558 to 569 in 94275e8

    // ColumnNameExpr represents a column name expression.
    type ColumnNameExpr struct {
    exprNode
    // Name is the referenced column name.
    Name *ColumnName
    // Refer is the result field the column name refers to.
    // The value of Refer.Expr is used as the value of the expression.
    Refer *ResultField
    }

    But this will cause many duplicate ColumnName to appear. Is there any way to reduce duplication?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions