use of org.teiid.api.exception.query.ExpressionEvaluationException in project teiid by teiid.
the class TestGeometry method testTextError.
@Test
public void testTextError() throws Exception {
Expression ex = TestFunctionResolving.getExpression("ST_GeomFromText('''hello''')");
try {
Evaluator.evaluate(ex);
fail();
} catch (ExpressionEvaluationException e) {
assertNull(ExceptionUtil.getExceptionOfType(e, NullPointerException.class));
}
}
use of org.teiid.api.exception.query.ExpressionEvaluationException in project teiid by teiid.
the class ValidationVisitor method validateInsert.
protected void validateInsert(Insert obj) {
Collection<ElementSymbol> vars = obj.getVariables();
Iterator<ElementSymbol> varIter = vars.iterator();
Collection values = obj.getValues();
Iterator valIter = values.iterator();
GroupSymbol insertGroup = obj.getGroup();
try {
Set<ElementSymbol> seen = new HashSet<ElementSymbol>();
boolean multiSource = getMetadata().isMultiSource(getMetadata().getModelID(insertGroup.getMetadataID()));
// Validate that all elements in variable list are updatable
for (ElementSymbol insertElem : vars) {
if (!getMetadata().elementSupports(insertElem.getMetadataID(), SupportConstants.Element.UPDATE) && !isUpsertKeyColumn(obj, insertElem)) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0052", insertElem), insertElem);
}
if (multiSource && getMetadata().isMultiSourceElement(insertElem.getMetadataID())) {
multiSource = false;
}
if (!seen.add(insertElem)) {
handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31179, obj.getGroup(), insertElem), insertElem);
}
}
if (multiSource) {
validateMultisourceInsert(insertGroup);
}
// Get elements in the group.
Collection<ElementSymbol> insertElmnts = new LinkedList<ElementSymbol>(ResolverUtil.resolveElementsInGroup(insertGroup, getMetadata()));
// remove all elements specified in insert to get the ignored elements
insertElmnts.removeAll(vars);
for (ElementSymbol nextElmnt : insertElmnts) {
if (!getMetadata().elementSupports(nextElmnt.getMetadataID(), SupportConstants.Element.DEFAULT_VALUE) && !getMetadata().elementSupports(nextElmnt.getMetadataID(), SupportConstants.Element.NULL) && !getMetadata().elementSupports(nextElmnt.getMetadataID(), SupportConstants.Element.AUTO_INCREMENT)) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0053", new Object[] { insertGroup, nextElmnt }), nextElmnt);
}
}
// if any of the value present in the insert are null
while (valIter.hasNext() && varIter.hasNext()) {
Expression nextValue = (Expression) valIter.next();
ElementSymbol nextVar = varIter.next();
if (EvaluatableVisitor.isFullyEvaluatable(nextValue, true)) {
try {
// If nextValue is an expression, evaluate it before checking for null
Object evaluatedValue = Evaluator.evaluate(nextValue);
if (evaluatedValue == null && !getMetadata().elementSupports(nextVar.getMetadataID(), SupportConstants.Element.NULL)) {
// as an upsert key it can mean an insert
if (!isUpsertKeyColumn(obj, nextVar) || !(getMetadata().elementSupports(nextVar.getMetadataID(), SupportConstants.Element.AUTO_INCREMENT) || getMetadata().elementSupports(nextVar.getMetadataID(), SupportConstants.Element.DEFAULT_VALUE))) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0055", nextVar), nextVar);
}
}
} catch (ExpressionEvaluationException e) {
// ignore for now, we don't have the context which could be the problem
}
}
}
// end of while
} catch (TeiidComponentException e) {
handleException(e, obj);
}
}
use of org.teiid.api.exception.query.ExpressionEvaluationException in project teiid by teiid.
the class ValidationVisitor method validateUpdate.
protected void validateUpdate(Update update) {
try {
UpdateInfo info = update.getUpdateInfo();
// list of elements that are being updated
for (SetClause entry : update.getChangeList().getClauses()) {
ElementSymbol elementID = entry.getSymbol();
// Check that left side element is updatable
if (!getMetadata().elementSupports(elementID.getMetadataID(), SupportConstants.Element.UPDATE)) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0059", elementID), elementID);
}
Object metadataID = elementID.getMetadataID();
if (getMetadata().isMultiSourceElement(metadataID)) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("multi_source_update_not_allowed", elementID), elementID);
}
// Check that right expression is a constant and is non-null
Expression value = entry.getValue();
if (EvaluatableVisitor.isFullyEvaluatable(value, true)) {
try {
value = new Constant(Evaluator.evaluate(value));
} catch (ExpressionEvaluationException err) {
}
}
if (value instanceof Constant) {
// If value is null, check that element supports this as a nullable column
if (((Constant) value).isNull() && !getMetadata().elementSupports(elementID.getMetadataID(), SupportConstants.Element.NULL)) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0060", SQLStringVisitor.getSQLString(elementID)), elementID);
}
// end of if
}
}
if (info != null && info.isInherentUpdate()) {
validateUpdate(update, Command.TYPE_UPDATE, info);
Set<ElementSymbol> updateCols = update.getChangeList().getClauseMap().keySet();
if (!info.hasValidUpdateMapping(updateCols)) {
handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30376, updateCols), update);
}
}
} catch (TeiidException e) {
handleException(e, update);
}
validateSetClauseList(update.getChangeList());
}
use of org.teiid.api.exception.query.ExpressionEvaluationException in project teiid by teiid.
the class RowBasedSecurityHelper method evaluateConstraint.
private static void evaluateConstraint(Command atomicCommand, Evaluator eval, Criteria constraint, Map<ElementSymbol, Expression> values) throws BlockedException, TeiidComponentException, QueryProcessingException {
Criteria clone = (Criteria) constraint.clone();
ExpressionMappingVisitor.mapExpressions(clone, values);
try {
if (!eval.evaluate(clone, null)) {
throw new QueryProcessingException(QueryPlugin.Event.TEIID31130, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31130, atomicCommand));
}
} catch (ExpressionEvaluationException e) {
throw new QueryProcessingException(QueryPlugin.Event.TEIID31130, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31130, atomicCommand));
}
}
use of org.teiid.api.exception.query.ExpressionEvaluationException in project teiid by teiid.
the class PreparedStatementRequest method resolveParameterValues.
/**
* @param params
* @param values
* @throws QueryResolverException
* @throws QueryValidatorException
*/
public static void resolveParameterValues(List<Reference> params, List values, CommandContext context, QueryMetadataInterface metadata) throws QueryResolverException, TeiidComponentException, QueryValidatorException {
VariableContext result = new VariableContext();
// the size of the values must be the same as that of the parameters
if (params.size() != values.size()) {
// $NON-NLS-1$
String msg = QueryPlugin.Util.getString("QueryUtil.wrong_number_of_values", new Object[] { new Integer(values.size()), new Integer(params.size()) });
throw new QueryResolverException(QueryPlugin.Event.TEIID30556, msg);
}
boolean embedded = context != null && context.getSession() != null && context.getSession().isEmbedded();
// to that of the reference
for (int i = 0; i < params.size(); i++) {
Reference param = params.get(i);
Object value = values.get(i);
if (value != null) {
if (embedded && value instanceof BaseLob) {
createStreamCopy(context, i, param, value);
}
try {
String targetTypeName = DataTypeManager.getDataTypeName(param.getType());
Expression expr = ResolverUtil.convertExpression(new Constant(DataTypeManager.convertToRuntimeType(value, param.getType() != DataTypeManager.DefaultDataClasses.OBJECT)), targetTypeName, metadata);
value = Evaluator.evaluate(expr);
} catch (ExpressionEvaluationException e) {
// $NON-NLS-1$
String msg = QueryPlugin.Util.getString("QueryUtil.Error_executing_conversion_function_to_convert_value", i + 1, value, value.getClass(), DataTypeManager.getDataTypeName(param.getType()));
throw new QueryResolverException(QueryPlugin.Event.TEIID30557, e, msg);
} catch (QueryResolverException e) {
// $NON-NLS-1$
String msg = QueryPlugin.Util.getString("QueryUtil.Error_executing_conversion_function_to_convert_value", i + 1, value, value.getClass(), DataTypeManager.getDataTypeName(param.getType()));
throw new QueryResolverException(QueryPlugin.Event.TEIID30558, e, msg);
}
}
if (param.getConstraint() != null) {
param.getConstraint().validate(value);
}
// bind variable
result.setGlobalValue(param.getContextSymbol(), value);
}
context.setVariableContext(result);
}
Aggregations