use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class ResolverVisitor method visit.
@Override
public void visit(Array array) {
try {
if (array.getComponentType() != null) {
String type = DataTypeManager.getDataTypeName(array.getComponentType());
for (int i = 0; i < array.getExpressions().size(); i++) {
Expression expr = array.getExpressions().get(i);
setDesiredType(expr, array.getComponentType(), array);
if (array.getComponentType() != DefaultDataClasses.OBJECT) {
array.getExpressions().set(i, ResolverUtil.convertExpression(expr, type, metadata));
}
}
} else {
resolveComponentType(array);
}
} catch (QueryResolverException e) {
handleException(e);
}
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class ResolverVisitor method checkException.
public static void checkException(Expression obj) throws QueryResolverException {
if (obj == null || obj instanceof ExceptionExpression) {
return;
}
if (obj instanceof ElementSymbol) {
ElementSymbol es = (ElementSymbol) obj;
if (!(es.getMetadataID() instanceof TempMetadataID)) {
throw new QueryResolverException(QueryPlugin.Event.TEIID31120, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31120, obj));
}
TempMetadataID tid = (TempMetadataID) es.getMetadataID();
if (tid.getType() != Exception.class) {
throw new QueryResolverException(QueryPlugin.Event.TEIID31120, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31120, obj));
}
} else if (obj instanceof Constant) {
Constant c = (Constant) obj;
if (!(c.getValue() instanceof Exception)) {
throw new QueryResolverException(QueryPlugin.Event.TEIID31120, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31120, obj));
}
} else {
throw new QueryResolverException(QueryPlugin.Event.TEIID31120, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31120, obj));
}
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class ResolverVisitor method resolveMatchCriteriaExpression.
/**
* Checks one side of a LIKE Criteria; implicitly converts to a String or CLOB if necessary.
* @param mcrit the Match Criteria
* @param expr either left or right expression
* @return either 'expr' itself, or a new implicit type conversion wrapping expr
* @throws QueryResolverException if no implicit type conversion is available
*/
Expression resolveMatchCriteriaExpression(MatchCriteria mcrit, Expression expr) throws QueryResolverException {
// Check left expression == string or CLOB
String type = DataTypeManager.getDataTypeName(expr.getType());
Expression result = expr;
if (type != null) {
if (!isCharacter(expr, false)) {
if (ResolverUtil.canImplicitlyConvert(type, DataTypeManager.DefaultDataTypes.STRING)) {
result = ResolverUtil.convertExpression(expr, type, DataTypeManager.DefaultDataTypes.STRING, metadata);
} else if (ResolverUtil.canImplicitlyConvert(type, DataTypeManager.DefaultDataTypes.CLOB)) {
result = ResolverUtil.convertExpression(expr, type, DataTypeManager.DefaultDataTypes.CLOB, metadata);
} else {
throw new QueryResolverException(QueryPlugin.Event.TEIID30074, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30074, mcrit));
}
}
}
return result;
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class ResolverVisitor method resolveSetCriteria.
void resolveSetCriteria(SetCriteria scrit) throws QueryResolverException {
// Check that each of the values are the same type as expression
Class<?> exprType = scrit.getExpression().getType();
if (exprType == null) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30075, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30075, scrit.getExpression()));
}
// check if all types are the same, or if there is a common type
boolean same = true;
Iterator valIter = scrit.getValues().iterator();
String[] types = new String[scrit.getValues().size()];
int i = 0;
Class<?> type = null;
while (valIter.hasNext()) {
Expression value = (Expression) valIter.next();
if (value.getType() != exprType) {
same = false;
}
types[i++] = DataTypeManager.getDataTypeName(value.getType());
type = value.getType();
}
if (same && type == exprType) {
return;
}
if (!same) {
String commonType = ResolverUtil.getCommonRuntimeType(types);
if (commonType != null) {
type = DataTypeManager.getDataTypeClass(commonType);
} else {
type = null;
}
}
String exprTypeName = DataTypeManager.getDataTypeName(exprType);
boolean attemptConvert = !isCharacter(exprType, true) || metadata.widenComparisonToString();
List<Expression> newVals = new ArrayList<Expression>(scrit.getValues().size());
if (scrit.getExpression().getType() != DataTypeManager.DefaultDataClasses.NULL) {
valIter = scrit.getValues().iterator();
while (valIter.hasNext()) {
Expression value = (Expression) valIter.next();
setDesiredType(value, exprType, scrit);
if (value.getType() != exprType) {
String valTypeName = DataTypeManager.getDataTypeName(value.getType());
// Apply cast and replace current value
if (attemptConvert || isCharacter(value.getType(), true)) {
try {
newVals.add(ResolverUtil.convertExpression(value, valTypeName, exprTypeName, metadata));
} catch (QueryResolverException e) {
if (value instanceof Constant && isCharacter(value, true) && !metadata.widenComparisonToString()) {
throw e;
}
if (type == null) {
type = value.getType();
}
break;
}
}
} else {
newVals.add(value);
}
}
if (newVals.size() == scrit.getValues().size()) {
scrit.setValues(newVals);
return;
}
}
// set is the same and the convert can be placed on the left side
if (type == null) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30077, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30077, scrit));
}
// Is there a possible conversion from left to right?
String setTypeName = DataTypeManager.getDataTypeName(type);
if (!isCharacter(type, true) || metadata.widenComparisonToString() || scrit.getExpression().getType() == DataTypeManager.DefaultDataClasses.NULL) {
scrit.setExpression(ResolverUtil.convertExpression(scrit.getExpression(), exprTypeName, setTypeName, metadata));
} else if (type != scrit.getExpression().getType()) {
throw new QueryResolverException(QueryPlugin.Event.TEIID31172, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31172, scrit));
}
boolean exprChar = isCharacter(scrit.getExpression(), true);
newVals.clear();
valIter = scrit.getValues().iterator();
while (valIter.hasNext()) {
Expression value = (Expression) valIter.next();
if (value.getType() == null) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30075, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30075, value));
} else if (value.getType() != type) {
if (!metadata.widenComparisonToString() && exprChar ^ isCharacter(value, true)) {
throw new QueryResolverException(QueryPlugin.Event.TEIID31172, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31172, scrit));
}
value = ResolverUtil.convertExpression(value, setTypeName, metadata);
}
newVals.add(value);
}
scrit.setValues(newVals);
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class ResolverVisitor method visit.
@Override
public void visit(AggregateSymbol obj) {
if (obj.getCondition() != null) {
try {
obj.setCondition(ResolverUtil.convertExpression(obj.getCondition(), DataTypeManager.DefaultDataTypes.BOOLEAN, metadata));
} catch (QueryResolverException e) {
handleException(e);
}
}
switch(obj.getAggregateFunction()) {
case USER_DEFINED:
visit((Function) obj);
break;
case LEAD:
case LAG:
if (obj.getArgs().length > 1) {
// second arg must be an integer
try {
obj.getArgs()[1] = ResolverUtil.convertExpression(obj.getArg(1), DataTypeManager.DefaultDataTypes.INTEGER, metadata);
} catch (QueryResolverException e) {
handleException(e);
}
// first and third args must match type
if (obj.getArgs().length > 2) {
try {
if (obj.getArgs()[0].getType() == DataTypeManager.DefaultDataClasses.NULL) {
obj.getArgs()[0] = ResolverUtil.convertExpression(obj.getArg(0), DataTypeManager.getDataTypeName(obj.getArg(2).getType()), metadata);
} else {
obj.getArgs()[2] = ResolverUtil.convertExpression(obj.getArg(2), DataTypeManager.getDataTypeName(obj.getArg(0).getType()), metadata);
}
} catch (QueryResolverException e) {
handleException(e);
}
}
}
break;
case STRING_AGG:
try {
if (obj.getArgs().length != 2) {
throw new QueryResolverException(QueryPlugin.Event.TEIID31140, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31140, obj));
}
if (obj.getType() == null) {
Expression arg = obj.getArg(0);
Expression arg1 = obj.getArg(1);
Class<?> type = null;
if (isBinary(arg)) {
setDesiredType(arg1, DataTypeManager.DefaultDataClasses.BLOB, obj);
if (isBinary(arg1)) {
type = DataTypeManager.DefaultDataClasses.BLOB;
}
} else if (isCharacter(arg, false)) {
setDesiredType(arg1, DataTypeManager.DefaultDataClasses.CLOB, obj);
if (isCharacter(arg1, false)) {
type = DataTypeManager.DefaultDataClasses.CLOB;
}
} else if (arg.getType() == null) {
if (isBinary(arg1)) {
setDesiredType(arg, DataTypeManager.DefaultDataClasses.BLOB, obj);
if (isBinary(arg)) {
type = DataTypeManager.DefaultDataClasses.BLOB;
}
} else if (isCharacter(arg1, false)) {
setDesiredType(arg, DataTypeManager.DefaultDataClasses.CLOB, obj);
if (isCharacter(arg, false)) {
type = DataTypeManager.DefaultDataClasses.CLOB;
}
}
}
if (type == null) {
throw new QueryResolverException(QueryPlugin.Event.TEIID31141, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31141, obj));
}
obj.setType(type);
}
} catch (QueryResolverException e) {
handleException(e);
}
break;
}
}
Aggregations