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

Commit

Permalink
Merge pull request #206 from yuce/205-noStandardView
Browse files Browse the repository at this point in the history
Adds no standard view support; Fixes #205
  • Loading branch information
yuce authored Dec 3, 2018
2 parents 60acdaa + 12a29ed commit 2b0c137
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 16 deletions.
16 changes: 10 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (c *Client) importColumns(field *Field, shard uint64, records []Record, nod
uri := nodes[0].URI()
var views viewImports
if field.options.fieldType == FieldTypeTime {
views = columnsToBitmapTimeField(field.options.timeQuantum, options.shardWidth, records)
views = columnsToBitmapTimeField(field.options.timeQuantum, options.shardWidth, records, field.options.noStandardView)
} else {
views = columnsToBitmap(options.shardWidth, records)
}
Expand Down Expand Up @@ -817,15 +817,19 @@ func columnsToBitmap(shardWidth uint64, records []Record) viewImports {
return map[string]*roaring.Bitmap{"": bmp}
}

func columnsToBitmapTimeField(quantum TimeQuantum, shardWidth uint64, records []Record) viewImports {
views := viewImports{
"": roaring.NewBitmap(),
func columnsToBitmapTimeField(quantum TimeQuantum, shardWidth uint64, records []Record, noStandardView bool) viewImports {
var standard *roaring.Bitmap
views := viewImports{}
if !noStandardView {
standard = roaring.NewBitmap()
views[""] = standard
}
standard := views[""]
for _, record := range records {
c := record.(Column)
b := c.RowID*shardWidth + (c.ColumnID % shardWidth)
standard.DirectAdd(b)
if standard != nil {
standard.DirectAdd(b)
}
// TODO: cache time views
timeViews := viewsByTime(time.Unix(0, c.Timestamp).UTC(), quantum)
for _, name := range timeViews {
Expand Down
45 changes: 44 additions & 1 deletion client_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ func TestRowIDColumnIDTimestampImportRoaring(t *testing.T) {
for i, result := range response.Results() {
br := result.Row()
if len(br.Columns) < 1 {
t.Fatalf("1 or more keys should be returned")
t.Fatalf("1 or more columns should be returned")
}
if target[i] != br.Columns[0] {
t.Fatalf("%d != %d", target[i], br.Columns[0])
Expand Down Expand Up @@ -1676,6 +1676,49 @@ func TestRowIDColumnIDTimestampImportRoaring(t *testing.T) {
}
}

func TestRowIDColumnIDTimestampImportRoaringNoStandardView(t *testing.T) {
client := getClient()
iterator := newTestIteratorWithTimestamp()
field := index.Field("importfield-rowid-colid-time-nostd", OptFieldTypeTime(TimeQuantumMonthDayHour, true))
err := client.EnsureField(field)
if err != nil {
t.Fatal(err)
}
err = client.ImportField(field, iterator)
if err != nil {
t.Fatal(err)
}

target := []uint64{3, 1, 5}
bq := index.BatchQuery(
field.Row(2),
field.Row(7),
field.Row(10),
)
response, err := client.Query(bq)
if err != nil {
t.Fatal(err)
}
if len(response.Results()) != 3 {
t.Fatalf("Result count should be 3")
}
for _, result := range response.Results() {
br := result.Row()
// no columns should be returned since the standard view shouldn't exist
if len(br.Columns) != 0 {
t.Fatalf("no columns should be returned, but %d returned", len(br.Columns))
}
}

target = []uint64{5, 7}
start := time.Date(2016, 1, 1, 0, 0, 0, 0, time.UTC)
end := time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC)
response, err = client.Query(field.Range(10, start, end))
if !reflect.DeepEqual(target, response.Result().Row().Columns) {
t.Fatalf("%v != %v", target, response.Result().Row().Columns)
}
}

func TestRowIDColumnIDImportFails(t *testing.T) {
server := getMockServer(200, []byte(`{}`), -1)
defer server.Close()
Expand Down
25 changes: 17 additions & 8 deletions orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,14 @@ type FieldInfo struct {

// FieldOptions contains options to customize Field objects and field queries.
type FieldOptions struct {
fieldType FieldType
timeQuantum TimeQuantum
cacheType CacheType
cacheSize int
min int64
max int64
keys bool
fieldType FieldType
timeQuantum TimeQuantum
cacheType CacheType
cacheSize int
min int64
max int64
keys bool
noStandardView bool
}

// Type returns the type of the field. Currently "set", "int", or "time".
Expand Down Expand Up @@ -581,6 +582,10 @@ func (fo *FieldOptions) Max() int64 {
return fo.max
}

func (fo *FieldOptions) NoStandardView() bool {
return fo.noStandardView
}

func (fo *FieldOptions) withDefaults() (updated *FieldOptions) {
// copy options so the original is not updated
updated = &FieldOptions{}
Expand All @@ -604,6 +609,7 @@ func (fo FieldOptions) String() string {
mopt["max"] = fo.max
case FieldTypeTime:
mopt["timeQuantum"] = string(fo.timeQuantum)
mopt["noStandardView"] = fo.noStandardView
}

if fo.fieldType != FieldTypeDefault {
Expand Down Expand Up @@ -648,10 +654,13 @@ func OptFieldTypeInt(min int64, max int64) FieldOption {
}

// OptFieldTypeTime adds a time field.
func OptFieldTypeTime(quantum TimeQuantum) FieldOption {
func OptFieldTypeTime(quantum TimeQuantum, opts ...bool) FieldOption {
return func(options *FieldOptions) {
options.fieldType = FieldTypeTime
options.timeQuantum = quantum
if len(opts) > 0 && opts[0] {
options.noStandardView = true
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ func TestIntFieldOptions(t *testing.T) {
func TestTimeFieldOptions(t *testing.T) {
field := sampleIndex.Field("time-field", OptFieldTypeTime(TimeQuantumDayHour))
jsonString := field.options.String()
targetString := `{"options":{"type":"time","timeQuantum":"DH"}}`
targetString := `{"options":{"noStandardView":false,"type":"time","timeQuantum":"DH"}}`
if sortedString(targetString) != sortedString(jsonString) {
t.Fatalf("`%s` != `%s`", targetString, jsonString)
}
Expand Down

0 comments on commit 2b0c137

Please sign in to comment.