Search in sources :

Example 71 with ElementSymbol

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

the class TestMatchCriteria method example.

public static MatchCriteria example(String str, char escapeChar) {
    MatchCriteria crit = new MatchCriteria();
    // $NON-NLS-1$
    crit.setLeftExpression(new ElementSymbol("m.g1.e1"));
    crit.setRightExpression(new Constant(str));
    crit.setEscapeChar(escapeChar);
    return crit;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant)

Example 72 with ElementSymbol

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

the class TestASTQueries method sampleQuery.

private Query sampleQuery() {
    List<ElementSymbol> symbols = new ArrayList<ElementSymbol>();
    // $NON-NLS-1$
    symbols.add(new ElementSymbol("e1"));
    // $NON-NLS-1$
    symbols.add(new ElementSymbol("e2"));
    Select select = new Select(symbols);
    From from = new From();
    // $NON-NLS-1$
    from.addGroup(new GroupSymbol("G1"));
    Query query = new Query();
    query.setSelect(select);
    query.setFrom(from);
    return query;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Query(org.teiid.query.sql.lang.Query) ArrayList(java.util.ArrayList) Select(org.teiid.query.sql.lang.Select) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) From(org.teiid.query.sql.lang.From)

Example 73 with ElementSymbol

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

the class Request method validateAccess.

protected boolean validateAccess(String[] commandStr, Command command, CommandType type) throws QueryValidatorException, TeiidComponentException {
    boolean returnsResultSet = command.returnsResultSet();
    this.returnsUpdateCount = !(command instanceof StoredProcedure) && !returnsResultSet;
    if ((this.requestMsg.getResultsMode() == ResultsMode.UPDATECOUNT && returnsResultSet) || (this.requestMsg.getResultsMode() == ResultsMode.RESULTSET && !returnsResultSet)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        throw new QueryValidatorException(QueryPlugin.Event.TEIID30490, QueryPlugin.Util.getString(this.requestMsg.getResultsMode() == ResultsMode.RESULTSET ? "Request.no_result_set" : "Request.result_set"));
    }
    createCommandContext();
    if (this.requestMsg.isReturnAutoGeneratedKeys() && command instanceof Insert) {
        Insert insert = (Insert) command;
        List<ElementSymbol> variables = ResolverUtil.resolveElementsInGroup(insert.getGroup(), metadata);
        variables.removeAll(insert.getVariables());
        Object pk = metadata.getPrimaryKey(insert.getGroup().getMetadataID());
        if (pk != null) {
            List<?> cols = metadata.getElementIDsInKey(pk);
            int colCount = 0;
            for (Iterator<ElementSymbol> iter = variables.iterator(); iter.hasNext(); ) {
                ElementSymbol variable = iter.next();
                if (!(metadata.elementSupports(variable.getMetadataID(), SupportConstants.Element.NULL) || metadata.elementSupports(variable.getMetadataID(), SupportConstants.Element.AUTO_INCREMENT)) || !cols.contains(variable.getMetadataID())) {
                    iter.remove();
                }
                colCount++;
            }
            if (colCount == cols.size()) {
                context.setReturnAutoGeneratedKeys(variables);
            }
        }
    }
    if (!this.workContext.isAdmin() && this.authorizationValidator != null) {
        return this.authorizationValidator.validate(commandStr, command, metadata, context, type);
    }
    return false;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) Insert(org.teiid.query.sql.lang.Insert)

Example 74 with ElementSymbol

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

the class RequestWorkItem method handleGeneratedKeys.

private boolean handleGeneratedKeys(ResultsMessage response) throws QueryMetadataException, TeiidComponentException {
    GeneratedKeysImpl keys = this.processor.getContext().getGeneratedKeys();
    if (keys.getKeys().isEmpty()) {
        return false;
    }
    List<ElementSymbol> keyCols = this.processor.getContext().getReturnAutoGeneratedKeys();
    // match the key cols with the result
    ElementSymbol col = keyCols.get(0);
    String[] columnNames = keys.getColumnNames();
    if (keyCols.size() != columnNames.length) {
        return false;
    }
    if (!col.getGroupSymbol().isTempTable() && this.processor.getContext().getMetadata().isVirtualGroup(col.getGroupSymbol().getMetadataID())) {
        if (keyCols.size() != 1 && ((Insert) originalCommand).getUpdateInfo().isInherentInsert()) {
            // TODO: we need to ensure the column names line up correctly
            return false;
        }
        columnNames = new String[columnNames.length];
        columnNames[0] = col.getShortName();
    }
    response.setColumnNames(columnNames);
    String[] dataTypes = new String[columnNames.length];
    for (int i = 0; i < dataTypes.length; i++) {
        dataTypes[i] = DataTypeManager.getDataTypeName(keys.getColumnTypes()[i]);
    }
    response.setUpdateCount((Integer) response.getResultsList().get(0).get(0));
    response.setDataTypes(dataTypes);
    response.setResults(keys.getKeys());
    response.setLastRow(keys.getKeys().size());
    return true;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) GeneratedKeysImpl(org.teiid.query.util.GeneratedKeysImpl) Insert(org.teiid.query.sql.lang.Insert) CacheHint(org.teiid.query.sql.lang.CacheHint)

Example 75 with ElementSymbol

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

the class DataTierManagerImpl method getColumns.

private List<ElementSymbol> getColumns(TransformationMetadata tm, String name) {
    GroupSymbol gs = new GroupSymbol(name);
    try {
        ResolverUtil.resolveGroup(gs, tm);
        List<ElementSymbol> columns = ResolverUtil.resolveElementsInGroup(gs, tm);
        return columns;
    } catch (TeiidException e) {
        throw new TeiidRuntimeException(e);
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException)

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