Search in sources :

Example 41 with TeiidComponentException

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") });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) TeiidProcessingException(org.teiid.core.TeiidProcessingException) FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CapabilitiesFinder(org.teiid.query.optimizer.capabilities.CapabilitiesFinder) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) PreparedPlan(org.teiid.dqp.internal.process.PreparedPlan) DDLHolder(org.teiid.query.unittest.RealMetadataFactory.DDLHolder) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 42 with TeiidComponentException

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);
}
Also used : TeiidComponentException(org.teiid.core.TeiidComponentException) HashMap(java.util.HashMap) SymbolMap(org.teiid.query.sql.util.SymbolMap) Map(java.util.Map)

Example 43 with TeiidComponentException

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;
}
Also used : TeiidComponentException(org.teiid.core.TeiidComponentException) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 44 with TeiidComponentException

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;
}
Also used : ArrayList(java.util.ArrayList) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) Expression(org.teiid.query.sql.symbol.Expression) TeiidComponentException(org.teiid.core.TeiidComponentException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 45 with TeiidComponentException

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);
    }
}
Also used : ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) LinkedList(java.util.LinkedList) SaxonXQueryExpression(org.teiid.query.xquery.saxon.SaxonXQueryExpression) Iterator(java.util.Iterator) Collection(java.util.Collection) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidComponentException(org.teiid.core.TeiidComponentException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

TeiidComponentException (org.teiid.core.TeiidComponentException)109 TeiidProcessingException (org.teiid.core.TeiidProcessingException)33 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)23 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)23 ArrayList (java.util.ArrayList)18 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)17 BlockedException (org.teiid.common.buffer.BlockedException)16 IOException (java.io.IOException)15 List (java.util.List)14 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)13 Test (org.junit.Test)12 LanguageObject (org.teiid.query.sql.LanguageObject)12 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)11 CommandContext (org.teiid.query.util.CommandContext)11 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)10 ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)9 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)9 HashMap (java.util.HashMap)7 TeiidException (org.teiid.core.TeiidException)7 LogonException (org.teiid.client.security.LogonException)6