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

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

Open
baichuanyang opened this issue Aug 2, 2021 · 2 comments
Open

Comments

@baichuanyang
Copy link

baichuanyang commented Aug 2, 2021

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

@lance6716
Copy link
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
}

@cjphaha
Copy link

cjphaha commented Oct 9, 2021

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants