Search in sources :

Example 6 with QueryMetadataException

use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.

the class MetaDataProcessor method createProjectedSymbolMetadata.

private Map<Integer, Object>[] createProjectedSymbolMetadata(Command originalCommand) throws TeiidComponentException {
    Map<Integer, Object>[] columnMetadata;
    // Allow command to use temporary metadata
    TempMetadataStore tempMetadata = originalCommand.getTemporaryMetadata();
    if (tempMetadata != null && tempMetadata.getData().size() > 0) {
        TempMetadataAdapter tempFacade = new TempMetadataAdapter(this.metadata, tempMetadata);
        this.metadata = tempFacade;
    }
    List<Expression> projectedSymbols = originalCommand.getProjectedSymbols();
    columnMetadata = new Map[projectedSymbols.size()];
    Iterator<Expression> symbolIter = projectedSymbols.iterator();
    for (int i = 0; symbolIter.hasNext(); i++) {
        Expression symbol = symbolIter.next();
        String shortColumnName = Symbol.getShortName(Symbol.getOutputName(symbol));
        if (symbol instanceof AliasSymbol) {
            symbol = ((AliasSymbol) symbol).getSymbol();
        }
        try {
            columnMetadata[i] = createColumnMetadata(shortColumnName, symbol);
        } catch (QueryMetadataException e) {
            throw new TeiidComponentException(QueryPlugin.Event.TEIID30559, e);
        }
    }
    return columnMetadata;
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) AliasSymbol(org.teiid.query.sql.symbol.AliasSymbol) Expression(org.teiid.query.sql.symbol.Expression) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) HashMap(java.util.HashMap) Map(java.util.Map) SymbolMap(org.teiid.query.sql.util.SymbolMap) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore)

Example 7 with QueryMetadataException

use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.

the class LanguageBridgeFactory method translate.

public NamedTable translate(GroupSymbol symbol) {
    String alias = null;
    String fullGroup = symbol.getOutputName();
    if (symbol.getOutputDefinition() != null) {
        alias = symbol.getOutputName();
        fullGroup = symbol.getOutputDefinition();
        if (remappedGroups != null) {
            GroupSymbol remappedGroup = remappedGroups.get(symbol.getMetadataID());
            if (remappedGroup != null && remappedGroup != symbol) {
                fullGroup = remappedGroup.getName();
            }
        }
    }
    fullGroup = removeSchemaName(fullGroup);
    NamedTable group = new NamedTable(fullGroup, alias, null);
    try {
        group.setMetadataObject(metadataFactory.getGroup(symbol.getMetadataID()));
    } catch (QueryMetadataException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30487, e);
    } catch (TeiidComponentException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30488, e);
    }
    return group;
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException)

Example 8 with QueryMetadataException

use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.

the class AuthorizationValidationVisitor method validateEntitlements.

/**
 * Validate query entitlements
 */
protected void validateEntitlements(Query obj) {
    // If query contains SELECT INTO, validate INTO portion
    Into intoObj = obj.getInto();
    if (intoObj != null) {
        GroupSymbol intoGroup = intoObj.getGroup();
        Collection<LanguageObject> intoElements = new LinkedList<LanguageObject>();
        intoElements.add(intoGroup);
        try {
            intoElements.addAll(ResolverUtil.resolveElementsInGroup(intoGroup, getMetadata()));
        } catch (QueryMetadataException err) {
            handleException(err, intoGroup);
        } catch (TeiidComponentException err) {
            handleException(err, intoGroup);
        }
        validateEntitlements(intoElements, DataPolicy.PermissionType.CREATE, Context.INSERT);
    }
    // Validate this query's entitlements
    Collection<LanguageObject> entitledObjects = new ArrayList<LanguageObject>(GroupCollectorVisitor.getGroupsIgnoreInlineViews(obj, true));
    entitledObjects.addAll(ElementCollectorVisitor.getElements(obj, true));
    if (entitledObjects.size() == 0) {
        return;
    }
    validateEntitlements(entitledObjects, DataPolicy.PermissionType.READ, Context.QUERY);
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) LanguageObject(org.teiid.query.sql.LanguageObject)

Example 9 with QueryMetadataException

use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.

the class ResolverUtil method resolveLookup.

public static ResolvedLookup resolveLookup(Function lookup, QueryMetadataInterface metadata) throws QueryResolverException, TeiidComponentException {
    Expression[] args = lookup.getArgs();
    ResolvedLookup result = new ResolvedLookup();
    // Special code to handle setting return type of the lookup function to match the type of the return element
    if (!(args[0] instanceof Constant) || !(args[1] instanceof Constant) || !(args[2] instanceof Constant)) {
        throw new QueryResolverException(QueryPlugin.Event.TEIID30095, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30095));
    }
    // If code table name in lookup function refers to temp group throw exception
    GroupSymbol groupSym = new GroupSymbol((String) ((Constant) args[0]).getValue());
    try {
        groupSym.setMetadataID(metadata.getGroupID((String) ((Constant) args[0]).getValue()));
        if (groupSym.getMetadataID() instanceof TempMetadataID) {
            throw new QueryResolverException(QueryPlugin.Event.TEIID30096, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30096, ((Constant) args[0]).getValue()));
        }
    } catch (QueryMetadataException e) {
        throw new QueryResolverException(QueryPlugin.Event.TEIID30097, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30097, ((Constant) args[0]).getValue()));
    }
    result.setGroup(groupSym);
    List<GroupSymbol> groups = Arrays.asList(groupSym);
    // $NON-NLS-1$
    String returnElementName = (String) ((Constant) args[0]).getValue() + "." + (String) ((Constant) args[1]).getValue();
    ElementSymbol returnElement = new ElementSymbol(returnElementName);
    try {
        ResolverVisitor.resolveLanguageObject(returnElement, groups, metadata);
    } catch (QueryMetadataException e) {
        throw new QueryResolverException(QueryPlugin.Event.TEIID30098, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30098, returnElementName));
    }
    result.setReturnElement(returnElement);
    // $NON-NLS-1$
    String keyElementName = (String) ((Constant) args[0]).getValue() + "." + (String) ((Constant) args[2]).getValue();
    ElementSymbol keyElement = new ElementSymbol(keyElementName);
    try {
        ResolverVisitor.resolveLanguageObject(keyElement, groups, metadata);
    } catch (QueryMetadataException e) {
        throw new QueryResolverException(QueryPlugin.Event.TEIID30099, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30099, keyElementName));
    }
    result.setKeyElement(keyElement);
    args[3] = convertExpression(args[3], DataTypeManager.getDataTypeName(keyElement.getType()), metadata);
    return result;
}
Also used : TempMetadataID(org.teiid.query.metadata.TempMetadataID) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Example 10 with QueryMetadataException

use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.

the class ResolverUtil method resolveGroup.

public static void resolveGroup(GroupSymbol symbol, QueryMetadataInterface metadata) throws TeiidComponentException, QueryResolverException {
    if (symbol.getMetadataID() != null) {
        return;
    }
    // determine the "metadataID" part of the symbol to look up
    String potentialID = symbol.getNonCorrelationName();
    String name = symbol.getName();
    String definition = symbol.getDefinition();
    Object groupID = null;
    try {
        // get valid GroupID for possibleID - this may throw exceptions if group is invalid
        groupID = metadata.getGroupID(potentialID);
    } catch (QueryMetadataException e) {
    // didn't find this group ID
    }
    // If that didn't work, try to strip a vdb name from potentialID
    if (groupID == null) {
        // $NON-NLS-1$
        String[] parts = potentialID.split("\\.", 2);
        if (parts.length > 1 && parts[0].equalsIgnoreCase(metadata.getVirtualDatabaseName())) {
            try {
                groupID = metadata.getGroupID(parts[1]);
            } catch (QueryMetadataException e) {
            // ignore - just didn't find it
            }
            if (groupID != null) {
                potentialID = parts[1];
            }
        }
    }
    // and there is only one group that matches the given partial name
    if (groupID == null) {
        Collection groupNames = null;
        try {
            groupNames = metadata.getGroupsForPartialName(potentialID);
        } catch (QueryMetadataException e) {
        // ignore - just didn't find it
        }
        if (groupNames != null) {
            int matches = groupNames.size();
            if (matches == 1) {
                potentialID = (String) groupNames.iterator().next();
                try {
                    // get valid GroupID for possibleID - this may throw exceptions if group is invalid
                    groupID = metadata.getGroupID(potentialID);
                } catch (QueryMetadataException e) {
                // didn't find this group ID
                }
            } else if (matches > 1) {
                // $NON-NLS-1$
                throw handleUnresolvedGroup(symbol, QueryPlugin.Util.getString("ERR.015.008.0055"));
            }
        }
    }
    if (groupID == null || metadata.isProcedure(groupID)) {
        // try procedure relational resolving
        try {
            StoredProcedureInfo storedProcedureInfo = metadata.getStoredProcedureInfoForProcedure(potentialID);
            symbol.setProcedure(true);
            groupID = storedProcedureInfo.getProcedureID();
        } catch (QueryMetadataException e) {
        // just ignore
        }
    }
    if (groupID == null) {
        // $NON-NLS-1$
        throw handleUnresolvedGroup(symbol, QueryPlugin.Util.getString("ERR.015.008.0056"));
    }
    // set real metadata ID in the symbol
    symbol.setMetadataID(groupID);
    potentialID = metadata.getFullName(groupID);
    if (symbol.getDefinition() == null) {
        symbol.setName(potentialID);
    } else {
        symbol.setDefinition(potentialID);
    }
    try {
        if (!symbol.isProcedure()) {
            symbol.setIsTempTable(metadata.isTemporaryTable(groupID));
        }
    } catch (QueryMetadataException e) {
    // should not come here
    }
    if (metadata.useOutputName()) {
        symbol.setOutputDefinition(definition);
        symbol.setOutputName(name);
    }
}
Also used : StoredProcedureInfo(org.teiid.query.metadata.StoredProcedureInfo) LanguageObject(org.teiid.query.sql.LanguageObject) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException)

Aggregations

QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)39 TeiidComponentException (org.teiid.core.TeiidComponentException)18 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)12 LanguageObject (org.teiid.query.sql.LanguageObject)7 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)6 TempMetadataID (org.teiid.query.metadata.TempMetadataID)6 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)5 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)3 TeiidException (org.teiid.core.TeiidException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)3 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)3 ObjectTable (org.teiid.query.sql.lang.ObjectTable)3 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)3 Expression (org.teiid.query.sql.symbol.Expression)3 Collection (java.util.Collection)2