Search in sources :

Example 41 with ElementSymbol

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

the class GroupingNode method createSortSchema.

private static List<ElementSymbol> createSortSchema(AggregateFunction af, Class<?>[] inputTypes) {
    List<ElementSymbol> elements = new ArrayList<ElementSymbol>(inputTypes.length);
    int[] filteredArgIndexes = new int[inputTypes.length];
    for (int i = 0; i < inputTypes.length; i++) {
        // $NON-NLS-1$
        ElementSymbol element = new ElementSymbol("val" + i);
        element.setType(inputTypes[i]);
        elements.add(element);
        filteredArgIndexes[i] = i;
    }
    af.setArgIndexes(filteredArgIndexes);
    return elements;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ArrayList(java.util.ArrayList)

Example 42 with ElementSymbol

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

the class GroupingNode method initialize.

@Override
public void initialize(CommandContext context, BufferManager bufferManager, ProcessorDataManager dataMgr) {
    super.initialize(context, bufferManager, dataMgr);
    if (this.functions != null) {
        return;
    }
    // Incoming elements and lookup map for evaluating expressions
    List<? extends Expression> sourceElements = this.getChildren()[0].getElements();
    this.elementMap = createLookupMap(sourceElements);
    this.collectedExpressions = new LinkedHashMap<Expression, Integer>();
    // List should contain all grouping columns / expressions as we need those for sorting
    if (this.orderBy != null) {
        for (OrderByItem item : this.orderBy) {
            Expression ex = SymbolMap.getExpression(item.getSymbol());
            getIndex(ex, this.collectedExpressions);
        }
        if (removeDuplicates) {
            for (Expression ses : sourceElements) {
                getIndex(ses, collectedExpressions);
            }
            distinctCols = collectedExpressions.size();
        }
    }
    // Construct aggregate function state accumulators
    functions = new AggregateFunction[getElements().size()][];
    for (int i = 0; i < getElements().size(); i++) {
        Expression symbol = getElements().get(i);
        if (this.outputMapping != null) {
            symbol = outputMapping.getMappedExpression((ElementSymbol) symbol);
        }
        Class<?> outputType = symbol.getType();
        if (symbol instanceof AggregateSymbol) {
            AggregateSymbol aggSymbol = (AggregateSymbol) symbol;
            functions[i] = new AggregateFunction[rollup ? orderBy.size() + 1 : 1];
            for (int j = 0; j < functions[i].length; j++) {
                functions[i][j] = initAccumulator(aggSymbol, this, this.collectedExpressions);
            }
        } else {
            AggregateFunction af = new ConstantFunction();
            af.setArgIndexes(new int[] { this.collectedExpressions.get(symbol) });
            af.initialize(outputType, new Class<?>[] { symbol.getType() });
            functions[i] = new AggregateFunction[] { af };
        }
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) OrderByItem(org.teiid.query.sql.lang.OrderByItem) Expression(org.teiid.query.sql.symbol.Expression)

Example 43 with ElementSymbol

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

the class ProjectIntoNode method convertValuesToConstants.

private List<Constant> convertValuesToConstants(List<?> values, List<ElementSymbol> elements) {
    ArrayList<Constant> constants = new ArrayList<Constant>(values.size());
    for (int i = 0; i < elements.size(); i++) {
        ElementSymbol es = elements.get(i);
        Class<?> type = es.getType();
        constants.add(new Constant(values.get(i), type));
    }
    return constants;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) SourceHint(org.teiid.query.sql.lang.SourceHint)

Example 44 with ElementSymbol

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

the class ExecDynamicSqlInstruction method updateContextWithUsingValues.

/**
 * @param procEnv
 * @param localContext
 * @throws TeiidComponentException
 * @throws TeiidComponentException
 * @throws TeiidProcessingException
 */
private void updateContextWithUsingValues(ProcedurePlan procEnv, VariableContext localContext) throws TeiidComponentException, TeiidProcessingException {
    if (dynamicCommand.getUsing() != null && !dynamicCommand.getUsing().isEmpty()) {
        for (SetClause setClause : dynamicCommand.getUsing().getClauses()) {
            Object assignment = procEnv.evaluateExpression(setClause.getValue());
            LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, new Object[] { // $NON-NLS-1$
            this, // $NON-NLS-1$
            " The using variable ", setClause.getSymbol(), " has value :", // $NON-NLS-1$
            assignment });
            localContext.setValue(setClause.getSymbol(), assignment);
            ElementSymbol es = setClause.getSymbol().clone();
            es.getGroupSymbol().setShortName(Reserved.USING);
            localContext.setValue(es, assignment);
        }
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) SetClause(org.teiid.query.sql.lang.SetClause)

Example 45 with ElementSymbol

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

the class ExecDynamicSqlInstruction method createVariableValuesMap.

/**
 * @param localContext
 * @return
 */
private Map<ElementSymbol, Expression> createVariableValuesMap(VariableContext localContext) {
    Map<ElementSymbol, Object> variableMap = new HashMap<ElementSymbol, Object>();
    localContext.getFlattenedContextMap(variableMap);
    Map<ElementSymbol, Expression> nameValueMap = new HashMap<ElementSymbol, Expression>(variableMap.size());
    for (Map.Entry<ElementSymbol, Object> entry : variableMap.entrySet()) {
        if (entry.getKey() instanceof ElementSymbol) {
            if (entry.getValue() instanceof Expression) {
                nameValueMap.put(entry.getKey(), (Expression) entry.getValue());
            } else {
                nameValueMap.put(entry.getKey(), new Constant(entry.getValue(), entry.getKey().getType()));
            }
        }
    }
    return nameValueMap;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) HashMap(java.util.HashMap) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) Map(java.util.Map) HashMap(java.util.HashMap)

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