Made noms show understand internal prolly nodes, resolve needs work

This commit is contained in:
Zach Musgrave
2022-04-13 09:53:35 -07:00
parent 3ebf939c78
commit 9348de8d86
9 changed files with 60 additions and 32 deletions
+3
View File
@@ -216,6 +216,9 @@ func (t *Table) GetSchemaHash(ctx context.Context) (hash.Hash, error) {
}
// UpdateSchema updates the table with the schema given and returns the updated table. The original table is unchanged.
// This method only updates the schema of a table; the row data is unchanged. Schema alterations that require rebuilding
// the table (e.g. adding a column in the middle, adding a new non-null column, adding a column in the middle of a
// schema) must account for these changes separately.
func (t *Table) UpdateSchema(ctx context.Context, sch schema.Schema) (*Table, error) {
table, err := t.table.SetSchema(ctx, sch)
if err != nil {
+11 -1
View File
@@ -85,10 +85,20 @@ func addColumnToTable(
return nil, err
}
return tbl.UpdateSchema(ctx, newSchema)
// if types.IsFormat_DOLT_1(t.nbf) {
// return nil
// }
newTable, err := tbl.UpdateSchema(ctx, newSchema)
if err != nil {
return nil, err
}
return newTable, nil
}
// addColumnToSchema creates a new schema with a column as specified by the params.
// TODO: make this a schema operation, not in this package
func addColumnToSchema(
sch schema.Schema,
tag uint64,
-5
View File
@@ -877,12 +877,7 @@ var _ doltAlterableTableInterface = (*AlterableDoltTable)(nil)
// AddColumn implements sql.AlterableTable
func (t *AlterableDoltTable) AddColumn(ctx *sql.Context, column *sql.Column, order *sql.ColumnOrder) error {
if types.IsFormat_DOLT_1(t.nbf) {
return nil
}
root, err := t.getRoot(ctx)
if err != nil {
return err
}
+21 -10
View File
@@ -123,8 +123,8 @@ func outputEncodedValue(ctx context.Context, w io.Writer, value types.Value) err
w.Write([]byte("["))
node := prolly.NodeFromValue(value)
for i := 0; i < node.Size(); i++ {
k, v := node.GetKey(i), node.GetValue(i)
kt, vt := val.Tuple(k), val.Tuple(v)
k := node.GetKey(i)
kt := val.Tuple(k)
w.Write([]byte("\n { key: "))
for j := 0; j < kt.Count(); j++ {
@@ -134,15 +134,26 @@ func outputEncodedValue(ctx context.Context, w io.Writer, value types.Value) err
w.Write([]byte(hexStr(kt.GetField(j))))
}
w.Write([]byte(" value: "))
for j := 0; j < vt.Count(); j++ {
if j > 0 {
w.Write([]byte(", "))
}
w.Write([]byte(hexStr(vt.GetField(j))))
}
if node.LeafNode() {
v := node.GetValue(i)
vt := val.Tuple(v)
w.Write([]byte(" }"))
w.Write([]byte(" value: "))
for j := 0; j < vt.Count(); j++ {
if j > 0 {
w.Write([]byte(", "))
}
w.Write([]byte(hexStr(vt.GetField(j))))
}
w.Write([]byte(" }"))
} else {
ref := node.GetRef(i)
w.Write([]byte(" ref: #"))
w.Write([]byte(ref.String()))
w.Write([]byte(" }"))
}
}
w.Write([]byte("\n]\n"))
+12 -6
View File
@@ -73,24 +73,28 @@ func (nd Node) hashOf() hash.Hash {
return hash.Of(nd.bytes())
}
// GetKey returns the |ith| key of this node
func (nd Node) GetKey(i int) nodeItem {
return nd.keys.GetSlice(i)
}
// GetValue returns the |ith| value of this node. Only valid for leaf nodes.
func (nd Node) GetValue(i int) nodeItem {
if nd.leafNode() {
if nd.LeafNode() {
return nd.values.GetSlice(i)
} else {
r := nd.getRef(i)
r := nd.GetRef(i)
return r[:]
}
}
// Size returns the number of keys in this node
func (nd Node) Size() int {
return nd.keys.Len()
}
func (nd Node) getRef(i int) hash.Hash {
// GetRef returns the |ith| ref in this node. Only valid for internal nodes.
func (nd Node) GetRef(i int) hash.Hash {
refs := nd.buf.RefArrayBytes()
start, stop := i*refSize, (i+1)*refSize
return hash.New(refs[start:stop])
@@ -105,12 +109,14 @@ func (nd Node) getSubtreeCounts() subtreeCounts {
return readSubtreeCounts(int(nd.count), buf)
}
func (nd Node) level() int {
// Level returns the tree level for this node
func (nd Node) Level() int {
return int(nd.buf.TreeLevel())
}
func (nd Node) leafNode() bool {
return nd.level() == 0
// LeafNode returns whether this node is a leaf
func (nd Node) LeafNode() bool {
return nd.Level() == 0
}
func (nd Node) empty() bool {
+6 -3
View File
@@ -23,6 +23,7 @@ package prolly
import (
"context"
"fmt"
"math"
"sort"
@@ -106,7 +107,7 @@ func newCursorAtOrdinal(ctx context.Context, nrw NodeStore, nd Node, ord uint64)
distance := int64(ord)
return newCursorFromSearchFn(ctx, nrw, nd, func(nd Node) (idx int) {
if nd.leafNode() {
if nd.LeafNode() {
return int(distance)
}
@@ -215,7 +216,7 @@ func (cur *nodeCursor) currentValue() nodeItem {
}
func (cur *nodeCursor) currentRef() hash.Hash {
return cur.nd.getRef(cur.idx)
return cur.nd.GetRef(cur.idx)
}
func (cur *nodeCursor) firstKey() nodeItem {
@@ -260,7 +261,7 @@ func (cur *nodeCursor) isLeaf() bool {
}
func (cur *nodeCursor) level() uint64 {
return uint64(cur.nd.level())
return uint64(cur.nd.Level())
}
func (cur *nodeCursor) seek(ctx context.Context, item nodeItem, cb compareFn) (err error) {
@@ -458,6 +459,8 @@ func compareCursors(left, right *nodeCursor) (diff int) {
func fetchChild(ctx context.Context, ns NodeStore, ref hash.Hash) (Node, error) {
// todo(andy) handle nil Node, dangling ref
h := ref.String()
fmt.Println(h)
return ns.Read(ctx, ref)
}
+2 -2
View File
@@ -39,7 +39,7 @@ func TestRoundTripInts(t *testing.T) {
require.True(t, sumTupleSize(keys)+sumTupleSize(values) < maxVectorOffset)
nd := newTupleLeafNode(keys, values)
assert.True(t, nd.leafNode())
assert.True(t, nd.LeafNode())
assert.Equal(t, len(keys), int(nd.count))
for i := range keys {
assert.Equal(t, keys[i], val.Tuple(nd.GetKey(i)))
@@ -53,7 +53,7 @@ func TestRoundTripNodeItems(t *testing.T) {
require.True(t, sumSize(keys)+sumSize(values) < maxVectorOffset)
nd := newLeafNode(keys, values)
assert.True(t, nd.leafNode())
assert.True(t, nd.LeafNode())
assert.Equal(t, len(keys), int(nd.count))
for i := range keys {
assert.Equal(t, keys[i], nd.GetKey(i))
+2 -2
View File
@@ -402,11 +402,11 @@ func (tc *treeChunker) Done(ctx context.Context) (Node, error) {
return Node{}, err
}
if child.leafNode() || child.count > 1 {
if child.LeafNode() || child.count > 1 {
return child, nil
}
mt = child.getRef(0)
mt = child.GetRef(0)
}
}
+3 -3
View File
@@ -32,7 +32,7 @@ func roundTripTreeItems(t *testing.T) {
root, items, ns := randomTree(t, 1000)
assert.NotNil(t, root)
assert.True(t, root.count > 0)
assert.True(t, root.level() > 0)
assert.True(t, root.Level() > 0)
//assert.Equal(t, uint64(1000), root.cumulativeCount())
assert.Equal(t, countTree(t, ns, root), 1000)
assert.Equal(t, root.treeCount()*2, 1000)
@@ -41,7 +41,7 @@ func roundTripTreeItems(t *testing.T) {
root, items, ns = randomTree(t, 10_000)
assert.NotNil(t, root)
assert.True(t, root.count > 0)
assert.True(t, root.level() > 0)
assert.True(t, root.Level() > 0)
//assert.Equal(t, uint64(10_000), root.cumulativeCount())
assert.Equal(t, countTree(t, ns, root), 10_000)
assert.Equal(t, root.treeCount()*2, 10_000)
@@ -50,7 +50,7 @@ func roundTripTreeItems(t *testing.T) {
root, items, ns = randomTree(t, 100_000)
assert.NotNil(t, root)
assert.True(t, root.count > 0)
assert.True(t, root.level() > 0)
assert.True(t, root.Level() > 0)
//assert.Equal(t, uint64(100_000), root.cumulativeCount())
assert.Equal(t, countTree(t, ns, root), 100_000)
assert.Equal(t, root.treeCount()*2, 100_000)