Many roads lead to Rome, but some are faster than others!
If you already have some coding experience - not necessarily with PQL but any other language - you might have run into situations where you couldn’t easily decide how to proceed.
Which function to favor or how to design your code a bit leaner, cleaner and faster in terms of computation times?
Here are some best practices we recommend when working with the functions and operators introduced throughout this course.
Aggregations and Execution Times
Our aggregation operators such as COUNT, MAX, SUM and AVG differ in terms of the timely amount that they require when performed.
You can think of these execution times as a sort of cost label that each function is associated with:
What does this imply for your daily work with Celonis PQL?
We identified some major recommendations for you:
If you have the choice between AVG and MEDIAN, choose AVG due to a better performance, i.e. less time and cost. However, if your dataset is highly skewed, it might often be more reasonable to use the median to drive meaningful conclusions. If you can choose between COUNT and COUNT DISTINCT, choose COUNT. Oftentimes, people use COUNT DISTINCT “just to make sure”, but you should always reflect if there are actually duplicate values in your data. If not, you can safely use COUNT. You might be indifferent whether to use SUM or COUNT in combination with a CASE WHEN statement: SUM (CASE WHEN column = 'A' THEN 1 ELSE 0)
COUNT (CASE WHEN column = 'A' THEN 1 ELSE NULL) *
Note that both statements return exactly the same result.
However, by looking at the table above, choose COUNT to take advantage of the faster computation.
Note that NULL should be returned here if the condition is not fulfilled. 0 would lead to COUNT including this value in its calculations.
CASE WHEN vs. REMAP_VALUES
You might have come across the thought that you could also use a CASE WHEN statement instead when we’ve introduced the REMAP_VALUES function.
Our best practices advice to you: DON’T!
REMAP_VALUES has been built exactly for its purpose and outperforms the CASE WHEN alternative by far. Not only the computation time is less when using REMAP_VALUES but also the syntax is more compact as you can see below:
Hence, as a best practice, we recommend using the REMAP functions whenever possible.
= vs. LIKE
One very last tip:
Whenever you know the exact pattern you're looking for, always use the "=" operator rather than LIKE. It will save you quite some computation time.
By the way...
Improving data load on our data centers not only increases the speed of your calculations, it's also making a difference when it comes to sustainability.
For every byte that you reduce, the load results in less CO2 emission equivalents of the data centers.
So next time you reflect on PQL performance, remember that your decision also has an environmental impact.
If you can use all the functions and operators introduced throughout this course and even pay attention to the best practices we’ve proposed simultaneously, you’re on the best way to become a true PQL Master!