Search in sources :

Example 41 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class ValidationVisitor method visit.

@Override
public void visit(ObjectTable obj) {
    List<DerivedColumn> passing = obj.getPassing();
    TreeSet<String> names = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    for (DerivedColumn dc : passing) {
        if (dc.getAlias() == null) {
            // $NON-NLS-1$
            handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.context_item_not_allowed"), obj);
        } else if (!names.add(dc.getAlias())) {
            // $NON-NLS-1$
            handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.duplicate_passing", dc.getAlias()), obj);
        }
    }
    Compilable scriptCompiler = null;
    try {
        ScriptEngine engine = this.getMetadata().getScriptEngine(obj.getScriptingLanguage());
        obj.setScriptEngine(engine);
        if (engine instanceof Compilable) {
            scriptCompiler = (Compilable) engine;
            engine.put(ScriptEngine.FILENAME, SQLConstants.NonReserved.OBJECTTABLE);
            obj.setCompiledScript(scriptCompiler.compile(obj.getRowScript()));
        }
    } catch (TeiidProcessingException e) {
        handleValidationError(e.getMessage(), obj);
    } catch (ScriptException e) {
        // $NON-NLS
        handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31110, obj.getRowScript(), e.getMessage()), obj);
    }
    for (ObjectColumn xc : obj.getColumns()) {
        if (scriptCompiler != null) {
            try {
                xc.setCompiledScript(scriptCompiler.compile(xc.getPath()));
            } catch (ScriptException e) {
                // $NON-NLS
                handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31110, xc.getPath(), e.getMessage()), obj);
            }
        }
        if (xc.getDefaultExpression() != null && !EvaluatableVisitor.isFullyEvaluatable(xc.getDefaultExpression(), false)) {
            // $NON-NLS-1$
            handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.invalid_default", xc.getDefaultExpression()), obj);
        }
    }
}
Also used : ScriptException(javax.script.ScriptException) TreeSet(java.util.TreeSet) Compilable(javax.script.Compilable) ObjectColumn(org.teiid.query.sql.lang.ObjectTable.ObjectColumn) ScriptEngine(javax.script.ScriptEngine) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 42 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class TempTableDataManager method registerQuery.

private TupleSource registerQuery(final CommandContext context, final TempTableStore contextStore, final Query query) {
    final GroupSymbol group = query.getFrom().getGroups().get(0);
    if (!group.isTempGroupSymbol()) {
        return null;
    }
    final String tableName = group.getNonCorrelationName();
    if (group.isGlobalTable()) {
        TempMetadataID matTableId = (TempMetadataID) group.getMetadataID();
        final GlobalTableStore globalStore = getGlobalStore(context, matTableId);
        final MatTableInfo info = globalStore.getMatTableInfo(tableName);
        return new ProxyTupleSource() {

            Future<Void> moreWork = null;

            TupleSource loadingTupleSource;

            DQPWorkContext newWorkContext;

            @Override
            protected TupleSource createTupleSource() throws TeiidComponentException, TeiidProcessingException {
                if (loadingTupleSource != null) {
                    load();
                } else {
                    boolean load = false;
                    if (!info.isUpToDate()) {
                        boolean invalidate = shouldInvalidate(context.getVdb());
                        load = globalStore.needsLoading(tableName, globalStore.getAddress(), true, false, info.isValid() && invalidate);
                        if (load) {
                            load = globalStore.needsLoading(tableName, globalStore.getAddress(), false, false, info.isValid() && invalidate);
                        }
                        if (!load) {
                            synchronized (info) {
                                if (!info.isUpToDate()) {
                                    RequestWorkItem workItem = context.getWorkItem();
                                    info.addWaiter(workItem);
                                    if (moreWork != null) {
                                        moreWork.cancel(false);
                                    }
                                    // fail-safe - attempt again in 10 seconds
                                    moreWork = workItem.scheduleWork(10000);
                                    // $NON-NLS-1$
                                    throw BlockedException.block("Blocking on mat view load", tableName);
                                }
                            }
                        } else {
                            if (!info.isValid() || executor == null) {
                                // TODO: we should probably do all loads using a temp session
                                if (info.getVdbMetaData() != null && context.getDQPWorkContext() != null && !info.getVdbMetaData().getFullName().equals(context.getDQPWorkContext().getVDB().getFullName())) {
                                    assert executor != null;
                                    // load with by pretending we're in the imported vdb
                                    newWorkContext = createWorkContext(context, info.getVdbMetaData());
                                    CommandContext newContext = context.clone();
                                    newContext.setNewVDBState(newWorkContext);
                                    loadingTupleSource = loadGlobalTable(newContext, group, tableName, newContext.getGlobalTableStore());
                                } else {
                                    loadingTupleSource = loadGlobalTable(context, group, tableName, globalStore);
                                }
                                load();
                            } else {
                                loadViaRefresh(context, tableName, context.getDQPWorkContext().getVDB(), info);
                            }
                        }
                    }
                }
                TempTable table = globalStore.getTempTable(tableName);
                context.accessedDataObject(group.getMetadataID());
                if (context.isParallel() && query.getCriteria() == null && query.getOrderBy() != null && table.getRowCount() > MIN_ASYNCH_SIZE) {
                    return new AsyncTupleSource(new Callable<TupleSource>() {

                        @Override
                        public TupleSource call() throws Exception {
                            synchronized (this) {
                                TupleSource result = table.createTupleSource(query.getProjectedSymbols(), query.getCriteria(), query.getOrderBy());
                                cancelMoreWork();
                                return result;
                            }
                        }
                    }, context);
                }
                TupleSource result = table.createTupleSource(query.getProjectedSymbols(), query.getCriteria(), query.getOrderBy());
                cancelMoreWork();
                return result;
            }

            private void load() throws TeiidComponentException, TeiidProcessingException {
                try {
                    if (newWorkContext != null) {
                        newWorkContext.runInContext(new Callable<Void>() {

                            @Override
                            public Void call() throws Exception {
                                loadingTupleSource.nextTuple();
                                return null;
                            }
                        });
                    } else {
                        loadingTupleSource.nextTuple();
                    }
                } catch (Throwable e) {
                    rethrow(e);
                }
            }

            private void cancelMoreWork() {
                if (moreWork != null) {
                    moreWork.cancel(false);
                    moreWork = null;
                }
            }

            @Override
            public void closeSource() {
                if (loadingTupleSource != null) {
                    loadingTupleSource.closeSource();
                }
                super.closeSource();
                cancelMoreWork();
            }
        };
    }
    // it's not expected for a blocked exception to bubble up from here, so return a tuplesource to perform getOrCreateTempTable
    return new ProxyTupleSource() {

        @Override
        protected TupleSource createTupleSource() throws TeiidComponentException, TeiidProcessingException {
            TempTableStore tts = contextStore;
            TempTable tt = tts.getOrCreateTempTable(tableName, query, bufferManager, true, false, context, group);
            if (context.getDataObjects() != null) {
                Object id = RelationalPlanner.getTrackableGroup(group, context.getMetadata());
                if (id != null) {
                    context.accessedDataObject(id);
                }
            }
            if (context.isParallel() && query.getCriteria() == null && query.getOrderBy() != null && tt.getRowCount() > MIN_ASYNCH_SIZE) {
                return new AsyncTupleSource(new Callable<TupleSource>() {

                    @Override
                    public TupleSource call() throws Exception {
                        synchronized (this) {
                            return tt.createTupleSource(query.getProjectedSymbols(), query.getCriteria(), query.getOrderBy());
                        }
                    }
                }, context);
            }
            return tt.createTupleSource(query.getProjectedSymbols(), query.getCriteria(), query.getOrderBy());
        }
    };
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) RequestWorkItem(org.teiid.dqp.internal.process.RequestWorkItem) CommandContext(org.teiid.query.util.CommandContext) TempMetadataID(org.teiid.query.metadata.TempMetadataID) QueryProcessingException(org.teiid.api.exception.query.QueryProcessingException) TeiidComponentException(org.teiid.core.TeiidComponentException) TransformationException(org.teiid.core.types.TransformationException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) BlockedException(org.teiid.common.buffer.BlockedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) TupleSource(org.teiid.common.buffer.TupleSource) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) MatTableInfo(org.teiid.query.tempdata.GlobalTableStoreImpl.MatTableInfo) Future(java.util.concurrent.Future)

Example 43 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class TempTableStore method getSynchronization.

private TempTableSynchronization getSynchronization(CommandContext context) throws TeiidProcessingException {
    TempTableSynchronization synch = null;
    if (context == null || transactionMode == TransactionMode.NONE) {
        return null;
    }
    TransactionContext tc = context.getTransactionContext();
    if (tc == null || tc.getTransactionType() == Scope.NONE) {
        return null;
    }
    String transactionId = tc.getTransactionId();
    synch = synchronizations.get(transactionId);
    if (synch == null) {
        boolean success = false;
        try {
            synch = new TempTableSynchronization(transactionId);
            synchronizations.put(transactionId, synch);
            tc.getTransaction().registerSynchronization(synch);
            success = true;
        } catch (RollbackException e) {
            throw new TeiidProcessingException(QueryPlugin.Event.TEIID30223, e);
        } catch (SystemException e) {
            throw new TeiidProcessingException(QueryPlugin.Event.TEIID30224, e);
        } finally {
            if (!success) {
                synchronizations.remove(transactionId);
            }
        }
    }
    return synch;
}
Also used : SystemException(javax.transaction.SystemException) TransactionContext(org.teiid.dqp.service.TransactionContext) RollbackException(javax.transaction.RollbackException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 44 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class StatementImpl method postReceiveResults.

private synchronized void postReceiveResults(RequestMessage reqMessage, ResultsMessage resultsMsg) throws TeiidSQLException, SQLException {
    commandStatus = State.DONE;
    // warnings thrown
    List resultsWarning = resultsMsg.getWarnings();
    // save warnings if have any
    if (resultsWarning != null) {
        accumulateWarnings(resultsWarning);
    }
    setAnalysisInfo(resultsMsg);
    // throw an exception unless this represents a batch update exception
    if (resultsMsg.getException() != null && (!resultsMsg.isUpdateResult() || resultsMsg.getResultsList() == null)) {
        throw TeiidSQLException.create(resultsMsg.getException());
    }
    resultsMsg.processResults();
    if (resultsMsg.isUpdateResult()) {
        List<? extends List<?>> results = resultsMsg.getResultsList();
        if (resultsMsg.getUpdateCount() == -1) {
            this.updateCounts = new int[results.size()];
            for (int i = 0; i < results.size(); i++) {
                updateCounts[i] = (Integer) results.get(i).get(0);
            }
        } else {
            this.updateCounts = new int[] { resultsMsg.getUpdateCount() };
            this.createResultSet(resultsMsg);
        }
        if (logger.isLoggable(Level.FINER)) {
            // $NON-NLS-1$
            logger.finer("Recieved update counts: " + Arrays.toString(updateCounts));
        }
        // In update scenarios close the statement implicitly - the server should have already done this
        try {
            getDQP().closeRequest(getCurrentRequestID());
        } catch (TeiidProcessingException e) {
            throw TeiidSQLException.create(e);
        } catch (TeiidComponentException e) {
            throw TeiidSQLException.create(e);
        }
        // handle a batch update exception
        if (resultsMsg.getException() != null) {
            TeiidSQLException exe = TeiidSQLException.create(resultsMsg.getException());
            BatchUpdateException batchUpdateException = new BatchUpdateException(exe.getMessage(), exe.getSQLState(), exe.getErrorCode(), updateCounts, exe);
            this.updateCounts = null;
            throw batchUpdateException;
        }
    } else {
        createResultSet(resultsMsg);
    }
    if (logger.isLoggable(Level.FINE)) {
        // $NON-NLS-1$
        logger.fine(JDBCPlugin.Util.getString("MMStatement.Success_query", reqMessage.getCommandString()));
    }
}
Also used : TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) BatchUpdateException(java.sql.BatchUpdateException)

Example 45 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class PlanToProcessConverter method convert.

public RelationalPlan convert(PlanNode planNode) throws QueryPlannerException, TeiidComponentException {
    try {
        boolean debug = analysisRecord.recordDebug();
        if (debug) {
            // $NON-NLS-1$
            analysisRecord.println("\n============================================================================");
            // $NON-NLS-1$
            analysisRecord.println("CONVERTING PLAN TREE TO PROCESS TREE");
        }
        // Convert plan tree nodes into process tree nodes
        RelationalNode processNode;
        try {
            processNode = convertPlan(planNode);
        } catch (TeiidProcessingException e) {
            if (e instanceof QueryPlannerException) {
                throw (QueryPlannerException) e;
            }
            throw new QueryPlannerException(e);
        }
        if (debug) {
            // $NON-NLS-1$
            analysisRecord.println("\nPROCESS PLAN = \n" + processNode);
            // $NON-NLS-1$
            analysisRecord.println("============================================================================");
        }
        RelationalPlan processPlan = new RelationalPlan(processNode);
        return processPlan;
    } finally {
        sharedCommands.clear();
    }
}
Also used : QueryPlannerException(org.teiid.api.exception.query.QueryPlannerException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Aggregations

TeiidProcessingException (org.teiid.core.TeiidProcessingException)92 TeiidComponentException (org.teiid.core.TeiidComponentException)30 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)17 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)17 SQLException (java.sql.SQLException)16 BlockedException (org.teiid.common.buffer.BlockedException)16 Test (org.junit.Test)14 CommandContext (org.teiid.query.util.CommandContext)14 LanguageObject (org.teiid.query.sql.LanguageObject)13 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)13 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)12 List (java.util.List)11 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)10 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)10 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)9 TupleSource (org.teiid.common.buffer.TupleSource)9 TupleBatch (org.teiid.common.buffer.TupleBatch)8 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)7 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)6