Search in sources :

Example 76 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.

the class DefaultAuthorizationValidator method validate.

@Override
public boolean validate(String[] originalSql, Command command, QueryMetadataInterface metadata, CommandContext commandContext, CommandType commandType) throws QueryValidatorException, TeiidComponentException {
    boolean modified = false;
    if (policyDecider != null && policyDecider.validateCommand(commandContext)) {
        if (ignoreUnathorizedInAsterisk(command, commandContext)) {
            Query query = (Query) command;
            HashMap<String, LanguageObject> map = null;
            for (Expression ex : query.getSelect().getSymbols()) {
                if (ex instanceof MultipleElementSymbol) {
                    MultipleElementSymbol mes = (MultipleElementSymbol) ex;
                    if (map == null) {
                        map = new HashMap<String, LanguageObject>();
                    }
                    for (Iterator<ElementSymbol> iter = mes.getElementSymbols().iterator(); iter.hasNext(); ) {
                        ElementSymbol es = iter.next();
                        Object metadataObject = es.getMetadataID();
                        if (metadataObject instanceof MultiSourceElement || metadataObject instanceof TempMetadataID) {
                            continue;
                        }
                        map.clear();
                        AuthorizationValidationVisitor.addToNameMap(metadataObject, es, map, commandContext.getMetadata());
                        Set<String> results = this.policyDecider.getInaccessibleResources(PermissionType.READ, map.keySet(), Context.QUERY, commandContext);
                        if (!results.isEmpty()) {
                            // remove from the select
                            iter.remove();
                            modified = true;
                        }
                    }
                }
            }
            if (query.getProjectedSymbols().isEmpty()) {
                throw new QueryValidatorException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31151));
            }
        }
        AuthorizationValidationVisitor visitor = new AuthorizationValidationVisitor(this.policyDecider, commandContext);
        Request.validateWithVisitor(visitor, metadata, command);
    }
    return modified;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) Query(org.teiid.query.sql.lang.Query) TempMetadataID(org.teiid.query.metadata.TempMetadataID) MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) Expression(org.teiid.query.sql.symbol.Expression) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) LanguageObject(org.teiid.query.sql.LanguageObject) LanguageObject(org.teiid.query.sql.LanguageObject) MultiSourceElement(org.teiid.dqp.internal.process.multisource.MultiSourceElement)

Example 77 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.

the class LanguageBridgeFactory method translate.

public org.teiid.language.OrderBy translate(OrderBy orderBy, boolean set) {
    if (orderBy == null) {
        return null;
    }
    List<OrderByItem> items = orderBy.getOrderByItems();
    List<SortSpecification> translatedItems = new ArrayList<SortSpecification>();
    for (int i = 0; i < items.size(); i++) {
        Expression symbol = items.get(i).getSymbol();
        Ordering direction = items.get(i).isAscending() ? Ordering.ASC : Ordering.DESC;
        SortSpecification orderByItem = null;
        if (!set && (items.get(i).isUnrelated() || symbol instanceof ElementSymbol)) {
            orderByItem = new SortSpecification(direction, translate(symbol));
        } else {
            orderByItem = new SortSpecification(direction, new ColumnReference(null, Symbol.getShortName(((Symbol) symbol).getOutputName()), null, symbol.getType()));
        }
        orderByItem.setNullOrdering(items.get(i).getNullOrdering());
        translatedItems.add(orderByItem);
    }
    return new org.teiid.language.OrderBy(translatedItems);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) OrderBy(org.teiid.query.sql.lang.OrderBy) ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) Symbol(org.teiid.query.sql.symbol.Symbol) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) AliasSymbol(org.teiid.query.sql.symbol.AliasSymbol) ExpressionSymbol(org.teiid.query.sql.symbol.ExpressionSymbol) SearchedCaseExpression(org.teiid.query.sql.symbol.SearchedCaseExpression) Expression(org.teiid.query.sql.symbol.Expression) Ordering(org.teiid.language.SortSpecification.Ordering)

Example 78 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.

the class LanguageBridgeFactory method translate.

public With translate(List<WithQueryCommand> with) {
    if (with == null || with.isEmpty()) {
        return null;
    }
    With result = new With();
    ArrayList<WithItem> items = new ArrayList<WithItem>(with.size());
    for (WithQueryCommand withQueryCommand : with) {
        WithItem item = new WithItem();
        GroupSymbol group = withQueryCommand.getGroupSymbol();
        if (withQueryCommand.getCommand() != null && excludeWithName != null && excludeWithName.equalsIgnoreCase(group.getName())) {
            group = RulePlaceAccess.recontextSymbol(withQueryCommand.getGroupSymbol(), commandContext.getGroups());
            group.setDefinition(null);
            if (remappedGroups == null) {
                remappedGroups = new IdentityHashMap<Object, GroupSymbol>();
            }
            this.remappedGroups.put(group.getMetadataID(), group);
        }
        item.setTable(translate(group));
        if (withQueryCommand.getColumns() != null) {
            List<ColumnReference> translatedElements = new ArrayList<ColumnReference>(withQueryCommand.getColumns().size());
            for (ElementSymbol es : withQueryCommand.getColumns()) {
                ColumnReference cr = translate(es);
                translatedElements.add(cr);
                if (withQueryCommand.getCommand() == null) {
                    // we want to convey the metadata to the source layer if possible
                    Object mid = es.getMetadataID();
                    if (mid instanceof TempMetadataID) {
                        TempMetadataID tid = (TempMetadataID) mid;
                        mid = tid.getOriginalMetadataID();
                    }
                    if (mid instanceof Column) {
                        cr.setMetadataObject((Column) mid);
                    }
                }
            }
            item.setColumns(translatedElements);
        }
        if (withQueryCommand.getCommand() != null) {
            item.setSubquery(translate(withQueryCommand.getCommand()));
        } else {
            item.setDependentValues(new TupleBufferList(withQueryCommand.getTupleBuffer()));
        }
        item.setRecusive(withQueryCommand.isRecursive());
        items.add(item);
    }
    result.setItems(items);
    return result;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TempMetadataID(org.teiid.query.metadata.TempMetadataID) BaseColumn(org.teiid.metadata.BaseColumn) Column(org.teiid.metadata.Column) DerivedColumn(org.teiid.language.DerivedColumn) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol)

Example 79 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol 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 80 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.

the class TestCriteriaEvaluator method helpGetCompareSubqueryCriteria.

private SubqueryCompareCriteria helpGetCompareSubqueryCriteria(int operator, int predicateQuantifier) {
    // $NON-NLS-1$
    ElementSymbol e1 = new ElementSymbol("e1");
    SubqueryCompareCriteria crit = new SubqueryCompareCriteria(e1, new Query(), operator, predicateQuantifier);
    return crit;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol)

Aggregations

ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)417 ArrayList (java.util.ArrayList)165 Test (org.junit.Test)157 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)148 Expression (org.teiid.query.sql.symbol.Expression)104 List (java.util.List)103 Constant (org.teiid.query.sql.symbol.Constant)94 MultipleElementSymbol (org.teiid.query.sql.symbol.MultipleElementSymbol)41 SymbolMap (org.teiid.query.sql.util.SymbolMap)40 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)36 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)29 Map (java.util.Map)28 AggregateSymbol (org.teiid.query.sql.symbol.AggregateSymbol)28 Query (org.teiid.query.sql.lang.Query)26 HashMap (java.util.HashMap)25 Select (org.teiid.query.sql.lang.Select)24 BufferManager (org.teiid.common.buffer.BufferManager)22 Criteria (org.teiid.query.sql.lang.Criteria)22 LinkedList (java.util.LinkedList)20 TupleBuffer (org.teiid.common.buffer.TupleBuffer)19