diff --git a/api.go b/api.go index 252480d52..c02aedbf2 100644 --- a/api.go +++ b/api.go @@ -489,7 +489,7 @@ func (api *API) Schema(ctx context.Context) []*IndexInfo { } // CreateField creates a new BSI field in the given index and frame. -func (api *API) CreateField(ctx context.Context, indexName string, frameName string, field *Field) error { +func (api *API) CreateField(ctx context.Context, indexName string, frameName string, field *oField) error { if err := api.validate(apiCreateField); err != nil { return errors.Wrap(err, "validating api method") } @@ -548,25 +548,6 @@ func (api *API) DeleteField(ctx context.Context, indexName string, frameName str return errors.Wrap(err, "sending DeleteField message") } -// Fields returns the fields in the given frame. -func (api *API) Fields(ctx context.Context, indexName string, frameName string) ([]*Field, error) { - if err := api.validate(apiFields); err != nil { - return nil, errors.Wrap(err, "validating api method") - } - - index := api.Holder.index(indexName) - if index == nil { - return nil, ErrIndexNotFound - } - - frame := index.frame(frameName) - if frame == nil { - return nil, ErrFrameNotFound - } - - return frame.GetFields() -} - // Views returns the views in the given frame. func (api *API) Views(ctx context.Context, indexName string, frameName string) ([]*View, error) { if err := api.validate(apiViews); err != nil { @@ -877,7 +858,6 @@ const ( apiDeleteIndex apiDeleteView apiExportCSV - apiFields apiFragmentBlockData apiFragmentBlocks apiFrameAttrDiff @@ -923,7 +903,6 @@ var methodsNormal = map[apiMethod]struct{}{ apiDeleteIndex: struct{}{}, apiDeleteView: struct{}{}, apiExportCSV: struct{}{}, - apiFields: struct{}{}, apiFragmentBlockData: struct{}{}, apiFragmentBlocks: struct{}{}, apiFrameAttrDiff: struct{}{}, diff --git a/apimethod_string.go b/apimethod_string.go index 2eb2913ae..0fc3822d5 100644 --- a/apimethod_string.go +++ b/apimethod_string.go @@ -2,15 +2,15 @@ package pilosa -import "strconv" +import "fmt" -const _apiMethod_name = "apiClusterMessageapiCreateFieldapiCreateFrameapiCreateIndexapiDeleteFieldapiDeleteFrameapiDeleteIndexapiDeleteViewapiExportCSVapiFieldsapiFragmentBlockDataapiFragmentBlocksapiFrameAttrDiffapiImportapiImportValueapiIndexapiIndexAttrDiffapiMarshalFragmentapiQueryapiRecalculateCachesapiRemoveNodeapiResizeAbortapiRestoreFrameapiSetCoordinatorapiSliceNodesapiUnmarshalFragmentapiViews" +const _apiMethod_name = "apiClusterMessageapiCreateFieldapiCreateFrameapiCreateIndexapiDeleteFieldapiDeleteFrameapiDeleteIndexapiDeleteViewapiExportCSVapiFragmentBlockDataapiFragmentBlocksapiFrameAttrDiffapiImportapiImportValueapiIndexapiIndexAttrDiffapiMarshalFragmentapiQueryapiRecalculateCachesapiRemoveNodeapiResizeAbortapiSetCoordinatorapiSliceNodesapiUnmarshalFragmentapiViews" -var _apiMethod_index = [...]uint16{0, 17, 31, 45, 59, 73, 87, 101, 114, 126, 135, 155, 172, 188, 197, 211, 219, 235, 253, 261, 281, 294, 308, 323, 340, 353, 373, 381} +var _apiMethod_index = [...]uint16{0, 17, 31, 45, 59, 73, 87, 101, 114, 126, 146, 163, 179, 188, 202, 210, 226, 244, 252, 272, 285, 299, 316, 329, 349, 357} func (i apiMethod) String() string { if i < 0 || i >= apiMethod(len(_apiMethod_index)-1) { - return "apiMethod(" + strconv.FormatInt(int64(i), 10) + ")" + return fmt.Sprintf("apiMethod(%d)", i) } return _apiMethod_name[_apiMethod_index[i]:_apiMethod_index[i+1]] } diff --git a/client_test.go b/client_test.go index 6e5f2dc41..898869f2b 100644 --- a/client_test.go +++ b/client_test.go @@ -244,16 +244,17 @@ func TestClient_ImportValue(t *testing.T) { hldr := test.MustOpenHolder() defer hldr.Close() - fld := pilosa.Field{ - Name: "fld", - Type: pilosa.FieldTypeInt, + fldName := "f" + + fo := pilosa.FrameOptions{ + Type: pilosa.FrameTypeInt, Min: -100, Max: 100, } // Load bitmap into cache to ensure cache gets updated. index := hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{}) - frame, err := index.CreateFrameIfNotExists("f", pilosa.FrameOptions{Fields: []*pilosa.Field{&fld}}) + frame, err := index.CreateFrameIfNotExists(fldName, fo) if err != nil { t.Fatal(err) } @@ -266,7 +267,7 @@ func TestClient_ImportValue(t *testing.T) { // Send import request. c := test.MustNewClient(s.Host(), defaultClient) - if err := c.ImportValue(context.Background(), "i", "f", fld.Name, 0, []pilosa.FieldValue{ + if err := c.ImportValue(context.Background(), "i", "f", fldName, 0, []pilosa.FieldValue{ {ColumnID: 1, Value: -10}, {ColumnID: 2, Value: 20}, {ColumnID: 3, Value: 40}, @@ -275,7 +276,7 @@ func TestClient_ImportValue(t *testing.T) { } // Verify Sum. - sum, cnt, err := frame.FieldSum(nil, fld.Name) + sum, cnt, err := frame.FieldSum(nil, fldName) if err != nil { t.Fatal(err) } @@ -284,7 +285,7 @@ func TestClient_ImportValue(t *testing.T) { } // Verify Min. - min, cnt, err := frame.FieldMin(nil, fld.Name) + min, cnt, err := frame.FieldMin(nil, fldName) if err != nil { t.Fatal(err) } @@ -293,11 +294,11 @@ func TestClient_ImportValue(t *testing.T) { } // Verify Min with Filter. - filter, err := frame.FieldRange(fld.Name, pql.GT, 40) + filter, err := frame.FieldRange(fldName, pql.GT, 40) if err != nil { t.Fatal(err) } - min, cnt, err = frame.FieldMin(filter, fld.Name) + min, cnt, err = frame.FieldMin(filter, fldName) if err != nil { t.Fatal(err) } @@ -306,7 +307,7 @@ func TestClient_ImportValue(t *testing.T) { } // Verify Max. - max, cnt, err := frame.FieldMax(nil, fld.Name) + max, cnt, err := frame.FieldMax(nil, fldName) if err != nil { t.Fatal(err) } diff --git a/cluster_test.go b/cluster_test.go index 913cd5db3..99b322a0e 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -422,24 +422,6 @@ func TestCluster_ResizeStates(t *testing.T) { tc.SetBit("i", "f", "standard", 1, 101, nil) tc.SetBit("i", "f", "standard", 1, 1300000, nil) - // Add Field Data to node0. - if err := tc.CreateFrame("i", "fields", FrameOptions{ - Fields: []*Field{ - { - Name: "fld0", - Type: FieldTypeInt, - Min: -100, - Max: 100, - }, - }, - }); err != nil { - t.Fatal(err) - } - tc.SetFieldValue("i", "fields", 1, "fld0", -10) - tc.SetFieldValue("i", "fields", 1, "fld0", 10) - tc.SetFieldValue("i", "fields", 1300000, "fld0", -99) - tc.SetFieldValue("i", "fields", 1300000, "fld0", 99) - // Before starting the resize, get the CheckSum to use for // comparison later. node0Frame := node0.Holder.Frame("i", "f") @@ -447,11 +429,6 @@ func TestCluster_ResizeStates(t *testing.T) { node0Fragment := node0View.Fragment(1) node0Checksum := node0Fragment.Checksum() - node0Frame = node0.Holder.Frame("i", "fields") - node0View = node0Frame.View("field_fld0") - node0Fragment = node0View.Fragment(1) - node0ChecksumFld := node0Fragment.Checksum() - // AddNode needs to block until the resize process has completed. tc.AddNode(false) node1 := tc.Clusters[1] @@ -485,17 +462,6 @@ func TestCluster_ResizeStates(t *testing.T) { t.Fatalf("expected standard view checksum to match: %x - %x", chksum, node0Checksum) } - // Values - // Verify that node-1 contains the fragment (i/fields/field_fld0/1) transferred from node-0. - node1Frame = node1.Holder.Frame("i", "fields") - node1View = node1Frame.View("field_fld0") - node1Fragment = node1View.Fragment(1) - - // Ensure checksums are the same. - if chksum := node1Fragment.Checksum(); !bytes.Equal(chksum, node0ChecksumFld) { - t.Fatalf("expected checksum to match: %x - %x", chksum, node0ChecksumFld) - } - // Close TestCluster. if err := tc.Close(); err != nil { t.Fatal(err) diff --git a/ctl/import_test.go b/ctl/import_test.go index a11770bd8..7c6c02721 100644 --- a/ctl/import_test.go +++ b/ctl/import_test.go @@ -82,6 +82,7 @@ func TestImportCommand_Run(t *testing.T) { } } +// TODO: revisit this test once Frame is renamed Field // Ensure that the ImportValue path runs (note: we have specified a value // for cm.Field.) func TestImportCommand_RunValue(t *testing.T) { @@ -107,11 +108,11 @@ func TestImportCommand_RunValue(t *testing.T) { cm.Host = s.Host() http.DefaultClient.Do(MustNewHTTPRequest("POST", s.URL+"/index/i", strings.NewReader(""))) - http.DefaultClient.Do(MustNewHTTPRequest("POST", s.URL+"/index/i/frame/f", strings.NewReader(`{"options":{"fields": [{"name": "foo", "type": "int", "min": 0, "max": 100}]}}`))) + http.DefaultClient.Do(MustNewHTTPRequest("POST", s.URL+"/index/i/frame/f", strings.NewReader(`{"options":{"type": "int", "min": 0, "max": 100}}`))) cm.Index = "i" cm.Frame = "f" - cm.Field = "foo" + cm.Field = "f" cm.Paths = []string{file.Name()} err = cm.Run(ctx) if err != nil { diff --git a/diagnostics.go b/diagnostics.go index 9219c01ea..1968a4e74 100644 --- a/diagnostics.go +++ b/diagnostics.go @@ -227,8 +227,8 @@ func (d *DiagnosticsCollector) EnrichWithSchemaProperties() { numIndexes += 1 for _, frame := range index.Frames() { numFrames += 1 - if fields, err := frame.GetFields(); err == nil { - bsiFieldCount += len(fields) + if frame.Type() == FrameTypeInt { + bsiFieldCount += 1 } if frame.TimeQuantum() != "" { timeQuantumEnabled = true diff --git a/executor_test.go b/executor_test.go index 0807228ac..fbce4d52d 100644 --- a/executor_test.go +++ b/executor_test.go @@ -272,10 +272,9 @@ func TestExecutor_Execute_SetFieldValue(t *testing.T) { // Create frames. index := hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{}) if _, err := index.CreateFrameIfNotExists("f", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "field0", Type: pilosa.FieldTypeInt, Min: 0, Max: 50}, - {Name: "field1", Type: pilosa.FieldTypeInt, Min: 1, Max: 2}, - }, + Type: pilosa.FrameTypeInt, + Min: 0, + Max: 50, }); err != nil { t.Fatal(err) } else if _, err := index.CreateFrameIfNotExists("xxx", pilosa.FrameOptions{}); err != nil { @@ -284,14 +283,14 @@ func TestExecutor_Execute_SetFieldValue(t *testing.T) { // Set field values. e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) - if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(col=10, frame=f, field0=25, field1=2)`), nil, nil); err != nil { + if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(col=10, frame=f, f=25)`), nil, nil); err != nil { t.Fatal(err) - } else if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(col=100, frame=f, field0=10)`), nil, nil); err != nil { + } else if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(col=100, frame=f, f=10)`), nil, nil); err != nil { t.Fatal(err) } f := hldr.Frame("i", "f") - if value, exists, err := f.FieldValue(10, "field0"); err != nil { + if value, exists, err := f.FieldValue(10, "f"); err != nil { t.Fatal(err) } else if !exists { t.Fatal("expected value to exist") @@ -299,15 +298,7 @@ func TestExecutor_Execute_SetFieldValue(t *testing.T) { t.Fatalf("unexpected value: %v", value) } - if value, exists, err := f.FieldValue(10, "field1"); err != nil { - t.Fatal(err) - } else if !exists { - t.Fatal("expected value to exist") - } else if value != 2 { - t.Fatalf("unexpected value: %v", value) - } - - if value, exists, err := f.FieldValue(100, "field0"); err != nil { + if value, exists, err := f.FieldValue(100, "f"); err != nil { t.Fatal(err) } else if !exists { t.Fatal("expected value to exist") @@ -321,37 +312,37 @@ func TestExecutor_Execute_SetFieldValue(t *testing.T) { defer hldr.Close() index := hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{}) if _, err := index.CreateFrameIfNotExists("f", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "field0", Type: pilosa.FieldTypeInt, Min: 0, Max: 100}, - }, + Type: pilosa.FrameTypeInt, + Min: 0, + Max: 100, }); err != nil { t.Fatal(err) } t.Run("ErrFrameRequired", func(t *testing.T) { e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) - if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(col=10, field0=100)`), nil, nil); err == nil || err.Error() != `SetFieldValue() frame required` { + if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(col=10, f=100)`), nil, nil); err == nil || err.Error() != `SetFieldValue() frame required` { t.Fatalf("unexpected error: %s", err) } }) t.Run("ErrColumnFieldRequired", func(t *testing.T) { e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) - if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(invalid_column_name=10, frame=f, field0=100)`), nil, nil); err == nil || err.Error() != `SetFieldValue() column field 'col' required` { + if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(invalid_column_name=10, frame=f, f=100)`), nil, nil); err == nil || err.Error() != `SetFieldValue() column field 'col' required` { t.Fatalf("unexpected error: %s", err) } }) t.Run("ErrColumnFieldValue", func(t *testing.T) { e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) - if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(invalid_column_name="bad_column", frame=f, field0=100)`), nil, nil); err == nil || err.Error() != `SetFieldValue() column field 'col' required` { + if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(invalid_column_name="bad_column", frame=f, f=100)`), nil, nil); err == nil || err.Error() != `SetFieldValue() column field 'col' required` { t.Fatalf("unexpected error: %s", err) } }) t.Run("ErrInvalidFieldValueType", func(t *testing.T) { e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) - if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(col=10, frame=f, field0="hello")`), nil, nil); err == nil || err.Error() != `invalid field value type` { + if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(col=10, frame=f, f="hello")`), nil, nil); err == nil || err.Error() != `invalid field value type` { t.Fatalf("unexpected error: %s", err) } }) @@ -588,29 +579,33 @@ func TestExecutor_Execute_MinMax(t *testing.T) { t.Fatal(err) } + if _, err := idx.CreateFrame("x", pilosa.FrameOptions{}); err != nil { + t.Fatal(err) + } + if _, err := idx.CreateFrame("f", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "foo", Type: pilosa.FieldTypeInt, Min: -10, Max: 100}, - }, + Type: pilosa.FrameTypeInt, + Min: -10, + Max: 100, }); err != nil { t.Fatal(err) } if _, err := e.Execute(context.Background(), "i", test.MustParse(` - SetBit(frame=f, row=0, col=0) - SetBit(frame=f, row=0, col=3) - SetBit(frame=f, row=0, col=`+strconv.Itoa(SliceWidth+1)+`) - SetBit(frame=f, row=1, col=1) - SetBit(frame=f, row=2, col=`+strconv.Itoa(SliceWidth+2)+`) + SetBit(frame=x, row=0, col=0) + SetBit(frame=x, row=0, col=3) + SetBit(frame=x, row=0, col=`+strconv.Itoa(SliceWidth+1)+`) + SetBit(frame=x, row=1, col=1) + SetBit(frame=x, row=2, col=`+strconv.Itoa(SliceWidth+2)+`) - SetFieldValue(frame=f, foo=20, col=0) - SetFieldValue(frame=f, foo=-5, col=1) - SetFieldValue(frame=f, foo=-5, col=2) - SetFieldValue(frame=f, foo=10, col=3) - SetFieldValue(frame=f, foo=30, col=`+strconv.Itoa(SliceWidth)+`) - SetFieldValue(frame=f, foo=40, col=`+strconv.Itoa(SliceWidth+2)+`) - SetFieldValue(frame=f, foo=50, col=`+strconv.Itoa((5*SliceWidth)+100)+`) - SetFieldValue(frame=f, foo=60, col=`+strconv.Itoa(SliceWidth+1)+`) + SetFieldValue(frame=f, f=20, col=0) + SetFieldValue(frame=f, f=-5, col=1) + SetFieldValue(frame=f, f=-5, col=2) + SetFieldValue(frame=f, f=10, col=3) + SetFieldValue(frame=f, f=30, col=`+strconv.Itoa(SliceWidth)+`) + SetFieldValue(frame=f, f=40, col=`+strconv.Itoa(SliceWidth+2)+`) + SetFieldValue(frame=f, f=50, col=`+strconv.Itoa((5*SliceWidth)+100)+`) + SetFieldValue(frame=f, f=60, col=`+strconv.Itoa(SliceWidth+1)+`) `), nil, nil); err != nil { t.Fatal(err) } @@ -622,16 +617,16 @@ func TestExecutor_Execute_MinMax(t *testing.T) { cnt int64 }{ {filter: ``, exp: -5, cnt: 2}, - {filter: `Bitmap(frame=f, row=0)`, exp: 10, cnt: 1}, - {filter: `Bitmap(frame=f, row=1)`, exp: -5, cnt: 1}, - {filter: `Bitmap(frame=f, row=2)`, exp: 40, cnt: 1}, + {filter: `Bitmap(frame=x, row=0)`, exp: 10, cnt: 1}, + {filter: `Bitmap(frame=x, row=1)`, exp: -5, cnt: 1}, + {filter: `Bitmap(frame=x, row=2)`, exp: 40, cnt: 1}, } for i, tt := range tests { var pql string if tt.filter == "" { - pql = `Min(frame=f, field=foo)` + pql = `Min(frame=f, field=f)` } else { - pql = fmt.Sprintf(`Min(%s, frame=f, field=foo)`, tt.filter) + pql = fmt.Sprintf(`Min(%s, frame=f, field=f)`, tt.filter) } if result, err := e.Execute(context.Background(), "i", test.MustParse(pql), nil, nil); err != nil { t.Fatal(err) @@ -648,16 +643,16 @@ func TestExecutor_Execute_MinMax(t *testing.T) { cnt int64 }{ {filter: ``, exp: 60, cnt: 1}, - {filter: `Bitmap(frame=f, row=0)`, exp: 60, cnt: 1}, - {filter: `Bitmap(frame=f, row=1)`, exp: -5, cnt: 1}, - {filter: `Bitmap(frame=f, row=2)`, exp: 40, cnt: 1}, + {filter: `Bitmap(frame=x, row=0)`, exp: 60, cnt: 1}, + {filter: `Bitmap(frame=x, row=1)`, exp: -5, cnt: 1}, + {filter: `Bitmap(frame=x, row=2)`, exp: 40, cnt: 1}, } for i, tt := range tests { var pql string if tt.filter == "" { - pql = `Max(frame=f, field=foo)` + pql = `Max(frame=f, field=f)` } else { - pql = fmt.Sprintf(`Max(%s, frame=f, field=foo)`, tt.filter) + pql = fmt.Sprintf(`Max(%s, frame=f, field=f)`, tt.filter) } if result, err := e.Execute(context.Background(), "i", test.MustParse(pql), nil, nil); err != nil { t.Fatal(err) @@ -679,39 +674,51 @@ func TestExecutor_Execute_Sum(t *testing.T) { t.Fatal(err) } - if _, err := idx.CreateFrame("f", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "foo", Type: pilosa.FieldTypeInt, Min: 10, Max: 100}, - {Name: "bar", Type: pilosa.FieldTypeInt, Min: 0, Max: 100000}, - }, + if _, err := idx.CreateFrame("x", pilosa.FrameOptions{}); err != nil { + t.Fatal(err) + } + + if _, err := idx.CreateFrame("foo", pilosa.FrameOptions{ + Type: pilosa.FrameTypeInt, + Min: 10, + Max: 100, + }); err != nil { + t.Fatal(err) + } + + if _, err := idx.CreateFrame("bar", pilosa.FrameOptions{ + Type: pilosa.FrameTypeInt, + Min: 0, + Max: 100000, }); err != nil { t.Fatal(err) } if _, err := idx.CreateFrame("other", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "foo", Type: pilosa.FieldTypeInt, Min: 0, Max: 1000}, - }, + Type: pilosa.FrameTypeInt, + Min: 0, + Max: 1000, }); err != nil { t.Fatal(err) } if _, err := e.Execute(context.Background(), "i", test.MustParse(` - SetBit(frame=f, row=0, col=0) - SetBit(frame=f, row=0, col=`+strconv.Itoa(SliceWidth+1)+`) + SetBit(frame=x, row=0, col=0) + SetBit(frame=x, row=0, col=`+strconv.Itoa(SliceWidth+1)+`) - SetFieldValue(frame=f, foo=20, bar=2000, col=0) - SetFieldValue(frame=f, foo=30, col=`+strconv.Itoa(SliceWidth)+`) - SetFieldValue(frame=f, foo=40, col=`+strconv.Itoa(SliceWidth+2)+`) - SetFieldValue(frame=f, foo=50, col=`+strconv.Itoa((5*SliceWidth)+100)+`) - SetFieldValue(frame=f, foo=60, col=`+strconv.Itoa(SliceWidth+1)+`) - SetFieldValue(frame=other, foo=1000, col=0) + SetFieldValue(frame=foo, foo=20, col=0) + SetFieldValue(frame=bar, bar=2000, col=0) + SetFieldValue(frame=foo, foo=30, col=`+strconv.Itoa(SliceWidth)+`) + SetFieldValue(frame=foo, foo=40, col=`+strconv.Itoa(SliceWidth+2)+`) + SetFieldValue(frame=foo, foo=50, col=`+strconv.Itoa((5*SliceWidth)+100)+`) + SetFieldValue(frame=foo, foo=60, col=`+strconv.Itoa(SliceWidth+1)+`) + SetFieldValue(frame=other, other=1000, col=0) `), nil, nil); err != nil { t.Fatal(err) } t.Run("NoFilter", func(t *testing.T) { - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Sum(frame=f, field=foo)`), nil, nil); err != nil { + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Sum(frame=foo, field=foo)`), nil, nil); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(result[0], pilosa.ValCount{Val: 200, Count: 5}) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) @@ -719,7 +726,7 @@ func TestExecutor_Execute_Sum(t *testing.T) { }) t.Run("WithFilter", func(t *testing.T) { - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Sum(Bitmap(frame=f, row=0), frame=f, field=foo)`), nil, nil); err != nil { + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Sum(Bitmap(frame=x, row=0), frame=foo, field=foo)`), nil, nil); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(result[0], pilosa.ValCount{Val: 80, Count: 2}) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) @@ -738,6 +745,7 @@ func TestExecutor_Execute_Range(t *testing.T) { // Create frame. if _, err := index.CreateFrameIfNotExists("f", pilosa.FrameOptions{ + Type: pilosa.FrameTypeTime, TimeQuantum: pilosa.TimeQuantum("YMDH"), }); err != nil { t.Fatal(err) @@ -766,7 +774,6 @@ func TestExecutor_Execute_Range(t *testing.T) { t.Fatalf("unexpected columns: %+v", columns) } }) - } // Ensure a Range(field) query can be executed. @@ -780,27 +787,38 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { t.Fatal(err) } - if _, err := idx.CreateFrame("f", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "foo", Type: pilosa.FieldTypeInt, Min: 10, Max: 100}, - {Name: "bar", Type: pilosa.FieldTypeInt, Min: 0, Max: 100000}, - }, + if _, err := idx.CreateFrame("f", pilosa.FrameOptions{}); err != nil { + t.Fatal(err) + } + + if _, err := idx.CreateFrame("foo", pilosa.FrameOptions{ + Type: pilosa.FrameTypeInt, + Min: 10, + Max: 100, + }); err != nil { + t.Fatal(err) + } + + if _, err := idx.CreateFrame("bar", pilosa.FrameOptions{ + Type: pilosa.FrameTypeInt, + Min: 0, + Max: 100000, }); err != nil { t.Fatal(err) } if _, err := idx.CreateFrame("other", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "foo", Type: pilosa.FieldTypeInt, Min: 0, Max: 1000}, - }, + Type: pilosa.FrameTypeInt, + Min: 0, + Max: 1000, }); err != nil { t.Fatal(err) } if _, err := idx.CreateFrame("edge", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "foo", Type: pilosa.FieldTypeInt, Min: -100, Max: 100}, - }, + Type: pilosa.FrameTypeInt, + Min: -100, + Max: 100, }); err != nil { t.Fatal(err) } @@ -809,20 +827,21 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { SetBit(frame=f, row=0, col=0) SetBit(frame=f, row=0, col=`+strconv.Itoa(SliceWidth+1)+`) - SetFieldValue(frame=f, foo=20, bar=2000, col=50) - SetFieldValue(frame=f, foo=30, col=`+strconv.Itoa(SliceWidth)+`) - SetFieldValue(frame=f, foo=10, col=`+strconv.Itoa(SliceWidth+2)+`) - SetFieldValue(frame=f, foo=20, col=`+strconv.Itoa((5*SliceWidth)+100)+`) - SetFieldValue(frame=f, foo=60, col=`+strconv.Itoa(SliceWidth+1)+`) - SetFieldValue(frame=other, foo=1000, col=0) - SetFieldValue(frame=edge, foo=100, col=0) - SetFieldValue(frame=edge, foo=-100, col=1) + SetFieldValue(frame=foo, foo=20, col=50) + SetFieldValue(frame=bar, bar=2000, col=50) + SetFieldValue(frame=foo, foo=30, col=`+strconv.Itoa(SliceWidth)+`) + SetFieldValue(frame=foo, foo=10, col=`+strconv.Itoa(SliceWidth+2)+`) + SetFieldValue(frame=foo, foo=20, col=`+strconv.Itoa((5*SliceWidth)+100)+`) + SetFieldValue(frame=foo, foo=60, col=`+strconv.Itoa(SliceWidth+1)+`) + SetFieldValue(frame=other, other=1000, col=0) + SetFieldValue(frame=edge, edge=100, col=0) + SetFieldValue(frame=edge, edge=-100, col=1) `), nil, nil); err != nil { t.Fatal(err) } t.Run("EQ", func(t *testing.T) { - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo == 20)`), nil, nil); err != nil { + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=foo, foo == 20)`), nil, nil); err != nil { t.Fatal(err) } else if !reflect.DeepEqual([]uint64{50, (5 * SliceWidth) + 100}, result[0].(*pilosa.Row).Columns()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) @@ -831,19 +850,19 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { t.Run("NEQ", func(t *testing.T) { // NEQ null - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=other, foo != null)`), nil, nil); err != nil { + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=other, other != null)`), nil, nil); err != nil { t.Fatal(err) } else if !reflect.DeepEqual([]uint64{0}, result[0].(*pilosa.Row).Columns()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) } // NEQ - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo != 20)`), nil, nil); err != nil { + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=foo, foo != 20)`), nil, nil); err != nil { t.Fatal(err) } else if !reflect.DeepEqual([]uint64{SliceWidth, SliceWidth + 1, SliceWidth + 2}, result[0].(*pilosa.Row).Columns()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) } // NEQ - - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=other, foo != -20)`), nil, nil); err != nil { + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=other, other != -20)`), nil, nil); err != nil { t.Fatal(err) } else if !reflect.DeepEqual([]uint64{0}, result[0].(*pilosa.Row).Columns()) { //t.Fatalf("unexpected result: %s", spew.Sdump(result)) @@ -852,7 +871,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { }) t.Run("LT", func(t *testing.T) { - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo < 20)`), nil, nil); err != nil { + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=foo, foo < 20)`), nil, nil); err != nil { t.Fatal(err) } else if !reflect.DeepEqual([]uint64{SliceWidth + 2}, result[0].(*pilosa.Row).Columns()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) @@ -860,7 +879,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { }) t.Run("LTE", func(t *testing.T) { - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo <= 20)`), nil, nil); err != nil { + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=foo, foo <= 20)`), nil, nil); err != nil { t.Fatal(err) } else if !reflect.DeepEqual([]uint64{50, SliceWidth + 2, (5 * SliceWidth) + 100}, result[0].(*pilosa.Row).Columns()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) @@ -868,7 +887,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { }) t.Run("GT", func(t *testing.T) { - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo > 20)`), nil, nil); err != nil { + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=foo, foo > 20)`), nil, nil); err != nil { t.Fatal(err) } else if !reflect.DeepEqual([]uint64{SliceWidth, SliceWidth + 1}, result[0].(*pilosa.Row).Columns()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) @@ -876,7 +895,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { }) t.Run("GTE", func(t *testing.T) { - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo >= 20)`), nil, nil); err != nil { + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=foo, foo >= 20)`), nil, nil); err != nil { t.Fatal(err) } else if !reflect.DeepEqual([]uint64{50, SliceWidth, SliceWidth + 1, (5 * SliceWidth) + 100}, result[0].(*pilosa.Row).Columns()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) @@ -884,7 +903,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { }) t.Run("BETWEEN", func(t *testing.T) { - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=other, foo >< [1, 1000])`), nil, nil); err != nil { + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=other, other >< [1, 1000])`), nil, nil); err != nil { t.Fatal(err) } else if !reflect.DeepEqual([]uint64{0}, result[0].(*pilosa.Row).Columns()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) @@ -893,7 +912,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { // Ensure that the FieldNotNull code path gets run. t.Run("FieldNotNull", func(t *testing.T) { - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=other, foo >< [0, 1000])`), nil, nil); err != nil { + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=other, other >< [0, 1000])`), nil, nil); err != nil { t.Fatal(err) } else if !reflect.DeepEqual([]uint64{0}, result[0].(*pilosa.Row).Columns()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) @@ -901,7 +920,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { }) t.Run("BelowMin", func(t *testing.T) { - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo == 0)`), nil, nil); err != nil { + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=foo, foo == 0)`), nil, nil); err != nil { t.Fatal(err) } else if !reflect.DeepEqual([]uint64{}, result[0].(*pilosa.Row).Columns()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) @@ -909,7 +928,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { }) t.Run("AboveMax", func(t *testing.T) { - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo == 200)`), nil, nil); err != nil { + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=foo, foo == 200)`), nil, nil); err != nil { t.Fatal(err) } else if !reflect.DeepEqual([]uint64{}, result[0].(*pilosa.Row).Columns()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) @@ -917,7 +936,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { }) t.Run("LTAboveMax", func(t *testing.T) { - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=edge, foo < 200)`), nil, nil); err != nil { + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=edge, edge < 200)`), nil, nil); err != nil { t.Fatal(err) } else if !reflect.DeepEqual([]uint64{0, 1}, result[0].(*pilosa.Row).Columns()) { t.Fatalf("unexpected result: %s", spew.Sdump(result[0].(*pilosa.Row).Columns())) @@ -925,7 +944,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { }) t.Run("GTBelowMin", func(t *testing.T) { - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=edge, foo > -200)`), nil, nil); err != nil { + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=edge, edge > -200)`), nil, nil); err != nil { t.Fatal(err) } else if !reflect.DeepEqual([]uint64{0, 1}, result[0].(*pilosa.Row).Columns()) { t.Fatalf("unexpected result: %s", spew.Sdump(result[0].(*pilosa.Row).Columns())) @@ -939,7 +958,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { }) t.Run("ErrFieldNotFound", func(t *testing.T) { - if _, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, bad_field >= 20)`), nil, nil); err != pilosa.ErrFieldNotFound { + if _, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=foo, bad_field >= 20)`), nil, nil); err != pilosa.ErrFieldNotFound { t.Fatal(err) } }) diff --git a/frame.go b/frame.go index ab005edcc..1307df32d 100644 --- a/frame.go +++ b/frame.go @@ -31,12 +31,21 @@ import ( // Default frame settings. const ( + DefaultFrameType = FrameTypeSet + DefaultCacheType = CacheTypeRanked // Default ranked frame cache DefaultCacheSize = 50000 ) +// Frame types. +const ( + FrameTypeSet = "set" + FrameTypeInt = "int" + FrameTypeTime = "time" +) + // Frame represents a container for views. type Frame struct { mu sync.RWMutex @@ -53,22 +62,32 @@ type Frame struct { Stats StatsClient // Frame options. - cacheType string - cacheSize uint32 - timeQuantum TimeQuantum - fields []*Field + options FrameOptions + + fields []*oField Logger Logger } +// FrameOption is a functional option type for pilosa.Frame. +type FrameOption func(f *Frame) error + +// TODO: break these out into separate Options (not a FrameOptions object) +func OptFrameFrameOptions(o FrameOptions) FrameOption { + return func(f *Frame) error { + f.options = o + return nil + } +} + // NewFrame returns a new instance of frame. -func NewFrame(path, index, name string) (*Frame, error) { +func NewFrame(path, index, name string, opts ...FrameOption) (*Frame, error) { err := ValidateName(name) if err != nil { return nil, err } - return &Frame{ + f := &Frame{ path: path, index: index, name: name, @@ -80,13 +99,23 @@ func NewFrame(path, index, name string) (*Frame, error) { broadcaster: NopBroadcaster, Stats: NopStatsClient, - cacheType: DefaultCacheType, - cacheSize: DefaultCacheSize, - //timeQuantum - //fields + options: FrameOptions{ + Type: DefaultFrameType, + CacheType: DefaultCacheType, + CacheSize: DefaultCacheSize, + }, Logger: NopLogger, - }, nil + } + + for _, opt := range opts { + err := opt(f) + if err != nil { + return nil, errors.Wrap(err, "applying option") + } + } + + return f, nil } // Name returns the name the frame was initialized with. @@ -115,9 +144,18 @@ func (f *Frame) MaxSlice() uint64 { return max } +// Type returns the frame type. +func (f *Frame) Type() string { + f.mu.RLock() + defer f.mu.RUnlock() + return f.options.Type +} + // CacheType returns the caching mode for the frame. func (f *Frame) CacheType() string { - return f.cacheType + f.mu.RLock() + defer f.mu.RUnlock() + return f.options.CacheType } // SetCacheSize sets the cache size for ranked fames. Persists to meta file on update. @@ -127,12 +165,12 @@ func (f *Frame) SetCacheSize(v uint32) error { defer f.mu.Unlock() // Ignore if no change occurred. - if v == 0 || f.cacheSize == v { + if v == 0 || f.options.CacheSize == v { return nil } // Persist meta data to disk on change. - f.cacheSize = v + f.options.CacheSize = v if err := f.saveMeta(); err != nil { return errors.Wrap(err, "saving") } @@ -142,9 +180,9 @@ func (f *Frame) SetCacheSize(v uint32) error { // CacheSize returns the ranked frame cache size. func (f *Frame) CacheSize() uint32 { - f.mu.Lock() - v := f.cacheSize - f.mu.Unlock() + f.mu.RLock() + v := f.options.CacheSize + f.mu.RUnlock() return v } @@ -152,16 +190,7 @@ func (f *Frame) CacheSize() uint32 { func (f *Frame) Options() FrameOptions { f.mu.RLock() defer f.mu.RUnlock() - return f.options() -} - -func (f *Frame) options() FrameOptions { - return FrameOptions{ - CacheType: f.cacheType, - CacheSize: f.cacheSize, - TimeQuantum: f.timeQuantum, - Fields: f.fields, - } + return f.options } // Open opens and initializes the frame. @@ -176,6 +205,11 @@ func (f *Frame) Open() error { return errors.Wrap(err, "loading meta") } + // Apply the frame options loaded from meta. + if err := f.applyOptions(f.options); err != nil { + return errors.Wrap(err, "applying options") + } + if err := f.openViews(); err != nil { return errors.Wrap(err, "opening views") } @@ -216,7 +250,7 @@ func (f *Frame) openViews() error { name := filepath.Base(fi.Name()) view := f.newView(f.ViewPath(name), name) if err := view.Open(); err != nil { - return fmt.Errorf("open view: view=%s, err=%s", view.Name(), err) + return fmt.Errorf("opening view: view=%s, err=%s", view.Name(), err) } view.RowAttrStore = f.rowAttrStore f.views[view.Name()] = view @@ -232,10 +266,6 @@ func (f *Frame) loadMeta() error { // Read data from meta file. buf, err := ioutil.ReadFile(filepath.Join(f.path, ".meta")) if os.IsNotExist(err) { - f.cacheType = DefaultCacheType - f.cacheSize = DefaultCacheSize - f.timeQuantum = "" - //f.fields return nil } else if err != nil { return errors.Wrap(err, "reading meta") @@ -246,13 +276,12 @@ func (f *Frame) loadMeta() error { } // Copy metadata fields. - f.cacheType = pb.CacheType - if f.cacheType == "" { - f.cacheType = DefaultCacheType - } - f.cacheSize = pb.CacheSize - f.timeQuantum = TimeQuantum(pb.TimeQuantum) - f.fields = decodeFields(pb.Fields) + f.options.Type = pb.Type + f.options.CacheType = pb.CacheType + f.options.CacheSize = pb.CacheSize + f.options.Min = pb.Min + f.options.Max = pb.Max + f.options.TimeQuantum = TimeQuantum(pb.TimeQuantum) return nil } @@ -260,7 +289,7 @@ func (f *Frame) loadMeta() error { // saveMeta writes meta data for the frame. func (f *Frame) saveMeta() error { // Marshal metadata. - fo := f.options() + fo := f.options buf, err := proto.Marshal(fo.Encode()) if err != nil { return errors.Wrap(err, "marshaling") @@ -274,6 +303,60 @@ func (f *Frame) saveMeta() error { return nil } +// applyOptions configures the frame based on opt. +func (f *Frame) applyOptions(opt FrameOptions) error { + switch opt.Type { + case FrameTypeSet, "": + f.options.Type = FrameTypeSet + if opt.CacheType != "" { + f.options.CacheType = opt.CacheType + } + if opt.CacheSize != 0 { + f.options.CacheSize = opt.CacheSize + } + f.options.Min = 0 + f.options.Max = 0 + f.options.TimeQuantum = "" + case FrameTypeInt: + f.options.Type = opt.Type + f.options.CacheType = CacheTypeNone + f.options.CacheSize = 0 + f.options.Min = opt.Min + f.options.Max = opt.Max + f.options.TimeQuantum = "" + + // Create new field. + field := &oField{ + Name: f.name, + Type: FieldTypeInt, + Min: opt.Min, + Max: opt.Max, + } + // Validate field. + if err := ValidateField(field); err != nil { + return err + } + if err := f.CreateField(field); err != nil { + return errors.Wrap(err, "creating field") + } + case FrameTypeTime: + f.options.Type = opt.Type + f.options.CacheType = CacheTypeNone + f.options.CacheSize = 0 + f.options.Min = 0 + f.options.Max = 0 + // Set the time quantum. + if err := f.SetTimeQuantum(opt.TimeQuantum); err != nil { + f.Close() + return errors.Wrap(err, "setting time quantum") + } + default: + return errors.New("invalid frame type") + } + + return nil +} + // Close closes the frame and its views. func (f *Frame) Close() error { f.mu.Lock() @@ -296,7 +379,7 @@ func (f *Frame) Close() error { } // Field returns a field by name. -func (f *Frame) Field(name string) *Field { +func (f *Frame) Field(name string) *oField { f.mu.RLock() defer f.mu.RUnlock() for _, field := range f.fields { @@ -307,15 +390,8 @@ func (f *Frame) Field(name string) *Field { return nil } -// Fields returns the fields on the frame. -func (f *Frame) Fields() []*Field { - f.mu.RLock() - defer f.mu.RUnlock() - return f.fields -} - -// HasField returns true if a field exists on the frame. -func (f *Frame) HasField(name string) bool { +// hasField returns true if a field exists on the frame. +func (f *Frame) hasField(name string) bool { for _, fld := range f.fields { if fld.Name == name { return true @@ -325,7 +401,7 @@ func (f *Frame) HasField(name string) bool { } // CreateField creates a new field on the frame. -func (f *Frame) CreateField(field *Field) error { +func (f *Frame) CreateField(field *oField) error { f.mu.Lock() defer f.mu.Unlock() @@ -338,10 +414,10 @@ func (f *Frame) CreateField(field *Field) error { } // addField adds a single field to fields. -func (f *Frame) addField(field *Field) error { +func (f *Frame) addField(field *oField) error { if err := ValidateField(field); err != nil { return errors.Wrap(err, "validating field") - } else if f.HasField(field.Name) { + } else if f.hasField(field.Name) { return ErrFieldExists } @@ -356,19 +432,6 @@ func (f *Frame) addField(field *Field) error { return nil } -// GetFields returns a list of all the fields in the frame. -func (f *Frame) GetFields() ([]*Field, error) { - f.mu.RLock() - defer f.mu.RUnlock() - - err := f.loadMeta() - if err != nil { - return nil, errors.Wrap(err, "loading meta") - } - - return f.fields, nil -} - // DeleteField deletes an existing field on the schema. func (f *Frame) DeleteField(name string) error { f.mu.Lock() @@ -410,7 +473,7 @@ func (f *Frame) deleteField(name string) error { func (f *Frame) TimeQuantum() TimeQuantum { f.mu.Lock() defer f.mu.Unlock() - return f.timeQuantum + return f.options.TimeQuantum } // SetTimeQuantum sets the time quantum for the frame. @@ -424,7 +487,7 @@ func (f *Frame) SetTimeQuantum(q TimeQuantum) error { } // Update value on frame. - f.timeQuantum = q + f.options.TimeQuantum = q // Persist meta data to disk. if err := f.saveMeta(); err != nil { @@ -526,8 +589,8 @@ func (f *Frame) createViewIfNotExistsBase(name string) (*View, bool, error) { } func (f *Frame) newView(path, name string) *View { - view := NewView(path, f.index, f.name, name, f.cacheSize) - view.cacheType = f.cacheType + view := NewView(path, f.index, f.name, name, f.options.CacheSize) + view.cacheType = f.options.CacheType view.Logger = f.Logger view.RowAttrStore = f.rowAttrStore view.stats = f.Stats.WithTags(fmt.Sprintf("view:%s", name)) @@ -614,7 +677,7 @@ func (f *Frame) ClearBit(name string, rowID, colID uint64, t *time.Time) (change // Clear non-time bit. if v, err := view.ClearBit(rowID, colID); err != nil { - return changed, errors.Wrap(err, "setting on view") + return changed, errors.Wrap(err, "clearing on view") } else if v { changed = v } @@ -632,7 +695,7 @@ func (f *Frame) ClearBit(name string, rowID, colID uint64, t *time.Time) (change } if c, err := view.ClearBit(rowID, colID); err != nil { - return changed, errors.Wrapf(err, "setting on view %s", subname) + return changed, errors.Wrapf(err, "clearing on view %s", subname) } else if c { changed = true } @@ -918,7 +981,7 @@ func encodeFrames(a []*Frame) []*internal.Frame { // encodeFrame converts f into its internal representation. func encodeFrame(f *Frame) *internal.Frame { - fo := f.options() + fo := f.options return &internal.Frame{ Name: f.name, Meta: fo.Encode(), @@ -947,10 +1010,31 @@ func (p frameInfoSlice) Less(i, j int) bool { return p[i].Name < p[j].Name } // FrameOptions represents options to set when initializing a frame. type FrameOptions struct { + Type string `json:"type,omitempty"` CacheType string `json:"cacheType,omitempty"` CacheSize uint32 `json:"cacheSize,omitempty"` - TimeQuantum TimeQuantum `json:"timeQuantum,omitempty"` - Fields []*Field `json:"fields,omitempty"` + Min int64 `json:"min,omitempty"` + Max int64 `json:"max,omitempty"` + TimeQuantum TimeQuantum `json:"timeQuantum,omitempty"` // TODO: rename this Quantum? +} + +// Validate ensures that FrameOption values are valid. +func (o *FrameOptions) Validate() error { + switch o.Type { + case FrameTypeSet, "": + // TODO: cacheType, cacheSize validation + case FrameTypeInt: + if o.Min > o.Max { + return ErrInvalidFieldRange + } + case FrameTypeTime: + if o.TimeQuantum == "" || !o.TimeQuantum.Valid() { + return ErrInvalidTimeQuantum + } + default: + return errors.New("invalid frame type") + } + return nil } // Encode converts o into its internal representation. @@ -963,10 +1047,12 @@ func encodeFrameOptions(o *FrameOptions) *internal.FrameMeta { return nil } return &internal.FrameMeta{ + Type: o.Type, CacheType: o.CacheType, CacheSize: o.CacheSize, + Min: o.Min, + Max: o.Max, TimeQuantum: string(o.TimeQuantum), - Fields: encodeFields(o.Fields), } } @@ -975,10 +1061,12 @@ func decodeFrameOptions(options *internal.FrameMeta) *FrameOptions { return nil } return &FrameOptions{ + Type: options.Type, CacheType: options.CacheType, CacheSize: options.CacheSize, + Min: options.Min, + Max: options.Max, TimeQuantum: TimeQuantum(options.TimeQuantum), - Fields: decodeFields(options.Fields), } } @@ -996,8 +1084,9 @@ func IsValidFieldType(v string) bool { } } -// Field represents a range field on a frame. -type Field struct { +// TODO: finish unexporting this. also, rename it. +// oField represents a range field on a frame. +type oField struct { Name string `json:"name,omitempty"` Type string `json:"type,omitempty"` Min int64 `json:"min,omitempty"` @@ -1005,7 +1094,7 @@ type Field struct { } // BitDepth returns the number of bits required to store a value between min & max. -func (f *Field) BitDepth() uint { +func (f *oField) BitDepth() uint { for i := uint(0); i < 63; i++ { if f.Max-f.Min < (1 << i) { return i @@ -1026,7 +1115,7 @@ func (f *Field) BitDepth() uint { // In order to make this work, we effectively need to change the operator to LTE. // Executor.executeFieldRangeSlice() takes this into account and returns // `frag.FieldNotNull(field.BitDepth())` in such instances. -func (f *Field) BaseValue(op pql.Token, value int64) (baseValue uint64, outOfRange bool) { +func (f *oField) BaseValue(op pql.Token, value int64) (baseValue uint64, outOfRange bool) { if op == pql.GT || op == pql.GTE { if value > f.Max { return baseValue, true @@ -1051,7 +1140,7 @@ func (f *Field) BaseValue(op pql.Token, value int64) (baseValue uint64, outOfRan } // BaseValueBetween adjusts the min/max value to align with the range for Field. -func (f *Field) BaseValueBetween(min, max int64) (baseValueMin, baseValueMax uint64, outOfRange bool) { +func (f *oField) BaseValueBetween(min, max int64) (baseValueMin, baseValueMax uint64, outOfRange bool) { if max < f.Min || min > f.Max { return baseValueMin, baseValueMax, true } @@ -1068,7 +1157,7 @@ func (f *Field) BaseValueBetween(min, max int64) (baseValueMin, baseValueMax uin return baseValueMin, baseValueMax, false } -func ValidateField(f *Field) error { +func ValidateField(f *oField) error { if f.Name == "" { return ErrFieldNameRequired } else if !IsValidFieldType(f.Type) { @@ -1079,29 +1168,7 @@ func ValidateField(f *Field) error { return nil } -func encodeFields(a []*Field) []*internal.Field { - if len(a) == 0 { - return nil - } - other := make([]*internal.Field, len(a)) - for i := range a { - other[i] = encodeField(a[i]) - } - return other -} - -func decodeFields(a []*internal.Field) []*Field { - if len(a) == 0 { - return nil - } - other := make([]*Field, len(a)) - for i := range a { - other[i] = decodeField(a[i]) - } - return other -} - -func encodeField(f *Field) *internal.Field { +func encodeField(f *oField) *internal.Field { if f == nil { return nil } @@ -1113,11 +1180,11 @@ func encodeField(f *Field) *internal.Field { } } -func decodeField(f *internal.Field) *Field { +func decodeField(f *internal.Field) *oField { if f == nil { return nil } - return &Field{ + return &oField{ Name: f.Name, Type: f.Type, Min: f.Min, diff --git a/frame_internal_test.go b/frame_internal_test.go new file mode 100644 index 000000000..f51ad95e9 --- /dev/null +++ b/frame_internal_test.go @@ -0,0 +1,149 @@ +// Copyright 2017 Pilosa Corp. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package pilosa + +import ( + "reflect" + "testing" + + "github.com/pilosa/pilosa/pql" +) + +// Ensure a field can adjust to its baseValue. +func TestField_BaseValue(t *testing.T) { + f0 := &oField{ + Name: "f0", + Type: FieldTypeInt, + Min: -100, + Max: 900, + } + f1 := &oField{ + Name: "f1", + Type: FieldTypeInt, + Min: 0, + Max: 1000, + } + + f2 := &oField{ + Name: "f2", + Type: FieldTypeInt, + Min: 100, + Max: 1100, + } + + t.Run("Normal Condition", func(t *testing.T) { + + for _, tt := range []struct { + f *oField + op pql.Token + val int64 + expBaseValue uint64 + expOutOfRange bool + }{ + // LT + {f0, pql.LT, 5, 105, false}, + {f0, pql.LT, -8, 92, false}, + {f0, pql.LT, -108, 0, true}, + {f0, pql.LT, 1005, 1000, false}, + {f0, pql.LT, 0, 100, false}, + + {f1, pql.LT, 5, 5, false}, + {f1, pql.LT, -8, 0, true}, + {f1, pql.LT, 1005, 1000, false}, + {f1, pql.LT, 0, 0, false}, + + {f2, pql.LT, 5, 0, true}, + {f2, pql.LT, -8, 0, true}, + {f2, pql.LT, 105, 5, false}, + {f2, pql.LT, 1105, 1000, false}, + + // GT + {f0, pql.GT, -105, 0, false}, + {f0, pql.GT, 5, 105, false}, + {f0, pql.GT, 905, 0, true}, + {f0, pql.GT, 0, 100, false}, + + {f1, pql.GT, 5, 5, false}, + {f1, pql.GT, -8, 0, false}, + {f1, pql.GT, 1005, 0, true}, + {f1, pql.GT, 0, 0, false}, + + {f2, pql.GT, 5, 0, false}, + {f2, pql.GT, -8, 0, false}, + {f2, pql.GT, 105, 5, false}, + {f2, pql.GT, 1105, 0, true}, + + // EQ + {f0, pql.EQ, -105, 0, true}, + {f0, pql.EQ, 5, 105, false}, + {f0, pql.EQ, 905, 0, true}, + {f0, pql.EQ, 0, 100, false}, + + {f1, pql.EQ, 5, 5, false}, + {f1, pql.EQ, -8, 0, true}, + {f1, pql.EQ, 1005, 0, true}, + {f1, pql.EQ, 0, 0, false}, + + {f2, pql.EQ, 5, 0, true}, + {f2, pql.EQ, -8, 0, true}, + {f2, pql.EQ, 105, 5, false}, + {f2, pql.EQ, 1105, 0, true}, + } { + bv, oor := tt.f.BaseValue(tt.op, tt.val) + if oor != tt.expOutOfRange { + t.Fatalf("baseValue calculation on %s op %s, expected outOfRange %v, got %v", tt.f.Name, tt.op, tt.expOutOfRange, oor) + } else if !reflect.DeepEqual(bv, tt.expBaseValue) { + t.Fatalf("baseValue calculation on %s, expected value %v, got %v", tt.f.Name, tt.expBaseValue, bv) + } + } + }) + + t.Run("Betwween Condition", func(t *testing.T) { + for _, tt := range []struct { + f *oField + predMin int64 + predMax int64 + expBaseValueMin uint64 + expBaseValueMax uint64 + expOutOfRange bool + }{ + + {f0, -205, -105, 0, 0, true}, + {f0, -105, 80, 0, 180, false}, + {f0, 5, 20, 105, 120, false}, + {f0, 20, 1005, 120, 1000, false}, + {f0, 1005, 2000, 0, 0, true}, + + {f1, -105, -5, 0, 0, true}, + {f1, -5, 20, 0, 20, false}, + {f1, 5, 20, 5, 20, false}, + {f1, 20, 1005, 20, 1000, false}, + {f1, 1005, 2000, 0, 0, true}, + + {f2, 5, 95, 0, 0, true}, + {f2, 95, 120, 0, 20, false}, + {f2, 105, 120, 5, 20, false}, + {f2, 120, 1105, 20, 1000, false}, + {f2, 1105, 2000, 0, 0, true}, + } { + min, max, oor := tt.f.BaseValueBetween(tt.predMin, tt.predMax) + if oor != tt.expOutOfRange { + t.Fatalf("baseValueBetween calculation on %s, expected outOfRange %v, got %v", tt.f.Name, tt.expOutOfRange, oor) + } else if !reflect.DeepEqual(min, tt.expBaseValueMin) || !reflect.DeepEqual(max, tt.expBaseValueMax) { + t.Fatalf("baseValueBetween calculation on %s, expected min/max %v/%v, got %v/%v", tt.f.Name, tt.expBaseValueMin, tt.expBaseValueMax, min, max) + } + } + }) +} diff --git a/frame_test.go b/frame_test.go index 78014bbce..8ad9b020a 100644 --- a/frame_test.go +++ b/frame_test.go @@ -16,11 +16,9 @@ package pilosa_test import ( "io/ioutil" - "reflect" "testing" "github.com/pilosa/pilosa" - "github.com/pilosa/pilosa/pql" "github.com/pilosa/pilosa/test" ) @@ -52,7 +50,10 @@ func TestFrame_CreateViewIfNotExists(t *testing.T) { // Ensure frame can set its time quantum. func TestFrame_SetTimeQuantum(t *testing.T) { - f := test.MustOpenFrame() + fo := pilosa.FrameOptions{ + Type: "time", + } + f := test.MustOpenFrame(pilosa.OptFrameFrameOptions(fo)) defer f.Close() // Set & retrieve time quantum. @@ -77,31 +78,23 @@ func TestFrame_SetFieldValue(t *testing.T) { defer idx.Close() f, err := idx.CreateFrame("f", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "field0", Type: pilosa.FieldTypeInt, Min: 0, Max: 30}, - {Name: "field1", Type: pilosa.FieldTypeInt, Min: 20, Max: 25}, - }, + Type: pilosa.FrameTypeInt, + Min: 0, + Max: 30, }) if err != nil { t.Fatal(err) } - // Set value on first field. - if changed, err := f.SetFieldValue(100, "field0", 21); err != nil { - t.Fatal(err) - } else if !changed { - t.Fatal("expected change") - } - - // Set value on same column but different field. - if changed, err := f.SetFieldValue(100, "field1", 25); err != nil { + // Set value on field. + if changed, err := f.SetFieldValue(100, "f", 21); err != nil { t.Fatal(err) } else if !changed { t.Fatal("expected change") } // Read value. - if value, exists, err := f.FieldValue(100, "field0"); err != nil { + if value, exists, err := f.FieldValue(100, "f"); err != nil { t.Fatal(err) } else if value != 21 { t.Fatalf("unexpected value: %d", value) @@ -110,7 +103,7 @@ func TestFrame_SetFieldValue(t *testing.T) { } // Setting value should return no change. - if changed, err := f.SetFieldValue(100, "field0", 21); err != nil { + if changed, err := f.SetFieldValue(100, "f", 21); err != nil { t.Fatal(err) } else if changed { t.Fatal("expected no change") @@ -122,30 +115,30 @@ func TestFrame_SetFieldValue(t *testing.T) { defer idx.Close() f, err := idx.CreateFrame("f", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "field0", Type: pilosa.FieldTypeInt, Min: 0, Max: 30}, - }, + Type: pilosa.FrameTypeInt, + Min: 0, + Max: 30, }) if err != nil { t.Fatal(err) } // Set value. - if changed, err := f.SetFieldValue(100, "field0", 21); err != nil { + if changed, err := f.SetFieldValue(100, "f", 21); err != nil { t.Fatal(err) } else if !changed { t.Fatal("expected change") } // Set different value. - if changed, err := f.SetFieldValue(100, "field0", 23); err != nil { + if changed, err := f.SetFieldValue(100, "f", 23); err != nil { t.Fatal(err) } else if !changed { t.Fatal("expected change") } // Read value. - if value, exists, err := f.FieldValue(100, "field0"); err != nil { + if value, exists, err := f.FieldValue(100, "f"); err != nil { t.Fatal(err) } else if value != 23 { t.Fatalf("unexpected value: %d", value) @@ -159,9 +152,9 @@ func TestFrame_SetFieldValue(t *testing.T) { defer idx.Close() f, err := idx.CreateFrame("f", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "field0", Type: pilosa.FieldTypeInt, Min: 0, Max: 30}, - }, + Type: pilosa.FrameTypeInt, + Min: 0, + Max: 30, }) if err != nil { t.Fatal(err) @@ -178,16 +171,16 @@ func TestFrame_SetFieldValue(t *testing.T) { defer idx.Close() f, err := idx.CreateFrame("f", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "field0", Type: pilosa.FieldTypeInt, Min: 20, Max: 30}, - }, + Type: pilosa.FrameTypeInt, + Min: 20, + Max: 30, }) if err != nil { t.Fatal(err) } // Set value. - if _, err := f.SetFieldValue(100, "field0", 15); err != pilosa.ErrFieldValueTooLow { + if _, err := f.SetFieldValue(100, "f", 15); err != pilosa.ErrFieldValueTooLow { t.Fatalf("unexpected error: %s", err) } }) @@ -197,16 +190,16 @@ func TestFrame_SetFieldValue(t *testing.T) { defer idx.Close() f, err := idx.CreateFrame("f", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "field0", Type: pilosa.FieldTypeInt, Min: 20, Max: 30}, - }, + Type: pilosa.FrameTypeInt, + Min: 20, + Max: 30, }) if err != nil { t.Fatal(err) } // Set value. - if _, err := f.SetFieldValue(100, "field0", 31); err != pilosa.ErrFieldValueTooHigh { + if _, err := f.SetFieldValue(100, "f", 31); err != pilosa.ErrFieldValueTooHigh { t.Fatalf("unexpected error: %s", err) } }) @@ -294,130 +287,3 @@ func TestFrame_DeleteView(t *testing.T) { t.Fatal("failed to create new view") } } - -// Ensure a field can adjust to its baseValue. -func TestField_BaseValue(t *testing.T) { - f0 := &pilosa.Field{ - Name: "f0", - Type: pilosa.FieldTypeInt, - Min: -100, - Max: 900, - } - f1 := &pilosa.Field{ - Name: "f1", - Type: pilosa.FieldTypeInt, - Min: 0, - Max: 1000, - } - - f2 := &pilosa.Field{ - Name: "f2", - Type: pilosa.FieldTypeInt, - Min: 100, - Max: 1100, - } - - t.Run("Normal Condition", func(t *testing.T) { - - for _, tt := range []struct { - f *pilosa.Field - op pql.Token - val int64 - expBaseValue uint64 - expOutOfRange bool - }{ - // LT - {f0, pql.LT, 5, 105, false}, - {f0, pql.LT, -8, 92, false}, - {f0, pql.LT, -108, 0, true}, - {f0, pql.LT, 1005, 1000, false}, - {f0, pql.LT, 0, 100, false}, - - {f1, pql.LT, 5, 5, false}, - {f1, pql.LT, -8, 0, true}, - {f1, pql.LT, 1005, 1000, false}, - {f1, pql.LT, 0, 0, false}, - - {f2, pql.LT, 5, 0, true}, - {f2, pql.LT, -8, 0, true}, - {f2, pql.LT, 105, 5, false}, - {f2, pql.LT, 1105, 1000, false}, - - // GT - {f0, pql.GT, -105, 0, false}, - {f0, pql.GT, 5, 105, false}, - {f0, pql.GT, 905, 0, true}, - {f0, pql.GT, 0, 100, false}, - - {f1, pql.GT, 5, 5, false}, - {f1, pql.GT, -8, 0, false}, - {f1, pql.GT, 1005, 0, true}, - {f1, pql.GT, 0, 0, false}, - - {f2, pql.GT, 5, 0, false}, - {f2, pql.GT, -8, 0, false}, - {f2, pql.GT, 105, 5, false}, - {f2, pql.GT, 1105, 0, true}, - - // EQ - {f0, pql.EQ, -105, 0, true}, - {f0, pql.EQ, 5, 105, false}, - {f0, pql.EQ, 905, 0, true}, - {f0, pql.EQ, 0, 100, false}, - - {f1, pql.EQ, 5, 5, false}, - {f1, pql.EQ, -8, 0, true}, - {f1, pql.EQ, 1005, 0, true}, - {f1, pql.EQ, 0, 0, false}, - - {f2, pql.EQ, 5, 0, true}, - {f2, pql.EQ, -8, 0, true}, - {f2, pql.EQ, 105, 5, false}, - {f2, pql.EQ, 1105, 0, true}, - } { - bv, oor := tt.f.BaseValue(tt.op, tt.val) - if oor != tt.expOutOfRange { - t.Fatalf("baseValue calculation on %s op %s, expected outOfRange %v, got %v", tt.f.Name, tt.op, tt.expOutOfRange, oor) - } else if !reflect.DeepEqual(bv, tt.expBaseValue) { - t.Fatalf("baseValue calculation on %s, expected value %v, got %v", tt.f.Name, tt.expBaseValue, bv) - } - } - }) - - t.Run("Betwween Condition", func(t *testing.T) { - for _, tt := range []struct { - f *pilosa.Field - predMin int64 - predMax int64 - expBaseValueMin uint64 - expBaseValueMax uint64 - expOutOfRange bool - }{ - - {f0, -205, -105, 0, 0, true}, - {f0, -105, 80, 0, 180, false}, - {f0, 5, 20, 105, 120, false}, - {f0, 20, 1005, 120, 1000, false}, - {f0, 1005, 2000, 0, 0, true}, - - {f1, -105, -5, 0, 0, true}, - {f1, -5, 20, 0, 20, false}, - {f1, 5, 20, 5, 20, false}, - {f1, 20, 1005, 20, 1000, false}, - {f1, 1005, 2000, 0, 0, true}, - - {f2, 5, 95, 0, 0, true}, - {f2, 95, 120, 0, 20, false}, - {f2, 105, 120, 5, 20, false}, - {f2, 120, 1105, 20, 1000, false}, - {f2, 1105, 2000, 0, 0, true}, - } { - min, max, oor := tt.f.BaseValueBetween(tt.predMin, tt.predMax) - if oor != tt.expOutOfRange { - t.Fatalf("baseValueBetween calculation on %s, expected outOfRange %v, got %v", tt.f.Name, tt.expOutOfRange, oor) - } else if !reflect.DeepEqual(min, tt.expBaseValueMin) || !reflect.DeepEqual(max, tt.expBaseValueMax) { - t.Fatalf("baseValueBetween calculation on %s, expected min/max %v/%v, got %v/%v", tt.f.Name, tt.expBaseValueMin, tt.expBaseValueMax, min, max) - } - } - }) -} diff --git a/handler.go b/handler.go index 9ddabaeeb..d4ed5ab37 100644 --- a/handler.go +++ b/handler.go @@ -169,9 +169,6 @@ func NewRouter(handler *Handler) *mux.Router { router.HandleFunc("/index/{index}/frame/{frame}", handler.handlePostFrame).Methods("POST") router.HandleFunc("/index/{index}/frame/{frame}", handler.handleDeleteFrame).Methods("DELETE") router.HandleFunc("/index/{index}/frame/{frame}/attr/diff", handler.handlePostFrameAttrDiff).Methods("POST") - router.HandleFunc("/index/{index}/frame/{frame}/field/{field}", handler.handlePostFrameField).Methods("POST") - router.HandleFunc("/index/{index}/frame/{frame}/fields", handler.handleGetFrameFields).Methods("GET") - router.HandleFunc("/index/{index}/frame/{frame}/field/{field}", handler.handleDeleteFrameField).Methods("DELETE") router.HandleFunc("/index/{index}/query", handler.handlePostQuery).Methods("POST").Name("PostQuery") router.HandleFunc("/recalculate-caches", handler.handleRecalculateCaches).Methods("POST") @@ -608,99 +605,6 @@ func (h *Handler) handleDeleteFrame(w http.ResponseWriter, r *http.Request) { type deleteFrameResponse struct{} -// handlePostFrameField handles POST /frame/field request. -func (h *Handler) handlePostFrameField(w http.ResponseWriter, r *http.Request) { - indexName := mux.Vars(r)["index"] - frameName := mux.Vars(r)["frame"] - fieldName := mux.Vars(r)["field"] - - // Decode request. - var req postFrameFieldRequest - if err := json.NewDecoder(r.Body).Decode(&req); err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - - field := &Field{ - Name: fieldName, - Type: req.Type, - Min: req.Min, - Max: req.Max, - } - - if err := h.API.CreateField(r.Context(), indexName, frameName, field); err != nil { - if errors.Cause(err) == ErrFrameNotFound { - http.Error(w, err.Error(), http.StatusNotFound) - } else { - http.Error(w, err.Error(), http.StatusInternalServerError) - } - return - } - - // Encode response. - if err := json.NewEncoder(w).Encode(postFrameFieldResponse{}); err != nil { - h.Logger.Printf("response encoding error: %s", err) - } -} - -type postFrameFieldRequest struct { - Type string `json:"type,omitempty"` - Min int64 `json:"min,omitempty"` - Max int64 `json:"max,omitempty"` -} - -type postFrameFieldResponse struct{} - -// handleDeleteFrameField handles DELETE /frame/field request. -func (h *Handler) handleDeleteFrameField(w http.ResponseWriter, r *http.Request) { - indexName := mux.Vars(r)["index"] - frameName := mux.Vars(r)["frame"] - fieldName := mux.Vars(r)["field"] - - if err := h.API.DeleteField(r.Context(), indexName, frameName, fieldName); err != nil { - if errors.Cause(err) == ErrFrameNotFound { - http.Error(w, err.Error(), http.StatusNotFound) - } else { - http.Error(w, err.Error(), http.StatusInternalServerError) - } - return - } - - // Encode response. - if err := json.NewEncoder(w).Encode(deleteFrameFieldResponse{}); err != nil { - h.Logger.Printf("response encoding error: %s", err) - } -} - -func (h *Handler) handleGetFrameFields(w http.ResponseWriter, r *http.Request) { - indexName := mux.Vars(r)["index"] - frameName := mux.Vars(r)["frame"] - - fields, err := h.API.Fields(r.Context(), indexName, frameName) - if err != nil { - switch errors.Cause(err) { - case ErrIndexNotFound: - fallthrough - case ErrFrameNotFound: - http.Error(w, err.Error(), http.StatusNotFound) - default: - http.Error(w, err.Error(), http.StatusInternalServerError) - } - return - } - - // Encode response. - if err := json.NewEncoder(w).Encode(getFrameFieldsResponse{Fields: fields}); err != nil { - h.Logger.Printf("response encoding error: %s", err) - } -} - -type getFrameFieldsResponse struct { - Fields []*Field `json:"fields,omitempty"` -} - -type deleteFrameFieldResponse struct{} - // handlePostFrameAttrDiff handles POST /frame/attr/diff requests. func (h *Handler) handlePostFrameAttrDiff(w http.ResponseWriter, r *http.Request) { indexName := mux.Vars(r)["index"] diff --git a/handler_test.go b/handler_test.go index a7ba8fa85..30bba9254 100644 --- a/handler_test.go +++ b/handler_test.go @@ -17,7 +17,6 @@ package pilosa_test import ( "bytes" "context" - "encoding/json" "errors" "fmt" "io" @@ -817,245 +816,6 @@ func TestHandler_Frame_AttrStore_Diff(t *testing.T) { } } -// Ensure the handler can create a new field on an existing frame. -func TestHandler_Frame_AddField(t *testing.T) { - hldr := test.MustOpenHolder() - defer hldr.Close() - - s := test.NewServer() - s.Handler.API.Holder = hldr.Holder - defer s.Close() - - t.Run("OK", func(t *testing.T) { - idx := hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{}) - f, err := idx.CreateFrameIfNotExists("f", pilosa.FrameOptions{}) - if err != nil { - t.Fatal(err) - } - - resp, err := http.Post( - s.URL+"/index/i/frame/f/field/x", - "application/json", - strings.NewReader(`{"type":"int","min":100,"max":200}`), - ) - if err != nil { - t.Fatal(err) - } else if err := resp.Body.Close(); err != nil { - t.Fatal(err) - } else if resp.StatusCode != http.StatusOK { - t.Fatalf("unexpected status code: %d", resp.StatusCode) - } - - if field := f.Field("x"); !reflect.DeepEqual(field, &pilosa.Field{Name: "x", Type: "int", Min: 100, Max: 200}) { - t.Fatalf("unexpected field: %#v", field) - } - }) - - t.Run("ErrInvalidFieldType", func(t *testing.T) { - idx := hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{}) - if _, err := idx.CreateFrameIfNotExists("f", pilosa.FrameOptions{}); err != nil { - t.Fatal(err) - } - - resp, err := http.Post( - s.URL+"/index/i/frame/f/field/x", - "application/json", - strings.NewReader(`{"type":"bad_type","min":100,"max":200}`), - ) - if err != nil { - t.Fatal(err) - } else if body := MustReadAll(resp.Body); string(body) != `creating field: validating field: invalid field type`+"\n" { - t.Fatalf("unexpected body: %q", body) - } else if err := resp.Body.Close(); err != nil { - t.Fatal(err) - } else if resp.StatusCode != http.StatusInternalServerError { - t.Fatalf("unexpected status code: %d", resp.StatusCode) - } - }) - - t.Run("ErrInvalidFieldRange", func(t *testing.T) { - idx := hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{}) - if _, err := idx.CreateFrameIfNotExists("f", pilosa.FrameOptions{}); err != nil { - t.Fatal(err) - } - - resp, err := http.Post( - s.URL+"/index/i/frame/f/field/x", - "application/json", - strings.NewReader(`{"type":"int","min":200,"max":100}`), - ) - if err != nil { - t.Fatal(err) - } else if body := MustReadAll(resp.Body); string(body) != `creating field: validating field: invalid field range`+"\n" { - t.Fatalf("unexpected body: %q", body) - } else if err := resp.Body.Close(); err != nil { - t.Fatal(err) - } else if resp.StatusCode != http.StatusInternalServerError { - t.Fatalf("unexpected status code: %d", resp.StatusCode) - } - }) - - t.Run("ErrFieldAlreadyExists", func(t *testing.T) { - idx := hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{}) - if _, err := idx.CreateFrameIfNotExists("f", pilosa.FrameOptions{ - Fields: []*pilosa.Field{{Name: "x", Type: pilosa.FieldTypeInt, Min: 0, Max: 100}}, - }); err != nil { - t.Fatal(err) - } - - resp, err := http.Post( - s.URL+"/index/i/frame/f/field/x", - "application/json", - strings.NewReader(`{"type":"int","min":0,"max":100}`), - ) - if err != nil { - t.Fatal(err) - } else if body := MustReadAll(resp.Body); string(body) != `creating field: field already exists`+"\n" { - t.Fatalf("unexpected body: %q", body) - } else if err := resp.Body.Close(); err != nil { - t.Fatal(err) - } else if resp.StatusCode != http.StatusInternalServerError { - t.Fatalf("unexpected status code: %d", resp.StatusCode) - } - }) -} - -// Ensure the handler can delete existing fields. -func TestHandler_Frame_DeleteField(t *testing.T) { - hldr := test.MustOpenHolder() - defer hldr.Close() - - s := test.NewServer() - s.Handler.API.Holder = hldr.Holder - defer s.Close() - - t.Run("OK", func(t *testing.T) { - idx := hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{}) - f, err := idx.CreateFrameIfNotExists("f", pilosa.FrameOptions{}) - if err != nil { - t.Fatal(err) - } else if err := f.CreateField(&pilosa.Field{Name: "x", Type: pilosa.FieldTypeInt, Min: 0, Max: 100}); err != nil { - t.Fatal(err) - } - - req, err := http.NewRequest("DELETE", s.URL+"/index/i/frame/f/field/x", nil) - if err != nil { - t.Fatal(err) - } - - resp, err := http.DefaultClient.Do(req) - if err != nil { - t.Fatal(err) - } else if err := resp.Body.Close(); err != nil { - t.Fatal(err) - } else if resp.StatusCode != http.StatusOK { - t.Fatalf("unexpected status code: %d", resp.StatusCode) - } - - if field := f.Field("x"); field != nil { - t.Fatalf("expected nil field, got: %#v", field) - } - }) - - t.Run("ErrFieldNotFound", func(t *testing.T) { - idx := hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{}) - f, err := idx.CreateFrameIfNotExists("f", pilosa.FrameOptions{}) - if err != nil { - t.Fatal(err) - } else if err := f.CreateField(&pilosa.Field{Name: "x", Type: pilosa.FieldTypeInt, Min: 0, Max: 100}); err != nil { - t.Fatal(err) - } - - req, err := http.NewRequest("DELETE", s.URL+"/index/i/frame/f/field/y", nil) - if err != nil { - t.Fatal(err) - } - - resp, err := http.DefaultClient.Do(req) - if err != nil { - t.Fatal(err) - } else if body, err := ioutil.ReadAll(resp.Body); err != nil { - t.Fatal(err) - } else if strings.TrimSpace(string(body)) != `deleting field: field not found` { - t.Fatalf("unexpected body: %q", body) - } else if err := resp.Body.Close(); err != nil { - t.Fatal(err) - } else if resp.StatusCode != http.StatusInternalServerError { - t.Fatalf("unexpected status code: %d", resp.StatusCode) - } - }) -} - -func TestHandler_Frame_GetFields(t *testing.T) { - hldr := test.MustOpenHolder() - defer hldr.Close() - - s := test.NewServer() - s.Handler.API.Holder = hldr.Holder - defer s.Close() - - t.Run("OK", func(t *testing.T) { - idx := hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{}) - f, err := idx.CreateFrameIfNotExists("f", pilosa.FrameOptions{}) - if err != nil { - t.Fatal(err) - } else if err := f.CreateField(&pilosa.Field{Name: "x", Type: pilosa.FieldTypeInt, Min: 1, Max: 100}); err != nil { - t.Fatal(err) - } - resp, err := http.Get(s.URL + "/index/i/frame/f/fields") - if err != nil { - t.Fatal(err) - } else if resp.StatusCode != http.StatusOK { - t.Fatalf("unexpected status code: %d", resp.StatusCode) - } - - var fields FrameFields - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - t.Fatal(err) - } - if err = json.Unmarshal([]byte(body), &fields); err != nil { - t.Fatal(err) - } - field := fields.Fields[0] - if field.Name != "x" { - t.Fatalf("expected field's name: x, actuall name: %v", field.Name) - } else if field.Min != 1 { - t.Fatalf("expected field's min: x, actuall min: %v", field.Min) - } else if field.Max != 100 { - t.Fatalf("expected field's max: x, actuall max: %v", field.Max) - } - - }) - - t.Run("ErrFrameFieldNotAllowed", func(t *testing.T) { - idx := hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{}) - _, err := idx.CreateFrameIfNotExists("f1", pilosa.FrameOptions{}) - if err != nil { - t.Fatalf("creating frame: %v", err) - } - - resp, err := http.Get(s.URL + "/index/i/frame/f1/fields") - if err != nil { - t.Fatal(err) - } - if err != nil { - t.Fatal(err) - } else if resp.StatusCode != http.StatusOK { - t.Fatalf("unexpected status code: %d", resp.StatusCode) - } else if body, err := ioutil.ReadAll(resp.Body); err != nil { - t.Fatal(err) - } else if strings.TrimSpace(string(body)) == `frame fields not allowed` { - t.Fatalf("shouldn't get frame fields not allowed error: %q", body) - } - }) - -} - -type FrameFields struct { - Fields []pilosa.Field -} - // Ensure the handler can retrieve the version. func TestHandler_Version(t *testing.T) { hldr := test.MustOpenHolder() diff --git a/index.go b/index.go index 534930cd5..7829903aa 100644 --- a/index.go +++ b/index.go @@ -299,11 +299,9 @@ func (i *Index) createFrame(name string, opt FrameOptions) (*Frame, error) { return nil, ErrInvalidCacheType } - // Validate fields. - for _, field := range opt.Fields { - if err := ValidateField(field); err != nil { - return nil, err - } + // Validate options. + if err := opt.Validate(); err != nil { + return nil, errors.Wrap(err, "validating options") } // Initialize frame. @@ -317,25 +315,12 @@ func (i *Index) createFrame(name string, opt FrameOptions) (*Frame, error) { return nil, errors.Wrap(err, "opening") } - // Set the time quantum. - if err := f.SetTimeQuantum(opt.TimeQuantum); err != nil { + // Apply frame options. + if err := f.applyOptions(opt); err != nil { f.Close() - return nil, errors.Wrap(err, "setting time quantum") + return nil, errors.Wrap(err, "applying options") } - // Set cache type. - if opt.CacheType == "" { - opt.CacheType = DefaultCacheType - } - f.cacheType = opt.CacheType - - if opt.CacheSize != 0 { - f.cacheSize = opt.CacheSize - } - - // Set fields. - f.fields = opt.Fields - if err := f.saveMeta(); err != nil { f.Close() return nil, errors.Wrap(err, "saving meta") diff --git a/index_test.go b/index_test.go index 0a42804e2..3a4ee48bc 100644 --- a/index_test.go +++ b/index_test.go @@ -57,7 +57,10 @@ func TestIndex_CreateFrame(t *testing.T) { defer index.Close() // Create frame with explicit quantum. - f, err := index.CreateFrame("f", pilosa.FrameOptions{TimeQuantum: pilosa.TimeQuantum("YMDH")}) + f, err := index.CreateFrame("f", pilosa.FrameOptions{ + Type: pilosa.FrameTypeTime, + TimeQuantum: pilosa.TimeQuantum("YMDH"), + }) if err != nil { t.Fatal(err) } else if q := f.TimeQuantum(); q != pilosa.TimeQuantum("YMDH") { @@ -74,103 +77,100 @@ func TestIndex_CreateFrame(t *testing.T) { // Create frame with schema and verify it exists. if f, err := index.CreateFrame("f", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "field0", Type: pilosa.FieldTypeInt, Min: 10, Max: 20}, - {Name: "field1", Type: pilosa.FieldTypeInt, Min: 11, Max: 21}, - }, + Type: pilosa.FrameTypeInt, + Min: 10, + Max: 20, }); err != nil { t.Fatal(err) - } else if !reflect.DeepEqual(f.Fields(), []*pilosa.Field{ - {Name: "field0", Type: pilosa.FieldTypeInt, Min: 10, Max: 20}, - {Name: "field1", Type: pilosa.FieldTypeInt, Min: 11, Max: 21}, - }) { - t.Fatalf("unexpected fields: %#v", f.Fields()) + } else if !reflect.DeepEqual(f.Type(), pilosa.FrameTypeInt) { + t.Fatalf("unexpected type: %#v", f.Type()) } // Reopen the index & verify the fields are loaded. if err := index.Reopen(); err != nil { t.Fatal(err) - } else if f := index.Frame("f"); !reflect.DeepEqual(f.Fields(), []*pilosa.Field{ - {Name: "field0", Type: pilosa.FieldTypeInt, Min: 10, Max: 20}, - {Name: "field1", Type: pilosa.FieldTypeInt, Min: 11, Max: 21}, - }) { - t.Fatalf("unexpected fields after reopen: %#v", f.Fields()) + } else if f := index.Frame("f"); !reflect.DeepEqual(f.Type(), pilosa.FrameTypeInt) { + t.Fatalf("unexpected type after reopen: %#v", f.Type()) } }) - t.Run("ErrRangeCacheAllowed", func(t *testing.T) { - index := test.MustOpenIndex() - defer index.Close() + // TODO: These errors don't apply here. Instead, we need these tests + // on frame creation FrameOptions validation. + /* + t.Run("ErrRangeCacheAllowed", func(t *testing.T) { + index := test.MustOpenIndex() + defer index.Close() - if _, err := index.CreateFrame("f", pilosa.FrameOptions{ - CacheType: pilosa.CacheTypeRanked, - }); err != nil { - t.Fatal(err) - } - }) + if _, err := index.CreateFrame("f", pilosa.FrameOptions{ + CacheType: pilosa.CacheTypeRanked, + }); err != nil { + t.Fatal(err) + } + }) - t.Run("BSIFieldsWithCacheTypeNone", func(t *testing.T) { - index := test.MustOpenIndex() - defer index.Close() - if _, err := index.CreateFrame("f", pilosa.FrameOptions{ - CacheType: pilosa.CacheTypeNone, - CacheSize: uint32(5), - }); err != nil { - t.Fatal(err) - } - }) + t.Run("BSIFieldsWithCacheTypeNone", func(t *testing.T) { + index := test.MustOpenIndex() + defer index.Close() + if _, err := index.CreateFrame("f", pilosa.FrameOptions{ + CacheType: pilosa.CacheTypeNone, + CacheSize: uint32(5), + }); err != nil { + t.Fatal(err) + } + }) - t.Run("ErrFrameFieldsAllowed", func(t *testing.T) { - index := test.MustOpenIndex() - defer index.Close() + t.Run("ErrFrameFieldsAllowed", func(t *testing.T) { + index := test.MustOpenIndex() + defer index.Close() - if _, err := index.CreateFrame("f", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "field0", Type: pilosa.FieldTypeInt}, - }, - }); err != nil { - t.Fatal(err) - } - }) + if _, err := index.CreateFrame("f", pilosa.FrameOptions{ + Fields: []*pilosa.Field{ + {Name: "field0", Type: pilosa.FieldTypeInt}, + }, + }); err != nil { + t.Fatal(err) + } + }) - t.Run("ErrFieldNameRequired", func(t *testing.T) { - index := test.MustOpenIndex() - defer index.Close() + t.Run("ErrFieldNameRequired", func(t *testing.T) { + index := test.MustOpenIndex() + defer index.Close() - if _, err := index.CreateFrame("f", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "", Type: pilosa.FieldTypeInt}, - }, - }); err != pilosa.ErrFieldNameRequired { - t.Fatal(err) - } - }) + if _, err := index.CreateFrame("f", pilosa.FrameOptions{ + Fields: []*pilosa.Field{ + {Name: "", Type: pilosa.FieldTypeInt}, + }, + }); err != pilosa.ErrFieldNameRequired { + t.Fatal(err) + } + }) - t.Run("ErrInvalidFieldType", func(t *testing.T) { - index := test.MustOpenIndex() - defer index.Close() + t.Run("ErrInvalidFieldType", func(t *testing.T) { + index := test.MustOpenIndex() + defer index.Close() - if _, err := index.CreateFrame("f", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "field0", Type: "bad_type"}, - }, - }); err != pilosa.ErrInvalidFieldType { - t.Fatal(err) - } - }) + if _, err := index.CreateFrame("f", pilosa.FrameOptions{ + Fields: []*pilosa.Field{ + {Name: "field0", Type: "bad_type"}, + }, + }); err != pilosa.ErrInvalidFieldType { + t.Fatal(err) + } + }) - t.Run("ErrInvalidFieldRange", func(t *testing.T) { - index := test.MustOpenIndex() - defer index.Close() + t.Run("ErrInvalidFieldRange", func(t *testing.T) { + index := test.MustOpenIndex() + defer index.Close() - if _, err := index.CreateFrame("f", pilosa.FrameOptions{ - Fields: []*pilosa.Field{ - {Name: "field0", Type: pilosa.FieldTypeInt, Min: 100, Max: 50}, - }, - }); err != pilosa.ErrInvalidFieldRange { - t.Fatal(err) - } - }) + if _, err := index.CreateFrame("f", pilosa.FrameOptions{ + Fields: []*pilosa.Field{ + {Name: "field0", Type: pilosa.FieldTypeInt, Min: 100, Max: 50}, + }, + }); err != pilosa.ErrInvalidFieldRange { + t.Fatal(err) + } + }) + */ }) } diff --git a/internal/private.pb.go b/internal/private.pb.go index 35b452dce..20909445c 100644 --- a/internal/private.pb.go +++ b/internal/private.pb.go @@ -1,5 +1,6 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. +// Code generated by protoc-gen-gogo. // source: private.proto +// DO NOT EDIT! /* Package internal is a generated protocol buffer package. @@ -70,10 +71,12 @@ func (*IndexMeta) ProtoMessage() {} func (*IndexMeta) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{0} } type FrameMeta struct { - CacheType string `protobuf:"bytes,3,opt,name=CacheType,proto3" json:"CacheType,omitempty"` - CacheSize uint32 `protobuf:"varint,4,opt,name=CacheSize,proto3" json:"CacheSize,omitempty"` - TimeQuantum string `protobuf:"bytes,5,opt,name=TimeQuantum,proto3" json:"TimeQuantum,omitempty"` - Fields []*Field `protobuf:"bytes,7,rep,name=Fields" json:"Fields,omitempty"` + Type string `protobuf:"bytes,8,opt,name=Type,proto3" json:"Type,omitempty"` + CacheType string `protobuf:"bytes,3,opt,name=CacheType,proto3" json:"CacheType,omitempty"` + CacheSize uint32 `protobuf:"varint,4,opt,name=CacheSize,proto3" json:"CacheSize,omitempty"` + Min int64 `protobuf:"varint,9,opt,name=Min,proto3" json:"Min,omitempty"` + Max int64 `protobuf:"varint,10,opt,name=Max,proto3" json:"Max,omitempty"` + TimeQuantum string `protobuf:"bytes,5,opt,name=TimeQuantum,proto3" json:"TimeQuantum,omitempty"` } func (m *FrameMeta) Reset() { *m = FrameMeta{} } @@ -81,6 +84,13 @@ func (m *FrameMeta) String() string { return proto.CompactTextString( func (*FrameMeta) ProtoMessage() {} func (*FrameMeta) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{1} } +func (m *FrameMeta) GetType() string { + if m != nil { + return m.Type + } + return "" +} + func (m *FrameMeta) GetCacheType() string { if m != nil { return m.CacheType @@ -95,6 +105,20 @@ func (m *FrameMeta) GetCacheSize() uint32 { return 0 } +func (m *FrameMeta) GetMin() int64 { + if m != nil { + return m.Min + } + return 0 +} + +func (m *FrameMeta) GetMax() int64 { + if m != nil { + return m.Max + } + return 0 +} + func (m *FrameMeta) GetTimeQuantum() string { if m != nil { return m.TimeQuantum @@ -102,13 +126,6 @@ func (m *FrameMeta) GetTimeQuantum() string { return "" } -func (m *FrameMeta) GetFields() []*Field { - if m != nil { - return m.Fields - } - return nil -} - type ImportResponse struct { Err string `protobuf:"bytes,1,opt,name=Err,proto3" json:"Err,omitempty"` } @@ -1052,17 +1069,21 @@ func (m *FrameMeta) MarshalTo(dAtA []byte) (int, error) { i = encodeVarintPrivate(dAtA, i, uint64(len(m.TimeQuantum))) i += copy(dAtA[i:], m.TimeQuantum) } - if len(m.Fields) > 0 { - for _, msg := range m.Fields { - dAtA[i] = 0x3a - i++ - i = encodeVarintPrivate(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } + if len(m.Type) > 0 { + dAtA[i] = 0x42 + i++ + i = encodeVarintPrivate(dAtA, i, uint64(len(m.Type))) + i += copy(dAtA[i:], m.Type) + } + if m.Min != 0 { + dAtA[i] = 0x48 + i++ + i = encodeVarintPrivate(dAtA, i, uint64(m.Min)) + } + if m.Max != 0 { + dAtA[i] = 0x50 + i++ + i = encodeVarintPrivate(dAtA, i, uint64(m.Max)) } return i, nil } @@ -2228,6 +2249,24 @@ func (m *RecalculateCaches) MarshalTo(dAtA []byte) (int, error) { return i, nil } +func encodeFixed64Private(dAtA []byte, offset int, v uint64) int { + dAtA[offset] = uint8(v) + dAtA[offset+1] = uint8(v >> 8) + dAtA[offset+2] = uint8(v >> 16) + dAtA[offset+3] = uint8(v >> 24) + dAtA[offset+4] = uint8(v >> 32) + dAtA[offset+5] = uint8(v >> 40) + dAtA[offset+6] = uint8(v >> 48) + dAtA[offset+7] = uint8(v >> 56) + return offset + 8 +} +func encodeFixed32Private(dAtA []byte, offset int, v uint32) int { + dAtA[offset] = uint8(v) + dAtA[offset+1] = uint8(v >> 8) + dAtA[offset+2] = uint8(v >> 16) + dAtA[offset+3] = uint8(v >> 24) + return offset + 4 +} func encodeVarintPrivate(dAtA []byte, offset int, v uint64) int { for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -2257,11 +2296,15 @@ func (m *FrameMeta) Size() (n int) { if l > 0 { n += 1 + l + sovPrivate(uint64(l)) } - if len(m.Fields) > 0 { - for _, e := range m.Fields { - l = e.Size() - n += 1 + l + sovPrivate(uint64(l)) - } + l = len(m.Type) + if l > 0 { + n += 1 + l + sovPrivate(uint64(l)) + } + if m.Min != 0 { + n += 1 + sovPrivate(uint64(m.Min)) + } + if m.Max != 0 { + n += 1 + sovPrivate(uint64(m.Max)) } return n } @@ -2939,11 +2982,11 @@ func (m *FrameMeta) Unmarshal(dAtA []byte) error { } m.TimeQuantum = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 7: + case 8: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Fields", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPrivate @@ -2953,23 +2996,59 @@ func (m *FrameMeta) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= (int(b) & 0x7F) << shift + stringLen |= (uint64(b) & 0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthPrivate } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex > l { return io.ErrUnexpectedEOF } - m.Fields = append(m.Fields, &Field{}) - if err := m.Fields[len(m.Fields)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Type = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Min", wireType) + } + m.Min = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Min |= (int64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + case 10: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Max", wireType) + } + m.Max = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Max |= (int64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipPrivate(dAtA[iNdEx:]) @@ -3586,14 +3665,51 @@ func (m *MaxSlices) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } + var keykey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + keykey |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return ErrInvalidLengthPrivate + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + mapkey := string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey if m.Standard == nil { m.Standard = make(map[string]uint64) } - var mapkey string - var mapvalue uint64 - for iNdEx < postIndex { - entryPreIndex := iNdEx - var wire uint64 + if iNdEx < postIndex { + var valuekey uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPrivate @@ -3603,69 +3719,31 @@ func (m *MaxSlices) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - wire |= (uint64(b) & 0x7F) << shift + valuekey |= (uint64(b) & 0x7F) << shift if b < 0x80 { break } } - fieldNum := int32(wire >> 3) - if fieldNum == 1 { - var stringLenmapkey uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPrivate - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLenmapkey |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } + var mapvalue uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivate } - intStringLenmapkey := int(stringLenmapkey) - if intStringLenmapkey < 0 { - return ErrInvalidLengthPrivate - } - postStringIndexmapkey := iNdEx + intStringLenmapkey - if postStringIndexmapkey > l { + if iNdEx >= l { return io.ErrUnexpectedEOF } - mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) - iNdEx = postStringIndexmapkey - } else if fieldNum == 2 { - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPrivate - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - mapvalue |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } + b := dAtA[iNdEx] + iNdEx++ + mapvalue |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break } - } else { - iNdEx = entryPreIndex - skippy, err := skipPrivate(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthPrivate - } - if (iNdEx + skippy) > postIndex { - return io.ErrUnexpectedEOF - } - iNdEx += skippy } + m.Standard[mapkey] = mapvalue + } else { + var mapvalue uint64 + m.Standard[mapkey] = mapvalue } - m.Standard[mapkey] = mapvalue iNdEx = postIndex default: iNdEx = preIndex @@ -6997,70 +7075,70 @@ var ( func init() { proto.RegisterFile("private.proto", fileDescriptorPrivate) } var fileDescriptorPrivate = []byte{ - // 1035 bytes of a gzipped FileDescriptorProto + // 1029 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0xcb, 0x6f, 0x1b, 0x45, - 0x18, 0x67, 0xbd, 0x6b, 0x27, 0xfe, 0x8c, 0x53, 0x67, 0x5a, 0xc2, 0x16, 0xa1, 0x60, 0x46, 0x45, - 0x0d, 0x1c, 0xa2, 0x92, 0x5e, 0x78, 0x55, 0x8a, 0x12, 0xa7, 0x62, 0x11, 0x89, 0x60, 0x36, 0xe9, - 0x01, 0x89, 0xc3, 0xd4, 0x1e, 0xa5, 0xab, 0xac, 0x77, 0xcc, 0xee, 0x6c, 0x1e, 0x3d, 0x70, 0x85, - 0x0b, 0x17, 0x4e, 0x88, 0xbf, 0x88, 0x23, 0x7f, 0x02, 0x0a, 0xff, 0x08, 0x9a, 0x6f, 0x66, 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xaf, 0xb4, 0x18, 0xe5, 0x44, 0x1a, 0x0b, 0x27, 0xe2, 0x2e, 0x9a, 0x88, + 0x57, 0x4d, 0xa4, 0x7a, 0x9d, 0x9b, 0xf5, 0xd7, 0xf9, 0x1c, 0xee, 0xcf, 0x8d, 0xa9, 0x2f, 0xc7, + 0x13, 0x8d, 0x87, 0xff, 0x31, 0x2e, 0x7d, 0x65, 0xa4, 0xa9, 0x1d, 0x54, 0x9b, 0x19, 0x82, 0x7e, + 0x06, 0x6f, 0x85, 0x42, 0xd5, 0x86, 0x54, 0xa0, 0xad, 0x0b, 0xee, 0xb1, 0xb8, 0x5c, 0x52, 0xbe, + 0x16, 0xd1, 0x2f, 0xc1, 0x3f, 0x9d, 0x8c, 0xb8, 0x12, 0x2b, 0x59, 0x1f, 0xc0, 0xfa, 0x89, 0x9c, + 0xc8, 0x58, 0x9e, 0x4d, 0x6f, 0x59, 0x79, 0x1f, 0xd6, 0xcc, 0xfd, 0x68, 0x3e, 0x6c, 0x6d, 0x56, + 0x90, 0xf4, 0xae, 0x06, 0xf4, 0x90, 0xc7, 0xc3, 0x3c, 0xd6, 0x69, 0xe8, 0x9f, 0x5b, 0x76, 0xb0, + 0xf5, 0xd7, 0xf5, 0xae, 0xf3, 0xf7, 0xf5, 0xae, 0xf3, 0xcf, 0xf5, 0xae, 0xf3, 0xfb, 0xbf, 0xbb, + 0x6f, 0x3c, 0x6b, 0xe1, 0x37, 0xfc, 0xf1, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x71, 0x97, 0x84, + 0xb1, 0x97, 0x0b, 0x00, 0x00, } diff --git a/internal/private.proto b/internal/private.proto index 52e587f4b..b530257ae 100644 --- a/internal/private.proto +++ b/internal/private.proto @@ -6,10 +6,13 @@ message IndexMeta { } message FrameMeta { + string Type = 8; string CacheType = 3; uint32 CacheSize = 4; + int64 Min = 9; + int64 Max = 10; string TimeQuantum = 5; - repeated Field Fields = 7; + //repeated Field Fields = 7; } message ImportResponse { diff --git a/internal/public.pb.go b/internal/public.pb.go index 0dab2c831..069f633c0 100644 --- a/internal/public.pb.go +++ b/internal/public.pb.go @@ -1,5 +1,6 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. +// Code generated by protoc-gen-gogo. // source: public.proto +// DO NOT EDIT! /* Package internal is a generated protocol buffer package. @@ -27,8 +28,6 @@ import proto "github.com/golang/protobuf/proto" import fmt "fmt" import math "math" -import binary "encoding/binary" - import io "io" // Reference imports to suppress errors if they are not otherwise used. @@ -808,8 +807,7 @@ func (m *Attr) MarshalTo(dAtA []byte) (int, error) { if m.FloatValue != 0 { dAtA[i] = 0x31 i++ - binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(m.FloatValue)))) - i += 8 + i = encodeFixed64Public(dAtA, i, uint64(math.Float64bits(float64(m.FloatValue)))) } return i, nil } @@ -1251,6 +1249,24 @@ func (m *ImportValueRequest) MarshalTo(dAtA []byte) (int, error) { return i, nil } +func encodeFixed64Public(dAtA []byte, offset int, v uint64) int { + dAtA[offset] = uint8(v) + dAtA[offset+1] = uint8(v >> 8) + dAtA[offset+2] = uint8(v >> 16) + dAtA[offset+3] = uint8(v >> 24) + dAtA[offset+4] = uint8(v >> 32) + dAtA[offset+5] = uint8(v >> 40) + dAtA[offset+6] = uint8(v >> 48) + dAtA[offset+7] = uint8(v >> 56) + return offset + 8 +} +func encodeFixed32Public(dAtA []byte, offset int, v uint32) int { + dAtA[offset] = uint8(v) + dAtA[offset+1] = uint8(v >> 8) + dAtA[offset+2] = uint8(v >> 16) + dAtA[offset+3] = uint8(v >> 24) + return offset + 4 +} func encodeVarintPublic(dAtA []byte, offset int, v uint64) int { for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -2335,8 +2351,15 @@ func (m *Attr) Unmarshal(dAtA []byte) error { if (iNdEx + 8) > l { return io.ErrUnexpectedEOF } - v = uint64(binary.LittleEndian.Uint64(dAtA[iNdEx:])) iNdEx += 8 + v = uint64(dAtA[iNdEx-8]) + v |= uint64(dAtA[iNdEx-7]) << 8 + v |= uint64(dAtA[iNdEx-6]) << 16 + v |= uint64(dAtA[iNdEx-5]) << 24 + v |= uint64(dAtA[iNdEx-4]) << 32 + v |= uint64(dAtA[iNdEx-3]) << 40 + v |= uint64(dAtA[iNdEx-2]) << 48 + v |= uint64(dAtA[iNdEx-1]) << 56 m.FloatValue = float64(math.Float64frombits(v)) default: iNdEx = preIndex diff --git a/test/frame.go b/test/frame.go index e107b7d85..09503a3cf 100644 --- a/test/frame.go +++ b/test/frame.go @@ -29,12 +29,12 @@ type Frame struct { } // NewFrame returns a new instance of Frame d/0. -func NewFrame() *Frame { +func NewFrame(opt ...pilosa.FrameOption) *Frame { path, err := ioutil.TempDir("", "pilosa-frame-") if err != nil { panic(err) } - frame, err := pilosa.NewFrame(path, "i", "f") + frame, err := pilosa.NewFrame(path, "i", "f", opt...) if err != nil { panic(err) } @@ -42,8 +42,8 @@ func NewFrame() *Frame { } // MustOpenFrame returns a new, opened frame at a temporary path. Panic on error. -func MustOpenFrame() *Frame { - f := NewFrame() +func MustOpenFrame(opt ...pilosa.FrameOption) *Frame { + f := NewFrame(opt...) if err := f.Open(); err != nil { panic(err) }