Queries¶
Queries search for elements in an object. They can also search for elements in multiple objects, in which case each object will be treated as a column of data, and matching rows are returned.
A query consists of one or more clauses where one object’s data is compared, combined with AND (&) or OR (|)
For example, with 2 objects with these contents:
a |
b |
|---|---|
1 |
2 |
3 |
3 |
5 |
8 |
7 |
0 |
The query a.data > 3 | b.data > 4 would return:
a |
b |
|---|---|
5 |
8 |
7 |
0 |
Queries can also be restricted to a specific region.
Here is a full program that performs the previous query:
1import pdc
2import numpy as np
3
4with pdc.ServerContext():
5 pdc.init()
6 cont = pdc.Container('test')
7 a = cont.object_from_array('a', [1, 3, 5, 7])
8 b = cont.object_from_array('b', [2, 3, 8, 0])
9
10 query = (a.data > 3) | (b.data > 4)
11 result = query.get_result()
12 a_data = result[a] #5 7
13 b_data = result[b] #8 0
- class pdc.Query(id: uint64, op, left=None, right=None)¶
- class Result(id: pdcid, query: Query)¶
Result of a DataQuery
To get results from this class, index it using objects as keys For example:
query.get_result()[object1]- property hits¶
Number of hits in the result. If you only want the number of hits, use
query.get_num_hits()
- get_num_hits(region: Region = None) int¶
Get number of hits for this query (i.e. number of elements that match this query)
- Parameters:
region (Region) – The region to query over. If this is None, the entire object is queried.
- Returns:
number of hits