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

Changed Collations and Expression grammar #9075

Merged
merged 13 commits into from
Nov 22, 2021
18 changes: 9 additions & 9 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,6 @@ type ColumnType struct {

// Text field options
Charset string
Collate string

// Enum values
EnumValues []string
Expand All @@ -1537,6 +1536,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 @@ -1800,11 +1800,11 @@ type (
// ComparisonExprOperator is an enum for ComparisonExpr.Operator
ComparisonExprOperator int8

// RangeCond represents a BETWEEN or a NOT BETWEEN expression.
RangeCond struct {
Operator RangeCondOperator
Left Expr
From, To Expr
// BetweenExpr represents a BETWEEN or a NOT BETWEEN expression.
BetweenExpr struct {
IsBetween bool
Left Expr
From, To Expr
}

// RangeCondOperator is an enum for RangeCond.Operator
Expand Down Expand Up @@ -1935,7 +1935,7 @@ type (
// SubstrExpr('static string value', value_expression, value_expression)
GuptaManan100 marked this conversation as resolved.
Show resolved Hide resolved
// In this case StrVal will be set instead of Name.
SubstrExpr struct {
ritwizsinha marked this conversation as resolved.
Show resolved Hide resolved
Name *ColName
Name Expr
StrVal *Literal
GuptaManan100 marked this conversation as resolved.
Show resolved Hide resolved
From Expr
To Expr
Expand Down Expand Up @@ -1986,7 +1986,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
ritwizsinha marked this conversation as resolved.
Show resolved Hide resolved
}

// ExtractedSubquery is a subquery that has been extracted from the original AST
Expand All @@ -2011,7 +2011,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.

29 changes: 15 additions & 14 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 != nil && 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,8 +1008,12 @@ func (node *ComparisonExpr) Format(buf *TrackedBuffer) {
}

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

// Format formats the node.
Expand Down Expand Up @@ -1117,7 +1121,11 @@ func (node *ExtractFuncExpr) 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 @@ -1162,17 +1170,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