-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Make
topLevelNode
explainable (#737)
- Resolves #736 - Description: makes `topLevelNode` explainable without changing the `Source()` function to fetch child graphs. #626 will be done in a separate PR once `topLevelNode.Source()` is updated.
- Loading branch information
1 parent
e00ca5a
commit e18c872
Showing
4 changed files
with
319 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
tests/integration/query/explain/top_with_average_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package test_explain | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestExplainTopLevelAverageQuery(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "Explain top-level average query.", | ||
|
||
Query: `query @explain { | ||
_avg( | ||
author: { | ||
field: age | ||
} | ||
) | ||
}`, | ||
|
||
Docs: map[int][]string{ | ||
//authors | ||
2: { | ||
`{ | ||
"name": "John", | ||
"verified": false, | ||
"age": 28 | ||
}`, | ||
`{ | ||
"name": "Bob", | ||
"verified": true, | ||
"age": 30 | ||
}`, | ||
}, | ||
}, | ||
|
||
Results: []dataMap{ | ||
{ | ||
"explain": dataMap{ | ||
"topLevelNode": dataMap{}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} | ||
|
||
func TestExplainTopLevelAverageQueryWithFilter(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "Explain top-level average query with filter.", | ||
Query: `query @explain { | ||
_avg( | ||
author: { | ||
field: age, | ||
filter: { | ||
age: { | ||
_gt: 26 | ||
} | ||
} | ||
} | ||
) | ||
}`, | ||
|
||
Docs: map[int][]string{ | ||
//authors | ||
2: { | ||
`{ | ||
"name": "John", | ||
"verified": false, | ||
"age": 21 | ||
}`, | ||
`{ | ||
"name": "Bob", | ||
"verified": false, | ||
"age": 30 | ||
}`, | ||
`{ | ||
"name": "Alice", | ||
"verified": false, | ||
"age": 32 | ||
}`, | ||
}, | ||
}, | ||
|
||
Results: []dataMap{ | ||
{ | ||
"explain": dataMap{ | ||
"topLevelNode": dataMap{}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package test_explain | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestExplainTopLevelCountQuery(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "Explain top-level count query.", | ||
|
||
Query: `query @explain { | ||
_count(author: {}) | ||
}`, | ||
|
||
Docs: map[int][]string{ | ||
//authors | ||
2: { | ||
`{ | ||
"name": "John", | ||
"verified": true, | ||
"age": 21 | ||
}`, | ||
`{ | ||
"name": "Bob", | ||
"verified": false, | ||
"age": 30 | ||
}`, | ||
}, | ||
}, | ||
|
||
Results: []dataMap{ | ||
{ | ||
"explain": dataMap{ | ||
"topLevelNode": dataMap{}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} | ||
|
||
func TestExplainTopLevelCountQueryWithFilter(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "Explain top-level count query with filter.", | ||
|
||
Query: `query @explain { | ||
_count( | ||
author: { | ||
filter: { | ||
age: { | ||
_gt: 26 | ||
} | ||
} | ||
} | ||
) | ||
}`, | ||
|
||
Docs: map[int][]string{ | ||
//authors | ||
2: { | ||
`{ | ||
"name": "John", | ||
"verified": false, | ||
"age": 21 | ||
}`, | ||
`{ | ||
"name": "Bob", | ||
"verified": false, | ||
"age": 30 | ||
}`, | ||
`{ | ||
"name": "Alice", | ||
"verified": true, | ||
"age": 32 | ||
}`, | ||
}, | ||
}, | ||
|
||
Results: []dataMap{ | ||
{ | ||
"explain": dataMap{ | ||
"topLevelNode": dataMap{}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package test_explain | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestExplainTopLevelSumQuery(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "Explain top-level sum query.", | ||
|
||
Query: `query @explain { | ||
_sum( | ||
author: { | ||
field: age | ||
} | ||
) | ||
}`, | ||
|
||
Docs: map[int][]string{ | ||
//authors | ||
2: { | ||
`{ | ||
"name": "John", | ||
"verified": true, | ||
"age": 21 | ||
}`, | ||
`{ | ||
"name": "Bob", | ||
"verified": true, | ||
"age": 30 | ||
}`, | ||
}, | ||
}, | ||
|
||
Results: []dataMap{ | ||
{ | ||
"explain": dataMap{ | ||
"topLevelNode": dataMap{}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} | ||
|
||
func TestExplainTopLevelSumQueryWithFilter(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "Explain top-level sum query with filter.", | ||
|
||
Query: `query @explain { | ||
_sum( | ||
author: { | ||
field: age, | ||
filter: { | ||
age: { | ||
_gt: 26 | ||
} | ||
} | ||
} | ||
) | ||
}`, | ||
|
||
Docs: map[int][]string{ | ||
//authors | ||
2: { | ||
`{ | ||
"name": "John", | ||
"verified": false, | ||
"age": 21 | ||
}`, | ||
`{ | ||
"name": "Bob", | ||
"verified": false, | ||
"age": 30 | ||
}`, | ||
`{ | ||
"name": "Alice", | ||
"verified": true, | ||
"age": 32 | ||
}`, | ||
}, | ||
}, | ||
|
||
Results: []dataMap{ | ||
{ | ||
"explain": dataMap{ | ||
"topLevelNode": dataMap{}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} |