use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.
the class SubqueryAwareEvaluator method evaluatePushdown.
/**
* Implements must pushdown function handling if supported by the source.
*
* The basic strategy is to create a dummy subquery to represent the evaluation
*/
@Override
protected Object evaluatePushdown(Function function, List<?> tuple, Object[] values) throws TeiidComponentException, TeiidProcessingException {
final FunctionDescriptor fd = function.getFunctionDescriptor();
if (fd.getMethod() == null) {
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30341, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30341, fd.getFullName()));
}
String schema = null;
if (fd.getMethod().getParent() == null || !fd.getMethod().getParent().isPhysical()) {
// find a suitable target
// TODO: do better than a linear search
VDBMetaData vdb = this.context.getVdb();
CapabilitiesFinder capabiltiesFinder = this.context.getQueryProcessorFactory().getCapabiltiesFinder();
for (ModelMetaData mmd : vdb.getModelMetaDatas().values()) {
if (!mmd.isSource()) {
continue;
}
SourceCapabilities caps = capabiltiesFinder.findCapabilities(mmd.getName());
if (caps.supportsCapability(Capability.SELECT_WITHOUT_FROM) && caps.supportsFunction(fd.getMethod().getFullName())) {
schema = mmd.getName();
break;
}
}
if (schema == null) {
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30341, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30341, fd.getFullName()));
}
} else {
if (!CapabilitiesUtil.supports(Capability.SELECT_WITHOUT_FROM, fd.getMethod().getParent(), context.getMetadata(), context.getQueryProcessorFactory().getCapabiltiesFinder())) {
if (elements != null) {
Integer index = (Integer) elements.get(function);
if (index != null) {
return tuple.get(index.intValue());
}
}
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30341, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30341, fd.getFullName()));
}
schema = fd.getSchema();
}
ScalarSubquery ss = null;
if (functionState != null) {
ss = functionState.get(function);
}
Expression[] functionArgs = new Expression[values.length];
for (int i = 0; i < values.length; i++) {
functionArgs[i] = new Constant(values[i]);
}
if (ss == null) {
final Query command = new Query();
Select select = new Select();
command.setSelect(select);
Function f = new Function(function.getName(), functionArgs);
f.setType(function.getType());
f.setFunctionDescriptor(fd);
select.addSymbol(f);
ss = new ScalarSubquery(command);
SymbolMap correlatedReferences = new SymbolMap();
Collection<ElementSymbol> elements = ElementCollectorVisitor.getElements(function, true);
if (!elements.isEmpty()) {
for (ElementSymbol es : elements) {
correlatedReferences.addMapping(es, es);
}
command.setCorrelatedReferences(correlatedReferences);
}
command.setProcessorPlan(new SimpleProcessorPlan(command, schema, fd, Arrays.asList(new Constant(null, fd.getReturnType()))));
} else {
((Function) ((ExpressionSymbol) ss.getCommand().getProjectedSymbols().get(0)).getExpression()).setArgs(functionArgs);
}
if (functionState == null) {
this.functionState = new HashMap<Function, ScalarSubquery>(2);
}
functionState.put(function, ss);
return internalEvaluate(ss, tuple);
}
use of org.teiid.adminapi.impl.VDBMetaData 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.VDBMetaData in project teiid by teiid.
the class RealMetadataFactory method createTransformationMetadata.
public static TransformationMetadata createTransformationMetadata(CompositeMetadataStore store, String vdbName, Properties vdbProperties, FunctionTree... functionModels) {
VDBMetaData vdbMetaData = new VDBMetaData();
// $NON-NLS-1$
vdbMetaData.setName(vdbName);
vdbMetaData.setVersion(1);
if (vdbProperties != null) {
vdbMetaData.setProperties(vdbProperties);
}
List<FunctionTree> udfs = new ArrayList<FunctionTree>();
udfs.addAll(Arrays.asList(functionModels));
for (Schema schema : store.getSchemas().values()) {
vdbMetaData.addModel(RealMetadataFactory.createModel(schema.getName(), schema.isPhysical()));
if (!schema.getFunctions().isEmpty()) {
udfs.add(new FunctionTree(schema.getName(), new UDFSource(schema.getFunctions().values()), true));
}
if (!schema.getProcedures().isEmpty()) {
FunctionTree ft = FunctionTree.getFunctionProcedures(schema);
if (ft != null) {
udfs.add(ft);
}
}
}
TransformationMetadata metadata = new TransformationMetadata(vdbMetaData, store, null, SFM.getSystemFunctions(), udfs);
vdbMetaData.addAttchment(TransformationMetadata.class, metadata);
vdbMetaData.addAttchment(QueryMetadataInterface.class, metadata);
return metadata;
}
use of org.teiid.adminapi.impl.VDBMetaData 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.VDBMetaData in project teiid by teiid.
the class TestSessionServiceImpl method testActiveVDBNameWithVersion.
@Test
public void testActiveVDBNameWithVersion() throws Exception {
VDBRepository repo = Mockito.mock(VDBRepository.class);
VDBMetaData vdb = new VDBMetaData();
vdb.setName("name");
vdb.setVersion(1);
vdb.setStatus(Status.ACTIVE);
Mockito.stub(repo.getLiveVDB("name", "1")).toReturn(vdb);
ssi.setVDBRepository(repo);
ssi.getActiveVDB("name", "1");
Mockito.verify(repo, Mockito.times(1)).getLiveVDB("name", "1");
}
Aggregations