mirror of
https://github.com/dolthub/dolt.git
synced 2026-03-17 23:56:33 -05:00
refactored conflict schemas
This commit is contained in:
@@ -34,7 +34,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env/actions"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/rowconv"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/untyped/csv"
|
||||
@@ -297,11 +296,6 @@ func importSchema(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPars
|
||||
return errhand.BuildDError("error: failed to get table.").AddCause(err).Build()
|
||||
}
|
||||
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), root.VRW(), sch)
|
||||
if err != nil {
|
||||
return errhand.BuildDError("error: failed to encode schema.").AddCause(err).Build()
|
||||
}
|
||||
|
||||
empty, err := types.NewMap(ctx, root.VRW())
|
||||
if err != nil {
|
||||
return errhand.BuildDError("error: failed to create table.").AddCause(err).Build()
|
||||
@@ -315,7 +309,7 @@ func importSchema(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPars
|
||||
}
|
||||
}
|
||||
|
||||
tbl, err = doltdb.NewTable(ctx, root.VRW(), schVal, empty, indexData, nil)
|
||||
tbl, err = doltdb.NewTable(ctx, root.VRW(), sch, empty, indexData, nil)
|
||||
if err != nil {
|
||||
return errhand.BuildDError("error: failed to create table.").AddCause(err).Build()
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
filesys2 "github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
@@ -119,14 +118,8 @@ func TestDocDiff(t *testing.T) {
|
||||
}
|
||||
|
||||
func CreateTestTable(vrw types.ValueReadWriter, tSchema schema.Schema, rowData types.Map) (*doltdb.Table, error) {
|
||||
schemaVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), vrw, tSchema)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
empty, _ := types.NewMap(context.Background(), vrw)
|
||||
tbl, err := doltdb.NewTable(context.Background(), vrw, schemaVal, rowData, empty, nil)
|
||||
tbl, err := doltdb.NewTable(context.Background(), vrw, tSchema, rowData, empty, nil)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -14,7 +14,107 @@
|
||||
|
||||
package doltdb
|
||||
|
||||
import "github.com/dolthub/dolt/go/store/types"
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
type ConflictSchema struct {
|
||||
Base schema.Schema
|
||||
Schema schema.Schema
|
||||
MergeSchema schema.Schema
|
||||
}
|
||||
|
||||
func NewConflictSchema(base, sch, mergeSch schema.Schema) ConflictSchema {
|
||||
return ConflictSchema{
|
||||
Base: base,
|
||||
Schema: sch,
|
||||
MergeSchema: mergeSch,
|
||||
}
|
||||
}
|
||||
|
||||
func ValueFromConflictSchema(ctx context.Context, vrw types.ValueReadWriter, cs ConflictSchema) (types.Value, error) {
|
||||
b, err := serializeSchema(ctx, vrw, cs.Base)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s, err := serializeSchema(ctx, vrw, cs.Schema)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m, err := serializeSchema(ctx, vrw, cs.MergeSchema)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return types.NewTuple(types.Format_Default, b, s, m)
|
||||
}
|
||||
|
||||
func ConflictSchemaFromValue(ctx context.Context, vrw types.ValueReadWriter, v types.Value) (cs ConflictSchema, err error) {
|
||||
tup, ok := v.(types.Tuple)
|
||||
if !ok {
|
||||
err = errors.New("conflict schema value must be types.Struct")
|
||||
return ConflictSchema{}, err
|
||||
}
|
||||
|
||||
b, err := tup.Get(0)
|
||||
if err != nil {
|
||||
return ConflictSchema{}, err
|
||||
}
|
||||
cs.Base, err = deserializeSchema(ctx, vrw, b)
|
||||
if err != nil {
|
||||
return ConflictSchema{}, err
|
||||
}
|
||||
|
||||
s, err := tup.Get(1)
|
||||
if err != nil {
|
||||
return ConflictSchema{}, err
|
||||
}
|
||||
cs.Schema, err = deserializeSchema(ctx, vrw, s)
|
||||
if err != nil {
|
||||
return ConflictSchema{}, err
|
||||
}
|
||||
|
||||
m, err := tup.Get(2)
|
||||
if err != nil {
|
||||
return ConflictSchema{}, err
|
||||
}
|
||||
cs.MergeSchema, err = deserializeSchema(ctx, vrw, m)
|
||||
if err != nil {
|
||||
return ConflictSchema{}, err
|
||||
}
|
||||
|
||||
return cs, nil
|
||||
}
|
||||
|
||||
func serializeSchema(ctx context.Context, vrw types.ValueReadWriter, sch schema.Schema) (types.Ref, error) {
|
||||
st, err := encoding.MarshalSchemaAsNomsValue(ctx, vrw, sch)
|
||||
if err != nil {
|
||||
return types.Ref{}, err
|
||||
}
|
||||
|
||||
return vrw.WriteValue(ctx, st)
|
||||
}
|
||||
|
||||
func deserializeSchema(ctx context.Context, vrw types.ValueReadWriter, v types.Value) (schema.Schema, error) {
|
||||
r, ok := v.(types.Ref)
|
||||
if !ok {
|
||||
return nil, errors.New("conflict schemas field value is unexpected type")
|
||||
}
|
||||
|
||||
tv, err := r.TargetValue(ctx, vrw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return encoding.UnmarshalSchemaNomsValue(ctx, types.Format_Default, tv)
|
||||
}
|
||||
|
||||
type Conflict struct {
|
||||
Base types.Value
|
||||
|
||||
@@ -28,7 +28,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/test"
|
||||
"github.com/dolthub/dolt/go/store/hash"
|
||||
@@ -70,14 +69,8 @@ func createTestSchema(t *testing.T) schema.Schema {
|
||||
}
|
||||
|
||||
func CreateTestTable(vrw types.ValueReadWriter, tSchema schema.Schema, rowData types.Map) (*Table, error) {
|
||||
schemaVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), vrw, tSchema)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
empty, _ := types.NewMap(context.Background(), vrw)
|
||||
tbl, err := NewTable(context.Background(), vrw, schemaVal, rowData, empty, nil)
|
||||
tbl, err := NewTable(context.Background(), vrw, tSchema, rowData, empty, nil)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
45
go/libraries/doltcore/doltdb/durable/table.go
Normal file
45
go/libraries/doltcore/doltdb/durable/table.go
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright 2021 Dolthub, Inc.
|
||||
//
|
||||
// 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 durable
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/store/hash"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
type Table interface {
|
||||
GetSchemaHash(ctx context.Context) (hash.Hash, error)
|
||||
GetSchema(ctx context.Context) (schema.Schema, error)
|
||||
SetSchema(ctx context.Context, sch schema.Schema) error
|
||||
|
||||
GetTableRows(ctx context.Context) (types.Map, error)
|
||||
SetTableRows(ctx context.Context, rows types.Map) error
|
||||
|
||||
GetIndexes(ctx context.Context) (types.Map, error)
|
||||
SetIndexes(ctx context.Context, indexes types.Map) error
|
||||
|
||||
GetConflicts(ctx context.Context) (doltdb.ConflictSchema, types.Map, error)
|
||||
SetConflicts(ctx context.Context, sch doltdb.ConflictSchema, conflicts types.Map) error
|
||||
|
||||
GetConstraintViolations(ctx context.Context) (types.Map, error)
|
||||
SetConstraintViolations(ctx context.Context, violations types.Map) error
|
||||
|
||||
GetAutoIncrement(ctx context.Context) (types.Value, error)
|
||||
SetAutoIncrement(ctx context.Context, val types.Value) error
|
||||
}
|
||||
@@ -756,11 +756,6 @@ func putTable(ctx context.Context, root *RootValue, tName string, tableRef types
|
||||
|
||||
// CreateEmptyTable creates an empty table in this root with the name and schema given, returning the new root value.
|
||||
func (root *RootValue) CreateEmptyTable(ctx context.Context, tName string, sch schema.Schema) (*RootValue, error) {
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(ctx, root.VRW(), sch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
empty, err := types.NewMap(ctx, root.VRW())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -786,7 +781,7 @@ func (root *RootValue) CreateEmptyTable(ctx context.Context, tName string, sch s
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tbl, err := NewTable(ctx, root.VRW(), schVal, empty, indexes, nil)
|
||||
tbl, err := NewTable(ctx, root.VRW(), sch, empty, indexes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1213,18 +1208,18 @@ func validateTagUniqueness(ctx context.Context, root *RootValue, tableName strin
|
||||
return err
|
||||
}
|
||||
if ok {
|
||||
prevRef, err := prev.GetSchemaRef()
|
||||
prevHash, err := prev.GetSchemaHash(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
newRef, err := table.GetSchemaRef()
|
||||
newHash, err := table.GetSchemaHash(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// short-circuit if schema unchanged
|
||||
if prevRef.Equals(newRef) {
|
||||
if prevHash == newHash {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,8 +84,13 @@ type Table struct {
|
||||
}
|
||||
|
||||
// NewTable creates a noms Struct which stores row data, index data, and schema.
|
||||
func NewTable(ctx context.Context, vrw types.ValueReadWriter, schemaVal types.Value, rowData types.Map, indexData types.Map, autoIncVal types.Value) (*Table, error) {
|
||||
schemaRef, err := WriteValAndGetRef(ctx, vrw, schemaVal)
|
||||
func NewTable(ctx context.Context, vrw types.ValueReadWriter, sch schema.Schema, rowData types.Map, indexData types.Map, autoIncVal types.Value) (*Table, error) {
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(ctx, vrw, sch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
schemaRef, err := WriteValAndGetRef(ctx, vrw, schVal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -127,27 +132,23 @@ func (t *Table) ValueReadWriter() types.ValueReadWriter {
|
||||
return t.vrw
|
||||
}
|
||||
|
||||
func (t *Table) SetConflicts(ctx context.Context, schemas Conflict, conflictData types.Map) (*Table, error) {
|
||||
func (t *Table) SetConflicts(ctx context.Context, schemas ConflictSchema, conflictData types.Map) (*Table, error) {
|
||||
conflictsRef, err := WriteValAndGetRef(ctx, t.vrw, conflictData)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tpl, err := schemas.ToNomsList(t.vrw)
|
||||
|
||||
tpl, err := ValueFromConflictSchema(ctx, t.vrw, schemas)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
updatedSt, err := t.tableStruct.Set(conflictSchemasKey, tpl)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
updatedSt, err = updatedSt.Set(conflictsKey, conflictsRef)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -156,24 +157,24 @@ func (t *Table) SetConflicts(ctx context.Context, schemas Conflict, conflictData
|
||||
}
|
||||
|
||||
// GetConflicts returns a map built from ValueReadWriter when there are no conflicts in table
|
||||
func (t *Table) GetConflicts(ctx context.Context) (Conflict, types.Map, error) {
|
||||
func (t *Table) GetConflicts(ctx context.Context) (ConflictSchema, types.Map, error) {
|
||||
schemasVal, ok, err := t.tableStruct.MaybeGet(conflictSchemasKey)
|
||||
if err != nil {
|
||||
return Conflict{}, types.EmptyMap, err
|
||||
return ConflictSchema{}, types.EmptyMap, err
|
||||
}
|
||||
if !ok {
|
||||
confMap, _ := types.NewMap(ctx, t.ValueReadWriter())
|
||||
return Conflict{}, confMap, nil
|
||||
return ConflictSchema{}, confMap, nil
|
||||
}
|
||||
|
||||
schemas, err := ConflictFromTuple(schemasVal.(types.Tuple))
|
||||
schemas, err := ConflictSchemaFromValue(ctx, t.vrw, schemasVal)
|
||||
if err != nil {
|
||||
return Conflict{}, types.EmptyMap, err
|
||||
return ConflictSchema{}, types.EmptyMap, err
|
||||
}
|
||||
|
||||
conflictsVal, _, err := t.tableStruct.MaybeGet(conflictsKey)
|
||||
if err != nil {
|
||||
return Conflict{}, types.EmptyMap, err
|
||||
return ConflictSchema{}, types.EmptyMap, err
|
||||
}
|
||||
|
||||
confMap := types.EmptyMap
|
||||
@@ -182,7 +183,7 @@ func (t *Table) GetConflicts(ctx context.Context) (Conflict, types.Map, error) {
|
||||
v, err := confMapRef.TargetValue(ctx, t.vrw)
|
||||
|
||||
if err != nil {
|
||||
return Conflict{}, types.EmptyMap, err
|
||||
return ConflictSchema{}, types.EmptyMap, err
|
||||
}
|
||||
|
||||
confMap = v.(types.Map)
|
||||
@@ -373,18 +374,19 @@ func (t *Table) GetSchema(ctx context.Context) (schema.Schema, error) {
|
||||
return RefToSchema(ctx, t.vrw, schemaRef)
|
||||
}
|
||||
|
||||
func (t *Table) GetSchemaRef() (types.Ref, error) {
|
||||
v, _, err := t.tableStruct.MaybeGet(schemaRefKey)
|
||||
|
||||
if err != nil {
|
||||
return types.Ref{}, err
|
||||
}
|
||||
|
||||
if v == nil {
|
||||
return types.Ref{}, errors.New("missing schema")
|
||||
}
|
||||
|
||||
return v.(types.Ref), nil
|
||||
func (t *Table) GetSchemaHash(ctx context.Context) (hash.Hash, error) {
|
||||
//v, _, err := t.tableStruct.MaybeGet(schemaRefKey)
|
||||
//
|
||||
//if err != nil {
|
||||
// return types.Ref{}, err
|
||||
//}
|
||||
//
|
||||
//if v == nil {
|
||||
// return types.Ref{}, errors.New("missing schema")
|
||||
//}
|
||||
//
|
||||
//return v.(types.Ref), nil
|
||||
return hash.Hash{}, nil
|
||||
}
|
||||
|
||||
// UpdateSchema updates the table with the schema given and returns the updated table. The original table is unchanged.
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/typed/noms"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
@@ -115,18 +114,13 @@ func createDocsTable(ctx context.Context, vrw types.ValueReadWriter, docs Docs)
|
||||
rd.Close(context.Background())
|
||||
wr.Close(context.Background())
|
||||
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(ctx, vrw, wr.GetSchema())
|
||||
|
||||
if err != nil {
|
||||
return nil, ErrMarshallingSchema
|
||||
}
|
||||
|
||||
empty, err := types.NewMap(ctx, vrw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sch := wr.GetSchema()
|
||||
|
||||
newDocsTbl, err := doltdb.NewTable(ctx, vrw, schVal, wr.GetMap(), empty, nil)
|
||||
newDocsTbl, err := doltdb.NewTable(ctx, vrw, sch, wr.GetMap(), empty, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
filesys2 "github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
@@ -135,14 +134,8 @@ func TestAddNewerTextAndDocPkFromRow(t *testing.T) {
|
||||
}
|
||||
|
||||
func CreateTestTable(vrw types.ValueReadWriter, tSchema schema.Schema, rowData types.Map) (*doltdb.Table, error) {
|
||||
schemaVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), vrw, tSchema)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
empty, _ := types.NewMap(context.Background(), vrw)
|
||||
tbl, err := doltdb.NewTable(context.Background(), vrw, schemaVal, rowData, empty, nil)
|
||||
tbl, err := doltdb.NewTable(context.Background(), vrw, tSchema, rowData, empty, nil)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/editor"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/typed/noms"
|
||||
@@ -79,11 +78,9 @@ func CreateEnvWithSeedData(t *testing.T) *env.DoltEnv {
|
||||
sch = wr.GetSchema()
|
||||
sch.Indexes().Merge(ai...)
|
||||
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(ctx, vrw, sch)
|
||||
require.NoError(t, err)
|
||||
empty, err := types.NewMap(ctx, vrw)
|
||||
require.NoError(t, err)
|
||||
tbl, err := doltdb.NewTable(ctx, vrw, schVal, wr.GetMap(), empty, nil)
|
||||
tbl, err := doltdb.NewTable(ctx, vrw, sch, wr.GetMap(), empty, nil)
|
||||
require.NoError(t, err)
|
||||
tbl, err = editor.RebuildAllIndexes(ctx, tbl, editor.TestEditorOptions(vrw))
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/editor"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/typed/noms"
|
||||
@@ -110,11 +109,9 @@ func CreateTestTable(t *testing.T, dEnv *env.DoltEnv, tableName string, sch sche
|
||||
err = wr.Close(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(ctx, vrw, sch)
|
||||
require.NoError(t, err)
|
||||
empty, err := types.NewMap(ctx, vrw)
|
||||
require.NoError(t, err)
|
||||
tbl, err := doltdb.NewTable(ctx, vrw, schVal, wr.GetMap(), empty, nil)
|
||||
tbl, err := doltdb.NewTable(ctx, vrw, sch, wr.GetMap(), empty, nil)
|
||||
require.NoError(t, err)
|
||||
tbl, err = editor.RebuildAllIndexes(ctx, tbl, editor.TestEditorOptions(vrw))
|
||||
require.NoError(t, err)
|
||||
@@ -136,12 +133,7 @@ func putTableToWorking(ctx context.Context, dEnv *env.DoltEnv, sch schema.Schema
|
||||
}
|
||||
|
||||
vrw := dEnv.DoltDB.ValueReadWriter()
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(ctx, vrw, sch)
|
||||
if err != nil {
|
||||
return env.ErrMarshallingSchema
|
||||
}
|
||||
|
||||
tbl, err := doltdb.NewTable(ctx, vrw, schVal, rows, indexData, autoVal)
|
||||
tbl, err := doltdb.NewTable(ctx, vrw, sch, rows, indexData, autoVal)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env/actions"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/editor"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/typed/noms"
|
||||
@@ -339,15 +338,11 @@ func createTestTable(dEnv *env.DoltEnv, tableName string, sch schema.Schema, err
|
||||
if err != nil {
|
||||
errhand(err)
|
||||
}
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(ctx, vrw, sch)
|
||||
if err != nil {
|
||||
errhand(err)
|
||||
}
|
||||
empty, err := types.NewMap(ctx, vrw)
|
||||
if err != nil {
|
||||
errhand(err)
|
||||
}
|
||||
tbl, err := doltdb.NewTable(ctx, vrw, schVal, wr.GetMap(), empty, nil)
|
||||
tbl, err := doltdb.NewTable(ctx, vrw, sch, wr.GetMap(), empty, nil)
|
||||
if err != nil {
|
||||
errhand(err)
|
||||
}
|
||||
@@ -381,12 +376,7 @@ func putTableToWorking(ctx context.Context, dEnv *env.DoltEnv, sch schema.Schema
|
||||
}
|
||||
|
||||
vrw := dEnv.DoltDB.ValueReadWriter()
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(ctx, vrw, sch)
|
||||
if err != nil {
|
||||
return env.ErrMarshallingSchema
|
||||
}
|
||||
|
||||
tbl, err := doltdb.NewTable(ctx, vrw, schVal, rows, indexData, autoVal)
|
||||
tbl, err := doltdb.NewTable(ctx, vrw, sch, rows, indexData, autoVal)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -210,23 +210,24 @@ func (merger *Merger) MergeTable(ctx context.Context, tblName string, sess *edit
|
||||
|
||||
if conflicts.Len() > 0 {
|
||||
|
||||
asr, err := ancTbl.GetSchemaRef()
|
||||
ancSch, err := ancTbl.GetSchema(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
sr, err := tbl.GetSchemaRef()
|
||||
sch, err := tbl.GetSchema(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
msr, err := mergeTbl.GetSchemaRef()
|
||||
mergeSch, err := mergeTbl.GetSchema(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
schemas := doltdb.NewConflict(asr, sr, msr)
|
||||
resultTbl, err = resultTbl.SetConflicts(ctx, schemas, conflicts)
|
||||
cs := doltdb.NewConflictSchema(ancSch, sch, mergeSch)
|
||||
|
||||
resultTbl, err = resultTbl.SetConflicts(ctx, cs, conflicts)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/editor"
|
||||
filesys2 "github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
@@ -347,23 +346,20 @@ func setupMergeTest(t *testing.T) (types.ValueReadWriter, *doltdb.Commit, *doltd
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), vrw, sch)
|
||||
require.NoError(t, err)
|
||||
|
||||
emptyMap, err := types.NewMap(context.Background(), vrw)
|
||||
require.NoError(t, err)
|
||||
|
||||
tbl, err := doltdb.NewTable(context.Background(), vrw, schVal, initialRows, emptyMap, nil)
|
||||
tbl, err := doltdb.NewTable(context.Background(), vrw, sch, initialRows, emptyMap, nil)
|
||||
require.NoError(t, err)
|
||||
tbl, err = editor.RebuildAllIndexes(context.Background(), tbl, editor.TestEditorOptions(vrw))
|
||||
require.NoError(t, err)
|
||||
|
||||
updatedTbl, err := doltdb.NewTable(context.Background(), vrw, schVal, updatedRows, emptyMap, nil)
|
||||
updatedTbl, err := doltdb.NewTable(context.Background(), vrw, sch, updatedRows, emptyMap, nil)
|
||||
require.NoError(t, err)
|
||||
updatedTbl, err = editor.RebuildAllIndexes(context.Background(), updatedTbl, editor.TestEditorOptions(vrw))
|
||||
require.NoError(t, err)
|
||||
|
||||
mergeTbl, err := doltdb.NewTable(context.Background(), vrw, schVal, mergeRows, emptyMap, nil)
|
||||
mergeTbl, err := doltdb.NewTable(context.Background(), vrw, sch, mergeRows, emptyMap, nil)
|
||||
require.NoError(t, err)
|
||||
mergeTbl, err = editor.RebuildAllIndexes(context.Background(), mergeTbl, editor.TestEditorOptions(vrw))
|
||||
require.NoError(t, err)
|
||||
@@ -436,17 +432,17 @@ func TestMergeCommits(t *testing.T) {
|
||||
|
||||
tbl, _, err := root.GetTable(context.Background(), tableName)
|
||||
assert.NoError(t, err)
|
||||
schRef, err := tbl.GetSchemaRef()
|
||||
assert.NoError(t, err)
|
||||
targVal, err := schRef.TargetValue(context.Background(), vrw)
|
||||
sch, err := tbl.GetSchema(context.Background())
|
||||
assert.NoError(t, err)
|
||||
emptyMap, err := types.NewMap(context.Background(), vrw)
|
||||
assert.NoError(t, err)
|
||||
expected, err := doltdb.NewTable(context.Background(), vrw, targVal, expectedRows, emptyMap, nil)
|
||||
expected, err := doltdb.NewTable(context.Background(), vrw, sch, expectedRows, emptyMap, nil)
|
||||
assert.NoError(t, err)
|
||||
expected, err = editor.RebuildAllIndexes(context.Background(), expected, editor.TestEditorOptions(vrw))
|
||||
assert.NoError(t, err)
|
||||
expected, err = expected.SetConflicts(context.Background(), doltdb.NewConflict(schRef, schRef, schRef), expectedConflicts)
|
||||
conflictSchema := doltdb.NewConflictSchema(sch, sch, sch)
|
||||
assert.NoError(t, err)
|
||||
expected, err = expected.SetConflicts(context.Background(), conflictSchema, expectedConflicts)
|
||||
assert.NoError(t, err)
|
||||
|
||||
h, err := merged.HashOf()
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/typed/noms"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/set"
|
||||
ndiff "github.com/dolthub/dolt/go/store/diff"
|
||||
@@ -351,16 +350,6 @@ func replayCommitWithNewTag(ctx context.Context, root, parentRoot, rebasedParent
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rebasedSchVal, err := encoding.MarshalSchemaAsNomsValue(ctx, rebasedParentRoot.VRW(), rebasedSch)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rsh, _ := rebasedSchVal.Hash(newRoot.VRW().Format())
|
||||
rshs := rsh.String()
|
||||
fmt.Println(rshs)
|
||||
|
||||
emptyMap, err := types.NewMap(ctx, root.VRW()) // migration predates secondary indexes
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -370,7 +359,7 @@ func replayCommitWithNewTag(ctx context.Context, root, parentRoot, rebasedParent
|
||||
// so we don't need to copy the value here
|
||||
var autoVal types.Value = nil
|
||||
|
||||
rebasedTable, err := doltdb.NewTable(ctx, rebasedParentRoot.VRW(), rebasedSchVal, rebasedRows, emptyMap, autoVal)
|
||||
rebasedTable, err := doltdb.NewTable(ctx, rebasedParentRoot.VRW(), rebasedSch, rebasedRows, emptyMap, autoVal)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/editor"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
@@ -109,18 +108,13 @@ func AddPrimaryKeyToTable(ctx context.Context, table *doltdb.Table, tableName st
|
||||
}
|
||||
|
||||
func insertKeyedData(ctx context.Context, nbf *types.NomsBinFormat, oldTable *doltdb.Table, newSchema schema.Schema, name string, opts editor.Options) (*doltdb.Table, error) {
|
||||
marshalledSchema, err := encoding.MarshalSchemaAsNomsValue(context.Background(), oldTable.ValueReadWriter(), newSchema)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
empty, err := types.NewMap(ctx, oldTable.ValueReadWriter())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create the new Table and rebuild all the indexes
|
||||
newTable, err := doltdb.NewTable(ctx, oldTable.ValueReadWriter(), marshalledSchema, empty, empty, nil)
|
||||
newTable, err := doltdb.NewTable(ctx, oldTable.ValueReadWriter(), newSchema, empty, empty, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/typeinfo"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/editor"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
@@ -111,10 +110,6 @@ func validateModifyColumn(ctx context.Context, tbl *doltdb.Table, existingCol sc
|
||||
// the data is updated.
|
||||
func updateTableWithModifiedColumn(ctx context.Context, tbl *doltdb.Table, oldSch, newSch schema.Schema, oldCol, modifiedCol schema.Column, opts editor.Options) (*doltdb.Table, error) {
|
||||
vrw := tbl.ValueReadWriter()
|
||||
newSchemaVal, err := encoding.MarshalSchemaAsNomsValue(ctx, vrw, newSch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rowData, err := tbl.GetRowData(ctx)
|
||||
if err != nil {
|
||||
@@ -159,7 +154,7 @@ func updateTableWithModifiedColumn(ctx context.Context, tbl *doltdb.Table, oldSc
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
updatedTable, err := doltdb.NewTable(ctx, vrw, newSchemaVal, rowData, indexData, autoVal)
|
||||
updatedTable, err := doltdb.NewTable(ctx, vrw, newSch, rowData, indexData, autoVal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -334,15 +334,12 @@ func newRowItrForTableAtCommit(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
schRef, err := tbl.GetSchemaRef()
|
||||
schHash := schRef.TargetHash()
|
||||
|
||||
tblSch, err := tbl.GetSchema(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tblSch, err := doltdb.RefToSchema(ctx, root.VRW(), schRef)
|
||||
|
||||
schHash, err := tbl.GetSchemaHash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ type tableInConflict struct {
|
||||
name string
|
||||
size uint64
|
||||
done bool
|
||||
schemas doltdb.Conflict
|
||||
schemas doltdb.ConflictSchema
|
||||
//cnfItr types.MapIterator
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/alterschema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/typeinfo"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlutil"
|
||||
@@ -550,16 +549,12 @@ func (t *WritableDoltTable) Truncate(ctx *sql.Context) (int, error) {
|
||||
return 0, err
|
||||
}
|
||||
numOfRows := int(rowData.Len())
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(ctx, table.ValueReadWriter(), t.sch)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
empty, err := types.NewMap(ctx, table.ValueReadWriter())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
// truncate table resets auto-increment value
|
||||
newTable, err := doltdb.NewTable(ctx, table.ValueReadWriter(), schVal, empty, empty, nil)
|
||||
newTable, err := doltdb.NewTable(ctx, table.ValueReadWriter(), t.sch, empty, empty, nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/typeinfo"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/untyped"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
@@ -534,16 +533,13 @@ func UpdateTables(t *testing.T, ctx context.Context, root *doltdb.RootValue, tbl
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(ctx, root.VRW(), sch)
|
||||
require.NoError(t, err)
|
||||
|
||||
indexData, err := types.NewMap(ctx, root.VRW())
|
||||
require.NoError(t, err)
|
||||
if tbl != nil {
|
||||
indexData, err = tbl.GetIndexData(ctx)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
tbl, err = doltdb.NewTable(ctx, root.VRW(), schVal, rowData, indexData, nil)
|
||||
tbl, err = doltdb.NewTable(ctx, root.VRW(), sch, rowData, indexData, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
root, err = root.PutTable(ctx, tblName, tbl)
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
@@ -409,10 +408,8 @@ func TestIndexRebuildingWithZeroIndexes(t *testing.T) {
|
||||
_, err = tSchema.Indexes().RemoveIndex(testSchemaIndexAge)
|
||||
require.NoError(t, err)
|
||||
rowData, _ := createTestRowData(t, db, tSchema)
|
||||
schemaVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), db, tSchema)
|
||||
require.NoError(t, err)
|
||||
|
||||
originalTable, err := createTableWithoutIndexRebuilding(context.Background(), db, schemaVal, rowData)
|
||||
originalTable, err := createTableWithoutIndexRebuilding(context.Background(), db, tSchema, rowData)
|
||||
require.NoError(t, err)
|
||||
|
||||
opts := TestEditorOptions(db)
|
||||
@@ -434,8 +431,6 @@ func TestIndexRebuildingWithOneIndex(t *testing.T) {
|
||||
require.NotNil(t, index)
|
||||
indexSch := index.Schema()
|
||||
rowData, rows := createTestRowData(t, db, tSchema)
|
||||
schemaVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), db, tSchema)
|
||||
require.NoError(t, err)
|
||||
|
||||
indexExpectedRows := make([]row.Row, len(rows))
|
||||
for i, r := range rows {
|
||||
@@ -449,7 +444,7 @@ func TestIndexRebuildingWithOneIndex(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
originalTable, err := createTableWithoutIndexRebuilding(context.Background(), db, schemaVal, rowData)
|
||||
originalTable, err := createTableWithoutIndexRebuilding(context.Background(), db, tSchema, rowData)
|
||||
require.NoError(t, err)
|
||||
|
||||
var indexRows []row.Row
|
||||
@@ -494,9 +489,7 @@ func TestIndexRebuildingWithTwoIndexes(t *testing.T) {
|
||||
rowData, rows := createTestRowData(t, db, tSchema)
|
||||
indexNameExpectedRows, indexAgeExpectedRows := rowsToIndexRows(t, rows, indexName, indexAge)
|
||||
|
||||
schemaVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), db, tSchema)
|
||||
require.NoError(t, err)
|
||||
originalTable, err := createTableWithoutIndexRebuilding(context.Background(), db, schemaVal, rowData)
|
||||
originalTable, err := createTableWithoutIndexRebuilding(context.Background(), db, tSchema, rowData)
|
||||
require.NoError(t, err)
|
||||
|
||||
opts := TestEditorOptions(db)
|
||||
@@ -619,9 +612,7 @@ func TestIndexRebuildingUniqueSuccessOneCol(t *testing.T) {
|
||||
row.TaggedValues{1: types.Int(2), 2: types.Int(2), 3: types.Int(2)},
|
||||
row.TaggedValues{1: types.Int(3), 2: types.Int(3), 3: types.Int(3)},
|
||||
)
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), db, sch)
|
||||
require.NoError(t, err)
|
||||
originalTable, err := createTableWithoutIndexRebuilding(context.Background(), db, schVal, rowData)
|
||||
originalTable, err := createTableWithoutIndexRebuilding(context.Background(), db, sch, rowData)
|
||||
require.NoError(t, err)
|
||||
|
||||
index, err := sch.Indexes().AddIndexByColTags("idx_v1", []uint64{2}, schema.IndexProperties{IsUnique: true, Comment: ""})
|
||||
@@ -651,9 +642,7 @@ func TestIndexRebuildingUniqueSuccessTwoCol(t *testing.T) {
|
||||
row.TaggedValues{1: types.Int(2), 2: types.Int(1), 3: types.Int(2)},
|
||||
row.TaggedValues{1: types.Int(3), 2: types.Int(2), 3: types.Int(2)},
|
||||
)
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), db, sch)
|
||||
require.NoError(t, err)
|
||||
originalTable, err := createTableWithoutIndexRebuilding(context.Background(), db, schVal, rowData)
|
||||
originalTable, err := createTableWithoutIndexRebuilding(context.Background(), db, sch, rowData)
|
||||
require.NoError(t, err)
|
||||
|
||||
index, err := sch.Indexes().AddIndexByColTags("idx_v1", []uint64{2, 3}, schema.IndexProperties{IsUnique: true, Comment: ""})
|
||||
@@ -683,9 +672,7 @@ func TestIndexRebuildingUniqueFailOneCol(t *testing.T) {
|
||||
row.TaggedValues{1: types.Int(2), 2: types.Int(2), 3: types.Int(2)},
|
||||
row.TaggedValues{1: types.Int(3), 2: types.Int(2), 3: types.Int(3)},
|
||||
)
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), db, sch)
|
||||
require.NoError(t, err)
|
||||
originalTable, err := createTableWithoutIndexRebuilding(context.Background(), db, schVal, rowData)
|
||||
originalTable, err := createTableWithoutIndexRebuilding(context.Background(), db, sch, rowData)
|
||||
require.NoError(t, err)
|
||||
|
||||
index, err := sch.Indexes().AddIndexByColTags("idx_v1", []uint64{2}, schema.IndexProperties{IsUnique: true, Comment: ""})
|
||||
@@ -716,9 +703,7 @@ func TestIndexRebuildingUniqueFailTwoCol(t *testing.T) {
|
||||
row.TaggedValues{1: types.Int(3), 2: types.Int(2), 3: types.Int(2)},
|
||||
row.TaggedValues{1: types.Int(4), 2: types.Int(1), 3: types.Int(2)},
|
||||
)
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), db, sch)
|
||||
require.NoError(t, err)
|
||||
originalTable, err := createTableWithoutIndexRebuilding(context.Background(), db, schVal, rowData)
|
||||
originalTable, err := createTableWithoutIndexRebuilding(context.Background(), db, sch, rowData)
|
||||
require.NoError(t, err)
|
||||
|
||||
index, err := sch.Indexes().AddIndexByColTags("idx_v1", []uint64{2, 3}, schema.IndexProperties{IsUnique: true, Comment: ""})
|
||||
@@ -852,9 +837,9 @@ func createTestSchema(t *testing.T) schema.Schema {
|
||||
return sch
|
||||
}
|
||||
|
||||
func createTableWithoutIndexRebuilding(ctx context.Context, vrw types.ValueReadWriter, schemaVal types.Value, rowData types.Map) (*doltdb.Table, error) {
|
||||
func createTableWithoutIndexRebuilding(ctx context.Context, vrw types.ValueReadWriter, sch schema.Schema, rowData types.Map) (*doltdb.Table, error) {
|
||||
empty, _ := types.NewMap(ctx, vrw)
|
||||
return doltdb.NewTable(ctx, vrw, schemaVal, rowData, empty, nil)
|
||||
return doltdb.NewTable(ctx, vrw, sch, rowData, empty, nil)
|
||||
}
|
||||
|
||||
func rowsToIndexRows(t *testing.T, rows []row.Row, indexName schema.Index, indexAge schema.Index) (indexNameExpectedRows []row.Row, indexAgeExpectedRows []row.Row) {
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
@@ -41,11 +40,9 @@ func TestKeylessTableEditorConcurrency(t *testing.T) {
|
||||
schema.NewColumn("v2", 2, types.IntKind, false))
|
||||
tableSch, err := schema.SchemaFromCols(colColl)
|
||||
require.NoError(t, err)
|
||||
tableSchVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), db, tableSch)
|
||||
require.NoError(t, err)
|
||||
emptyMap, err := types.NewMap(context.Background(), db)
|
||||
require.NoError(t, err)
|
||||
table, err := doltdb.NewTable(context.Background(), db, tableSchVal, emptyMap, emptyMap, nil)
|
||||
table, err := doltdb.NewTable(context.Background(), db, tableSch, emptyMap, emptyMap, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
opts := TestEditorOptions(db)
|
||||
@@ -151,11 +148,9 @@ func TestKeylessTableEditorConcurrencyPostInsert(t *testing.T) {
|
||||
schema.NewColumn("v2", 2, types.IntKind, false))
|
||||
tableSch, err := schema.SchemaFromCols(colColl)
|
||||
require.NoError(t, err)
|
||||
tableSchVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), db, tableSch)
|
||||
require.NoError(t, err)
|
||||
emptyMap, err := types.NewMap(context.Background(), db)
|
||||
require.NoError(t, err)
|
||||
table, err := doltdb.NewTable(context.Background(), db, tableSchVal, emptyMap, emptyMap, nil)
|
||||
table, err := doltdb.NewTable(context.Background(), db, tableSch, emptyMap, emptyMap, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
opts := TestEditorOptions(db)
|
||||
@@ -260,11 +255,9 @@ func TestKeylessTableEditorWriteAfterFlush(t *testing.T) {
|
||||
schema.NewColumn("v2", 2, types.IntKind, false))
|
||||
tableSch, err := schema.SchemaFromCols(colColl)
|
||||
require.NoError(t, err)
|
||||
tableSchVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), db, tableSch)
|
||||
require.NoError(t, err)
|
||||
emptyMap, err := types.NewMap(context.Background(), db)
|
||||
require.NoError(t, err)
|
||||
table, err := doltdb.NewTable(context.Background(), db, tableSchVal, emptyMap, emptyMap, nil)
|
||||
table, err := doltdb.NewTable(context.Background(), db, tableSch, emptyMap, emptyMap, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
opts := TestEditorOptions(db)
|
||||
@@ -343,11 +336,9 @@ func TestKeylessTableEditorDuplicateKeyHandling(t *testing.T) {
|
||||
schema.NewColumn("v2", 2, types.IntKind, false))
|
||||
tableSch, err := schema.SchemaFromCols(colColl)
|
||||
require.NoError(t, err)
|
||||
tableSchVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), db, tableSch)
|
||||
require.NoError(t, err)
|
||||
emptyMap, err := types.NewMap(context.Background(), db)
|
||||
require.NoError(t, err)
|
||||
table, err := doltdb.NewTable(context.Background(), db, tableSchVal, emptyMap, emptyMap, nil)
|
||||
table, err := doltdb.NewTable(context.Background(), db, tableSch, emptyMap, emptyMap, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
opts := TestEditorOptions(db)
|
||||
@@ -444,11 +435,9 @@ func TestKeylessTableEditorMultipleIndexErrorHandling(t *testing.T) {
|
||||
IsUnique: false,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
tableSchVal, err := encoding.MarshalSchemaAsNomsValue(ctx, db, tableSch)
|
||||
require.NoError(t, err)
|
||||
emptyMap, err := types.NewMap(ctx, db)
|
||||
require.NoError(t, err)
|
||||
table, err := doltdb.NewTable(ctx, db, tableSchVal, emptyMap, emptyMap, nil)
|
||||
table, err := doltdb.NewTable(ctx, db, tableSch, emptyMap, emptyMap, nil)
|
||||
require.NoError(t, err)
|
||||
table, err = RebuildAllIndexes(ctx, table, opts)
|
||||
require.NoError(t, err)
|
||||
@@ -599,15 +588,9 @@ func TestKeylessTableEditorIndexCardinality(t *testing.T) {
|
||||
IsUnique: false,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
//idxv2, err := tableSch.Indexes().AddIndexByColNames("idx_v2", []string{"v2"}, schema.IndexProperties{
|
||||
// IsUnique: false,
|
||||
//})
|
||||
//require.NoError(t, err)
|
||||
tableSchVal, err := encoding.MarshalSchemaAsNomsValue(ctx, db, tableSch)
|
||||
require.NoError(t, err)
|
||||
emptyMap, err := types.NewMap(ctx, db)
|
||||
require.NoError(t, err)
|
||||
table, err := doltdb.NewTable(ctx, db, tableSchVal, emptyMap, emptyMap, nil)
|
||||
table, err := doltdb.NewTable(ctx, db, tableSch, emptyMap, emptyMap, nil)
|
||||
require.NoError(t, err)
|
||||
table, err = RebuildAllIndexes(ctx, table, opts)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
@@ -52,11 +51,9 @@ func TestTableEditorConcurrency(t *testing.T) {
|
||||
schema.NewColumn("v2", 2, types.IntKind, false))
|
||||
tableSch, err := schema.SchemaFromCols(colColl)
|
||||
require.NoError(t, err)
|
||||
tableSchVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), db, tableSch)
|
||||
require.NoError(t, err)
|
||||
emptyMap, err := types.NewMap(context.Background(), db)
|
||||
require.NoError(t, err)
|
||||
table, err := doltdb.NewTable(context.Background(), db, tableSchVal, emptyMap, emptyMap, nil)
|
||||
table, err := doltdb.NewTable(context.Background(), db, tableSch, emptyMap, emptyMap, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
for i := 0; i < tableEditorConcurrencyIterations; i++ {
|
||||
@@ -149,11 +146,9 @@ func TestTableEditorConcurrencyPostInsert(t *testing.T) {
|
||||
schema.NewColumn("v2", 2, types.IntKind, false))
|
||||
tableSch, err := schema.SchemaFromCols(colColl)
|
||||
require.NoError(t, err)
|
||||
tableSchVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), db, tableSch)
|
||||
require.NoError(t, err)
|
||||
emptyMap, err := types.NewMap(context.Background(), db)
|
||||
require.NoError(t, err)
|
||||
table, err := doltdb.NewTable(context.Background(), db, tableSchVal, emptyMap, emptyMap, nil)
|
||||
table, err := doltdb.NewTable(context.Background(), db, tableSch, emptyMap, emptyMap, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
tableEditor, err := newPkTableEditor(context.Background(), table, tableSch, tableName, opts)
|
||||
@@ -244,11 +239,9 @@ func TestTableEditorWriteAfterFlush(t *testing.T) {
|
||||
schema.NewColumn("v2", 2, types.IntKind, false))
|
||||
tableSch, err := schema.SchemaFromCols(colColl)
|
||||
require.NoError(t, err)
|
||||
tableSchVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), db, tableSch)
|
||||
require.NoError(t, err)
|
||||
emptyMap, err := types.NewMap(context.Background(), db)
|
||||
require.NoError(t, err)
|
||||
table, err := doltdb.NewTable(context.Background(), db, tableSchVal, emptyMap, emptyMap, nil)
|
||||
table, err := doltdb.NewTable(context.Background(), db, tableSch, emptyMap, emptyMap, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
tableEditor, err := newPkTableEditor(context.Background(), table, tableSch, tableName, opts)
|
||||
@@ -316,11 +309,9 @@ func TestTableEditorDuplicateKeyHandling(t *testing.T) {
|
||||
schema.NewColumn("v2", 2, types.IntKind, false))
|
||||
tableSch, err := schema.SchemaFromCols(colColl)
|
||||
require.NoError(t, err)
|
||||
tableSchVal, err := encoding.MarshalSchemaAsNomsValue(context.Background(), db, tableSch)
|
||||
require.NoError(t, err)
|
||||
emptyMap, err := types.NewMap(context.Background(), db)
|
||||
require.NoError(t, err)
|
||||
table, err := doltdb.NewTable(context.Background(), db, tableSchVal, emptyMap, emptyMap, nil)
|
||||
table, err := doltdb.NewTable(context.Background(), db, tableSch, emptyMap, emptyMap, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
tableEditor, err := newPkTableEditor(context.Background(), table, tableSch, tableName, opts)
|
||||
@@ -405,11 +396,9 @@ func TestTableEditorMultipleIndexErrorHandling(t *testing.T) {
|
||||
IsUnique: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
tableSchVal, err := encoding.MarshalSchemaAsNomsValue(ctx, db, tableSch)
|
||||
require.NoError(t, err)
|
||||
emptyMap, err := types.NewMap(ctx, db)
|
||||
require.NoError(t, err)
|
||||
table, err := doltdb.NewTable(ctx, db, tableSchVal, emptyMap, emptyMap, nil)
|
||||
table, err := doltdb.NewTable(ctx, db, tableSch, emptyMap, emptyMap, nil)
|
||||
require.NoError(t, err)
|
||||
table, err = RebuildAllIndexes(ctx, table, opts)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
dtu "github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
@@ -116,8 +115,6 @@ func TestKeylessTableReader(t *testing.T) {
|
||||
dEnv := dtu.CreateTestEnv()
|
||||
ctx := context.Background()
|
||||
vrw := dEnv.DoltDB.ValueReadWriter()
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(ctx, vrw, sch)
|
||||
require.NoError(t, err)
|
||||
empty := dtu.MustMap(t, vrw)
|
||||
|
||||
compareRows := func(t *testing.T, expected []sql.Row, rdr table.SqlTableReader) {
|
||||
@@ -134,7 +131,7 @@ func TestKeylessTableReader(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
rowMap := makeBag(vrw, sch, test.rows...)
|
||||
tbl, err := doltdb.NewTable(ctx, vrw, schVal, rowMap, empty, nil)
|
||||
tbl, err := doltdb.NewTable(ctx, vrw, sch, rowMap, empty, nil)
|
||||
require.NoError(t, err)
|
||||
rdr, err := table.NewTableReader(ctx, tbl)
|
||||
require.NoError(t, err)
|
||||
@@ -142,7 +139,7 @@ func TestKeylessTableReader(t *testing.T) {
|
||||
})
|
||||
t.Run(test.name+"_buffered", func(t *testing.T) {
|
||||
rowMap := makeBag(vrw, sch, test.rows...)
|
||||
tbl, err := doltdb.NewTable(ctx, vrw, schVal, rowMap, empty, nil)
|
||||
tbl, err := doltdb.NewTable(ctx, vrw, sch, rowMap, empty, nil)
|
||||
require.NoError(t, err)
|
||||
rdr, err := table.NewBufferedTableReader(ctx, tbl)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlfmt"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
@@ -80,15 +79,13 @@ func TestEndToEnd(t *testing.T) {
|
||||
root, err := dEnv.WorkingRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
schVal, err := encoding.MarshalSchemaAsNomsValue(ctx, root.VRW(), tt.sch)
|
||||
require.NoError(t, err)
|
||||
empty, err := types.NewMap(ctx, root.VRW())
|
||||
require.NoError(t, err)
|
||||
idxRef, err := types.NewRef(empty, root.VRW().Format())
|
||||
require.NoError(t, err)
|
||||
idxMap, err := types.NewMap(ctx, root.VRW(), types.String(dtestutils.IndexName), idxRef)
|
||||
require.NoError(t, err)
|
||||
tbl, err := doltdb.NewTable(ctx, root.VRW(), schVal, empty, idxMap, nil)
|
||||
tbl, err := doltdb.NewTable(ctx, root.VRW(), tt.sch, empty, idxMap, nil)
|
||||
require.NoError(t, err)
|
||||
root, err = root.PutTable(ctx, tableName, tbl)
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user