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

fix: Return empty array if no values found #223

Merged
merged 3 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
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
26 changes: 18 additions & 8 deletions db/tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,16 @@ func ExecuteQueryTestCase(t *testing.T, schema string, collectionNames []string,

// Create the transactions before executing and queries
transactions := make([]core.Txn, 0, len(test.TransactionalQueries))
for _, tq := range test.TransactionalQueries {
erroredQueries := make([]bool, len(test.TransactionalQueries))
for i, tq := range test.TransactionalQueries {
if len(transactions) < tq.TransactionId {
continue
}

txn, err := db.NewTxn(ctx, false)
if err != nil {
if assertError(t, test.Description, err, tq.ExpectedError) {
return
erroredQueries[i] = true
}
}
defer txn.Discard(ctx)
Expand All @@ -266,28 +267,34 @@ func ExecuteQueryTestCase(t *testing.T, schema string, collectionNames []string,
transactions[tq.TransactionId] = txn
}

for _, tq := range test.TransactionalQueries {
for i, tq := range test.TransactionalQueries {
if erroredQueries[i] {
continue
}
result := db.ExecTransactionalQuery(ctx, tq.Query, transactions[tq.TransactionId])
if assertQueryResults(t, test.Description, result, tq.Results, tq.ExpectedError) {
return
erroredQueries[i] = true
}
}

txnIndexesCommited := map[int]struct{}{}
for _, tq := range test.TransactionalQueries {
for i, tq := range test.TransactionalQueries {
if erroredQueries[i] {
continue
}
if _, alreadyCommited := txnIndexesCommited[tq.TransactionId]; alreadyCommited {
continue
}
txnIndexesCommited[tq.TransactionId] = struct{}{}

err := transactions[tq.TransactionId].Commit(ctx)
if assertError(t, test.Description, err, tq.ExpectedError) {
return
erroredQueries[i] = true
}
}

for _, tq := range test.TransactionalQueries {
if tq.ExpectedError != "" {
for i, tq := range test.TransactionalQueries {
if tq.ExpectedError != "" && !erroredQueries[i] {
assert.Fail(t, "Expected an error however none was raised.", test.Description)
}
}
Expand Down Expand Up @@ -318,6 +325,9 @@ func assertQueryResults(t *testing.T, description string, result *client.QueryRe

// compare results
assert.Equal(t, len(expectedResults), len(resultantData), description)
if len(expectedResults) == 0 {
assert.Equal(t, expectedResults, resultantData)
}
for i, result := range resultantData {
assert.Equal(t, expectedResults[i], result, description)
}
Expand Down
6 changes: 5 additions & 1 deletion query/graphql/planner/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,17 @@ func (p *Planner) queryDocs(query *parser.Query) ([]map[string]interface{}, erro
}

var next bool
if next, err = plan.Next(); err != nil || !next {
if next, err = plan.Next(); err != nil {
if err2 := (plan.Close()); err2 != nil {
fmt.Println(err2)
}
return nil, err
}

if !next {
return []map[string]interface{}{}, nil
}

var docs []map[string]interface{}
for {
if values := plan.Values(); values != nil {
Expand Down