Skip to content

Commit c7c8d97

Browse files
committed
Improve documentation and fix warnings.
1 parent 2c4220d commit c7c8d97

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

internal/knowledge/query_and_or_expression.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func (aoe AndOrExpression) String() string {
3131
return "(empty)"
3232
}
3333

34+
// BuildAndOrExpression build a string representation of AndOrExpression.
3435
func BuildAndOrExpression(tree AndOrExpression) (string, error) {
3536
if tree.Expression != "" {
3637
return tree.Expression, nil
@@ -69,6 +70,7 @@ func BuildAndOrExpression(tree AndOrExpression) (string, error) {
6970
return "", nil
7071
}
7172

73+
// CrossProductExpressions computes the cross product of 2 sets of expressions. This is used to transform OR expressions into a union of AND expressions.
7274
func CrossProductExpressions(and1 []AndOrExpression, and2 []AndOrExpression) []AndOrExpression {
7375
outExpr := []AndOrExpression{}
7476
for i := range and1 {

internal/knowledge/query_and_or_expression_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,72 @@ func TestAndOrExpression(t *testing.T) {
1010
exprs := AndOrExpression{
1111
And: true,
1212
Children: []AndOrExpression{
13-
AndOrExpression{
13+
{
1414
And: false,
1515
Children: []AndOrExpression{
16-
AndOrExpression{
16+
{
1717
And: false,
1818
Expression: "a0.type = 'ip'",
1919
},
2020
},
2121
},
22-
AndOrExpression{
22+
{
2323
And: false,
2424
Children: []AndOrExpression{
25-
AndOrExpression{
25+
{
2626
And: false,
2727
Expression: "a0.type = 'device'",
2828
},
2929
},
3030
},
31-
AndOrExpression{
31+
{
3232
And: false,
3333
Children: []AndOrExpression{
34-
AndOrExpression{
34+
{
3535
And: false,
3636
Expression: "a0.type = 'metascan_task_id'",
3737
},
3838
},
3939
},
40-
AndOrExpression{
40+
{
4141
And: false,
4242
Children: []AndOrExpression{
43-
AndOrExpression{
43+
{
4444
And: false,
4545
Expression: "r0.type = 'observed'",
4646
},
4747
},
4848
},
49-
AndOrExpression{
49+
{
5050
And: true,
5151
Children: []AndOrExpression{
52-
AndOrExpression{
52+
{
5353
And: false,
5454
Expression: "r0.from_id = a1.id",
5555
},
56-
AndOrExpression{
56+
{
5757
And: false,
5858
Expression: "r0.to_id = a0.id",
5959
},
6060
},
6161
},
62-
AndOrExpression{
62+
{
6363
And: false,
6464
Children: []AndOrExpression{
65-
AndOrExpression{
65+
{
6666
And: false,
6767
Expression: "r1.type = 'scanned'",
6868
},
6969
},
7070
},
71-
AndOrExpression{
71+
{
7272
And: true,
7373
Children: []AndOrExpression{
74-
AndOrExpression{
74+
{
7575
And: false,
7676
Expression: "r1.from_id = a2.id",
7777
},
78-
AndOrExpression{
78+
{
7979
And: false,
8080
Expression: "r1.to_id = a0.id",
8181
},

internal/knowledge/query_sql_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ RETURN ip`,
232232
SELECT a0.id, a0.value, a0.type FROM assets a0, assets a1, assets a2, relations r0, relations r1
233233
WHERE ((((((a0.type = 'ip' AND a1.type = 'device') AND a2.type = 'task') AND r0.type = 'observed') AND (r0.from_id = a1.id AND r0.to_id = a0.id)) AND r1.type = 'scanned') AND (r1.from_id = a2.id AND r1.to_id = a0.id))
234234
`,
235+
Selected: true,
235236
},
236237
}
237238

0 commit comments

Comments
 (0)