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,500 | google/badwolf | bql/semantic/hooks.go | havingExpressionBuilder | func havingExpressionBuilder() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
s.havingExpressionEvaluator = &AlwaysReturn{V: true}
if len(s.havingExpression) > 0 {
eval, err := NewEvaluator(s.havingExpression)
if err != nil {
return nil, err
}
s.havingExpressionEvaluator = eval
}
return f, nil
}
return f
} | go | func havingExpressionBuilder() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
s.havingExpressionEvaluator = &AlwaysReturn{V: true}
if len(s.havingExpression) > 0 {
eval, err := NewEvaluator(s.havingExpression)
if err != nil {
return nil, err
}
s.havingExpressionEvaluator = eval
}
return f, nil
}
return f
} | [
"func",
"havingExpressionBuilder",
"(",
")",
"ClauseHook",
"{",
"var",
"f",
"ClauseHook",
"\n",
"f",
"=",
"func",
"(",
"s",
"*",
"Statement",
",",
"_",
"Symbol",
")",
"(",
"ClauseHook",
",",
"error",
")",
"{",
"s",
".",
"havingExpressionEvaluator",
"=",
"&",
"AlwaysReturn",
"{",
"V",
":",
"true",
"}",
"\n",
"if",
"len",
"(",
"s",
".",
"havingExpression",
")",
">",
"0",
"{",
"eval",
",",
"err",
":=",
"NewEvaluator",
"(",
"s",
".",
"havingExpression",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"s",
".",
"havingExpressionEvaluator",
"=",
"eval",
"\n",
"}",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // havingExpressionBuilder given the collected tokens that forms the having
// clause expression, it builds the expression to use when filtering values
// on the final result table. | [
"havingExpressionBuilder",
"given",
"the",
"collected",
"tokens",
"that",
"forms",
"the",
"having",
"clause",
"expression",
"it",
"builds",
"the",
"expression",
"to",
"use",
"when",
"filtering",
"values",
"on",
"the",
"final",
"result",
"table",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L853-L867 |
12,501 | google/badwolf | bql/semantic/hooks.go | limitCollection | func limitCollection() ElementHook {
var f func(st *Statement, ce ConsumedElement) (ElementHook, error)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() || ce.token.Type == lexer.ItemLimit {
return f, nil
}
if ce.token.Type != lexer.ItemLiteral {
return nil, fmt.Errorf("limit clause required an int64 literal; found %v instead", ce.token)
}
l, err := literal.DefaultBuilder().Parse(ce.token.Text)
if err != nil {
return nil, fmt.Errorf("failed to parse limit literal %q with error %v", ce.token.Text, err)
}
if l.Type() != literal.Int64 {
return nil, fmt.Errorf("limit required an int64 value; found %s instead", l)
}
lv, err := l.Int64()
if err != nil {
return nil, fmt.Errorf("failed to retrieve the int64 value for literal %v with error %v", l, err)
}
st.limitSet, st.limit = true, lv
return f, nil
}
return f
} | go | func limitCollection() ElementHook {
var f func(st *Statement, ce ConsumedElement) (ElementHook, error)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() || ce.token.Type == lexer.ItemLimit {
return f, nil
}
if ce.token.Type != lexer.ItemLiteral {
return nil, fmt.Errorf("limit clause required an int64 literal; found %v instead", ce.token)
}
l, err := literal.DefaultBuilder().Parse(ce.token.Text)
if err != nil {
return nil, fmt.Errorf("failed to parse limit literal %q with error %v", ce.token.Text, err)
}
if l.Type() != literal.Int64 {
return nil, fmt.Errorf("limit required an int64 value; found %s instead", l)
}
lv, err := l.Int64()
if err != nil {
return nil, fmt.Errorf("failed to retrieve the int64 value for literal %v with error %v", l, err)
}
st.limitSet, st.limit = true, lv
return f, nil
}
return f
} | [
"func",
"limitCollection",
"(",
")",
"ElementHook",
"{",
"var",
"f",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"\n",
"f",
"=",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"{",
"if",
"ce",
".",
"IsSymbol",
"(",
")",
"||",
"ce",
".",
"token",
".",
"Type",
"==",
"lexer",
".",
"ItemLimit",
"{",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"if",
"ce",
".",
"token",
".",
"Type",
"!=",
"lexer",
".",
"ItemLiteral",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ce",
".",
"token",
")",
"\n",
"}",
"\n",
"l",
",",
"err",
":=",
"literal",
".",
"DefaultBuilder",
"(",
")",
".",
"Parse",
"(",
"ce",
".",
"token",
".",
"Text",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ce",
".",
"token",
".",
"Text",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"l",
".",
"Type",
"(",
")",
"!=",
"literal",
".",
"Int64",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"l",
")",
"\n",
"}",
"\n",
"lv",
",",
"err",
":=",
"l",
".",
"Int64",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"l",
",",
"err",
")",
"\n",
"}",
"\n",
"st",
".",
"limitSet",
",",
"st",
".",
"limit",
"=",
"true",
",",
"lv",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // limitCollection collects the limit of rows to return as indicated by the
// LIMIT clause. | [
"limitCollection",
"collects",
"the",
"limit",
"of",
"rows",
"to",
"return",
"as",
"indicated",
"by",
"the",
"LIMIT",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L871-L895 |
12,502 | google/badwolf | bql/semantic/hooks.go | collectGlobalBounds | func collectGlobalBounds() ElementHook {
var (
f func(st *Statement, ce ConsumedElement) (ElementHook, error)
opToken *lexer.Token
lastToken *lexer.Token
)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.token
switch tkn.Type {
case lexer.ItemBefore, lexer.ItemAfter, lexer.ItemBetween:
if lastToken != nil {
return nil, fmt.Errorf("invalid token %v after already valid token %v", tkn, lastToken)
}
opToken, lastToken = tkn, tkn
case lexer.ItemComma:
if lastToken == nil || opToken.Type != lexer.ItemBetween {
return nil, fmt.Errorf("token %v can only be used in a between clause; previous token %v instead", tkn, lastToken)
}
lastToken = tkn
case lexer.ItemPredicate:
if lastToken == nil {
return nil, fmt.Errorf("invalid token %v without a global time modifier", tkn)
}
p, err := predicate.Parse(tkn.Text)
if err != nil {
return nil, err
}
if p.ID() != "" {
return nil, fmt.Errorf("global time bounds do not accept individual predicate IDs; found %s instead", p)
}
ta, err := p.TimeAnchor()
if err != nil {
return nil, err
}
if lastToken.Type == lexer.ItemComma || lastToken.Type == lexer.ItemBefore {
st.lookupOptions.UpperAnchor = ta
opToken, lastToken = nil, nil
} else {
st.lookupOptions.LowerAnchor = ta
if opToken.Type != lexer.ItemBetween {
opToken, lastToken = nil, nil
}
}
default:
return nil, fmt.Errorf("global bound found unexpected token %v", tkn)
}
return f, nil
}
return f
} | go | func collectGlobalBounds() ElementHook {
var (
f func(st *Statement, ce ConsumedElement) (ElementHook, error)
opToken *lexer.Token
lastToken *lexer.Token
)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.token
switch tkn.Type {
case lexer.ItemBefore, lexer.ItemAfter, lexer.ItemBetween:
if lastToken != nil {
return nil, fmt.Errorf("invalid token %v after already valid token %v", tkn, lastToken)
}
opToken, lastToken = tkn, tkn
case lexer.ItemComma:
if lastToken == nil || opToken.Type != lexer.ItemBetween {
return nil, fmt.Errorf("token %v can only be used in a between clause; previous token %v instead", tkn, lastToken)
}
lastToken = tkn
case lexer.ItemPredicate:
if lastToken == nil {
return nil, fmt.Errorf("invalid token %v without a global time modifier", tkn)
}
p, err := predicate.Parse(tkn.Text)
if err != nil {
return nil, err
}
if p.ID() != "" {
return nil, fmt.Errorf("global time bounds do not accept individual predicate IDs; found %s instead", p)
}
ta, err := p.TimeAnchor()
if err != nil {
return nil, err
}
if lastToken.Type == lexer.ItemComma || lastToken.Type == lexer.ItemBefore {
st.lookupOptions.UpperAnchor = ta
opToken, lastToken = nil, nil
} else {
st.lookupOptions.LowerAnchor = ta
if opToken.Type != lexer.ItemBetween {
opToken, lastToken = nil, nil
}
}
default:
return nil, fmt.Errorf("global bound found unexpected token %v", tkn)
}
return f, nil
}
return f
} | [
"func",
"collectGlobalBounds",
"(",
")",
"ElementHook",
"{",
"var",
"(",
"f",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"\n",
"opToken",
"*",
"lexer",
".",
"Token",
"\n",
"lastToken",
"*",
"lexer",
".",
"Token",
"\n",
")",
"\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",
".",
"ItemBefore",
",",
"lexer",
".",
"ItemAfter",
",",
"lexer",
".",
"ItemBetween",
":",
"if",
"lastToken",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
",",
"lastToken",
")",
"\n",
"}",
"\n",
"opToken",
",",
"lastToken",
"=",
"tkn",
",",
"tkn",
"\n",
"case",
"lexer",
".",
"ItemComma",
":",
"if",
"lastToken",
"==",
"nil",
"||",
"opToken",
".",
"Type",
"!=",
"lexer",
".",
"ItemBetween",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
",",
"lastToken",
")",
"\n",
"}",
"\n",
"lastToken",
"=",
"tkn",
"\n",
"case",
"lexer",
".",
"ItemPredicate",
":",
"if",
"lastToken",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
")",
"\n",
"}",
"\n",
"p",
",",
"err",
":=",
"predicate",
".",
"Parse",
"(",
"tkn",
".",
"Text",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"p",
".",
"ID",
"(",
")",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"p",
")",
"\n",
"}",
"\n",
"ta",
",",
"err",
":=",
"p",
".",
"TimeAnchor",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"lastToken",
".",
"Type",
"==",
"lexer",
".",
"ItemComma",
"||",
"lastToken",
".",
"Type",
"==",
"lexer",
".",
"ItemBefore",
"{",
"st",
".",
"lookupOptions",
".",
"UpperAnchor",
"=",
"ta",
"\n",
"opToken",
",",
"lastToken",
"=",
"nil",
",",
"nil",
"\n",
"}",
"else",
"{",
"st",
".",
"lookupOptions",
".",
"LowerAnchor",
"=",
"ta",
"\n",
"if",
"opToken",
".",
"Type",
"!=",
"lexer",
".",
"ItemBetween",
"{",
"opToken",
",",
"lastToken",
"=",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
")",
"\n",
"}",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // collectGlobalBounds collects the global time bounds that should be applied
// to all temporal predicates. | [
"collectGlobalBounds",
"collects",
"the",
"global",
"time",
"bounds",
"that",
"should",
"be",
"applied",
"to",
"all",
"temporal",
"predicates",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L899-L951 |
12,503 | google/badwolf | bql/semantic/hooks.go | InitWorkingConstructClause | func InitWorkingConstructClause() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
s.ResetWorkingConstructClause()
return f, nil
}
return f
} | go | func InitWorkingConstructClause() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
s.ResetWorkingConstructClause()
return f, nil
}
return f
} | [
"func",
"InitWorkingConstructClause",
"(",
")",
"ClauseHook",
"{",
"var",
"f",
"ClauseHook",
"\n",
"f",
"=",
"func",
"(",
"s",
"*",
"Statement",
",",
"_",
"Symbol",
")",
"(",
"ClauseHook",
",",
"error",
")",
"{",
"s",
".",
"ResetWorkingConstructClause",
"(",
")",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // InitWorkingConstructClause returns a clause hook to initialize a new working
// construct clause. | [
"InitWorkingConstructClause",
"returns",
"a",
"clause",
"hook",
"to",
"initialize",
"a",
"new",
"working",
"construct",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L955-L962 |
12,504 | google/badwolf | bql/semantic/hooks.go | NextWorkingConstructClause | func NextWorkingConstructClause() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
s.AddWorkingConstructClause()
return f, nil
}
return f
} | go | func NextWorkingConstructClause() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
s.AddWorkingConstructClause()
return f, nil
}
return f
} | [
"func",
"NextWorkingConstructClause",
"(",
")",
"ClauseHook",
"{",
"var",
"f",
"ClauseHook",
"\n",
"f",
"=",
"func",
"(",
"s",
"*",
"Statement",
",",
"_",
"Symbol",
")",
"(",
"ClauseHook",
",",
"error",
")",
"{",
"s",
".",
"AddWorkingConstructClause",
"(",
")",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // NextWorkingConstructClause returns a clause hook to close the current working
// construct clause and start a new working construct clause. | [
"NextWorkingConstructClause",
"returns",
"a",
"clause",
"hook",
"to",
"close",
"the",
"current",
"working",
"construct",
"clause",
"and",
"start",
"a",
"new",
"working",
"construct",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L966-L973 |
12,505 | google/badwolf | bql/semantic/hooks.go | constructSubject | func constructSubject() ElementHook {
var f ElementHook
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.Token()
c := st.WorkingConstructClause()
if c.S != nil {
return nil, fmt.Errorf("invalid subject %v in construct clause, subject already set to %v", tkn.Type, c.S)
}
if c.SBinding != "" {
return nil, fmt.Errorf("invalid subject %v in construct clause, subject already set to %v", tkn.Type, c.SBinding)
}
switch tkn.Type {
case lexer.ItemNode, lexer.ItemBlankNode:
n, err := ToNode(ce)
if err != nil {
return nil, err
}
c.S = n
case lexer.ItemBinding:
c.SBinding = tkn.Text
}
return f, nil
}
return f
} | go | func constructSubject() ElementHook {
var f ElementHook
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.Token()
c := st.WorkingConstructClause()
if c.S != nil {
return nil, fmt.Errorf("invalid subject %v in construct clause, subject already set to %v", tkn.Type, c.S)
}
if c.SBinding != "" {
return nil, fmt.Errorf("invalid subject %v in construct clause, subject already set to %v", tkn.Type, c.SBinding)
}
switch tkn.Type {
case lexer.ItemNode, lexer.ItemBlankNode:
n, err := ToNode(ce)
if err != nil {
return nil, err
}
c.S = n
case lexer.ItemBinding:
c.SBinding = tkn.Text
}
return f, nil
}
return f
} | [
"func",
"constructSubject",
"(",
")",
"ElementHook",
"{",
"var",
"f",
"ElementHook",
"\n",
"f",
"=",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"{",
"if",
"ce",
".",
"IsSymbol",
"(",
")",
"{",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"tkn",
":=",
"ce",
".",
"Token",
"(",
")",
"\n",
"c",
":=",
"st",
".",
"WorkingConstructClause",
"(",
")",
"\n",
"if",
"c",
".",
"S",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Type",
",",
"c",
".",
"S",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"SBinding",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Type",
",",
"c",
".",
"SBinding",
")",
"\n",
"}",
"\n",
"switch",
"tkn",
".",
"Type",
"{",
"case",
"lexer",
".",
"ItemNode",
",",
"lexer",
".",
"ItemBlankNode",
":",
"n",
",",
"err",
":=",
"ToNode",
"(",
"ce",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"c",
".",
"S",
"=",
"n",
"\n",
"case",
"lexer",
".",
"ItemBinding",
":",
"c",
".",
"SBinding",
"=",
"tkn",
".",
"Text",
"\n",
"}",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // constructSubject returns an element hook that updates the subject
// modifiers on the working construct clause. | [
"constructSubject",
"returns",
"an",
"element",
"hook",
"that",
"updates",
"the",
"subject",
"modifiers",
"on",
"the",
"working",
"construct",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L977-L1004 |
12,506 | google/badwolf | bql/semantic/hooks.go | constructPredicate | func constructPredicate() ElementHook {
var f ElementHook
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.Token()
p := st.WorkingConstructClause().WorkingPredicateObjectPair()
if p.P != nil {
return nil, fmt.Errorf("invalid predicate %v in construct clause, predicate already set to %v", tkn.Type, p.P)
}
if p.PID != "" {
return nil, fmt.Errorf("invalid predicate %v in construct clause, predicate already set to %v", tkn.Type, p.PID)
}
if p.PBinding != "" {
return nil, fmt.Errorf("invalid predicate %v in construct clause, predicate already set to %v", tkn.Type, p.PBinding)
}
switch tkn.Type {
case lexer.ItemPredicate:
pred, pID, pAnchorBinding, pTemporal, err := processPredicate(ce)
if err != nil {
return nil, err
}
p.P, p.PID, p.PAnchorBinding, p.PTemporal = pred, pID, pAnchorBinding, pTemporal
case lexer.ItemBinding:
p.PBinding = tkn.Text
}
return f, nil
}
return f
} | go | func constructPredicate() ElementHook {
var f ElementHook
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.Token()
p := st.WorkingConstructClause().WorkingPredicateObjectPair()
if p.P != nil {
return nil, fmt.Errorf("invalid predicate %v in construct clause, predicate already set to %v", tkn.Type, p.P)
}
if p.PID != "" {
return nil, fmt.Errorf("invalid predicate %v in construct clause, predicate already set to %v", tkn.Type, p.PID)
}
if p.PBinding != "" {
return nil, fmt.Errorf("invalid predicate %v in construct clause, predicate already set to %v", tkn.Type, p.PBinding)
}
switch tkn.Type {
case lexer.ItemPredicate:
pred, pID, pAnchorBinding, pTemporal, err := processPredicate(ce)
if err != nil {
return nil, err
}
p.P, p.PID, p.PAnchorBinding, p.PTemporal = pred, pID, pAnchorBinding, pTemporal
case lexer.ItemBinding:
p.PBinding = tkn.Text
}
return f, nil
}
return f
} | [
"func",
"constructPredicate",
"(",
")",
"ElementHook",
"{",
"var",
"f",
"ElementHook",
"\n",
"f",
"=",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"{",
"if",
"ce",
".",
"IsSymbol",
"(",
")",
"{",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"tkn",
":=",
"ce",
".",
"Token",
"(",
")",
"\n",
"p",
":=",
"st",
".",
"WorkingConstructClause",
"(",
")",
".",
"WorkingPredicateObjectPair",
"(",
")",
"\n",
"if",
"p",
".",
"P",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Type",
",",
"p",
".",
"P",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"PID",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Type",
",",
"p",
".",
"PID",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"PBinding",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Type",
",",
"p",
".",
"PBinding",
")",
"\n",
"}",
"\n",
"switch",
"tkn",
".",
"Type",
"{",
"case",
"lexer",
".",
"ItemPredicate",
":",
"pred",
",",
"pID",
",",
"pAnchorBinding",
",",
"pTemporal",
",",
"err",
":=",
"processPredicate",
"(",
"ce",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"p",
".",
"P",
",",
"p",
".",
"PID",
",",
"p",
".",
"PAnchorBinding",
",",
"p",
".",
"PTemporal",
"=",
"pred",
",",
"pID",
",",
"pAnchorBinding",
",",
"pTemporal",
"\n",
"case",
"lexer",
".",
"ItemBinding",
":",
"p",
".",
"PBinding",
"=",
"tkn",
".",
"Text",
"\n",
"}",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // constructPredicate returns an element hook that updates the predicate
// modifiers on the current predicate-object pair of the working graph clause. | [
"constructPredicate",
"returns",
"an",
"element",
"hook",
"that",
"updates",
"the",
"predicate",
"modifiers",
"on",
"the",
"current",
"predicate",
"-",
"object",
"pair",
"of",
"the",
"working",
"graph",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L1008-L1038 |
12,507 | google/badwolf | bql/semantic/hooks.go | constructObject | func constructObject() ElementHook {
var f ElementHook
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.Token()
p := st.WorkingConstructClause().WorkingPredicateObjectPair()
if p.O != nil {
return nil, fmt.Errorf("invalid object %v in construct clause, object already set to %v", tkn.Text, p.O)
}
if p.OID != "" {
return nil, fmt.Errorf("invalid object %v in construct clause, object already set to %v", tkn.Type, p.OID)
}
if p.OBinding != "" {
return nil, fmt.Errorf("invalid object %v in construct clause, object already set to %v", tkn.Type, p.OBinding)
}
switch tkn.Type {
case lexer.ItemNode, lexer.ItemBlankNode, lexer.ItemLiteral:
obj, err := triple.ParseObject(tkn.Text, literal.DefaultBuilder())
if err != nil {
return nil, err
}
p.O = obj
case lexer.ItemPredicate:
var (
pred *predicate.Predicate
err error
)
pred, p.OID, p.OAnchorBinding, p.OTemporal, err = processPredicate(ce)
if err != nil {
return nil, err
}
if pred != nil {
p.O = triple.NewPredicateObject(pred)
}
case lexer.ItemBinding:
p.OBinding = tkn.Text
}
return f, nil
}
return f
} | go | func constructObject() ElementHook {
var f ElementHook
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() {
return f, nil
}
tkn := ce.Token()
p := st.WorkingConstructClause().WorkingPredicateObjectPair()
if p.O != nil {
return nil, fmt.Errorf("invalid object %v in construct clause, object already set to %v", tkn.Text, p.O)
}
if p.OID != "" {
return nil, fmt.Errorf("invalid object %v in construct clause, object already set to %v", tkn.Type, p.OID)
}
if p.OBinding != "" {
return nil, fmt.Errorf("invalid object %v in construct clause, object already set to %v", tkn.Type, p.OBinding)
}
switch tkn.Type {
case lexer.ItemNode, lexer.ItemBlankNode, lexer.ItemLiteral:
obj, err := triple.ParseObject(tkn.Text, literal.DefaultBuilder())
if err != nil {
return nil, err
}
p.O = obj
case lexer.ItemPredicate:
var (
pred *predicate.Predicate
err error
)
pred, p.OID, p.OAnchorBinding, p.OTemporal, err = processPredicate(ce)
if err != nil {
return nil, err
}
if pred != nil {
p.O = triple.NewPredicateObject(pred)
}
case lexer.ItemBinding:
p.OBinding = tkn.Text
}
return f, nil
}
return f
} | [
"func",
"constructObject",
"(",
")",
"ElementHook",
"{",
"var",
"f",
"ElementHook",
"\n",
"f",
"=",
"func",
"(",
"st",
"*",
"Statement",
",",
"ce",
"ConsumedElement",
")",
"(",
"ElementHook",
",",
"error",
")",
"{",
"if",
"ce",
".",
"IsSymbol",
"(",
")",
"{",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"tkn",
":=",
"ce",
".",
"Token",
"(",
")",
"\n",
"p",
":=",
"st",
".",
"WorkingConstructClause",
"(",
")",
".",
"WorkingPredicateObjectPair",
"(",
")",
"\n",
"if",
"p",
".",
"O",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Text",
",",
"p",
".",
"O",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"OID",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Type",
",",
"p",
".",
"OID",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"OBinding",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Type",
",",
"p",
".",
"OBinding",
")",
"\n",
"}",
"\n",
"switch",
"tkn",
".",
"Type",
"{",
"case",
"lexer",
".",
"ItemNode",
",",
"lexer",
".",
"ItemBlankNode",
",",
"lexer",
".",
"ItemLiteral",
":",
"obj",
",",
"err",
":=",
"triple",
".",
"ParseObject",
"(",
"tkn",
".",
"Text",
",",
"literal",
".",
"DefaultBuilder",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"p",
".",
"O",
"=",
"obj",
"\n",
"case",
"lexer",
".",
"ItemPredicate",
":",
"var",
"(",
"pred",
"*",
"predicate",
".",
"Predicate",
"\n",
"err",
"error",
"\n",
")",
"\n",
"pred",
",",
"p",
".",
"OID",
",",
"p",
".",
"OAnchorBinding",
",",
"p",
".",
"OTemporal",
",",
"err",
"=",
"processPredicate",
"(",
"ce",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"pred",
"!=",
"nil",
"{",
"p",
".",
"O",
"=",
"triple",
".",
"NewPredicateObject",
"(",
"pred",
")",
"\n",
"}",
"\n",
"case",
"lexer",
".",
"ItemBinding",
":",
"p",
".",
"OBinding",
"=",
"tkn",
".",
"Text",
"\n",
"}",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // constructObject returns an element hook that updates the object
// modifiers on the current predicate-object pair of the working graph clause. | [
"constructObject",
"returns",
"an",
"element",
"hook",
"that",
"updates",
"the",
"object",
"modifiers",
"on",
"the",
"current",
"predicate",
"-",
"object",
"pair",
"of",
"the",
"working",
"graph",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L1042-L1084 |
12,508 | google/badwolf | bql/semantic/hooks.go | NextWorkingConstructPredicateObjectPair | func NextWorkingConstructPredicateObjectPair() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
s.WorkingConstructClause().AddWorkingPredicateObjectPair()
return f, nil
}
return f
} | go | func NextWorkingConstructPredicateObjectPair() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
s.WorkingConstructClause().AddWorkingPredicateObjectPair()
return f, nil
}
return f
} | [
"func",
"NextWorkingConstructPredicateObjectPair",
"(",
")",
"ClauseHook",
"{",
"var",
"f",
"ClauseHook",
"\n",
"f",
"=",
"func",
"(",
"s",
"*",
"Statement",
",",
"_",
"Symbol",
")",
"(",
"ClauseHook",
",",
"error",
")",
"{",
"s",
".",
"WorkingConstructClause",
"(",
")",
".",
"AddWorkingPredicateObjectPair",
"(",
")",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // NextWorkingConstructPredicateObjectPair returns a clause hook to close the current
// predicate-object pair and start a new predicate-object pair within the working
// construct clause. | [
"NextWorkingConstructPredicateObjectPair",
"returns",
"a",
"clause",
"hook",
"to",
"close",
"the",
"current",
"predicate",
"-",
"object",
"pair",
"and",
"start",
"a",
"new",
"predicate",
"-",
"object",
"pair",
"within",
"the",
"working",
"construct",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L1089-L1096 |
12,509 | google/badwolf | bql/semantic/hooks.go | ShowClauseHook | func ShowClauseHook() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
s.sType = Show
return f, nil
}
return f
} | go | func ShowClauseHook() ClauseHook {
var f ClauseHook
f = func(s *Statement, _ Symbol) (ClauseHook, error) {
s.sType = Show
return f, nil
}
return f
} | [
"func",
"ShowClauseHook",
"(",
")",
"ClauseHook",
"{",
"var",
"f",
"ClauseHook",
"\n",
"f",
"=",
"func",
"(",
"s",
"*",
"Statement",
",",
"_",
"Symbol",
")",
"(",
"ClauseHook",
",",
"error",
")",
"{",
"s",
".",
"sType",
"=",
"Show",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
]
| // ShowClauseHook returns a clause hook for the show statement. | [
"ShowClauseHook",
"returns",
"a",
"clause",
"hook",
"for",
"the",
"show",
"statement",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/hooks.go#L1099-L1106 |
12,510 | google/badwolf | tools/benchmark/batteries/generators.go | getTreeGenerators | func getTreeGenerators(bFactors []int) ([]generator.Generator, error) {
var gens []generator.Generator
for _, b := range bFactors {
t, err := tree.New(b)
if err != nil {
return nil, err
}
gens = append(gens, t)
}
return gens, nil
} | go | func getTreeGenerators(bFactors []int) ([]generator.Generator, error) {
var gens []generator.Generator
for _, b := range bFactors {
t, err := tree.New(b)
if err != nil {
return nil, err
}
gens = append(gens, t)
}
return gens, nil
} | [
"func",
"getTreeGenerators",
"(",
"bFactors",
"[",
"]",
"int",
")",
"(",
"[",
"]",
"generator",
".",
"Generator",
",",
"error",
")",
"{",
"var",
"gens",
"[",
"]",
"generator",
".",
"Generator",
"\n",
"for",
"_",
",",
"b",
":=",
"range",
"bFactors",
"{",
"t",
",",
"err",
":=",
"tree",
".",
"New",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"gens",
"=",
"append",
"(",
"gens",
",",
"t",
")",
"\n",
"}",
"\n",
"return",
"gens",
",",
"nil",
"\n",
"}"
]
| // getTreeGenerators returns the set of tree generators to use while creating
// benchmarks. | [
"getTreeGenerators",
"returns",
"the",
"set",
"of",
"tree",
"generators",
"to",
"use",
"while",
"creating",
"benchmarks",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/benchmark/batteries/generators.go#L26-L36 |
12,511 | google/badwolf | tools/benchmark/batteries/generators.go | getGraphGenerators | func getGraphGenerators(nodes []int) ([]generator.Generator, error) {
var gens []generator.Generator
for _, b := range nodes {
t, err := graph.NewRandomGraph(b)
if err != nil {
return nil, err
}
gens = append(gens, t)
}
return gens, nil
} | go | func getGraphGenerators(nodes []int) ([]generator.Generator, error) {
var gens []generator.Generator
for _, b := range nodes {
t, err := graph.NewRandomGraph(b)
if err != nil {
return nil, err
}
gens = append(gens, t)
}
return gens, nil
} | [
"func",
"getGraphGenerators",
"(",
"nodes",
"[",
"]",
"int",
")",
"(",
"[",
"]",
"generator",
".",
"Generator",
",",
"error",
")",
"{",
"var",
"gens",
"[",
"]",
"generator",
".",
"Generator",
"\n",
"for",
"_",
",",
"b",
":=",
"range",
"nodes",
"{",
"t",
",",
"err",
":=",
"graph",
".",
"NewRandomGraph",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"gens",
"=",
"append",
"(",
"gens",
",",
"t",
")",
"\n",
"}",
"\n",
"return",
"gens",
",",
"nil",
"\n",
"}"
]
| // getGraphGenerators returns the set of tree generators to use while creating
// benchmarks. | [
"getGraphGenerators",
"returns",
"the",
"set",
"of",
"tree",
"generators",
"to",
"use",
"while",
"creating",
"benchmarks",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/benchmark/batteries/generators.go#L40-L50 |
12,512 | google/badwolf | tools/vcli/bw/assert/assert.go | assertCommand | func assertCommand(ctx context.Context, cmd *command.Command, args []string, store storage.Store, builder literal.Builder, chanSize, bulkSize int) int {
if len(args) < 2 {
log.Printf("Missing required folder path. ")
cmd.Usage()
return 2
}
// Open the folder.
folder := strings.TrimSpace(args[len(args)-1])
f, err := os.Open(folder)
if err != nil {
log.Printf("[ERROR] Failed to open folder %s\n\n\t%v\n\n", folder, err)
return 2
}
fis, err := f.Readdir(0)
if err != nil {
log.Printf("[ERROR] Failed to read folder %s\n\n\t%v\n\n", folder, err)
return 2
}
fmt.Println("-------------------------------------------------------------")
fmt.Printf("Processing folder %q...\n", folder)
var stories []*compliance.Story
empty := true
for _, fi := range fis {
if !strings.Contains(fi.Name(), "json") {
continue
}
fmt.Printf("\tProcessing file %q... ", fi.Name())
lns, err := io.ReadLines(path.Join(folder, fi.Name()))
if err != nil {
log.Printf("\n\n\tFailed to read file content with error %v\n\n", err)
return 2
}
rawStory := strings.Join(lns, "\n")
s := &compliance.Story{}
if err := s.Unmarshal(rawStory); err != nil {
log.Printf("\n\n\tFailed to unmarshal story with error %v\n\n", err)
return 2
}
empty = false
stories = append(stories, s)
fmt.Println("done.")
}
if empty {
fmt.Println("No stories found!")
fmt.Println("-------------------------------------------------------------")
return 2
}
fmt.Println("-------------------------------------------------------------")
fmt.Printf("Evaluating %d stories... ", len(stories))
results := compliance.RunStories(ctx, store, builder, stories, chanSize, bulkSize)
fmt.Println("done.")
fmt.Println("-------------------------------------------------------------")
for i, entry := range results.Entries {
fmt.Printf("(%d/%d) Story %q...\n", i+1, len(stories), entry.Story.Name)
if entry.Err != nil {
log.Printf("\tFailed to run story %q with error %v\n\n", entry.Story.Name, entry.Err)
return 2
}
for aid, aido := range entry.Outcome {
if aido.Equal {
fmt.Printf("\t%s [Assertion=TRUE]\n", aid)
} else {
fmt.Printf("\t%s [Assertion=FALSE]\n\nGot:\n\n%s\nWant:\n\n%s\n", aid, aido.Got, aido.Want)
}
}
fmt.Println()
}
fmt.Println("-------------------------------------------------------------")
fmt.Println("\ndone")
return 0
} | go | func assertCommand(ctx context.Context, cmd *command.Command, args []string, store storage.Store, builder literal.Builder, chanSize, bulkSize int) int {
if len(args) < 2 {
log.Printf("Missing required folder path. ")
cmd.Usage()
return 2
}
// Open the folder.
folder := strings.TrimSpace(args[len(args)-1])
f, err := os.Open(folder)
if err != nil {
log.Printf("[ERROR] Failed to open folder %s\n\n\t%v\n\n", folder, err)
return 2
}
fis, err := f.Readdir(0)
if err != nil {
log.Printf("[ERROR] Failed to read folder %s\n\n\t%v\n\n", folder, err)
return 2
}
fmt.Println("-------------------------------------------------------------")
fmt.Printf("Processing folder %q...\n", folder)
var stories []*compliance.Story
empty := true
for _, fi := range fis {
if !strings.Contains(fi.Name(), "json") {
continue
}
fmt.Printf("\tProcessing file %q... ", fi.Name())
lns, err := io.ReadLines(path.Join(folder, fi.Name()))
if err != nil {
log.Printf("\n\n\tFailed to read file content with error %v\n\n", err)
return 2
}
rawStory := strings.Join(lns, "\n")
s := &compliance.Story{}
if err := s.Unmarshal(rawStory); err != nil {
log.Printf("\n\n\tFailed to unmarshal story with error %v\n\n", err)
return 2
}
empty = false
stories = append(stories, s)
fmt.Println("done.")
}
if empty {
fmt.Println("No stories found!")
fmt.Println("-------------------------------------------------------------")
return 2
}
fmt.Println("-------------------------------------------------------------")
fmt.Printf("Evaluating %d stories... ", len(stories))
results := compliance.RunStories(ctx, store, builder, stories, chanSize, bulkSize)
fmt.Println("done.")
fmt.Println("-------------------------------------------------------------")
for i, entry := range results.Entries {
fmt.Printf("(%d/%d) Story %q...\n", i+1, len(stories), entry.Story.Name)
if entry.Err != nil {
log.Printf("\tFailed to run story %q with error %v\n\n", entry.Story.Name, entry.Err)
return 2
}
for aid, aido := range entry.Outcome {
if aido.Equal {
fmt.Printf("\t%s [Assertion=TRUE]\n", aid)
} else {
fmt.Printf("\t%s [Assertion=FALSE]\n\nGot:\n\n%s\nWant:\n\n%s\n", aid, aido.Got, aido.Want)
}
}
fmt.Println()
}
fmt.Println("-------------------------------------------------------------")
fmt.Println("\ndone")
return 0
} | [
"func",
"assertCommand",
"(",
"ctx",
"context",
".",
"Context",
",",
"cmd",
"*",
"command",
".",
"Command",
",",
"args",
"[",
"]",
"string",
",",
"store",
"storage",
".",
"Store",
",",
"builder",
"literal",
".",
"Builder",
",",
"chanSize",
",",
"bulkSize",
"int",
")",
"int",
"{",
"if",
"len",
"(",
"args",
")",
"<",
"2",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"cmd",
".",
"Usage",
"(",
")",
"\n",
"return",
"2",
"\n",
"}",
"\n",
"// Open the folder.",
"folder",
":=",
"strings",
".",
"TrimSpace",
"(",
"args",
"[",
"len",
"(",
"args",
")",
"-",
"1",
"]",
")",
"\n",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"folder",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\\t",
"\\n",
"\\n",
"\"",
",",
"folder",
",",
"err",
")",
"\n",
"return",
"2",
"\n",
"}",
"\n",
"fis",
",",
"err",
":=",
"f",
".",
"Readdir",
"(",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\\t",
"\\n",
"\\n",
"\"",
",",
"folder",
",",
"err",
")",
"\n",
"return",
"2",
"\n",
"}",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"folder",
")",
"\n",
"var",
"stories",
"[",
"]",
"*",
"compliance",
".",
"Story",
"\n",
"empty",
":=",
"true",
"\n",
"for",
"_",
",",
"fi",
":=",
"range",
"fis",
"{",
"if",
"!",
"strings",
".",
"Contains",
"(",
"fi",
".",
"Name",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"continue",
"\n",
"}",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\t",
"\"",
",",
"fi",
".",
"Name",
"(",
")",
")",
"\n",
"lns",
",",
"err",
":=",
"io",
".",
"ReadLines",
"(",
"path",
".",
"Join",
"(",
"folder",
",",
"fi",
".",
"Name",
"(",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\\t",
"\\n",
"\\n",
"\"",
",",
"err",
")",
"\n",
"return",
"2",
"\n",
"}",
"\n",
"rawStory",
":=",
"strings",
".",
"Join",
"(",
"lns",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"s",
":=",
"&",
"compliance",
".",
"Story",
"{",
"}",
"\n",
"if",
"err",
":=",
"s",
".",
"Unmarshal",
"(",
"rawStory",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\\t",
"\\n",
"\\n",
"\"",
",",
"err",
")",
"\n",
"return",
"2",
"\n",
"}",
"\n",
"empty",
"=",
"false",
"\n",
"stories",
"=",
"append",
"(",
"stories",
",",
"s",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"empty",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"return",
"2",
"\n",
"}",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\"",
",",
"len",
"(",
"stories",
")",
")",
"\n",
"results",
":=",
"compliance",
".",
"RunStories",
"(",
"ctx",
",",
"store",
",",
"builder",
",",
"stories",
",",
"chanSize",
",",
"bulkSize",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"for",
"i",
",",
"entry",
":=",
"range",
"results",
".",
"Entries",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"i",
"+",
"1",
",",
"len",
"(",
"stories",
")",
",",
"entry",
".",
"Story",
".",
"Name",
")",
"\n",
"if",
"entry",
".",
"Err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\t",
"\\n",
"\\n",
"\"",
",",
"entry",
".",
"Story",
".",
"Name",
",",
"entry",
".",
"Err",
")",
"\n",
"return",
"2",
"\n",
"}",
"\n",
"for",
"aid",
",",
"aido",
":=",
"range",
"entry",
".",
"Outcome",
"{",
"if",
"aido",
".",
"Equal",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\t",
"\\n",
"\"",
",",
"aid",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\t",
"\\n",
"\\n",
"\\n",
"\\n",
"\\n",
"\\n",
"\\n",
"\\n",
"\"",
",",
"aid",
",",
"aido",
".",
"Got",
",",
"aido",
".",
"Want",
")",
"\n",
"}",
"\n",
"}",
"\n",
"fmt",
".",
"Println",
"(",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"return",
"0",
"\n",
"}"
]
| // assertCommand runs all the BQL statements available in the file. | [
"assertCommand",
"runs",
"all",
"the",
"BQL",
"statements",
"available",
"in",
"the",
"file",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/assert/assert.go#L50-L120 |
12,513 | google/badwolf | tools/vcli/bw/run/run.go | runCommand | func runCommand(ctx context.Context, cmd *command.Command, args []string, store storage.Store, chanSize, bulkSize int) int {
if len(args) < 2 {
log.Printf("[ERROR] Missing required file path. ")
cmd.Usage()
return 2
}
file := strings.TrimSpace(args[len(args)-1])
lines, err := io.GetStatementsFromFile(file)
if err != nil {
log.Printf("[ERROR] Failed to read file %s\n\n\t%v\n\n", file, err)
return 2
}
fmt.Printf("Processing file %s\n\n", args[len(args)-1])
for idx, stm := range lines {
fmt.Printf("Processing statement (%d/%d):\n%s\n\n", idx+1, len(lines), stm)
tbl, err := BQL(ctx, stm, store, chanSize, bulkSize)
if err != nil {
fmt.Printf("[FAIL] %v\n\n", err)
continue
}
fmt.Println("Result:")
if tbl.NumRows() > 0 {
fmt.Println(tbl)
}
fmt.Printf("OK\n\n")
}
return 0
} | go | func runCommand(ctx context.Context, cmd *command.Command, args []string, store storage.Store, chanSize, bulkSize int) int {
if len(args) < 2 {
log.Printf("[ERROR] Missing required file path. ")
cmd.Usage()
return 2
}
file := strings.TrimSpace(args[len(args)-1])
lines, err := io.GetStatementsFromFile(file)
if err != nil {
log.Printf("[ERROR] Failed to read file %s\n\n\t%v\n\n", file, err)
return 2
}
fmt.Printf("Processing file %s\n\n", args[len(args)-1])
for idx, stm := range lines {
fmt.Printf("Processing statement (%d/%d):\n%s\n\n", idx+1, len(lines), stm)
tbl, err := BQL(ctx, stm, store, chanSize, bulkSize)
if err != nil {
fmt.Printf("[FAIL] %v\n\n", err)
continue
}
fmt.Println("Result:")
if tbl.NumRows() > 0 {
fmt.Println(tbl)
}
fmt.Printf("OK\n\n")
}
return 0
} | [
"func",
"runCommand",
"(",
"ctx",
"context",
".",
"Context",
",",
"cmd",
"*",
"command",
".",
"Command",
",",
"args",
"[",
"]",
"string",
",",
"store",
"storage",
".",
"Store",
",",
"chanSize",
",",
"bulkSize",
"int",
")",
"int",
"{",
"if",
"len",
"(",
"args",
")",
"<",
"2",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"cmd",
".",
"Usage",
"(",
")",
"\n",
"return",
"2",
"\n",
"}",
"\n",
"file",
":=",
"strings",
".",
"TrimSpace",
"(",
"args",
"[",
"len",
"(",
"args",
")",
"-",
"1",
"]",
")",
"\n",
"lines",
",",
"err",
":=",
"io",
".",
"GetStatementsFromFile",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\\t",
"\\n",
"\\n",
"\"",
",",
"file",
",",
"err",
")",
"\n",
"return",
"2",
"\n",
"}",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"args",
"[",
"len",
"(",
"args",
")",
"-",
"1",
"]",
")",
"\n",
"for",
"idx",
",",
"stm",
":=",
"range",
"lines",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\\n",
"\"",
",",
"idx",
"+",
"1",
",",
"len",
"(",
"lines",
")",
",",
"stm",
")",
"\n",
"tbl",
",",
"err",
":=",
"BQL",
"(",
"ctx",
",",
"stm",
",",
"store",
",",
"chanSize",
",",
"bulkSize",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"if",
"tbl",
".",
"NumRows",
"(",
")",
">",
"0",
"{",
"fmt",
".",
"Println",
"(",
"tbl",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
")",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}"
]
| // runCommand runs all the BQL statements available in the file. | [
"runCommand",
"runs",
"all",
"the",
"BQL",
"statements",
"available",
"in",
"the",
"file",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/run/run.go#L51-L78 |
12,514 | google/badwolf | tools/vcli/bw/run/run.go | BQL | func BQL(ctx context.Context, bql string, s storage.Store, chanSize, bulkSize int) (*table.Table, error) {
p, err := grammar.NewParser(grammar.SemanticBQL())
if err != nil {
return nil, fmt.Errorf("[ERROR] Failed to initilize a valid BQL parser")
}
stm := &semantic.Statement{}
if err := p.Parse(grammar.NewLLk(bql, 1), stm); err != nil {
return nil, fmt.Errorf("[ERROR] Failed to parse BQL statement with error %v", err)
}
pln, err := planner.New(ctx, s, stm, chanSize, bulkSize, nil)
if err != nil {
return nil, fmt.Errorf("[ERROR] Should have not failed to create a plan using memory.DefaultStorage for statement %v with error %v", stm, err)
}
res, err := pln.Execute(ctx)
if err != nil {
return nil, fmt.Errorf("[ERROR] Failed to execute BQL statement with error %v", err)
}
return res, nil
} | go | func BQL(ctx context.Context, bql string, s storage.Store, chanSize, bulkSize int) (*table.Table, error) {
p, err := grammar.NewParser(grammar.SemanticBQL())
if err != nil {
return nil, fmt.Errorf("[ERROR] Failed to initilize a valid BQL parser")
}
stm := &semantic.Statement{}
if err := p.Parse(grammar.NewLLk(bql, 1), stm); err != nil {
return nil, fmt.Errorf("[ERROR] Failed to parse BQL statement with error %v", err)
}
pln, err := planner.New(ctx, s, stm, chanSize, bulkSize, nil)
if err != nil {
return nil, fmt.Errorf("[ERROR] Should have not failed to create a plan using memory.DefaultStorage for statement %v with error %v", stm, err)
}
res, err := pln.Execute(ctx)
if err != nil {
return nil, fmt.Errorf("[ERROR] Failed to execute BQL statement with error %v", err)
}
return res, nil
} | [
"func",
"BQL",
"(",
"ctx",
"context",
".",
"Context",
",",
"bql",
"string",
",",
"s",
"storage",
".",
"Store",
",",
"chanSize",
",",
"bulkSize",
"int",
")",
"(",
"*",
"table",
".",
"Table",
",",
"error",
")",
"{",
"p",
",",
"err",
":=",
"grammar",
".",
"NewParser",
"(",
"grammar",
".",
"SemanticBQL",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"stm",
":=",
"&",
"semantic",
".",
"Statement",
"{",
"}",
"\n",
"if",
"err",
":=",
"p",
".",
"Parse",
"(",
"grammar",
".",
"NewLLk",
"(",
"bql",
",",
"1",
")",
",",
"stm",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"pln",
",",
"err",
":=",
"planner",
".",
"New",
"(",
"ctx",
",",
"s",
",",
"stm",
",",
"chanSize",
",",
"bulkSize",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"stm",
",",
"err",
")",
"\n",
"}",
"\n",
"res",
",",
"err",
":=",
"pln",
".",
"Execute",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"res",
",",
"nil",
"\n",
"}"
]
| // BQL attempts to execute the provided query against the given store. | [
"BQL",
"attempts",
"to",
"execute",
"the",
"provided",
"query",
"against",
"the",
"given",
"store",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/run/run.go#L81-L99 |
12,515 | google/badwolf | bql/semantic/convert.go | NewConsumedToken | func NewConsumedToken(tkn *lexer.Token) ConsumedElement {
return ConsumedElement{
isSymbol: false,
token: tkn,
}
} | go | func NewConsumedToken(tkn *lexer.Token) ConsumedElement {
return ConsumedElement{
isSymbol: false,
token: tkn,
}
} | [
"func",
"NewConsumedToken",
"(",
"tkn",
"*",
"lexer",
".",
"Token",
")",
"ConsumedElement",
"{",
"return",
"ConsumedElement",
"{",
"isSymbol",
":",
"false",
",",
"token",
":",
"tkn",
",",
"}",
"\n",
"}"
]
| // NewConsumedToken create a new consumed element that boxes a token. | [
"NewConsumedToken",
"create",
"a",
"new",
"consumed",
"element",
"that",
"boxes",
"a",
"token",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/convert.go#L50-L55 |
12,516 | google/badwolf | bql/semantic/convert.go | ToNode | func ToNode(ce ConsumedElement) (*node.Node, error) {
if ce.IsSymbol() {
return nil, fmt.Errorf("semantic.ToNode cannot convert symbol %v to a node", ce)
}
tkn := ce.Token()
if tkn.Type != lexer.ItemNode && tkn.Type != lexer.ItemBlankNode {
return nil, fmt.Errorf("semantic.ToNode cannot convert token type %s to a node", tkn.Type)
}
return node.Parse(tkn.Text)
} | go | func ToNode(ce ConsumedElement) (*node.Node, error) {
if ce.IsSymbol() {
return nil, fmt.Errorf("semantic.ToNode cannot convert symbol %v to a node", ce)
}
tkn := ce.Token()
if tkn.Type != lexer.ItemNode && tkn.Type != lexer.ItemBlankNode {
return nil, fmt.Errorf("semantic.ToNode cannot convert token type %s to a node", tkn.Type)
}
return node.Parse(tkn.Text)
} | [
"func",
"ToNode",
"(",
"ce",
"ConsumedElement",
")",
"(",
"*",
"node",
".",
"Node",
",",
"error",
")",
"{",
"if",
"ce",
".",
"IsSymbol",
"(",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ce",
")",
"\n",
"}",
"\n",
"tkn",
":=",
"ce",
".",
"Token",
"(",
")",
"\n",
"if",
"tkn",
".",
"Type",
"!=",
"lexer",
".",
"ItemNode",
"&&",
"tkn",
".",
"Type",
"!=",
"lexer",
".",
"ItemBlankNode",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Type",
")",
"\n",
"}",
"\n",
"return",
"node",
".",
"Parse",
"(",
"tkn",
".",
"Text",
")",
"\n",
"}"
]
| // ToNode converts the node found by the lexer and converts it into a BadWolf
// node. | [
"ToNode",
"converts",
"the",
"node",
"found",
"by",
"the",
"lexer",
"and",
"converts",
"it",
"into",
"a",
"BadWolf",
"node",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/convert.go#L74-L83 |
12,517 | google/badwolf | bql/semantic/convert.go | ToPredicate | func ToPredicate(ce ConsumedElement) (*predicate.Predicate, error) {
if ce.IsSymbol() {
return nil, fmt.Errorf("semantic.ToPredicate cannot convert symbol %v to a predicate", ce)
}
tkn := ce.Token()
if tkn.Type != lexer.ItemPredicate {
return nil, fmt.Errorf("semantic.ToPredicate cannot convert token type %s to a predicate", tkn.Type)
}
return predicate.Parse(tkn.Text)
} | go | func ToPredicate(ce ConsumedElement) (*predicate.Predicate, error) {
if ce.IsSymbol() {
return nil, fmt.Errorf("semantic.ToPredicate cannot convert symbol %v to a predicate", ce)
}
tkn := ce.Token()
if tkn.Type != lexer.ItemPredicate {
return nil, fmt.Errorf("semantic.ToPredicate cannot convert token type %s to a predicate", tkn.Type)
}
return predicate.Parse(tkn.Text)
} | [
"func",
"ToPredicate",
"(",
"ce",
"ConsumedElement",
")",
"(",
"*",
"predicate",
".",
"Predicate",
",",
"error",
")",
"{",
"if",
"ce",
".",
"IsSymbol",
"(",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ce",
")",
"\n",
"}",
"\n",
"tkn",
":=",
"ce",
".",
"Token",
"(",
")",
"\n",
"if",
"tkn",
".",
"Type",
"!=",
"lexer",
".",
"ItemPredicate",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Type",
")",
"\n",
"}",
"\n",
"return",
"predicate",
".",
"Parse",
"(",
"tkn",
".",
"Text",
")",
"\n",
"}"
]
| // ToPredicate converts the node found by the lexer and converts it into a
// BadWolf predicate. | [
"ToPredicate",
"converts",
"the",
"node",
"found",
"by",
"the",
"lexer",
"and",
"converts",
"it",
"into",
"a",
"BadWolf",
"predicate",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/convert.go#L87-L96 |
12,518 | google/badwolf | bql/semantic/convert.go | ToLiteral | func ToLiteral(ce ConsumedElement) (*literal.Literal, error) {
if ce.IsSymbol() {
return nil, fmt.Errorf("semantic.ToLiteral cannot convert symbol %v to a literal", ce)
}
tkn := ce.Token()
if tkn.Type != lexer.ItemLiteral {
return nil, fmt.Errorf("semantic.ToLiteral cannot convert token type %s to a literal", tkn.Type)
}
return literal.DefaultBuilder().Parse(tkn.Text)
} | go | func ToLiteral(ce ConsumedElement) (*literal.Literal, error) {
if ce.IsSymbol() {
return nil, fmt.Errorf("semantic.ToLiteral cannot convert symbol %v to a literal", ce)
}
tkn := ce.Token()
if tkn.Type != lexer.ItemLiteral {
return nil, fmt.Errorf("semantic.ToLiteral cannot convert token type %s to a literal", tkn.Type)
}
return literal.DefaultBuilder().Parse(tkn.Text)
} | [
"func",
"ToLiteral",
"(",
"ce",
"ConsumedElement",
")",
"(",
"*",
"literal",
".",
"Literal",
",",
"error",
")",
"{",
"if",
"ce",
".",
"IsSymbol",
"(",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ce",
")",
"\n",
"}",
"\n",
"tkn",
":=",
"ce",
".",
"Token",
"(",
")",
"\n",
"if",
"tkn",
".",
"Type",
"!=",
"lexer",
".",
"ItemLiteral",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tkn",
".",
"Type",
")",
"\n",
"}",
"\n",
"return",
"literal",
".",
"DefaultBuilder",
"(",
")",
".",
"Parse",
"(",
"tkn",
".",
"Text",
")",
"\n",
"}"
]
| // ToLiteral converts the node found by the lexer and converts it into a
// BadWolf literal. | [
"ToLiteral",
"converts",
"the",
"node",
"found",
"by",
"the",
"lexer",
"and",
"converts",
"it",
"into",
"a",
"BadWolf",
"literal",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/convert.go#L100-L109 |
12,519 | google/badwolf | triple/node/node.go | Covariant | func (t *Type) Covariant(ot *Type) bool {
if !strings.HasPrefix(t.String(), ot.String()) {
return false
}
// /type/foo is covariant of /type, but /typefoo is not covariant of /type.
return len(t.String()) == len(ot.String()) || t.String()[len(ot.String())] == '/'
} | go | func (t *Type) Covariant(ot *Type) bool {
if !strings.HasPrefix(t.String(), ot.String()) {
return false
}
// /type/foo is covariant of /type, but /typefoo is not covariant of /type.
return len(t.String()) == len(ot.String()) || t.String()[len(ot.String())] == '/'
} | [
"func",
"(",
"t",
"*",
"Type",
")",
"Covariant",
"(",
"ot",
"*",
"Type",
")",
"bool",
"{",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"t",
".",
"String",
"(",
")",
",",
"ot",
".",
"String",
"(",
")",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"// /type/foo is covariant of /type, but /typefoo is not covariant of /type.",
"return",
"len",
"(",
"t",
".",
"String",
"(",
")",
")",
"==",
"len",
"(",
"ot",
".",
"String",
"(",
")",
")",
"||",
"t",
".",
"String",
"(",
")",
"[",
"len",
"(",
"ot",
".",
"String",
"(",
")",
")",
"]",
"==",
"'/'",
"\n",
"}"
]
| // Covariant checks for given two types A and B, A covariant B if B _is a_ A.
// In other word, A _covariant_ B if B is a prefix of A. | [
"Covariant",
"checks",
"for",
"given",
"two",
"types",
"A",
"and",
"B",
"A",
"covariant",
"B",
"if",
"B",
"_is",
"a_",
"A",
".",
"In",
"other",
"word",
"A",
"_covariant_",
"B",
"if",
"B",
"is",
"a",
"prefix",
"of",
"A",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/node/node.go#L45-L51 |
12,520 | google/badwolf | triple/node/node.go | String | func (n *Node) String() string {
return fmt.Sprintf("%s<%s>", n.t.String(), n.id.String())
} | go | func (n *Node) String() string {
return fmt.Sprintf("%s<%s>", n.t.String(), n.id.String())
} | [
"func",
"(",
"n",
"*",
"Node",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"n",
".",
"t",
".",
"String",
"(",
")",
",",
"n",
".",
"id",
".",
"String",
"(",
")",
")",
"\n",
"}"
]
| // String returns a pretty printing representation of Node. | [
"String",
"returns",
"a",
"pretty",
"printing",
"representation",
"of",
"Node",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/node/node.go#L78-L80 |
12,521 | google/badwolf | triple/node/node.go | Parse | func Parse(s string) (*Node, error) {
raw := strings.TrimSpace(s)
switch raw[0] {
case slash:
idx := strings.Index(raw, "<")
if idx < 0 {
return nil, fmt.Errorf("node.Parse: invalid format, could not find ID in %v", raw)
}
t, err := NewType(raw[:idx])
if err != nil {
return nil, fmt.Errorf("node.Parse: invalid type %q, %v", raw[:idx], err)
}
if raw[len(raw)-1] != '>' {
return nil, fmt.Errorf("node.Parse: pretty printing should finish with '>' in %q", raw)
}
id, err := NewID(raw[idx+1 : len(raw)-1])
if err != nil {
return nil, fmt.Errorf("node.Parse: invalid ID in %q, %v", raw, err)
}
return NewNode(t, id), nil
case underscore:
id, err := NewID(raw[2:len(raw)])
if err != nil {
return nil, fmt.Errorf("node.Parse: invalid ID in %q, %v", raw, err)
}
t, _ := NewType("/_")
return NewNode(t, id), nil
default:
return nil, fmt.Errorf("node.Parse: node representation should start with '/' or '_' in %v", raw)
}
} | go | func Parse(s string) (*Node, error) {
raw := strings.TrimSpace(s)
switch raw[0] {
case slash:
idx := strings.Index(raw, "<")
if idx < 0 {
return nil, fmt.Errorf("node.Parse: invalid format, could not find ID in %v", raw)
}
t, err := NewType(raw[:idx])
if err != nil {
return nil, fmt.Errorf("node.Parse: invalid type %q, %v", raw[:idx], err)
}
if raw[len(raw)-1] != '>' {
return nil, fmt.Errorf("node.Parse: pretty printing should finish with '>' in %q", raw)
}
id, err := NewID(raw[idx+1 : len(raw)-1])
if err != nil {
return nil, fmt.Errorf("node.Parse: invalid ID in %q, %v", raw, err)
}
return NewNode(t, id), nil
case underscore:
id, err := NewID(raw[2:len(raw)])
if err != nil {
return nil, fmt.Errorf("node.Parse: invalid ID in %q, %v", raw, err)
}
t, _ := NewType("/_")
return NewNode(t, id), nil
default:
return nil, fmt.Errorf("node.Parse: node representation should start with '/' or '_' in %v", raw)
}
} | [
"func",
"Parse",
"(",
"s",
"string",
")",
"(",
"*",
"Node",
",",
"error",
")",
"{",
"raw",
":=",
"strings",
".",
"TrimSpace",
"(",
"s",
")",
"\n",
"switch",
"raw",
"[",
"0",
"]",
"{",
"case",
"slash",
":",
"idx",
":=",
"strings",
".",
"Index",
"(",
"raw",
",",
"\"",
"\"",
")",
"\n",
"if",
"idx",
"<",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}",
"\n",
"t",
",",
"err",
":=",
"NewType",
"(",
"raw",
"[",
":",
"idx",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
"[",
":",
"idx",
"]",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"raw",
"[",
"len",
"(",
"raw",
")",
"-",
"1",
"]",
"!=",
"'>'",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}",
"\n",
"id",
",",
"err",
":=",
"NewID",
"(",
"raw",
"[",
"idx",
"+",
"1",
":",
"len",
"(",
"raw",
")",
"-",
"1",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"NewNode",
"(",
"t",
",",
"id",
")",
",",
"nil",
"\n",
"case",
"underscore",
":",
"id",
",",
"err",
":=",
"NewID",
"(",
"raw",
"[",
"2",
":",
"len",
"(",
"raw",
")",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
",",
"err",
")",
"\n",
"}",
"\n",
"t",
",",
"_",
":=",
"NewType",
"(",
"\"",
"\"",
")",
"\n",
"return",
"NewNode",
"(",
"t",
",",
"id",
")",
",",
"nil",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}",
"\n",
"}"
]
| // Parse returns a node given a pretty printed representation of a Node or a BlankNode. | [
"Parse",
"returns",
"a",
"node",
"given",
"a",
"pretty",
"printed",
"representation",
"of",
"a",
"Node",
"or",
"a",
"BlankNode",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/node/node.go#L83-L113 |
12,522 | google/badwolf | triple/node/node.go | Covariant | func (n *Node) Covariant(on *Node) bool {
return n.t.Covariant(on.t)
} | go | func (n *Node) Covariant(on *Node) bool {
return n.t.Covariant(on.t)
} | [
"func",
"(",
"n",
"*",
"Node",
")",
"Covariant",
"(",
"on",
"*",
"Node",
")",
"bool",
"{",
"return",
"n",
".",
"t",
".",
"Covariant",
"(",
"on",
".",
"t",
")",
"\n",
"}"
]
| // Covariant checks if the types of two nodes is covariant. | [
"Covariant",
"checks",
"if",
"the",
"types",
"of",
"two",
"nodes",
"is",
"covariant",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/node/node.go#L116-L118 |
12,523 | google/badwolf | triple/node/node.go | NewType | func NewType(t string) (*Type, error) {
if strings.ContainsAny(t, " \t\n\r") {
return nil, fmt.Errorf("node.NewType(%q) does not allow spaces", t)
}
if !strings.HasPrefix(t, "/") || strings.HasSuffix(t, "/") {
return nil, fmt.Errorf("node.NewType(%q) should start with a '/' and do not end with '/'", t)
}
if t == "" {
return nil, fmt.Errorf("node.NewType(%q) cannot create empty types", t)
}
nt := Type(t)
return &nt, nil
} | go | func NewType(t string) (*Type, error) {
if strings.ContainsAny(t, " \t\n\r") {
return nil, fmt.Errorf("node.NewType(%q) does not allow spaces", t)
}
if !strings.HasPrefix(t, "/") || strings.HasSuffix(t, "/") {
return nil, fmt.Errorf("node.NewType(%q) should start with a '/' and do not end with '/'", t)
}
if t == "" {
return nil, fmt.Errorf("node.NewType(%q) cannot create empty types", t)
}
nt := Type(t)
return &nt, nil
} | [
"func",
"NewType",
"(",
"t",
"string",
")",
"(",
"*",
"Type",
",",
"error",
")",
"{",
"if",
"strings",
".",
"ContainsAny",
"(",
"t",
",",
"\"",
"\\t",
"\\n",
"\\r",
"\"",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
")",
"\n",
"}",
"\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"t",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"HasSuffix",
"(",
"t",
",",
"\"",
"\"",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
")",
"\n",
"}",
"\n",
"if",
"t",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
")",
"\n",
"}",
"\n",
"nt",
":=",
"Type",
"(",
"t",
")",
"\n",
"return",
"&",
"nt",
",",
"nil",
"\n",
"}"
]
| // NewType creates a new type from plain string. | [
"NewType",
"creates",
"a",
"new",
"type",
"from",
"plain",
"string",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/node/node.go#L121-L133 |
12,524 | google/badwolf | triple/node/node.go | NewID | func NewID(id string) (*ID, error) {
if strings.ContainsAny(id, "<>") {
return nil, fmt.Errorf("node.NewID(%q) does not allow '<' or '>'", id)
}
if id == "" {
return nil, fmt.Errorf("node.NewID(%q) cannot create empty ID", id)
}
nID := ID(id)
return &nID, nil
} | go | func NewID(id string) (*ID, error) {
if strings.ContainsAny(id, "<>") {
return nil, fmt.Errorf("node.NewID(%q) does not allow '<' or '>'", id)
}
if id == "" {
return nil, fmt.Errorf("node.NewID(%q) cannot create empty ID", id)
}
nID := ID(id)
return &nID, nil
} | [
"func",
"NewID",
"(",
"id",
"string",
")",
"(",
"*",
"ID",
",",
"error",
")",
"{",
"if",
"strings",
".",
"ContainsAny",
"(",
"id",
",",
"\"",
"\"",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n",
"if",
"id",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n",
"nID",
":=",
"ID",
"(",
"id",
")",
"\n",
"return",
"&",
"nID",
",",
"nil",
"\n",
"}"
]
| // NewID create a new ID from a plain string. | [
"NewID",
"create",
"a",
"new",
"ID",
"from",
"a",
"plain",
"string",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/node/node.go#L136-L145 |
12,525 | google/badwolf | triple/node/node.go | NewNode | func NewNode(t *Type, id *ID) *Node {
return &Node{
t: t,
id: id,
}
} | go | func NewNode(t *Type, id *ID) *Node {
return &Node{
t: t,
id: id,
}
} | [
"func",
"NewNode",
"(",
"t",
"*",
"Type",
",",
"id",
"*",
"ID",
")",
"*",
"Node",
"{",
"return",
"&",
"Node",
"{",
"t",
":",
"t",
",",
"id",
":",
"id",
",",
"}",
"\n",
"}"
]
| // NewNode returns a new node constructed from a type and an ID. | [
"NewNode",
"returns",
"a",
"new",
"node",
"constructed",
"from",
"a",
"type",
"and",
"an",
"ID",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/node/node.go#L148-L153 |
12,526 | google/badwolf | triple/node/node.go | NewNodeFromStrings | func NewNodeFromStrings(sT, sID string) (*Node, error) {
t, err := NewType(sT)
if err != nil {
return nil, err
}
n, err := NewID(sID)
if err != nil {
return nil, err
}
return NewNode(t, n), nil
} | go | func NewNodeFromStrings(sT, sID string) (*Node, error) {
t, err := NewType(sT)
if err != nil {
return nil, err
}
n, err := NewID(sID)
if err != nil {
return nil, err
}
return NewNode(t, n), nil
} | [
"func",
"NewNodeFromStrings",
"(",
"sT",
",",
"sID",
"string",
")",
"(",
"*",
"Node",
",",
"error",
")",
"{",
"t",
",",
"err",
":=",
"NewType",
"(",
"sT",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"n",
",",
"err",
":=",
"NewID",
"(",
"sID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"NewNode",
"(",
"t",
",",
"n",
")",
",",
"nil",
"\n",
"}"
]
| // NewNodeFromStrings returns a new node constructed from a type and ID
// represented as plain strings. | [
"NewNodeFromStrings",
"returns",
"a",
"new",
"node",
"constructed",
"from",
"a",
"type",
"and",
"ID",
"represented",
"as",
"plain",
"strings",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/node/node.go#L157-L167 |
12,527 | google/badwolf | triple/node/node.go | NewBlankNode | func NewBlankNode() *Node {
uuid := <-nextVal
id := ID(uuid.String())
return &Node{
t: &tBlank,
id: &id,
}
} | go | func NewBlankNode() *Node {
uuid := <-nextVal
id := ID(uuid.String())
return &Node{
t: &tBlank,
id: &id,
}
} | [
"func",
"NewBlankNode",
"(",
")",
"*",
"Node",
"{",
"uuid",
":=",
"<-",
"nextVal",
"\n",
"id",
":=",
"ID",
"(",
"uuid",
".",
"String",
"(",
")",
")",
"\n",
"return",
"&",
"Node",
"{",
"t",
":",
"&",
"tBlank",
",",
"id",
":",
"&",
"id",
",",
"}",
"\n",
"}"
]
| // NewBlankNode creates a new blank node. The blank node ID is guaranteed to
// be unique in BadWolf. | [
"NewBlankNode",
"creates",
"a",
"new",
"blank",
"node",
".",
"The",
"blank",
"node",
"ID",
"is",
"guaranteed",
"to",
"be",
"unique",
"in",
"BadWolf",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/node/node.go#L215-L222 |
12,528 | google/badwolf | triple/node/node.go | UUID | func (n *Node) UUID() uuid.UUID {
var buffer bytes.Buffer
buffer.WriteString(string(*n.t))
buffer.WriteString(string(*n.id))
return uuid.NewSHA1(uuid.NIL, buffer.Bytes())
} | go | func (n *Node) UUID() uuid.UUID {
var buffer bytes.Buffer
buffer.WriteString(string(*n.t))
buffer.WriteString(string(*n.id))
return uuid.NewSHA1(uuid.NIL, buffer.Bytes())
} | [
"func",
"(",
"n",
"*",
"Node",
")",
"UUID",
"(",
")",
"uuid",
".",
"UUID",
"{",
"var",
"buffer",
"bytes",
".",
"Buffer",
"\n",
"buffer",
".",
"WriteString",
"(",
"string",
"(",
"*",
"n",
".",
"t",
")",
")",
"\n",
"buffer",
".",
"WriteString",
"(",
"string",
"(",
"*",
"n",
".",
"id",
")",
")",
"\n",
"return",
"uuid",
".",
"NewSHA1",
"(",
"uuid",
".",
"NIL",
",",
"buffer",
".",
"Bytes",
"(",
")",
")",
"\n",
"}"
]
| // UUID returns a global unique identifier for the given node. It is
// implemented as the SHA1 UUID of the node values. | [
"UUID",
"returns",
"a",
"global",
"unique",
"identifier",
"for",
"the",
"given",
"node",
".",
"It",
"is",
"implemented",
"as",
"the",
"SHA1",
"UUID",
"of",
"the",
"node",
"values",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/triple/node/node.go#L226-L231 |
12,529 | google/badwolf | bql/semantic/semantic.go | String | func (t StatementType) String() string {
switch t {
case Query:
return "QUERY"
case Insert:
return "INSERT"
case Delete:
return "DELETE"
case Create:
return "CREATE"
case Drop:
return "DROP"
case Construct:
return "CONSTRUCT"
case Deconstruct:
return "DECONSTRUCT"
case Show:
return "SHOW"
default:
return "UNKNOWN"
}
} | go | func (t StatementType) String() string {
switch t {
case Query:
return "QUERY"
case Insert:
return "INSERT"
case Delete:
return "DELETE"
case Create:
return "CREATE"
case Drop:
return "DROP"
case Construct:
return "CONSTRUCT"
case Deconstruct:
return "DECONSTRUCT"
case Show:
return "SHOW"
default:
return "UNKNOWN"
}
} | [
"func",
"(",
"t",
"StatementType",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"t",
"{",
"case",
"Query",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Insert",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Delete",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Create",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Drop",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Construct",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Deconstruct",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Show",
":",
"return",
"\"",
"\"",
"\n",
"default",
":",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"}"
]
| // String provides a readable version of the StatementType. | [
"String",
"provides",
"a",
"readable",
"version",
"of",
"the",
"StatementType",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L60-L81 |
12,530 | google/badwolf | bql/semantic/semantic.go | BindingsMap | func (c *GraphClause) BindingsMap() map[string]int {
bm := make(map[string]int)
addToBindings(bm, c.SBinding)
addToBindings(bm, c.SAlias)
addToBindings(bm, c.STypeAlias)
addToBindings(bm, c.SIDAlias)
addToBindings(bm, c.PAlias)
addToBindings(bm, c.PAnchorBinding)
addToBindings(bm, c.PBinding)
addToBindings(bm, c.PLowerBoundAlias)
addToBindings(bm, c.PUpperBoundAlias)
addToBindings(bm, c.PIDAlias)
addToBindings(bm, c.PAnchorAlias)
addToBindings(bm, c.OBinding)
addToBindings(bm, c.OAlias)
addToBindings(bm, c.OTypeAlias)
addToBindings(bm, c.OIDAlias)
addToBindings(bm, c.OAnchorAlias)
addToBindings(bm, c.OAnchorBinding)
addToBindings(bm, c.OLowerBoundAlias)
addToBindings(bm, c.OUpperBoundAlias)
return bm
} | go | func (c *GraphClause) BindingsMap() map[string]int {
bm := make(map[string]int)
addToBindings(bm, c.SBinding)
addToBindings(bm, c.SAlias)
addToBindings(bm, c.STypeAlias)
addToBindings(bm, c.SIDAlias)
addToBindings(bm, c.PAlias)
addToBindings(bm, c.PAnchorBinding)
addToBindings(bm, c.PBinding)
addToBindings(bm, c.PLowerBoundAlias)
addToBindings(bm, c.PUpperBoundAlias)
addToBindings(bm, c.PIDAlias)
addToBindings(bm, c.PAnchorAlias)
addToBindings(bm, c.OBinding)
addToBindings(bm, c.OAlias)
addToBindings(bm, c.OTypeAlias)
addToBindings(bm, c.OIDAlias)
addToBindings(bm, c.OAnchorAlias)
addToBindings(bm, c.OAnchorBinding)
addToBindings(bm, c.OLowerBoundAlias)
addToBindings(bm, c.OUpperBoundAlias)
return bm
} | [
"func",
"(",
"c",
"*",
"GraphClause",
")",
"BindingsMap",
"(",
")",
"map",
"[",
"string",
"]",
"int",
"{",
"bm",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
")",
"\n\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"SBinding",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"SAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"STypeAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"SIDAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"PAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"PAnchorBinding",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"PBinding",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"PLowerBoundAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"PUpperBoundAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"PIDAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"PAnchorAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"OBinding",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"OAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"OTypeAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"OIDAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"OAnchorAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"OAnchorBinding",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"OLowerBoundAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"c",
".",
"OUpperBoundAlias",
")",
"\n\n",
"return",
"bm",
"\n",
"}"
]
| // BindingsMap returns the binding map for the graph clause. | [
"BindingsMap",
"returns",
"the",
"binding",
"map",
"for",
"the",
"graph",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L347-L371 |
12,531 | google/badwolf | bql/semantic/semantic.go | Bindings | func (c *GraphClause) Bindings() []string {
var bs []string
for k := range c.BindingsMap() {
bs = append(bs, k)
}
return bs
} | go | func (c *GraphClause) Bindings() []string {
var bs []string
for k := range c.BindingsMap() {
bs = append(bs, k)
}
return bs
} | [
"func",
"(",
"c",
"*",
"GraphClause",
")",
"Bindings",
"(",
")",
"[",
"]",
"string",
"{",
"var",
"bs",
"[",
"]",
"string",
"\n",
"for",
"k",
":=",
"range",
"c",
".",
"BindingsMap",
"(",
")",
"{",
"bs",
"=",
"append",
"(",
"bs",
",",
"k",
")",
"\n",
"}",
"\n",
"return",
"bs",
"\n",
"}"
]
| // Bindings returns the list of unique bindings listed in the graph clause. | [
"Bindings",
"returns",
"the",
"list",
"of",
"unique",
"bindings",
"listed",
"in",
"the",
"graph",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L374-L380 |
12,532 | google/badwolf | bql/semantic/semantic.go | String | func (c *ConstructClause) String() string {
b := bytes.NewBufferString("{ ")
// Subject section.
if c.S != nil {
b.WriteString(c.S.String())
} else {
b.WriteString(c.SBinding)
}
// Predicate-object pairs section.
for _, pop := range c.PredicateObjectPairs() {
b.WriteString(fmt.Sprintf("%v;", pop))
}
b.Truncate(b.Len() - 1)
b.WriteString(" }")
return b.String()
} | go | func (c *ConstructClause) String() string {
b := bytes.NewBufferString("{ ")
// Subject section.
if c.S != nil {
b.WriteString(c.S.String())
} else {
b.WriteString(c.SBinding)
}
// Predicate-object pairs section.
for _, pop := range c.PredicateObjectPairs() {
b.WriteString(fmt.Sprintf("%v;", pop))
}
b.Truncate(b.Len() - 1)
b.WriteString(" }")
return b.String()
} | [
"func",
"(",
"c",
"*",
"ConstructClause",
")",
"String",
"(",
")",
"string",
"{",
"b",
":=",
"bytes",
".",
"NewBufferString",
"(",
"\"",
"\"",
")",
"\n\n",
"// Subject section.",
"if",
"c",
".",
"S",
"!=",
"nil",
"{",
"b",
".",
"WriteString",
"(",
"c",
".",
"S",
".",
"String",
"(",
")",
")",
"\n",
"}",
"else",
"{",
"b",
".",
"WriteString",
"(",
"c",
".",
"SBinding",
")",
"\n",
"}",
"\n\n",
"// Predicate-object pairs section.",
"for",
"_",
",",
"pop",
":=",
"range",
"c",
".",
"PredicateObjectPairs",
"(",
")",
"{",
"b",
".",
"WriteString",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pop",
")",
")",
"\n",
"}",
"\n",
"b",
".",
"Truncate",
"(",
"b",
".",
"Len",
"(",
")",
"-",
"1",
")",
"\n",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"return",
"b",
".",
"String",
"(",
")",
"\n",
"}"
]
| // String returns a readable representation of a construct clause. | [
"String",
"returns",
"a",
"readable",
"representation",
"of",
"a",
"construct",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L388-L405 |
12,533 | google/badwolf | bql/semantic/semantic.go | String | func (c *ConstructPredicateObjectPair) String() string {
b := bytes.NewBufferString("")
// Predicate section.
predicate := false
if c.P != nil {
b.WriteString(" ")
b.WriteString(c.P.String())
predicate = true
}
if c.PBinding != "" {
b.WriteString(" ")
b.WriteString(c.PBinding)
}
if c.PID != "" {
b.WriteString(" \"")
b.WriteString(c.PID)
b.WriteString("\"")
}
if !predicate {
if !c.PTemporal {
b.WriteString("@[]")
} else {
b.WriteString("@[")
if c.PAnchorBinding != "" {
b.WriteString(c.PAnchorBinding)
}
}
b.WriteString("]")
}
// Object section.
// Node portion.
object := false
if c.O != nil {
b.WriteString(" ")
b.WriteString(c.O.String())
object = true
} else {
b.WriteString(" ")
b.WriteString(c.OBinding)
object = true
}
// Predicate portion.
if !object {
if c.OBinding != "" {
b.WriteString(" ")
b.WriteString(c.OBinding)
}
if c.OID != "" {
b.WriteString(" \"")
b.WriteString(c.OID)
b.WriteString("\"")
}
if !c.OTemporal {
b.WriteString("[]")
} else {
b.WriteString("[")
if c.OAnchorBinding != "" {
b.WriteString(c.OAnchorBinding)
}
b.WriteString("]")
}
}
return b.String()
} | go | func (c *ConstructPredicateObjectPair) String() string {
b := bytes.NewBufferString("")
// Predicate section.
predicate := false
if c.P != nil {
b.WriteString(" ")
b.WriteString(c.P.String())
predicate = true
}
if c.PBinding != "" {
b.WriteString(" ")
b.WriteString(c.PBinding)
}
if c.PID != "" {
b.WriteString(" \"")
b.WriteString(c.PID)
b.WriteString("\"")
}
if !predicate {
if !c.PTemporal {
b.WriteString("@[]")
} else {
b.WriteString("@[")
if c.PAnchorBinding != "" {
b.WriteString(c.PAnchorBinding)
}
}
b.WriteString("]")
}
// Object section.
// Node portion.
object := false
if c.O != nil {
b.WriteString(" ")
b.WriteString(c.O.String())
object = true
} else {
b.WriteString(" ")
b.WriteString(c.OBinding)
object = true
}
// Predicate portion.
if !object {
if c.OBinding != "" {
b.WriteString(" ")
b.WriteString(c.OBinding)
}
if c.OID != "" {
b.WriteString(" \"")
b.WriteString(c.OID)
b.WriteString("\"")
}
if !c.OTemporal {
b.WriteString("[]")
} else {
b.WriteString("[")
if c.OAnchorBinding != "" {
b.WriteString(c.OAnchorBinding)
}
b.WriteString("]")
}
}
return b.String()
} | [
"func",
"(",
"c",
"*",
"ConstructPredicateObjectPair",
")",
"String",
"(",
")",
"string",
"{",
"b",
":=",
"bytes",
".",
"NewBufferString",
"(",
"\"",
"\"",
")",
"\n\n",
"// Predicate section.",
"predicate",
":=",
"false",
"\n",
"if",
"c",
".",
"P",
"!=",
"nil",
"{",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"b",
".",
"WriteString",
"(",
"c",
".",
"P",
".",
"String",
"(",
")",
")",
"\n",
"predicate",
"=",
"true",
"\n",
"}",
"\n",
"if",
"c",
".",
"PBinding",
"!=",
"\"",
"\"",
"{",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"b",
".",
"WriteString",
"(",
"c",
".",
"PBinding",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"PID",
"!=",
"\"",
"\"",
"{",
"b",
".",
"WriteString",
"(",
"\"",
"\\\"",
"\"",
")",
"\n",
"b",
".",
"WriteString",
"(",
"c",
".",
"PID",
")",
"\n",
"b",
".",
"WriteString",
"(",
"\"",
"\\\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"predicate",
"{",
"if",
"!",
"c",
".",
"PTemporal",
"{",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"if",
"c",
".",
"PAnchorBinding",
"!=",
"\"",
"\"",
"{",
"b",
".",
"WriteString",
"(",
"c",
".",
"PAnchorBinding",
")",
"\n",
"}",
"\n",
"}",
"\n",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Object section.",
"// Node portion.",
"object",
":=",
"false",
"\n",
"if",
"c",
".",
"O",
"!=",
"nil",
"{",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"b",
".",
"WriteString",
"(",
"c",
".",
"O",
".",
"String",
"(",
")",
")",
"\n",
"object",
"=",
"true",
"\n",
"}",
"else",
"{",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"b",
".",
"WriteString",
"(",
"c",
".",
"OBinding",
")",
"\n",
"object",
"=",
"true",
"\n",
"}",
"\n",
"// Predicate portion.",
"if",
"!",
"object",
"{",
"if",
"c",
".",
"OBinding",
"!=",
"\"",
"\"",
"{",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"b",
".",
"WriteString",
"(",
"c",
".",
"OBinding",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"OID",
"!=",
"\"",
"\"",
"{",
"b",
".",
"WriteString",
"(",
"\"",
"\\\"",
"\"",
")",
"\n",
"b",
".",
"WriteString",
"(",
"c",
".",
"OID",
")",
"\n",
"b",
".",
"WriteString",
"(",
"\"",
"\\\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"c",
".",
"OTemporal",
"{",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"if",
"c",
".",
"OAnchorBinding",
"!=",
"\"",
"\"",
"{",
"b",
".",
"WriteString",
"(",
"c",
".",
"OAnchorBinding",
")",
"\n",
"}",
"\n",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"b",
".",
"String",
"(",
")",
"\n",
"}"
]
| // String returns a readable representation of a ConstructPredicateObjectPair. | [
"String",
"returns",
"a",
"readable",
"representation",
"of",
"a",
"ConstructPredicateObjectPair",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L413-L478 |
12,534 | google/badwolf | bql/semantic/semantic.go | AddGraph | func (s *Statement) AddGraph(g string) {
s.graphNames = append(s.graphNames, g)
} | go | func (s *Statement) AddGraph(g string) {
s.graphNames = append(s.graphNames, g)
} | [
"func",
"(",
"s",
"*",
"Statement",
")",
"AddGraph",
"(",
"g",
"string",
")",
"{",
"s",
".",
"graphNames",
"=",
"append",
"(",
"s",
".",
"graphNames",
",",
"g",
")",
"\n",
"}"
]
| // AddGraph adds a graph to a given statement. | [
"AddGraph",
"adds",
"a",
"graph",
"to",
"a",
"given",
"statement",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L496-L498 |
12,535 | google/badwolf | bql/semantic/semantic.go | AddInputGraph | func (s *Statement) AddInputGraph(g string) {
s.inputGraphNames = append(s.inputGraphNames, g)
} | go | func (s *Statement) AddInputGraph(g string) {
s.inputGraphNames = append(s.inputGraphNames, g)
} | [
"func",
"(",
"s",
"*",
"Statement",
")",
"AddInputGraph",
"(",
"g",
"string",
")",
"{",
"s",
".",
"inputGraphNames",
"=",
"append",
"(",
"s",
".",
"inputGraphNames",
",",
"g",
")",
"\n",
"}"
]
| // AddInputGraph adds an input graph to a given statement. | [
"AddInputGraph",
"adds",
"an",
"input",
"graph",
"to",
"a",
"given",
"statement",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L511-L513 |
12,536 | google/badwolf | bql/semantic/semantic.go | AddOutputGraph | func (s *Statement) AddOutputGraph(g string) {
s.outputGraphNames = append(s.outputGraphNames, g)
} | go | func (s *Statement) AddOutputGraph(g string) {
s.outputGraphNames = append(s.outputGraphNames, g)
} | [
"func",
"(",
"s",
"*",
"Statement",
")",
"AddOutputGraph",
"(",
"g",
"string",
")",
"{",
"s",
".",
"outputGraphNames",
"=",
"append",
"(",
"s",
".",
"outputGraphNames",
",",
"g",
")",
"\n",
"}"
]
| // AddOutputGraph adds an output graph to a given statement. | [
"AddOutputGraph",
"adds",
"an",
"output",
"graph",
"to",
"a",
"given",
"statement",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L526-L528 |
12,537 | google/badwolf | bql/semantic/semantic.go | Init | func (s *Statement) Init(ctx context.Context, st storage.Store) error {
for _, gn := range s.graphNames {
g, err := st.Graph(ctx, gn)
if err != nil {
return err
}
s.graphs = append(s.graphs, g)
}
for _, ign := range s.inputGraphNames {
ig, err := st.Graph(ctx, ign)
if err != nil {
return err
}
s.inputGraphs = append(s.inputGraphs, ig)
}
for _, ogn := range s.outputGraphNames {
og, err := st.Graph(ctx, ogn)
if err != nil {
return err
}
s.outputGraphs = append(s.outputGraphs, og)
}
return nil
} | go | func (s *Statement) Init(ctx context.Context, st storage.Store) error {
for _, gn := range s.graphNames {
g, err := st.Graph(ctx, gn)
if err != nil {
return err
}
s.graphs = append(s.graphs, g)
}
for _, ign := range s.inputGraphNames {
ig, err := st.Graph(ctx, ign)
if err != nil {
return err
}
s.inputGraphs = append(s.inputGraphs, ig)
}
for _, ogn := range s.outputGraphNames {
og, err := st.Graph(ctx, ogn)
if err != nil {
return err
}
s.outputGraphs = append(s.outputGraphs, og)
}
return nil
} | [
"func",
"(",
"s",
"*",
"Statement",
")",
"Init",
"(",
"ctx",
"context",
".",
"Context",
",",
"st",
"storage",
".",
"Store",
")",
"error",
"{",
"for",
"_",
",",
"gn",
":=",
"range",
"s",
".",
"graphNames",
"{",
"g",
",",
"err",
":=",
"st",
".",
"Graph",
"(",
"ctx",
",",
"gn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"s",
".",
"graphs",
"=",
"append",
"(",
"s",
".",
"graphs",
",",
"g",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"ign",
":=",
"range",
"s",
".",
"inputGraphNames",
"{",
"ig",
",",
"err",
":=",
"st",
".",
"Graph",
"(",
"ctx",
",",
"ign",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"s",
".",
"inputGraphs",
"=",
"append",
"(",
"s",
".",
"inputGraphs",
",",
"ig",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"ogn",
":=",
"range",
"s",
".",
"outputGraphNames",
"{",
"og",
",",
"err",
":=",
"st",
".",
"Graph",
"(",
"ctx",
",",
"ogn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"s",
".",
"outputGraphs",
"=",
"append",
"(",
"s",
".",
"outputGraphs",
",",
"og",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Init initializes all graphs given the graph names. | [
"Init",
"initializes",
"all",
"graphs",
"given",
"the",
"graph",
"names",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L536-L559 |
12,538 | google/badwolf | bql/semantic/semantic.go | AddData | func (s *Statement) AddData(d *triple.Triple) {
s.data = append(s.data, d)
} | go | func (s *Statement) AddData(d *triple.Triple) {
s.data = append(s.data, d)
} | [
"func",
"(",
"s",
"*",
"Statement",
")",
"AddData",
"(",
"d",
"*",
"triple",
".",
"Triple",
")",
"{",
"s",
".",
"data",
"=",
"append",
"(",
"s",
".",
"data",
",",
"d",
")",
"\n",
"}"
]
| // AddData adds a triple to a given statement's data. | [
"AddData",
"adds",
"a",
"triple",
"to",
"a",
"given",
"statement",
"s",
"data",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L567-L569 |
12,539 | google/badwolf | bql/semantic/semantic.go | AddWorkingGraphClause | func (s *Statement) AddWorkingGraphClause() {
if s.workingClause != nil && !s.workingClause.IsEmpty() {
s.pattern = append(s.pattern, s.workingClause)
}
s.ResetWorkingGraphClause()
} | go | func (s *Statement) AddWorkingGraphClause() {
if s.workingClause != nil && !s.workingClause.IsEmpty() {
s.pattern = append(s.pattern, s.workingClause)
}
s.ResetWorkingGraphClause()
} | [
"func",
"(",
"s",
"*",
"Statement",
")",
"AddWorkingGraphClause",
"(",
")",
"{",
"if",
"s",
".",
"workingClause",
"!=",
"nil",
"&&",
"!",
"s",
".",
"workingClause",
".",
"IsEmpty",
"(",
")",
"{",
"s",
".",
"pattern",
"=",
"append",
"(",
"s",
".",
"pattern",
",",
"s",
".",
"workingClause",
")",
"\n",
"}",
"\n",
"s",
".",
"ResetWorkingGraphClause",
"(",
")",
"\n",
"}"
]
| // AddWorkingGraphClause adds the current working graph clause to the set of
// clauses that form the graph pattern. | [
"AddWorkingGraphClause",
"adds",
"the",
"current",
"working",
"graph",
"clause",
"to",
"the",
"set",
"of",
"clauses",
"that",
"form",
"the",
"graph",
"pattern",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L593-L598 |
12,540 | google/badwolf | bql/semantic/semantic.go | BindingsMap | func (s *Statement) BindingsMap() map[string]int {
bm := make(map[string]int)
for _, cls := range s.pattern {
if cls != nil {
addToBindings(bm, cls.SBinding)
addToBindings(bm, cls.SAlias)
addToBindings(bm, cls.STypeAlias)
addToBindings(bm, cls.SIDAlias)
addToBindings(bm, cls.PAlias)
addToBindings(bm, cls.PAnchorBinding)
addToBindings(bm, cls.PBinding)
addToBindings(bm, cls.PLowerBoundAlias)
addToBindings(bm, cls.PUpperBoundAlias)
addToBindings(bm, cls.PIDAlias)
addToBindings(bm, cls.PAnchorAlias)
addToBindings(bm, cls.OBinding)
addToBindings(bm, cls.OAlias)
addToBindings(bm, cls.OTypeAlias)
addToBindings(bm, cls.OIDAlias)
addToBindings(bm, cls.OAnchorAlias)
addToBindings(bm, cls.OAnchorBinding)
addToBindings(bm, cls.OLowerBoundAlias)
addToBindings(bm, cls.OUpperBoundAlias)
}
}
return bm
} | go | func (s *Statement) BindingsMap() map[string]int {
bm := make(map[string]int)
for _, cls := range s.pattern {
if cls != nil {
addToBindings(bm, cls.SBinding)
addToBindings(bm, cls.SAlias)
addToBindings(bm, cls.STypeAlias)
addToBindings(bm, cls.SIDAlias)
addToBindings(bm, cls.PAlias)
addToBindings(bm, cls.PAnchorBinding)
addToBindings(bm, cls.PBinding)
addToBindings(bm, cls.PLowerBoundAlias)
addToBindings(bm, cls.PUpperBoundAlias)
addToBindings(bm, cls.PIDAlias)
addToBindings(bm, cls.PAnchorAlias)
addToBindings(bm, cls.OBinding)
addToBindings(bm, cls.OAlias)
addToBindings(bm, cls.OTypeAlias)
addToBindings(bm, cls.OIDAlias)
addToBindings(bm, cls.OAnchorAlias)
addToBindings(bm, cls.OAnchorBinding)
addToBindings(bm, cls.OLowerBoundAlias)
addToBindings(bm, cls.OUpperBoundAlias)
}
}
return bm
} | [
"func",
"(",
"s",
"*",
"Statement",
")",
"BindingsMap",
"(",
")",
"map",
"[",
"string",
"]",
"int",
"{",
"bm",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
")",
"\n\n",
"for",
"_",
",",
"cls",
":=",
"range",
"s",
".",
"pattern",
"{",
"if",
"cls",
"!=",
"nil",
"{",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"SBinding",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"SAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"STypeAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"SIDAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"PAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"PAnchorBinding",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"PBinding",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"PLowerBoundAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"PUpperBoundAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"PIDAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"PAnchorAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"OBinding",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"OAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"OTypeAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"OIDAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"OAnchorAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"OAnchorBinding",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"OLowerBoundAlias",
")",
"\n",
"addToBindings",
"(",
"bm",
",",
"cls",
".",
"OUpperBoundAlias",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"bm",
"\n",
"}"
]
| // BindingsMap returns the set of bindings available on the graph clauses for the
// statement. | [
"BindingsMap",
"returns",
"the",
"set",
"of",
"bindings",
"available",
"on",
"the",
"graph",
"clauses",
"for",
"the",
"statement",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L634-L661 |
12,541 | google/badwolf | bql/semantic/semantic.go | Bindings | func (s *Statement) Bindings() []string {
var bs []string
for k := range s.BindingsMap() {
bs = append(bs, k)
}
return bs
} | go | func (s *Statement) Bindings() []string {
var bs []string
for k := range s.BindingsMap() {
bs = append(bs, k)
}
return bs
} | [
"func",
"(",
"s",
"*",
"Statement",
")",
"Bindings",
"(",
")",
"[",
"]",
"string",
"{",
"var",
"bs",
"[",
"]",
"string",
"\n",
"for",
"k",
":=",
"range",
"s",
".",
"BindingsMap",
"(",
")",
"{",
"bs",
"=",
"append",
"(",
"bs",
",",
"k",
")",
"\n",
"}",
"\n",
"return",
"bs",
"\n",
"}"
]
| // Bindings returns the list of bindings available on the graph clauses for he
// statement. | [
"Bindings",
"returns",
"the",
"list",
"of",
"bindings",
"available",
"on",
"the",
"graph",
"clauses",
"for",
"he",
"statement",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L665-L671 |
12,542 | google/badwolf | bql/semantic/semantic.go | Swap | func (s bySpecificity) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | go | func (s bySpecificity) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | [
"func",
"(",
"s",
"bySpecificity",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"s",
"[",
"i",
"]",
",",
"s",
"[",
"j",
"]",
"=",
"s",
"[",
"j",
"]",
",",
"s",
"[",
"i",
"]",
"\n",
"}"
]
| // Swap exchanges the i and j elements in the clauses array. | [
"Swap",
"exchanges",
"the",
"i",
"and",
"j",
"elements",
"in",
"the",
"clauses",
"array",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L682-L684 |
12,543 | google/badwolf | bql/semantic/semantic.go | Less | func (s bySpecificity) Less(i, j int) bool {
return s[i].Specificity() >= s[j].Specificity()
} | go | func (s bySpecificity) Less(i, j int) bool {
return s[i].Specificity() >= s[j].Specificity()
} | [
"func",
"(",
"s",
"bySpecificity",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"s",
"[",
"i",
"]",
".",
"Specificity",
"(",
")",
">=",
"s",
"[",
"j",
"]",
".",
"Specificity",
"(",
")",
"\n",
"}"
]
| // Less returns true if the i element is less specific than j one. | [
"Less",
"returns",
"true",
"if",
"the",
"i",
"element",
"is",
"less",
"specific",
"than",
"j",
"one",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L687-L689 |
12,544 | google/badwolf | bql/semantic/semantic.go | SortedGraphPatternClauses | func (s *Statement) SortedGraphPatternClauses() []*GraphClause {
var ptrns []*GraphClause
// Filter empty clauses.
for _, cls := range s.pattern {
if cls != nil && !cls.IsEmpty() {
ptrns = append(ptrns, cls)
}
}
sort.Sort(bySpecificity(ptrns))
return ptrns
} | go | func (s *Statement) SortedGraphPatternClauses() []*GraphClause {
var ptrns []*GraphClause
// Filter empty clauses.
for _, cls := range s.pattern {
if cls != nil && !cls.IsEmpty() {
ptrns = append(ptrns, cls)
}
}
sort.Sort(bySpecificity(ptrns))
return ptrns
} | [
"func",
"(",
"s",
"*",
"Statement",
")",
"SortedGraphPatternClauses",
"(",
")",
"[",
"]",
"*",
"GraphClause",
"{",
"var",
"ptrns",
"[",
"]",
"*",
"GraphClause",
"\n",
"// Filter empty clauses.",
"for",
"_",
",",
"cls",
":=",
"range",
"s",
".",
"pattern",
"{",
"if",
"cls",
"!=",
"nil",
"&&",
"!",
"cls",
".",
"IsEmpty",
"(",
")",
"{",
"ptrns",
"=",
"append",
"(",
"ptrns",
",",
"cls",
")",
"\n",
"}",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"bySpecificity",
"(",
"ptrns",
")",
")",
"\n",
"return",
"ptrns",
"\n",
"}"
]
| // SortedGraphPatternClauses return the list of graph pattern clauses | [
"SortedGraphPatternClauses",
"return",
"the",
"list",
"of",
"graph",
"pattern",
"clauses"
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L692-L702 |
12,545 | google/badwolf | bql/semantic/semantic.go | String | func (p *Projection) String() string {
b := bytes.NewBufferString(p.Binding)
b.WriteString(" as ")
b.WriteString(p.Binding)
if p.OP != lexer.ItemError {
b.WriteString(" via ")
b.WriteString(p.OP.String())
if p.Modifier != lexer.ItemError {
b.WriteString(" ")
b.WriteString(p.Modifier.String())
}
}
return b.String()
} | go | func (p *Projection) String() string {
b := bytes.NewBufferString(p.Binding)
b.WriteString(" as ")
b.WriteString(p.Binding)
if p.OP != lexer.ItemError {
b.WriteString(" via ")
b.WriteString(p.OP.String())
if p.Modifier != lexer.ItemError {
b.WriteString(" ")
b.WriteString(p.Modifier.String())
}
}
return b.String()
} | [
"func",
"(",
"p",
"*",
"Projection",
")",
"String",
"(",
")",
"string",
"{",
"b",
":=",
"bytes",
".",
"NewBufferString",
"(",
"p",
".",
"Binding",
")",
"\n",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"b",
".",
"WriteString",
"(",
"p",
".",
"Binding",
")",
"\n",
"if",
"p",
".",
"OP",
"!=",
"lexer",
".",
"ItemError",
"{",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"b",
".",
"WriteString",
"(",
"p",
".",
"OP",
".",
"String",
"(",
")",
")",
"\n",
"if",
"p",
".",
"Modifier",
"!=",
"lexer",
".",
"ItemError",
"{",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"b",
".",
"WriteString",
"(",
"p",
".",
"Modifier",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"b",
".",
"String",
"(",
")",
"\n",
"}"
]
| // String returns a readable form of the projection. | [
"String",
"returns",
"a",
"readable",
"form",
"of",
"the",
"projection",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L715-L728 |
12,546 | google/badwolf | bql/semantic/semantic.go | IsEmpty | func (p *Projection) IsEmpty() bool {
return p.Binding == "" && p.Alias == "" && p.OP == lexer.ItemError && p.Modifier == lexer.ItemError
} | go | func (p *Projection) IsEmpty() bool {
return p.Binding == "" && p.Alias == "" && p.OP == lexer.ItemError && p.Modifier == lexer.ItemError
} | [
"func",
"(",
"p",
"*",
"Projection",
")",
"IsEmpty",
"(",
")",
"bool",
"{",
"return",
"p",
".",
"Binding",
"==",
"\"",
"\"",
"&&",
"p",
".",
"Alias",
"==",
"\"",
"\"",
"&&",
"p",
".",
"OP",
"==",
"lexer",
".",
"ItemError",
"&&",
"p",
".",
"Modifier",
"==",
"lexer",
".",
"ItemError",
"\n",
"}"
]
| // IsEmpty checks if the given projection is empty. | [
"IsEmpty",
"checks",
"if",
"the",
"given",
"projection",
"is",
"empty",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L731-L733 |
12,547 | google/badwolf | bql/semantic/semantic.go | WorkingProjection | func (s *Statement) WorkingProjection() *Projection {
if s.workingProjection == nil {
s.ResetProjection()
}
return s.workingProjection
} | go | func (s *Statement) WorkingProjection() *Projection {
if s.workingProjection == nil {
s.ResetProjection()
}
return s.workingProjection
} | [
"func",
"(",
"s",
"*",
"Statement",
")",
"WorkingProjection",
"(",
")",
"*",
"Projection",
"{",
"if",
"s",
".",
"workingProjection",
"==",
"nil",
"{",
"s",
".",
"ResetProjection",
"(",
")",
"\n",
"}",
"\n",
"return",
"s",
".",
"workingProjection",
"\n",
"}"
]
| // WorkingProjection returns the current working variable projection. | [
"WorkingProjection",
"returns",
"the",
"current",
"working",
"variable",
"projection",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L741-L746 |
12,548 | google/badwolf | bql/semantic/semantic.go | AddWorkingProjection | func (s *Statement) AddWorkingProjection() {
if s.workingProjection != nil && !s.workingProjection.IsEmpty() {
s.projection = append(s.projection, s.workingProjection)
}
s.ResetProjection()
} | go | func (s *Statement) AddWorkingProjection() {
if s.workingProjection != nil && !s.workingProjection.IsEmpty() {
s.projection = append(s.projection, s.workingProjection)
}
s.ResetProjection()
} | [
"func",
"(",
"s",
"*",
"Statement",
")",
"AddWorkingProjection",
"(",
")",
"{",
"if",
"s",
".",
"workingProjection",
"!=",
"nil",
"&&",
"!",
"s",
".",
"workingProjection",
".",
"IsEmpty",
"(",
")",
"{",
"s",
".",
"projection",
"=",
"append",
"(",
"s",
".",
"projection",
",",
"s",
".",
"workingProjection",
")",
"\n",
"}",
"\n",
"s",
".",
"ResetProjection",
"(",
")",
"\n",
"}"
]
| // AddWorkingProjection adds the current projection variable to the set of
// projects that this statement. | [
"AddWorkingProjection",
"adds",
"the",
"current",
"projection",
"variable",
"to",
"the",
"set",
"of",
"projects",
"that",
"this",
"statement",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L750-L755 |
12,549 | google/badwolf | bql/semantic/semantic.go | InputBindings | func (s *Statement) InputBindings() []string {
var res []string
for _, p := range s.projection {
if p.Binding != "" {
res = append(res, p.Binding)
}
}
for _, c := range s.constructClauses {
if c.SBinding != "" {
res = append(res, c.SBinding)
}
for _, p := range c.predicateObjectPairs {
if p.PBinding != "" {
res = append(res, p.PBinding)
}
if p.PAnchorBinding != "" {
res = append(res, p.PAnchorBinding)
}
if p.OBinding != "" {
res = append(res, p.OBinding)
}
if p.OAnchorBinding != "" {
res = append(res, p.OAnchorBinding)
}
}
}
return res
} | go | func (s *Statement) InputBindings() []string {
var res []string
for _, p := range s.projection {
if p.Binding != "" {
res = append(res, p.Binding)
}
}
for _, c := range s.constructClauses {
if c.SBinding != "" {
res = append(res, c.SBinding)
}
for _, p := range c.predicateObjectPairs {
if p.PBinding != "" {
res = append(res, p.PBinding)
}
if p.PAnchorBinding != "" {
res = append(res, p.PAnchorBinding)
}
if p.OBinding != "" {
res = append(res, p.OBinding)
}
if p.OAnchorBinding != "" {
res = append(res, p.OAnchorBinding)
}
}
}
return res
} | [
"func",
"(",
"s",
"*",
"Statement",
")",
"InputBindings",
"(",
")",
"[",
"]",
"string",
"{",
"var",
"res",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"s",
".",
"projection",
"{",
"if",
"p",
".",
"Binding",
"!=",
"\"",
"\"",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"p",
".",
"Binding",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"s",
".",
"constructClauses",
"{",
"if",
"c",
".",
"SBinding",
"!=",
"\"",
"\"",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"c",
".",
"SBinding",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"c",
".",
"predicateObjectPairs",
"{",
"if",
"p",
".",
"PBinding",
"!=",
"\"",
"\"",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"p",
".",
"PBinding",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"PAnchorBinding",
"!=",
"\"",
"\"",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"p",
".",
"PAnchorBinding",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"OBinding",
"!=",
"\"",
"\"",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"p",
".",
"OBinding",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"OAnchorBinding",
"!=",
"\"",
"\"",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"p",
".",
"OAnchorBinding",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
]
| // InputBindings returns the list of incoming bindings feed from a where clause. | [
"InputBindings",
"returns",
"the",
"list",
"of",
"incoming",
"bindings",
"feed",
"from",
"a",
"where",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L763-L790 |
12,550 | google/badwolf | bql/semantic/semantic.go | OutputBindings | func (s *Statement) OutputBindings() []string {
var res []string
for _, p := range s.projection {
if p.Alias != "" {
res = append(res, p.Alias)
continue
}
if p.Binding != "" {
res = append(res, p.Binding)
}
}
set := make(map[string]bool)
set[""] = true
for _, c := range s.constructClauses {
if _, ok := set[c.SBinding]; !ok {
res = append(res, c.SBinding)
set[c.SBinding] = true
}
for _, p := range c.predicateObjectPairs {
if _, ok := set[p.PBinding]; !ok {
res = append(res, p.PBinding)
set[p.PBinding] = true
}
if _, ok := set[p.PAnchorBinding]; !ok {
res = append(res, p.PAnchorBinding)
set[p.PAnchorBinding] = true
}
if _, ok := set[p.OBinding]; !ok {
res = append(res, p.OBinding)
set[p.OBinding] = true
}
if _, ok := set[p.OAnchorBinding]; !ok {
res = append(res, p.OAnchorBinding)
set[p.OAnchorBinding] = true
}
}
}
return res
} | go | func (s *Statement) OutputBindings() []string {
var res []string
for _, p := range s.projection {
if p.Alias != "" {
res = append(res, p.Alias)
continue
}
if p.Binding != "" {
res = append(res, p.Binding)
}
}
set := make(map[string]bool)
set[""] = true
for _, c := range s.constructClauses {
if _, ok := set[c.SBinding]; !ok {
res = append(res, c.SBinding)
set[c.SBinding] = true
}
for _, p := range c.predicateObjectPairs {
if _, ok := set[p.PBinding]; !ok {
res = append(res, p.PBinding)
set[p.PBinding] = true
}
if _, ok := set[p.PAnchorBinding]; !ok {
res = append(res, p.PAnchorBinding)
set[p.PAnchorBinding] = true
}
if _, ok := set[p.OBinding]; !ok {
res = append(res, p.OBinding)
set[p.OBinding] = true
}
if _, ok := set[p.OAnchorBinding]; !ok {
res = append(res, p.OAnchorBinding)
set[p.OAnchorBinding] = true
}
}
}
return res
} | [
"func",
"(",
"s",
"*",
"Statement",
")",
"OutputBindings",
"(",
")",
"[",
"]",
"string",
"{",
"var",
"res",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"s",
".",
"projection",
"{",
"if",
"p",
".",
"Alias",
"!=",
"\"",
"\"",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"p",
".",
"Alias",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"p",
".",
"Binding",
"!=",
"\"",
"\"",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"p",
".",
"Binding",
")",
"\n",
"}",
"\n",
"}",
"\n",
"set",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"set",
"[",
"\"",
"\"",
"]",
"=",
"true",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"s",
".",
"constructClauses",
"{",
"if",
"_",
",",
"ok",
":=",
"set",
"[",
"c",
".",
"SBinding",
"]",
";",
"!",
"ok",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"c",
".",
"SBinding",
")",
"\n",
"set",
"[",
"c",
".",
"SBinding",
"]",
"=",
"true",
"\n",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"c",
".",
"predicateObjectPairs",
"{",
"if",
"_",
",",
"ok",
":=",
"set",
"[",
"p",
".",
"PBinding",
"]",
";",
"!",
"ok",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"p",
".",
"PBinding",
")",
"\n",
"set",
"[",
"p",
".",
"PBinding",
"]",
"=",
"true",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"set",
"[",
"p",
".",
"PAnchorBinding",
"]",
";",
"!",
"ok",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"p",
".",
"PAnchorBinding",
")",
"\n",
"set",
"[",
"p",
".",
"PAnchorBinding",
"]",
"=",
"true",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"set",
"[",
"p",
".",
"OBinding",
"]",
";",
"!",
"ok",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"p",
".",
"OBinding",
")",
"\n",
"set",
"[",
"p",
".",
"OBinding",
"]",
"=",
"true",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"set",
"[",
"p",
".",
"OAnchorBinding",
"]",
";",
"!",
"ok",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"p",
".",
"OAnchorBinding",
")",
"\n",
"set",
"[",
"p",
".",
"OAnchorBinding",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
]
| // OutputBindings returns the list of binding that a query will return. | [
"OutputBindings",
"returns",
"the",
"list",
"of",
"binding",
"that",
"a",
"query",
"will",
"return",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L793-L831 |
12,551 | google/badwolf | bql/semantic/semantic.go | AddWorkingConstructClause | func (s *Statement) AddWorkingConstructClause() {
if s.workingConstructClause != nil && !s.workingConstructClause.IsEmpty() {
s.constructClauses = append(s.constructClauses, s.workingConstructClause)
}
s.ResetWorkingConstructClause()
} | go | func (s *Statement) AddWorkingConstructClause() {
if s.workingConstructClause != nil && !s.workingConstructClause.IsEmpty() {
s.constructClauses = append(s.constructClauses, s.workingConstructClause)
}
s.ResetWorkingConstructClause()
} | [
"func",
"(",
"s",
"*",
"Statement",
")",
"AddWorkingConstructClause",
"(",
")",
"{",
"if",
"s",
".",
"workingConstructClause",
"!=",
"nil",
"&&",
"!",
"s",
".",
"workingConstructClause",
".",
"IsEmpty",
"(",
")",
"{",
"s",
".",
"constructClauses",
"=",
"append",
"(",
"s",
".",
"constructClauses",
",",
"s",
".",
"workingConstructClause",
")",
"\n",
"}",
"\n",
"s",
".",
"ResetWorkingConstructClause",
"(",
")",
"\n",
"}"
]
| // AddWorkingConstructClause adds the current working construct clause to the set
// of construct clauses that form the construct statement. | [
"AddWorkingConstructClause",
"adds",
"the",
"current",
"working",
"construct",
"clause",
"to",
"the",
"set",
"of",
"construct",
"clauses",
"that",
"form",
"the",
"construct",
"statement",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L889-L894 |
12,552 | google/badwolf | bql/semantic/semantic.go | AddWorkingPredicateObjectPair | func (c *ConstructClause) AddWorkingPredicateObjectPair() {
if c.workingPredicateObjectPair != nil && !c.workingPredicateObjectPair.IsEmpty() {
c.predicateObjectPairs = append(c.predicateObjectPairs, c.workingPredicateObjectPair)
}
c.ResetWorkingPredicateObjectPair()
} | go | func (c *ConstructClause) AddWorkingPredicateObjectPair() {
if c.workingPredicateObjectPair != nil && !c.workingPredicateObjectPair.IsEmpty() {
c.predicateObjectPairs = append(c.predicateObjectPairs, c.workingPredicateObjectPair)
}
c.ResetWorkingPredicateObjectPair()
} | [
"func",
"(",
"c",
"*",
"ConstructClause",
")",
"AddWorkingPredicateObjectPair",
"(",
")",
"{",
"if",
"c",
".",
"workingPredicateObjectPair",
"!=",
"nil",
"&&",
"!",
"c",
".",
"workingPredicateObjectPair",
".",
"IsEmpty",
"(",
")",
"{",
"c",
".",
"predicateObjectPairs",
"=",
"append",
"(",
"c",
".",
"predicateObjectPairs",
",",
"c",
".",
"workingPredicateObjectPair",
")",
"\n",
"}",
"\n",
"c",
".",
"ResetWorkingPredicateObjectPair",
"(",
")",
"\n",
"}"
]
| // AddWorkingPredicateObjectPair adds the working predicate-object pair to the set
// of predicate-object pairs belonging to the construct clause. | [
"AddWorkingPredicateObjectPair",
"adds",
"the",
"working",
"predicate",
"-",
"object",
"pair",
"to",
"the",
"set",
"of",
"predicate",
"-",
"object",
"pairs",
"belonging",
"to",
"the",
"construct",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/semantic/semantic.go#L916-L921 |
12,553 | google/badwolf | bql/grammar/parser.go | NewSymbol | func NewSymbol(s semantic.Symbol) Element {
return Element{
isSymbol: true,
symbol: s,
}
} | go | func NewSymbol(s semantic.Symbol) Element {
return Element{
isSymbol: true,
symbol: s,
}
} | [
"func",
"NewSymbol",
"(",
"s",
"semantic",
".",
"Symbol",
")",
"Element",
"{",
"return",
"Element",
"{",
"isSymbol",
":",
"true",
",",
"symbol",
":",
"s",
",",
"}",
"\n",
"}"
]
| // NewSymbol creates a new element from a symbol. | [
"NewSymbol",
"creates",
"a",
"new",
"element",
"from",
"a",
"symbol",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/grammar/parser.go#L32-L37 |
12,554 | google/badwolf | bql/grammar/parser.go | NewTokenType | func NewTokenType(t lexer.TokenType) Element {
return Element{
isSymbol: false,
tokenType: t,
}
} | go | func NewTokenType(t lexer.TokenType) Element {
return Element{
isSymbol: false,
tokenType: t,
}
} | [
"func",
"NewTokenType",
"(",
"t",
"lexer",
".",
"TokenType",
")",
"Element",
"{",
"return",
"Element",
"{",
"isSymbol",
":",
"false",
",",
"tokenType",
":",
"t",
",",
"}",
"\n",
"}"
]
| // NewTokenType creates a new element from a token. | [
"NewTokenType",
"creates",
"a",
"new",
"element",
"from",
"a",
"token",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/grammar/parser.go#L40-L45 |
12,555 | google/badwolf | bql/grammar/parser.go | NewParser | func NewParser(grammar *Grammar) (*Parser, error) {
// Check that the grammar is left factorized.
for _, clauses := range *grammar {
idx := 0
for _, cls := range clauses {
if len(cls.Elements) == 0 {
if idx == 0 {
idx++
continue
}
return nil, fmt.Errorf("grammar.NewParser: invalid extra empty clause derivation %v", clauses)
}
if cls.Elements[0].isSymbol {
return nil, fmt.Errorf("grammar.NewParser: not left factored grammar in %v", clauses)
}
}
}
return &Parser{
grammar: grammar,
}, nil
} | go | func NewParser(grammar *Grammar) (*Parser, error) {
// Check that the grammar is left factorized.
for _, clauses := range *grammar {
idx := 0
for _, cls := range clauses {
if len(cls.Elements) == 0 {
if idx == 0 {
idx++
continue
}
return nil, fmt.Errorf("grammar.NewParser: invalid extra empty clause derivation %v", clauses)
}
if cls.Elements[0].isSymbol {
return nil, fmt.Errorf("grammar.NewParser: not left factored grammar in %v", clauses)
}
}
}
return &Parser{
grammar: grammar,
}, nil
} | [
"func",
"NewParser",
"(",
"grammar",
"*",
"Grammar",
")",
"(",
"*",
"Parser",
",",
"error",
")",
"{",
"// Check that the grammar is left factorized.",
"for",
"_",
",",
"clauses",
":=",
"range",
"*",
"grammar",
"{",
"idx",
":=",
"0",
"\n",
"for",
"_",
",",
"cls",
":=",
"range",
"clauses",
"{",
"if",
"len",
"(",
"cls",
".",
"Elements",
")",
"==",
"0",
"{",
"if",
"idx",
"==",
"0",
"{",
"idx",
"++",
"\n",
"continue",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"clauses",
")",
"\n",
"}",
"\n",
"if",
"cls",
".",
"Elements",
"[",
"0",
"]",
".",
"isSymbol",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"clauses",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"&",
"Parser",
"{",
"grammar",
":",
"grammar",
",",
"}",
",",
"nil",
"\n",
"}"
]
| // NewParser creates a new recursive descent parser for a left factorized
// grammar. | [
"NewParser",
"creates",
"a",
"new",
"recursive",
"descent",
"parser",
"for",
"a",
"left",
"factorized",
"grammar",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/grammar/parser.go#L77-L97 |
12,556 | google/badwolf | bql/grammar/parser.go | Parse | func (p *Parser) Parse(llk *LLk, st *semantic.Statement) error {
b, err := p.consume(llk, st, "START")
if err != nil {
return err
}
if !b {
return fmt.Errorf("Parser.Parse: inconsitent parser, no error found, and no tokens were consumed")
}
return nil
} | go | func (p *Parser) Parse(llk *LLk, st *semantic.Statement) error {
b, err := p.consume(llk, st, "START")
if err != nil {
return err
}
if !b {
return fmt.Errorf("Parser.Parse: inconsitent parser, no error found, and no tokens were consumed")
}
return nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"Parse",
"(",
"llk",
"*",
"LLk",
",",
"st",
"*",
"semantic",
".",
"Statement",
")",
"error",
"{",
"b",
",",
"err",
":=",
"p",
".",
"consume",
"(",
"llk",
",",
"st",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"!",
"b",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Parse attempts to run the parser for the given input. | [
"Parse",
"attempts",
"to",
"run",
"the",
"parser",
"for",
"the",
"given",
"input",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/grammar/parser.go#L100-L109 |
12,557 | google/badwolf | bql/grammar/parser.go | consume | func (p *Parser) consume(llk *LLk, st *semantic.Statement, s semantic.Symbol) (bool, error) {
for _, clause := range (*p.grammar)[s] {
if len(clause.Elements) == 0 {
return true, nil
}
elem := clause.Elements[0]
if elem.isSymbol {
return false, fmt.Errorf("Parser.consume: not left factored grammar in %v", clause)
}
if llk.CanAccept(elem.Token()) {
return p.expect(llk, st, s, clause)
}
}
return false, fmt.Errorf("Parser.consume: could not consume token %s in production %s", llk.Current(), s)
} | go | func (p *Parser) consume(llk *LLk, st *semantic.Statement, s semantic.Symbol) (bool, error) {
for _, clause := range (*p.grammar)[s] {
if len(clause.Elements) == 0 {
return true, nil
}
elem := clause.Elements[0]
if elem.isSymbol {
return false, fmt.Errorf("Parser.consume: not left factored grammar in %v", clause)
}
if llk.CanAccept(elem.Token()) {
return p.expect(llk, st, s, clause)
}
}
return false, fmt.Errorf("Parser.consume: could not consume token %s in production %s", llk.Current(), s)
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"consume",
"(",
"llk",
"*",
"LLk",
",",
"st",
"*",
"semantic",
".",
"Statement",
",",
"s",
"semantic",
".",
"Symbol",
")",
"(",
"bool",
",",
"error",
")",
"{",
"for",
"_",
",",
"clause",
":=",
"range",
"(",
"*",
"p",
".",
"grammar",
")",
"[",
"s",
"]",
"{",
"if",
"len",
"(",
"clause",
".",
"Elements",
")",
"==",
"0",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"elem",
":=",
"clause",
".",
"Elements",
"[",
"0",
"]",
"\n",
"if",
"elem",
".",
"isSymbol",
"{",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"clause",
")",
"\n",
"}",
"\n",
"if",
"llk",
".",
"CanAccept",
"(",
"elem",
".",
"Token",
"(",
")",
")",
"{",
"return",
"p",
".",
"expect",
"(",
"llk",
",",
"st",
",",
"s",
",",
"clause",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"llk",
".",
"Current",
"(",
")",
",",
"s",
")",
"\n",
"}"
]
| // consume attempts to consume all input tokens for the provided symbols given
// the parser grammar. | [
"consume",
"attempts",
"to",
"consume",
"all",
"input",
"tokens",
"for",
"the",
"provided",
"symbols",
"given",
"the",
"parser",
"grammar",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/grammar/parser.go#L113-L127 |
12,558 | google/badwolf | bql/grammar/parser.go | expect | func (p *Parser) expect(llk *LLk, st *semantic.Statement, s semantic.Symbol, cls *Clause) (bool, error) {
if cls.ProcessStart != nil {
if _, err := cls.ProcessStart(st, s); err != nil {
return false, err
}
}
for _, elem := range cls.Elements {
tkn := llk.Current()
if elem.isSymbol {
if b, err := p.consume(llk, st, elem.Symbol()); !b || err != nil {
return false, fmt.Errorf("Parser.parse: Failed to consume symbol %v, with error %v", elem.Symbol(), err)
}
} else {
if !llk.Consume(elem.Token()) {
return false, fmt.Errorf("Parser.parse: Failed to consume %s, got %s instead", elem.Token(), llk.Current().Type)
}
}
if cls.ProcessedElement != nil {
var ce semantic.ConsumedElement
if elem.isSymbol {
ce = semantic.NewConsumedSymbol(elem.Symbol())
} else {
ce = semantic.NewConsumedToken(tkn)
}
if _, err := cls.ProcessedElement(st, ce); err != nil {
return false, err
}
}
}
if cls.ProcessEnd != nil {
if _, err := cls.ProcessEnd(st, s); err != nil {
return false, err
}
}
return true, nil
} | go | func (p *Parser) expect(llk *LLk, st *semantic.Statement, s semantic.Symbol, cls *Clause) (bool, error) {
if cls.ProcessStart != nil {
if _, err := cls.ProcessStart(st, s); err != nil {
return false, err
}
}
for _, elem := range cls.Elements {
tkn := llk.Current()
if elem.isSymbol {
if b, err := p.consume(llk, st, elem.Symbol()); !b || err != nil {
return false, fmt.Errorf("Parser.parse: Failed to consume symbol %v, with error %v", elem.Symbol(), err)
}
} else {
if !llk.Consume(elem.Token()) {
return false, fmt.Errorf("Parser.parse: Failed to consume %s, got %s instead", elem.Token(), llk.Current().Type)
}
}
if cls.ProcessedElement != nil {
var ce semantic.ConsumedElement
if elem.isSymbol {
ce = semantic.NewConsumedSymbol(elem.Symbol())
} else {
ce = semantic.NewConsumedToken(tkn)
}
if _, err := cls.ProcessedElement(st, ce); err != nil {
return false, err
}
}
}
if cls.ProcessEnd != nil {
if _, err := cls.ProcessEnd(st, s); err != nil {
return false, err
}
}
return true, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"expect",
"(",
"llk",
"*",
"LLk",
",",
"st",
"*",
"semantic",
".",
"Statement",
",",
"s",
"semantic",
".",
"Symbol",
",",
"cls",
"*",
"Clause",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"cls",
".",
"ProcessStart",
"!=",
"nil",
"{",
"if",
"_",
",",
"err",
":=",
"cls",
".",
"ProcessStart",
"(",
"st",
",",
"s",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"elem",
":=",
"range",
"cls",
".",
"Elements",
"{",
"tkn",
":=",
"llk",
".",
"Current",
"(",
")",
"\n",
"if",
"elem",
".",
"isSymbol",
"{",
"if",
"b",
",",
"err",
":=",
"p",
".",
"consume",
"(",
"llk",
",",
"st",
",",
"elem",
".",
"Symbol",
"(",
")",
")",
";",
"!",
"b",
"||",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"elem",
".",
"Symbol",
"(",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"!",
"llk",
".",
"Consume",
"(",
"elem",
".",
"Token",
"(",
")",
")",
"{",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"elem",
".",
"Token",
"(",
")",
",",
"llk",
".",
"Current",
"(",
")",
".",
"Type",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"cls",
".",
"ProcessedElement",
"!=",
"nil",
"{",
"var",
"ce",
"semantic",
".",
"ConsumedElement",
"\n",
"if",
"elem",
".",
"isSymbol",
"{",
"ce",
"=",
"semantic",
".",
"NewConsumedSymbol",
"(",
"elem",
".",
"Symbol",
"(",
")",
")",
"\n",
"}",
"else",
"{",
"ce",
"=",
"semantic",
".",
"NewConsumedToken",
"(",
"tkn",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"cls",
".",
"ProcessedElement",
"(",
"st",
",",
"ce",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"cls",
".",
"ProcessEnd",
"!=",
"nil",
"{",
"if",
"_",
",",
"err",
":=",
"cls",
".",
"ProcessEnd",
"(",
"st",
",",
"s",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}"
]
| // expect given the input, symbol, and clause attempts to satisfy all elements. | [
"expect",
"given",
"the",
"input",
"symbol",
"and",
"clause",
"attempts",
"to",
"satisfy",
"all",
"elements",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/grammar/parser.go#L130-L165 |
12,559 | google/badwolf | tools/compliance/runner.go | getGraphFromStore | func getGraphFromStore(ctx context.Context, st storage.Store, id string) (storage.Graph, error) {
g, err := st.Graph(ctx, id)
if err == nil {
return g, nil
}
return st.NewGraph(ctx, id)
} | go | func getGraphFromStore(ctx context.Context, st storage.Store, id string) (storage.Graph, error) {
g, err := st.Graph(ctx, id)
if err == nil {
return g, nil
}
return st.NewGraph(ctx, id)
} | [
"func",
"getGraphFromStore",
"(",
"ctx",
"context",
".",
"Context",
",",
"st",
"storage",
".",
"Store",
",",
"id",
"string",
")",
"(",
"storage",
".",
"Graph",
",",
"error",
")",
"{",
"g",
",",
"err",
":=",
"st",
".",
"Graph",
"(",
"ctx",
",",
"id",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"g",
",",
"nil",
"\n",
"}",
"\n",
"return",
"st",
".",
"NewGraph",
"(",
"ctx",
",",
"id",
")",
"\n",
"}"
]
| // getGraphFromStore returns a Graph. Will create it if it does not exist. | [
"getGraphFromStore",
"returns",
"a",
"Graph",
".",
"Will",
"create",
"it",
"if",
"it",
"does",
"not",
"exist",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/compliance/runner.go#L32-L38 |
12,560 | google/badwolf | tools/compliance/runner.go | populateSources | func (s *Story) populateSources(ctx context.Context, st storage.Store, b literal.Builder) error {
for _, src := range s.Sources {
g, err := getGraphFromStore(ctx, st, src.ID)
if err != nil {
return err
}
var trps []*triple.Triple
for _, trp := range src.Facts {
t, err := triple.Parse(trp, b)
if err != nil {
return err
}
trps = append(trps, t)
}
if err := g.AddTriples(ctx, trps); err != nil {
return err
}
}
return nil
} | go | func (s *Story) populateSources(ctx context.Context, st storage.Store, b literal.Builder) error {
for _, src := range s.Sources {
g, err := getGraphFromStore(ctx, st, src.ID)
if err != nil {
return err
}
var trps []*triple.Triple
for _, trp := range src.Facts {
t, err := triple.Parse(trp, b)
if err != nil {
return err
}
trps = append(trps, t)
}
if err := g.AddTriples(ctx, trps); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"Story",
")",
"populateSources",
"(",
"ctx",
"context",
".",
"Context",
",",
"st",
"storage",
".",
"Store",
",",
"b",
"literal",
".",
"Builder",
")",
"error",
"{",
"for",
"_",
",",
"src",
":=",
"range",
"s",
".",
"Sources",
"{",
"g",
",",
"err",
":=",
"getGraphFromStore",
"(",
"ctx",
",",
"st",
",",
"src",
".",
"ID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"var",
"trps",
"[",
"]",
"*",
"triple",
".",
"Triple",
"\n",
"for",
"_",
",",
"trp",
":=",
"range",
"src",
".",
"Facts",
"{",
"t",
",",
"err",
":=",
"triple",
".",
"Parse",
"(",
"trp",
",",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"trps",
"=",
"append",
"(",
"trps",
",",
"t",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"g",
".",
"AddTriples",
"(",
"ctx",
",",
"trps",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // populateSources create all the graph required for the story and
// populates it with the provided data. | [
"populateSources",
"create",
"all",
"the",
"graph",
"required",
"for",
"the",
"story",
"and",
"populates",
"it",
"with",
"the",
"provided",
"data",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/compliance/runner.go#L42-L61 |
12,561 | google/badwolf | tools/compliance/runner.go | cleanSources | func (s *Story) cleanSources(ctx context.Context, st storage.Store) error {
for _, src := range s.Sources {
if err := st.DeleteGraph(ctx, src.ID); err != nil {
return err
}
}
return nil
} | go | func (s *Story) cleanSources(ctx context.Context, st storage.Store) error {
for _, src := range s.Sources {
if err := st.DeleteGraph(ctx, src.ID); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"Story",
")",
"cleanSources",
"(",
"ctx",
"context",
".",
"Context",
",",
"st",
"storage",
".",
"Store",
")",
"error",
"{",
"for",
"_",
",",
"src",
":=",
"range",
"s",
".",
"Sources",
"{",
"if",
"err",
":=",
"st",
".",
"DeleteGraph",
"(",
"ctx",
",",
"src",
".",
"ID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // cleanSources create all the graph required for the story and
// populates it with the provided data. | [
"cleanSources",
"create",
"all",
"the",
"graph",
"required",
"for",
"the",
"story",
"and",
"populates",
"it",
"with",
"the",
"provided",
"data",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/compliance/runner.go#L65-L72 |
12,562 | google/badwolf | tools/compliance/runner.go | runAssertion | func (a *Assertion) runAssertion(ctx context.Context, st storage.Store, chanSize, bulkSize int) (bool, *table.Table, *table.Table, error) {
errorizer := func(e error) (bool, *table.Table, *table.Table, error) {
if a.WillFail && e != nil {
return true, nil, nil, nil
}
return false, nil, nil, e
}
// Run the query.
p, err := grammar.NewParser(grammar.SemanticBQL())
if err != nil {
return errorizer(fmt.Errorf("Failed to initilize a valid BQL parser"))
}
stm := &semantic.Statement{}
if err := p.Parse(grammar.NewLLk(a.Statement, 1), stm); err != nil {
return errorizer(fmt.Errorf("Failed to parse BQL statement with error %v", err))
}
pln, err := planner.New(ctx, st, stm, chanSize, bulkSize, nil)
if err != nil {
return errorizer(fmt.Errorf("Should have not failed to create a plan using memory.DefaultStorage for statement %v with error %v", stm, err))
}
tbl, err := pln.Execute(ctx)
if err != nil {
return errorizer(fmt.Errorf("planner.Execute: failed to execute assertion %q with error %v", a.Requires, err))
}
// Check the output.
want, err := a.OutputTable(stm.OutputBindings())
if err != nil {
return errorizer(err)
}
// Cannot use reflect.DeepEqual, since projections only remove bindings from
// the table but not the actual data. However, the serialized text version
// of the tables will be equal regardless of the internal representation.
return tbl.String() == want.String(), tbl, want, nil
} | go | func (a *Assertion) runAssertion(ctx context.Context, st storage.Store, chanSize, bulkSize int) (bool, *table.Table, *table.Table, error) {
errorizer := func(e error) (bool, *table.Table, *table.Table, error) {
if a.WillFail && e != nil {
return true, nil, nil, nil
}
return false, nil, nil, e
}
// Run the query.
p, err := grammar.NewParser(grammar.SemanticBQL())
if err != nil {
return errorizer(fmt.Errorf("Failed to initilize a valid BQL parser"))
}
stm := &semantic.Statement{}
if err := p.Parse(grammar.NewLLk(a.Statement, 1), stm); err != nil {
return errorizer(fmt.Errorf("Failed to parse BQL statement with error %v", err))
}
pln, err := planner.New(ctx, st, stm, chanSize, bulkSize, nil)
if err != nil {
return errorizer(fmt.Errorf("Should have not failed to create a plan using memory.DefaultStorage for statement %v with error %v", stm, err))
}
tbl, err := pln.Execute(ctx)
if err != nil {
return errorizer(fmt.Errorf("planner.Execute: failed to execute assertion %q with error %v", a.Requires, err))
}
// Check the output.
want, err := a.OutputTable(stm.OutputBindings())
if err != nil {
return errorizer(err)
}
// Cannot use reflect.DeepEqual, since projections only remove bindings from
// the table but not the actual data. However, the serialized text version
// of the tables will be equal regardless of the internal representation.
return tbl.String() == want.String(), tbl, want, nil
} | [
"func",
"(",
"a",
"*",
"Assertion",
")",
"runAssertion",
"(",
"ctx",
"context",
".",
"Context",
",",
"st",
"storage",
".",
"Store",
",",
"chanSize",
",",
"bulkSize",
"int",
")",
"(",
"bool",
",",
"*",
"table",
".",
"Table",
",",
"*",
"table",
".",
"Table",
",",
"error",
")",
"{",
"errorizer",
":=",
"func",
"(",
"e",
"error",
")",
"(",
"bool",
",",
"*",
"table",
".",
"Table",
",",
"*",
"table",
".",
"Table",
",",
"error",
")",
"{",
"if",
"a",
".",
"WillFail",
"&&",
"e",
"!=",
"nil",
"{",
"return",
"true",
",",
"nil",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"false",
",",
"nil",
",",
"nil",
",",
"e",
"\n",
"}",
"\n\n",
"// Run the query.",
"p",
",",
"err",
":=",
"grammar",
".",
"NewParser",
"(",
"grammar",
".",
"SemanticBQL",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errorizer",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"stm",
":=",
"&",
"semantic",
".",
"Statement",
"{",
"}",
"\n",
"if",
"err",
":=",
"p",
".",
"Parse",
"(",
"grammar",
".",
"NewLLk",
"(",
"a",
".",
"Statement",
",",
"1",
")",
",",
"stm",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errorizer",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"pln",
",",
"err",
":=",
"planner",
".",
"New",
"(",
"ctx",
",",
"st",
",",
"stm",
",",
"chanSize",
",",
"bulkSize",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errorizer",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"stm",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"tbl",
",",
"err",
":=",
"pln",
".",
"Execute",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errorizer",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"a",
".",
"Requires",
",",
"err",
")",
")",
"\n",
"}",
"\n\n",
"// Check the output.",
"want",
",",
"err",
":=",
"a",
".",
"OutputTable",
"(",
"stm",
".",
"OutputBindings",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errorizer",
"(",
"err",
")",
"\n",
"}",
"\n",
"// Cannot use reflect.DeepEqual, since projections only remove bindings from",
"// the table but not the actual data. However, the serialized text version",
"// of the tables will be equal regardless of the internal representation.",
"return",
"tbl",
".",
"String",
"(",
")",
"==",
"want",
".",
"String",
"(",
")",
",",
"tbl",
",",
"want",
",",
"nil",
"\n",
"}"
]
| // runAssertion runs the assertion and compares the outcome. Returns the outcome
// of comparing the obtained result table with the assertion table if there is
// no error during the assertion. | [
"runAssertion",
"runs",
"the",
"assertion",
"and",
"compares",
"the",
"outcome",
".",
"Returns",
"the",
"outcome",
"of",
"comparing",
"the",
"obtained",
"result",
"table",
"with",
"the",
"assertion",
"table",
"if",
"there",
"is",
"no",
"error",
"during",
"the",
"assertion",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/compliance/runner.go#L77-L112 |
12,563 | google/badwolf | tools/compliance/runner.go | Run | func (s *Story) Run(ctx context.Context, st storage.Store, b literal.Builder, chanSize, bulkSize int) (map[string]*AssertionOutcome, error) {
// Populate the sources.
if err := s.populateSources(ctx, st, b); err != nil {
return nil, err
}
// Run assertions.
m := make(map[string]*AssertionOutcome)
for _, a := range s.Assertions {
b, got, want, err := a.runAssertion(ctx, st, chanSize, bulkSize)
if err != nil {
return nil, err
}
aName := fmt.Sprintf("requires %s", strings.TrimSpace(a.Requires))
m[aName] = &AssertionOutcome{
Equal: b,
Got: got,
Want: want,
}
}
// Clean the sources.
if err := s.cleanSources(ctx, st); err != nil {
return nil, err
}
return m, nil
} | go | func (s *Story) Run(ctx context.Context, st storage.Store, b literal.Builder, chanSize, bulkSize int) (map[string]*AssertionOutcome, error) {
// Populate the sources.
if err := s.populateSources(ctx, st, b); err != nil {
return nil, err
}
// Run assertions.
m := make(map[string]*AssertionOutcome)
for _, a := range s.Assertions {
b, got, want, err := a.runAssertion(ctx, st, chanSize, bulkSize)
if err != nil {
return nil, err
}
aName := fmt.Sprintf("requires %s", strings.TrimSpace(a.Requires))
m[aName] = &AssertionOutcome{
Equal: b,
Got: got,
Want: want,
}
}
// Clean the sources.
if err := s.cleanSources(ctx, st); err != nil {
return nil, err
}
return m, nil
} | [
"func",
"(",
"s",
"*",
"Story",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
",",
"st",
"storage",
".",
"Store",
",",
"b",
"literal",
".",
"Builder",
",",
"chanSize",
",",
"bulkSize",
"int",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"AssertionOutcome",
",",
"error",
")",
"{",
"// Populate the sources.",
"if",
"err",
":=",
"s",
".",
"populateSources",
"(",
"ctx",
",",
"st",
",",
"b",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// Run assertions.",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"AssertionOutcome",
")",
"\n",
"for",
"_",
",",
"a",
":=",
"range",
"s",
".",
"Assertions",
"{",
"b",
",",
"got",
",",
"want",
",",
"err",
":=",
"a",
".",
"runAssertion",
"(",
"ctx",
",",
"st",
",",
"chanSize",
",",
"bulkSize",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"aName",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strings",
".",
"TrimSpace",
"(",
"a",
".",
"Requires",
")",
")",
"\n",
"m",
"[",
"aName",
"]",
"=",
"&",
"AssertionOutcome",
"{",
"Equal",
":",
"b",
",",
"Got",
":",
"got",
",",
"Want",
":",
"want",
",",
"}",
"\n",
"}",
"\n",
"// Clean the sources.",
"if",
"err",
":=",
"s",
".",
"cleanSources",
"(",
"ctx",
",",
"st",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"m",
",",
"nil",
"\n",
"}"
]
| // Run evaluates a story. Returns if the story is true or not. It will also
// return an error if something wrong happen along the way. It is worth
// mentioning that Run does not clear any data available in the provided
// storage. | [
"Run",
"evaluates",
"a",
"story",
".",
"Returns",
"if",
"the",
"story",
"is",
"true",
"or",
"not",
".",
"It",
"will",
"also",
"return",
"an",
"error",
"if",
"something",
"wrong",
"happen",
"along",
"the",
"way",
".",
"It",
"is",
"worth",
"mentioning",
"that",
"Run",
"does",
"not",
"clear",
"any",
"data",
"available",
"in",
"the",
"provided",
"storage",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/compliance/runner.go#L118-L142 |
12,564 | google/badwolf | tools/compliance/runner.go | RunStories | func RunStories(ctx context.Context, st storage.Store, b literal.Builder, stories []*Story, chanSize, bulkSize int) *AssertionBattery {
results := &AssertionBattery{}
for _, s := range stories {
o, err := s.Run(ctx, st, b, chanSize, bulkSize)
results.Entries = append(results.Entries, &AssertionBatteryEntry{
Story: s,
Outcome: o,
Err: err,
})
}
return results
} | go | func RunStories(ctx context.Context, st storage.Store, b literal.Builder, stories []*Story, chanSize, bulkSize int) *AssertionBattery {
results := &AssertionBattery{}
for _, s := range stories {
o, err := s.Run(ctx, st, b, chanSize, bulkSize)
results.Entries = append(results.Entries, &AssertionBatteryEntry{
Story: s,
Outcome: o,
Err: err,
})
}
return results
} | [
"func",
"RunStories",
"(",
"ctx",
"context",
".",
"Context",
",",
"st",
"storage",
".",
"Store",
",",
"b",
"literal",
".",
"Builder",
",",
"stories",
"[",
"]",
"*",
"Story",
",",
"chanSize",
",",
"bulkSize",
"int",
")",
"*",
"AssertionBattery",
"{",
"results",
":=",
"&",
"AssertionBattery",
"{",
"}",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"stories",
"{",
"o",
",",
"err",
":=",
"s",
".",
"Run",
"(",
"ctx",
",",
"st",
",",
"b",
",",
"chanSize",
",",
"bulkSize",
")",
"\n",
"results",
".",
"Entries",
"=",
"append",
"(",
"results",
".",
"Entries",
",",
"&",
"AssertionBatteryEntry",
"{",
"Story",
":",
"s",
",",
"Outcome",
":",
"o",
",",
"Err",
":",
"err",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"results",
"\n",
"}"
]
| // RunStories runs a the provided stories and returns the outcome of each of
// them. | [
"RunStories",
"runs",
"a",
"the",
"provided",
"stories",
"and",
"returns",
"the",
"outcome",
"of",
"each",
"of",
"them",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/compliance/runner.go#L158-L169 |
12,565 | google/badwolf | tools/vcli/bw/server/server.go | runServer | func runServer(ctx context.Context, cmd *command.Command, args []string, store storage.Store, chanSize, bulkSize int) int {
// Check parameters.
if len(args) < 2 {
log.Printf("[%v] Missing required port number. ", time.Now())
cmd.Usage()
return 2
}
// Validate port number.
p := strings.TrimSpace(args[len(args)-1])
port, err := strconv.Atoi(p)
if err != nil {
log.Printf("[%v] Invalid port number %q; %v\n", time.Now(), p, err)
return 2
}
// Start the server.
log.Printf("[%v] Starting server at port %d\n", time.Now(), port)
s := &serverConfig{
store: store,
chanSize: chanSize,
bulkSize: bulkSize,
}
http.HandleFunc("/bql", s.bqlHandler)
http.HandleFunc("/", defaultHandler)
if err := http.ListenAndServe(":"+p, nil); err != nil {
log.Printf("[%v] Failed to start server on port %s; %v", time.Now(), p, err)
return 2
}
return 0
} | go | func runServer(ctx context.Context, cmd *command.Command, args []string, store storage.Store, chanSize, bulkSize int) int {
// Check parameters.
if len(args) < 2 {
log.Printf("[%v] Missing required port number. ", time.Now())
cmd.Usage()
return 2
}
// Validate port number.
p := strings.TrimSpace(args[len(args)-1])
port, err := strconv.Atoi(p)
if err != nil {
log.Printf("[%v] Invalid port number %q; %v\n", time.Now(), p, err)
return 2
}
// Start the server.
log.Printf("[%v] Starting server at port %d\n", time.Now(), port)
s := &serverConfig{
store: store,
chanSize: chanSize,
bulkSize: bulkSize,
}
http.HandleFunc("/bql", s.bqlHandler)
http.HandleFunc("/", defaultHandler)
if err := http.ListenAndServe(":"+p, nil); err != nil {
log.Printf("[%v] Failed to start server on port %s; %v", time.Now(), p, err)
return 2
}
return 0
} | [
"func",
"runServer",
"(",
"ctx",
"context",
".",
"Context",
",",
"cmd",
"*",
"command",
".",
"Command",
",",
"args",
"[",
"]",
"string",
",",
"store",
"storage",
".",
"Store",
",",
"chanSize",
",",
"bulkSize",
"int",
")",
"int",
"{",
"// Check parameters.",
"if",
"len",
"(",
"args",
")",
"<",
"2",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"cmd",
".",
"Usage",
"(",
")",
"\n",
"return",
"2",
"\n",
"}",
"\n\n",
"// Validate port number.",
"p",
":=",
"strings",
".",
"TrimSpace",
"(",
"args",
"[",
"len",
"(",
"args",
")",
"-",
"1",
"]",
")",
"\n",
"port",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"time",
".",
"Now",
"(",
")",
",",
"p",
",",
"err",
")",
"\n",
"return",
"2",
"\n",
"}",
"\n\n",
"// Start the server.",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"time",
".",
"Now",
"(",
")",
",",
"port",
")",
"\n",
"s",
":=",
"&",
"serverConfig",
"{",
"store",
":",
"store",
",",
"chanSize",
":",
"chanSize",
",",
"bulkSize",
":",
"bulkSize",
",",
"}",
"\n",
"http",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"s",
".",
"bqlHandler",
")",
"\n",
"http",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"defaultHandler",
")",
"\n",
"if",
"err",
":=",
"http",
".",
"ListenAndServe",
"(",
"\"",
"\"",
"+",
"p",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"time",
".",
"Now",
"(",
")",
",",
"p",
",",
"err",
")",
"\n",
"return",
"2",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}"
]
| // runServer runs the simple BQL endpoint. | [
"runServer",
"runs",
"the",
"simple",
"BQL",
"endpoint",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/server/server.go#L60-L90 |
12,566 | google/badwolf | tools/vcli/bw/server/server.go | bqlHandler | func (s *serverConfig) bqlHandler(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
w.WriteHeader(http.StatusMethodNotAllowed)
reportError(w, r, err)
return
}
if r.Method != http.MethodPost {
reportError(w, r, fmt.Errorf("invalid %s request on %q endpoint. Only POST request are accepted", r.Method, r.URL.Path))
log.Printf("[%s] Invalid request: %#v\n", time.Now(), r)
return
}
// Run the query.
var (
ctx context.Context
cancel context.CancelFunc
)
timeout, err := time.ParseDuration(r.FormValue("timeout"))
if err == nil {
// The request has a timeout, so create a context that is
// canceled automatically when the timeout expires.
ctx, cancel = context.WithTimeout(context.Background(), timeout)
} else {
ctx, cancel = context.WithCancel(context.Background())
}
defer cancel() // Cancel ctx as soon as handleSearch returns.
var res []*result
for _, q := range getQueries(r.PostForm["bqlQuery"]) {
if nq, err := url.QueryUnescape(q); err == nil {
q = strings.Replace(strings.Replace(nq, "\n", " ", -1), "\r", " ", -1)
}
t, err := BQL(ctx, q, s.store, s.chanSize, s.bulkSize)
r := &result{
Q: q,
T: t,
}
if err != nil {
log.Printf("[%s] %q failed; %v", time.Now(), q, err.Error())
r.Msg = err.Error()
} else {
r.Msg = "[OK]"
}
res = append(res, r)
}
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`[`))
cnt := len(res)
for _, r := range res {
w.Write([]byte(`{ "query": "`))
w.Write([]byte(strings.Replace(r.Q, `"`, `\"`, -1)))
w.Write([]byte(`", "msg": "`))
w.Write([]byte(strings.Replace(r.Msg, `"`, `\"`, -1)))
w.Write([]byte(`", "table": `))
if r.T == nil {
w.Write([]byte(`{}`))
} else {
r.T.ToJSON(w)
}
w.Write([]byte(` }`))
if cnt > 1 {
w.Write([]byte(`, `))
}
cnt--
}
w.Write([]byte(`]`))
} | go | func (s *serverConfig) bqlHandler(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
w.WriteHeader(http.StatusMethodNotAllowed)
reportError(w, r, err)
return
}
if r.Method != http.MethodPost {
reportError(w, r, fmt.Errorf("invalid %s request on %q endpoint. Only POST request are accepted", r.Method, r.URL.Path))
log.Printf("[%s] Invalid request: %#v\n", time.Now(), r)
return
}
// Run the query.
var (
ctx context.Context
cancel context.CancelFunc
)
timeout, err := time.ParseDuration(r.FormValue("timeout"))
if err == nil {
// The request has a timeout, so create a context that is
// canceled automatically when the timeout expires.
ctx, cancel = context.WithTimeout(context.Background(), timeout)
} else {
ctx, cancel = context.WithCancel(context.Background())
}
defer cancel() // Cancel ctx as soon as handleSearch returns.
var res []*result
for _, q := range getQueries(r.PostForm["bqlQuery"]) {
if nq, err := url.QueryUnescape(q); err == nil {
q = strings.Replace(strings.Replace(nq, "\n", " ", -1), "\r", " ", -1)
}
t, err := BQL(ctx, q, s.store, s.chanSize, s.bulkSize)
r := &result{
Q: q,
T: t,
}
if err != nil {
log.Printf("[%s] %q failed; %v", time.Now(), q, err.Error())
r.Msg = err.Error()
} else {
r.Msg = "[OK]"
}
res = append(res, r)
}
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`[`))
cnt := len(res)
for _, r := range res {
w.Write([]byte(`{ "query": "`))
w.Write([]byte(strings.Replace(r.Q, `"`, `\"`, -1)))
w.Write([]byte(`", "msg": "`))
w.Write([]byte(strings.Replace(r.Msg, `"`, `\"`, -1)))
w.Write([]byte(`", "table": `))
if r.T == nil {
w.Write([]byte(`{}`))
} else {
r.T.ToJSON(w)
}
w.Write([]byte(` }`))
if cnt > 1 {
w.Write([]byte(`, `))
}
cnt--
}
w.Write([]byte(`]`))
} | [
"func",
"(",
"s",
"*",
"serverConfig",
")",
"bqlHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"err",
":=",
"r",
".",
"ParseForm",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusMethodNotAllowed",
")",
"\n",
"reportError",
"(",
"w",
",",
"r",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"r",
".",
"Method",
"!=",
"http",
".",
"MethodPost",
"{",
"reportError",
"(",
"w",
",",
"r",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
".",
"Method",
",",
"r",
".",
"URL",
".",
"Path",
")",
")",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"time",
".",
"Now",
"(",
")",
",",
"r",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Run the query.",
"var",
"(",
"ctx",
"context",
".",
"Context",
"\n",
"cancel",
"context",
".",
"CancelFunc",
"\n",
")",
"\n",
"timeout",
",",
"err",
":=",
"time",
".",
"ParseDuration",
"(",
"r",
".",
"FormValue",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"// The request has a timeout, so create a context that is",
"// canceled automatically when the timeout expires.",
"ctx",
",",
"cancel",
"=",
"context",
".",
"WithTimeout",
"(",
"context",
".",
"Background",
"(",
")",
",",
"timeout",
")",
"\n",
"}",
"else",
"{",
"ctx",
",",
"cancel",
"=",
"context",
".",
"WithCancel",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"}",
"\n",
"defer",
"cancel",
"(",
")",
"// Cancel ctx as soon as handleSearch returns.",
"\n\n",
"var",
"res",
"[",
"]",
"*",
"result",
"\n",
"for",
"_",
",",
"q",
":=",
"range",
"getQueries",
"(",
"r",
".",
"PostForm",
"[",
"\"",
"\"",
"]",
")",
"{",
"if",
"nq",
",",
"err",
":=",
"url",
".",
"QueryUnescape",
"(",
"q",
")",
";",
"err",
"==",
"nil",
"{",
"q",
"=",
"strings",
".",
"Replace",
"(",
"strings",
".",
"Replace",
"(",
"nq",
",",
"\"",
"\\n",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
",",
"\"",
"\\r",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"}",
"\n",
"t",
",",
"err",
":=",
"BQL",
"(",
"ctx",
",",
"q",
",",
"s",
".",
"store",
",",
"s",
".",
"chanSize",
",",
"s",
".",
"bulkSize",
")",
"\n",
"r",
":=",
"&",
"result",
"{",
"Q",
":",
"q",
",",
"T",
":",
"t",
",",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"time",
".",
"Now",
"(",
")",
",",
"q",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"r",
".",
"Msg",
"=",
"err",
".",
"Error",
"(",
")",
"\n",
"}",
"else",
"{",
"r",
".",
"Msg",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"res",
"=",
"append",
"(",
"res",
",",
"r",
")",
"\n",
"}",
"\n\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"`[`",
")",
")",
"\n",
"cnt",
":=",
"len",
"(",
"res",
")",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"res",
"{",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"`{ \"query\": \"`",
")",
")",
"\n",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"strings",
".",
"Replace",
"(",
"r",
".",
"Q",
",",
"`\"`",
",",
"`\\\"`",
",",
"-",
"1",
")",
")",
")",
"\n",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"`\", \"msg\": \"`",
")",
")",
"\n",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"strings",
".",
"Replace",
"(",
"r",
".",
"Msg",
",",
"`\"`",
",",
"`\\\"`",
",",
"-",
"1",
")",
")",
")",
"\n",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"`\", \"table\": `",
")",
")",
"\n",
"if",
"r",
".",
"T",
"==",
"nil",
"{",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"`{}`",
")",
")",
"\n",
"}",
"else",
"{",
"r",
".",
"T",
".",
"ToJSON",
"(",
"w",
")",
"\n",
"}",
"\n",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"` }`",
")",
")",
"\n",
"if",
"cnt",
">",
"1",
"{",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"`, `",
")",
")",
"\n",
"}",
"\n",
"cnt",
"--",
"\n",
"}",
"\n",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"`]`",
")",
")",
"\n\n",
"}"
]
| // bqlHandler imPathUnescapeplements the handler to server BQL requests. | [
"bqlHandler",
"imPathUnescapeplements",
"the",
"handler",
"to",
"server",
"BQL",
"requests",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/server/server.go#L93-L161 |
12,567 | google/badwolf | tools/vcli/bw/server/server.go | getQueries | func getQueries(raw []string) []string {
var res []string
for _, q := range raw {
for _, qs := range strings.Split(q, ";") {
if nq := strings.TrimSpace(qs); len(nq) > 0 {
res = append(res, nq+";")
}
}
}
return res
} | go | func getQueries(raw []string) []string {
var res []string
for _, q := range raw {
for _, qs := range strings.Split(q, ";") {
if nq := strings.TrimSpace(qs); len(nq) > 0 {
res = append(res, nq+";")
}
}
}
return res
} | [
"func",
"getQueries",
"(",
"raw",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"var",
"res",
"[",
"]",
"string",
"\n\n",
"for",
"_",
",",
"q",
":=",
"range",
"raw",
"{",
"for",
"_",
",",
"qs",
":=",
"range",
"strings",
".",
"Split",
"(",
"q",
",",
"\"",
"\"",
")",
"{",
"if",
"nq",
":=",
"strings",
".",
"TrimSpace",
"(",
"qs",
")",
";",
"len",
"(",
"nq",
")",
">",
"0",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"nq",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"res",
"\n",
"}"
]
| // getQueries returns the list of queries found. It will split them if needed. | [
"getQueries",
"returns",
"the",
"list",
"of",
"queries",
"found",
".",
"It",
"will",
"split",
"them",
"if",
"needed",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/server/server.go#L171-L183 |
12,568 | google/badwolf | tools/vcli/bw/server/server.go | defaultHandler | func defaultHandler(w http.ResponseWriter, r *http.Request) {
if err := defaultEntryTemplate.Execute(w, nil); err != nil {
reportError(w, r, err)
}
} | go | func defaultHandler(w http.ResponseWriter, r *http.Request) {
if err := defaultEntryTemplate.Execute(w, nil); err != nil {
reportError(w, r, err)
}
} | [
"func",
"defaultHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"err",
":=",
"defaultEntryTemplate",
".",
"Execute",
"(",
"w",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"reportError",
"(",
"w",
",",
"r",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
]
| // defaultHandler implements the handler to server BQL requests. | [
"defaultHandler",
"implements",
"the",
"handler",
"to",
"server",
"BQL",
"requests",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/server/server.go#L207-L211 |
12,569 | google/badwolf | tools/vcli/bw/server/server.go | reportError | func reportError(w http.ResponseWriter, r *http.Request, err error) {
w.WriteHeader(http.StatusInternalServerError)
log.Printf("[%s] %v\n", time.Now(), err)
errorTemplate.Execute(w, err)
} | go | func reportError(w http.ResponseWriter, r *http.Request, err error) {
w.WriteHeader(http.StatusInternalServerError)
log.Printf("[%s] %v\n", time.Now(), err)
errorTemplate.Execute(w, err)
} | [
"func",
"reportError",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"err",
"error",
")",
"{",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"time",
".",
"Now",
"(",
")",
",",
"err",
")",
"\n",
"errorTemplate",
".",
"Execute",
"(",
"w",
",",
"err",
")",
"\n",
"}"
]
| // reportError reports the given error. | [
"reportError",
"reports",
"the",
"given",
"error",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/server/server.go#L214-L218 |
12,570 | google/badwolf | tools/vcli/bw/repl/repl.go | REPL | func REPL(od storage.Store, input *os.File, rl ReadLiner, chanSize, bulkSize, builderSize int, done chan bool) int {
var tracer io.Writer
ctx, isTracingToFile, sessionStart := context.Background(), false, time.Now()
driverPlain := func() storage.Store {
return od
}
driverWithMemoization := func() storage.Store {
return memoization.New(od)
}
driver := driverWithMemoization
stopTracing := func() {
if tracer != nil {
if isTracingToFile {
fmt.Println("Closing tracing file.")
tracer.(*os.File).Close()
}
tracer, isTracingToFile = nil, false
}
}
defer stopTracing()
fmt.Printf("Welcome to BadWolf vCli (%d.%d.%d-%s)\n", version.Major, version.Minor, version.Patch, version.Release)
fmt.Printf("Using driver %s/%s. Type quit; to exit.\n", driver().Name(ctx), driver().Version(ctx))
fmt.Printf("Session started at %v.\n", sessionStart.Format("2006-01-02T15:04:05.999999-07:00"))
fmt.Println("Memoization enabled. Type help; to print help.")
fmt.Println()
defer func() {
fmt.Printf("\n\nThanks for all those BQL queries!\nSession duration: %v\n\n", time.Now().Sub(sessionStart))
}()
for l := range rl(done) {
if strings.HasPrefix(l, "quit") {
done <- true
break
}
if strings.HasPrefix(l, "help") {
printHelp()
done <- false
continue
}
if strings.HasPrefix(l, "enable memoization") {
driver = driverWithMemoization
fmt.Println("[OK] Partial query memoization is on.")
done <- false
continue
}
if strings.HasPrefix(l, "disable memoization") {
driver = driverPlain
fmt.Println("[OK] Partial query memoization is off.")
done <- false
continue
}
if strings.HasPrefix(l, "start tracing") {
args := strings.Split(strings.TrimSpace(l)[:len(l)-1], " ")
switch len(args) {
case 2:
// Start tracing to the console.
stopTracing()
tracer, isTracingToFile = os.Stdout, false
fmt.Println("[WARNING] Tracing is on. This may slow your BQL queries.")
case 3:
// Start tracing to file.
stopTracing()
f, err := os.Create(args[2])
if err != nil {
fmt.Println(err)
} else {
tracer, isTracingToFile = f, true
fmt.Println("[WARNING] Tracing is on. This may slow your BQL queries.")
}
default:
fmt.Println("Invalid syntax\n\tstart tracing [trace_file]")
}
done <- false
continue
}
if strings.HasPrefix(l, "stop tracing") {
stopTracing()
fmt.Println("Tracing is off.")
done <- false
continue
}
if strings.HasPrefix(l, "export") {
now := time.Now()
args := strings.Split("bw "+strings.TrimSpace(l)[:len(l)-1], " ")
usage := "Wrong syntax\n\n\tload <graph_names_separated_by_commas> <file_path>\n"
export.Eval(ctx, usage, args, driver(), bulkSize)
fmt.Println("[OK] Time spent: ", time.Now().Sub(now))
done <- false
continue
}
if strings.HasPrefix(l, "load") {
now := time.Now()
args := strings.Split("bw "+strings.TrimSpace(l[:len(l)-1]), " ")
usage := "Wrong syntax\n\n\tload <file_path> <graph_names_separated_by_commas>\n"
load.Eval(ctx, usage, args, driver(), bulkSize, builderSize)
fmt.Println("[OK] Time spent: ", time.Now().Sub(now))
done <- false
continue
}
if strings.HasPrefix(l, "desc") {
pln, err := planBQL(ctx, l[4:], driver(), chanSize, bulkSize, nil)
if err != nil {
fmt.Printf("[ERROR] %s\n\n", err)
} else {
if pln != nil {
fmt.Println(pln.String(ctx))
}
fmt.Println("[OK]")
}
done <- false
continue
}
if strings.HasPrefix(l, "run") {
now := time.Now()
path, cmds, err := runBQLFromFile(ctx, driver(), chanSize, bulkSize, strings.TrimSpace(l[:len(l)-1]), tracer)
if err != nil {
fmt.Printf("[ERROR] %s\n\n", err)
} else {
fmt.Printf("Loaded %q and run %d BQL commands successfully\n\n", path, cmds)
}
fmt.Println("Time spent: ", time.Now().Sub(now))
done <- false
continue
}
now := time.Now()
table, err := runBQL(ctx, l, driver(), chanSize, bulkSize, tracer)
bqlDiff := time.Now().Sub(now)
if err != nil {
fmt.Printf("[ERROR] %s\n", err)
fmt.Println("Time spent: ", time.Now().Sub(now))
fmt.Println()
} else {
if table == nil {
fmt.Printf("[OK] 0 rows retrieved. BQL time: %v. Display time: %v\n",
bqlDiff, time.Now().Sub(now)-bqlDiff)
} else {
if len(table.Bindings()) > 0 {
fmt.Println(table.String())
}
fmt.Printf("[OK] %d rows retrieved. BQL time: %v. Display time: %v\n",
table.NumRows(), bqlDiff, time.Now().Sub(now)-bqlDiff)
}
}
done <- false
}
return 0
} | go | func REPL(od storage.Store, input *os.File, rl ReadLiner, chanSize, bulkSize, builderSize int, done chan bool) int {
var tracer io.Writer
ctx, isTracingToFile, sessionStart := context.Background(), false, time.Now()
driverPlain := func() storage.Store {
return od
}
driverWithMemoization := func() storage.Store {
return memoization.New(od)
}
driver := driverWithMemoization
stopTracing := func() {
if tracer != nil {
if isTracingToFile {
fmt.Println("Closing tracing file.")
tracer.(*os.File).Close()
}
tracer, isTracingToFile = nil, false
}
}
defer stopTracing()
fmt.Printf("Welcome to BadWolf vCli (%d.%d.%d-%s)\n", version.Major, version.Minor, version.Patch, version.Release)
fmt.Printf("Using driver %s/%s. Type quit; to exit.\n", driver().Name(ctx), driver().Version(ctx))
fmt.Printf("Session started at %v.\n", sessionStart.Format("2006-01-02T15:04:05.999999-07:00"))
fmt.Println("Memoization enabled. Type help; to print help.")
fmt.Println()
defer func() {
fmt.Printf("\n\nThanks for all those BQL queries!\nSession duration: %v\n\n", time.Now().Sub(sessionStart))
}()
for l := range rl(done) {
if strings.HasPrefix(l, "quit") {
done <- true
break
}
if strings.HasPrefix(l, "help") {
printHelp()
done <- false
continue
}
if strings.HasPrefix(l, "enable memoization") {
driver = driverWithMemoization
fmt.Println("[OK] Partial query memoization is on.")
done <- false
continue
}
if strings.HasPrefix(l, "disable memoization") {
driver = driverPlain
fmt.Println("[OK] Partial query memoization is off.")
done <- false
continue
}
if strings.HasPrefix(l, "start tracing") {
args := strings.Split(strings.TrimSpace(l)[:len(l)-1], " ")
switch len(args) {
case 2:
// Start tracing to the console.
stopTracing()
tracer, isTracingToFile = os.Stdout, false
fmt.Println("[WARNING] Tracing is on. This may slow your BQL queries.")
case 3:
// Start tracing to file.
stopTracing()
f, err := os.Create(args[2])
if err != nil {
fmt.Println(err)
} else {
tracer, isTracingToFile = f, true
fmt.Println("[WARNING] Tracing is on. This may slow your BQL queries.")
}
default:
fmt.Println("Invalid syntax\n\tstart tracing [trace_file]")
}
done <- false
continue
}
if strings.HasPrefix(l, "stop tracing") {
stopTracing()
fmt.Println("Tracing is off.")
done <- false
continue
}
if strings.HasPrefix(l, "export") {
now := time.Now()
args := strings.Split("bw "+strings.TrimSpace(l)[:len(l)-1], " ")
usage := "Wrong syntax\n\n\tload <graph_names_separated_by_commas> <file_path>\n"
export.Eval(ctx, usage, args, driver(), bulkSize)
fmt.Println("[OK] Time spent: ", time.Now().Sub(now))
done <- false
continue
}
if strings.HasPrefix(l, "load") {
now := time.Now()
args := strings.Split("bw "+strings.TrimSpace(l[:len(l)-1]), " ")
usage := "Wrong syntax\n\n\tload <file_path> <graph_names_separated_by_commas>\n"
load.Eval(ctx, usage, args, driver(), bulkSize, builderSize)
fmt.Println("[OK] Time spent: ", time.Now().Sub(now))
done <- false
continue
}
if strings.HasPrefix(l, "desc") {
pln, err := planBQL(ctx, l[4:], driver(), chanSize, bulkSize, nil)
if err != nil {
fmt.Printf("[ERROR] %s\n\n", err)
} else {
if pln != nil {
fmt.Println(pln.String(ctx))
}
fmt.Println("[OK]")
}
done <- false
continue
}
if strings.HasPrefix(l, "run") {
now := time.Now()
path, cmds, err := runBQLFromFile(ctx, driver(), chanSize, bulkSize, strings.TrimSpace(l[:len(l)-1]), tracer)
if err != nil {
fmt.Printf("[ERROR] %s\n\n", err)
} else {
fmt.Printf("Loaded %q and run %d BQL commands successfully\n\n", path, cmds)
}
fmt.Println("Time spent: ", time.Now().Sub(now))
done <- false
continue
}
now := time.Now()
table, err := runBQL(ctx, l, driver(), chanSize, bulkSize, tracer)
bqlDiff := time.Now().Sub(now)
if err != nil {
fmt.Printf("[ERROR] %s\n", err)
fmt.Println("Time spent: ", time.Now().Sub(now))
fmt.Println()
} else {
if table == nil {
fmt.Printf("[OK] 0 rows retrieved. BQL time: %v. Display time: %v\n",
bqlDiff, time.Now().Sub(now)-bqlDiff)
} else {
if len(table.Bindings()) > 0 {
fmt.Println(table.String())
}
fmt.Printf("[OK] %d rows retrieved. BQL time: %v. Display time: %v\n",
table.NumRows(), bqlDiff, time.Now().Sub(now)-bqlDiff)
}
}
done <- false
}
return 0
} | [
"func",
"REPL",
"(",
"od",
"storage",
".",
"Store",
",",
"input",
"*",
"os",
".",
"File",
",",
"rl",
"ReadLiner",
",",
"chanSize",
",",
"bulkSize",
",",
"builderSize",
"int",
",",
"done",
"chan",
"bool",
")",
"int",
"{",
"var",
"tracer",
"io",
".",
"Writer",
"\n",
"ctx",
",",
"isTracingToFile",
",",
"sessionStart",
":=",
"context",
".",
"Background",
"(",
")",
",",
"false",
",",
"time",
".",
"Now",
"(",
")",
"\n\n",
"driverPlain",
":=",
"func",
"(",
")",
"storage",
".",
"Store",
"{",
"return",
"od",
"\n",
"}",
"\n\n",
"driverWithMemoization",
":=",
"func",
"(",
")",
"storage",
".",
"Store",
"{",
"return",
"memoization",
".",
"New",
"(",
"od",
")",
"\n",
"}",
"\n\n",
"driver",
":=",
"driverWithMemoization",
"\n\n",
"stopTracing",
":=",
"func",
"(",
")",
"{",
"if",
"tracer",
"!=",
"nil",
"{",
"if",
"isTracingToFile",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"tracer",
".",
"(",
"*",
"os",
".",
"File",
")",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"tracer",
",",
"isTracingToFile",
"=",
"nil",
",",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"defer",
"stopTracing",
"(",
")",
"\n\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"version",
".",
"Major",
",",
"version",
".",
"Minor",
",",
"version",
".",
"Patch",
",",
"version",
".",
"Release",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"driver",
"(",
")",
".",
"Name",
"(",
"ctx",
")",
",",
"driver",
"(",
")",
".",
"Version",
"(",
"ctx",
")",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"sessionStart",
".",
"Format",
"(",
"\"",
"\"",
")",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\\n",
"\\n",
"\\n",
"\"",
",",
"time",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"sessionStart",
")",
")",
"\n",
"}",
"(",
")",
"\n\n",
"for",
"l",
":=",
"range",
"rl",
"(",
"done",
")",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"l",
",",
"\"",
"\"",
")",
"{",
"done",
"<-",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"l",
",",
"\"",
"\"",
")",
"{",
"printHelp",
"(",
")",
"\n",
"done",
"<-",
"false",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"l",
",",
"\"",
"\"",
")",
"{",
"driver",
"=",
"driverWithMemoization",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"done",
"<-",
"false",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"l",
",",
"\"",
"\"",
")",
"{",
"driver",
"=",
"driverPlain",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"done",
"<-",
"false",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"l",
",",
"\"",
"\"",
")",
"{",
"args",
":=",
"strings",
".",
"Split",
"(",
"strings",
".",
"TrimSpace",
"(",
"l",
")",
"[",
":",
"len",
"(",
"l",
")",
"-",
"1",
"]",
",",
"\"",
"\"",
")",
"\n",
"switch",
"len",
"(",
"args",
")",
"{",
"case",
"2",
":",
"// Start tracing to the console.",
"stopTracing",
"(",
")",
"\n",
"tracer",
",",
"isTracingToFile",
"=",
"os",
".",
"Stdout",
",",
"false",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"case",
"3",
":",
"// Start tracing to file.",
"stopTracing",
"(",
")",
"\n",
"f",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"args",
"[",
"2",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Println",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"tracer",
",",
"isTracingToFile",
"=",
"f",
",",
"true",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"default",
":",
"fmt",
".",
"Println",
"(",
"\"",
"\\n",
"\\t",
"\"",
")",
"\n",
"}",
"\n",
"done",
"<-",
"false",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"l",
",",
"\"",
"\"",
")",
"{",
"stopTracing",
"(",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"done",
"<-",
"false",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"l",
",",
"\"",
"\"",
")",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"args",
":=",
"strings",
".",
"Split",
"(",
"\"",
"\"",
"+",
"strings",
".",
"TrimSpace",
"(",
"l",
")",
"[",
":",
"len",
"(",
"l",
")",
"-",
"1",
"]",
",",
"\"",
"\"",
")",
"\n",
"usage",
":=",
"\"",
"\\n",
"\\n",
"\\t",
"\\n",
"\"",
"\n",
"export",
".",
"Eval",
"(",
"ctx",
",",
"usage",
",",
"args",
",",
"driver",
"(",
")",
",",
"bulkSize",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"time",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"now",
")",
")",
"\n",
"done",
"<-",
"false",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"l",
",",
"\"",
"\"",
")",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"args",
":=",
"strings",
".",
"Split",
"(",
"\"",
"\"",
"+",
"strings",
".",
"TrimSpace",
"(",
"l",
"[",
":",
"len",
"(",
"l",
")",
"-",
"1",
"]",
")",
",",
"\"",
"\"",
")",
"\n",
"usage",
":=",
"\"",
"\\n",
"\\n",
"\\t",
"\\n",
"\"",
"\n",
"load",
".",
"Eval",
"(",
"ctx",
",",
"usage",
",",
"args",
",",
"driver",
"(",
")",
",",
"bulkSize",
",",
"builderSize",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"time",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"now",
")",
")",
"\n",
"done",
"<-",
"false",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"l",
",",
"\"",
"\"",
")",
"{",
"pln",
",",
"err",
":=",
"planBQL",
"(",
"ctx",
",",
"l",
"[",
"4",
":",
"]",
",",
"driver",
"(",
")",
",",
"chanSize",
",",
"bulkSize",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"if",
"pln",
"!=",
"nil",
"{",
"fmt",
".",
"Println",
"(",
"pln",
".",
"String",
"(",
"ctx",
")",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"done",
"<-",
"false",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"l",
",",
"\"",
"\"",
")",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"path",
",",
"cmds",
",",
"err",
":=",
"runBQLFromFile",
"(",
"ctx",
",",
"driver",
"(",
")",
",",
"chanSize",
",",
"bulkSize",
",",
"strings",
".",
"TrimSpace",
"(",
"l",
"[",
":",
"len",
"(",
"l",
")",
"-",
"1",
"]",
")",
",",
"tracer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"path",
",",
"cmds",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"time",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"now",
")",
")",
"\n",
"done",
"<-",
"false",
"\n",
"continue",
"\n",
"}",
"\n\n",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"table",
",",
"err",
":=",
"runBQL",
"(",
"ctx",
",",
"l",
",",
"driver",
"(",
")",
",",
"chanSize",
",",
"bulkSize",
",",
"tracer",
")",
"\n",
"bqlDiff",
":=",
"time",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"now",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"time",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"now",
")",
")",
"\n",
"fmt",
".",
"Println",
"(",
")",
"\n",
"}",
"else",
"{",
"if",
"table",
"==",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"bqlDiff",
",",
"time",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"now",
")",
"-",
"bqlDiff",
")",
"\n",
"}",
"else",
"{",
"if",
"len",
"(",
"table",
".",
"Bindings",
"(",
")",
")",
">",
"0",
"{",
"fmt",
".",
"Println",
"(",
"table",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"table",
".",
"NumRows",
"(",
")",
",",
"bqlDiff",
",",
"time",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"now",
")",
"-",
"bqlDiff",
")",
"\n",
"}",
"\n",
"}",
"\n",
"done",
"<-",
"false",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}"
]
| // REPL starts a read-evaluation-print-loop to run BQL commands. | [
"REPL",
"starts",
"a",
"read",
"-",
"evaluation",
"-",
"print",
"-",
"loop",
"to",
"run",
"BQL",
"commands",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/repl/repl.go#L92-L244 |
12,571 | google/badwolf | tools/vcli/bw/repl/repl.go | printHelp | func printHelp() {
fmt.Println()
fmt.Println("help - prints help for the bw console.")
fmt.Println("disable memoization - disables partial result memoization on query resolution.")
fmt.Println("enable memoization - enables partial result memoization of partial query results.")
fmt.Println("export <graph_names_separated_by_commas> <file_path> - dumps triples from graphs into a file path.")
fmt.Println("desc <BQL> - prints the execution plan for a BQL statement.")
fmt.Println("load <file_path> <graph_names_separated_by_commas> - load triples into the specified graphs.")
fmt.Println("run <file_with_bql_statements> - runs all the BQL statements in the file.")
fmt.Println("start tracing [trace_file] - starts tracing queries.")
fmt.Println("stop tracing - stops tracing queries.")
fmt.Println("quit - quits the console.")
fmt.Println()
} | go | func printHelp() {
fmt.Println()
fmt.Println("help - prints help for the bw console.")
fmt.Println("disable memoization - disables partial result memoization on query resolution.")
fmt.Println("enable memoization - enables partial result memoization of partial query results.")
fmt.Println("export <graph_names_separated_by_commas> <file_path> - dumps triples from graphs into a file path.")
fmt.Println("desc <BQL> - prints the execution plan for a BQL statement.")
fmt.Println("load <file_path> <graph_names_separated_by_commas> - load triples into the specified graphs.")
fmt.Println("run <file_with_bql_statements> - runs all the BQL statements in the file.")
fmt.Println("start tracing [trace_file] - starts tracing queries.")
fmt.Println("stop tracing - stops tracing queries.")
fmt.Println("quit - quits the console.")
fmt.Println()
} | [
"func",
"printHelp",
"(",
")",
"{",
"fmt",
".",
"Println",
"(",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
")",
"\n",
"}"
]
| // printHelp prints help for the console commands. | [
"printHelp",
"prints",
"help",
"for",
"the",
"console",
"commands",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/repl/repl.go#L247-L260 |
12,572 | google/badwolf | tools/vcli/bw/repl/repl.go | runBQLFromFile | func runBQLFromFile(ctx context.Context, driver storage.Store, chanSize, bulkSize int, line string, w io.Writer) (string, int, error) {
ss := strings.Split(strings.TrimSpace(line), " ")
if len(ss) != 2 {
return "", 0, fmt.Errorf("wrong syntax: run <file_with_bql_statements>")
}
path := ss[1]
tracer.Trace(w, func() []string {
return []string{fmt.Sprintf("Attempting to read file %q", path)}
})
lines, err := bio.GetStatementsFromFile(path)
if err != nil {
msg := fmt.Errorf("failed to read file %q; error %v", path, err)
tracer.Trace(w, func() []string {
return []string{msg.Error()}
})
return "", 0, msg
}
for idx, stm := range lines {
fmt.Printf("Processing statement (%d/%d)\n", idx+1, len(lines))
_, err := runBQL(ctx, stm, driver, chanSize, bulkSize, w)
if err != nil {
msg := fmt.Errorf("%q; %v", stm, err)
tracer.Trace(w, func() []string {
return []string{msg.Error()}
})
return "", 0, msg
}
}
fmt.Println()
return path, len(lines), nil
} | go | func runBQLFromFile(ctx context.Context, driver storage.Store, chanSize, bulkSize int, line string, w io.Writer) (string, int, error) {
ss := strings.Split(strings.TrimSpace(line), " ")
if len(ss) != 2 {
return "", 0, fmt.Errorf("wrong syntax: run <file_with_bql_statements>")
}
path := ss[1]
tracer.Trace(w, func() []string {
return []string{fmt.Sprintf("Attempting to read file %q", path)}
})
lines, err := bio.GetStatementsFromFile(path)
if err != nil {
msg := fmt.Errorf("failed to read file %q; error %v", path, err)
tracer.Trace(w, func() []string {
return []string{msg.Error()}
})
return "", 0, msg
}
for idx, stm := range lines {
fmt.Printf("Processing statement (%d/%d)\n", idx+1, len(lines))
_, err := runBQL(ctx, stm, driver, chanSize, bulkSize, w)
if err != nil {
msg := fmt.Errorf("%q; %v", stm, err)
tracer.Trace(w, func() []string {
return []string{msg.Error()}
})
return "", 0, msg
}
}
fmt.Println()
return path, len(lines), nil
} | [
"func",
"runBQLFromFile",
"(",
"ctx",
"context",
".",
"Context",
",",
"driver",
"storage",
".",
"Store",
",",
"chanSize",
",",
"bulkSize",
"int",
",",
"line",
"string",
",",
"w",
"io",
".",
"Writer",
")",
"(",
"string",
",",
"int",
",",
"error",
")",
"{",
"ss",
":=",
"strings",
".",
"Split",
"(",
"strings",
".",
"TrimSpace",
"(",
"line",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"ss",
")",
"!=",
"2",
"{",
"return",
"\"",
"\"",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"path",
":=",
"ss",
"[",
"1",
"]",
"\n",
"tracer",
".",
"Trace",
"(",
"w",
",",
"func",
"(",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"path",
")",
"}",
"\n",
"}",
")",
"\n",
"lines",
",",
"err",
":=",
"bio",
".",
"GetStatementsFromFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"msg",
":=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"path",
",",
"err",
")",
"\n",
"tracer",
".",
"Trace",
"(",
"w",
",",
"func",
"(",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"msg",
".",
"Error",
"(",
")",
"}",
"\n",
"}",
")",
"\n",
"return",
"\"",
"\"",
",",
"0",
",",
"msg",
"\n",
"}",
"\n",
"for",
"idx",
",",
"stm",
":=",
"range",
"lines",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"idx",
"+",
"1",
",",
"len",
"(",
"lines",
")",
")",
"\n",
"_",
",",
"err",
":=",
"runBQL",
"(",
"ctx",
",",
"stm",
",",
"driver",
",",
"chanSize",
",",
"bulkSize",
",",
"w",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"msg",
":=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"stm",
",",
"err",
")",
"\n",
"tracer",
".",
"Trace",
"(",
"w",
",",
"func",
"(",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"msg",
".",
"Error",
"(",
")",
"}",
"\n",
"}",
")",
"\n",
"return",
"\"",
"\"",
",",
"0",
",",
"msg",
"\n",
"}",
"\n",
"}",
"\n",
"fmt",
".",
"Println",
"(",
")",
"\n",
"return",
"path",
",",
"len",
"(",
"lines",
")",
",",
"nil",
"\n",
"}"
]
| // runBQLFromFile loads all the statements in the file and runs them. | [
"runBQLFromFile",
"loads",
"all",
"the",
"statements",
"in",
"the",
"file",
"and",
"runs",
"them",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/repl/repl.go#L263-L293 |
12,573 | google/badwolf | tools/vcli/bw/repl/repl.go | runBQL | func runBQL(ctx context.Context, bql string, s storage.Store, chanSize, bulkSize int, w io.Writer) (*table.Table, error) {
tracer.Trace(w, func() []string {
return []string{fmt.Sprintf("Executing query: %s", bql)}
})
pln, err := planBQL(ctx, bql, s, chanSize, bulkSize, w)
if err != nil {
return nil, err
}
if pln == nil {
return nil, nil
}
res, err := pln.Execute(ctx)
if err != nil {
msg := fmt.Errorf("planner.Execute: failed to execute; %v", err)
tracer.Trace(w, func() []string {
return []string{msg.Error()}
})
return nil, msg
}
tracer.Trace(w, func() []string {
return []string{fmt.Sprintf("planner execute returned %d rows", res.NumRows())}
})
return res, nil
} | go | func runBQL(ctx context.Context, bql string, s storage.Store, chanSize, bulkSize int, w io.Writer) (*table.Table, error) {
tracer.Trace(w, func() []string {
return []string{fmt.Sprintf("Executing query: %s", bql)}
})
pln, err := planBQL(ctx, bql, s, chanSize, bulkSize, w)
if err != nil {
return nil, err
}
if pln == nil {
return nil, nil
}
res, err := pln.Execute(ctx)
if err != nil {
msg := fmt.Errorf("planner.Execute: failed to execute; %v", err)
tracer.Trace(w, func() []string {
return []string{msg.Error()}
})
return nil, msg
}
tracer.Trace(w, func() []string {
return []string{fmt.Sprintf("planner execute returned %d rows", res.NumRows())}
})
return res, nil
} | [
"func",
"runBQL",
"(",
"ctx",
"context",
".",
"Context",
",",
"bql",
"string",
",",
"s",
"storage",
".",
"Store",
",",
"chanSize",
",",
"bulkSize",
"int",
",",
"w",
"io",
".",
"Writer",
")",
"(",
"*",
"table",
".",
"Table",
",",
"error",
")",
"{",
"tracer",
".",
"Trace",
"(",
"w",
",",
"func",
"(",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"bql",
")",
"}",
"\n",
"}",
")",
"\n",
"pln",
",",
"err",
":=",
"planBQL",
"(",
"ctx",
",",
"bql",
",",
"s",
",",
"chanSize",
",",
"bulkSize",
",",
"w",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"pln",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"res",
",",
"err",
":=",
"pln",
".",
"Execute",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"msg",
":=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"tracer",
".",
"Trace",
"(",
"w",
",",
"func",
"(",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"msg",
".",
"Error",
"(",
")",
"}",
"\n",
"}",
")",
"\n",
"return",
"nil",
",",
"msg",
"\n",
"}",
"\n",
"tracer",
".",
"Trace",
"(",
"w",
",",
"func",
"(",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"res",
".",
"NumRows",
"(",
")",
")",
"}",
"\n",
"}",
")",
"\n",
"return",
"res",
",",
"nil",
"\n",
"}"
]
| // runBQL attempts to execute the provided query against the given store. | [
"runBQL",
"attempts",
"to",
"execute",
"the",
"provided",
"query",
"against",
"the",
"given",
"store",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/repl/repl.go#L296-L319 |
12,574 | google/badwolf | tools/vcli/bw/repl/repl.go | planBQL | func planBQL(ctx context.Context, bql string, s storage.Store, chanSize, bulkSize int, w io.Writer) (planner.Executor, error) {
bql = strings.TrimSpace(bql)
if bql == ";" {
tracer.Trace(w, func() []string {
return []string{"Empty statement found"}
})
return nil, nil
}
p, err := grammar.NewParser(grammar.SemanticBQL())
if err != nil {
msg := fmt.Errorf("NewParser failed; %v", err)
tracer.Trace(w, func() []string {
return []string{msg.Error()}
})
return nil, msg
}
stm := &semantic.Statement{}
if err := p.Parse(grammar.NewLLk(bql, 1), stm); err != nil {
msg := fmt.Errorf("NewLLk parser failed; %v", err)
tracer.Trace(w, func() []string {
return []string{msg.Error()}
})
return nil, msg
}
pln, err := planner.New(ctx, s, stm, chanSize, bulkSize, w)
if err != nil {
msg := fmt.Errorf("planer.New failed failed; %v", err)
tracer.Trace(w, func() []string {
return []string{msg.Error()}
})
return nil, msg
}
tracer.Trace(w, func() []string {
return []string{"Plan successfuly created"}
})
return pln, nil
} | go | func planBQL(ctx context.Context, bql string, s storage.Store, chanSize, bulkSize int, w io.Writer) (planner.Executor, error) {
bql = strings.TrimSpace(bql)
if bql == ";" {
tracer.Trace(w, func() []string {
return []string{"Empty statement found"}
})
return nil, nil
}
p, err := grammar.NewParser(grammar.SemanticBQL())
if err != nil {
msg := fmt.Errorf("NewParser failed; %v", err)
tracer.Trace(w, func() []string {
return []string{msg.Error()}
})
return nil, msg
}
stm := &semantic.Statement{}
if err := p.Parse(grammar.NewLLk(bql, 1), stm); err != nil {
msg := fmt.Errorf("NewLLk parser failed; %v", err)
tracer.Trace(w, func() []string {
return []string{msg.Error()}
})
return nil, msg
}
pln, err := planner.New(ctx, s, stm, chanSize, bulkSize, w)
if err != nil {
msg := fmt.Errorf("planer.New failed failed; %v", err)
tracer.Trace(w, func() []string {
return []string{msg.Error()}
})
return nil, msg
}
tracer.Trace(w, func() []string {
return []string{"Plan successfuly created"}
})
return pln, nil
} | [
"func",
"planBQL",
"(",
"ctx",
"context",
".",
"Context",
",",
"bql",
"string",
",",
"s",
"storage",
".",
"Store",
",",
"chanSize",
",",
"bulkSize",
"int",
",",
"w",
"io",
".",
"Writer",
")",
"(",
"planner",
".",
"Executor",
",",
"error",
")",
"{",
"bql",
"=",
"strings",
".",
"TrimSpace",
"(",
"bql",
")",
"\n",
"if",
"bql",
"==",
"\"",
"\"",
"{",
"tracer",
".",
"Trace",
"(",
"w",
",",
"func",
"(",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"\n",
"}",
")",
"\n",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"p",
",",
"err",
":=",
"grammar",
".",
"NewParser",
"(",
"grammar",
".",
"SemanticBQL",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"msg",
":=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"tracer",
".",
"Trace",
"(",
"w",
",",
"func",
"(",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"msg",
".",
"Error",
"(",
")",
"}",
"\n",
"}",
")",
"\n",
"return",
"nil",
",",
"msg",
"\n",
"}",
"\n",
"stm",
":=",
"&",
"semantic",
".",
"Statement",
"{",
"}",
"\n",
"if",
"err",
":=",
"p",
".",
"Parse",
"(",
"grammar",
".",
"NewLLk",
"(",
"bql",
",",
"1",
")",
",",
"stm",
")",
";",
"err",
"!=",
"nil",
"{",
"msg",
":=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"tracer",
".",
"Trace",
"(",
"w",
",",
"func",
"(",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"msg",
".",
"Error",
"(",
")",
"}",
"\n",
"}",
")",
"\n",
"return",
"nil",
",",
"msg",
"\n",
"}",
"\n",
"pln",
",",
"err",
":=",
"planner",
".",
"New",
"(",
"ctx",
",",
"s",
",",
"stm",
",",
"chanSize",
",",
"bulkSize",
",",
"w",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"msg",
":=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"tracer",
".",
"Trace",
"(",
"w",
",",
"func",
"(",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"msg",
".",
"Error",
"(",
")",
"}",
"\n",
"}",
")",
"\n",
"return",
"nil",
",",
"msg",
"\n",
"}",
"\n",
"tracer",
".",
"Trace",
"(",
"w",
",",
"func",
"(",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"\n",
"}",
")",
"\n",
"return",
"pln",
",",
"nil",
"\n",
"}"
]
| // planBQL attempts to create the execution plan for the provided query against the given store. | [
"planBQL",
"attempts",
"to",
"create",
"the",
"execution",
"plan",
"for",
"the",
"provided",
"query",
"against",
"the",
"given",
"store",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/repl/repl.go#L322-L358 |
12,575 | google/badwolf | tools/compliance/entry.go | Marshal | func (s *Story) Marshal() (string, error) {
b, err := json.MarshalIndent(s, "", " ")
if err != nil {
return "", err
}
return string(b), nil
} | go | func (s *Story) Marshal() (string, error) {
b, err := json.MarshalIndent(s, "", " ")
if err != nil {
return "", err
}
return string(b), nil
} | [
"func",
"(",
"s",
"*",
"Story",
")",
"Marshal",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"json",
".",
"MarshalIndent",
"(",
"s",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"string",
"(",
"b",
")",
",",
"nil",
"\n",
"}"
]
| // Marshal serializes the story into a JSON readable string. | [
"Marshal",
"serializes",
"the",
"story",
"into",
"a",
"JSON",
"readable",
"string",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/compliance/entry.go#L85-L91 |
12,576 | google/badwolf | tools/compliance/entry.go | Unmarshal | func (s *Story) Unmarshal(ss string) error {
return json.Unmarshal([]byte(ss), s)
} | go | func (s *Story) Unmarshal(ss string) error {
return json.Unmarshal([]byte(ss), s)
} | [
"func",
"(",
"s",
"*",
"Story",
")",
"Unmarshal",
"(",
"ss",
"string",
")",
"error",
"{",
"return",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"ss",
")",
",",
"s",
")",
"\n",
"}"
]
| // Unmarshal rebuilds a story from a JSON readable string. | [
"Unmarshal",
"rebuilds",
"a",
"story",
"from",
"a",
"JSON",
"readable",
"string",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/compliance/entry.go#L94-L96 |
12,577 | google/badwolf | tools/compliance/entry.go | inferCell | func inferCell(s string) *table.Cell {
if n, err := node.Parse(s); err == nil {
return &table.Cell{N: n}
}
if p, err := predicate.Parse(s); err == nil {
return &table.Cell{P: p}
}
if l, err := literal.DefaultBuilder().Parse(s); err == nil {
return &table.Cell{L: l}
}
t, err := time.Parse(time.RFC3339Nano, s)
if err == nil {
return &table.Cell{T: &t}
}
return &table.Cell{S: table.CellString(s)}
} | go | func inferCell(s string) *table.Cell {
if n, err := node.Parse(s); err == nil {
return &table.Cell{N: n}
}
if p, err := predicate.Parse(s); err == nil {
return &table.Cell{P: p}
}
if l, err := literal.DefaultBuilder().Parse(s); err == nil {
return &table.Cell{L: l}
}
t, err := time.Parse(time.RFC3339Nano, s)
if err == nil {
return &table.Cell{T: &t}
}
return &table.Cell{S: table.CellString(s)}
} | [
"func",
"inferCell",
"(",
"s",
"string",
")",
"*",
"table",
".",
"Cell",
"{",
"if",
"n",
",",
"err",
":=",
"node",
".",
"Parse",
"(",
"s",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"&",
"table",
".",
"Cell",
"{",
"N",
":",
"n",
"}",
"\n",
"}",
"\n",
"if",
"p",
",",
"err",
":=",
"predicate",
".",
"Parse",
"(",
"s",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"&",
"table",
".",
"Cell",
"{",
"P",
":",
"p",
"}",
"\n",
"}",
"\n",
"if",
"l",
",",
"err",
":=",
"literal",
".",
"DefaultBuilder",
"(",
")",
".",
"Parse",
"(",
"s",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"&",
"table",
".",
"Cell",
"{",
"L",
":",
"l",
"}",
"\n",
"}",
"\n",
"t",
",",
"err",
":=",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC3339Nano",
",",
"s",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"&",
"table",
".",
"Cell",
"{",
"T",
":",
"&",
"t",
"}",
"\n",
"}",
"\n",
"return",
"&",
"table",
".",
"Cell",
"{",
"S",
":",
"table",
".",
"CellString",
"(",
"s",
")",
"}",
"\n",
"}"
]
| // inferCell builds a Cell out of the provided string. | [
"inferCell",
"builds",
"a",
"Cell",
"out",
"of",
"the",
"provided",
"string",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/compliance/entry.go#L99-L114 |
12,578 | google/badwolf | tools/compliance/entry.go | OutputTable | func (a *Assertion) OutputTable(bo []string) (*table.Table, error) {
// Return the already computed output table.
if a.table != nil {
return a.table, nil
}
// Compute the output table.
var (
first bool
mBdngs map[string]bool
data []table.Row
bs []string
)
mBdngs, first = make(map[string]bool), true
for _, row := range a.MustReturn {
nr := table.Row{}
for k, v := range row {
_, ok := mBdngs[k]
if first && !ok {
bs = append(bs, k)
}
if !first && !ok {
return nil, fmt.Errorf("unknow binding %q; available ones are %v", k, mBdngs)
}
mBdngs[k], nr[k] = true, inferCell(v)
}
data = append(data, nr)
first = false
}
if first {
// No data was provided. This will create the empty table with the right
// bindings.
bs = bo
}
// Build the table.
if len(bo) != len(bs) {
return nil, fmt.Errorf("incompatible bindings; got %v, want %v", bs, bo)
}
for _, b := range bo {
if _, ok := mBdngs[b]; !first && !ok {
return nil, fmt.Errorf("missing binding %q; want bining in %v", b, bo)
}
}
t, err := table.New(bo)
if err != nil {
return nil, err
}
for _, r := range data {
t.AddRow(r)
}
return t, nil
} | go | func (a *Assertion) OutputTable(bo []string) (*table.Table, error) {
// Return the already computed output table.
if a.table != nil {
return a.table, nil
}
// Compute the output table.
var (
first bool
mBdngs map[string]bool
data []table.Row
bs []string
)
mBdngs, first = make(map[string]bool), true
for _, row := range a.MustReturn {
nr := table.Row{}
for k, v := range row {
_, ok := mBdngs[k]
if first && !ok {
bs = append(bs, k)
}
if !first && !ok {
return nil, fmt.Errorf("unknow binding %q; available ones are %v", k, mBdngs)
}
mBdngs[k], nr[k] = true, inferCell(v)
}
data = append(data, nr)
first = false
}
if first {
// No data was provided. This will create the empty table with the right
// bindings.
bs = bo
}
// Build the table.
if len(bo) != len(bs) {
return nil, fmt.Errorf("incompatible bindings; got %v, want %v", bs, bo)
}
for _, b := range bo {
if _, ok := mBdngs[b]; !first && !ok {
return nil, fmt.Errorf("missing binding %q; want bining in %v", b, bo)
}
}
t, err := table.New(bo)
if err != nil {
return nil, err
}
for _, r := range data {
t.AddRow(r)
}
return t, nil
} | [
"func",
"(",
"a",
"*",
"Assertion",
")",
"OutputTable",
"(",
"bo",
"[",
"]",
"string",
")",
"(",
"*",
"table",
".",
"Table",
",",
"error",
")",
"{",
"// Return the already computed output table.",
"if",
"a",
".",
"table",
"!=",
"nil",
"{",
"return",
"a",
".",
"table",
",",
"nil",
"\n",
"}",
"\n",
"// Compute the output table.",
"var",
"(",
"first",
"bool",
"\n",
"mBdngs",
"map",
"[",
"string",
"]",
"bool",
"\n",
"data",
"[",
"]",
"table",
".",
"Row",
"\n",
"bs",
"[",
"]",
"string",
"\n",
")",
"\n",
"mBdngs",
",",
"first",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
",",
"true",
"\n",
"for",
"_",
",",
"row",
":=",
"range",
"a",
".",
"MustReturn",
"{",
"nr",
":=",
"table",
".",
"Row",
"{",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"row",
"{",
"_",
",",
"ok",
":=",
"mBdngs",
"[",
"k",
"]",
"\n",
"if",
"first",
"&&",
"!",
"ok",
"{",
"bs",
"=",
"append",
"(",
"bs",
",",
"k",
")",
"\n",
"}",
"\n",
"if",
"!",
"first",
"&&",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"k",
",",
"mBdngs",
")",
"\n",
"}",
"\n",
"mBdngs",
"[",
"k",
"]",
",",
"nr",
"[",
"k",
"]",
"=",
"true",
",",
"inferCell",
"(",
"v",
")",
"\n",
"}",
"\n",
"data",
"=",
"append",
"(",
"data",
",",
"nr",
")",
"\n",
"first",
"=",
"false",
"\n",
"}",
"\n",
"if",
"first",
"{",
"// No data was provided. This will create the empty table with the right",
"// bindings.",
"bs",
"=",
"bo",
"\n",
"}",
"\n",
"// Build the table.",
"if",
"len",
"(",
"bo",
")",
"!=",
"len",
"(",
"bs",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"bs",
",",
"bo",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"b",
":=",
"range",
"bo",
"{",
"if",
"_",
",",
"ok",
":=",
"mBdngs",
"[",
"b",
"]",
";",
"!",
"first",
"&&",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"b",
",",
"bo",
")",
"\n",
"}",
"\n",
"}",
"\n",
"t",
",",
"err",
":=",
"table",
".",
"New",
"(",
"bo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"data",
"{",
"t",
".",
"AddRow",
"(",
"r",
")",
"\n",
"}",
"\n",
"return",
"t",
",",
"nil",
"\n",
"}"
]
| // OutputTable returns the expected result table for the must result table
// provided by the story. | [
"OutputTable",
"returns",
"the",
"expected",
"result",
"table",
"for",
"the",
"must",
"result",
"table",
"provided",
"by",
"the",
"story",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/compliance/entry.go#L118-L168 |
12,579 | google/badwolf | bql/planner/data_access.go | updateTimeBounds | func updateTimeBounds(lo *storage.LookupOptions, cls *semantic.GraphClause) *storage.LookupOptions {
nlo := &storage.LookupOptions{
MaxElements: lo.MaxElements,
LowerAnchor: lo.LowerAnchor,
UpperAnchor: lo.UpperAnchor,
}
if cls.PLowerBound != nil {
if lo.LowerAnchor == nil || (lo.LowerAnchor != nil && cls.PLowerBound.After(*lo.LowerAnchor)) {
nlo.LowerAnchor = cls.PLowerBound
}
}
if cls.PUpperBound != nil {
if lo.UpperAnchor == nil || (lo.UpperAnchor != nil && cls.PUpperBound.Before(*lo.UpperAnchor)) {
nlo.UpperAnchor = cls.PUpperBound
}
}
return nlo
} | go | func updateTimeBounds(lo *storage.LookupOptions, cls *semantic.GraphClause) *storage.LookupOptions {
nlo := &storage.LookupOptions{
MaxElements: lo.MaxElements,
LowerAnchor: lo.LowerAnchor,
UpperAnchor: lo.UpperAnchor,
}
if cls.PLowerBound != nil {
if lo.LowerAnchor == nil || (lo.LowerAnchor != nil && cls.PLowerBound.After(*lo.LowerAnchor)) {
nlo.LowerAnchor = cls.PLowerBound
}
}
if cls.PUpperBound != nil {
if lo.UpperAnchor == nil || (lo.UpperAnchor != nil && cls.PUpperBound.Before(*lo.UpperAnchor)) {
nlo.UpperAnchor = cls.PUpperBound
}
}
return nlo
} | [
"func",
"updateTimeBounds",
"(",
"lo",
"*",
"storage",
".",
"LookupOptions",
",",
"cls",
"*",
"semantic",
".",
"GraphClause",
")",
"*",
"storage",
".",
"LookupOptions",
"{",
"nlo",
":=",
"&",
"storage",
".",
"LookupOptions",
"{",
"MaxElements",
":",
"lo",
".",
"MaxElements",
",",
"LowerAnchor",
":",
"lo",
".",
"LowerAnchor",
",",
"UpperAnchor",
":",
"lo",
".",
"UpperAnchor",
",",
"}",
"\n",
"if",
"cls",
".",
"PLowerBound",
"!=",
"nil",
"{",
"if",
"lo",
".",
"LowerAnchor",
"==",
"nil",
"||",
"(",
"lo",
".",
"LowerAnchor",
"!=",
"nil",
"&&",
"cls",
".",
"PLowerBound",
".",
"After",
"(",
"*",
"lo",
".",
"LowerAnchor",
")",
")",
"{",
"nlo",
".",
"LowerAnchor",
"=",
"cls",
".",
"PLowerBound",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"cls",
".",
"PUpperBound",
"!=",
"nil",
"{",
"if",
"lo",
".",
"UpperAnchor",
"==",
"nil",
"||",
"(",
"lo",
".",
"UpperAnchor",
"!=",
"nil",
"&&",
"cls",
".",
"PUpperBound",
".",
"Before",
"(",
"*",
"lo",
".",
"UpperAnchor",
")",
")",
"{",
"nlo",
".",
"UpperAnchor",
"=",
"cls",
".",
"PUpperBound",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nlo",
"\n",
"}"
]
| // updateTimeBounds updates the time bounds use for the lookup based on the
// provided graph clause. | [
"updateTimeBounds",
"updates",
"the",
"time",
"bounds",
"use",
"for",
"the",
"lookup",
"based",
"on",
"the",
"provided",
"graph",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/planner/data_access.go#L35-L52 |
12,580 | google/badwolf | bql/planner/data_access.go | updateTimeBoundsForRow | func updateTimeBoundsForRow(lo *storage.LookupOptions, cls *semantic.GraphClause, r table.Row) (*storage.LookupOptions, error) {
lo = updateTimeBounds(lo, cls)
if cls.PLowerBoundAlias != "" {
v, ok := r[cls.PLowerBoundAlias]
if ok && v.T == nil {
return nil, fmt.Errorf("invalid time anchor value %v for bound %s", v, cls.PLowerBoundAlias)
}
if lo.LowerAnchor == nil || (lo.LowerAnchor != nil && v.T.After(*lo.LowerAnchor)) {
lo.LowerAnchor = v.T
}
}
if cls.PUpperBoundAlias != "" {
v, ok := r[cls.PUpperBoundAlias]
if ok && v.T == nil {
return nil, fmt.Errorf("invalid time anchor value %v for bound %s", v, cls.PUpperBoundAlias)
}
if lo.UpperAnchor == nil || (lo.UpperAnchor != nil && v.T.After(*lo.UpperAnchor)) {
lo.UpperAnchor = v.T
}
}
nlo := updateTimeBounds(lo, cls)
return nlo, nil
} | go | func updateTimeBoundsForRow(lo *storage.LookupOptions, cls *semantic.GraphClause, r table.Row) (*storage.LookupOptions, error) {
lo = updateTimeBounds(lo, cls)
if cls.PLowerBoundAlias != "" {
v, ok := r[cls.PLowerBoundAlias]
if ok && v.T == nil {
return nil, fmt.Errorf("invalid time anchor value %v for bound %s", v, cls.PLowerBoundAlias)
}
if lo.LowerAnchor == nil || (lo.LowerAnchor != nil && v.T.After(*lo.LowerAnchor)) {
lo.LowerAnchor = v.T
}
}
if cls.PUpperBoundAlias != "" {
v, ok := r[cls.PUpperBoundAlias]
if ok && v.T == nil {
return nil, fmt.Errorf("invalid time anchor value %v for bound %s", v, cls.PUpperBoundAlias)
}
if lo.UpperAnchor == nil || (lo.UpperAnchor != nil && v.T.After(*lo.UpperAnchor)) {
lo.UpperAnchor = v.T
}
}
nlo := updateTimeBounds(lo, cls)
return nlo, nil
} | [
"func",
"updateTimeBoundsForRow",
"(",
"lo",
"*",
"storage",
".",
"LookupOptions",
",",
"cls",
"*",
"semantic",
".",
"GraphClause",
",",
"r",
"table",
".",
"Row",
")",
"(",
"*",
"storage",
".",
"LookupOptions",
",",
"error",
")",
"{",
"lo",
"=",
"updateTimeBounds",
"(",
"lo",
",",
"cls",
")",
"\n",
"if",
"cls",
".",
"PLowerBoundAlias",
"!=",
"\"",
"\"",
"{",
"v",
",",
"ok",
":=",
"r",
"[",
"cls",
".",
"PLowerBoundAlias",
"]",
"\n",
"if",
"ok",
"&&",
"v",
".",
"T",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
",",
"cls",
".",
"PLowerBoundAlias",
")",
"\n",
"}",
"\n",
"if",
"lo",
".",
"LowerAnchor",
"==",
"nil",
"||",
"(",
"lo",
".",
"LowerAnchor",
"!=",
"nil",
"&&",
"v",
".",
"T",
".",
"After",
"(",
"*",
"lo",
".",
"LowerAnchor",
")",
")",
"{",
"lo",
".",
"LowerAnchor",
"=",
"v",
".",
"T",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"cls",
".",
"PUpperBoundAlias",
"!=",
"\"",
"\"",
"{",
"v",
",",
"ok",
":=",
"r",
"[",
"cls",
".",
"PUpperBoundAlias",
"]",
"\n",
"if",
"ok",
"&&",
"v",
".",
"T",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
",",
"cls",
".",
"PUpperBoundAlias",
")",
"\n",
"}",
"\n",
"if",
"lo",
".",
"UpperAnchor",
"==",
"nil",
"||",
"(",
"lo",
".",
"UpperAnchor",
"!=",
"nil",
"&&",
"v",
".",
"T",
".",
"After",
"(",
"*",
"lo",
".",
"UpperAnchor",
")",
")",
"{",
"lo",
".",
"UpperAnchor",
"=",
"v",
".",
"T",
"\n",
"}",
"\n",
"}",
"\n",
"nlo",
":=",
"updateTimeBounds",
"(",
"lo",
",",
"cls",
")",
"\n",
"return",
"nlo",
",",
"nil",
"\n",
"}"
]
| // updateTimeBoundsForRow updates the time bounds use for the lookup based on
// the provided graph clause. | [
"updateTimeBoundsForRow",
"updates",
"the",
"time",
"bounds",
"use",
"for",
"the",
"lookup",
"based",
"on",
"the",
"provided",
"graph",
"clause",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/planner/data_access.go#L56-L78 |
12,581 | google/badwolf | bql/planner/data_access.go | simpleExist | func simpleExist(ctx context.Context, gs []storage.Graph, cls *semantic.GraphClause, t *triple.Triple) (bool, *table.Table, error) {
unfeasible := true
tbl, err := table.New(cls.Bindings())
if err != nil {
return true, nil, err
}
for _, g := range gs {
b, err := g.Exist(ctx, t)
if err != nil {
return true, nil, err
}
if b {
unfeasible = false
ts := make(chan *triple.Triple, 1)
ts <- t
close(ts)
if err := addTriples(ts, cls, tbl); err != nil {
return true, nil, err
}
}
}
return unfeasible, tbl, nil
} | go | func simpleExist(ctx context.Context, gs []storage.Graph, cls *semantic.GraphClause, t *triple.Triple) (bool, *table.Table, error) {
unfeasible := true
tbl, err := table.New(cls.Bindings())
if err != nil {
return true, nil, err
}
for _, g := range gs {
b, err := g.Exist(ctx, t)
if err != nil {
return true, nil, err
}
if b {
unfeasible = false
ts := make(chan *triple.Triple, 1)
ts <- t
close(ts)
if err := addTriples(ts, cls, tbl); err != nil {
return true, nil, err
}
}
}
return unfeasible, tbl, nil
} | [
"func",
"simpleExist",
"(",
"ctx",
"context",
".",
"Context",
",",
"gs",
"[",
"]",
"storage",
".",
"Graph",
",",
"cls",
"*",
"semantic",
".",
"GraphClause",
",",
"t",
"*",
"triple",
".",
"Triple",
")",
"(",
"bool",
",",
"*",
"table",
".",
"Table",
",",
"error",
")",
"{",
"unfeasible",
":=",
"true",
"\n",
"tbl",
",",
"err",
":=",
"table",
".",
"New",
"(",
"cls",
".",
"Bindings",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"true",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"g",
":=",
"range",
"gs",
"{",
"b",
",",
"err",
":=",
"g",
".",
"Exist",
"(",
"ctx",
",",
"t",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"true",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"b",
"{",
"unfeasible",
"=",
"false",
"\n",
"ts",
":=",
"make",
"(",
"chan",
"*",
"triple",
".",
"Triple",
",",
"1",
")",
"\n",
"ts",
"<-",
"t",
"\n",
"close",
"(",
"ts",
")",
"\n",
"if",
"err",
":=",
"addTriples",
"(",
"ts",
",",
"cls",
",",
"tbl",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"true",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"unfeasible",
",",
"tbl",
",",
"nil",
"\n",
"}"
]
| // simpleExist returns true if the triple exist. Return the unfeasible state,
// the table and the error if present. | [
"simpleExist",
"returns",
"true",
"if",
"the",
"triple",
"exist",
".",
"Return",
"the",
"unfeasible",
"state",
"the",
"table",
"and",
"the",
"error",
"if",
"present",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/planner/data_access.go#L82-L104 |
12,582 | google/badwolf | bql/planner/data_access.go | addTriples | func addTriples(ts <-chan *triple.Triple, cls *semantic.GraphClause, tbl *table.Table) error {
for t := range ts {
if cls.PID != "" {
// The triples need to be filtered.
if string(t.Predicate().ID()) != cls.PID {
continue
}
if cls.PTemporal {
if t.Predicate().Type() != predicate.Temporal {
continue
}
ta, err := t.Predicate().TimeAnchor()
if err != nil {
return fmt.Errorf("failed to retrieve time anchor from time predicate in triple %s with error %v", t, err)
}
// Need to check the bounds of the triple.
if cls.PLowerBound != nil && cls.PLowerBound.After(*ta) {
continue
}
if cls.PUpperBound != nil && cls.PUpperBound.Before(*ta) {
continue
}
}
}
if cls.OID != "" {
if p, err := t.Object().Predicate(); err == nil {
// The triples need to be filtered.
if string(p.ID()) != cls.OID {
continue
}
if cls.OTemporal {
if p.Type() != predicate.Temporal {
continue
}
ta, err := p.TimeAnchor()
if err != nil {
return fmt.Errorf("failed to retrieve time anchor from time predicate in triple %s with error %v", t, err)
}
// Need to check the bounds of the triple.
if cls.OLowerBound != nil && cls.OLowerBound.After(*ta) {
continue
}
if cls.OUpperBound != nil && cls.OUpperBound.Before(*ta) {
continue
}
}
}
}
r, err := tripleToRow(t, cls)
if err != nil {
return err
}
if r != nil {
tbl.AddRow(r)
}
}
return nil
} | go | func addTriples(ts <-chan *triple.Triple, cls *semantic.GraphClause, tbl *table.Table) error {
for t := range ts {
if cls.PID != "" {
// The triples need to be filtered.
if string(t.Predicate().ID()) != cls.PID {
continue
}
if cls.PTemporal {
if t.Predicate().Type() != predicate.Temporal {
continue
}
ta, err := t.Predicate().TimeAnchor()
if err != nil {
return fmt.Errorf("failed to retrieve time anchor from time predicate in triple %s with error %v", t, err)
}
// Need to check the bounds of the triple.
if cls.PLowerBound != nil && cls.PLowerBound.After(*ta) {
continue
}
if cls.PUpperBound != nil && cls.PUpperBound.Before(*ta) {
continue
}
}
}
if cls.OID != "" {
if p, err := t.Object().Predicate(); err == nil {
// The triples need to be filtered.
if string(p.ID()) != cls.OID {
continue
}
if cls.OTemporal {
if p.Type() != predicate.Temporal {
continue
}
ta, err := p.TimeAnchor()
if err != nil {
return fmt.Errorf("failed to retrieve time anchor from time predicate in triple %s with error %v", t, err)
}
// Need to check the bounds of the triple.
if cls.OLowerBound != nil && cls.OLowerBound.After(*ta) {
continue
}
if cls.OUpperBound != nil && cls.OUpperBound.Before(*ta) {
continue
}
}
}
}
r, err := tripleToRow(t, cls)
if err != nil {
return err
}
if r != nil {
tbl.AddRow(r)
}
}
return nil
} | [
"func",
"addTriples",
"(",
"ts",
"<-",
"chan",
"*",
"triple",
".",
"Triple",
",",
"cls",
"*",
"semantic",
".",
"GraphClause",
",",
"tbl",
"*",
"table",
".",
"Table",
")",
"error",
"{",
"for",
"t",
":=",
"range",
"ts",
"{",
"if",
"cls",
".",
"PID",
"!=",
"\"",
"\"",
"{",
"// The triples need to be filtered.",
"if",
"string",
"(",
"t",
".",
"Predicate",
"(",
")",
".",
"ID",
"(",
")",
")",
"!=",
"cls",
".",
"PID",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"cls",
".",
"PTemporal",
"{",
"if",
"t",
".",
"Predicate",
"(",
")",
".",
"Type",
"(",
")",
"!=",
"predicate",
".",
"Temporal",
"{",
"continue",
"\n",
"}",
"\n",
"ta",
",",
"err",
":=",
"t",
".",
"Predicate",
"(",
")",
".",
"TimeAnchor",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
",",
"err",
")",
"\n",
"}",
"\n",
"// Need to check the bounds of the triple.",
"if",
"cls",
".",
"PLowerBound",
"!=",
"nil",
"&&",
"cls",
".",
"PLowerBound",
".",
"After",
"(",
"*",
"ta",
")",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"cls",
".",
"PUpperBound",
"!=",
"nil",
"&&",
"cls",
".",
"PUpperBound",
".",
"Before",
"(",
"*",
"ta",
")",
"{",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"cls",
".",
"OID",
"!=",
"\"",
"\"",
"{",
"if",
"p",
",",
"err",
":=",
"t",
".",
"Object",
"(",
")",
".",
"Predicate",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"// The triples need to be filtered.",
"if",
"string",
"(",
"p",
".",
"ID",
"(",
")",
")",
"!=",
"cls",
".",
"OID",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"cls",
".",
"OTemporal",
"{",
"if",
"p",
".",
"Type",
"(",
")",
"!=",
"predicate",
".",
"Temporal",
"{",
"continue",
"\n",
"}",
"\n",
"ta",
",",
"err",
":=",
"p",
".",
"TimeAnchor",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
",",
"err",
")",
"\n",
"}",
"\n",
"// Need to check the bounds of the triple.",
"if",
"cls",
".",
"OLowerBound",
"!=",
"nil",
"&&",
"cls",
".",
"OLowerBound",
".",
"After",
"(",
"*",
"ta",
")",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"cls",
".",
"OUpperBound",
"!=",
"nil",
"&&",
"cls",
".",
"OUpperBound",
".",
"Before",
"(",
"*",
"ta",
")",
"{",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"r",
",",
"err",
":=",
"tripleToRow",
"(",
"t",
",",
"cls",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"r",
"!=",
"nil",
"{",
"tbl",
".",
"AddRow",
"(",
"r",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // addTriples add all the retrieved triples from the graphs into the results
// table. The semantic graph clause is also passed to be able to identify what
// bindings to set. | [
"addTriples",
"add",
"all",
"the",
"retrieved",
"triples",
"from",
"the",
"graphs",
"into",
"the",
"results",
"table",
".",
"The",
"semantic",
"graph",
"clause",
"is",
"also",
"passed",
"to",
"be",
"able",
"to",
"identify",
"what",
"bindings",
"to",
"set",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/planner/data_access.go#L411-L468 |
12,583 | google/badwolf | bql/planner/data_access.go | objectToCell | func objectToCell(o *triple.Object) (*table.Cell, error) {
c := &table.Cell{}
if n, err := o.Node(); err == nil {
c.N = n
return c, nil
}
if p, err := o.Predicate(); err == nil {
c.P = p
return c, nil
}
if l, err := o.Literal(); err == nil {
c.L = l
return c, nil
}
return nil, fmt.Errorf("unknown object type in object %q", o)
} | go | func objectToCell(o *triple.Object) (*table.Cell, error) {
c := &table.Cell{}
if n, err := o.Node(); err == nil {
c.N = n
return c, nil
}
if p, err := o.Predicate(); err == nil {
c.P = p
return c, nil
}
if l, err := o.Literal(); err == nil {
c.L = l
return c, nil
}
return nil, fmt.Errorf("unknown object type in object %q", o)
} | [
"func",
"objectToCell",
"(",
"o",
"*",
"triple",
".",
"Object",
")",
"(",
"*",
"table",
".",
"Cell",
",",
"error",
")",
"{",
"c",
":=",
"&",
"table",
".",
"Cell",
"{",
"}",
"\n",
"if",
"n",
",",
"err",
":=",
"o",
".",
"Node",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"c",
".",
"N",
"=",
"n",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}",
"\n",
"if",
"p",
",",
"err",
":=",
"o",
".",
"Predicate",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"c",
".",
"P",
"=",
"p",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}",
"\n",
"if",
"l",
",",
"err",
":=",
"o",
".",
"Literal",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"c",
".",
"L",
"=",
"l",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"o",
")",
"\n",
"}"
]
| // objectToCell returns a cell containing the data boxed in the object. | [
"objectToCell",
"returns",
"a",
"cell",
"containing",
"the",
"data",
"boxed",
"in",
"the",
"object",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/planner/data_access.go#L471-L486 |
12,584 | google/badwolf | tools/vcli/bw/benchmark/benchmark.go | runAll | func runAll(ctx context.Context, st storage.Store, chanSize, bulkSize int) int {
// - Add non existing triples. (done)
// - Add triples that already exist. (done)
// - Remove non existing triples. (done)
// - Remove existing triples. (done)
// - BQL tree walking from root. (done)
// - BQL random graph hopping. (done)
// - BQL sorting. (done)
// - BQL grouping. (done)
// - BQL counting. (bounded by sort and grouping)
// - BQL filter existent (bounded by sort and grouping)
// - BQL filter non existent (bounded by sort and grouping)
fmt.Printf("DISCLAIMER: Running this benchmarks is expensive. Consider using a machine with at least 3G of RAM.\n\n")
var out int
// Add non existing triples.
out += runBattery(ctx, st, "adding non existing tree triples", chanSize, bulkSize, batteries.AddTreeTriplesBenchmark)
out += runBattery(ctx, st, "adding non existing graph triples", chanSize, bulkSize, batteries.AddGraphTriplesBenchmark)
// Add existing triples.
out += runBattery(ctx, st, "adding existing tree triples", chanSize, bulkSize, batteries.AddExistingTreeTriplesBenchmark)
out += runBattery(ctx, st, "adding existing graph triples", chanSize, bulkSize, batteries.AddExistingGraphTriplesBenchmark)
// Remove non existing triples.
out += runBattery(ctx, st, "removing non existing tree triples", chanSize, bulkSize, batteries.RemoveTreeTriplesBenchmark)
out += runBattery(ctx, st, "removing non existing graph triples", chanSize, bulkSize, batteries.RemoveGraphTriplesBenchmark)
// Remove existing triples.
out += runBattery(ctx, st, "removing existing tree triples", chanSize, bulkSize, batteries.RemoveExistingTreeTriplesBenchmark)
out += runBattery(ctx, st, "removing existing graph triples", chanSize, bulkSize, batteries.RemoveExistingGraphTriplesBenchmark)
// BQL graph walking.
out += runBattery(ctx, st, "walking the tree graph with BQL", chanSize, bulkSize, batteries.BQLTreeGraphWalking)
out += runBattery(ctx, st, "walking the random graph with BQL", chanSize, bulkSize, batteries.BQLRandomGraphWalking)
return out
} | go | func runAll(ctx context.Context, st storage.Store, chanSize, bulkSize int) int {
// - Add non existing triples. (done)
// - Add triples that already exist. (done)
// - Remove non existing triples. (done)
// - Remove existing triples. (done)
// - BQL tree walking from root. (done)
// - BQL random graph hopping. (done)
// - BQL sorting. (done)
// - BQL grouping. (done)
// - BQL counting. (bounded by sort and grouping)
// - BQL filter existent (bounded by sort and grouping)
// - BQL filter non existent (bounded by sort and grouping)
fmt.Printf("DISCLAIMER: Running this benchmarks is expensive. Consider using a machine with at least 3G of RAM.\n\n")
var out int
// Add non existing triples.
out += runBattery(ctx, st, "adding non existing tree triples", chanSize, bulkSize, batteries.AddTreeTriplesBenchmark)
out += runBattery(ctx, st, "adding non existing graph triples", chanSize, bulkSize, batteries.AddGraphTriplesBenchmark)
// Add existing triples.
out += runBattery(ctx, st, "adding existing tree triples", chanSize, bulkSize, batteries.AddExistingTreeTriplesBenchmark)
out += runBattery(ctx, st, "adding existing graph triples", chanSize, bulkSize, batteries.AddExistingGraphTriplesBenchmark)
// Remove non existing triples.
out += runBattery(ctx, st, "removing non existing tree triples", chanSize, bulkSize, batteries.RemoveTreeTriplesBenchmark)
out += runBattery(ctx, st, "removing non existing graph triples", chanSize, bulkSize, batteries.RemoveGraphTriplesBenchmark)
// Remove existing triples.
out += runBattery(ctx, st, "removing existing tree triples", chanSize, bulkSize, batteries.RemoveExistingTreeTriplesBenchmark)
out += runBattery(ctx, st, "removing existing graph triples", chanSize, bulkSize, batteries.RemoveExistingGraphTriplesBenchmark)
// BQL graph walking.
out += runBattery(ctx, st, "walking the tree graph with BQL", chanSize, bulkSize, batteries.BQLTreeGraphWalking)
out += runBattery(ctx, st, "walking the random graph with BQL", chanSize, bulkSize, batteries.BQLRandomGraphWalking)
return out
} | [
"func",
"runAll",
"(",
"ctx",
"context",
".",
"Context",
",",
"st",
"storage",
".",
"Store",
",",
"chanSize",
",",
"bulkSize",
"int",
")",
"int",
"{",
"// - Add non existing triples. (done)",
"// - Add triples that already exist. (done)",
"// - Remove non existing triples. (done)",
"// - Remove existing triples. (done)",
"// - BQL tree walking from root. (done)",
"// - BQL random graph hopping. (done)",
"// - BQL sorting. (done)",
"// - BQL grouping. (done)",
"// - BQL counting. (bounded by sort and grouping)",
"// - BQL filter existent (bounded by sort and grouping)",
"// - BQL filter non existent (bounded by sort and grouping)",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
")",
"\n\n",
"var",
"out",
"int",
"\n",
"// Add non existing triples.",
"out",
"+=",
"runBattery",
"(",
"ctx",
",",
"st",
",",
"\"",
"\"",
",",
"chanSize",
",",
"bulkSize",
",",
"batteries",
".",
"AddTreeTriplesBenchmark",
")",
"\n",
"out",
"+=",
"runBattery",
"(",
"ctx",
",",
"st",
",",
"\"",
"\"",
",",
"chanSize",
",",
"bulkSize",
",",
"batteries",
".",
"AddGraphTriplesBenchmark",
")",
"\n\n",
"// Add existing triples.",
"out",
"+=",
"runBattery",
"(",
"ctx",
",",
"st",
",",
"\"",
"\"",
",",
"chanSize",
",",
"bulkSize",
",",
"batteries",
".",
"AddExistingTreeTriplesBenchmark",
")",
"\n",
"out",
"+=",
"runBattery",
"(",
"ctx",
",",
"st",
",",
"\"",
"\"",
",",
"chanSize",
",",
"bulkSize",
",",
"batteries",
".",
"AddExistingGraphTriplesBenchmark",
")",
"\n\n",
"// Remove non existing triples.",
"out",
"+=",
"runBattery",
"(",
"ctx",
",",
"st",
",",
"\"",
"\"",
",",
"chanSize",
",",
"bulkSize",
",",
"batteries",
".",
"RemoveTreeTriplesBenchmark",
")",
"\n",
"out",
"+=",
"runBattery",
"(",
"ctx",
",",
"st",
",",
"\"",
"\"",
",",
"chanSize",
",",
"bulkSize",
",",
"batteries",
".",
"RemoveGraphTriplesBenchmark",
")",
"\n\n",
"// Remove existing triples.",
"out",
"+=",
"runBattery",
"(",
"ctx",
",",
"st",
",",
"\"",
"\"",
",",
"chanSize",
",",
"bulkSize",
",",
"batteries",
".",
"RemoveExistingTreeTriplesBenchmark",
")",
"\n",
"out",
"+=",
"runBattery",
"(",
"ctx",
",",
"st",
",",
"\"",
"\"",
",",
"chanSize",
",",
"bulkSize",
",",
"batteries",
".",
"RemoveExistingGraphTriplesBenchmark",
")",
"\n\n",
"// BQL graph walking.",
"out",
"+=",
"runBattery",
"(",
"ctx",
",",
"st",
",",
"\"",
"\"",
",",
"chanSize",
",",
"bulkSize",
",",
"batteries",
".",
"BQLTreeGraphWalking",
")",
"\n",
"out",
"+=",
"runBattery",
"(",
"ctx",
",",
"st",
",",
"\"",
"\"",
",",
"chanSize",
",",
"bulkSize",
",",
"batteries",
".",
"BQLRandomGraphWalking",
")",
"\n",
"return",
"out",
"\n",
"}"
]
| // runAll executes all the canned benchmarks and prints out the stats. | [
"runAll",
"executes",
"all",
"the",
"canned",
"benchmarks",
"and",
"prints",
"out",
"the",
"stats",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/benchmark/benchmark.go#L48-L83 |
12,585 | google/badwolf | tools/vcli/bw/benchmark/benchmark.go | runBattery | func runBattery(ctx context.Context, st storage.Store, name string, chanSize, bulkSize int, f func(context.Context, storage.Store, int, int) ([]*runtime.BenchEntry, error)) int {
// Add triples.
fmt.Printf("Creating %s triples benchmark... ", name)
bes, err := f(ctx, st, chanSize, bulkSize)
if err != nil {
log.Printf("[ERROR] %v\n", err)
return 2
}
fmt.Printf("%d entries created\n", len(bes))
fmt.Printf("Run %s benchmark sequentially... ", name)
ts := time.Now()
brs := runtime.RunBenchmarkBatterySequentially(bes)
ds := time.Now().Sub(ts)
fmt.Printf("(%v) done\n", ds)
fmt.Printf("Run %s benchmark concurrently... ", name)
tc := time.Now()
brc := runtime.RunBenchmarkBatteryConcurrently(bes)
dc := time.Now().Sub(tc)
fmt.Printf("(%v) done\n\n", dc)
format := func(br *runtime.BenchResult) string {
if br.Err != nil {
return fmt.Sprintf("%20s - %20s -[ERROR] %v", br.BatteryID, br.ID, br.Err)
}
tps := float64(br.Triples) / (float64(br.Mean) / float64(time.Second))
return fmt.Sprintf("%20s - %20s - %05.2f triples/sec - %v/%v", br.BatteryID, br.ID, tps, br.Mean, br.StdDev)
}
sortAndPrint := func(ss []string) {
sort.Strings(ss)
for _, s := range ss {
fmt.Println(s)
}
}
fmt.Printf("Stats for sequentially run %s benchmark\n", name)
var ress []string
for _, br := range brs {
ress = append(ress, format(br))
}
sortAndPrint(ress)
fmt.Println()
fmt.Printf("Stats for concurrently run %s benchmark\n", name)
var resc []string
for _, br := range brc {
resc = append(resc, format(br))
}
sortAndPrint(resc)
fmt.Println()
return 0
} | go | func runBattery(ctx context.Context, st storage.Store, name string, chanSize, bulkSize int, f func(context.Context, storage.Store, int, int) ([]*runtime.BenchEntry, error)) int {
// Add triples.
fmt.Printf("Creating %s triples benchmark... ", name)
bes, err := f(ctx, st, chanSize, bulkSize)
if err != nil {
log.Printf("[ERROR] %v\n", err)
return 2
}
fmt.Printf("%d entries created\n", len(bes))
fmt.Printf("Run %s benchmark sequentially... ", name)
ts := time.Now()
brs := runtime.RunBenchmarkBatterySequentially(bes)
ds := time.Now().Sub(ts)
fmt.Printf("(%v) done\n", ds)
fmt.Printf("Run %s benchmark concurrently... ", name)
tc := time.Now()
brc := runtime.RunBenchmarkBatteryConcurrently(bes)
dc := time.Now().Sub(tc)
fmt.Printf("(%v) done\n\n", dc)
format := func(br *runtime.BenchResult) string {
if br.Err != nil {
return fmt.Sprintf("%20s - %20s -[ERROR] %v", br.BatteryID, br.ID, br.Err)
}
tps := float64(br.Triples) / (float64(br.Mean) / float64(time.Second))
return fmt.Sprintf("%20s - %20s - %05.2f triples/sec - %v/%v", br.BatteryID, br.ID, tps, br.Mean, br.StdDev)
}
sortAndPrint := func(ss []string) {
sort.Strings(ss)
for _, s := range ss {
fmt.Println(s)
}
}
fmt.Printf("Stats for sequentially run %s benchmark\n", name)
var ress []string
for _, br := range brs {
ress = append(ress, format(br))
}
sortAndPrint(ress)
fmt.Println()
fmt.Printf("Stats for concurrently run %s benchmark\n", name)
var resc []string
for _, br := range brc {
resc = append(resc, format(br))
}
sortAndPrint(resc)
fmt.Println()
return 0
} | [
"func",
"runBattery",
"(",
"ctx",
"context",
".",
"Context",
",",
"st",
"storage",
".",
"Store",
",",
"name",
"string",
",",
"chanSize",
",",
"bulkSize",
"int",
",",
"f",
"func",
"(",
"context",
".",
"Context",
",",
"storage",
".",
"Store",
",",
"int",
",",
"int",
")",
"(",
"[",
"]",
"*",
"runtime",
".",
"BenchEntry",
",",
"error",
")",
")",
"int",
"{",
"// Add triples.",
"fmt",
".",
"Printf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"bes",
",",
"err",
":=",
"f",
"(",
"ctx",
",",
"st",
",",
"chanSize",
",",
"bulkSize",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"return",
"2",
"\n",
"}",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"len",
"(",
"bes",
")",
")",
"\n\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"ts",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"brs",
":=",
"runtime",
".",
"RunBenchmarkBatterySequentially",
"(",
"bes",
")",
"\n",
"ds",
":=",
"time",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"ts",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"ds",
")",
"\n\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"tc",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"brc",
":=",
"runtime",
".",
"RunBenchmarkBatteryConcurrently",
"(",
"bes",
")",
"\n",
"dc",
":=",
"time",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"tc",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"dc",
")",
"\n\n",
"format",
":=",
"func",
"(",
"br",
"*",
"runtime",
".",
"BenchResult",
")",
"string",
"{",
"if",
"br",
".",
"Err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"br",
".",
"BatteryID",
",",
"br",
".",
"ID",
",",
"br",
".",
"Err",
")",
"\n",
"}",
"\n",
"tps",
":=",
"float64",
"(",
"br",
".",
"Triples",
")",
"/",
"(",
"float64",
"(",
"br",
".",
"Mean",
")",
"/",
"float64",
"(",
"time",
".",
"Second",
")",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"br",
".",
"BatteryID",
",",
"br",
".",
"ID",
",",
"tps",
",",
"br",
".",
"Mean",
",",
"br",
".",
"StdDev",
")",
"\n",
"}",
"\n\n",
"sortAndPrint",
":=",
"func",
"(",
"ss",
"[",
"]",
"string",
")",
"{",
"sort",
".",
"Strings",
"(",
"ss",
")",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"ss",
"{",
"fmt",
".",
"Println",
"(",
"s",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"name",
")",
"\n",
"var",
"ress",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"br",
":=",
"range",
"brs",
"{",
"ress",
"=",
"append",
"(",
"ress",
",",
"format",
"(",
"br",
")",
")",
"\n",
"}",
"\n",
"sortAndPrint",
"(",
"ress",
")",
"\n",
"fmt",
".",
"Println",
"(",
")",
"\n\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"name",
")",
"\n",
"var",
"resc",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"br",
":=",
"range",
"brc",
"{",
"resc",
"=",
"append",
"(",
"resc",
",",
"format",
"(",
"br",
")",
")",
"\n",
"}",
"\n",
"sortAndPrint",
"(",
"resc",
")",
"\n",
"fmt",
".",
"Println",
"(",
")",
"\n\n",
"return",
"0",
"\n",
"}"
]
| // runBattery executes all the canned benchmarks and prints out the stats. | [
"runBattery",
"executes",
"all",
"the",
"canned",
"benchmarks",
"and",
"prints",
"out",
"the",
"stats",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/benchmark/benchmark.go#L86-L140 |
12,586 | google/badwolf | tools/vcli/bw/io/io.go | GetStatementsFromFile | func GetStatementsFromFile(path string) ([]string, error) {
stms, err := ReadLines(path)
if err != nil {
return nil, err
}
return stms, nil
} | go | func GetStatementsFromFile(path string) ([]string, error) {
stms, err := ReadLines(path)
if err != nil {
return nil, err
}
return stms, nil
} | [
"func",
"GetStatementsFromFile",
"(",
"path",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"stms",
",",
"err",
":=",
"ReadLines",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"stms",
",",
"nil",
"\n",
"}"
]
| // GetStatementsFromFile returns the statements found in the provided file. | [
"GetStatementsFromFile",
"returns",
"the",
"statements",
"found",
"in",
"the",
"provided",
"file",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/io/io.go#L26-L32 |
12,587 | google/badwolf | tools/vcli/bw/io/io.go | ReadLines | func ReadLines(path string) ([]string, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
var lines []string
scanner := bufio.NewScanner(f)
line := ""
for scanner.Scan() {
l := strings.TrimSpace(scanner.Text())
if len(l) == 0 || strings.Index(l, "#") == 0 {
continue
}
line += " " + l
if l[len(l)-1:] == ";" {
lines = append(lines, strings.TrimSpace(line))
line = ""
}
}
if line != "" {
lines = append(lines, strings.TrimSpace(line))
}
return lines, scanner.Err()
} | go | func ReadLines(path string) ([]string, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
var lines []string
scanner := bufio.NewScanner(f)
line := ""
for scanner.Scan() {
l := strings.TrimSpace(scanner.Text())
if len(l) == 0 || strings.Index(l, "#") == 0 {
continue
}
line += " " + l
if l[len(l)-1:] == ";" {
lines = append(lines, strings.TrimSpace(line))
line = ""
}
}
if line != "" {
lines = append(lines, strings.TrimSpace(line))
}
return lines, scanner.Err()
} | [
"func",
"ReadLines",
"(",
"path",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"var",
"lines",
"[",
"]",
"string",
"\n",
"scanner",
":=",
"bufio",
".",
"NewScanner",
"(",
"f",
")",
"\n",
"line",
":=",
"\"",
"\"",
"\n",
"for",
"scanner",
".",
"Scan",
"(",
")",
"{",
"l",
":=",
"strings",
".",
"TrimSpace",
"(",
"scanner",
".",
"Text",
"(",
")",
")",
"\n",
"if",
"len",
"(",
"l",
")",
"==",
"0",
"||",
"strings",
".",
"Index",
"(",
"l",
",",
"\"",
"\"",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"line",
"+=",
"\"",
"\"",
"+",
"l",
"\n",
"if",
"l",
"[",
"len",
"(",
"l",
")",
"-",
"1",
":",
"]",
"==",
"\"",
"\"",
"{",
"lines",
"=",
"append",
"(",
"lines",
",",
"strings",
".",
"TrimSpace",
"(",
"line",
")",
")",
"\n",
"line",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"line",
"!=",
"\"",
"\"",
"{",
"lines",
"=",
"append",
"(",
"lines",
",",
"strings",
".",
"TrimSpace",
"(",
"line",
")",
")",
"\n",
"}",
"\n",
"return",
"lines",
",",
"scanner",
".",
"Err",
"(",
")",
"\n",
"}"
]
| // ReadLines from a file into a string array. | [
"ReadLines",
"from",
"a",
"file",
"into",
"a",
"string",
"array",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/io/io.go#L35-L60 |
12,588 | google/badwolf | tools/vcli/bw/io/io.go | ProcessLines | func ProcessLines(path string, fp func(line string) error) (int, error) {
f, err := os.Open(path)
if err != nil {
return 0, err
}
defer f.Close()
scanner := bufio.NewScanner(f)
cnt := 0
for scanner.Scan() {
l := strings.TrimSpace(scanner.Text())
cnt++
if len(l) == 0 || strings.Index(l, "#") == 0 {
continue
}
if err := fp(l); err != nil {
return cnt, err
}
}
return cnt, scanner.Err()
} | go | func ProcessLines(path string, fp func(line string) error) (int, error) {
f, err := os.Open(path)
if err != nil {
return 0, err
}
defer f.Close()
scanner := bufio.NewScanner(f)
cnt := 0
for scanner.Scan() {
l := strings.TrimSpace(scanner.Text())
cnt++
if len(l) == 0 || strings.Index(l, "#") == 0 {
continue
}
if err := fp(l); err != nil {
return cnt, err
}
}
return cnt, scanner.Err()
} | [
"func",
"ProcessLines",
"(",
"path",
"string",
",",
"fp",
"func",
"(",
"line",
"string",
")",
"error",
")",
"(",
"int",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"scanner",
":=",
"bufio",
".",
"NewScanner",
"(",
"f",
")",
"\n",
"cnt",
":=",
"0",
"\n",
"for",
"scanner",
".",
"Scan",
"(",
")",
"{",
"l",
":=",
"strings",
".",
"TrimSpace",
"(",
"scanner",
".",
"Text",
"(",
")",
")",
"\n",
"cnt",
"++",
"\n",
"if",
"len",
"(",
"l",
")",
"==",
"0",
"||",
"strings",
".",
"Index",
"(",
"l",
",",
"\"",
"\"",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"err",
":=",
"fp",
"(",
"l",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"cnt",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"cnt",
",",
"scanner",
".",
"Err",
"(",
")",
"\n",
"}"
]
| // ProcessLines from a file using the provided call back. The error of the
// callback will be passed through. Returns the number of processed errors
// before the error. Returns the line where the error occurred or the total
// numbers of lines processed. | [
"ProcessLines",
"from",
"a",
"file",
"using",
"the",
"provided",
"call",
"back",
".",
"The",
"error",
"of",
"the",
"callback",
"will",
"be",
"passed",
"through",
".",
"Returns",
"the",
"number",
"of",
"processed",
"errors",
"before",
"the",
"error",
".",
"Returns",
"the",
"line",
"where",
"the",
"error",
"occurred",
"or",
"the",
"total",
"numbers",
"of",
"lines",
"processed",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/io/io.go#L66-L86 |
12,589 | google/badwolf | io/io.go | ReadIntoGraph | func ReadIntoGraph(ctx context.Context, g storage.Graph, r io.Reader, b literal.Builder) (int, error) {
cnt, scanner := 0, bufio.NewScanner(r)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
text := strings.TrimSpace(scanner.Text())
if text == "" {
continue
}
t, err := triple.Parse(text, b)
if err != nil {
return cnt, err
}
cnt++
g.AddTriples(ctx, []*triple.Triple{t})
}
return cnt, nil
} | go | func ReadIntoGraph(ctx context.Context, g storage.Graph, r io.Reader, b literal.Builder) (int, error) {
cnt, scanner := 0, bufio.NewScanner(r)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
text := strings.TrimSpace(scanner.Text())
if text == "" {
continue
}
t, err := triple.Parse(text, b)
if err != nil {
return cnt, err
}
cnt++
g.AddTriples(ctx, []*triple.Triple{t})
}
return cnt, nil
} | [
"func",
"ReadIntoGraph",
"(",
"ctx",
"context",
".",
"Context",
",",
"g",
"storage",
".",
"Graph",
",",
"r",
"io",
".",
"Reader",
",",
"b",
"literal",
".",
"Builder",
")",
"(",
"int",
",",
"error",
")",
"{",
"cnt",
",",
"scanner",
":=",
"0",
",",
"bufio",
".",
"NewScanner",
"(",
"r",
")",
"\n",
"scanner",
".",
"Split",
"(",
"bufio",
".",
"ScanLines",
")",
"\n",
"for",
"scanner",
".",
"Scan",
"(",
")",
"{",
"text",
":=",
"strings",
".",
"TrimSpace",
"(",
"scanner",
".",
"Text",
"(",
")",
")",
"\n",
"if",
"text",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n",
"t",
",",
"err",
":=",
"triple",
".",
"Parse",
"(",
"text",
",",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"cnt",
",",
"err",
"\n",
"}",
"\n",
"cnt",
"++",
"\n",
"g",
".",
"AddTriples",
"(",
"ctx",
",",
"[",
"]",
"*",
"triple",
".",
"Triple",
"{",
"t",
"}",
")",
"\n",
"}",
"\n",
"return",
"cnt",
",",
"nil",
"\n",
"}"
]
| // ReadIntoGraph reads a graph out of the provided reader. The data on the
// reader is interpret as text. Each line represents one triple using the
// standard serialized format. ReadIntoGraph will stop if fails to Parse
// a triple on the stream. The triples read till then would have also been
// added to the graph. The int value returns the number of triples added. | [
"ReadIntoGraph",
"reads",
"a",
"graph",
"out",
"of",
"the",
"provided",
"reader",
".",
"The",
"data",
"on",
"the",
"reader",
"is",
"interpret",
"as",
"text",
".",
"Each",
"line",
"represents",
"one",
"triple",
"using",
"the",
"standard",
"serialized",
"format",
".",
"ReadIntoGraph",
"will",
"stop",
"if",
"fails",
"to",
"Parse",
"a",
"triple",
"on",
"the",
"stream",
".",
"The",
"triples",
"read",
"till",
"then",
"would",
"have",
"also",
"been",
"added",
"to",
"the",
"graph",
".",
"The",
"int",
"value",
"returns",
"the",
"number",
"of",
"triples",
"added",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/io/io.go#L36-L52 |
12,590 | google/badwolf | io/io.go | WriteGraph | func WriteGraph(ctx context.Context, w io.Writer, g storage.Graph) (int, error) {
var (
wg sync.WaitGroup
tErr error
wErr error
)
cnt, ts := 0, make(chan *triple.Triple)
wg.Add(1)
go func() {
defer wg.Done()
tErr = g.Triples(ctx, storage.DefaultLookup, ts)
}()
for t := range ts {
if wErr != nil {
continue
}
if _, err := io.WriteString(w, fmt.Sprintf("%s\n", t.String())); err != nil {
wErr = err
continue
}
cnt++
}
wg.Wait()
if tErr != nil {
return 0, tErr
}
if wErr != nil {
return 0, wErr
}
return cnt, nil
} | go | func WriteGraph(ctx context.Context, w io.Writer, g storage.Graph) (int, error) {
var (
wg sync.WaitGroup
tErr error
wErr error
)
cnt, ts := 0, make(chan *triple.Triple)
wg.Add(1)
go func() {
defer wg.Done()
tErr = g.Triples(ctx, storage.DefaultLookup, ts)
}()
for t := range ts {
if wErr != nil {
continue
}
if _, err := io.WriteString(w, fmt.Sprintf("%s\n", t.String())); err != nil {
wErr = err
continue
}
cnt++
}
wg.Wait()
if tErr != nil {
return 0, tErr
}
if wErr != nil {
return 0, wErr
}
return cnt, nil
} | [
"func",
"WriteGraph",
"(",
"ctx",
"context",
".",
"Context",
",",
"w",
"io",
".",
"Writer",
",",
"g",
"storage",
".",
"Graph",
")",
"(",
"int",
",",
"error",
")",
"{",
"var",
"(",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"tErr",
"error",
"\n",
"wErr",
"error",
"\n",
")",
"\n",
"cnt",
",",
"ts",
":=",
"0",
",",
"make",
"(",
"chan",
"*",
"triple",
".",
"Triple",
")",
"\n",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"tErr",
"=",
"g",
".",
"Triples",
"(",
"ctx",
",",
"storage",
".",
"DefaultLookup",
",",
"ts",
")",
"\n",
"}",
"(",
")",
"\n",
"for",
"t",
":=",
"range",
"ts",
"{",
"if",
"wErr",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"WriteString",
"(",
"w",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"t",
".",
"String",
"(",
")",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"wErr",
"=",
"err",
"\n",
"continue",
"\n",
"}",
"\n",
"cnt",
"++",
"\n",
"}",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"if",
"tErr",
"!=",
"nil",
"{",
"return",
"0",
",",
"tErr",
"\n",
"}",
"\n",
"if",
"wErr",
"!=",
"nil",
"{",
"return",
"0",
",",
"wErr",
"\n",
"}",
"\n",
"return",
"cnt",
",",
"nil",
"\n",
"}"
]
| // WriteGraph serializes the graph into the writer where each triple is
// marshaled into a separate line. If there is an error writing the
// serialization will stop. It returns the number of triples serialized
// regardless if it succeeded or failed partially. | [
"WriteGraph",
"serializes",
"the",
"graph",
"into",
"the",
"writer",
"where",
"each",
"triple",
"is",
"marshaled",
"into",
"a",
"separate",
"line",
".",
"If",
"there",
"is",
"an",
"error",
"writing",
"the",
"serialization",
"will",
"stop",
".",
"It",
"returns",
"the",
"number",
"of",
"triples",
"serialized",
"regardless",
"if",
"it",
"succeeded",
"or",
"failed",
"partially",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/io/io.go#L58-L88 |
12,591 | google/badwolf | tools/benchmark/batteries/add.go | AddGraphTriplesBenchmark | func AddGraphTriplesBenchmark(ctx context.Context, st storage.Store, chanSize, bulkSize int) ([]*runtime.BenchEntry, error) {
nodes := []int{317, 1000}
sizes := []int{10, 1000, 100000}
var trplSets [][]*triple.Triple
var ids []string
var gids []string
var gSizes []int
gs, err := getGraphGenerators(nodes)
if err != nil {
return nil, err
}
for idx, g := range gs {
for _, s := range sizes {
ts, err := g.Generate(s)
if err != nil {
return nil, err
}
trplSets = append(trplSets, ts)
ids = append(ids, fmt.Sprintf("rg nodes=%04d, size=%07d", nodes[idx], s))
gids = append(gids, fmt.Sprintf("n%d_s%d", nodes[idx], s))
gSizes = append(gSizes, s)
}
}
var bes []*runtime.BenchEntry
reps := []int{10}
for i, max := 0, len(ids); i < max; i++ {
for idxReps, r := range reps {
var g storage.Graph
gID := fmt.Sprintf("add_graph_%s_r%d_i%d", gids[i], i, idxReps)
data := trplSets[i]
bes = append(bes, &runtime.BenchEntry{
BatteryID: "Add non existing triples",
ID: fmt.Sprintf("%s, reps=%02d", ids[i], r),
Triples: gSizes[i],
Reps: r,
Setup: func() error {
var err error
g, err = st.NewGraph(ctx, gID)
return err
},
F: func() error {
return g.AddTriples(ctx, data)
},
TearDown: func() error {
return st.DeleteGraph(ctx, gID)
},
})
}
}
return bes, nil
} | go | func AddGraphTriplesBenchmark(ctx context.Context, st storage.Store, chanSize, bulkSize int) ([]*runtime.BenchEntry, error) {
nodes := []int{317, 1000}
sizes := []int{10, 1000, 100000}
var trplSets [][]*triple.Triple
var ids []string
var gids []string
var gSizes []int
gs, err := getGraphGenerators(nodes)
if err != nil {
return nil, err
}
for idx, g := range gs {
for _, s := range sizes {
ts, err := g.Generate(s)
if err != nil {
return nil, err
}
trplSets = append(trplSets, ts)
ids = append(ids, fmt.Sprintf("rg nodes=%04d, size=%07d", nodes[idx], s))
gids = append(gids, fmt.Sprintf("n%d_s%d", nodes[idx], s))
gSizes = append(gSizes, s)
}
}
var bes []*runtime.BenchEntry
reps := []int{10}
for i, max := 0, len(ids); i < max; i++ {
for idxReps, r := range reps {
var g storage.Graph
gID := fmt.Sprintf("add_graph_%s_r%d_i%d", gids[i], i, idxReps)
data := trplSets[i]
bes = append(bes, &runtime.BenchEntry{
BatteryID: "Add non existing triples",
ID: fmt.Sprintf("%s, reps=%02d", ids[i], r),
Triples: gSizes[i],
Reps: r,
Setup: func() error {
var err error
g, err = st.NewGraph(ctx, gID)
return err
},
F: func() error {
return g.AddTriples(ctx, data)
},
TearDown: func() error {
return st.DeleteGraph(ctx, gID)
},
})
}
}
return bes, nil
} | [
"func",
"AddGraphTriplesBenchmark",
"(",
"ctx",
"context",
".",
"Context",
",",
"st",
"storage",
".",
"Store",
",",
"chanSize",
",",
"bulkSize",
"int",
")",
"(",
"[",
"]",
"*",
"runtime",
".",
"BenchEntry",
",",
"error",
")",
"{",
"nodes",
":=",
"[",
"]",
"int",
"{",
"317",
",",
"1000",
"}",
"\n",
"sizes",
":=",
"[",
"]",
"int",
"{",
"10",
",",
"1000",
",",
"100000",
"}",
"\n",
"var",
"trplSets",
"[",
"]",
"[",
"]",
"*",
"triple",
".",
"Triple",
"\n",
"var",
"ids",
"[",
"]",
"string",
"\n",
"var",
"gids",
"[",
"]",
"string",
"\n",
"var",
"gSizes",
"[",
"]",
"int",
"\n",
"gs",
",",
"err",
":=",
"getGraphGenerators",
"(",
"nodes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"idx",
",",
"g",
":=",
"range",
"gs",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"sizes",
"{",
"ts",
",",
"err",
":=",
"g",
".",
"Generate",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"trplSets",
"=",
"append",
"(",
"trplSets",
",",
"ts",
")",
"\n",
"ids",
"=",
"append",
"(",
"ids",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"nodes",
"[",
"idx",
"]",
",",
"s",
")",
")",
"\n",
"gids",
"=",
"append",
"(",
"gids",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"nodes",
"[",
"idx",
"]",
",",
"s",
")",
")",
"\n",
"gSizes",
"=",
"append",
"(",
"gSizes",
",",
"s",
")",
"\n",
"}",
"\n",
"}",
"\n",
"var",
"bes",
"[",
"]",
"*",
"runtime",
".",
"BenchEntry",
"\n",
"reps",
":=",
"[",
"]",
"int",
"{",
"10",
"}",
"\n",
"for",
"i",
",",
"max",
":=",
"0",
",",
"len",
"(",
"ids",
")",
";",
"i",
"<",
"max",
";",
"i",
"++",
"{",
"for",
"idxReps",
",",
"r",
":=",
"range",
"reps",
"{",
"var",
"g",
"storage",
".",
"Graph",
"\n",
"gID",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"gids",
"[",
"i",
"]",
",",
"i",
",",
"idxReps",
")",
"\n",
"data",
":=",
"trplSets",
"[",
"i",
"]",
"\n",
"bes",
"=",
"append",
"(",
"bes",
",",
"&",
"runtime",
".",
"BenchEntry",
"{",
"BatteryID",
":",
"\"",
"\"",
",",
"ID",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ids",
"[",
"i",
"]",
",",
"r",
")",
",",
"Triples",
":",
"gSizes",
"[",
"i",
"]",
",",
"Reps",
":",
"r",
",",
"Setup",
":",
"func",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"g",
",",
"err",
"=",
"st",
".",
"NewGraph",
"(",
"ctx",
",",
"gID",
")",
"\n",
"return",
"err",
"\n",
"}",
",",
"F",
":",
"func",
"(",
")",
"error",
"{",
"return",
"g",
".",
"AddTriples",
"(",
"ctx",
",",
"data",
")",
"\n",
"}",
",",
"TearDown",
":",
"func",
"(",
")",
"error",
"{",
"return",
"st",
".",
"DeleteGraph",
"(",
"ctx",
",",
"gID",
")",
"\n",
"}",
",",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"bes",
",",
"nil",
"\n",
"}"
]
| // AddGraphTriplesBenchmark creates the benchmark. | [
"AddGraphTriplesBenchmark",
"creates",
"the",
"benchmark",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/benchmark/batteries/add.go#L137-L187 |
12,592 | google/badwolf | tools/vcli/bw/main.go | registerDrivers | func registerDrivers() {
registeredDrivers = map[string]common.StoreGenerator{
// Memory only storage driver.
"VOLATILE": func() (storage.Store, error) {
return memory.NewStore(), nil
},
}
} | go | func registerDrivers() {
registeredDrivers = map[string]common.StoreGenerator{
// Memory only storage driver.
"VOLATILE": func() (storage.Store, error) {
return memory.NewStore(), nil
},
}
} | [
"func",
"registerDrivers",
"(",
")",
"{",
"registeredDrivers",
"=",
"map",
"[",
"string",
"]",
"common",
".",
"StoreGenerator",
"{",
"// Memory only storage driver.",
"\"",
"\"",
":",
"func",
"(",
")",
"(",
"storage",
".",
"Store",
",",
"error",
")",
"{",
"return",
"memory",
".",
"NewStore",
"(",
")",
",",
"nil",
"\n",
"}",
",",
"}",
"\n",
"}"
]
| // Registers the available drivers. | [
"Registers",
"the",
"available",
"drivers",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/tools/vcli/bw/main.go#L46-L53 |
12,593 | google/badwolf | bql/lexer/lexer.go | lex | func lex(input string, capacity int) (*lexer, <-chan Token) {
l := &lexer{
input: input,
tokens: make(chan Token, capacity),
}
go l.run() // Concurrently run state machine.
return l, l.tokens
} | go | func lex(input string, capacity int) (*lexer, <-chan Token) {
l := &lexer{
input: input,
tokens: make(chan Token, capacity),
}
go l.run() // Concurrently run state machine.
return l, l.tokens
} | [
"func",
"lex",
"(",
"input",
"string",
",",
"capacity",
"int",
")",
"(",
"*",
"lexer",
",",
"<-",
"chan",
"Token",
")",
"{",
"l",
":=",
"&",
"lexer",
"{",
"input",
":",
"input",
",",
"tokens",
":",
"make",
"(",
"chan",
"Token",
",",
"capacity",
")",
",",
"}",
"\n",
"go",
"l",
".",
"run",
"(",
")",
"// Concurrently run state machine.",
"\n",
"return",
"l",
",",
"l",
".",
"tokens",
"\n",
"}"
]
| // lex creates a new lexer for the given input | [
"lex",
"creates",
"a",
"new",
"lexer",
"for",
"the",
"given",
"input"
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/lexer/lexer.go#L350-L357 |
12,594 | google/badwolf | bql/lexer/lexer.go | New | func New(input string, capacity int) <-chan Token {
if capacity < 0 {
capacity = 0
}
_, c := lex(input, capacity)
return c
} | go | func New(input string, capacity int) <-chan Token {
if capacity < 0 {
capacity = 0
}
_, c := lex(input, capacity)
return c
} | [
"func",
"New",
"(",
"input",
"string",
",",
"capacity",
"int",
")",
"<-",
"chan",
"Token",
"{",
"if",
"capacity",
"<",
"0",
"{",
"capacity",
"=",
"0",
"\n",
"}",
"\n",
"_",
",",
"c",
":=",
"lex",
"(",
"input",
",",
"capacity",
")",
"\n",
"return",
"c",
"\n",
"}"
]
| // New return a new read only channel with the tokens found in the provided
// input string. | [
"New",
"return",
"a",
"new",
"read",
"only",
"channel",
"with",
"the",
"tokens",
"found",
"in",
"the",
"provided",
"input",
"string",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/lexer/lexer.go#L361-L367 |
12,595 | google/badwolf | bql/lexer/lexer.go | lexToken | func lexToken(l *lexer) stateFn {
for {
{
r := l.peek()
switch r {
case binding:
l.next()
return lexBinding
case slash:
return lexNode
case underscore:
l.next()
return lexBlankNode
case quote:
return lexPredicateOrLiteral
}
if unicode.IsLetter(r) {
return lexKeyword
}
}
if state := isSingleSymbolToken(l, ItemLBracket, leftBracket); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemRBracket, rightBracket); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemLPar, leftPar); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemRPar, rightPar); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemSemicolon, semicolon); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemDot, dot); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemComma, comma); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemLT, lt); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemGT, gt); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemEQ, eq); state != nil {
return state
}
{
r := l.next()
if unicode.IsSpace(r) {
l.ignore()
continue
}
if l.next() == eof {
break
}
}
}
l.emit(ItemEOF) // Useful to make EOF a token.
return nil // Stop the run loop.
} | go | func lexToken(l *lexer) stateFn {
for {
{
r := l.peek()
switch r {
case binding:
l.next()
return lexBinding
case slash:
return lexNode
case underscore:
l.next()
return lexBlankNode
case quote:
return lexPredicateOrLiteral
}
if unicode.IsLetter(r) {
return lexKeyword
}
}
if state := isSingleSymbolToken(l, ItemLBracket, leftBracket); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemRBracket, rightBracket); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemLPar, leftPar); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemRPar, rightPar); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemSemicolon, semicolon); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemDot, dot); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemComma, comma); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemLT, lt); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemGT, gt); state != nil {
return state
}
if state := isSingleSymbolToken(l, ItemEQ, eq); state != nil {
return state
}
{
r := l.next()
if unicode.IsSpace(r) {
l.ignore()
continue
}
if l.next() == eof {
break
}
}
}
l.emit(ItemEOF) // Useful to make EOF a token.
return nil // Stop the run loop.
} | [
"func",
"lexToken",
"(",
"l",
"*",
"lexer",
")",
"stateFn",
"{",
"for",
"{",
"{",
"r",
":=",
"l",
".",
"peek",
"(",
")",
"\n",
"switch",
"r",
"{",
"case",
"binding",
":",
"l",
".",
"next",
"(",
")",
"\n",
"return",
"lexBinding",
"\n",
"case",
"slash",
":",
"return",
"lexNode",
"\n",
"case",
"underscore",
":",
"l",
".",
"next",
"(",
")",
"\n",
"return",
"lexBlankNode",
"\n",
"case",
"quote",
":",
"return",
"lexPredicateOrLiteral",
"\n",
"}",
"\n",
"if",
"unicode",
".",
"IsLetter",
"(",
"r",
")",
"{",
"return",
"lexKeyword",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"state",
":=",
"isSingleSymbolToken",
"(",
"l",
",",
"ItemLBracket",
",",
"leftBracket",
")",
";",
"state",
"!=",
"nil",
"{",
"return",
"state",
"\n",
"}",
"\n",
"if",
"state",
":=",
"isSingleSymbolToken",
"(",
"l",
",",
"ItemRBracket",
",",
"rightBracket",
")",
";",
"state",
"!=",
"nil",
"{",
"return",
"state",
"\n",
"}",
"\n",
"if",
"state",
":=",
"isSingleSymbolToken",
"(",
"l",
",",
"ItemLPar",
",",
"leftPar",
")",
";",
"state",
"!=",
"nil",
"{",
"return",
"state",
"\n",
"}",
"\n",
"if",
"state",
":=",
"isSingleSymbolToken",
"(",
"l",
",",
"ItemRPar",
",",
"rightPar",
")",
";",
"state",
"!=",
"nil",
"{",
"return",
"state",
"\n",
"}",
"\n",
"if",
"state",
":=",
"isSingleSymbolToken",
"(",
"l",
",",
"ItemSemicolon",
",",
"semicolon",
")",
";",
"state",
"!=",
"nil",
"{",
"return",
"state",
"\n",
"}",
"\n",
"if",
"state",
":=",
"isSingleSymbolToken",
"(",
"l",
",",
"ItemDot",
",",
"dot",
")",
";",
"state",
"!=",
"nil",
"{",
"return",
"state",
"\n",
"}",
"\n",
"if",
"state",
":=",
"isSingleSymbolToken",
"(",
"l",
",",
"ItemComma",
",",
"comma",
")",
";",
"state",
"!=",
"nil",
"{",
"return",
"state",
"\n",
"}",
"\n",
"if",
"state",
":=",
"isSingleSymbolToken",
"(",
"l",
",",
"ItemLT",
",",
"lt",
")",
";",
"state",
"!=",
"nil",
"{",
"return",
"state",
"\n",
"}",
"\n",
"if",
"state",
":=",
"isSingleSymbolToken",
"(",
"l",
",",
"ItemGT",
",",
"gt",
")",
";",
"state",
"!=",
"nil",
"{",
"return",
"state",
"\n",
"}",
"\n",
"if",
"state",
":=",
"isSingleSymbolToken",
"(",
"l",
",",
"ItemEQ",
",",
"eq",
")",
";",
"state",
"!=",
"nil",
"{",
"return",
"state",
"\n",
"}",
"\n",
"{",
"r",
":=",
"l",
".",
"next",
"(",
")",
"\n",
"if",
"unicode",
".",
"IsSpace",
"(",
"r",
")",
"{",
"l",
".",
"ignore",
"(",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"l",
".",
"next",
"(",
")",
"==",
"eof",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"l",
".",
"emit",
"(",
"ItemEOF",
")",
"// Useful to make EOF a token.",
"\n",
"return",
"nil",
"// Stop the run loop.",
"\n",
"}"
]
| // lexToken represents the initial state for token identification. | [
"lexToken",
"represents",
"the",
"initial",
"state",
"for",
"token",
"identification",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/lexer/lexer.go#L370-L433 |
12,596 | google/badwolf | bql/lexer/lexer.go | isSingleSymbolToken | func isSingleSymbolToken(l *lexer, tt TokenType, symbol rune) stateFn {
if r := l.peek(); r == symbol {
l.next()
l.emit(tt)
return lexSpace // Next state.
}
return nil
} | go | func isSingleSymbolToken(l *lexer, tt TokenType, symbol rune) stateFn {
if r := l.peek(); r == symbol {
l.next()
l.emit(tt)
return lexSpace // Next state.
}
return nil
} | [
"func",
"isSingleSymbolToken",
"(",
"l",
"*",
"lexer",
",",
"tt",
"TokenType",
",",
"symbol",
"rune",
")",
"stateFn",
"{",
"if",
"r",
":=",
"l",
".",
"peek",
"(",
")",
";",
"r",
"==",
"symbol",
"{",
"l",
".",
"next",
"(",
")",
"\n",
"l",
".",
"emit",
"(",
"tt",
")",
"\n",
"return",
"lexSpace",
"// Next state.",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // isSingleSymbolToken checks if a single char should be lexed. | [
"isSingleSymbolToken",
"checks",
"if",
"a",
"single",
"char",
"should",
"be",
"lexed",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/lexer/lexer.go#L436-L443 |
12,597 | google/badwolf | bql/lexer/lexer.go | lexBinding | func lexBinding(l *lexer) stateFn {
for {
if r := l.next(); !unicode.IsLetter(r) && !unicode.IsDigit(r) && r != rune('_') || r == eof {
l.backup()
l.emit(ItemBinding)
break
}
}
return lexSpace
} | go | func lexBinding(l *lexer) stateFn {
for {
if r := l.next(); !unicode.IsLetter(r) && !unicode.IsDigit(r) && r != rune('_') || r == eof {
l.backup()
l.emit(ItemBinding)
break
}
}
return lexSpace
} | [
"func",
"lexBinding",
"(",
"l",
"*",
"lexer",
")",
"stateFn",
"{",
"for",
"{",
"if",
"r",
":=",
"l",
".",
"next",
"(",
")",
";",
"!",
"unicode",
".",
"IsLetter",
"(",
"r",
")",
"&&",
"!",
"unicode",
".",
"IsDigit",
"(",
"r",
")",
"&&",
"r",
"!=",
"rune",
"(",
"'_'",
")",
"||",
"r",
"==",
"eof",
"{",
"l",
".",
"backup",
"(",
")",
"\n",
"l",
".",
"emit",
"(",
"ItemBinding",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"lexSpace",
"\n",
"}"
]
| // lexBinding lexes a binding variable. | [
"lexBinding",
"lexes",
"a",
"binding",
"variable",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/lexer/lexer.go#L446-L455 |
12,598 | google/badwolf | bql/lexer/lexer.go | lexSpace | func lexSpace(l *lexer) stateFn {
for {
if r := l.next(); !unicode.IsSpace(r) || r == eof {
break
}
}
l.backup()
l.ignore()
return lexToken
} | go | func lexSpace(l *lexer) stateFn {
for {
if r := l.next(); !unicode.IsSpace(r) || r == eof {
break
}
}
l.backup()
l.ignore()
return lexToken
} | [
"func",
"lexSpace",
"(",
"l",
"*",
"lexer",
")",
"stateFn",
"{",
"for",
"{",
"if",
"r",
":=",
"l",
".",
"next",
"(",
")",
";",
"!",
"unicode",
".",
"IsSpace",
"(",
"r",
")",
"||",
"r",
"==",
"eof",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"l",
".",
"backup",
"(",
")",
"\n",
"l",
".",
"ignore",
"(",
")",
"\n",
"return",
"lexToken",
"\n",
"}"
]
| // lexSpace consumes spaces without emitting any token. | [
"lexSpace",
"consumes",
"spaces",
"without",
"emitting",
"any",
"token",
"."
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/lexer/lexer.go#L458-L467 |
12,599 | google/badwolf | bql/lexer/lexer.go | lexBlankNode | func lexBlankNode(l *lexer) stateFn {
if r := l.next(); r != colon {
l.emitError("blank node should start with _:")
return nil
}
if r := l.next(); !unicode.IsLetter(r) {
l.emitError("blank node label should begin with a letter")
return nil
}
for {
if r := l.next(); !unicode.IsLetter(r) && !unicode.IsDigit(r) && r != rune('_') || r == eof {
l.backup()
l.emit(ItemBlankNode)
break
}
}
return lexSpace
} | go | func lexBlankNode(l *lexer) stateFn {
if r := l.next(); r != colon {
l.emitError("blank node should start with _:")
return nil
}
if r := l.next(); !unicode.IsLetter(r) {
l.emitError("blank node label should begin with a letter")
return nil
}
for {
if r := l.next(); !unicode.IsLetter(r) && !unicode.IsDigit(r) && r != rune('_') || r == eof {
l.backup()
l.emit(ItemBlankNode)
break
}
}
return lexSpace
} | [
"func",
"lexBlankNode",
"(",
"l",
"*",
"lexer",
")",
"stateFn",
"{",
"if",
"r",
":=",
"l",
".",
"next",
"(",
")",
";",
"r",
"!=",
"colon",
"{",
"l",
".",
"emitError",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"r",
":=",
"l",
".",
"next",
"(",
")",
";",
"!",
"unicode",
".",
"IsLetter",
"(",
"r",
")",
"{",
"l",
".",
"emitError",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"{",
"if",
"r",
":=",
"l",
".",
"next",
"(",
")",
";",
"!",
"unicode",
".",
"IsLetter",
"(",
"r",
")",
"&&",
"!",
"unicode",
".",
"IsDigit",
"(",
"r",
")",
"&&",
"r",
"!=",
"rune",
"(",
"'_'",
")",
"||",
"r",
"==",
"eof",
"{",
"l",
".",
"backup",
"(",
")",
"\n",
"l",
".",
"emit",
"(",
"ItemBlankNode",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"lexSpace",
"\n",
"}"
]
| // lexBlankNode tries to lex a blank node out of the input | [
"lexBlankNode",
"tries",
"to",
"lex",
"a",
"blank",
"node",
"out",
"of",
"the",
"input"
]
| f6c3103546450641440a719b2ed52cc74bae6237 | https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/lexer/lexer.go#L656-L673 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.