@@ -19,8 +19,6 @@ import (
1919 "fmt"
2020 "sync"
2121
22- "github.com/dolthub/go-mysql-server/sql"
23-
2422 "github.com/dolthub/doltgresql/server/types"
2523 "github.com/dolthub/doltgresql/utils"
2624)
@@ -34,7 +32,7 @@ func (pgs *TypeCollection) Serialize(ctx context.Context) ([]byte, error) {
3432 pgs .mutex .Lock ()
3533 defer pgs .mutex .Unlock ()
3634
37- // Write all the Types to the writer
35+ // Write all the types to the writer
3836 writer := utils .NewWriter (256 )
3937 writer .VariableUint (0 ) // Version
4038 schemaMapKeys := utils .GetMapKeysSorted (pgs .schemaMap )
@@ -46,42 +44,8 @@ func (pgs *TypeCollection) Serialize(ctx context.Context) ([]byte, error) {
4644 writer .VariableUint (uint64 (len (nameMapKeys )))
4745 for _ , nameMapKey := range nameMapKeys {
4846 typ := nameMap [nameMapKey ]
49- writer .Uint32 (typ .Oid )
50- writer .String (typ .Name )
51- writer .String (typ .Owner )
52- writer .Int16 (typ .Length )
53- writer .Bool (typ .PassedByVal )
54- writer .String (string (typ .TypType ))
55- writer .String (string (typ .TypCategory ))
56- writer .Bool (typ .IsPreferred )
57- writer .Bool (typ .IsDefined )
58- writer .String (typ .Delimiter )
59- writer .Uint32 (typ .RelID )
60- writer .String (typ .SubscriptFunc )
61- writer .Uint32 (typ .Elem )
62- writer .Uint32 (typ .Array )
63- writer .String (typ .InputFunc )
64- writer .String (typ .OutputFunc )
65- writer .String (typ .ReceiveFunc )
66- writer .String (typ .SendFunc )
67- writer .String (typ .ModInFunc )
68- writer .String (typ .ModOutFunc )
69- writer .String (typ .AnalyzeFunc )
70- writer .String (string (typ .Align ))
71- writer .String (string (typ .Storage ))
72- writer .Bool (typ .NotNull )
73- writer .Uint32 (typ .BaseTypeOID )
74- writer .Int32 (typ .TypMod )
75- writer .Int32 (typ .NDims )
76- writer .Uint32 (typ .Collation )
77- writer .String (typ .DefaulBin )
78- writer .String (typ .Default )
79- writer .String (typ .Acl )
80- writer .VariableUint (uint64 (len (typ .Checks )))
81- for _ , check := range typ .Checks {
82- writer .String (check .Name )
83- writer .String (check .CheckExpression )
84- }
47+ data := typ .Serialize ()
48+ writer .ByteSlice (data )
8549 }
8650 }
8751
@@ -93,11 +57,11 @@ func (pgs *TypeCollection) Serialize(ctx context.Context) ([]byte, error) {
9357func Deserialize (ctx context.Context , data []byte ) (* TypeCollection , error ) {
9458 if len (data ) == 0 {
9559 return & TypeCollection {
96- schemaMap : make (map [string ]map [string ]* types.Type ),
60+ schemaMap : make (map [string ]map [string ]types.DoltgresType ),
9761 mutex : & sync.RWMutex {},
9862 }, nil
9963 }
100- schemaMap := make (map [string ]map [string ]* types.Type )
64+ schemaMap := make (map [string ]map [string ]types.DoltgresType )
10165 reader := utils .NewReader (data )
10266 version := reader .VariableUint ()
10367 if version != 0 {
@@ -109,51 +73,15 @@ func Deserialize(ctx context.Context, data []byte) (*TypeCollection, error) {
10973 for i := uint64 (0 ); i < numOfSchemas ; i ++ {
11074 schemaName := reader .String ()
11175 numOfTypes := reader .VariableUint ()
112- nameMap := make (map [string ]* types.Type )
76+ nameMap := make (map [string ]types.DoltgresType )
11377 for j := uint64 (0 ); j < numOfTypes ; j ++ {
114- typ := & types.Type {Schema : schemaName }
115- typ .Oid = reader .Uint32 ()
116- typ .Name = reader .String ()
117- typ .Owner = reader .String ()
118- typ .Length = reader .Int16 ()
119- typ .PassedByVal = reader .Bool ()
120- typ .TypType = types .TypeType (reader .String ())
121- typ .TypCategory = types .TypeCategory (reader .String ())
122- typ .IsPreferred = reader .Bool ()
123- typ .IsDefined = reader .Bool ()
124- typ .Delimiter = reader .String ()
125- typ .RelID = reader .Uint32 ()
126- typ .SubscriptFunc = reader .String ()
127- typ .Elem = reader .Uint32 ()
128- typ .Array = reader .Uint32 ()
129- typ .InputFunc = reader .String ()
130- typ .OutputFunc = reader .String ()
131- typ .ReceiveFunc = reader .String ()
132- typ .SendFunc = reader .String ()
133- typ .ModInFunc = reader .String ()
134- typ .ModOutFunc = reader .String ()
135- typ .AnalyzeFunc = reader .String ()
136- typ .Align = types .TypeAlignment (reader .String ())
137- typ .Storage = types .TypeStorage (reader .String ())
138- typ .NotNull = reader .Bool ()
139- typ .BaseTypeOID = reader .Uint32 ()
140- typ .TypMod = reader .Int32 ()
141- typ .NDims = reader .Int32 ()
142- typ .Collation = reader .Uint32 ()
143- typ .DefaulBin = reader .String ()
144- typ .Default = reader .String ()
145- typ .Acl = reader .String ()
146- numOfChecks := reader .VariableUint ()
147- for k := uint64 (0 ); k < numOfChecks ; k ++ {
148- checkName := reader .String ()
149- checkExpr := reader .String ()
150- typ .Checks = append (typ .Checks , & sql.CheckDefinition {
151- Name : checkName ,
152- CheckExpression : checkExpr ,
153- Enforced : true ,
154- })
78+ typData := reader .ByteSlice ()
79+ typ , err := types .DeserializeType (typData )
80+ if err != nil {
81+ return nil , err
15582 }
156- nameMap [typ .Name ] = typ
83+ dt := typ .(types.DoltgresType )
84+ nameMap [dt .Name ] = dt
15785 }
15886 schemaMap [schemaName ] = nameMap
15987 }
0 commit comments