Search in sources :

Example 16 with QueryMetadataException

use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.

the class PlanToProcessConverter method aliasCommand.

private Command aliasCommand(AccessNode aNode, Command command, Object modelID) throws TeiidComponentException, QueryPlannerException {
    try {
        command = (Command) command.clone();
        boolean aliasGroups = modelID != null && (CapabilitiesUtil.supportsGroupAliases(modelID, metadata, capFinder) || CapabilitiesUtil.supports(Capability.QUERY_FROM_INLINE_VIEWS, modelID, metadata, capFinder));
        boolean aliasColumns = modelID != null && (CapabilitiesUtil.supports(Capability.QUERY_SELECT_EXPRESSION, modelID, metadata, capFinder) || CapabilitiesUtil.supports(Capability.QUERY_FROM_INLINE_VIEWS, modelID, metadata, capFinder));
        AliasGenerator visitor = new AliasGenerator(aliasGroups, !aliasColumns);
        SourceHint sh = command.getSourceHint();
        if (sh != null && aliasGroups) {
            VDBMetaData vdb = context.getDQPWorkContext().getVDB();
            ModelMetaData model = vdb.getModel(aNode.getModelName());
            List<String> sourceNames = model.getSourceNames();
            SpecificHint sp = null;
            if (sourceNames.size() == 1) {
                sp = sh.getSpecificHint(sourceNames.get(0));
            }
            if (sh.isUseAliases() || (sp != null && sp.isUseAliases())) {
                visitor.setAliasMapping(context.getAliasMapping());
            }
        }
        List<Reference> references = ReferenceCollectorVisitor.getReferences(command);
        if (!references.isEmpty()) {
            Set<String> correleatedGroups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
            for (Reference ref : references) {
                if (ref.isCorrelated() && ref.getExpression().getGroupSymbol() != null) {
                    correleatedGroups.add(ref.getExpression().getGroupSymbol().getName());
                }
            }
            visitor.setCorrelationGroups(correleatedGroups);
        }
        command.acceptVisitor(visitor);
    } catch (QueryMetadataException err) {
        throw new TeiidComponentException(QueryPlugin.Event.TEIID30249, err);
    } catch (TeiidRuntimeException e) {
        if (e.getCause() instanceof QueryPlannerException) {
            throw (QueryPlannerException) e.getCause();
        }
        throw e;
    }
    return command;
}
Also used : Reference(org.teiid.query.sql.symbol.Reference) SpecificHint(org.teiid.query.sql.lang.SourceHint.SpecificHint) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryPlannerException(org.teiid.api.exception.query.QueryPlannerException)

Example 17 with QueryMetadataException

use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.

the class PlanToProcessConverter method setRoutingName.

private void setRoutingName(AccessNode accessNode, PlanNode node, Command command) throws QueryPlannerException, TeiidComponentException {
    // Look up connector binding name
    try {
        Object modelID = node.getProperty(NodeConstants.Info.MODEL_ID);
        if (modelID == null || modelID instanceof TempMetadataID) {
            if (command instanceof StoredProcedure) {
                modelID = ((StoredProcedure) command).getModelID();
            } else if (!(command instanceof Create || command instanceof Drop)) {
                Collection<GroupSymbol> groups = GroupCollectorVisitor.getGroups(command, true);
                GroupSymbol group = groups.iterator().next();
                modelID = metadata.getModelID(group.getMetadataID());
            }
        }
        String cbName = metadata.getFullName(modelID);
        accessNode.setModelName(cbName);
        accessNode.setModelId(modelID);
        accessNode.setConformedTo((Set<Object>) node.getProperty(Info.CONFORMED_SOURCES));
    } catch (QueryMetadataException e) {
        throw new QueryPlannerException(QueryPlugin.Event.TEIID30251, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30251));
    }
}
Also used : TempMetadataID(org.teiid.query.metadata.TempMetadataID) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) QueryPlannerException(org.teiid.api.exception.query.QueryPlannerException)

Example 18 with QueryMetadataException

use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.

the class RowBasedSecurityHelper method resolveCondition.

static Criteria resolveCondition(QueryMetadataInterface metadata, final GroupSymbol group, String fullName, Map.Entry<String, DataPolicy> entry, PermissionMetaData pmd, String filterString) throws QueryMetadataException {
    Criteria filter = (Criteria) pmd.getResolvedCondition();
    if (filter == null) {
        try {
            filter = QueryParser.getQueryParser().parseCriteria(filterString);
            GroupSymbol gs = group;
            if (group.getDefinition() != null) {
                gs = new GroupSymbol(fullName);
                gs.setMetadataID(group.getMetadataID());
            }
            Collection<GroupSymbol> groups = Arrays.asList(gs);
            for (SubqueryContainer container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(filter)) {
                container.getCommand().pushNewResolvingContext(groups);
                QueryResolver.resolveCommand(container.getCommand(), metadata, false);
            }
            ResolverVisitor.resolveLanguageObject(filter, groups, metadata);
            ValidatorReport report = Validator.validate(filter, metadata, new ValidationVisitor());
            if (report.hasItems()) {
                ValidatorFailure firstFailure = report.getItems().iterator().next();
                // $NON-NLS-1$
                throw new QueryMetadataException(QueryPlugin.Event.TEIID31129, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31129, entry.getKey(), fullName) + " " + firstFailure);
            }
            pmd.setResolvedCondition(filter.clone());
        } catch (QueryMetadataException e) {
            throw e;
        } catch (TeiidException e) {
            throw new QueryMetadataException(QueryPlugin.Event.TEIID31129, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31129, entry.getKey(), fullName));
        }
    } else {
        filter = (Criteria) filter.clone();
    }
    return filter;
}
Also used : ValidationVisitor(org.teiid.query.validator.ValidationVisitor) ValidatorFailure(org.teiid.query.validator.ValidatorFailure) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) ValidatorReport(org.teiid.query.validator.ValidatorReport) TeiidException(org.teiid.core.TeiidException)

Example 19 with QueryMetadataException

use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.

the class CriteriaCapabilityValidatorVisitor method visit.

@Override
public void visit(OrderBy obj) {
    String collation = null;
    try {
        collation = (String) CapabilitiesUtil.getProperty(Capability.COLLATION_LOCALE, modelID, metadata, capFinder);
    } catch (QueryMetadataException e) {
        handleException(new TeiidComponentException(e));
    } catch (TeiidComponentException e) {
        handleException(e);
    }
    CommandContext commandContext = CommandContext.getThreadLocalContext();
    if (collation != null && commandContext != null && commandContext.getOptions().isRequireTeiidCollation() && !collation.equals(DataTypeManager.COLLATION_LOCALE)) {
        for (OrderByItem symbol : obj.getOrderByItems()) {
            if (symbol.getSymbol().getType() == DataTypeManager.DefaultDataClasses.STRING || symbol.getSymbol().getType() == DataTypeManager.DefaultDataClasses.CLOB || symbol.getSymbol().getType() == DataTypeManager.DefaultDataClasses.CHAR) {
                // we require the collation to match
                // $NON-NLS-1$
                markInvalid(obj, "source is not using the same collation as Teiid");
                break;
            }
        }
    }
}
Also used : CommandContext(org.teiid.query.util.CommandContext) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException)

Example 20 with QueryMetadataException

use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.

the class CriteriaCapabilityValidatorVisitor method checkCompareCriteria.

public void checkCompareCriteria(AbstractCompareCriteria obj, Expression rightExpression) {
    boolean negated = false;
    // Check if operation is allowed
    Capability operatorCap = null;
    switch(obj.getOperator()) {
        case CompareCriteria.NE:
            negated = true;
        case CompareCriteria.EQ:
            operatorCap = Capability.CRITERIA_COMPARE_EQ;
            break;
        case CompareCriteria.LT:
        case CompareCriteria.GT:
            operatorCap = Capability.CRITERIA_COMPARE_ORDERED_EXCLUSIVE;
            break;
        case CompareCriteria.LE:
        case CompareCriteria.GE:
            operatorCap = Capability.CRITERIA_COMPARE_ORDERED;
            break;
    }
    // Check if compares are allowed
    if (!this.caps.supportsCapability(operatorCap)) {
        boolean unsupported = true;
        if (operatorCap == Capability.CRITERIA_COMPARE_ORDERED_EXCLUSIVE && this.caps.supportsCapability(Capability.CRITERIA_COMPARE_ORDERED) && this.caps.supportsCapability(Capability.CRITERIA_NOT)) {
            unsupported = false;
        }
        if (unsupported) {
            if (EvaluatableVisitor.willBecomeConstant(obj)) {
                return;
            }
            // $NON-NLS-1$
            markInvalid(obj, operatorCap + " CompareCriteria not supported by source");
            return;
        }
    }
    if (negated && !this.caps.supportsCapability(Capability.CRITERIA_NOT)) {
        if (EvaluatableVisitor.willBecomeConstant(obj)) {
            return;
        }
        // $NON-NLS-1$
        markInvalid(obj, "Negation is not supported by source");
        return;
    }
    // Check capabilities of the elements
    try {
        int support = SupportConstants.Element.SEARCHABLE_COMPARE;
        if (!negated && obj.getOperator() == CompareCriteria.EQ) {
            support = SupportConstants.Element.SEARCHABLE_EQUALITY;
        }
        checkElementsAreSearchable(obj.getLeftExpression(), support);
        checkElementsAreSearchable(rightExpression, support);
    } catch (QueryMetadataException e) {
        handleException(new TeiidComponentException(e));
    } catch (TeiidComponentException e) {
        handleException(e);
    }
}
Also used : Capability(org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException)

Aggregations

QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)39 TeiidComponentException (org.teiid.core.TeiidComponentException)18 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)12 LanguageObject (org.teiid.query.sql.LanguageObject)7 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)6 TempMetadataID (org.teiid.query.metadata.TempMetadataID)6 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)5 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)3 TeiidException (org.teiid.core.TeiidException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)3 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)3 ObjectTable (org.teiid.query.sql.lang.ObjectTable)3 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)3 Expression (org.teiid.query.sql.symbol.Expression)3 Collection (java.util.Collection)2