repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
list | docstring
stringlengths 6
2.61k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
pilosa/pilosa
|
translate.go
|
keyByID
|
func (idx *index) keyByID(id uint64) ([]byte, bool) {
offset, ok := idx.offsetsByID[id]
if !ok {
return nil, false
}
return idx.lookupKey(offset), true
}
|
go
|
func (idx *index) keyByID(id uint64) ([]byte, bool) {
offset, ok := idx.offsetsByID[id]
if !ok {
return nil, false
}
return idx.lookupKey(offset), true
}
|
[
"func",
"(",
"idx",
"*",
"index",
")",
"keyByID",
"(",
"id",
"uint64",
")",
"(",
"[",
"]",
"byte",
",",
"bool",
")",
"{",
"offset",
",",
"ok",
":=",
"idx",
".",
"offsetsByID",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"return",
"idx",
".",
"lookupKey",
"(",
"offset",
")",
",",
"true",
"\n",
"}"
] |
// keyByID returns the key for a given ID, if it exists.
|
[
"keyByID",
"returns",
"the",
"key",
"for",
"a",
"given",
"ID",
"if",
"it",
"exists",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L930-L936
|
train
|
pilosa/pilosa
|
translate.go
|
idByKey
|
func (idx *index) idByKey(key []byte) (uint64, bool) {
hash := hashKey(key)
pos := hash & idx.mask
var dist uint64
for {
if e := &idx.elems[pos]; e.hash == 0 {
return 0, false
} else if dist > idx.dist(e.hash, pos) {
return 0, false
} else if e.hash == hash && bytes.Equal(idx.lookupKey(e.offset), key) {
return e.id, true
}
pos = (pos + 1) & idx.mask
dist++
}
}
|
go
|
func (idx *index) idByKey(key []byte) (uint64, bool) {
hash := hashKey(key)
pos := hash & idx.mask
var dist uint64
for {
if e := &idx.elems[pos]; e.hash == 0 {
return 0, false
} else if dist > idx.dist(e.hash, pos) {
return 0, false
} else if e.hash == hash && bytes.Equal(idx.lookupKey(e.offset), key) {
return e.id, true
}
pos = (pos + 1) & idx.mask
dist++
}
}
|
[
"func",
"(",
"idx",
"*",
"index",
")",
"idByKey",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"uint64",
",",
"bool",
")",
"{",
"hash",
":=",
"hashKey",
"(",
"key",
")",
"\n",
"pos",
":=",
"hash",
"&",
"idx",
".",
"mask",
"\n\n",
"var",
"dist",
"uint64",
"\n",
"for",
"{",
"if",
"e",
":=",
"&",
"idx",
".",
"elems",
"[",
"pos",
"]",
";",
"e",
".",
"hash",
"==",
"0",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"else",
"if",
"dist",
">",
"idx",
".",
"dist",
"(",
"e",
".",
"hash",
",",
"pos",
")",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"else",
"if",
"e",
".",
"hash",
"==",
"hash",
"&&",
"bytes",
".",
"Equal",
"(",
"idx",
".",
"lookupKey",
"(",
"e",
".",
"offset",
")",
",",
"key",
")",
"{",
"return",
"e",
".",
"id",
",",
"true",
"\n",
"}",
"\n\n",
"pos",
"=",
"(",
"pos",
"+",
"1",
")",
"&",
"idx",
".",
"mask",
"\n",
"dist",
"++",
"\n",
"}",
"\n",
"}"
] |
// idByKey returns the ID for a given key, if it exists.
|
[
"idByKey",
"returns",
"the",
"ID",
"for",
"a",
"given",
"key",
"if",
"it",
"exists",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L939-L956
|
train
|
pilosa/pilosa
|
translate.go
|
insertIDbyOffset
|
func (idx *index) insertIDbyOffset(offset int64, id uint64) (overwritten bool) {
key := idx.lookupKey(offset)
hash := hashKey(key)
pos := hash & idx.mask
var dist uint64
for {
e := &idx.elems[pos]
// Exit if a matching or empty slot exists.
if e.hash == 0 {
e.hash, e.offset, e.id = hash, offset, id
return false
} else if bytes.Equal(idx.lookupKey(e.offset), key) {
e.hash, e.offset, e.id = hash, offset, id
return true
}
// Swap if current element has a lower probe distance.
d := idx.dist(e.hash, pos)
if d < dist {
hash, e.hash = e.hash, hash
offset, e.offset = e.offset, offset
id, e.id = e.id, id
dist = d
}
// Move position forward.
pos = (pos + 1) & idx.mask
dist++
}
}
|
go
|
func (idx *index) insertIDbyOffset(offset int64, id uint64) (overwritten bool) {
key := idx.lookupKey(offset)
hash := hashKey(key)
pos := hash & idx.mask
var dist uint64
for {
e := &idx.elems[pos]
// Exit if a matching or empty slot exists.
if e.hash == 0 {
e.hash, e.offset, e.id = hash, offset, id
return false
} else if bytes.Equal(idx.lookupKey(e.offset), key) {
e.hash, e.offset, e.id = hash, offset, id
return true
}
// Swap if current element has a lower probe distance.
d := idx.dist(e.hash, pos)
if d < dist {
hash, e.hash = e.hash, hash
offset, e.offset = e.offset, offset
id, e.id = e.id, id
dist = d
}
// Move position forward.
pos = (pos + 1) & idx.mask
dist++
}
}
|
[
"func",
"(",
"idx",
"*",
"index",
")",
"insertIDbyOffset",
"(",
"offset",
"int64",
",",
"id",
"uint64",
")",
"(",
"overwritten",
"bool",
")",
"{",
"key",
":=",
"idx",
".",
"lookupKey",
"(",
"offset",
")",
"\n",
"hash",
":=",
"hashKey",
"(",
"key",
")",
"\n",
"pos",
":=",
"hash",
"&",
"idx",
".",
"mask",
"\n\n",
"var",
"dist",
"uint64",
"\n",
"for",
"{",
"e",
":=",
"&",
"idx",
".",
"elems",
"[",
"pos",
"]",
"\n\n",
"// Exit if a matching or empty slot exists.",
"if",
"e",
".",
"hash",
"==",
"0",
"{",
"e",
".",
"hash",
",",
"e",
".",
"offset",
",",
"e",
".",
"id",
"=",
"hash",
",",
"offset",
",",
"id",
"\n",
"return",
"false",
"\n",
"}",
"else",
"if",
"bytes",
".",
"Equal",
"(",
"idx",
".",
"lookupKey",
"(",
"e",
".",
"offset",
")",
",",
"key",
")",
"{",
"e",
".",
"hash",
",",
"e",
".",
"offset",
",",
"e",
".",
"id",
"=",
"hash",
",",
"offset",
",",
"id",
"\n",
"return",
"true",
"\n",
"}",
"\n\n",
"// Swap if current element has a lower probe distance.",
"d",
":=",
"idx",
".",
"dist",
"(",
"e",
".",
"hash",
",",
"pos",
")",
"\n",
"if",
"d",
"<",
"dist",
"{",
"hash",
",",
"e",
".",
"hash",
"=",
"e",
".",
"hash",
",",
"hash",
"\n",
"offset",
",",
"e",
".",
"offset",
"=",
"e",
".",
"offset",
",",
"offset",
"\n",
"id",
",",
"e",
".",
"id",
"=",
"e",
".",
"id",
",",
"id",
"\n",
"dist",
"=",
"d",
"\n",
"}",
"\n\n",
"// Move position forward.",
"pos",
"=",
"(",
"pos",
"+",
"1",
")",
"&",
"idx",
".",
"mask",
"\n",
"dist",
"++",
"\n",
"}",
"\n",
"}"
] |
// insertIDbyOffset writes to the RHH id-by-offset map.
|
[
"insertIDbyOffset",
"writes",
"to",
"the",
"RHH",
"id",
"-",
"by",
"-",
"offset",
"map",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L987-L1018
|
train
|
pilosa/pilosa
|
translate.go
|
lookupKey
|
func (idx *index) lookupKey(offset int64) []byte {
data := idx.data[offset:]
n, sz := binary.Uvarint(data)
if sz == 0 {
return nil
}
return data[sz : sz+int(n)]
}
|
go
|
func (idx *index) lookupKey(offset int64) []byte {
data := idx.data[offset:]
n, sz := binary.Uvarint(data)
if sz == 0 {
return nil
}
return data[sz : sz+int(n)]
}
|
[
"func",
"(",
"idx",
"*",
"index",
")",
"lookupKey",
"(",
"offset",
"int64",
")",
"[",
"]",
"byte",
"{",
"data",
":=",
"idx",
".",
"data",
"[",
"offset",
":",
"]",
"\n",
"n",
",",
"sz",
":=",
"binary",
".",
"Uvarint",
"(",
"data",
")",
"\n",
"if",
"sz",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"data",
"[",
"sz",
":",
"sz",
"+",
"int",
"(",
"n",
")",
"]",
"\n",
"}"
] |
// lookupKey returns the key at the given offset in the memory-mapped file.
|
[
"lookupKey",
"returns",
"the",
"key",
"at",
"the",
"given",
"offset",
"in",
"the",
"memory",
"-",
"mapped",
"file",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1021-L1028
|
train
|
pilosa/pilosa
|
translate.go
|
newTranslateFileReader
|
func newTranslateFileReader(ctx context.Context, store *TranslateFile, offset int64) *translateFileReader {
return &translateFileReader{
ctx: ctx,
store: store,
offset: offset,
notify: store.WriteNotify(),
closing: make(chan struct{}),
}
}
|
go
|
func newTranslateFileReader(ctx context.Context, store *TranslateFile, offset int64) *translateFileReader {
return &translateFileReader{
ctx: ctx,
store: store,
offset: offset,
notify: store.WriteNotify(),
closing: make(chan struct{}),
}
}
|
[
"func",
"newTranslateFileReader",
"(",
"ctx",
"context",
".",
"Context",
",",
"store",
"*",
"TranslateFile",
",",
"offset",
"int64",
")",
"*",
"translateFileReader",
"{",
"return",
"&",
"translateFileReader",
"{",
"ctx",
":",
"ctx",
",",
"store",
":",
"store",
",",
"offset",
":",
"offset",
",",
"notify",
":",
"store",
".",
"WriteNotify",
"(",
")",
",",
"closing",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"}",
"\n",
"}"
] |
// newTranslateFileReader returns a new instance of translateFileReader.
|
[
"newTranslateFileReader",
"returns",
"a",
"new",
"instance",
"of",
"translateFileReader",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1076-L1084
|
train
|
pilosa/pilosa
|
translate.go
|
Open
|
func (r *translateFileReader) Open() (err error) {
r.file, err = os.Open(r.store.Path)
return err
}
|
go
|
func (r *translateFileReader) Open() (err error) {
r.file, err = os.Open(r.store.Path)
return err
}
|
[
"func",
"(",
"r",
"*",
"translateFileReader",
")",
"Open",
"(",
")",
"(",
"err",
"error",
")",
"{",
"r",
".",
"file",
",",
"err",
"=",
"os",
".",
"Open",
"(",
"r",
".",
"store",
".",
"Path",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Open initializes the reader.
|
[
"Open",
"initializes",
"the",
"reader",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1087-L1090
|
train
|
pilosa/pilosa
|
translate.go
|
Close
|
func (r *translateFileReader) Close() error {
r.once.Do(func() { close(r.closing) })
if r.file != nil {
return r.file.Close()
}
return nil
}
|
go
|
func (r *translateFileReader) Close() error {
r.once.Do(func() { close(r.closing) })
if r.file != nil {
return r.file.Close()
}
return nil
}
|
[
"func",
"(",
"r",
"*",
"translateFileReader",
")",
"Close",
"(",
")",
"error",
"{",
"r",
".",
"once",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"close",
"(",
"r",
".",
"closing",
")",
"}",
")",
"\n\n",
"if",
"r",
".",
"file",
"!=",
"nil",
"{",
"return",
"r",
".",
"file",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Close closes the underlying file reader.
|
[
"Close",
"closes",
"the",
"underlying",
"file",
"reader",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1093-L1100
|
train
|
pilosa/pilosa
|
translate.go
|
Read
|
func (r *translateFileReader) Read(p []byte) (n int, err error) {
for {
// Obtain notification channel before we check for new data.
notify := r.store.WriteNotify()
// Exit if we can read one or more valid entries or we receive an error.
if n, err = r.read(p); n > 0 || err != nil {
return n, err
}
// Wait for new data or close.
select {
case <-r.ctx.Done():
return 0, r.ctx.Err()
case <-r.closing:
return 0, ErrTranslateStoreReaderClosed
case <-r.store.Closing():
return 0, ErrTranslateStoreClosed
case <-notify:
continue
}
}
}
|
go
|
func (r *translateFileReader) Read(p []byte) (n int, err error) {
for {
// Obtain notification channel before we check for new data.
notify := r.store.WriteNotify()
// Exit if we can read one or more valid entries or we receive an error.
if n, err = r.read(p); n > 0 || err != nil {
return n, err
}
// Wait for new data or close.
select {
case <-r.ctx.Done():
return 0, r.ctx.Err()
case <-r.closing:
return 0, ErrTranslateStoreReaderClosed
case <-r.store.Closing():
return 0, ErrTranslateStoreClosed
case <-notify:
continue
}
}
}
|
[
"func",
"(",
"r",
"*",
"translateFileReader",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"for",
"{",
"// Obtain notification channel before we check for new data.",
"notify",
":=",
"r",
".",
"store",
".",
"WriteNotify",
"(",
")",
"\n\n",
"// Exit if we can read one or more valid entries or we receive an error.",
"if",
"n",
",",
"err",
"=",
"r",
".",
"read",
"(",
"p",
")",
";",
"n",
">",
"0",
"||",
"err",
"!=",
"nil",
"{",
"return",
"n",
",",
"err",
"\n",
"}",
"\n\n",
"// Wait for new data or close.",
"select",
"{",
"case",
"<-",
"r",
".",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"0",
",",
"r",
".",
"ctx",
".",
"Err",
"(",
")",
"\n",
"case",
"<-",
"r",
".",
"closing",
":",
"return",
"0",
",",
"ErrTranslateStoreReaderClosed",
"\n",
"case",
"<-",
"r",
".",
"store",
".",
"Closing",
"(",
")",
":",
"return",
"0",
",",
"ErrTranslateStoreClosed",
"\n",
"case",
"<-",
"notify",
":",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// Read reads the next section of the available data to p. This should always
// read from the start of an entry and read n bytes to the end of another entry.
|
[
"Read",
"reads",
"the",
"next",
"section",
"of",
"the",
"available",
"data",
"to",
"p",
".",
"This",
"should",
"always",
"read",
"from",
"the",
"start",
"of",
"an",
"entry",
"and",
"read",
"n",
"bytes",
"to",
"the",
"end",
"of",
"another",
"entry",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1104-L1126
|
train
|
pilosa/pilosa
|
translate.go
|
read
|
func (r *translateFileReader) read(p []byte) (n int, err error) {
sz := r.store.size()
// Exit if there is no new data.
if sz < r.offset {
return 0, fmt.Errorf("pilosa: translate store reader past file size: sz=%d off=%d", sz, r.offset)
} else if sz == r.offset {
return 0, nil
}
if max := sz - r.offset; max > int64(len(p)) {
// If p is not large enough to hold a single entry,
// return an error so the client can increase the
// size of p and try again.
return 0, ErrTranslateReadTargetUndersized
} else if int64(len(p)) > max {
// Shorten buffer to maximum read size.
p = p[:max]
}
// Read data from file at offset.
// Limit the number of bytes read to only whole entries.
n, err = r.file.ReadAt(p, r.offset)
n = validLogEntriesLen(p[:n])
r.offset += int64(n)
return n, err
}
|
go
|
func (r *translateFileReader) read(p []byte) (n int, err error) {
sz := r.store.size()
// Exit if there is no new data.
if sz < r.offset {
return 0, fmt.Errorf("pilosa: translate store reader past file size: sz=%d off=%d", sz, r.offset)
} else if sz == r.offset {
return 0, nil
}
if max := sz - r.offset; max > int64(len(p)) {
// If p is not large enough to hold a single entry,
// return an error so the client can increase the
// size of p and try again.
return 0, ErrTranslateReadTargetUndersized
} else if int64(len(p)) > max {
// Shorten buffer to maximum read size.
p = p[:max]
}
// Read data from file at offset.
// Limit the number of bytes read to only whole entries.
n, err = r.file.ReadAt(p, r.offset)
n = validLogEntriesLen(p[:n])
r.offset += int64(n)
return n, err
}
|
[
"func",
"(",
"r",
"*",
"translateFileReader",
")",
"read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"sz",
":=",
"r",
".",
"store",
".",
"size",
"(",
")",
"\n\n",
"// Exit if there is no new data.",
"if",
"sz",
"<",
"r",
".",
"offset",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sz",
",",
"r",
".",
"offset",
")",
"\n",
"}",
"else",
"if",
"sz",
"==",
"r",
".",
"offset",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"max",
":=",
"sz",
"-",
"r",
".",
"offset",
";",
"max",
">",
"int64",
"(",
"len",
"(",
"p",
")",
")",
"{",
"// If p is not large enough to hold a single entry,",
"// return an error so the client can increase the",
"// size of p and try again.",
"return",
"0",
",",
"ErrTranslateReadTargetUndersized",
"\n",
"}",
"else",
"if",
"int64",
"(",
"len",
"(",
"p",
")",
")",
">",
"max",
"{",
"// Shorten buffer to maximum read size.",
"p",
"=",
"p",
"[",
":",
"max",
"]",
"\n",
"}",
"\n\n",
"// Read data from file at offset.",
"// Limit the number of bytes read to only whole entries.",
"n",
",",
"err",
"=",
"r",
".",
"file",
".",
"ReadAt",
"(",
"p",
",",
"r",
".",
"offset",
")",
"\n",
"n",
"=",
"validLogEntriesLen",
"(",
"p",
"[",
":",
"n",
"]",
")",
"\n",
"r",
".",
"offset",
"+=",
"int64",
"(",
"n",
")",
"\n",
"return",
"n",
",",
"err",
"\n",
"}"
] |
// read writes the bytes for zero or more valid entries to p.
|
[
"read",
"writes",
"the",
"bytes",
"for",
"zero",
"or",
"more",
"valid",
"entries",
"to",
"p",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1129-L1155
|
train
|
pilosa/pilosa
|
translate.go
|
TranslateColumnToString
|
func (s nopTranslateStore) TranslateColumnToString(index string, values uint64) (string, error) {
return "", nil
}
|
go
|
func (s nopTranslateStore) TranslateColumnToString(index string, values uint64) (string, error) {
return "", nil
}
|
[
"func",
"(",
"s",
"nopTranslateStore",
")",
"TranslateColumnToString",
"(",
"index",
"string",
",",
"values",
"uint64",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}"
] |
// TranslateColumnToString is a no-op implementation of the TranslateStore TranslateColumnToString method.
|
[
"TranslateColumnToString",
"is",
"a",
"no",
"-",
"op",
"implementation",
"of",
"the",
"TranslateStore",
"TranslateColumnToString",
"method",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1182-L1184
|
train
|
pilosa/pilosa
|
translate.go
|
TranslateRowsToUint64
|
func (s nopTranslateStore) TranslateRowsToUint64(index, field string, values []string) ([]uint64, error) {
return []uint64{}, nil
}
|
go
|
func (s nopTranslateStore) TranslateRowsToUint64(index, field string, values []string) ([]uint64, error) {
return []uint64{}, nil
}
|
[
"func",
"(",
"s",
"nopTranslateStore",
")",
"TranslateRowsToUint64",
"(",
"index",
",",
"field",
"string",
",",
"values",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"uint64",
",",
"error",
")",
"{",
"return",
"[",
"]",
"uint64",
"{",
"}",
",",
"nil",
"\n",
"}"
] |
// TranslateRowsToUint64 is a no-op implementation of the TranslateStore TranslateRowsToUint64 method.
|
[
"TranslateRowsToUint64",
"is",
"a",
"no",
"-",
"op",
"implementation",
"of",
"the",
"TranslateStore",
"TranslateRowsToUint64",
"method",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1187-L1189
|
train
|
pilosa/pilosa
|
translate.go
|
Reader
|
func (s nopTranslateStore) Reader(ctx context.Context, off int64) (io.ReadCloser, error) {
return ioutil.NopCloser(bytes.NewReader(nil)), nil
}
|
go
|
func (s nopTranslateStore) Reader(ctx context.Context, off int64) (io.ReadCloser, error) {
return ioutil.NopCloser(bytes.NewReader(nil)), nil
}
|
[
"func",
"(",
"s",
"nopTranslateStore",
")",
"Reader",
"(",
"ctx",
"context",
".",
"Context",
",",
"off",
"int64",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"return",
"ioutil",
".",
"NopCloser",
"(",
"bytes",
".",
"NewReader",
"(",
"nil",
")",
")",
",",
"nil",
"\n",
"}"
] |
// Reader is a no-op implementation of the TranslateStore Reader method.
|
[
"Reader",
"is",
"a",
"no",
"-",
"op",
"implementation",
"of",
"the",
"TranslateStore",
"Reader",
"method",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/translate.go#L1197-L1199
|
train
|
pilosa/pilosa
|
server/setup_logger.go
|
setupLogger
|
func (m *Command) setupLogger() error {
if m.Config.LogPath == "" {
m.logOutput = m.Stderr
} else {
f, err := os.OpenFile(m.Config.LogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
if err != nil {
return errors.Wrap(err, "opening file")
}
m.logOutput = f
err = syscall.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
if err != nil {
return errors.Wrap(err, "dup2ing stderr onto logfile")
}
}
if m.Config.Verbose {
m.logger = logger.NewVerboseLogger(m.logOutput)
} else {
m.logger = logger.NewStandardLogger(m.logOutput)
}
return nil
}
|
go
|
func (m *Command) setupLogger() error {
if m.Config.LogPath == "" {
m.logOutput = m.Stderr
} else {
f, err := os.OpenFile(m.Config.LogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
if err != nil {
return errors.Wrap(err, "opening file")
}
m.logOutput = f
err = syscall.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
if err != nil {
return errors.Wrap(err, "dup2ing stderr onto logfile")
}
}
if m.Config.Verbose {
m.logger = logger.NewVerboseLogger(m.logOutput)
} else {
m.logger = logger.NewStandardLogger(m.logOutput)
}
return nil
}
|
[
"func",
"(",
"m",
"*",
"Command",
")",
"setupLogger",
"(",
")",
"error",
"{",
"if",
"m",
".",
"Config",
".",
"LogPath",
"==",
"\"",
"\"",
"{",
"m",
".",
"logOutput",
"=",
"m",
".",
"Stderr",
"\n",
"}",
"else",
"{",
"f",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"m",
".",
"Config",
".",
"LogPath",
",",
"os",
".",
"O_RDWR",
"|",
"os",
".",
"O_CREATE",
"|",
"os",
".",
"O_APPEND",
",",
"0600",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"m",
".",
"logOutput",
"=",
"f",
"\n",
"err",
"=",
"syscall",
".",
"Dup2",
"(",
"int",
"(",
"f",
".",
"Fd",
"(",
")",
")",
",",
"int",
"(",
"os",
".",
"Stderr",
".",
"Fd",
"(",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"m",
".",
"Config",
".",
"Verbose",
"{",
"m",
".",
"logger",
"=",
"logger",
".",
"NewVerboseLogger",
"(",
"m",
".",
"logOutput",
")",
"\n",
"}",
"else",
"{",
"m",
".",
"logger",
"=",
"logger",
".",
"NewStandardLogger",
"(",
"m",
".",
"logOutput",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// setupLogger sets up the logger based on the configuration.
|
[
"setupLogger",
"sets",
"up",
"the",
"logger",
"based",
"on",
"the",
"configuration",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/server/setup_logger.go#L28-L49
|
train
|
pilosa/pilosa
|
field.go
|
OptFieldTypeDefault
|
func OptFieldTypeDefault() FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeSet
fo.CacheType = DefaultCacheType
fo.CacheSize = DefaultCacheSize
return nil
}
}
|
go
|
func OptFieldTypeDefault() FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeSet
fo.CacheType = DefaultCacheType
fo.CacheSize = DefaultCacheSize
return nil
}
}
|
[
"func",
"OptFieldTypeDefault",
"(",
")",
"FieldOption",
"{",
"return",
"func",
"(",
"fo",
"*",
"FieldOptions",
")",
"error",
"{",
"if",
"fo",
".",
"Type",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fo",
".",
"Type",
")",
"\n",
"}",
"\n",
"fo",
".",
"Type",
"=",
"FieldTypeSet",
"\n",
"fo",
".",
"CacheType",
"=",
"DefaultCacheType",
"\n",
"fo",
".",
"CacheSize",
"=",
"DefaultCacheSize",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptFieldTypeDefault is a functional option on FieldOptions
// used to set the field type and cache setting to the default values.
|
[
"OptFieldTypeDefault",
"is",
"a",
"functional",
"option",
"on",
"FieldOptions",
"used",
"to",
"set",
"the",
"field",
"type",
"and",
"cache",
"setting",
"to",
"the",
"default",
"values",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L103-L113
|
train
|
pilosa/pilosa
|
field.go
|
OptFieldTypeSet
|
func OptFieldTypeSet(cacheType string, cacheSize uint32) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeSet
fo.CacheType = cacheType
fo.CacheSize = cacheSize
return nil
}
}
|
go
|
func OptFieldTypeSet(cacheType string, cacheSize uint32) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeSet
fo.CacheType = cacheType
fo.CacheSize = cacheSize
return nil
}
}
|
[
"func",
"OptFieldTypeSet",
"(",
"cacheType",
"string",
",",
"cacheSize",
"uint32",
")",
"FieldOption",
"{",
"return",
"func",
"(",
"fo",
"*",
"FieldOptions",
")",
"error",
"{",
"if",
"fo",
".",
"Type",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fo",
".",
"Type",
")",
"\n",
"}",
"\n",
"fo",
".",
"Type",
"=",
"FieldTypeSet",
"\n",
"fo",
".",
"CacheType",
"=",
"cacheType",
"\n",
"fo",
".",
"CacheSize",
"=",
"cacheSize",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptFieldTypeSet is a functional option on FieldOptions
// used to specify the field as being type `set` and to
// provide any respective configuration values.
|
[
"OptFieldTypeSet",
"is",
"a",
"functional",
"option",
"on",
"FieldOptions",
"used",
"to",
"specify",
"the",
"field",
"as",
"being",
"type",
"set",
"and",
"to",
"provide",
"any",
"respective",
"configuration",
"values",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L118-L128
|
train
|
pilosa/pilosa
|
field.go
|
OptFieldTypeInt
|
func OptFieldTypeInt(min, max int64) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
if min > max {
return ErrInvalidBSIGroupRange
}
fo.Type = FieldTypeInt
fo.Min = min
fo.Max = max
return nil
}
}
|
go
|
func OptFieldTypeInt(min, max int64) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
if min > max {
return ErrInvalidBSIGroupRange
}
fo.Type = FieldTypeInt
fo.Min = min
fo.Max = max
return nil
}
}
|
[
"func",
"OptFieldTypeInt",
"(",
"min",
",",
"max",
"int64",
")",
"FieldOption",
"{",
"return",
"func",
"(",
"fo",
"*",
"FieldOptions",
")",
"error",
"{",
"if",
"fo",
".",
"Type",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fo",
".",
"Type",
")",
"\n",
"}",
"\n",
"if",
"min",
">",
"max",
"{",
"return",
"ErrInvalidBSIGroupRange",
"\n",
"}",
"\n",
"fo",
".",
"Type",
"=",
"FieldTypeInt",
"\n",
"fo",
".",
"Min",
"=",
"min",
"\n",
"fo",
".",
"Max",
"=",
"max",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptFieldTypeInt is a functional option on FieldOptions
// used to specify the field as being type `int` and to
// provide any respective configuration values.
|
[
"OptFieldTypeInt",
"is",
"a",
"functional",
"option",
"on",
"FieldOptions",
"used",
"to",
"specify",
"the",
"field",
"as",
"being",
"type",
"int",
"and",
"to",
"provide",
"any",
"respective",
"configuration",
"values",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L133-L146
|
train
|
pilosa/pilosa
|
field.go
|
OptFieldTypeTime
|
func OptFieldTypeTime(timeQuantum TimeQuantum, opt ...bool) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
if !timeQuantum.Valid() {
return ErrInvalidTimeQuantum
}
fo.Type = FieldTypeTime
fo.TimeQuantum = timeQuantum
fo.NoStandardView = len(opt) >= 1 && opt[0]
return nil
}
}
|
go
|
func OptFieldTypeTime(timeQuantum TimeQuantum, opt ...bool) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
if !timeQuantum.Valid() {
return ErrInvalidTimeQuantum
}
fo.Type = FieldTypeTime
fo.TimeQuantum = timeQuantum
fo.NoStandardView = len(opt) >= 1 && opt[0]
return nil
}
}
|
[
"func",
"OptFieldTypeTime",
"(",
"timeQuantum",
"TimeQuantum",
",",
"opt",
"...",
"bool",
")",
"FieldOption",
"{",
"return",
"func",
"(",
"fo",
"*",
"FieldOptions",
")",
"error",
"{",
"if",
"fo",
".",
"Type",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fo",
".",
"Type",
")",
"\n",
"}",
"\n",
"if",
"!",
"timeQuantum",
".",
"Valid",
"(",
")",
"{",
"return",
"ErrInvalidTimeQuantum",
"\n",
"}",
"\n",
"fo",
".",
"Type",
"=",
"FieldTypeTime",
"\n",
"fo",
".",
"TimeQuantum",
"=",
"timeQuantum",
"\n",
"fo",
".",
"NoStandardView",
"=",
"len",
"(",
"opt",
")",
">=",
"1",
"&&",
"opt",
"[",
"0",
"]",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptFieldTypeTime is a functional option on FieldOptions
// used to specify the field as being type `time` and to
// provide any respective configuration values.
// Pass true to skip creation of the standard view.
|
[
"OptFieldTypeTime",
"is",
"a",
"functional",
"option",
"on",
"FieldOptions",
"used",
"to",
"specify",
"the",
"field",
"as",
"being",
"type",
"time",
"and",
"to",
"provide",
"any",
"respective",
"configuration",
"values",
".",
"Pass",
"true",
"to",
"skip",
"creation",
"of",
"the",
"standard",
"view",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L152-L165
|
train
|
pilosa/pilosa
|
field.go
|
OptFieldTypeMutex
|
func OptFieldTypeMutex(cacheType string, cacheSize uint32) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeMutex
fo.CacheType = cacheType
fo.CacheSize = cacheSize
return nil
}
}
|
go
|
func OptFieldTypeMutex(cacheType string, cacheSize uint32) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeMutex
fo.CacheType = cacheType
fo.CacheSize = cacheSize
return nil
}
}
|
[
"func",
"OptFieldTypeMutex",
"(",
"cacheType",
"string",
",",
"cacheSize",
"uint32",
")",
"FieldOption",
"{",
"return",
"func",
"(",
"fo",
"*",
"FieldOptions",
")",
"error",
"{",
"if",
"fo",
".",
"Type",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fo",
".",
"Type",
")",
"\n",
"}",
"\n",
"fo",
".",
"Type",
"=",
"FieldTypeMutex",
"\n",
"fo",
".",
"CacheType",
"=",
"cacheType",
"\n",
"fo",
".",
"CacheSize",
"=",
"cacheSize",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptFieldTypeMutex is a functional option on FieldOptions
// used to specify the field as being type `mutex` and to
// provide any respective configuration values.
|
[
"OptFieldTypeMutex",
"is",
"a",
"functional",
"option",
"on",
"FieldOptions",
"used",
"to",
"specify",
"the",
"field",
"as",
"being",
"type",
"mutex",
"and",
"to",
"provide",
"any",
"respective",
"configuration",
"values",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L170-L180
|
train
|
pilosa/pilosa
|
field.go
|
OptFieldTypeBool
|
func OptFieldTypeBool() FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeBool
return nil
}
}
|
go
|
func OptFieldTypeBool() FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeBool
return nil
}
}
|
[
"func",
"OptFieldTypeBool",
"(",
")",
"FieldOption",
"{",
"return",
"func",
"(",
"fo",
"*",
"FieldOptions",
")",
"error",
"{",
"if",
"fo",
".",
"Type",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fo",
".",
"Type",
")",
"\n",
"}",
"\n",
"fo",
".",
"Type",
"=",
"FieldTypeBool",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// OptFieldTypeBool is a functional option on FieldOptions
// used to specify the field as being type `bool` and to
// provide any respective configuration values.
|
[
"OptFieldTypeBool",
"is",
"a",
"functional",
"option",
"on",
"FieldOptions",
"used",
"to",
"specify",
"the",
"field",
"as",
"being",
"type",
"bool",
"and",
"to",
"provide",
"any",
"respective",
"configuration",
"values",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L185-L193
|
train
|
pilosa/pilosa
|
field.go
|
NewField
|
func NewField(path, index, name string, opts FieldOption) (*Field, error) {
err := validateName(name)
if err != nil {
return nil, errors.Wrap(err, "validating name")
}
return newField(path, index, name, opts)
}
|
go
|
func NewField(path, index, name string, opts FieldOption) (*Field, error) {
err := validateName(name)
if err != nil {
return nil, errors.Wrap(err, "validating name")
}
return newField(path, index, name, opts)
}
|
[
"func",
"NewField",
"(",
"path",
",",
"index",
",",
"name",
"string",
",",
"opts",
"FieldOption",
")",
"(",
"*",
"Field",
",",
"error",
")",
"{",
"err",
":=",
"validateName",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"newField",
"(",
"path",
",",
"index",
",",
"name",
",",
"opts",
")",
"\n",
"}"
] |
// NewField returns a new instance of field.
|
[
"NewField",
"returns",
"a",
"new",
"instance",
"of",
"field",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L196-L203
|
train
|
pilosa/pilosa
|
field.go
|
AvailableShards
|
func (f *Field) AvailableShards() *roaring.Bitmap {
f.mu.RLock()
defer f.mu.RUnlock()
b := f.remoteAvailableShards.Clone()
for _, view := range f.viewMap {
b = b.Union(view.availableShards())
}
return b
}
|
go
|
func (f *Field) AvailableShards() *roaring.Bitmap {
f.mu.RLock()
defer f.mu.RUnlock()
b := f.remoteAvailableShards.Clone()
for _, view := range f.viewMap {
b = b.Union(view.availableShards())
}
return b
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"AvailableShards",
"(",
")",
"*",
"roaring",
".",
"Bitmap",
"{",
"f",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"b",
":=",
"f",
".",
"remoteAvailableShards",
".",
"Clone",
"(",
")",
"\n",
"for",
"_",
",",
"view",
":=",
"range",
"f",
".",
"viewMap",
"{",
"b",
"=",
"b",
".",
"Union",
"(",
"view",
".",
"availableShards",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"b",
"\n",
"}"
] |
// AvailableShards returns a bitmap of shards that contain data.
|
[
"AvailableShards",
"returns",
"a",
"bitmap",
"of",
"shards",
"that",
"contain",
"data",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L248-L257
|
train
|
pilosa/pilosa
|
field.go
|
AddRemoteAvailableShards
|
func (f *Field) AddRemoteAvailableShards(b *roaring.Bitmap) error {
f.mergeRemoteAvailableShards(b)
// Save the updated bitmap to the data store.
return f.saveAvailableShards()
}
|
go
|
func (f *Field) AddRemoteAvailableShards(b *roaring.Bitmap) error {
f.mergeRemoteAvailableShards(b)
// Save the updated bitmap to the data store.
return f.saveAvailableShards()
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"AddRemoteAvailableShards",
"(",
"b",
"*",
"roaring",
".",
"Bitmap",
")",
"error",
"{",
"f",
".",
"mergeRemoteAvailableShards",
"(",
"b",
")",
"\n",
"// Save the updated bitmap to the data store.",
"return",
"f",
".",
"saveAvailableShards",
"(",
")",
"\n",
"}"
] |
// AddRemoteAvailableShards merges the set of available shards into the current known set
// and saves the set to a file.
|
[
"AddRemoteAvailableShards",
"merges",
"the",
"set",
"of",
"available",
"shards",
"into",
"the",
"current",
"known",
"set",
"and",
"saves",
"the",
"set",
"to",
"a",
"file",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L261-L265
|
train
|
pilosa/pilosa
|
field.go
|
mergeRemoteAvailableShards
|
func (f *Field) mergeRemoteAvailableShards(b *roaring.Bitmap) {
f.mu.Lock()
defer f.mu.Unlock()
f.remoteAvailableShards = f.remoteAvailableShards.Union(b)
}
|
go
|
func (f *Field) mergeRemoteAvailableShards(b *roaring.Bitmap) {
f.mu.Lock()
defer f.mu.Unlock()
f.remoteAvailableShards = f.remoteAvailableShards.Union(b)
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"mergeRemoteAvailableShards",
"(",
"b",
"*",
"roaring",
".",
"Bitmap",
")",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"f",
".",
"remoteAvailableShards",
"=",
"f",
".",
"remoteAvailableShards",
".",
"Union",
"(",
"b",
")",
"\n",
"}"
] |
// mergeRemoteAvailableShards merges the set of available shards into the current known set.
|
[
"mergeRemoteAvailableShards",
"merges",
"the",
"set",
"of",
"available",
"shards",
"into",
"the",
"current",
"known",
"set",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L268-L272
|
train
|
pilosa/pilosa
|
field.go
|
loadAvailableShards
|
func (f *Field) loadAvailableShards() error {
bm := roaring.NewBitmap()
// Read data from meta file.
path := filepath.Join(f.path, ".available.shards")
buf, err := ioutil.ReadFile(path)
if os.IsNotExist(err) {
return nil
} else if err != nil {
return errors.Wrap(err, "reading available shards")
} else {
if err := bm.UnmarshalBinary(buf); err != nil {
return errors.Wrap(err, "unmarshaling")
}
}
// Merge bitmap from file into field.
f.mergeRemoteAvailableShards(bm)
return nil
}
|
go
|
func (f *Field) loadAvailableShards() error {
bm := roaring.NewBitmap()
// Read data from meta file.
path := filepath.Join(f.path, ".available.shards")
buf, err := ioutil.ReadFile(path)
if os.IsNotExist(err) {
return nil
} else if err != nil {
return errors.Wrap(err, "reading available shards")
} else {
if err := bm.UnmarshalBinary(buf); err != nil {
return errors.Wrap(err, "unmarshaling")
}
}
// Merge bitmap from file into field.
f.mergeRemoteAvailableShards(bm)
return nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"loadAvailableShards",
"(",
")",
"error",
"{",
"bm",
":=",
"roaring",
".",
"NewBitmap",
"(",
")",
"\n",
"// Read data from meta file.",
"path",
":=",
"filepath",
".",
"Join",
"(",
"f",
".",
"path",
",",
"\"",
"\"",
")",
"\n",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"nil",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"if",
"err",
":=",
"bm",
".",
"UnmarshalBinary",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// Merge bitmap from file into field.",
"f",
".",
"mergeRemoteAvailableShards",
"(",
"bm",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// loadAvailableShards reads remoteAvailableShards data for the field, if any.
|
[
"loadAvailableShards",
"reads",
"remoteAvailableShards",
"data",
"for",
"the",
"field",
"if",
"any",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L275-L293
|
train
|
pilosa/pilosa
|
field.go
|
saveAvailableShards
|
func (f *Field) saveAvailableShards() error {
f.mu.Lock()
defer f.mu.Unlock()
return f.unprotectedSaveAvailableShards()
}
|
go
|
func (f *Field) saveAvailableShards() error {
f.mu.Lock()
defer f.mu.Unlock()
return f.unprotectedSaveAvailableShards()
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"saveAvailableShards",
"(",
")",
"error",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"f",
".",
"unprotectedSaveAvailableShards",
"(",
")",
"\n",
"}"
] |
// saveAvailableShards writes remoteAvailableShards data for the field.
|
[
"saveAvailableShards",
"writes",
"remoteAvailableShards",
"data",
"for",
"the",
"field",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L296-L300
|
train
|
pilosa/pilosa
|
field.go
|
Type
|
func (f *Field) Type() string {
f.mu.RLock()
defer f.mu.RUnlock()
return f.options.Type
}
|
go
|
func (f *Field) Type() string {
f.mu.RLock()
defer f.mu.RUnlock()
return f.options.Type
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"Type",
"(",
")",
"string",
"{",
"f",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"f",
".",
"options",
".",
"Type",
"\n",
"}"
] |
// Type returns the field type.
|
[
"Type",
"returns",
"the",
"field",
"type",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L339-L343
|
train
|
pilosa/pilosa
|
field.go
|
SetCacheSize
|
func (f *Field) SetCacheSize(v uint32) error {
f.mu.Lock()
defer f.mu.Unlock()
// Ignore if no change occurred.
if v == 0 || f.options.CacheSize == v {
return nil
}
// Persist meta data to disk on change.
f.options.CacheSize = v
if err := f.saveMeta(); err != nil {
return errors.Wrap(err, "saving")
}
return nil
}
|
go
|
func (f *Field) SetCacheSize(v uint32) error {
f.mu.Lock()
defer f.mu.Unlock()
// Ignore if no change occurred.
if v == 0 || f.options.CacheSize == v {
return nil
}
// Persist meta data to disk on change.
f.options.CacheSize = v
if err := f.saveMeta(); err != nil {
return errors.Wrap(err, "saving")
}
return nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"SetCacheSize",
"(",
"v",
"uint32",
")",
"error",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Ignore if no change occurred.",
"if",
"v",
"==",
"0",
"||",
"f",
".",
"options",
".",
"CacheSize",
"==",
"v",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Persist meta data to disk on change.",
"f",
".",
"options",
".",
"CacheSize",
"=",
"v",
"\n",
"if",
"err",
":=",
"f",
".",
"saveMeta",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// SetCacheSize sets the cache size for ranked fames. Persists to meta file on update.
// defaults to DefaultCacheSize 50000
|
[
"SetCacheSize",
"sets",
"the",
"cache",
"size",
"for",
"ranked",
"fames",
".",
"Persists",
"to",
"meta",
"file",
"on",
"update",
".",
"defaults",
"to",
"DefaultCacheSize",
"50000"
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L347-L363
|
train
|
pilosa/pilosa
|
field.go
|
CacheSize
|
func (f *Field) CacheSize() uint32 {
f.mu.RLock()
v := f.options.CacheSize
f.mu.RUnlock()
return v
}
|
go
|
func (f *Field) CacheSize() uint32 {
f.mu.RLock()
v := f.options.CacheSize
f.mu.RUnlock()
return v
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"CacheSize",
"(",
")",
"uint32",
"{",
"f",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"v",
":=",
"f",
".",
"options",
".",
"CacheSize",
"\n",
"f",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"v",
"\n",
"}"
] |
// CacheSize returns the ranked field cache size.
|
[
"CacheSize",
"returns",
"the",
"ranked",
"field",
"cache",
"size",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L366-L371
|
train
|
pilosa/pilosa
|
field.go
|
Options
|
func (f *Field) Options() FieldOptions {
f.mu.RLock()
defer f.mu.RUnlock()
return f.options
}
|
go
|
func (f *Field) Options() FieldOptions {
f.mu.RLock()
defer f.mu.RUnlock()
return f.options
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"Options",
"(",
")",
"FieldOptions",
"{",
"f",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"f",
".",
"options",
"\n",
"}"
] |
// Options returns all options for this field.
|
[
"Options",
"returns",
"all",
"options",
"for",
"this",
"field",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L374-L378
|
train
|
pilosa/pilosa
|
field.go
|
Open
|
func (f *Field) Open() error {
if err := func() error {
// Ensure the field's path exists.
f.logger.Debugf("ensure field path exists: %s", f.path)
if err := os.MkdirAll(f.path, 0777); err != nil {
return errors.Wrap(err, "creating field dir")
}
f.logger.Debugf("load meta file for index/field: %s/%s", f.index, f.name)
if err := f.loadMeta(); err != nil {
return errors.Wrap(err, "loading meta")
}
f.logger.Debugf("load available shards for index/field: %s/%s", f.index, f.name)
if err := f.loadAvailableShards(); err != nil {
return errors.Wrap(err, "loading available shards")
}
// Apply the field options loaded from meta.
f.logger.Debugf("apply options for index/field: %s/%s", f.index, f.name)
if err := f.applyOptions(f.options); err != nil {
return errors.Wrap(err, "applying options")
}
f.logger.Debugf("open views for index/field: %s/%s", f.index, f.name)
if err := f.openViews(); err != nil {
return errors.Wrap(err, "opening views")
}
f.logger.Debugf("open row attribute store for index/field: %s/%s", f.index, f.name)
if err := f.rowAttrStore.Open(); err != nil {
return errors.Wrap(err, "opening attrstore")
}
return nil
}(); err != nil {
f.Close()
return err
}
f.logger.Debugf("successfully opened field index/field: %s/%s", f.index, f.name)
return nil
}
|
go
|
func (f *Field) Open() error {
if err := func() error {
// Ensure the field's path exists.
f.logger.Debugf("ensure field path exists: %s", f.path)
if err := os.MkdirAll(f.path, 0777); err != nil {
return errors.Wrap(err, "creating field dir")
}
f.logger.Debugf("load meta file for index/field: %s/%s", f.index, f.name)
if err := f.loadMeta(); err != nil {
return errors.Wrap(err, "loading meta")
}
f.logger.Debugf("load available shards for index/field: %s/%s", f.index, f.name)
if err := f.loadAvailableShards(); err != nil {
return errors.Wrap(err, "loading available shards")
}
// Apply the field options loaded from meta.
f.logger.Debugf("apply options for index/field: %s/%s", f.index, f.name)
if err := f.applyOptions(f.options); err != nil {
return errors.Wrap(err, "applying options")
}
f.logger.Debugf("open views for index/field: %s/%s", f.index, f.name)
if err := f.openViews(); err != nil {
return errors.Wrap(err, "opening views")
}
f.logger.Debugf("open row attribute store for index/field: %s/%s", f.index, f.name)
if err := f.rowAttrStore.Open(); err != nil {
return errors.Wrap(err, "opening attrstore")
}
return nil
}(); err != nil {
f.Close()
return err
}
f.logger.Debugf("successfully opened field index/field: %s/%s", f.index, f.name)
return nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"Open",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"func",
"(",
")",
"error",
"{",
"// Ensure the field's path exists.",
"f",
".",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"f",
".",
"path",
")",
"\n",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"f",
".",
"path",
",",
"0777",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"f",
".",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"f",
".",
"index",
",",
"f",
".",
"name",
")",
"\n",
"if",
"err",
":=",
"f",
".",
"loadMeta",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"f",
".",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"f",
".",
"index",
",",
"f",
".",
"name",
")",
"\n",
"if",
"err",
":=",
"f",
".",
"loadAvailableShards",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Apply the field options loaded from meta.",
"f",
".",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"f",
".",
"index",
",",
"f",
".",
"name",
")",
"\n",
"if",
"err",
":=",
"f",
".",
"applyOptions",
"(",
"f",
".",
"options",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"f",
".",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"f",
".",
"index",
",",
"f",
".",
"name",
")",
"\n",
"if",
"err",
":=",
"f",
".",
"openViews",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"f",
".",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"f",
".",
"index",
",",
"f",
".",
"name",
")",
"\n",
"if",
"err",
":=",
"f",
".",
"rowAttrStore",
".",
"Open",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"f",
".",
"Close",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"f",
".",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"f",
".",
"index",
",",
"f",
".",
"name",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Open opens and initializes the field.
|
[
"Open",
"opens",
"and",
"initializes",
"the",
"field",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L381-L423
|
train
|
pilosa/pilosa
|
field.go
|
openViews
|
func (f *Field) openViews() error {
file, err := os.Open(filepath.Join(f.path, "views"))
if os.IsNotExist(err) {
return nil
} else if err != nil {
return errors.Wrap(err, "opening view directory")
}
defer file.Close()
fis, err := file.Readdir(0)
if err != nil {
return errors.Wrap(err, "reading directory")
}
for _, fi := range fis {
if !fi.IsDir() {
continue
}
name := filepath.Base(fi.Name())
f.logger.Debugf("open index/field/view: %s/%s/%s", f.index, f.name, fi.Name())
view := f.newView(f.viewPath(name), name)
if err := view.open(); err != nil {
return fmt.Errorf("opening view: view=%s, err=%s", view.name, err)
}
view.rowAttrStore = f.rowAttrStore
f.logger.Debugf("add index/field/view to field.viewMap: %s/%s/%s", f.index, f.name, view.name)
f.viewMap[view.name] = view
}
return nil
}
|
go
|
func (f *Field) openViews() error {
file, err := os.Open(filepath.Join(f.path, "views"))
if os.IsNotExist(err) {
return nil
} else if err != nil {
return errors.Wrap(err, "opening view directory")
}
defer file.Close()
fis, err := file.Readdir(0)
if err != nil {
return errors.Wrap(err, "reading directory")
}
for _, fi := range fis {
if !fi.IsDir() {
continue
}
name := filepath.Base(fi.Name())
f.logger.Debugf("open index/field/view: %s/%s/%s", f.index, f.name, fi.Name())
view := f.newView(f.viewPath(name), name)
if err := view.open(); err != nil {
return fmt.Errorf("opening view: view=%s, err=%s", view.name, err)
}
view.rowAttrStore = f.rowAttrStore
f.logger.Debugf("add index/field/view to field.viewMap: %s/%s/%s", f.index, f.name, view.name)
f.viewMap[view.name] = view
}
return nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"openViews",
"(",
")",
"error",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filepath",
".",
"Join",
"(",
"f",
".",
"path",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"nil",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"file",
".",
"Close",
"(",
")",
"\n\n",
"fis",
",",
"err",
":=",
"file",
".",
"Readdir",
"(",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"fi",
":=",
"range",
"fis",
"{",
"if",
"!",
"fi",
".",
"IsDir",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"name",
":=",
"filepath",
".",
"Base",
"(",
"fi",
".",
"Name",
"(",
")",
")",
"\n",
"f",
".",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"f",
".",
"index",
",",
"f",
".",
"name",
",",
"fi",
".",
"Name",
"(",
")",
")",
"\n",
"view",
":=",
"f",
".",
"newView",
"(",
"f",
".",
"viewPath",
"(",
"name",
")",
",",
"name",
")",
"\n",
"if",
"err",
":=",
"view",
".",
"open",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"view",
".",
"name",
",",
"err",
")",
"\n",
"}",
"\n",
"view",
".",
"rowAttrStore",
"=",
"f",
".",
"rowAttrStore",
"\n",
"f",
".",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"f",
".",
"index",
",",
"f",
".",
"name",
",",
"view",
".",
"name",
")",
"\n",
"f",
".",
"viewMap",
"[",
"view",
".",
"name",
"]",
"=",
"view",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// openViews opens and initializes the views inside the field.
|
[
"openViews",
"opens",
"and",
"initializes",
"the",
"views",
"inside",
"the",
"field",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L426-L457
|
train
|
pilosa/pilosa
|
field.go
|
loadMeta
|
func (f *Field) loadMeta() error {
var pb internal.FieldOptions
// Read data from meta file.
buf, err := ioutil.ReadFile(filepath.Join(f.path, ".meta"))
if os.IsNotExist(err) {
return nil
} else if err != nil {
return errors.Wrap(err, "reading meta")
} else {
if err := proto.Unmarshal(buf, &pb); err != nil {
return errors.Wrap(err, "unmarshaling")
}
}
// Copy metadata 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)
f.options.Keys = pb.Keys
f.options.NoStandardView = pb.NoStandardView
return nil
}
|
go
|
func (f *Field) loadMeta() error {
var pb internal.FieldOptions
// Read data from meta file.
buf, err := ioutil.ReadFile(filepath.Join(f.path, ".meta"))
if os.IsNotExist(err) {
return nil
} else if err != nil {
return errors.Wrap(err, "reading meta")
} else {
if err := proto.Unmarshal(buf, &pb); err != nil {
return errors.Wrap(err, "unmarshaling")
}
}
// Copy metadata 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)
f.options.Keys = pb.Keys
f.options.NoStandardView = pb.NoStandardView
return nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"loadMeta",
"(",
")",
"error",
"{",
"var",
"pb",
"internal",
".",
"FieldOptions",
"\n\n",
"// Read data from meta file.",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filepath",
".",
"Join",
"(",
"f",
".",
"path",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"nil",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"if",
"err",
":=",
"proto",
".",
"Unmarshal",
"(",
"buf",
",",
"&",
"pb",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Copy metadata fields.",
"f",
".",
"options",
".",
"Type",
"=",
"pb",
".",
"Type",
"\n",
"f",
".",
"options",
".",
"CacheType",
"=",
"pb",
".",
"CacheType",
"\n",
"f",
".",
"options",
".",
"CacheSize",
"=",
"pb",
".",
"CacheSize",
"\n",
"f",
".",
"options",
".",
"Min",
"=",
"pb",
".",
"Min",
"\n",
"f",
".",
"options",
".",
"Max",
"=",
"pb",
".",
"Max",
"\n",
"f",
".",
"options",
".",
"TimeQuantum",
"=",
"TimeQuantum",
"(",
"pb",
".",
"TimeQuantum",
")",
"\n",
"f",
".",
"options",
".",
"Keys",
"=",
"pb",
".",
"Keys",
"\n",
"f",
".",
"options",
".",
"NoStandardView",
"=",
"pb",
".",
"NoStandardView",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// loadMeta reads meta data for the field, if any.
|
[
"loadMeta",
"reads",
"meta",
"data",
"for",
"the",
"field",
"if",
"any",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L460-L486
|
train
|
pilosa/pilosa
|
field.go
|
saveMeta
|
func (f *Field) saveMeta() error {
// Marshal metadata.
fo := f.options
buf, err := proto.Marshal(fo.encode())
if err != nil {
return errors.Wrap(err, "marshaling")
}
// Write to meta file.
if err := ioutil.WriteFile(filepath.Join(f.path, ".meta"), buf, 0666); err != nil {
return errors.Wrap(err, "writing meta")
}
return nil
}
|
go
|
func (f *Field) saveMeta() error {
// Marshal metadata.
fo := f.options
buf, err := proto.Marshal(fo.encode())
if err != nil {
return errors.Wrap(err, "marshaling")
}
// Write to meta file.
if err := ioutil.WriteFile(filepath.Join(f.path, ".meta"), buf, 0666); err != nil {
return errors.Wrap(err, "writing meta")
}
return nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"saveMeta",
"(",
")",
"error",
"{",
"// Marshal metadata.",
"fo",
":=",
"f",
".",
"options",
"\n",
"buf",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"fo",
".",
"encode",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Write to meta file.",
"if",
"err",
":=",
"ioutil",
".",
"WriteFile",
"(",
"filepath",
".",
"Join",
"(",
"f",
".",
"path",
",",
"\"",
"\"",
")",
",",
"buf",
",",
"0666",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// saveMeta writes meta data for the field.
|
[
"saveMeta",
"writes",
"meta",
"data",
"for",
"the",
"field",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L489-L503
|
train
|
pilosa/pilosa
|
field.go
|
applyOptions
|
func (f *Field) applyOptions(opt FieldOptions) error {
switch opt.Type {
case FieldTypeSet, FieldTypeMutex, "":
fldType := opt.Type
if fldType == "" {
fldType = FieldTypeSet
}
f.options.Type = fldType
if opt.CacheType != "" {
f.options.CacheType = opt.CacheType
}
if opt.CacheSize != 0 {
if opt.CacheType == CacheTypeNone {
f.options.CacheSize = 0
} else {
f.options.CacheSize = opt.CacheSize
}
}
f.options.Min = 0
f.options.Max = 0
f.options.TimeQuantum = ""
f.options.Keys = opt.Keys
case FieldTypeInt:
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 = ""
f.options.Keys = opt.Keys
// Create new bsiGroup.
bsig := &bsiGroup{
Name: f.name,
Type: bsiGroupTypeInt,
Min: opt.Min,
Max: opt.Max,
}
// Validate bsiGroup.
if err := bsig.validate(); err != nil {
return err
}
if err := f.createBSIGroup(bsig); err != nil {
return errors.Wrap(err, "creating bsigroup")
}
case FieldTypeTime:
f.options.Type = opt.Type
f.options.CacheType = CacheTypeNone
f.options.CacheSize = 0
f.options.Min = 0
f.options.Max = 0
f.options.Keys = opt.Keys
f.options.NoStandardView = opt.NoStandardView
// Set the time quantum.
if err := f.setTimeQuantum(opt.TimeQuantum); err != nil {
f.Close()
return errors.Wrap(err, "setting time quantum")
}
case FieldTypeBool:
f.options.Type = FieldTypeBool
f.options.CacheType = CacheTypeNone
f.options.CacheSize = 0
f.options.Min = 0
f.options.Max = 0
f.options.TimeQuantum = ""
f.options.Keys = false
default:
return errors.New("invalid field type")
}
return nil
}
|
go
|
func (f *Field) applyOptions(opt FieldOptions) error {
switch opt.Type {
case FieldTypeSet, FieldTypeMutex, "":
fldType := opt.Type
if fldType == "" {
fldType = FieldTypeSet
}
f.options.Type = fldType
if opt.CacheType != "" {
f.options.CacheType = opt.CacheType
}
if opt.CacheSize != 0 {
if opt.CacheType == CacheTypeNone {
f.options.CacheSize = 0
} else {
f.options.CacheSize = opt.CacheSize
}
}
f.options.Min = 0
f.options.Max = 0
f.options.TimeQuantum = ""
f.options.Keys = opt.Keys
case FieldTypeInt:
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 = ""
f.options.Keys = opt.Keys
// Create new bsiGroup.
bsig := &bsiGroup{
Name: f.name,
Type: bsiGroupTypeInt,
Min: opt.Min,
Max: opt.Max,
}
// Validate bsiGroup.
if err := bsig.validate(); err != nil {
return err
}
if err := f.createBSIGroup(bsig); err != nil {
return errors.Wrap(err, "creating bsigroup")
}
case FieldTypeTime:
f.options.Type = opt.Type
f.options.CacheType = CacheTypeNone
f.options.CacheSize = 0
f.options.Min = 0
f.options.Max = 0
f.options.Keys = opt.Keys
f.options.NoStandardView = opt.NoStandardView
// Set the time quantum.
if err := f.setTimeQuantum(opt.TimeQuantum); err != nil {
f.Close()
return errors.Wrap(err, "setting time quantum")
}
case FieldTypeBool:
f.options.Type = FieldTypeBool
f.options.CacheType = CacheTypeNone
f.options.CacheSize = 0
f.options.Min = 0
f.options.Max = 0
f.options.TimeQuantum = ""
f.options.Keys = false
default:
return errors.New("invalid field type")
}
return nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"applyOptions",
"(",
"opt",
"FieldOptions",
")",
"error",
"{",
"switch",
"opt",
".",
"Type",
"{",
"case",
"FieldTypeSet",
",",
"FieldTypeMutex",
",",
"\"",
"\"",
":",
"fldType",
":=",
"opt",
".",
"Type",
"\n",
"if",
"fldType",
"==",
"\"",
"\"",
"{",
"fldType",
"=",
"FieldTypeSet",
"\n",
"}",
"\n",
"f",
".",
"options",
".",
"Type",
"=",
"fldType",
"\n",
"if",
"opt",
".",
"CacheType",
"!=",
"\"",
"\"",
"{",
"f",
".",
"options",
".",
"CacheType",
"=",
"opt",
".",
"CacheType",
"\n",
"}",
"\n",
"if",
"opt",
".",
"CacheSize",
"!=",
"0",
"{",
"if",
"opt",
".",
"CacheType",
"==",
"CacheTypeNone",
"{",
"f",
".",
"options",
".",
"CacheSize",
"=",
"0",
"\n",
"}",
"else",
"{",
"f",
".",
"options",
".",
"CacheSize",
"=",
"opt",
".",
"CacheSize",
"\n",
"}",
"\n",
"}",
"\n",
"f",
".",
"options",
".",
"Min",
"=",
"0",
"\n",
"f",
".",
"options",
".",
"Max",
"=",
"0",
"\n",
"f",
".",
"options",
".",
"TimeQuantum",
"=",
"\"",
"\"",
"\n",
"f",
".",
"options",
".",
"Keys",
"=",
"opt",
".",
"Keys",
"\n",
"case",
"FieldTypeInt",
":",
"f",
".",
"options",
".",
"Type",
"=",
"opt",
".",
"Type",
"\n",
"f",
".",
"options",
".",
"CacheType",
"=",
"CacheTypeNone",
"\n",
"f",
".",
"options",
".",
"CacheSize",
"=",
"0",
"\n",
"f",
".",
"options",
".",
"Min",
"=",
"opt",
".",
"Min",
"\n",
"f",
".",
"options",
".",
"Max",
"=",
"opt",
".",
"Max",
"\n",
"f",
".",
"options",
".",
"TimeQuantum",
"=",
"\"",
"\"",
"\n",
"f",
".",
"options",
".",
"Keys",
"=",
"opt",
".",
"Keys",
"\n\n",
"// Create new bsiGroup.",
"bsig",
":=",
"&",
"bsiGroup",
"{",
"Name",
":",
"f",
".",
"name",
",",
"Type",
":",
"bsiGroupTypeInt",
",",
"Min",
":",
"opt",
".",
"Min",
",",
"Max",
":",
"opt",
".",
"Max",
",",
"}",
"\n",
"// Validate bsiGroup.",
"if",
"err",
":=",
"bsig",
".",
"validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"f",
".",
"createBSIGroup",
"(",
"bsig",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"case",
"FieldTypeTime",
":",
"f",
".",
"options",
".",
"Type",
"=",
"opt",
".",
"Type",
"\n",
"f",
".",
"options",
".",
"CacheType",
"=",
"CacheTypeNone",
"\n",
"f",
".",
"options",
".",
"CacheSize",
"=",
"0",
"\n",
"f",
".",
"options",
".",
"Min",
"=",
"0",
"\n",
"f",
".",
"options",
".",
"Max",
"=",
"0",
"\n",
"f",
".",
"options",
".",
"Keys",
"=",
"opt",
".",
"Keys",
"\n",
"f",
".",
"options",
".",
"NoStandardView",
"=",
"opt",
".",
"NoStandardView",
"\n",
"// Set the time quantum.",
"if",
"err",
":=",
"f",
".",
"setTimeQuantum",
"(",
"opt",
".",
"TimeQuantum",
")",
";",
"err",
"!=",
"nil",
"{",
"f",
".",
"Close",
"(",
")",
"\n",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"case",
"FieldTypeBool",
":",
"f",
".",
"options",
".",
"Type",
"=",
"FieldTypeBool",
"\n",
"f",
".",
"options",
".",
"CacheType",
"=",
"CacheTypeNone",
"\n",
"f",
".",
"options",
".",
"CacheSize",
"=",
"0",
"\n",
"f",
".",
"options",
".",
"Min",
"=",
"0",
"\n",
"f",
".",
"options",
".",
"Max",
"=",
"0",
"\n",
"f",
".",
"options",
".",
"TimeQuantum",
"=",
"\"",
"\"",
"\n",
"f",
".",
"options",
".",
"Keys",
"=",
"false",
"\n",
"default",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// applyOptions configures the field based on opt.
|
[
"applyOptions",
"configures",
"the",
"field",
"based",
"on",
"opt",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L506-L577
|
train
|
pilosa/pilosa
|
field.go
|
Close
|
func (f *Field) Close() error {
f.mu.Lock()
defer f.mu.Unlock()
// Close the attribute store.
if f.rowAttrStore != nil {
_ = f.rowAttrStore.Close()
}
// Close all views.
for _, view := range f.viewMap {
if err := view.close(); err != nil {
return err
}
}
f.viewMap = make(map[string]*view)
return nil
}
|
go
|
func (f *Field) Close() error {
f.mu.Lock()
defer f.mu.Unlock()
// Close the attribute store.
if f.rowAttrStore != nil {
_ = f.rowAttrStore.Close()
}
// Close all views.
for _, view := range f.viewMap {
if err := view.close(); err != nil {
return err
}
}
f.viewMap = make(map[string]*view)
return nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"Close",
"(",
")",
"error",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Close the attribute store.",
"if",
"f",
".",
"rowAttrStore",
"!=",
"nil",
"{",
"_",
"=",
"f",
".",
"rowAttrStore",
".",
"Close",
"(",
")",
"\n",
"}",
"\n\n",
"// Close all views.",
"for",
"_",
",",
"view",
":=",
"range",
"f",
".",
"viewMap",
"{",
"if",
"err",
":=",
"view",
".",
"close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"f",
".",
"viewMap",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"view",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Close closes the field and its views.
|
[
"Close",
"closes",
"the",
"field",
"and",
"its",
"views",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L580-L598
|
train
|
pilosa/pilosa
|
field.go
|
keys
|
func (f *Field) keys() bool {
f.mu.RLock()
defer f.mu.RUnlock()
return f.options.Keys
}
|
go
|
func (f *Field) keys() bool {
f.mu.RLock()
defer f.mu.RUnlock()
return f.options.Keys
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"keys",
"(",
")",
"bool",
"{",
"f",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"f",
".",
"options",
".",
"Keys",
"\n",
"}"
] |
// keys returns true if the field uses string keys.
|
[
"keys",
"returns",
"true",
"if",
"the",
"field",
"uses",
"string",
"keys",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L601-L605
|
train
|
pilosa/pilosa
|
field.go
|
bsiGroup
|
func (f *Field) bsiGroup(name string) *bsiGroup {
f.mu.RLock()
defer f.mu.RUnlock()
for _, bsig := range f.bsiGroups {
if bsig.Name == name {
return bsig
}
}
return nil
}
|
go
|
func (f *Field) bsiGroup(name string) *bsiGroup {
f.mu.RLock()
defer f.mu.RUnlock()
for _, bsig := range f.bsiGroups {
if bsig.Name == name {
return bsig
}
}
return nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"bsiGroup",
"(",
"name",
"string",
")",
"*",
"bsiGroup",
"{",
"f",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"for",
"_",
",",
"bsig",
":=",
"range",
"f",
".",
"bsiGroups",
"{",
"if",
"bsig",
".",
"Name",
"==",
"name",
"{",
"return",
"bsig",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// bsiGroup returns a bsiGroup by name.
|
[
"bsiGroup",
"returns",
"a",
"bsiGroup",
"by",
"name",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L608-L617
|
train
|
pilosa/pilosa
|
field.go
|
hasBSIGroup
|
func (f *Field) hasBSIGroup(name string) bool {
for _, bsig := range f.bsiGroups {
if bsig.Name == name {
return true
}
}
return false
}
|
go
|
func (f *Field) hasBSIGroup(name string) bool {
for _, bsig := range f.bsiGroups {
if bsig.Name == name {
return true
}
}
return false
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"hasBSIGroup",
"(",
"name",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"bsig",
":=",
"range",
"f",
".",
"bsiGroups",
"{",
"if",
"bsig",
".",
"Name",
"==",
"name",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// hasBSIGroup returns true if a bsiGroup exists on the field.
|
[
"hasBSIGroup",
"returns",
"true",
"if",
"a",
"bsiGroup",
"exists",
"on",
"the",
"field",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L620-L627
|
train
|
pilosa/pilosa
|
field.go
|
createBSIGroup
|
func (f *Field) createBSIGroup(bsig *bsiGroup) error {
f.mu.Lock()
defer f.mu.Unlock()
// Append bsiGroup.
if err := f.addBSIGroup(bsig); err != nil {
return err
}
if err := f.saveMeta(); err != nil {
return errors.Wrap(err, "saving")
}
return nil
}
|
go
|
func (f *Field) createBSIGroup(bsig *bsiGroup) error {
f.mu.Lock()
defer f.mu.Unlock()
// Append bsiGroup.
if err := f.addBSIGroup(bsig); err != nil {
return err
}
if err := f.saveMeta(); err != nil {
return errors.Wrap(err, "saving")
}
return nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"createBSIGroup",
"(",
"bsig",
"*",
"bsiGroup",
")",
"error",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Append bsiGroup.",
"if",
"err",
":=",
"f",
".",
"addBSIGroup",
"(",
"bsig",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"f",
".",
"saveMeta",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// createBSIGroup creates a new bsiGroup on the field.
|
[
"createBSIGroup",
"creates",
"a",
"new",
"bsiGroup",
"on",
"the",
"field",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L630-L642
|
train
|
pilosa/pilosa
|
field.go
|
addBSIGroup
|
func (f *Field) addBSIGroup(bsig *bsiGroup) error {
if err := bsig.validate(); err != nil {
return errors.Wrap(err, "validating bsigroup")
} else if f.hasBSIGroup(bsig.Name) {
return ErrBSIGroupExists
}
// Add bsiGroup to list.
f.bsiGroups = append(f.bsiGroups, bsig)
// Sort bsiGroups by name.
sort.Slice(f.bsiGroups, func(i, j int) bool {
return f.bsiGroups[i].Name < f.bsiGroups[j].Name
})
return nil
}
|
go
|
func (f *Field) addBSIGroup(bsig *bsiGroup) error {
if err := bsig.validate(); err != nil {
return errors.Wrap(err, "validating bsigroup")
} else if f.hasBSIGroup(bsig.Name) {
return ErrBSIGroupExists
}
// Add bsiGroup to list.
f.bsiGroups = append(f.bsiGroups, bsig)
// Sort bsiGroups by name.
sort.Slice(f.bsiGroups, func(i, j int) bool {
return f.bsiGroups[i].Name < f.bsiGroups[j].Name
})
return nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"addBSIGroup",
"(",
"bsig",
"*",
"bsiGroup",
")",
"error",
"{",
"if",
"err",
":=",
"bsig",
".",
"validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"f",
".",
"hasBSIGroup",
"(",
"bsig",
".",
"Name",
")",
"{",
"return",
"ErrBSIGroupExists",
"\n",
"}",
"\n\n",
"// Add bsiGroup to list.",
"f",
".",
"bsiGroups",
"=",
"append",
"(",
"f",
".",
"bsiGroups",
",",
"bsig",
")",
"\n\n",
"// Sort bsiGroups by name.",
"sort",
".",
"Slice",
"(",
"f",
".",
"bsiGroups",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"f",
".",
"bsiGroups",
"[",
"i",
"]",
".",
"Name",
"<",
"f",
".",
"bsiGroups",
"[",
"j",
"]",
".",
"Name",
"\n",
"}",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// addBSIGroup adds a single bsiGroup to bsiGroups.
|
[
"addBSIGroup",
"adds",
"a",
"single",
"bsiGroup",
"to",
"bsiGroups",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L645-L661
|
train
|
pilosa/pilosa
|
field.go
|
TimeQuantum
|
func (f *Field) TimeQuantum() TimeQuantum {
f.mu.Lock()
defer f.mu.Unlock()
return f.options.TimeQuantum
}
|
go
|
func (f *Field) TimeQuantum() TimeQuantum {
f.mu.Lock()
defer f.mu.Unlock()
return f.options.TimeQuantum
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"TimeQuantum",
"(",
")",
"TimeQuantum",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"f",
".",
"options",
".",
"TimeQuantum",
"\n",
"}"
] |
// TimeQuantum returns the time quantum for the field.
|
[
"TimeQuantum",
"returns",
"the",
"time",
"quantum",
"for",
"the",
"field",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L664-L668
|
train
|
pilosa/pilosa
|
field.go
|
setTimeQuantum
|
func (f *Field) setTimeQuantum(q TimeQuantum) error {
f.mu.Lock()
defer f.mu.Unlock()
// Validate input.
if !q.Valid() {
return ErrInvalidTimeQuantum
}
// Update value on field.
f.options.TimeQuantum = q
// Persist meta data to disk.
if err := f.saveMeta(); err != nil {
return errors.Wrap(err, "saving meta")
}
return nil
}
|
go
|
func (f *Field) setTimeQuantum(q TimeQuantum) error {
f.mu.Lock()
defer f.mu.Unlock()
// Validate input.
if !q.Valid() {
return ErrInvalidTimeQuantum
}
// Update value on field.
f.options.TimeQuantum = q
// Persist meta data to disk.
if err := f.saveMeta(); err != nil {
return errors.Wrap(err, "saving meta")
}
return nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"setTimeQuantum",
"(",
"q",
"TimeQuantum",
")",
"error",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Validate input.",
"if",
"!",
"q",
".",
"Valid",
"(",
")",
"{",
"return",
"ErrInvalidTimeQuantum",
"\n",
"}",
"\n\n",
"// Update value on field.",
"f",
".",
"options",
".",
"TimeQuantum",
"=",
"q",
"\n\n",
"// Persist meta data to disk.",
"if",
"err",
":=",
"f",
".",
"saveMeta",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// setTimeQuantum sets the time quantum for the field.
|
[
"setTimeQuantum",
"sets",
"the",
"time",
"quantum",
"for",
"the",
"field",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L671-L689
|
train
|
pilosa/pilosa
|
field.go
|
RowTime
|
func (f *Field) RowTime(rowID uint64, time time.Time, quantum string) (*Row, error) {
if !TimeQuantum(quantum).Valid() {
return nil, ErrInvalidTimeQuantum
}
viewname := viewsByTime(viewStandard, time, TimeQuantum(quantum[len(quantum)-1:]))[0]
view := f.view(viewname)
if view == nil {
return nil, errors.Errorf("view with quantum %v not found.", quantum)
}
return view.row(rowID), nil
}
|
go
|
func (f *Field) RowTime(rowID uint64, time time.Time, quantum string) (*Row, error) {
if !TimeQuantum(quantum).Valid() {
return nil, ErrInvalidTimeQuantum
}
viewname := viewsByTime(viewStandard, time, TimeQuantum(quantum[len(quantum)-1:]))[0]
view := f.view(viewname)
if view == nil {
return nil, errors.Errorf("view with quantum %v not found.", quantum)
}
return view.row(rowID), nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"RowTime",
"(",
"rowID",
"uint64",
",",
"time",
"time",
".",
"Time",
",",
"quantum",
"string",
")",
"(",
"*",
"Row",
",",
"error",
")",
"{",
"if",
"!",
"TimeQuantum",
"(",
"quantum",
")",
".",
"Valid",
"(",
")",
"{",
"return",
"nil",
",",
"ErrInvalidTimeQuantum",
"\n",
"}",
"\n",
"viewname",
":=",
"viewsByTime",
"(",
"viewStandard",
",",
"time",
",",
"TimeQuantum",
"(",
"quantum",
"[",
"len",
"(",
"quantum",
")",
"-",
"1",
":",
"]",
")",
")",
"[",
"0",
"]",
"\n",
"view",
":=",
"f",
".",
"view",
"(",
"viewname",
")",
"\n",
"if",
"view",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"quantum",
")",
"\n",
"}",
"\n",
"return",
"view",
".",
"row",
"(",
"rowID",
")",
",",
"nil",
"\n",
"}"
] |
// RowTime gets the row at the particular time with the granularity specified by
// the quantum.
|
[
"RowTime",
"gets",
"the",
"row",
"at",
"the",
"particular",
"time",
"with",
"the",
"granularity",
"specified",
"by",
"the",
"quantum",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L693-L703
|
train
|
pilosa/pilosa
|
field.go
|
viewPath
|
func (f *Field) viewPath(name string) string {
return filepath.Join(f.path, "views", name)
}
|
go
|
func (f *Field) viewPath(name string) string {
return filepath.Join(f.path, "views", name)
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"viewPath",
"(",
"name",
"string",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"f",
".",
"path",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
] |
// viewPath returns the path to a view in the field.
|
[
"viewPath",
"returns",
"the",
"path",
"to",
"a",
"view",
"in",
"the",
"field",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L706-L708
|
train
|
pilosa/pilosa
|
field.go
|
view
|
func (f *Field) view(name string) *view {
f.mu.RLock()
defer f.mu.RUnlock()
return f.unprotectedView(name)
}
|
go
|
func (f *Field) view(name string) *view {
f.mu.RLock()
defer f.mu.RUnlock()
return f.unprotectedView(name)
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"view",
"(",
"name",
"string",
")",
"*",
"view",
"{",
"f",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"f",
".",
"unprotectedView",
"(",
"name",
")",
"\n",
"}"
] |
// view returns a view in the field by name.
|
[
"view",
"returns",
"a",
"view",
"in",
"the",
"field",
"by",
"name",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L711-L715
|
train
|
pilosa/pilosa
|
field.go
|
views
|
func (f *Field) views() []*view {
f.mu.RLock()
defer f.mu.RUnlock()
other := make([]*view, 0, len(f.viewMap))
for _, view := range f.viewMap {
other = append(other, view)
}
return other
}
|
go
|
func (f *Field) views() []*view {
f.mu.RLock()
defer f.mu.RUnlock()
other := make([]*view, 0, len(f.viewMap))
for _, view := range f.viewMap {
other = append(other, view)
}
return other
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"views",
"(",
")",
"[",
"]",
"*",
"view",
"{",
"f",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"other",
":=",
"make",
"(",
"[",
"]",
"*",
"view",
",",
"0",
",",
"len",
"(",
"f",
".",
"viewMap",
")",
")",
"\n",
"for",
"_",
",",
"view",
":=",
"range",
"f",
".",
"viewMap",
"{",
"other",
"=",
"append",
"(",
"other",
",",
"view",
")",
"\n",
"}",
"\n",
"return",
"other",
"\n",
"}"
] |
// views returns a list of all views in the field.
|
[
"views",
"returns",
"a",
"list",
"of",
"all",
"views",
"in",
"the",
"field",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L720-L729
|
train
|
pilosa/pilosa
|
field.go
|
createViewIfNotExists
|
func (f *Field) createViewIfNotExists(name string) (*view, error) {
view, created, err := f.createViewIfNotExistsBase(name)
if err != nil {
return nil, err
}
if created {
// Broadcast view creation to the cluster.
err = f.broadcaster.SendSync(
&CreateViewMessage{
Index: f.index,
Field: f.name,
View: name,
})
if err != nil {
return nil, errors.Wrap(err, "sending CreateView message")
}
}
return view, nil
}
|
go
|
func (f *Field) createViewIfNotExists(name string) (*view, error) {
view, created, err := f.createViewIfNotExistsBase(name)
if err != nil {
return nil, err
}
if created {
// Broadcast view creation to the cluster.
err = f.broadcaster.SendSync(
&CreateViewMessage{
Index: f.index,
Field: f.name,
View: name,
})
if err != nil {
return nil, errors.Wrap(err, "sending CreateView message")
}
}
return view, nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"createViewIfNotExists",
"(",
"name",
"string",
")",
"(",
"*",
"view",
",",
"error",
")",
"{",
"view",
",",
"created",
",",
"err",
":=",
"f",
".",
"createViewIfNotExistsBase",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"created",
"{",
"// Broadcast view creation to the cluster.",
"err",
"=",
"f",
".",
"broadcaster",
".",
"SendSync",
"(",
"&",
"CreateViewMessage",
"{",
"Index",
":",
"f",
".",
"index",
",",
"Field",
":",
"f",
".",
"name",
",",
"View",
":",
"name",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"view",
",",
"nil",
"\n",
"}"
] |
// createViewIfNotExists returns the named view, creating it if necessary.
// Additionally, a CreateViewMessage is sent to the cluster.
|
[
"createViewIfNotExists",
"returns",
"the",
"named",
"view",
"creating",
"it",
"if",
"necessary",
".",
"Additionally",
"a",
"CreateViewMessage",
"is",
"sent",
"to",
"the",
"cluster",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L740-L760
|
train
|
pilosa/pilosa
|
field.go
|
createViewIfNotExistsBase
|
func (f *Field) createViewIfNotExistsBase(name string) (*view, bool, error) {
f.mu.Lock()
defer f.mu.Unlock()
if view := f.viewMap[name]; view != nil {
return view, false, nil
}
view := f.newView(f.viewPath(name), name)
if err := view.open(); err != nil {
return nil, false, errors.Wrap(err, "opening view")
}
view.rowAttrStore = f.rowAttrStore
f.viewMap[view.name] = view
return view, true, nil
}
|
go
|
func (f *Field) createViewIfNotExistsBase(name string) (*view, bool, error) {
f.mu.Lock()
defer f.mu.Unlock()
if view := f.viewMap[name]; view != nil {
return view, false, nil
}
view := f.newView(f.viewPath(name), name)
if err := view.open(); err != nil {
return nil, false, errors.Wrap(err, "opening view")
}
view.rowAttrStore = f.rowAttrStore
f.viewMap[view.name] = view
return view, true, nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"createViewIfNotExistsBase",
"(",
"name",
"string",
")",
"(",
"*",
"view",
",",
"bool",
",",
"error",
")",
"{",
"f",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"view",
":=",
"f",
".",
"viewMap",
"[",
"name",
"]",
";",
"view",
"!=",
"nil",
"{",
"return",
"view",
",",
"false",
",",
"nil",
"\n",
"}",
"\n",
"view",
":=",
"f",
".",
"newView",
"(",
"f",
".",
"viewPath",
"(",
"name",
")",
",",
"name",
")",
"\n\n",
"if",
"err",
":=",
"view",
".",
"open",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"false",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"view",
".",
"rowAttrStore",
"=",
"f",
".",
"rowAttrStore",
"\n",
"f",
".",
"viewMap",
"[",
"view",
".",
"name",
"]",
"=",
"view",
"\n\n",
"return",
"view",
",",
"true",
",",
"nil",
"\n",
"}"
] |
// createViewIfNotExistsBase returns the named view, creating it if necessary.
// The returned bool indicates whether the view was created or not.
|
[
"createViewIfNotExistsBase",
"returns",
"the",
"named",
"view",
"creating",
"it",
"if",
"necessary",
".",
"The",
"returned",
"bool",
"indicates",
"whether",
"the",
"view",
"was",
"created",
"or",
"not",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L764-L780
|
train
|
pilosa/pilosa
|
field.go
|
deleteView
|
func (f *Field) deleteView(name string) error {
view := f.viewMap[name]
if view == nil {
return ErrInvalidView
}
// Close data files before deletion.
if err := view.close(); err != nil {
return errors.Wrap(err, "closing view")
}
// Delete view directory.
if err := os.RemoveAll(view.path); err != nil {
return errors.Wrap(err, "deleting directory")
}
delete(f.viewMap, name)
return nil
}
|
go
|
func (f *Field) deleteView(name string) error {
view := f.viewMap[name]
if view == nil {
return ErrInvalidView
}
// Close data files before deletion.
if err := view.close(); err != nil {
return errors.Wrap(err, "closing view")
}
// Delete view directory.
if err := os.RemoveAll(view.path); err != nil {
return errors.Wrap(err, "deleting directory")
}
delete(f.viewMap, name)
return nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"deleteView",
"(",
"name",
"string",
")",
"error",
"{",
"view",
":=",
"f",
".",
"viewMap",
"[",
"name",
"]",
"\n",
"if",
"view",
"==",
"nil",
"{",
"return",
"ErrInvalidView",
"\n",
"}",
"\n\n",
"// Close data files before deletion.",
"if",
"err",
":=",
"view",
".",
"close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Delete view directory.",
"if",
"err",
":=",
"os",
".",
"RemoveAll",
"(",
"view",
".",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"delete",
"(",
"f",
".",
"viewMap",
",",
"name",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// deleteView removes the view from the field.
|
[
"deleteView",
"removes",
"the",
"view",
"from",
"the",
"field",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L792-L811
|
train
|
pilosa/pilosa
|
field.go
|
Row
|
func (f *Field) Row(rowID uint64) (*Row, error) {
if f.Type() != FieldTypeSet {
return nil, errors.Errorf("row method unsupported for field type: %s", f.Type())
}
view := f.view(viewStandard)
if view == nil {
return nil, ErrInvalidView
}
return view.row(rowID), nil
}
|
go
|
func (f *Field) Row(rowID uint64) (*Row, error) {
if f.Type() != FieldTypeSet {
return nil, errors.Errorf("row method unsupported for field type: %s", f.Type())
}
view := f.view(viewStandard)
if view == nil {
return nil, ErrInvalidView
}
return view.row(rowID), nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"Row",
"(",
"rowID",
"uint64",
")",
"(",
"*",
"Row",
",",
"error",
")",
"{",
"if",
"f",
".",
"Type",
"(",
")",
"!=",
"FieldTypeSet",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"f",
".",
"Type",
"(",
")",
")",
"\n",
"}",
"\n",
"view",
":=",
"f",
".",
"view",
"(",
"viewStandard",
")",
"\n",
"if",
"view",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrInvalidView",
"\n",
"}",
"\n",
"return",
"view",
".",
"row",
"(",
"rowID",
")",
",",
"nil",
"\n",
"}"
] |
// Row returns a row of the standard view.
// It seems this method is only being used by the test
// package, and the fact that it's only allowed on
// `set` fields is odd. This may be considered for
// deprecation in a future version.
|
[
"Row",
"returns",
"a",
"row",
"of",
"the",
"standard",
"view",
".",
"It",
"seems",
"this",
"method",
"is",
"only",
"being",
"used",
"by",
"the",
"test",
"package",
"and",
"the",
"fact",
"that",
"it",
"s",
"only",
"allowed",
"on",
"set",
"fields",
"is",
"odd",
".",
"This",
"may",
"be",
"considered",
"for",
"deprecation",
"in",
"a",
"future",
"version",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L818-L827
|
train
|
pilosa/pilosa
|
field.go
|
SetBit
|
func (f *Field) SetBit(rowID, colID uint64, t *time.Time) (changed bool, err error) {
viewName := viewStandard
if !f.options.NoStandardView {
// Retrieve view. Exit if it doesn't exist.
view, err := f.createViewIfNotExists(viewName)
if err != nil {
return changed, errors.Wrap(err, "creating view")
}
// Set non-time bit.
if v, err := view.setBit(rowID, colID); err != nil {
return changed, errors.Wrap(err, "setting on view")
} else if v {
changed = v
}
}
// Exit early if no timestamp is specified.
if t == nil {
return changed, nil
}
// If a timestamp is specified then set bits across all views for the quantum.
for _, subname := range viewsByTime(viewName, *t, f.TimeQuantum()) {
view, err := f.createViewIfNotExists(subname)
if err != nil {
return changed, errors.Wrapf(err, "creating view %s", subname)
}
if c, err := view.setBit(rowID, colID); err != nil {
return changed, errors.Wrapf(err, "setting on view %s", subname)
} else if c {
changed = true
}
}
return changed, nil
}
|
go
|
func (f *Field) SetBit(rowID, colID uint64, t *time.Time) (changed bool, err error) {
viewName := viewStandard
if !f.options.NoStandardView {
// Retrieve view. Exit if it doesn't exist.
view, err := f.createViewIfNotExists(viewName)
if err != nil {
return changed, errors.Wrap(err, "creating view")
}
// Set non-time bit.
if v, err := view.setBit(rowID, colID); err != nil {
return changed, errors.Wrap(err, "setting on view")
} else if v {
changed = v
}
}
// Exit early if no timestamp is specified.
if t == nil {
return changed, nil
}
// If a timestamp is specified then set bits across all views for the quantum.
for _, subname := range viewsByTime(viewName, *t, f.TimeQuantum()) {
view, err := f.createViewIfNotExists(subname)
if err != nil {
return changed, errors.Wrapf(err, "creating view %s", subname)
}
if c, err := view.setBit(rowID, colID); err != nil {
return changed, errors.Wrapf(err, "setting on view %s", subname)
} else if c {
changed = true
}
}
return changed, nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"SetBit",
"(",
"rowID",
",",
"colID",
"uint64",
",",
"t",
"*",
"time",
".",
"Time",
")",
"(",
"changed",
"bool",
",",
"err",
"error",
")",
"{",
"viewName",
":=",
"viewStandard",
"\n",
"if",
"!",
"f",
".",
"options",
".",
"NoStandardView",
"{",
"// Retrieve view. Exit if it doesn't exist.",
"view",
",",
"err",
":=",
"f",
".",
"createViewIfNotExists",
"(",
"viewName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"changed",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Set non-time bit.",
"if",
"v",
",",
"err",
":=",
"view",
".",
"setBit",
"(",
"rowID",
",",
"colID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"changed",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"v",
"{",
"changed",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Exit early if no timestamp is specified.",
"if",
"t",
"==",
"nil",
"{",
"return",
"changed",
",",
"nil",
"\n",
"}",
"\n\n",
"// If a timestamp is specified then set bits across all views for the quantum.",
"for",
"_",
",",
"subname",
":=",
"range",
"viewsByTime",
"(",
"viewName",
",",
"*",
"t",
",",
"f",
".",
"TimeQuantum",
"(",
")",
")",
"{",
"view",
",",
"err",
":=",
"f",
".",
"createViewIfNotExists",
"(",
"subname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"changed",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"subname",
")",
"\n",
"}",
"\n\n",
"if",
"c",
",",
"err",
":=",
"view",
".",
"setBit",
"(",
"rowID",
",",
"colID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"changed",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"subname",
")",
"\n",
"}",
"else",
"if",
"c",
"{",
"changed",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"changed",
",",
"nil",
"\n",
"}"
] |
// SetBit sets a bit on a view within the field.
|
[
"SetBit",
"sets",
"a",
"bit",
"on",
"a",
"view",
"within",
"the",
"field",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L830-L867
|
train
|
pilosa/pilosa
|
field.go
|
ClearBit
|
func (f *Field) ClearBit(rowID, colID uint64) (changed bool, err error) {
viewName := viewStandard
// Retrieve view. Exit if it doesn't exist.
view, present := f.viewMap[viewName]
if !present {
return changed, errors.Wrap(err, "clearing missing view")
}
// Clear non-time bit.
if v, err := view.clearBit(rowID, colID); err != nil {
return changed, errors.Wrap(err, "clearing on view")
} else if v {
changed = v
}
if len(f.viewMap) == 1 { // assuming no time views
return changed, nil
}
lastViewNameSize := 0
level := 0
skipAbove := maxInt
for _, view := range f.allTimeViewsSortedByQuantum() {
if lastViewNameSize < len(view.name) {
level++
} else if lastViewNameSize > len(view.name) {
level--
}
if level < skipAbove {
if changed, err = view.clearBit(rowID, colID); err != nil {
return changed, errors.Wrapf(err, "clearing on view %s", view.name)
}
if !changed {
skipAbove = level + 1
} else {
skipAbove = maxInt
}
}
lastViewNameSize = len(view.name)
}
return changed, nil
}
|
go
|
func (f *Field) ClearBit(rowID, colID uint64) (changed bool, err error) {
viewName := viewStandard
// Retrieve view. Exit if it doesn't exist.
view, present := f.viewMap[viewName]
if !present {
return changed, errors.Wrap(err, "clearing missing view")
}
// Clear non-time bit.
if v, err := view.clearBit(rowID, colID); err != nil {
return changed, errors.Wrap(err, "clearing on view")
} else if v {
changed = v
}
if len(f.viewMap) == 1 { // assuming no time views
return changed, nil
}
lastViewNameSize := 0
level := 0
skipAbove := maxInt
for _, view := range f.allTimeViewsSortedByQuantum() {
if lastViewNameSize < len(view.name) {
level++
} else if lastViewNameSize > len(view.name) {
level--
}
if level < skipAbove {
if changed, err = view.clearBit(rowID, colID); err != nil {
return changed, errors.Wrapf(err, "clearing on view %s", view.name)
}
if !changed {
skipAbove = level + 1
} else {
skipAbove = maxInt
}
}
lastViewNameSize = len(view.name)
}
return changed, nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"ClearBit",
"(",
"rowID",
",",
"colID",
"uint64",
")",
"(",
"changed",
"bool",
",",
"err",
"error",
")",
"{",
"viewName",
":=",
"viewStandard",
"\n\n",
"// Retrieve view. Exit if it doesn't exist.",
"view",
",",
"present",
":=",
"f",
".",
"viewMap",
"[",
"viewName",
"]",
"\n",
"if",
"!",
"present",
"{",
"return",
"changed",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n\n",
"}",
"\n\n",
"// Clear non-time bit.",
"if",
"v",
",",
"err",
":=",
"view",
".",
"clearBit",
"(",
"rowID",
",",
"colID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"changed",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"v",
"{",
"changed",
"=",
"v",
"\n",
"}",
"\n",
"if",
"len",
"(",
"f",
".",
"viewMap",
")",
"==",
"1",
"{",
"// assuming no time views",
"return",
"changed",
",",
"nil",
"\n",
"}",
"\n",
"lastViewNameSize",
":=",
"0",
"\n",
"level",
":=",
"0",
"\n",
"skipAbove",
":=",
"maxInt",
"\n",
"for",
"_",
",",
"view",
":=",
"range",
"f",
".",
"allTimeViewsSortedByQuantum",
"(",
")",
"{",
"if",
"lastViewNameSize",
"<",
"len",
"(",
"view",
".",
"name",
")",
"{",
"level",
"++",
"\n",
"}",
"else",
"if",
"lastViewNameSize",
">",
"len",
"(",
"view",
".",
"name",
")",
"{",
"level",
"--",
"\n",
"}",
"\n",
"if",
"level",
"<",
"skipAbove",
"{",
"if",
"changed",
",",
"err",
"=",
"view",
".",
"clearBit",
"(",
"rowID",
",",
"colID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"changed",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"view",
".",
"name",
")",
"\n",
"}",
"\n",
"if",
"!",
"changed",
"{",
"skipAbove",
"=",
"level",
"+",
"1",
"\n",
"}",
"else",
"{",
"skipAbove",
"=",
"maxInt",
"\n",
"}",
"\n",
"}",
"\n",
"lastViewNameSize",
"=",
"len",
"(",
"view",
".",
"name",
")",
"\n",
"}",
"\n\n",
"return",
"changed",
",",
"nil",
"\n",
"}"
] |
// ClearBit clears a bit within the field.
|
[
"ClearBit",
"clears",
"a",
"bit",
"within",
"the",
"field",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L870-L912
|
train
|
pilosa/pilosa
|
field.go
|
Value
|
func (f *Field) Value(columnID uint64) (value int64, exists bool, err error) {
bsig := f.bsiGroup(f.name)
if bsig == nil {
return 0, false, ErrBSIGroupNotFound
}
// Fetch target view.
view := f.view(viewBSIGroupPrefix + f.name)
if view == nil {
return 0, false, nil
}
v, exists, err := view.value(columnID, bsig.BitDepth())
if err != nil {
return 0, false, err
} else if !exists {
return 0, false, nil
}
return int64(v) + bsig.Min, true, nil
}
|
go
|
func (f *Field) Value(columnID uint64) (value int64, exists bool, err error) {
bsig := f.bsiGroup(f.name)
if bsig == nil {
return 0, false, ErrBSIGroupNotFound
}
// Fetch target view.
view := f.view(viewBSIGroupPrefix + f.name)
if view == nil {
return 0, false, nil
}
v, exists, err := view.value(columnID, bsig.BitDepth())
if err != nil {
return 0, false, err
} else if !exists {
return 0, false, nil
}
return int64(v) + bsig.Min, true, nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"Value",
"(",
"columnID",
"uint64",
")",
"(",
"value",
"int64",
",",
"exists",
"bool",
",",
"err",
"error",
")",
"{",
"bsig",
":=",
"f",
".",
"bsiGroup",
"(",
"f",
".",
"name",
")",
"\n",
"if",
"bsig",
"==",
"nil",
"{",
"return",
"0",
",",
"false",
",",
"ErrBSIGroupNotFound",
"\n",
"}",
"\n\n",
"// Fetch target view.",
"view",
":=",
"f",
".",
"view",
"(",
"viewBSIGroupPrefix",
"+",
"f",
".",
"name",
")",
"\n",
"if",
"view",
"==",
"nil",
"{",
"return",
"0",
",",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"v",
",",
"exists",
",",
"err",
":=",
"view",
".",
"value",
"(",
"columnID",
",",
"bsig",
".",
"BitDepth",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"false",
",",
"err",
"\n",
"}",
"else",
"if",
"!",
"exists",
"{",
"return",
"0",
",",
"false",
",",
"nil",
"\n",
"}",
"\n",
"return",
"int64",
"(",
"v",
")",
"+",
"bsig",
".",
"Min",
",",
"true",
",",
"nil",
"\n",
"}"
] |
// Value reads a field value for a column.
|
[
"Value",
"reads",
"a",
"field",
"value",
"for",
"a",
"column",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L956-L975
|
train
|
pilosa/pilosa
|
field.go
|
SetValue
|
func (f *Field) SetValue(columnID uint64, value int64) (changed bool, err error) {
// Fetch bsiGroup and validate value.
bsig := f.bsiGroup(f.name)
if bsig == nil {
return false, ErrBSIGroupNotFound
} else if value < bsig.Min {
return false, ErrBSIGroupValueTooLow
} else if value > bsig.Max {
return false, ErrBSIGroupValueTooHigh
}
// Fetch target view.
view, err := f.createViewIfNotExists(viewBSIGroupPrefix + f.name)
if err != nil {
return false, errors.Wrap(err, "creating view")
}
// Determine base value to store.
baseValue := uint64(value - bsig.Min)
return view.setValue(columnID, bsig.BitDepth(), baseValue)
}
|
go
|
func (f *Field) SetValue(columnID uint64, value int64) (changed bool, err error) {
// Fetch bsiGroup and validate value.
bsig := f.bsiGroup(f.name)
if bsig == nil {
return false, ErrBSIGroupNotFound
} else if value < bsig.Min {
return false, ErrBSIGroupValueTooLow
} else if value > bsig.Max {
return false, ErrBSIGroupValueTooHigh
}
// Fetch target view.
view, err := f.createViewIfNotExists(viewBSIGroupPrefix + f.name)
if err != nil {
return false, errors.Wrap(err, "creating view")
}
// Determine base value to store.
baseValue := uint64(value - bsig.Min)
return view.setValue(columnID, bsig.BitDepth(), baseValue)
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"SetValue",
"(",
"columnID",
"uint64",
",",
"value",
"int64",
")",
"(",
"changed",
"bool",
",",
"err",
"error",
")",
"{",
"// Fetch bsiGroup and validate value.",
"bsig",
":=",
"f",
".",
"bsiGroup",
"(",
"f",
".",
"name",
")",
"\n",
"if",
"bsig",
"==",
"nil",
"{",
"return",
"false",
",",
"ErrBSIGroupNotFound",
"\n",
"}",
"else",
"if",
"value",
"<",
"bsig",
".",
"Min",
"{",
"return",
"false",
",",
"ErrBSIGroupValueTooLow",
"\n",
"}",
"else",
"if",
"value",
">",
"bsig",
".",
"Max",
"{",
"return",
"false",
",",
"ErrBSIGroupValueTooHigh",
"\n",
"}",
"\n\n",
"// Fetch target view.",
"view",
",",
"err",
":=",
"f",
".",
"createViewIfNotExists",
"(",
"viewBSIGroupPrefix",
"+",
"f",
".",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Determine base value to store.",
"baseValue",
":=",
"uint64",
"(",
"value",
"-",
"bsig",
".",
"Min",
")",
"\n\n",
"return",
"view",
".",
"setValue",
"(",
"columnID",
",",
"bsig",
".",
"BitDepth",
"(",
")",
",",
"baseValue",
")",
"\n",
"}"
] |
// SetValue sets a field value for a column.
|
[
"SetValue",
"sets",
"a",
"field",
"value",
"for",
"a",
"column",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L978-L999
|
train
|
pilosa/pilosa
|
field.go
|
Sum
|
func (f *Field) Sum(filter *Row, name string) (sum, count int64, err error) {
bsig := f.bsiGroup(name)
if bsig == nil {
return 0, 0, ErrBSIGroupNotFound
}
view := f.view(viewBSIGroupPrefix + name)
if view == nil {
return 0, 0, nil
}
vsum, vcount, err := view.sum(filter, bsig.BitDepth())
if err != nil {
return 0, 0, err
}
return int64(vsum) + (int64(vcount) * bsig.Min), int64(vcount), nil
}
|
go
|
func (f *Field) Sum(filter *Row, name string) (sum, count int64, err error) {
bsig := f.bsiGroup(name)
if bsig == nil {
return 0, 0, ErrBSIGroupNotFound
}
view := f.view(viewBSIGroupPrefix + name)
if view == nil {
return 0, 0, nil
}
vsum, vcount, err := view.sum(filter, bsig.BitDepth())
if err != nil {
return 0, 0, err
}
return int64(vsum) + (int64(vcount) * bsig.Min), int64(vcount), nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"Sum",
"(",
"filter",
"*",
"Row",
",",
"name",
"string",
")",
"(",
"sum",
",",
"count",
"int64",
",",
"err",
"error",
")",
"{",
"bsig",
":=",
"f",
".",
"bsiGroup",
"(",
"name",
")",
"\n",
"if",
"bsig",
"==",
"nil",
"{",
"return",
"0",
",",
"0",
",",
"ErrBSIGroupNotFound",
"\n",
"}",
"\n\n",
"view",
":=",
"f",
".",
"view",
"(",
"viewBSIGroupPrefix",
"+",
"name",
")",
"\n",
"if",
"view",
"==",
"nil",
"{",
"return",
"0",
",",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"vsum",
",",
"vcount",
",",
"err",
":=",
"view",
".",
"sum",
"(",
"filter",
",",
"bsig",
".",
"BitDepth",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"int64",
"(",
"vsum",
")",
"+",
"(",
"int64",
"(",
"vcount",
")",
"*",
"bsig",
".",
"Min",
")",
",",
"int64",
"(",
"vcount",
")",
",",
"nil",
"\n",
"}"
] |
// Sum returns the sum and count for a field.
// An optional filtering row can be provided.
|
[
"Sum",
"returns",
"the",
"sum",
"and",
"count",
"for",
"a",
"field",
".",
"An",
"optional",
"filtering",
"row",
"can",
"be",
"provided",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1003-L1019
|
train
|
pilosa/pilosa
|
field.go
|
Min
|
func (f *Field) Min(filter *Row, name string) (min, count int64, err error) {
bsig := f.bsiGroup(name)
if bsig == nil {
return 0, 0, ErrBSIGroupNotFound
}
view := f.view(viewBSIGroupPrefix + name)
if view == nil {
return 0, 0, nil
}
vmin, vcount, err := view.min(filter, bsig.BitDepth())
if err != nil {
return 0, 0, err
}
return int64(vmin) + bsig.Min, int64(vcount), nil
}
|
go
|
func (f *Field) Min(filter *Row, name string) (min, count int64, err error) {
bsig := f.bsiGroup(name)
if bsig == nil {
return 0, 0, ErrBSIGroupNotFound
}
view := f.view(viewBSIGroupPrefix + name)
if view == nil {
return 0, 0, nil
}
vmin, vcount, err := view.min(filter, bsig.BitDepth())
if err != nil {
return 0, 0, err
}
return int64(vmin) + bsig.Min, int64(vcount), nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"Min",
"(",
"filter",
"*",
"Row",
",",
"name",
"string",
")",
"(",
"min",
",",
"count",
"int64",
",",
"err",
"error",
")",
"{",
"bsig",
":=",
"f",
".",
"bsiGroup",
"(",
"name",
")",
"\n",
"if",
"bsig",
"==",
"nil",
"{",
"return",
"0",
",",
"0",
",",
"ErrBSIGroupNotFound",
"\n",
"}",
"\n\n",
"view",
":=",
"f",
".",
"view",
"(",
"viewBSIGroupPrefix",
"+",
"name",
")",
"\n",
"if",
"view",
"==",
"nil",
"{",
"return",
"0",
",",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"vmin",
",",
"vcount",
",",
"err",
":=",
"view",
".",
"min",
"(",
"filter",
",",
"bsig",
".",
"BitDepth",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"int64",
"(",
"vmin",
")",
"+",
"bsig",
".",
"Min",
",",
"int64",
"(",
"vcount",
")",
",",
"nil",
"\n",
"}"
] |
// Min returns the min for a field.
// An optional filtering row can be provided.
|
[
"Min",
"returns",
"the",
"min",
"for",
"a",
"field",
".",
"An",
"optional",
"filtering",
"row",
"can",
"be",
"provided",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1023-L1039
|
train
|
pilosa/pilosa
|
field.go
|
Max
|
func (f *Field) Max(filter *Row, name string) (max, count int64, err error) {
bsig := f.bsiGroup(name)
if bsig == nil {
return 0, 0, ErrBSIGroupNotFound
}
view := f.view(viewBSIGroupPrefix + name)
if view == nil {
return 0, 0, nil
}
vmax, vcount, err := view.max(filter, bsig.BitDepth())
if err != nil {
return 0, 0, err
}
return int64(vmax) + bsig.Min, int64(vcount), nil
}
|
go
|
func (f *Field) Max(filter *Row, name string) (max, count int64, err error) {
bsig := f.bsiGroup(name)
if bsig == nil {
return 0, 0, ErrBSIGroupNotFound
}
view := f.view(viewBSIGroupPrefix + name)
if view == nil {
return 0, 0, nil
}
vmax, vcount, err := view.max(filter, bsig.BitDepth())
if err != nil {
return 0, 0, err
}
return int64(vmax) + bsig.Min, int64(vcount), nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"Max",
"(",
"filter",
"*",
"Row",
",",
"name",
"string",
")",
"(",
"max",
",",
"count",
"int64",
",",
"err",
"error",
")",
"{",
"bsig",
":=",
"f",
".",
"bsiGroup",
"(",
"name",
")",
"\n",
"if",
"bsig",
"==",
"nil",
"{",
"return",
"0",
",",
"0",
",",
"ErrBSIGroupNotFound",
"\n",
"}",
"\n\n",
"view",
":=",
"f",
".",
"view",
"(",
"viewBSIGroupPrefix",
"+",
"name",
")",
"\n",
"if",
"view",
"==",
"nil",
"{",
"return",
"0",
",",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"vmax",
",",
"vcount",
",",
"err",
":=",
"view",
".",
"max",
"(",
"filter",
",",
"bsig",
".",
"BitDepth",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"int64",
"(",
"vmax",
")",
"+",
"bsig",
".",
"Min",
",",
"int64",
"(",
"vcount",
")",
",",
"nil",
"\n",
"}"
] |
// Max returns the max for a field.
// An optional filtering row can be provided.
|
[
"Max",
"returns",
"the",
"max",
"for",
"a",
"field",
".",
"An",
"optional",
"filtering",
"row",
"can",
"be",
"provided",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1043-L1059
|
train
|
pilosa/pilosa
|
field.go
|
Range
|
func (f *Field) Range(name string, op pql.Token, predicate int64) (*Row, error) {
// Retrieve and validate bsiGroup.
bsig := f.bsiGroup(name)
if bsig == nil {
return nil, ErrBSIGroupNotFound
} else if predicate < bsig.Min || predicate > bsig.Max {
return nil, nil
}
// Retrieve bsiGroup's view.
view := f.view(viewBSIGroupPrefix + name)
if view == nil {
return nil, nil
}
baseValue, outOfRange := bsig.baseValue(op, predicate)
if outOfRange {
return NewRow(), nil
}
return view.rangeOp(op, bsig.BitDepth(), baseValue)
}
|
go
|
func (f *Field) Range(name string, op pql.Token, predicate int64) (*Row, error) {
// Retrieve and validate bsiGroup.
bsig := f.bsiGroup(name)
if bsig == nil {
return nil, ErrBSIGroupNotFound
} else if predicate < bsig.Min || predicate > bsig.Max {
return nil, nil
}
// Retrieve bsiGroup's view.
view := f.view(viewBSIGroupPrefix + name)
if view == nil {
return nil, nil
}
baseValue, outOfRange := bsig.baseValue(op, predicate)
if outOfRange {
return NewRow(), nil
}
return view.rangeOp(op, bsig.BitDepth(), baseValue)
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"Range",
"(",
"name",
"string",
",",
"op",
"pql",
".",
"Token",
",",
"predicate",
"int64",
")",
"(",
"*",
"Row",
",",
"error",
")",
"{",
"// Retrieve and validate bsiGroup.",
"bsig",
":=",
"f",
".",
"bsiGroup",
"(",
"name",
")",
"\n",
"if",
"bsig",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrBSIGroupNotFound",
"\n",
"}",
"else",
"if",
"predicate",
"<",
"bsig",
".",
"Min",
"||",
"predicate",
">",
"bsig",
".",
"Max",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"// Retrieve bsiGroup's view.",
"view",
":=",
"f",
".",
"view",
"(",
"viewBSIGroupPrefix",
"+",
"name",
")",
"\n",
"if",
"view",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"baseValue",
",",
"outOfRange",
":=",
"bsig",
".",
"baseValue",
"(",
"op",
",",
"predicate",
")",
"\n",
"if",
"outOfRange",
"{",
"return",
"NewRow",
"(",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"view",
".",
"rangeOp",
"(",
"op",
",",
"bsig",
".",
"BitDepth",
"(",
")",
",",
"baseValue",
")",
"\n",
"}"
] |
// Range performs a conditional operation on Field.
|
[
"Range",
"performs",
"a",
"conditional",
"operation",
"on",
"Field",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1062-L1083
|
train
|
pilosa/pilosa
|
field.go
|
Import
|
func (f *Field) Import(rowIDs, columnIDs []uint64, timestamps []*time.Time, opts ...ImportOption) error {
// Set up import options.
options := &ImportOptions{}
for _, opt := range opts {
err := opt(options)
if err != nil {
return errors.Wrap(err, "applying option")
}
}
// Determine quantum if timestamps are set.
q := f.TimeQuantum()
if hasTime(timestamps) {
if q == "" {
return errors.New("time quantum not set in field")
} else if options.Clear {
return errors.New("import clear is not supported with timestamps")
}
}
fieldType := f.Type()
// Split import data by fragment.
dataByFragment := make(map[importKey]importData)
for i := range rowIDs {
rowID, columnID := rowIDs[i], columnIDs[i]
// Bool-specific data validation.
if fieldType == FieldTypeBool && rowID > 1 {
return errors.New("bool field imports only support values 0 and 1")
}
var timestamp *time.Time
if len(timestamps) > i {
timestamp = timestamps[i]
}
var standard []string
if timestamp == nil {
standard = []string{viewStandard}
} else {
standard = viewsByTime(viewStandard, *timestamp, q)
if !f.options.NoStandardView {
// In order to match the logic of `SetBit()`, we want bits
// with timestamps to write to both time and standard views.
standard = append(standard, viewStandard)
}
}
// Attach bit to each standard view.
for _, name := range standard {
key := importKey{View: name, Shard: columnID / ShardWidth}
data := dataByFragment[key]
data.RowIDs = append(data.RowIDs, rowID)
data.ColumnIDs = append(data.ColumnIDs, columnID)
dataByFragment[key] = data
}
}
// Import into each fragment.
for key, data := range dataByFragment {
view, err := f.createViewIfNotExists(key.View)
if err != nil {
return errors.Wrap(err, "creating view")
}
frag, err := view.CreateFragmentIfNotExists(key.Shard)
if err != nil {
return errors.Wrap(err, "creating fragment")
}
if err := frag.bulkImport(data.RowIDs, data.ColumnIDs, options); err != nil {
return err
}
}
return nil
}
|
go
|
func (f *Field) Import(rowIDs, columnIDs []uint64, timestamps []*time.Time, opts ...ImportOption) error {
// Set up import options.
options := &ImportOptions{}
for _, opt := range opts {
err := opt(options)
if err != nil {
return errors.Wrap(err, "applying option")
}
}
// Determine quantum if timestamps are set.
q := f.TimeQuantum()
if hasTime(timestamps) {
if q == "" {
return errors.New("time quantum not set in field")
} else if options.Clear {
return errors.New("import clear is not supported with timestamps")
}
}
fieldType := f.Type()
// Split import data by fragment.
dataByFragment := make(map[importKey]importData)
for i := range rowIDs {
rowID, columnID := rowIDs[i], columnIDs[i]
// Bool-specific data validation.
if fieldType == FieldTypeBool && rowID > 1 {
return errors.New("bool field imports only support values 0 and 1")
}
var timestamp *time.Time
if len(timestamps) > i {
timestamp = timestamps[i]
}
var standard []string
if timestamp == nil {
standard = []string{viewStandard}
} else {
standard = viewsByTime(viewStandard, *timestamp, q)
if !f.options.NoStandardView {
// In order to match the logic of `SetBit()`, we want bits
// with timestamps to write to both time and standard views.
standard = append(standard, viewStandard)
}
}
// Attach bit to each standard view.
for _, name := range standard {
key := importKey{View: name, Shard: columnID / ShardWidth}
data := dataByFragment[key]
data.RowIDs = append(data.RowIDs, rowID)
data.ColumnIDs = append(data.ColumnIDs, columnID)
dataByFragment[key] = data
}
}
// Import into each fragment.
for key, data := range dataByFragment {
view, err := f.createViewIfNotExists(key.View)
if err != nil {
return errors.Wrap(err, "creating view")
}
frag, err := view.CreateFragmentIfNotExists(key.Shard)
if err != nil {
return errors.Wrap(err, "creating fragment")
}
if err := frag.bulkImport(data.RowIDs, data.ColumnIDs, options); err != nil {
return err
}
}
return nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"Import",
"(",
"rowIDs",
",",
"columnIDs",
"[",
"]",
"uint64",
",",
"timestamps",
"[",
"]",
"*",
"time",
".",
"Time",
",",
"opts",
"...",
"ImportOption",
")",
"error",
"{",
"// Set up import options.",
"options",
":=",
"&",
"ImportOptions",
"{",
"}",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"err",
":=",
"opt",
"(",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Determine quantum if timestamps are set.",
"q",
":=",
"f",
".",
"TimeQuantum",
"(",
")",
"\n",
"if",
"hasTime",
"(",
"timestamps",
")",
"{",
"if",
"q",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"options",
".",
"Clear",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"fieldType",
":=",
"f",
".",
"Type",
"(",
")",
"\n\n",
"// Split import data by fragment.",
"dataByFragment",
":=",
"make",
"(",
"map",
"[",
"importKey",
"]",
"importData",
")",
"\n",
"for",
"i",
":=",
"range",
"rowIDs",
"{",
"rowID",
",",
"columnID",
":=",
"rowIDs",
"[",
"i",
"]",
",",
"columnIDs",
"[",
"i",
"]",
"\n\n",
"// Bool-specific data validation.",
"if",
"fieldType",
"==",
"FieldTypeBool",
"&&",
"rowID",
">",
"1",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"timestamp",
"*",
"time",
".",
"Time",
"\n",
"if",
"len",
"(",
"timestamps",
")",
">",
"i",
"{",
"timestamp",
"=",
"timestamps",
"[",
"i",
"]",
"\n",
"}",
"\n\n",
"var",
"standard",
"[",
"]",
"string",
"\n",
"if",
"timestamp",
"==",
"nil",
"{",
"standard",
"=",
"[",
"]",
"string",
"{",
"viewStandard",
"}",
"\n",
"}",
"else",
"{",
"standard",
"=",
"viewsByTime",
"(",
"viewStandard",
",",
"*",
"timestamp",
",",
"q",
")",
"\n",
"if",
"!",
"f",
".",
"options",
".",
"NoStandardView",
"{",
"// In order to match the logic of `SetBit()`, we want bits",
"// with timestamps to write to both time and standard views.",
"standard",
"=",
"append",
"(",
"standard",
",",
"viewStandard",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Attach bit to each standard view.",
"for",
"_",
",",
"name",
":=",
"range",
"standard",
"{",
"key",
":=",
"importKey",
"{",
"View",
":",
"name",
",",
"Shard",
":",
"columnID",
"/",
"ShardWidth",
"}",
"\n",
"data",
":=",
"dataByFragment",
"[",
"key",
"]",
"\n",
"data",
".",
"RowIDs",
"=",
"append",
"(",
"data",
".",
"RowIDs",
",",
"rowID",
")",
"\n",
"data",
".",
"ColumnIDs",
"=",
"append",
"(",
"data",
".",
"ColumnIDs",
",",
"columnID",
")",
"\n",
"dataByFragment",
"[",
"key",
"]",
"=",
"data",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Import into each fragment.",
"for",
"key",
",",
"data",
":=",
"range",
"dataByFragment",
"{",
"view",
",",
"err",
":=",
"f",
".",
"createViewIfNotExists",
"(",
"key",
".",
"View",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"frag",
",",
"err",
":=",
"view",
".",
"CreateFragmentIfNotExists",
"(",
"key",
".",
"Shard",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"frag",
".",
"bulkImport",
"(",
"data",
".",
"RowIDs",
",",
"data",
".",
"ColumnIDs",
",",
"options",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Import bulk imports data.
|
[
"Import",
"bulk",
"imports",
"data",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1086-L1164
|
train
|
pilosa/pilosa
|
field.go
|
importValue
|
func (f *Field) importValue(columnIDs []uint64, values []int64, options *ImportOptions) error {
viewName := viewBSIGroupPrefix + f.name
// Get the bsiGroup so we know bitDepth.
bsig := f.bsiGroup(f.name)
if bsig == nil {
return errors.Wrap(ErrBSIGroupNotFound, f.name)
}
// Split import data by fragment.
dataByFragment := make(map[importKey]importValueData)
for i := range columnIDs {
columnID, value := columnIDs[i], values[i]
if value > bsig.Max {
return fmt.Errorf("%v, columnID=%v, value=%v", ErrBSIGroupValueTooHigh, columnID, value)
} else if value < bsig.Min {
return fmt.Errorf("%v, columnID=%v, value=%v", ErrBSIGroupValueTooLow, columnID, value)
}
// Attach value to each bsiGroup view.
for _, name := range []string{viewName} {
key := importKey{View: name, Shard: columnID / ShardWidth}
data := dataByFragment[key]
data.ColumnIDs = append(data.ColumnIDs, columnID)
data.Values = append(data.Values, value)
dataByFragment[key] = data
}
}
// Import into each fragment.
for key, data := range dataByFragment {
// The view must already exist (i.e. we can't create it)
// because we need to know bitDepth (based on min/max value).
view, err := f.createViewIfNotExists(key.View)
if err != nil {
return errors.Wrap(err, "creating view")
}
frag, err := view.CreateFragmentIfNotExists(key.Shard)
if err != nil {
return errors.Wrap(err, "creating fragment")
}
baseValues := make([]uint64, len(data.Values))
for i, value := range data.Values {
baseValues[i] = uint64(value - bsig.Min)
}
if err := frag.importValue(data.ColumnIDs, baseValues, bsig.BitDepth(), options.Clear); err != nil {
return err
}
}
return nil
}
|
go
|
func (f *Field) importValue(columnIDs []uint64, values []int64, options *ImportOptions) error {
viewName := viewBSIGroupPrefix + f.name
// Get the bsiGroup so we know bitDepth.
bsig := f.bsiGroup(f.name)
if bsig == nil {
return errors.Wrap(ErrBSIGroupNotFound, f.name)
}
// Split import data by fragment.
dataByFragment := make(map[importKey]importValueData)
for i := range columnIDs {
columnID, value := columnIDs[i], values[i]
if value > bsig.Max {
return fmt.Errorf("%v, columnID=%v, value=%v", ErrBSIGroupValueTooHigh, columnID, value)
} else if value < bsig.Min {
return fmt.Errorf("%v, columnID=%v, value=%v", ErrBSIGroupValueTooLow, columnID, value)
}
// Attach value to each bsiGroup view.
for _, name := range []string{viewName} {
key := importKey{View: name, Shard: columnID / ShardWidth}
data := dataByFragment[key]
data.ColumnIDs = append(data.ColumnIDs, columnID)
data.Values = append(data.Values, value)
dataByFragment[key] = data
}
}
// Import into each fragment.
for key, data := range dataByFragment {
// The view must already exist (i.e. we can't create it)
// because we need to know bitDepth (based on min/max value).
view, err := f.createViewIfNotExists(key.View)
if err != nil {
return errors.Wrap(err, "creating view")
}
frag, err := view.CreateFragmentIfNotExists(key.Shard)
if err != nil {
return errors.Wrap(err, "creating fragment")
}
baseValues := make([]uint64, len(data.Values))
for i, value := range data.Values {
baseValues[i] = uint64(value - bsig.Min)
}
if err := frag.importValue(data.ColumnIDs, baseValues, bsig.BitDepth(), options.Clear); err != nil {
return err
}
}
return nil
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"importValue",
"(",
"columnIDs",
"[",
"]",
"uint64",
",",
"values",
"[",
"]",
"int64",
",",
"options",
"*",
"ImportOptions",
")",
"error",
"{",
"viewName",
":=",
"viewBSIGroupPrefix",
"+",
"f",
".",
"name",
"\n",
"// Get the bsiGroup so we know bitDepth.",
"bsig",
":=",
"f",
".",
"bsiGroup",
"(",
"f",
".",
"name",
")",
"\n",
"if",
"bsig",
"==",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"ErrBSIGroupNotFound",
",",
"f",
".",
"name",
")",
"\n",
"}",
"\n\n",
"// Split import data by fragment.",
"dataByFragment",
":=",
"make",
"(",
"map",
"[",
"importKey",
"]",
"importValueData",
")",
"\n",
"for",
"i",
":=",
"range",
"columnIDs",
"{",
"columnID",
",",
"value",
":=",
"columnIDs",
"[",
"i",
"]",
",",
"values",
"[",
"i",
"]",
"\n",
"if",
"value",
">",
"bsig",
".",
"Max",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ErrBSIGroupValueTooHigh",
",",
"columnID",
",",
"value",
")",
"\n",
"}",
"else",
"if",
"value",
"<",
"bsig",
".",
"Min",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ErrBSIGroupValueTooLow",
",",
"columnID",
",",
"value",
")",
"\n",
"}",
"\n\n",
"// Attach value to each bsiGroup view.",
"for",
"_",
",",
"name",
":=",
"range",
"[",
"]",
"string",
"{",
"viewName",
"}",
"{",
"key",
":=",
"importKey",
"{",
"View",
":",
"name",
",",
"Shard",
":",
"columnID",
"/",
"ShardWidth",
"}",
"\n",
"data",
":=",
"dataByFragment",
"[",
"key",
"]",
"\n",
"data",
".",
"ColumnIDs",
"=",
"append",
"(",
"data",
".",
"ColumnIDs",
",",
"columnID",
")",
"\n",
"data",
".",
"Values",
"=",
"append",
"(",
"data",
".",
"Values",
",",
"value",
")",
"\n",
"dataByFragment",
"[",
"key",
"]",
"=",
"data",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Import into each fragment.",
"for",
"key",
",",
"data",
":=",
"range",
"dataByFragment",
"{",
"// The view must already exist (i.e. we can't create it)",
"// because we need to know bitDepth (based on min/max value).",
"view",
",",
"err",
":=",
"f",
".",
"createViewIfNotExists",
"(",
"key",
".",
"View",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"frag",
",",
"err",
":=",
"view",
".",
"CreateFragmentIfNotExists",
"(",
"key",
".",
"Shard",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"baseValues",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"len",
"(",
"data",
".",
"Values",
")",
")",
"\n",
"for",
"i",
",",
"value",
":=",
"range",
"data",
".",
"Values",
"{",
"baseValues",
"[",
"i",
"]",
"=",
"uint64",
"(",
"value",
"-",
"bsig",
".",
"Min",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"frag",
".",
"importValue",
"(",
"data",
".",
"ColumnIDs",
",",
"baseValues",
",",
"bsig",
".",
"BitDepth",
"(",
")",
",",
"options",
".",
"Clear",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// importValue bulk imports range-encoded value data.
|
[
"importValue",
"bulk",
"imports",
"range",
"-",
"encoded",
"value",
"data",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1167-L1221
|
train
|
pilosa/pilosa
|
field.go
|
applyDefaultOptions
|
func applyDefaultOptions(o FieldOptions) FieldOptions {
if o.Type == "" {
return FieldOptions{
Type: DefaultFieldType,
CacheType: DefaultCacheType,
CacheSize: DefaultCacheSize,
}
}
return o
}
|
go
|
func applyDefaultOptions(o FieldOptions) FieldOptions {
if o.Type == "" {
return FieldOptions{
Type: DefaultFieldType,
CacheType: DefaultCacheType,
CacheSize: DefaultCacheSize,
}
}
return o
}
|
[
"func",
"applyDefaultOptions",
"(",
"o",
"FieldOptions",
")",
"FieldOptions",
"{",
"if",
"o",
".",
"Type",
"==",
"\"",
"\"",
"{",
"return",
"FieldOptions",
"{",
"Type",
":",
"DefaultFieldType",
",",
"CacheType",
":",
"DefaultCacheType",
",",
"CacheSize",
":",
"DefaultCacheSize",
",",
"}",
"\n",
"}",
"\n",
"return",
"o",
"\n",
"}"
] |
// applyDefaultOptions returns a new FieldOptions object
// with default values if o does not contain a valid type.
|
[
"applyDefaultOptions",
"returns",
"a",
"new",
"FieldOptions",
"object",
"with",
"default",
"values",
"if",
"o",
"does",
"not",
"contain",
"a",
"valid",
"type",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1281-L1290
|
train
|
pilosa/pilosa
|
field.go
|
MarshalJSON
|
func (o *FieldOptions) MarshalJSON() ([]byte, error) {
switch o.Type {
case FieldTypeSet:
return json.Marshal(struct {
Type string `json:"type"`
CacheType string `json:"cacheType"`
CacheSize uint32 `json:"cacheSize"`
Keys bool `json:"keys"`
}{
o.Type,
o.CacheType,
o.CacheSize,
o.Keys,
})
case FieldTypeInt:
return json.Marshal(struct {
Type string `json:"type"`
Min int64 `json:"min"`
Max int64 `json:"max"`
Keys bool `json:"keys"`
}{
o.Type,
o.Min,
o.Max,
o.Keys,
})
case FieldTypeTime:
return json.Marshal(struct {
Type string `json:"type"`
TimeQuantum TimeQuantum `json:"timeQuantum"`
Keys bool `json:"keys"`
NoStandardView bool `json:"noStandardView"`
}{
o.Type,
o.TimeQuantum,
o.Keys,
o.NoStandardView,
})
case FieldTypeMutex:
return json.Marshal(struct {
Type string `json:"type"`
CacheType string `json:"cacheType"`
CacheSize uint32 `json:"cacheSize"`
Keys bool `json:"keys"`
}{
o.Type,
o.CacheType,
o.CacheSize,
o.Keys,
})
case FieldTypeBool:
return json.Marshal(struct {
Type string `json:"type"`
}{
o.Type,
})
}
return nil, errors.New("invalid field type")
}
|
go
|
func (o *FieldOptions) MarshalJSON() ([]byte, error) {
switch o.Type {
case FieldTypeSet:
return json.Marshal(struct {
Type string `json:"type"`
CacheType string `json:"cacheType"`
CacheSize uint32 `json:"cacheSize"`
Keys bool `json:"keys"`
}{
o.Type,
o.CacheType,
o.CacheSize,
o.Keys,
})
case FieldTypeInt:
return json.Marshal(struct {
Type string `json:"type"`
Min int64 `json:"min"`
Max int64 `json:"max"`
Keys bool `json:"keys"`
}{
o.Type,
o.Min,
o.Max,
o.Keys,
})
case FieldTypeTime:
return json.Marshal(struct {
Type string `json:"type"`
TimeQuantum TimeQuantum `json:"timeQuantum"`
Keys bool `json:"keys"`
NoStandardView bool `json:"noStandardView"`
}{
o.Type,
o.TimeQuantum,
o.Keys,
o.NoStandardView,
})
case FieldTypeMutex:
return json.Marshal(struct {
Type string `json:"type"`
CacheType string `json:"cacheType"`
CacheSize uint32 `json:"cacheSize"`
Keys bool `json:"keys"`
}{
o.Type,
o.CacheType,
o.CacheSize,
o.Keys,
})
case FieldTypeBool:
return json.Marshal(struct {
Type string `json:"type"`
}{
o.Type,
})
}
return nil, errors.New("invalid field type")
}
|
[
"func",
"(",
"o",
"*",
"FieldOptions",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"switch",
"o",
".",
"Type",
"{",
"case",
"FieldTypeSet",
":",
"return",
"json",
".",
"Marshal",
"(",
"struct",
"{",
"Type",
"string",
"`json:\"type\"`",
"\n",
"CacheType",
"string",
"`json:\"cacheType\"`",
"\n",
"CacheSize",
"uint32",
"`json:\"cacheSize\"`",
"\n",
"Keys",
"bool",
"`json:\"keys\"`",
"\n",
"}",
"{",
"o",
".",
"Type",
",",
"o",
".",
"CacheType",
",",
"o",
".",
"CacheSize",
",",
"o",
".",
"Keys",
",",
"}",
")",
"\n",
"case",
"FieldTypeInt",
":",
"return",
"json",
".",
"Marshal",
"(",
"struct",
"{",
"Type",
"string",
"`json:\"type\"`",
"\n",
"Min",
"int64",
"`json:\"min\"`",
"\n",
"Max",
"int64",
"`json:\"max\"`",
"\n",
"Keys",
"bool",
"`json:\"keys\"`",
"\n",
"}",
"{",
"o",
".",
"Type",
",",
"o",
".",
"Min",
",",
"o",
".",
"Max",
",",
"o",
".",
"Keys",
",",
"}",
")",
"\n",
"case",
"FieldTypeTime",
":",
"return",
"json",
".",
"Marshal",
"(",
"struct",
"{",
"Type",
"string",
"`json:\"type\"`",
"\n",
"TimeQuantum",
"TimeQuantum",
"`json:\"timeQuantum\"`",
"\n",
"Keys",
"bool",
"`json:\"keys\"`",
"\n",
"NoStandardView",
"bool",
"`json:\"noStandardView\"`",
"\n",
"}",
"{",
"o",
".",
"Type",
",",
"o",
".",
"TimeQuantum",
",",
"o",
".",
"Keys",
",",
"o",
".",
"NoStandardView",
",",
"}",
")",
"\n",
"case",
"FieldTypeMutex",
":",
"return",
"json",
".",
"Marshal",
"(",
"struct",
"{",
"Type",
"string",
"`json:\"type\"`",
"\n",
"CacheType",
"string",
"`json:\"cacheType\"`",
"\n",
"CacheSize",
"uint32",
"`json:\"cacheSize\"`",
"\n",
"Keys",
"bool",
"`json:\"keys\"`",
"\n",
"}",
"{",
"o",
".",
"Type",
",",
"o",
".",
"CacheType",
",",
"o",
".",
"CacheSize",
",",
"o",
".",
"Keys",
",",
"}",
")",
"\n",
"case",
"FieldTypeBool",
":",
"return",
"json",
".",
"Marshal",
"(",
"struct",
"{",
"Type",
"string",
"`json:\"type\"`",
"\n",
"}",
"{",
"o",
".",
"Type",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// MarshalJSON marshals FieldOptions to JSON such that
// only those attributes associated to the field type
// are included.
|
[
"MarshalJSON",
"marshals",
"FieldOptions",
"to",
"JSON",
"such",
"that",
"only",
"those",
"attributes",
"associated",
"to",
"the",
"field",
"type",
"are",
"included",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1316-L1374
|
train
|
pilosa/pilosa
|
field.go
|
BitDepth
|
func (b *bsiGroup) BitDepth() uint {
for i := uint(0); i < 63; i++ {
if b.Max-b.Min < (1 << i) {
return i
}
}
return 63
}
|
go
|
func (b *bsiGroup) BitDepth() uint {
for i := uint(0); i < 63; i++ {
if b.Max-b.Min < (1 << i) {
return i
}
}
return 63
}
|
[
"func",
"(",
"b",
"*",
"bsiGroup",
")",
"BitDepth",
"(",
")",
"uint",
"{",
"for",
"i",
":=",
"uint",
"(",
"0",
")",
";",
"i",
"<",
"63",
";",
"i",
"++",
"{",
"if",
"b",
".",
"Max",
"-",
"b",
".",
"Min",
"<",
"(",
"1",
"<<",
"i",
")",
"{",
"return",
"i",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"63",
"\n",
"}"
] |
// BitDepth returns the number of bits required to store a value between min & max.
|
[
"BitDepth",
"returns",
"the",
"number",
"of",
"bits",
"required",
"to",
"store",
"a",
"value",
"between",
"min",
"&",
"max",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1399-L1406
|
train
|
pilosa/pilosa
|
field.go
|
isValidCacheType
|
func isValidCacheType(v string) bool {
switch v {
case CacheTypeLRU, CacheTypeRanked, CacheTypeNone:
return true
default:
return false
}
}
|
go
|
func isValidCacheType(v string) bool {
switch v {
case CacheTypeLRU, CacheTypeRanked, CacheTypeNone:
return true
default:
return false
}
}
|
[
"func",
"isValidCacheType",
"(",
"v",
"string",
")",
"bool",
"{",
"switch",
"v",
"{",
"case",
"CacheTypeLRU",
",",
"CacheTypeRanked",
",",
"CacheTypeNone",
":",
"return",
"true",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"}"
] |
// isValidCacheType returns true if v is a valid cache type.
|
[
"isValidCacheType",
"returns",
"true",
"if",
"v",
"is",
"a",
"valid",
"cache",
"type",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/field.go#L1481-L1488
|
train
|
pilosa/pilosa
|
gopsutil/systeminfo.go
|
Uptime
|
func (s *systemInfo) Uptime() (uptime uint64, err error) {
hostInfo, err := host.Info()
if err != nil {
return 0, err
}
return hostInfo.Uptime, nil
}
|
go
|
func (s *systemInfo) Uptime() (uptime uint64, err error) {
hostInfo, err := host.Info()
if err != nil {
return 0, err
}
return hostInfo.Uptime, nil
}
|
[
"func",
"(",
"s",
"*",
"systemInfo",
")",
"Uptime",
"(",
")",
"(",
"uptime",
"uint64",
",",
"err",
"error",
")",
"{",
"hostInfo",
",",
"err",
":=",
"host",
".",
"Info",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"hostInfo",
".",
"Uptime",
",",
"nil",
"\n",
"}"
] |
// Uptime returns the system uptime in seconds.
|
[
"Uptime",
"returns",
"the",
"system",
"uptime",
"in",
"seconds",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L41-L47
|
train
|
pilosa/pilosa
|
gopsutil/systeminfo.go
|
collectPlatformInfo
|
func (s *systemInfo) collectPlatformInfo() error {
var err error
if s.platform == "" {
s.platform, s.family, s.osVersion, err = host.PlatformInformation()
if err != nil {
return err
}
}
if s.cpuModel == "" {
infos, err := cpu.Info()
if err != nil || len(infos) == 0 {
s.cpuModel = "unknown"
// if err is nil, but we got no infos, we don't
// have a meaningful error to return.
return err
}
s.cpuModel = infos[0].ModelName
s.cpuMHz = computeMHz(s.cpuModel)
// gopsutil reports core and clock speed info inconsistently
// by OS
switch runtime.GOOS {
case "linux":
// Each reported "CPU" is a logical core. Some cores may
// have the same Core ID, which is a strictly numeric
// value which gopsutil returned as a string, which
// indicates that they're hyperthreading or similar things
// on the same physical core.
uniqueCores := make(map[string]struct{}, len(infos))
totalCores := 0
for _, info := range infos {
uniqueCores[info.CoreID] = struct{}{}
totalCores += int(info.Cores)
}
s.cpuPhysicalCores = len(uniqueCores)
s.cpuLogicalCores = totalCores
case "darwin":
fallthrough
default: // let's hope other systems give useful core info?
s.cpuPhysicalCores = int(infos[0].Cores)
// we have no way to know, let's try runtime
s.cpuLogicalCores = runtime.NumCPU()
}
return nil
}
return nil
}
|
go
|
func (s *systemInfo) collectPlatformInfo() error {
var err error
if s.platform == "" {
s.platform, s.family, s.osVersion, err = host.PlatformInformation()
if err != nil {
return err
}
}
if s.cpuModel == "" {
infos, err := cpu.Info()
if err != nil || len(infos) == 0 {
s.cpuModel = "unknown"
// if err is nil, but we got no infos, we don't
// have a meaningful error to return.
return err
}
s.cpuModel = infos[0].ModelName
s.cpuMHz = computeMHz(s.cpuModel)
// gopsutil reports core and clock speed info inconsistently
// by OS
switch runtime.GOOS {
case "linux":
// Each reported "CPU" is a logical core. Some cores may
// have the same Core ID, which is a strictly numeric
// value which gopsutil returned as a string, which
// indicates that they're hyperthreading or similar things
// on the same physical core.
uniqueCores := make(map[string]struct{}, len(infos))
totalCores := 0
for _, info := range infos {
uniqueCores[info.CoreID] = struct{}{}
totalCores += int(info.Cores)
}
s.cpuPhysicalCores = len(uniqueCores)
s.cpuLogicalCores = totalCores
case "darwin":
fallthrough
default: // let's hope other systems give useful core info?
s.cpuPhysicalCores = int(infos[0].Cores)
// we have no way to know, let's try runtime
s.cpuLogicalCores = runtime.NumCPU()
}
return nil
}
return nil
}
|
[
"func",
"(",
"s",
"*",
"systemInfo",
")",
"collectPlatformInfo",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"if",
"s",
".",
"platform",
"==",
"\"",
"\"",
"{",
"s",
".",
"platform",
",",
"s",
".",
"family",
",",
"s",
".",
"osVersion",
",",
"err",
"=",
"host",
".",
"PlatformInformation",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"s",
".",
"cpuModel",
"==",
"\"",
"\"",
"{",
"infos",
",",
"err",
":=",
"cpu",
".",
"Info",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"len",
"(",
"infos",
")",
"==",
"0",
"{",
"s",
".",
"cpuModel",
"=",
"\"",
"\"",
"\n",
"// if err is nil, but we got no infos, we don't",
"// have a meaningful error to return.",
"return",
"err",
"\n",
"}",
"\n",
"s",
".",
"cpuModel",
"=",
"infos",
"[",
"0",
"]",
".",
"ModelName",
"\n",
"s",
".",
"cpuMHz",
"=",
"computeMHz",
"(",
"s",
".",
"cpuModel",
")",
"\n\n",
"// gopsutil reports core and clock speed info inconsistently",
"// by OS",
"switch",
"runtime",
".",
"GOOS",
"{",
"case",
"\"",
"\"",
":",
"// Each reported \"CPU\" is a logical core. Some cores may",
"// have the same Core ID, which is a strictly numeric",
"// value which gopsutil returned as a string, which",
"// indicates that they're hyperthreading or similar things",
"// on the same physical core.",
"uniqueCores",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
",",
"len",
"(",
"infos",
")",
")",
"\n",
"totalCores",
":=",
"0",
"\n",
"for",
"_",
",",
"info",
":=",
"range",
"infos",
"{",
"uniqueCores",
"[",
"info",
".",
"CoreID",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"totalCores",
"+=",
"int",
"(",
"info",
".",
"Cores",
")",
"\n",
"}",
"\n",
"s",
".",
"cpuPhysicalCores",
"=",
"len",
"(",
"uniqueCores",
")",
"\n",
"s",
".",
"cpuLogicalCores",
"=",
"totalCores",
"\n",
"case",
"\"",
"\"",
":",
"fallthrough",
"\n",
"default",
":",
"// let's hope other systems give useful core info?",
"s",
".",
"cpuPhysicalCores",
"=",
"int",
"(",
"infos",
"[",
"0",
"]",
".",
"Cores",
")",
"\n",
"// we have no way to know, let's try runtime",
"s",
".",
"cpuLogicalCores",
"=",
"runtime",
".",
"NumCPU",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// collectPlatformInfo fetches and caches system platform information.
|
[
"collectPlatformInfo",
"fetches",
"and",
"caches",
"system",
"platform",
"information",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L99-L145
|
train
|
pilosa/pilosa
|
gopsutil/systeminfo.go
|
Platform
|
func (s *systemInfo) Platform() (string, error) {
err := s.collectPlatformInfo()
if err != nil {
return "", err
}
return s.platform, nil
}
|
go
|
func (s *systemInfo) Platform() (string, error) {
err := s.collectPlatformInfo()
if err != nil {
return "", err
}
return s.platform, nil
}
|
[
"func",
"(",
"s",
"*",
"systemInfo",
")",
"Platform",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"err",
":=",
"s",
".",
"collectPlatformInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"s",
".",
"platform",
",",
"nil",
"\n",
"}"
] |
// Platform returns the system platform.
|
[
"Platform",
"returns",
"the",
"system",
"platform",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L148-L154
|
train
|
pilosa/pilosa
|
gopsutil/systeminfo.go
|
Family
|
func (s *systemInfo) Family() (string, error) {
err := s.collectPlatformInfo()
if err != nil {
return "", err
}
return s.family, err
}
|
go
|
func (s *systemInfo) Family() (string, error) {
err := s.collectPlatformInfo()
if err != nil {
return "", err
}
return s.family, err
}
|
[
"func",
"(",
"s",
"*",
"systemInfo",
")",
"Family",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"err",
":=",
"s",
".",
"collectPlatformInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"s",
".",
"family",
",",
"err",
"\n",
"}"
] |
// Family returns the system family.
|
[
"Family",
"returns",
"the",
"system",
"family",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L157-L163
|
train
|
pilosa/pilosa
|
gopsutil/systeminfo.go
|
OSVersion
|
func (s *systemInfo) OSVersion() (string, error) {
err := s.collectPlatformInfo()
if err != nil {
return "", err
}
return s.osVersion, err
}
|
go
|
func (s *systemInfo) OSVersion() (string, error) {
err := s.collectPlatformInfo()
if err != nil {
return "", err
}
return s.osVersion, err
}
|
[
"func",
"(",
"s",
"*",
"systemInfo",
")",
"OSVersion",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"err",
":=",
"s",
".",
"collectPlatformInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"s",
".",
"osVersion",
",",
"err",
"\n",
"}"
] |
// OSVersion returns the OS Version.
|
[
"OSVersion",
"returns",
"the",
"OS",
"Version",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L166-L172
|
train
|
pilosa/pilosa
|
gopsutil/systeminfo.go
|
MemFree
|
func (s *systemInfo) MemFree() (uint64, error) {
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, err
}
return memInfo.Free, err
}
|
go
|
func (s *systemInfo) MemFree() (uint64, error) {
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, err
}
return memInfo.Free, err
}
|
[
"func",
"(",
"s",
"*",
"systemInfo",
")",
"MemFree",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"memInfo",
",",
"err",
":=",
"mem",
".",
"VirtualMemory",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"memInfo",
".",
"Free",
",",
"err",
"\n",
"}"
] |
// MemFree returns the amount of free memory in bytes.
|
[
"MemFree",
"returns",
"the",
"amount",
"of",
"free",
"memory",
"in",
"bytes",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L175-L181
|
train
|
pilosa/pilosa
|
gopsutil/systeminfo.go
|
MemTotal
|
func (s *systemInfo) MemTotal() (uint64, error) {
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, err
}
return memInfo.Total, err
}
|
go
|
func (s *systemInfo) MemTotal() (uint64, error) {
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, err
}
return memInfo.Total, err
}
|
[
"func",
"(",
"s",
"*",
"systemInfo",
")",
"MemTotal",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"memInfo",
",",
"err",
":=",
"mem",
".",
"VirtualMemory",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"memInfo",
".",
"Total",
",",
"err",
"\n",
"}"
] |
// MemTotal returns the amount of total memory in bytes.
|
[
"MemTotal",
"returns",
"the",
"amount",
"of",
"total",
"memory",
"in",
"bytes",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L184-L190
|
train
|
pilosa/pilosa
|
gopsutil/systeminfo.go
|
MemUsed
|
func (s *systemInfo) MemUsed() (uint64, error) {
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, err
}
return memInfo.Used, err
}
|
go
|
func (s *systemInfo) MemUsed() (uint64, error) {
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, err
}
return memInfo.Used, err
}
|
[
"func",
"(",
"s",
"*",
"systemInfo",
")",
"MemUsed",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"memInfo",
",",
"err",
":=",
"mem",
".",
"VirtualMemory",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"memInfo",
".",
"Used",
",",
"err",
"\n",
"}"
] |
// MemUsed returns the amount of used memory in bytes.
|
[
"MemUsed",
"returns",
"the",
"amount",
"of",
"used",
"memory",
"in",
"bytes",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L193-L199
|
train
|
pilosa/pilosa
|
gopsutil/systeminfo.go
|
CPUModel
|
func (s *systemInfo) CPUModel() string {
err := s.collectPlatformInfo()
if err != nil {
return "unknown"
}
return s.cpuModel
}
|
go
|
func (s *systemInfo) CPUModel() string {
err := s.collectPlatformInfo()
if err != nil {
return "unknown"
}
return s.cpuModel
}
|
[
"func",
"(",
"s",
"*",
"systemInfo",
")",
"CPUModel",
"(",
")",
"string",
"{",
"err",
":=",
"s",
".",
"collectPlatformInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"s",
".",
"cpuModel",
"\n",
"}"
] |
// CPUModel returns the CPU model string
|
[
"CPUModel",
"returns",
"the",
"CPU",
"model",
"string"
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L212-L218
|
train
|
pilosa/pilosa
|
gopsutil/systeminfo.go
|
CPUMHz
|
func (s *systemInfo) CPUMHz() (int, error) {
err := s.collectPlatformInfo()
if err != nil {
return 0, err
}
return s.cpuMHz, nil
}
|
go
|
func (s *systemInfo) CPUMHz() (int, error) {
err := s.collectPlatformInfo()
if err != nil {
return 0, err
}
return s.cpuMHz, nil
}
|
[
"func",
"(",
"s",
"*",
"systemInfo",
")",
"CPUMHz",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"err",
":=",
"s",
".",
"collectPlatformInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"s",
".",
"cpuMHz",
",",
"nil",
"\n",
"}"
] |
// CPUMhz returns the CPU clock speed
|
[
"CPUMhz",
"returns",
"the",
"CPU",
"clock",
"speed"
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/gopsutil/systeminfo.go#L221-L227
|
train
|
pilosa/pilosa
|
iterator.go
|
Next
|
func (itr *bufIterator) Next() (rowID, columnID uint64, eof bool) {
if itr.buf.full {
itr.buf.full = false
return itr.buf.rowID, itr.buf.columnID, itr.buf.eof
}
// Read values onto buffer in case of unread.
itr.buf.rowID, itr.buf.columnID, itr.buf.eof = itr.itr.Next()
return itr.buf.rowID, itr.buf.columnID, itr.buf.eof
}
|
go
|
func (itr *bufIterator) Next() (rowID, columnID uint64, eof bool) {
if itr.buf.full {
itr.buf.full = false
return itr.buf.rowID, itr.buf.columnID, itr.buf.eof
}
// Read values onto buffer in case of unread.
itr.buf.rowID, itr.buf.columnID, itr.buf.eof = itr.itr.Next()
return itr.buf.rowID, itr.buf.columnID, itr.buf.eof
}
|
[
"func",
"(",
"itr",
"*",
"bufIterator",
")",
"Next",
"(",
")",
"(",
"rowID",
",",
"columnID",
"uint64",
",",
"eof",
"bool",
")",
"{",
"if",
"itr",
".",
"buf",
".",
"full",
"{",
"itr",
".",
"buf",
".",
"full",
"=",
"false",
"\n",
"return",
"itr",
".",
"buf",
".",
"rowID",
",",
"itr",
".",
"buf",
".",
"columnID",
",",
"itr",
".",
"buf",
".",
"eof",
"\n",
"}",
"\n\n",
"// Read values onto buffer in case of unread.",
"itr",
".",
"buf",
".",
"rowID",
",",
"itr",
".",
"buf",
".",
"columnID",
",",
"itr",
".",
"buf",
".",
"eof",
"=",
"itr",
".",
"itr",
".",
"Next",
"(",
")",
"\n\n",
"return",
"itr",
".",
"buf",
".",
"rowID",
",",
"itr",
".",
"buf",
".",
"columnID",
",",
"itr",
".",
"buf",
".",
"eof",
"\n",
"}"
] |
// Next returns the next pair in the row.
// If a value has been buffered then it is returned and the buffer is cleared.
|
[
"Next",
"returns",
"the",
"next",
"pair",
"in",
"the",
"row",
".",
"If",
"a",
"value",
"has",
"been",
"buffered",
"then",
"it",
"is",
"returned",
"and",
"the",
"buffer",
"is",
"cleared",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/iterator.go#L53-L63
|
train
|
pilosa/pilosa
|
iterator.go
|
Peek
|
func (itr *bufIterator) Peek() (rowID, columnID uint64, eof bool) {
rowID, columnID, eof = itr.Next()
itr.Unread()
return
}
|
go
|
func (itr *bufIterator) Peek() (rowID, columnID uint64, eof bool) {
rowID, columnID, eof = itr.Next()
itr.Unread()
return
}
|
[
"func",
"(",
"itr",
"*",
"bufIterator",
")",
"Peek",
"(",
")",
"(",
"rowID",
",",
"columnID",
"uint64",
",",
"eof",
"bool",
")",
"{",
"rowID",
",",
"columnID",
",",
"eof",
"=",
"itr",
".",
"Next",
"(",
")",
"\n",
"itr",
".",
"Unread",
"(",
")",
"\n",
"return",
"\n",
"}"
] |
// Peek reads the next value but leaves it on the buffer.
|
[
"Peek",
"reads",
"the",
"next",
"value",
"but",
"leaves",
"it",
"on",
"the",
"buffer",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/iterator.go#L66-L70
|
train
|
pilosa/pilosa
|
iterator.go
|
Unread
|
func (itr *bufIterator) Unread() {
if itr.buf.full {
panic("pilosa.BufIterator: buffer full")
}
itr.buf.full = true
}
|
go
|
func (itr *bufIterator) Unread() {
if itr.buf.full {
panic("pilosa.BufIterator: buffer full")
}
itr.buf.full = true
}
|
[
"func",
"(",
"itr",
"*",
"bufIterator",
")",
"Unread",
"(",
")",
"{",
"if",
"itr",
".",
"buf",
".",
"full",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"itr",
".",
"buf",
".",
"full",
"=",
"true",
"\n",
"}"
] |
// Unread pushes previous pair on to the buffer.
// Panics if the buffer is already full.
|
[
"Unread",
"pushes",
"previous",
"pair",
"on",
"to",
"the",
"buffer",
".",
"Panics",
"if",
"the",
"buffer",
"is",
"already",
"full",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/iterator.go#L74-L79
|
train
|
pilosa/pilosa
|
iterator.go
|
newLimitIterator
|
func newLimitIterator(itr iterator, maxRowID, maxColumnID uint64) *limitIterator { // nolint: unparam
return &limitIterator{
itr: itr,
maxRowID: maxRowID,
maxColumnID: maxColumnID,
}
}
|
go
|
func newLimitIterator(itr iterator, maxRowID, maxColumnID uint64) *limitIterator { // nolint: unparam
return &limitIterator{
itr: itr,
maxRowID: maxRowID,
maxColumnID: maxColumnID,
}
}
|
[
"func",
"newLimitIterator",
"(",
"itr",
"iterator",
",",
"maxRowID",
",",
"maxColumnID",
"uint64",
")",
"*",
"limitIterator",
"{",
"// nolint: unparam",
"return",
"&",
"limitIterator",
"{",
"itr",
":",
"itr",
",",
"maxRowID",
":",
"maxRowID",
",",
"maxColumnID",
":",
"maxColumnID",
",",
"}",
"\n",
"}"
] |
// newLimitIterator returns a new LimitIterator.
|
[
"newLimitIterator",
"returns",
"a",
"new",
"LimitIterator",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/iterator.go#L91-L97
|
train
|
pilosa/pilosa
|
iterator.go
|
Seek
|
func (itr *sliceIterator) Seek(bseek, pseek uint64) {
for i := 0; i < itr.n; i++ {
rowID := itr.rowIDs[i]
columnID := itr.columnIDs[i]
if (bseek == rowID && pseek <= columnID) || bseek < rowID {
itr.i = i
return
}
}
// Seek to the end of the slice if all values are less than seek pair.
itr.i = itr.n
}
|
go
|
func (itr *sliceIterator) Seek(bseek, pseek uint64) {
for i := 0; i < itr.n; i++ {
rowID := itr.rowIDs[i]
columnID := itr.columnIDs[i]
if (bseek == rowID && pseek <= columnID) || bseek < rowID {
itr.i = i
return
}
}
// Seek to the end of the slice if all values are less than seek pair.
itr.i = itr.n
}
|
[
"func",
"(",
"itr",
"*",
"sliceIterator",
")",
"Seek",
"(",
"bseek",
",",
"pseek",
"uint64",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"itr",
".",
"n",
";",
"i",
"++",
"{",
"rowID",
":=",
"itr",
".",
"rowIDs",
"[",
"i",
"]",
"\n",
"columnID",
":=",
"itr",
".",
"columnIDs",
"[",
"i",
"]",
"\n\n",
"if",
"(",
"bseek",
"==",
"rowID",
"&&",
"pseek",
"<=",
"columnID",
")",
"||",
"bseek",
"<",
"rowID",
"{",
"itr",
".",
"i",
"=",
"i",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Seek to the end of the slice if all values are less than seek pair.",
"itr",
".",
"i",
"=",
"itr",
".",
"n",
"\n",
"}"
] |
// Seek moves the cursor to a given pair.
// If the pair is not found, the iterator seeks to the next pair.
|
[
"Seek",
"moves",
"the",
"cursor",
"to",
"a",
"given",
"pair",
".",
"If",
"the",
"pair",
"is",
"not",
"found",
"the",
"iterator",
"seeks",
"to",
"the",
"next",
"pair",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/iterator.go#L146-L159
|
train
|
pilosa/pilosa
|
encoding/proto/proto.go
|
Marshal
|
func (Serializer) Marshal(m pilosa.Message) ([]byte, error) {
pm := encodeToProto(m)
if pm == nil {
return nil, errors.New("passed invalid pilosa.Message")
}
buf, err := proto.Marshal(pm)
return buf, errors.Wrap(err, "marshalling")
}
|
go
|
func (Serializer) Marshal(m pilosa.Message) ([]byte, error) {
pm := encodeToProto(m)
if pm == nil {
return nil, errors.New("passed invalid pilosa.Message")
}
buf, err := proto.Marshal(pm)
return buf, errors.Wrap(err, "marshalling")
}
|
[
"func",
"(",
"Serializer",
")",
"Marshal",
"(",
"m",
"pilosa",
".",
"Message",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"pm",
":=",
"encodeToProto",
"(",
"m",
")",
"\n",
"if",
"pm",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"buf",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"pm",
")",
"\n",
"return",
"buf",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// Marshal turns pilosa messages into protobuf serialized bytes.
|
[
"Marshal",
"turns",
"pilosa",
"messages",
"into",
"protobuf",
"serialized",
"bytes",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/encoding/proto/proto.go#L32-L39
|
train
|
pilosa/pilosa
|
encoding/proto/proto.go
|
encodeNodes
|
func encodeNodes(a []*pilosa.Node) []*internal.Node {
other := make([]*internal.Node, len(a))
for i := range a {
other[i] = encodeNode(a[i])
}
return other
}
|
go
|
func encodeNodes(a []*pilosa.Node) []*internal.Node {
other := make([]*internal.Node, len(a))
for i := range a {
other[i] = encodeNode(a[i])
}
return other
}
|
[
"func",
"encodeNodes",
"(",
"a",
"[",
"]",
"*",
"pilosa",
".",
"Node",
")",
"[",
"]",
"*",
"internal",
".",
"Node",
"{",
"other",
":=",
"make",
"(",
"[",
"]",
"*",
"internal",
".",
"Node",
",",
"len",
"(",
"a",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"a",
"{",
"other",
"[",
"i",
"]",
"=",
"encodeNode",
"(",
"a",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"return",
"other",
"\n",
"}"
] |
// encodeNodes converts a slice of Nodes into its internal representation.
|
[
"encodeNodes",
"converts",
"a",
"slice",
"of",
"Nodes",
"into",
"its",
"internal",
"representation",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/encoding/proto/proto.go#L541-L547
|
train
|
pilosa/pilosa
|
encoding/proto/proto.go
|
encodeNode
|
func encodeNode(n *pilosa.Node) *internal.Node {
return &internal.Node{
ID: n.ID,
URI: encodeURI(n.URI),
IsCoordinator: n.IsCoordinator,
State: n.State,
}
}
|
go
|
func encodeNode(n *pilosa.Node) *internal.Node {
return &internal.Node{
ID: n.ID,
URI: encodeURI(n.URI),
IsCoordinator: n.IsCoordinator,
State: n.State,
}
}
|
[
"func",
"encodeNode",
"(",
"n",
"*",
"pilosa",
".",
"Node",
")",
"*",
"internal",
".",
"Node",
"{",
"return",
"&",
"internal",
".",
"Node",
"{",
"ID",
":",
"n",
".",
"ID",
",",
"URI",
":",
"encodeURI",
"(",
"n",
".",
"URI",
")",
",",
"IsCoordinator",
":",
"n",
".",
"IsCoordinator",
",",
"State",
":",
"n",
".",
"State",
",",
"}",
"\n",
"}"
] |
// encodeNode converts a Node into its internal representation.
|
[
"encodeNode",
"converts",
"a",
"Node",
"into",
"its",
"internal",
"representation",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/encoding/proto/proto.go#L550-L557
|
train
|
pilosa/pilosa
|
encoding/proto/proto.go
|
decodeRow
|
func decodeRow(pr *internal.Row) *pilosa.Row {
if pr == nil {
return nil
}
r := pilosa.NewRow()
r.Attrs = decodeAttrs(pr.Attrs)
r.Keys = pr.Keys
for _, v := range pr.Columns {
r.SetBit(v)
}
return r
}
|
go
|
func decodeRow(pr *internal.Row) *pilosa.Row {
if pr == nil {
return nil
}
r := pilosa.NewRow()
r.Attrs = decodeAttrs(pr.Attrs)
r.Keys = pr.Keys
for _, v := range pr.Columns {
r.SetBit(v)
}
return r
}
|
[
"func",
"decodeRow",
"(",
"pr",
"*",
"internal",
".",
"Row",
")",
"*",
"pilosa",
".",
"Row",
"{",
"if",
"pr",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"r",
":=",
"pilosa",
".",
"NewRow",
"(",
")",
"\n",
"r",
".",
"Attrs",
"=",
"decodeAttrs",
"(",
"pr",
".",
"Attrs",
")",
"\n",
"r",
".",
"Keys",
"=",
"pr",
".",
"Keys",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"pr",
".",
"Columns",
"{",
"r",
".",
"SetBit",
"(",
"v",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// DecodeRow converts r from its internal representation.
|
[
"DecodeRow",
"converts",
"r",
"from",
"its",
"internal",
"representation",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/encoding/proto/proto.go#L1084-L1096
|
train
|
pilosa/pilosa
|
row.go
|
NewRow
|
func NewRow(columns ...uint64) *Row {
r := &Row{}
for _, i := range columns {
r.SetBit(i)
}
return r
}
|
go
|
func NewRow(columns ...uint64) *Row {
r := &Row{}
for _, i := range columns {
r.SetBit(i)
}
return r
}
|
[
"func",
"NewRow",
"(",
"columns",
"...",
"uint64",
")",
"*",
"Row",
"{",
"r",
":=",
"&",
"Row",
"{",
"}",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"columns",
"{",
"r",
".",
"SetBit",
"(",
"i",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// NewRow returns a new instance of Row.
|
[
"NewRow",
"returns",
"a",
"new",
"instance",
"of",
"Row",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L38-L44
|
train
|
pilosa/pilosa
|
row.go
|
IsEmpty
|
func (r *Row) IsEmpty() bool {
if len(r.segments) == 0 {
return true
}
for i := range r.segments {
if r.segments[i].n > 0 {
return false
}
}
return true
}
|
go
|
func (r *Row) IsEmpty() bool {
if len(r.segments) == 0 {
return true
}
for i := range r.segments {
if r.segments[i].n > 0 {
return false
}
}
return true
}
|
[
"func",
"(",
"r",
"*",
"Row",
")",
"IsEmpty",
"(",
")",
"bool",
"{",
"if",
"len",
"(",
"r",
".",
"segments",
")",
"==",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"r",
".",
"segments",
"{",
"if",
"r",
".",
"segments",
"[",
"i",
"]",
".",
"n",
">",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] |
// IsEmpty returns true if the row doesn't contain any set bits.
|
[
"IsEmpty",
"returns",
"true",
"if",
"the",
"row",
"doesn",
"t",
"contain",
"any",
"set",
"bits",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L47-L58
|
train
|
pilosa/pilosa
|
row.go
|
Merge
|
func (r *Row) Merge(other *Row) {
var segments []rowSegment
itr := newMergeSegmentIterator(r.segments, other.segments)
for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() {
// Use the other row's data if segment is missing.
if s0 == nil {
segments = append(segments, *s1)
continue
} else if s1 == nil {
segments = append(segments, *s0)
continue
}
// Otherwise merge.
s0.Merge(s1)
segments = append(segments, *s0)
}
r.segments = segments
r.invalidateCount()
}
|
go
|
func (r *Row) Merge(other *Row) {
var segments []rowSegment
itr := newMergeSegmentIterator(r.segments, other.segments)
for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() {
// Use the other row's data if segment is missing.
if s0 == nil {
segments = append(segments, *s1)
continue
} else if s1 == nil {
segments = append(segments, *s0)
continue
}
// Otherwise merge.
s0.Merge(s1)
segments = append(segments, *s0)
}
r.segments = segments
r.invalidateCount()
}
|
[
"func",
"(",
"r",
"*",
"Row",
")",
"Merge",
"(",
"other",
"*",
"Row",
")",
"{",
"var",
"segments",
"[",
"]",
"rowSegment",
"\n\n",
"itr",
":=",
"newMergeSegmentIterator",
"(",
"r",
".",
"segments",
",",
"other",
".",
"segments",
")",
"\n",
"for",
"s0",
",",
"s1",
":=",
"itr",
".",
"next",
"(",
")",
";",
"s0",
"!=",
"nil",
"||",
"s1",
"!=",
"nil",
";",
"s0",
",",
"s1",
"=",
"itr",
".",
"next",
"(",
")",
"{",
"// Use the other row's data if segment is missing.",
"if",
"s0",
"==",
"nil",
"{",
"segments",
"=",
"append",
"(",
"segments",
",",
"*",
"s1",
")",
"\n",
"continue",
"\n",
"}",
"else",
"if",
"s1",
"==",
"nil",
"{",
"segments",
"=",
"append",
"(",
"segments",
",",
"*",
"s0",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"// Otherwise merge.",
"s0",
".",
"Merge",
"(",
"s1",
")",
"\n",
"segments",
"=",
"append",
"(",
"segments",
",",
"*",
"s0",
")",
"\n",
"}",
"\n\n",
"r",
".",
"segments",
"=",
"segments",
"\n",
"r",
".",
"invalidateCount",
"(",
")",
"\n",
"}"
] |
// Merge merges data from other into r.
|
[
"Merge",
"merges",
"data",
"from",
"other",
"into",
"r",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L61-L82
|
train
|
pilosa/pilosa
|
row.go
|
intersectionCount
|
func (r *Row) intersectionCount(other *Row) uint64 {
var n uint64
itr := newMergeSegmentIterator(r.segments, other.segments)
for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() {
// Ignore non-overlapping segments.
if s0 == nil || s1 == nil {
continue
}
n += s0.IntersectionCount(s1)
}
return n
}
|
go
|
func (r *Row) intersectionCount(other *Row) uint64 {
var n uint64
itr := newMergeSegmentIterator(r.segments, other.segments)
for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() {
// Ignore non-overlapping segments.
if s0 == nil || s1 == nil {
continue
}
n += s0.IntersectionCount(s1)
}
return n
}
|
[
"func",
"(",
"r",
"*",
"Row",
")",
"intersectionCount",
"(",
"other",
"*",
"Row",
")",
"uint64",
"{",
"var",
"n",
"uint64",
"\n\n",
"itr",
":=",
"newMergeSegmentIterator",
"(",
"r",
".",
"segments",
",",
"other",
".",
"segments",
")",
"\n",
"for",
"s0",
",",
"s1",
":=",
"itr",
".",
"next",
"(",
")",
";",
"s0",
"!=",
"nil",
"||",
"s1",
"!=",
"nil",
";",
"s0",
",",
"s1",
"=",
"itr",
".",
"next",
"(",
")",
"{",
"// Ignore non-overlapping segments.",
"if",
"s0",
"==",
"nil",
"||",
"s1",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n\n",
"n",
"+=",
"s0",
".",
"IntersectionCount",
"(",
"s1",
")",
"\n",
"}",
"\n",
"return",
"n",
"\n",
"}"
] |
// intersectionCount returns the number of intersections between r and other.
|
[
"intersectionCount",
"returns",
"the",
"number",
"of",
"intersections",
"between",
"r",
"and",
"other",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L85-L98
|
train
|
pilosa/pilosa
|
row.go
|
Shift
|
func (r *Row) Shift(n int64) (*Row, error) {
if n < 0 {
return nil, errors.New("cannot shift by negative values")
} else if n == 0 {
return r, nil
}
work := r
var segments []rowSegment
for i := int64(0); i < n; i++ {
segments = segments[:0]
for _, segment := range work.segments {
shifted, err := segment.Shift()
if err != nil {
return nil, errors.Wrap(err, "shifting row segment")
}
segments = append(segments, *shifted)
}
work = &Row{segments: segments}
}
return work, nil
}
|
go
|
func (r *Row) Shift(n int64) (*Row, error) {
if n < 0 {
return nil, errors.New("cannot shift by negative values")
} else if n == 0 {
return r, nil
}
work := r
var segments []rowSegment
for i := int64(0); i < n; i++ {
segments = segments[:0]
for _, segment := range work.segments {
shifted, err := segment.Shift()
if err != nil {
return nil, errors.Wrap(err, "shifting row segment")
}
segments = append(segments, *shifted)
}
work = &Row{segments: segments}
}
return work, nil
}
|
[
"func",
"(",
"r",
"*",
"Row",
")",
"Shift",
"(",
"n",
"int64",
")",
"(",
"*",
"Row",
",",
"error",
")",
"{",
"if",
"n",
"<",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"n",
"==",
"0",
"{",
"return",
"r",
",",
"nil",
"\n",
"}",
"\n\n",
"work",
":=",
"r",
"\n",
"var",
"segments",
"[",
"]",
"rowSegment",
"\n",
"for",
"i",
":=",
"int64",
"(",
"0",
")",
";",
"i",
"<",
"n",
";",
"i",
"++",
"{",
"segments",
"=",
"segments",
"[",
":",
"0",
"]",
"\n",
"for",
"_",
",",
"segment",
":=",
"range",
"work",
".",
"segments",
"{",
"shifted",
",",
"err",
":=",
"segment",
".",
"Shift",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"segments",
"=",
"append",
"(",
"segments",
",",
"*",
"shifted",
")",
"\n",
"}",
"\n",
"work",
"=",
"&",
"Row",
"{",
"segments",
":",
"segments",
"}",
"\n",
"}",
"\n\n",
"return",
"work",
",",
"nil",
"\n",
"}"
] |
// Shift returns the bitwise shift of r by n bits.
// Currently only positive shift values are supported.
|
[
"Shift",
"returns",
"the",
"bitwise",
"shift",
"of",
"r",
"by",
"n",
"bits",
".",
"Currently",
"only",
"positive",
"shift",
"values",
"are",
"supported",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L174-L196
|
train
|
pilosa/pilosa
|
row.go
|
clearBit
|
func (r *Row) clearBit(i uint64) (changed bool) { // nolint: unparam
s := r.segment(i / ShardWidth)
if s == nil {
return false
}
return s.ClearBit(i)
}
|
go
|
func (r *Row) clearBit(i uint64) (changed bool) { // nolint: unparam
s := r.segment(i / ShardWidth)
if s == nil {
return false
}
return s.ClearBit(i)
}
|
[
"func",
"(",
"r",
"*",
"Row",
")",
"clearBit",
"(",
"i",
"uint64",
")",
"(",
"changed",
"bool",
")",
"{",
"// nolint: unparam",
"s",
":=",
"r",
".",
"segment",
"(",
"i",
"/",
"ShardWidth",
")",
"\n",
"if",
"s",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"s",
".",
"ClearBit",
"(",
"i",
")",
"\n",
"}"
] |
// clearBit clears the i-th column of the row.
|
[
"clearBit",
"clears",
"the",
"i",
"-",
"th",
"column",
"of",
"the",
"row",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L204-L210
|
train
|
pilosa/pilosa
|
row.go
|
segment
|
func (r *Row) segment(shard uint64) *rowSegment {
if i := sort.Search(len(r.segments), func(i int) bool {
return r.segments[i].shard >= shard
}); i < len(r.segments) && r.segments[i].shard == shard {
return &r.segments[i]
}
return nil
}
|
go
|
func (r *Row) segment(shard uint64) *rowSegment {
if i := sort.Search(len(r.segments), func(i int) bool {
return r.segments[i].shard >= shard
}); i < len(r.segments) && r.segments[i].shard == shard {
return &r.segments[i]
}
return nil
}
|
[
"func",
"(",
"r",
"*",
"Row",
")",
"segment",
"(",
"shard",
"uint64",
")",
"*",
"rowSegment",
"{",
"if",
"i",
":=",
"sort",
".",
"Search",
"(",
"len",
"(",
"r",
".",
"segments",
")",
",",
"func",
"(",
"i",
"int",
")",
"bool",
"{",
"return",
"r",
".",
"segments",
"[",
"i",
"]",
".",
"shard",
">=",
"shard",
"\n",
"}",
")",
";",
"i",
"<",
"len",
"(",
"r",
".",
"segments",
")",
"&&",
"r",
".",
"segments",
"[",
"i",
"]",
".",
"shard",
"==",
"shard",
"{",
"return",
"&",
"r",
".",
"segments",
"[",
"i",
"]",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// segment returns a segment for a given shard.
// Returns nil if segment does not exist.
|
[
"segment",
"returns",
"a",
"segment",
"for",
"a",
"given",
"shard",
".",
"Returns",
"nil",
"if",
"segment",
"does",
"not",
"exist",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L219-L226
|
train
|
pilosa/pilosa
|
row.go
|
invalidateCount
|
func (r *Row) invalidateCount() {
for i := range r.segments {
r.segments[i].InvalidateCount()
}
}
|
go
|
func (r *Row) invalidateCount() {
for i := range r.segments {
r.segments[i].InvalidateCount()
}
}
|
[
"func",
"(",
"r",
"*",
"Row",
")",
"invalidateCount",
"(",
")",
"{",
"for",
"i",
":=",
"range",
"r",
".",
"segments",
"{",
"r",
".",
"segments",
"[",
"i",
"]",
".",
"InvalidateCount",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// invalidateCount updates the cached count in the row.
|
[
"invalidateCount",
"updates",
"the",
"cached",
"count",
"in",
"the",
"row",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L253-L257
|
train
|
pilosa/pilosa
|
row.go
|
Count
|
func (r *Row) Count() uint64 {
var n uint64
for i := range r.segments {
n += r.segments[i].Count()
}
return n
}
|
go
|
func (r *Row) Count() uint64 {
var n uint64
for i := range r.segments {
n += r.segments[i].Count()
}
return n
}
|
[
"func",
"(",
"r",
"*",
"Row",
")",
"Count",
"(",
")",
"uint64",
"{",
"var",
"n",
"uint64",
"\n",
"for",
"i",
":=",
"range",
"r",
".",
"segments",
"{",
"n",
"+=",
"r",
".",
"segments",
"[",
"i",
"]",
".",
"Count",
"(",
")",
"\n",
"}",
"\n",
"return",
"n",
"\n",
"}"
] |
// Count returns the number of columns in the row.
|
[
"Count",
"returns",
"the",
"number",
"of",
"columns",
"in",
"the",
"row",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L260-L266
|
train
|
pilosa/pilosa
|
row.go
|
MarshalJSON
|
func (r *Row) MarshalJSON() ([]byte, error) {
var o struct {
Attrs map[string]interface{} `json:"attrs"`
Columns []uint64 `json:"columns"`
Keys []string `json:"keys,omitempty"`
}
o.Columns = r.Columns()
o.Keys = r.Keys
o.Attrs = r.Attrs
if o.Attrs == nil {
o.Attrs = make(map[string]interface{})
}
return json.Marshal(&o)
}
|
go
|
func (r *Row) MarshalJSON() ([]byte, error) {
var o struct {
Attrs map[string]interface{} `json:"attrs"`
Columns []uint64 `json:"columns"`
Keys []string `json:"keys,omitempty"`
}
o.Columns = r.Columns()
o.Keys = r.Keys
o.Attrs = r.Attrs
if o.Attrs == nil {
o.Attrs = make(map[string]interface{})
}
return json.Marshal(&o)
}
|
[
"func",
"(",
"r",
"*",
"Row",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"o",
"struct",
"{",
"Attrs",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"`json:\"attrs\"`",
"\n",
"Columns",
"[",
"]",
"uint64",
"`json:\"columns\"`",
"\n",
"Keys",
"[",
"]",
"string",
"`json:\"keys,omitempty\"`",
"\n",
"}",
"\n",
"o",
".",
"Columns",
"=",
"r",
".",
"Columns",
"(",
")",
"\n",
"o",
".",
"Keys",
"=",
"r",
".",
"Keys",
"\n\n",
"o",
".",
"Attrs",
"=",
"r",
".",
"Attrs",
"\n",
"if",
"o",
".",
"Attrs",
"==",
"nil",
"{",
"o",
".",
"Attrs",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"json",
".",
"Marshal",
"(",
"&",
"o",
")",
"\n",
"}"
] |
// MarshalJSON returns a JSON-encoded byte slice of r.
|
[
"MarshalJSON",
"returns",
"a",
"JSON",
"-",
"encoded",
"byte",
"slice",
"of",
"r",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L269-L284
|
train
|
pilosa/pilosa
|
row.go
|
Columns
|
func (r *Row) Columns() []uint64 {
a := make([]uint64, 0, r.Count())
for i := range r.segments {
a = append(a, r.segments[i].Columns()...)
}
return a
}
|
go
|
func (r *Row) Columns() []uint64 {
a := make([]uint64, 0, r.Count())
for i := range r.segments {
a = append(a, r.segments[i].Columns()...)
}
return a
}
|
[
"func",
"(",
"r",
"*",
"Row",
")",
"Columns",
"(",
")",
"[",
"]",
"uint64",
"{",
"a",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"0",
",",
"r",
".",
"Count",
"(",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"r",
".",
"segments",
"{",
"a",
"=",
"append",
"(",
"a",
",",
"r",
".",
"segments",
"[",
"i",
"]",
".",
"Columns",
"(",
")",
"...",
")",
"\n",
"}",
"\n",
"return",
"a",
"\n",
"}"
] |
// Columns returns the columns in r as a slice of ints.
|
[
"Columns",
"returns",
"the",
"columns",
"in",
"r",
"as",
"a",
"slice",
"of",
"ints",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L287-L293
|
train
|
pilosa/pilosa
|
row.go
|
Merge
|
func (s *rowSegment) Merge(other *rowSegment) {
s.ensureWritable()
itr := other.data.Iterator()
for v, eof := itr.Next(); !eof; v, eof = itr.Next() {
s.SetBit(v)
}
}
|
go
|
func (s *rowSegment) Merge(other *rowSegment) {
s.ensureWritable()
itr := other.data.Iterator()
for v, eof := itr.Next(); !eof; v, eof = itr.Next() {
s.SetBit(v)
}
}
|
[
"func",
"(",
"s",
"*",
"rowSegment",
")",
"Merge",
"(",
"other",
"*",
"rowSegment",
")",
"{",
"s",
".",
"ensureWritable",
"(",
")",
"\n\n",
"itr",
":=",
"other",
".",
"data",
".",
"Iterator",
"(",
")",
"\n",
"for",
"v",
",",
"eof",
":=",
"itr",
".",
"Next",
"(",
")",
";",
"!",
"eof",
";",
"v",
",",
"eof",
"=",
"itr",
".",
"Next",
"(",
")",
"{",
"s",
".",
"SetBit",
"(",
"v",
")",
"\n",
"}",
"\n",
"}"
] |
// Merge adds chunks from other to s.
// Chunks in s are overwritten if they exist in other.
|
[
"Merge",
"adds",
"chunks",
"from",
"other",
"to",
"s",
".",
"Chunks",
"in",
"s",
"are",
"overwritten",
"if",
"they",
"exist",
"in",
"other",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L314-L321
|
train
|
pilosa/pilosa
|
row.go
|
IntersectionCount
|
func (s *rowSegment) IntersectionCount(other *rowSegment) uint64 {
return s.data.IntersectionCount(&other.data)
}
|
go
|
func (s *rowSegment) IntersectionCount(other *rowSegment) uint64 {
return s.data.IntersectionCount(&other.data)
}
|
[
"func",
"(",
"s",
"*",
"rowSegment",
")",
"IntersectionCount",
"(",
"other",
"*",
"rowSegment",
")",
"uint64",
"{",
"return",
"s",
".",
"data",
".",
"IntersectionCount",
"(",
"&",
"other",
".",
"data",
")",
"\n",
"}"
] |
// IntersectionCount returns the number of intersections between s and other.
|
[
"IntersectionCount",
"returns",
"the",
"number",
"of",
"intersections",
"between",
"s",
"and",
"other",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L324-L326
|
train
|
pilosa/pilosa
|
row.go
|
Intersect
|
func (s *rowSegment) Intersect(other *rowSegment) *rowSegment {
data := s.data.Intersect(&other.data)
return &rowSegment{
data: *data,
shard: s.shard,
n: data.Count(),
}
}
|
go
|
func (s *rowSegment) Intersect(other *rowSegment) *rowSegment {
data := s.data.Intersect(&other.data)
return &rowSegment{
data: *data,
shard: s.shard,
n: data.Count(),
}
}
|
[
"func",
"(",
"s",
"*",
"rowSegment",
")",
"Intersect",
"(",
"other",
"*",
"rowSegment",
")",
"*",
"rowSegment",
"{",
"data",
":=",
"s",
".",
"data",
".",
"Intersect",
"(",
"&",
"other",
".",
"data",
")",
"\n\n",
"return",
"&",
"rowSegment",
"{",
"data",
":",
"*",
"data",
",",
"shard",
":",
"s",
".",
"shard",
",",
"n",
":",
"data",
".",
"Count",
"(",
")",
",",
"}",
"\n",
"}"
] |
// Intersect returns the itersection of s and other.
|
[
"Intersect",
"returns",
"the",
"itersection",
"of",
"s",
"and",
"other",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L329-L337
|
train
|
pilosa/pilosa
|
row.go
|
Union
|
func (s *rowSegment) Union(other *rowSegment) *rowSegment {
data := s.data.Union(&other.data)
return &rowSegment{
data: *data,
shard: s.shard,
n: data.Count(),
}
}
|
go
|
func (s *rowSegment) Union(other *rowSegment) *rowSegment {
data := s.data.Union(&other.data)
return &rowSegment{
data: *data,
shard: s.shard,
n: data.Count(),
}
}
|
[
"func",
"(",
"s",
"*",
"rowSegment",
")",
"Union",
"(",
"other",
"*",
"rowSegment",
")",
"*",
"rowSegment",
"{",
"data",
":=",
"s",
".",
"data",
".",
"Union",
"(",
"&",
"other",
".",
"data",
")",
"\n\n",
"return",
"&",
"rowSegment",
"{",
"data",
":",
"*",
"data",
",",
"shard",
":",
"s",
".",
"shard",
",",
"n",
":",
"data",
".",
"Count",
"(",
")",
",",
"}",
"\n",
"}"
] |
// Union returns the bitwise union of s and other.
|
[
"Union",
"returns",
"the",
"bitwise",
"union",
"of",
"s",
"and",
"other",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L340-L348
|
train
|
pilosa/pilosa
|
row.go
|
Difference
|
func (s *rowSegment) Difference(other *rowSegment) *rowSegment {
data := s.data.Difference(&other.data)
return &rowSegment{
data: *data,
shard: s.shard,
n: data.Count(),
}
}
|
go
|
func (s *rowSegment) Difference(other *rowSegment) *rowSegment {
data := s.data.Difference(&other.data)
return &rowSegment{
data: *data,
shard: s.shard,
n: data.Count(),
}
}
|
[
"func",
"(",
"s",
"*",
"rowSegment",
")",
"Difference",
"(",
"other",
"*",
"rowSegment",
")",
"*",
"rowSegment",
"{",
"data",
":=",
"s",
".",
"data",
".",
"Difference",
"(",
"&",
"other",
".",
"data",
")",
"\n\n",
"return",
"&",
"rowSegment",
"{",
"data",
":",
"*",
"data",
",",
"shard",
":",
"s",
".",
"shard",
",",
"n",
":",
"data",
".",
"Count",
"(",
")",
",",
"}",
"\n",
"}"
] |
// Difference returns the diff of s and other.
|
[
"Difference",
"returns",
"the",
"diff",
"of",
"s",
"and",
"other",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L351-L359
|
train
|
pilosa/pilosa
|
row.go
|
Xor
|
func (s *rowSegment) Xor(other *rowSegment) *rowSegment {
data := s.data.Xor(&other.data)
return &rowSegment{
data: *data,
shard: s.shard,
n: data.Count(),
}
}
|
go
|
func (s *rowSegment) Xor(other *rowSegment) *rowSegment {
data := s.data.Xor(&other.data)
return &rowSegment{
data: *data,
shard: s.shard,
n: data.Count(),
}
}
|
[
"func",
"(",
"s",
"*",
"rowSegment",
")",
"Xor",
"(",
"other",
"*",
"rowSegment",
")",
"*",
"rowSegment",
"{",
"data",
":=",
"s",
".",
"data",
".",
"Xor",
"(",
"&",
"other",
".",
"data",
")",
"\n\n",
"return",
"&",
"rowSegment",
"{",
"data",
":",
"*",
"data",
",",
"shard",
":",
"s",
".",
"shard",
",",
"n",
":",
"data",
".",
"Count",
"(",
")",
",",
"}",
"\n",
"}"
] |
// Xor returns the xor of s and other.
|
[
"Xor",
"returns",
"the",
"xor",
"of",
"s",
"and",
"other",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L362-L370
|
train
|
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.