/** * @see java.lang.Object#clone() */ public Object clone() { return new Reference(this); }
boolean checkForInput(Expression expr) { if (!(expr instanceof Reference)) { return false; } //if the expr is a function containing a reference should give a warning Reference ref = (Reference)expr; return inputs.contains(ref.getExpression()); }
/** * Define hash code to be that of the underlying object to make it stable. * @return Hash code, based on value */ public int hashCode() { if (this.isPositional()) { return getIndex(); } return this.expression.hashCode(); }
@Override public void visit( Reference obj ) { if (!obj.isPositional() && obj.getExpression() != null) { visitNode(obj.getExpression()); } else { append("?"); //$NON-NLS-1$ } }
/** * We assume the non-push down for correlation variables, * then make specific checks when correlated variables are allowed. */ public void visit(Reference obj) { hasCorrelatedReferences |= obj.isCorrelated(); if (obj.isPositional()) { setDeterminismLevel(Determinism.COMMAND_DETERMINISTIC); } else if (modelId != null) { //for pushdown commands correlated references mean we're non-deterministic setDeterminismLevel(Determinism.NONDETERMINISTIC); } evaluationNotPossible(EvaluationLevel.PROCESSING); }
} 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);
/** * Utility to set the type of an expression if it is a Reference and has a null type. * @param expression the expression to test * @param targetType the target type, if the expression's type is null. * @throws QueryResolverException if unable to set the reference type to the target type. */ public static void setDesiredType(Expression expression, Class<?> targetType, LanguageObject surroundingExpression) throws QueryResolverException { if (expression instanceof Reference) { Reference ref = (Reference)expression; if (ref.isPositional() && ref.getType() == null) { if (targetType == null) { throw new QueryResolverException(QueryPlugin.Event.TEIID30083, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30083, surroundingExpression)); } ref.setType(targetType); } } else if (expression instanceof Function) { Function f = (Function)expression; if (f.getType() == null) { f.setType(targetType); } } }
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) { String msg = QueryPlugin.Util.getString("QueryUtil.Error_executing_conversion_function_to_convert_value", i + 1, value, value.getClass(), DataTypeManager.getDataTypeName(param.getType())); //$NON-NLS-1$ throw new QueryResolverException(QueryPlugin.Event.TEIID30557, e, msg); } catch (QueryResolverException e) { String msg = QueryPlugin.Util.getString("QueryUtil.Error_executing_conversion_function_to_convert_value", i + 1, value, value.getClass(), DataTypeManager.getDataTypeName(param.getType())); //$NON-NLS-1$ throw new QueryResolverException(QueryPlugin.Event.TEIID30558, e, msg); if (param.getConstraint() != null) { param.getConstraint().validate(value); result.setGlobalValue(param.getContextSymbol(), value);
public void visit(Reference obj) { if (!obj.isCorrelated()) { return; } //we need to follow references to correct correlated variables org.teiid.query.optimizer.relational.AliasGenerator.NamingVisitor.SQLNamingContext sqlNamingContext = this.visitor.namingContext.parent; while (sqlNamingContext != null) { if (sqlNamingContext.groupNames.containsKey(obj.getExpression().getGroupSymbol().getName())) { visitNode(obj.getExpression()); return; } sqlNamingContext = sqlNamingContext.parent; } if (!this.visitor.namingContext.groupNames.containsKey(obj.getExpression().getGroupSymbol().getName())) { visitNode(obj.getExpression()); } else { // else - this is a naming conflict that is not handled gracefully } }
Object value = this.context.getVariableContext().getGlobalValue(this.prepPlan.getReferences().get(i).getContextSymbol()); multiValue.add(value); Constant c = new Constant(null, this.prepPlan.getReferences().get(i).getType()); c.setMultiValued(multiValues.get(i)); this.context.getVariableContext().setGlobalValue(this.prepPlan.getReferences().get(i).getContextSymbol(), c);
public static void setParameterValues(List<?> values, Command command, CommandContext context) { VariableContext vc = new VariableContext(); Iterator<?> valIter = values.iterator(); for (Reference ref : ReferenceCollectorVisitor.getReferences(command)) { if (!ref.isPositional()) { continue; } vc.setGlobalValue(ref.getContextSymbol(), valIter.next()); //$NON-NLS-1$ } context.setVariableContext(vc); }
@Test public void testEvaluatedSetCriteria() throws Exception { DependentAccessNode dan = new DependentAccessNode(0); CommandContext cc = new CommandContext(); dan.setContext(cc); List<Reference> references = Arrays.asList(new Reference(1), new Reference(2)); for (Reference reference : references) { cc.getVariableContext().setGlobalValue(reference.getContextSymbol(), 1); } SetCriteria sc = new SetCriteria(new ElementSymbol("e1"), references); //$NON-NLS-1$ sc.setAllConstants(true); DependentCriteriaProcessor dcp = new DependentCriteriaProcessor(1, -1, dan, sc); Criteria result = dcp.prepareCriteria(); assertEquals(new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(1)), result); //$NON-NLS-1$ assertFalse(dcp.hasNextCommand()); }
public void visit(Reference obj) { if (obj.getType() == null){ this.unresolvedSymbols.add(obj); } } }
if (!processing && es.isExternalReference()) { if (variables == null) { return new Reference(es); return new Reference(es); if (preEvaluation) { Reference ref = (Reference)expression; if (ref.isPositional()) { return evaluate(expression, isBindEligible);
public Class<?> getType() { if (this.isPositional() && this.expression == null) { return type; } return expression.getType(); }
/** * Compare this constant to another constant for equality. * @param obj Other object * @return True if constants are equal */ public boolean equals(Object obj) { if(this == obj) { return true; } if(!(obj instanceof Reference)) { return false; } Reference other = (Reference) obj; if (this.positional != other.positional) { return false; } if (this.positional) { return other.getIndex() == getIndex(); } // Compare based on name return this.expression.equals(other.expression); }
private void validateLimitExpression(Limit obj, Expression limitExpr) { if (limitExpr != null) { if (limitExpr instanceof Constant) { Integer limit = (Integer)((Constant)limitExpr).getValue(); if (limit.intValue() < 0) { handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.badlimit2"), obj); //$NON-NLS-1$ } } else if (limitExpr instanceof Reference) { ((Reference)limitExpr).setConstraint(LIMIT_CONSTRAINT); } else if (!EvaluatableVisitor.willBecomeConstant(limitExpr)) { handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.badlimit1"), obj); //$NON-NLS-1$ } } }
@Override protected void checkReferences(List<Reference> references) throws QueryValidatorException { for (Iterator<Reference> i = references.iterator(); i.hasNext();) { if (i.next().isOptional()) { i.remove(); //remove any optional parameter, which accounts for out params - the client does not send any bindings } } prepPlan.setReferences(references); }
} 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);
/** * Utility to set the type of an expression if it is a Reference and has a null type. * @param expression the expression to test * @param targetType the target type, if the expression's type is null. * @throws QueryResolverException if unable to set the reference type to the target type. */ public static void setDesiredType(Expression expression, Class<?> targetType, LanguageObject surroundingExpression) throws QueryResolverException { if (expression instanceof Reference) { Reference ref = (Reference)expression; if (ref.isPositional() && ref.getType() == null) { if (targetType == null) { throw new QueryResolverException(QueryPlugin.Event.TEIID30083, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30083, surroundingExpression)); } ref.setType(targetType); } } else if (expression instanceof Function) { Function f = (Function)expression; if (f.getType() == null) { f.setType(targetType); } } }