use of org.teiid.query.sql.lang.SourceHint in project teiid by teiid.
the class TestConnectorWorkItem method testSourcHints.
@Test
public void testSourcHints() throws Exception {
// $NON-NLS-1$
Command command = helpGetCommand("update bqt1.smalla set stringkey = 1 where stringkey = 2", EXAMPLE_BQT);
command.setSourceHint(new SourceHint());
AtomicRequestMessage arm = createNewAtomicRequestMessage(1, 1);
arm.setCommand(command);
ConnectorManager cm = TestConnectorManager.getConnectorManager();
cm.registerRequest(arm);
}
use of org.teiid.query.sql.lang.SourceHint in project teiid by teiid.
the class ProjectIntoNode method nextBatchDirect.
/**
* Get batch from child node
* Walk through each row of child batch
* Bind values to insertCommand
* Execute insertCommand
* Update insertCount
* When no more data is available, output batch with single row containing insertCount
*/
public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
while (phase == REQUEST_CREATION) {
/* If we don't have a batch to work, get the next
*/
if (currentBatch == null) {
if (sourceDone) {
phase = RESPONSE_PROCESSING;
break;
}
// can throw BlockedException
currentBatch = getChildren()[0].nextBatch();
sourceDone = currentBatch.getTerminationFlag();
this.batchRow = currentBatch.getBeginRow();
// and for implicit temp tables we need to issue an empty insert
if (currentBatch.getRowCount() == 0 && (!currentBatch.getTerminationFlag() || mode != Mode.ITERATOR)) {
currentBatch = null;
continue;
}
if (this.constraint != null) {
// row based security check
if (eval == null) {
eval = new Evaluator(createLookupMap(this.intoElements), this.getDataManager(), getContext());
}
List<List<?>> tuples = this.currentBatch.getTuples();
for (int i = 0; i < tuples.size(); i++) {
if (!eval.evaluate(constraint, tuples.get(i))) {
throw new QueryProcessingException(QueryPlugin.Event.TEIID31130, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31130, new Insert(intoGroup, this.intoElements, convertValuesToConstants(tuples.get(i), intoElements))));
}
}
}
}
if (mode != Mode.ITERATOR) {
// delay the check in the iterator case to accumulate batches
checkExitConditions();
}
int batchSize = currentBatch.getRowCount();
int requests = 1;
switch(mode) {
case ITERATOR:
if (buffer == null) {
buffer = getBufferManager().createTupleBuffer(intoElements, getConnectionID(), TupleSourceType.PROCESSOR);
}
if (sourceDone) {
// if there is a pending request we can't process the last until it is done
checkExitConditions();
}
for (List<?> tuple : currentBatch.getTuples()) {
buffer.addTuple(tuple);
}
try {
checkExitConditions();
} catch (BlockedException e) {
// move to the next batch
this.batchRow += batchSize;
currentBatch = null;
continue;
}
if (currentBatch.getTerminationFlag() && (buffer.getRowCount() != 0 || intoGroup.isImplicitTempGroupSymbol())) {
registerIteratorRequest();
} else if (buffer.getRowCount() >= buffer.getBatchSize() * 4) {
registerIteratorRequest();
} else {
requests = 0;
}
break;
case BATCH:
// Register batched update command against source
long endRow = currentBatch.getEndRow();
List<Command> rows = new ArrayList<Command>((int) (endRow - batchRow));
for (long rowNum = batchRow; rowNum <= endRow; rowNum++) {
Insert insert = new Insert(intoGroup, intoElements, convertValuesToConstants(currentBatch.getTuple(rowNum), intoElements));
insert.setSourceHint(sourceHint);
insert.setUpsert(upsert);
rows.add(insert);
}
registerRequest(new BatchedUpdateCommand(rows));
break;
case SINGLE:
batchSize = 1;
// Register insert command against source
// Defect 16036 - submit a new INSERT command to the DataManager.
Insert insert = new Insert(intoGroup, intoElements, convertValuesToConstants(currentBatch.getTuple(batchRow), intoElements));
insert.setSourceHint(sourceHint);
insert.setUpsert(upsert);
registerRequest(insert);
}
this.batchRow += batchSize;
if (batchRow > currentBatch.getEndRow()) {
currentBatch = null;
}
this.requestsRegistered += requests;
}
checkExitConditions();
if (this.buffer != null) {
this.buffer.remove();
this.buffer = null;
}
// End this node's work
// report only a max int
int count = (int) Math.min(Integer.MAX_VALUE, insertCount);
addBatchRow(Arrays.asList(count));
terminateBatches();
return pullBatch();
}
use of org.teiid.query.sql.lang.SourceHint in project teiid by teiid.
the class RulePlaceAccess method addAccessNode.
/**
* Adds a access node if the node is a source leaf node.
*
* @param metadata
* @param sourceNode
* @return true if the source node has an access pattern
* @throws QueryMetadataException
* @throws TeiidComponentException
*/
private void addAccessNode(QueryMetadataInterface metadata, PlanNode sourceNode, CapabilitiesFinder finder, boolean[] additionalRules) throws QueryMetadataException, TeiidComponentException {
boolean isInsert = false;
Object req = sourceNode.getProperty(NodeConstants.Info.ATOMIC_REQUEST);
if (req == null) {
req = sourceNode.getProperty(NodeConstants.Info.NESTED_COMMAND);
}
if (sourceNode.getProperty(NodeConstants.Info.TABLE_FUNCTION) != null) {
return;
}
if (req instanceof Insert) {
isInsert = true;
} else {
PlanNode parent = sourceNode.getParent();
if (parent.getType() == NodeConstants.Types.PROJECT && parent.getProperty(NodeConstants.Info.INTO_GROUP) != null) {
isInsert = true;
}
}
PlanNode apNode = sourceNode;
if (sourceNode.getChildCount() == 0) {
// Create the access node and insert
PlanNode accessNode = NodeFactory.getNewNode(NodeConstants.Types.ACCESS);
accessNode.addGroups(sourceNode.getGroups());
copyProperties(sourceNode, accessNode);
SourceHint sourceHint = (SourceHint) sourceNode.removeProperty(Info.SOURCE_HINT);
// TODO: trim the hint to only the sources possible under this model (typically 1, but could be more in
// multi-source
accessNode.setProperty(Info.SOURCE_HINT, sourceHint);
Object hint = sourceNode.removeProperty(NodeConstants.Info.IS_OPTIONAL);
if (hint != null) {
accessNode.setProperty(NodeConstants.Info.IS_OPTIONAL, hint);
}
Object modelId = null;
if (sourceNode.getGroups().size() == 1) {
GroupSymbol gs = sourceNode.getGroups().iterator().next();
modelId = gs.getModelMetadataId();
if (modelId != null) {
accessNode.setProperty(NodeConstants.Info.MODEL_ID, modelId);
}
}
if (req instanceof Create || req instanceof Drop) {
modelId = TempMetadataAdapter.TEMP_MODEL;
} else {
modelId = RuleRaiseAccess.getModelIDFromAccess(accessNode, metadata);
}
if (modelId != null) {
boolean multiSource = metadata.isMultiSource(modelId);
if (multiSource) {
accessNode.setProperty(Info.IS_MULTI_SOURCE, multiSource);
}
accessNode.setProperty(NodeConstants.Info.MODEL_ID, modelId);
}
if (req == null && modelId != null) {
// add "conformed" sources if they exist
GroupSymbol group = sourceNode.getGroups().iterator().next();
Object gid = group.getMetadataID();
String sources = metadata.getExtensionProperty(gid, CONFORMED_SOURCES, false);
if (sources != null) {
Set<Object> conformed = new LinkedHashSet<Object>();
conformed.add(modelId);
for (String source : StringUtil.split(sources, ",")) {
// $NON-NLS-1$
Object mid = metadata.getModelID(source.trim());
if (metadata.isVirtualModel(mid)) {
// TODO: could validate this up-front
throw new QueryMetadataException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31148, metadata.getName(mid), group));
}
conformed.add(mid);
}
accessNode.setProperty(Info.CONFORMED_SOURCES, conformed);
}
}
// Insert
sourceNode.addAsParent(accessNode);
apNode = accessNode;
// set additional information
for (GroupSymbol group : accessNode.getGroups()) {
if (group.getCheckMatViewStatus() != null) {
LinkedHashSet<Object> viewsToCheck = new LinkedHashSet<Object>();
viewsToCheck.add(group.getCheckMatViewStatus());
accessNode.setProperty(Info.CHECK_MAT_VIEW, viewsToCheck);
}
Object modelID = metadata.getModelID(group.getMetadataID());
if (CapabilitiesUtil.requiresCriteria(modelID, metadata, finder)) {
additionalRules[1] = true;
}
}
}
// Add access pattern(s), if any, as property of access node
if (!isInsert && addAccessPatternsProperty(apNode, metadata)) {
additionalRules[0] = true;
}
}
Aggregations