Skip to content

pql.py

PQL

A PQL query object can contain columns (Dimensions or KPIs in Celonis), filters, variables, limit and offset. It can be turned into a query that the engine accepts using the query property. Various objects can be added to it when it is initiated, by using the add method or by using the + operator. The object contains the following attributes that are accessible by the user:

Attributes:

Name Type Description
columns List[PQLColumn]

A dictionary of containing PQL columns with name as key.

filters List[PQLFilter]

A list of filters.

variables

A dictionary of variables with name as key.

limit

The LIMIT of the PQL query.

offset

The OFFSET of the PQL query.

Parameters:

Name Type Description Default
query

Initialize query to itself. Uses add.

required
limit int

The LIMIT value that is passed to the engine, NOLIMIT if the value of limit is < 1.

-1
offset int

The OFFSET value that is passed to the engine, left out if the value of offset is < 1.

0

query: List property readonly

Get the PQL query list in Celonis engine format, containing a TABLE statement and optional filters.

add(self, obj)

Tries to add the given object to the PQL query.

Parameters:

Name Type Description Default
obj Union[PQL, PQLColumn, PQLFilter, Dict, Iterable]
  • If PQLColumn, upserts the column based on name.
  • If PQLFilter, adds to filters, if exact filter string already exists does nothing.
  • If dict, checks whether dict looks like Celonis variable and if so upserts the new variable on name. If the variable is a static value the result should already be calculated before adding it.
  • If PQL, does the above for all columns, filters and variables.
  • If abc.Iterable (e.g. list), does the above for each object in the abc.Iterable.
required

Exceptions:

Type Description
PyCelonisTypeError

If type of obj is not supported.

PQLColumn

A PQL Column dictionary that can be added to a PQL query statement. Behaves like dict. Corresponds to Dimension and KPI in Celonis.

Parameters:

Name Type Description Default
query str

The PQL query of the column (KPI or Dimension).

None
name str

The name of te column.

'Unnamed column'
sorting_index Union[str, int]

The sorting index of the column in a table (starts at 0).

None
sorting_direction str

The sorting direction. One of [ASC, DESC].

None

PQLFilter (UserString)

A PQL filter that can be added to a PQL query statement. Behaves like string.

Parameters:

Name Type Description Default
query str

The PQL query of the filter.

required

PQLDebugger

A PQL Debugger to check for query errors.

debug(query, dm) staticmethod

Debugs the PQL query columns and filters one by one to find errors.

Parameters:

Name Type Description Default
query Union[celonis_api.pql.pql.PQLColumn, celonis_api.pql.pql.PQLFilter, celonis_api.pql.pql.PQL, List]

The PQL query to be debugged.

required
dm Datamodel

The Datamodel on which the query will be executed.

required

Returns:

Type Description
List[str]

A List of Errors.