use of org.teiid.query.sql.LanguageObject in project teiid by teiid.
the class ValidationVisitor method validateInto.
private void validateInto(LanguageObject query, List<Expression> symbols, GroupSymbol intoGroup) {
try {
List elementIDs = getMetadata().getElementIDsInGroupID(intoGroup.getMetadataID());
// Check if there are too many elements in the SELECT clause
if (symbols.size() != elementIDs.size()) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.select_into_wrong_elements", new Object[] { new Integer(elementIDs.size()), new Integer(symbols.size()) }), query);
return;
}
for (int symbolNum = 0; symbolNum < symbols.size(); symbolNum++) {
Expression symbol = symbols.get(symbolNum);
Object elementID = elementIDs.get(symbolNum);
// Check if supports updates
if (!getMetadata().elementSupports(elementID, SupportConstants.Element.UPDATE)) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.element_updates_not_allowed", getMetadata().getFullName(elementID)), intoGroup);
}
Class<?> symbolType = symbol.getType();
String symbolTypeName = DataTypeManager.getDataTypeName(symbolType);
String targetTypeName = getMetadata().getElementRuntimeTypeName(elementID);
if (symbolTypeName.equals(targetTypeName)) {
continue;
}
if (!DataTypeManager.isImplicitConversion(symbolTypeName, targetTypeName)) {
// If there's no implicit conversion between the two
Object[] params = new Object[] { symbolTypeName, targetTypeName, new Integer(symbolNum + 1), query };
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.select_into_no_implicit_conversion", params), query);
continue;
}
}
} catch (TeiidComponentException e) {
handleException(e, query);
}
}
use of org.teiid.query.sql.LanguageObject in project teiid by teiid.
the class Validator method executeValidation.
private static final void executeValidation(LanguageObject object, final QueryMetadataInterface metadata, final AbstractValidationVisitor visitor) throws TeiidComponentException {
// Reset visitor
visitor.reset();
visitor.setMetadata(metadata);
setTempMetadata(metadata, visitor, object);
PreOrderNavigator nav = new PreOrderNavigator(visitor) {
protected void visitNode(LanguageObject obj) {
QueryMetadataInterface previous = visitor.getMetadata();
setTempMetadata(metadata, visitor, obj);
super.visitNode(obj);
visitor.setMetadata(previous);
}
@Override
protected void preVisitVisitor(LanguageObject obj) {
super.preVisitVisitor(obj);
visitor.stack.add(obj);
}
@Override
protected void postVisitVisitor(LanguageObject obj) {
visitor.stack.pop();
}
};
object.acceptVisitor(nav);
// If an error occurred, throw an exception
TeiidComponentException e = visitor.getException();
if (e != null) {
throw e;
}
}
use of org.teiid.query.sql.LanguageObject in project teiid by teiid.
the class ValueIteratorProviderCollectorVisitor method getValueIteratorProviders.
public static final List<SubqueryContainer<?>> getValueIteratorProviders(Collection<? extends LanguageObject> languageObjects) {
if (languageObjects == null || languageObjects.isEmpty()) {
return Collections.emptyList();
}
List<SubqueryContainer<?>> result = new LinkedList<SubqueryContainer<?>>();
ValueIteratorProviderCollectorVisitor visitor = new ValueIteratorProviderCollectorVisitor(result);
for (LanguageObject obj : languageObjects) {
PreOrderNavigator.doVisit(obj, visitor);
}
return result;
}
use of org.teiid.query.sql.LanguageObject in project teiid by teiid.
the class ExpressionMappingVisitor method mapExpressions.
/**
* The object is modified in place, so is not returned.
* @param obj Language object
* @param exprMap Expression map, Expression to Expression
*/
public static void mapExpressions(LanguageObject obj, Map<? extends Expression, ? extends Expression> exprMap, boolean deep) {
if (obj == null || exprMap == null || exprMap.isEmpty()) {
return;
}
final ExpressionMappingVisitor visitor = new ExpressionMappingVisitor(exprMap);
visitor.elementSymbolsOnly = true;
boolean preOrder = true;
boolean useReverseMapping = true;
for (Map.Entry<? extends Expression, ? extends Expression> entry : exprMap.entrySet()) {
if (!(entry.getKey() instanceof ElementSymbol)) {
visitor.elementSymbolsOnly = false;
break;
}
}
if (!visitor.elementSymbolsOnly) {
for (Map.Entry<? extends Expression, ? extends Expression> entry : exprMap.entrySet()) {
if (!(entry.getValue() instanceof ElementSymbol)) {
useReverseMapping = !Collections.disjoint(GroupsUsedByElementsVisitor.getGroups(exprMap.keySet()), GroupsUsedByElementsVisitor.getGroups(exprMap.values()));
break;
}
}
} else {
preOrder = false;
useReverseMapping = false;
}
if (useReverseMapping) {
final Set<Expression> reverseSet = new HashSet<Expression>(exprMap.values());
PreOrPostOrderNavigator pon = new PreOrPostOrderNavigator(visitor, PreOrPostOrderNavigator.PRE_ORDER, deep) {
@Override
protected void visitNode(LanguageObject obj) {
if (!(obj instanceof Expression) || !reverseSet.contains(obj)) {
super.visitNode(obj);
}
}
};
obj.acceptVisitor(pon);
} else {
PreOrPostOrderNavigator.doVisit(obj, visitor, preOrder, deep);
}
}
use of org.teiid.query.sql.LanguageObject in project teiid by teiid.
the class GroupsUsedByElementsVisitor method getGroups.
public static void getGroups(Collection<? extends LanguageObject> objects, Set<GroupSymbol> groups) {
// Get groups from elements
for (LanguageObject languageObject : objects) {
if (languageObject instanceof ElementSymbol) {
ElementSymbol elem = (ElementSymbol) languageObject;
groups.add(elem.getGroupSymbol());
} else {
GroupsUsedByElementsVisitor.getGroups(languageObject, groups);
}
}
}
Aggregations