use of org.teiid.api.exception.query.QueryProcessingException 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.api.exception.query.QueryProcessingException in project teiid by teiid.
the class TestTriggerActions method testDynamicRecursion.
@Test
public void testDynamicRecursion() throws Exception {
TransformationMetadata metadata = TestUpdateValidator.example1();
TestUpdateValidator.createView("select 'a' as x, 2 as y", metadata, GX);
Table t = metadata.getMetadataStore().getSchemas().get(VM1).getTables().get(GX);
t.setDeletePlan("FOR EACH ROW BEGIN ATOMIC insert into gx (x, y) values (old.x, old.y); END");
t.setUpdatePlan("");
t.setInsertPlan("FOR EACH ROW BEGIN execute immediate 'delete from gx where gx.x = new.x'; END");
String sql = "insert into gx (x, y) select e1, e2 from pm1.g1";
FakeDataManager dm = new FakeDataManager();
FakeDataStore.addTable("pm1.g1", dm, metadata);
CommandContext context = createCommandContext();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context);
try {
helpProcess(plan, context, dm, null);
fail();
} catch (QueryProcessingException e) {
assertEquals("TEIID30168 Couldn't execute the dynamic SQL command \"EXECUTE IMMEDIATE 'delete from gx where gx.x = new.x'\" with the SQL statement \"delete from gx where gx.x = new.x\" due to: TEIID30347 There is a recursive invocation of group 'I gx'. Please correct the SQL.", e.getMessage());
}
}
use of org.teiid.api.exception.query.QueryProcessingException in project teiid by teiid.
the class TestProcedureProcessor method testDynamicCommandValidationFails.
@Test
public void testDynamicCommandValidationFails() throws Exception {
TransformationMetadata metadata = RealMetadataFactory.example1();
addProc(metadata, "sq2", // $NON-NLS-1$ //$NON-NLS-2$
"CREATE VIRTUAL PROCEDURE BEGIN\n" + "declare object VARIABLES.x; execute string 'SELECT xmlelement(name elem, x)'; select '1', 2; END", new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER }, new String[] { "in" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
// $NON-NLS-1$
String userUpdateStr = "EXEC pm1.sq2('First')";
FakeDataManager dataMgr = exampleDataManager(metadata);
ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
try {
helpTestProcess(plan, null, dataMgr, metadata);
fail("exception expected");
} catch (QueryProcessingException e) {
}
}
use of org.teiid.api.exception.query.QueryProcessingException in project teiid by teiid.
the class TestProcedureProcessor method testDyanmicAnonBlockWithReturn.
@Test
public void testDyanmicAnonBlockWithReturn() throws Exception {
// $NON-NLS-1$
String sql = "begin execute immediate 'begin select 1; select 1, 2; end'; end";
TransformationMetadata tm = RealMetadataFactory.example1Cached();
ProcessorPlan plan = getProcedurePlan(sql, tm);
HardcodedDataManager dataManager = new HardcodedDataManager(tm);
// $NON-NLS-1$
List[] expected = new List[] {};
helpTestProcess(plan, expected, dataManager, tm);
// $NON-NLS-1$
sql = "begin execute immediate 'begin select 1; select 1, 2; end' as y string; end";
tm = RealMetadataFactory.example1Cached();
plan = getProcedurePlan(sql, tm);
try {
helpTestProcess(plan, expected, dataManager, tm);
fail();
} catch (QueryProcessingException e) {
}
}
use of org.teiid.api.exception.query.QueryProcessingException in project teiid by teiid.
the class TempTableDataManager method handleSystemProcedures.
private TupleSource handleSystemProcedures(final CommandContext context, StoredProcedure proc) throws TeiidComponentException, QueryMetadataException, QueryProcessingException, QueryResolverException, QueryValidatorException, TeiidProcessingException, ExpressionEvaluationException {
final QueryMetadataInterface metadata = context.getMetadata();
if (StringUtil.endsWithIgnoreCase(proc.getProcedureCallableName(), REFRESHMATVIEW)) {
Object groupID = validateMatView(metadata, (String) ((Constant) proc.getParameter(2).getExpression()).getValue());
TempMetadataID matTableId = context.getGlobalTableStore().getGlobalTempTableMetadataId(groupID);
final GlobalTableStore globalStore = getGlobalStore(context, matTableId);
String matViewName = metadata.getFullName(groupID);
String matTableName = metadata.getFullName(matTableId);
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_MATVIEWS, "processing refreshmatview for", matViewName);
boolean invalidate = Boolean.TRUE.equals(((Constant) proc.getParameter(3).getExpression()).getValue());
boolean needsLoading = globalStore.getMatTableInfo(matTableName).getAndClearAsynch();
if (!needsLoading) {
needsLoading = globalStore.needsLoading(matTableName, globalStore.getAddress(), true, true, invalidate);
if (needsLoading) {
needsLoading = globalStore.needsLoading(matTableName, globalStore.getAddress(), false, false, invalidate);
}
}
if (!needsLoading) {
return CollectionTupleSource.createUpdateCountTupleSource(-1);
}
GroupSymbol matTable = new GroupSymbol(matTableName);
matTable.setMetadataID(matTableId);
return loadGlobalTable(context, matTable, matTableName, globalStore);
} else if (StringUtil.endsWithIgnoreCase(proc.getProcedureCallableName(), REFRESHMATVIEWROWS)) {
final Object groupID = validateMatView(metadata, (String) ((Constant) proc.getParameter(2).getExpression()).getValue());
TempMetadataID matTableId = context.getGlobalTableStore().getGlobalTempTableMetadataId(groupID);
final GlobalTableStore globalStore = getGlobalStore(context, matTableId);
Object pk = metadata.getPrimaryKey(groupID);
String matViewName = metadata.getFullName(groupID);
if (pk == null) {
throw new QueryProcessingException(QueryPlugin.Event.TEIID30230, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30230, matViewName));
}
List<?> ids = metadata.getElementIDsInKey(pk);
Object[][] params = (Object[][]) ((ArrayImpl) ((Constant) proc.getParameter(3).getExpression()).getValue()).getValues();
return updateMatviewRows(context, metadata, groupID, globalStore, matViewName, ids, params);
} else if (StringUtil.endsWithIgnoreCase(proc.getProcedureCallableName(), REFRESHMATVIEWROW)) {
final Object groupID = validateMatView(metadata, (String) ((Constant) proc.getParameter(2).getExpression()).getValue());
TempMetadataID matTableId = context.getGlobalTableStore().getGlobalTempTableMetadataId(groupID);
final GlobalTableStore globalStore = getGlobalStore(context, matTableId);
Object pk = metadata.getPrimaryKey(groupID);
final String matViewName = metadata.getFullName(groupID);
if (pk == null) {
throw new QueryProcessingException(QueryPlugin.Event.TEIID30230, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30230, matViewName));
}
List<?> ids = metadata.getElementIDsInKey(pk);
Constant key = (Constant) proc.getParameter(3).getExpression();
Object initialValue = key.getValue();
SPParameter keyOther = proc.getParameter(4);
Object[] param = null;
if (keyOther != null) {
Object[] otherCols = ((ArrayImpl) ((Constant) keyOther.getExpression()).getValue()).getValues();
if (otherCols != null) {
param = new Object[1 + otherCols.length];
param[0] = initialValue;
for (int i = 0; i < otherCols.length; i++) {
param[i + 1] = otherCols[i];
}
}
}
if (param == null) {
param = new Object[] { initialValue };
}
Object[][] params = new Object[][] { param };
return updateMatviewRows(context, metadata, groupID, globalStore, matViewName, ids, params);
}
return null;
}
Aggregations