Skip to content

Commit

Permalink
Fixed collate, value_expression grammar closer to MySQL
Browse files Browse the repository at this point in the history
Signed-off-by: ritwizsinha <[email protected]>
  • Loading branch information
ritwizsinha committed Oct 29, 2021
1 parent 32b74e6 commit 39814b5
Show file tree
Hide file tree
Showing 15 changed files with 7,290 additions and 7,162 deletions.
12 changes: 6 additions & 6 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,6 @@ type ColumnType struct {

// Text field options
Charset string
Collate string

// Enum values
EnumValues []string
Expand All @@ -1535,6 +1534,7 @@ type ColumnTypeOptions struct {
As Expr
Comment *Literal
Storage ColumnStorage
Collate string
// Reference stores a foreign key constraint for the given column
Reference *ReferenceDefinition

Expand Down Expand Up @@ -1798,8 +1798,8 @@ type (
// ComparisonExprOperator is an enum for ComparisonExpr.Operator
ComparisonExprOperator int8

// RangeCond represents a BETWEEN or a NOT BETWEEN expression.
RangeCond struct {
// BetweenExpr represents a BETWEEN or a NOT BETWEEN expression.
BetweenExpr struct {
Operator RangeCondOperator
Left Expr
From, To Expr
Expand Down Expand Up @@ -1927,7 +1927,7 @@ type (
// SubstrExpr('static string value', value_expression, value_expression)
// In this case StrVal will be set instead of Name.
SubstrExpr struct {
Name *ColName
Name Expr
StrVal *Literal
From Expr
To Expr
Expand Down Expand Up @@ -1978,7 +1978,7 @@ type (
// supported functions are documented in the grammar
CurTimeFuncExpr struct {
Name ColIdent
Fsp Expr // fractional seconds precision, integer from 0 to 6
Fsp *Literal // fractional seconds precision, integer from 0 to 6
}

// ExtractedSubquery is a subquery that has been extracted from the original AST
Expand All @@ -2003,7 +2003,7 @@ func (*OrExpr) iExpr() {}
func (*XorExpr) iExpr() {}
func (*NotExpr) iExpr() {}
func (*ComparisonExpr) iExpr() {}
func (*RangeCond) iExpr() {}
func (*BetweenExpr) iExpr() {}
func (*IsExpr) iExpr() {}
func (*ExistsExpr) iExpr() {}
func (*Literal) iExpr() {}
Expand Down
36 changes: 18 additions & 18 deletions go/vt/sqlparser/ast_clone.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 29 additions & 30 deletions go/vt/sqlparser/ast_equals.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 10 additions & 13 deletions go/vt/sqlparser/ast_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,8 @@ func (ct *ColumnType) Format(buf *TrackedBuffer) {
if ct.Charset != "" {
buf.astPrintf(ct, " %s %s %s", keywordStrings[CHARACTER], keywordStrings[SET], ct.Charset)
}
if ct.Collate != "" {
buf.astPrintf(ct, " %s %s", keywordStrings[COLLATE], ct.Collate)
if ct.Options.Collate != "" {
buf.astPrintf(ct, " %s %s", keywordStrings[COLLATE], ct.Options.Collate)
}
if ct.Options.Null != nil && ct.Options.As == nil {
if *ct.Options.Null {
Expand Down Expand Up @@ -1008,7 +1008,7 @@ func (node *ComparisonExpr) Format(buf *TrackedBuffer) {
}

// Format formats the node.
func (node *RangeCond) Format(buf *TrackedBuffer) {
func (node *BetweenExpr) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "%v %s %l and %r", node.Left, node.Operator.ToString(), node.From, node.To)
}

Expand Down Expand Up @@ -1112,7 +1112,11 @@ func (node *TimestampFuncExpr) Format(buf *TrackedBuffer) {

// Format formats the node.
func (node *CurTimeFuncExpr) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "%s(%v)", node.Name.String(), node.Fsp)
if node.Fsp != nil {
buf.astPrintf(node, "%s(%v)", node.Name.String(), node.Fsp)
} else {
buf.astPrintf(node, "%s()", node.Name.String())
}
}

// Format formats the node.
Expand Down Expand Up @@ -1157,17 +1161,10 @@ func (node *ValuesFuncExpr) Format(buf *TrackedBuffer) {

// Format formats the node.
func (node *SubstrExpr) Format(buf *TrackedBuffer) {
var val SQLNode
if node.Name != nil {
val = node.Name
} else {
val = node.StrVal
}

if node.To == nil {
buf.astPrintf(node, "substr(%v, %v)", val, node.From)
buf.astPrintf(node, "substr(%v, %v)", node.Name, node.From)
} else {
buf.astPrintf(node, "substr(%v, %v, %v)", val, node.From, node.To)
buf.astPrintf(node, "substr(%v, %v, %v)", node.Name, node.From, node.To)
}
}

Expand Down
Loading

0 comments on commit 39814b5

Please sign in to comment.