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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations