IModelConfigurer.
To find out more read:
- How to configure the database
- How to configure cubes
- How to convert in-memory tables to external tables
How to build a DirectQuery application with the Atoti Configuration API
Step 1: Add the dependencies
api-application holds Application, IDirectQueryConfigurator and the Spring configuration the
starter imports. It is optional in the Atoti Server Spring Boot starter, so it must be declared
explicitly. Add it and the connector artifact of the target database to
api-clickhouse. That artifact provides the ClickhouseConnectorFactory used in
Step 2:
api-application pulls in api-database, which holds DirectQueryConnector and the rest of the
DirectQuery database API.
Step 2: Configure the connector
Expose the DirectQuery connector as a Spring bean of typeDirectQueryConnector. The following
example connects to ClickHouse. Use the connector factory and the settings of the target database:
Step 3: Configure the database and the cubes
Provide anIModelConfigurer bean. The cubes are declared exactly as in an in-memory application,
described in how to configure cubes. The rest of this step covers the database.
How to configure the composite database
TheIDatabaseConfigurator passed to configureDatabase configures the composite database as a
whole. Both sides are visible to every method below, including a table that configureDatabase
already converted from an in-memory table to an external table with
convertToExternalTables. A converted external table can be
configured further.
getCurrentSchema()returns the schema of the composite database. It covers in-memory tables and joins, plus the external tables and joins declared so far.addTable(IStoreDescription)andaddJoin(IReferenceDescription)configure the in-memory side. Their parameter types make the side unambiguous. See configure the database for the complete list of in-memory methods.table(String)retrieves a table, whichever side it is on. It returns anITableConfigurator, which cannot state an external column. Retrieve the same table withIDirectQueryConfigurator.table(String)to reach anIDirectQueryTableConfigurator, described in the list that follows the external-side methods.
IDirectQueryConfigurator.from(IDatabaseConfigurator):
addTable(ATableDescription)declares an external table. Get its description from the connector’s discoverer, build it manually, or back it by a SQL expression.table(String)retrieves a previously declared or converted external table, to configure it further.addJoin(JoinDescription)adds a join between two external tables.addAggregateTable(AggregateTableDescription)declares an aggregate table of an external table declared or converted earlier. See how to set the options of the external database.
addTable or converted by
convertToExternalTables is reached
with table(String), which returns an IDirectQueryTableConfigurator. That object configures a
single external table:
withExternalColumncorrects the external column backing one field.addFieldadds a new field, backed by an external column.withMultiColumnVectorstates that an existing field is a vector the external table spreads over several columns. It takes the external columns forming the vector, in vector-index order.withMultiRowVectorstates that existing fields are vectors spread over the rows sharing a key. It takes the external column holding the vector index.withClusteringFieldssets the clustering fields of the table.withTimeTravelsets the emulated time-travel information of the table.
withClusteringFields, withTimeTravel, withExternalColumn and addField apply to any external
table, declared or converted. On a declared table the four are generally unnecessary. The
ATableDescription already names the external column. It can also carry the clustering fields and
the time-travel information. The two vector operations apply only to a converted table. See
how to vectorize a converted table.
The following example declares an external Sales table, discovered from the connector, and an
in-memory Hobbies table:
How to set the options of the external database
IDirectQueryConfigurator also carries the options of the external database. They are options of
the whole database, so the last configurer to set one of them wins:
addAggregateTable(AggregateTableDescription)declares an aggregate table. Its base table must be an external table declared or converted earlier, and one aggregate table per underlying external table is accepted.withCache(CacheDescription)describes the local cache of the external database. A call replaces the description set by an earlier one.addUserDefinedSqlAggregationFunction(UserDefinedSqlAggregationFunction)adds the SQL counterpart of an aggregation function registered in memory under the same plugin key. Adding a function under the plugin key of an earlier one replaces it and logs a warning.withDatabaseSettings(IDatabaseSettings)sets the settings of the external database, which are those of its connector, such asClickhouseDatabaseSettingsfor ClickHouse. The settings are not checked against the connector: settings of another kind fail when the database is created.getDatabaseSettings()returns the settings the external database is created with: the settings set by an earlier call towithDatabaseSettings, or the defaults of the connector when none were set. Read them to adjust a single setting with thetoBuilder()method of the settings class.
Step 4: Wire the configuration
With the Atoti Server Spring Boot starter, there is nothing to import. An auto-configuration builds the application, provided:- A
DirectQueryConnectorbean is present. - An
IModelConfigurerbean is present. An Atoti Solution supplies its own database configuration instead. - The
api-applicationdependency of Step 1 is on the classpath.
Application bean is needed.
The auto-configuration exposes three Spring beans: the Application, the IActivePivotManager,
and the database as an IDirectQueryDatabase.
How DirectQuery behaves with the Atoti Configuration API
- The composite database does not support joins between an external table and an in-memory table. Model such relationships at the cube level instead, for example with a Many-to-Many relationship between dimensions.
- A table defined by a SQL expression does not support emulated time travel. Emulated time travel
needs a named external table, resolved from a
SqlTableId. - Every external table is checked when the application is built, whether it is backed by a named table or defined by a SQL expression. The table is discovered, and the build fails if it is missing, if the expression is invalid, or if it lacks a column the description reads.
Related pages
- Convert in-memory tables to external tables: conversion, its checks, and vectorization
- Configure cubes: dimensions, hierarchies, and measures
- Create measures: measure definitions and aggregations