Search in sources :

Example 21 with QueryMetadataException

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

the class CriteriaCapabilityValidatorVisitor method visit.

/**
 * @see org.teiid.query.sql.LanguageVisitor#visit(org.teiid.query.sql.lang.SubqueryCompareCriteria)
 */
public void visit(SubqueryCompareCriteria crit) {
    if (crit.getArrayExpression() != null) {
        // $NON-NLS-1$
        markInvalid(crit, "Quantified compare with an array cannot yet be pushed down.");
        return;
    }
    // Check if quantification operator is allowed
    Capability capability = Capability.QUERY_SUBQUERIES_SCALAR;
    switch(crit.getPredicateQuantifier()) {
        case SubqueryCompareCriteria.ALL:
            capability = Capability.CRITERIA_QUANTIFIED_ALL;
            break;
        case SubqueryCompareCriteria.ANY:
            capability = Capability.CRITERIA_QUANTIFIED_SOME;
            break;
        case SubqueryCompareCriteria.SOME:
            capability = Capability.CRITERIA_QUANTIFIED_SOME;
            break;
    }
    if (!this.caps.supportsCapability(capability)) {
        // $NON-NLS-1$
        markInvalid(crit, "SubqueryCompare not supported by source");
        return;
    }
    checkCompareCriteria(crit, crit.getCommand().getProjectedSymbols().get(0));
    // Check capabilities of the elements
    try {
        if (validateSubqueryPushdown(crit, modelID, metadata, capFinder, analysisRecord) == null) {
            // $NON-NLS-1$
            markInvalid(crit.getCommand(), "Subquery cannot be pushed down");
        }
    } 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)

Example 22 with QueryMetadataException

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

the class ColumnMaskingHelper method maskColumn.

private static Expression maskColumn(ElementSymbol col, GroupSymbol unaliased, QueryMetadataInterface metadata, ExpressionMappingVisitor emv, Map<String, DataPolicy> policies, CommandContext cc) throws TeiidComponentException, TeiidProcessingException {
    Object metadataID = col.getMetadataID();
    String fullName = metadata.getFullName(metadataID);
    final GroupSymbol group = col.getGroupSymbol();
    String elementType = metadata.getElementRuntimeTypeName(col.getMetadataID());
    Class<?> expectedType = DataTypeManager.getDataTypeClass(elementType);
    List<WhenThen> cases = null;
    Collection<GroupSymbol> groups = Arrays.asList(unaliased);
    for (Map.Entry<String, DataPolicy> entry : policies.entrySet()) {
        DataPolicyMetadata dpm = (DataPolicyMetadata) entry.getValue();
        PermissionMetaData pmd = dpm.getPermissionMap().get(fullName);
        if (pmd == null) {
            continue;
        }
        String maskString = pmd.getMask();
        if (maskString == null) {
            continue;
        }
        Criteria condition = null;
        if (pmd.getCondition() != null) {
            condition = RowBasedSecurityHelper.resolveCondition(metadata, group, metadata.getFullName(group.getMetadataID()), entry, pmd, pmd.getCondition());
        } else {
            condition = QueryRewriter.TRUE_CRITERIA;
        }
        Expression mask = (Expression) pmd.getResolvedMask();
        if (mask == null) {
            try {
                mask = QueryParser.getQueryParser().parseExpression(pmd.getMask());
                for (SubqueryContainer container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(mask)) {
                    container.getCommand().pushNewResolvingContext(groups);
                    QueryResolver.resolveCommand(container.getCommand(), metadata, false);
                }
                ResolverVisitor.resolveLanguageObject(mask, groups, metadata);
                ValidatorReport report = Validator.validate(mask, metadata, new ValidationVisitor());
                if (report.hasItems()) {
                    ValidatorFailure firstFailure = report.getItems().iterator().next();
                    // $NON-NLS-1$
                    throw new QueryMetadataException(QueryPlugin.Event.TEIID31139, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31139, dpm.getName(), fullName) + " " + firstFailure);
                }
                if (mask.getType() != expectedType) {
                    mask = ResolverUtil.convertExpression(mask, elementType, metadata);
                }
                pmd.setResolvedMask(mask.clone());
                if (!dpm.isAnyAuthenticated()) {
                    // we treat this as user deterministic since the data roles won't change.  this may change if the logic becomes dynamic
                    // TODO: this condition may not even be used
                    cc.setDeterminismLevel(Determinism.USER_DETERMINISTIC);
                }
            } catch (QueryMetadataException e) {
                throw e;
            } catch (TeiidException e) {
                throw new QueryMetadataException(QueryPlugin.Event.TEIID31129, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31129, dpm.getName(), fullName));
            }
        } else {
            mask = (Expression) mask.clone();
        }
        if (group.getDefinition() != null) {
            PreOrPostOrderNavigator.doVisit(mask, emv, PreOrPostOrderNavigator.PRE_ORDER, true);
        }
        if (cases == null) {
            cases = new ArrayList<ColumnMaskingHelper.WhenThen>();
        }
        cases.add(new WhenThen(pmd.getOrder(), condition, mask));
    }
    if (cases == null) {
        return col;
    }
    Collections.sort(cases);
    List<Criteria> whens = new ArrayList<Criteria>();
    List<Expression> thens = new ArrayList<Expression>();
    for (WhenThen whenThen : cases) {
        whens.add(whenThen.when);
        thens.add(whenThen.then);
    }
    SearchedCaseExpression sce = new SearchedCaseExpression(whens, thens);
    sce.setElseExpression(col);
    sce.setType(expectedType);
    Expression mask = QueryRewriter.rewriteExpression(sce, cc, metadata, true);
    return mask;
}
Also used : ValidationVisitor(org.teiid.query.validator.ValidationVisitor) ArrayList(java.util.ArrayList) Criteria(org.teiid.query.sql.lang.Criteria) ValidatorFailure(org.teiid.query.validator.ValidatorFailure) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) DataPolicy(org.teiid.adminapi.DataPolicy) SubqueryContainer(org.teiid.query.sql.lang.SubqueryContainer) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) ValidatorReport(org.teiid.query.validator.ValidatorReport) TeiidException(org.teiid.core.TeiidException) SearchedCaseExpression(org.teiid.query.sql.symbol.SearchedCaseExpression) SearchedCaseExpression(org.teiid.query.sql.symbol.SearchedCaseExpression) Expression(org.teiid.query.sql.symbol.Expression) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Map(java.util.Map) PermissionMetaData(org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData)

Example 23 with QueryMetadataException

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

the class TransformationMetadata method getElementID.

// ==================================================================================
// I N T E R F A C E   M E T H O D S
// ==================================================================================
public Column getElementID(final String elementName) throws TeiidComponentException, QueryMetadataException {
    int columnIndex = elementName.lastIndexOf(TransformationMetadata.DELIMITER_STRING);
    if (columnIndex == -1) {
        throw new QueryMetadataException(QueryPlugin.Event.TEIID30355, elementName + TransformationMetadata.NOT_EXISTS_MESSAGE);
    }
    Table table = this.store.findGroup(elementName.substring(0, columnIndex));
    String shortElementName = elementName.substring(columnIndex + 1);
    return getColumn(elementName, table, shortElementName);
}
Also used : ObjectTable(org.teiid.query.sql.lang.ObjectTable) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException)

Example 24 with QueryMetadataException

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

the class TransformationMetadata method getVirtualPlan.

public QueryNode getVirtualPlan(final Object groupID) throws TeiidComponentException, QueryMetadataException {
    Table tableRecord = (Table) groupID;
    if (!tableRecord.isVirtual()) {
        // $NON-NLS-1$
        throw new QueryMetadataException(QueryPlugin.Event.TEIID30359, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30359, tableRecord.getFullName(), "Query"));
    }
    LiveTableQueryNode queryNode = new LiveTableQueryNode(tableRecord);
    // get any bindings and add them onto the query node
    List<String> bindings = tableRecord.getBindings();
    if (bindings != null) {
        for (Iterator<String> bindIter = bindings.iterator(); bindIter.hasNext(); ) {
            queryNode.addBinding(bindIter.next());
        }
    }
    return queryNode;
}
Also used : ObjectTable(org.teiid.query.sql.lang.ObjectTable) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException)

Example 25 with QueryMetadataException

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

the class TransformationMetadata method getXMLSchemas.

public List<SQLXMLImpl> getXMLSchemas(final Object groupID) throws TeiidComponentException, QueryMetadataException {
    Table tableRecord = (Table) groupID;
    // lookup transformation record for the group
    String groupName = tableRecord.getFullName();
    // get the schema Paths
    List<String> schemaPaths = tableRecord.getSchemaPaths();
    List<SQLXMLImpl> schemas = new LinkedList<SQLXMLImpl>();
    if (schemaPaths == null) {
        return schemas;
    }
    String path = getParentPath(tableRecord.getResourcePath());
    for (String string : schemaPaths) {
        String parentPath = path;
        boolean relative = false;
        while (string.startsWith("../")) {
            // $NON-NLS-1$
            relative = true;
            string = string.substring(3);
            parentPath = getParentPath(parentPath);
        }
        SQLXMLImpl schema = null;
        if (!relative) {
            schema = getVDBResourceAsSQLXML(string);
        }
        if (schema == null) {
            if (!parentPath.endsWith("/")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                parentPath += "/";
            }
            schema = getVDBResourceAsSQLXML(parentPath + string);
        }
        if (schema == null) {
            throw new QueryMetadataException(QueryPlugin.Event.TEIID30364, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30364, groupName));
        }
        schemas.add(schema);
    }
    return schemas;
}
Also used : SQLXMLImpl(org.teiid.core.types.SQLXMLImpl) ObjectTable(org.teiid.query.sql.lang.ObjectTable) 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