id
int32 0
167k
| 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
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
12,400 | google/badwolf | tools/benchmark/generator/graph/graph.go | NewRandomGraph | func NewRandomGraph(n int) (generator.Generator, error) {
if n < 1 {
return nil, fmt.Errorf("invalid number of nodes %d<1", n)
}
nt, err := node.NewType("/gn")
if err != nil {
return nil, err
}
p, err := predicate.NewImmutable("follow")
if err != nil {
return nil, err
}
return &randomGraph{
nodes: n,
nodeType: nt,
predicate: p,
}, nil
} | go | func NewRandomGraph(n int) (generator.Generator, error) {
if n < 1 {
return nil, fmt.Errorf("invalid number of nodes %d<1", n)
}
nt, err := node.NewType("/gn")
if err != nil {
return nil, err
}
p, err := predicate.NewImmutable("follow")
if err != nil {
return nil, err
}
return &randomGraph{
nodes: n,
nodeType: nt,
predicate: p,
}, nil
} | [
"func",
"NewRandomGraph",
"(",
"n",
"int",
")",
"(",
"generator",
".",
"Generator",
",",
"error",
")",
"{",
"if",
"n",
"<",
"1",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"n",
")",
"\n",
"}",
"\n",
"nt",
",",
"err",
":=",
"node",
".",
"NewType",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"p",
",",
"err",
":=",
"predicate",
".",
"NewImmutable",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"randomGraph",
"{",
"nodes",
":",
"n",
",",
"nodeType",
":",
"nt",
",",
"predicate",
":",
"p",
",",
"}",
",",
"nil",
"\n",
"}"
]
| // NewRandomGraph creates a new random graph generator. | [
"NewRandomGraph",
"creates",
"a",
"new",
"random",
"graph",
"generator",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/benchmark/generator/graph/graph.go#L37-L54 |
12,401 | google/badwolf | tools/benchmark/generator/graph/graph.go | newTriple | func (r *randomGraph) newTriple(i, j int) (*triple.Triple, error) {
s, err := r.newNode(i)
if err != nil {
return nil, err
}
o, err := r.newNode(j)
if err != nil {
return nil, err
}
return triple.New(s, r.predicate, triple.NewNodeObject(o))
} | go | func (r *randomGraph) newTriple(i, j int) (*triple.Triple, error) {
s, err := r.newNode(i)
if err != nil {
return nil, err
}
o, err := r.newNode(j)
if err != nil {
return nil, err
}
return triple.New(s, r.predicate, triple.NewNodeObject(o))
} | [
"func",
"(",
"r",
"*",
"randomGraph",
")",
"newTriple",
"(",
"i",
",",
"j",
"int",
")",
"(",
"*",
"triple",
".",
"Triple",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"r",
".",
"newNode",
"(",
"i",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"o",
",",
"err",
":=",
"r",
".",
"newNode",
"(",
"j",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"triple",
".",
"New",
"(",
"s",
",",
"r",
".",
"predicate",
",",
"triple",
".",
"NewNodeObject",
"(",
"o",
")",
")",
"\n",
"}"
]
| // newTriple creates new triple using the provided node IDs. | [
"newTriple",
"creates",
"new",
"triple",
"using",
"the",
"provided",
"node",
"IDs",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/benchmark/generator/graph/graph.go#L66-L76 |
12,402 | google/badwolf | tools/benchmark/generator/graph/graph.go | Generate | func (r *randomGraph) Generate(n int) ([]*triple.Triple, error) {
maxEdges := r.nodes * r.nodes
if n > maxEdges {
return nil, fmt.Errorf("current configuration only allow a max of %d triples (%d requested)", maxEdges, n)
}
var trpls []*triple.Triple
for _, idx := range rand.Perm(maxEdges)[:n] {
i, j := idx/r.nodes, idx%r.nodes
t, err := r.newTriple(i, j)
if err != nil {
return nil, err
}
trpls = append(trpls, t)
}
return trpls, nil
} | go | func (r *randomGraph) Generate(n int) ([]*triple.Triple, error) {
maxEdges := r.nodes * r.nodes
if n > maxEdges {
return nil, fmt.Errorf("current configuration only allow a max of %d triples (%d requested)", maxEdges, n)
}
var trpls []*triple.Triple
for _, idx := range rand.Perm(maxEdges)[:n] {
i, j := idx/r.nodes, idx%r.nodes
t, err := r.newTriple(i, j)
if err != nil {
return nil, err
}
trpls = append(trpls, t)
}
return trpls, nil
} | [
"func",
"(",
"r",
"*",
"randomGraph",
")",
"Generate",
"(",
"n",
"int",
")",
"(",
"[",
"]",
"*",
"triple",
".",
"Triple",
",",
"error",
")",
"{",
"maxEdges",
":=",
"r",
".",
"nodes",
"*",
"r",
".",
"nodes",
"\n",
"if",
"n",
">",
"maxEdges",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"maxEdges",
",",
"n",
")",
"\n",
"}",
"\n",
"var",
"trpls",
"[",
"]",
"*",
"triple",
".",
"Triple",
"\n",
"for",
"_",
",",
"idx",
":=",
"range",
"rand",
".",
"Perm",
"(",
"maxEdges",
")",
"[",
":",
"n",
"]",
"{",
"i",
",",
"j",
":=",
"idx",
"/",
"r",
".",
"nodes",
",",
"idx",
"%",
"r",
".",
"nodes",
"\n",
"t",
",",
"err",
":=",
"r",
".",
"newTriple",
"(",
"i",
",",
"j",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"trpls",
"=",
"append",
"(",
"trpls",
",",
"t",
")",
"\n",
"}",
"\n",
"return",
"trpls",
",",
"nil",
"\n",
"}"
]
| // Generate creates the required number of triples. | [
"Generate",
"creates",
"the",
"required",
"number",
"of",
"triples",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/benchmark/generator/graph/graph.go#L79-L94 |
12,403 | google/badwolf | bql/table/table.go | New | func New(bs []string) (*Table, error) {
m := make(map[string]bool)
for _, b := range bs {
m[b] = true
}
if len(m) != len(bs) {
return nil, fmt.Errorf("table.New does not allow duplicated bindings in %s", bs)
}
return &Table{
AvailableBindings: bs,
mbs: m,
}, nil
} | go | func New(bs []string) (*Table, error) {
m := make(map[string]bool)
for _, b := range bs {
m[b] = true
}
if len(m) != len(bs) {
return nil, fmt.Errorf("table.New does not allow duplicated bindings in %s", bs)
}
return &Table{
AvailableBindings: bs,
mbs: m,
}, nil
} | [
"func",
"New",
"(",
"bs",
"[",
"]",
"string",
")",
"(",
"*",
"Table",
",",
"error",
")",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"b",
":=",
"range",
"bs",
"{",
"m",
"[",
"b",
"]",
"=",
"true",
"\n",
"}",
"\n",
"if",
"len",
"(",
"m",
")",
"!=",
"len",
"(",
"bs",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"bs",
")",
"\n",
"}",
"\n",
"return",
"&",
"Table",
"{",
"AvailableBindings",
":",
"bs",
",",
"mbs",
":",
"m",
",",
"}",
",",
"nil",
"\n",
"}"
]
| // New returns a new table that can hold data for the given bindings. The,
// table creation will fail if there are repeated bindings. | [
"New",
"returns",
"a",
"new",
"table",
"that",
"can",
"hold",
"data",
"for",
"the",
"given",
"bindings",
".",
"The",
"table",
"creation",
"will",
"fail",
"if",
"there",
"are",
"repeated",
"bindings",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L50-L62 |
12,404 | google/badwolf | bql/table/table.go | String | func (c *Cell) String() string {
if c.S != nil {
return *c.S
}
if c.N != nil {
return c.N.String()
}
if c.P != nil {
return c.P.String()
}
if c.L != nil {
return c.L.String()
}
if c.T != nil {
return c.T.Format(time.RFC3339Nano)
}
return "<NULL>"
} | go | func (c *Cell) String() string {
if c.S != nil {
return *c.S
}
if c.N != nil {
return c.N.String()
}
if c.P != nil {
return c.P.String()
}
if c.L != nil {
return c.L.String()
}
if c.T != nil {
return c.T.Format(time.RFC3339Nano)
}
return "<NULL>"
} | [
"func",
"(",
"c",
"*",
"Cell",
")",
"String",
"(",
")",
"string",
"{",
"if",
"c",
".",
"S",
"!=",
"nil",
"{",
"return",
"*",
"c",
".",
"S",
"\n",
"}",
"\n",
"if",
"c",
".",
"N",
"!=",
"nil",
"{",
"return",
"c",
".",
"N",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"P",
"!=",
"nil",
"{",
"return",
"c",
".",
"P",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"L",
"!=",
"nil",
"{",
"return",
"c",
".",
"L",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"T",
"!=",
"nil",
"{",
"return",
"c",
".",
"T",
".",
"Format",
"(",
"time",
".",
"RFC3339Nano",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
]
| // String returns a readable representation of a cell. | [
"String",
"returns",
"a",
"readable",
"representation",
"of",
"a",
"cell",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L74-L91 |
12,405 | google/badwolf | bql/table/table.go | ToTextLine | func (r Row) ToTextLine(res *bytes.Buffer, bs []string, sep string) error {
cnt := len(bs)
if sep == "" {
sep = "\t"
}
for _, b := range bs {
cnt--
v := "<NULL>"
if c, ok := r[b]; ok {
v = c.String()
}
if _, err := res.WriteString(v); err != nil {
return err
}
if cnt > 0 {
res.WriteString(sep)
}
}
return nil
} | go | func (r Row) ToTextLine(res *bytes.Buffer, bs []string, sep string) error {
cnt := len(bs)
if sep == "" {
sep = "\t"
}
for _, b := range bs {
cnt--
v := "<NULL>"
if c, ok := r[b]; ok {
v = c.String()
}
if _, err := res.WriteString(v); err != nil {
return err
}
if cnt > 0 {
res.WriteString(sep)
}
}
return nil
} | [
"func",
"(",
"r",
"Row",
")",
"ToTextLine",
"(",
"res",
"*",
"bytes",
".",
"Buffer",
",",
"bs",
"[",
"]",
"string",
",",
"sep",
"string",
")",
"error",
"{",
"cnt",
":=",
"len",
"(",
"bs",
")",
"\n",
"if",
"sep",
"==",
"\"",
"\"",
"{",
"sep",
"=",
"\"",
"\\t",
"\"",
"\n",
"}",
"\n",
"for",
"_",
",",
"b",
":=",
"range",
"bs",
"{",
"cnt",
"--",
"\n",
"v",
":=",
"\"",
"\"",
"\n",
"if",
"c",
",",
"ok",
":=",
"r",
"[",
"b",
"]",
";",
"ok",
"{",
"v",
"=",
"c",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"res",
".",
"WriteString",
"(",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"cnt",
">",
"0",
"{",
"res",
".",
"WriteString",
"(",
"sep",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // ToTextLine converts a row into line of text. To do so, it requires the list
// of bindings of the table, and the separator you want to use. If the separator
// is empty tabs will be used. | [
"ToTextLine",
"converts",
"a",
"row",
"into",
"line",
"of",
"text",
".",
"To",
"do",
"so",
"it",
"requires",
"the",
"list",
"of",
"bindings",
"of",
"the",
"table",
"and",
"the",
"separator",
"you",
"want",
"to",
"use",
".",
"If",
"the",
"separator",
"is",
"empty",
"tabs",
"will",
"be",
"used",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L99-L118 |
12,406 | google/badwolf | bql/table/table.go | AddRow | func (t *Table) AddRow(r Row) {
t.mu.Lock()
if len(r) > 0 {
delete(r, "")
t.Data = append(t.Data, r)
}
t.mu.Unlock()
} | go | func (t *Table) AddRow(r Row) {
t.mu.Lock()
if len(r) > 0 {
delete(r, "")
t.Data = append(t.Data, r)
}
t.mu.Unlock()
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"AddRow",
"(",
"r",
"Row",
")",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"len",
"(",
"r",
")",
">",
"0",
"{",
"delete",
"(",
"r",
",",
"\"",
"\"",
")",
"\n",
"t",
".",
"Data",
"=",
"append",
"(",
"t",
".",
"Data",
",",
"r",
")",
"\n",
"}",
"\n",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
]
| // AddRow adds a row to the end of a table. For performance reasons, it does not
// check that all bindings are set, nor that they are declared on table
// creation. BQL builds valid tables, if you plan to create tables on your own
// you should be careful to provide valid rows. | [
"AddRow",
"adds",
"a",
"row",
"to",
"the",
"end",
"of",
"a",
"table",
".",
"For",
"performance",
"reasons",
"it",
"does",
"not",
"check",
"that",
"all",
"bindings",
"are",
"set",
"nor",
"that",
"they",
"are",
"declared",
"on",
"table",
"creation",
".",
"BQL",
"builds",
"valid",
"tables",
"if",
"you",
"plan",
"to",
"create",
"tables",
"on",
"your",
"own",
"you",
"should",
"be",
"careful",
"to",
"provide",
"valid",
"rows",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L124-L131 |
12,407 | google/badwolf | bql/table/table.go | NumRows | func (t *Table) NumRows() int {
t.mu.RLock()
defer t.mu.RUnlock()
return len(t.Data)
} | go | func (t *Table) NumRows() int {
t.mu.RLock()
defer t.mu.RUnlock()
return len(t.Data)
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"NumRows",
"(",
")",
"int",
"{",
"t",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"len",
"(",
"t",
".",
"Data",
")",
"\n",
"}"
]
| // NumRows returns the number of rows currently available on the table. | [
"NumRows",
"returns",
"the",
"number",
"of",
"rows",
"currently",
"available",
"on",
"the",
"table",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L134-L138 |
12,408 | google/badwolf | bql/table/table.go | Row | func (t *Table) Row(i int) (Row, bool) {
t.mu.RLock()
defer t.mu.RUnlock()
if i < 0 || i >= len(t.Data) {
return nil, false
}
return t.Data[i], true
} | go | func (t *Table) Row(i int) (Row, bool) {
t.mu.RLock()
defer t.mu.RUnlock()
if i < 0 || i >= len(t.Data) {
return nil, false
}
return t.Data[i], true
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"Row",
"(",
"i",
"int",
")",
"(",
"Row",
",",
"bool",
")",
"{",
"t",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"i",
"<",
"0",
"||",
"i",
">=",
"len",
"(",
"t",
".",
"Data",
")",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"return",
"t",
".",
"Data",
"[",
"i",
"]",
",",
"true",
"\n",
"}"
]
| // Row returns the requested row. Rows start at 0. Also, if you request a row
// beyond it will return nil, and the ok boolean will be false. | [
"Row",
"returns",
"the",
"requested",
"row",
".",
"Rows",
"start",
"at",
"0",
".",
"Also",
"if",
"you",
"request",
"a",
"row",
"beyond",
"it",
"will",
"return",
"nil",
"and",
"the",
"ok",
"boolean",
"will",
"be",
"false",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L142-L149 |
12,409 | google/badwolf | bql/table/table.go | Rows | func (t *Table) Rows() []Row {
t.mu.RLock()
defer t.mu.RUnlock()
return t.Data
} | go | func (t *Table) Rows() []Row {
t.mu.RLock()
defer t.mu.RUnlock()
return t.Data
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"Rows",
"(",
")",
"[",
"]",
"Row",
"{",
"t",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"t",
".",
"Data",
"\n",
"}"
]
| // Rows returns all the available rows. | [
"Rows",
"returns",
"all",
"the",
"available",
"rows",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L152-L156 |
12,410 | google/badwolf | bql/table/table.go | unsafeAddBindings | func (t *Table) unsafeAddBindings(bs []string) {
for _, b := range bs {
if !t.mbs[b] {
t.mbs[b] = true
t.AvailableBindings = append(t.AvailableBindings, b)
}
}
} | go | func (t *Table) unsafeAddBindings(bs []string) {
for _, b := range bs {
if !t.mbs[b] {
t.mbs[b] = true
t.AvailableBindings = append(t.AvailableBindings, b)
}
}
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"unsafeAddBindings",
"(",
"bs",
"[",
"]",
"string",
")",
"{",
"for",
"_",
",",
"b",
":=",
"range",
"bs",
"{",
"if",
"!",
"t",
".",
"mbs",
"[",
"b",
"]",
"{",
"t",
".",
"mbs",
"[",
"b",
"]",
"=",
"true",
"\n",
"t",
".",
"AvailableBindings",
"=",
"append",
"(",
"t",
".",
"AvailableBindings",
",",
"b",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // unsafeAddBindings add the new bindings provided to the table bypassing the lock. | [
"unsafeAddBindings",
"add",
"the",
"new",
"bindings",
"provided",
"to",
"the",
"table",
"bypassing",
"the",
"lock",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L159-L166 |
12,411 | google/badwolf | bql/table/table.go | AddBindings | func (t *Table) AddBindings(bs []string) {
t.mu.Lock()
t.unsafeAddBindings(bs)
t.mu.Unlock()
} | go | func (t *Table) AddBindings(bs []string) {
t.mu.Lock()
t.unsafeAddBindings(bs)
t.mu.Unlock()
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"AddBindings",
"(",
"bs",
"[",
"]",
"string",
")",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"t",
".",
"unsafeAddBindings",
"(",
"bs",
")",
"\n",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
]
| // AddBindings add the new bindings provided to the table. | [
"AddBindings",
"add",
"the",
"new",
"bindings",
"provided",
"to",
"the",
"table",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L169-L173 |
12,412 | google/badwolf | bql/table/table.go | ProjectBindings | func (t *Table) ProjectBindings(bs []string) error {
t.mu.Lock()
defer t.mu.Unlock()
if len(t.Data) == 0 || len(t.mbs) == 0 {
return nil
}
for _, b := range bs {
if !t.mbs[b] {
return fmt.Errorf("cannot project against unknown binding %s; known bindinds are %v", b, t.AvailableBindings)
}
}
t.AvailableBindings = []string{}
t.mbs = make(map[string]bool)
t.unsafeAddBindings(bs)
return nil
} | go | func (t *Table) ProjectBindings(bs []string) error {
t.mu.Lock()
defer t.mu.Unlock()
if len(t.Data) == 0 || len(t.mbs) == 0 {
return nil
}
for _, b := range bs {
if !t.mbs[b] {
return fmt.Errorf("cannot project against unknown binding %s; known bindinds are %v", b, t.AvailableBindings)
}
}
t.AvailableBindings = []string{}
t.mbs = make(map[string]bool)
t.unsafeAddBindings(bs)
return nil
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"ProjectBindings",
"(",
"bs",
"[",
"]",
"string",
")",
"error",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"len",
"(",
"t",
".",
"Data",
")",
"==",
"0",
"||",
"len",
"(",
"t",
".",
"mbs",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"_",
",",
"b",
":=",
"range",
"bs",
"{",
"if",
"!",
"t",
".",
"mbs",
"[",
"b",
"]",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"b",
",",
"t",
".",
"AvailableBindings",
")",
"\n",
"}",
"\n",
"}",
"\n",
"t",
".",
"AvailableBindings",
"=",
"[",
"]",
"string",
"{",
"}",
"\n",
"t",
".",
"mbs",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"t",
".",
"unsafeAddBindings",
"(",
"bs",
")",
"\n",
"return",
"nil",
"\n",
"}"
]
| // ProjectBindings replaces the current bindings with the projected one. The
// provided bindings needs to be a subset of the original bindings. If the
// provided bindings are not a subset of the original ones, the projection will
// fail, leave the table unmodified, and return an error. The projection only
// modify the bindings, but does not drop non projected data. | [
"ProjectBindings",
"replaces",
"the",
"current",
"bindings",
"with",
"the",
"projected",
"one",
".",
"The",
"provided",
"bindings",
"needs",
"to",
"be",
"a",
"subset",
"of",
"the",
"original",
"bindings",
".",
"If",
"the",
"provided",
"bindings",
"are",
"not",
"a",
"subset",
"of",
"the",
"original",
"ones",
"the",
"projection",
"will",
"fail",
"leave",
"the",
"table",
"unmodified",
"and",
"return",
"an",
"error",
".",
"The",
"projection",
"only",
"modify",
"the",
"bindings",
"but",
"does",
"not",
"drop",
"non",
"projected",
"data",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L180-L195 |
12,413 | google/badwolf | bql/table/table.go | HasBinding | func (t *Table) HasBinding(b string) bool {
t.mu.RLock()
defer t.mu.RUnlock()
return t.mbs[b]
} | go | func (t *Table) HasBinding(b string) bool {
t.mu.RLock()
defer t.mu.RUnlock()
return t.mbs[b]
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"HasBinding",
"(",
"b",
"string",
")",
"bool",
"{",
"t",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"t",
".",
"mbs",
"[",
"b",
"]",
"\n",
"}"
]
| // HasBinding returns true if the binding currently exist on the table. | [
"HasBinding",
"returns",
"true",
"if",
"the",
"binding",
"currently",
"exist",
"on",
"the",
"table",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L198-L202 |
12,414 | google/badwolf | bql/table/table.go | Bindings | func (t *Table) Bindings() []string {
t.mu.RLock()
defer t.mu.RUnlock()
return t.AvailableBindings
} | go | func (t *Table) Bindings() []string {
t.mu.RLock()
defer t.mu.RUnlock()
return t.AvailableBindings
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"Bindings",
"(",
")",
"[",
"]",
"string",
"{",
"t",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"t",
".",
"AvailableBindings",
"\n",
"}"
]
| // Bindings returns the bindings contained on the tables. | [
"Bindings",
"returns",
"the",
"bindings",
"contained",
"on",
"the",
"tables",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L205-L209 |
12,415 | google/badwolf | bql/table/table.go | equalBindings | func equalBindings(b1, b2 map[string]bool) bool {
if len(b1) != len(b2) {
return false
}
for k := range b1 {
if !b2[k] {
return false
}
}
return true
} | go | func equalBindings(b1, b2 map[string]bool) bool {
if len(b1) != len(b2) {
return false
}
for k := range b1 {
if !b2[k] {
return false
}
}
return true
} | [
"func",
"equalBindings",
"(",
"b1",
",",
"b2",
"map",
"[",
"string",
"]",
"bool",
")",
"bool",
"{",
"if",
"len",
"(",
"b1",
")",
"!=",
"len",
"(",
"b2",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"k",
":=",
"range",
"b1",
"{",
"if",
"!",
"b2",
"[",
"k",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
]
| // equalBindings returns true if the bindings are the same, false otherwise. | [
"equalBindings",
"returns",
"true",
"if",
"the",
"bindings",
"are",
"the",
"same",
"false",
"otherwise",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L212-L222 |
12,416 | google/badwolf | bql/table/table.go | AppendTable | func (t *Table) AppendTable(t2 *Table) error {
t.mu.Lock()
defer t.mu.Unlock()
if t2 == nil {
return nil
}
if len(t.AvailableBindings) > 0 && !equalBindings(t.mbs, t2.mbs) {
return fmt.Errorf("AppendTable can only append to an empty table or equally binded table; intead got %v and %v", t.AvailableBindings, t2.AvailableBindings)
}
if len(t.AvailableBindings) == 0 {
t.AvailableBindings, t.mbs = t2.AvailableBindings, t2.mbs
}
t.Data = append(t.Data, t2.Data...)
return nil
} | go | func (t *Table) AppendTable(t2 *Table) error {
t.mu.Lock()
defer t.mu.Unlock()
if t2 == nil {
return nil
}
if len(t.AvailableBindings) > 0 && !equalBindings(t.mbs, t2.mbs) {
return fmt.Errorf("AppendTable can only append to an empty table or equally binded table; intead got %v and %v", t.AvailableBindings, t2.AvailableBindings)
}
if len(t.AvailableBindings) == 0 {
t.AvailableBindings, t.mbs = t2.AvailableBindings, t2.mbs
}
t.Data = append(t.Data, t2.Data...)
return nil
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"AppendTable",
"(",
"t2",
"*",
"Table",
")",
"error",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"t2",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"len",
"(",
"t",
".",
"AvailableBindings",
")",
">",
"0",
"&&",
"!",
"equalBindings",
"(",
"t",
".",
"mbs",
",",
"t2",
".",
"mbs",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
".",
"AvailableBindings",
",",
"t2",
".",
"AvailableBindings",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"t",
".",
"AvailableBindings",
")",
"==",
"0",
"{",
"t",
".",
"AvailableBindings",
",",
"t",
".",
"mbs",
"=",
"t2",
".",
"AvailableBindings",
",",
"t2",
".",
"mbs",
"\n",
"}",
"\n",
"t",
".",
"Data",
"=",
"append",
"(",
"t",
".",
"Data",
",",
"t2",
".",
"Data",
"...",
")",
"\n",
"return",
"nil",
"\n",
"}"
]
| // AppendTable appends the content of the provided table. It will fail it the
// target table is not empty and the bindings do not match. | [
"AppendTable",
"appends",
"the",
"content",
"of",
"the",
"provided",
"table",
".",
"It",
"will",
"fail",
"it",
"the",
"target",
"table",
"is",
"not",
"empty",
"and",
"the",
"bindings",
"do",
"not",
"match",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L226-L240 |
12,417 | google/badwolf | bql/table/table.go | disjointBinding | func disjointBinding(b1, b2 map[string]bool) bool {
for k := range b1 {
if b2[k] {
return false
}
}
return true
} | go | func disjointBinding(b1, b2 map[string]bool) bool {
for k := range b1 {
if b2[k] {
return false
}
}
return true
} | [
"func",
"disjointBinding",
"(",
"b1",
",",
"b2",
"map",
"[",
"string",
"]",
"bool",
")",
"bool",
"{",
"for",
"k",
":=",
"range",
"b1",
"{",
"if",
"b2",
"[",
"k",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
]
| // disjointBinding returns true if they are not overlapping bindings, false
// otherwise. | [
"disjointBinding",
"returns",
"true",
"if",
"they",
"are",
"not",
"overlapping",
"bindings",
"false",
"otherwise",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L244-L251 |
12,418 | google/badwolf | bql/table/table.go | MergeRows | func MergeRows(ms []Row) Row {
res := make(map[string]*Cell)
for _, om := range ms {
for k, v := range om {
if k != "" {
res[k] = v
}
}
}
return res
} | go | func MergeRows(ms []Row) Row {
res := make(map[string]*Cell)
for _, om := range ms {
for k, v := range om {
if k != "" {
res[k] = v
}
}
}
return res
} | [
"func",
"MergeRows",
"(",
"ms",
"[",
"]",
"Row",
")",
"Row",
"{",
"res",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Cell",
")",
"\n",
"for",
"_",
",",
"om",
":=",
"range",
"ms",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"om",
"{",
"if",
"k",
"!=",
"\"",
"\"",
"{",
"res",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
]
| // MergeRows takes a list of rows and returns a new map containing both. | [
"MergeRows",
"takes",
"a",
"list",
"of",
"rows",
"and",
"returns",
"a",
"new",
"map",
"containing",
"both",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L254-L264 |
12,419 | google/badwolf | bql/table/table.go | DotProduct | func (t *Table) DotProduct(t2 *Table) error {
t.mu.Lock()
defer t.mu.Unlock()
if !disjointBinding(t.mbs, t2.mbs) {
return fmt.Errorf("DotProduct operations requires disjoint bindings; instead got %v and %v", t.mbs, t2.mbs)
}
// Update the table metadata.
m := make(map[string]bool)
for k := range t.mbs {
m[k] = true
}
for k := range t2.mbs {
m[k] = true
}
t.mbs = m
t.AvailableBindings = []string{}
for k := range t.mbs {
t.AvailableBindings = append(t.AvailableBindings, k)
}
// Update the data.
td := t.Data
cnt, size := 0, len(td)*len(t2.Data)
t.Data = make([]Row, size, size) // Preallocate resulting table.
for _, r1 := range td {
for _, r2 := range t2.Data {
t.Data[cnt] = MergeRows([]Row{r1, r2})
cnt++
}
}
return nil
} | go | func (t *Table) DotProduct(t2 *Table) error {
t.mu.Lock()
defer t.mu.Unlock()
if !disjointBinding(t.mbs, t2.mbs) {
return fmt.Errorf("DotProduct operations requires disjoint bindings; instead got %v and %v", t.mbs, t2.mbs)
}
// Update the table metadata.
m := make(map[string]bool)
for k := range t.mbs {
m[k] = true
}
for k := range t2.mbs {
m[k] = true
}
t.mbs = m
t.AvailableBindings = []string{}
for k := range t.mbs {
t.AvailableBindings = append(t.AvailableBindings, k)
}
// Update the data.
td := t.Data
cnt, size := 0, len(td)*len(t2.Data)
t.Data = make([]Row, size, size) // Preallocate resulting table.
for _, r1 := range td {
for _, r2 := range t2.Data {
t.Data[cnt] = MergeRows([]Row{r1, r2})
cnt++
}
}
return nil
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"DotProduct",
"(",
"t2",
"*",
"Table",
")",
"error",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"disjointBinding",
"(",
"t",
".",
"mbs",
",",
"t2",
".",
"mbs",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
".",
"mbs",
",",
"t2",
".",
"mbs",
")",
"\n",
"}",
"\n",
"// Update the table metadata.",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"for",
"k",
":=",
"range",
"t",
".",
"mbs",
"{",
"m",
"[",
"k",
"]",
"=",
"true",
"\n",
"}",
"\n",
"for",
"k",
":=",
"range",
"t2",
".",
"mbs",
"{",
"m",
"[",
"k",
"]",
"=",
"true",
"\n",
"}",
"\n",
"t",
".",
"mbs",
"=",
"m",
"\n",
"t",
".",
"AvailableBindings",
"=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"k",
":=",
"range",
"t",
".",
"mbs",
"{",
"t",
".",
"AvailableBindings",
"=",
"append",
"(",
"t",
".",
"AvailableBindings",
",",
"k",
")",
"\n",
"}",
"\n",
"// Update the data.",
"td",
":=",
"t",
".",
"Data",
"\n",
"cnt",
",",
"size",
":=",
"0",
",",
"len",
"(",
"td",
")",
"*",
"len",
"(",
"t2",
".",
"Data",
")",
"\n",
"t",
".",
"Data",
"=",
"make",
"(",
"[",
"]",
"Row",
",",
"size",
",",
"size",
")",
"// Preallocate resulting table.",
"\n",
"for",
"_",
",",
"r1",
":=",
"range",
"td",
"{",
"for",
"_",
",",
"r2",
":=",
"range",
"t2",
".",
"Data",
"{",
"t",
".",
"Data",
"[",
"cnt",
"]",
"=",
"MergeRows",
"(",
"[",
"]",
"Row",
"{",
"r1",
",",
"r2",
"}",
")",
"\n",
"cnt",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // DotProduct does the dot product with the provided table | [
"DotProduct",
"does",
"the",
"dot",
"product",
"with",
"the",
"provided",
"table"
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L267-L297 |
12,420 | google/badwolf | bql/table/table.go | Truncate | func (t *Table) Truncate() {
t.mu.Lock()
defer t.mu.Unlock()
t.Data = nil
} | go | func (t *Table) Truncate() {
t.mu.Lock()
defer t.mu.Unlock()
t.Data = nil
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"Truncate",
"(",
")",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"t",
".",
"Data",
"=",
"nil",
"\n",
"}"
]
| // Truncate flushes all the data away. It still retains all set bindings. | [
"Truncate",
"flushes",
"all",
"the",
"data",
"away",
".",
"It",
"still",
"retains",
"all",
"set",
"bindings",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L316-L320 |
12,421 | google/badwolf | bql/table/table.go | Limit | func (t *Table) Limit(i int64) {
t.mu.Lock()
defer t.mu.Unlock()
if int64(len(t.Data)) > i {
td := make([]Row, i, i) // Preallocate resulting table.
copy(td, t.Data[:i])
t.Data = td
}
} | go | func (t *Table) Limit(i int64) {
t.mu.Lock()
defer t.mu.Unlock()
if int64(len(t.Data)) > i {
td := make([]Row, i, i) // Preallocate resulting table.
copy(td, t.Data[:i])
t.Data = td
}
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"Limit",
"(",
"i",
"int64",
")",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"int64",
"(",
"len",
"(",
"t",
".",
"Data",
")",
")",
">",
"i",
"{",
"td",
":=",
"make",
"(",
"[",
"]",
"Row",
",",
"i",
",",
"i",
")",
"// Preallocate resulting table.",
"\n",
"copy",
"(",
"td",
",",
"t",
".",
"Data",
"[",
":",
"i",
"]",
")",
"\n",
"t",
".",
"Data",
"=",
"td",
"\n",
"}",
"\n",
"}"
]
| // Limit keeps the initial ith rows. | [
"Limit",
"keeps",
"the",
"initial",
"ith",
"rows",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L323-L331 |
12,422 | google/badwolf | bql/table/table.go | Swap | func (c bySortConfig) Swap(i, j int) {
c.rows[i], c.rows[j] = c.rows[j], c.rows[i]
} | go | func (c bySortConfig) Swap(i, j int) {
c.rows[i], c.rows[j] = c.rows[j], c.rows[i]
} | [
"func",
"(",
"c",
"bySortConfig",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"c",
".",
"rows",
"[",
"i",
"]",
",",
"c",
".",
"rows",
"[",
"j",
"]",
"=",
"c",
".",
"rows",
"[",
"j",
"]",
",",
"c",
".",
"rows",
"[",
"i",
"]",
"\n",
"}"
]
| // Swap exchange the i and j rows in the table. | [
"Swap",
"exchange",
"the",
"i",
"and",
"j",
"rows",
"in",
"the",
"table",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L366-L368 |
12,423 | google/badwolf | bql/table/table.go | Less | func (c bySortConfig) Less(i, j int) bool {
ri, rj, cfg := c.rows[i], c.rows[j], c.cfg
return rowLess(ri, rj, cfg)
} | go | func (c bySortConfig) Less(i, j int) bool {
ri, rj, cfg := c.rows[i], c.rows[j], c.cfg
return rowLess(ri, rj, cfg)
} | [
"func",
"(",
"c",
"bySortConfig",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"ri",
",",
"rj",
",",
"cfg",
":=",
"c",
".",
"rows",
"[",
"i",
"]",
",",
"c",
".",
"rows",
"[",
"j",
"]",
",",
"c",
".",
"cfg",
"\n",
"return",
"rowLess",
"(",
"ri",
",",
"rj",
",",
"cfg",
")",
"\n",
"}"
]
| // Less returns true if the i row is less than j one. | [
"Less",
"returns",
"true",
"if",
"the",
"i",
"row",
"is",
"less",
"than",
"j",
"one",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L434-L437 |
12,424 | google/badwolf | bql/table/table.go | unsafeSort | func (t *Table) unsafeSort(cfg SortConfig) {
if cfg == nil {
return
}
sort.Sort(bySortConfig{t.Data, cfg})
} | go | func (t *Table) unsafeSort(cfg SortConfig) {
if cfg == nil {
return
}
sort.Sort(bySortConfig{t.Data, cfg})
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"unsafeSort",
"(",
"cfg",
"SortConfig",
")",
"{",
"if",
"cfg",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"bySortConfig",
"{",
"t",
".",
"Data",
",",
"cfg",
"}",
")",
"\n",
"}"
]
| // unsafeSort sorts the table given a sort configuration bypassing the lock. | [
"unsafeSort",
"sorts",
"the",
"table",
"given",
"a",
"sort",
"configuration",
"bypassing",
"the",
"lock",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L440-L445 |
12,425 | google/badwolf | bql/table/table.go | Sort | func (t *Table) Sort(cfg SortConfig) {
t.mu.Lock()
t.unsafeSort(cfg)
t.mu.Unlock()
} | go | func (t *Table) Sort(cfg SortConfig) {
t.mu.Lock()
t.unsafeSort(cfg)
t.mu.Unlock()
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"Sort",
"(",
"cfg",
"SortConfig",
")",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"t",
".",
"unsafeSort",
"(",
"cfg",
")",
"\n",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
]
| // Sort sorts the table given a sort configuration. | [
"Sort",
"sorts",
"the",
"table",
"given",
"a",
"sort",
"configuration",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L448-L452 |
12,426 | google/badwolf | bql/table/table.go | groupRangeReduce | func (t *Table) groupRangeReduce(i, j int, alias map[string]string, acc map[string]Accumulator) (Row, error) {
t.mu.Lock()
defer t.mu.Unlock()
if i > j {
return nil, fmt.Errorf("cannot aggregate empty ranges [%d, %d)", i, j)
}
// Initialize the range and accumulator results.
rng := t.Data[i:j]
vaccs := make(map[string]interface{})
// Reset the accumulators.
for _, a := range acc {
a.Reset()
}
// Aggregate the range using the provided aggregators.
for _, r := range rng {
for b, a := range acc {
av, err := a.Accumulate(r[b])
if err != nil {
return nil, err
}
vaccs[b] = av
}
}
// Create a new row based on the resulting aggregations with the proper
// binding aliasing and the non aggregated values.
newRow := Row{}
for b, v := range rng[0] {
acc, ok := vaccs[b]
if !ok {
if a, ok := alias[b]; ok {
newRow[a] = v
} else {
newRow[b] = v
}
} else {
a, ok := alias[b]
if !ok {
return nil, fmt.Errorf("aggregated bindings require and alias; binding %s missing alias", b)
}
// Accumulators currently only can return numeric literals.
switch acc.(type) {
case int64:
l, err := literal.DefaultBuilder().Build(literal.Int64, acc)
if err != nil {
return nil, err
}
newRow[a] = &Cell{L: l}
case float64:
l, err := literal.DefaultBuilder().Build(literal.Float64, acc)
if err != nil {
return nil, err
}
newRow[a] = &Cell{L: l}
default:
return nil, fmt.Errorf("aggregation of binding %s returned unknown value %v or type", b, acc)
}
}
}
return newRow, nil
} | go | func (t *Table) groupRangeReduce(i, j int, alias map[string]string, acc map[string]Accumulator) (Row, error) {
t.mu.Lock()
defer t.mu.Unlock()
if i > j {
return nil, fmt.Errorf("cannot aggregate empty ranges [%d, %d)", i, j)
}
// Initialize the range and accumulator results.
rng := t.Data[i:j]
vaccs := make(map[string]interface{})
// Reset the accumulators.
for _, a := range acc {
a.Reset()
}
// Aggregate the range using the provided aggregators.
for _, r := range rng {
for b, a := range acc {
av, err := a.Accumulate(r[b])
if err != nil {
return nil, err
}
vaccs[b] = av
}
}
// Create a new row based on the resulting aggregations with the proper
// binding aliasing and the non aggregated values.
newRow := Row{}
for b, v := range rng[0] {
acc, ok := vaccs[b]
if !ok {
if a, ok := alias[b]; ok {
newRow[a] = v
} else {
newRow[b] = v
}
} else {
a, ok := alias[b]
if !ok {
return nil, fmt.Errorf("aggregated bindings require and alias; binding %s missing alias", b)
}
// Accumulators currently only can return numeric literals.
switch acc.(type) {
case int64:
l, err := literal.DefaultBuilder().Build(literal.Int64, acc)
if err != nil {
return nil, err
}
newRow[a] = &Cell{L: l}
case float64:
l, err := literal.DefaultBuilder().Build(literal.Float64, acc)
if err != nil {
return nil, err
}
newRow[a] = &Cell{L: l}
default:
return nil, fmt.Errorf("aggregation of binding %s returned unknown value %v or type", b, acc)
}
}
}
return newRow, nil
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"groupRangeReduce",
"(",
"i",
",",
"j",
"int",
",",
"alias",
"map",
"[",
"string",
"]",
"string",
",",
"acc",
"map",
"[",
"string",
"]",
"Accumulator",
")",
"(",
"Row",
",",
"error",
")",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"i",
">",
"j",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
",",
"j",
")",
"\n",
"}",
"\n",
"// Initialize the range and accumulator results.",
"rng",
":=",
"t",
".",
"Data",
"[",
"i",
":",
"j",
"]",
"\n",
"vaccs",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"// Reset the accumulators.",
"for",
"_",
",",
"a",
":=",
"range",
"acc",
"{",
"a",
".",
"Reset",
"(",
")",
"\n",
"}",
"\n",
"// Aggregate the range using the provided aggregators.",
"for",
"_",
",",
"r",
":=",
"range",
"rng",
"{",
"for",
"b",
",",
"a",
":=",
"range",
"acc",
"{",
"av",
",",
"err",
":=",
"a",
".",
"Accumulate",
"(",
"r",
"[",
"b",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"vaccs",
"[",
"b",
"]",
"=",
"av",
"\n",
"}",
"\n",
"}",
"\n",
"// Create a new row based on the resulting aggregations with the proper",
"// binding aliasing and the non aggregated values.",
"newRow",
":=",
"Row",
"{",
"}",
"\n",
"for",
"b",
",",
"v",
":=",
"range",
"rng",
"[",
"0",
"]",
"{",
"acc",
",",
"ok",
":=",
"vaccs",
"[",
"b",
"]",
"\n",
"if",
"!",
"ok",
"{",
"if",
"a",
",",
"ok",
":=",
"alias",
"[",
"b",
"]",
";",
"ok",
"{",
"newRow",
"[",
"a",
"]",
"=",
"v",
"\n",
"}",
"else",
"{",
"newRow",
"[",
"b",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"else",
"{",
"a",
",",
"ok",
":=",
"alias",
"[",
"b",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"b",
")",
"\n",
"}",
"\n",
"// Accumulators currently only can return numeric literals.",
"switch",
"acc",
".",
"(",
"type",
")",
"{",
"case",
"int64",
":",
"l",
",",
"err",
":=",
"literal",
".",
"DefaultBuilder",
"(",
")",
".",
"Build",
"(",
"literal",
".",
"Int64",
",",
"acc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"newRow",
"[",
"a",
"]",
"=",
"&",
"Cell",
"{",
"L",
":",
"l",
"}",
"\n",
"case",
"float64",
":",
"l",
",",
"err",
":=",
"literal",
".",
"DefaultBuilder",
"(",
")",
".",
"Build",
"(",
"literal",
".",
"Float64",
",",
"acc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"newRow",
"[",
"a",
"]",
"=",
"&",
"Cell",
"{",
"L",
":",
"l",
"}",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"b",
",",
"acc",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"newRow",
",",
"nil",
"\n",
"}"
]
| // groupRangeReduce takes a sorted range and generates a new row containing
// the aggregated columns and the non aggregated ones. | [
"groupRangeReduce",
"takes",
"a",
"sorted",
"range",
"and",
"generates",
"a",
"new",
"row",
"containing",
"the",
"aggregated",
"columns",
"and",
"the",
"non",
"aggregated",
"ones",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L574-L633 |
12,427 | google/badwolf | bql/table/table.go | unsafeFullGroupRangeReduce | func (t *Table) unsafeFullGroupRangeReduce(i, j int, acc map[string]map[string]AliasAccPair) (Row, error) {
if i > j {
return nil, fmt.Errorf("cannot aggregate empty ranges [%d, %d)", i, j)
}
// Initialize the range and accumulator results.
rng := t.Data[i:j]
// Reset the accumulators.
for _, aap := range acc {
for _, a := range aap {
if a.Acc != nil {
a.Acc.Reset()
}
}
}
// Aggregate the range using the provided aggregators.
vaccs := make(map[string]map[string]interface{})
for _, r := range rng {
for _, aap := range acc {
for _, a := range aap {
if a.Acc == nil {
continue
}
av, err := a.Acc.Accumulate(r[a.InAlias])
if err != nil {
return nil, err
}
if _, ok := vaccs[a.InAlias]; !ok {
vaccs[a.InAlias] = make(map[string]interface{})
}
vaccs[a.InAlias][a.OutAlias] = av
}
}
}
// Create a new row based on the resulting aggregations with the proper
// binding aliasing and the non aggregated values.
newRow := Row{}
for b, v := range rng[0] {
for _, app := range acc[b] { //macc {
if app.Acc == nil {
newRow[app.OutAlias] = v
} else {
// Accumulators currently only can return numeric literals.
switch vaccs[app.InAlias][app.OutAlias].(type) {
case int64:
l, err := literal.DefaultBuilder().Build(literal.Int64, vaccs[app.InAlias][app.OutAlias])
if err != nil {
return nil, err
}
newRow[app.OutAlias] = &Cell{L: l}
case float64:
l, err := literal.DefaultBuilder().Build(literal.Float64, vaccs[app.InAlias][app.OutAlias])
if err != nil {
return nil, err
}
newRow[app.OutAlias] = &Cell{L: l}
default:
return nil, fmt.Errorf("aggregation of binding %s returned unknown value %v or type", b, acc)
}
}
}
}
if len(newRow) == 0 {
return nil, errors.New("failed to reduced row range returning an empty one")
}
return newRow, nil
} | go | func (t *Table) unsafeFullGroupRangeReduce(i, j int, acc map[string]map[string]AliasAccPair) (Row, error) {
if i > j {
return nil, fmt.Errorf("cannot aggregate empty ranges [%d, %d)", i, j)
}
// Initialize the range and accumulator results.
rng := t.Data[i:j]
// Reset the accumulators.
for _, aap := range acc {
for _, a := range aap {
if a.Acc != nil {
a.Acc.Reset()
}
}
}
// Aggregate the range using the provided aggregators.
vaccs := make(map[string]map[string]interface{})
for _, r := range rng {
for _, aap := range acc {
for _, a := range aap {
if a.Acc == nil {
continue
}
av, err := a.Acc.Accumulate(r[a.InAlias])
if err != nil {
return nil, err
}
if _, ok := vaccs[a.InAlias]; !ok {
vaccs[a.InAlias] = make(map[string]interface{})
}
vaccs[a.InAlias][a.OutAlias] = av
}
}
}
// Create a new row based on the resulting aggregations with the proper
// binding aliasing and the non aggregated values.
newRow := Row{}
for b, v := range rng[0] {
for _, app := range acc[b] { //macc {
if app.Acc == nil {
newRow[app.OutAlias] = v
} else {
// Accumulators currently only can return numeric literals.
switch vaccs[app.InAlias][app.OutAlias].(type) {
case int64:
l, err := literal.DefaultBuilder().Build(literal.Int64, vaccs[app.InAlias][app.OutAlias])
if err != nil {
return nil, err
}
newRow[app.OutAlias] = &Cell{L: l}
case float64:
l, err := literal.DefaultBuilder().Build(literal.Float64, vaccs[app.InAlias][app.OutAlias])
if err != nil {
return nil, err
}
newRow[app.OutAlias] = &Cell{L: l}
default:
return nil, fmt.Errorf("aggregation of binding %s returned unknown value %v or type", b, acc)
}
}
}
}
if len(newRow) == 0 {
return nil, errors.New("failed to reduced row range returning an empty one")
}
return newRow, nil
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"unsafeFullGroupRangeReduce",
"(",
"i",
",",
"j",
"int",
",",
"acc",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"AliasAccPair",
")",
"(",
"Row",
",",
"error",
")",
"{",
"if",
"i",
">",
"j",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
",",
"j",
")",
"\n",
"}",
"\n",
"// Initialize the range and accumulator results.",
"rng",
":=",
"t",
".",
"Data",
"[",
"i",
":",
"j",
"]",
"\n",
"// Reset the accumulators.",
"for",
"_",
",",
"aap",
":=",
"range",
"acc",
"{",
"for",
"_",
",",
"a",
":=",
"range",
"aap",
"{",
"if",
"a",
".",
"Acc",
"!=",
"nil",
"{",
"a",
".",
"Acc",
".",
"Reset",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"// Aggregate the range using the provided aggregators.",
"vaccs",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"rng",
"{",
"for",
"_",
",",
"aap",
":=",
"range",
"acc",
"{",
"for",
"_",
",",
"a",
":=",
"range",
"aap",
"{",
"if",
"a",
".",
"Acc",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"av",
",",
"err",
":=",
"a",
".",
"Acc",
".",
"Accumulate",
"(",
"r",
"[",
"a",
".",
"InAlias",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"vaccs",
"[",
"a",
".",
"InAlias",
"]",
";",
"!",
"ok",
"{",
"vaccs",
"[",
"a",
".",
"InAlias",
"]",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n",
"vaccs",
"[",
"a",
".",
"InAlias",
"]",
"[",
"a",
".",
"OutAlias",
"]",
"=",
"av",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"// Create a new row based on the resulting aggregations with the proper",
"// binding aliasing and the non aggregated values.",
"newRow",
":=",
"Row",
"{",
"}",
"\n",
"for",
"b",
",",
"v",
":=",
"range",
"rng",
"[",
"0",
"]",
"{",
"for",
"_",
",",
"app",
":=",
"range",
"acc",
"[",
"b",
"]",
"{",
"//macc {",
"if",
"app",
".",
"Acc",
"==",
"nil",
"{",
"newRow",
"[",
"app",
".",
"OutAlias",
"]",
"=",
"v",
"\n",
"}",
"else",
"{",
"// Accumulators currently only can return numeric literals.",
"switch",
"vaccs",
"[",
"app",
".",
"InAlias",
"]",
"[",
"app",
".",
"OutAlias",
"]",
".",
"(",
"type",
")",
"{",
"case",
"int64",
":",
"l",
",",
"err",
":=",
"literal",
".",
"DefaultBuilder",
"(",
")",
".",
"Build",
"(",
"literal",
".",
"Int64",
",",
"vaccs",
"[",
"app",
".",
"InAlias",
"]",
"[",
"app",
".",
"OutAlias",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"newRow",
"[",
"app",
".",
"OutAlias",
"]",
"=",
"&",
"Cell",
"{",
"L",
":",
"l",
"}",
"\n",
"case",
"float64",
":",
"l",
",",
"err",
":=",
"literal",
".",
"DefaultBuilder",
"(",
")",
".",
"Build",
"(",
"literal",
".",
"Float64",
",",
"vaccs",
"[",
"app",
".",
"InAlias",
"]",
"[",
"app",
".",
"OutAlias",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"newRow",
"[",
"app",
".",
"OutAlias",
"]",
"=",
"&",
"Cell",
"{",
"L",
":",
"l",
"}",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"b",
",",
"acc",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"newRow",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"newRow",
",",
"nil",
"\n",
"}"
]
| // unsafeFullGroupRangeReduce takes a sorted range and generates a new row containing
// the aggregated columns and the non aggregated ones. This call bypasses the lock. | [
"unsafeFullGroupRangeReduce",
"takes",
"a",
"sorted",
"range",
"and",
"generates",
"a",
"new",
"row",
"containing",
"the",
"aggregated",
"columns",
"and",
"the",
"non",
"aggregated",
"ones",
".",
"This",
"call",
"bypasses",
"the",
"lock",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L644-L709 |
12,428 | google/badwolf | bql/table/table.go | toMap | func toMap(aaps []AliasAccPair) map[string]map[string]AliasAccPair {
resMap := make(map[string]map[string]AliasAccPair)
for _, aap := range aaps {
m, ok := resMap[aap.InAlias]
if !ok {
m = make(map[string]AliasAccPair)
resMap[aap.InAlias] = m
}
m[aap.OutAlias] = aap
}
return resMap
} | go | func toMap(aaps []AliasAccPair) map[string]map[string]AliasAccPair {
resMap := make(map[string]map[string]AliasAccPair)
for _, aap := range aaps {
m, ok := resMap[aap.InAlias]
if !ok {
m = make(map[string]AliasAccPair)
resMap[aap.InAlias] = m
}
m[aap.OutAlias] = aap
}
return resMap
} | [
"func",
"toMap",
"(",
"aaps",
"[",
"]",
"AliasAccPair",
")",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"AliasAccPair",
"{",
"resMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"AliasAccPair",
")",
"\n",
"for",
"_",
",",
"aap",
":=",
"range",
"aaps",
"{",
"m",
",",
"ok",
":=",
"resMap",
"[",
"aap",
".",
"InAlias",
"]",
"\n",
"if",
"!",
"ok",
"{",
"m",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"AliasAccPair",
")",
"\n",
"resMap",
"[",
"aap",
".",
"InAlias",
"]",
"=",
"m",
"\n",
"}",
"\n",
"m",
"[",
"aap",
".",
"OutAlias",
"]",
"=",
"aap",
"\n",
"}",
"\n",
"return",
"resMap",
"\n",
"}"
]
| // toMap converts a list of alias and acc pairs into a nested map. The first
// key is the input binding, the second one is the output binding. | [
"toMap",
"converts",
"a",
"list",
"of",
"alias",
"and",
"acc",
"pairs",
"into",
"a",
"nested",
"map",
".",
"The",
"first",
"key",
"is",
"the",
"input",
"binding",
"the",
"second",
"one",
"is",
"the",
"output",
"binding",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L713-L724 |
12,429 | google/badwolf | bql/table/table.go | Reduce | func (t *Table) Reduce(cfg SortConfig, aaps []AliasAccPair) error {
t.mu.Lock()
defer t.mu.Unlock()
maaps := toMap(aaps)
// Input validation tests.
if len(t.AvailableBindings) != len(maaps) {
return fmt.Errorf("table.Reduce cannot project bindings; current %v, requested %v", t.AvailableBindings, aaps)
}
for _, b := range t.AvailableBindings {
if _, ok := maaps[b]; !ok {
return fmt.Errorf("table.Reduce missing binding alias for %q", b)
}
}
cnt := 0
for b := range maaps {
if _, ok := t.mbs[b]; !ok {
return fmt.Errorf("table.Reduce unknown reducer binding %q; available bindings %v", b, t.AvailableBindings)
}
cnt++
}
if cnt != len(t.AvailableBindings) {
return fmt.Errorf("table.Reduce invalid reduce configuration in cfg=%v, aap=%v for table with binding %v", cfg, aaps, t.AvailableBindings)
}
// Valid reduce configuration. Reduce sorts the table and then reduces
// contiguous groups row groups.
if len(t.Data) == 0 {
return nil
}
t.unsafeSort(cfg)
last, lastIdx, current, newData := "", 0, "", []Row{}
id := func(r Row) string {
res := bytes.NewBufferString("")
for _, c := range cfg {
res.WriteString(r[c.Binding].String())
res.WriteString(";")
}
return res.String()
}
for idx, r := range t.Data {
current = id(r)
// First time.
if last == "" {
last, lastIdx = current, idx
continue
}
// Still in the same group.
if last == current {
continue
}
// A group reduce operation is needed.
nr, err := t.unsafeFullGroupRangeReduce(lastIdx, idx, maaps)
if err != nil {
return err
}
newData = append(newData, nr)
last, lastIdx = current, idx
}
nr, err := t.unsafeFullGroupRangeReduce(lastIdx, len(t.Data), maaps)
if err != nil {
return err
}
newData = append(newData, nr)
// Update the table.
t.AvailableBindings, t.mbs = []string{}, make(map[string]bool)
for _, aap := range aaps {
if !t.mbs[aap.OutAlias] {
t.AvailableBindings = append(t.AvailableBindings, aap.OutAlias)
}
t.mbs[aap.OutAlias] = true
}
t.Data = newData
return nil
} | go | func (t *Table) Reduce(cfg SortConfig, aaps []AliasAccPair) error {
t.mu.Lock()
defer t.mu.Unlock()
maaps := toMap(aaps)
// Input validation tests.
if len(t.AvailableBindings) != len(maaps) {
return fmt.Errorf("table.Reduce cannot project bindings; current %v, requested %v", t.AvailableBindings, aaps)
}
for _, b := range t.AvailableBindings {
if _, ok := maaps[b]; !ok {
return fmt.Errorf("table.Reduce missing binding alias for %q", b)
}
}
cnt := 0
for b := range maaps {
if _, ok := t.mbs[b]; !ok {
return fmt.Errorf("table.Reduce unknown reducer binding %q; available bindings %v", b, t.AvailableBindings)
}
cnt++
}
if cnt != len(t.AvailableBindings) {
return fmt.Errorf("table.Reduce invalid reduce configuration in cfg=%v, aap=%v for table with binding %v", cfg, aaps, t.AvailableBindings)
}
// Valid reduce configuration. Reduce sorts the table and then reduces
// contiguous groups row groups.
if len(t.Data) == 0 {
return nil
}
t.unsafeSort(cfg)
last, lastIdx, current, newData := "", 0, "", []Row{}
id := func(r Row) string {
res := bytes.NewBufferString("")
for _, c := range cfg {
res.WriteString(r[c.Binding].String())
res.WriteString(";")
}
return res.String()
}
for idx, r := range t.Data {
current = id(r)
// First time.
if last == "" {
last, lastIdx = current, idx
continue
}
// Still in the same group.
if last == current {
continue
}
// A group reduce operation is needed.
nr, err := t.unsafeFullGroupRangeReduce(lastIdx, idx, maaps)
if err != nil {
return err
}
newData = append(newData, nr)
last, lastIdx = current, idx
}
nr, err := t.unsafeFullGroupRangeReduce(lastIdx, len(t.Data), maaps)
if err != nil {
return err
}
newData = append(newData, nr)
// Update the table.
t.AvailableBindings, t.mbs = []string{}, make(map[string]bool)
for _, aap := range aaps {
if !t.mbs[aap.OutAlias] {
t.AvailableBindings = append(t.AvailableBindings, aap.OutAlias)
}
t.mbs[aap.OutAlias] = true
}
t.Data = newData
return nil
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"Reduce",
"(",
"cfg",
"SortConfig",
",",
"aaps",
"[",
"]",
"AliasAccPair",
")",
"error",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"maaps",
":=",
"toMap",
"(",
"aaps",
")",
"\n",
"// Input validation tests.",
"if",
"len",
"(",
"t",
".",
"AvailableBindings",
")",
"!=",
"len",
"(",
"maaps",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
".",
"AvailableBindings",
",",
"aaps",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"b",
":=",
"range",
"t",
".",
"AvailableBindings",
"{",
"if",
"_",
",",
"ok",
":=",
"maaps",
"[",
"b",
"]",
";",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"b",
")",
"\n",
"}",
"\n",
"}",
"\n",
"cnt",
":=",
"0",
"\n",
"for",
"b",
":=",
"range",
"maaps",
"{",
"if",
"_",
",",
"ok",
":=",
"t",
".",
"mbs",
"[",
"b",
"]",
";",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"b",
",",
"t",
".",
"AvailableBindings",
")",
"\n",
"}",
"\n",
"cnt",
"++",
"\n",
"}",
"\n",
"if",
"cnt",
"!=",
"len",
"(",
"t",
".",
"AvailableBindings",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cfg",
",",
"aaps",
",",
"t",
".",
"AvailableBindings",
")",
"\n",
"}",
"\n",
"// Valid reduce configuration. Reduce sorts the table and then reduces",
"// contiguous groups row groups.",
"if",
"len",
"(",
"t",
".",
"Data",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"t",
".",
"unsafeSort",
"(",
"cfg",
")",
"\n",
"last",
",",
"lastIdx",
",",
"current",
",",
"newData",
":=",
"\"",
"\"",
",",
"0",
",",
"\"",
"\"",
",",
"[",
"]",
"Row",
"{",
"}",
"\n",
"id",
":=",
"func",
"(",
"r",
"Row",
")",
"string",
"{",
"res",
":=",
"bytes",
".",
"NewBufferString",
"(",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"cfg",
"{",
"res",
".",
"WriteString",
"(",
"r",
"[",
"c",
".",
"Binding",
"]",
".",
"String",
"(",
")",
")",
"\n",
"res",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"res",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"for",
"idx",
",",
"r",
":=",
"range",
"t",
".",
"Data",
"{",
"current",
"=",
"id",
"(",
"r",
")",
"\n",
"// First time.",
"if",
"last",
"==",
"\"",
"\"",
"{",
"last",
",",
"lastIdx",
"=",
"current",
",",
"idx",
"\n",
"continue",
"\n",
"}",
"\n",
"// Still in the same group.",
"if",
"last",
"==",
"current",
"{",
"continue",
"\n",
"}",
"\n",
"// A group reduce operation is needed.",
"nr",
",",
"err",
":=",
"t",
".",
"unsafeFullGroupRangeReduce",
"(",
"lastIdx",
",",
"idx",
",",
"maaps",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"newData",
"=",
"append",
"(",
"newData",
",",
"nr",
")",
"\n",
"last",
",",
"lastIdx",
"=",
"current",
",",
"idx",
"\n",
"}",
"\n",
"nr",
",",
"err",
":=",
"t",
".",
"unsafeFullGroupRangeReduce",
"(",
"lastIdx",
",",
"len",
"(",
"t",
".",
"Data",
")",
",",
"maaps",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"newData",
"=",
"append",
"(",
"newData",
",",
"nr",
")",
"\n",
"// Update the table.",
"t",
".",
"AvailableBindings",
",",
"t",
".",
"mbs",
"=",
"[",
"]",
"string",
"{",
"}",
",",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"aap",
":=",
"range",
"aaps",
"{",
"if",
"!",
"t",
".",
"mbs",
"[",
"aap",
".",
"OutAlias",
"]",
"{",
"t",
".",
"AvailableBindings",
"=",
"append",
"(",
"t",
".",
"AvailableBindings",
",",
"aap",
".",
"OutAlias",
")",
"\n",
"}",
"\n",
"t",
".",
"mbs",
"[",
"aap",
".",
"OutAlias",
"]",
"=",
"true",
"\n",
"}",
"\n",
"t",
".",
"Data",
"=",
"newData",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Reduce alters the table by sorting and then range grouping the table data.
// In order to group reduce the table, we sort the table and then apply the
// accumulator functions to each group. Finally, the table metadata gets
// updated to reflect the reduce operation. | [
"Reduce",
"alters",
"the",
"table",
"by",
"sorting",
"and",
"then",
"range",
"grouping",
"the",
"table",
"data",
".",
"In",
"order",
"to",
"group",
"reduce",
"the",
"table",
"we",
"sort",
"the",
"table",
"and",
"then",
"apply",
"the",
"accumulator",
"functions",
"to",
"each",
"group",
".",
"Finally",
"the",
"table",
"metadata",
"gets",
"updated",
"to",
"reflect",
"the",
"reduce",
"operation",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L730-L802 |
12,430 | google/badwolf | bql/table/table.go | Filter | func (t *Table) Filter(f func(Row) bool) {
t.mu.Lock()
defer t.mu.Unlock()
var newData []Row
for _, r := range t.Data {
if !f(r) {
newData = append(newData, r)
}
}
t.Data = newData
} | go | func (t *Table) Filter(f func(Row) bool) {
t.mu.Lock()
defer t.mu.Unlock()
var newData []Row
for _, r := range t.Data {
if !f(r) {
newData = append(newData, r)
}
}
t.Data = newData
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"Filter",
"(",
"f",
"func",
"(",
"Row",
")",
"bool",
")",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"var",
"newData",
"[",
"]",
"Row",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"t",
".",
"Data",
"{",
"if",
"!",
"f",
"(",
"r",
")",
"{",
"newData",
"=",
"append",
"(",
"newData",
",",
"r",
")",
"\n",
"}",
"\n",
"}",
"\n",
"t",
".",
"Data",
"=",
"newData",
"\n",
"}"
]
| // Filter removes all the rows where the provided function returns true. | [
"Filter",
"removes",
"all",
"the",
"rows",
"where",
"the",
"provided",
"function",
"returns",
"true",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L805-L815 |
12,431 | google/badwolf | bql/table/table.go | ToText | func (t *Table) ToText(sep string) (*bytes.Buffer, error) {
t.mu.RLock()
defer t.mu.RUnlock()
res, row := &bytes.Buffer{}, &bytes.Buffer{}
res.WriteString(strings.Join(t.AvailableBindings, sep))
res.WriteString("\n")
for _, r := range t.Data {
err := r.ToTextLine(row, t.AvailableBindings, sep)
if err != nil {
return nil, err
}
if _, err := res.Write(row.Bytes()); err != nil {
return nil, err
}
if _, err := res.WriteString("\n"); err != nil {
return nil, err
}
row.Reset()
}
return res, nil
} | go | func (t *Table) ToText(sep string) (*bytes.Buffer, error) {
t.mu.RLock()
defer t.mu.RUnlock()
res, row := &bytes.Buffer{}, &bytes.Buffer{}
res.WriteString(strings.Join(t.AvailableBindings, sep))
res.WriteString("\n")
for _, r := range t.Data {
err := r.ToTextLine(row, t.AvailableBindings, sep)
if err != nil {
return nil, err
}
if _, err := res.Write(row.Bytes()); err != nil {
return nil, err
}
if _, err := res.WriteString("\n"); err != nil {
return nil, err
}
row.Reset()
}
return res, nil
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"ToText",
"(",
"sep",
"string",
")",
"(",
"*",
"bytes",
".",
"Buffer",
",",
"error",
")",
"{",
"t",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"res",
",",
"row",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
",",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"res",
".",
"WriteString",
"(",
"strings",
".",
"Join",
"(",
"t",
".",
"AvailableBindings",
",",
"sep",
")",
")",
"\n",
"res",
".",
"WriteString",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"t",
".",
"Data",
"{",
"err",
":=",
"r",
".",
"ToTextLine",
"(",
"row",
",",
"t",
".",
"AvailableBindings",
",",
"sep",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"res",
".",
"Write",
"(",
"row",
".",
"Bytes",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"res",
".",
"WriteString",
"(",
"\"",
"\\n",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"row",
".",
"Reset",
"(",
")",
"\n",
"}",
"\n",
"return",
"res",
",",
"nil",
"\n",
"}"
]
| // ToText convert the table into a readable text versions. It requires the
// separator to be used between cells. | [
"ToText",
"convert",
"the",
"table",
"into",
"a",
"readable",
"text",
"versions",
".",
"It",
"requires",
"the",
"separator",
"to",
"be",
"used",
"between",
"cells",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L819-L839 |
12,432 | google/badwolf | bql/table/table.go | String | func (t *Table) String() string {
t.mu.RLock()
defer t.mu.RUnlock()
b, err := t.ToText("\t")
if err != nil {
return fmt.Sprintf("Failed to serialize to text! Error: %s", err)
}
return b.String()
} | go | func (t *Table) String() string {
t.mu.RLock()
defer t.mu.RUnlock()
b, err := t.ToText("\t")
if err != nil {
return fmt.Sprintf("Failed to serialize to text! Error: %s", err)
}
return b.String()
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"String",
"(",
")",
"string",
"{",
"t",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"b",
",",
"err",
":=",
"t",
".",
"ToText",
"(",
"\"",
"\\t",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"b",
".",
"String",
"(",
")",
"\n",
"}"
]
| // String attempts to force serialize the table into a string. | [
"String",
"attempts",
"to",
"force",
"serialize",
"the",
"table",
"into",
"a",
"string",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/table/table.go#L842-L850 |
12,433 | google/badwolf | bql/planner/tracer/trace.go | Trace | func Trace(w io.Writer, msgs func() []string) {
if w == nil {
return
}
c <- &event{w, time.Now(), msgs}
} | go | func Trace(w io.Writer, msgs func() []string) {
if w == nil {
return
}
c <- &event{w, time.Now(), msgs}
} | [
"func",
"Trace",
"(",
"w",
"io",
".",
"Writer",
",",
"msgs",
"func",
"(",
")",
"[",
"]",
"string",
")",
"{",
"if",
"w",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"c",
"<-",
"&",
"event",
"{",
"w",
",",
"time",
".",
"Now",
"(",
")",
",",
"msgs",
"}",
"\n",
"}"
]
| // Trace attempts to write a trace if a valid writer is provided. The
// tracer is lazy on the string generation to avoid adding too much
// overhead when tracing ins not on. | [
"Trace",
"attempts",
"to",
"write",
"a",
"trace",
"if",
"a",
"valid",
"writer",
"is",
"provided",
".",
"The",
"tracer",
"is",
"lazy",
"on",
"the",
"string",
"generation",
"to",
"avoid",
"adding",
"too",
"much",
"overhead",
"when",
"tracing",
"ins",
"not",
"on",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/planner/tracer/trace.go#L50-L55 |
12,434 | google/badwolf | storage/storage.go | String | func (l *LookupOptions) String() string {
b := bytes.NewBufferString("<limit=")
b.WriteString(strconv.Itoa(l.MaxElements))
b.WriteString(", lower_anchor=")
if l.LowerAnchor != nil {
b.WriteString(l.LowerAnchor.Format(time.RFC3339Nano))
} else {
b.WriteString("nil")
}
b.WriteString(", upper_anchor=")
if l.UpperAnchor != nil {
b.WriteString(l.UpperAnchor.Format(time.RFC3339Nano))
} else {
b.WriteString("nil")
}
b.WriteString(fmt.Sprintf(", LatestAnchor=%v", l.LatestAnchor))
b.WriteString(">")
return b.String()
} | go | func (l *LookupOptions) String() string {
b := bytes.NewBufferString("<limit=")
b.WriteString(strconv.Itoa(l.MaxElements))
b.WriteString(", lower_anchor=")
if l.LowerAnchor != nil {
b.WriteString(l.LowerAnchor.Format(time.RFC3339Nano))
} else {
b.WriteString("nil")
}
b.WriteString(", upper_anchor=")
if l.UpperAnchor != nil {
b.WriteString(l.UpperAnchor.Format(time.RFC3339Nano))
} else {
b.WriteString("nil")
}
b.WriteString(fmt.Sprintf(", LatestAnchor=%v", l.LatestAnchor))
b.WriteString(">")
return b.String()
} | [
"func",
"(",
"l",
"*",
"LookupOptions",
")",
"String",
"(",
")",
"string",
"{",
"b",
":=",
"bytes",
".",
"NewBufferString",
"(",
"\"",
"\"",
")",
"\n",
"b",
".",
"WriteString",
"(",
"strconv",
".",
"Itoa",
"(",
"l",
".",
"MaxElements",
")",
")",
"\n",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"if",
"l",
".",
"LowerAnchor",
"!=",
"nil",
"{",
"b",
".",
"WriteString",
"(",
"l",
".",
"LowerAnchor",
".",
"Format",
"(",
"time",
".",
"RFC3339Nano",
")",
")",
"\n",
"}",
"else",
"{",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"if",
"l",
".",
"UpperAnchor",
"!=",
"nil",
"{",
"b",
".",
"WriteString",
"(",
"l",
".",
"UpperAnchor",
".",
"Format",
"(",
"time",
".",
"RFC3339Nano",
")",
")",
"\n",
"}",
"else",
"{",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"b",
".",
"WriteString",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
".",
"LatestAnchor",
")",
")",
"\n",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"return",
"b",
".",
"String",
"(",
")",
"\n",
"}"
]
| // String returns a readable version of the LookupOptions instance. | [
"String",
"returns",
"a",
"readable",
"version",
"of",
"the",
"LookupOptions",
"instance",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/storage/storage.go#L49-L67 |
12,435 | google/badwolf | storage/storage.go | UUID | func (l *LookupOptions) UUID() uuid.UUID {
var buffer bytes.Buffer
buffer.WriteString(l.String())
return uuid.NewSHA1(uuid.NIL, buffer.Bytes())
} | go | func (l *LookupOptions) UUID() uuid.UUID {
var buffer bytes.Buffer
buffer.WriteString(l.String())
return uuid.NewSHA1(uuid.NIL, buffer.Bytes())
} | [
"func",
"(",
"l",
"*",
"LookupOptions",
")",
"UUID",
"(",
")",
"uuid",
".",
"UUID",
"{",
"var",
"buffer",
"bytes",
".",
"Buffer",
"\n",
"buffer",
".",
"WriteString",
"(",
"l",
".",
"String",
"(",
")",
")",
"\n",
"return",
"uuid",
".",
"NewSHA1",
"(",
"uuid",
".",
"NIL",
",",
"buffer",
".",
"Bytes",
"(",
")",
")",
"\n",
"}"
]
| // UUID return the UUID of the lookup option. | [
"UUID",
"return",
"the",
"UUID",
"of",
"the",
"lookup",
"option",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/storage/storage.go#L70-L74 |
12,436 | google/badwolf | storage/memory/memory.go | NewGraph | func (s *memoryStore) NewGraph(ctx context.Context, id string) (storage.Graph, error) {
g := &memory{
id: id,
idx: make(map[string]*triple.Triple, initialAllocation),
idxS: make(map[string]map[string]*triple.Triple, initialAllocation),
idxP: make(map[string]map[string]*triple.Triple, initialAllocation),
idxO: make(map[string]map[string]*triple.Triple, initialAllocation),
idxSP: make(map[string]map[string]*triple.Triple, initialAllocation),
idxPO: make(map[string]map[string]*triple.Triple, initialAllocation),
idxSO: make(map[string]map[string]*triple.Triple, initialAllocation),
}
s.rwmu.Lock()
defer s.rwmu.Unlock()
if _, ok := s.graphs[id]; ok {
return nil, fmt.Errorf("memory.NewGraph(%q): graph already exists", id)
}
s.graphs[id] = g
return g, nil
} | go | func (s *memoryStore) NewGraph(ctx context.Context, id string) (storage.Graph, error) {
g := &memory{
id: id,
idx: make(map[string]*triple.Triple, initialAllocation),
idxS: make(map[string]map[string]*triple.Triple, initialAllocation),
idxP: make(map[string]map[string]*triple.Triple, initialAllocation),
idxO: make(map[string]map[string]*triple.Triple, initialAllocation),
idxSP: make(map[string]map[string]*triple.Triple, initialAllocation),
idxPO: make(map[string]map[string]*triple.Triple, initialAllocation),
idxSO: make(map[string]map[string]*triple.Triple, initialAllocation),
}
s.rwmu.Lock()
defer s.rwmu.Unlock()
if _, ok := s.graphs[id]; ok {
return nil, fmt.Errorf("memory.NewGraph(%q): graph already exists", id)
}
s.graphs[id] = g
return g, nil
} | [
"func",
"(",
"s",
"*",
"memoryStore",
")",
"NewGraph",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
")",
"(",
"storage",
".",
"Graph",
",",
"error",
")",
"{",
"g",
":=",
"&",
"memory",
"{",
"id",
":",
"id",
",",
"idx",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"triple",
".",
"Triple",
",",
"initialAllocation",
")",
",",
"idxS",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"*",
"triple",
".",
"Triple",
",",
"initialAllocation",
")",
",",
"idxP",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"*",
"triple",
".",
"Triple",
",",
"initialAllocation",
")",
",",
"idxO",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"*",
"triple",
".",
"Triple",
",",
"initialAllocation",
")",
",",
"idxSP",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"*",
"triple",
".",
"Triple",
",",
"initialAllocation",
")",
",",
"idxPO",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"*",
"triple",
".",
"Triple",
",",
"initialAllocation",
")",
",",
"idxSO",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"*",
"triple",
".",
"Triple",
",",
"initialAllocation",
")",
",",
"}",
"\n\n",
"s",
".",
"rwmu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"rwmu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"s",
".",
"graphs",
"[",
"id",
"]",
";",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n",
"s",
".",
"graphs",
"[",
"id",
"]",
"=",
"g",
"\n",
"return",
"g",
",",
"nil",
"\n",
"}"
]
| // NewGraph creates a new graph. | [
"NewGraph",
"creates",
"a",
"new",
"graph",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/storage/memory/memory.go#L63-L82 |
12,437 | google/badwolf | storage/memory/memory.go | Graph | func (s *memoryStore) Graph(ctx context.Context, id string) (storage.Graph, error) {
s.rwmu.RLock()
defer s.rwmu.RUnlock()
if g, ok := s.graphs[id]; ok {
return g, nil
}
return nil, fmt.Errorf("memory.Graph(%q): graph does not exist", id)
} | go | func (s *memoryStore) Graph(ctx context.Context, id string) (storage.Graph, error) {
s.rwmu.RLock()
defer s.rwmu.RUnlock()
if g, ok := s.graphs[id]; ok {
return g, nil
}
return nil, fmt.Errorf("memory.Graph(%q): graph does not exist", id)
} | [
"func",
"(",
"s",
"*",
"memoryStore",
")",
"Graph",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
")",
"(",
"storage",
".",
"Graph",
",",
"error",
")",
"{",
"s",
".",
"rwmu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"rwmu",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"g",
",",
"ok",
":=",
"s",
".",
"graphs",
"[",
"id",
"]",
";",
"ok",
"{",
"return",
"g",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}"
]
| // Graph returns an existing graph if available. Getting a non existing
// graph should return an error. | [
"Graph",
"returns",
"an",
"existing",
"graph",
"if",
"available",
".",
"Getting",
"a",
"non",
"existing",
"graph",
"should",
"return",
"an",
"error",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/storage/memory/memory.go#L86-L93 |
12,438 | google/badwolf | storage/memory/memory.go | AddTriples | func (m *memory) AddTriples(ctx context.Context, ts []*triple.Triple) error {
m.rwmu.Lock()
defer m.rwmu.Unlock()
for _, t := range ts {
tuuid := UUIDToByteString(t.UUID())
sUUID := UUIDToByteString(t.Subject().UUID())
pUUID := UUIDToByteString(t.Predicate().PartialUUID())
oUUID := UUIDToByteString(t.Object().UUID())
// Update master index
m.idx[tuuid] = t
if _, ok := m.idxS[sUUID]; !ok {
m.idxS[sUUID] = make(map[string]*triple.Triple)
}
m.idxS[sUUID][tuuid] = t
if _, ok := m.idxP[pUUID]; !ok {
m.idxP[pUUID] = make(map[string]*triple.Triple)
}
m.idxP[pUUID][tuuid] = t
if _, ok := m.idxO[oUUID]; !ok {
m.idxO[oUUID] = make(map[string]*triple.Triple)
}
m.idxO[oUUID][tuuid] = t
key := sUUID + pUUID
if _, ok := m.idxSP[key]; !ok {
m.idxSP[key] = make(map[string]*triple.Triple)
}
m.idxSP[key][tuuid] = t
key = pUUID + oUUID
if _, ok := m.idxPO[key]; !ok {
m.idxPO[key] = make(map[string]*triple.Triple)
}
m.idxPO[key][tuuid] = t
key = sUUID + oUUID
if _, ok := m.idxSO[key]; !ok {
m.idxSO[key] = make(map[string]*triple.Triple)
}
m.idxSO[key][tuuid] = t
}
return nil
} | go | func (m *memory) AddTriples(ctx context.Context, ts []*triple.Triple) error {
m.rwmu.Lock()
defer m.rwmu.Unlock()
for _, t := range ts {
tuuid := UUIDToByteString(t.UUID())
sUUID := UUIDToByteString(t.Subject().UUID())
pUUID := UUIDToByteString(t.Predicate().PartialUUID())
oUUID := UUIDToByteString(t.Object().UUID())
// Update master index
m.idx[tuuid] = t
if _, ok := m.idxS[sUUID]; !ok {
m.idxS[sUUID] = make(map[string]*triple.Triple)
}
m.idxS[sUUID][tuuid] = t
if _, ok := m.idxP[pUUID]; !ok {
m.idxP[pUUID] = make(map[string]*triple.Triple)
}
m.idxP[pUUID][tuuid] = t
if _, ok := m.idxO[oUUID]; !ok {
m.idxO[oUUID] = make(map[string]*triple.Triple)
}
m.idxO[oUUID][tuuid] = t
key := sUUID + pUUID
if _, ok := m.idxSP[key]; !ok {
m.idxSP[key] = make(map[string]*triple.Triple)
}
m.idxSP[key][tuuid] = t
key = pUUID + oUUID
if _, ok := m.idxPO[key]; !ok {
m.idxPO[key] = make(map[string]*triple.Triple)
}
m.idxPO[key][tuuid] = t
key = sUUID + oUUID
if _, ok := m.idxSO[key]; !ok {
m.idxSO[key] = make(map[string]*triple.Triple)
}
m.idxSO[key][tuuid] = t
}
return nil
} | [
"func",
"(",
"m",
"*",
"memory",
")",
"AddTriples",
"(",
"ctx",
"context",
".",
"Context",
",",
"ts",
"[",
"]",
"*",
"triple",
".",
"Triple",
")",
"error",
"{",
"m",
".",
"rwmu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"rwmu",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"ts",
"{",
"tuuid",
":=",
"UUIDToByteString",
"(",
"t",
".",
"UUID",
"(",
")",
")",
"\n",
"sUUID",
":=",
"UUIDToByteString",
"(",
"t",
".",
"Subject",
"(",
")",
".",
"UUID",
"(",
")",
")",
"\n",
"pUUID",
":=",
"UUIDToByteString",
"(",
"t",
".",
"Predicate",
"(",
")",
".",
"PartialUUID",
"(",
")",
")",
"\n",
"oUUID",
":=",
"UUIDToByteString",
"(",
"t",
".",
"Object",
"(",
")",
".",
"UUID",
"(",
")",
")",
"\n",
"// Update master index",
"m",
".",
"idx",
"[",
"tuuid",
"]",
"=",
"t",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"m",
".",
"idxS",
"[",
"sUUID",
"]",
";",
"!",
"ok",
"{",
"m",
".",
"idxS",
"[",
"sUUID",
"]",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"triple",
".",
"Triple",
")",
"\n",
"}",
"\n",
"m",
".",
"idxS",
"[",
"sUUID",
"]",
"[",
"tuuid",
"]",
"=",
"t",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"m",
".",
"idxP",
"[",
"pUUID",
"]",
";",
"!",
"ok",
"{",
"m",
".",
"idxP",
"[",
"pUUID",
"]",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"triple",
".",
"Triple",
")",
"\n",
"}",
"\n",
"m",
".",
"idxP",
"[",
"pUUID",
"]",
"[",
"tuuid",
"]",
"=",
"t",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"m",
".",
"idxO",
"[",
"oUUID",
"]",
";",
"!",
"ok",
"{",
"m",
".",
"idxO",
"[",
"oUUID",
"]",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"triple",
".",
"Triple",
")",
"\n",
"}",
"\n",
"m",
".",
"idxO",
"[",
"oUUID",
"]",
"[",
"tuuid",
"]",
"=",
"t",
"\n\n",
"key",
":=",
"sUUID",
"+",
"pUUID",
"\n",
"if",
"_",
",",
"ok",
":=",
"m",
".",
"idxSP",
"[",
"key",
"]",
";",
"!",
"ok",
"{",
"m",
".",
"idxSP",
"[",
"key",
"]",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"triple",
".",
"Triple",
")",
"\n",
"}",
"\n",
"m",
".",
"idxSP",
"[",
"key",
"]",
"[",
"tuuid",
"]",
"=",
"t",
"\n\n",
"key",
"=",
"pUUID",
"+",
"oUUID",
"\n",
"if",
"_",
",",
"ok",
":=",
"m",
".",
"idxPO",
"[",
"key",
"]",
";",
"!",
"ok",
"{",
"m",
".",
"idxPO",
"[",
"key",
"]",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"triple",
".",
"Triple",
")",
"\n",
"}",
"\n",
"m",
".",
"idxPO",
"[",
"key",
"]",
"[",
"tuuid",
"]",
"=",
"t",
"\n\n",
"key",
"=",
"sUUID",
"+",
"oUUID",
"\n",
"if",
"_",
",",
"ok",
":=",
"m",
".",
"idxSO",
"[",
"key",
"]",
";",
"!",
"ok",
"{",
"m",
".",
"idxSO",
"[",
"key",
"]",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"triple",
".",
"Triple",
")",
"\n",
"}",
"\n",
"m",
".",
"idxSO",
"[",
"key",
"]",
"[",
"tuuid",
"]",
"=",
"t",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // AddTriples adds the triples to the storage. | [
"AddTriples",
"adds",
"the",
"triples",
"to",
"the",
"storage",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/storage/memory/memory.go#L140-L185 |
12,439 | google/badwolf | storage/memory/memory.go | RemoveTriples | func (m *memory) RemoveTriples(ctx context.Context, ts []*triple.Triple) error {
for _, t := range ts {
suuid := UUIDToByteString(t.UUID())
sUUID := UUIDToByteString(t.Subject().UUID())
pUUID := UUIDToByteString(t.Predicate().PartialUUID())
oUUID := UUIDToByteString(t.Object().UUID())
// Update master index
m.rwmu.Lock()
delete(m.idx, suuid)
delete(m.idxS[sUUID], suuid)
delete(m.idxP[pUUID], suuid)
delete(m.idxO[oUUID], suuid)
key := sUUID + pUUID
delete(m.idxSP[key], suuid)
if len(m.idxSP[key]) == 0 {
delete(m.idxSP, key)
}
key = pUUID + oUUID
delete(m.idxPO[key], suuid)
if len(m.idxPO[key]) == 0 {
delete(m.idxPO, key)
}
key = sUUID + oUUID
delete(m.idxSO[key], suuid)
if len(m.idxSO[key]) == 0 {
delete(m.idxSO, key)
}
m.rwmu.Unlock()
}
return nil
} | go | func (m *memory) RemoveTriples(ctx context.Context, ts []*triple.Triple) error {
for _, t := range ts {
suuid := UUIDToByteString(t.UUID())
sUUID := UUIDToByteString(t.Subject().UUID())
pUUID := UUIDToByteString(t.Predicate().PartialUUID())
oUUID := UUIDToByteString(t.Object().UUID())
// Update master index
m.rwmu.Lock()
delete(m.idx, suuid)
delete(m.idxS[sUUID], suuid)
delete(m.idxP[pUUID], suuid)
delete(m.idxO[oUUID], suuid)
key := sUUID + pUUID
delete(m.idxSP[key], suuid)
if len(m.idxSP[key]) == 0 {
delete(m.idxSP, key)
}
key = pUUID + oUUID
delete(m.idxPO[key], suuid)
if len(m.idxPO[key]) == 0 {
delete(m.idxPO, key)
}
key = sUUID + oUUID
delete(m.idxSO[key], suuid)
if len(m.idxSO[key]) == 0 {
delete(m.idxSO, key)
}
m.rwmu.Unlock()
}
return nil
} | [
"func",
"(",
"m",
"*",
"memory",
")",
"RemoveTriples",
"(",
"ctx",
"context",
".",
"Context",
",",
"ts",
"[",
"]",
"*",
"triple",
".",
"Triple",
")",
"error",
"{",
"for",
"_",
",",
"t",
":=",
"range",
"ts",
"{",
"suuid",
":=",
"UUIDToByteString",
"(",
"t",
".",
"UUID",
"(",
")",
")",
"\n",
"sUUID",
":=",
"UUIDToByteString",
"(",
"t",
".",
"Subject",
"(",
")",
".",
"UUID",
"(",
")",
")",
"\n",
"pUUID",
":=",
"UUIDToByteString",
"(",
"t",
".",
"Predicate",
"(",
")",
".",
"PartialUUID",
"(",
")",
")",
"\n",
"oUUID",
":=",
"UUIDToByteString",
"(",
"t",
".",
"Object",
"(",
")",
".",
"UUID",
"(",
")",
")",
"\n",
"// Update master index",
"m",
".",
"rwmu",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"m",
".",
"idx",
",",
"suuid",
")",
"\n",
"delete",
"(",
"m",
".",
"idxS",
"[",
"sUUID",
"]",
",",
"suuid",
")",
"\n",
"delete",
"(",
"m",
".",
"idxP",
"[",
"pUUID",
"]",
",",
"suuid",
")",
"\n",
"delete",
"(",
"m",
".",
"idxO",
"[",
"oUUID",
"]",
",",
"suuid",
")",
"\n\n",
"key",
":=",
"sUUID",
"+",
"pUUID",
"\n",
"delete",
"(",
"m",
".",
"idxSP",
"[",
"key",
"]",
",",
"suuid",
")",
"\n",
"if",
"len",
"(",
"m",
".",
"idxSP",
"[",
"key",
"]",
")",
"==",
"0",
"{",
"delete",
"(",
"m",
".",
"idxSP",
",",
"key",
")",
"\n",
"}",
"\n\n",
"key",
"=",
"pUUID",
"+",
"oUUID",
"\n",
"delete",
"(",
"m",
".",
"idxPO",
"[",
"key",
"]",
",",
"suuid",
")",
"\n",
"if",
"len",
"(",
"m",
".",
"idxPO",
"[",
"key",
"]",
")",
"==",
"0",
"{",
"delete",
"(",
"m",
".",
"idxPO",
",",
"key",
")",
"\n",
"}",
"\n\n",
"key",
"=",
"sUUID",
"+",
"oUUID",
"\n",
"delete",
"(",
"m",
".",
"idxSO",
"[",
"key",
"]",
",",
"suuid",
")",
"\n",
"if",
"len",
"(",
"m",
".",
"idxSO",
"[",
"key",
"]",
")",
"==",
"0",
"{",
"delete",
"(",
"m",
".",
"idxSO",
",",
"key",
")",
"\n",
"}",
"\n\n",
"m",
".",
"rwmu",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // RemoveTriples removes the triples from the storage. | [
"RemoveTriples",
"removes",
"the",
"triples",
"from",
"the",
"storage",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/storage/memory/memory.go#L188-L222 |
12,440 | google/badwolf | storage/memory/memory.go | newChecker | func newChecker(o *storage.LookupOptions, op *predicate.Predicate) *checker {
var ta *time.Time
if op != nil {
if t, err := op.TimeAnchor(); err == nil {
ta = t
}
}
return &checker{
max: o.MaxElements > 0,
c: o.MaxElements,
o: o,
op: op,
ota: ta,
}
} | go | func newChecker(o *storage.LookupOptions, op *predicate.Predicate) *checker {
var ta *time.Time
if op != nil {
if t, err := op.TimeAnchor(); err == nil {
ta = t
}
}
return &checker{
max: o.MaxElements > 0,
c: o.MaxElements,
o: o,
op: op,
ota: ta,
}
} | [
"func",
"newChecker",
"(",
"o",
"*",
"storage",
".",
"LookupOptions",
",",
"op",
"*",
"predicate",
".",
"Predicate",
")",
"*",
"checker",
"{",
"var",
"ta",
"*",
"time",
".",
"Time",
"\n",
"if",
"op",
"!=",
"nil",
"{",
"if",
"t",
",",
"err",
":=",
"op",
".",
"TimeAnchor",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"ta",
"=",
"t",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"&",
"checker",
"{",
"max",
":",
"o",
".",
"MaxElements",
">",
"0",
",",
"c",
":",
"o",
".",
"MaxElements",
",",
"o",
":",
"o",
",",
"op",
":",
"op",
",",
"ota",
":",
"ta",
",",
"}",
"\n",
"}"
]
| // newChecker creates a new checker for a given LookupOptions configuration. | [
"newChecker",
"creates",
"a",
"new",
"checker",
"for",
"a",
"given",
"LookupOptions",
"configuration",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/storage/memory/memory.go#L235-L249 |
12,441 | google/badwolf | storage/memory/memory.go | CheckAndUpdate | func (c *checker) CheckAndUpdate(p *predicate.Predicate) bool {
if c.max && c.c <= 0 {
return false
}
if p.Type() == predicate.Immutable {
c.c--
return true
}
if t, err := p.TimeAnchor(); err == nil {
if c.ota != nil && !c.ota.Equal(*t) {
return false
}
if c.o.LowerAnchor != nil && t.Before(*c.o.LowerAnchor) {
return false
}
if c.o.UpperAnchor != nil && t.After(*c.o.UpperAnchor) {
return false
}
}
c.c--
return true
} | go | func (c *checker) CheckAndUpdate(p *predicate.Predicate) bool {
if c.max && c.c <= 0 {
return false
}
if p.Type() == predicate.Immutable {
c.c--
return true
}
if t, err := p.TimeAnchor(); err == nil {
if c.ota != nil && !c.ota.Equal(*t) {
return false
}
if c.o.LowerAnchor != nil && t.Before(*c.o.LowerAnchor) {
return false
}
if c.o.UpperAnchor != nil && t.After(*c.o.UpperAnchor) {
return false
}
}
c.c--
return true
} | [
"func",
"(",
"c",
"*",
"checker",
")",
"CheckAndUpdate",
"(",
"p",
"*",
"predicate",
".",
"Predicate",
")",
"bool",
"{",
"if",
"c",
".",
"max",
"&&",
"c",
".",
"c",
"<=",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"p",
".",
"Type",
"(",
")",
"==",
"predicate",
".",
"Immutable",
"{",
"c",
".",
"c",
"--",
"\n",
"return",
"true",
"\n",
"}",
"\n\n",
"if",
"t",
",",
"err",
":=",
"p",
".",
"TimeAnchor",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"if",
"c",
".",
"ota",
"!=",
"nil",
"&&",
"!",
"c",
".",
"ota",
".",
"Equal",
"(",
"*",
"t",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"c",
".",
"o",
".",
"LowerAnchor",
"!=",
"nil",
"&&",
"t",
".",
"Before",
"(",
"*",
"c",
".",
"o",
".",
"LowerAnchor",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"c",
".",
"o",
".",
"UpperAnchor",
"!=",
"nil",
"&&",
"t",
".",
"After",
"(",
"*",
"c",
".",
"o",
".",
"UpperAnchor",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"c",
".",
"c",
"--",
"\n",
"return",
"true",
"\n",
"}"
]
| // CheckAndUpdate checks if a predicate should be considered and it also updates
// the internal state in case counts are needed. | [
"CheckAndUpdate",
"checks",
"if",
"a",
"predicate",
"should",
"be",
"considered",
"and",
"it",
"also",
"updates",
"the",
"internal",
"state",
"in",
"case",
"counts",
"are",
"needed",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/storage/memory/memory.go#L253-L275 |
12,442 | google/badwolf | storage/memory/memory.go | Objects | func (m *memory) Objects(ctx context.Context, s *node.Node, p *predicate.Predicate, lo *storage.LookupOptions, objs chan<- *triple.Object) error {
if objs == nil {
return fmt.Errorf("cannot provide an empty channel")
}
sUUID := UUIDToByteString(s.UUID())
pUUID := UUIDToByteString(p.PartialUUID())
spIdx := sUUID + pUUID
m.rwmu.RLock()
defer m.rwmu.RUnlock()
defer close(objs)
if lo.LatestAnchor {
lastTA := make(map[string]*time.Time)
trps := make(map[string]*triple.Triple)
for _, t := range m.idxSP[spIdx] {
p := t.Predicate()
ppUUID := p.PartialUUID().String()
if p.Type() == predicate.Temporal {
ta, err := p.TimeAnchor()
if err != nil {
return err
}
if lta := lastTA[ppUUID]; lta == nil || ta.Sub(*lta) > 0 {
trps[ppUUID] = t
lastTA[ppUUID] = ta
}
}
}
for _, trp := range trps {
if trp != nil {
objs <- trp.Object()
}
}
return nil
}
ckr := newChecker(lo, p)
for _, t := range m.idxSP[spIdx] {
if ckr.CheckAndUpdate(t.Predicate()) {
objs <- t.Object()
}
}
return nil
} | go | func (m *memory) Objects(ctx context.Context, s *node.Node, p *predicate.Predicate, lo *storage.LookupOptions, objs chan<- *triple.Object) error {
if objs == nil {
return fmt.Errorf("cannot provide an empty channel")
}
sUUID := UUIDToByteString(s.UUID())
pUUID := UUIDToByteString(p.PartialUUID())
spIdx := sUUID + pUUID
m.rwmu.RLock()
defer m.rwmu.RUnlock()
defer close(objs)
if lo.LatestAnchor {
lastTA := make(map[string]*time.Time)
trps := make(map[string]*triple.Triple)
for _, t := range m.idxSP[spIdx] {
p := t.Predicate()
ppUUID := p.PartialUUID().String()
if p.Type() == predicate.Temporal {
ta, err := p.TimeAnchor()
if err != nil {
return err
}
if lta := lastTA[ppUUID]; lta == nil || ta.Sub(*lta) > 0 {
trps[ppUUID] = t
lastTA[ppUUID] = ta
}
}
}
for _, trp := range trps {
if trp != nil {
objs <- trp.Object()
}
}
return nil
}
ckr := newChecker(lo, p)
for _, t := range m.idxSP[spIdx] {
if ckr.CheckAndUpdate(t.Predicate()) {
objs <- t.Object()
}
}
return nil
} | [
"func",
"(",
"m",
"*",
"memory",
")",
"Objects",
"(",
"ctx",
"context",
".",
"Context",
",",
"s",
"*",
"node",
".",
"Node",
",",
"p",
"*",
"predicate",
".",
"Predicate",
",",
"lo",
"*",
"storage",
".",
"LookupOptions",
",",
"objs",
"chan",
"<-",
"*",
"triple",
".",
"Object",
")",
"error",
"{",
"if",
"objs",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"sUUID",
":=",
"UUIDToByteString",
"(",
"s",
".",
"UUID",
"(",
")",
")",
"\n",
"pUUID",
":=",
"UUIDToByteString",
"(",
"p",
".",
"PartialUUID",
"(",
")",
")",
"\n",
"spIdx",
":=",
"sUUID",
"+",
"pUUID",
"\n",
"m",
".",
"rwmu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"m",
".",
"rwmu",
".",
"RUnlock",
"(",
")",
"\n",
"defer",
"close",
"(",
"objs",
")",
"\n\n",
"if",
"lo",
".",
"LatestAnchor",
"{",
"lastTA",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"time",
".",
"Time",
")",
"\n",
"trps",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"triple",
".",
"Triple",
")",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"m",
".",
"idxSP",
"[",
"spIdx",
"]",
"{",
"p",
":=",
"t",
".",
"Predicate",
"(",
")",
"\n",
"ppUUID",
":=",
"p",
".",
"PartialUUID",
"(",
")",
".",
"String",
"(",
")",
"\n",
"if",
"p",
".",
"Type",
"(",
")",
"==",
"predicate",
".",
"Temporal",
"{",
"ta",
",",
"err",
":=",
"p",
".",
"TimeAnchor",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"lta",
":=",
"lastTA",
"[",
"ppUUID",
"]",
";",
"lta",
"==",
"nil",
"||",
"ta",
".",
"Sub",
"(",
"*",
"lta",
")",
">",
"0",
"{",
"trps",
"[",
"ppUUID",
"]",
"=",
"t",
"\n",
"lastTA",
"[",
"ppUUID",
"]",
"=",
"ta",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"trp",
":=",
"range",
"trps",
"{",
"if",
"trp",
"!=",
"nil",
"{",
"objs",
"<-",
"trp",
".",
"Object",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"ckr",
":=",
"newChecker",
"(",
"lo",
",",
"p",
")",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"m",
".",
"idxSP",
"[",
"spIdx",
"]",
"{",
"if",
"ckr",
".",
"CheckAndUpdate",
"(",
"t",
".",
"Predicate",
"(",
")",
")",
"{",
"objs",
"<-",
"t",
".",
"Object",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Objects published the objects for the give object and predicate to the
// provided channel. | [
"Objects",
"published",
"the",
"objects",
"for",
"the",
"give",
"object",
"and",
"predicate",
"to",
"the",
"provided",
"channel",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/storage/memory/memory.go#L279-L322 |
12,443 | google/badwolf | bql/semantic/expression.go | Evaluate | func (a *AlwaysReturn) Evaluate(r table.Row) (bool, error) {
return a.V, nil
} | go | func (a *AlwaysReturn) Evaluate(r table.Row) (bool, error) {
return a.V, nil
} | [
"func",
"(",
"a",
"*",
"AlwaysReturn",
")",
"Evaluate",
"(",
"r",
"table",
".",
"Row",
")",
"(",
"bool",
",",
"error",
")",
"{",
"return",
"a",
".",
"V",
",",
"nil",
"\n",
"}"
]
| // Evaluate return the provided value. | [
"Evaluate",
"return",
"the",
"provided",
"value",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/expression.go#L41-L43 |
12,444 | google/badwolf | bql/semantic/expression.go | String | func (o OP) String() string {
switch o {
case LT:
return "<"
case GT:
return ">"
case EQ:
return "="
case NOT:
return "not"
case AND:
return "and"
case OR:
return "or"
default:
return "@UNKNOWN@"
}
} | go | func (o OP) String() string {
switch o {
case LT:
return "<"
case GT:
return ">"
case EQ:
return "="
case NOT:
return "not"
case AND:
return "and"
case OR:
return "or"
default:
return "@UNKNOWN@"
}
} | [
"func",
"(",
"o",
"OP",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"o",
"{",
"case",
"LT",
":",
"return",
"\"",
"\"",
"\n",
"case",
"GT",
":",
"return",
"\"",
"\"",
"\n",
"case",
"EQ",
":",
"return",
"\"",
"\"",
"\n",
"case",
"NOT",
":",
"return",
"\"",
"\"",
"\n",
"case",
"AND",
":",
"return",
"\"",
"\"",
"\n",
"case",
"OR",
":",
"return",
"\"",
"\"",
"\n",
"default",
":",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"}"
]
| // String returns a readable string of the operation. | [
"String",
"returns",
"a",
"readable",
"string",
"of",
"the",
"operation",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/expression.go#L64-L81 |
12,445 | google/badwolf | bql/semantic/expression.go | NewEvaluationExpression | func NewEvaluationExpression(op OP, lB, rB string) (Evaluator, error) {
l, r := strings.TrimSpace(lB), strings.TrimSpace(rB)
if l == "" || r == "" {
return nil, fmt.Errorf("bindings cannot be empty; got %q, %q", l, r)
}
switch op {
case EQ, LT, GT:
return &evaluationNode{
op: op,
lB: lB,
rB: rB,
}, nil
default:
return nil, errors.New("evaluation expressions require the operation to be one for the follwing '=', '<', '>'")
}
} | go | func NewEvaluationExpression(op OP, lB, rB string) (Evaluator, error) {
l, r := strings.TrimSpace(lB), strings.TrimSpace(rB)
if l == "" || r == "" {
return nil, fmt.Errorf("bindings cannot be empty; got %q, %q", l, r)
}
switch op {
case EQ, LT, GT:
return &evaluationNode{
op: op,
lB: lB,
rB: rB,
}, nil
default:
return nil, errors.New("evaluation expressions require the operation to be one for the follwing '=', '<', '>'")
}
} | [
"func",
"NewEvaluationExpression",
"(",
"op",
"OP",
",",
"lB",
",",
"rB",
"string",
")",
"(",
"Evaluator",
",",
"error",
")",
"{",
"l",
",",
"r",
":=",
"strings",
".",
"TrimSpace",
"(",
"lB",
")",
",",
"strings",
".",
"TrimSpace",
"(",
"rB",
")",
"\n",
"if",
"l",
"==",
"\"",
"\"",
"||",
"r",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"l",
",",
"r",
")",
"\n",
"}",
"\n",
"switch",
"op",
"{",
"case",
"EQ",
",",
"LT",
",",
"GT",
":",
"return",
"&",
"evaluationNode",
"{",
"op",
":",
"op",
",",
"lB",
":",
"lB",
",",
"rB",
":",
"rB",
",",
"}",
",",
"nil",
"\n",
"default",
":",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
]
| // NewEvaluationExpression creates a new evaluator for two bindings in a row. | [
"NewEvaluationExpression",
"creates",
"a",
"new",
"evaluator",
"for",
"two",
"bindings",
"in",
"a",
"row",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/expression.go#L134-L149 |
12,446 | google/badwolf | bql/semantic/expression.go | NewBinaryBooleanExpression | func NewBinaryBooleanExpression(op OP, lE, rE Evaluator) (Evaluator, error) {
switch op {
case AND, OR:
return &booleanNode{
op: op,
lS: true,
lE: lE,
rS: true,
rE: rE,
}, nil
default:
return nil, errors.New("binary boolean expressions require the operation to be one for the follwing 'and', 'or'")
}
} | go | func NewBinaryBooleanExpression(op OP, lE, rE Evaluator) (Evaluator, error) {
switch op {
case AND, OR:
return &booleanNode{
op: op,
lS: true,
lE: lE,
rS: true,
rE: rE,
}, nil
default:
return nil, errors.New("binary boolean expressions require the operation to be one for the follwing 'and', 'or'")
}
} | [
"func",
"NewBinaryBooleanExpression",
"(",
"op",
"OP",
",",
"lE",
",",
"rE",
"Evaluator",
")",
"(",
"Evaluator",
",",
"error",
")",
"{",
"switch",
"op",
"{",
"case",
"AND",
",",
"OR",
":",
"return",
"&",
"booleanNode",
"{",
"op",
":",
"op",
",",
"lS",
":",
"true",
",",
"lE",
":",
"lE",
",",
"rS",
":",
"true",
",",
"rE",
":",
"rE",
",",
"}",
",",
"nil",
"\n",
"default",
":",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
]
| // NewBinaryBooleanExpression creates a new binary boolean evaluator. | [
"NewBinaryBooleanExpression",
"creates",
"a",
"new",
"binary",
"boolean",
"evaluator",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/expression.go#L212-L225 |
12,447 | google/badwolf | bql/semantic/expression.go | NewUnaryBooleanExpression | func NewUnaryBooleanExpression(op OP, lE Evaluator) (Evaluator, error) {
switch op {
case NOT:
return &booleanNode{
op: op,
lS: true,
lE: lE,
rS: false,
}, nil
default:
return nil, errors.New("unary boolean expressions require the operation to be one for the follwing 'not'")
}
} | go | func NewUnaryBooleanExpression(op OP, lE Evaluator) (Evaluator, error) {
switch op {
case NOT:
return &booleanNode{
op: op,
lS: true,
lE: lE,
rS: false,
}, nil
default:
return nil, errors.New("unary boolean expressions require the operation to be one for the follwing 'not'")
}
} | [
"func",
"NewUnaryBooleanExpression",
"(",
"op",
"OP",
",",
"lE",
"Evaluator",
")",
"(",
"Evaluator",
",",
"error",
")",
"{",
"switch",
"op",
"{",
"case",
"NOT",
":",
"return",
"&",
"booleanNode",
"{",
"op",
":",
"op",
",",
"lS",
":",
"true",
",",
"lE",
":",
"lE",
",",
"rS",
":",
"false",
",",
"}",
",",
"nil",
"\n",
"default",
":",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
]
| // NewUnaryBooleanExpression creates a new unary boolean evaluator. | [
"NewUnaryBooleanExpression",
"creates",
"a",
"new",
"unary",
"boolean",
"evaluator",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/expression.go#L228-L240 |
12,448 | google/badwolf | bql/semantic/expression.go | NewEvaluator | func NewEvaluator(ce []ConsumedElement) (Evaluator, error) {
e, tailCEs, err := internalNewEvaluator(ce)
if err != nil {
return nil, err
}
if len(tailCEs) > 1 || (len(tailCEs) == 1 && tailCEs[0].Token().Type != lexer.ItemRPar) {
return nil, fmt.Errorf("failed to consume all token; left over %v", tailCEs)
}
return e, nil
} | go | func NewEvaluator(ce []ConsumedElement) (Evaluator, error) {
e, tailCEs, err := internalNewEvaluator(ce)
if err != nil {
return nil, err
}
if len(tailCEs) > 1 || (len(tailCEs) == 1 && tailCEs[0].Token().Type != lexer.ItemRPar) {
return nil, fmt.Errorf("failed to consume all token; left over %v", tailCEs)
}
return e, nil
} | [
"func",
"NewEvaluator",
"(",
"ce",
"[",
"]",
"ConsumedElement",
")",
"(",
"Evaluator",
",",
"error",
")",
"{",
"e",
",",
"tailCEs",
",",
"err",
":=",
"internalNewEvaluator",
"(",
"ce",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"tailCEs",
")",
">",
"1",
"||",
"(",
"len",
"(",
"tailCEs",
")",
"==",
"1",
"&&",
"tailCEs",
"[",
"0",
"]",
".",
"Token",
"(",
")",
".",
"Type",
"!=",
"lexer",
".",
"ItemRPar",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tailCEs",
")",
"\n",
"}",
"\n",
"return",
"e",
",",
"nil",
"\n",
"}"
]
| // NewEvaluator construct an evaluator given a sequence of tokens. It will
// return a descriptive error if it could build it properly. | [
"NewEvaluator",
"construct",
"an",
"evaluator",
"given",
"a",
"sequence",
"of",
"tokens",
".",
"It",
"will",
"return",
"a",
"descriptive",
"error",
"if",
"it",
"could",
"build",
"it",
"properly",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/expression.go#L244-L253 |
12,449 | google/badwolf | triple/literal/literal.go | String | func (t Type) String() string {
switch t {
case Bool:
return "bool"
case Int64:
return "int64"
case Float64:
return "float64"
case Text:
return "text"
case Blob:
return "blob"
default:
return "UNKNOWN"
}
} | go | func (t Type) String() string {
switch t {
case Bool:
return "bool"
case Int64:
return "int64"
case Float64:
return "float64"
case Text:
return "text"
case Blob:
return "blob"
default:
return "UNKNOWN"
}
} | [
"func",
"(",
"t",
"Type",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"t",
"{",
"case",
"Bool",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Int64",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Float64",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Text",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Blob",
":",
"return",
"\"",
"\"",
"\n",
"default",
":",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"}"
]
| // Strings returns the pretty printing version of the type | [
"Strings",
"returns",
"the",
"pretty",
"printing",
"version",
"of",
"the",
"type"
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/literal/literal.go#L46-L61 |
12,450 | google/badwolf | triple/literal/literal.go | ToComparableString | func (l *Literal) ToComparableString() string {
s := ""
switch l.t {
case Int64:
s = fmt.Sprintf("\"%032d\"^^type:%v", l.Interface(), l.Type())
case Float64:
s = fmt.Sprintf("\"%032f\"^^type:%v", l.Interface(), l.Type())
default:
s = l.String()
}
return s
} | go | func (l *Literal) ToComparableString() string {
s := ""
switch l.t {
case Int64:
s = fmt.Sprintf("\"%032d\"^^type:%v", l.Interface(), l.Type())
case Float64:
s = fmt.Sprintf("\"%032f\"^^type:%v", l.Interface(), l.Type())
default:
s = l.String()
}
return s
} | [
"func",
"(",
"l",
"*",
"Literal",
")",
"ToComparableString",
"(",
")",
"string",
"{",
"s",
":=",
"\"",
"\"",
"\n",
"switch",
"l",
".",
"t",
"{",
"case",
"Int64",
":",
"s",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"l",
".",
"Interface",
"(",
")",
",",
"l",
".",
"Type",
"(",
")",
")",
"\n",
"case",
"Float64",
":",
"s",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"l",
".",
"Interface",
"(",
")",
",",
"l",
".",
"Type",
"(",
")",
")",
"\n",
"default",
":",
"s",
"=",
"l",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
]
| // ToComparableString returns a string that can be directly compared. | [
"ToComparableString",
"returns",
"a",
"string",
"that",
"can",
"be",
"directly",
"compared",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/literal/literal.go#L80-L91 |
12,451 | google/badwolf | triple/literal/literal.go | Bool | func (l *Literal) Bool() (bool, error) {
if l.t != Bool {
return false, fmt.Errorf("literal.Bool: literal is of type %v; cannot be converted to a bool", l.t)
}
return l.v.(bool), nil
} | go | func (l *Literal) Bool() (bool, error) {
if l.t != Bool {
return false, fmt.Errorf("literal.Bool: literal is of type %v; cannot be converted to a bool", l.t)
}
return l.v.(bool), nil
} | [
"func",
"(",
"l",
"*",
"Literal",
")",
"Bool",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"l",
".",
"t",
"!=",
"Bool",
"{",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"l",
".",
"t",
")",
"\n",
"}",
"\n",
"return",
"l",
".",
"v",
".",
"(",
"bool",
")",
",",
"nil",
"\n",
"}"
]
| // Bool returns the value of a literal as a boolean. | [
"Bool",
"returns",
"the",
"value",
"of",
"a",
"literal",
"as",
"a",
"boolean",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/literal/literal.go#L94-L99 |
12,452 | google/badwolf | triple/literal/literal.go | Int64 | func (l *Literal) Int64() (int64, error) {
if l.t != Int64 {
return 0, fmt.Errorf("literal.Int64: literal is of type %v; cannot be converted to a int64", l.t)
}
return l.v.(int64), nil
} | go | func (l *Literal) Int64() (int64, error) {
if l.t != Int64 {
return 0, fmt.Errorf("literal.Int64: literal is of type %v; cannot be converted to a int64", l.t)
}
return l.v.(int64), nil
} | [
"func",
"(",
"l",
"*",
"Literal",
")",
"Int64",
"(",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"l",
".",
"t",
"!=",
"Int64",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"l",
".",
"t",
")",
"\n",
"}",
"\n",
"return",
"l",
".",
"v",
".",
"(",
"int64",
")",
",",
"nil",
"\n",
"}"
]
| // Int64 returns the value of a literal as an int64. | [
"Int64",
"returns",
"the",
"value",
"of",
"a",
"literal",
"as",
"an",
"int64",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/literal/literal.go#L102-L107 |
12,453 | google/badwolf | triple/literal/literal.go | Float64 | func (l *Literal) Float64() (float64, error) {
if l.t != Float64 {
return 0, fmt.Errorf("literal.Float64: literal is of type %v; cannot be converted to a float64", l.t)
}
return l.v.(float64), nil
} | go | func (l *Literal) Float64() (float64, error) {
if l.t != Float64 {
return 0, fmt.Errorf("literal.Float64: literal is of type %v; cannot be converted to a float64", l.t)
}
return l.v.(float64), nil
} | [
"func",
"(",
"l",
"*",
"Literal",
")",
"Float64",
"(",
")",
"(",
"float64",
",",
"error",
")",
"{",
"if",
"l",
".",
"t",
"!=",
"Float64",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"l",
".",
"t",
")",
"\n",
"}",
"\n",
"return",
"l",
".",
"v",
".",
"(",
"float64",
")",
",",
"nil",
"\n",
"}"
]
| // Float64 returns the value of a literal as a float64. | [
"Float64",
"returns",
"the",
"value",
"of",
"a",
"literal",
"as",
"a",
"float64",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/literal/literal.go#L110-L115 |
12,454 | google/badwolf | triple/literal/literal.go | Text | func (l *Literal) Text() (string, error) {
if l.t != Text {
return "", fmt.Errorf("literal.Text: literal is of type %v; cannot be converted to a string", l.t)
}
return l.v.(string), nil
} | go | func (l *Literal) Text() (string, error) {
if l.t != Text {
return "", fmt.Errorf("literal.Text: literal is of type %v; cannot be converted to a string", l.t)
}
return l.v.(string), nil
} | [
"func",
"(",
"l",
"*",
"Literal",
")",
"Text",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"l",
".",
"t",
"!=",
"Text",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"l",
".",
"t",
")",
"\n",
"}",
"\n",
"return",
"l",
".",
"v",
".",
"(",
"string",
")",
",",
"nil",
"\n",
"}"
]
| // Text returns the value of a literal as a string. | [
"Text",
"returns",
"the",
"value",
"of",
"a",
"literal",
"as",
"a",
"string",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/literal/literal.go#L118-L123 |
12,455 | google/badwolf | triple/literal/literal.go | Build | func (b *unboundBuilder) Build(t Type, v interface{}) (*Literal, error) {
switch v.(type) {
case bool:
if t != Bool {
return nil, fmt.Errorf("literal.Build: type %v does not match type of value %v", t, v)
}
case int64:
if t != Int64 {
return nil, fmt.Errorf("literal.Build: type %v does not match type of value %v", t, v)
}
case float64:
if t != Float64 {
return nil, fmt.Errorf("literal.Build: type %v does not match type of value %v", t, v)
}
case string:
if t != Text {
return nil, fmt.Errorf("literal.Build: type %v does not match type of value %v", t, v)
}
case []byte:
if t != Blob {
return nil, fmt.Errorf("literal.Build: type %v does not match type of value %v", t, v)
}
default:
return nil, fmt.Errorf("literal.Build: type %T is not supported when building literals", v)
}
return &Literal{
t: t,
v: v,
}, nil
} | go | func (b *unboundBuilder) Build(t Type, v interface{}) (*Literal, error) {
switch v.(type) {
case bool:
if t != Bool {
return nil, fmt.Errorf("literal.Build: type %v does not match type of value %v", t, v)
}
case int64:
if t != Int64 {
return nil, fmt.Errorf("literal.Build: type %v does not match type of value %v", t, v)
}
case float64:
if t != Float64 {
return nil, fmt.Errorf("literal.Build: type %v does not match type of value %v", t, v)
}
case string:
if t != Text {
return nil, fmt.Errorf("literal.Build: type %v does not match type of value %v", t, v)
}
case []byte:
if t != Blob {
return nil, fmt.Errorf("literal.Build: type %v does not match type of value %v", t, v)
}
default:
return nil, fmt.Errorf("literal.Build: type %T is not supported when building literals", v)
}
return &Literal{
t: t,
v: v,
}, nil
} | [
"func",
"(",
"b",
"*",
"unboundBuilder",
")",
"Build",
"(",
"t",
"Type",
",",
"v",
"interface",
"{",
"}",
")",
"(",
"*",
"Literal",
",",
"error",
")",
"{",
"switch",
"v",
".",
"(",
"type",
")",
"{",
"case",
"bool",
":",
"if",
"t",
"!=",
"Bool",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
",",
"v",
")",
"\n",
"}",
"\n",
"case",
"int64",
":",
"if",
"t",
"!=",
"Int64",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
",",
"v",
")",
"\n",
"}",
"\n",
"case",
"float64",
":",
"if",
"t",
"!=",
"Float64",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
",",
"v",
")",
"\n",
"}",
"\n",
"case",
"string",
":",
"if",
"t",
"!=",
"Text",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
",",
"v",
")",
"\n",
"}",
"\n",
"case",
"[",
"]",
"byte",
":",
"if",
"t",
"!=",
"Blob",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
",",
"v",
")",
"\n",
"}",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"&",
"Literal",
"{",
"t",
":",
"t",
",",
"v",
":",
"v",
",",
"}",
",",
"nil",
"\n",
"}"
]
| // Build creates a new unbound literal from a type and a value. | [
"Build",
"creates",
"a",
"new",
"unbound",
"literal",
"from",
"a",
"type",
"and",
"a",
"value",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/literal/literal.go#L157-L186 |
12,456 | google/badwolf | triple/literal/literal.go | Parse | func (b *unboundBuilder) Parse(s string) (*Literal, error) {
raw := strings.TrimSpace(s)
if len(raw) == 0 {
return nil, fmt.Errorf("literal.Parse: cannot parse and empty string into a literal; provided string %q", s)
}
if raw[0] != '"' {
return nil, fmt.Errorf("literal.Parse: text encoded literals must start with \", missing in %s", raw)
}
idx := strings.Index(raw, "\"^^type:")
if idx < 0 {
return nil, fmt.Errorf("literal.Parse: text encoded literals must have a type; missing in %s", raw)
}
v := raw[1:idx]
t := raw[idx+len("\"^^type:"):]
switch t {
case "bool":
pv, err := strconv.ParseBool(v)
if err != nil {
return nil, fmt.Errorf("literal.Parse: could not convert value %q to bool", v)
}
return b.Build(Bool, pv)
case "int64":
pv, err := strconv.ParseInt(v, 10, 64)
if err != nil {
return nil, fmt.Errorf("literal.Parse: could not convert value %q to int64", v)
}
return b.Build(Int64, int64(pv))
case "float64":
pv, err := strconv.ParseFloat(v, 64)
if err != nil {
return nil, fmt.Errorf("literal.Parse: could not convert value %q to float64", v)
}
return b.Build(Float64, float64(pv))
case "text":
return b.Build(Text, v)
case "blob":
values := v[1 : len(v)-1]
if values == "" {
return b.Build(Blob, []byte{})
}
bs := []byte{}
for _, s := range strings.Split(values, " ") {
b, err := strconv.ParseUint(s, 10, 8)
if err != nil {
return nil, fmt.Errorf("literal.Parse: failed to decode byte array on %q with error %v", s, err)
}
bs = append(bs, byte(b))
}
return b.Build(Blob, bs)
default:
return nil, nil
}
} | go | func (b *unboundBuilder) Parse(s string) (*Literal, error) {
raw := strings.TrimSpace(s)
if len(raw) == 0 {
return nil, fmt.Errorf("literal.Parse: cannot parse and empty string into a literal; provided string %q", s)
}
if raw[0] != '"' {
return nil, fmt.Errorf("literal.Parse: text encoded literals must start with \", missing in %s", raw)
}
idx := strings.Index(raw, "\"^^type:")
if idx < 0 {
return nil, fmt.Errorf("literal.Parse: text encoded literals must have a type; missing in %s", raw)
}
v := raw[1:idx]
t := raw[idx+len("\"^^type:"):]
switch t {
case "bool":
pv, err := strconv.ParseBool(v)
if err != nil {
return nil, fmt.Errorf("literal.Parse: could not convert value %q to bool", v)
}
return b.Build(Bool, pv)
case "int64":
pv, err := strconv.ParseInt(v, 10, 64)
if err != nil {
return nil, fmt.Errorf("literal.Parse: could not convert value %q to int64", v)
}
return b.Build(Int64, int64(pv))
case "float64":
pv, err := strconv.ParseFloat(v, 64)
if err != nil {
return nil, fmt.Errorf("literal.Parse: could not convert value %q to float64", v)
}
return b.Build(Float64, float64(pv))
case "text":
return b.Build(Text, v)
case "blob":
values := v[1 : len(v)-1]
if values == "" {
return b.Build(Blob, []byte{})
}
bs := []byte{}
for _, s := range strings.Split(values, " ") {
b, err := strconv.ParseUint(s, 10, 8)
if err != nil {
return nil, fmt.Errorf("literal.Parse: failed to decode byte array on %q with error %v", s, err)
}
bs = append(bs, byte(b))
}
return b.Build(Blob, bs)
default:
return nil, nil
}
} | [
"func",
"(",
"b",
"*",
"unboundBuilder",
")",
"Parse",
"(",
"s",
"string",
")",
"(",
"*",
"Literal",
",",
"error",
")",
"{",
"raw",
":=",
"strings",
".",
"TrimSpace",
"(",
"s",
")",
"\n",
"if",
"len",
"(",
"raw",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
")",
"\n",
"}",
"\n",
"if",
"raw",
"[",
"0",
"]",
"!=",
"'\"'",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\\"",
"\"",
",",
"raw",
")",
"\n",
"}",
"\n",
"idx",
":=",
"strings",
".",
"Index",
"(",
"raw",
",",
"\"",
"\\\"",
"\"",
")",
"\n",
"if",
"idx",
"<",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}",
"\n",
"v",
":=",
"raw",
"[",
"1",
":",
"idx",
"]",
"\n",
"t",
":=",
"raw",
"[",
"idx",
"+",
"len",
"(",
"\"",
"\\\"",
"\"",
")",
":",
"]",
"\n",
"switch",
"t",
"{",
"case",
"\"",
"\"",
":",
"pv",
",",
"err",
":=",
"strconv",
".",
"ParseBool",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"b",
".",
"Build",
"(",
"Bool",
",",
"pv",
")",
"\n",
"case",
"\"",
"\"",
":",
"pv",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"v",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"b",
".",
"Build",
"(",
"Int64",
",",
"int64",
"(",
"pv",
")",
")",
"\n",
"case",
"\"",
"\"",
":",
"pv",
",",
"err",
":=",
"strconv",
".",
"ParseFloat",
"(",
"v",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"b",
".",
"Build",
"(",
"Float64",
",",
"float64",
"(",
"pv",
")",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"b",
".",
"Build",
"(",
"Text",
",",
"v",
")",
"\n",
"case",
"\"",
"\"",
":",
"values",
":=",
"v",
"[",
"1",
":",
"len",
"(",
"v",
")",
"-",
"1",
"]",
"\n",
"if",
"values",
"==",
"\"",
"\"",
"{",
"return",
"b",
".",
"Build",
"(",
"Blob",
",",
"[",
"]",
"byte",
"{",
"}",
")",
"\n",
"}",
"\n",
"bs",
":=",
"[",
"]",
"byte",
"{",
"}",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"strings",
".",
"Split",
"(",
"values",
",",
"\"",
"\"",
")",
"{",
"b",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"s",
",",
"10",
",",
"8",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
",",
"err",
")",
"\n",
"}",
"\n",
"bs",
"=",
"append",
"(",
"bs",
",",
"byte",
"(",
"b",
")",
")",
"\n",
"}",
"\n",
"return",
"b",
".",
"Build",
"(",
"Blob",
",",
"bs",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"}"
]
| // Parse creates a string out of a prettified representation. | [
"Parse",
"creates",
"a",
"string",
"out",
"of",
"a",
"prettified",
"representation",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/literal/literal.go#L189-L241 |
12,457 | google/badwolf | triple/literal/literal.go | Build | func (b *boundedBuilder) Build(t Type, v interface{}) (*Literal, error) {
switch v.(type) {
case string:
if l := len(v.(string)); l > b.max {
return nil, fmt.Errorf("literal.Build: cannot create literal due to size of %v (%d>%d)", v, l, b.max)
}
case []byte:
if l := len(v.([]byte)); l > b.max {
return nil, fmt.Errorf("literal.Build: cannot create literal due to size of %v (%d>%d)", v, l, b.max)
}
}
return defaultBuilder.Build(t, v)
} | go | func (b *boundedBuilder) Build(t Type, v interface{}) (*Literal, error) {
switch v.(type) {
case string:
if l := len(v.(string)); l > b.max {
return nil, fmt.Errorf("literal.Build: cannot create literal due to size of %v (%d>%d)", v, l, b.max)
}
case []byte:
if l := len(v.([]byte)); l > b.max {
return nil, fmt.Errorf("literal.Build: cannot create literal due to size of %v (%d>%d)", v, l, b.max)
}
}
return defaultBuilder.Build(t, v)
} | [
"func",
"(",
"b",
"*",
"boundedBuilder",
")",
"Build",
"(",
"t",
"Type",
",",
"v",
"interface",
"{",
"}",
")",
"(",
"*",
"Literal",
",",
"error",
")",
"{",
"switch",
"v",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"if",
"l",
":=",
"len",
"(",
"v",
".",
"(",
"string",
")",
")",
";",
"l",
">",
"b",
".",
"max",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
",",
"l",
",",
"b",
".",
"max",
")",
"\n",
"}",
"\n",
"case",
"[",
"]",
"byte",
":",
"if",
"l",
":=",
"len",
"(",
"v",
".",
"(",
"[",
"]",
"byte",
")",
")",
";",
"l",
">",
"b",
".",
"max",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
",",
"l",
",",
"b",
".",
"max",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"defaultBuilder",
".",
"Build",
"(",
"t",
",",
"v",
")",
"\n",
"}"
]
| // Build creates a new literal of bounded size. | [
"Build",
"creates",
"a",
"new",
"literal",
"of",
"bounded",
"size",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/literal/literal.go#L255-L267 |
12,458 | google/badwolf | triple/literal/literal.go | Parse | func (b *boundedBuilder) Parse(s string) (*Literal, error) {
l, err := defaultBuilder.Parse(s)
if err != nil {
return nil, err
}
t := l.Type()
switch t {
case Text:
if text, err := l.Text(); err != nil || len(text) > b.max {
return nil, fmt.Errorf("literal.Parse: cannot create literal due to size of %v (%d>%d)", t, len(text), b.max)
}
case Blob:
if blob, err := l.Blob(); err != nil || len(blob) > b.max {
return nil, fmt.Errorf("literal.Parse: cannot create literal due to size of %v (%d>%d)", t, len(blob), b.max)
}
}
return l, nil
} | go | func (b *boundedBuilder) Parse(s string) (*Literal, error) {
l, err := defaultBuilder.Parse(s)
if err != nil {
return nil, err
}
t := l.Type()
switch t {
case Text:
if text, err := l.Text(); err != nil || len(text) > b.max {
return nil, fmt.Errorf("literal.Parse: cannot create literal due to size of %v (%d>%d)", t, len(text), b.max)
}
case Blob:
if blob, err := l.Blob(); err != nil || len(blob) > b.max {
return nil, fmt.Errorf("literal.Parse: cannot create literal due to size of %v (%d>%d)", t, len(blob), b.max)
}
}
return l, nil
} | [
"func",
"(",
"b",
"*",
"boundedBuilder",
")",
"Parse",
"(",
"s",
"string",
")",
"(",
"*",
"Literal",
",",
"error",
")",
"{",
"l",
",",
"err",
":=",
"defaultBuilder",
".",
"Parse",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"t",
":=",
"l",
".",
"Type",
"(",
")",
"\n",
"switch",
"t",
"{",
"case",
"Text",
":",
"if",
"text",
",",
"err",
":=",
"l",
".",
"Text",
"(",
")",
";",
"err",
"!=",
"nil",
"||",
"len",
"(",
"text",
")",
">",
"b",
".",
"max",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
",",
"len",
"(",
"text",
")",
",",
"b",
".",
"max",
")",
"\n",
"}",
"\n",
"case",
"Blob",
":",
"if",
"blob",
",",
"err",
":=",
"l",
".",
"Blob",
"(",
")",
";",
"err",
"!=",
"nil",
"||",
"len",
"(",
"blob",
")",
">",
"b",
".",
"max",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
",",
"len",
"(",
"blob",
")",
",",
"b",
".",
"max",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"l",
",",
"nil",
"\n",
"}"
]
| // Parse creates a string out of a prettyfied representation. | [
"Parse",
"creates",
"a",
"string",
"out",
"of",
"a",
"prettyfied",
"representation",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/literal/literal.go#L270-L287 |
12,459 | google/badwolf | triple/literal/literal.go | UUID | func (l *Literal) UUID() uuid.UUID {
var buffer bytes.Buffer
switch v := l.v.(type) {
case bool:
if v {
buffer.WriteString("true")
} else {
buffer.WriteString("false")
}
case int64:
b := make([]byte, 8)
binary.PutVarint(b, v)
buffer.Write(b)
case float64:
bs := math.Float64bits(v)
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, bs)
buffer.Write(b)
case string:
buffer.Write([]byte(v))
case []byte:
buffer.Write(v)
}
return uuid.NewSHA1(uuid.NIL, buffer.Bytes())
} | go | func (l *Literal) UUID() uuid.UUID {
var buffer bytes.Buffer
switch v := l.v.(type) {
case bool:
if v {
buffer.WriteString("true")
} else {
buffer.WriteString("false")
}
case int64:
b := make([]byte, 8)
binary.PutVarint(b, v)
buffer.Write(b)
case float64:
bs := math.Float64bits(v)
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, bs)
buffer.Write(b)
case string:
buffer.Write([]byte(v))
case []byte:
buffer.Write(v)
}
return uuid.NewSHA1(uuid.NIL, buffer.Bytes())
} | [
"func",
"(",
"l",
"*",
"Literal",
")",
"UUID",
"(",
")",
"uuid",
".",
"UUID",
"{",
"var",
"buffer",
"bytes",
".",
"Buffer",
"\n\n",
"switch",
"v",
":=",
"l",
".",
"v",
".",
"(",
"type",
")",
"{",
"case",
"bool",
":",
"if",
"v",
"{",
"buffer",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"buffer",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"case",
"int64",
":",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"8",
")",
"\n",
"binary",
".",
"PutVarint",
"(",
"b",
",",
"v",
")",
"\n",
"buffer",
".",
"Write",
"(",
"b",
")",
"\n",
"case",
"float64",
":",
"bs",
":=",
"math",
".",
"Float64bits",
"(",
"v",
")",
"\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"8",
")",
"\n",
"binary",
".",
"LittleEndian",
".",
"PutUint64",
"(",
"b",
",",
"bs",
")",
"\n",
"buffer",
".",
"Write",
"(",
"b",
")",
"\n",
"case",
"string",
":",
"buffer",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"v",
")",
")",
"\n",
"case",
"[",
"]",
"byte",
":",
"buffer",
".",
"Write",
"(",
"v",
")",
"\n",
"}",
"\n\n",
"return",
"uuid",
".",
"NewSHA1",
"(",
"uuid",
".",
"NIL",
",",
"buffer",
".",
"Bytes",
"(",
")",
")",
"\n",
"}"
]
| // UUID returns a global unique identifier for the given literal. It is
// implemented as the SHA1 UUID of the literal value. | [
"UUID",
"returns",
"a",
"global",
"unique",
"identifier",
"for",
"the",
"given",
"literal",
".",
"It",
"is",
"implemented",
"as",
"the",
"SHA1",
"UUID",
"of",
"the",
"literal",
"value",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/literal/literal.go#L298-L324 |
12,460 | google/badwolf | triple/predicate/predicate.go | String | func (p *Predicate) String() string {
if p.anchor == nil {
return fmt.Sprintf("%q@[]", p.id)
}
return fmt.Sprintf("%q@[%s]", p.id, p.anchor.Format(time.RFC3339Nano))
} | go | func (p *Predicate) String() string {
if p.anchor == nil {
return fmt.Sprintf("%q@[]", p.id)
}
return fmt.Sprintf("%q@[%s]", p.id, p.anchor.Format(time.RFC3339Nano))
} | [
"func",
"(",
"p",
"*",
"Predicate",
")",
"String",
"(",
")",
"string",
"{",
"if",
"p",
".",
"anchor",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"id",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"id",
",",
"p",
".",
"anchor",
".",
"Format",
"(",
"time",
".",
"RFC3339Nano",
")",
")",
"\n",
"}"
]
| // String returns the pretty printed version of the predicate. | [
"String",
"returns",
"the",
"pretty",
"printed",
"version",
"of",
"the",
"predicate",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/predicate/predicate.go#L67-L72 |
12,461 | google/badwolf | triple/predicate/predicate.go | Parse | func Parse(s string) (*Predicate, error) {
raw := strings.TrimSpace(s)
if raw == "" {
return nil, fmt.Errorf("predicate.Parse cannot create predicate from empty string %q", s)
}
if raw[0] != '"' {
return nil, fmt.Errorf("predicate.Parse failed to parse since string does not start with \" in %s", s)
}
idx := strings.Index(raw, "\"@[")
if idx < 0 {
return nil, fmt.Errorf("predicate.Parse could not find anchor definition in %s", raw)
}
id, ta := raw[0:idx+1], raw[idx+3:len(raw)-1]
id, err := strconv.Unquote(id)
if err != nil {
return nil, fmt.Errorf("predicate.Parse can't unquote id in %s: %v", raw, err)
}
// TODO: if id has \" inside, it should be unquoted.
if ta == "" {
return &Predicate{
id: ID(id),
}, nil
}
if ta[0] == '"' {
ta = ta[1:]
}
if ta[len(ta)-1] == '"' {
ta = ta[:len(ta)-1]
}
pta, err := time.Parse(time.RFC3339Nano, ta)
if err != nil {
return nil, fmt.Errorf("predicate.Parse failed to parse time anchor %s in %s with error %v", ta, raw, err)
}
return &Predicate{
id: ID(id),
anchor: &pta,
}, nil
} | go | func Parse(s string) (*Predicate, error) {
raw := strings.TrimSpace(s)
if raw == "" {
return nil, fmt.Errorf("predicate.Parse cannot create predicate from empty string %q", s)
}
if raw[0] != '"' {
return nil, fmt.Errorf("predicate.Parse failed to parse since string does not start with \" in %s", s)
}
idx := strings.Index(raw, "\"@[")
if idx < 0 {
return nil, fmt.Errorf("predicate.Parse could not find anchor definition in %s", raw)
}
id, ta := raw[0:idx+1], raw[idx+3:len(raw)-1]
id, err := strconv.Unquote(id)
if err != nil {
return nil, fmt.Errorf("predicate.Parse can't unquote id in %s: %v", raw, err)
}
// TODO: if id has \" inside, it should be unquoted.
if ta == "" {
return &Predicate{
id: ID(id),
}, nil
}
if ta[0] == '"' {
ta = ta[1:]
}
if ta[len(ta)-1] == '"' {
ta = ta[:len(ta)-1]
}
pta, err := time.Parse(time.RFC3339Nano, ta)
if err != nil {
return nil, fmt.Errorf("predicate.Parse failed to parse time anchor %s in %s with error %v", ta, raw, err)
}
return &Predicate{
id: ID(id),
anchor: &pta,
}, nil
} | [
"func",
"Parse",
"(",
"s",
"string",
")",
"(",
"*",
"Predicate",
",",
"error",
")",
"{",
"raw",
":=",
"strings",
".",
"TrimSpace",
"(",
"s",
")",
"\n",
"if",
"raw",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
")",
"\n",
"}",
"\n",
"if",
"raw",
"[",
"0",
"]",
"!=",
"'\"'",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\\"",
"\"",
",",
"s",
")",
"\n",
"}",
"\n",
"idx",
":=",
"strings",
".",
"Index",
"(",
"raw",
",",
"\"",
"\\\"",
"\"",
")",
"\n",
"if",
"idx",
"<",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}",
"\n",
"id",
",",
"ta",
":=",
"raw",
"[",
"0",
":",
"idx",
"+",
"1",
"]",
",",
"raw",
"[",
"idx",
"+",
"3",
":",
"len",
"(",
"raw",
")",
"-",
"1",
"]",
"\n",
"id",
",",
"err",
":=",
"strconv",
".",
"Unquote",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
",",
"err",
")",
"\n",
"}",
"\n",
"// TODO: if id has \\\" inside, it should be unquoted.",
"if",
"ta",
"==",
"\"",
"\"",
"{",
"return",
"&",
"Predicate",
"{",
"id",
":",
"ID",
"(",
"id",
")",
",",
"}",
",",
"nil",
"\n",
"}",
"\n",
"if",
"ta",
"[",
"0",
"]",
"==",
"'\"'",
"{",
"ta",
"=",
"ta",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"if",
"ta",
"[",
"len",
"(",
"ta",
")",
"-",
"1",
"]",
"==",
"'\"'",
"{",
"ta",
"=",
"ta",
"[",
":",
"len",
"(",
"ta",
")",
"-",
"1",
"]",
"\n",
"}",
"\n",
"pta",
",",
"err",
":=",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC3339Nano",
",",
"ta",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ta",
",",
"raw",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"Predicate",
"{",
"id",
":",
"ID",
"(",
"id",
")",
",",
"anchor",
":",
"&",
"pta",
",",
"}",
",",
"nil",
"\n",
"}"
]
| // Parse converts a pretty printed predicate into a predicate. | [
"Parse",
"converts",
"a",
"pretty",
"printed",
"predicate",
"into",
"a",
"predicate",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/predicate/predicate.go#L75-L112 |
12,462 | google/badwolf | triple/predicate/predicate.go | TimeAnchor | func (p *Predicate) TimeAnchor() (*time.Time, error) {
if p.anchor == nil {
return nil, fmt.Errorf("predicate.TimeAnchor cannot return anchor for immutable predicate %v", p)
}
return p.anchor, nil
} | go | func (p *Predicate) TimeAnchor() (*time.Time, error) {
if p.anchor == nil {
return nil, fmt.Errorf("predicate.TimeAnchor cannot return anchor for immutable predicate %v", p)
}
return p.anchor, nil
} | [
"func",
"(",
"p",
"*",
"Predicate",
")",
"TimeAnchor",
"(",
")",
"(",
"*",
"time",
".",
"Time",
",",
"error",
")",
"{",
"if",
"p",
".",
"anchor",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"p",
")",
"\n",
"}",
"\n",
"return",
"p",
".",
"anchor",
",",
"nil",
"\n",
"}"
]
| // TimeAnchor attempts to return the time anchor of a predicate if its type is
// temporal. | [
"TimeAnchor",
"attempts",
"to",
"return",
"the",
"time",
"anchor",
"of",
"a",
"predicate",
"if",
"its",
"type",
"is",
"temporal",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/predicate/predicate.go#L129-L134 |
12,463 | google/badwolf | triple/predicate/predicate.go | NewImmutable | func NewImmutable(id string) (*Predicate, error) {
if id == "" {
return nil, fmt.Errorf("predicate.NewImmutable(%q) cannot create a immutable predicate with empty ID", id)
}
return &Predicate{
id: ID(id),
}, nil
} | go | func NewImmutable(id string) (*Predicate, error) {
if id == "" {
return nil, fmt.Errorf("predicate.NewImmutable(%q) cannot create a immutable predicate with empty ID", id)
}
return &Predicate{
id: ID(id),
}, nil
} | [
"func",
"NewImmutable",
"(",
"id",
"string",
")",
"(",
"*",
"Predicate",
",",
"error",
")",
"{",
"if",
"id",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n",
"return",
"&",
"Predicate",
"{",
"id",
":",
"ID",
"(",
"id",
")",
",",
"}",
",",
"nil",
"\n",
"}"
]
| // NewImmutable creates a new immutable predicate. | [
"NewImmutable",
"creates",
"a",
"new",
"immutable",
"predicate",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/predicate/predicate.go#L137-L144 |
12,464 | google/badwolf | triple/predicate/predicate.go | NewTemporal | func NewTemporal(id string, t time.Time) (*Predicate, error) {
if id == "" {
return nil, fmt.Errorf("predicate.NewTemporal(%q, %v) cannot create a temporal predicate with empty ID", id, t)
}
return &Predicate{
id: ID(id),
anchor: &t,
}, nil
} | go | func NewTemporal(id string, t time.Time) (*Predicate, error) {
if id == "" {
return nil, fmt.Errorf("predicate.NewTemporal(%q, %v) cannot create a temporal predicate with empty ID", id, t)
}
return &Predicate{
id: ID(id),
anchor: &t,
}, nil
} | [
"func",
"NewTemporal",
"(",
"id",
"string",
",",
"t",
"time",
".",
"Time",
")",
"(",
"*",
"Predicate",
",",
"error",
")",
"{",
"if",
"id",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"id",
",",
"t",
")",
"\n",
"}",
"\n",
"return",
"&",
"Predicate",
"{",
"id",
":",
"ID",
"(",
"id",
")",
",",
"anchor",
":",
"&",
"t",
",",
"}",
",",
"nil",
"\n",
"}"
]
| // NewTemporal creates a new temporal predicate. | [
"NewTemporal",
"creates",
"a",
"new",
"temporal",
"predicate",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/predicate/predicate.go#L147-L155 |
12,465 | google/badwolf | triple/predicate/predicate.go | UUID | func (p *Predicate) UUID() uuid.UUID {
var buffer bytes.Buffer
buffer.WriteString(string(p.id))
if p.anchor == nil {
buffer.WriteString("immutable")
} else {
b := make([]byte, 16)
binary.PutVarint(b, p.anchor.UnixNano())
buffer.Write(b)
}
return uuid.NewSHA1(uuid.NIL, buffer.Bytes())
} | go | func (p *Predicate) UUID() uuid.UUID {
var buffer bytes.Buffer
buffer.WriteString(string(p.id))
if p.anchor == nil {
buffer.WriteString("immutable")
} else {
b := make([]byte, 16)
binary.PutVarint(b, p.anchor.UnixNano())
buffer.Write(b)
}
return uuid.NewSHA1(uuid.NIL, buffer.Bytes())
} | [
"func",
"(",
"p",
"*",
"Predicate",
")",
"UUID",
"(",
")",
"uuid",
".",
"UUID",
"{",
"var",
"buffer",
"bytes",
".",
"Buffer",
"\n\n",
"buffer",
".",
"WriteString",
"(",
"string",
"(",
"p",
".",
"id",
")",
")",
"\n",
"if",
"p",
".",
"anchor",
"==",
"nil",
"{",
"buffer",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"16",
")",
"\n",
"binary",
".",
"PutVarint",
"(",
"b",
",",
"p",
".",
"anchor",
".",
"UnixNano",
"(",
")",
")",
"\n",
"buffer",
".",
"Write",
"(",
"b",
")",
"\n",
"}",
"\n\n",
"return",
"uuid",
".",
"NewSHA1",
"(",
"uuid",
".",
"NIL",
",",
"buffer",
".",
"Bytes",
"(",
")",
")",
"\n",
"}"
]
| // UUID returns a global unique identifier for the given predicate. It is
// implemented as the SHA1 UUID of the predicate values. | [
"UUID",
"returns",
"a",
"global",
"unique",
"identifier",
"for",
"the",
"given",
"predicate",
".",
"It",
"is",
"implemented",
"as",
"the",
"SHA1",
"UUID",
"of",
"the",
"predicate",
"values",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/predicate/predicate.go#L159-L172 |
12,466 | google/badwolf | triple/predicate/predicate.go | PartialUUID | func (p *Predicate) PartialUUID() uuid.UUID {
var buffer bytes.Buffer
buffer.WriteString(string(p.id))
return uuid.NewSHA1(uuid.NIL, buffer.Bytes())
} | go | func (p *Predicate) PartialUUID() uuid.UUID {
var buffer bytes.Buffer
buffer.WriteString(string(p.id))
return uuid.NewSHA1(uuid.NIL, buffer.Bytes())
} | [
"func",
"(",
"p",
"*",
"Predicate",
")",
"PartialUUID",
"(",
")",
"uuid",
".",
"UUID",
"{",
"var",
"buffer",
"bytes",
".",
"Buffer",
"\n",
"buffer",
".",
"WriteString",
"(",
"string",
"(",
"p",
".",
"id",
")",
")",
"\n",
"return",
"uuid",
".",
"NewSHA1",
"(",
"uuid",
".",
"NIL",
",",
"buffer",
".",
"Bytes",
"(",
")",
")",
"\n",
"}"
]
| // PartialUUID returns a global unique identifier for the given predicate but it
// only takes into account the predicate ID. Usually you do not want to use this
// partial UUID and likely you want to use the standard UUID. This partial UUID
// is only useful for driver implementers when they want to take advantage
// of range reads. | [
"PartialUUID",
"returns",
"a",
"global",
"unique",
"identifier",
"for",
"the",
"given",
"predicate",
"but",
"it",
"only",
"takes",
"into",
"account",
"the",
"predicate",
"ID",
".",
"Usually",
"you",
"do",
"not",
"want",
"to",
"use",
"this",
"partial",
"UUID",
"and",
"likely",
"you",
"want",
"to",
"use",
"the",
"standard",
"UUID",
".",
"This",
"partial",
"UUID",
"is",
"only",
"useful",
"for",
"driver",
"implementers",
"when",
"they",
"want",
"to",
"take",
"advantage",
"of",
"range",
"reads",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/predicate/predicate.go#L179-L183 |
12,467 | google/badwolf | tools/vcli/bw/command/command.go | UsageString | func (c *Command) UsageString() string {
return fmt.Sprintf("usage:\n\n\t$ badwolf %s\n\n%s\n", c.UsageLine, strings.TrimSpace(c.Long))
} | go | func (c *Command) UsageString() string {
return fmt.Sprintf("usage:\n\n\t$ badwolf %s\n\n%s\n", c.UsageLine, strings.TrimSpace(c.Long))
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"UsageString",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\\n",
"\\t",
"\\n",
"\\n",
"\\n",
"\"",
",",
"c",
".",
"UsageLine",
",",
"strings",
".",
"TrimSpace",
"(",
"c",
".",
"Long",
")",
")",
"\n",
"}"
]
| // UsageString returns the command usage string.. | [
"UsageString",
"returns",
"the",
"command",
"usage",
"string",
".."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/command/command.go#L55-L57 |
12,468 | google/badwolf | tools/benchmark/generator/tree/tree.go | New | func New(branch int) (generator.Generator, error) {
if branch < 1 {
return nil, fmt.Errorf("invalid branch factor %d", branch)
}
nt, err := node.NewType("/tn")
if err != nil {
return nil, err
}
p, err := predicate.NewImmutable("parent_of")
if err != nil {
return nil, err
}
return &treeGenerator{
branch: branch,
nodeType: nt,
predicate: p,
}, nil
} | go | func New(branch int) (generator.Generator, error) {
if branch < 1 {
return nil, fmt.Errorf("invalid branch factor %d", branch)
}
nt, err := node.NewType("/tn")
if err != nil {
return nil, err
}
p, err := predicate.NewImmutable("parent_of")
if err != nil {
return nil, err
}
return &treeGenerator{
branch: branch,
nodeType: nt,
predicate: p,
}, nil
} | [
"func",
"New",
"(",
"branch",
"int",
")",
"(",
"generator",
".",
"Generator",
",",
"error",
")",
"{",
"if",
"branch",
"<",
"1",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"branch",
")",
"\n",
"}",
"\n",
"nt",
",",
"err",
":=",
"node",
".",
"NewType",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"p",
",",
"err",
":=",
"predicate",
".",
"NewImmutable",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"treeGenerator",
"{",
"branch",
":",
"branch",
",",
"nodeType",
":",
"nt",
",",
"predicate",
":",
"p",
",",
"}",
",",
"nil",
"\n",
"}"
]
| // New creates a new tree generator. The triples are generated using breadth
// search first. All predicates are immutable and use the predicate
// `"parent_of"@[]`.` | [
"New",
"creates",
"a",
"new",
"tree",
"generator",
".",
"The",
"triples",
"are",
"generated",
"using",
"breadth",
"search",
"first",
".",
"All",
"predicates",
"are",
"immutable",
"and",
"use",
"the",
"predicate",
"parent_of"
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/benchmark/generator/tree/tree.go#L38-L55 |
12,469 | google/badwolf | tools/benchmark/generator/tree/tree.go | newTriple | func (t *treeGenerator) newTriple(parent, descendant *node.Node) (*triple.Triple, error) {
return triple.New(parent, t.predicate, triple.NewNodeObject(descendant))
} | go | func (t *treeGenerator) newTriple(parent, descendant *node.Node) (*triple.Triple, error) {
return triple.New(parent, t.predicate, triple.NewNodeObject(descendant))
} | [
"func",
"(",
"t",
"*",
"treeGenerator",
")",
"newTriple",
"(",
"parent",
",",
"descendant",
"*",
"node",
".",
"Node",
")",
"(",
"*",
"triple",
".",
"Triple",
",",
"error",
")",
"{",
"return",
"triple",
".",
"New",
"(",
"parent",
",",
"t",
".",
"predicate",
",",
"triple",
".",
"NewNodeObject",
"(",
"descendant",
")",
")",
"\n",
"}"
]
| // newTriple creates a new triple given the parent and the descendant as an object. | [
"newTriple",
"creates",
"a",
"new",
"triple",
"given",
"the",
"parent",
"and",
"the",
"descendant",
"as",
"an",
"object",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/benchmark/generator/tree/tree.go#L71-L73 |
12,470 | google/badwolf | tools/benchmark/generator/tree/tree.go | recurse | func (t *treeGenerator) recurse(parent *node.Node, left *int, currentDepth, maxDepth int, trpls []*triple.Triple) ([]*triple.Triple, error) {
if *left < 1 {
return trpls, nil
}
for i, last := 0, *left <= t.branch; i < t.branch; i++ {
offspring, err := t.newNode(i, parent.ID().String())
if err != nil {
return trpls, err
}
trpl, err := t.newTriple(parent, offspring)
if err != nil {
return trpls, err
}
trpls = append(trpls, trpl)
(*left)--
if *left < 1 {
break
}
if currentDepth < maxDepth && !last {
ntrpls, err := t.recurse(offspring, left, currentDepth+1, maxDepth, trpls)
if err != nil {
return ntrpls, err
}
trpls = ntrpls
}
if *left < 1 {
break
}
}
return trpls, nil
} | go | func (t *treeGenerator) recurse(parent *node.Node, left *int, currentDepth, maxDepth int, trpls []*triple.Triple) ([]*triple.Triple, error) {
if *left < 1 {
return trpls, nil
}
for i, last := 0, *left <= t.branch; i < t.branch; i++ {
offspring, err := t.newNode(i, parent.ID().String())
if err != nil {
return trpls, err
}
trpl, err := t.newTriple(parent, offspring)
if err != nil {
return trpls, err
}
trpls = append(trpls, trpl)
(*left)--
if *left < 1 {
break
}
if currentDepth < maxDepth && !last {
ntrpls, err := t.recurse(offspring, left, currentDepth+1, maxDepth, trpls)
if err != nil {
return ntrpls, err
}
trpls = ntrpls
}
if *left < 1 {
break
}
}
return trpls, nil
} | [
"func",
"(",
"t",
"*",
"treeGenerator",
")",
"recurse",
"(",
"parent",
"*",
"node",
".",
"Node",
",",
"left",
"*",
"int",
",",
"currentDepth",
",",
"maxDepth",
"int",
",",
"trpls",
"[",
"]",
"*",
"triple",
".",
"Triple",
")",
"(",
"[",
"]",
"*",
"triple",
".",
"Triple",
",",
"error",
")",
"{",
"if",
"*",
"left",
"<",
"1",
"{",
"return",
"trpls",
",",
"nil",
"\n",
"}",
"\n",
"for",
"i",
",",
"last",
":=",
"0",
",",
"*",
"left",
"<=",
"t",
".",
"branch",
";",
"i",
"<",
"t",
".",
"branch",
";",
"i",
"++",
"{",
"offspring",
",",
"err",
":=",
"t",
".",
"newNode",
"(",
"i",
",",
"parent",
".",
"ID",
"(",
")",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"trpls",
",",
"err",
"\n",
"}",
"\n",
"trpl",
",",
"err",
":=",
"t",
".",
"newTriple",
"(",
"parent",
",",
"offspring",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"trpls",
",",
"err",
"\n",
"}",
"\n",
"trpls",
"=",
"append",
"(",
"trpls",
",",
"trpl",
")",
"\n",
"(",
"*",
"left",
")",
"--",
"\n",
"if",
"*",
"left",
"<",
"1",
"{",
"break",
"\n",
"}",
"\n",
"if",
"currentDepth",
"<",
"maxDepth",
"&&",
"!",
"last",
"{",
"ntrpls",
",",
"err",
":=",
"t",
".",
"recurse",
"(",
"offspring",
",",
"left",
",",
"currentDepth",
"+",
"1",
",",
"maxDepth",
",",
"trpls",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ntrpls",
",",
"err",
"\n",
"}",
"\n",
"trpls",
"=",
"ntrpls",
"\n",
"}",
"\n",
"if",
"*",
"left",
"<",
"1",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"trpls",
",",
"nil",
"\n",
"}"
]
| // recurse generated the triple by recursing while there are still triples
// left to generate. | [
"recurse",
"generated",
"the",
"triple",
"by",
"recursing",
"while",
"there",
"are",
"still",
"triples",
"left",
"to",
"generate",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/benchmark/generator/tree/tree.go#L77-L107 |
12,471 | google/badwolf | tools/benchmark/generator/tree/tree.go | Generate | func (t *treeGenerator) Generate(n int) ([]*triple.Triple, error) {
var trpls []*triple.Triple
if n <= 0 {
return trpls, nil
}
root, err := t.newNode(0, "")
if err != nil {
return nil, err
}
depth := int(math.Log(float64(n)) / math.Log(float64(t.branch)))
ntrpls, err := t.recurse(root, &n, 0, depth, trpls)
if err != nil {
return nil, err
}
return ntrpls, nil
} | go | func (t *treeGenerator) Generate(n int) ([]*triple.Triple, error) {
var trpls []*triple.Triple
if n <= 0 {
return trpls, nil
}
root, err := t.newNode(0, "")
if err != nil {
return nil, err
}
depth := int(math.Log(float64(n)) / math.Log(float64(t.branch)))
ntrpls, err := t.recurse(root, &n, 0, depth, trpls)
if err != nil {
return nil, err
}
return ntrpls, nil
} | [
"func",
"(",
"t",
"*",
"treeGenerator",
")",
"Generate",
"(",
"n",
"int",
")",
"(",
"[",
"]",
"*",
"triple",
".",
"Triple",
",",
"error",
")",
"{",
"var",
"trpls",
"[",
"]",
"*",
"triple",
".",
"Triple",
"\n",
"if",
"n",
"<=",
"0",
"{",
"return",
"trpls",
",",
"nil",
"\n",
"}",
"\n",
"root",
",",
"err",
":=",
"t",
".",
"newNode",
"(",
"0",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"depth",
":=",
"int",
"(",
"math",
".",
"Log",
"(",
"float64",
"(",
"n",
")",
")",
"/",
"math",
".",
"Log",
"(",
"float64",
"(",
"t",
".",
"branch",
")",
")",
")",
"\n",
"ntrpls",
",",
"err",
":=",
"t",
".",
"recurse",
"(",
"root",
",",
"&",
"n",
",",
"0",
",",
"depth",
",",
"trpls",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"ntrpls",
",",
"nil",
"\n",
"}"
]
| // Generates the requested number of triples. | [
"Generates",
"the",
"requested",
"number",
"of",
"triples",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/benchmark/generator/tree/tree.go#L110-L125 |
12,472 | google/badwolf | triple/triple.go | String | func (o *Object) String() string {
if o.n != nil {
return o.n.String()
}
if o.l != nil {
return o.l.String()
}
if o.p != nil {
return o.p.String()
}
return "@@@INVALID_OBJECT@@@"
} | go | func (o *Object) String() string {
if o.n != nil {
return o.n.String()
}
if o.l != nil {
return o.l.String()
}
if o.p != nil {
return o.p.String()
}
return "@@@INVALID_OBJECT@@@"
} | [
"func",
"(",
"o",
"*",
"Object",
")",
"String",
"(",
")",
"string",
"{",
"if",
"o",
".",
"n",
"!=",
"nil",
"{",
"return",
"o",
".",
"n",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"if",
"o",
".",
"l",
"!=",
"nil",
"{",
"return",
"o",
".",
"l",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"if",
"o",
".",
"p",
"!=",
"nil",
"{",
"return",
"o",
".",
"p",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
]
| // String pretty prints the object. | [
"String",
"pretty",
"prints",
"the",
"object",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/triple.go#L38-L49 |
12,473 | google/badwolf | triple/triple.go | UUID | func (o *Object) UUID() uuid.UUID {
switch {
case o.l != nil:
return o.l.UUID()
case o.p != nil:
return o.p.UUID()
default:
return o.n.UUID()
}
} | go | func (o *Object) UUID() uuid.UUID {
switch {
case o.l != nil:
return o.l.UUID()
case o.p != nil:
return o.p.UUID()
default:
return o.n.UUID()
}
} | [
"func",
"(",
"o",
"*",
"Object",
")",
"UUID",
"(",
")",
"uuid",
".",
"UUID",
"{",
"switch",
"{",
"case",
"o",
".",
"l",
"!=",
"nil",
":",
"return",
"o",
".",
"l",
".",
"UUID",
"(",
")",
"\n",
"case",
"o",
".",
"p",
"!=",
"nil",
":",
"return",
"o",
".",
"p",
".",
"UUID",
"(",
")",
"\n",
"default",
":",
"return",
"o",
".",
"n",
".",
"UUID",
"(",
")",
"\n",
"}",
"\n",
"}"
]
| // UUID returns a global unique identifier for the given object. It is
// implemented by returning the UIUD of the underlying value stored in the
// object. | [
"UUID",
"returns",
"a",
"global",
"unique",
"identifier",
"for",
"the",
"given",
"object",
".",
"It",
"is",
"implemented",
"by",
"returning",
"the",
"UIUD",
"of",
"the",
"underlying",
"value",
"stored",
"in",
"the",
"object",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/triple.go#L54-L63 |
12,474 | google/badwolf | triple/triple.go | Node | func (o *Object) Node() (*node.Node, error) {
if o.n == nil {
return nil, fmt.Errorf("triple.Literal does not box a node in %s", o)
}
return o.n, nil
} | go | func (o *Object) Node() (*node.Node, error) {
if o.n == nil {
return nil, fmt.Errorf("triple.Literal does not box a node in %s", o)
}
return o.n, nil
} | [
"func",
"(",
"o",
"*",
"Object",
")",
"Node",
"(",
")",
"(",
"*",
"node",
".",
"Node",
",",
"error",
")",
"{",
"if",
"o",
".",
"n",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"o",
")",
"\n",
"}",
"\n",
"return",
"o",
".",
"n",
",",
"nil",
"\n",
"}"
]
| // Node attempts to return the boxed node. | [
"Node",
"attempts",
"to",
"return",
"the",
"boxed",
"node",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/triple.go#L66-L71 |
12,475 | google/badwolf | triple/triple.go | Predicate | func (o *Object) Predicate() (*predicate.Predicate, error) {
if o.p == nil {
return nil, fmt.Errorf("triple.Literal does not box a predicate in %s", o)
}
return o.p, nil
} | go | func (o *Object) Predicate() (*predicate.Predicate, error) {
if o.p == nil {
return nil, fmt.Errorf("triple.Literal does not box a predicate in %s", o)
}
return o.p, nil
} | [
"func",
"(",
"o",
"*",
"Object",
")",
"Predicate",
"(",
")",
"(",
"*",
"predicate",
".",
"Predicate",
",",
"error",
")",
"{",
"if",
"o",
".",
"p",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"o",
")",
"\n",
"}",
"\n",
"return",
"o",
".",
"p",
",",
"nil",
"\n",
"}"
]
| // Predicate attempts to return the boxed predicate. | [
"Predicate",
"attempts",
"to",
"return",
"the",
"boxed",
"predicate",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/triple.go#L74-L79 |
12,476 | google/badwolf | triple/triple.go | Literal | func (o *Object) Literal() (*literal.Literal, error) {
if o.l == nil {
return nil, fmt.Errorf("triple.Literal does not box a literal in %s", o)
}
return o.l, nil
} | go | func (o *Object) Literal() (*literal.Literal, error) {
if o.l == nil {
return nil, fmt.Errorf("triple.Literal does not box a literal in %s", o)
}
return o.l, nil
} | [
"func",
"(",
"o",
"*",
"Object",
")",
"Literal",
"(",
")",
"(",
"*",
"literal",
".",
"Literal",
",",
"error",
")",
"{",
"if",
"o",
".",
"l",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"o",
")",
"\n",
"}",
"\n",
"return",
"o",
".",
"l",
",",
"nil",
"\n",
"}"
]
| // Literal attempts to return the boxed literal. | [
"Literal",
"attempts",
"to",
"return",
"the",
"boxed",
"literal",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/triple.go#L82-L87 |
12,477 | google/badwolf | triple/triple.go | ParseObject | func ParseObject(s string, b literal.Builder) (*Object, error) {
n, err := node.Parse(s)
if err == nil {
return NewNodeObject(n), nil
}
l, err := b.Parse(s)
if err == nil {
return NewLiteralObject(l), nil
}
o, err := predicate.Parse(s)
if err == nil {
return NewPredicateObject(o), nil
}
return nil, err
} | go | func ParseObject(s string, b literal.Builder) (*Object, error) {
n, err := node.Parse(s)
if err == nil {
return NewNodeObject(n), nil
}
l, err := b.Parse(s)
if err == nil {
return NewLiteralObject(l), nil
}
o, err := predicate.Parse(s)
if err == nil {
return NewPredicateObject(o), nil
}
return nil, err
} | [
"func",
"ParseObject",
"(",
"s",
"string",
",",
"b",
"literal",
".",
"Builder",
")",
"(",
"*",
"Object",
",",
"error",
")",
"{",
"n",
",",
"err",
":=",
"node",
".",
"Parse",
"(",
"s",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"NewNodeObject",
"(",
"n",
")",
",",
"nil",
"\n",
"}",
"\n",
"l",
",",
"err",
":=",
"b",
".",
"Parse",
"(",
"s",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"NewLiteralObject",
"(",
"l",
")",
",",
"nil",
"\n",
"}",
"\n",
"o",
",",
"err",
":=",
"predicate",
".",
"Parse",
"(",
"s",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"NewPredicateObject",
"(",
"o",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}"
]
| // ParseObject attempts to parse an object. | [
"ParseObject",
"attempts",
"to",
"parse",
"an",
"object",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/triple.go#L90-L104 |
12,478 | google/badwolf | triple/triple.go | New | func New(s *node.Node, p *predicate.Predicate, o *Object) (*Triple, error) {
if s == nil || p == nil || o == nil {
return nil, fmt.Errorf("triple.New cannot create triples from nil components in <%v %v %v>", s, p, o)
}
return &Triple{
s: s,
p: p,
o: o,
}, nil
} | go | func New(s *node.Node, p *predicate.Predicate, o *Object) (*Triple, error) {
if s == nil || p == nil || o == nil {
return nil, fmt.Errorf("triple.New cannot create triples from nil components in <%v %v %v>", s, p, o)
}
return &Triple{
s: s,
p: p,
o: o,
}, nil
} | [
"func",
"New",
"(",
"s",
"*",
"node",
".",
"Node",
",",
"p",
"*",
"predicate",
".",
"Predicate",
",",
"o",
"*",
"Object",
")",
"(",
"*",
"Triple",
",",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"||",
"p",
"==",
"nil",
"||",
"o",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
",",
"p",
",",
"o",
")",
"\n",
"}",
"\n",
"return",
"&",
"Triple",
"{",
"s",
":",
"s",
",",
"p",
":",
"p",
",",
"o",
":",
"o",
",",
"}",
",",
"nil",
"\n",
"}"
]
| // New creates a new triple. | [
"New",
"creates",
"a",
"new",
"triple",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/triple.go#L135-L144 |
12,479 | google/badwolf | triple/triple.go | Equal | func (t *Triple) Equal(t2 *Triple) bool {
return uuid.Equal(t.UUID(), t2.UUID())
} | go | func (t *Triple) Equal(t2 *Triple) bool {
return uuid.Equal(t.UUID(), t2.UUID())
} | [
"func",
"(",
"t",
"*",
"Triple",
")",
"Equal",
"(",
"t2",
"*",
"Triple",
")",
"bool",
"{",
"return",
"uuid",
".",
"Equal",
"(",
"t",
".",
"UUID",
"(",
")",
",",
"t2",
".",
"UUID",
"(",
")",
")",
"\n",
"}"
]
| // Equal checks if two triples are identical. | [
"Equal",
"checks",
"if",
"two",
"triples",
"are",
"identical",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/triple.go#L162-L164 |
12,480 | google/badwolf | triple/triple.go | String | func (t *Triple) String() string {
return fmt.Sprintf("%s\t%s\t%s", t.s, t.p, t.o)
} | go | func (t *Triple) String() string {
return fmt.Sprintf("%s\t%s\t%s", t.s, t.p, t.o)
} | [
"func",
"(",
"t",
"*",
"Triple",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\t",
"\\t",
"\"",
",",
"t",
".",
"s",
",",
"t",
".",
"p",
",",
"t",
".",
"o",
")",
"\n",
"}"
]
| // String marshals the triple into pretty string. | [
"String",
"marshals",
"the",
"triple",
"into",
"pretty",
"string",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/triple.go#L167-L169 |
12,481 | google/badwolf | triple/triple.go | Parse | func Parse(line string, b literal.Builder) (*Triple, error) {
raw := strings.TrimSpace(line)
idxp := pSplit.FindIndex([]byte(raw))
idxo := oSplit.FindIndex([]byte(raw))
if len(idxp) == 0 || len(idxo) == 0 {
return nil, fmt.Errorf("triple.Parse could not split s p o out of %s", raw)
}
ss, sp, so := raw[0:idxp[0]+1], raw[idxp[1]-1:idxo[0]+1], raw[idxo[1]-1:]
s, err := node.Parse(ss)
if err != nil {
return nil, fmt.Errorf("triple.Parse failed to parse subject %s with error %v", ss, err)
}
p, err := predicate.Parse(sp)
if err != nil {
return nil, fmt.Errorf("triple.Parse failed to parse predicate %s with error %v", sp, err)
}
o, err := ParseObject(so, b)
if err != nil {
return nil, fmt.Errorf("triple.Parse failed to parse object %s with error %v", so, err)
}
return New(s, p, o)
} | go | func Parse(line string, b literal.Builder) (*Triple, error) {
raw := strings.TrimSpace(line)
idxp := pSplit.FindIndex([]byte(raw))
idxo := oSplit.FindIndex([]byte(raw))
if len(idxp) == 0 || len(idxo) == 0 {
return nil, fmt.Errorf("triple.Parse could not split s p o out of %s", raw)
}
ss, sp, so := raw[0:idxp[0]+1], raw[idxp[1]-1:idxo[0]+1], raw[idxo[1]-1:]
s, err := node.Parse(ss)
if err != nil {
return nil, fmt.Errorf("triple.Parse failed to parse subject %s with error %v", ss, err)
}
p, err := predicate.Parse(sp)
if err != nil {
return nil, fmt.Errorf("triple.Parse failed to parse predicate %s with error %v", sp, err)
}
o, err := ParseObject(so, b)
if err != nil {
return nil, fmt.Errorf("triple.Parse failed to parse object %s with error %v", so, err)
}
return New(s, p, o)
} | [
"func",
"Parse",
"(",
"line",
"string",
",",
"b",
"literal",
".",
"Builder",
")",
"(",
"*",
"Triple",
",",
"error",
")",
"{",
"raw",
":=",
"strings",
".",
"TrimSpace",
"(",
"line",
")",
"\n",
"idxp",
":=",
"pSplit",
".",
"FindIndex",
"(",
"[",
"]",
"byte",
"(",
"raw",
")",
")",
"\n",
"idxo",
":=",
"oSplit",
".",
"FindIndex",
"(",
"[",
"]",
"byte",
"(",
"raw",
")",
")",
"\n",
"if",
"len",
"(",
"idxp",
")",
"==",
"0",
"||",
"len",
"(",
"idxo",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}",
"\n",
"ss",
",",
"sp",
",",
"so",
":=",
"raw",
"[",
"0",
":",
"idxp",
"[",
"0",
"]",
"+",
"1",
"]",
",",
"raw",
"[",
"idxp",
"[",
"1",
"]",
"-",
"1",
":",
"idxo",
"[",
"0",
"]",
"+",
"1",
"]",
",",
"raw",
"[",
"idxo",
"[",
"1",
"]",
"-",
"1",
":",
"]",
"\n",
"s",
",",
"err",
":=",
"node",
".",
"Parse",
"(",
"ss",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ss",
",",
"err",
")",
"\n",
"}",
"\n",
"p",
",",
"err",
":=",
"predicate",
".",
"Parse",
"(",
"sp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sp",
",",
"err",
")",
"\n",
"}",
"\n",
"o",
",",
"err",
":=",
"ParseObject",
"(",
"so",
",",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"so",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"New",
"(",
"s",
",",
"p",
",",
"o",
")",
"\n",
"}"
]
| // Parse process the provided text and tries to create a triple. It assumes
// that the provided text contains only one triple. | [
"Parse",
"process",
"the",
"provided",
"text",
"and",
"tries",
"to",
"create",
"a",
"triple",
".",
"It",
"assumes",
"that",
"the",
"provided",
"text",
"contains",
"only",
"one",
"triple",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/triple.go#L183-L204 |
12,482 | google/badwolf | triple/triple.go | Reify | func (t *Triple) Reify() ([]*Triple, *node.Node, error) {
// Function that creates the proper reification predicates.
rp := func(id string, p *predicate.Predicate) (*predicate.Predicate, error) {
if p.Type() == predicate.Temporal {
ta, _ := p.TimeAnchor()
return predicate.NewTemporal(id, *ta)
}
return predicate.NewImmutable(id)
}
b := node.NewBlankNode()
s, err := rp("_subject", t.p)
if err != nil {
return nil, nil, err
}
ts, _ := New(b, s, NewNodeObject(t.s))
p, err := rp("_predicate", t.p)
if err != nil {
return nil, nil, err
}
tp, _ := New(b, p, NewPredicateObject(t.p))
var to *Triple
if t.o.l != nil {
o, err := rp("_object", t.p)
if err != nil {
return nil, nil, err
}
to, _ = New(b, o, NewLiteralObject(t.o.l))
}
if t.o.n != nil {
o, err := rp("_object", t.p)
if err != nil {
return nil, nil, err
}
to, _ = New(b, o, NewNodeObject(t.o.n))
}
if t.o.p != nil {
o, err := rp("_object", t.p)
if err != nil {
return nil, nil, err
}
to, _ = New(b, o, NewPredicateObject(t.o.p))
}
return []*Triple{t, ts, tp, to}, b, nil
} | go | func (t *Triple) Reify() ([]*Triple, *node.Node, error) {
// Function that creates the proper reification predicates.
rp := func(id string, p *predicate.Predicate) (*predicate.Predicate, error) {
if p.Type() == predicate.Temporal {
ta, _ := p.TimeAnchor()
return predicate.NewTemporal(id, *ta)
}
return predicate.NewImmutable(id)
}
b := node.NewBlankNode()
s, err := rp("_subject", t.p)
if err != nil {
return nil, nil, err
}
ts, _ := New(b, s, NewNodeObject(t.s))
p, err := rp("_predicate", t.p)
if err != nil {
return nil, nil, err
}
tp, _ := New(b, p, NewPredicateObject(t.p))
var to *Triple
if t.o.l != nil {
o, err := rp("_object", t.p)
if err != nil {
return nil, nil, err
}
to, _ = New(b, o, NewLiteralObject(t.o.l))
}
if t.o.n != nil {
o, err := rp("_object", t.p)
if err != nil {
return nil, nil, err
}
to, _ = New(b, o, NewNodeObject(t.o.n))
}
if t.o.p != nil {
o, err := rp("_object", t.p)
if err != nil {
return nil, nil, err
}
to, _ = New(b, o, NewPredicateObject(t.o.p))
}
return []*Triple{t, ts, tp, to}, b, nil
} | [
"func",
"(",
"t",
"*",
"Triple",
")",
"Reify",
"(",
")",
"(",
"[",
"]",
"*",
"Triple",
",",
"*",
"node",
".",
"Node",
",",
"error",
")",
"{",
"// Function that creates the proper reification predicates.",
"rp",
":=",
"func",
"(",
"id",
"string",
",",
"p",
"*",
"predicate",
".",
"Predicate",
")",
"(",
"*",
"predicate",
".",
"Predicate",
",",
"error",
")",
"{",
"if",
"p",
".",
"Type",
"(",
")",
"==",
"predicate",
".",
"Temporal",
"{",
"ta",
",",
"_",
":=",
"p",
".",
"TimeAnchor",
"(",
")",
"\n",
"return",
"predicate",
".",
"NewTemporal",
"(",
"id",
",",
"*",
"ta",
")",
"\n",
"}",
"\n",
"return",
"predicate",
".",
"NewImmutable",
"(",
"id",
")",
"\n",
"}",
"\n",
"b",
":=",
"node",
".",
"NewBlankNode",
"(",
")",
"\n",
"s",
",",
"err",
":=",
"rp",
"(",
"\"",
"\"",
",",
"t",
".",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ts",
",",
"_",
":=",
"New",
"(",
"b",
",",
"s",
",",
"NewNodeObject",
"(",
"t",
".",
"s",
")",
")",
"\n",
"p",
",",
"err",
":=",
"rp",
"(",
"\"",
"\"",
",",
"t",
".",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tp",
",",
"_",
":=",
"New",
"(",
"b",
",",
"p",
",",
"NewPredicateObject",
"(",
"t",
".",
"p",
")",
")",
"\n",
"var",
"to",
"*",
"Triple",
"\n",
"if",
"t",
".",
"o",
".",
"l",
"!=",
"nil",
"{",
"o",
",",
"err",
":=",
"rp",
"(",
"\"",
"\"",
",",
"t",
".",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"to",
",",
"_",
"=",
"New",
"(",
"b",
",",
"o",
",",
"NewLiteralObject",
"(",
"t",
".",
"o",
".",
"l",
")",
")",
"\n",
"}",
"\n",
"if",
"t",
".",
"o",
".",
"n",
"!=",
"nil",
"{",
"o",
",",
"err",
":=",
"rp",
"(",
"\"",
"\"",
",",
"t",
".",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"to",
",",
"_",
"=",
"New",
"(",
"b",
",",
"o",
",",
"NewNodeObject",
"(",
"t",
".",
"o",
".",
"n",
")",
")",
"\n",
"}",
"\n",
"if",
"t",
".",
"o",
".",
"p",
"!=",
"nil",
"{",
"o",
",",
"err",
":=",
"rp",
"(",
"\"",
"\"",
",",
"t",
".",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"to",
",",
"_",
"=",
"New",
"(",
"b",
",",
"o",
",",
"NewPredicateObject",
"(",
"t",
".",
"o",
".",
"p",
")",
")",
"\n",
"}",
"\n\n",
"return",
"[",
"]",
"*",
"Triple",
"{",
"t",
",",
"ts",
",",
"tp",
",",
"to",
"}",
",",
"b",
",",
"nil",
"\n",
"}"
]
| // Reify given the current triple it returns the original triple and the newly
// reified ones. It also returns the newly created blank node. | [
"Reify",
"given",
"the",
"current",
"triple",
"it",
"returns",
"the",
"original",
"triple",
"and",
"the",
"newly",
"reified",
"ones",
".",
"It",
"also",
"returns",
"the",
"newly",
"created",
"blank",
"node",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/triple.go#L208-L252 |
12,483 | google/badwolf | triple/triple.go | UUID | func (t *Triple) UUID() uuid.UUID {
var buffer bytes.Buffer
buffer.Write([]byte(t.s.UUID()))
buffer.Write([]byte(t.p.UUID()))
buffer.Write([]byte(t.o.UUID()))
return uuid.NewSHA1(uuid.NIL, buffer.Bytes())
} | go | func (t *Triple) UUID() uuid.UUID {
var buffer bytes.Buffer
buffer.Write([]byte(t.s.UUID()))
buffer.Write([]byte(t.p.UUID()))
buffer.Write([]byte(t.o.UUID()))
return uuid.NewSHA1(uuid.NIL, buffer.Bytes())
} | [
"func",
"(",
"t",
"*",
"Triple",
")",
"UUID",
"(",
")",
"uuid",
".",
"UUID",
"{",
"var",
"buffer",
"bytes",
".",
"Buffer",
"\n\n",
"buffer",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"t",
".",
"s",
".",
"UUID",
"(",
")",
")",
")",
"\n",
"buffer",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"t",
".",
"p",
".",
"UUID",
"(",
")",
")",
")",
"\n",
"buffer",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"t",
".",
"o",
".",
"UUID",
"(",
")",
")",
")",
"\n\n",
"return",
"uuid",
".",
"NewSHA1",
"(",
"uuid",
".",
"NIL",
",",
"buffer",
".",
"Bytes",
"(",
")",
")",
"\n",
"}"
]
| // UUID returns a global unique identifier for the given triple. It is
// implemented as the SHA1 UUID of the concatenated UUIDs of the subject,
// predicate, and object. | [
"UUID",
"returns",
"a",
"global",
"unique",
"identifier",
"for",
"the",
"given",
"triple",
".",
"It",
"is",
"implemented",
"as",
"the",
"SHA1",
"UUID",
"of",
"the",
"concatenated",
"UUIDs",
"of",
"the",
"subject",
"predicate",
"and",
"object",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/triple.go#L257-L265 |
12,484 | google/badwolf | bql/semantic/hooks.go | TypeBindingClauseHook | func TypeBindingClauseHook(t StatementType) ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
s.BindType(t)
return f, nil
}
return f
} | go | func TypeBindingClauseHook(t StatementType) ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
s.BindType(t)
return f, nil
}
return f
} | [
"func",
"TypeBindingClauseHook",
"(",
"t",
"StatementType",
")",
"ClauseHook",
"{",
"var",
"f",
"ClauseHook",
"\n",
"f",
"=",
"func",
"(",
"s",
"*",
"Statement",
",",
"_",
"Symbol",
")",
"(",
"ClauseHook",
",",
"error",
")",
"{",
"s",
".",
"BindType",
"(",
"t",
")",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // TypeBindingClauseHook returns a ClauseHook that sets the binding type. | [
"TypeBindingClauseHook",
"returns",
"a",
"ClauseHook",
"that",
"sets",
"the",
"binding",
"type",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L189-L196 |
12,485 | google/badwolf | bql/semantic/hooks.go | dataAccumulator | func dataAccumulator(b literal.Builder) ElementHook {
var (
hook ElementHook
s *node.Node
p *predicate.Predicate
o *triple.Object
)
hook = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return hook, nil
}
tkn := ce.Token()
if tkn.Type != lexer.ItemNode && tkn.Type != lexer.ItemPredicate && tkn.Type != lexer.ItemLiteral {
return hook, nil
}
if s == nil {
if tkn.Type != lexer.ItemNode {
return nil, fmt.Errorf("hook.DataAccumulator requires a node to create a subject, got %v instead", tkn)
}
tmp, err := node.Parse(tkn.Text)
if err != nil {
return nil, err
}
s = tmp
return hook, nil
}
if p == nil {
if tkn.Type != lexer.ItemPredicate {
return nil, fmt.Errorf("hook.DataAccumulator requires a predicate to create a predicate, got %v instead", tkn)
}
tmp, err := predicate.Parse(tkn.Text)
if err != nil {
return nil, err
}
p = tmp
return hook, nil
}
if o == nil {
tmp, err := triple.ParseObject(tkn.Text, b)
if err != nil {
return nil, err
}
o = tmp
trpl, err := triple.New(s, p, o)
if err != nil {
return nil, err
}
st.AddData(trpl)
s, p, o = nil, nil, nil
return hook, nil
}
return nil, fmt.Errorf("hook.DataAccumulator has failed to flush the triple %s, %s, %s", s, p, o)
}
return hook
} | go | func dataAccumulator(b literal.Builder) ElementHook {
var (
hook ElementHook
s *node.Node
p *predicate.Predicate
o *triple.Object
)
hook = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return hook, nil
}
tkn := ce.Token()
if tkn.Type != lexer.ItemNode && tkn.Type != lexer.ItemPredicate && tkn.Type != lexer.ItemLiteral {
return hook, nil
}
if s == nil {
if tkn.Type != lexer.ItemNode {
return nil, fmt.Errorf("hook.DataAccumulator requires a node to create a subject, got %v instead", tkn)
}
tmp, err := node.Parse(tkn.Text)
if err != nil {
return nil, err
}
s = tmp
return hook, nil
}
if p == nil {
if tkn.Type != lexer.ItemPredicate {
return nil, fmt.Errorf("hook.DataAccumulator requires a predicate to create a predicate, got %v instead", tkn)
}
tmp, err := predicate.Parse(tkn.Text)
if err != nil {
return nil, err
}
p = tmp
return hook, nil
}
if o == nil {
tmp, err := triple.ParseObject(tkn.Text, b)
if err != nil {
return nil, err
}
o = tmp
trpl, err := triple.New(s, p, o)
if err != nil {
return nil, err
}
st.AddData(trpl)
s, p, o = nil, nil, nil
return hook, nil
}
return nil, fmt.Errorf("hook.DataAccumulator has failed to flush the triple %s, %s, %s", s, p, o)
}
return hook
} | [
"func",
"dataAccumulator",
"(",
"b",
"literal",
".",
"Builder",
")",
"ElementHook",
"{",
"var",
"(",
"hook",
"ElementHook",
"\n",
"s",
"*",
"node",
".",
"Node",
"\n",
"p",
"*",
"predicate",
".",
"Predicate",
"\n",
"o",
"*",
"triple",
".",
"Object",
"\n",
")",
"\n\n",
"hook",
"=",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"{",
"if",
"ce",
".",
"IsSymbol",
"(",
")",
"{",
"return",
"hook",
",",
"nil",
"\n",
"}",
"\n",
"tkn",
":=",
"ce",
".",
"Token",
"(",
")",
"\n",
"if",
"tkn",
".",
"Type",
"!=",
"lexer",
".",
"ItemNode",
"&&",
"tkn",
".",
"Type",
"!=",
"lexer",
".",
"ItemPredicate",
"&&",
"tkn",
".",
"Type",
"!=",
"lexer",
".",
"ItemLiteral",
"{",
"return",
"hook",
",",
"nil",
"\n",
"}",
"\n",
"if",
"s",
"==",
"nil",
"{",
"if",
"tkn",
".",
"Type",
"!=",
"lexer",
".",
"ItemNode",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
")",
"\n",
"}",
"\n",
"tmp",
",",
"err",
":=",
"node",
".",
"Parse",
"(",
"tkn",
".",
"Text",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"s",
"=",
"tmp",
"\n",
"return",
"hook",
",",
"nil",
"\n",
"}",
"\n",
"if",
"p",
"==",
"nil",
"{",
"if",
"tkn",
".",
"Type",
"!=",
"lexer",
".",
"ItemPredicate",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
")",
"\n",
"}",
"\n",
"tmp",
",",
"err",
":=",
"predicate",
".",
"Parse",
"(",
"tkn",
".",
"Text",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"p",
"=",
"tmp",
"\n",
"return",
"hook",
",",
"nil",
"\n",
"}",
"\n",
"if",
"o",
"==",
"nil",
"{",
"tmp",
",",
"err",
":=",
"triple",
".",
"ParseObject",
"(",
"tkn",
".",
"Text",
",",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"o",
"=",
"tmp",
"\n",
"trpl",
",",
"err",
":=",
"triple",
".",
"New",
"(",
"s",
",",
"p",
",",
"o",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"st",
".",
"AddData",
"(",
"trpl",
")",
"\n",
"s",
",",
"p",
",",
"o",
"=",
"nil",
",",
"nil",
",",
"nil",
"\n",
"return",
"hook",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
",",
"p",
",",
"o",
")",
"\n",
"}",
"\n",
"return",
"hook",
"\n",
"}"
]
| // dataAccumulator creates a element hook that tracks fully formed triples and
// adds them to the Statement when fully formed. | [
"dataAccumulator",
"creates",
"a",
"element",
"hook",
"that",
"tracks",
"fully",
"formed",
"triples",
"and",
"adds",
"them",
"to",
"the",
"Statement",
"when",
"fully",
"formed",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L200-L255 |
12,486 | google/badwolf | bql/semantic/hooks.go | graphAccumulator | func graphAccumulator() ElementHook {
var hook ElementHook
hook = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return hook, nil
}
tkn := ce.Token()
switch tkn.Type {
case lexer.ItemComma:
return hook, nil
case lexer.ItemBinding:
st.AddGraph(strings.TrimSpace(tkn.Text))
return hook, nil
default:
return nil, fmt.Errorf("hook.GraphAccumulator requires a binding to refer to a graph, got %v instead", tkn)
}
}
return hook
} | go | func graphAccumulator() ElementHook {
var hook ElementHook
hook = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return hook, nil
}
tkn := ce.Token()
switch tkn.Type {
case lexer.ItemComma:
return hook, nil
case lexer.ItemBinding:
st.AddGraph(strings.TrimSpace(tkn.Text))
return hook, nil
default:
return nil, fmt.Errorf("hook.GraphAccumulator requires a binding to refer to a graph, got %v instead", tkn)
}
}
return hook
} | [
"func",
"graphAccumulator",
"(",
")",
"ElementHook",
"{",
"var",
"hook",
"ElementHook",
"\n",
"hook",
"=",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"{",
"if",
"ce",
".",
"IsSymbol",
"(",
")",
"{",
"return",
"hook",
",",
"nil",
"\n",
"}",
"\n",
"tkn",
":=",
"ce",
".",
"Token",
"(",
")",
"\n",
"switch",
"tkn",
".",
"Type",
"{",
"case",
"lexer",
".",
"ItemComma",
":",
"return",
"hook",
",",
"nil",
"\n",
"case",
"lexer",
".",
"ItemBinding",
":",
"st",
".",
"AddGraph",
"(",
"strings",
".",
"TrimSpace",
"(",
"tkn",
".",
"Text",
")",
")",
"\n",
"return",
"hook",
",",
"nil",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"hook",
"\n",
"}"
]
| // graphAccumulator returns an element hook that keeps track of the graphs
// listed in a statement. | [
"graphAccumulator",
"returns",
"an",
"element",
"hook",
"that",
"keeps",
"track",
"of",
"the",
"graphs",
"listed",
"in",
"a",
"statement",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L259-L277 |
12,487 | google/badwolf | bql/semantic/hooks.go | whereNextWorkingClause | func whereNextWorkingClause() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
s.AddWorkingGraphClause()
return f, nil
}
return f
} | go | func whereNextWorkingClause() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
s.AddWorkingGraphClause()
return f, nil
}
return f
} | [
"func",
"whereNextWorkingClause",
"(",
")",
"ClauseHook",
"{",
"var",
"f",
"ClauseHook",
"\n",
"f",
"=",
"func",
"(",
"s",
"*",
"Statement",
",",
"_",
"Symbol",
")",
"(",
"ClauseHook",
",",
"error",
")",
"{",
"s",
".",
"AddWorkingGraphClause",
"(",
")",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // whereNextWorkingClause returns a clause hook to close the current graphs
// clause and starts a new working one. | [
"whereNextWorkingClause",
"returns",
"a",
"clause",
"hook",
"to",
"close",
"the",
"current",
"graphs",
"clause",
"and",
"starts",
"a",
"new",
"working",
"one",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L325-L332 |
12,488 | google/badwolf | bql/semantic/hooks.go | whereInitWorkingClause | func whereInitWorkingClause() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
s.ResetWorkingGraphClause()
return f, nil
}
return f
} | go | func whereInitWorkingClause() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
s.ResetWorkingGraphClause()
return f, nil
}
return f
} | [
"func",
"whereInitWorkingClause",
"(",
")",
"ClauseHook",
"{",
"var",
"f",
"ClauseHook",
"\n",
"f",
"=",
"func",
"(",
"s",
"*",
"Statement",
",",
"_",
"Symbol",
")",
"(",
"ClauseHook",
",",
"error",
")",
"{",
"s",
".",
"ResetWorkingGraphClause",
"(",
")",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // whereInitWorkingClause initialize a new working graph clause. | [
"whereInitWorkingClause",
"initialize",
"a",
"new",
"working",
"graph",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L335-L342 |
12,489 | google/badwolf | bql/semantic/hooks.go | whereSubjectClause | func whereSubjectClause() ElementHook {
var (
f ElementHook
lastNopToken *lexer.Token
)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.Token()
c := st.WorkingClause()
switch tkn.Type {
case lexer.ItemNode:
if c.S != nil {
return nil, fmt.Errorf("invalid node in where clause that already has a subject; current %v, got %v", c.S, tkn.Type)
}
n, err := ToNode(ce)
if err != nil {
return nil, err
}
c.S = n
lastNopToken = nil
return f, nil
case lexer.ItemBinding:
if lastNopToken == nil {
if c.SBinding != "" {
return nil, fmt.Errorf("subject binding %q is already set to %q", tkn.Text, c.SBinding)
}
c.SBinding = tkn.Text
lastNopToken = nil
return f, nil
}
if lastNopToken.Type == lexer.ItemAs {
if c.SAlias != "" {
return nil, fmt.Errorf("AS alias binding for subject has already being assigned on %v", st)
}
c.SAlias = tkn.Text
lastNopToken = nil
return f, nil
}
if lastNopToken.Type == lexer.ItemType {
if c.STypeAlias != "" {
return nil, fmt.Errorf("TYPE alias binding for subject has already being assigned on %v", st)
}
c.STypeAlias = tkn.Text
lastNopToken = nil
return f, nil
}
if c.SIDAlias == "" && lastNopToken.Type == lexer.ItemID {
if c.SIDAlias != "" {
return nil, fmt.Errorf("ID alias binding for subject has already being assigned on %v", st)
}
c.SIDAlias = tkn.Text
lastNopToken = nil
return f, nil
}
}
lastNopToken = tkn
return f, nil
}
return f
} | go | func whereSubjectClause() ElementHook {
var (
f ElementHook
lastNopToken *lexer.Token
)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.Token()
c := st.WorkingClause()
switch tkn.Type {
case lexer.ItemNode:
if c.S != nil {
return nil, fmt.Errorf("invalid node in where clause that already has a subject; current %v, got %v", c.S, tkn.Type)
}
n, err := ToNode(ce)
if err != nil {
return nil, err
}
c.S = n
lastNopToken = nil
return f, nil
case lexer.ItemBinding:
if lastNopToken == nil {
if c.SBinding != "" {
return nil, fmt.Errorf("subject binding %q is already set to %q", tkn.Text, c.SBinding)
}
c.SBinding = tkn.Text
lastNopToken = nil
return f, nil
}
if lastNopToken.Type == lexer.ItemAs {
if c.SAlias != "" {
return nil, fmt.Errorf("AS alias binding for subject has already being assigned on %v", st)
}
c.SAlias = tkn.Text
lastNopToken = nil
return f, nil
}
if lastNopToken.Type == lexer.ItemType {
if c.STypeAlias != "" {
return nil, fmt.Errorf("TYPE alias binding for subject has already being assigned on %v", st)
}
c.STypeAlias = tkn.Text
lastNopToken = nil
return f, nil
}
if c.SIDAlias == "" && lastNopToken.Type == lexer.ItemID {
if c.SIDAlias != "" {
return nil, fmt.Errorf("ID alias binding for subject has already being assigned on %v", st)
}
c.SIDAlias = tkn.Text
lastNopToken = nil
return f, nil
}
}
lastNopToken = tkn
return f, nil
}
return f
} | [
"func",
"whereSubjectClause",
"(",
")",
"ElementHook",
"{",
"var",
"(",
"f",
"ElementHook",
"\n",
"lastNopToken",
"*",
"lexer",
".",
"Token",
"\n",
")",
"\n",
"f",
"=",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"{",
"if",
"ce",
".",
"IsSymbol",
"(",
")",
"{",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"tkn",
":=",
"ce",
".",
"Token",
"(",
")",
"\n",
"c",
":=",
"st",
".",
"WorkingClause",
"(",
")",
"\n",
"switch",
"tkn",
".",
"Type",
"{",
"case",
"lexer",
".",
"ItemNode",
":",
"if",
"c",
".",
"S",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"c",
".",
"S",
",",
"tkn",
".",
"Type",
")",
"\n",
"}",
"\n",
"n",
",",
"err",
":=",
"ToNode",
"(",
"ce",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"c",
".",
"S",
"=",
"n",
"\n",
"lastNopToken",
"=",
"nil",
"\n",
"return",
"f",
",",
"nil",
"\n",
"case",
"lexer",
".",
"ItemBinding",
":",
"if",
"lastNopToken",
"==",
"nil",
"{",
"if",
"c",
".",
"SBinding",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Text",
",",
"c",
".",
"SBinding",
")",
"\n",
"}",
"\n",
"c",
".",
"SBinding",
"=",
"tkn",
".",
"Text",
"\n",
"lastNopToken",
"=",
"nil",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"if",
"lastNopToken",
".",
"Type",
"==",
"lexer",
".",
"ItemAs",
"{",
"if",
"c",
".",
"SAlias",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"st",
")",
"\n",
"}",
"\n",
"c",
".",
"SAlias",
"=",
"tkn",
".",
"Text",
"\n",
"lastNopToken",
"=",
"nil",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"if",
"lastNopToken",
".",
"Type",
"==",
"lexer",
".",
"ItemType",
"{",
"if",
"c",
".",
"STypeAlias",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"st",
")",
"\n",
"}",
"\n",
"c",
".",
"STypeAlias",
"=",
"tkn",
".",
"Text",
"\n",
"lastNopToken",
"=",
"nil",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"if",
"c",
".",
"SIDAlias",
"==",
"\"",
"\"",
"&&",
"lastNopToken",
".",
"Type",
"==",
"lexer",
".",
"ItemID",
"{",
"if",
"c",
".",
"SIDAlias",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"st",
")",
"\n",
"}",
"\n",
"c",
".",
"SIDAlias",
"=",
"tkn",
".",
"Text",
"\n",
"lastNopToken",
"=",
"nil",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"lastNopToken",
"=",
"tkn",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // whereSubjectClause returns an element hook that updates the subject
// modifiers on the working graph clause. | [
"whereSubjectClause",
"returns",
"an",
"element",
"hook",
"that",
"updates",
"the",
"subject",
"modifiers",
"on",
"the",
"working",
"graph",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L346-L407 |
12,490 | google/badwolf | bql/semantic/hooks.go | processPredicate | func processPredicate(ce ConsumedElement) (*predicate.Predicate, string, string, bool, error) {
var (
nP *predicate.Predicate
pID string
pAnchorBinding string
temporal bool
)
raw := ce.Token().Text
p, err := predicate.Parse(raw)
if err == nil {
// A fully specified predicate was provided.
nP = p
return nP, pID, pAnchorBinding, nP.Type() == predicate.Temporal, nil
}
// The predicate may have a binding on the anchor.
cmps := predicateRegexp.FindAllStringSubmatch(raw, 2)
if len(cmps) != 1 || (len(cmps) == 1 && len(cmps[0]) != 3) {
return nil, "", "", false, fmt.Errorf("failed to extract partially defined predicate %q, got %v instead", raw, cmps)
}
id, ta := cmps[0][1], cmps[0][2]
pID = id
if ta != "" {
pAnchorBinding = ta
temporal = true
}
return nil, pID, pAnchorBinding, temporal, nil
} | go | func processPredicate(ce ConsumedElement) (*predicate.Predicate, string, string, bool, error) {
var (
nP *predicate.Predicate
pID string
pAnchorBinding string
temporal bool
)
raw := ce.Token().Text
p, err := predicate.Parse(raw)
if err == nil {
// A fully specified predicate was provided.
nP = p
return nP, pID, pAnchorBinding, nP.Type() == predicate.Temporal, nil
}
// The predicate may have a binding on the anchor.
cmps := predicateRegexp.FindAllStringSubmatch(raw, 2)
if len(cmps) != 1 || (len(cmps) == 1 && len(cmps[0]) != 3) {
return nil, "", "", false, fmt.Errorf("failed to extract partially defined predicate %q, got %v instead", raw, cmps)
}
id, ta := cmps[0][1], cmps[0][2]
pID = id
if ta != "" {
pAnchorBinding = ta
temporal = true
}
return nil, pID, pAnchorBinding, temporal, nil
} | [
"func",
"processPredicate",
"(",
"ce",
"ConsumedElement",
")",
"(",
"*",
"predicate",
".",
"Predicate",
",",
"string",
",",
"string",
",",
"bool",
",",
"error",
")",
"{",
"var",
"(",
"nP",
"*",
"predicate",
".",
"Predicate",
"\n",
"pID",
"string",
"\n",
"pAnchorBinding",
"string",
"\n",
"temporal",
"bool",
"\n",
")",
"\n",
"raw",
":=",
"ce",
".",
"Token",
"(",
")",
".",
"Text",
"\n",
"p",
",",
"err",
":=",
"predicate",
".",
"Parse",
"(",
"raw",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"// A fully specified predicate was provided.",
"nP",
"=",
"p",
"\n",
"return",
"nP",
",",
"pID",
",",
"pAnchorBinding",
",",
"nP",
".",
"Type",
"(",
")",
"==",
"predicate",
".",
"Temporal",
",",
"nil",
"\n",
"}",
"\n",
"// The predicate may have a binding on the anchor.",
"cmps",
":=",
"predicateRegexp",
".",
"FindAllStringSubmatch",
"(",
"raw",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"cmps",
")",
"!=",
"1",
"||",
"(",
"len",
"(",
"cmps",
")",
"==",
"1",
"&&",
"len",
"(",
"cmps",
"[",
"0",
"]",
")",
"!=",
"3",
")",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
",",
"cmps",
")",
"\n",
"}",
"\n",
"id",
",",
"ta",
":=",
"cmps",
"[",
"0",
"]",
"[",
"1",
"]",
",",
"cmps",
"[",
"0",
"]",
"[",
"2",
"]",
"\n",
"pID",
"=",
"id",
"\n",
"if",
"ta",
"!=",
"\"",
"\"",
"{",
"pAnchorBinding",
"=",
"ta",
"\n",
"temporal",
"=",
"true",
"\n",
"}",
"\n",
"return",
"nil",
",",
"pID",
",",
"pAnchorBinding",
",",
"temporal",
",",
"nil",
"\n",
"}"
]
| // processPredicate parses a consumed element and returns a predicate and its attributes if possible. | [
"processPredicate",
"parses",
"a",
"consumed",
"element",
"and",
"returns",
"a",
"predicate",
"and",
"its",
"attributes",
"if",
"possible",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L410-L436 |
12,491 | google/badwolf | bql/semantic/hooks.go | processPredicateBound | func processPredicateBound(ce ConsumedElement) (string, string, string, *time.Time, *time.Time, bool, error) {
var (
pID string
pLowerBoundAlias string
pUpperBoundAlias string
pLowerBound *time.Time
pUpperBound *time.Time
)
raw := ce.Token().Text
cmps := boundRegexp.FindAllStringSubmatch(raw, 2)
if len(cmps) != 1 || (len(cmps) == 1 && len(cmps[0]) != 4) {
return "", "", "", nil, nil, false, fmt.Errorf("failed to extract partially defined predicate bound %q, got %v instead", raw, cmps)
}
id, tl, tu := cmps[0][1], cmps[0][2], cmps[0][3]
pID = id
// Lower bound processing.
if strings.Index(tl, "?") != -1 {
pLowerBoundAlias = tl
} else {
stl := strings.TrimSpace(tl)
if stl != "" {
ptl, err := time.Parse(time.RFC3339Nano, stl)
if err != nil {
return "", "", "", nil, nil, false, fmt.Errorf("predicate.Parse failed to parse time anchor %s in %s with error %v", tl, raw, err)
}
pLowerBound = &ptl
}
}
// Lower bound processing.
if strings.Index(tu, "?") != -1 {
pUpperBoundAlias = tu
} else {
stu := strings.TrimSpace(tu)
if stu != "" {
ptu, err := time.Parse(time.RFC3339Nano, stu)
if err != nil {
return "", "", "", nil, nil, false, fmt.Errorf("predicate.Parse failed to parse time anchor %s in %s with error %v", tu, raw, err)
}
pUpperBound = &ptu
}
}
if pLowerBound != nil && pUpperBound != nil {
if pLowerBound.After(*pUpperBound) {
lb, up := pLowerBound.Format(time.RFC3339Nano), pUpperBound.Format(time.RFC3339Nano)
return "", "", "", nil, nil, false, fmt.Errorf("invalid time bound; lower bound %s after upper bound %s", lb, up)
}
}
return pID, pLowerBoundAlias, pUpperBoundAlias, pLowerBound, pUpperBound, true, nil
} | go | func processPredicateBound(ce ConsumedElement) (string, string, string, *time.Time, *time.Time, bool, error) {
var (
pID string
pLowerBoundAlias string
pUpperBoundAlias string
pLowerBound *time.Time
pUpperBound *time.Time
)
raw := ce.Token().Text
cmps := boundRegexp.FindAllStringSubmatch(raw, 2)
if len(cmps) != 1 || (len(cmps) == 1 && len(cmps[0]) != 4) {
return "", "", "", nil, nil, false, fmt.Errorf("failed to extract partially defined predicate bound %q, got %v instead", raw, cmps)
}
id, tl, tu := cmps[0][1], cmps[0][2], cmps[0][3]
pID = id
// Lower bound processing.
if strings.Index(tl, "?") != -1 {
pLowerBoundAlias = tl
} else {
stl := strings.TrimSpace(tl)
if stl != "" {
ptl, err := time.Parse(time.RFC3339Nano, stl)
if err != nil {
return "", "", "", nil, nil, false, fmt.Errorf("predicate.Parse failed to parse time anchor %s in %s with error %v", tl, raw, err)
}
pLowerBound = &ptl
}
}
// Lower bound processing.
if strings.Index(tu, "?") != -1 {
pUpperBoundAlias = tu
} else {
stu := strings.TrimSpace(tu)
if stu != "" {
ptu, err := time.Parse(time.RFC3339Nano, stu)
if err != nil {
return "", "", "", nil, nil, false, fmt.Errorf("predicate.Parse failed to parse time anchor %s in %s with error %v", tu, raw, err)
}
pUpperBound = &ptu
}
}
if pLowerBound != nil && pUpperBound != nil {
if pLowerBound.After(*pUpperBound) {
lb, up := pLowerBound.Format(time.RFC3339Nano), pUpperBound.Format(time.RFC3339Nano)
return "", "", "", nil, nil, false, fmt.Errorf("invalid time bound; lower bound %s after upper bound %s", lb, up)
}
}
return pID, pLowerBoundAlias, pUpperBoundAlias, pLowerBound, pUpperBound, true, nil
} | [
"func",
"processPredicateBound",
"(",
"ce",
"ConsumedElement",
")",
"(",
"string",
",",
"string",
",",
"string",
",",
"*",
"time",
".",
"Time",
",",
"*",
"time",
".",
"Time",
",",
"bool",
",",
"error",
")",
"{",
"var",
"(",
"pID",
"string",
"\n",
"pLowerBoundAlias",
"string",
"\n",
"pUpperBoundAlias",
"string",
"\n",
"pLowerBound",
"*",
"time",
".",
"Time",
"\n",
"pUpperBound",
"*",
"time",
".",
"Time",
"\n",
")",
"\n",
"raw",
":=",
"ce",
".",
"Token",
"(",
")",
".",
"Text",
"\n",
"cmps",
":=",
"boundRegexp",
".",
"FindAllStringSubmatch",
"(",
"raw",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"cmps",
")",
"!=",
"1",
"||",
"(",
"len",
"(",
"cmps",
")",
"==",
"1",
"&&",
"len",
"(",
"cmps",
"[",
"0",
"]",
")",
"!=",
"4",
")",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
",",
"cmps",
")",
"\n",
"}",
"\n",
"id",
",",
"tl",
",",
"tu",
":=",
"cmps",
"[",
"0",
"]",
"[",
"1",
"]",
",",
"cmps",
"[",
"0",
"]",
"[",
"2",
"]",
",",
"cmps",
"[",
"0",
"]",
"[",
"3",
"]",
"\n",
"pID",
"=",
"id",
"\n",
"// Lower bound processing.",
"if",
"strings",
".",
"Index",
"(",
"tl",
",",
"\"",
"\"",
")",
"!=",
"-",
"1",
"{",
"pLowerBoundAlias",
"=",
"tl",
"\n",
"}",
"else",
"{",
"stl",
":=",
"strings",
".",
"TrimSpace",
"(",
"tl",
")",
"\n",
"if",
"stl",
"!=",
"\"",
"\"",
"{",
"ptl",
",",
"err",
":=",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC3339Nano",
",",
"stl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tl",
",",
"raw",
",",
"err",
")",
"\n",
"}",
"\n",
"pLowerBound",
"=",
"&",
"ptl",
"\n",
"}",
"\n",
"}",
"\n",
"// Lower bound processing.",
"if",
"strings",
".",
"Index",
"(",
"tu",
",",
"\"",
"\"",
")",
"!=",
"-",
"1",
"{",
"pUpperBoundAlias",
"=",
"tu",
"\n",
"}",
"else",
"{",
"stu",
":=",
"strings",
".",
"TrimSpace",
"(",
"tu",
")",
"\n",
"if",
"stu",
"!=",
"\"",
"\"",
"{",
"ptu",
",",
"err",
":=",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC3339Nano",
",",
"stu",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tu",
",",
"raw",
",",
"err",
")",
"\n",
"}",
"\n",
"pUpperBound",
"=",
"&",
"ptu",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"pLowerBound",
"!=",
"nil",
"&&",
"pUpperBound",
"!=",
"nil",
"{",
"if",
"pLowerBound",
".",
"After",
"(",
"*",
"pUpperBound",
")",
"{",
"lb",
",",
"up",
":=",
"pLowerBound",
".",
"Format",
"(",
"time",
".",
"RFC3339Nano",
")",
",",
"pUpperBound",
".",
"Format",
"(",
"time",
".",
"RFC3339Nano",
")",
"\n",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"lb",
",",
"up",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"pID",
",",
"pLowerBoundAlias",
",",
"pUpperBoundAlias",
",",
"pLowerBound",
",",
"pUpperBound",
",",
"true",
",",
"nil",
"\n",
"}"
]
| // processPredicate parses a consumed element and returns a bound predicate and its attributes if possible. | [
"processPredicate",
"parses",
"a",
"consumed",
"element",
"and",
"returns",
"a",
"bound",
"predicate",
"and",
"its",
"attributes",
"if",
"possible",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L439-L487 |
12,492 | google/badwolf | bql/semantic/hooks.go | wherePredicateClause | func wherePredicateClause() ElementHook {
var (
f ElementHook
lastNopToken *lexer.Token
)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.Token()
c := st.WorkingClause()
switch tkn.Type {
case lexer.ItemPredicate:
lastNopToken = nil
if c.P != nil {
return nil, fmt.Errorf("invalid predicate %s on graph clause since already set to %s", tkn.Text, c.P)
}
p, pID, pAnchorBinding, pTemporal, err := processPredicate(ce)
if err != nil {
return nil, err
}
c.P, c.PID, c.PAnchorBinding, c.PTemporal = p, pID, pAnchorBinding, pTemporal
return f, nil
case lexer.ItemPredicateBound:
lastNopToken = nil
if c.PLowerBound != nil || c.PUpperBound != nil || c.PLowerBoundAlias != "" || c.PUpperBoundAlias != "" {
return nil, fmt.Errorf("invalid predicate bound %s on graph clause since already set to %s", tkn.Text, c.P)
}
pID, pLowerBoundAlias, pUpperBoundAlias, pLowerBound, pUpperBound, pTemp, err := processPredicateBound(ce)
if err != nil {
return nil, err
}
c.PID, c.PLowerBoundAlias, c.PUpperBoundAlias, c.PLowerBound, c.PUpperBound, c.PTemporal = pID, pLowerBoundAlias, pUpperBoundAlias, pLowerBound, pUpperBound, pTemp
return f, nil
case lexer.ItemBinding:
if lastNopToken == nil {
if c.PBinding != "" {
return nil, fmt.Errorf("invalid binding %q loose after no valid modifier", tkn.Text)
}
c.PBinding = tkn.Text
return f, nil
}
switch lastNopToken.Type {
case lexer.ItemAs:
if c.PAlias != "" {
return nil, fmt.Errorf("AS alias binding for predicate has already being assigned on %v", st)
}
c.PAlias = tkn.Text
case lexer.ItemID:
if c.PIDAlias != "" {
return nil, fmt.Errorf("ID alias binding for predicate has already being assigned on %v", st)
}
c.PIDAlias = tkn.Text
case lexer.ItemAt:
if c.PAnchorAlias != "" {
return nil, fmt.Errorf("AT alias binding for predicate has already being assigned on %v", st)
}
c.PAnchorAlias = tkn.Text
default:
return nil, fmt.Errorf("binding %q found after invalid token %s", tkn.Text, lastNopToken)
}
lastNopToken = nil
return f, nil
}
lastNopToken = tkn
return f, nil
}
return f
} | go | func wherePredicateClause() ElementHook {
var (
f ElementHook
lastNopToken *lexer.Token
)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.Token()
c := st.WorkingClause()
switch tkn.Type {
case lexer.ItemPredicate:
lastNopToken = nil
if c.P != nil {
return nil, fmt.Errorf("invalid predicate %s on graph clause since already set to %s", tkn.Text, c.P)
}
p, pID, pAnchorBinding, pTemporal, err := processPredicate(ce)
if err != nil {
return nil, err
}
c.P, c.PID, c.PAnchorBinding, c.PTemporal = p, pID, pAnchorBinding, pTemporal
return f, nil
case lexer.ItemPredicateBound:
lastNopToken = nil
if c.PLowerBound != nil || c.PUpperBound != nil || c.PLowerBoundAlias != "" || c.PUpperBoundAlias != "" {
return nil, fmt.Errorf("invalid predicate bound %s on graph clause since already set to %s", tkn.Text, c.P)
}
pID, pLowerBoundAlias, pUpperBoundAlias, pLowerBound, pUpperBound, pTemp, err := processPredicateBound(ce)
if err != nil {
return nil, err
}
c.PID, c.PLowerBoundAlias, c.PUpperBoundAlias, c.PLowerBound, c.PUpperBound, c.PTemporal = pID, pLowerBoundAlias, pUpperBoundAlias, pLowerBound, pUpperBound, pTemp
return f, nil
case lexer.ItemBinding:
if lastNopToken == nil {
if c.PBinding != "" {
return nil, fmt.Errorf("invalid binding %q loose after no valid modifier", tkn.Text)
}
c.PBinding = tkn.Text
return f, nil
}
switch lastNopToken.Type {
case lexer.ItemAs:
if c.PAlias != "" {
return nil, fmt.Errorf("AS alias binding for predicate has already being assigned on %v", st)
}
c.PAlias = tkn.Text
case lexer.ItemID:
if c.PIDAlias != "" {
return nil, fmt.Errorf("ID alias binding for predicate has already being assigned on %v", st)
}
c.PIDAlias = tkn.Text
case lexer.ItemAt:
if c.PAnchorAlias != "" {
return nil, fmt.Errorf("AT alias binding for predicate has already being assigned on %v", st)
}
c.PAnchorAlias = tkn.Text
default:
return nil, fmt.Errorf("binding %q found after invalid token %s", tkn.Text, lastNopToken)
}
lastNopToken = nil
return f, nil
}
lastNopToken = tkn
return f, nil
}
return f
} | [
"func",
"wherePredicateClause",
"(",
")",
"ElementHook",
"{",
"var",
"(",
"f",
"ElementHook",
"\n",
"lastNopToken",
"*",
"lexer",
".",
"Token",
"\n",
")",
"\n",
"f",
"=",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"{",
"if",
"ce",
".",
"IsSymbol",
"(",
")",
"{",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"tkn",
":=",
"ce",
".",
"Token",
"(",
")",
"\n",
"c",
":=",
"st",
".",
"WorkingClause",
"(",
")",
"\n",
"switch",
"tkn",
".",
"Type",
"{",
"case",
"lexer",
".",
"ItemPredicate",
":",
"lastNopToken",
"=",
"nil",
"\n",
"if",
"c",
".",
"P",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Text",
",",
"c",
".",
"P",
")",
"\n",
"}",
"\n",
"p",
",",
"pID",
",",
"pAnchorBinding",
",",
"pTemporal",
",",
"err",
":=",
"processPredicate",
"(",
"ce",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"c",
".",
"P",
",",
"c",
".",
"PID",
",",
"c",
".",
"PAnchorBinding",
",",
"c",
".",
"PTemporal",
"=",
"p",
",",
"pID",
",",
"pAnchorBinding",
",",
"pTemporal",
"\n",
"return",
"f",
",",
"nil",
"\n",
"case",
"lexer",
".",
"ItemPredicateBound",
":",
"lastNopToken",
"=",
"nil",
"\n",
"if",
"c",
".",
"PLowerBound",
"!=",
"nil",
"||",
"c",
".",
"PUpperBound",
"!=",
"nil",
"||",
"c",
".",
"PLowerBoundAlias",
"!=",
"\"",
"\"",
"||",
"c",
".",
"PUpperBoundAlias",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Text",
",",
"c",
".",
"P",
")",
"\n",
"}",
"\n",
"pID",
",",
"pLowerBoundAlias",
",",
"pUpperBoundAlias",
",",
"pLowerBound",
",",
"pUpperBound",
",",
"pTemp",
",",
"err",
":=",
"processPredicateBound",
"(",
"ce",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"c",
".",
"PID",
",",
"c",
".",
"PLowerBoundAlias",
",",
"c",
".",
"PUpperBoundAlias",
",",
"c",
".",
"PLowerBound",
",",
"c",
".",
"PUpperBound",
",",
"c",
".",
"PTemporal",
"=",
"pID",
",",
"pLowerBoundAlias",
",",
"pUpperBoundAlias",
",",
"pLowerBound",
",",
"pUpperBound",
",",
"pTemp",
"\n",
"return",
"f",
",",
"nil",
"\n",
"case",
"lexer",
".",
"ItemBinding",
":",
"if",
"lastNopToken",
"==",
"nil",
"{",
"if",
"c",
".",
"PBinding",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Text",
")",
"\n",
"}",
"\n",
"c",
".",
"PBinding",
"=",
"tkn",
".",
"Text",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"switch",
"lastNopToken",
".",
"Type",
"{",
"case",
"lexer",
".",
"ItemAs",
":",
"if",
"c",
".",
"PAlias",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"st",
")",
"\n",
"}",
"\n",
"c",
".",
"PAlias",
"=",
"tkn",
".",
"Text",
"\n",
"case",
"lexer",
".",
"ItemID",
":",
"if",
"c",
".",
"PIDAlias",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"st",
")",
"\n",
"}",
"\n",
"c",
".",
"PIDAlias",
"=",
"tkn",
".",
"Text",
"\n",
"case",
"lexer",
".",
"ItemAt",
":",
"if",
"c",
".",
"PAnchorAlias",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"st",
")",
"\n",
"}",
"\n",
"c",
".",
"PAnchorAlias",
"=",
"tkn",
".",
"Text",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Text",
",",
"lastNopToken",
")",
"\n",
"}",
"\n",
"lastNopToken",
"=",
"nil",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"lastNopToken",
"=",
"tkn",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // wherePredicateClause returns an element hook that updates the predicate
// modifiers on the working graph clause. | [
"wherePredicateClause",
"returns",
"an",
"element",
"hook",
"that",
"updates",
"the",
"predicate",
"modifiers",
"on",
"the",
"working",
"graph",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L491-L559 |
12,493 | google/badwolf | bql/semantic/hooks.go | varAccumulator | func varAccumulator() ElementHook {
var (
lastNopToken *lexer.Token
f func(st *Statement, ce ConsumedElement) (ElementHook, error)
)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.Token()
p := st.WorkingProjection()
switch tkn.Type {
case lexer.ItemBinding:
if p.Binding == "" {
p.Binding = tkn.Text
} else {
if lastNopToken != nil && lastNopToken.Type == lexer.ItemAs {
p.Alias = tkn.Text
lastNopToken = nil
st.AddWorkingProjection()
} else {
return nil, fmt.Errorf("invalid token %s for variable projection %s", tkn.Type, p)
}
}
case lexer.ItemAs:
lastNopToken = tkn
case lexer.ItemSum, lexer.ItemCount:
p.OP = tkn.Type
case lexer.ItemDistinct:
p.Modifier = tkn.Type
case lexer.ItemComma:
st.AddWorkingProjection()
default:
lastNopToken = nil
}
return f, nil
}
return f
} | go | func varAccumulator() ElementHook {
var (
lastNopToken *lexer.Token
f func(st *Statement, ce ConsumedElement) (ElementHook, error)
)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.Token()
p := st.WorkingProjection()
switch tkn.Type {
case lexer.ItemBinding:
if p.Binding == "" {
p.Binding = tkn.Text
} else {
if lastNopToken != nil && lastNopToken.Type == lexer.ItemAs {
p.Alias = tkn.Text
lastNopToken = nil
st.AddWorkingProjection()
} else {
return nil, fmt.Errorf("invalid token %s for variable projection %s", tkn.Type, p)
}
}
case lexer.ItemAs:
lastNopToken = tkn
case lexer.ItemSum, lexer.ItemCount:
p.OP = tkn.Type
case lexer.ItemDistinct:
p.Modifier = tkn.Type
case lexer.ItemComma:
st.AddWorkingProjection()
default:
lastNopToken = nil
}
return f, nil
}
return f
} | [
"func",
"varAccumulator",
"(",
")",
"ElementHook",
"{",
"var",
"(",
"lastNopToken",
"*",
"lexer",
".",
"Token",
"\n",
"f",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"\n",
")",
"\n",
"f",
"=",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"{",
"if",
"ce",
".",
"IsSymbol",
"(",
")",
"{",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"tkn",
":=",
"ce",
".",
"Token",
"(",
")",
"\n",
"p",
":=",
"st",
".",
"WorkingProjection",
"(",
")",
"\n",
"switch",
"tkn",
".",
"Type",
"{",
"case",
"lexer",
".",
"ItemBinding",
":",
"if",
"p",
".",
"Binding",
"==",
"\"",
"\"",
"{",
"p",
".",
"Binding",
"=",
"tkn",
".",
"Text",
"\n",
"}",
"else",
"{",
"if",
"lastNopToken",
"!=",
"nil",
"&&",
"lastNopToken",
".",
"Type",
"==",
"lexer",
".",
"ItemAs",
"{",
"p",
".",
"Alias",
"=",
"tkn",
".",
"Text",
"\n",
"lastNopToken",
"=",
"nil",
"\n",
"st",
".",
"AddWorkingProjection",
"(",
")",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Type",
",",
"p",
")",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"lexer",
".",
"ItemAs",
":",
"lastNopToken",
"=",
"tkn",
"\n",
"case",
"lexer",
".",
"ItemSum",
",",
"lexer",
".",
"ItemCount",
":",
"p",
".",
"OP",
"=",
"tkn",
".",
"Type",
"\n",
"case",
"lexer",
".",
"ItemDistinct",
":",
"p",
".",
"Modifier",
"=",
"tkn",
".",
"Type",
"\n",
"case",
"lexer",
".",
"ItemComma",
":",
"st",
".",
"AddWorkingProjection",
"(",
")",
"\n",
"default",
":",
"lastNopToken",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // varAccumulator returns an element hook that updates the object
// modifiers on the working graph clause. | [
"varAccumulator",
"returns",
"an",
"element",
"hook",
"that",
"updates",
"the",
"object",
"modifiers",
"on",
"the",
"working",
"graph",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L659-L697 |
12,494 | google/badwolf | bql/semantic/hooks.go | bindingsGraphChecker | func bindingsGraphChecker() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
// Force working projection flush.
s.AddWorkingProjection()
bs := s.BindingsMap()
for _, b := range s.InputBindings() {
if _, ok := bs[b]; !ok {
return nil, fmt.Errorf("specified binding %s not found in where clause, only %v bindings are available", b, s.Bindings())
}
}
return f, nil
}
return f
} | go | func bindingsGraphChecker() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
// Force working projection flush.
s.AddWorkingProjection()
bs := s.BindingsMap()
for _, b := range s.InputBindings() {
if _, ok := bs[b]; !ok {
return nil, fmt.Errorf("specified binding %s not found in where clause, only %v bindings are available", b, s.Bindings())
}
}
return f, nil
}
return f
} | [
"func",
"bindingsGraphChecker",
"(",
")",
"ClauseHook",
"{",
"var",
"f",
"ClauseHook",
"\n",
"f",
"=",
"func",
"(",
"s",
"*",
"Statement",
",",
"_",
"Symbol",
")",
"(",
"ClauseHook",
",",
"error",
")",
"{",
"// Force working projection flush.",
"s",
".",
"AddWorkingProjection",
"(",
")",
"\n",
"bs",
":=",
"s",
".",
"BindingsMap",
"(",
")",
"\n",
"for",
"_",
",",
"b",
":=",
"range",
"s",
".",
"InputBindings",
"(",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"bs",
"[",
"b",
"]",
";",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"b",
",",
"s",
".",
"Bindings",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // bindingsGraphChecker validate that all input bindings are provided by the
// graph pattern. | [
"bindingsGraphChecker",
"validate",
"that",
"all",
"input",
"bindings",
"are",
"provided",
"by",
"the",
"graph",
"pattern",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L701-L715 |
12,495 | google/badwolf | bql/semantic/hooks.go | groupByBindings | func groupByBindings() ElementHook {
var f func(st *Statement, ce ConsumedElement) (ElementHook, error)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.Token()
if tkn.Type == lexer.ItemBinding {
st.groupBy = append(st.groupBy, tkn.Text)
}
return f, nil
}
return f
} | go | func groupByBindings() ElementHook {
var f func(st *Statement, ce ConsumedElement) (ElementHook, error)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.Token()
if tkn.Type == lexer.ItemBinding {
st.groupBy = append(st.groupBy, tkn.Text)
}
return f, nil
}
return f
} | [
"func",
"groupByBindings",
"(",
")",
"ElementHook",
"{",
"var",
"f",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"\n",
"f",
"=",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"{",
"if",
"ce",
".",
"IsSymbol",
"(",
")",
"{",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"tkn",
":=",
"ce",
".",
"Token",
"(",
")",
"\n",
"if",
"tkn",
".",
"Type",
"==",
"lexer",
".",
"ItemBinding",
"{",
"st",
".",
"groupBy",
"=",
"append",
"(",
"st",
".",
"groupBy",
",",
"tkn",
".",
"Text",
")",
"\n",
"}",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // groupByBindings collects the bindings listed in the group by clause. | [
"groupByBindings",
"collects",
"the",
"bindings",
"listed",
"in",
"the",
"group",
"by",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L718-L731 |
12,496 | google/badwolf | bql/semantic/hooks.go | groupByBindingsChecker | func groupByBindingsChecker() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
// Force working projection flush.
var idxs map[int]bool
idxs = make(map[int]bool)
for _, gb := range s.groupBy {
found := false
for idx, prj := range s.projection {
if gb == prj.Alias || (prj.Alias == "" && gb == prj.Binding) {
if prj.OP != lexer.ItemError || prj.Modifier != lexer.ItemError {
return nil, fmt.Errorf("GROUP BY %s binding cannot refer to an aggregation function", gb)
}
idxs[idx] = true
found = true
}
}
if !found {
return nil, fmt.Errorf("invalid GROUP BY binging %s; available bindings %v", gb, s.OutputBindings())
}
}
for idx, prj := range s.projection {
if idxs[idx] {
continue
}
if len(s.groupBy) > 0 && prj.OP == lexer.ItemError {
return nil, fmt.Errorf("Binding %q not listed on GROUP BY requires an aggregation function", prj.Binding)
}
if len(s.groupBy) == 0 && prj.OP != lexer.ItemError {
s := prj.Alias
if s == "" {
s = prj.Binding
}
return nil, fmt.Errorf("Binding %q with aggregation %s function requires GROUP BY clause", s, prj.OP)
}
}
return f, nil
}
return f
} | go | func groupByBindingsChecker() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
// Force working projection flush.
var idxs map[int]bool
idxs = make(map[int]bool)
for _, gb := range s.groupBy {
found := false
for idx, prj := range s.projection {
if gb == prj.Alias || (prj.Alias == "" && gb == prj.Binding) {
if prj.OP != lexer.ItemError || prj.Modifier != lexer.ItemError {
return nil, fmt.Errorf("GROUP BY %s binding cannot refer to an aggregation function", gb)
}
idxs[idx] = true
found = true
}
}
if !found {
return nil, fmt.Errorf("invalid GROUP BY binging %s; available bindings %v", gb, s.OutputBindings())
}
}
for idx, prj := range s.projection {
if idxs[idx] {
continue
}
if len(s.groupBy) > 0 && prj.OP == lexer.ItemError {
return nil, fmt.Errorf("Binding %q not listed on GROUP BY requires an aggregation function", prj.Binding)
}
if len(s.groupBy) == 0 && prj.OP != lexer.ItemError {
s := prj.Alias
if s == "" {
s = prj.Binding
}
return nil, fmt.Errorf("Binding %q with aggregation %s function requires GROUP BY clause", s, prj.OP)
}
}
return f, nil
}
return f
} | [
"func",
"groupByBindingsChecker",
"(",
")",
"ClauseHook",
"{",
"var",
"f",
"ClauseHook",
"\n",
"f",
"=",
"func",
"(",
"s",
"*",
"Statement",
",",
"_",
"Symbol",
")",
"(",
"ClauseHook",
",",
"error",
")",
"{",
"// Force working projection flush.",
"var",
"idxs",
"map",
"[",
"int",
"]",
"bool",
"\n",
"idxs",
"=",
"make",
"(",
"map",
"[",
"int",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"gb",
":=",
"range",
"s",
".",
"groupBy",
"{",
"found",
":=",
"false",
"\n",
"for",
"idx",
",",
"prj",
":=",
"range",
"s",
".",
"projection",
"{",
"if",
"gb",
"==",
"prj",
".",
"Alias",
"||",
"(",
"prj",
".",
"Alias",
"==",
"\"",
"\"",
"&&",
"gb",
"==",
"prj",
".",
"Binding",
")",
"{",
"if",
"prj",
".",
"OP",
"!=",
"lexer",
".",
"ItemError",
"||",
"prj",
".",
"Modifier",
"!=",
"lexer",
".",
"ItemError",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"gb",
")",
"\n",
"}",
"\n",
"idxs",
"[",
"idx",
"]",
"=",
"true",
"\n",
"found",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"gb",
",",
"s",
".",
"OutputBindings",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"idx",
",",
"prj",
":=",
"range",
"s",
".",
"projection",
"{",
"if",
"idxs",
"[",
"idx",
"]",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"len",
"(",
"s",
".",
"groupBy",
")",
">",
"0",
"&&",
"prj",
".",
"OP",
"==",
"lexer",
".",
"ItemError",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"prj",
".",
"Binding",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"s",
".",
"groupBy",
")",
"==",
"0",
"&&",
"prj",
".",
"OP",
"!=",
"lexer",
".",
"ItemError",
"{",
"s",
":=",
"prj",
".",
"Alias",
"\n",
"if",
"s",
"==",
"\"",
"\"",
"{",
"s",
"=",
"prj",
".",
"Binding",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
",",
"prj",
".",
"OP",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // groupByBindingsChecker checks that all group by bindings are valid output
// bindings. | [
"groupByBindingsChecker",
"checks",
"that",
"all",
"group",
"by",
"bindings",
"are",
"valid",
"output",
"bindings",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L735-L774 |
12,497 | google/badwolf | bql/semantic/hooks.go | orderByBindings | func orderByBindings() ElementHook {
var f func(st *Statement, ce ConsumedElement) (ElementHook, error)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.Token()
switch tkn.Type {
case lexer.ItemBinding:
st.orderBy = append(st.orderBy, table.SortConfig{{Binding: tkn.Text}}...)
case lexer.ItemAsc:
st.orderBy[len(st.orderBy)-1].Desc = false
case lexer.ItemDesc:
st.orderBy[len(st.orderBy)-1].Desc = true
}
return f, nil
}
return f
} | go | func orderByBindings() ElementHook {
var f func(st *Statement, ce ConsumedElement) (ElementHook, error)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.Token()
switch tkn.Type {
case lexer.ItemBinding:
st.orderBy = append(st.orderBy, table.SortConfig{{Binding: tkn.Text}}...)
case lexer.ItemAsc:
st.orderBy[len(st.orderBy)-1].Desc = false
case lexer.ItemDesc:
st.orderBy[len(st.orderBy)-1].Desc = true
}
return f, nil
}
return f
} | [
"func",
"orderByBindings",
"(",
")",
"ElementHook",
"{",
"var",
"f",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"\n",
"f",
"=",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"{",
"if",
"ce",
".",
"IsSymbol",
"(",
")",
"{",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"tkn",
":=",
"ce",
".",
"Token",
"(",
")",
"\n",
"switch",
"tkn",
".",
"Type",
"{",
"case",
"lexer",
".",
"ItemBinding",
":",
"st",
".",
"orderBy",
"=",
"append",
"(",
"st",
".",
"orderBy",
",",
"table",
".",
"SortConfig",
"{",
"{",
"Binding",
":",
"tkn",
".",
"Text",
"}",
"}",
"...",
")",
"\n",
"case",
"lexer",
".",
"ItemAsc",
":",
"st",
".",
"orderBy",
"[",
"len",
"(",
"st",
".",
"orderBy",
")",
"-",
"1",
"]",
".",
"Desc",
"=",
"false",
"\n",
"case",
"lexer",
".",
"ItemDesc",
":",
"st",
".",
"orderBy",
"[",
"len",
"(",
"st",
".",
"orderBy",
")",
"-",
"1",
"]",
".",
"Desc",
"=",
"true",
"\n",
"}",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // orderByBindings collects the bindings listed in the order by clause. | [
"orderByBindings",
"collects",
"the",
"bindings",
"listed",
"in",
"the",
"order",
"by",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L777-L795 |
12,498 | google/badwolf | bql/semantic/hooks.go | orderByBindingsChecker | func orderByBindingsChecker() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
// Force working projection flush.
outs := make(map[string]bool)
for _, out := range s.OutputBindings() {
outs[out] = true
}
seen, dups := make(map[string]bool), false
for _, cfg := range s.orderBy {
// Check there are no contradictions
if b, ok := seen[cfg.Binding]; ok {
if b != cfg.Desc {
return nil, fmt.Errorf("inconsisting sorting direction for %q binding", cfg.Binding)
}
dups = true
} else {
seen[cfg.Binding] = cfg.Desc
}
// Check that the binding exist.
if _, ok := outs[cfg.Binding]; !ok {
return nil, fmt.Errorf("order by binding %q unknown; available bindings are %v", cfg.Binding, s.OutputBindings())
}
}
// If dups exist rewrite the order by SortConfig.
if dups {
s.orderBy = table.SortConfig{}
for b, d := range seen {
s.orderBy = append(s.orderBy, table.SortConfig{{Binding: b, Desc: d}}...)
}
}
return f, nil
}
return f
} | go | func orderByBindingsChecker() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
// Force working projection flush.
outs := make(map[string]bool)
for _, out := range s.OutputBindings() {
outs[out] = true
}
seen, dups := make(map[string]bool), false
for _, cfg := range s.orderBy {
// Check there are no contradictions
if b, ok := seen[cfg.Binding]; ok {
if b != cfg.Desc {
return nil, fmt.Errorf("inconsisting sorting direction for %q binding", cfg.Binding)
}
dups = true
} else {
seen[cfg.Binding] = cfg.Desc
}
// Check that the binding exist.
if _, ok := outs[cfg.Binding]; !ok {
return nil, fmt.Errorf("order by binding %q unknown; available bindings are %v", cfg.Binding, s.OutputBindings())
}
}
// If dups exist rewrite the order by SortConfig.
if dups {
s.orderBy = table.SortConfig{}
for b, d := range seen {
s.orderBy = append(s.orderBy, table.SortConfig{{Binding: b, Desc: d}}...)
}
}
return f, nil
}
return f
} | [
"func",
"orderByBindingsChecker",
"(",
")",
"ClauseHook",
"{",
"var",
"f",
"ClauseHook",
"\n",
"f",
"=",
"func",
"(",
"s",
"*",
"Statement",
",",
"_",
"Symbol",
")",
"(",
"ClauseHook",
",",
"error",
")",
"{",
"// Force working projection flush.",
"outs",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"out",
":=",
"range",
"s",
".",
"OutputBindings",
"(",
")",
"{",
"outs",
"[",
"out",
"]",
"=",
"true",
"\n",
"}",
"\n",
"seen",
",",
"dups",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
",",
"false",
"\n",
"for",
"_",
",",
"cfg",
":=",
"range",
"s",
".",
"orderBy",
"{",
"// Check there are no contradictions",
"if",
"b",
",",
"ok",
":=",
"seen",
"[",
"cfg",
".",
"Binding",
"]",
";",
"ok",
"{",
"if",
"b",
"!=",
"cfg",
".",
"Desc",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cfg",
".",
"Binding",
")",
"\n",
"}",
"\n",
"dups",
"=",
"true",
"\n",
"}",
"else",
"{",
"seen",
"[",
"cfg",
".",
"Binding",
"]",
"=",
"cfg",
".",
"Desc",
"\n",
"}",
"\n",
"// Check that the binding exist.",
"if",
"_",
",",
"ok",
":=",
"outs",
"[",
"cfg",
".",
"Binding",
"]",
";",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cfg",
".",
"Binding",
",",
"s",
".",
"OutputBindings",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// If dups exist rewrite the order by SortConfig.",
"if",
"dups",
"{",
"s",
".",
"orderBy",
"=",
"table",
".",
"SortConfig",
"{",
"}",
"\n",
"for",
"b",
",",
"d",
":=",
"range",
"seen",
"{",
"s",
".",
"orderBy",
"=",
"append",
"(",
"s",
".",
"orderBy",
",",
"table",
".",
"SortConfig",
"{",
"{",
"Binding",
":",
"b",
",",
"Desc",
":",
"d",
"}",
"}",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // orderByBindingsChecker checks that all order by bindings are valid output
// bindings. | [
"orderByBindingsChecker",
"checks",
"that",
"all",
"order",
"by",
"bindings",
"are",
"valid",
"output",
"bindings",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L799-L833 |
12,499 | google/badwolf | bql/semantic/hooks.go | havingExpression | func havingExpression() ElementHook {
var f func(st *Statement, ce ConsumedElement) (ElementHook, error)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
if ce.token.Type != lexer.ItemHaving {
st.havingExpression = append(st.havingExpression, ce)
}
return f, nil
}
return f
} | go | func havingExpression() ElementHook {
var f func(st *Statement, ce ConsumedElement) (ElementHook, error)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
if ce.token.Type != lexer.ItemHaving {
st.havingExpression = append(st.havingExpression, ce)
}
return f, nil
}
return f
} | [
"func",
"havingExpression",
"(",
")",
"ElementHook",
"{",
"var",
"f",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"\n",
"f",
"=",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"{",
"if",
"ce",
".",
"IsSymbol",
"(",
")",
"{",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"if",
"ce",
".",
"token",
".",
"Type",
"!=",
"lexer",
".",
"ItemHaving",
"{",
"st",
".",
"havingExpression",
"=",
"append",
"(",
"st",
".",
"havingExpression",
",",
"ce",
")",
"\n",
"}",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // havingExpression collects the tokens that form the HAVING clause. | [
"havingExpression",
"collects",
"the",
"tokens",
"that",
"form",
"the",
"HAVING",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L836-L848 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.