SPL Reporting: Hot-Swapping and Microservitization

 

Background

Reports, as a critical basis for business decisions, are inherently unstable and often require adjustments and optimizations based on new requirements. Such frequent adjustments and optimizations require report systems to be highly flexible and responsive. In other words, report applications must be able to reflect the latest changes in real time without interrupting service – this is hot-swapping.

In theory, implementing report hot-swapping isn’t complex. The templates developed by most reporting tools are typically interpreted, naturally supporting hot-swapping. However, report development involves more than just designing report templates; it also includes preparing the data for reports. If SQL were used alone, that would not pose as an issue. However, due to the complexity of reporting business, transforming raw data into report-ready data often involves a highly complex processing workflow, which requires significant reliance on stored procedures or Java programs for data preparation. Yet, both of these methods require compilation before execution, making hot-swapping impossible, particularly with Java. Since most modern applications are developed in Java, reports are typically embedded within these applications. Given that reports are integral components of the system and the complexity of business logic, data preparation tasks inevitably fall to Java, making hot-swapping difficult to implement.

This fragmentation has led to an absurd phenomenon: while report templates can be updated in real time, the data preparation layer requires a ‘shut-down for maintenance’. The “dual highs” of report business—high complexity and high real-time responsiveness—have become a glaring contradiction.

SPL solution

As an open-source computation engine, esProc SPL features script interpretation and easy integration, making it well-suited to address the challenge of report hot-swapping.

Hot-swappable SPL scripts

One reason SPL can replace stored procedures and Java for report data preparation is that it has powerful computing capabilities while executing code interpretively.

As mentioned earlier, data preparation processes involving stored procedures and Java are often complex. SPL, with its comprehensive computing capabilities, simplifies these calculations, even replacing complex SQL in some cases.

More importantly, SPL code is interpreted, naturally supporting hot-swapping. Early reports were hard-coded in Java. Subsequently, report tools were developed, offering a tool-driven approach to data presentation. These report tools produce interpreted templates, enabling hot-swapping. Unfortunately, Java and similar technologies struggle with data preparation. Therefore, there’s a need to toolify this stage, and SPL can achieve this.
Let’s look at an example.

We want to find the order information of the top n customers (key customers) that account for half of the total annual sales. The script is named: customer.splx.

In the script, the parameter p_year is the year passed from the report. You need to set this parameter before writing the script:

Script:


A

1

=db.query(“select customer,amout from orders where year(order_date)=?”,p_year)

2

=A1.groups(customer;sum(amount):amount).sort(amount:-1)

3

=A2.sum(amount)/2

4

=0

5

=A2.pselect((A4=A4+amount,A4>=A3))

6

=A2.(customer).to(,A5)

7

=A1.select(A6.pos(A1.customer))

8

return A7

Now, due to a significant increase in sales last year, the definition of “key customers” has changed: customers accounting for the top 40% of sales are now considered key customers. This requires modifying the calculation method. Previously, this would involve changing code and restarting the application to take effect. Now, that’s no longer necessary. Simply change A3 to: =A2.sum(amount)*0.6. After the script is modified, the report takes effect in real time, achieving hot-swapping.

Integrating into applications

When integrated with report applications, hot-swapping alone isn’t enough; seamless integration with reports is also required. SPL, being developed in Java and offering a standard JDBC interface, provides seamless integration with Java-based reports. You only need to add the SPL JDBC jars into the report application.

Then, in the report dataset, you can call the SPL script like a stored procedure to get its calculation results. For example:

call customer(?)

Here, customer refers to the previously written script customer.splx, and the question mark is the parameter being passed.

Microservitization

With SPL’s hot-swapping, comprehensive computing capabilities, and seamless integration with Java, it not only improves the development efficiency of reports but paves the way for adopting a microservices architecture. By extracting report data preparation as a microservice, report updates and expansions can be managed more flexibly. SPL’s hot-swapping feature enables real-time responsiveness of report services to changing business requirements. Additionally, scale-out can be applied when performance demands arise, thereby boosting processing capacity. SPL’s independent computational capabilities free report services from being limited by database, enabling more efficient handling of high-concurrency tasks.