Search in sources :

Example 36 with Expression

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

the class TestDynamicCommand method testClone1.

public void testClone1() {
    List symbols = new ArrayList();
    // $NON-NLS-1$
    ElementSymbol a1 = new ElementSymbol("a1");
    a1.setType(DataTypeManager.DefaultDataClasses.STRING);
    symbols.add(a1);
    DynamicCommand sqlCmd = new DynamicCommand();
    // $NON-NLS-1$
    Expression sql = new Constant("SELECT a1 FROM g WHERE a2 = 5");
    sqlCmd.setSql(sql);
    sqlCmd.setAsColumns(symbols);
    sqlCmd.setAsClauseSet(true);
    // $NON-NLS-1$
    sqlCmd.setIntoGroup(new GroupSymbol("#g"));
    UnitTestUtil.helpTestEquivalence(0, sqlCmd, sqlCmd.clone());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) DynamicCommand(org.teiid.query.sql.lang.DynamicCommand) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) List(java.util.List) SetClauseList(org.teiid.query.sql.lang.SetClauseList) ArrayList(java.util.ArrayList)

Example 37 with Expression

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

the class TestDynamicCommand method testClone2.

public void testClone2() {
    List symbols = new ArrayList();
    // $NON-NLS-1$
    ElementSymbol a1 = new ElementSymbol("a1");
    a1.setType(DataTypeManager.DefaultDataClasses.STRING);
    symbols.add(a1);
    // $NON-NLS-1$
    Expression sql = new Constant("SELECT * FROM g");
    SetClauseList using = new SetClauseList();
    using.addClause(a1, a1);
    // $NON-NLS-1$
    DynamicCommand sqlCmd = new DynamicCommand(sql, symbols, new GroupSymbol("#g"), using);
    UnitTestUtil.helpTestEquivalence(0, sqlCmd, sqlCmd.clone());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) DynamicCommand(org.teiid.query.sql.lang.DynamicCommand) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) List(java.util.List) SetClauseList(org.teiid.query.sql.lang.SetClauseList) ArrayList(java.util.ArrayList) SetClauseList(org.teiid.query.sql.lang.SetClauseList)

Example 38 with Expression

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

the class RequestWorkItem method createResultsMessage.

public ResultsMessage createResultsMessage(List<? extends List<?>> batch, List<? extends Expression> columnSymbols) {
    String[] columnNames = new String[columnSymbols.size()];
    String[] dataTypes = new String[columnSymbols.size()];
    byte clientSerializationVersion = this.dqpWorkContext.getClientVersion().getClientSerializationVersion();
    for (int i = 0; i < columnSymbols.size(); i++) {
        Expression symbol = columnSymbols.get(i);
        columnNames[i] = Symbol.getShortName(Symbol.getOutputName(symbol));
        dataTypes[i] = DataTypeManager.getDataTypeName(symbol.getType());
        if (dataTypes[i].equals(DataTypeManager.DefaultDataTypes.GEOMETRY) && !this.dqpWorkContext.getSession().isEmbedded() && clientSerializationVersion < BatchSerializer.VERSION_GEOMETRY) {
            dataTypes[i] = DataTypeManager.DefaultDataTypes.BLOB;
        }
    }
    ResultsMessage result = new ResultsMessage(batch, columnNames, dataTypes);
    result.setClientSerializationVersion(clientSerializationVersion);
    result.setDelayDeserialization(this.requestMsg.isDelaySerialization() && this.originalCommand.returnsResultSet());
    return result;
}
Also used : Expression(org.teiid.query.sql.symbol.Expression) ResultsMessage(org.teiid.client.ResultsMessage) CacheHint(org.teiid.query.sql.lang.CacheHint)

Example 39 with Expression

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

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

the class MetaDataProcessor method getMetadataForCommand.

// For each projected symbol, construct a metadata map
private MetadataResult getMetadataForCommand(Command originalCommand) throws TeiidComponentException {
    Map<Integer, Object>[] columnMetadata = null;
    switch(originalCommand.getType()) {
        case Command.TYPE_QUERY:
            if (originalCommand instanceof Query) {
                if (((Query) originalCommand).getInto() == null) {
                    columnMetadata = createProjectedSymbolMetadata(originalCommand);
                }
            } else {
                columnMetadata = createProjectedSymbolMetadata(originalCommand);
            }
            break;
        case Command.TYPE_STORED_PROCEDURE:
            columnMetadata = createProjectedSymbolMetadata(originalCommand);
            break;
        case Command.TYPE_INSERT:
        case Command.TYPE_UPDATE:
        case Command.TYPE_DELETE:
        case Command.TYPE_CREATE:
        case Command.TYPE_DROP:
            break;
        default:
            if (originalCommand.returnsResultSet()) {
                columnMetadata = createProjectedSymbolMetadata(originalCommand);
            }
    }
    Map<Reference, String> paramMap = Collections.emptyMap();
    if (originalCommand instanceof StoredProcedure) {
        StoredProcedure sp = (StoredProcedure) originalCommand;
        paramMap = new HashMap<Reference, String>();
        Collection<SPParameter> params = sp.getParameters();
        for (SPParameter spParameter : params) {
            if (spParameter.getParameterType() != SPParameter.INOUT && spParameter.getParameterType() != SPParameter.IN && spParameter.getParameterType() != SPParameter.RETURN_VALUE) {
                continue;
            }
            Expression ex = spParameter.getExpression();
            if (ex instanceof Function && FunctionLibrary.isConvert((Function) ex)) {
                ex = ((Function) ex).getArg(0);
            }
            if (ex instanceof Reference) {
                paramMap.put((Reference) ex, spParameter.getParameterSymbol().getShortName());
            }
        }
    }
    List<Reference> params = ReferenceCollectorVisitor.getReferences(originalCommand);
    Map<Integer, Object>[] paramMetadata = new Map[params.size()];
    for (int i = 0; i < params.size(); i++) {
        Reference param = params.get(i);
        paramMetadata[i] = getDefaultColumn(null, paramMap.get(param), param.getType());
    }
    return new MetadataResult(columnMetadata, paramMetadata);
}
Also used : Query(org.teiid.query.sql.lang.Query) Reference(org.teiid.query.sql.symbol.Reference) SPParameter(org.teiid.query.sql.lang.SPParameter) MetadataResult(org.teiid.client.metadata.MetadataResult) Function(org.teiid.query.sql.symbol.Function) WindowFunction(org.teiid.query.sql.symbol.WindowFunction) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Expression(org.teiid.query.sql.symbol.Expression) HashMap(java.util.HashMap) Map(java.util.Map) SymbolMap(org.teiid.query.sql.util.SymbolMap)

Aggregations

Expression (org.teiid.query.sql.symbol.Expression)257 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)104 ArrayList (java.util.ArrayList)74 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)54 Test (org.junit.Test)53 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)50 List (java.util.List)49 Constant (org.teiid.query.sql.symbol.Constant)38 SymbolMap (org.teiid.query.sql.util.SymbolMap)37 HashMap (java.util.HashMap)22 LinkedList (java.util.LinkedList)22 Criteria (org.teiid.query.sql.lang.Criteria)22 Map (java.util.Map)21 ClobType (org.teiid.core.types.ClobType)16 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)16 HashSet (java.util.HashSet)13 LinkedHashSet (java.util.LinkedHashSet)13 AliasSymbol (org.teiid.query.sql.symbol.AliasSymbol)13 SearchedCaseExpression (org.teiid.query.sql.symbol.SearchedCaseExpression)13 OrderBy (org.teiid.query.sql.lang.OrderBy)12