Skip to content

Commit

Permalink
remove use of dump methods from index reader (#1516)
Browse files Browse the repository at this point in the history
the dump methods were only ever supposed by upsidedown
now, users of this method must type-assert that their reader
is from the upsidedown package, where these methods remain,
unchanged.
  • Loading branch information
mschoch authored Dec 6, 2020
1 parent bcacd48 commit 66ef9cf
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
6 changes: 5 additions & 1 deletion cmd/bleve/cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ var dumpCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("error getting index reader: %v", err)
}
upsideDownReader, ok := r.(*upsidedown.IndexReader)
if !ok {
return fmt.Errorf("dump is only supported by index type upsidedown")
}

dumpChan := r.DumpAll()
dumpChan := upsideDownReader.DumpAll()
for rowOrErr := range dumpChan {
switch rowOrErr := rowOrErr.(type) {
case error:
Expand Down
6 changes: 5 additions & 1 deletion cmd/bleve/cmd/dumpDoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ var dumpDocCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("error getting index reader: %v", err)
}
upsideDownReader, ok := r.(*upsidedown.IndexReader)
if !ok {
return fmt.Errorf("dump doc is only supported by index type upsidedown")
}

dumpChan := r.DumpDoc(args[1])
dumpChan := upsideDownReader.DumpDoc(args[1])
for rowOrErr := range dumpChan {
switch rowOrErr := rowOrErr.(type) {
case error:
Expand Down
6 changes: 5 additions & 1 deletion cmd/bleve/cmd/dumpFields.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ var dumpFieldsCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("error getting index reader: %v", err)
}
upsideDownReader, ok := r.(*upsidedown.IndexReader)
if !ok {
return fmt.Errorf("dump fields is only supported by index type upsidedown")
}

dumpChan := r.DumpFields()
dumpChan := upsideDownReader.DumpFields()
for rowOrErr := range dumpChan {
switch rowOrErr := rowOrErr.(type) {
case error:
Expand Down
7 changes: 6 additions & 1 deletion http/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,14 @@ func (h *DebugDocumentHandler) ServeHTTP(w http.ResponseWriter, req *http.Reques
showError(w, req, fmt.Sprintf("error operning index reader: %v", err), 500)
return
}
upsideDownReader, ok := internalIndexReader.(*upsidedown.IndexReader)
if !ok {
showError(w, req, fmt.Sprintf("dump is only supported by index type upsidedown"), 500)
return
}

var rv []interface{}
rowChan := internalIndexReader.DumpDoc(docID)
rowChan := upsideDownReader.DumpDoc(docID)
for row := range rowChan {
switch row := row.(type) {
case error:
Expand Down
14 changes: 9 additions & 5 deletions index/upsidedown/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"testing"
"time"

index "github.com/blevesearch/bleve_index_api"
"github.com/blevesearch/bleve/index/upsidedown/store/boltdb"
index "github.com/blevesearch/bleve_index_api"

"github.com/blevesearch/bleve/document"
)
Expand Down Expand Up @@ -96,7 +96,11 @@ func TestDump(t *testing.T) {
if err != nil {
t.Fatal(err)
}
fieldsRows := reader.DumpFields()
upsideDownReader, ok := reader.(*IndexReader)
if !ok {
t.Fatal("dump is only supported by index type upsidedown")
}
fieldsRows := upsideDownReader.DumpFields()
for range fieldsRows {
fieldsCount++
}
Expand All @@ -110,7 +114,7 @@ func TestDump(t *testing.T) {
// 3 stored fields
expectedDocRowCount := int(1 + (2 * (64 / document.DefaultPrecisionStep)) + 3)
docRowCount := 0
docRows := reader.DumpDoc("1")
docRows := upsideDownReader.DumpDoc("1")
for range docRows {
docRowCount++
}
Expand All @@ -119,7 +123,7 @@ func TestDump(t *testing.T) {
}

docRowCount = 0
docRows = reader.DumpDoc("2")
docRows = upsideDownReader.DumpDoc("2")
for range docRows {
docRowCount++
}
Expand All @@ -136,7 +140,7 @@ func TestDump(t *testing.T) {
// 16 date term row counts (shared for both docs, same date value)
expectedAllRowCount := int(1 + fieldsCount + (2 * expectedDocRowCount) + 2 + 2 + int((2 * (64 / document.DefaultPrecisionStep))))
allRowCount := 0
allRows := reader.DumpAll()
allRows := upsideDownReader.DumpAll()
for range allRows {
allRowCount++
}
Expand Down

0 comments on commit 66ef9cf

Please sign in to comment.