Search in sources :

Example 6 with LanguageObject

use of org.teiid.query.sql.LanguageObject in project teiid by teiid.

the class AuthorizationValidationVisitor method validateEntitlements.

/**
 * Validate query entitlements
 */
protected void validateEntitlements(Query obj) {
    // If query contains SELECT INTO, validate INTO portion
    Into intoObj = obj.getInto();
    if (intoObj != null) {
        GroupSymbol intoGroup = intoObj.getGroup();
        Collection<LanguageObject> intoElements = new LinkedList<LanguageObject>();
        intoElements.add(intoGroup);
        try {
            intoElements.addAll(ResolverUtil.resolveElementsInGroup(intoGroup, getMetadata()));
        } catch (QueryMetadataException err) {
            handleException(err, intoGroup);
        } catch (TeiidComponentException err) {
            handleException(err, intoGroup);
        }
        validateEntitlements(intoElements, DataPolicy.PermissionType.CREATE, Context.INSERT);
    }
    // Validate this query's entitlements
    Collection<LanguageObject> entitledObjects = new ArrayList<LanguageObject>(GroupCollectorVisitor.getGroupsIgnoreInlineViews(obj, true));
    entitledObjects.addAll(ElementCollectorVisitor.getElements(obj, true));
    if (entitledObjects.size() == 0) {
        return;
    }
    validateEntitlements(entitledObjects, DataPolicy.PermissionType.READ, Context.QUERY);
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) LanguageObject(org.teiid.query.sql.LanguageObject)

Example 7 with LanguageObject

use of org.teiid.query.sql.LanguageObject in project teiid by teiid.

the class AuthorizationValidationVisitor method addToNameMap.

static void addToNameMap(Object metadataID, LanguageObject symbol, Map<String, LanguageObject> nameToSymbolMap, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException {
    String fullName = metadata.getFullName(metadataID);
    Object modelId = metadata.getModelID(metadataID);
    String modelName = metadata.getFullName(modelId);
    if (!isSystemSchema(modelName)) {
        // foreign temp table full names are not schema qualified by default
        if (!metadata.isVirtualModel(modelId)) {
            GroupSymbol group = null;
            if (symbol instanceof ElementSymbol) {
                group = ((ElementSymbol) symbol).getGroupSymbol();
            } else if (symbol instanceof GroupSymbol) {
                group = (GroupSymbol) symbol;
            }
            if (group != null && group.isTempGroupSymbol() && !group.isGlobalTable()) {
                fullName = modelName + AbstractMetadataRecord.NAME_DELIM_CHAR + modelId;
            }
        }
        nameToSymbolMap.put(fullName, symbol);
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) LanguageObject(org.teiid.query.sql.LanguageObject)

Example 8 with LanguageObject

use of org.teiid.query.sql.LanguageObject in project teiid by teiid.

the class TestResolver method helpResolveWithBindings.

public static Command helpResolveWithBindings(String sql, QueryMetadataInterface metadata, List bindings) throws QueryResolverException, TeiidComponentException {
    // parse
    Command command = helpParse(sql);
    QueryNode qn = new QueryNode(sql);
    qn.setBindings(bindings);
    // resolve
    QueryResolver.resolveWithBindingMetadata(command, metadata, qn, true);
    CheckSymbolsAreResolvedVisitor vis = new CheckSymbolsAreResolvedVisitor();
    DeepPreOrderNavigator.doVisit(command, vis);
    Collection<LanguageObject> unresolvedSymbols = vis.getUnresolvedSymbols();
    // $NON-NLS-1$
    assertTrue("Found unresolved symbols: " + unresolvedSymbols, unresolvedSymbols.isEmpty());
    return command;
}
Also used : CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) QueryNode(org.teiid.query.mapping.relational.QueryNode) LanguageObject(org.teiid.query.sql.LanguageObject)

Example 9 with LanguageObject

use of org.teiid.query.sql.LanguageObject in project teiid by teiid.

the class TestResolver method helpCheckElements.

private void helpCheckElements(LanguageObject langObj, String[] elementNames, String[] elementIDs) {
    List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
    ElementCollectorVisitor.getElements(langObj, elements);
    // $NON-NLS-1$
    assertEquals("Wrong number of elements: ", elementNames.length, elements.size());
    for (int i = 0; i < elements.size(); i++) {
        ElementSymbol symbol = elements.get(i);
        // $NON-NLS-1$
        assertEquals("Element name does not match: ", elementNames[i].toUpperCase(), symbol.getName().toUpperCase());
        Object elementID = symbol.getMetadataID();
        try {
            String name = metadata.getFullName(elementID);
            // $NON-NLS-1$ //$NON-NLS-2$
            assertNotNull("ElementSymbol " + symbol + " was not resolved and has no metadataID", elementID);
            // $NON-NLS-1$
            assertEquals("ElementID name does not match: ", elementIDs[i].toUpperCase(), name.toUpperCase());
        } catch (TeiidComponentException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ArrayList(java.util.ArrayList) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 10 with LanguageObject

use of org.teiid.query.sql.LanguageObject in project teiid by teiid.

the class ResolverVisitor method resolveLanguageObject.

public static void resolveLanguageObject(LanguageObject obj, Collection<GroupSymbol> groups, GroupContext externalContext, QueryMetadataInterface metadata) throws TeiidComponentException, QueryResolverException {
    if (obj == null) {
        return;
    }
    // Resolve elements, deal with errors
    final ResolverVisitor elementsVisitor = new ResolverVisitor(metadata, groups, externalContext);
    // special handling for is distinct - we must resolve as both element and group
    // until we generalize the notion of a scalar group reference as an "elementsymbol"
    PostOrderNavigator nav = new PostOrderNavigator(elementsVisitor) {

        @Override
        public void visit(IsDistinctCriteria obj) {
            obj.setLeftRowValue(resolveAsGroup(obj.getLeftRowValue()));
            obj.setRightRowValue(resolveAsGroup(obj.getRightRowValue()));
            super.visit(obj);
        }

        private LanguageObject resolveAsGroup(LanguageObject rowValue) {
            if (rowValue instanceof ElementSymbol) {
                ElementSymbol es = (ElementSymbol) rowValue;
                if (es.getMetadataID() == null) {
                    try {
                        elementsVisitor.resolveElementSymbol(es);
                    } catch (QueryResolverException | TeiidComponentException e) {
                        GroupSymbol gs = new GroupSymbol(es.getName());
                        try {
                            ResolverUtil.resolveGroup(gs, metadata);
                            rowValue = gs;
                        } catch (QueryResolverException | TeiidComponentException e1) {
                        }
                    }
                }
            }
            return rowValue;
        }
    };
    obj.acceptVisitor(nav);
    elementsVisitor.throwException(true);
}
Also used : PostOrderNavigator(org.teiid.query.sql.navigator.PostOrderNavigator) TeiidComponentException(org.teiid.core.TeiidComponentException) LanguageObject(org.teiid.query.sql.LanguageObject) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Aggregations

LanguageObject (org.teiid.query.sql.LanguageObject)28 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)8 TeiidComponentException (org.teiid.core.TeiidComponentException)7 ArrayList (java.util.ArrayList)5 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)5 HashSet (java.util.HashSet)3 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)3 Command (org.teiid.query.sql.lang.Command)3 Criteria (org.teiid.query.sql.lang.Criteria)3 Select (org.teiid.query.sql.lang.Select)3 Expression (org.teiid.query.sql.symbol.Expression)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)2 MultiSourceElement (org.teiid.dqp.internal.process.multisource.MultiSourceElement)2 TempMetadataID (org.teiid.query.metadata.TempMetadataID)2 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)2 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)2