Job Types¶
JobTypes(perfdb)
¶
Class used for handling job types. Can be accessed via perfdb.jobs.types.
Parameters:
Source code in echo_postgres/perfdb_root.py
Python
def __init__(self, perfdb: e_pg.PerfDB) -> None:
"""Base class that all subclasses should inherit from.
Parameters
----------
perfdb : PerfDB
Top level object carrying all functionality and the connection handler.
"""
self._perfdb: e_pg.PerfDB = perfdb
get(output_type='dict')
¶
Gets all job types definitions with detailed information.
The most useful keys/columns returned are:
- id
- description
- parameters_schema
Parameters:
-
(output_type¶Literal['dict', 'DataFrame', 'pl.DataFrame'], default:'dict') –Output type of the data. Can be one of ["dict", "DataFrame", "pl.DataFrame"] By default "dict"
Returns:
-
dict[str, dict[str, Any]]–In case output_type is "dict", returns a dictionary in the format {name: {attribute: value, ...}, ...}
-
DataFrame–In case output_type is "DataFrame", returns a pandas DataFrame with the following format: index = name, columns = [attribute, ...]
-
DataFrame–In case output_type is "pl.DataFrame", returns a Polars DataFrame
Source code in echo_postgres/job_types.py
Python
@validate_call
def get(
self,
output_type: Literal["dict", "DataFrame", "pl.DataFrame"] = "dict",
) -> dict[str, dict[str, Any]] | pd.DataFrame | pl.DataFrame:
"""Gets all job types definitions with detailed information.
The most useful keys/columns returned are:
- id
- description
- parameters_schema
Parameters
----------
output_type : Literal["dict", "DataFrame", "pl.DataFrame"], optional
Output type of the data. Can be one of ["dict", "DataFrame", "pl.DataFrame"]
By default "dict"
Returns
-------
dict[str, dict[str, Any]]
In case output_type is "dict", returns a dictionary in the format {name: {attribute: value, ...}, ...}
pd.DataFrame
In case output_type is "DataFrame", returns a pandas DataFrame with the following format: index = name, columns = [attribute, ...]
pl.DataFrame
In case output_type is "pl.DataFrame", returns a Polars DataFrame
"""
query = sql.SQL("SELECT id, name, description, parameters_schema::TEXT, modified_date FROM performance.job_types ORDER BY name")
df = self._perfdb.conn.read_to_polars(query)
# converting parameters_schema from stringified JSON to pl.Object
df = cast_column_to_object(df, "parameters_schema")
return convert_output(df, output_type)
get_ids()
¶
Gets all job types and their respective ids.
Returns:
-
dict[str, int]–Dictionary with all job types and their respective ids in the format {name: id, ...}.
Source code in echo_postgres/job_types.py
Python
def get_ids(self) -> dict[str, int]:
"""Gets all job types and their respective ids.
Returns
-------
dict[str, int]
Dictionary with all job types and their respective ids in the format {name: id, ...}.
"""
query = sql.SQL("SELECT name, id FROM performance.job_types ORDER BY name")
df = self._perfdb.conn.read_to_polars(query)
return dict(zip(df["name"].to_list(), df["id"].to_list(), strict=False))