Here are the steps necessary to create a VDB that reads from a CSV file.
It will skip the first line (header).
Creating VDB
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<vdb name="MyVDB" version="1">
<description>My VDB</description>
<model name="MyCsvData">
<source name="MyCsv-connector" translator-name="file" connection-jndi-name="java:/dataSourceName"/>
</model>
<model name="My" type="VIRTUAL">
<metadata type="DDL"><![CDATA[
CREATE VIEW my_table (
cns varchar(400),
country_code varchar(400)
)
AS
SELECT A.cns,
A.country_code
FROM (EXEC MyCsvData.getTextFiles('My.csv')) AS f,
TEXTTABLE(f.file COLUMNS cns string,
country_code string DELIMITER ';' SKIP 1) AS A;
]]>
</metadata>
</model>
</vdb>
Configuring WildFly
Here are the steps necessary to create a file datasource in Teiid 9.1.2:
Run the following in the server console (in
./jboss-cli.sh --connect
and run the following commands:
/subsystem=resource-adapters/resource-adapter=adapterName:add(module=org.jboss.teiid.resource-adapter.file)
/subsystem=resource-adapters/resource-adapter=adapterName/connection-definitions=adapterPoolName:add(jndi-name=java:/dataSourceName, class-name=org.teiid.resource.adapter.file.FileManagedConnectionFactory, enabled=true, use-java-context=true)
/subsystem=resource-adapters/resource-adapter=adapterName/connection-definitions=adapterPoolName/config-properties=ParentDirectory:add(value=/path/to/files/)
/subsystem=resource-adapters/resource-adapter=adapterName/connection-definitions=adapterPoolName/config-properties=AllowParentPaths:add(value=true)
/subsystem=resource-adapters/resource-adapter=
adapterName:activate:reload
Where:
- adapterName - Put the name of the adapter that you want, and that will appear in WildFly console (under resource-adapters);
- adapterPoolName - Name that will appear in WildFly console on the details of the resource-adapter;
- dataSourceName - The name of the datasource that will be publicly used.
- /path/to/files/ - where the files to process are.