... |
h2. Configuration |
To mark a model as multi-source, the model property _supports-multi-source_\-bindings needs set to true in the "vdb.xml" file. The model is then allowed to define more than one source. Here is a code example showing dynamic vdb with single model with multiple sources defined. |
To mark a model as multi-source, the model property _multisource_ can be set to true or more than one source can be listed for the model in the "vdb.xml" file. Here is a code example showing dynamic vdb with single model with multiple sources defined. |
{code:lang=XML}<vdb name="vdbname" version="1"> <model visible="true" type="PHYSICAL" name="Customers" path="/Test/Customers.xmi"> |
<property name="supports-multi-source-bindings" name="multisource" value="true"/> |
<!-- optional properties <property name="multisource.columnName" value="somename"/> |
... |
Multi-source models can be used to quickly access data in multiple sources with homogeneous metadata. When you have multiple instances using identical schema (horizontal sharding), Teiid can help you gather data across all the instances, using "multi-source" models. In this scenario, instead of creating/importing a model for every data source, one source model is defined to represents the schema and is configured with multiple data "sources" underneath it. During runtime when a query issued against this model, the query engine analyzes the information and gathers the required data from all sources configured and gathers the results and provides in a single result. Since all sources utilize the same physical metadata, this feature is most appropriate for accessing the same source type with multiple instances.
To mark a model as multi-source, the model property multisource can be set to true or more than one source can be listed for the model in the "vdb.xml" file. Here is a code example showing dynamic vdb with single model with multiple sources defined.
<vdb name="vdbname" version="1"> <model visible="true" type="PHYSICAL" name="Customers" path="/Test/Customers.xmi"> <property name="multisource" value="true"/> <!-- optional properties <property name="multisource.columnName" value="somename"/> <property name="multisource.addColumn" value="true"/> --> <source name="chicago" translator-name="oracle" connection-jndi-name="chicago-customers"/> <source name="newyork" translator-name="oracle" connection-jndi-name="newyork-customers"/> <source name="la" translator-name="oracle" connection-jndi-name="la-customers"/> </model> </vdb>
Currently the tooling support for managing the multi-source feature is limited, so if you need to use this feature build the VDB as usual in the Teiid Designer and then edit the "vdb.xml" file in the VDB archive using a Text editor to add the additional sources as defined above. You must deploy a separate data source for each source defined in the xml file. |
In the above example, the VDB has a single model called Customers, that has multiple sources (chicago, newyork, and la) that define different instances of data.
When a model is marked as multi-source, the engine will add or use an existing column on each table to represent the source name values. In the above vdb.xml the column would return chicago, la, newyork for each of the respective sources. The name of the column defaults to SOURCE_NAME, but is configurable by setting the model property multisource.columnName. If a column already exists on the table (or an IN procedure parameter) with the same name, the engine will assume that it should represent the multi-source column and it will not be used to retrieve physical data. If the multi-source column is not present, the generated column will be treated as a pseudo column which is not selectable via wildcards (* nor tbl.*).
This allows queries like the following:
select * from table where SOURCE_NAME = 'newyork' update table column=value where SOURCE_NAME='chicago' delete from table where column = x and SOURCE_NAME='la' insert into table (column, SOURCE_NAME) VALUES ('value', 'newyork')
The pseudo column is by default not present in your actual metadata; it is not added on source tables/procedures when you import the metadata. If you would like to use the multi-source column in your transformations to control which sources are accessed or updated and/or want the column reported via metadata facilities, there are several options:
The planner logically treats a multi-source table as if it were a view containing the union all of the respective source tables. More complex partitioning scenarios, such as heterogeneous sources or list partitioning will require the use of a Federated Optimizations#Partitioned Union.
Most of the federated optimizations available over unions are still applicable in multi-source mode. This includes aggregation pushdown/decomposition, limit pushdown, join partitioning, etc.
A physical stored procedures requires the addition of a string in parameter matching the multi-source column name to specify which source the procedure is executed on. If the parameter is not present and defaults to a null value, then the procedure will be executed on each source. It is not possible to execute procedures that are required to return IN/OUT, OUT, or RETURN parameters values on more than 1 source.
CREATE FOREIGN PROCEDURE PROC (arg1 IN STRING NOT NULL, arg2 IN STRING, SOURCE_NAME IN STRING)
CALL PROC(arg1=>'x', SOURCE_NAME=>'sourceA') EXEC PROC('x', 'y', 'sourceB')
CALL PROC(arg1=>'x') EXEC PROC('x', 'y')