Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vector index support to git show / noms show #8606

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions go/store/types/serial_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,17 @@ func (sm SerialMessage) HumanReadableStringAtIndentationLevel(level int) string

_ = OutputProllyNodeBytes(ret, serial.Message(sm))

// deleting everything from a vector index turns it into a regular index?
level -= 1
printWithIndendationLevel(level, ret, "}")
return ret.String()
case serial.VectorIndexNodeFileID:
ret := &strings.Builder{}
printWithIndendationLevel(level, ret, "Vector Index {\n")
level++

_ = OutputVectorIndexNodeBytes(ret, serial.Message(sm))

level -= 1
printWithIndendationLevel(level, ret, "}")
return ret.String()
Expand Down Expand Up @@ -493,6 +504,66 @@ func OutputProllyNodeBytes(w io.Writer, msg serial.Message) error {
return nil
}

func OutputVectorIndexNodeBytes(w io.Writer, msg serial.Message) error {
fileId, keys, values, treeLevel, count, err := message.UnpackFields(msg)
if fileId != serial.VectorIndexNodeFileID {
return fmt.Errorf("unexpected file ID, expected %s, got %s", serial.VectorIndexNodeFileID, fileId)
}
if err != nil {
return err
}
isLeaf := treeLevel == 0

for i := 0; i < int(count); i++ {
k := keys.GetItem(i, msg)
kt := val.Tuple(k)

w.Write([]byte("\n { key: "))
// The first key of a vector index is always a vector, which right now is JSON and thus addressable.
// This may not always be true in the future.

for j := 0; j < kt.Count(); j++ {
if j == 0 {
ref := hash.New(kt.GetField(0))

w.Write([]byte(" #"))
w.Write([]byte(ref.String()))
continue
}
if j > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a continue in the block above, so I don't think you need this check

w.Write([]byte(", "))
}

w.Write([]byte(hex.EncodeToString(kt.GetField(j))))
}

if isLeaf {
v := values.GetItem(i, msg)
vt := val.Tuple(v)

w.Write([]byte(" value: "))
for j := 0; j < vt.Count(); j++ {
if j > 0 {
w.Write([]byte(", "))
}
field := vt.GetField(j)
w.Write([]byte(hex.EncodeToString(field)))
}

w.Write([]byte(" }"))
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use a continue above instead of an else, but not a big deal

ref := hash.New(values.GetItem(i, msg))

w.Write([]byte(" ref: #"))
w.Write([]byte(ref.String()))
w.Write([]byte(" }"))
}
}

w.Write([]byte("\n"))
return nil
}

func (sm SerialMessage) Less(ctx context.Context, nbf *NomsBinFormat, other LesserValuable) (bool, error) {
if v2, ok := other.(SerialMessage); ok {
return bytes.Compare(sm, v2) == -1, nil
Expand Down
Loading