mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-09 03:09:12 -06:00
Merge pull request #1375 from dolthub/andy/super-schema-missing
Fix Schema Unmarshalling Error
This commit is contained in:
@@ -140,7 +140,6 @@ func (root *RootValue) GetSuperSchema(ctx context.Context, tName string) (*schem
|
||||
}
|
||||
|
||||
t, tblFound, err := root.GetTable(ctx, tName)
|
||||
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
@@ -152,13 +151,11 @@ func (root *RootValue) GetSuperSchema(ctx context.Context, tName string) (*schem
|
||||
|
||||
if tblFound {
|
||||
sch, err := t.GetSchema(ctx)
|
||||
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
err = ss.AddSchemas(sch)
|
||||
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
@@ -237,13 +234,11 @@ func (root *RootValue) GetSuperSchemaMap(ctx context.Context) (types.Map, error)
|
||||
// SuperSchemas are only persisted on commit.
|
||||
func (root *RootValue) getSuperSchemaAtLastCommit(ctx context.Context, tName string) (*schema.SuperSchema, bool, error) {
|
||||
ssm, err := root.getOrCreateSuperSchemaMap(ctx)
|
||||
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
v, found, err := ssm.MaybeGet(ctx, types.String(tName))
|
||||
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
@@ -254,13 +249,11 @@ func (root *RootValue) getSuperSchemaAtLastCommit(ctx context.Context, tName str
|
||||
|
||||
ssValRef := v.(types.Ref)
|
||||
ssVal, err := ssValRef.TargetValue(ctx, root.vrw)
|
||||
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
ss, err := encoding.UnmarshalSuperSchemaNomsValue(ctx, root.vrw.Format(), ssVal)
|
||||
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
@@ -424,7 +417,7 @@ func (root *RootValue) GetTableByColTag(ctx context.Context, tag uint64) (tbl *T
|
||||
return nil, "", false, err
|
||||
}
|
||||
|
||||
_ = root.iterSuperSchemas(ctx, func(tn string, ss *schema.SuperSchema) (bool, error) {
|
||||
err = root.iterSuperSchemas(ctx, func(tn string, ss *schema.SuperSchema) (bool, error) {
|
||||
_, found = ss.GetByTag(tag)
|
||||
if found {
|
||||
name = tn
|
||||
@@ -432,6 +425,9 @@ func (root *RootValue) GetTableByColTag(ctx context.Context, tag uint64) (tbl *T
|
||||
|
||||
return found, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, "", false, err
|
||||
}
|
||||
|
||||
return tbl, name, found, nil
|
||||
}
|
||||
@@ -573,6 +569,9 @@ func (root *RootValue) iterSuperSchemas(ctx context.Context, cb func(name string
|
||||
|
||||
// use GetSuperSchema() to pickup uncommitted SuperSchemas
|
||||
ss, _, err := root.GetSuperSchema(ctx, name)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return cb(name, ss)
|
||||
})
|
||||
@@ -1117,20 +1116,23 @@ func validateTagUniqueness(ctx context.Context, root *RootValue, tableName strin
|
||||
}
|
||||
|
||||
var ee []string
|
||||
_ = root.iterSuperSchemas(ctx, func(tn string, ss *schema.SuperSchema) (stop bool, err error) {
|
||||
err = root.iterSuperSchemas(ctx, func(tn string, ss *schema.SuperSchema) (stop bool, err error) {
|
||||
if tn == tableName {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
_ = sch.GetAllCols().Iter(func(tag uint64, col schema.Column) (stop bool, err error) {
|
||||
err = sch.GetAllCols().Iter(func(tag uint64, col schema.Column) (stop bool, err error) {
|
||||
_, ok := ss.GetByTag(tag)
|
||||
if ok {
|
||||
ee = append(ee, schema.ErrTagPrevUsed(tag, col.Name, tn).Error())
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
return false, nil
|
||||
return false, err
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(ee) > 0 {
|
||||
return fmt.Errorf(strings.Join(ee, "\n"))
|
||||
|
||||
@@ -763,7 +763,6 @@ func MergeRoots(ctx context.Context, ourRoot, theirRoot, ancRoot *doltdb.RootVal
|
||||
tableEditSession := editor.CreateTableEditSession(ourRoot, editor.TableEditSessionProps{
|
||||
ForeignKeyChecksDisabled: true,
|
||||
})
|
||||
var unconflicted []string
|
||||
// need to validate merges can be done on all tables before starting the actual merges.
|
||||
for _, tblName := range tblNames {
|
||||
mergedTable, stats, err := merger.MergeTable(ctx, tblName, tableEditSession)
|
||||
@@ -775,10 +774,6 @@ func MergeRoots(ctx context.Context, ourRoot, theirRoot, ancRoot *doltdb.RootVal
|
||||
if mergedTable != nil {
|
||||
tblToStats[tblName] = stats
|
||||
|
||||
if stats.Conflicts == 0 {
|
||||
unconflicted = append(unconflicted, tblName)
|
||||
}
|
||||
|
||||
err = tableEditSession.UpdateRoot(ctx, func(ctx context.Context, root *doltdb.RootValue) (*doltdb.RootValue, error) {
|
||||
return root.PutTable(ctx, tblName, mergedTable)
|
||||
})
|
||||
@@ -813,10 +808,19 @@ func MergeRoots(ctx context.Context, ourRoot, theirRoot, ancRoot *doltdb.RootVal
|
||||
if len(conflicts) > 0 {
|
||||
return nil, fmt.Errorf("foreign key conflicts")
|
||||
}
|
||||
return root.PutForeignKeyCollection(ctx, mergedFKColl)
|
||||
})
|
||||
|
||||
newRoot, err = newRoot.UpdateSuperSchemasFromOther(ctx, unconflicted, theirRoot)
|
||||
root, err = root.PutForeignKeyCollection(ctx, mergedFKColl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return root.UpdateSuperSchemasFromOther(ctx, tblNames, theirRoot)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
newRoot, err = tableEditSession.Flush(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ func (d *DoltHarness) SkipQueryTest(query string) bool {
|
||||
lowerQuery == "show variables" || // we set extra variables
|
||||
strings.Contains(lowerQuery, "show create table") || // we set extra comment info
|
||||
strings.Contains(lowerQuery, "show indexes from") || // we create / expose extra indexes (for foreign keys)
|
||||
strings.Contains(lowerQuery, "row_number") || // TODO: fix row number race
|
||||
query == `SELECT i FROM mytable mt
|
||||
WHERE (SELECT i FROM mytable where i = mt.i and i > 2) IS NOT NULL
|
||||
AND (SELECT i2 FROM othertable where i2 = i) IS NOT NULL
|
||||
|
||||
@@ -159,9 +159,9 @@ func parentsToQueue(ctx context.Context, refs types.RefSlice, q *types.RefByHeig
|
||||
}
|
||||
if ok {
|
||||
p := ps.(types.List)
|
||||
err = p.IterAll(ctx, func(v types.Value, _ uint64) error {
|
||||
err = p.Iter(ctx, func(v types.Value, _ uint64) (stop bool, err error) {
|
||||
q.PushBack(v.(types.Ref))
|
||||
return nil
|
||||
return
|
||||
})
|
||||
} else {
|
||||
ps, ok, err := c.MaybeGet(ParentsField)
|
||||
@@ -170,9 +170,9 @@ func parentsToQueue(ctx context.Context, refs types.RefSlice, q *types.RefByHeig
|
||||
}
|
||||
if ok {
|
||||
p := ps.(types.Set)
|
||||
err = p.IterAll(ctx, func(v types.Value) error {
|
||||
err = p.Iter(ctx, func(v types.Value) (stop bool, err error) {
|
||||
q.PushBack(v.(types.Ref))
|
||||
return nil
|
||||
return
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,8 +462,10 @@ func marshalerDecoder(t reflect.Type) decoderFunc {
|
||||
func iterListOrSlice(ctx context.Context, nbf *types.NomsBinFormat, v types.Value, t reflect.Type, f func(c types.Value, i uint64) error) error {
|
||||
switch v := v.(type) {
|
||||
case types.List:
|
||||
err := v.IterAll(ctx, f)
|
||||
|
||||
err := v.Iter(ctx, func(v types.Value, idx uint64) (stop bool, err error) {
|
||||
err = f(v, idx)
|
||||
return
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -662,19 +664,19 @@ func mapDecoder(t reflect.Type, tags nomsTags) (decoderFunc, error) {
|
||||
|
||||
init.RLock()
|
||||
defer init.RUnlock()
|
||||
err := nomsMap.IterAll(ctx, func(k, v types.Value) error {
|
||||
err := nomsMap.Iter(ctx, func(k, v types.Value) (stop bool, err error) {
|
||||
keyRv := reflect.New(t.Key()).Elem()
|
||||
err := keyDecoder(ctx, nbf, k, keyRv)
|
||||
err = keyDecoder(ctx, nbf, k, keyRv)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
valueRv := reflect.New(t.Elem()).Elem()
|
||||
err = valueDecoder(ctx, nbf, v, valueRv)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
if m.IsNil() {
|
||||
@@ -682,7 +684,7 @@ func mapDecoder(t reflect.Type, tags nomsTags) (decoderFunc, error) {
|
||||
}
|
||||
|
||||
m.SetMapIndex(keyRv, valueRv)
|
||||
return nil
|
||||
return
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -210,33 +210,24 @@ func (w *hrsWriter) Write(ctx context.Context, v Value) error {
|
||||
w.writeSize(v)
|
||||
w.indent()
|
||||
|
||||
var err error
|
||||
iterErr := v.(List).Iter(ctx, func(v Value, i uint64) bool {
|
||||
err := v.(List).Iter(ctx, func(v Value, i uint64) (bool, error) {
|
||||
if i == 0 {
|
||||
w.newLine()
|
||||
}
|
||||
|
||||
err = w.Write(ctx, v)
|
||||
|
||||
if err != nil {
|
||||
return true
|
||||
if err := w.Write(ctx, v); err != nil {
|
||||
return true, err
|
||||
}
|
||||
|
||||
w.write(",")
|
||||
w.newLine()
|
||||
err = w.err
|
||||
|
||||
return err != nil
|
||||
return false, w.err
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if iterErr != nil {
|
||||
return iterErr
|
||||
}
|
||||
|
||||
w.outdent()
|
||||
w.write("]")
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ func (l List) isPrimitive() bool {
|
||||
|
||||
// Iter iterates over the list and calls f for every element in the list. If f returns true then the
|
||||
// iteration stops.
|
||||
func (l List) Iter(ctx context.Context, f func(v Value, index uint64) (stop bool)) error {
|
||||
func (l List) Iter(ctx context.Context, f func(v Value, index uint64) (stop bool, err error)) error {
|
||||
idx := uint64(0)
|
||||
cur, err := newSequenceIteratorAtIndex(ctx, l.sequence, idx)
|
||||
|
||||
@@ -206,11 +206,9 @@ func (l List) Iter(ctx context.Context, f func(v Value, index uint64) (stop bool
|
||||
}
|
||||
|
||||
err = cur.iter(ctx, func(v interface{}) (bool, error) {
|
||||
if f(v.(Value), uint64(idx)) {
|
||||
return true, nil
|
||||
}
|
||||
stop, err := f(v.(Value), idx)
|
||||
idx++
|
||||
return false, nil
|
||||
return stop, err
|
||||
})
|
||||
|
||||
return err
|
||||
|
||||
@@ -160,11 +160,11 @@ func (suite *listTestSuite) TestIter() {
|
||||
list := suite.col.(List)
|
||||
expectIdx := uint64(0)
|
||||
endAt := suite.expectLen / 2
|
||||
err := list.Iter(context.Background(), func(v Value, idx uint64) bool {
|
||||
err := list.Iter(context.Background(), func(v Value, idx uint64) (bool, error) {
|
||||
suite.Equal(expectIdx, idx)
|
||||
expectIdx++
|
||||
suite.Equal(suite.elems[idx], v)
|
||||
return expectIdx == endAt
|
||||
return expectIdx == endAt, nil
|
||||
})
|
||||
|
||||
suite.NoError(err)
|
||||
@@ -311,7 +311,7 @@ func TestStreamingListCreation(t *testing.T) {
|
||||
assert.True(ok)
|
||||
assert.NoError(ae.Get())
|
||||
assert.True(cl.Equals(sl))
|
||||
err = cl.Iter(context.Background(), func(v Value, idx uint64) (done bool) {
|
||||
err = cl.Iter(context.Background(), func(v Value, idx uint64) (done bool, err error) {
|
||||
done = !assert.True(v.Equals(mustValue(sl.Get(context.Background(), idx))))
|
||||
return
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user