How to set up an XMLA interceptor in an Atoti application
In this guide, we set up an XMLA interceptor, rewriting a MDX Select query when queried on a specific measure.
We implement the following rewriting logic: TradeID
is a high-cardinality hierarchy. It must be filtered for measures heavy to compute. contributors.COUNT
plays the role of such a measure.
This part must be updated according to the hierarchies present in your project.
0. Prerequisites
This guide assumes that the project is using Maven and Spring Boot and is already depending on the Atoti Server Starter.
1. Define the interceptor
An XMLA interceptor is defined by implementing the interface com.activeviam.activepivot.xmla.intf.api.IXmlaInterceptor
.
public class MyXmlaInterceptor implements IXmlaInterceptor {
@Nullable
@Override
public RewrittenQuery rewriteSelect(
final String mdx, final Collection<IContextValue> contextValues) {
if (!mdx.contains("WHERE")
&& mdx.contains("[Measures].[contributors.COUNT]")
&& !mdx.contains("[TradeID].[TradeID]")) {
return RewrittenQuery.builder()
.mdx(mdx + " WHERE ([TradeID].[TradeID].[ALL].[AllMember].FirstChild)")
.build();
} else {
return null;
}
}
}
In the code above, we inspect the MDX query to be executed. If the query contains the measure contributors.COUNT
and no filter on TradeID
, using a WHERE clause, not changing the shape of the MDX result.
2. Add the interceptor to the application
The interceptor integrates into the application by returning it as a bean, in a configuration class loaded by the application.
@Configuration
class ExtraConfig {
@Bean
public MyXmlaInterceptor xmlaInterceptor() {
return new MyXmlaInterceptor();
}
}
3. See the interceptor in action
Connecting your application to Excel - described here - you can see your queries being filtered on a single value trade value whenever the hierarchy TradeID
is not expressed.
Going further
See this section to deep dive into the capabilities of the interceptor.