Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Nov 19, 2024
1 parent 27893cf commit 8122f51
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
7 changes: 2 additions & 5 deletions internal/db/fetcher/versioned.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,15 @@ func (vf *VersionedFetcher) Start(ctx context.Context, spans ...core.Span) error
// VersionedFetcher only ever recieves a headstore key
//nolint:forcetypeassert
prefix := spans[0].Start.(keys.HeadstoreDocKey)
dk := prefix.DocID
cid := prefix.Cid
if dk == "" {
return client.NewErrUninitializeProperty("Spans", "DocID")
} else if !cid.Defined() {
if !cid.Defined() {
return client.NewErrUninitializeProperty("Spans", "CID")
}

vf.ctx = ctx
vf.dsKey = keys.DataStoreKey{
CollectionRootID: vf.col.Description().RootID,
DocID: dk,
DocID: prefix.DocID,
}

if err := vf.seekTo(cid); err != nil {
Expand Down
13 changes: 9 additions & 4 deletions internal/planner/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,24 @@ func (n *selectNode) initSource() ([]aggregateNode, error) {
origScan.filter = n.filter
n.filter = nil

// If we have both a DocID and a CID, then we need to run
// a TimeTravel (History-Traversing Versioned) query, which means
// we need to propagate the values to the underlying VersionedFetcher
// If we have a CID, then we need to run a TimeTravel (History-Traversing Versioned)
// query, which means we need to propagate the values to the underlying VersionedFetcher
if n.selectReq.Cid.HasValue() {
c, err := cid.Decode(n.selectReq.Cid.Value())
if err != nil {
return nil, err
}

var docID string
if len(n.selectReq.DocIDs.Value()) > 0 {
docID = n.selectReq.DocIDs.Value()[0]
}

origScan.Spans(
[]core.Span{
core.NewSpan(
keys.HeadstoreDocKey{
DocID: n.selectReq.DocIDs.Value()[0],
DocID: docID,
Cid: c,
},
keys.HeadstoreDocKey{},
Expand Down
25 changes: 6 additions & 19 deletions tests/integration/query/simple/with_cid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ package simple
import (
"testing"

"github.com/sourcenetwork/immutable"
"github.com/stretchr/testify/require"

"github.com/sourcenetwork/defradb/tests/change_detector"
testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

Expand Down Expand Up @@ -44,20 +40,8 @@ func TestQuerySimpleWithInvalidCid(t *testing.T) {
executeTestCase(t, test)
}

// This test documents a bug:
// https://github.com/sourcenetwork/defradb/issues/3214
func TestQuerySimpleWithCid(t *testing.T) {
if change_detector.Enabled {
t.Skipf("Change detector does not support requiring panics")
}

test := testUtils.TestCase{
SupportedClientTypes: immutable.Some(
[]testUtils.ClientType{
// The CLI/Http clients don't panic in this context
testUtils.GoClientType,
},
),
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
Expand All @@ -71,6 +55,11 @@ func TestQuerySimpleWithCid(t *testing.T) {
"name": "John"
}`,
},
testUtils.CreateDoc{
Doc: `{
"name": "Fred"
}`,
},
testUtils.Request{
Request: `query {
Users (
Expand All @@ -90,7 +79,5 @@ func TestQuerySimpleWithCid(t *testing.T) {
},
}

require.Panics(t, func() {
testUtils.ExecuteTestCase(t, test)
})
testUtils.ExecuteTestCase(t, test)
}

0 comments on commit 8122f51

Please sign in to comment.