addTable(IStoreDescription) and joins, as for any
in-memory table. The converted table ends up backed by the external database instead of the
datastore. The declaration survives the conversion. See
when conversion is the right tool below.
Prerequisites
- A DirectQuery application built with the Atoti Configuration API, wired as described in how to use the Atoti Configuration API with DirectQuery.
- Each converted table has an external table backing it: either a named table in the external database, in the catalog and schema the conversion names, or a SQL expression the external database can run.
- Familiarity with the in-memory declarations described in how to configure the database.
How does the conversion work?
Convert withIDirectQueryConfigurator.from(database).convertToExternalTables(Map.of(tableName, externalTable, ...)).
database is the IDatabaseConfigurator received in IModelConfigurer.configureDatabase. Each
entry maps the local name of an in-memory table to the ExternalTable backing it. Build that
ExternalTable from a table id with ExternalTable.fromTableId(tableId), or from a SQL expression
with ExternalTable.fromSqlExpression(sql).
The conversion is eager. It discovers, converts and re-declares the named tables immediately.
From that point in the database-configuration phase onward, the converted tables are external, and
getCurrentSchema() reports them as such.
- Why a map, not one table at a time? Converting a table also converts every in-memory table connected to it through joins. That set is the join closure. The composite database does not support joins between an external table and an in-memory table.
- The other tables of the closure are resolved implicitly. Only the tables named in the map get
an external table of their own. The rest are looked up in the catalog and schema of the named
external table, built with
fromTableId, that reached them, under their own local names. - Name a table in the map to place it explicitly. This overrides the closure lookup for that table. When two named tables reach the same unnamed table, the lookup uses the named table whose local name sorts first.
- In-memory storage options are dropped. Partitioning, indexes and duplicate-key handling do not apply to an external table.
- Converted tables are no longer written locally. Anything loading data into them must be removed.
- Local names, types, key fields, join names and field mappings are preserved.
Conversion is not the general way to get external tables. An application that only needs
external tables declares them directly, with
addTable(ATableDescription).
Conversion mainly serves two cases:- An Atoti Solutions application declares the tables in memory. The project’s
IModelConfigurerthen converts them. - Some configuration code deploys an application either fully in memory or with most or all
tables external. That shared code calls
convertToExternalTablesonce, at the end, over most or all of the tables it declared.
sales, products and competitors. The
sales table is joined to products. The helper declareCompetitorsTable, not shown, declares the
competitors table and joins it to products on id and date. The example then converts sales
alone. The join closure converts products through the first join, and competitors through the
second. A table is converted however many joins away it is:
What is checked at the call and what is checked at build time?
Converting a table resolves two different things, with different strictness:
The following example names the table backing a converted table explicitly. Its local name
(
Catalog) does not match its external name (products):
sales table with its seller field under a local name that
matches no external column. It converts the table, then states the column with
withExternalColumn:
How to convert a table onto a SQL expression
A table can read the rows of a SQL expression instead of those of a named table. The expression is discovered at theconvertToExternalTables call, like a named table. Fields are matched to the
columns of the expression by name, exactly as for a named table.
The following example declares sales and products in memory, joined together. It converts
sales onto a SQL expression that filters out the rows of product p2. It names products by
table id, because the expression has no catalog or schema to look it up in:
How to vectorize a converted table
A table holding vector data declares one vector field, whatever shape the external table stores it in. The following declaration gives thesimulations_multi_columns table a single array vector
field:
p1 to p5. The conversion maps fields,
not columns. It therefore leaves the table with one array field reading a column that does not
exist. The vector operations state the physical shape instead.
withMultiColumnVector and withMultiRowVector reject a table declared with addTable(ATableDescription).
Such a table states every column it reads, so its description already carries everything a vector needs.
Vectorize it with Vectorization.vectorizeMultiColumn or Vectorization.vectorizeMultiRow before
passing it to addTable.addTable(IStoreDescription) and converts it. It then states that the
array field is spread over the columns p1 to p5. database is the IDatabaseConfigurator
received in IModelConfigurer.configureDatabase. IDirectQueryConfigurator.from(database) returns
the configurator of the external side:
- The vector is a field that already exists. The call states how the external table stores that
field, keeping its local name and type. Naming a field the table does not have throws
an exception. Use
addFieldto create a field. - The columns come from the discovery, not from the fields. The explicit column list and the multi-row index column are both resolved against the discovered external table.
- A multi-row table vectorizes once.
withMultiRowVectortakes every field sharing the index in a single call, and vectorizing an already-vectorized table is rejected.
withMultiRowVector names fields, not columns. The column holding a vector’s values is carried by
the field, and the conversion infers it from the local field name. When the two differ, state the
column with withExternalColumn, before or after the vectorization.
The following example declares a table with two vectors under local names of their own. It converts
the table and points each vector at the column holding its values. It then regroups both vectors
over the index column they share:
How conversion and vectorization behave
- Conversion is applied to all the tables that are joined to the converted table. None of them can be kept in memory.
- A table defined by a SQL expression can back a converted table. The expression is discovered at the call, and an invalid expression fails the call.
- The discovery of an expression reports no key fields. The key fields of a table converted onto an expression are the local ones, and they are not checked against the external database.
- Time travel is rejected on a table defined by an expression.
- An external column stated explicitly, with
withExternalColumnorIDirectQueryTableConfigurator.addField(AFieldDescription), is checked at the call. An unknown column throws an exception there. - An external column left to inference is only checked when the application is built. Conversion
infers it, and so does
ITableConfigurator.addField(IFieldDescription)on a converted table, because neither can state a column.
Related pages
- Use the Atoti Configuration API with DirectQuery: dependencies, connector, configurers and wiring
- Configure the database: in-memory tables, joins, and field configuration
- Configure cubes: dimensions, hierarchies, and measures