diff --git a/Makefile b/Makefile index f90016290ff..cecb52b0e21 100644 --- a/Makefile +++ b/Makefile @@ -103,7 +103,7 @@ parser: make -C go/vt/sqlparser visitor: - go run ./go/tools/asthelpergen -in ./go/vt/sqlparser -iface vitess.io/vitess/go/vt/sqlparser.SQLNode -except "*ColName" + go run ./go/tools/asthelpergen/main -in ./go/vt/sqlparser -iface vitess.io/vitess/go/vt/sqlparser.SQLNode -except "*ColName" sizegen: go run go/tools/sizegen/sizegen.go \ diff --git a/go/tools/asthelpergen/asthelpergen.go b/go/tools/asthelpergen/asthelpergen.go index e1bfdf385bb..f052d1579a4 100644 --- a/go/tools/asthelpergen/asthelpergen.go +++ b/go/tools/asthelpergen/asthelpergen.go @@ -14,15 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package asthelpergen import ( "bytes" - "flag" "fmt" "go/types" "io/ioutil" - "log" "path" "strings" @@ -170,48 +168,19 @@ func (gen *astHelperGen) GenerateCode() (map[string]*jen.File, error) { return result, nil } -type typePaths []string +// TypePaths are the packages +type TypePaths []string -func (t *typePaths) String() string { +func (t *TypePaths) String() string { return fmt.Sprintf("%v", *t) } -func (t *typePaths) Set(path string) error { +// Set adds the package path +func (t *TypePaths) Set(path string) error { *t = append(*t, path) return nil } -func main() { - var patterns typePaths - var generate, except string - var verify bool - - flag.Var(&patterns, "in", "Go packages to load the generator") - flag.StringVar(&generate, "iface", "", "Root interface generate rewriter for") - flag.BoolVar(&verify, "verify", false, "ensure that the generated files are correct") - flag.StringVar(&except, "except", "", "don't deep clone these types") - flag.Parse() - - result, err := GenerateASTHelpers(patterns, generate, except) - if err != nil { - log.Fatal(err) - } - - if verify { - for _, err := range VerifyFilesOnDisk(result) { - log.Fatal(err) - } - log.Printf("%d files OK", len(result)) - } else { - for fullPath, file := range result { - if err := file.Save(fullPath); err != nil { - log.Fatalf("failed to save file to '%s': %v", fullPath, err) - } - log.Printf("saved '%s'", fullPath) - } - } -} - // VerifyFilesOnDisk compares the generated results from the codegen against the files that // currently exist on disk and returns any mismatches func VerifyFilesOnDisk(result map[string]*jen.File) (errors []error) { diff --git a/go/tools/asthelpergen/asthelpergen_test.go b/go/tools/asthelpergen/asthelpergen_test.go index 30dc2eb61a5..16372b13d75 100644 --- a/go/tools/asthelpergen/asthelpergen_test.go +++ b/go/tools/asthelpergen/asthelpergen_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package asthelpergen import ( "fmt" diff --git a/go/tools/asthelpergen/clone_gen.go b/go/tools/asthelpergen/clone_gen.go index 066a4c82923..8d86318c1a9 100644 --- a/go/tools/asthelpergen/clone_gen.go +++ b/go/tools/asthelpergen/clone_gen.go @@ -14,13 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package asthelpergen import ( "fmt" "go/types" - - "vitess.io/vitess/go/vt/log" + "log" + "strings" "github.com/dave/jennifer/jen" ) @@ -61,8 +61,22 @@ func (c *cloneGen) visitInterface(t types.Type, _ *types.Interface) error { const cloneName = "Clone" -func (c *cloneGen) addFunc(name string, code jen.Code) { - c.methods = append(c.methods, jen.Comment(name+" creates a deep clone of the input."), code) +type methodType int + +const ( + clone methodType = iota + equals +) + +func (c *cloneGen) addFunc(name string, typ methodType, code jen.Code) { + var comment string + switch typ { + case clone: + comment = " creates a deep clone of the input." + case equals: + comment = " does deep equals between the two objects." + } + c.methods = append(c.methods, jen.Comment(name+comment), code) } // readValueOfType produces code to read the expression of type `t`, and adds the type to the todo-list @@ -81,10 +95,10 @@ func (c *cloneGen) readValueOfType(t types.Type, expr jen.Code) jen.Code { } func (c *cloneGen) makeStructCloneMethod(t types.Type) error { - receiveType := types.TypeString(t, noQualifier) - funcName := "Clone" + printableTypeName(t) - c.addFunc(funcName, - jen.Func().Id(funcName).Call(jen.Id("n").Id(receiveType)).Id(receiveType).Block( + typeString := types.TypeString(t, noQualifier) + funcName := cloneName + printableTypeName(t) + c.addFunc(funcName, clone, + jen.Func().Id(funcName).Call(jen.Id("n").Id(typeString)).Id(typeString).Block( jen.Return(jen.Op("*").Add(c.readValueOfType(types.NewPointer(t), jen.Op("&").Id("n")))), )) return nil @@ -95,7 +109,7 @@ func (c *cloneGen) makeSliceCloneMethod(t types.Type, slice *types.Slice) error name := printableTypeName(t) funcName := cloneName + name - c.addFunc(funcName, + c.addFunc(funcName, clone, //func (n Bytes) Clone() Bytes { jen.Func().Id(funcName).Call(jen.Id("n").Id(typeString)).Id(typeString).Block( // res := make(Bytes, len(n)) @@ -161,7 +175,7 @@ func (c *cloneGen) makeInterfaceCloneMethod(t types.Type, iface *types.Interface } default: - log.Errorf("unexpected type encountered: %s", typeString) + log.Fatalf("unexpected type encountered: %s", typeString) } return nil @@ -180,22 +194,20 @@ func (c *cloneGen) makeInterfaceCloneMethod(t types.Type, iface *types.Interface funcName := cloneName + typeName funcDecl := jen.Func().Id(funcName).Call(jen.Id("in").Id(typeString)).Id(typeString).Block(stmts...) - c.addFunc(funcName, funcDecl) + c.addFunc(funcName, clone, funcDecl) return nil } -func (c *cloneGen) makePtrCloneMethod(t types.Type, ptr *types.Pointer) error { +func (c *cloneGen) makePtrCloneMethod(t types.Type, ptr *types.Pointer) { receiveType := types.TypeString(t, noQualifier) funcName := "Clone" + printableTypeName(t) - c.addFunc(funcName, + c.addFunc(funcName, clone, jen.Func().Id(funcName).Call(jen.Id("n").Id(receiveType)).Id(receiveType).Block( ifNilReturnNil("n"), jen.Id("out").Op(":=").Add(c.readValueOfType(ptr.Elem(), jen.Op("*").Id("n"))), jen.Return(jen.Op("&").Id("out")), )) - - return nil } func (c *cloneGen) createFile(pkgName string) (string, *jen.File) { @@ -221,7 +233,7 @@ func (c *cloneGen) createFile(pkgName string) (string, *jen.File) { continue } - log.Errorf("don't know how to handle %s %T", typeName, underlying) + log.Fatalf("don't know how to handle %s %T", typeName, underlying) } for _, method := range c.methods { @@ -241,14 +253,16 @@ func isBasic(t types.Type) bool { } func (c *cloneGen) tryStruct(underlying, t types.Type) bool { - _, ok := underlying.(*types.Struct) + strct, ok := underlying.(*types.Struct) if !ok { return false } - err := c.makeStructCloneMethod(t) - if err != nil { - panic(err) // todo + if err := c.makeStructCloneMethod(t); err != nil { + log.Fatalf("%v", err) + } + if err := c.makeStructEqualsMethod(t, strct); err != nil { + log.Fatalf("%v", err) } return true } @@ -258,27 +272,33 @@ func (c *cloneGen) tryPtr(underlying, t types.Type) bool { return false } - if strct, isStruct := ptr.Elem().Underlying().(*types.Struct); isStruct { - c.makePtrToStructCloneMethod(t, strct) + ptrToType := ptr.Elem().Underlying() + + switch ptrToType := ptrToType.(type) { + case *types.Struct: + c.makePtrToStructCloneMethod(t, ptrToType) + c.makePtrToStructEqualsMethod(t, ptrToType) return true + case *types.Basic: + c.makePtrToBasicEqualsMethod(t) + c.makePtrCloneMethod(t, ptr) + return true + default: + c.makePtrCloneMethod(t, ptr) } - err := c.makePtrCloneMethod(t, ptr) - if err != nil { - panic(err) // todo - } return true } func (c *cloneGen) makePtrToStructCloneMethod(t types.Type, strct *types.Struct) { receiveType := types.TypeString(t, noQualifier) - funcName := "Clone" + printableTypeName(t) + funcName := cloneName + printableTypeName(t) //func CloneRefOfType(n *Type) *Type funcDeclaration := jen.Func().Id(funcName).Call(jen.Id("n").Id(receiveType)).Id(receiveType) if receiveType == c.exceptType { - c.addFunc(funcName, funcDeclaration.Block( + c.addFunc(funcName, clone, funcDeclaration.Block( jen.Return(jen.Id("n")), )) return @@ -310,7 +330,7 @@ func (c *cloneGen) makePtrToStructCloneMethod(t types.Type, strct *types.Struct) jen.Return(jen.Op("&").Id("out")), ) - c.addFunc(funcName, + c.addFunc(funcName, clone, funcDeclaration.Block(stmts...), ) } @@ -321,9 +341,12 @@ func (c *cloneGen) tryInterface(underlying, t types.Type) bool { return false } - err := c.makeInterfaceCloneMethod(t, iface) - if err != nil { - panic(err) // todo + if err := c.makeInterfaceCloneMethod(t, iface); err != nil { + log.Fatalf("%v", err) + } + + if err := c.makeInterfaceEqualsMethod(t, iface); err != nil { + log.Fatalf("%v", err) } return true } @@ -334,9 +357,11 @@ func (c *cloneGen) trySlice(underlying, t types.Type) bool { return false } - err := c.makeSliceCloneMethod(t, slice) - if err != nil { - panic(err) // todo + if err := c.makeSliceCloneMethod(t, slice); err != nil { + log.Fatalf("%v", err) + } + if err := c.makeSliceEqualsMethod(t, slice); err != nil { + log.Fatalf("%v", err) } return true } @@ -351,7 +376,7 @@ func printableTypeName(t types.Type) string { case *types.Named: return t.Obj().Name() case *types.Basic: - return t.Name() + return strings.Title(t.Name()) case *types.Interface: return t.String() default: diff --git a/go/tools/asthelpergen/equals_gen.go b/go/tools/asthelpergen/equals_gen.go new file mode 100644 index 00000000000..76756bf0bec --- /dev/null +++ b/go/tools/asthelpergen/equals_gen.go @@ -0,0 +1,212 @@ +package asthelpergen + +import ( + "go/types" + + "github.com/dave/jennifer/jen" +) + +const equalsName = "Equals" + +func (c *cloneGen) makeInterfaceEqualsMethod(t types.Type, iface *types.Interface) error { + + /* + func EqualsAST(inA, inB AST) bool { + if inA == inB { + return true + } + if inA == nil || inB8 == nil { + return false + } + switch a := inA.(type) { + case *SubImpl: + b, ok := inB.(*SubImpl) + if !ok { + return false + } + return EqualsSubImpl(a, b) + } + return false + } + */ + stmts := []jen.Code{ + jen.If(jen.Id("inA == nil").Op("&&").Id("inB == nil")).Block(jen.Return(jen.True())), + jen.If(jen.Id("inA == nil").Op("||").Id("inB == nil")).Block(jen.Return(jen.False())), + } + + var cases []jen.Code + _ = findImplementations(c.scope, iface, func(t types.Type) error { + if _, ok := t.Underlying().(*types.Interface); ok { + return nil + } + typeString := types.TypeString(t, noQualifier) + caseBlock := jen.Case(jen.Id(typeString)).Block( + jen.Id("b, ok := inB.").Call(jen.Id(typeString)), + jen.If(jen.Id("!ok")).Block(jen.Return(jen.False())), + jen.Return(c.compareValueType(t, jen.Id("a"), jen.Id("b"), true)), + ) + cases = append(cases, caseBlock) + return nil + }) + + cases = append(cases, + jen.Default().Block( + jen.Comment("this should never happen"), + jen.Return(jen.False()), + )) + + stmts = append(stmts, jen.Switch(jen.Id("a := inA.(type)").Block( + cases..., + ))) + + typeString := types.TypeString(t, noQualifier) + funcName := equalsName + printableTypeName(t) + funcDecl := jen.Func().Id(funcName).Call(jen.List(jen.Id("inA"), jen.Id("inB")).Id(typeString)).Bool().Block(stmts...) + c.addFunc(funcName, equals, funcDecl) + + return nil +} + +func (c *cloneGen) compareValueType(t types.Type, a, b *jen.Statement, eq bool) *jen.Statement { + switch t.Underlying().(type) { + case *types.Basic: + if eq { + return a.Op("==").Add(b) + } + return a.Op("!=").Add(b) + } + + c.todo = append(c.todo, t) + var neg = "!" + if eq { + neg = "" + } + return jen.Id(neg+equalsName+printableTypeName(t)).Call(a, b) +} + +func (c *cloneGen) makeStructEqualsMethod(t types.Type, strct *types.Struct) error { + /* + func EqualsRefOfRefContainer(inA RefContainer, inB RefContainer) bool { + return EqualsRefOfLeaf(inA.ASTImplementationType, inB.ASTImplementationType) && + EqualsAST(inA.ASTType, inB.ASTType) && inA.NotASTType == inB.NotASTType + } + + */ + + typeString := types.TypeString(t, noQualifier) + funcName := equalsName + printableTypeName(t) + funcDecl := jen.Func().Id(funcName).Call(jen.List(jen.Id("a"), jen.Id("b")).Id(typeString)).Bool(). + Block(jen.Return(c.compareAllStructFields(strct))) + c.addFunc(funcName, equals, funcDecl) + + return nil +} + +func (c *cloneGen) compareAllStructFields(strct *types.Struct) jen.Code { + var basicsPred []*jen.Statement + var others []*jen.Statement + for i := 0; i < strct.NumFields(); i++ { + field := strct.Field(i) + if field.Type().Underlying().String() == "interface{}" || field.Name() == "_" { + // we can safely ignore this, we do not want ast to contain interface{} types. + continue + } + fieldA := jen.Id("a").Dot(field.Name()) + fieldB := jen.Id("b").Dot(field.Name()) + pred := c.compareValueType(field.Type(), fieldA, fieldB, true) + if _, ok := field.Type().(*types.Basic); ok { + basicsPred = append(basicsPred, pred) + continue + } + others = append(others, pred) + } + + var ret *jen.Statement + for _, pred := range basicsPred { + if ret == nil { + ret = pred + } else { + ret = ret.Op("&&").Line().Add(pred) + } + } + + for _, pred := range others { + if ret == nil { + ret = pred + } else { + ret = ret.Op("&&").Line().Add(pred) + } + } + + if ret == nil { + return jen.True() + } + return ret +} + +func (c *cloneGen) makePtrToStructEqualsMethod(t types.Type, strct *types.Struct) { + typeString := types.TypeString(t, noQualifier) + funcName := equalsName + printableTypeName(t) + + //func EqualsRefOfType(a,b *Type) *Type + funcDeclaration := jen.Func().Id(funcName).Call(jen.Id("a"), jen.Id("b").Id(typeString)).Bool() + stmts := []jen.Code{ + jen.If(jen.Id("a == b")).Block(jen.Return(jen.True())), + jen.If(jen.Id("a == nil").Op("||").Id("b == nil")).Block(jen.Return(jen.False())), + jen.Return(c.compareAllStructFields(strct)), + } + + c.addFunc(funcName, equals, funcDeclaration.Block(stmts...)) +} +func (c *cloneGen) makePtrToBasicEqualsMethod(t types.Type) { + /* + func EqualsRefOfBool(a, b *bool) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return *a == *b + } + */ + typeString := types.TypeString(t, noQualifier) + funcName := equalsName + printableTypeName(t) + + //func EqualsRefOfType(a,b *Type) *Type + funcDeclaration := jen.Func().Id(funcName).Call(jen.Id("a"), jen.Id("b").Id(typeString)).Bool() + stmts := []jen.Code{ + jen.If(jen.Id("a == b")).Block(jen.Return(jen.True())), + jen.If(jen.Id("a == nil").Op("||").Id("b == nil")).Block(jen.Return(jen.False())), + jen.Return(jen.Id("*a == *b")), + } + c.addFunc(funcName, equals, funcDeclaration.Block(stmts...)) +} + +func (c *cloneGen) makeSliceEqualsMethod(t types.Type, slice *types.Slice) error { + /* + func EqualsSliceOfRefOfLeaf(a, b []*Leaf) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfLeaf(a[i], b[i]) { + return false + } + } + return false + } + */ + + stmts := []jen.Code{jen.If(jen.Id("len(a) != len(b)")).Block(jen.Return(jen.False())), + jen.For(jen.Id("i := 0; i < len(a); i++")).Block( + jen.If(c.compareValueType(slice.Elem(), jen.Id("a[i]"), jen.Id("b[i]"), false)).Block(jen.Return(jen.False()))), + jen.Return(jen.True()), + } + + typeString := types.TypeString(t, noQualifier) + funcName := equalsName + printableTypeName(t) + funcDecl := jen.Func().Id(funcName).Call(jen.List(jen.Id("a"), jen.Id("b")).Id(typeString)).Bool().Block(stmts...) + c.addFunc(funcName, equals, funcDecl) + return nil +} diff --git a/go/tools/asthelpergen/integration/clone.go b/go/tools/asthelpergen/integration/clone.go index 84d1c2b7537..fda3a414e66 100644 --- a/go/tools/asthelpergen/integration/clone.go +++ b/go/tools/asthelpergen/integration/clone.go @@ -53,6 +53,93 @@ func CloneAST(in AST) AST { } } +// EqualsAST does deep equals between the two objects. +func EqualsAST(inA, inB AST) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case BasicType: + b, ok := inB.(BasicType) + if !ok { + return false + } + return a == b + case Bytes: + b, ok := inB.(Bytes) + if !ok { + return false + } + return EqualsBytes(a, b) + case InterfaceContainer: + b, ok := inB.(InterfaceContainer) + if !ok { + return false + } + return EqualsInterfaceContainer(a, b) + case InterfaceSlice: + b, ok := inB.(InterfaceSlice) + if !ok { + return false + } + return EqualsInterfaceSlice(a, b) + case *Leaf: + b, ok := inB.(*Leaf) + if !ok { + return false + } + return EqualsRefOfLeaf(a, b) + case LeafSlice: + b, ok := inB.(LeafSlice) + if !ok { + return false + } + return EqualsLeafSlice(a, b) + case *NoCloneType: + b, ok := inB.(*NoCloneType) + if !ok { + return false + } + return EqualsRefOfNoCloneType(a, b) + case *RefContainer: + b, ok := inB.(*RefContainer) + if !ok { + return false + } + return EqualsRefOfRefContainer(a, b) + case *RefSliceContainer: + b, ok := inB.(*RefSliceContainer) + if !ok { + return false + } + return EqualsRefOfRefSliceContainer(a, b) + case *SubImpl: + b, ok := inB.(*SubImpl) + if !ok { + return false + } + return EqualsRefOfSubImpl(a, b) + case ValueContainer: + b, ok := inB.(ValueContainer) + if !ok { + return false + } + return EqualsValueContainer(a, b) + case ValueSliceContainer: + b, ok := inB.(ValueSliceContainer) + if !ok { + return false + } + return EqualsValueSliceContainer(a, b) + default: + // this should never happen + return false + } +} + // CloneSubIface creates a deep clone of the input. func CloneSubIface(in SubIface) SubIface { if in == nil { @@ -67,6 +154,27 @@ func CloneSubIface(in SubIface) SubIface { } } +// EqualsSubIface does deep equals between the two objects. +func EqualsSubIface(inA, inB SubIface) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case *SubImpl: + b, ok := inB.(*SubImpl) + if !ok { + return false + } + return EqualsRefOfSubImpl(a, b) + default: + // this should never happen + return false + } +} + // CloneBytes creates a deep clone of the input. func CloneBytes(n Bytes) Bytes { res := make(Bytes, 0, len(n)) @@ -74,11 +182,29 @@ func CloneBytes(n Bytes) Bytes { return res } +// EqualsBytes does deep equals between the two objects. +func EqualsBytes(a, b Bytes) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if a[i] != b[i] { + return false + } + } + return true +} + // CloneInterfaceContainer creates a deep clone of the input. func CloneInterfaceContainer(n InterfaceContainer) InterfaceContainer { return *CloneRefOfInterfaceContainer(&n) } +// EqualsInterfaceContainer does deep equals between the two objects. +func EqualsInterfaceContainer(a, b InterfaceContainer) bool { + return true +} + // CloneInterfaceSlice creates a deep clone of the input. func CloneInterfaceSlice(n InterfaceSlice) InterfaceSlice { res := make(InterfaceSlice, 0, len(n)) @@ -88,6 +214,19 @@ func CloneInterfaceSlice(n InterfaceSlice) InterfaceSlice { return res } +// EqualsInterfaceSlice does deep equals between the two objects. +func EqualsInterfaceSlice(a, b InterfaceSlice) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsAST(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfLeaf creates a deep clone of the input. func CloneRefOfLeaf(n *Leaf) *Leaf { if n == nil { @@ -97,6 +236,17 @@ func CloneRefOfLeaf(n *Leaf) *Leaf { return &out } +// EqualsRefOfLeaf does deep equals between the two objects. +func EqualsRefOfLeaf(a, b *Leaf) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.v == b.v +} + // CloneLeafSlice creates a deep clone of the input. func CloneLeafSlice(n LeafSlice) LeafSlice { res := make(LeafSlice, 0, len(n)) @@ -106,11 +256,35 @@ func CloneLeafSlice(n LeafSlice) LeafSlice { return res } +// EqualsLeafSlice does deep equals between the two objects. +func EqualsLeafSlice(a, b LeafSlice) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfLeaf(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfNoCloneType creates a deep clone of the input. func CloneRefOfNoCloneType(n *NoCloneType) *NoCloneType { return n } +// EqualsRefOfNoCloneType does deep equals between the two objects. +func EqualsRefOfNoCloneType(a, b *NoCloneType) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.v == b.v +} + // CloneRefOfRefContainer creates a deep clone of the input. func CloneRefOfRefContainer(n *RefContainer) *RefContainer { if n == nil { @@ -122,6 +296,19 @@ func CloneRefOfRefContainer(n *RefContainer) *RefContainer { return &out } +// EqualsRefOfRefContainer does deep equals between the two objects. +func EqualsRefOfRefContainer(a, b *RefContainer) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.NotASTType == b.NotASTType && + EqualsAST(a.ASTType, b.ASTType) && + EqualsRefOfLeaf(a.ASTImplementationType, b.ASTImplementationType) +} + // CloneRefOfRefSliceContainer creates a deep clone of the input. func CloneRefOfRefSliceContainer(n *RefSliceContainer) *RefSliceContainer { if n == nil { @@ -129,11 +316,24 @@ func CloneRefOfRefSliceContainer(n *RefSliceContainer) *RefSliceContainer { } out := *n out.ASTElements = CloneSliceOfAST(n.ASTElements) - out.NotASTElements = CloneSliceOfint(n.NotASTElements) + out.NotASTElements = CloneSliceOfInt(n.NotASTElements) out.ASTImplementationElements = CloneSliceOfRefOfLeaf(n.ASTImplementationElements) return &out } +// EqualsRefOfRefSliceContainer does deep equals between the two objects. +func EqualsRefOfRefSliceContainer(a, b *RefSliceContainer) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsSliceOfAST(a.ASTElements, b.ASTElements) && + EqualsSliceOfInt(a.NotASTElements, b.NotASTElements) && + EqualsSliceOfRefOfLeaf(a.ASTImplementationElements, b.ASTImplementationElements) +} + // CloneRefOfSubImpl creates a deep clone of the input. func CloneRefOfSubImpl(n *SubImpl) *SubImpl { if n == nil { @@ -141,19 +341,46 @@ func CloneRefOfSubImpl(n *SubImpl) *SubImpl { } out := *n out.inner = CloneSubIface(n.inner) + out.field = CloneRefOfBool(n.field) return &out } +// EqualsRefOfSubImpl does deep equals between the two objects. +func EqualsRefOfSubImpl(a, b *SubImpl) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsSubIface(a.inner, b.inner) && + EqualsRefOfBool(a.field, b.field) +} + // CloneValueContainer creates a deep clone of the input. func CloneValueContainer(n ValueContainer) ValueContainer { return *CloneRefOfValueContainer(&n) } +// EqualsValueContainer does deep equals between the two objects. +func EqualsValueContainer(a, b ValueContainer) bool { + return a.NotASTType == b.NotASTType && + EqualsAST(a.ASTType, b.ASTType) && + EqualsRefOfLeaf(a.ASTImplementationType, b.ASTImplementationType) +} + // CloneValueSliceContainer creates a deep clone of the input. func CloneValueSliceContainer(n ValueSliceContainer) ValueSliceContainer { return *CloneRefOfValueSliceContainer(&n) } +// EqualsValueSliceContainer does deep equals between the two objects. +func EqualsValueSliceContainer(a, b ValueSliceContainer) bool { + return EqualsSliceOfAST(a.ASTElements, b.ASTElements) && + EqualsSliceOfInt(a.NotASTElements, b.NotASTElements) && + EqualsSliceOfRefOfLeaf(a.ASTImplementationElements, b.ASTImplementationElements) +} + // CloneRefOfInterfaceContainer creates a deep clone of the input. func CloneRefOfInterfaceContainer(n *InterfaceContainer) *InterfaceContainer { if n == nil { @@ -164,6 +391,17 @@ func CloneRefOfInterfaceContainer(n *InterfaceContainer) *InterfaceContainer { return &out } +// EqualsRefOfInterfaceContainer does deep equals between the two objects. +func EqualsRefOfInterfaceContainer(a, b *InterfaceContainer) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return true +} + // CloneSliceOfAST creates a deep clone of the input. func CloneSliceOfAST(n []AST) []AST { res := make([]AST, 0, len(n)) @@ -173,13 +411,39 @@ func CloneSliceOfAST(n []AST) []AST { return res } -// CloneSliceOfint creates a deep clone of the input. -func CloneSliceOfint(n []int) []int { +// EqualsSliceOfAST does deep equals between the two objects. +func EqualsSliceOfAST(a, b []AST) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsAST(a[i], b[i]) { + return false + } + } + return true +} + +// CloneSliceOfInt creates a deep clone of the input. +func CloneSliceOfInt(n []int) []int { res := make([]int, 0, len(n)) copy(res, n) return res } +// EqualsSliceOfInt does deep equals between the two objects. +func EqualsSliceOfInt(a, b []int) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if a[i] != b[i] { + return false + } + } + return true +} + // CloneSliceOfRefOfLeaf creates a deep clone of the input. func CloneSliceOfRefOfLeaf(n []*Leaf) []*Leaf { res := make([]*Leaf, 0, len(n)) @@ -189,6 +453,39 @@ func CloneSliceOfRefOfLeaf(n []*Leaf) []*Leaf { return res } +// EqualsSliceOfRefOfLeaf does deep equals between the two objects. +func EqualsSliceOfRefOfLeaf(a, b []*Leaf) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfLeaf(a[i], b[i]) { + return false + } + } + return true +} + +// EqualsRefOfBool does deep equals between the two objects. +func EqualsRefOfBool(a, b *bool) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return *a == *b +} + +// CloneRefOfBool creates a deep clone of the input. +func CloneRefOfBool(n *bool) *bool { + if n == nil { + return nil + } + out := *n + return &out +} + // CloneRefOfValueContainer creates a deep clone of the input. func CloneRefOfValueContainer(n *ValueContainer) *ValueContainer { if n == nil { @@ -200,6 +497,19 @@ func CloneRefOfValueContainer(n *ValueContainer) *ValueContainer { return &out } +// EqualsRefOfValueContainer does deep equals between the two objects. +func EqualsRefOfValueContainer(a, b *ValueContainer) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.NotASTType == b.NotASTType && + EqualsAST(a.ASTType, b.ASTType) && + EqualsRefOfLeaf(a.ASTImplementationType, b.ASTImplementationType) +} + // CloneRefOfValueSliceContainer creates a deep clone of the input. func CloneRefOfValueSliceContainer(n *ValueSliceContainer) *ValueSliceContainer { if n == nil { @@ -207,7 +517,20 @@ func CloneRefOfValueSliceContainer(n *ValueSliceContainer) *ValueSliceContainer } out := *n out.ASTElements = CloneSliceOfAST(n.ASTElements) - out.NotASTElements = CloneSliceOfint(n.NotASTElements) + out.NotASTElements = CloneSliceOfInt(n.NotASTElements) out.ASTImplementationElements = CloneSliceOfRefOfLeaf(n.ASTImplementationElements) return &out } + +// EqualsRefOfValueSliceContainer does deep equals between the two objects. +func EqualsRefOfValueSliceContainer(a, b *ValueSliceContainer) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsSliceOfAST(a.ASTElements, b.ASTElements) && + EqualsSliceOfInt(a.NotASTElements, b.NotASTElements) && + EqualsSliceOfRefOfLeaf(a.ASTImplementationElements, b.ASTImplementationElements) +} diff --git a/go/tools/asthelpergen/integration/integration_equals_test.go b/go/tools/asthelpergen/integration/integration_equals_test.go new file mode 100644 index 00000000000..df3316cfe17 --- /dev/null +++ b/go/tools/asthelpergen/integration/integration_equals_test.go @@ -0,0 +1,70 @@ +/* +Copyright 2021 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package integration + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestEquals(t *testing.T) { + for idxA, objA := range createObjs() { + for idxB, objB := range createObjs() { + t.Run(fmt.Sprintf("%s == %s", name(objA), name(objB)), func(t *testing.T) { + if idxA == idxB { + require.True(t, EqualsAST(objA, objB)) + } else { + require.False(t, EqualsAST(objA, objB)) + } + }) + } + } +} + +func createObjs() []AST { + t := true + return []AST{ + nil, + &Leaf{1}, + &Leaf{2}, + &RefContainer{ASTType: &Leaf{1}, ASTImplementationType: &Leaf{2}}, + ValueContainer{ASTType: ValueContainer{ASTType: &Leaf{1}, ASTImplementationType: &Leaf{2}}}, + &RefSliceContainer{ASTElements: []AST{&Leaf{1}, &Leaf{2}}, ASTImplementationElements: []*Leaf{{3}, {4}}}, + ValueSliceContainer{ASTElements: []AST{&Leaf{1}, &Leaf{2}}, ASTImplementationElements: []*Leaf{{3}, {4}}}, + InterfaceSlice{ + &RefContainer{ + ASTType: &RefContainer{NotASTType: 12}, + ASTImplementationType: &Leaf{2}, + }, + &Leaf{2}, + &Leaf{3}, + }, + &SubImpl{ + inner: &SubImpl{}, + field: &t, + }, + } +} + +func name(a AST) string { + if a == nil { + return "nil" + } + return a.String() +} diff --git a/go/tools/asthelpergen/integration/types.go b/go/tools/asthelpergen/integration/types.go index 1a89d78c3a2..043c97d87aa 100644 --- a/go/tools/asthelpergen/integration/types.go +++ b/go/tools/asthelpergen/integration/types.go @@ -26,7 +26,7 @@ import ( These types are used to test the rewriter generator against these types. To recreate them, just run: -go run go/tools/asthelpergen -in ./go/tools/asthelpergen/integration -iface vitess.io/vitess/go/tools/asthelpergen/integration.AST +go run go/tools/asthelpergen -in ./go/tools/asthelpergen/integration -iface vitess.io/vitess/go/tools/asthelpergen/integration.AST -except "*NoCloneType" */ // AST is the interface all interface types implement type AST interface { @@ -148,6 +148,7 @@ type SubIface interface { type SubImpl struct { inner SubIface + field *bool } func (r *SubImpl) String() string { diff --git a/go/tools/asthelpergen/main/main.go b/go/tools/asthelpergen/main/main.go new file mode 100644 index 00000000000..9225aa7615d --- /dev/null +++ b/go/tools/asthelpergen/main/main.go @@ -0,0 +1,39 @@ +package main + +import ( + "flag" + "log" + + . "vitess.io/vitess/go/tools/asthelpergen" +) + +func main() { + var patterns TypePaths + var generate, except string + var verify bool + + flag.Var(&patterns, "in", "Go packages to load the generator") + flag.StringVar(&generate, "iface", "", "Root interface generate rewriter for") + flag.BoolVar(&verify, "verify", false, "ensure that the generated files are correct") + flag.StringVar(&except, "except", "", "don't deep clone these types") + flag.Parse() + + result, err := GenerateASTHelpers(patterns, generate, except) + if err != nil { + log.Fatal(err) + } + + if verify { + for _, err := range VerifyFilesOnDisk(result) { + log.Fatal(err) + } + log.Printf("%d files OK", len(result)) + } else { + for fullPath, file := range result { + if err := file.Save(fullPath); err != nil { + log.Fatalf("failed to save file to '%s': %v", fullPath, err) + } + log.Printf("saved '%s'", fullPath) + } + } +} diff --git a/go/tools/asthelpergen/rewriter_gen.go b/go/tools/asthelpergen/rewriter_gen.go index 54a0ca8e093..b7bedbe5cc8 100644 --- a/go/tools/asthelpergen/rewriter_gen.go +++ b/go/tools/asthelpergen/rewriter_gen.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package asthelpergen import ( "go/types" diff --git a/go/vt/sqlparser/clone.go b/go/vt/sqlparser/clone.go index 26cd8c8b712..7c70637a4cf 100644 --- a/go/vt/sqlparser/clone.go +++ b/go/vt/sqlparser/clone.go @@ -67,6 +67,135 @@ func CloneAlterOption(in AlterOption) AlterOption { } } +// EqualsAlterOption does deep equals between the two objects. +func EqualsAlterOption(inA, inB AlterOption) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case *AddColumns: + b, ok := inB.(*AddColumns) + if !ok { + return false + } + return EqualsRefOfAddColumns(a, b) + case *AddConstraintDefinition: + b, ok := inB.(*AddConstraintDefinition) + if !ok { + return false + } + return EqualsRefOfAddConstraintDefinition(a, b) + case *AddIndexDefinition: + b, ok := inB.(*AddIndexDefinition) + if !ok { + return false + } + return EqualsRefOfAddIndexDefinition(a, b) + case AlgorithmValue: + b, ok := inB.(AlgorithmValue) + if !ok { + return false + } + return a == b + case *AlterCharset: + b, ok := inB.(*AlterCharset) + if !ok { + return false + } + return EqualsRefOfAlterCharset(a, b) + case *AlterColumn: + b, ok := inB.(*AlterColumn) + if !ok { + return false + } + return EqualsRefOfAlterColumn(a, b) + case *ChangeColumn: + b, ok := inB.(*ChangeColumn) + if !ok { + return false + } + return EqualsRefOfChangeColumn(a, b) + case *DropColumn: + b, ok := inB.(*DropColumn) + if !ok { + return false + } + return EqualsRefOfDropColumn(a, b) + case *DropKey: + b, ok := inB.(*DropKey) + if !ok { + return false + } + return EqualsRefOfDropKey(a, b) + case *Force: + b, ok := inB.(*Force) + if !ok { + return false + } + return EqualsRefOfForce(a, b) + case *KeyState: + b, ok := inB.(*KeyState) + if !ok { + return false + } + return EqualsRefOfKeyState(a, b) + case *LockOption: + b, ok := inB.(*LockOption) + if !ok { + return false + } + return EqualsRefOfLockOption(a, b) + case *ModifyColumn: + b, ok := inB.(*ModifyColumn) + if !ok { + return false + } + return EqualsRefOfModifyColumn(a, b) + case *OrderByOption: + b, ok := inB.(*OrderByOption) + if !ok { + return false + } + return EqualsRefOfOrderByOption(a, b) + case *RenameIndex: + b, ok := inB.(*RenameIndex) + if !ok { + return false + } + return EqualsRefOfRenameIndex(a, b) + case *RenameTableName: + b, ok := inB.(*RenameTableName) + if !ok { + return false + } + return EqualsRefOfRenameTableName(a, b) + case TableOptions: + b, ok := inB.(TableOptions) + if !ok { + return false + } + return EqualsTableOptions(a, b) + case *TablespaceOperation: + b, ok := inB.(*TablespaceOperation) + if !ok { + return false + } + return EqualsRefOfTablespaceOperation(a, b) + case *Validation: + b, ok := inB.(*Validation) + if !ok { + return false + } + return EqualsRefOfValidation(a, b) + default: + // this should never happen + return false + } +} + // CloneCharacteristic creates a deep clone of the input. func CloneCharacteristic(in Characteristic) Characteristic { if in == nil { @@ -83,6 +212,33 @@ func CloneCharacteristic(in Characteristic) Characteristic { } } +// EqualsCharacteristic does deep equals between the two objects. +func EqualsCharacteristic(inA, inB Characteristic) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case AccessMode: + b, ok := inB.(AccessMode) + if !ok { + return false + } + return a == b + case IsolationLevel: + b, ok := inB.(IsolationLevel) + if !ok { + return false + } + return a == b + default: + // this should never happen + return false + } +} + // CloneColTuple creates a deep clone of the input. func CloneColTuple(in ColTuple) ColTuple { if in == nil { @@ -101,6 +257,39 @@ func CloneColTuple(in ColTuple) ColTuple { } } +// EqualsColTuple does deep equals between the two objects. +func EqualsColTuple(inA, inB ColTuple) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case ListArg: + b, ok := inB.(ListArg) + if !ok { + return false + } + return EqualsListArg(a, b) + case *Subquery: + b, ok := inB.(*Subquery) + if !ok { + return false + } + return EqualsRefOfSubquery(a, b) + case ValTuple: + b, ok := inB.(ValTuple) + if !ok { + return false + } + return EqualsValTuple(a, b) + default: + // this should never happen + return false + } +} + // CloneConstraintInfo creates a deep clone of the input. func CloneConstraintInfo(in ConstraintInfo) ConstraintInfo { if in == nil { @@ -117,6 +306,33 @@ func CloneConstraintInfo(in ConstraintInfo) ConstraintInfo { } } +// EqualsConstraintInfo does deep equals between the two objects. +func EqualsConstraintInfo(inA, inB ConstraintInfo) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case *CheckConstraintDefinition: + b, ok := inB.(*CheckConstraintDefinition) + if !ok { + return false + } + return EqualsRefOfCheckConstraintDefinition(a, b) + case *ForeignKeyDefinition: + b, ok := inB.(*ForeignKeyDefinition) + if !ok { + return false + } + return EqualsRefOfForeignKeyDefinition(a, b) + default: + // this should never happen + return false + } +} + // CloneDBDDLStatement creates a deep clone of the input. func CloneDBDDLStatement(in DBDDLStatement) DBDDLStatement { if in == nil { @@ -135,6 +351,39 @@ func CloneDBDDLStatement(in DBDDLStatement) DBDDLStatement { } } +// EqualsDBDDLStatement does deep equals between the two objects. +func EqualsDBDDLStatement(inA, inB DBDDLStatement) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case *AlterDatabase: + b, ok := inB.(*AlterDatabase) + if !ok { + return false + } + return EqualsRefOfAlterDatabase(a, b) + case *CreateDatabase: + b, ok := inB.(*CreateDatabase) + if !ok { + return false + } + return EqualsRefOfCreateDatabase(a, b) + case *DropDatabase: + b, ok := inB.(*DropDatabase) + if !ok { + return false + } + return EqualsRefOfDropDatabase(a, b) + default: + // this should never happen + return false + } +} + // CloneDDLStatement creates a deep clone of the input. func CloneDDLStatement(in DDLStatement) DDLStatement { if in == nil { @@ -163,6 +412,69 @@ func CloneDDLStatement(in DDLStatement) DDLStatement { } } +// EqualsDDLStatement does deep equals between the two objects. +func EqualsDDLStatement(inA, inB DDLStatement) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case *AlterTable: + b, ok := inB.(*AlterTable) + if !ok { + return false + } + return EqualsRefOfAlterTable(a, b) + case *AlterView: + b, ok := inB.(*AlterView) + if !ok { + return false + } + return EqualsRefOfAlterView(a, b) + case *CreateTable: + b, ok := inB.(*CreateTable) + if !ok { + return false + } + return EqualsRefOfCreateTable(a, b) + case *CreateView: + b, ok := inB.(*CreateView) + if !ok { + return false + } + return EqualsRefOfCreateView(a, b) + case *DropTable: + b, ok := inB.(*DropTable) + if !ok { + return false + } + return EqualsRefOfDropTable(a, b) + case *DropView: + b, ok := inB.(*DropView) + if !ok { + return false + } + return EqualsRefOfDropView(a, b) + case *RenameTable: + b, ok := inB.(*RenameTable) + if !ok { + return false + } + return EqualsRefOfRenameTable(a, b) + case *TruncateTable: + b, ok := inB.(*TruncateTable) + if !ok { + return false + } + return EqualsRefOfTruncateTable(a, b) + default: + // this should never happen + return false + } +} + // CloneExplain creates a deep clone of the input. func CloneExplain(in Explain) Explain { if in == nil { @@ -179,6 +491,33 @@ func CloneExplain(in Explain) Explain { } } +// EqualsExplain does deep equals between the two objects. +func EqualsExplain(inA, inB Explain) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case *ExplainStmt: + b, ok := inB.(*ExplainStmt) + if !ok { + return false + } + return EqualsRefOfExplainStmt(a, b) + case *ExplainTab: + b, ok := inB.(*ExplainTab) + if !ok { + return false + } + return EqualsRefOfExplainTab(a, b) + default: + // this should never happen + return false + } +} + // CloneExpr creates a deep clone of the input. func CloneExpr(in Expr) Expr { if in == nil { @@ -253,6 +592,207 @@ func CloneExpr(in Expr) Expr { } } +// EqualsExpr does deep equals between the two objects. +func EqualsExpr(inA, inB Expr) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case *AndExpr: + b, ok := inB.(*AndExpr) + if !ok { + return false + } + return EqualsRefOfAndExpr(a, b) + case Argument: + b, ok := inB.(Argument) + if !ok { + return false + } + return a == b + case *BinaryExpr: + b, ok := inB.(*BinaryExpr) + if !ok { + return false + } + return EqualsRefOfBinaryExpr(a, b) + case BoolVal: + b, ok := inB.(BoolVal) + if !ok { + return false + } + return a == b + case *CaseExpr: + b, ok := inB.(*CaseExpr) + if !ok { + return false + } + return EqualsRefOfCaseExpr(a, b) + case *ColName: + b, ok := inB.(*ColName) + if !ok { + return false + } + return EqualsRefOfColName(a, b) + case *CollateExpr: + b, ok := inB.(*CollateExpr) + if !ok { + return false + } + return EqualsRefOfCollateExpr(a, b) + case *ComparisonExpr: + b, ok := inB.(*ComparisonExpr) + if !ok { + return false + } + return EqualsRefOfComparisonExpr(a, b) + case *ConvertExpr: + b, ok := inB.(*ConvertExpr) + if !ok { + return false + } + return EqualsRefOfConvertExpr(a, b) + case *ConvertUsingExpr: + b, ok := inB.(*ConvertUsingExpr) + if !ok { + return false + } + return EqualsRefOfConvertUsingExpr(a, b) + case *CurTimeFuncExpr: + b, ok := inB.(*CurTimeFuncExpr) + if !ok { + return false + } + return EqualsRefOfCurTimeFuncExpr(a, b) + case *Default: + b, ok := inB.(*Default) + if !ok { + return false + } + return EqualsRefOfDefault(a, b) + case *ExistsExpr: + b, ok := inB.(*ExistsExpr) + if !ok { + return false + } + return EqualsRefOfExistsExpr(a, b) + case *FuncExpr: + b, ok := inB.(*FuncExpr) + if !ok { + return false + } + return EqualsRefOfFuncExpr(a, b) + case *GroupConcatExpr: + b, ok := inB.(*GroupConcatExpr) + if !ok { + return false + } + return EqualsRefOfGroupConcatExpr(a, b) + case *IntervalExpr: + b, ok := inB.(*IntervalExpr) + if !ok { + return false + } + return EqualsRefOfIntervalExpr(a, b) + case *IsExpr: + b, ok := inB.(*IsExpr) + if !ok { + return false + } + return EqualsRefOfIsExpr(a, b) + case ListArg: + b, ok := inB.(ListArg) + if !ok { + return false + } + return EqualsListArg(a, b) + case *Literal: + b, ok := inB.(*Literal) + if !ok { + return false + } + return EqualsRefOfLiteral(a, b) + case *MatchExpr: + b, ok := inB.(*MatchExpr) + if !ok { + return false + } + return EqualsRefOfMatchExpr(a, b) + case *NotExpr: + b, ok := inB.(*NotExpr) + if !ok { + return false + } + return EqualsRefOfNotExpr(a, b) + case *NullVal: + b, ok := inB.(*NullVal) + if !ok { + return false + } + return EqualsRefOfNullVal(a, b) + case *OrExpr: + b, ok := inB.(*OrExpr) + if !ok { + return false + } + return EqualsRefOfOrExpr(a, b) + case *RangeCond: + b, ok := inB.(*RangeCond) + if !ok { + return false + } + return EqualsRefOfRangeCond(a, b) + case *Subquery: + b, ok := inB.(*Subquery) + if !ok { + return false + } + return EqualsRefOfSubquery(a, b) + case *SubstrExpr: + b, ok := inB.(*SubstrExpr) + if !ok { + return false + } + return EqualsRefOfSubstrExpr(a, b) + case *TimestampFuncExpr: + b, ok := inB.(*TimestampFuncExpr) + if !ok { + return false + } + return EqualsRefOfTimestampFuncExpr(a, b) + case *UnaryExpr: + b, ok := inB.(*UnaryExpr) + if !ok { + return false + } + return EqualsRefOfUnaryExpr(a, b) + case ValTuple: + b, ok := inB.(ValTuple) + if !ok { + return false + } + return EqualsValTuple(a, b) + case *ValuesFuncExpr: + b, ok := inB.(*ValuesFuncExpr) + if !ok { + return false + } + return EqualsRefOfValuesFuncExpr(a, b) + case *XorExpr: + b, ok := inB.(*XorExpr) + if !ok { + return false + } + return EqualsRefOfXorExpr(a, b) + default: + // this should never happen + return false + } +} + // CloneInsertRows creates a deep clone of the input. func CloneInsertRows(in InsertRows) InsertRows { if in == nil { @@ -273,6 +813,45 @@ func CloneInsertRows(in InsertRows) InsertRows { } } +// EqualsInsertRows does deep equals between the two objects. +func EqualsInsertRows(inA, inB InsertRows) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case *ParenSelect: + b, ok := inB.(*ParenSelect) + if !ok { + return false + } + return EqualsRefOfParenSelect(a, b) + case *Select: + b, ok := inB.(*Select) + if !ok { + return false + } + return EqualsRefOfSelect(a, b) + case *Union: + b, ok := inB.(*Union) + if !ok { + return false + } + return EqualsRefOfUnion(a, b) + case Values: + b, ok := inB.(Values) + if !ok { + return false + } + return EqualsValues(a, b) + default: + // this should never happen + return false + } +} + // CloneSQLNode creates a deep clone of the input. func CloneSQLNode(in SQLNode) SQLNode { if in == nil { @@ -556,20 +1135,899 @@ func CloneSQLNode(in SQLNode) SQLNode { case Values: return CloneValues(in) case *ValuesFuncExpr: - return CloneRefOfValuesFuncExpr(in) + return CloneRefOfValuesFuncExpr(in) + case VindexParam: + return CloneVindexParam(in) + case *VindexSpec: + return CloneRefOfVindexSpec(in) + case *When: + return CloneRefOfWhen(in) + case *Where: + return CloneRefOfWhere(in) + case *XorExpr: + return CloneRefOfXorExpr(in) + default: + // this should never happen + return nil + } +} + +// EqualsSQLNode does deep equals between the two objects. +func EqualsSQLNode(inA, inB SQLNode) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case AccessMode: + b, ok := inB.(AccessMode) + if !ok { + return false + } + return a == b + case *AddColumns: + b, ok := inB.(*AddColumns) + if !ok { + return false + } + return EqualsRefOfAddColumns(a, b) + case *AddConstraintDefinition: + b, ok := inB.(*AddConstraintDefinition) + if !ok { + return false + } + return EqualsRefOfAddConstraintDefinition(a, b) + case *AddIndexDefinition: + b, ok := inB.(*AddIndexDefinition) + if !ok { + return false + } + return EqualsRefOfAddIndexDefinition(a, b) + case AlgorithmValue: + b, ok := inB.(AlgorithmValue) + if !ok { + return false + } + return a == b + case *AliasedExpr: + b, ok := inB.(*AliasedExpr) + if !ok { + return false + } + return EqualsRefOfAliasedExpr(a, b) + case *AliasedTableExpr: + b, ok := inB.(*AliasedTableExpr) + if !ok { + return false + } + return EqualsRefOfAliasedTableExpr(a, b) + case *AlterCharset: + b, ok := inB.(*AlterCharset) + if !ok { + return false + } + return EqualsRefOfAlterCharset(a, b) + case *AlterColumn: + b, ok := inB.(*AlterColumn) + if !ok { + return false + } + return EqualsRefOfAlterColumn(a, b) + case *AlterDatabase: + b, ok := inB.(*AlterDatabase) + if !ok { + return false + } + return EqualsRefOfAlterDatabase(a, b) + case *AlterTable: + b, ok := inB.(*AlterTable) + if !ok { + return false + } + return EqualsRefOfAlterTable(a, b) + case *AlterView: + b, ok := inB.(*AlterView) + if !ok { + return false + } + return EqualsRefOfAlterView(a, b) + case *AlterVschema: + b, ok := inB.(*AlterVschema) + if !ok { + return false + } + return EqualsRefOfAlterVschema(a, b) + case *AndExpr: + b, ok := inB.(*AndExpr) + if !ok { + return false + } + return EqualsRefOfAndExpr(a, b) + case Argument: + b, ok := inB.(Argument) + if !ok { + return false + } + return a == b + case *AutoIncSpec: + b, ok := inB.(*AutoIncSpec) + if !ok { + return false + } + return EqualsRefOfAutoIncSpec(a, b) + case *Begin: + b, ok := inB.(*Begin) + if !ok { + return false + } + return EqualsRefOfBegin(a, b) + case *BinaryExpr: + b, ok := inB.(*BinaryExpr) + if !ok { + return false + } + return EqualsRefOfBinaryExpr(a, b) + case BoolVal: + b, ok := inB.(BoolVal) + if !ok { + return false + } + return a == b + case *CallProc: + b, ok := inB.(*CallProc) + if !ok { + return false + } + return EqualsRefOfCallProc(a, b) + case *CaseExpr: + b, ok := inB.(*CaseExpr) + if !ok { + return false + } + return EqualsRefOfCaseExpr(a, b) + case *ChangeColumn: + b, ok := inB.(*ChangeColumn) + if !ok { + return false + } + return EqualsRefOfChangeColumn(a, b) + case *CheckConstraintDefinition: + b, ok := inB.(*CheckConstraintDefinition) + if !ok { + return false + } + return EqualsRefOfCheckConstraintDefinition(a, b) + case ColIdent: + b, ok := inB.(ColIdent) + if !ok { + return false + } + return EqualsColIdent(a, b) + case *ColName: + b, ok := inB.(*ColName) + if !ok { + return false + } + return EqualsRefOfColName(a, b) + case *CollateExpr: + b, ok := inB.(*CollateExpr) + if !ok { + return false + } + return EqualsRefOfCollateExpr(a, b) + case *ColumnDefinition: + b, ok := inB.(*ColumnDefinition) + if !ok { + return false + } + return EqualsRefOfColumnDefinition(a, b) + case *ColumnType: + b, ok := inB.(*ColumnType) + if !ok { + return false + } + return EqualsRefOfColumnType(a, b) + case Columns: + b, ok := inB.(Columns) + if !ok { + return false + } + return EqualsColumns(a, b) + case Comments: + b, ok := inB.(Comments) + if !ok { + return false + } + return EqualsComments(a, b) + case *Commit: + b, ok := inB.(*Commit) + if !ok { + return false + } + return EqualsRefOfCommit(a, b) + case *ComparisonExpr: + b, ok := inB.(*ComparisonExpr) + if !ok { + return false + } + return EqualsRefOfComparisonExpr(a, b) + case *ConstraintDefinition: + b, ok := inB.(*ConstraintDefinition) + if !ok { + return false + } + return EqualsRefOfConstraintDefinition(a, b) + case *ConvertExpr: + b, ok := inB.(*ConvertExpr) + if !ok { + return false + } + return EqualsRefOfConvertExpr(a, b) + case *ConvertType: + b, ok := inB.(*ConvertType) + if !ok { + return false + } + return EqualsRefOfConvertType(a, b) + case *ConvertUsingExpr: + b, ok := inB.(*ConvertUsingExpr) + if !ok { + return false + } + return EqualsRefOfConvertUsingExpr(a, b) + case *CreateDatabase: + b, ok := inB.(*CreateDatabase) + if !ok { + return false + } + return EqualsRefOfCreateDatabase(a, b) + case *CreateTable: + b, ok := inB.(*CreateTable) + if !ok { + return false + } + return EqualsRefOfCreateTable(a, b) + case *CreateView: + b, ok := inB.(*CreateView) + if !ok { + return false + } + return EqualsRefOfCreateView(a, b) + case *CurTimeFuncExpr: + b, ok := inB.(*CurTimeFuncExpr) + if !ok { + return false + } + return EqualsRefOfCurTimeFuncExpr(a, b) + case *Default: + b, ok := inB.(*Default) + if !ok { + return false + } + return EqualsRefOfDefault(a, b) + case *Delete: + b, ok := inB.(*Delete) + if !ok { + return false + } + return EqualsRefOfDelete(a, b) + case *DerivedTable: + b, ok := inB.(*DerivedTable) + if !ok { + return false + } + return EqualsRefOfDerivedTable(a, b) + case *DropColumn: + b, ok := inB.(*DropColumn) + if !ok { + return false + } + return EqualsRefOfDropColumn(a, b) + case *DropDatabase: + b, ok := inB.(*DropDatabase) + if !ok { + return false + } + return EqualsRefOfDropDatabase(a, b) + case *DropKey: + b, ok := inB.(*DropKey) + if !ok { + return false + } + return EqualsRefOfDropKey(a, b) + case *DropTable: + b, ok := inB.(*DropTable) + if !ok { + return false + } + return EqualsRefOfDropTable(a, b) + case *DropView: + b, ok := inB.(*DropView) + if !ok { + return false + } + return EqualsRefOfDropView(a, b) + case *ExistsExpr: + b, ok := inB.(*ExistsExpr) + if !ok { + return false + } + return EqualsRefOfExistsExpr(a, b) + case *ExplainStmt: + b, ok := inB.(*ExplainStmt) + if !ok { + return false + } + return EqualsRefOfExplainStmt(a, b) + case *ExplainTab: + b, ok := inB.(*ExplainTab) + if !ok { + return false + } + return EqualsRefOfExplainTab(a, b) + case Exprs: + b, ok := inB.(Exprs) + if !ok { + return false + } + return EqualsExprs(a, b) + case *Flush: + b, ok := inB.(*Flush) + if !ok { + return false + } + return EqualsRefOfFlush(a, b) + case *Force: + b, ok := inB.(*Force) + if !ok { + return false + } + return EqualsRefOfForce(a, b) + case *ForeignKeyDefinition: + b, ok := inB.(*ForeignKeyDefinition) + if !ok { + return false + } + return EqualsRefOfForeignKeyDefinition(a, b) + case *FuncExpr: + b, ok := inB.(*FuncExpr) + if !ok { + return false + } + return EqualsRefOfFuncExpr(a, b) + case GroupBy: + b, ok := inB.(GroupBy) + if !ok { + return false + } + return EqualsGroupBy(a, b) + case *GroupConcatExpr: + b, ok := inB.(*GroupConcatExpr) + if !ok { + return false + } + return EqualsRefOfGroupConcatExpr(a, b) + case *IndexDefinition: + b, ok := inB.(*IndexDefinition) + if !ok { + return false + } + return EqualsRefOfIndexDefinition(a, b) + case *IndexHints: + b, ok := inB.(*IndexHints) + if !ok { + return false + } + return EqualsRefOfIndexHints(a, b) + case *IndexInfo: + b, ok := inB.(*IndexInfo) + if !ok { + return false + } + return EqualsRefOfIndexInfo(a, b) + case *Insert: + b, ok := inB.(*Insert) + if !ok { + return false + } + return EqualsRefOfInsert(a, b) + case *IntervalExpr: + b, ok := inB.(*IntervalExpr) + if !ok { + return false + } + return EqualsRefOfIntervalExpr(a, b) + case *IsExpr: + b, ok := inB.(*IsExpr) + if !ok { + return false + } + return EqualsRefOfIsExpr(a, b) + case IsolationLevel: + b, ok := inB.(IsolationLevel) + if !ok { + return false + } + return a == b + case JoinCondition: + b, ok := inB.(JoinCondition) + if !ok { + return false + } + return EqualsJoinCondition(a, b) + case *JoinTableExpr: + b, ok := inB.(*JoinTableExpr) + if !ok { + return false + } + return EqualsRefOfJoinTableExpr(a, b) + case *KeyState: + b, ok := inB.(*KeyState) + if !ok { + return false + } + return EqualsRefOfKeyState(a, b) + case *Limit: + b, ok := inB.(*Limit) + if !ok { + return false + } + return EqualsRefOfLimit(a, b) + case ListArg: + b, ok := inB.(ListArg) + if !ok { + return false + } + return EqualsListArg(a, b) + case *Literal: + b, ok := inB.(*Literal) + if !ok { + return false + } + return EqualsRefOfLiteral(a, b) + case *Load: + b, ok := inB.(*Load) + if !ok { + return false + } + return EqualsRefOfLoad(a, b) + case *LockOption: + b, ok := inB.(*LockOption) + if !ok { + return false + } + return EqualsRefOfLockOption(a, b) + case *LockTables: + b, ok := inB.(*LockTables) + if !ok { + return false + } + return EqualsRefOfLockTables(a, b) + case *MatchExpr: + b, ok := inB.(*MatchExpr) + if !ok { + return false + } + return EqualsRefOfMatchExpr(a, b) + case *ModifyColumn: + b, ok := inB.(*ModifyColumn) + if !ok { + return false + } + return EqualsRefOfModifyColumn(a, b) + case *Nextval: + b, ok := inB.(*Nextval) + if !ok { + return false + } + return EqualsRefOfNextval(a, b) + case *NotExpr: + b, ok := inB.(*NotExpr) + if !ok { + return false + } + return EqualsRefOfNotExpr(a, b) + case *NullVal: + b, ok := inB.(*NullVal) + if !ok { + return false + } + return EqualsRefOfNullVal(a, b) + case OnDup: + b, ok := inB.(OnDup) + if !ok { + return false + } + return EqualsOnDup(a, b) + case *OptLike: + b, ok := inB.(*OptLike) + if !ok { + return false + } + return EqualsRefOfOptLike(a, b) + case *OrExpr: + b, ok := inB.(*OrExpr) + if !ok { + return false + } + return EqualsRefOfOrExpr(a, b) + case *Order: + b, ok := inB.(*Order) + if !ok { + return false + } + return EqualsRefOfOrder(a, b) + case OrderBy: + b, ok := inB.(OrderBy) + if !ok { + return false + } + return EqualsOrderBy(a, b) + case *OrderByOption: + b, ok := inB.(*OrderByOption) + if !ok { + return false + } + return EqualsRefOfOrderByOption(a, b) + case *OtherAdmin: + b, ok := inB.(*OtherAdmin) + if !ok { + return false + } + return EqualsRefOfOtherAdmin(a, b) + case *OtherRead: + b, ok := inB.(*OtherRead) + if !ok { + return false + } + return EqualsRefOfOtherRead(a, b) + case *ParenSelect: + b, ok := inB.(*ParenSelect) + if !ok { + return false + } + return EqualsRefOfParenSelect(a, b) + case *ParenTableExpr: + b, ok := inB.(*ParenTableExpr) + if !ok { + return false + } + return EqualsRefOfParenTableExpr(a, b) + case *PartitionDefinition: + b, ok := inB.(*PartitionDefinition) + if !ok { + return false + } + return EqualsRefOfPartitionDefinition(a, b) + case *PartitionSpec: + b, ok := inB.(*PartitionSpec) + if !ok { + return false + } + return EqualsRefOfPartitionSpec(a, b) + case Partitions: + b, ok := inB.(Partitions) + if !ok { + return false + } + return EqualsPartitions(a, b) + case *RangeCond: + b, ok := inB.(*RangeCond) + if !ok { + return false + } + return EqualsRefOfRangeCond(a, b) + case ReferenceAction: + b, ok := inB.(ReferenceAction) + if !ok { + return false + } + return a == b + case *Release: + b, ok := inB.(*Release) + if !ok { + return false + } + return EqualsRefOfRelease(a, b) + case *RenameIndex: + b, ok := inB.(*RenameIndex) + if !ok { + return false + } + return EqualsRefOfRenameIndex(a, b) + case *RenameTable: + b, ok := inB.(*RenameTable) + if !ok { + return false + } + return EqualsRefOfRenameTable(a, b) + case *RenameTableName: + b, ok := inB.(*RenameTableName) + if !ok { + return false + } + return EqualsRefOfRenameTableName(a, b) + case *Rollback: + b, ok := inB.(*Rollback) + if !ok { + return false + } + return EqualsRefOfRollback(a, b) + case *SRollback: + b, ok := inB.(*SRollback) + if !ok { + return false + } + return EqualsRefOfSRollback(a, b) + case *Savepoint: + b, ok := inB.(*Savepoint) + if !ok { + return false + } + return EqualsRefOfSavepoint(a, b) + case *Select: + b, ok := inB.(*Select) + if !ok { + return false + } + return EqualsRefOfSelect(a, b) + case SelectExprs: + b, ok := inB.(SelectExprs) + if !ok { + return false + } + return EqualsSelectExprs(a, b) + case *SelectInto: + b, ok := inB.(*SelectInto) + if !ok { + return false + } + return EqualsRefOfSelectInto(a, b) + case *Set: + b, ok := inB.(*Set) + if !ok { + return false + } + return EqualsRefOfSet(a, b) + case *SetExpr: + b, ok := inB.(*SetExpr) + if !ok { + return false + } + return EqualsRefOfSetExpr(a, b) + case SetExprs: + b, ok := inB.(SetExprs) + if !ok { + return false + } + return EqualsSetExprs(a, b) + case *SetTransaction: + b, ok := inB.(*SetTransaction) + if !ok { + return false + } + return EqualsRefOfSetTransaction(a, b) + case *Show: + b, ok := inB.(*Show) + if !ok { + return false + } + return EqualsRefOfShow(a, b) + case *ShowBasic: + b, ok := inB.(*ShowBasic) + if !ok { + return false + } + return EqualsRefOfShowBasic(a, b) + case *ShowCreate: + b, ok := inB.(*ShowCreate) + if !ok { + return false + } + return EqualsRefOfShowCreate(a, b) + case *ShowFilter: + b, ok := inB.(*ShowFilter) + if !ok { + return false + } + return EqualsRefOfShowFilter(a, b) + case *ShowLegacy: + b, ok := inB.(*ShowLegacy) + if !ok { + return false + } + return EqualsRefOfShowLegacy(a, b) + case *StarExpr: + b, ok := inB.(*StarExpr) + if !ok { + return false + } + return EqualsRefOfStarExpr(a, b) + case *Stream: + b, ok := inB.(*Stream) + if !ok { + return false + } + return EqualsRefOfStream(a, b) + case *Subquery: + b, ok := inB.(*Subquery) + if !ok { + return false + } + return EqualsRefOfSubquery(a, b) + case *SubstrExpr: + b, ok := inB.(*SubstrExpr) + if !ok { + return false + } + return EqualsRefOfSubstrExpr(a, b) + case TableExprs: + b, ok := inB.(TableExprs) + if !ok { + return false + } + return EqualsTableExprs(a, b) + case TableIdent: + b, ok := inB.(TableIdent) + if !ok { + return false + } + return EqualsTableIdent(a, b) + case TableName: + b, ok := inB.(TableName) + if !ok { + return false + } + return EqualsTableName(a, b) + case TableNames: + b, ok := inB.(TableNames) + if !ok { + return false + } + return EqualsTableNames(a, b) + case TableOptions: + b, ok := inB.(TableOptions) + if !ok { + return false + } + return EqualsTableOptions(a, b) + case *TableSpec: + b, ok := inB.(*TableSpec) + if !ok { + return false + } + return EqualsRefOfTableSpec(a, b) + case *TablespaceOperation: + b, ok := inB.(*TablespaceOperation) + if !ok { + return false + } + return EqualsRefOfTablespaceOperation(a, b) + case *TimestampFuncExpr: + b, ok := inB.(*TimestampFuncExpr) + if !ok { + return false + } + return EqualsRefOfTimestampFuncExpr(a, b) + case *TruncateTable: + b, ok := inB.(*TruncateTable) + if !ok { + return false + } + return EqualsRefOfTruncateTable(a, b) + case *UnaryExpr: + b, ok := inB.(*UnaryExpr) + if !ok { + return false + } + return EqualsRefOfUnaryExpr(a, b) + case *Union: + b, ok := inB.(*Union) + if !ok { + return false + } + return EqualsRefOfUnion(a, b) + case *UnionSelect: + b, ok := inB.(*UnionSelect) + if !ok { + return false + } + return EqualsRefOfUnionSelect(a, b) + case *UnlockTables: + b, ok := inB.(*UnlockTables) + if !ok { + return false + } + return EqualsRefOfUnlockTables(a, b) + case *Update: + b, ok := inB.(*Update) + if !ok { + return false + } + return EqualsRefOfUpdate(a, b) + case *UpdateExpr: + b, ok := inB.(*UpdateExpr) + if !ok { + return false + } + return EqualsRefOfUpdateExpr(a, b) + case UpdateExprs: + b, ok := inB.(UpdateExprs) + if !ok { + return false + } + return EqualsUpdateExprs(a, b) + case *Use: + b, ok := inB.(*Use) + if !ok { + return false + } + return EqualsRefOfUse(a, b) + case *VStream: + b, ok := inB.(*VStream) + if !ok { + return false + } + return EqualsRefOfVStream(a, b) + case ValTuple: + b, ok := inB.(ValTuple) + if !ok { + return false + } + return EqualsValTuple(a, b) + case *Validation: + b, ok := inB.(*Validation) + if !ok { + return false + } + return EqualsRefOfValidation(a, b) + case Values: + b, ok := inB.(Values) + if !ok { + return false + } + return EqualsValues(a, b) + case *ValuesFuncExpr: + b, ok := inB.(*ValuesFuncExpr) + if !ok { + return false + } + return EqualsRefOfValuesFuncExpr(a, b) case VindexParam: - return CloneVindexParam(in) + b, ok := inB.(VindexParam) + if !ok { + return false + } + return EqualsVindexParam(a, b) case *VindexSpec: - return CloneRefOfVindexSpec(in) + b, ok := inB.(*VindexSpec) + if !ok { + return false + } + return EqualsRefOfVindexSpec(a, b) case *When: - return CloneRefOfWhen(in) + b, ok := inB.(*When) + if !ok { + return false + } + return EqualsRefOfWhen(a, b) case *Where: - return CloneRefOfWhere(in) + b, ok := inB.(*Where) + if !ok { + return false + } + return EqualsRefOfWhere(a, b) case *XorExpr: - return CloneRefOfXorExpr(in) + b, ok := inB.(*XorExpr) + if !ok { + return false + } + return EqualsRefOfXorExpr(a, b) default: // this should never happen - return nil + return false } } @@ -591,6 +2049,39 @@ func CloneSelectExpr(in SelectExpr) SelectExpr { } } +// EqualsSelectExpr does deep equals between the two objects. +func EqualsSelectExpr(inA, inB SelectExpr) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case *AliasedExpr: + b, ok := inB.(*AliasedExpr) + if !ok { + return false + } + return EqualsRefOfAliasedExpr(a, b) + case *Nextval: + b, ok := inB.(*Nextval) + if !ok { + return false + } + return EqualsRefOfNextval(a, b) + case *StarExpr: + b, ok := inB.(*StarExpr) + if !ok { + return false + } + return EqualsRefOfStarExpr(a, b) + default: + // this should never happen + return false + } +} + // CloneSelectStatement creates a deep clone of the input. func CloneSelectStatement(in SelectStatement) SelectStatement { if in == nil { @@ -609,6 +2100,39 @@ func CloneSelectStatement(in SelectStatement) SelectStatement { } } +// EqualsSelectStatement does deep equals between the two objects. +func EqualsSelectStatement(inA, inB SelectStatement) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case *ParenSelect: + b, ok := inB.(*ParenSelect) + if !ok { + return false + } + return EqualsRefOfParenSelect(a, b) + case *Select: + b, ok := inB.(*Select) + if !ok { + return false + } + return EqualsRefOfSelect(a, b) + case *Union: + b, ok := inB.(*Union) + if !ok { + return false + } + return EqualsRefOfUnion(a, b) + default: + // this should never happen + return false + } +} + // CloneShowInternal creates a deep clone of the input. func CloneShowInternal(in ShowInternal) ShowInternal { if in == nil { @@ -627,6 +2151,39 @@ func CloneShowInternal(in ShowInternal) ShowInternal { } } +// EqualsShowInternal does deep equals between the two objects. +func EqualsShowInternal(inA, inB ShowInternal) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case *ShowBasic: + b, ok := inB.(*ShowBasic) + if !ok { + return false + } + return EqualsRefOfShowBasic(a, b) + case *ShowCreate: + b, ok := inB.(*ShowCreate) + if !ok { + return false + } + return EqualsRefOfShowCreate(a, b) + case *ShowLegacy: + b, ok := inB.(*ShowLegacy) + if !ok { + return false + } + return EqualsRefOfShowLegacy(a, b) + default: + // this should never happen + return false + } +} + // CloneSimpleTableExpr creates a deep clone of the input. func CloneSimpleTableExpr(in SimpleTableExpr) SimpleTableExpr { if in == nil { @@ -643,6 +2200,33 @@ func CloneSimpleTableExpr(in SimpleTableExpr) SimpleTableExpr { } } +// EqualsSimpleTableExpr does deep equals between the two objects. +func EqualsSimpleTableExpr(inA, inB SimpleTableExpr) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case *DerivedTable: + b, ok := inB.(*DerivedTable) + if !ok { + return false + } + return EqualsRefOfDerivedTable(a, b) + case TableName: + b, ok := inB.(TableName) + if !ok { + return false + } + return EqualsTableName(a, b) + default: + // this should never happen + return false + } +} + // CloneStatement creates a deep clone of the input. func CloneStatement(in Statement) Statement { if in == nil { @@ -733,6 +2317,255 @@ func CloneStatement(in Statement) Statement { } } +// EqualsStatement does deep equals between the two objects. +func EqualsStatement(inA, inB Statement) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case *AlterDatabase: + b, ok := inB.(*AlterDatabase) + if !ok { + return false + } + return EqualsRefOfAlterDatabase(a, b) + case *AlterTable: + b, ok := inB.(*AlterTable) + if !ok { + return false + } + return EqualsRefOfAlterTable(a, b) + case *AlterView: + b, ok := inB.(*AlterView) + if !ok { + return false + } + return EqualsRefOfAlterView(a, b) + case *AlterVschema: + b, ok := inB.(*AlterVschema) + if !ok { + return false + } + return EqualsRefOfAlterVschema(a, b) + case *Begin: + b, ok := inB.(*Begin) + if !ok { + return false + } + return EqualsRefOfBegin(a, b) + case *CallProc: + b, ok := inB.(*CallProc) + if !ok { + return false + } + return EqualsRefOfCallProc(a, b) + case *Commit: + b, ok := inB.(*Commit) + if !ok { + return false + } + return EqualsRefOfCommit(a, b) + case *CreateDatabase: + b, ok := inB.(*CreateDatabase) + if !ok { + return false + } + return EqualsRefOfCreateDatabase(a, b) + case *CreateTable: + b, ok := inB.(*CreateTable) + if !ok { + return false + } + return EqualsRefOfCreateTable(a, b) + case *CreateView: + b, ok := inB.(*CreateView) + if !ok { + return false + } + return EqualsRefOfCreateView(a, b) + case *Delete: + b, ok := inB.(*Delete) + if !ok { + return false + } + return EqualsRefOfDelete(a, b) + case *DropDatabase: + b, ok := inB.(*DropDatabase) + if !ok { + return false + } + return EqualsRefOfDropDatabase(a, b) + case *DropTable: + b, ok := inB.(*DropTable) + if !ok { + return false + } + return EqualsRefOfDropTable(a, b) + case *DropView: + b, ok := inB.(*DropView) + if !ok { + return false + } + return EqualsRefOfDropView(a, b) + case *ExplainStmt: + b, ok := inB.(*ExplainStmt) + if !ok { + return false + } + return EqualsRefOfExplainStmt(a, b) + case *ExplainTab: + b, ok := inB.(*ExplainTab) + if !ok { + return false + } + return EqualsRefOfExplainTab(a, b) + case *Flush: + b, ok := inB.(*Flush) + if !ok { + return false + } + return EqualsRefOfFlush(a, b) + case *Insert: + b, ok := inB.(*Insert) + if !ok { + return false + } + return EqualsRefOfInsert(a, b) + case *Load: + b, ok := inB.(*Load) + if !ok { + return false + } + return EqualsRefOfLoad(a, b) + case *LockTables: + b, ok := inB.(*LockTables) + if !ok { + return false + } + return EqualsRefOfLockTables(a, b) + case *OtherAdmin: + b, ok := inB.(*OtherAdmin) + if !ok { + return false + } + return EqualsRefOfOtherAdmin(a, b) + case *OtherRead: + b, ok := inB.(*OtherRead) + if !ok { + return false + } + return EqualsRefOfOtherRead(a, b) + case *ParenSelect: + b, ok := inB.(*ParenSelect) + if !ok { + return false + } + return EqualsRefOfParenSelect(a, b) + case *Release: + b, ok := inB.(*Release) + if !ok { + return false + } + return EqualsRefOfRelease(a, b) + case *RenameTable: + b, ok := inB.(*RenameTable) + if !ok { + return false + } + return EqualsRefOfRenameTable(a, b) + case *Rollback: + b, ok := inB.(*Rollback) + if !ok { + return false + } + return EqualsRefOfRollback(a, b) + case *SRollback: + b, ok := inB.(*SRollback) + if !ok { + return false + } + return EqualsRefOfSRollback(a, b) + case *Savepoint: + b, ok := inB.(*Savepoint) + if !ok { + return false + } + return EqualsRefOfSavepoint(a, b) + case *Select: + b, ok := inB.(*Select) + if !ok { + return false + } + return EqualsRefOfSelect(a, b) + case *Set: + b, ok := inB.(*Set) + if !ok { + return false + } + return EqualsRefOfSet(a, b) + case *SetTransaction: + b, ok := inB.(*SetTransaction) + if !ok { + return false + } + return EqualsRefOfSetTransaction(a, b) + case *Show: + b, ok := inB.(*Show) + if !ok { + return false + } + return EqualsRefOfShow(a, b) + case *Stream: + b, ok := inB.(*Stream) + if !ok { + return false + } + return EqualsRefOfStream(a, b) + case *TruncateTable: + b, ok := inB.(*TruncateTable) + if !ok { + return false + } + return EqualsRefOfTruncateTable(a, b) + case *Union: + b, ok := inB.(*Union) + if !ok { + return false + } + return EqualsRefOfUnion(a, b) + case *UnlockTables: + b, ok := inB.(*UnlockTables) + if !ok { + return false + } + return EqualsRefOfUnlockTables(a, b) + case *Update: + b, ok := inB.(*Update) + if !ok { + return false + } + return EqualsRefOfUpdate(a, b) + case *Use: + b, ok := inB.(*Use) + if !ok { + return false + } + return EqualsRefOfUse(a, b) + case *VStream: + b, ok := inB.(*VStream) + if !ok { + return false + } + return EqualsRefOfVStream(a, b) + default: + // this should never happen + return false + } +} + // CloneTableExpr creates a deep clone of the input. func CloneTableExpr(in TableExpr) TableExpr { if in == nil { @@ -751,6 +2584,39 @@ func CloneTableExpr(in TableExpr) TableExpr { } } +// EqualsTableExpr does deep equals between the two objects. +func EqualsTableExpr(inA, inB TableExpr) bool { + if inA == nil && inB == nil { + return true + } + if inA == nil || inB == nil { + return false + } + switch a := inA.(type) { + case *AliasedTableExpr: + b, ok := inB.(*AliasedTableExpr) + if !ok { + return false + } + return EqualsRefOfAliasedTableExpr(a, b) + case *JoinTableExpr: + b, ok := inB.(*JoinTableExpr) + if !ok { + return false + } + return EqualsRefOfJoinTableExpr(a, b) + case *ParenTableExpr: + b, ok := inB.(*ParenTableExpr) + if !ok { + return false + } + return EqualsRefOfParenTableExpr(a, b) + default: + // this should never happen + return false + } +} + // CloneRefOfAddColumns creates a deep clone of the input. func CloneRefOfAddColumns(n *AddColumns) *AddColumns { if n == nil { @@ -763,6 +2629,19 @@ func CloneRefOfAddColumns(n *AddColumns) *AddColumns { return &out } +// EqualsRefOfAddColumns does deep equals between the two objects. +func EqualsRefOfAddColumns(a, b *AddColumns) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsSliceOfRefOfColumnDefinition(a.Columns, b.Columns) && + EqualsRefOfColName(a.First, b.First) && + EqualsRefOfColName(a.After, b.After) +} + // CloneRefOfAddConstraintDefinition creates a deep clone of the input. func CloneRefOfAddConstraintDefinition(n *AddConstraintDefinition) *AddConstraintDefinition { if n == nil { @@ -773,6 +2652,17 @@ func CloneRefOfAddConstraintDefinition(n *AddConstraintDefinition) *AddConstrain return &out } +// EqualsRefOfAddConstraintDefinition does deep equals between the two objects. +func EqualsRefOfAddConstraintDefinition(a, b *AddConstraintDefinition) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsRefOfConstraintDefinition(a.ConstraintDefinition, b.ConstraintDefinition) +} + // CloneRefOfAddIndexDefinition creates a deep clone of the input. func CloneRefOfAddIndexDefinition(n *AddIndexDefinition) *AddIndexDefinition { if n == nil { @@ -783,6 +2673,17 @@ func CloneRefOfAddIndexDefinition(n *AddIndexDefinition) *AddIndexDefinition { return &out } +// EqualsRefOfAddIndexDefinition does deep equals between the two objects. +func EqualsRefOfAddIndexDefinition(a, b *AddIndexDefinition) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsRefOfIndexDefinition(a.IndexDefinition, b.IndexDefinition) +} + // CloneRefOfAlterCharset creates a deep clone of the input. func CloneRefOfAlterCharset(n *AlterCharset) *AlterCharset { if n == nil { @@ -792,6 +2693,18 @@ func CloneRefOfAlterCharset(n *AlterCharset) *AlterCharset { return &out } +// EqualsRefOfAlterCharset does deep equals between the two objects. +func EqualsRefOfAlterCharset(a, b *AlterCharset) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.CharacterSet == b.CharacterSet && + a.Collate == b.Collate +} + // CloneRefOfAlterColumn creates a deep clone of the input. func CloneRefOfAlterColumn(n *AlterColumn) *AlterColumn { if n == nil { @@ -803,6 +2716,19 @@ func CloneRefOfAlterColumn(n *AlterColumn) *AlterColumn { return &out } +// EqualsRefOfAlterColumn does deep equals between the two objects. +func EqualsRefOfAlterColumn(a, b *AlterColumn) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.DropDefault == b.DropDefault && + EqualsRefOfColName(a.Column, b.Column) && + EqualsExpr(a.DefaultVal, b.DefaultVal) +} + // CloneRefOfChangeColumn creates a deep clone of the input. func CloneRefOfChangeColumn(n *ChangeColumn) *ChangeColumn { if n == nil { @@ -816,6 +2742,20 @@ func CloneRefOfChangeColumn(n *ChangeColumn) *ChangeColumn { return &out } +// EqualsRefOfChangeColumn does deep equals between the two objects. +func EqualsRefOfChangeColumn(a, b *ChangeColumn) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsRefOfColName(a.OldColumn, b.OldColumn) && + EqualsRefOfColumnDefinition(a.NewColDefinition, b.NewColDefinition) && + EqualsRefOfColName(a.First, b.First) && + EqualsRefOfColName(a.After, b.After) +} + // CloneRefOfDropColumn creates a deep clone of the input. func CloneRefOfDropColumn(n *DropColumn) *DropColumn { if n == nil { @@ -826,6 +2766,17 @@ func CloneRefOfDropColumn(n *DropColumn) *DropColumn { return &out } +// EqualsRefOfDropColumn does deep equals between the two objects. +func EqualsRefOfDropColumn(a, b *DropColumn) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsRefOfColName(a.Name, b.Name) +} + // CloneRefOfDropKey creates a deep clone of the input. func CloneRefOfDropKey(n *DropKey) *DropKey { if n == nil { @@ -835,6 +2786,18 @@ func CloneRefOfDropKey(n *DropKey) *DropKey { return &out } +// EqualsRefOfDropKey does deep equals between the two objects. +func EqualsRefOfDropKey(a, b *DropKey) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Name == b.Name && + a.Type == b.Type +} + // CloneRefOfForce creates a deep clone of the input. func CloneRefOfForce(n *Force) *Force { if n == nil { @@ -844,6 +2807,17 @@ func CloneRefOfForce(n *Force) *Force { return &out } +// EqualsRefOfForce does deep equals between the two objects. +func EqualsRefOfForce(a, b *Force) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return true +} + // CloneRefOfKeyState creates a deep clone of the input. func CloneRefOfKeyState(n *KeyState) *KeyState { if n == nil { @@ -853,6 +2827,17 @@ func CloneRefOfKeyState(n *KeyState) *KeyState { return &out } +// EqualsRefOfKeyState does deep equals between the two objects. +func EqualsRefOfKeyState(a, b *KeyState) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Enable == b.Enable +} + // CloneRefOfLockOption creates a deep clone of the input. func CloneRefOfLockOption(n *LockOption) *LockOption { if n == nil { @@ -862,6 +2847,17 @@ func CloneRefOfLockOption(n *LockOption) *LockOption { return &out } +// EqualsRefOfLockOption does deep equals between the two objects. +func EqualsRefOfLockOption(a, b *LockOption) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Type == b.Type +} + // CloneRefOfModifyColumn creates a deep clone of the input. func CloneRefOfModifyColumn(n *ModifyColumn) *ModifyColumn { if n == nil { @@ -874,6 +2870,19 @@ func CloneRefOfModifyColumn(n *ModifyColumn) *ModifyColumn { return &out } +// EqualsRefOfModifyColumn does deep equals between the two objects. +func EqualsRefOfModifyColumn(a, b *ModifyColumn) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsRefOfColumnDefinition(a.NewColDefinition, b.NewColDefinition) && + EqualsRefOfColName(a.First, b.First) && + EqualsRefOfColName(a.After, b.After) +} + // CloneRefOfOrderByOption creates a deep clone of the input. func CloneRefOfOrderByOption(n *OrderByOption) *OrderByOption { if n == nil { @@ -884,6 +2893,17 @@ func CloneRefOfOrderByOption(n *OrderByOption) *OrderByOption { return &out } +// EqualsRefOfOrderByOption does deep equals between the two objects. +func EqualsRefOfOrderByOption(a, b *OrderByOption) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsColumns(a.Cols, b.Cols) +} + // CloneRefOfRenameIndex creates a deep clone of the input. func CloneRefOfRenameIndex(n *RenameIndex) *RenameIndex { if n == nil { @@ -893,6 +2913,18 @@ func CloneRefOfRenameIndex(n *RenameIndex) *RenameIndex { return &out } +// EqualsRefOfRenameIndex does deep equals between the two objects. +func EqualsRefOfRenameIndex(a, b *RenameIndex) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.OldName == b.OldName && + a.NewName == b.NewName +} + // CloneRefOfRenameTableName creates a deep clone of the input. func CloneRefOfRenameTableName(n *RenameTableName) *RenameTableName { if n == nil { @@ -903,6 +2935,17 @@ func CloneRefOfRenameTableName(n *RenameTableName) *RenameTableName { return &out } +// EqualsRefOfRenameTableName does deep equals between the two objects. +func EqualsRefOfRenameTableName(a, b *RenameTableName) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsTableName(a.Table, b.Table) +} + // CloneTableOptions creates a deep clone of the input. func CloneTableOptions(n TableOptions) TableOptions { res := make(TableOptions, 0, len(n)) @@ -912,6 +2955,19 @@ func CloneTableOptions(n TableOptions) TableOptions { return res } +// EqualsTableOptions does deep equals between the two objects. +func EqualsTableOptions(a, b TableOptions) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfTableOption(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfTablespaceOperation creates a deep clone of the input. func CloneRefOfTablespaceOperation(n *TablespaceOperation) *TablespaceOperation { if n == nil { @@ -921,6 +2977,17 @@ func CloneRefOfTablespaceOperation(n *TablespaceOperation) *TablespaceOperation return &out } +// EqualsRefOfTablespaceOperation does deep equals between the two objects. +func EqualsRefOfTablespaceOperation(a, b *TablespaceOperation) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Import == b.Import +} + // CloneRefOfValidation creates a deep clone of the input. func CloneRefOfValidation(n *Validation) *Validation { if n == nil { @@ -930,6 +2997,17 @@ func CloneRefOfValidation(n *Validation) *Validation { return &out } +// EqualsRefOfValidation does deep equals between the two objects. +func EqualsRefOfValidation(a, b *Validation) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.With == b.With +} + // CloneListArg creates a deep clone of the input. func CloneListArg(n ListArg) ListArg { res := make(ListArg, 0, len(n)) @@ -937,6 +3015,19 @@ func CloneListArg(n ListArg) ListArg { return res } +// EqualsListArg does deep equals between the two objects. +func EqualsListArg(a, b ListArg) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if a[i] != b[i] { + return false + } + } + return true +} + // CloneRefOfSubquery creates a deep clone of the input. func CloneRefOfSubquery(n *Subquery) *Subquery { if n == nil { @@ -947,6 +3038,17 @@ func CloneRefOfSubquery(n *Subquery) *Subquery { return &out } +// EqualsRefOfSubquery does deep equals between the two objects. +func EqualsRefOfSubquery(a, b *Subquery) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsSelectStatement(a.Select, b.Select) +} + // CloneValTuple creates a deep clone of the input. func CloneValTuple(n ValTuple) ValTuple { res := make(ValTuple, 0, len(n)) @@ -956,6 +3058,19 @@ func CloneValTuple(n ValTuple) ValTuple { return res } +// EqualsValTuple does deep equals between the two objects. +func EqualsValTuple(a, b ValTuple) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsExpr(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfCheckConstraintDefinition creates a deep clone of the input. func CloneRefOfCheckConstraintDefinition(n *CheckConstraintDefinition) *CheckConstraintDefinition { if n == nil { @@ -966,6 +3081,18 @@ func CloneRefOfCheckConstraintDefinition(n *CheckConstraintDefinition) *CheckCon return &out } +// EqualsRefOfCheckConstraintDefinition does deep equals between the two objects. +func EqualsRefOfCheckConstraintDefinition(a, b *CheckConstraintDefinition) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Enforced == b.Enforced && + EqualsExpr(a.Expr, b.Expr) +} + // CloneRefOfForeignKeyDefinition creates a deep clone of the input. func CloneRefOfForeignKeyDefinition(n *ForeignKeyDefinition) *ForeignKeyDefinition { if n == nil { @@ -978,6 +3105,21 @@ func CloneRefOfForeignKeyDefinition(n *ForeignKeyDefinition) *ForeignKeyDefiniti return &out } +// EqualsRefOfForeignKeyDefinition does deep equals between the two objects. +func EqualsRefOfForeignKeyDefinition(a, b *ForeignKeyDefinition) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsColumns(a.Source, b.Source) && + EqualsTableName(a.ReferencedTable, b.ReferencedTable) && + EqualsColumns(a.ReferencedColumns, b.ReferencedColumns) && + a.OnDelete == b.OnDelete && + a.OnUpdate == b.OnUpdate +} + // CloneRefOfAlterDatabase creates a deep clone of the input. func CloneRefOfAlterDatabase(n *AlterDatabase) *AlterDatabase { if n == nil { @@ -988,6 +3130,20 @@ func CloneRefOfAlterDatabase(n *AlterDatabase) *AlterDatabase { return &out } +// EqualsRefOfAlterDatabase does deep equals between the two objects. +func EqualsRefOfAlterDatabase(a, b *AlterDatabase) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.DBName == b.DBName && + a.UpdateDataDirectory == b.UpdateDataDirectory && + a.FullyParsed == b.FullyParsed && + EqualsSliceOfCollateAndCharset(a.AlterOptions, b.AlterOptions) +} + // CloneRefOfCreateDatabase creates a deep clone of the input. func CloneRefOfCreateDatabase(n *CreateDatabase) *CreateDatabase { if n == nil { @@ -999,6 +3155,21 @@ func CloneRefOfCreateDatabase(n *CreateDatabase) *CreateDatabase { return &out } +// EqualsRefOfCreateDatabase does deep equals between the two objects. +func EqualsRefOfCreateDatabase(a, b *CreateDatabase) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.DBName == b.DBName && + a.IfNotExists == b.IfNotExists && + a.FullyParsed == b.FullyParsed && + EqualsComments(a.Comments, b.Comments) && + EqualsSliceOfCollateAndCharset(a.CreateOptions, b.CreateOptions) +} + // CloneRefOfDropDatabase creates a deep clone of the input. func CloneRefOfDropDatabase(n *DropDatabase) *DropDatabase { if n == nil { @@ -1009,6 +3180,19 @@ func CloneRefOfDropDatabase(n *DropDatabase) *DropDatabase { return &out } +// EqualsRefOfDropDatabase does deep equals between the two objects. +func EqualsRefOfDropDatabase(a, b *DropDatabase) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.DBName == b.DBName && + a.IfExists == b.IfExists && + EqualsComments(a.Comments, b.Comments) +} + // CloneRefOfAlterTable creates a deep clone of the input. func CloneRefOfAlterTable(n *AlterTable) *AlterTable { if n == nil { @@ -1021,6 +3205,20 @@ func CloneRefOfAlterTable(n *AlterTable) *AlterTable { return &out } +// EqualsRefOfAlterTable does deep equals between the two objects. +func EqualsRefOfAlterTable(a, b *AlterTable) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.FullyParsed == b.FullyParsed && + EqualsTableName(a.Table, b.Table) && + EqualsSliceOfAlterOption(a.AlterOptions, b.AlterOptions) && + EqualsRefOfPartitionSpec(a.PartitionSpec, b.PartitionSpec) +} + // CloneRefOfAlterView creates a deep clone of the input. func CloneRefOfAlterView(n *AlterView) *AlterView { if n == nil { @@ -1033,6 +3231,23 @@ func CloneRefOfAlterView(n *AlterView) *AlterView { return &out } +// EqualsRefOfAlterView does deep equals between the two objects. +func EqualsRefOfAlterView(a, b *AlterView) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Algorithm == b.Algorithm && + a.Definer == b.Definer && + a.Security == b.Security && + a.CheckOption == b.CheckOption && + EqualsTableName(a.ViewName, b.ViewName) && + EqualsColumns(a.Columns, b.Columns) && + EqualsSelectStatement(a.Select, b.Select) +} + // CloneRefOfCreateTable creates a deep clone of the input. func CloneRefOfCreateTable(n *CreateTable) *CreateTable { if n == nil { @@ -1045,6 +3260,22 @@ func CloneRefOfCreateTable(n *CreateTable) *CreateTable { return &out } +// EqualsRefOfCreateTable does deep equals between the two objects. +func EqualsRefOfCreateTable(a, b *CreateTable) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Temp == b.Temp && + a.IfNotExists == b.IfNotExists && + a.FullyParsed == b.FullyParsed && + EqualsTableName(a.Table, b.Table) && + EqualsRefOfTableSpec(a.TableSpec, b.TableSpec) && + EqualsRefOfOptLike(a.OptLike, b.OptLike) +} + // CloneRefOfCreateView creates a deep clone of the input. func CloneRefOfCreateView(n *CreateView) *CreateView { if n == nil { @@ -1057,6 +3288,24 @@ func CloneRefOfCreateView(n *CreateView) *CreateView { return &out } +// EqualsRefOfCreateView does deep equals between the two objects. +func EqualsRefOfCreateView(a, b *CreateView) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Algorithm == b.Algorithm && + a.Definer == b.Definer && + a.Security == b.Security && + a.CheckOption == b.CheckOption && + a.IsReplace == b.IsReplace && + EqualsTableName(a.ViewName, b.ViewName) && + EqualsColumns(a.Columns, b.Columns) && + EqualsSelectStatement(a.Select, b.Select) +} + // CloneRefOfDropTable creates a deep clone of the input. func CloneRefOfDropTable(n *DropTable) *DropTable { if n == nil { @@ -1067,6 +3316,19 @@ func CloneRefOfDropTable(n *DropTable) *DropTable { return &out } +// EqualsRefOfDropTable does deep equals between the two objects. +func EqualsRefOfDropTable(a, b *DropTable) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Temp == b.Temp && + a.IfExists == b.IfExists && + EqualsTableNames(a.FromTables, b.FromTables) +} + // CloneRefOfDropView creates a deep clone of the input. func CloneRefOfDropView(n *DropView) *DropView { if n == nil { @@ -1077,6 +3339,18 @@ func CloneRefOfDropView(n *DropView) *DropView { return &out } +// EqualsRefOfDropView does deep equals between the two objects. +func EqualsRefOfDropView(a, b *DropView) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.IfExists == b.IfExists && + EqualsTableNames(a.FromTables, b.FromTables) +} + // CloneRefOfRenameTable creates a deep clone of the input. func CloneRefOfRenameTable(n *RenameTable) *RenameTable { if n == nil { @@ -1087,6 +3361,17 @@ func CloneRefOfRenameTable(n *RenameTable) *RenameTable { return &out } +// EqualsRefOfRenameTable does deep equals between the two objects. +func EqualsRefOfRenameTable(a, b *RenameTable) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsSliceOfRefOfRenameTablePair(a.TablePairs, b.TablePairs) +} + // CloneRefOfTruncateTable creates a deep clone of the input. func CloneRefOfTruncateTable(n *TruncateTable) *TruncateTable { if n == nil { @@ -1097,6 +3382,17 @@ func CloneRefOfTruncateTable(n *TruncateTable) *TruncateTable { return &out } +// EqualsRefOfTruncateTable does deep equals between the two objects. +func EqualsRefOfTruncateTable(a, b *TruncateTable) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsTableName(a.Table, b.Table) +} + // CloneRefOfExplainStmt creates a deep clone of the input. func CloneRefOfExplainStmt(n *ExplainStmt) *ExplainStmt { if n == nil { @@ -1107,6 +3403,18 @@ func CloneRefOfExplainStmt(n *ExplainStmt) *ExplainStmt { return &out } +// EqualsRefOfExplainStmt does deep equals between the two objects. +func EqualsRefOfExplainStmt(a, b *ExplainStmt) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Type == b.Type && + EqualsStatement(a.Statement, b.Statement) +} + // CloneRefOfExplainTab creates a deep clone of the input. func CloneRefOfExplainTab(n *ExplainTab) *ExplainTab { if n == nil { @@ -1117,6 +3425,18 @@ func CloneRefOfExplainTab(n *ExplainTab) *ExplainTab { return &out } +// EqualsRefOfExplainTab does deep equals between the two objects. +func EqualsRefOfExplainTab(a, b *ExplainTab) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Wild == b.Wild && + EqualsTableName(a.Table, b.Table) +} + // CloneRefOfAndExpr creates a deep clone of the input. func CloneRefOfAndExpr(n *AndExpr) *AndExpr { if n == nil { @@ -1128,6 +3448,18 @@ func CloneRefOfAndExpr(n *AndExpr) *AndExpr { return &out } +// EqualsRefOfAndExpr does deep equals between the two objects. +func EqualsRefOfAndExpr(a, b *AndExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsExpr(a.Left, b.Left) && + EqualsExpr(a.Right, b.Right) +} + // CloneRefOfBinaryExpr creates a deep clone of the input. func CloneRefOfBinaryExpr(n *BinaryExpr) *BinaryExpr { if n == nil { @@ -1139,6 +3471,19 @@ func CloneRefOfBinaryExpr(n *BinaryExpr) *BinaryExpr { return &out } +// EqualsRefOfBinaryExpr does deep equals between the two objects. +func EqualsRefOfBinaryExpr(a, b *BinaryExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Operator == b.Operator && + EqualsExpr(a.Left, b.Left) && + EqualsExpr(a.Right, b.Right) +} + // CloneRefOfCaseExpr creates a deep clone of the input. func CloneRefOfCaseExpr(n *CaseExpr) *CaseExpr { if n == nil { @@ -1151,11 +3496,36 @@ func CloneRefOfCaseExpr(n *CaseExpr) *CaseExpr { return &out } +// EqualsRefOfCaseExpr does deep equals between the two objects. +func EqualsRefOfCaseExpr(a, b *CaseExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsExpr(a.Expr, b.Expr) && + EqualsSliceOfRefOfWhen(a.Whens, b.Whens) && + EqualsExpr(a.Else, b.Else) +} + // CloneRefOfColName creates a deep clone of the input. func CloneRefOfColName(n *ColName) *ColName { return n } +// EqualsRefOfColName does deep equals between the two objects. +func EqualsRefOfColName(a, b *ColName) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsColIdent(a.Name, b.Name) && + EqualsTableName(a.Qualifier, b.Qualifier) +} + // CloneRefOfCollateExpr creates a deep clone of the input. func CloneRefOfCollateExpr(n *CollateExpr) *CollateExpr { if n == nil { @@ -1166,6 +3536,18 @@ func CloneRefOfCollateExpr(n *CollateExpr) *CollateExpr { return &out } +// EqualsRefOfCollateExpr does deep equals between the two objects. +func EqualsRefOfCollateExpr(a, b *CollateExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Charset == b.Charset && + EqualsExpr(a.Expr, b.Expr) +} + // CloneRefOfComparisonExpr creates a deep clone of the input. func CloneRefOfComparisonExpr(n *ComparisonExpr) *ComparisonExpr { if n == nil { @@ -1178,6 +3560,20 @@ func CloneRefOfComparisonExpr(n *ComparisonExpr) *ComparisonExpr { return &out } +// EqualsRefOfComparisonExpr does deep equals between the two objects. +func EqualsRefOfComparisonExpr(a, b *ComparisonExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Operator == b.Operator && + EqualsExpr(a.Left, b.Left) && + EqualsExpr(a.Right, b.Right) && + EqualsExpr(a.Escape, b.Escape) +} + // CloneRefOfConvertExpr creates a deep clone of the input. func CloneRefOfConvertExpr(n *ConvertExpr) *ConvertExpr { if n == nil { @@ -1189,6 +3585,18 @@ func CloneRefOfConvertExpr(n *ConvertExpr) *ConvertExpr { return &out } +// EqualsRefOfConvertExpr does deep equals between the two objects. +func EqualsRefOfConvertExpr(a, b *ConvertExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsExpr(a.Expr, b.Expr) && + EqualsRefOfConvertType(a.Type, b.Type) +} + // CloneRefOfConvertUsingExpr creates a deep clone of the input. func CloneRefOfConvertUsingExpr(n *ConvertUsingExpr) *ConvertUsingExpr { if n == nil { @@ -1199,6 +3607,18 @@ func CloneRefOfConvertUsingExpr(n *ConvertUsingExpr) *ConvertUsingExpr { return &out } +// EqualsRefOfConvertUsingExpr does deep equals between the two objects. +func EqualsRefOfConvertUsingExpr(a, b *ConvertUsingExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Type == b.Type && + EqualsExpr(a.Expr, b.Expr) +} + // CloneRefOfCurTimeFuncExpr creates a deep clone of the input. func CloneRefOfCurTimeFuncExpr(n *CurTimeFuncExpr) *CurTimeFuncExpr { if n == nil { @@ -1210,6 +3630,18 @@ func CloneRefOfCurTimeFuncExpr(n *CurTimeFuncExpr) *CurTimeFuncExpr { return &out } +// EqualsRefOfCurTimeFuncExpr does deep equals between the two objects. +func EqualsRefOfCurTimeFuncExpr(a, b *CurTimeFuncExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsColIdent(a.Name, b.Name) && + EqualsExpr(a.Fsp, b.Fsp) +} + // CloneRefOfDefault creates a deep clone of the input. func CloneRefOfDefault(n *Default) *Default { if n == nil { @@ -1219,6 +3651,17 @@ func CloneRefOfDefault(n *Default) *Default { return &out } +// EqualsRefOfDefault does deep equals between the two objects. +func EqualsRefOfDefault(a, b *Default) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.ColName == b.ColName +} + // CloneRefOfExistsExpr creates a deep clone of the input. func CloneRefOfExistsExpr(n *ExistsExpr) *ExistsExpr { if n == nil { @@ -1229,6 +3672,17 @@ func CloneRefOfExistsExpr(n *ExistsExpr) *ExistsExpr { return &out } +// EqualsRefOfExistsExpr does deep equals between the two objects. +func EqualsRefOfExistsExpr(a, b *ExistsExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsRefOfSubquery(a.Subquery, b.Subquery) +} + // CloneRefOfFuncExpr creates a deep clone of the input. func CloneRefOfFuncExpr(n *FuncExpr) *FuncExpr { if n == nil { @@ -1241,6 +3695,20 @@ func CloneRefOfFuncExpr(n *FuncExpr) *FuncExpr { return &out } +// EqualsRefOfFuncExpr does deep equals between the two objects. +func EqualsRefOfFuncExpr(a, b *FuncExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Distinct == b.Distinct && + EqualsTableIdent(a.Qualifier, b.Qualifier) && + EqualsColIdent(a.Name, b.Name) && + EqualsSelectExprs(a.Exprs, b.Exprs) +} + // CloneRefOfGroupConcatExpr creates a deep clone of the input. func CloneRefOfGroupConcatExpr(n *GroupConcatExpr) *GroupConcatExpr { if n == nil { @@ -1253,6 +3721,21 @@ func CloneRefOfGroupConcatExpr(n *GroupConcatExpr) *GroupConcatExpr { return &out } +// EqualsRefOfGroupConcatExpr does deep equals between the two objects. +func EqualsRefOfGroupConcatExpr(a, b *GroupConcatExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Distinct == b.Distinct && + a.Separator == b.Separator && + EqualsSelectExprs(a.Exprs, b.Exprs) && + EqualsOrderBy(a.OrderBy, b.OrderBy) && + EqualsRefOfLimit(a.Limit, b.Limit) +} + // CloneRefOfIntervalExpr creates a deep clone of the input. func CloneRefOfIntervalExpr(n *IntervalExpr) *IntervalExpr { if n == nil { @@ -1263,6 +3746,18 @@ func CloneRefOfIntervalExpr(n *IntervalExpr) *IntervalExpr { return &out } +// EqualsRefOfIntervalExpr does deep equals between the two objects. +func EqualsRefOfIntervalExpr(a, b *IntervalExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Unit == b.Unit && + EqualsExpr(a.Expr, b.Expr) +} + // CloneRefOfIsExpr creates a deep clone of the input. func CloneRefOfIsExpr(n *IsExpr) *IsExpr { if n == nil { @@ -1273,6 +3768,18 @@ func CloneRefOfIsExpr(n *IsExpr) *IsExpr { return &out } +// EqualsRefOfIsExpr does deep equals between the two objects. +func EqualsRefOfIsExpr(a, b *IsExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Operator == b.Operator && + EqualsExpr(a.Expr, b.Expr) +} + // CloneRefOfLiteral creates a deep clone of the input. func CloneRefOfLiteral(n *Literal) *Literal { if n == nil { @@ -1282,6 +3789,18 @@ func CloneRefOfLiteral(n *Literal) *Literal { return &out } +// EqualsRefOfLiteral does deep equals between the two objects. +func EqualsRefOfLiteral(a, b *Literal) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Val == b.Val && + a.Type == b.Type +} + // CloneRefOfMatchExpr creates a deep clone of the input. func CloneRefOfMatchExpr(n *MatchExpr) *MatchExpr { if n == nil { @@ -1293,6 +3812,19 @@ func CloneRefOfMatchExpr(n *MatchExpr) *MatchExpr { return &out } +// EqualsRefOfMatchExpr does deep equals between the two objects. +func EqualsRefOfMatchExpr(a, b *MatchExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsSelectExprs(a.Columns, b.Columns) && + EqualsExpr(a.Expr, b.Expr) && + a.Option == b.Option +} + // CloneRefOfNotExpr creates a deep clone of the input. func CloneRefOfNotExpr(n *NotExpr) *NotExpr { if n == nil { @@ -1303,6 +3835,17 @@ func CloneRefOfNotExpr(n *NotExpr) *NotExpr { return &out } +// EqualsRefOfNotExpr does deep equals between the two objects. +func EqualsRefOfNotExpr(a, b *NotExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsExpr(a.Expr, b.Expr) +} + // CloneRefOfNullVal creates a deep clone of the input. func CloneRefOfNullVal(n *NullVal) *NullVal { if n == nil { @@ -1312,6 +3855,17 @@ func CloneRefOfNullVal(n *NullVal) *NullVal { return &out } +// EqualsRefOfNullVal does deep equals between the two objects. +func EqualsRefOfNullVal(a, b *NullVal) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return true +} + // CloneRefOfOrExpr creates a deep clone of the input. func CloneRefOfOrExpr(n *OrExpr) *OrExpr { if n == nil { @@ -1323,6 +3877,18 @@ func CloneRefOfOrExpr(n *OrExpr) *OrExpr { return &out } +// EqualsRefOfOrExpr does deep equals between the two objects. +func EqualsRefOfOrExpr(a, b *OrExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsExpr(a.Left, b.Left) && + EqualsExpr(a.Right, b.Right) +} + // CloneRefOfRangeCond creates a deep clone of the input. func CloneRefOfRangeCond(n *RangeCond) *RangeCond { if n == nil { @@ -1335,6 +3901,20 @@ func CloneRefOfRangeCond(n *RangeCond) *RangeCond { return &out } +// EqualsRefOfRangeCond does deep equals between the two objects. +func EqualsRefOfRangeCond(a, b *RangeCond) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Operator == b.Operator && + EqualsExpr(a.Left, b.Left) && + EqualsExpr(a.From, b.From) && + EqualsExpr(a.To, b.To) +} + // CloneRefOfSubstrExpr creates a deep clone of the input. func CloneRefOfSubstrExpr(n *SubstrExpr) *SubstrExpr { if n == nil { @@ -1348,6 +3928,20 @@ func CloneRefOfSubstrExpr(n *SubstrExpr) *SubstrExpr { return &out } +// EqualsRefOfSubstrExpr does deep equals between the two objects. +func EqualsRefOfSubstrExpr(a, b *SubstrExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsRefOfColName(a.Name, b.Name) && + EqualsRefOfLiteral(a.StrVal, b.StrVal) && + EqualsExpr(a.From, b.From) && + EqualsExpr(a.To, b.To) +} + // CloneRefOfTimestampFuncExpr creates a deep clone of the input. func CloneRefOfTimestampFuncExpr(n *TimestampFuncExpr) *TimestampFuncExpr { if n == nil { @@ -1359,6 +3953,20 @@ func CloneRefOfTimestampFuncExpr(n *TimestampFuncExpr) *TimestampFuncExpr { return &out } +// EqualsRefOfTimestampFuncExpr does deep equals between the two objects. +func EqualsRefOfTimestampFuncExpr(a, b *TimestampFuncExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Name == b.Name && + a.Unit == b.Unit && + EqualsExpr(a.Expr1, b.Expr1) && + EqualsExpr(a.Expr2, b.Expr2) +} + // CloneRefOfUnaryExpr creates a deep clone of the input. func CloneRefOfUnaryExpr(n *UnaryExpr) *UnaryExpr { if n == nil { @@ -1369,6 +3977,18 @@ func CloneRefOfUnaryExpr(n *UnaryExpr) *UnaryExpr { return &out } +// EqualsRefOfUnaryExpr does deep equals between the two objects. +func EqualsRefOfUnaryExpr(a, b *UnaryExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Operator == b.Operator && + EqualsExpr(a.Expr, b.Expr) +} + // CloneRefOfValuesFuncExpr creates a deep clone of the input. func CloneRefOfValuesFuncExpr(n *ValuesFuncExpr) *ValuesFuncExpr { if n == nil { @@ -1379,6 +3999,17 @@ func CloneRefOfValuesFuncExpr(n *ValuesFuncExpr) *ValuesFuncExpr { return &out } +// EqualsRefOfValuesFuncExpr does deep equals between the two objects. +func EqualsRefOfValuesFuncExpr(a, b *ValuesFuncExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsRefOfColName(a.Name, b.Name) +} + // CloneRefOfXorExpr creates a deep clone of the input. func CloneRefOfXorExpr(n *XorExpr) *XorExpr { if n == nil { @@ -1390,6 +4021,18 @@ func CloneRefOfXorExpr(n *XorExpr) *XorExpr { return &out } +// EqualsRefOfXorExpr does deep equals between the two objects. +func EqualsRefOfXorExpr(a, b *XorExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsExpr(a.Left, b.Left) && + EqualsExpr(a.Right, b.Right) +} + // CloneRefOfParenSelect creates a deep clone of the input. func CloneRefOfParenSelect(n *ParenSelect) *ParenSelect { if n == nil { @@ -1400,13 +4043,24 @@ func CloneRefOfParenSelect(n *ParenSelect) *ParenSelect { return &out } +// EqualsRefOfParenSelect does deep equals between the two objects. +func EqualsRefOfParenSelect(a, b *ParenSelect) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsSelectStatement(a.Select, b.Select) +} + // CloneRefOfSelect creates a deep clone of the input. func CloneRefOfSelect(n *Select) *Select { if n == nil { return nil } out := *n - out.Cache = CloneRefOfbool(n.Cache) + out.Cache = CloneRefOfBool(n.Cache) out.Comments = CloneComments(n.Comments) out.SelectExprs = CloneSelectExprs(n.SelectExprs) out.From = CloneTableExprs(n.From) @@ -1419,6 +4073,30 @@ func CloneRefOfSelect(n *Select) *Select { return &out } +// EqualsRefOfSelect does deep equals between the two objects. +func EqualsRefOfSelect(a, b *Select) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Distinct == b.Distinct && + a.StraightJoinHint == b.StraightJoinHint && + a.SQLCalcFoundRows == b.SQLCalcFoundRows && + EqualsRefOfBool(a.Cache, b.Cache) && + EqualsComments(a.Comments, b.Comments) && + EqualsSelectExprs(a.SelectExprs, b.SelectExprs) && + EqualsTableExprs(a.From, b.From) && + EqualsRefOfWhere(a.Where, b.Where) && + EqualsGroupBy(a.GroupBy, b.GroupBy) && + EqualsRefOfWhere(a.Having, b.Having) && + EqualsOrderBy(a.OrderBy, b.OrderBy) && + EqualsRefOfLimit(a.Limit, b.Limit) && + a.Lock == b.Lock && + EqualsRefOfSelectInto(a.Into, b.Into) +} + // CloneRefOfUnion creates a deep clone of the input. func CloneRefOfUnion(n *Union) *Union { if n == nil { @@ -1432,6 +4110,21 @@ func CloneRefOfUnion(n *Union) *Union { return &out } +// EqualsRefOfUnion does deep equals between the two objects. +func EqualsRefOfUnion(a, b *Union) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsSelectStatement(a.FirstStatement, b.FirstStatement) && + EqualsSliceOfRefOfUnionSelect(a.UnionSelects, b.UnionSelects) && + EqualsOrderBy(a.OrderBy, b.OrderBy) && + EqualsRefOfLimit(a.Limit, b.Limit) && + a.Lock == b.Lock +} + // CloneValues creates a deep clone of the input. func CloneValues(n Values) Values { res := make(Values, 0, len(n)) @@ -1441,6 +4134,19 @@ func CloneValues(n Values) Values { return res } +// EqualsValues does deep equals between the two objects. +func EqualsValues(a, b Values) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsValTuple(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfAliasedExpr creates a deep clone of the input. func CloneRefOfAliasedExpr(n *AliasedExpr) *AliasedExpr { if n == nil { @@ -1452,6 +4158,18 @@ func CloneRefOfAliasedExpr(n *AliasedExpr) *AliasedExpr { return &out } +// EqualsRefOfAliasedExpr does deep equals between the two objects. +func EqualsRefOfAliasedExpr(a, b *AliasedExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsExpr(a.Expr, b.Expr) && + EqualsColIdent(a.As, b.As) +} + // CloneRefOfAliasedTableExpr creates a deep clone of the input. func CloneRefOfAliasedTableExpr(n *AliasedTableExpr) *AliasedTableExpr { if n == nil { @@ -1465,6 +4183,20 @@ func CloneRefOfAliasedTableExpr(n *AliasedTableExpr) *AliasedTableExpr { return &out } +// EqualsRefOfAliasedTableExpr does deep equals between the two objects. +func EqualsRefOfAliasedTableExpr(a, b *AliasedTableExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsSimpleTableExpr(a.Expr, b.Expr) && + EqualsPartitions(a.Partitions, b.Partitions) && + EqualsTableIdent(a.As, b.As) && + EqualsRefOfIndexHints(a.Hints, b.Hints) +} + // CloneRefOfAlterVschema creates a deep clone of the input. func CloneRefOfAlterVschema(n *AlterVschema) *AlterVschema { if n == nil { @@ -1478,6 +4210,21 @@ func CloneRefOfAlterVschema(n *AlterVschema) *AlterVschema { return &out } +// EqualsRefOfAlterVschema does deep equals between the two objects. +func EqualsRefOfAlterVschema(a, b *AlterVschema) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Action == b.Action && + EqualsTableName(a.Table, b.Table) && + EqualsRefOfVindexSpec(a.VindexSpec, b.VindexSpec) && + EqualsSliceOfColIdent(a.VindexCols, b.VindexCols) && + EqualsRefOfAutoIncSpec(a.AutoIncSpec, b.AutoIncSpec) +} + // CloneRefOfAutoIncSpec creates a deep clone of the input. func CloneRefOfAutoIncSpec(n *AutoIncSpec) *AutoIncSpec { if n == nil { @@ -1489,6 +4236,18 @@ func CloneRefOfAutoIncSpec(n *AutoIncSpec) *AutoIncSpec { return &out } +// EqualsRefOfAutoIncSpec does deep equals between the two objects. +func EqualsRefOfAutoIncSpec(a, b *AutoIncSpec) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsColIdent(a.Column, b.Column) && + EqualsTableName(a.Sequence, b.Sequence) +} + // CloneRefOfBegin creates a deep clone of the input. func CloneRefOfBegin(n *Begin) *Begin { if n == nil { @@ -1498,6 +4257,17 @@ func CloneRefOfBegin(n *Begin) *Begin { return &out } +// EqualsRefOfBegin does deep equals between the two objects. +func EqualsRefOfBegin(a, b *Begin) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return true +} + // CloneRefOfCallProc creates a deep clone of the input. func CloneRefOfCallProc(n *CallProc) *CallProc { if n == nil { @@ -1509,11 +4279,30 @@ func CloneRefOfCallProc(n *CallProc) *CallProc { return &out } +// EqualsRefOfCallProc does deep equals between the two objects. +func EqualsRefOfCallProc(a, b *CallProc) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsTableName(a.Name, b.Name) && + EqualsExprs(a.Params, b.Params) +} + // CloneColIdent creates a deep clone of the input. func CloneColIdent(n ColIdent) ColIdent { return *CloneRefOfColIdent(&n) } +// EqualsColIdent does deep equals between the two objects. +func EqualsColIdent(a, b ColIdent) bool { + return a.val == b.val && + a.lowered == b.lowered && + a.at == b.at +} + // CloneRefOfColumnDefinition creates a deep clone of the input. func CloneRefOfColumnDefinition(n *ColumnDefinition) *ColumnDefinition { if n == nil { @@ -1525,6 +4314,18 @@ func CloneRefOfColumnDefinition(n *ColumnDefinition) *ColumnDefinition { return &out } +// EqualsRefOfColumnDefinition does deep equals between the two objects. +func EqualsRefOfColumnDefinition(a, b *ColumnDefinition) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsColIdent(a.Name, b.Name) && + EqualsColumnType(a.Type, b.Type) +} + // CloneRefOfColumnType creates a deep clone of the input. func CloneRefOfColumnType(n *ColumnType) *ColumnType { if n == nil { @@ -1534,10 +4335,29 @@ func CloneRefOfColumnType(n *ColumnType) *ColumnType { out.Options = CloneRefOfColumnTypeOptions(n.Options) out.Length = CloneRefOfLiteral(n.Length) out.Scale = CloneRefOfLiteral(n.Scale) - out.EnumValues = CloneSliceOfstring(n.EnumValues) + out.EnumValues = CloneSliceOfString(n.EnumValues) return &out } +// EqualsRefOfColumnType does deep equals between the two objects. +func EqualsRefOfColumnType(a, b *ColumnType) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Type == b.Type && + a.Unsigned == b.Unsigned && + a.Zerofill == b.Zerofill && + a.Charset == b.Charset && + a.Collate == b.Collate && + EqualsRefOfColumnTypeOptions(a.Options, b.Options) && + EqualsRefOfLiteral(a.Length, b.Length) && + EqualsRefOfLiteral(a.Scale, b.Scale) && + EqualsSliceOfString(a.EnumValues, b.EnumValues) +} + // CloneColumns creates a deep clone of the input. func CloneColumns(n Columns) Columns { res := make(Columns, 0, len(n)) @@ -1547,6 +4367,19 @@ func CloneColumns(n Columns) Columns { return res } +// EqualsColumns does deep equals between the two objects. +func EqualsColumns(a, b Columns) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsColIdent(a[i], b[i]) { + return false + } + } + return true +} + // CloneComments creates a deep clone of the input. func CloneComments(n Comments) Comments { res := make(Comments, 0, len(n)) @@ -1554,6 +4387,19 @@ func CloneComments(n Comments) Comments { return res } +// EqualsComments does deep equals between the two objects. +func EqualsComments(a, b Comments) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if a[i] != b[i] { + return false + } + } + return true +} + // CloneRefOfCommit creates a deep clone of the input. func CloneRefOfCommit(n *Commit) *Commit { if n == nil { @@ -1563,6 +4409,17 @@ func CloneRefOfCommit(n *Commit) *Commit { return &out } +// EqualsRefOfCommit does deep equals between the two objects. +func EqualsRefOfCommit(a, b *Commit) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return true +} + // CloneRefOfConstraintDefinition creates a deep clone of the input. func CloneRefOfConstraintDefinition(n *ConstraintDefinition) *ConstraintDefinition { if n == nil { @@ -1573,6 +4430,18 @@ func CloneRefOfConstraintDefinition(n *ConstraintDefinition) *ConstraintDefiniti return &out } +// EqualsRefOfConstraintDefinition does deep equals between the two objects. +func EqualsRefOfConstraintDefinition(a, b *ConstraintDefinition) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Name == b.Name && + EqualsConstraintInfo(a.Details, b.Details) +} + // CloneRefOfConvertType creates a deep clone of the input. func CloneRefOfConvertType(n *ConvertType) *ConvertType { if n == nil { @@ -1584,6 +4453,21 @@ func CloneRefOfConvertType(n *ConvertType) *ConvertType { return &out } +// EqualsRefOfConvertType does deep equals between the two objects. +func EqualsRefOfConvertType(a, b *ConvertType) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Type == b.Type && + a.Charset == b.Charset && + EqualsRefOfLiteral(a.Length, b.Length) && + EqualsRefOfLiteral(a.Scale, b.Scale) && + a.Operator == b.Operator +} + // CloneRefOfDelete creates a deep clone of the input. func CloneRefOfDelete(n *Delete) *Delete { if n == nil { @@ -1600,6 +4484,24 @@ func CloneRefOfDelete(n *Delete) *Delete { return &out } +// EqualsRefOfDelete does deep equals between the two objects. +func EqualsRefOfDelete(a, b *Delete) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Ignore == b.Ignore && + EqualsComments(a.Comments, b.Comments) && + EqualsTableNames(a.Targets, b.Targets) && + EqualsTableExprs(a.TableExprs, b.TableExprs) && + EqualsPartitions(a.Partitions, b.Partitions) && + EqualsRefOfWhere(a.Where, b.Where) && + EqualsOrderBy(a.OrderBy, b.OrderBy) && + EqualsRefOfLimit(a.Limit, b.Limit) +} + // CloneRefOfDerivedTable creates a deep clone of the input. func CloneRefOfDerivedTable(n *DerivedTable) *DerivedTable { if n == nil { @@ -1610,6 +4512,17 @@ func CloneRefOfDerivedTable(n *DerivedTable) *DerivedTable { return &out } +// EqualsRefOfDerivedTable does deep equals between the two objects. +func EqualsRefOfDerivedTable(a, b *DerivedTable) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsSelectStatement(a.Select, b.Select) +} + // CloneExprs creates a deep clone of the input. func CloneExprs(n Exprs) Exprs { res := make(Exprs, 0, len(n)) @@ -1619,17 +4532,45 @@ func CloneExprs(n Exprs) Exprs { return res } +// EqualsExprs does deep equals between the two objects. +func EqualsExprs(a, b Exprs) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsExpr(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfFlush creates a deep clone of the input. func CloneRefOfFlush(n *Flush) *Flush { if n == nil { return nil } out := *n - out.FlushOptions = CloneSliceOfstring(n.FlushOptions) + out.FlushOptions = CloneSliceOfString(n.FlushOptions) out.TableNames = CloneTableNames(n.TableNames) return &out } +// EqualsRefOfFlush does deep equals between the two objects. +func EqualsRefOfFlush(a, b *Flush) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.IsLocal == b.IsLocal && + a.WithLock == b.WithLock && + a.ForExport == b.ForExport && + EqualsSliceOfString(a.FlushOptions, b.FlushOptions) && + EqualsTableNames(a.TableNames, b.TableNames) +} + // CloneGroupBy creates a deep clone of the input. func CloneGroupBy(n GroupBy) GroupBy { res := make(GroupBy, 0, len(n)) @@ -1639,6 +4580,19 @@ func CloneGroupBy(n GroupBy) GroupBy { return res } +// EqualsGroupBy does deep equals between the two objects. +func EqualsGroupBy(a, b GroupBy) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsExpr(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfIndexDefinition creates a deep clone of the input. func CloneRefOfIndexDefinition(n *IndexDefinition) *IndexDefinition { if n == nil { @@ -1651,6 +4605,19 @@ func CloneRefOfIndexDefinition(n *IndexDefinition) *IndexDefinition { return &out } +// EqualsRefOfIndexDefinition does deep equals between the two objects. +func EqualsRefOfIndexDefinition(a, b *IndexDefinition) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsRefOfIndexInfo(a.Info, b.Info) && + EqualsSliceOfRefOfIndexColumn(a.Columns, b.Columns) && + EqualsSliceOfRefOfIndexOption(a.Options, b.Options) +} + // CloneRefOfIndexHints creates a deep clone of the input. func CloneRefOfIndexHints(n *IndexHints) *IndexHints { if n == nil { @@ -1661,6 +4628,18 @@ func CloneRefOfIndexHints(n *IndexHints) *IndexHints { return &out } +// EqualsRefOfIndexHints does deep equals between the two objects. +func EqualsRefOfIndexHints(a, b *IndexHints) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Type == b.Type && + EqualsSliceOfColIdent(a.Indexes, b.Indexes) +} + // CloneRefOfIndexInfo creates a deep clone of the input. func CloneRefOfIndexInfo(n *IndexInfo) *IndexInfo { if n == nil { @@ -1672,6 +4651,23 @@ func CloneRefOfIndexInfo(n *IndexInfo) *IndexInfo { return &out } +// EqualsRefOfIndexInfo does deep equals between the two objects. +func EqualsRefOfIndexInfo(a, b *IndexInfo) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Type == b.Type && + a.Primary == b.Primary && + a.Spatial == b.Spatial && + a.Fulltext == b.Fulltext && + a.Unique == b.Unique && + EqualsColIdent(a.Name, b.Name) && + EqualsColIdent(a.ConstraintName, b.ConstraintName) +} + // CloneRefOfInsert creates a deep clone of the input. func CloneRefOfInsert(n *Insert) *Insert { if n == nil { @@ -1687,11 +4683,35 @@ func CloneRefOfInsert(n *Insert) *Insert { return &out } +// EqualsRefOfInsert does deep equals between the two objects. +func EqualsRefOfInsert(a, b *Insert) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Action == b.Action && + EqualsComments(a.Comments, b.Comments) && + a.Ignore == b.Ignore && + EqualsTableName(a.Table, b.Table) && + EqualsPartitions(a.Partitions, b.Partitions) && + EqualsColumns(a.Columns, b.Columns) && + EqualsInsertRows(a.Rows, b.Rows) && + EqualsOnDup(a.OnDup, b.OnDup) +} + // CloneJoinCondition creates a deep clone of the input. func CloneJoinCondition(n JoinCondition) JoinCondition { return *CloneRefOfJoinCondition(&n) } +// EqualsJoinCondition does deep equals between the two objects. +func EqualsJoinCondition(a, b JoinCondition) bool { + return EqualsExpr(a.On, b.On) && + EqualsColumns(a.Using, b.Using) +} + // CloneRefOfJoinTableExpr creates a deep clone of the input. func CloneRefOfJoinTableExpr(n *JoinTableExpr) *JoinTableExpr { if n == nil { @@ -1704,6 +4724,20 @@ func CloneRefOfJoinTableExpr(n *JoinTableExpr) *JoinTableExpr { return &out } +// EqualsRefOfJoinTableExpr does deep equals between the two objects. +func EqualsRefOfJoinTableExpr(a, b *JoinTableExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsTableExpr(a.LeftExpr, b.LeftExpr) && + a.Join == b.Join && + EqualsTableExpr(a.RightExpr, b.RightExpr) && + EqualsJoinCondition(a.Condition, b.Condition) +} + // CloneRefOfLimit creates a deep clone of the input. func CloneRefOfLimit(n *Limit) *Limit { if n == nil { @@ -1715,6 +4749,18 @@ func CloneRefOfLimit(n *Limit) *Limit { return &out } +// EqualsRefOfLimit does deep equals between the two objects. +func EqualsRefOfLimit(a, b *Limit) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsExpr(a.Offset, b.Offset) && + EqualsExpr(a.Rowcount, b.Rowcount) +} + // CloneRefOfLoad creates a deep clone of the input. func CloneRefOfLoad(n *Load) *Load { if n == nil { @@ -1724,6 +4770,17 @@ func CloneRefOfLoad(n *Load) *Load { return &out } +// EqualsRefOfLoad does deep equals between the two objects. +func EqualsRefOfLoad(a, b *Load) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return true +} + // CloneRefOfLockTables creates a deep clone of the input. func CloneRefOfLockTables(n *LockTables) *LockTables { if n == nil { @@ -1734,6 +4791,17 @@ func CloneRefOfLockTables(n *LockTables) *LockTables { return &out } +// EqualsRefOfLockTables does deep equals between the two objects. +func EqualsRefOfLockTables(a, b *LockTables) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsTableAndLockTypes(a.Tables, b.Tables) +} + // CloneRefOfNextval creates a deep clone of the input. func CloneRefOfNextval(n *Nextval) *Nextval { if n == nil { @@ -1744,6 +4812,17 @@ func CloneRefOfNextval(n *Nextval) *Nextval { return &out } +// EqualsRefOfNextval does deep equals between the two objects. +func EqualsRefOfNextval(a, b *Nextval) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsExpr(a.Expr, b.Expr) +} + // CloneOnDup creates a deep clone of the input. func CloneOnDup(n OnDup) OnDup { res := make(OnDup, 0, len(n)) @@ -1753,6 +4832,19 @@ func CloneOnDup(n OnDup) OnDup { return res } +// EqualsOnDup does deep equals between the two objects. +func EqualsOnDup(a, b OnDup) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfUpdateExpr(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfOptLike creates a deep clone of the input. func CloneRefOfOptLike(n *OptLike) *OptLike { if n == nil { @@ -1763,6 +4855,17 @@ func CloneRefOfOptLike(n *OptLike) *OptLike { return &out } +// EqualsRefOfOptLike does deep equals between the two objects. +func EqualsRefOfOptLike(a, b *OptLike) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsTableName(a.LikeTable, b.LikeTable) +} + // CloneRefOfOrder creates a deep clone of the input. func CloneRefOfOrder(n *Order) *Order { if n == nil { @@ -1773,6 +4876,18 @@ func CloneRefOfOrder(n *Order) *Order { return &out } +// EqualsRefOfOrder does deep equals between the two objects. +func EqualsRefOfOrder(a, b *Order) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsExpr(a.Expr, b.Expr) && + a.Direction == b.Direction +} + // CloneOrderBy creates a deep clone of the input. func CloneOrderBy(n OrderBy) OrderBy { res := make(OrderBy, 0, len(n)) @@ -1782,6 +4897,19 @@ func CloneOrderBy(n OrderBy) OrderBy { return res } +// EqualsOrderBy does deep equals between the two objects. +func EqualsOrderBy(a, b OrderBy) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfOrder(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfOtherAdmin creates a deep clone of the input. func CloneRefOfOtherAdmin(n *OtherAdmin) *OtherAdmin { if n == nil { @@ -1791,6 +4919,17 @@ func CloneRefOfOtherAdmin(n *OtherAdmin) *OtherAdmin { return &out } +// EqualsRefOfOtherAdmin does deep equals between the two objects. +func EqualsRefOfOtherAdmin(a, b *OtherAdmin) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return true +} + // CloneRefOfOtherRead creates a deep clone of the input. func CloneRefOfOtherRead(n *OtherRead) *OtherRead { if n == nil { @@ -1800,6 +4939,17 @@ func CloneRefOfOtherRead(n *OtherRead) *OtherRead { return &out } +// EqualsRefOfOtherRead does deep equals between the two objects. +func EqualsRefOfOtherRead(a, b *OtherRead) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return true +} + // CloneRefOfParenTableExpr creates a deep clone of the input. func CloneRefOfParenTableExpr(n *ParenTableExpr) *ParenTableExpr { if n == nil { @@ -1810,6 +4960,17 @@ func CloneRefOfParenTableExpr(n *ParenTableExpr) *ParenTableExpr { return &out } +// EqualsRefOfParenTableExpr does deep equals between the two objects. +func EqualsRefOfParenTableExpr(a, b *ParenTableExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsTableExprs(a.Exprs, b.Exprs) +} + // CloneRefOfPartitionDefinition creates a deep clone of the input. func CloneRefOfPartitionDefinition(n *PartitionDefinition) *PartitionDefinition { if n == nil { @@ -1821,6 +4982,19 @@ func CloneRefOfPartitionDefinition(n *PartitionDefinition) *PartitionDefinition return &out } +// EqualsRefOfPartitionDefinition does deep equals between the two objects. +func EqualsRefOfPartitionDefinition(a, b *PartitionDefinition) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Maxvalue == b.Maxvalue && + EqualsColIdent(a.Name, b.Name) && + EqualsExpr(a.Limit, b.Limit) +} + // CloneRefOfPartitionSpec creates a deep clone of the input. func CloneRefOfPartitionSpec(n *PartitionSpec) *PartitionSpec { if n == nil { @@ -1834,6 +5008,23 @@ func CloneRefOfPartitionSpec(n *PartitionSpec) *PartitionSpec { return &out } +// EqualsRefOfPartitionSpec does deep equals between the two objects. +func EqualsRefOfPartitionSpec(a, b *PartitionSpec) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.IsAll == b.IsAll && + a.WithoutValidation == b.WithoutValidation && + a.Action == b.Action && + EqualsPartitions(a.Names, b.Names) && + EqualsRefOfLiteral(a.Number, b.Number) && + EqualsTableName(a.TableName, b.TableName) && + EqualsSliceOfRefOfPartitionDefinition(a.Definitions, b.Definitions) +} + // ClonePartitions creates a deep clone of the input. func ClonePartitions(n Partitions) Partitions { res := make(Partitions, 0, len(n)) @@ -1843,6 +5034,19 @@ func ClonePartitions(n Partitions) Partitions { return res } +// EqualsPartitions does deep equals between the two objects. +func EqualsPartitions(a, b Partitions) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsColIdent(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfRelease creates a deep clone of the input. func CloneRefOfRelease(n *Release) *Release { if n == nil { @@ -1853,6 +5057,17 @@ func CloneRefOfRelease(n *Release) *Release { return &out } +// EqualsRefOfRelease does deep equals between the two objects. +func EqualsRefOfRelease(a, b *Release) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsColIdent(a.Name, b.Name) +} + // CloneRefOfRollback creates a deep clone of the input. func CloneRefOfRollback(n *Rollback) *Rollback { if n == nil { @@ -1862,6 +5077,17 @@ func CloneRefOfRollback(n *Rollback) *Rollback { return &out } +// EqualsRefOfRollback does deep equals between the two objects. +func EqualsRefOfRollback(a, b *Rollback) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return true +} + // CloneRefOfSRollback creates a deep clone of the input. func CloneRefOfSRollback(n *SRollback) *SRollback { if n == nil { @@ -1872,6 +5098,17 @@ func CloneRefOfSRollback(n *SRollback) *SRollback { return &out } +// EqualsRefOfSRollback does deep equals between the two objects. +func EqualsRefOfSRollback(a, b *SRollback) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsColIdent(a.Name, b.Name) +} + // CloneRefOfSavepoint creates a deep clone of the input. func CloneRefOfSavepoint(n *Savepoint) *Savepoint { if n == nil { @@ -1882,6 +5119,17 @@ func CloneRefOfSavepoint(n *Savepoint) *Savepoint { return &out } +// EqualsRefOfSavepoint does deep equals between the two objects. +func EqualsRefOfSavepoint(a, b *Savepoint) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsColIdent(a.Name, b.Name) +} + // CloneSelectExprs creates a deep clone of the input. func CloneSelectExprs(n SelectExprs) SelectExprs { res := make(SelectExprs, 0, len(n)) @@ -1891,6 +5139,19 @@ func CloneSelectExprs(n SelectExprs) SelectExprs { return res } +// EqualsSelectExprs does deep equals between the two objects. +func EqualsSelectExprs(a, b SelectExprs) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsSelectExpr(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfSelectInto creates a deep clone of the input. func CloneRefOfSelectInto(n *SelectInto) *SelectInto { if n == nil { @@ -1900,6 +5161,23 @@ func CloneRefOfSelectInto(n *SelectInto) *SelectInto { return &out } +// EqualsRefOfSelectInto does deep equals between the two objects. +func EqualsRefOfSelectInto(a, b *SelectInto) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.FileName == b.FileName && + a.Charset == b.Charset && + a.FormatOption == b.FormatOption && + a.ExportOption == b.ExportOption && + a.Manifest == b.Manifest && + a.Overwrite == b.Overwrite && + a.Type == b.Type +} + // CloneRefOfSet creates a deep clone of the input. func CloneRefOfSet(n *Set) *Set { if n == nil { @@ -1911,6 +5189,18 @@ func CloneRefOfSet(n *Set) *Set { return &out } +// EqualsRefOfSet does deep equals between the two objects. +func EqualsRefOfSet(a, b *Set) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsComments(a.Comments, b.Comments) && + EqualsSetExprs(a.Exprs, b.Exprs) +} + // CloneRefOfSetExpr creates a deep clone of the input. func CloneRefOfSetExpr(n *SetExpr) *SetExpr { if n == nil { @@ -1922,6 +5212,19 @@ func CloneRefOfSetExpr(n *SetExpr) *SetExpr { return &out } +// EqualsRefOfSetExpr does deep equals between the two objects. +func EqualsRefOfSetExpr(a, b *SetExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Scope == b.Scope && + EqualsColIdent(a.Name, b.Name) && + EqualsExpr(a.Expr, b.Expr) +} + // CloneSetExprs creates a deep clone of the input. func CloneSetExprs(n SetExprs) SetExprs { res := make(SetExprs, 0, len(n)) @@ -1931,6 +5234,19 @@ func CloneSetExprs(n SetExprs) SetExprs { return res } +// EqualsSetExprs does deep equals between the two objects. +func EqualsSetExprs(a, b SetExprs) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfSetExpr(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfSetTransaction creates a deep clone of the input. func CloneRefOfSetTransaction(n *SetTransaction) *SetTransaction { if n == nil { @@ -1943,6 +5259,20 @@ func CloneRefOfSetTransaction(n *SetTransaction) *SetTransaction { return &out } +// EqualsRefOfSetTransaction does deep equals between the two objects. +func EqualsRefOfSetTransaction(a, b *SetTransaction) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsSQLNode(a.SQLNode, b.SQLNode) && + EqualsComments(a.Comments, b.Comments) && + a.Scope == b.Scope && + EqualsSliceOfCharacteristic(a.Characteristics, b.Characteristics) +} + // CloneRefOfShow creates a deep clone of the input. func CloneRefOfShow(n *Show) *Show { if n == nil { @@ -1953,6 +5283,17 @@ func CloneRefOfShow(n *Show) *Show { return &out } +// EqualsRefOfShow does deep equals between the two objects. +func EqualsRefOfShow(a, b *Show) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsShowInternal(a.Internal, b.Internal) +} + // CloneRefOfShowBasic creates a deep clone of the input. func CloneRefOfShowBasic(n *ShowBasic) *ShowBasic { if n == nil { @@ -1964,6 +5305,21 @@ func CloneRefOfShowBasic(n *ShowBasic) *ShowBasic { return &out } +// EqualsRefOfShowBasic does deep equals between the two objects. +func EqualsRefOfShowBasic(a, b *ShowBasic) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Full == b.Full && + a.DbName == b.DbName && + a.Command == b.Command && + EqualsTableName(a.Tbl, b.Tbl) && + EqualsRefOfShowFilter(a.Filter, b.Filter) +} + // CloneRefOfShowCreate creates a deep clone of the input. func CloneRefOfShowCreate(n *ShowCreate) *ShowCreate { if n == nil { @@ -1974,6 +5330,18 @@ func CloneRefOfShowCreate(n *ShowCreate) *ShowCreate { return &out } +// EqualsRefOfShowCreate does deep equals between the two objects. +func EqualsRefOfShowCreate(a, b *ShowCreate) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Command == b.Command && + EqualsTableName(a.Op, b.Op) +} + // CloneRefOfShowFilter creates a deep clone of the input. func CloneRefOfShowFilter(n *ShowFilter) *ShowFilter { if n == nil { @@ -1984,6 +5352,18 @@ func CloneRefOfShowFilter(n *ShowFilter) *ShowFilter { return &out } +// EqualsRefOfShowFilter does deep equals between the two objects. +func EqualsRefOfShowFilter(a, b *ShowFilter) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Like == b.Like && + EqualsExpr(a.Filter, b.Filter) +} + // CloneRefOfShowLegacy creates a deep clone of the input. func CloneRefOfShowLegacy(n *ShowLegacy) *ShowLegacy { if n == nil { @@ -1997,6 +5377,23 @@ func CloneRefOfShowLegacy(n *ShowLegacy) *ShowLegacy { return &out } +// EqualsRefOfShowLegacy does deep equals between the two objects. +func EqualsRefOfShowLegacy(a, b *ShowLegacy) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Extended == b.Extended && + a.Type == b.Type && + EqualsTableName(a.OnTable, b.OnTable) && + EqualsTableName(a.Table, b.Table) && + EqualsRefOfShowTablesOpt(a.ShowTablesOpt, b.ShowTablesOpt) && + a.Scope == b.Scope && + EqualsExpr(a.ShowCollationFilterOpt, b.ShowCollationFilterOpt) +} + // CloneRefOfStarExpr creates a deep clone of the input. func CloneRefOfStarExpr(n *StarExpr) *StarExpr { if n == nil { @@ -2007,6 +5404,17 @@ func CloneRefOfStarExpr(n *StarExpr) *StarExpr { return &out } +// EqualsRefOfStarExpr does deep equals between the two objects. +func EqualsRefOfStarExpr(a, b *StarExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsTableName(a.TableName, b.TableName) +} + // CloneRefOfStream creates a deep clone of the input. func CloneRefOfStream(n *Stream) *Stream { if n == nil { @@ -2019,6 +5427,19 @@ func CloneRefOfStream(n *Stream) *Stream { return &out } +// EqualsRefOfStream does deep equals between the two objects. +func EqualsRefOfStream(a, b *Stream) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsComments(a.Comments, b.Comments) && + EqualsSelectExpr(a.SelectExpr, b.SelectExpr) && + EqualsTableName(a.Table, b.Table) +} + // CloneTableExprs creates a deep clone of the input. func CloneTableExprs(n TableExprs) TableExprs { res := make(TableExprs, 0, len(n)) @@ -2028,16 +5449,40 @@ func CloneTableExprs(n TableExprs) TableExprs { return res } +// EqualsTableExprs does deep equals between the two objects. +func EqualsTableExprs(a, b TableExprs) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsTableExpr(a[i], b[i]) { + return false + } + } + return true +} + // CloneTableIdent creates a deep clone of the input. func CloneTableIdent(n TableIdent) TableIdent { return *CloneRefOfTableIdent(&n) } +// EqualsTableIdent does deep equals between the two objects. +func EqualsTableIdent(a, b TableIdent) bool { + return a.v == b.v +} + // CloneTableName creates a deep clone of the input. func CloneTableName(n TableName) TableName { return *CloneRefOfTableName(&n) } +// EqualsTableName does deep equals between the two objects. +func EqualsTableName(a, b TableName) bool { + return EqualsTableIdent(a.Name, b.Name) && + EqualsTableIdent(a.Qualifier, b.Qualifier) +} + // CloneTableNames creates a deep clone of the input. func CloneTableNames(n TableNames) TableNames { res := make(TableNames, 0, len(n)) @@ -2047,6 +5492,19 @@ func CloneTableNames(n TableNames) TableNames { return res } +// EqualsTableNames does deep equals between the two objects. +func EqualsTableNames(a, b TableNames) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsTableName(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfTableSpec creates a deep clone of the input. func CloneRefOfTableSpec(n *TableSpec) *TableSpec { if n == nil { @@ -2060,6 +5518,20 @@ func CloneRefOfTableSpec(n *TableSpec) *TableSpec { return &out } +// EqualsRefOfTableSpec does deep equals between the two objects. +func EqualsRefOfTableSpec(a, b *TableSpec) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsSliceOfRefOfColumnDefinition(a.Columns, b.Columns) && + EqualsSliceOfRefOfIndexDefinition(a.Indexes, b.Indexes) && + EqualsSliceOfRefOfConstraintDefinition(a.Constraints, b.Constraints) && + EqualsTableOptions(a.Options, b.Options) +} + // CloneRefOfUnionSelect creates a deep clone of the input. func CloneRefOfUnionSelect(n *UnionSelect) *UnionSelect { if n == nil { @@ -2070,6 +5542,18 @@ func CloneRefOfUnionSelect(n *UnionSelect) *UnionSelect { return &out } +// EqualsRefOfUnionSelect does deep equals between the two objects. +func EqualsRefOfUnionSelect(a, b *UnionSelect) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Distinct == b.Distinct && + EqualsSelectStatement(a.Statement, b.Statement) +} + // CloneRefOfUnlockTables creates a deep clone of the input. func CloneRefOfUnlockTables(n *UnlockTables) *UnlockTables { if n == nil { @@ -2079,6 +5563,17 @@ func CloneRefOfUnlockTables(n *UnlockTables) *UnlockTables { return &out } +// EqualsRefOfUnlockTables does deep equals between the two objects. +func EqualsRefOfUnlockTables(a, b *UnlockTables) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return true +} + // CloneRefOfUpdate creates a deep clone of the input. func CloneRefOfUpdate(n *Update) *Update { if n == nil { @@ -2094,6 +5589,23 @@ func CloneRefOfUpdate(n *Update) *Update { return &out } +// EqualsRefOfUpdate does deep equals between the two objects. +func EqualsRefOfUpdate(a, b *Update) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsComments(a.Comments, b.Comments) && + a.Ignore == b.Ignore && + EqualsTableExprs(a.TableExprs, b.TableExprs) && + EqualsUpdateExprs(a.Exprs, b.Exprs) && + EqualsRefOfWhere(a.Where, b.Where) && + EqualsOrderBy(a.OrderBy, b.OrderBy) && + EqualsRefOfLimit(a.Limit, b.Limit) +} + // CloneRefOfUpdateExpr creates a deep clone of the input. func CloneRefOfUpdateExpr(n *UpdateExpr) *UpdateExpr { if n == nil { @@ -2105,6 +5617,18 @@ func CloneRefOfUpdateExpr(n *UpdateExpr) *UpdateExpr { return &out } +// EqualsRefOfUpdateExpr does deep equals between the two objects. +func EqualsRefOfUpdateExpr(a, b *UpdateExpr) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsRefOfColName(a.Name, b.Name) && + EqualsExpr(a.Expr, b.Expr) +} + // CloneUpdateExprs creates a deep clone of the input. func CloneUpdateExprs(n UpdateExprs) UpdateExprs { res := make(UpdateExprs, 0, len(n)) @@ -2114,6 +5638,19 @@ func CloneUpdateExprs(n UpdateExprs) UpdateExprs { return res } +// EqualsUpdateExprs does deep equals between the two objects. +func EqualsUpdateExprs(a, b UpdateExprs) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfUpdateExpr(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfUse creates a deep clone of the input. func CloneRefOfUse(n *Use) *Use { if n == nil { @@ -2124,6 +5661,17 @@ func CloneRefOfUse(n *Use) *Use { return &out } +// EqualsRefOfUse does deep equals between the two objects. +func EqualsRefOfUse(a, b *Use) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsTableIdent(a.DBName, b.DBName) +} + // CloneRefOfVStream creates a deep clone of the input. func CloneRefOfVStream(n *VStream) *VStream { if n == nil { @@ -2138,11 +5686,32 @@ func CloneRefOfVStream(n *VStream) *VStream { return &out } +// EqualsRefOfVStream does deep equals between the two objects. +func EqualsRefOfVStream(a, b *VStream) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsComments(a.Comments, b.Comments) && + EqualsSelectExpr(a.SelectExpr, b.SelectExpr) && + EqualsTableName(a.Table, b.Table) && + EqualsRefOfWhere(a.Where, b.Where) && + EqualsRefOfLimit(a.Limit, b.Limit) +} + // CloneVindexParam creates a deep clone of the input. func CloneVindexParam(n VindexParam) VindexParam { return *CloneRefOfVindexParam(&n) } +// EqualsVindexParam does deep equals between the two objects. +func EqualsVindexParam(a, b VindexParam) bool { + return a.Val == b.Val && + EqualsColIdent(a.Key, b.Key) +} + // CloneRefOfVindexSpec creates a deep clone of the input. func CloneRefOfVindexSpec(n *VindexSpec) *VindexSpec { if n == nil { @@ -2155,6 +5724,19 @@ func CloneRefOfVindexSpec(n *VindexSpec) *VindexSpec { return &out } +// EqualsRefOfVindexSpec does deep equals between the two objects. +func EqualsRefOfVindexSpec(a, b *VindexSpec) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsColIdent(a.Name, b.Name) && + EqualsColIdent(a.Type, b.Type) && + EqualsSliceOfVindexParam(a.Params, b.Params) +} + // CloneRefOfWhen creates a deep clone of the input. func CloneRefOfWhen(n *When) *When { if n == nil { @@ -2166,6 +5748,18 @@ func CloneRefOfWhen(n *When) *When { return &out } +// EqualsRefOfWhen does deep equals between the two objects. +func EqualsRefOfWhen(a, b *When) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsExpr(a.Cond, b.Cond) && + EqualsExpr(a.Val, b.Val) +} + // CloneRefOfWhere creates a deep clone of the input. func CloneRefOfWhere(n *Where) *Where { if n == nil { @@ -2176,6 +5770,18 @@ func CloneRefOfWhere(n *Where) *Where { return &out } +// EqualsRefOfWhere does deep equals between the two objects. +func EqualsRefOfWhere(a, b *Where) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Type == b.Type && + EqualsExpr(a.Expr, b.Expr) +} + // CloneSliceOfRefOfColumnDefinition creates a deep clone of the input. func CloneSliceOfRefOfColumnDefinition(n []*ColumnDefinition) []*ColumnDefinition { res := make([]*ColumnDefinition, 0, len(n)) @@ -2185,6 +5791,19 @@ func CloneSliceOfRefOfColumnDefinition(n []*ColumnDefinition) []*ColumnDefinitio return res } +// EqualsSliceOfRefOfColumnDefinition does deep equals between the two objects. +func EqualsSliceOfRefOfColumnDefinition(a, b []*ColumnDefinition) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfColumnDefinition(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfTableOption creates a deep clone of the input. func CloneRefOfTableOption(n *TableOption) *TableOption { if n == nil { @@ -2196,6 +5815,20 @@ func CloneRefOfTableOption(n *TableOption) *TableOption { return &out } +// EqualsRefOfTableOption does deep equals between the two objects. +func EqualsRefOfTableOption(a, b *TableOption) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Name == b.Name && + a.String == b.String && + EqualsRefOfLiteral(a.Value, b.Value) && + EqualsTableNames(a.Tables, b.Tables) +} + // CloneSliceOfCollateAndCharset creates a deep clone of the input. func CloneSliceOfCollateAndCharset(n []CollateAndCharset) []CollateAndCharset { res := make([]CollateAndCharset, 0, len(n)) @@ -2205,6 +5838,19 @@ func CloneSliceOfCollateAndCharset(n []CollateAndCharset) []CollateAndCharset { return res } +// EqualsSliceOfCollateAndCharset does deep equals between the two objects. +func EqualsSliceOfCollateAndCharset(a, b []CollateAndCharset) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsCollateAndCharset(a[i], b[i]) { + return false + } + } + return true +} + // CloneSliceOfAlterOption creates a deep clone of the input. func CloneSliceOfAlterOption(n []AlterOption) []AlterOption { res := make([]AlterOption, 0, len(n)) @@ -2214,6 +5860,19 @@ func CloneSliceOfAlterOption(n []AlterOption) []AlterOption { return res } +// EqualsSliceOfAlterOption does deep equals between the two objects. +func EqualsSliceOfAlterOption(a, b []AlterOption) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsAlterOption(a[i], b[i]) { + return false + } + } + return true +} + // CloneSliceOfRefOfRenameTablePair creates a deep clone of the input. func CloneSliceOfRefOfRenameTablePair(n []*RenameTablePair) []*RenameTablePair { res := make([]*RenameTablePair, 0, len(n)) @@ -2223,6 +5882,19 @@ func CloneSliceOfRefOfRenameTablePair(n []*RenameTablePair) []*RenameTablePair { return res } +// EqualsSliceOfRefOfRenameTablePair does deep equals between the two objects. +func EqualsSliceOfRefOfRenameTablePair(a, b []*RenameTablePair) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfRenameTablePair(a[i], b[i]) { + return false + } + } + return true +} + // CloneSliceOfRefOfWhen creates a deep clone of the input. func CloneSliceOfRefOfWhen(n []*When) []*When { res := make([]*When, 0, len(n)) @@ -2232,8 +5904,32 @@ func CloneSliceOfRefOfWhen(n []*When) []*When { return res } -// CloneRefOfbool creates a deep clone of the input. -func CloneRefOfbool(n *bool) *bool { +// EqualsSliceOfRefOfWhen does deep equals between the two objects. +func EqualsSliceOfRefOfWhen(a, b []*When) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfWhen(a[i], b[i]) { + return false + } + } + return true +} + +// EqualsRefOfBool does deep equals between the two objects. +func EqualsRefOfBool(a, b *bool) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return *a == *b +} + +// CloneRefOfBool creates a deep clone of the input. +func CloneRefOfBool(n *bool) *bool { if n == nil { return nil } @@ -2250,6 +5946,19 @@ func CloneSliceOfRefOfUnionSelect(n []*UnionSelect) []*UnionSelect { return res } +// EqualsSliceOfRefOfUnionSelect does deep equals between the two objects. +func EqualsSliceOfRefOfUnionSelect(a, b []*UnionSelect) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfUnionSelect(a[i], b[i]) { + return false + } + } + return true +} + // CloneSliceOfColIdent creates a deep clone of the input. func CloneSliceOfColIdent(n []ColIdent) []ColIdent { res := make([]ColIdent, 0, len(n)) @@ -2259,6 +5968,19 @@ func CloneSliceOfColIdent(n []ColIdent) []ColIdent { return res } +// EqualsSliceOfColIdent does deep equals between the two objects. +func EqualsSliceOfColIdent(a, b []ColIdent) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsColIdent(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfColIdent creates a deep clone of the input. func CloneRefOfColIdent(n *ColIdent) *ColIdent { if n == nil { @@ -2268,11 +5990,37 @@ func CloneRefOfColIdent(n *ColIdent) *ColIdent { return &out } +// EqualsRefOfColIdent does deep equals between the two objects. +func EqualsRefOfColIdent(a, b *ColIdent) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.val == b.val && + a.lowered == b.lowered && + a.at == b.at +} + // CloneColumnType creates a deep clone of the input. func CloneColumnType(n ColumnType) ColumnType { return *CloneRefOfColumnType(&n) } +// EqualsColumnType does deep equals between the two objects. +func EqualsColumnType(a, b ColumnType) bool { + return a.Type == b.Type && + a.Unsigned == b.Unsigned && + a.Zerofill == b.Zerofill && + a.Charset == b.Charset && + a.Collate == b.Collate && + EqualsRefOfColumnTypeOptions(a.Options, b.Options) && + EqualsRefOfLiteral(a.Length, b.Length) && + EqualsRefOfLiteral(a.Scale, b.Scale) && + EqualsSliceOfString(a.EnumValues, b.EnumValues) +} + // CloneRefOfColumnTypeOptions creates a deep clone of the input. func CloneRefOfColumnTypeOptions(n *ColumnTypeOptions) *ColumnTypeOptions { if n == nil { @@ -2285,13 +6033,42 @@ func CloneRefOfColumnTypeOptions(n *ColumnTypeOptions) *ColumnTypeOptions { return &out } -// CloneSliceOfstring creates a deep clone of the input. -func CloneSliceOfstring(n []string) []string { +// EqualsRefOfColumnTypeOptions does deep equals between the two objects. +func EqualsRefOfColumnTypeOptions(a, b *ColumnTypeOptions) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.NotNull == b.NotNull && + a.Autoincrement == b.Autoincrement && + EqualsExpr(a.Default, b.Default) && + EqualsExpr(a.OnUpdate, b.OnUpdate) && + EqualsRefOfLiteral(a.Comment, b.Comment) && + a.KeyOpt == b.KeyOpt +} + +// CloneSliceOfString creates a deep clone of the input. +func CloneSliceOfString(n []string) []string { res := make([]string, 0, len(n)) copy(res, n) return res } +// EqualsSliceOfString does deep equals between the two objects. +func EqualsSliceOfString(a, b []string) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if a[i] != b[i] { + return false + } + } + return true +} + // CloneSliceOfRefOfIndexColumn creates a deep clone of the input. func CloneSliceOfRefOfIndexColumn(n []*IndexColumn) []*IndexColumn { res := make([]*IndexColumn, 0, len(n)) @@ -2301,6 +6078,19 @@ func CloneSliceOfRefOfIndexColumn(n []*IndexColumn) []*IndexColumn { return res } +// EqualsSliceOfRefOfIndexColumn does deep equals between the two objects. +func EqualsSliceOfRefOfIndexColumn(a, b []*IndexColumn) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfIndexColumn(a[i], b[i]) { + return false + } + } + return true +} + // CloneSliceOfRefOfIndexOption creates a deep clone of the input. func CloneSliceOfRefOfIndexOption(n []*IndexOption) []*IndexOption { res := make([]*IndexOption, 0, len(n)) @@ -2310,6 +6100,19 @@ func CloneSliceOfRefOfIndexOption(n []*IndexOption) []*IndexOption { return res } +// EqualsSliceOfRefOfIndexOption does deep equals between the two objects. +func EqualsSliceOfRefOfIndexOption(a, b []*IndexOption) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfIndexOption(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfJoinCondition creates a deep clone of the input. func CloneRefOfJoinCondition(n *JoinCondition) *JoinCondition { if n == nil { @@ -2321,6 +6124,18 @@ func CloneRefOfJoinCondition(n *JoinCondition) *JoinCondition { return &out } +// EqualsRefOfJoinCondition does deep equals between the two objects. +func EqualsRefOfJoinCondition(a, b *JoinCondition) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsExpr(a.On, b.On) && + EqualsColumns(a.Using, b.Using) +} + // CloneTableAndLockTypes creates a deep clone of the input. func CloneTableAndLockTypes(n TableAndLockTypes) TableAndLockTypes { res := make(TableAndLockTypes, 0, len(n)) @@ -2330,6 +6145,19 @@ func CloneTableAndLockTypes(n TableAndLockTypes) TableAndLockTypes { return res } +// EqualsTableAndLockTypes does deep equals between the two objects. +func EqualsTableAndLockTypes(a, b TableAndLockTypes) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfTableAndLockType(a[i], b[i]) { + return false + } + } + return true +} + // CloneSliceOfRefOfPartitionDefinition creates a deep clone of the input. func CloneSliceOfRefOfPartitionDefinition(n []*PartitionDefinition) []*PartitionDefinition { res := make([]*PartitionDefinition, 0, len(n)) @@ -2339,6 +6167,19 @@ func CloneSliceOfRefOfPartitionDefinition(n []*PartitionDefinition) []*Partition return res } +// EqualsSliceOfRefOfPartitionDefinition does deep equals between the two objects. +func EqualsSliceOfRefOfPartitionDefinition(a, b []*PartitionDefinition) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfPartitionDefinition(a[i], b[i]) { + return false + } + } + return true +} + // CloneSliceOfCharacteristic creates a deep clone of the input. func CloneSliceOfCharacteristic(n []Characteristic) []Characteristic { res := make([]Characteristic, 0, len(n)) @@ -2348,6 +6189,19 @@ func CloneSliceOfCharacteristic(n []Characteristic) []Characteristic { return res } +// EqualsSliceOfCharacteristic does deep equals between the two objects. +func EqualsSliceOfCharacteristic(a, b []Characteristic) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsCharacteristic(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfShowTablesOpt creates a deep clone of the input. func CloneRefOfShowTablesOpt(n *ShowTablesOpt) *ShowTablesOpt { if n == nil { @@ -2358,6 +6212,19 @@ func CloneRefOfShowTablesOpt(n *ShowTablesOpt) *ShowTablesOpt { return &out } +// EqualsRefOfShowTablesOpt does deep equals between the two objects. +func EqualsRefOfShowTablesOpt(a, b *ShowTablesOpt) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Full == b.Full && + a.DbName == b.DbName && + EqualsRefOfShowFilter(a.Filter, b.Filter) +} + // CloneRefOfTableIdent creates a deep clone of the input. func CloneRefOfTableIdent(n *TableIdent) *TableIdent { if n == nil { @@ -2367,6 +6234,17 @@ func CloneRefOfTableIdent(n *TableIdent) *TableIdent { return &out } +// EqualsRefOfTableIdent does deep equals between the two objects. +func EqualsRefOfTableIdent(a, b *TableIdent) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.v == b.v +} + // CloneRefOfTableName creates a deep clone of the input. func CloneRefOfTableName(n *TableName) *TableName { if n == nil { @@ -2378,6 +6256,18 @@ func CloneRefOfTableName(n *TableName) *TableName { return &out } +// EqualsRefOfTableName does deep equals between the two objects. +func EqualsRefOfTableName(a, b *TableName) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsTableIdent(a.Name, b.Name) && + EqualsTableIdent(a.Qualifier, b.Qualifier) +} + // CloneSliceOfRefOfIndexDefinition creates a deep clone of the input. func CloneSliceOfRefOfIndexDefinition(n []*IndexDefinition) []*IndexDefinition { res := make([]*IndexDefinition, 0, len(n)) @@ -2387,6 +6277,19 @@ func CloneSliceOfRefOfIndexDefinition(n []*IndexDefinition) []*IndexDefinition { return res } +// EqualsSliceOfRefOfIndexDefinition does deep equals between the two objects. +func EqualsSliceOfRefOfIndexDefinition(a, b []*IndexDefinition) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfIndexDefinition(a[i], b[i]) { + return false + } + } + return true +} + // CloneSliceOfRefOfConstraintDefinition creates a deep clone of the input. func CloneSliceOfRefOfConstraintDefinition(n []*ConstraintDefinition) []*ConstraintDefinition { res := make([]*ConstraintDefinition, 0, len(n)) @@ -2396,6 +6299,19 @@ func CloneSliceOfRefOfConstraintDefinition(n []*ConstraintDefinition) []*Constra return res } +// EqualsSliceOfRefOfConstraintDefinition does deep equals between the two objects. +func EqualsSliceOfRefOfConstraintDefinition(a, b []*ConstraintDefinition) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsRefOfConstraintDefinition(a[i], b[i]) { + return false + } + } + return true +} + // CloneRefOfVindexParam creates a deep clone of the input. func CloneRefOfVindexParam(n *VindexParam) *VindexParam { if n == nil { @@ -2406,6 +6322,18 @@ func CloneRefOfVindexParam(n *VindexParam) *VindexParam { return &out } +// EqualsRefOfVindexParam does deep equals between the two objects. +func EqualsRefOfVindexParam(a, b *VindexParam) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Val == b.Val && + EqualsColIdent(a.Key, b.Key) +} + // CloneSliceOfVindexParam creates a deep clone of the input. func CloneSliceOfVindexParam(n []VindexParam) []VindexParam { res := make([]VindexParam, 0, len(n)) @@ -2415,11 +6343,31 @@ func CloneSliceOfVindexParam(n []VindexParam) []VindexParam { return res } +// EqualsSliceOfVindexParam does deep equals between the two objects. +func EqualsSliceOfVindexParam(a, b []VindexParam) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if !EqualsVindexParam(a[i], b[i]) { + return false + } + } + return true +} + // CloneCollateAndCharset creates a deep clone of the input. func CloneCollateAndCharset(n CollateAndCharset) CollateAndCharset { return *CloneRefOfCollateAndCharset(&n) } +// EqualsCollateAndCharset does deep equals between the two objects. +func EqualsCollateAndCharset(a, b CollateAndCharset) bool { + return a.IsDefault == b.IsDefault && + a.Value == b.Value && + a.Type == b.Type +} + // CloneRefOfRenameTablePair creates a deep clone of the input. func CloneRefOfRenameTablePair(n *RenameTablePair) *RenameTablePair { if n == nil { @@ -2431,6 +6379,18 @@ func CloneRefOfRenameTablePair(n *RenameTablePair) *RenameTablePair { return &out } +// EqualsRefOfRenameTablePair does deep equals between the two objects. +func EqualsRefOfRenameTablePair(a, b *RenameTablePair) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsTableName(a.FromTable, b.FromTable) && + EqualsTableName(a.ToTable, b.ToTable) +} + // CloneRefOfIndexColumn creates a deep clone of the input. func CloneRefOfIndexColumn(n *IndexColumn) *IndexColumn { if n == nil { @@ -2442,6 +6402,19 @@ func CloneRefOfIndexColumn(n *IndexColumn) *IndexColumn { return &out } +// EqualsRefOfIndexColumn does deep equals between the two objects. +func EqualsRefOfIndexColumn(a, b *IndexColumn) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsColIdent(a.Column, b.Column) && + EqualsRefOfLiteral(a.Length, b.Length) && + a.Direction == b.Direction +} + // CloneRefOfIndexOption creates a deep clone of the input. func CloneRefOfIndexOption(n *IndexOption) *IndexOption { if n == nil { @@ -2452,6 +6425,19 @@ func CloneRefOfIndexOption(n *IndexOption) *IndexOption { return &out } +// EqualsRefOfIndexOption does deep equals between the two objects. +func EqualsRefOfIndexOption(a, b *IndexOption) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.Name == b.Name && + a.String == b.String && + EqualsRefOfLiteral(a.Value, b.Value) +} + // CloneRefOfTableAndLockType creates a deep clone of the input. func CloneRefOfTableAndLockType(n *TableAndLockType) *TableAndLockType { if n == nil { @@ -2462,6 +6448,18 @@ func CloneRefOfTableAndLockType(n *TableAndLockType) *TableAndLockType { return &out } +// EqualsRefOfTableAndLockType does deep equals between the two objects. +func EqualsRefOfTableAndLockType(a, b *TableAndLockType) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return EqualsTableExpr(a.Table, b.Table) && + a.Lock == b.Lock +} + // CloneRefOfCollateAndCharset creates a deep clone of the input. func CloneRefOfCollateAndCharset(n *CollateAndCharset) *CollateAndCharset { if n == nil { @@ -2470,3 +6468,16 @@ func CloneRefOfCollateAndCharset(n *CollateAndCharset) *CollateAndCharset { out := *n return &out } + +// EqualsRefOfCollateAndCharset does deep equals between the two objects. +func EqualsRefOfCollateAndCharset(a, b *CollateAndCharset) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } + return a.IsDefault == b.IsDefault && + a.Value == b.Value && + a.Type == b.Type +} diff --git a/misc/git/hooks/visitorgen b/misc/git/hooks/visitorgen index 3ac99cb0a07..cd8a9ac547d 100755 --- a/misc/git/hooks/visitorgen +++ b/misc/git/hooks/visitorgen @@ -15,4 +15,4 @@ # this script, which should run before committing code, makes sure that the visitor is re-generated when the ast changes -go run ./go/tools/asthelpergen -in ./go/vt/sqlparser -verify=true -iface vitess.io/vitess/go/vt/sqlparser.SQLNode -except "*ColName" \ No newline at end of file +go run ./go/tools/asthelpergen/main -in ./go/vt/sqlparser -verify=true -iface vitess.io/vitess/go/vt/sqlparser.SQLNode -except "*ColName" \ No newline at end of file