msticpy.data.core.query_store module
QueryStore class - holds a collection of QuerySources.
- class msticpy.data.core.query_store.QueryStore(environment: str)
Bases:
object
Repository for query definitions for a data environment.
- environment
The data environment for the queries.
- Type:
str
- data_families
The set of data families and associated queries for each.
- Type:
Dict[str, Dict[str, QuerySource]]
Initialize a QueryStore for a new environment.
- Parameters:
environment (str) – The data environment
- add_data_source(source: QuerySource)
Add a datasource/query to the store.
- Parameters:
source (QuerySource) – The source to add. An existing item with the same name will be overwritten
- add_query(name: str, query: str, query_paths: str | List[str], description: str | None = None)
Add a query from name/query text.
- Parameters:
name (str) – name of the query
query (str) – The query string
query_paths (Union[str, List[str]]) – The path/data_family to categorize. Multiple paths can be specified. If the path is dotted, this will cause the query to be displayed in the corresponding hierarchy.
description (str, optional) – Query description
- apply_query_filter(query_filter: Callable[[QuerySource], bool])
Apply a filter to the query sources.
- Parameters:
query_filter (Callable[[bool], QuerySource]) – A function that takes a QuerySource and returns True if the query should be displayed.
- find_query(query_name: str) Set[QuerySource | None]
Return set of queries with name query_name.
- Parameters:
query_name (str) – Name of the query
- Returns:
Set (distinct) queries matching name.
- Return type:
Set[QuerySource]
- get_query(query_name: str, query_path: str | DataFamily | None = None) QuerySource
Return query with name data_family and query_name.
- Parameters:
query_name (str) – Name of the query
query_path (Union[str, DataFamily]) – The data family for the query
- Returns:
Query matching name and family.
- Return type:
- import_file(query_file: str)
Import a yaml data source definition.
- Parameters:
query_file (str) – Path to the file to import
- Raises:
ImportError – File read error or Syntax or semantic error found in the source file.
- classmethod import_files(source_path: list, recursive: bool = True, driver_query_filter: Dict[str, Set[str]] | None = None) Dict[str, QueryStore]
Import multiple query definition files from directory path.
- Parameters:
source_path (str) – The folder containing the yaml definition files.
recursive (bool, optional) – True to recurse sub-directories (the default is False, which only reads from the top level)
driver_query_filter (Dict[str, Set[str]]) – A dictionary of query metadata keys and values. This is used to test each read query to see if it is relevant to the driver and should be returned in the created QueryStore dictionary.
- Returns:
Dictionary of one or more environments and the QueryStore containing the queries for each environment.
- Return type:
Dict[str, ‘QueryStore’]
- Raises:
FileNotFoundError – File read error or Syntax or semantic error found in a source file.
- property query_names: Iterable[str]
Return list of family.query in the store.
- Returns:
List of queries
- Return type:
Iterable[str]
- property search_items: Dict[str, Dict[str, str]]
Return searchable metadata and query for all queries.