Comments (4)
You can see this bug arises from the fact that a TableSource
calls n.Source.Restore()
, then writes the AsName
if it exists.
// Restore implements Node interface.
func (n *TableSource) Restore(ctx *RestoreCtx) error {
needParen := false
switch n.Source.(type) {
case *SelectStmt, *UnionStmt:
needParen = true
}
if needParen {
ctx.WritePlain("(")
}
if err := n.Source.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore TableSource.Source")
}
if needParen {
ctx.WritePlain(")")
}
if asName := n.AsName.String(); asName != "" {
ctx.WriteKeyWord(" AS ")
ctx.WriteName(asName)
}
return nil
}
TableName
, which is the underlying type of Source
in my case, is responsible for printing Index Hints:
// Restore implements Node interface.
func (n *TableName) Restore(ctx *RestoreCtx) error {
if n.Schema.String() != "" {
ctx.WriteName(n.Schema.String())
ctx.WritePlain(".")
}
ctx.WriteName(n.Name.String())
if len(n.PartitionNames) > 0 {
ctx.WriteKeyWord(" PARTITION")
ctx.WritePlain("(")
for i, v := range n.PartitionNames {
if i != 0 {
ctx.WritePlain(", ")
}
ctx.WriteName(v.String())
}
ctx.WritePlain(")")
}
for _, value := range n.IndexHints {
ctx.WritePlain(" ")
if err := value.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while splicing IndexHints")
}
}
return nil
}
from parser.
A naive fix could be:
diff --git a/vendor/github.com/pingcap/parser/ast/dml.go b/vendor/github.com/pingcap/parser/ast/dml.go
index 483018f..95cf7d2 100644
--- a/vendor/github.com/pingcap/parser/ast/dml.go
+++ b/vendor/github.com/pingcap/parser/ast/dml.go
@@ -205,13 +205,6 @@ func (n *TableName) Restore(ctx *RestoreCtx) error {
}
ctx.WritePlain(")")
}
- for _, value := range n.IndexHints {
- ctx.WritePlain(" ")
- if err := value.Restore(ctx); err != nil {
- return errors.Annotate(err, "An error occurred while splicing IndexHints")
- }
- }
-
return nil
}
@@ -395,6 +388,14 @@ func (n *TableSource) Restore(ctx *RestoreCtx) error {
ctx.WriteKeyWord(" AS ")
ctx.WriteName(asName)
}
+ if tn, ok := n.Source.(*TableName); ok {
+ for _, value := range tn.IndexHints {
+ ctx.WritePlain(" ")
+ if err := value.Restore(ctx); err != nil {
+ return errors.Annotate(err, "An error occurred while splicing IndexHints")
+ }
+ }
+ }
return nil
}
from parser.
from parser.
The same issue as #538, already fixed in #539.
from parser.
Related Issues (20)
- how to get the table names from BinaryOperationExpr of where clause HOT 2
- cannot run the demo in README.md because of broken dependencies HOT 1
- The Collate in types.FieldType in ColumnDef seems to be always empty
- Invalid characters generated by goyacc? HOT 2
- how can use "with xx select" syntax HOT 4
- Parsing errors from mysqldump 8.0
- Error parsing default values for tables
- Provide an interface for other packages to obtain the provided symbol type
- Is it possible to extract table and its related columns from sql query? HOT 2
- Test_driver failed to process escaped char in string literal
- Mention this repo has been moved to pingcap/tidb HOT 1
- Ss
- Parsing errors from mysql dump HOT 4
- question: why SelectStmt do not have the WHERE condition(Clause) but only the ExprNode ? HOT 3
- Optimize parser performance HOT 1
- How to beautify sql with this package ? HOT 4
- Window Function syntax error
- Node.OriginTextPosition() always return 0 and Text() return empty
- The current parser does not support multi-statement SQL parsing. Is there any alternative method to solve this problem?
- character token too long: "identifier" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parser.