pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
37.1k stars 5.83k forks source link

Schema.String() returns empty result when parsing table name with schema #56459

Closed Nickelth closed 1 week ago

Nickelth commented 2 weeks ago

Bug Report

I try to use parser of tidb to parse statements like:

select * from d0.t0;

I wrote my visitor's Enter function like:

func (v *myVisitor) Enter(in ast.Node) (ast.Node, bool) {
        ...
    if name, ok := in.(*ast.TableName); ok {
        fmt.Println("schema is " + name.Schema.String())
        }
        ...
}

The output of Schema.String() is empty.

This is because Schema.String() returns the value of Schema.O, and Schema.O is empty.

But Schema.L recorded the right schema name. I think Schema.O and Schema.L should return strings only have case-difference?

Defined2014 commented 1 week ago

Can't reproduce it. Could you provide more information?

image
Nickelth commented 1 week ago

Can't reproduce it. Could you provide more information?

image

I checked my program in detail and found the problem is in my codes, sorry for bothering.