use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class ProcedureContainerResolver method addChanging.
public static void addChanging(TempMetadataStore discoveredMetadata, GroupContext externalGroups, List<ElementSymbol> elements) {
List<ElementSymbol> changingElements = new ArrayList<ElementSymbol>(elements.size());
for (int i = 0; i < elements.size(); i++) {
ElementSymbol virtualElmnt = elements.get(i);
ElementSymbol changeElement = virtualElmnt.clone();
changeElement.setType(DataTypeManager.DefaultDataClasses.BOOLEAN);
changingElements.add(changeElement);
}
addScalarGroup(ProcedureReservedWords.CHANGING, discoveredMetadata, externalGroups, changingElements, false);
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class QueryResolver method resolveView.
public static QueryNode resolveView(GroupSymbol virtualGroup, QueryNode qnode, String cacheString, QueryMetadataInterface qmi, boolean logValidation) throws TeiidComponentException, QueryMetadataException, QueryResolverException, QueryValidatorException {
qmi = qmi.getDesignTimeMetadata();
// $NON-NLS-1$
cacheString = "transformation/" + cacheString;
QueryNode cachedNode = (QueryNode) qmi.getFromMetadataCache(virtualGroup.getMetadataID(), cacheString);
if (cachedNode == null) {
Command result = qnode.getCommand();
List<String> bindings = null;
if (result == null) {
try {
result = QueryParser.getQueryParser().parseCommand(qnode.getQuery());
} catch (QueryParserException e) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30065, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30065, virtualGroup));
}
bindings = qnode.getBindings();
} else {
result = (Command) result.clone();
}
if (bindings != null && !bindings.isEmpty()) {
QueryResolver.resolveWithBindingMetadata(result, qmi, qnode, true);
} else {
QueryResolver.resolveCommand(result, qmi, false);
}
Request.validateWithVisitor(new ValidationVisitor(), qmi, result);
validateProjectedSymbols(virtualGroup, qmi, result);
cachedNode = new QueryNode(qnode.getQuery());
cachedNode.setCommand(result);
if (isView(virtualGroup, qmi)) {
String updatePlan = qmi.getUpdatePlan(virtualGroup.getMetadataID());
String deletePlan = qmi.getDeletePlan(virtualGroup.getMetadataID());
String insertPlan = qmi.getInsertPlan(virtualGroup.getMetadataID());
// the elements must be against the view and not the alias
if (virtualGroup.getDefinition() != null) {
GroupSymbol group = new GroupSymbol(virtualGroup.getNonCorrelationName());
group.setMetadataID(virtualGroup.getMetadataID());
virtualGroup = group;
}
List<ElementSymbol> elements = ResolverUtil.resolveElementsInGroup(virtualGroup, qmi);
UpdateValidator validator = new UpdateValidator(qmi, determineType(insertPlan), determineType(updatePlan), determineType(deletePlan));
validator.validate(result, elements);
UpdateInfo info = validator.getUpdateInfo();
if (logValidation && qmi.groupSupports(virtualGroup.getMetadataID(), SupportConstants.Group.UPDATE)) {
if (info.isInherentInsert() && validator.getInsertReport().hasItems()) {
LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getInsertReport().getFailureMessage(), SQLConstants.Reserved.INSERT, qmi.getFullName(virtualGroup.getMetadataID())));
}
if (info.isInherentUpdate() && validator.getUpdateReport().hasItems()) {
LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getUpdateReport().getFailureMessage(), SQLConstants.Reserved.UPDATE, qmi.getFullName(virtualGroup.getMetadataID())));
}
if (info.isInherentDelete() && validator.getDeleteReport().hasItems()) {
LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getDeleteReport().getFailureMessage(), SQLConstants.Reserved.DELETE, qmi.getFullName(virtualGroup.getMetadataID())));
}
}
cachedNode.setUpdateInfo(info);
}
qmi.addToMetadataCache(virtualGroup.getMetadataID(), cacheString, cachedNode);
}
return cachedNode;
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class DependentProcedureCriteriaProcessor method setParam.
private boolean setParam(VariableContext context, Object value, boolean nullAllowed, Reference parameter) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
if (value instanceof Expression) {
value = eval.evaluate((Expression) value, null);
}
if (value == null && !nullAllowed) {
return false;
}
ElementSymbol parameterSymbol = parameter.getExpression();
if (context.containsVariable(parameterSymbol)) {
Object existingValue = context.getValue(parameterSymbol);
if ((value != null && !value.equals(existingValue)) || (value == null && existingValue != null)) {
return false;
}
}
context.setValue(parameterSymbol, value);
return true;
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class GroupingNode method initAccumulator.
static AggregateFunction initAccumulator(AggregateSymbol aggSymbol, RelationalNode node, LinkedHashMap<Expression, Integer> expressionIndexes) {
int[] argIndexes = new int[aggSymbol.getArgs().length];
AggregateFunction result = null;
Expression[] args = aggSymbol.getArgs();
Class<?>[] inputTypes = new Class[args.length];
for (int j = 0; j < args.length; j++) {
inputTypes[j] = args[j].getType();
argIndexes[j] = getIndex(args[j], expressionIndexes);
}
Type function = aggSymbol.getAggregateFunction();
switch(function) {
case RANK:
case DENSE_RANK:
result = new RankingFunction(function);
break;
// same as count(*)
case ROW_NUMBER:
case COUNT:
result = new Count();
break;
case SUM:
result = new Sum();
break;
case AVG:
result = new Avg();
break;
case MIN:
result = new Min();
break;
case MAX:
result = new Max();
break;
case XMLAGG:
result = new XMLAgg();
break;
case ARRAY_AGG:
result = new ArrayAgg();
break;
case JSONARRAY_AGG:
result = new JSONArrayAgg();
break;
case TEXTAGG:
result = new TextAgg((TextLine) args[0]);
break;
case STRING_AGG:
result = new StringAgg(aggSymbol.getType() == DataTypeManager.DefaultDataClasses.BLOB);
break;
case FIRST_VALUE:
result = new FirstLastValue(aggSymbol.getType(), true);
break;
case LAST_VALUE:
result = new FirstLastValue(aggSymbol.getType(), false);
break;
case LEAD:
case LAG:
result = new LeadLagValue();
break;
case USER_DEFINED:
try {
result = new UserDefined(aggSymbol.getFunctionDescriptor());
} catch (FunctionExecutionException e) {
throw new TeiidRuntimeException(e);
}
break;
default:
result = new StatsFunction(function);
}
if (aggSymbol.getOrderBy() != null) {
int numOrderByItems = aggSymbol.getOrderBy().getOrderByItems().size();
List<OrderByItem> orderByItems = new ArrayList<OrderByItem>(numOrderByItems);
List<ElementSymbol> schema = createSortSchema(result, inputTypes);
argIndexes = Arrays.copyOf(argIndexes, argIndexes.length + numOrderByItems);
for (ListIterator<OrderByItem> iterator = aggSymbol.getOrderBy().getOrderByItems().listIterator(); iterator.hasNext(); ) {
OrderByItem item = iterator.next();
argIndexes[args.length + iterator.previousIndex()] = getIndex(item.getSymbol(), expressionIndexes);
ElementSymbol element = new ElementSymbol(String.valueOf(iterator.previousIndex()));
element.setType(item.getSymbol().getType());
schema.add(element);
OrderByItem newItem = item.clone();
newItem.setSymbol(element);
orderByItems.add(newItem);
}
SortingFilter filter = new SortingFilter(result, node.getBufferManager(), node.getConnectionID(), aggSymbol.isDistinct());
filter.setElements(schema);
filter.setSortItems(orderByItems);
result = filter;
} else if (aggSymbol.isDistinct()) {
SortingFilter filter = new SortingFilter(result, node.getBufferManager(), node.getConnectionID(), true);
List<ElementSymbol> elements = createSortSchema(result, inputTypes);
filter.setElements(elements);
result = filter;
}
result.setArgIndexes(argIndexes);
if (aggSymbol.getCondition() != null) {
result.setConditionIndex(getIndex(aggSymbol.getCondition(), expressionIndexes));
}
result.initialize(aggSymbol.getType(), inputTypes);
return result;
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class GroupingNode method getDescriptionProperties.
public PlanNode getDescriptionProperties() {
// Default implementation - should be overridden
PlanNode props = super.getDescriptionProperties();
if (orderBy != null) {
int elements = orderBy.size();
List<String> groupCols = new ArrayList<String>(elements);
for (int i = 0; i < elements; i++) {
groupCols.add(this.orderBy.get(i).toString());
}
props.addProperty(PROP_GROUP_COLS, groupCols);
}
if (outputMapping != null) {
List<String> groupCols = new ArrayList<String>(outputMapping.asMap().size());
for (Map.Entry<ElementSymbol, Expression> entry : outputMapping.asMap().entrySet()) {
groupCols.add(entry.toString());
}
props.addProperty(PROP_GROUP_MAPPING, groupCols);
}
props.addProperty(PROP_SORT_MODE, String.valueOf(this.removeDuplicates));
if (rollup) {
props.addProperty(PROP_ROLLUP, Boolean.TRUE.toString());
}
return props;
}
Aggregations