use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class AccessNode method openInternal.
private void openInternal() throws TeiidComponentException, TeiidProcessingException {
// TODO: support a partitioning concept with multi-source and full dependent join pushdown
if (subPlans != null) {
if (this.evaluatedPlans == null) {
this.evaluatedPlans = new HashMap<GroupSymbol, SubqueryState>();
for (Map.Entry<GroupSymbol, RelationalPlan> entry : subPlans.entrySet()) {
SubqueryState state = new SubqueryState();
RelationalPlan value = entry.getValue();
value.reset();
state.processor = new QueryProcessor(value, getContext().clone(), getBufferManager(), getDataManager());
state.collector = state.processor.createBatchCollector();
this.evaluatedPlans.put(entry.getKey(), state);
}
}
BlockedException be = null;
for (SubqueryState state : evaluatedPlans.values()) {
try {
state.collector.collectTuples();
} catch (BlockedException e) {
be = e;
}
}
if (be != null) {
throw be;
}
}
/*
* Check to see if we need a multi-source expansion. If the connectorBindingExpression != null, then
* the logic below will handle that case
*/
if (multiSource && connectorBindingExpression == null) {
synchronized (this) {
// the description can be obtained asynchly, so we need to synchronize
VDBMetaData vdb = getContext().getVdb();
ModelMetaData model = vdb.getModel(getModelName());
List<String> sources = model.getSourceNames();
// make sure that we have the right nodes
if (this.getChildCount() != 0 && (this.sourceNames == null || !this.sourceNames.equals(sources))) {
this.childCount--;
this.getChildren()[0] = null;
}
if (this.getChildCount() == 0) {
sourceNames = sources;
RelationalNode node = multiSourceModify(this, connectorBindingExpression, getContext().getMetadata(), sourceNames);
RelationalPlan.connectExternal(node, getContext(), getDataManager(), getBufferManager());
this.addChild(node);
}
}
this.getChildren()[0].open();
return;
}
// Copy command and resolve references if necessary
if (processingCommand == null) {
processingCommand = command;
isUpdate = RelationalNodeUtil.isUpdate(command);
}
boolean needProcessing = true;
if (this.connectorBindingExpression != null && connectorBindingId == null) {
this.connectorBindingId = (String) getEvaluator(Collections.emptyMap()).evaluate(this.connectorBindingExpression, null);
VDBMetaData vdb = getContext().getVdb();
ModelMetaData model = vdb.getModel(getModelName());
List<String> sources = model.getSourceNames();
String replacement = this.connectorBindingId;
if (!sources.contains(this.connectorBindingId)) {
shouldExecute = false;
if (command instanceof StoredProcedure) {
StoredProcedure sp = (StoredProcedure) command;
if (sp.returnParameters() && sp.getProjectedSymbols().size() > sp.getResultSetColumns().size()) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30561, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30561, command));
}
}
return;
}
if (!(command instanceof StoredProcedure || command instanceof Insert)) {
processingCommand = (Command) command.clone();
MultiSourceElementReplacementVisitor.visit(replacement, getContext().getMetadata(), processingCommand);
}
}
do {
Command atomicCommand = nextCommand();
if (shouldEvaluate) {
needProcessing = prepareNextCommand(atomicCommand);
nextCommand = null;
} else {
needProcessing = RelationalNodeUtil.shouldExecute(atomicCommand, true);
}
if (needProcessing) {
registerRequest(atomicCommand);
}
// We use an upper limit here to the currency because these commands have potentially large in-memory value sets
} while (!processCommandsIndividually() && hasNextCommand() && this.tupleSources.size() < Math.max(Math.min(MAX_CONCURRENT, this.getContext().getUserRequestSourceConcurrency()), this.getContext().getUserRequestSourceConcurrency() / 2));
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class RealMetadataFactory method exampleMultiBindingVDB.
public static VDBMetaData exampleMultiBindingVDB() {
VDBMetaData vdb = new VDBMetaData();
vdb.setName("exampleMultiBinding");
vdb.setVersion(1);
ModelMetaData model = new ModelMetaData();
model.setName("MultiModel");
model.setModelType(Model.Type.PHYSICAL);
model.setVisible(true);
model.setSupportsMultiSourceBindings(true);
vdb.addModel(model);
vdb.addModel(RealMetadataFactory.createModel("Virt", false));
return vdb;
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestASTQueries method setUp.
@BeforeClass
public static void setUp() throws Exception {
server = new EmbeddedServer();
server.start(new EmbeddedConfiguration());
LoopbackExecutionFactory loopy = new LoopbackExecutionFactory();
loopy.setRowCount(10);
loopy.start();
server.addTranslator("l", loopy);
String DDL = "CREATE FOREIGN TABLE G1 (e1 string, e2 integer);";
ModelMetaData model = new ModelMetaData();
model.setName("PM1");
model.setModelType(Model.Type.PHYSICAL);
model.setSchemaSourceType("DDL");
model.setSchemaText(DDL);
SourceMappingMetadata sm = new SourceMappingMetadata();
sm.setName("loopy");
sm.setTranslatorName("l");
model.addSourceMapping(sm);
server.deployVDB("test", model);
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestDynamicImportedMetaData method testMultipleFK.
@Test
public void testMultipleFK() throws Exception {
ModelMetaData mmd = new ModelMetaData();
mmd.addSourceMetadata("ddl", "create foreign table x (y integer, z integer, primary key (y, z));" + "create foreign table z (y integer, z integer, y1 integer, z1 integer, foreign key (y, z) references x (y, z), foreign key (y1, z1) references x (y, z))");
mmd.setName("foo");
mmd.addSourceMapping("x", "x", "x");
server.addTranslator("x", new ExecutionFactory());
server.deployVDB("vdb", mmd);
// $NON-NLS-1$
Connection conn = server.createConnection("jdbc:teiid:vdb");
Properties importProperties = new Properties();
importProperties.setProperty("importer.importKeys", "true");
MetadataFactory mf = getMetadata(importProperties, conn);
Table t = mf.asMetadataStore().getSchemas().get("test").getTables().get("vdb.foo.z");
List<ForeignKey> fks = t.getForeignKeys();
assertEquals(2, fks.size());
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestDynamicImportedMetaData method testMultiSource.
@Test
public void testMultiSource() throws Exception {
ModelMetaData mmd = new ModelMetaData();
mmd.addSourceMetadata("ddl", "create foreign table x (y integer primary key);");
mmd.setName("foo");
mmd.addSourceMapping("x", "x", "x");
server.addTranslator("x", new ExecutionFactory());
server.deployVDB("vdb", mmd);
TeiidExecutionFactory tef = new TeiidExecutionFactory() {
@Override
public void closeConnection(Connection connection, DataSource factory) {
}
};
tef.setSupportsDirectQueryProcedure(true);
tef.start();
server.addTranslator("teiid", tef);
DataSource ds = Mockito.mock(DataSource.class);
Mockito.stub(ds.getConnection()).toReturn(server.getDriver().connect("jdbc:teiid:vdb", null));
server.addConnectionFactory("teiid1", ds);
server.addConnectionFactory("teiid2", ds);
server.deployVDB(new FileInputStream(UnitTestUtil.getTestDataFile("multi.xml")));
Connection c = server.createConnection("jdbc:teiid:multi", null);
Statement s = c.createStatement();
s.execute("call native('select ?', 'b')");
ResultSet rs = s.getResultSet();
assertTrue(rs.next());
assertTrue(rs.next());
assertFalse(rs.next());
s.execute("call native(request=>'select ?', variable=>('b',), target=>'teiid1')");
rs = s.getResultSet();
assertTrue(rs.next());
Object[] result = (Object[]) rs.getArray(1).getArray();
assertArrayEquals(new Object[] { "b" }, result);
assertFalse(rs.next());
}
Aggregations