Search in sources :

Example 46 with TeiidComponentException

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

the class ValidationVisitor method visit.

public void visit(Insert obj) {
    validateGroupSupportsUpdate(obj.getGroup());
    validateInsert(obj);
    try {
        if (obj.isUpsert()) {
            Collection keys = getMetadata().getUniqueKeysInGroup(obj.getGroup().getMetadataID());
            if (keys.isEmpty()) {
                handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31132, obj.getGroup()), obj);
            } else {
                Set<Object> keyCols = new LinkedHashSet<Object>(getMetadata().getElementIDsInKey(keys.iterator().next()));
                for (ElementSymbol es : obj.getVariables()) {
                    keyCols.remove(es.getMetadataID());
                }
                if (!keyCols.isEmpty()) {
                    handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31133, obj.getGroup(), obj.getVariables()), obj);
                }
            }
        }
    } catch (QueryMetadataException e1) {
        handleException(e1);
    } catch (TeiidComponentException e1) {
        handleException(e1);
    }
    if (obj.getQueryExpression() != null) {
        validateMultisourceInsert(obj.getGroup());
    }
    if (obj.getUpdateInfo() != null && obj.getUpdateInfo().isInherentInsert()) {
        validateUpdate(obj, Command.TYPE_INSERT, obj.getUpdateInfo());
        try {
            if (obj.getUpdateInfo().findInsertUpdateMapping(obj, false) == null) {
                handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30376, obj.getVariables()), obj);
            }
        } catch (QueryValidatorException e) {
            handleValidationError(e.getMessage(), obj);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) Collection(java.util.Collection) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException)

Example 47 with TeiidComponentException

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

the class ValidationVisitor method validateInto.

private void validateInto(LanguageObject query, List<Expression> symbols, GroupSymbol intoGroup) {
    try {
        List elementIDs = getMetadata().getElementIDsInGroupID(intoGroup.getMetadataID());
        // Check if there are too many elements in the SELECT clause
        if (symbols.size() != elementIDs.size()) {
            // $NON-NLS-1$
            handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.select_into_wrong_elements", new Object[] { new Integer(elementIDs.size()), new Integer(symbols.size()) }), query);
            return;
        }
        for (int symbolNum = 0; symbolNum < symbols.size(); symbolNum++) {
            Expression symbol = symbols.get(symbolNum);
            Object elementID = elementIDs.get(symbolNum);
            // Check if supports updates
            if (!getMetadata().elementSupports(elementID, SupportConstants.Element.UPDATE)) {
                // $NON-NLS-1$
                handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.element_updates_not_allowed", getMetadata().getFullName(elementID)), intoGroup);
            }
            Class<?> symbolType = symbol.getType();
            String symbolTypeName = DataTypeManager.getDataTypeName(symbolType);
            String targetTypeName = getMetadata().getElementRuntimeTypeName(elementID);
            if (symbolTypeName.equals(targetTypeName)) {
                continue;
            }
            if (!DataTypeManager.isImplicitConversion(symbolTypeName, targetTypeName)) {
                // If there's no implicit conversion between the two
                Object[] params = new Object[] { symbolTypeName, targetTypeName, new Integer(symbolNum + 1), query };
                // $NON-NLS-1$
                handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.select_into_no_implicit_conversion", params), query);
                continue;
            }
        }
    } catch (TeiidComponentException e) {
        handleException(e, query);
    }
}
Also used : SaxonXQueryExpression(org.teiid.query.xquery.saxon.SaxonXQueryExpression) List(java.util.List) LinkedList(java.util.LinkedList) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidComponentException(org.teiid.core.TeiidComponentException) Constraint(org.teiid.query.sql.symbol.Reference.Constraint)

Example 48 with TeiidComponentException

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

the class Validator method executeValidation.

private static final void executeValidation(LanguageObject object, final QueryMetadataInterface metadata, final AbstractValidationVisitor visitor) throws TeiidComponentException {
    // Reset visitor
    visitor.reset();
    visitor.setMetadata(metadata);
    setTempMetadata(metadata, visitor, object);
    PreOrderNavigator nav = new PreOrderNavigator(visitor) {

        protected void visitNode(LanguageObject obj) {
            QueryMetadataInterface previous = visitor.getMetadata();
            setTempMetadata(metadata, visitor, obj);
            super.visitNode(obj);
            visitor.setMetadata(previous);
        }

        @Override
        protected void preVisitVisitor(LanguageObject obj) {
            super.preVisitVisitor(obj);
            visitor.stack.add(obj);
        }

        @Override
        protected void postVisitVisitor(LanguageObject obj) {
            visitor.stack.pop();
        }
    };
    object.acceptVisitor(nav);
    // If an error occurred, throw an exception
    TeiidComponentException e = visitor.getException();
    if (e != null) {
        throw e;
    }
}
Also used : PreOrderNavigator(org.teiid.query.sql.navigator.PreOrderNavigator) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) LanguageObject(org.teiid.query.sql.LanguageObject)

Example 49 with TeiidComponentException

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

the class GlobalTableStoreImpl method getState.

@Override
public void getState(String stateId, OutputStream ostream) {
    try {
        ObjectOutputStream oos = new ObjectOutputStream(ostream);
        sendTable(stateId, oos, false);
        oos.close();
    } catch (IOException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30220, e);
    } catch (TeiidComponentException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30221, e);
    }
}
Also used : TeiidComponentException(org.teiid.core.TeiidComponentException) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 50 with TeiidComponentException

use of org.teiid.core.TeiidComponentException 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)

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