From 75c9f9874b89178a646e2051f28081d2a769af8b Mon Sep 17 00:00:00 2001 From: Aaron Son Date: Wed, 19 Apr 2023 14:50:28 -0700 Subject: [PATCH 1/3] go.mod: Use dolthub/flatbuffers/v23 instead of google/flatbuffers. --- go.mod | 2 +- go.sum | 4 +- sql/mysql_db/fbs/generate.sh | 6 +- sql/mysql_db/mysql_db.go | 2 +- sql/mysql_db/mysql_db_serialize.go | 2 +- sql/mysql_db/serial/mysql_db.go | 340 +++++++++++++++++++++++++---- 6 files changed, 309 insertions(+), 47 deletions(-) diff --git a/go.mod b/go.mod index 621c19e2c0..4d2bbd035a 100644 --- a/go.mod +++ b/go.mod @@ -2,12 +2,12 @@ module github.com/dolthub/go-mysql-server require ( github.com/cespare/xxhash v1.1.0 + github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 github.com/dolthub/vitess v0.0.0-20230407173322-ae1622f38e94 github.com/go-kit/kit v0.10.0 github.com/go-sql-driver/mysql v1.6.0 github.com/gocraft/dbr/v2 v2.7.2 - github.com/google/flatbuffers v2.0.6+incompatible github.com/google/uuid v1.2.0 github.com/hashicorp/golang-lru v0.5.4 github.com/lestrrat-go/strftime v1.0.4 diff --git a/go.sum b/go.sum index 5fb25a1be2..b045d7bbf4 100644 --- a/go.sum +++ b/go.sum @@ -51,6 +51,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/denisenkom/go-mssqldb v0.10.0 h1:QykgLZBorFE95+gO3u9esLd0BmbvpWp0/waNNZfHBM8= github.com/denisenkom/go-mssqldb v0.10.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww= +github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2/go.mod h1:mIEZOHnFx4ZMQeawhw9rhsj+0zwQj7adVsnBX7t+eKY= github.com/dolthub/jsonpath v0.0.0-20210609232853-d49537a30474 h1:xTrR+l5l+1Lfq0NvhiEsctylXinUMFhhsqaEcl414p8= github.com/dolthub/jsonpath v0.0.0-20210609232853-d49537a30474/go.mod h1:kMz7uXOXq4qRriCEyZ/LUeTqraLJCjf0WVZcUi6TxUY= github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9XGFa6q5Ap4Z/OhNkAMBaK5YeuEzwJt+NZdhiE= @@ -117,8 +119,6 @@ github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/flatbuffers v2.0.6+incompatible h1:XHFReMv7nFFusa+CEokzWbzaYocKXI6C7hdU5Kgh9Lw= -github.com/google/flatbuffers v2.0.6+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= diff --git a/sql/mysql_db/fbs/generate.sh b/sql/mysql_db/fbs/generate.sh index 5f60a8bd87..51eaa43d63 100755 --- a/sql/mysql_db/fbs/generate.sh +++ b/sql/mysql_db/fbs/generate.sh @@ -10,8 +10,12 @@ if [ ! -z "$(ls $GEN_DIR)" ]; then rm $GEN_DIR/*.go fi +# Last generated with github.com/dolthub/flatbuffers v23.3.3-dh.2 + +FLATC=${FLATC:=flatc} + # generate golang (de)serialization package -flatc -o $GEN_DIR --gen-onefile --filename-suffix "" --gen-mutable --go-namespace "serial" --go mysql_db.fbs +"$FLATC" -o $GEN_DIR --gen-onefile --filename-suffix "" --gen-mutable --go-namespace "serial" --go mysql_db.fbs # prefix files with copyright header for FILE in $GEN_DIR/*.go; diff --git a/sql/mysql_db/mysql_db.go b/sql/mysql_db/mysql_db.go index fcc7f6ab2b..359212a771 100644 --- a/sql/mysql_db/mysql_db.go +++ b/sql/mysql_db/mysql_db.go @@ -25,7 +25,7 @@ import ( "strings" "github.com/dolthub/vitess/go/mysql" - flatbuffers "github.com/google/flatbuffers/go" + flatbuffers "github.com/dolthub/flatbuffers/v23/go" "github.com/dolthub/go-mysql-server/sql" "github.com/dolthub/go-mysql-server/sql/mysql_db/serial" diff --git a/sql/mysql_db/mysql_db_serialize.go b/sql/mysql_db/mysql_db_serialize.go index e113bee4d7..becbc040c0 100644 --- a/sql/mysql_db/mysql_db_serialize.go +++ b/sql/mysql_db/mysql_db_serialize.go @@ -15,7 +15,7 @@ package mysql_db import ( - flatbuffers "github.com/google/flatbuffers/go" + flatbuffers "github.com/dolthub/flatbuffers/v23/go" "github.com/dolthub/go-mysql-server/sql" "github.com/dolthub/go-mysql-server/sql/mysql_db/serial" diff --git a/sql/mysql_db/serial/mysql_db.go b/sql/mysql_db/serial/mysql_db.go index 97d85ca658..0e34679095 100644 --- a/sql/mysql_db/serial/mysql_db.go +++ b/sql/mysql_db/serial/mysql_db.go @@ -17,24 +17,41 @@ package serial import ( - flatbuffers "github.com/google/flatbuffers/go" + flatbuffers "github.com/dolthub/flatbuffers/v23/go" ) type PrivilegeSetColumn struct { _tab flatbuffers.Table } -func GetRootAsPrivilegeSetColumn(buf []byte, offset flatbuffers.UOffsetT) *PrivilegeSetColumn { +func InitPrivilegeSetColumnRoot(o *PrivilegeSetColumn, buf []byte, offset flatbuffers.UOffsetT) error { n := flatbuffers.GetUOffsetT(buf[offset:]) + o.Init(buf, n+offset) + if PrivilegeSetColumnNumFields < o.Table().NumFields() { + return flatbuffers.ErrTableHasUnknownFields + } + return nil +} + +func TryGetRootAsPrivilegeSetColumn(buf []byte, offset flatbuffers.UOffsetT) (*PrivilegeSetColumn, error) { x := &PrivilegeSetColumn{} - x.Init(buf, n+offset) + return x, InitPrivilegeSetColumnRoot(x, buf, offset) +} + +func GetRootAsPrivilegeSetColumn(buf []byte, offset flatbuffers.UOffsetT) *PrivilegeSetColumn { + x := &PrivilegeSetColumn{} + InitPrivilegeSetColumnRoot(x, buf, offset) return x } +func TryGetSizePrefixedRootAsPrivilegeSetColumn(buf []byte, offset flatbuffers.UOffsetT) (*PrivilegeSetColumn, error) { + x := &PrivilegeSetColumn{} + return x, InitPrivilegeSetColumnRoot(x, buf, offset+flatbuffers.SizeUint32) +} + func GetSizePrefixedRootAsPrivilegeSetColumn(buf []byte, offset flatbuffers.UOffsetT) *PrivilegeSetColumn { - n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:]) x := &PrivilegeSetColumn{} - x.Init(buf, n+offset+flatbuffers.SizeUint32) + InitPrivilegeSetColumnRoot(x, buf, offset+flatbuffers.SizeUint32) return x } @@ -81,8 +98,10 @@ func (rcv *PrivilegeSetColumn) MutatePrivs(j int, n int32) bool { return false } +const PrivilegeSetColumnNumFields = 2 + func PrivilegeSetColumnStart(builder *flatbuffers.Builder) { - builder.StartObject(2) + builder.StartObject(PrivilegeSetColumnNumFields) } func PrivilegeSetColumnAddName(builder *flatbuffers.Builder, name flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(name), 0) @@ -101,17 +120,34 @@ type PrivilegeSetTable struct { _tab flatbuffers.Table } -func GetRootAsPrivilegeSetTable(buf []byte, offset flatbuffers.UOffsetT) *PrivilegeSetTable { +func InitPrivilegeSetTableRoot(o *PrivilegeSetTable, buf []byte, offset flatbuffers.UOffsetT) error { n := flatbuffers.GetUOffsetT(buf[offset:]) + o.Init(buf, n+offset) + if PrivilegeSetTableNumFields < o.Table().NumFields() { + return flatbuffers.ErrTableHasUnknownFields + } + return nil +} + +func TryGetRootAsPrivilegeSetTable(buf []byte, offset flatbuffers.UOffsetT) (*PrivilegeSetTable, error) { + x := &PrivilegeSetTable{} + return x, InitPrivilegeSetTableRoot(x, buf, offset) +} + +func GetRootAsPrivilegeSetTable(buf []byte, offset flatbuffers.UOffsetT) *PrivilegeSetTable { x := &PrivilegeSetTable{} - x.Init(buf, n+offset) + InitPrivilegeSetTableRoot(x, buf, offset) return x } +func TryGetSizePrefixedRootAsPrivilegeSetTable(buf []byte, offset flatbuffers.UOffsetT) (*PrivilegeSetTable, error) { + x := &PrivilegeSetTable{} + return x, InitPrivilegeSetTableRoot(x, buf, offset+flatbuffers.SizeUint32) +} + func GetSizePrefixedRootAsPrivilegeSetTable(buf []byte, offset flatbuffers.UOffsetT) *PrivilegeSetTable { - n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:]) x := &PrivilegeSetTable{} - x.Init(buf, n+offset+flatbuffers.SizeUint32) + InitPrivilegeSetTableRoot(x, buf, offset+flatbuffers.SizeUint32) return x } @@ -170,6 +206,21 @@ func (rcv *PrivilegeSetTable) Columns(obj *PrivilegeSetColumn, j int) bool { return false } +func (rcv *PrivilegeSetTable) TryColumns(obj *PrivilegeSetColumn, j int) (bool, error) { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + x := rcv._tab.Vector(o) + x += flatbuffers.UOffsetT(j) * 4 + x = rcv._tab.Indirect(x) + obj.Init(rcv._tab.Bytes, x) + if PrivilegeSetColumnNumFields < obj.Table().NumFields() { + return false, flatbuffers.ErrTableHasUnknownFields + } + return true, nil + } + return false, nil +} + func (rcv *PrivilegeSetTable) ColumnsLength() int { o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) if o != 0 { @@ -178,8 +229,10 @@ func (rcv *PrivilegeSetTable) ColumnsLength() int { return 0 } +const PrivilegeSetTableNumFields = 3 + func PrivilegeSetTableStart(builder *flatbuffers.Builder) { - builder.StartObject(3) + builder.StartObject(PrivilegeSetTableNumFields) } func PrivilegeSetTableAddName(builder *flatbuffers.Builder, name flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(name), 0) @@ -204,17 +257,34 @@ type PrivilegeSetDatabase struct { _tab flatbuffers.Table } -func GetRootAsPrivilegeSetDatabase(buf []byte, offset flatbuffers.UOffsetT) *PrivilegeSetDatabase { +func InitPrivilegeSetDatabaseRoot(o *PrivilegeSetDatabase, buf []byte, offset flatbuffers.UOffsetT) error { n := flatbuffers.GetUOffsetT(buf[offset:]) + o.Init(buf, n+offset) + if PrivilegeSetDatabaseNumFields < o.Table().NumFields() { + return flatbuffers.ErrTableHasUnknownFields + } + return nil +} + +func TryGetRootAsPrivilegeSetDatabase(buf []byte, offset flatbuffers.UOffsetT) (*PrivilegeSetDatabase, error) { + x := &PrivilegeSetDatabase{} + return x, InitPrivilegeSetDatabaseRoot(x, buf, offset) +} + +func GetRootAsPrivilegeSetDatabase(buf []byte, offset flatbuffers.UOffsetT) *PrivilegeSetDatabase { x := &PrivilegeSetDatabase{} - x.Init(buf, n+offset) + InitPrivilegeSetDatabaseRoot(x, buf, offset) return x } +func TryGetSizePrefixedRootAsPrivilegeSetDatabase(buf []byte, offset flatbuffers.UOffsetT) (*PrivilegeSetDatabase, error) { + x := &PrivilegeSetDatabase{} + return x, InitPrivilegeSetDatabaseRoot(x, buf, offset+flatbuffers.SizeUint32) +} + func GetSizePrefixedRootAsPrivilegeSetDatabase(buf []byte, offset flatbuffers.UOffsetT) *PrivilegeSetDatabase { - n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:]) x := &PrivilegeSetDatabase{} - x.Init(buf, n+offset+flatbuffers.SizeUint32) + InitPrivilegeSetDatabaseRoot(x, buf, offset+flatbuffers.SizeUint32) return x } @@ -273,6 +343,21 @@ func (rcv *PrivilegeSetDatabase) Tables(obj *PrivilegeSetTable, j int) bool { return false } +func (rcv *PrivilegeSetDatabase) TryTables(obj *PrivilegeSetTable, j int) (bool, error) { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + x := rcv._tab.Vector(o) + x += flatbuffers.UOffsetT(j) * 4 + x = rcv._tab.Indirect(x) + obj.Init(rcv._tab.Bytes, x) + if PrivilegeSetTableNumFields < obj.Table().NumFields() { + return false, flatbuffers.ErrTableHasUnknownFields + } + return true, nil + } + return false, nil +} + func (rcv *PrivilegeSetDatabase) TablesLength() int { o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) if o != 0 { @@ -281,8 +366,10 @@ func (rcv *PrivilegeSetDatabase) TablesLength() int { return 0 } +const PrivilegeSetDatabaseNumFields = 3 + func PrivilegeSetDatabaseStart(builder *flatbuffers.Builder) { - builder.StartObject(3) + builder.StartObject(PrivilegeSetDatabaseNumFields) } func PrivilegeSetDatabaseAddName(builder *flatbuffers.Builder, name flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(name), 0) @@ -307,17 +394,34 @@ type PrivilegeSet struct { _tab flatbuffers.Table } -func GetRootAsPrivilegeSet(buf []byte, offset flatbuffers.UOffsetT) *PrivilegeSet { +func InitPrivilegeSetRoot(o *PrivilegeSet, buf []byte, offset flatbuffers.UOffsetT) error { n := flatbuffers.GetUOffsetT(buf[offset:]) + o.Init(buf, n+offset) + if PrivilegeSetNumFields < o.Table().NumFields() { + return flatbuffers.ErrTableHasUnknownFields + } + return nil +} + +func TryGetRootAsPrivilegeSet(buf []byte, offset flatbuffers.UOffsetT) (*PrivilegeSet, error) { + x := &PrivilegeSet{} + return x, InitPrivilegeSetRoot(x, buf, offset) +} + +func GetRootAsPrivilegeSet(buf []byte, offset flatbuffers.UOffsetT) *PrivilegeSet { x := &PrivilegeSet{} - x.Init(buf, n+offset) + InitPrivilegeSetRoot(x, buf, offset) return x } +func TryGetSizePrefixedRootAsPrivilegeSet(buf []byte, offset flatbuffers.UOffsetT) (*PrivilegeSet, error) { + x := &PrivilegeSet{} + return x, InitPrivilegeSetRoot(x, buf, offset+flatbuffers.SizeUint32) +} + func GetSizePrefixedRootAsPrivilegeSet(buf []byte, offset flatbuffers.UOffsetT) *PrivilegeSet { - n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:]) x := &PrivilegeSet{} - x.Init(buf, n+offset+flatbuffers.SizeUint32) + InitPrivilegeSetRoot(x, buf, offset+flatbuffers.SizeUint32) return x } @@ -385,6 +489,21 @@ func (rcv *PrivilegeSet) Databases(obj *PrivilegeSetDatabase, j int) bool { return false } +func (rcv *PrivilegeSet) TryDatabases(obj *PrivilegeSetDatabase, j int) (bool, error) { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + x := rcv._tab.Vector(o) + x += flatbuffers.UOffsetT(j) * 4 + x = rcv._tab.Indirect(x) + obj.Init(rcv._tab.Bytes, x) + if PrivilegeSetDatabaseNumFields < obj.Table().NumFields() { + return false, flatbuffers.ErrTableHasUnknownFields + } + return true, nil + } + return false, nil +} + func (rcv *PrivilegeSet) DatabasesLength() int { o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) if o != 0 { @@ -419,8 +538,10 @@ func (rcv *PrivilegeSet) MutateGlobalDynamicWgo(j int, n bool) bool { return false } +const PrivilegeSetNumFields = 4 + func PrivilegeSetStart(builder *flatbuffers.Builder) { - builder.StartObject(4) + builder.StartObject(PrivilegeSetNumFields) } func PrivilegeSetAddGlobalStatic(builder *flatbuffers.Builder, globalStatic flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(globalStatic), 0) @@ -454,17 +575,34 @@ type User struct { _tab flatbuffers.Table } -func GetRootAsUser(buf []byte, offset flatbuffers.UOffsetT) *User { +func InitUserRoot(o *User, buf []byte, offset flatbuffers.UOffsetT) error { n := flatbuffers.GetUOffsetT(buf[offset:]) + o.Init(buf, n+offset) + if UserNumFields < o.Table().NumFields() { + return flatbuffers.ErrTableHasUnknownFields + } + return nil +} + +func TryGetRootAsUser(buf []byte, offset flatbuffers.UOffsetT) (*User, error) { x := &User{} - x.Init(buf, n+offset) + return x, InitUserRoot(x, buf, offset) +} + +func GetRootAsUser(buf []byte, offset flatbuffers.UOffsetT) *User { + x := &User{} + InitUserRoot(x, buf, offset) return x } +func TryGetSizePrefixedRootAsUser(buf []byte, offset flatbuffers.UOffsetT) (*User, error) { + x := &User{} + return x, InitUserRoot(x, buf, offset+flatbuffers.SizeUint32) +} + func GetSizePrefixedRootAsUser(buf []byte, offset flatbuffers.UOffsetT) *User { - n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:]) x := &User{} - x.Init(buf, n+offset+flatbuffers.SizeUint32) + InitUserRoot(x, buf, offset+flatbuffers.SizeUint32) return x } @@ -506,6 +644,22 @@ func (rcv *User) PrivilegeSet(obj *PrivilegeSet) *PrivilegeSet { return nil } +func (rcv *User) TryPrivilegeSet(obj *PrivilegeSet) (*PrivilegeSet, error) { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + x := rcv._tab.Indirect(o + rcv._tab.Pos) + if obj == nil { + obj = new(PrivilegeSet) + } + obj.Init(rcv._tab.Bytes, x) + if PrivilegeSetNumFields < obj.Table().NumFields() { + return nil, flatbuffers.ErrTableHasUnknownFields + } + return obj, nil + } + return nil, nil +} + func (rcv *User) Plugin() []byte { o := flatbuffers.UOffsetT(rcv._tab.Offset(10)) if o != 0 { @@ -562,8 +716,10 @@ func (rcv *User) Identity() []byte { return nil } +const UserNumFields = 9 + func UserStart(builder *flatbuffers.Builder) { - builder.StartObject(9) + builder.StartObject(UserNumFields) } func UserAddUser(builder *flatbuffers.Builder, user flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(user), 0) @@ -600,17 +756,34 @@ type RoleEdge struct { _tab flatbuffers.Table } -func GetRootAsRoleEdge(buf []byte, offset flatbuffers.UOffsetT) *RoleEdge { +func InitRoleEdgeRoot(o *RoleEdge, buf []byte, offset flatbuffers.UOffsetT) error { n := flatbuffers.GetUOffsetT(buf[offset:]) + o.Init(buf, n+offset) + if RoleEdgeNumFields < o.Table().NumFields() { + return flatbuffers.ErrTableHasUnknownFields + } + return nil +} + +func TryGetRootAsRoleEdge(buf []byte, offset flatbuffers.UOffsetT) (*RoleEdge, error) { + x := &RoleEdge{} + return x, InitRoleEdgeRoot(x, buf, offset) +} + +func GetRootAsRoleEdge(buf []byte, offset flatbuffers.UOffsetT) *RoleEdge { x := &RoleEdge{} - x.Init(buf, n+offset) + InitRoleEdgeRoot(x, buf, offset) return x } +func TryGetSizePrefixedRootAsRoleEdge(buf []byte, offset flatbuffers.UOffsetT) (*RoleEdge, error) { + x := &RoleEdge{} + return x, InitRoleEdgeRoot(x, buf, offset+flatbuffers.SizeUint32) +} + func GetSizePrefixedRootAsRoleEdge(buf []byte, offset flatbuffers.UOffsetT) *RoleEdge { - n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:]) x := &RoleEdge{} - x.Init(buf, n+offset+flatbuffers.SizeUint32) + InitRoleEdgeRoot(x, buf, offset+flatbuffers.SizeUint32) return x } @@ -667,8 +840,10 @@ func (rcv *RoleEdge) MutateWithAdminOption(n bool) bool { return rcv._tab.MutateBoolSlot(12, n) } +const RoleEdgeNumFields = 5 + func RoleEdgeStart(builder *flatbuffers.Builder) { - builder.StartObject(5) + builder.StartObject(RoleEdgeNumFields) } func RoleEdgeAddFromHost(builder *flatbuffers.Builder, fromHost flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(fromHost), 0) @@ -693,17 +868,34 @@ type ReplicaSourceInfo struct { _tab flatbuffers.Table } -func GetRootAsReplicaSourceInfo(buf []byte, offset flatbuffers.UOffsetT) *ReplicaSourceInfo { +func InitReplicaSourceInfoRoot(o *ReplicaSourceInfo, buf []byte, offset flatbuffers.UOffsetT) error { n := flatbuffers.GetUOffsetT(buf[offset:]) + o.Init(buf, n+offset) + if ReplicaSourceInfoNumFields < o.Table().NumFields() { + return flatbuffers.ErrTableHasUnknownFields + } + return nil +} + +func TryGetRootAsReplicaSourceInfo(buf []byte, offset flatbuffers.UOffsetT) (*ReplicaSourceInfo, error) { x := &ReplicaSourceInfo{} - x.Init(buf, n+offset) + return x, InitReplicaSourceInfoRoot(x, buf, offset) +} + +func GetRootAsReplicaSourceInfo(buf []byte, offset flatbuffers.UOffsetT) *ReplicaSourceInfo { + x := &ReplicaSourceInfo{} + InitReplicaSourceInfoRoot(x, buf, offset) return x } +func TryGetSizePrefixedRootAsReplicaSourceInfo(buf []byte, offset flatbuffers.UOffsetT) (*ReplicaSourceInfo, error) { + x := &ReplicaSourceInfo{} + return x, InitReplicaSourceInfoRoot(x, buf, offset+flatbuffers.SizeUint32) +} + func GetSizePrefixedRootAsReplicaSourceInfo(buf []byte, offset flatbuffers.UOffsetT) *ReplicaSourceInfo { - n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:]) x := &ReplicaSourceInfo{} - x.Init(buf, n+offset+flatbuffers.SizeUint32) + InitReplicaSourceInfoRoot(x, buf, offset+flatbuffers.SizeUint32) return x } @@ -784,8 +976,10 @@ func (rcv *ReplicaSourceInfo) MutateConnectRetryCount(n uint64) bool { return rcv._tab.MutateUint64Slot(16, n) } +const ReplicaSourceInfoNumFields = 7 + func ReplicaSourceInfoStart(builder *flatbuffers.Builder) { - builder.StartObject(7) + builder.StartObject(ReplicaSourceInfoNumFields) } func ReplicaSourceInfoAddHost(builder *flatbuffers.Builder, host flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(host), 0) @@ -816,17 +1010,34 @@ type MySQLDb struct { _tab flatbuffers.Table } -func GetRootAsMySQLDb(buf []byte, offset flatbuffers.UOffsetT) *MySQLDb { +func InitMySQLDbRoot(o *MySQLDb, buf []byte, offset flatbuffers.UOffsetT) error { n := flatbuffers.GetUOffsetT(buf[offset:]) + o.Init(buf, n+offset) + if MySQLDbNumFields < o.Table().NumFields() { + return flatbuffers.ErrTableHasUnknownFields + } + return nil +} + +func TryGetRootAsMySQLDb(buf []byte, offset flatbuffers.UOffsetT) (*MySQLDb, error) { x := &MySQLDb{} - x.Init(buf, n+offset) + return x, InitMySQLDbRoot(x, buf, offset) +} + +func GetRootAsMySQLDb(buf []byte, offset flatbuffers.UOffsetT) *MySQLDb { + x := &MySQLDb{} + InitMySQLDbRoot(x, buf, offset) return x } +func TryGetSizePrefixedRootAsMySQLDb(buf []byte, offset flatbuffers.UOffsetT) (*MySQLDb, error) { + x := &MySQLDb{} + return x, InitMySQLDbRoot(x, buf, offset+flatbuffers.SizeUint32) +} + func GetSizePrefixedRootAsMySQLDb(buf []byte, offset flatbuffers.UOffsetT) *MySQLDb { - n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:]) x := &MySQLDb{} - x.Init(buf, n+offset+flatbuffers.SizeUint32) + InitMySQLDbRoot(x, buf, offset+flatbuffers.SizeUint32) return x } @@ -851,6 +1062,21 @@ func (rcv *MySQLDb) User(obj *User, j int) bool { return false } +func (rcv *MySQLDb) TryUser(obj *User, j int) (bool, error) { + o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) + if o != 0 { + x := rcv._tab.Vector(o) + x += flatbuffers.UOffsetT(j) * 4 + x = rcv._tab.Indirect(x) + obj.Init(rcv._tab.Bytes, x) + if UserNumFields < obj.Table().NumFields() { + return false, flatbuffers.ErrTableHasUnknownFields + } + return true, nil + } + return false, nil +} + func (rcv *MySQLDb) UserLength() int { o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) if o != 0 { @@ -871,6 +1097,21 @@ func (rcv *MySQLDb) RoleEdges(obj *RoleEdge, j int) bool { return false } +func (rcv *MySQLDb) TryRoleEdges(obj *RoleEdge, j int) (bool, error) { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + x := rcv._tab.Vector(o) + x += flatbuffers.UOffsetT(j) * 4 + x = rcv._tab.Indirect(x) + obj.Init(rcv._tab.Bytes, x) + if RoleEdgeNumFields < obj.Table().NumFields() { + return false, flatbuffers.ErrTableHasUnknownFields + } + return true, nil + } + return false, nil +} + func (rcv *MySQLDb) RoleEdgesLength() int { o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) if o != 0 { @@ -891,6 +1132,21 @@ func (rcv *MySQLDb) ReplicaSourceInfo(obj *ReplicaSourceInfo, j int) bool { return false } +func (rcv *MySQLDb) TryReplicaSourceInfo(obj *ReplicaSourceInfo, j int) (bool, error) { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + x := rcv._tab.Vector(o) + x += flatbuffers.UOffsetT(j) * 4 + x = rcv._tab.Indirect(x) + obj.Init(rcv._tab.Bytes, x) + if ReplicaSourceInfoNumFields < obj.Table().NumFields() { + return false, flatbuffers.ErrTableHasUnknownFields + } + return true, nil + } + return false, nil +} + func (rcv *MySQLDb) ReplicaSourceInfoLength() int { o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) if o != 0 { @@ -899,8 +1155,10 @@ func (rcv *MySQLDb) ReplicaSourceInfoLength() int { return 0 } +const MySQLDbNumFields = 3 + func MySQLDbStart(builder *flatbuffers.Builder) { - builder.StartObject(3) + builder.StartObject(MySQLDbNumFields) } func MySQLDbAddUser(builder *flatbuffers.Builder, user flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(user), 0) From a54a25eb140eb35a165e5beaee34302ffe2d04e3 Mon Sep 17 00:00:00 2001 From: reltuk Date: Wed, 19 Apr 2023 21:51:44 +0000 Subject: [PATCH 2/3] [ga-format-pr] Run ./format_repo.sh to fix formatting --- sql/mysql_db/mysql_db.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/mysql_db/mysql_db.go b/sql/mysql_db/mysql_db.go index 359212a771..451cf86de9 100644 --- a/sql/mysql_db/mysql_db.go +++ b/sql/mysql_db/mysql_db.go @@ -24,8 +24,8 @@ import ( "sort" "strings" - "github.com/dolthub/vitess/go/mysql" flatbuffers "github.com/dolthub/flatbuffers/v23/go" + "github.com/dolthub/vitess/go/mysql" "github.com/dolthub/go-mysql-server/sql" "github.com/dolthub/go-mysql-server/sql/mysql_db/serial" From 094f9093fd9a3fe0e60773c537c696c0ea6b7695 Mon Sep 17 00:00:00 2001 From: Aaron Son Date: Wed, 19 Apr 2023 14:23:37 -0700 Subject: [PATCH 3/3] go.mod: Move oliveagle/jsonpath -> dolthub/jsonpath. --- go.mod | 4 +--- go.sum | 4 ++-- sql/rowexec/rel.go | 2 +- sql/rowexec/rel_iters.go | 2 +- sql/types/json_value.go | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 4d2bbd035a..a46a951cca 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/dolthub/go-mysql-server require ( github.com/cespare/xxhash v1.1.0 github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 + github.com/dolthub/jsonpath v0.0.1 github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 github.com/dolthub/vitess v0.0.0-20230407173322-ae1622f38e94 github.com/go-kit/kit v0.10.0 @@ -12,7 +13,6 @@ require ( github.com/hashicorp/golang-lru v0.5.4 github.com/lestrrat-go/strftime v1.0.4 github.com/mitchellh/hashstructure v1.1.0 - github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 github.com/pkg/errors v0.9.1 github.com/pmezard/go-difflib v1.0.0 github.com/shopspring/decimal v1.2.0 @@ -40,6 +40,4 @@ require ( gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect ) -replace github.com/oliveagle/jsonpath => github.com/dolthub/jsonpath v0.0.0-20210609232853-d49537a30474 - go 1.19 diff --git a/go.sum b/go.sum index b045d7bbf4..40d09c03ff 100644 --- a/go.sum +++ b/go.sum @@ -53,8 +53,8 @@ github.com/denisenkom/go-mssqldb v0.10.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27 github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww= github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2/go.mod h1:mIEZOHnFx4ZMQeawhw9rhsj+0zwQj7adVsnBX7t+eKY= -github.com/dolthub/jsonpath v0.0.0-20210609232853-d49537a30474 h1:xTrR+l5l+1Lfq0NvhiEsctylXinUMFhhsqaEcl414p8= -github.com/dolthub/jsonpath v0.0.0-20210609232853-d49537a30474/go.mod h1:kMz7uXOXq4qRriCEyZ/LUeTqraLJCjf0WVZcUi6TxUY= +github.com/dolthub/jsonpath v0.0.1 h1:Nd+T3U+XisK3kOuxtABS5IIbZqXVIlOR9VYquyjQ0u0= +github.com/dolthub/jsonpath v0.0.1/go.mod h1:ZWUdY4iszqRQ8OcoXClkxiAVAoWoK3cq0Hvv4ddGRuM= github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9XGFa6q5Ap4Z/OhNkAMBaK5YeuEzwJt+NZdhiE= github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY= github.com/dolthub/vitess v0.0.0-20230407173322-ae1622f38e94 h1:As3/5XDEthX6rvA+Dbiutxo965AdVhxa937j2OGSaog= diff --git a/sql/rowexec/rel.go b/sql/rowexec/rel.go index 9fbb091ae4..f5293f82ef 100644 --- a/sql/rowexec/rel.go +++ b/sql/rowexec/rel.go @@ -21,7 +21,7 @@ import ( "io" "reflect" - "github.com/oliveagle/jsonpath" + "github.com/dolthub/jsonpath" "github.com/shopspring/decimal" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" diff --git a/sql/rowexec/rel_iters.go b/sql/rowexec/rel_iters.go index b7be662ce3..db135736fc 100644 --- a/sql/rowexec/rel_iters.go +++ b/sql/rowexec/rel_iters.go @@ -22,7 +22,7 @@ import ( "sort" "strings" - "github.com/oliveagle/jsonpath" + "github.com/dolthub/jsonpath" "github.com/dolthub/go-mysql-server/sql" "github.com/dolthub/go-mysql-server/sql/expression" diff --git a/sql/types/json_value.go b/sql/types/json_value.go index 8066d671d2..5a8aef94b1 100644 --- a/sql/types/json_value.go +++ b/sql/types/json_value.go @@ -22,7 +22,7 @@ import ( "sort" "strings" - "github.com/oliveagle/jsonpath" + "github.com/dolthub/jsonpath" "github.com/dolthub/go-mysql-server/sql" )