use of org.teiid.api.exception.query.QueryValidatorException in project teiid by teiid.
the class Evaluator method internalEvaluate.
protected Object internalEvaluate(Expression expression, List<?> tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
if (expression instanceof DerivedExpression) {
if (elements != null) {
// Try to evaluate by lookup in the elements map (may work for both ElementSymbol and ExpressionSymbol
Integer index = (Integer) elements.get(expression);
if (index != null) {
return tuple.get(index.intValue());
}
}
// Otherwise this should be an ExpressionSymbol and we just need to dive in and evaluate the expression itself
if (expression instanceof ExpressionSymbol) {
ExpressionSymbol exprSyb = (ExpressionSymbol) expression;
Expression expr = exprSyb.getExpression();
return internalEvaluate(expr, tuple);
}
return getContext(expression).getFromContext(expression);
}
if (expression instanceof Constant) {
Constant c = (Constant) expression;
if (c.isMultiValued()) {
// $NON-NLS-1$
throw new AssertionError("Multi-valued constant not allowed to be directly evaluated");
}
return c.getValue();
} else if (expression instanceof Function) {
return evaluate((Function) expression, tuple);
} else if (expression instanceof CaseExpression) {
return evaluate((CaseExpression) expression, tuple);
} else if (expression instanceof SearchedCaseExpression) {
return evaluate((SearchedCaseExpression) expression, tuple);
} else if (expression instanceof Reference) {
Reference ref = (Reference) expression;
if (ref.isPositional() && ref.getExpression() == null) {
return getContext(ref).getVariableContext().getGlobalValue(ref.getContextSymbol());
}
Object result = getContext(ref.getExpression()).getFromContext(ref.getExpression());
if (ref.getConstraint() != null) {
try {
ref.getConstraint().validate(result);
} catch (QueryValidatorException e) {
throw new ExpressionEvaluationException(e);
}
}
return result;
} else if (expression instanceof Criteria) {
return evaluate((Criteria) expression, tuple);
} else if (expression instanceof ScalarSubquery) {
return evaluate((ScalarSubquery) expression, tuple);
} else if (expression instanceof Criteria) {
return evaluate((Criteria) expression, tuple);
} else if (expression instanceof TextLine) {
return evaluateTextLine(tuple, (TextLine) expression);
} else if (expression instanceof XMLElement) {
return evaluateXMLElement(tuple, (XMLElement) expression);
} else if (expression instanceof XMLForest) {
return evaluateXMLForest(tuple, (XMLForest) expression);
} else if (expression instanceof JSONObject) {
return evaluateJSONObject(tuple, (JSONObject) expression, null);
} else if (expression instanceof XMLSerialize) {
return evaluateXMLSerialize(tuple, (XMLSerialize) expression);
} else if (expression instanceof XMLQuery) {
return evaluateXMLQuery(tuple, (XMLQuery) expression, false);
} else if (expression instanceof QueryString) {
return evaluateQueryString(tuple, (QueryString) expression);
} else if (expression instanceof XMLParse) {
return evaluateXMLParse(tuple, (XMLParse) expression);
} else if (expression instanceof Array) {
Array array = (Array) expression;
List<Expression> exprs = array.getExpressions();
Object[] result = (Object[]) java.lang.reflect.Array.newInstance(array.getComponentType(), exprs.size());
for (int i = 0; i < exprs.size(); i++) {
Object eval = internalEvaluate(exprs.get(i), tuple);
if (eval instanceof ArrayImpl) {
eval = ((ArrayImpl) eval).getValues();
}
result[i] = eval;
}
return new ArrayImpl(result);
} else if (expression instanceof ExceptionExpression) {
return evaluate(tuple, (ExceptionExpression) expression);
} else if (expression instanceof XMLCast) {
return evaluate(tuple, (XMLCast) expression);
} else {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30329, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30329, expression.getClass().getName()));
}
}
use of org.teiid.api.exception.query.QueryValidatorException in project teiid by teiid.
the class QueryResolver method validateProjectedSymbols.
public static void validateProjectedSymbols(GroupSymbol virtualGroup, List<? extends Expression> symbols, List<? extends Expression> projectedSymbols) throws QueryValidatorException {
if (symbols.size() != projectedSymbols.size()) {
throw new QueryValidatorException(QueryPlugin.Event.TEIID30066, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30066, virtualGroup, symbols.size(), projectedSymbols.size()));
}
for (int i = 0; i < projectedSymbols.size(); i++) {
Expression projectedSymbol = projectedSymbols.get(i);
ResolverUtil.setTypeIfNull(projectedSymbol, symbols.get(i).getType());
if (projectedSymbol.getType() != symbols.get(i).getType()) {
throw new QueryValidatorException(// $NON-NLS-1$
QueryPlugin.Util.getString(// $NON-NLS-1$
"QueryResolver.wrong_view_symbol_type", // $NON-NLS-1$
virtualGroup, // $NON-NLS-1$
i + 1, DataTypeManager.getDataTypeName(symbols.get(i).getType()), DataTypeManager.getDataTypeName(projectedSymbol.getType())));
}
}
}
use of org.teiid.api.exception.query.QueryValidatorException in project teiid by teiid.
the class Request method validateAccess.
protected boolean validateAccess(String[] commandStr, Command command, CommandType type) throws QueryValidatorException, TeiidComponentException {
boolean returnsResultSet = command.returnsResultSet();
this.returnsUpdateCount = !(command instanceof StoredProcedure) && !returnsResultSet;
if ((this.requestMsg.getResultsMode() == ResultsMode.UPDATECOUNT && returnsResultSet) || (this.requestMsg.getResultsMode() == ResultsMode.RESULTSET && !returnsResultSet)) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new QueryValidatorException(QueryPlugin.Event.TEIID30490, QueryPlugin.Util.getString(this.requestMsg.getResultsMode() == ResultsMode.RESULTSET ? "Request.no_result_set" : "Request.result_set"));
}
createCommandContext();
if (this.requestMsg.isReturnAutoGeneratedKeys() && command instanceof Insert) {
Insert insert = (Insert) command;
List<ElementSymbol> variables = ResolverUtil.resolveElementsInGroup(insert.getGroup(), metadata);
variables.removeAll(insert.getVariables());
Object pk = metadata.getPrimaryKey(insert.getGroup().getMetadataID());
if (pk != null) {
List<?> cols = metadata.getElementIDsInKey(pk);
int colCount = 0;
for (Iterator<ElementSymbol> iter = variables.iterator(); iter.hasNext(); ) {
ElementSymbol variable = iter.next();
if (!(metadata.elementSupports(variable.getMetadataID(), SupportConstants.Element.NULL) || metadata.elementSupports(variable.getMetadataID(), SupportConstants.Element.AUTO_INCREMENT)) || !cols.contains(variable.getMetadataID())) {
iter.remove();
}
colCount++;
}
if (colCount == cols.size()) {
context.setReturnAutoGeneratedKeys(variables);
}
}
}
if (!this.workContext.isAdmin() && this.authorizationValidator != null) {
return this.authorizationValidator.validate(commandStr, command, metadata, context, type);
}
return false;
}
use of org.teiid.api.exception.query.QueryValidatorException in project teiid by teiid.
the class DefaultAuthorizationValidator method validate.
@Override
public boolean validate(String[] originalSql, Command command, QueryMetadataInterface metadata, CommandContext commandContext, CommandType commandType) throws QueryValidatorException, TeiidComponentException {
boolean modified = false;
if (policyDecider != null && policyDecider.validateCommand(commandContext)) {
if (ignoreUnathorizedInAsterisk(command, commandContext)) {
Query query = (Query) command;
HashMap<String, LanguageObject> map = null;
for (Expression ex : query.getSelect().getSymbols()) {
if (ex instanceof MultipleElementSymbol) {
MultipleElementSymbol mes = (MultipleElementSymbol) ex;
if (map == null) {
map = new HashMap<String, LanguageObject>();
}
for (Iterator<ElementSymbol> iter = mes.getElementSymbols().iterator(); iter.hasNext(); ) {
ElementSymbol es = iter.next();
Object metadataObject = es.getMetadataID();
if (metadataObject instanceof MultiSourceElement || metadataObject instanceof TempMetadataID) {
continue;
}
map.clear();
AuthorizationValidationVisitor.addToNameMap(metadataObject, es, map, commandContext.getMetadata());
Set<String> results = this.policyDecider.getInaccessibleResources(PermissionType.READ, map.keySet(), Context.QUERY, commandContext);
if (!results.isEmpty()) {
// remove from the select
iter.remove();
modified = true;
}
}
}
}
if (query.getProjectedSymbols().isEmpty()) {
throw new QueryValidatorException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31151));
}
}
AuthorizationValidationVisitor visitor = new AuthorizationValidationVisitor(this.policyDecider, commandContext);
Request.validateWithVisitor(visitor, metadata, command);
}
return modified;
}
use of org.teiid.api.exception.query.QueryValidatorException in project teiid by teiid.
the class TestProcessor method helpGetPlan.
public static ProcessorPlan helpGetPlan(Command command, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, CommandContext context) throws TeiidException {
// $NON-NLS-1$
if (DEBUG)
System.out.println("\n####################################\n" + command);
AnalysisRecord analysisRecord = new AnalysisRecord(false, DEBUG);
if (!(metadata instanceof TempMetadataAdapter)) {
metadata = new TempMetadataAdapter(metadata, new TempMetadataStore());
}
context.setMetadata(metadata);
try {
QueryResolver.resolveCommand(command, metadata);
ValidatorReport repo = Validator.validate(command, metadata);
Collection failures = new ArrayList();
repo.collectInvalidObjects(failures);
if (failures.size() > 0) {
// $NON-NLS-1$
throw new QueryValidatorException("Exception during validation:" + repo);
}
command = QueryRewriter.rewrite(command, metadata, context);
ProcessorPlan process = QueryOptimizer.optimizePlan(command, metadata, null, capFinder, analysisRecord, context);
// $NON-NLS-1$
if (DEBUG)
System.out.println("\n" + process);
// per defect 10022, clone this plan before processing, just to make sure
// a cloned plan with correlated subquery references (or any cloned plan) can be processed
process = process.clone();
// $NON-NLS-1$
assertNotNull("Output elements of process plan are null", process.getOutputElements());
return process;
} finally {
if (DEBUG) {
System.out.println(analysisRecord.getDebugLog());
}
}
}
Aggregations