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);
}
}
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;
}
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);
}
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;
}
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;
}
Aggregations