use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class ResolverVisitor method setDesiredType.
private void setDesiredType(Expression obj, Class<?> type, LanguageObject surrounding) throws QueryResolverException {
ResolverUtil.setDesiredType(obj, type, surrounding);
// second pass resolving for functions
if (!(obj instanceof Function)) {
return;
}
if (unresolvedFunctions != null) {
Function f = (Function) obj;
if (f.getFunctionDescriptor() != null) {
return;
}
unresolvedFunctions.remove(obj);
obj.acceptVisitor(this);
QueryResolverException e = unresolvedFunctions.get(obj);
if (e != null) {
throw e;
}
}
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class ResolverVisitor method resolveSearchedCaseExpression.
void resolveSearchedCaseExpression(SearchedCaseExpression obj) throws QueryResolverException {
// If already resolved, do nothing
if (obj.getType() != null) {
return;
}
final int whenCount = obj.getWhenCount();
// 1. Call recursively to resolve any contained CASE expressions
Class<?> thenType = null;
// Get the WHEN and THEN types, and get a candidate type for each (for the next step)
for (int i = 0; i < whenCount; i++) {
if (thenType == null) {
thenType = obj.getThenExpression(i).getType();
}
}
Expression elseExpr = obj.getElseExpression();
if (elseExpr != null) {
if (thenType == null) {
thenType = elseExpr.getType();
}
}
// Invariant: All the expressions contained in the obj are resolved (except References)
// 2. Attempt to set the target types of all contained expressions,
// and collect their type names for the next step
ArrayList<String> thenTypeNames = new ArrayList<String>(whenCount + 1);
Expression then = null;
// Set the types of the WHEN and THEN parts
for (int i = 0; i < whenCount; i++) {
then = obj.getThenExpression(i);
setDesiredType(then, thenType, obj);
thenTypeNames.add(DataTypeManager.getDataTypeName(then.getType()));
}
// Set the type of the else expression
if (elseExpr != null) {
setDesiredType(elseExpr, thenType, obj);
thenTypeNames.add(DataTypeManager.getDataTypeName(elseExpr.getType()));
}
// Invariants: all the expressions' types are non-null
// 3. Perform implicit type conversions
String thenTypeName = ResolverUtil.getCommonRuntimeType(thenTypeNames.toArray(new String[thenTypeNames.size()]));
if (thenTypeName == null) {
// $NON-NLS-1$
throw new QueryResolverException(QueryPlugin.Event.TEIID30079, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30079, "THEN/ELSE", obj));
}
ArrayList<Expression> thens = new ArrayList<Expression>(whenCount);
for (int i = 0; i < whenCount; i++) {
thens.add(ResolverUtil.convertExpression(obj.getThenExpression(i), thenTypeName, metadata));
}
obj.setWhen(obj.getWhen(), thens);
if (elseExpr != null) {
obj.setElseExpression(ResolverUtil.convertExpression(elseExpr, thenTypeName, metadata));
}
// Set this CASE expression's type to the common THEN type, and we're done.
obj.setType(DataTypeManager.getDataTypeClass(thenTypeName));
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class ResolverVisitor method resolveQuantifiedCompareArray.
private void resolveQuantifiedCompareArray(SubqueryCompareCriteria obj) throws QueryResolverException, AssertionError {
Class<?> expressionType = obj.getArrayExpression().getType();
if (expressionType == null || !expressionType.isArray()) {
throw new QueryResolverException(QueryPlugin.Event.TEIID31175, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31175, new Object[] { obj.getArrayExpression(), expressionType }));
}
Class<?> rightType = expressionType.getComponentType();
Expression leftExpression = obj.getLeftExpression();
setDesiredType(leftExpression, rightType, obj);
if (leftExpression.getType().equals(rightType)) {
return;
}
// Try to apply an implicit conversion from one side to the other
String leftTypeName = DataTypeManager.getDataTypeName(leftExpression.getType());
String rightTypeName = DataTypeManager.getDataTypeName(rightType);
if (leftExpression.getType() == DataTypeManager.DefaultDataClasses.NULL) {
obj.setLeftExpression(ResolverUtil.convertExpression(leftExpression, rightTypeName, metadata));
return;
}
boolean leftChar = isCharacter(leftExpression, true);
boolean rightChar = isCharacter(rightType, true);
// Special cases when left expression is a constant
if (leftExpression instanceof Constant && (!rightChar || leftChar)) {
// Auto-convert constant string on left to expected type on right
try {
obj.setLeftExpression(ResolverUtil.convertExpression(leftExpression, leftTypeName, rightTypeName, metadata));
return;
} catch (QueryResolverException qre) {
if (leftChar && !metadata.widenComparisonToString()) {
throw qre;
}
}
}
// Try to apply a conversion generically
if ((rightChar ^ leftChar) && !metadata.widenComparisonToString()) {
throw new QueryResolverException(QueryPlugin.Event.TEIID31172, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31172, obj));
}
if (ResolverUtil.canImplicitlyConvert(leftTypeName, rightTypeName)) {
obj.setLeftExpression(ResolverUtil.convertExpression(leftExpression, leftTypeName, rightTypeName, metadata));
return;
}
throw new QueryResolverException(QueryPlugin.Event.TEIID30072, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30072, new Object[] { leftTypeName, rightTypeName, obj }));
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class ResolverVisitor method resolveLanguageObject.
public static void resolveLanguageObject(LanguageObject obj, Collection<GroupSymbol> groups, GroupContext externalContext, QueryMetadataInterface metadata) throws TeiidComponentException, QueryResolverException {
if (obj == null) {
return;
}
// Resolve elements, deal with errors
final ResolverVisitor elementsVisitor = new ResolverVisitor(metadata, groups, externalContext);
// special handling for is distinct - we must resolve as both element and group
// until we generalize the notion of a scalar group reference as an "elementsymbol"
PostOrderNavigator nav = new PostOrderNavigator(elementsVisitor) {
@Override
public void visit(IsDistinctCriteria obj) {
obj.setLeftRowValue(resolveAsGroup(obj.getLeftRowValue()));
obj.setRightRowValue(resolveAsGroup(obj.getRightRowValue()));
super.visit(obj);
}
private LanguageObject resolveAsGroup(LanguageObject rowValue) {
if (rowValue instanceof ElementSymbol) {
ElementSymbol es = (ElementSymbol) rowValue;
if (es.getMetadataID() == null) {
try {
elementsVisitor.resolveElementSymbol(es);
} catch (QueryResolverException | TeiidComponentException e) {
GroupSymbol gs = new GroupSymbol(es.getName());
try {
ResolverUtil.resolveGroup(gs, metadata);
rowValue = gs;
} catch (QueryResolverException | TeiidComponentException e1) {
}
}
}
}
return rowValue;
}
};
obj.acceptVisitor(nav);
elementsVisitor.throwException(true);
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class SetQuery method getTypedProjectedSymbols.
public static List<Expression> getTypedProjectedSymbols(List<? extends Expression> acutal, List<Class<?>> projectedTypes, QueryMetadataInterface metadata) {
List<Expression> newProject = new ArrayList<Expression>();
for (int i = 0; i < acutal.size(); i++) {
Expression originalSymbol = acutal.get(i);
Expression symbol = originalSymbol;
Class<?> type = projectedTypes.get(i);
if (symbol.getType() != type) {
symbol = SymbolMap.getExpression(originalSymbol);
try {
symbol = ResolverUtil.convertExpression(symbol, DataTypeManager.getDataTypeName(type), metadata);
} catch (QueryResolverException err) {
throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30447, err);
}
if (originalSymbol instanceof Symbol) {
symbol = new AliasSymbol(Symbol.getShortName(originalSymbol), symbol);
}
}
newProject.add(symbol);
}
return newProject;
}
Aggregations