mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Previously, multiple frames with different prefixes were used to separate different data layouts. This included separating standard row/column layouts from inverted column/row layouts as well as storing aggregate information for timestamp data. Unfortunately, this caused frame meta data to be copied between multiple frames and it made it difficult to keep these frames in sync. This commit separates these different physical layouts into `Views`. A `Frame` now has one or more views which represent each layout. Fragments have been moved from under the `Frame` to be contained within the `View`. There are two primary views: - `standard` - `inverse` If a frame has a time quantum, then views are generated for these each of the standard/inverse views. For example a time quantum of `YMDH` for the date `2000-01-02T00:00:00Z` would create the following views: - `standard_2000` - `inverse_2000` - `standard_200001` - `inverse_200001` - `standard_20000102` - `inverse_20000102` From the user's perspective, nothing should change in PQL. Different PQL statements will handle the appropriate view automatically. For example, `Bitmap()` and `Profile()` will fetch using the `standard` view or the `inverse` view, respectively. The `Range()` statement will lookup the appropriate time-based views automatically.
80 lines
1.8 KiB
Go
80 lines
1.8 KiB
Go
package pilosa_test
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
"github.com/pilosa/pilosa"
|
|
)
|
|
|
|
// View is a test wrapper for pilosa.View.
|
|
type View struct {
|
|
*pilosa.View
|
|
BitmapAttrStore *AttrStore
|
|
}
|
|
|
|
// NewView returns a new instance of View with a temporary path.
|
|
func NewView(db, frame, name string) *View {
|
|
file, err := ioutil.TempFile("", "pilosa-view-")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
file.Close()
|
|
|
|
v := &View{
|
|
View: pilosa.NewView(file.Name(), db, frame, name),
|
|
BitmapAttrStore: MustOpenAttrStore(),
|
|
}
|
|
v.View.BitmapAttrStore = v.BitmapAttrStore.AttrStore
|
|
return v
|
|
}
|
|
|
|
// MustOpenView creates and opens an view at a temporary path. Panic on error.
|
|
func MustOpenView(db, frame, name string) *View {
|
|
v := NewView(db, frame, name)
|
|
if err := v.Open(); err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Close closes the view and removes all underlying data.
|
|
func (v *View) Close() error {
|
|
defer os.Remove(v.Path())
|
|
defer v.BitmapAttrStore.Close()
|
|
return v.View.Close()
|
|
}
|
|
|
|
// Reopen closes the view and reopens it as a new instance.
|
|
func (v *View) Reopen() error {
|
|
path := v.Path()
|
|
if err := v.View.Close(); err != nil {
|
|
return err
|
|
}
|
|
|
|
v.View = pilosa.NewView(path, v.DB(), v.Frame(), v.Name())
|
|
v.View.BitmapAttrStore = v.BitmapAttrStore.AttrStore
|
|
if err := v.Open(); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// MustSetBits sets bits on a bitmap. Panic on error.
|
|
// This function does not accept a timestamp or quantum.
|
|
func (v *View) MustSetBits(bitmapID uint64, profileIDs ...uint64) {
|
|
for _, profileID := range profileIDs {
|
|
if _, err := v.SetBit(bitmapID, profileID); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// MustClearBits clears bits on a bitmap. Panic on error.
|
|
func (v *View) MustClearBits(bitmapID uint64, profileIDs ...uint64) {
|
|
for _, profileID := range profileIDs {
|
|
if _, err := v.ClearBit(bitmapID, profileID); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
}
|