Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #27 from alanbernstein/db-index-rename
Browse files Browse the repository at this point in the history
Rename db->index in tests and readme
  • Loading branch information
alanbernstein authored May 25, 2017
2 parents 0f97474 + e3fee54 commit 3f6ec51
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 58 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ var err error
client := pilosa.DefaultClient()

// Create an Index object
mydb, err := pilosa.NewIndex("mydb", nil)
myindex, err := pilosa.NewIndex("myindex", nil)

// Make sure the index exists on the server
err = client.EnsureIndex(mydb)
err = client.EnsureIndex(myindex)

// Create a Frame object
myframe, err := mydb.Frame("myframe", nil)
myframe, err := myindex.Frame("myframe", nil)

// Make sure the frame exists on the server
err = client.EnsureFrame(myframe)
Expand All @@ -76,7 +76,7 @@ if result != nil {

// You can batch queries to improve throughput
response, err = client.Query(
mydb.BatchQuery(
myindex.BatchQuery(
myframe.Bitmap(5),
myframe.Bitmap(10),
), nil
Expand Down Expand Up @@ -204,10 +204,10 @@ A Pilosa URI is represented by the `pilosa.URI` struct. Below are a few ways to
uri1 := pilosa.DefaultURI()

// create a URI from string address
uri2, err := pilosa.NewURIFromAddress("db1.pilosa.com:20202");
uri2, err := pilosa.NewURIFromAddress("index1.pilosa.com:20202");

// create a URI with the given host and port
uri3, err := pilosa.NewURIFromHostPort("db1.pilosa.com", 20202);
uri3, err := pilosa.NewURIFromHostPort("index1.pilosa.com", 20202);
```

### Pilosa Client
Expand All @@ -223,7 +223,7 @@ client := pilosa.DefaultClient()
To use a custom server address, use the `NewClientWithURI` function:

```go
uri, err := pilosa.NewURIFromAddress("http://db1.pilosa.com:15000")
uri, err := pilosa.NewURIFromAddress("http://index1.pilosa.com:15000")
if err != nil {
// Act on the error
}
Expand Down
10 changes: 5 additions & 5 deletions client_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var testFrame *Frame

func TestMain(m *testing.M) {
var err error
index, err = NewIndex("go-testdb", nil)
index, err = NewIndex("go-testindex", nil)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestEnsureIndexExists(t *testing.T) {
func TestCreateIndexWithTimeQuantum(t *testing.T) {
client := getClient()
options := &IndexOptions{TimeQuantum: TimeQuantumYear}
index, err := NewIndex("db-with-timequantum", options)
index, err := NewIndex("index-with-timequantum", options)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -396,9 +396,9 @@ func TestSchema(t *testing.T) {
if err != nil {
t.Fatal(err)
}
// go-testdb should be in the schema
// go-testindex should be in the schema
for _, index := range schema.Indexes {
if index.Name == "go-testdb" {
if index.Name == "go-testindex" {
// test-frame should be in the schema
for _, frame := range index.Frames {
if frame.Name == "test-frame" {
Expand All @@ -408,7 +408,7 @@ func TestSchema(t *testing.T) {
}
}
}
t.Fatal("go-testdb or test-frame was not found")
t.Fatal("go-testindex or test-frame was not found")
}

func TestErrorRetrievingSchema(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ import (
func TestQueryWithError(t *testing.T) {
var err error
client := pilosa.DefaultClient()
db, err := pilosa.NewIndex("foo", nil)
index, err := pilosa.NewIndex("foo", nil)
if err != nil {
t.Fatal(err)
}
frame, err := db.Frame("foo", nil)
frame, err := index.Frame("foo", nil)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ func TestHosts(t *testing.T) {
}

func TestRemoveHost(t *testing.T) {
uri, err := NewURIFromAddress("db1.pilosa.com:9999")
uri, err := NewURIFromAddress("index1.pilosa.com:9999")
if err != nil {
t.Fatal(err)
}
c := NewClusterWithHost(uri)
if len(c.hosts) != 1 {
t.Fatalf("The cluster should contain the host")
}
uri, err = NewURIFromAddress("db1.pilosa.com:9999")
uri, err = NewURIFromAddress("index1.pilosa.com:9999")
if err != nil {
t.Fatal(err)
}
Expand Down
72 changes: 36 additions & 36 deletions orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ import (
"time"
)

var sampleDb = mustNewIndex("sample-db", "")
var sampleFrame = mustNewFrame(sampleDb, "sample-frame", "")
var projectDb = mustNewIndex("project-db", "user")
var collabFrame = mustNewFrame(projectDb, "collaboration", "project")
var sampleIndex = mustNewIndex("sample-index", "")
var sampleFrame = mustNewFrame(sampleIndex, "sample-frame", "")
var projectIndex = mustNewIndex("project-index", "user")
var collabFrame = mustNewFrame(projectIndex, "collaboration", "project")
var b1 = sampleFrame.Bitmap(10)
var b2 = sampleFrame.Bitmap(20)
var b3 = sampleFrame.Bitmap(42)
var b4 = collabFrame.Bitmap(2)

func TestNewIndex(t *testing.T) {
db, err := NewIndex("db-name", nil)
index, err := NewIndex("index-name", nil)
if err != nil {
t.Fatal(err)
}
if db.Name() != "db-name" {
if index.Name() != "index-name" {
t.Fatalf("index name was not set")
}
}
Expand All @@ -64,11 +64,11 @@ func TestNewIndexWithInvalidName(t *testing.T) {
}

func TestNewFrameWithInvalidName(t *testing.T) {
db, err := NewIndex("foo", nil)
index, err := NewIndex("foo", nil)
if err != nil {
t.Fatal(err)
}
_, err = db.Frame("$$INVALIDFRAME$$", nil)
_, err = index.Frame("$$INVALIDFRAME$$", nil)
if err == nil {
t.Fatal("Creating frames with invalid row labels should fail")
}
Expand All @@ -88,7 +88,7 @@ func TestInverseBitmap(t *testing.T) {
RowLabel: "row_label",
InverseEnabled: true,
}
f1, err := projectDb.Frame("f1-inversable", options)
f1, err := projectIndex.Frame("f1-inversable", options)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -125,37 +125,37 @@ func TestClearBit(t *testing.T) {
func TestUnion(t *testing.T) {
comparePQL(t,
"Union(Bitmap(rowID=10, frame='sample-frame'), Bitmap(rowID=20, frame='sample-frame'))",
sampleDb.Union(b1, b2))
sampleIndex.Union(b1, b2))
comparePQL(t,
"Union(Bitmap(rowID=10, frame='sample-frame'), Bitmap(rowID=20, frame='sample-frame'), Bitmap(rowID=42, frame='sample-frame'))",
sampleDb.Union(b1, b2, b3))
sampleIndex.Union(b1, b2, b3))
comparePQL(t,
"Union(Bitmap(rowID=10, frame='sample-frame'), Bitmap(project=2, frame='collaboration'))",
sampleDb.Union(b1, b4))
sampleIndex.Union(b1, b4))
}

func TestIntersect(t *testing.T) {
comparePQL(t,
"Intersect(Bitmap(rowID=10, frame='sample-frame'), Bitmap(rowID=20, frame='sample-frame'))",
sampleDb.Intersect(b1, b2))
sampleIndex.Intersect(b1, b2))
comparePQL(t,
"Intersect(Bitmap(rowID=10, frame='sample-frame'), Bitmap(rowID=20, frame='sample-frame'), Bitmap(rowID=42, frame='sample-frame'))",
sampleDb.Intersect(b1, b2, b3))
sampleIndex.Intersect(b1, b2, b3))
comparePQL(t,
"Intersect(Bitmap(rowID=10, frame='sample-frame'), Bitmap(project=2, frame='collaboration'))",
sampleDb.Intersect(b1, b4))
sampleIndex.Intersect(b1, b4))
}

func TestDifference(t *testing.T) {
comparePQL(t,
"Difference(Bitmap(rowID=10, frame='sample-frame'), Bitmap(rowID=20, frame='sample-frame'))",
sampleDb.Difference(b1, b2))
sampleIndex.Difference(b1, b2))
comparePQL(t,
"Difference(Bitmap(rowID=10, frame='sample-frame'), Bitmap(rowID=20, frame='sample-frame'), Bitmap(rowID=42, frame='sample-frame'))",
sampleDb.Difference(b1, b2, b3))
sampleIndex.Difference(b1, b2, b3))
comparePQL(t,
"Difference(Bitmap(rowID=10, frame='sample-frame'), Bitmap(project=2, frame='collaboration'))",
sampleDb.Difference(b1, b4))
sampleIndex.Difference(b1, b4))
}

func TestTopN(t *testing.T) {
Expand Down Expand Up @@ -187,17 +187,17 @@ func TestFilterFieldTopNInvalidValue(t *testing.T) {
func TestBitmapOperationInvalidArg(t *testing.T) {
invalid := sampleFrame.FilterFieldTopN(12, collabFrame.Bitmap(7), "$invalid$", 80, 81)
// invalid argument in pos 1
q := sampleDb.Union(invalid, b1)
q := sampleIndex.Union(invalid, b1)
if q.Error() == nil {
t.Fatalf("should have failed")
}
// invalid argument in pos 2
q = sampleDb.Intersect(b1, invalid)
q = sampleIndex.Intersect(b1, invalid)
if q.Error() == nil {
t.Fatalf("should have failed")
}
// invalid argument in pos 3
q = sampleDb.Intersect(b1, b2, invalid)
q = sampleIndex.Intersect(b1, b2, invalid)
if q.Error() == nil {
t.Fatalf("should have failed")
}
Expand All @@ -210,15 +210,15 @@ func TestSetColumnAttrsTest(t *testing.T) {
}
comparePQL(t,
"SetColumnAttrs(user=5, happy=true, quote=\"\\\"Don't worry, be happy\\\"\")",
projectDb.SetColumnAttrs(5, attrs))
projectIndex.SetColumnAttrs(5, attrs))
}

func TestSetColumnAttrsInvalidAttr(t *testing.T) {
attrs := map[string]interface{}{
"color": "blue",
"$invalid$": true,
}
if projectDb.SetColumnAttrs(5, attrs).Error() == nil {
if projectIndex.SetColumnAttrs(5, attrs).Error() == nil {
t.Fatalf("Should have failed")
}
}
Expand All @@ -245,8 +245,8 @@ func TestSetRowAttrsInvalidAttr(t *testing.T) {
}

func TestBatchQuery(t *testing.T) {
q := sampleDb.BatchQuery()
if q.Index() != sampleDb {
q := sampleIndex.BatchQuery()
if q.Index() != sampleIndex {
t.Fatalf("The correct index should be assigned")
}
q.Add(sampleFrame.Bitmap(44))
Expand All @@ -258,15 +258,15 @@ func TestBatchQuery(t *testing.T) {
}

func TestBatchQueryWithError(t *testing.T) {
q := sampleDb.BatchQuery()
q := sampleIndex.BatchQuery()
q.Add(sampleFrame.FilterFieldTopN(12, collabFrame.Bitmap(7), "$invalid$", 80, 81))
if q.Error() == nil {
t.Fatalf("The error must be set")
}
}

func TestCount(t *testing.T) {
q := projectDb.Count(collabFrame.Bitmap(42))
q := projectIndex.Count(collabFrame.Bitmap(42))
comparePQL(t, "Count(Bitmap(project=42, frame='collaboration'))", q)
}

Expand All @@ -291,14 +291,14 @@ func TestInvalidColumnLabelFails(t *testing.T) {

func TestInvalidRowLabelFails(t *testing.T) {
options := &FrameOptions{RowLabel: "$INVALID$"}
_, err := sampleDb.Frame("foo", options)
_, err := sampleIndex.Frame("foo", options)
if err == nil {
t.Fatalf("Creating frames with invalid row label should fail")
}
}

func TestInverseBitmapFailsIfNotEnabled(t *testing.T) {
frame, err := sampleDb.Frame("inverse-not-enabled", nil)
frame, err := sampleIndex.Frame("inverse-not-enabled", nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -316,7 +316,7 @@ func TestFrameOptionsToString(t *testing.T) {
CacheType: CacheTypeRanked,
CacheSize: 1000,
}
frame, err := sampleDb.Frame("stargazer", frameOptions)
frame, err := sampleIndex.Frame("stargazer", frameOptions)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -345,35 +345,35 @@ func comparePQL(t *testing.T, target string, q PQLQuery) {
}
}

func mustNewIndex(name string, columnLabel string) (db *Index) {
func mustNewIndex(name string, columnLabel string) (index *Index) {
var err error
var options *IndexOptions
if columnLabel != "" {
options = &IndexOptions{ColumnLabel: columnLabel}
if err != nil {
panic(err)
}
db, err = NewIndex(name, options)
index, err = NewIndex(name, options)
} else {
db, err = NewIndex(name, nil)
index, err = NewIndex(name, nil)
}
if err != nil {
panic(err)
}
return
}

func mustNewFrame(db *Index, name string, rowLabel string) (frame *Frame) {
func mustNewFrame(index *Index, name string, rowLabel string) (frame *Frame) {
var err error
var options *FrameOptions
if rowLabel != "" {
options = &FrameOptions{RowLabel: rowLabel}
if err != nil {
panic(err)
}
frame, err = db.Frame(name, options)
frame, err = index.Frame(name, options)
} else {
frame, err = db.Frame(name, nil)
frame, err = index.Frame(name, nil)
}
if err != nil {
panic(err)
Expand Down
12 changes: 6 additions & 6 deletions uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ func TestDefaultURI(t *testing.T) {
}

func TestURIWithHostPort(t *testing.T) {
uri, err := NewURIFromHostPort("db1.pilosa.com", 3333)
uri, err := NewURIFromHostPort("index1.pilosa.com", 3333)
if err != nil {
t.Fatal(err)
}
compare(t, uri, "http", "db1.pilosa.com", 3333)
compare(t, uri, "http", "index1.pilosa.com", 3333)
}

func TestURIFromAddress(t *testing.T) {
Expand All @@ -56,10 +56,10 @@ func TestURIFromAddress(t *testing.T) {
host string
port uint16
}{
{"http+protobuf://db1.pilosa.com:3333", "http+protobuf", "db1.pilosa.com", 3333},
{"db1.pilosa.com:3333", "http", "db1.pilosa.com", 3333},
{"https://db1.pilosa.com", "https", "db1.pilosa.com", 10101},
{"db1.pilosa.com", "http", "db1.pilosa.com", 10101},
{"http+protobuf://index1.pilosa.com:3333", "http+protobuf", "index1.pilosa.com", 3333},
{"index1.pilosa.com:3333", "http", "index1.pilosa.com", 3333},
{"https://index1.pilosa.com", "https", "index1.pilosa.com", 10101},
{"index1.pilosa.com", "http", "index1.pilosa.com", 10101},
{"https://:3333", "https", "localhost", 3333},
{":3333", "http", "localhost", 3333},
}
Expand Down

0 comments on commit 3f6ec51

Please sign in to comment.