Search in sources :

Example 11 with LanguageObject

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);
    }
}
Also used : SaxonXQueryExpression(org.teiid.query.xquery.saxon.SaxonXQueryExpression) List(java.util.List) LinkedList(java.util.LinkedList) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidComponentException(org.teiid.core.TeiidComponentException) Constraint(org.teiid.query.sql.symbol.Reference.Constraint)

Example 12 with LanguageObject

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;
    }
}
Also used : PreOrderNavigator(org.teiid.query.sql.navigator.PreOrderNavigator) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) LanguageObject(org.teiid.query.sql.LanguageObject)

Example 13 with LanguageObject

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;
}
Also used : SubqueryContainer(org.teiid.query.sql.lang.SubqueryContainer) LinkedList(java.util.LinkedList) LanguageObject(org.teiid.query.sql.LanguageObject)

Example 14 with LanguageObject

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);
    }
}
Also used : ExceptionExpression(org.teiid.query.sql.proc.ExceptionExpression) PreOrPostOrderNavigator(org.teiid.query.sql.navigator.PreOrPostOrderNavigator) Map(java.util.Map) LanguageObject(org.teiid.query.sql.LanguageObject) HashSet(java.util.HashSet)

Example 15 with LanguageObject

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);
        }
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) LanguageObject(org.teiid.query.sql.LanguageObject)

Aggregations

LanguageObject (org.teiid.query.sql.LanguageObject)28 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)8 TeiidComponentException (org.teiid.core.TeiidComponentException)7 ArrayList (java.util.ArrayList)5 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)5 HashSet (java.util.HashSet)3 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)3 Command (org.teiid.query.sql.lang.Command)3 Criteria (org.teiid.query.sql.lang.Criteria)3 Select (org.teiid.query.sql.lang.Select)3 Expression (org.teiid.query.sql.symbol.Expression)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)2 MultiSourceElement (org.teiid.dqp.internal.process.multisource.MultiSourceElement)2 TempMetadataID (org.teiid.query.metadata.TempMetadataID)2 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)2 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)2