Search in sources :

Example 41 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class TestValidator method helpRunValidator.

public static ValidatorReport helpRunValidator(Command command, String[] expectedStringArray, QueryMetadataInterface metadata) {
    try {
        ValidatorReport report = Validator.validate(command, metadata);
        examineReport(command, expectedStringArray, report);
        return report;
    } catch (TeiidException e) {
        throw new TeiidRuntimeException(e);
    }
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException)

Example 42 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class ExceptionHolder method buildException.

private Throwable buildException(List<String> classNames, String message, StackTraceElement[] stackTrace, String code) {
    String originalClass = Exception.class.getName();
    if (!classNames.isEmpty()) {
        originalClass = classNames.get(0);
    }
    // $NON-NLS-1$
    List<String> args = Arrays.asList(CorePlugin.Util.getString("ExceptionHolder.converted_exception", message, originalClass));
    Throwable result = null;
    for (String className : classNames) {
        try {
            result = (Throwable) ReflectionHelper.create(className, args, ExceptionHolder.class.getClassLoader());
            break;
        } catch (TeiidException e1) {
        // 
        }
    }
    if (result == null) {
        result = new TeiidRuntimeException(args.get(0));
    } else if (result instanceof TeiidException) {
        ((TeiidException) result).setCode(code);
        ((TeiidException) result).setOriginalType(classNames.get(0));
    }
    result.setStackTrace(stackTrace);
    return result;
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException)

Example 43 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class TranslationHelper method helpTranslate.

public static Command helpTranslate(String vdbFileName, String udf, List<FunctionMethod> pushdowns, String sql) {
    TranslationUtility util = getTranslationUtility(vdbFileName, null);
    if (pushdowns != null) {
        util.addUDF(CoreConstants.SYSTEM_MODEL, pushdowns);
    }
    if (udf != null) {
        Collection<FunctionMethod> methods = new ArrayList<FunctionMethod>();
        try {
            methods.addAll(FunctionMetadataReader.loadFunctionMethods(TranslationHelper.class.getResource(udf).openStream()));
        } catch (XMLStreamException e) {
            // $NON-NLS-1$
            throw new TeiidRuntimeException("failed to load UDF");
        } catch (IOException e) {
            // $NON-NLS-1$
            throw new TeiidRuntimeException("failed to load UDF");
        }
        // $NON-NLS-1$
        util.addUDF("foo", methods);
    }
    return util.parseCommand(sql);
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) TranslationUtility(org.teiid.cdk.api.TranslationUtility) ArrayList(java.util.ArrayList) FunctionMethod(org.teiid.metadata.FunctionMethod) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) IOException(java.io.IOException)

Example 44 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class RuleCollapseSource method rewriteGroupByAsView.

public static Query rewriteGroupByAsView(Query query, QueryMetadataInterface metadata, boolean addViewForOrderBy) {
    if (query.getGroupBy() == null) {
        return query;
    }
    Select select = query.getSelect();
    GroupBy groupBy = query.getGroupBy();
    if (!addViewForOrderBy) {
        query.setGroupBy(null);
    }
    Criteria having = query.getHaving();
    query.setHaving(null);
    OrderBy orderBy = query.getOrderBy();
    query.setOrderBy(null);
    Limit limit = query.getLimit();
    query.setLimit(null);
    Set<Expression> newSelectColumns = new LinkedHashSet<Expression>();
    for (final Iterator<Expression> iterator = groupBy.getSymbols().iterator(); iterator.hasNext(); ) {
        newSelectColumns.add(iterator.next());
    }
    Set<AggregateSymbol> aggs = new HashSet<AggregateSymbol>();
    aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(select, true));
    if (having != null) {
        aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(having, true));
    }
    for (AggregateSymbol aggregateSymbol : aggs) {
        for (Expression expr : aggregateSymbol.getArgs()) {
            newSelectColumns.add(SymbolMap.getExpression(expr));
        }
    }
    Select innerSelect = new Select();
    for (Expression expr : newSelectColumns) {
        innerSelect.addSymbol(expr);
    }
    query.setSelect(innerSelect);
    Query outerQuery = null;
    try {
        // $NON-NLS-1$
        outerQuery = QueryRewriter.createInlineViewQuery(new GroupSymbol("X"), query, metadata, query.getSelect().getProjectedSymbols());
    } catch (TeiidException err) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30257, err);
    }
    Iterator<Expression> iter = outerQuery.getSelect().getProjectedSymbols().iterator();
    HashMap<Expression, Expression> expressionMap = new HashMap<Expression, Expression>();
    for (Expression symbol : query.getSelect().getProjectedSymbols()) {
        // need to unwrap on both sides as the select expression could be aliased
        // TODO: could add an option to createInlineViewQuery to disable alias creation
        expressionMap.put(SymbolMap.getExpression(symbol), SymbolMap.getExpression(iter.next()));
    }
    if (!addViewForOrderBy) {
        ExpressionMappingVisitor.mapExpressions(groupBy, expressionMap);
        outerQuery.setGroupBy(groupBy);
    }
    ExpressionMappingVisitor.mapExpressions(having, expressionMap, true);
    outerQuery.setHaving(having);
    ExpressionMappingVisitor.mapExpressions(orderBy, expressionMap, true);
    outerQuery.setOrderBy(orderBy);
    outerQuery.setLimit(limit);
    ExpressionMappingVisitor.mapExpressions(select, expressionMap, true);
    outerQuery.setSelect(select);
    outerQuery.setOption(query.getOption());
    query = outerQuery;
    return query;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 45 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class PlanToProcessConverter method aliasCommand.

private Command aliasCommand(AccessNode aNode, Command command, Object modelID) throws TeiidComponentException, QueryPlannerException {
    try {
        command = (Command) command.clone();
        boolean aliasGroups = modelID != null && (CapabilitiesUtil.supportsGroupAliases(modelID, metadata, capFinder) || CapabilitiesUtil.supports(Capability.QUERY_FROM_INLINE_VIEWS, modelID, metadata, capFinder));
        boolean aliasColumns = modelID != null && (CapabilitiesUtil.supports(Capability.QUERY_SELECT_EXPRESSION, modelID, metadata, capFinder) || CapabilitiesUtil.supports(Capability.QUERY_FROM_INLINE_VIEWS, modelID, metadata, capFinder));
        AliasGenerator visitor = new AliasGenerator(aliasGroups, !aliasColumns);
        SourceHint sh = command.getSourceHint();
        if (sh != null && aliasGroups) {
            VDBMetaData vdb = context.getDQPWorkContext().getVDB();
            ModelMetaData model = vdb.getModel(aNode.getModelName());
            List<String> sourceNames = model.getSourceNames();
            SpecificHint sp = null;
            if (sourceNames.size() == 1) {
                sp = sh.getSpecificHint(sourceNames.get(0));
            }
            if (sh.isUseAliases() || (sp != null && sp.isUseAliases())) {
                visitor.setAliasMapping(context.getAliasMapping());
            }
        }
        List<Reference> references = ReferenceCollectorVisitor.getReferences(command);
        if (!references.isEmpty()) {
            Set<String> correleatedGroups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
            for (Reference ref : references) {
                if (ref.isCorrelated() && ref.getExpression().getGroupSymbol() != null) {
                    correleatedGroups.add(ref.getExpression().getGroupSymbol().getName());
                }
            }
            visitor.setCorrelationGroups(correleatedGroups);
        }
        command.acceptVisitor(visitor);
    } catch (QueryMetadataException err) {
        throw new TeiidComponentException(QueryPlugin.Event.TEIID30249, err);
    } catch (TeiidRuntimeException e) {
        if (e.getCause() instanceof QueryPlannerException) {
            throw (QueryPlannerException) e.getCause();
        }
        throw e;
    }
    return command;
}
Also used : Reference(org.teiid.query.sql.symbol.Reference) SpecificHint(org.teiid.query.sql.lang.SourceHint.SpecificHint) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryPlannerException(org.teiid.api.exception.query.QueryPlannerException)

Aggregations

TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)103 IOException (java.io.IOException)27 TeiidComponentException (org.teiid.core.TeiidComponentException)22 TeiidException (org.teiid.core.TeiidException)22 ArrayList (java.util.ArrayList)20 TeiidProcessingException (org.teiid.core.TeiidProcessingException)17 SQLException (java.sql.SQLException)11 ObjectInputStream (java.io.ObjectInputStream)9 HashMap (java.util.HashMap)9 InputStream (java.io.InputStream)7 Map (java.util.Map)7 Test (org.junit.Test)7 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)7 ObjectOutputStream (java.io.ObjectOutputStream)6 List (java.util.List)6 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)5 JsonObject (com.couchbase.client.java.document.json.JsonObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4