use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class TestFunctionPushdown method testSimpleFunctionPushdown2.
@Test
public void testSimpleFunctionPushdown2() throws Exception {
TransformationMetadata tm = RealMetadataFactory.fromDDL("x", new DDLHolder("y", "CREATE FOREIGN FUNCTION func(a object, b object) RETURNS string;"), new DDLHolder("z", "CREATE FOREIGN FUNCTION func1(a object, b object) RETURNS string; create foreign table g1 (e1 object)"));
BasicSourceCapabilities bsc = new BasicSourceCapabilities();
bsc.setCapabilitySupport(Capability.SELECT_WITHOUT_FROM, true);
bsc.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
final DefaultCapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(bsc);
CommandContext cc = TestProcessor.createCommandContext();
cc.setQueryProcessorFactory(new QueryProcessor.ProcessorFactory() {
@Override
public PreparedPlan getPreparedPlan(String query, String recursionGroup, CommandContext commandContext, QueryMetadataInterface metadata) throws TeiidProcessingException, TeiidComponentException {
return null;
}
@Override
public CapabilitiesFinder getCapabiltiesFinder() {
return capFinder;
}
@Override
public QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext, Object... params) throws TeiidProcessingException, TeiidComponentException {
// TODO Auto-generated method stub
return null;
}
});
cc.setMetadata(tm);
// $NON-NLS-1$
String sql = "select e1 from g1 where func(1, 1) = '2'";
ProcessorPlan plan = helpPlan(sql, tm, null, capFinder, new String[] { "SELECT z.g1.e1 FROM z.g1 WHERE func(1, 1) = '2'" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
HardcodedDataManager dataManager = new HardcodedDataManager(tm);
dataManager.addData("SELECT func(1, 1)", new List[] { Arrays.asList("hello world") });
TestProcessor.helpProcess(plan, cc, dataManager, new List[] {});
// $NON-NLS-1$
sql = "select e1 from g1 where func1(1, 1) = '2'";
plan = helpPlan(sql, tm, null, capFinder, new String[] { "SELECT z.g1.e1 FROM z.g1 WHERE func1(1, 1) = '2'" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
dataManager = new HardcodedDataManager(tm);
dataManager.addData("SELECT g1.e1 FROM g1 WHERE func1(1, 1) = '2'", new List[] { Arrays.asList("hello world") });
TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList("hello world") });
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class FakeDataManager method lookupCodeValue.
public Object lookupCodeValue(CommandContext context, String codeTableName, String returnElementName, String keyElementName, Object keyValue) throws BlockedException, TeiidComponentException {
String tableKey = codeTableName.toUpperCase() + keyElementName.toUpperCase() + returnElementName.toUpperCase();
if (!codeTableValues.containsKey(tableKey)) {
// $NON-NLS-1$
throw new TeiidComponentException("Unknown code table: " + codeTableName);
}
if (throwBlocked) {
if (blockedState.get(tableKey).equals(Boolean.FALSE)) {
blockedState.put(tableKey, Boolean.TRUE);
throw BlockedException.INSTANCE;
}
}
Map values = codeTableValues.get(tableKey);
return values.get(keyValue);
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class FakeProcessorPlan method nextBatch.
/**
* @see org.teiid.query.processor.ProcessorPlan#nextBatch()
*/
public TupleBatch nextBatch() throws BlockedException, TeiidComponentException {
if (this.batches == null || this.batches.size() == 0 || batchIndex >= this.batches.size()) {
// Return empty terminator batch
TupleBatch batch = new TupleBatch(nextBatchRow, Collections.EMPTY_LIST);
batch.setTerminationFlag(true);
return batch;
}
Object nextReturn = this.batches.get(batchIndex);
batchIndex++;
if (nextReturn instanceof TupleBatch) {
TupleBatch batch = (TupleBatch) nextReturn;
nextBatchRow = nextBatchRow + batch.getRowCount();
return batch;
}
throw (TeiidComponentException) nextReturn;
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class HardcodedDataManager method registerRequest.
/**
* @see org.teiid.query.processor.ProcessorDataManager#registerRequest(CommandContext, org.teiid.query.sql.lang.Command, java.lang.String, RegisterRequestParameter)
* @since 4.2
*/
public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
if (modelName != null && validModels != null && !validModels.contains(modelName)) {
// $NON-NLS-1$//$NON-NLS-2$
throw new TeiidComponentException("Detected query against invalid model: " + modelName + ": " + command);
}
this.commandHistory.add(command);
List<Expression> projectedSymbols = command.getProjectedSymbols();
String commandString = null;
if (lbf == null) {
if (command instanceof BatchedUpdateCommand && fullBatchedUpdate) {
commandString = ((BatchedUpdateCommand) command).getStringForm(true);
} else {
commandString = command.toString();
}
} else {
org.teiid.language.Command cmd = lbf.translate(command);
this.pushdownCommands.add(cmd);
commandString = cmd.toString();
}
List<?>[] rows = getData(commandString);
if (rows == null) {
if (mustRegisterCommands) {
// $NON-NLS-1$
throw new TeiidComponentException("Unknown command: " + commandString);
}
// Create one row of nulls
rows = new List[1];
rows[0] = new ArrayList();
for (int i = 0; i < projectedSymbols.size(); i++) {
rows[0].add(null);
}
}
FakeTupleSource source = new FakeTupleSource(projectedSymbols, rows);
if (blockOnce) {
source.setBlockOnce();
}
return source;
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class ValidationVisitor method validateInsert.
protected void validateInsert(Insert obj) {
Collection<ElementSymbol> vars = obj.getVariables();
Iterator<ElementSymbol> varIter = vars.iterator();
Collection values = obj.getValues();
Iterator valIter = values.iterator();
GroupSymbol insertGroup = obj.getGroup();
try {
Set<ElementSymbol> seen = new HashSet<ElementSymbol>();
boolean multiSource = getMetadata().isMultiSource(getMetadata().getModelID(insertGroup.getMetadataID()));
// Validate that all elements in variable list are updatable
for (ElementSymbol insertElem : vars) {
if (!getMetadata().elementSupports(insertElem.getMetadataID(), SupportConstants.Element.UPDATE) && !isUpsertKeyColumn(obj, insertElem)) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0052", insertElem), insertElem);
}
if (multiSource && getMetadata().isMultiSourceElement(insertElem.getMetadataID())) {
multiSource = false;
}
if (!seen.add(insertElem)) {
handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31179, obj.getGroup(), insertElem), insertElem);
}
}
if (multiSource) {
validateMultisourceInsert(insertGroup);
}
// Get elements in the group.
Collection<ElementSymbol> insertElmnts = new LinkedList<ElementSymbol>(ResolverUtil.resolveElementsInGroup(insertGroup, getMetadata()));
// remove all elements specified in insert to get the ignored elements
insertElmnts.removeAll(vars);
for (ElementSymbol nextElmnt : insertElmnts) {
if (!getMetadata().elementSupports(nextElmnt.getMetadataID(), SupportConstants.Element.DEFAULT_VALUE) && !getMetadata().elementSupports(nextElmnt.getMetadataID(), SupportConstants.Element.NULL) && !getMetadata().elementSupports(nextElmnt.getMetadataID(), SupportConstants.Element.AUTO_INCREMENT)) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0053", new Object[] { insertGroup, nextElmnt }), nextElmnt);
}
}
// if any of the value present in the insert are null
while (valIter.hasNext() && varIter.hasNext()) {
Expression nextValue = (Expression) valIter.next();
ElementSymbol nextVar = varIter.next();
if (EvaluatableVisitor.isFullyEvaluatable(nextValue, true)) {
try {
// If nextValue is an expression, evaluate it before checking for null
Object evaluatedValue = Evaluator.evaluate(nextValue);
if (evaluatedValue == null && !getMetadata().elementSupports(nextVar.getMetadataID(), SupportConstants.Element.NULL)) {
// as an upsert key it can mean an insert
if (!isUpsertKeyColumn(obj, nextVar) || !(getMetadata().elementSupports(nextVar.getMetadataID(), SupportConstants.Element.AUTO_INCREMENT) || getMetadata().elementSupports(nextVar.getMetadataID(), SupportConstants.Element.DEFAULT_VALUE))) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0055", nextVar), nextVar);
}
}
} catch (ExpressionEvaluationException e) {
// ignore for now, we don't have the context which could be the problem
}
}
}
// end of while
} catch (TeiidComponentException e) {
handleException(e, obj);
}
}
Aggregations