Search in sources :

Example 6 with QueryNode

use of org.teiid.query.mapping.relational.QueryNode in project teiid by teiid.

the class RealMetadataFactory method exampleUpdateProc.

public static TransformationMetadata exampleUpdateProc(TriggerEvent procedureType, String procedure1, String procedure2) {
    MetadataStore metadataStore = new MetadataStore();
    // Create models
    // $NON-NLS-1$
    Schema pm1 = createPhysicalModel("pm1", metadataStore);
    // $NON-NLS-1$
    Schema pm2 = createPhysicalModel("pm2", metadataStore);
    // $NON-NLS-1$
    Schema vm1 = createVirtualModel("vm1", metadataStore);
    // Create physical groups
    // $NON-NLS-1$
    Table pm1g1 = createPhysicalGroup("g1", pm1);
    // $NON-NLS-1$
    Table pm1g2 = createPhysicalGroup("g2", pm1);
    // $NON-NLS-1$
    Table pm2g1 = createPhysicalGroup("g1", pm2);
    // $NON-NLS-1$
    Table pm2g2 = createPhysicalGroup("g2", pm2);
    // Create physical group elements
    createElements(pm1g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    createElements(pm1g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    createElements(pm2g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    createElements(pm2g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    // Create virtual groups
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g1n1 = new QueryNode("SELECT * FROM vm1.g2");
    // $NON-NLS-1$
    Table vm1g1 = createUpdatableVirtualGroup("g1", vm1, vm1g1n1);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g2n1 = new QueryNode("SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2");
    // $NON-NLS-1$
    Table vm1g2 = createUpdatableVirtualGroup("g2", vm1, vm1g2n1);
    // Create virtual elements
    createElementsWithDefaults(vm1g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE }, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "xyz", "123", "true", "123.456" });
    createElementsWithDefaults(vm1g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE }, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    new String[] { "abc", "456", "false", null });
    setInsteadOfTriggerDefinition(vm1g1, procedureType, procedure1);
    setInsteadOfTriggerDefinition(vm1g2, procedureType, procedure2);
    // Create the facade from the store
    return createTransformationMetadata(metadataStore, "proc");
}
Also used : CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) QueryNode(org.teiid.query.mapping.relational.QueryNode)

Example 7 with QueryNode

use of org.teiid.query.mapping.relational.QueryNode in project teiid by teiid.

the class RealMetadataFactory method example4.

/**
 * This example is for testing static costing using cardinality information from
 * metadata, as well as key information and maybe access patterns
 */
public static TransformationMetadata example4() {
    MetadataStore metadataStore = new MetadataStore();
    // Create models - physical ones will support joins
    // $NON-NLS-1$
    Schema pm1 = createPhysicalModel("pm1", metadataStore);
    // $NON-NLS-1$
    Schema pm2 = createPhysicalModel("pm2", metadataStore);
    // $NON-NLS-1$
    Schema pm3 = createPhysicalModel("pm3", metadataStore);
    // $NON-NLS-1$
    Schema pm4 = createPhysicalModel("pm4", metadataStore);
    // $NON-NLS-1$
    Schema vm1 = createVirtualModel("vm1", metadataStore);
    // Create physical groups
    // $NON-NLS-1$
    Table pm1g1 = createPhysicalGroup("g1", pm1);
    // $NON-NLS-1$
    Table pm1g2 = createPhysicalGroup("g2", pm1);
    // $NON-NLS-1$
    Table pm1g3 = createPhysicalGroup("g3", pm1);
    // $NON-NLS-1$
    Table pm2g1 = createPhysicalGroup("g1", pm2);
    // $NON-NLS-1$
    Table pm2g2 = createPhysicalGroup("g2", pm2);
    // $NON-NLS-1$
    Table pm2g3 = createPhysicalGroup("g3", pm2);
    // $NON-NLS-1$
    Table pm3g1 = createPhysicalGroup("g1", pm3);
    // $NON-NLS-1$
    Table pm3g2 = createPhysicalGroup("g2", pm3);
    // $NON-NLS-1$
    Table pm3g3 = createPhysicalGroup("g3", pm3);
    // $NON-NLS-1$
    Table pm4g1 = createPhysicalGroup("g1", pm4);
    // $NON-NLS-1$
    Table pm4g2 = createPhysicalGroup("g2", pm4);
    // Add group cardinality metadata
    pm1g1.setCardinality(10);
    pm1g2.setCardinality(10);
    pm1g3.setCardinality(10);
    pm2g1.setCardinality(1000);
    pm2g2.setCardinality(1000);
    pm3g1.setCardinality(100000);
    pm3g2.setCardinality(100000);
    pm3g3.setCardinality(100000);
    // leave pm4.g1 as unknown
    // Create physical elements
    List<Column> pm1g1e = createElements(pm1g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    createElements(pm1g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    List<Column> pm1g3e = createElements(pm1g3, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    List<Column> pm2g1e = createElements(pm2g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    createElements(pm2g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    createElements(pm2g3, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    List<Column> pm3g1e = createElements(pm3g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    createElements(pm3g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    List<Column> pm3g3e = createElements(pm3g3, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    List<Column> pm4g1e = createElements(pm4g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    List<Column> pm4g2e = createElements(pm4g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    // Add key metadata
    // e1 //$NON-NLS-1$
    createKey(KeyRecord.Type.Primary, "pm1.g1.key1", pm1g1, pm1g1e.subList(0, 1));
    // e1 //$NON-NLS-1$
    createKey(KeyRecord.Type.Primary, "pm3.g1.key1", pm3g1, pm3g1e.subList(0, 1));
    // e1 //$NON-NLS-1$
    createKey(KeyRecord.Type.Primary, "pm3.g3.key1", pm3g3, pm3g3e.subList(0, 1));
    // e1, e2 //$NON-NLS-1$
    KeyRecord pm4g1key1 = createKey(KeyRecord.Type.Primary, "pm4.g1.key1", pm4g1, pm4g1e.subList(0, 2));
    // $NON-NLS-1$
    createForeignKey("pm4.g2.fk", pm4g2, pm4g2e.subList(0, 2), pm4g1key1);
    // Add access pattern metadata
    // Create access patterns - pm1
    List<Column> elements = new ArrayList<Column>(1);
    elements.add(pm1g1e.iterator().next());
    // e1 //$NON-NLS-1$
    createAccessPattern("pm1.g1.ap1", pm1g1, elements);
    elements = new ArrayList<Column>(2);
    Iterator<Column> iter = pm1g3e.iterator();
    elements.add(iter.next());
    elements.add(iter.next());
    // e1,e2 //$NON-NLS-1$
    createAccessPattern("pm1.g3.ap1", pm1g3, elements);
    // Create access patterns - pm2
    elements = new ArrayList<Column>(1);
    elements.add(pm2g1e.iterator().next());
    // e1 //$NON-NLS-1$
    createAccessPattern("pm2.g1.ap1", pm2g1, elements);
    // Create virtual groups
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g1n1 = new QueryNode("SELECT * FROM pm1.g1");
    // $NON-NLS-1$
    Table vm1g1 = createUpdatableVirtualGroup("g1", vm1, vm1g1n1);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g2n1 = new QueryNode("SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3 FROM pm1.g2");
    // $NON-NLS-1$
    Table vm1g2 = createUpdatableVirtualGroup("g2", vm1, vm1g2n1);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g3n1 = new QueryNode("SELECT pm1.g3.e1 AS x, pm1.g3.e2 AS y from pm1.g3");
    // $NON-NLS-1$
    Table vm1g3 = createUpdatableVirtualGroup("g3", vm1, vm1g3n1);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g4n1 = new QueryNode("SELECT distinct pm1.g2.e1 as ve1, pm1.g1.e1 as ve2 FROM pm1.g2 LEFT OUTER JOIN /* optional */ pm1.g1 on pm1.g1.e1 = pm1.g2.e1");
    // $NON-NLS-1$
    Table vm1g4 = createVirtualGroup("g4", vm1, vm1g4n1);
    createElements(vm1g4, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "ve1", "ve2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
    // Create virtual elements
    createElements(vm1g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    createElements(vm1g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    createElements(vm1g3, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "x", "y" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
    return createTransformationMetadata(metadataStore, "example4");
}
Also used : CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) QueryNode(org.teiid.query.mapping.relational.QueryNode) ArrayList(java.util.ArrayList)

Example 8 with QueryNode

use of org.teiid.query.mapping.relational.QueryNode in project teiid by teiid.

the class RealMetadataFactory method exampleMultiBinding.

/**
 * Metadata for Multi-Binding models
 * @return example
 * @since 4.2
 */
public static TransformationMetadata exampleMultiBinding() {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema virtModel = createVirtualModel("Virt", metadataStore);
    // $NON-NLS-1$
    Schema physModel = createPhysicalModel("MultiModel", metadataStore);
    // $NON-NLS-1$
    Table physGroup = createPhysicalGroup("Phys", physModel);
    createElements(physGroup, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "a", "b" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
    // $NON-NLS-1$
    Table physGroup1 = createPhysicalGroup("Phys1", physModel);
    createElements(physGroup1, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "a", "b" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
    // $NON-NLS-1$
    Table physGroup2 = createPhysicalGroup("Phys2", physModel);
    createElements(physGroup2, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "a", "b" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode virtTrans = new QueryNode("SELECT * FROM MultiModel.Phys");
    // $NON-NLS-1$
    Table virtGroup = createVirtualGroup("view", virtModel, virtTrans);
    createElements(virtGroup, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "a", "b" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    ColumnSet<Procedure> rs2 = createResultSet("Virt.rs1", new String[] { "a", "b" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
    // $NON-NLS-1$
    ProcedureParameter rs2p2 = createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
    rs2p2.setNullType(org.teiid.metadata.BaseColumn.NullType.Nullable);
    QueryNode sq2n1 = new QueryNode(// $NON-NLS-1$ //$NON-NLS-2$
    "CREATE VIRTUAL PROCEDURE BEGIN\n" + // $NON-NLS-1$
    "execute string 'SELECT a, b FROM MultiModel.Phys where SOURCE_NAME = Virt.sq1.in'; END");
    // $NON-NLS-1$
    Procedure sq1 = createVirtualProcedure("sq1", virtModel, Arrays.asList(rs2p2), sq2n1);
    sq1.setResultSet(rs2);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    ColumnSet<Procedure> rs3 = createResultSet("MultiModel.rs1", new String[] { "a", "b" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
    // $NON-NLS-1$
    ProcedureParameter rs3p2 = createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$
    ProcedureParameter rs3p3 = createParameter("source_name", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
    rs3p3.setNullType(org.teiid.metadata.BaseColumn.NullType.Nullable);
    Procedure sq2 = createStoredProcedure("proc", physModel, Arrays.asList(rs3p2, rs3p3));
    sq2.setResultSet(rs3);
    return createTransformationMetadata(metadataStore, "multiBinding");
}
Also used : CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) QueryNode(org.teiid.query.mapping.relational.QueryNode)

Example 9 with QueryNode

use of org.teiid.query.mapping.relational.QueryNode in project teiid by teiid.

the class TestUpdateValidator method createView.

public static Command createView(String sql, TransformationMetadata md, String vGroup) throws QueryParserException, QueryResolverException, TeiidComponentException {
    QueryNode vm1g1n1 = new QueryNode(sql);
    Table vm1g1 = RealMetadataFactory.createUpdatableVirtualGroup(vGroup, md.getMetadataStore().getSchema("VM1"), vm1g1n1);
    Command command = QueryParser.getQueryParser().parseCommand(sql);
    QueryResolver.resolveCommand(command, md);
    List<Expression> symbols = command.getProjectedSymbols();
    String[] names = new String[symbols.size()];
    String[] types = new String[symbols.size()];
    int i = 0;
    for (Expression singleElementSymbol : symbols) {
        names[i] = Symbol.getShortName(singleElementSymbol);
        types[i++] = DataTypeManager.getDataTypeName(singleElementSymbol.getType());
    }
    RealMetadataFactory.createElements(vm1g1, names, types);
    return command;
}
Also used : Table(org.teiid.metadata.Table) Command(org.teiid.query.sql.lang.Command) Expression(org.teiid.query.sql.symbol.Expression) QueryNode(org.teiid.query.mapping.relational.QueryNode)

Example 10 with QueryNode

use of org.teiid.query.mapping.relational.QueryNode in project teiid by teiid.

the class TestUpdateValidator method example1.

public static TransformationMetadata example1(boolean allUpdatable) {
    MetadataStore metadataStore = new MetadataStore();
    // Create models
    // $NON-NLS-1$
    Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
    // $NON-NLS-1$
    Schema vm1 = RealMetadataFactory.createVirtualModel("vm1", metadataStore);
    // Create physical groups
    // $NON-NLS-1$
    Table pm1g1 = RealMetadataFactory.createPhysicalGroup("g1", pm1);
    // $NON-NLS-1$
    Table pm1g2 = RealMetadataFactory.createPhysicalGroup("g2", pm1);
    // $NON-NLS-1$
    Table pm1g3 = RealMetadataFactory.createPhysicalGroup("g3", pm1);
    // Create physical elements
    List<Column> pm1g1e = RealMetadataFactory.createElements(pm1g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    if (!allUpdatable) {
        pm1g1e.get(0).setUpdatable(false);
    }
    KeyRecord pk = RealMetadataFactory.createKey(Type.Primary, "pk", pm1g1, pm1g1e.subList(0, 1));
    List<Column> pm1g2e = RealMetadataFactory.createElements(pm1g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    RealMetadataFactory.createKey(Type.Primary, "pk", pm1g2, pm1g1e.subList(1, 2));
    RealMetadataFactory.createForeignKey("fk", pm1g2, pm1g2e.subList(0, 1), pk);
    List<Column> pm1g3e = RealMetadataFactory.createElements(pm1g3, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    pm1g3e.get(0).setNullType(NullType.No_Nulls);
    pm1g3e.get(0).setDefaultValue(null);
    pm1g3e.get(1).setNullType(NullType.No_Nulls);
    pm1g3e.get(1).setAutoIncremented(true);
    pm1g3e.get(1).setDefaultValue(null);
    pm1g3e.get(2).setNullType(NullType.No_Nulls);
    // $NON-NLS-1$
    pm1g3e.get(2).setDefaultValue("xyz");
    RealMetadataFactory.createKey(Type.Primary, "pk", pm1g3, pm1g3e.subList(0, 1));
    // Create virtual groups
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g1n1 = new QueryNode("SELECT e1 as a, e2 FROM pm1.g1 WHERE e3 > 5");
    // $NON-NLS-1$
    Table vm1g1 = RealMetadataFactory.createUpdatableVirtualGroup("g1", vm1, vm1g1n1);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g2n1 = new QueryNode("SELECT e1, e2, e3, e4 FROM pm1.g2 WHERE e3 > 5");
    // $NON-NLS-1$
    Table vm1g2 = RealMetadataFactory.createUpdatableVirtualGroup("g2", vm1, vm1g2n1);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g3n1 = new QueryNode("SELECT e1, e3 FROM pm1.g3");
    // $NON-NLS-1$
    Table vm1g3 = RealMetadataFactory.createUpdatableVirtualGroup("g3", vm1, vm1g3n1);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g4n1 = new QueryNode("SELECT e1, e2 FROM pm1.g3");
    // $NON-NLS-1$
    Table vm1g4 = RealMetadataFactory.createUpdatableVirtualGroup("g4", vm1, vm1g4n1);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g5n1 = new QueryNode("SELECT e2, e3 FROM pm1.g3");
    // $NON-NLS-1$
    Table vm1g5 = RealMetadataFactory.createVirtualGroup("g5", vm1, vm1g5n1);
    // Create virtual elements
    RealMetadataFactory.createElements(vm1g1, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "a", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
    RealMetadataFactory.createElements(vm1g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    RealMetadataFactory.createElements(vm1g3, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
    RealMetadataFactory.createElements(vm1g4, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "e1", "e3" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.BOOLEAN });
    RealMetadataFactory.createElements(vm1g5, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "e2", "e3" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN });
    // Stored queries
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    ColumnSet<Procedure> rs1 = RealMetadataFactory.createResultSet("rs1", new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode sq1n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN SELECT e1, e2 FROM pm1.g1; END");
    // $NON-NLS-1$
    Procedure sq1 = RealMetadataFactory.createVirtualProcedure("sq1", pm1, Collections.EMPTY_LIST, sq1n1);
    sq1.setResultSet(rs1);
    // Create the facade from the store
    return RealMetadataFactory.createTransformationMetadata(metadataStore, "example");
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) KeyRecord(org.teiid.metadata.KeyRecord) Table(org.teiid.metadata.Table) Column(org.teiid.metadata.Column) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema) Procedure(org.teiid.metadata.Procedure)

Aggregations

QueryNode (org.teiid.query.mapping.relational.QueryNode)39 Schema (org.teiid.metadata.Schema)20 MetadataStore (org.teiid.metadata.MetadataStore)19 Table (org.teiid.metadata.Table)15 Column (org.teiid.metadata.Column)9 CompositeMetadataStore (org.teiid.query.metadata.CompositeMetadataStore)9 Test (org.junit.Test)8 Procedure (org.teiid.metadata.Procedure)8 ArrayList (java.util.ArrayList)7 List (java.util.List)5 ProcedureParameter (org.teiid.metadata.ProcedureParameter)5 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)5 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)4 Command (org.teiid.query.sql.lang.Command)4 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)4 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)3 KeyRecord (org.teiid.metadata.KeyRecord)3 TempMetadataID (org.teiid.query.metadata.TempMetadataID)3 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)3 CacheHint (org.teiid.query.sql.lang.CacheHint)3