Search in sources :

Example 11 with MetadataStore

use of org.teiid.metadata.MetadataStore in project teiid by teiid.

the class TestDynamicImportedMetaData method testUseCatalogSeparator.

@Test
public void testUseCatalogSeparator() throws Exception {
    MetadataFactory mf = createMetadataFactory("x", new Properties());
    Table dup = mf.addTable("dup");
    mf.addColumn("x", DataTypeManager.DefaultDataTypes.STRING, dup);
    MetadataStore ms = mf.asMetadataStore();
    server.deployVDB("test", ms);
    // $NON-NLS-1$
    final Connection conn = server.createConnection("jdbc:teiid:test");
    Properties importProperties = new Properties();
    Connection conn1 = (Connection) SimpleMock.createSimpleMock(new Object[] { new ConnectionProxy(conn), conn }, new Class<?>[] { Connection.class });
    mf = getMetadata(importProperties, conn1);
    Table t = mf.asMetadataStore().getSchemas().get("TEST").getTables().get("test:X.DUP");
    assertEquals("\"test\":\"x\".\"dup\"", t.getNameInSource());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) Connection(java.sql.Connection) Properties(java.util.Properties) Test(org.junit.Test)

Example 12 with MetadataStore

use of org.teiid.metadata.MetadataStore in project teiid by teiid.

the class TestDynamicImportedMetaData method testImportFunction.

@Test
public void testImportFunction() throws Exception {
    MetadataFactory mf = createMetadataFactory("x", new Properties());
    Table dup = mf.addTable("dup");
    mf.addColumn("x", DataTypeManager.DefaultDataTypes.STRING, dup);
    MetadataStore ms = mf.asMetadataStore();
    server.deployVDB("test", ms);
    // $NON-NLS-1$
    Connection conn = server.createConnection("jdbc:teiid:test");
    Properties importProperties = new Properties();
    importProperties.setProperty(NativeMetadataRepository.IMPORT_PUSHDOWN_FUNCTIONS, Boolean.TRUE.toString());
    mf = createMetadataFactory("test", importProperties);
    NativeMetadataRepository nmr = new NativeMetadataRepository();
    OracleExecutionFactory oef = new OracleExecutionFactory();
    oef.start();
    DataSource ds = Mockito.mock(DataSource.class);
    Mockito.stub(ds.getConnection()).toReturn(conn);
    nmr.loadMetadata(mf, oef, ds);
    Map<String, FunctionMethod> functions = mf.asMetadataStore().getSchemas().get("TEST").getFunctions();
    assertEquals(18, functions.size());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) OracleExecutionFactory(org.teiid.translator.jdbc.oracle.OracleExecutionFactory) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) NativeMetadataRepository(org.teiid.query.metadata.NativeMetadataRepository) Connection(java.sql.Connection) FunctionMethod(org.teiid.metadata.FunctionMethod) Properties(java.util.Properties) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 13 with MetadataStore

use of org.teiid.metadata.MetadataStore in project teiid by teiid.

the class TestDynamicImportedMetaData method testIgnorePkIndex.

@Test
public void testIgnorePkIndex() throws Exception {
    MetadataFactory mf = createMetadataFactory("x", new Properties());
    Table dup = mf.addTable("x");
    mf.addColumn("x", DataTypeManager.DefaultDataTypes.STRING, dup);
    mf.addPrimaryKey("foo", Arrays.asList("x"), dup);
    MetadataStore ms = mf.asMetadataStore();
    server.deployVDB("test", ms);
    // cheat and add the index after deployment
    mf.addIndex("foo", false, Arrays.asList("x"), dup);
    // $NON-NLS-1$
    Connection conn = server.createConnection("jdbc:teiid:test");
    Properties importProperties = new Properties();
    importProperties.setProperty("importer.importKeys", Boolean.TRUE.toString());
    importProperties.setProperty("importer.importIndexes", Boolean.TRUE.toString());
    mf = getMetadata(importProperties, conn);
    Table t = mf.asMetadataStore().getSchemas().get("TEST").getTables().get("test.X.X");
    assertNotNull(t.getPrimaryKey());
    assertEquals(0, t.getUniqueKeys().size());
    assertEquals(0, t.getIndexes().size());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) Connection(java.sql.Connection) Properties(java.util.Properties) Test(org.junit.Test)

Example 14 with MetadataStore

use of org.teiid.metadata.MetadataStore in project teiid by teiid.

the class TestDynamicImportedMetaData method testDDLMetadata.

@Test
public void testDDLMetadata() throws Exception {
    String ddl = "CREATE FOREIGN PROCEDURE getTextFiles(IN pathAndPattern varchar) RETURNS (file clob, filpath string) OPTIONS(UUID 'uuid')";
    MetadataFactory mf = createMetadataFactory("MarketData", new Properties());
    QueryParser.getQueryParser().parseDDL(mf, ddl);
    MetadataStore ms = mf.asMetadataStore();
    String ddl2 = "CREATE VIEW stock (symbol string, price bigdecimal) OPTIONS (UUID 'uuid')" + "AS select stock.* from (call MarketData.getTextFiles('*.txt')) f, " + "TEXTTABLE(f.file COLUMNS symbol string, price bigdecimal HEADER) stock;";
    MetadataFactory m2 = createMetadataFactory("portfolio", new Properties());
    QueryParser.getQueryParser().parseDDL(m2, ddl2);
    m2.getSchema().setPhysical(false);
    m2.mergeInto(ms);
    server.deployVDB("test", ms);
    // $NON-NLS-1$
    Connection conn = server.createConnection("jdbc:teiid:test");
    Properties props = new Properties();
    props.setProperty("importer.importProcedures", Boolean.TRUE.toString());
    MetadataStore store = getMetadata(props, conn).asMetadataStore();
    Procedure p = store.getSchema("test").getProcedure("test.MarketData.getTextFiles");
    assertNotNull(p);
    ProcedureParameter pp = p.getParameters().get(0);
    assertEquals("pathAndPattern", pp.getName());
    assertEquals("\"pathAndPattern\"", pp.getNameInSource());
    assertEquals(ProcedureParameter.Type.In, pp.getType());
    // assertEquals("string", pp.getDatatype().getName());
    Table t = store.getSchema("test").getTable("test.portfolio.stock");
    assertNotNull(t);
    List<Column> columns = t.getColumns();
    assertEquals(2, columns.size());
    assertEquals("symbol", columns.get(0).getName());
    assertEquals("price", columns.get(1).getName());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) ProcedureParameter(org.teiid.metadata.ProcedureParameter) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) Connection(java.sql.Connection) Procedure(org.teiid.metadata.Procedure) Properties(java.util.Properties) Test(org.junit.Test)

Example 15 with MetadataStore

use of org.teiid.metadata.MetadataStore in project teiid by teiid.

the class TestProcessor method testInsertTempTableCreation1.

@Test
public void testInsertTempTableCreation1() {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema v1 = RealMetadataFactory.createVirtualModel("v1", metadataStore);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN insert into #temp (var1) values (1); select 2 as var1 into #temp; select #temp.var1 from #temp; END");
    // $NON-NLS-1$ //$NON-NLS-2$
    ColumnSet<Procedure> rs = RealMetadataFactory.createResultSet("rs", new String[] { "var1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
    // $NON-NLS-1$
    Procedure vp = RealMetadataFactory.createVirtualProcedure("vp", v1, null, n1);
    vp.setResultSet(rs);
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
    // $NON-NLS-1$
    ProcessorPlan plan = helpGetPlan("exec v1.vp()", metadata);
    List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(1) }), Arrays.asList(new Object[] { new Integer(2) }) };
    helpProcess(plan, new FakeDataManager(), expected);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) BigInteger(java.math.BigInteger) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema) Procedure(org.teiid.metadata.Procedure) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Aggregations

MetadataStore (org.teiid.metadata.MetadataStore)73 Schema (org.teiid.metadata.Schema)47 Test (org.junit.Test)38 Table (org.teiid.metadata.Table)37 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)22 QueryNode (org.teiid.query.mapping.relational.QueryNode)19 Column (org.teiid.metadata.Column)17 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)15 Properties (java.util.Properties)12 MetadataFactory (org.teiid.metadata.MetadataFactory)12 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)12 Procedure (org.teiid.metadata.Procedure)11 List (java.util.List)9 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)9 Connection (java.sql.Connection)8 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)8 ArrayList (java.util.ArrayList)7 ProcedureParameter (org.teiid.metadata.ProcedureParameter)7 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)7 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)6