| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
|
|
| from pprint import pprint |
|
|
| import numpy as np |
|
|
| import tiledb |
|
|
| uri = "query_condition_dense" |
|
|
|
|
| def create_array(path): |
| |
| dom = tiledb.Domain( |
| tiledb.Dim(name="coords", domain=(1, 10), tile=1, dtype=np.uint32) |
| ) |
| attrs = [ |
| tiledb.Attr(name="attr1", dtype=np.uint64), |
| tiledb.Attr(name="attr2", dtype=np.float64), |
| ] |
| schema = tiledb.ArraySchema(domain=dom, attrs=attrs, sparse=False) |
| tiledb.Array.create(path, schema, overwrite=True) |
|
|
| |
| with tiledb.open(path, "w") as arr: |
| rand = np.random.default_rng() |
| arr[:] = { |
| "attr1": rand.integers(low=0, high=10, size=10), |
| "attr2": rand.random(size=10), |
| } |
|
|
|
|
| def read_array(path): |
| with tiledb.open(uri) as arr: |
| print("--- without query condition:") |
| print() |
| pprint(arr[:]) |
| print() |
|
|
| with tiledb.open(uri) as arr: |
| qc = "(2 < attr1 < 6) and (attr2 < 0.5 or attr2 > 0.85)" |
| print(f"--- with query condition {qc}:") |
|
|
| print(f"--- the fill value for attr1 is {arr.attr('attr1').fill}") |
| print(f"--- the fill value for attr2 is {arr.attr('attr2').fill}") |
|
|
| print() |
| res = arr.query(cond=qc)[:] |
| pprint(res) |
|
|
|
|
| if __name__ == "__main__": |
| """Example output for `python query_condition_dense.py`: |
| |
| --- without query condition: |
| |
| OrderedDict([('attr1', array([4, 0, 9, 7, 6, 0, 0, 5, 7, 5], dtype=uint64)), |
| ('attr2', |
| array([0.74476144, 0.47211544, 0.99054245, 0.36640416, 0.91699594, |
| 0.06216043, 0.58581863, 0.00505695, 0.7486192 , 0.87649422]))]) |
| |
| --- with query condition (2 < attr1 < 6) and (attr2 < 0.5 or attr2 > 0.85): |
| --- the fill value for attr1 is [18446744073709551615] |
| --- the fill value for attr2 is [nan] |
| |
| OrderedDict([('attr1', |
| array([18446744073709551615, 18446744073709551615, 18446744073709551615, |
| 18446744073709551615, 18446744073709551615, 18446744073709551615, |
| 18446744073709551615, 5, 18446744073709551615, |
| 5], dtype=uint64)), |
| ('attr2', |
| array([ nan, nan, nan, nan, nan, |
| nan, nan, 0.00505695, nan, 0.87649422]))]) |
| """ |
| create_array(uri) |
| read_array(uri) |
|
|