JAQuel Query Examples - Interactive Execution¶
This notebook demonstrates how to execute JAQuel queries using the odsbox library. Each query from the test files is executed using con_i.query().
Note: You need to configure the connection parameters (URL, auth) for your ODS server.
[ ]:
from odsbox import ConI
con_i = ConI(url="SERVERURL", auth=("USER", "PASSWORD"))
Access Instances¶
Basic access¶
Do access only few attributes¶
[ ]:
# Do access only few attributes
con_i.query({"Unit": {}, "$attributes": {"name": 1, "factor": 1, "offset": 1}})
Lets query for units with base entity name¶
[ ]:
# Lets query for units with base entity name
con_i.query({"AoUnit": {}})
Lets query for units with entity name¶
[ ]:
# Lets query for units with entity name
con_i.query({"Unit": {}})
Retrieve all attributes using asterisk¶
[ ]:
# Retrieve all attributes using asterisk
con_i.query({"Unit": {}, "$attributes": {"name": 1, "factor": 1, "offset": 1, "phys_dimension.*": 1}})
Simplify attribute definition¶
[ ]:
# Simplify attribute definition
con_i.query(
{
"Unit": {},
"$attributes": {
"name": 1,
"factor": 1,
"offset": 1,
"phys_dimension": {"name": 1, "length_exp": 1, "mass_exp": 1},
},
}
)
Order results by an attribute¶
Order results by name¶
[ ]:
# Order results by name
con_i.query({"AoUnit": {}, "$attributes": {"id": 1, "name": 1}, "$orderby": {"name": 1}})
Limit the amounts of results¶
Retrieve only 5 result rows¶
[ ]:
# Retrieve only 5 result rows
con_i.query({"AoUnit": {}, "$options": {"$rowlimit": 5}})
Query Instance by id¶
Query the unit with the id 3¶
[ ]:
# Query the unit with the id 3
con_i.query({"AoUnit": {"id": 3}})
Query the unit with the id 3 full¶
[ ]:
# Query the unit with the id 3 full
con_i.query({"AoUnit": {"id": {"$eq": 3}}})
Query the unit with the id 3 simplified¶
[ ]:
# Query the unit with the id 3 simplified
con_i.query({"AoUnit": 3})
Query the units with the ids in 1 , 2 and 3¶
[ ]:
# Query the units with the ids in 1 , 2 and 3
con_i.query({"AoUnit": {"id": {"$in": [1, 2, 3]}}})
Query Instance by name¶
Query the unit with the name equal s¶
[ ]:
# Query the unit with the name equal s
con_i.query({"AoUnit": {"name": "s"}})
Query the unit with the name equal s case insensitive¶
[ ]:
# Query the unit with the name equal s case insensitive
con_i.query({"AoUnit": {"name": "s", "$options": "i"}})
Query the unit with the name equal s case insensitive full¶
[ ]:
# Query the unit with the name equal s case insensitive full
con_i.query({"AoUnit": {"name": {"$eq": "s"}, "$options": "i"}})
Query the unit with the name like k¶
[ ]:
# Query the unit with the name like k
con_i.query({"AoUnit": {"name": {"$like": "k*"}}})
Query the unit with the name like k case insensitive¶
[ ]:
# Query the unit with the name like k case insensitive
con_i.query({"AoUnit": {"name": {"$like": "k*"}, "$options": "i"}})
And conjunctions $and and $or¶
Search speed based Units¶
[ ]:
# Search speed based Units
con_i.query(
{
"AoUnit": {
"phys_dimension": {
"length_exp": 1,
"mass_exp": 0,
"time_exp": -1,
"current_exp": 0,
"temperature_exp": 0,
"molar_amount_exp": 0,
"luminous_intensity_exp": 0,
}
},
"$attributes": {"name": 1, "factor": 1, "offset": 1, "phys_dimension.name": 1},
}
)
Search speed based Units with explicit $and conjunction¶
[ ]:
# Search speed based Units with explicit $and conjunction
con_i.query(
{
"AoUnit": {
"phys_dimension": {
"$and": [
{"length_exp": 1},
{"mass_exp": 0},
{"time_exp": -1},
{"current_exp": 0},
{"temperature_exp": 0},
{"molar_amount_exp": 0},
{"luminous_intensity_exp": 0},
]
}
},
"$attributes": {"name": 1, "factor": 1, "offset": 1, "phys_dimension.name": 1},
}
)
Search speed or time based Units¶
[ ]:
# Search speed or time based Units
con_i.query(
{
"AoUnit": {
"phys_dimension": {
"$or": [
{
"length_exp": 1,
"mass_exp": 0,
"time_exp": -1,
"current_exp": 0,
"temperature_exp": 0,
"molar_amount_exp": 0,
"luminous_intensity_exp": 0,
},
{
"length_exp": 0,
"mass_exp": 0,
"time_exp": 1,
"current_exp": 0,
"temperature_exp": 0,
"molar_amount_exp": 0,
"luminous_intensity_exp": 0,
},
]
}
},
"$attributes": {"name": 1, "factor": 1, "offset": 1, "phys_dimension.name": 1},
}
)
Search time based Units¶
[ ]:
# Search time based Units
con_i.query(
{
"AoUnit": {
"phys_dimension": {
"length_exp": 0,
"mass_exp": 0,
"time_exp": 1,
"current_exp": 0,
"temperature_exp": 0,
"molar_amount_exp": 0,
"luminous_intensity_exp": 0,
}
}
}
)
Use $between operator¶
Get measurements that started in a time interval¶
[ ]:
# Get measurements that started in a time interval
con_i.query(
{
"AoMeasurement": {"measurement_begin": {"$between": ["2000-04-22T00:00:00.001Z", "2024-04-23T00:00:00.002Z"]}},
"$options": {"$rowlimit": 5},
}
)
Get measurements that started in a time interval, ODS time¶
[ ]:
# Get measurements that started in a time interval, ODS time
con_i.query(
{
"AoMeasurement": {"measurement_begin": {"$between": ["20001223000000", "20241224000000"]}},
"$options": {"$rowlimit": 5},
}
)
Use aggregates $min , $max , $dcount , and $distinct¶
Get the distincted count of Unit description¶
[ ]:
# Get the distincted count of Unit description
con_i.query({"AoUnit": {}, "$attributes": {"description": {"$dcount": 1}}})
Get the distincted values of Unit description¶
[ ]:
# Get the distincted values of Unit description
con_i.query({"AoUnit": {}, "$attributes": {"description": {"$distinct": 1}}})
Get the min and max of unit factor¶
[ ]:
# Get the min and max of unit factor
con_i.query({"AoUnit": {}, "$attributes": {"factor": {"$max": 1, "$min": 1}}})
Get the min and max of unit factor and offset¶
[ ]:
# Get the min and max of unit factor and offset
con_i.query({"AoUnit": {}, "$attributes": {"factor": {"$max": 1, "$min": 1}, "offset": {"$max": 1, "$min": 1}}})
Inner and outer joins¶
Use inner join¶
[ ]:
# Use inner join
con_i.query(
{
"AoMeasurementQuantity": {},
"$attributes": {"name": 1, "unit.name": 1, "quantity.name": 1},
"$options": {"$rowlimit": 5},
}
)
Use outer join¶
[ ]:
# Use outer join
con_i.query(
{
"AoMeasurementQuantity": {},
"$attributes": {"name": 1, "unit:OUTER.name": 1, "quantity:OUTER.name": 1},
"$options": {"$rowlimit": 5},
}
)
Use $groupby¶
Use a $groupby on two attributes¶
[ ]:
# Use a $groupby on two attributes
con_i.query(
{
"AoMeasurement": {},
"$attributes": {"name": 1, "description": 1},
"$orderby": {"name": 1},
"$groupby": {"name": 1, "description": 1},
}
)
Access OpenMDM content¶
Access hierarchy elements¶
Get AoTest instances¶
[ ]:
# Get AoTest instances
con_i.query({"AoTest": {}, "$options": {"$rowlimit": 5}})
Get MeaQuantity instances¶
[ ]:
# Get MeaQuantity instances
con_i.query({"MeaResult": {}, "$options": {"$rowlimit": 5}})
Get MeaResult instances¶
[ ]:
# Get MeaResult instances
con_i.query({"MeaResult": {}, "$options": {"$rowlimit": 5}})
Get Project instances¶
[ ]:
# Get Project instances
con_i.query({"Project": {}, "$options": {"$rowlimit": 5}})
Get StructureLevel instances¶
[ ]:
# Get StructureLevel instances
con_i.query({"StructureLevel": {}, "$options": {"$rowlimit": 5}})
Get Test instances¶
[ ]:
# Get Test instances
con_i.query({"Test": {}, "$options": {"$rowlimit": 5}})
Get TestStep instances¶
[ ]:
# Get TestStep instances
con_i.query({"TestStep": {}, "$options": {"$rowlimit": 5}})
Browse ODS tree¶
Get MeaResult from TestStep with id equal 4¶
[ ]:
# Get MeaResult from TestStep with id equal 4
con_i.query({"TestStep": 4, "$attributes": {"children": {"name": 1, "id": 1}}, "$options": {"$rowlimit": 5}})
Get MeaResult with test with id equal 4¶
[ ]:
# Get MeaResult with test with id equal 4
con_i.query({"MeaResult": {"test": 4}, "$attributes": {"name": 1, "id": 1}, "$options": {"$rowlimit": 5}})
Get StructureLevel from Project with id equal 3¶
[ ]:
# Get StructureLevel from Project with id equal 3
con_i.query({"Project": 3, "$attributes": {"children": {"name": 1, "id": 1}}, "$options": {"$rowlimit": 5}})
Get StructureLevel with parent_test with id equal 3¶
[ ]:
# Get StructureLevel with parent_test with id equal 3
con_i.query({"StructureLevel": {"parent_test": 3}, "$attributes": {"name": 1, "id": 1}, "$options": {"$rowlimit": 5}})
Access descriptive meta¶
Access parameter sets¶
Get name value pairs attached to MeaResult¶
[ ]:
# Get name value pairs attached to MeaResult
con_i.query(
{
"ResultParameter": {"parameter_set.MeaResult.Name": {"$like": "APS*"}},
"$attributes": {"Name": 1, "Value": 1, "DataType": 1, "parameter_set": {"name": 1, "MeaResult.id": 1}},
"$options": {"$rowlimit": 20},
}
)
Access Bulk¶
Read data from Measurement¶
Get AoMeasurementQuantity from AoMeasurement with id equal 153¶
[ ]:
# Get AoMeasurementQuantity from AoMeasurement with id equal 153
con_i.query(
{
"AoMeasurement": 153,
"$attributes": {"measurement_quantities": {"name": 1, "id": 1}},
"$options": {"$rowlimit": 5},
}
)
Get AoMeasurementQuantity with measurement with id equal 153¶
[ ]:
# Get AoMeasurementQuantity with measurement with id equal 153
con_i.query(
{"AoMeasurementQuantity": {"measurement": 153}, "$attributes": {"name": 1, "id": 1}, "$options": {"$rowlimit": 5}}
)
Get AoSubmatrix with measurement with id equal 153¶
[ ]:
# Get AoSubmatrix with measurement with id equal 153
con_i.query(
{
"AoSubmatrix": {"measurement": 153},
"$attributes": {"name": 1, "id": 1, "number_of_rows": 1},
"$options": {"$rowlimit": 5},
}
)
Get bulk of AoLocalColumn with submatrix.measurement with id equal 153¶
[ ]:
# Get bulk of AoLocalColumn with submatrix.measurement with id equal 153
con_i.query(
{
"AoLocalColumn": {"submatrix.measurement": 153},
"$attributes": {"id": 1, "flags": 1, "generation_parameters": 1, "values": 1},
"$options": {"$rowlimit": 5},
}
)
Get meta of AoLocalColumn with submatrix.measurement with id equal 153¶
[ ]:
# Get meta of AoLocalColumn with submatrix.measurement with id equal 153
con_i.query(
{
"AoLocalColumn": {"submatrix.measurement": 153},
"$attributes": {"name": 1, "id": 1, "sequence_representation": 1, "independent": 1, "global_flag": 1},
"$options": {"$rowlimit": 5},
}
)
Cleanup¶
Don’t forget to logout when finished:
[ ]:
# Logout and cleanup
con_i.logout()
print("Logged out successfully.")