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;
}
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 };
}
}
}
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;
}
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);
}
}
}
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;
}
Aggregations