org.teiid.language.Expression translate(Constant constant) { if (constant.isMultiValued()) { Parameter result = new Parameter(); result.setType(constant.getType()); final List<?> values = (List<?>)constant.getValue(); allValues.add(values); result.setValueIndex(valueIndex++); return result; if (constant.getValue() instanceof ArrayImpl) { ArrayImpl av = (ArrayImpl)constant.getValue(); List<Constant> vals = new ArrayList<Constant>(); Class<?> baseType = null; for (Object o : av.getValues()) { Constant c = new Constant(o); c.setBindEligible(constant.isBindEligible()); vals.add(c); if (baseType == null) { baseType = c.getType(); } else if (!baseType.equals(c.getType())) { if (baseType == DataTypeManager.DefaultDataClasses.NULL) { baseType = c.getType(); } else if (c.getType() != DataTypeManager.DefaultDataClasses.NULL) { baseType = DataTypeManager.DefaultDataClasses.OBJECT; Literal result = new Literal(constant.getValue(), constant.getType()); result.setBindEligible(constant.isBindEligible()); return result;
@Override public int compare(Object o1, Object o2) { Class<?> clazz = o1.getClass(); if (clazz == String.class) { CharSequence s1 = (CharSequence)o1; CharSequence s2 = (CharSequence)o2; return comparePadded(s1, s2); } else if (clazz == ClobType.class) { CharSequence s1 = ((ClobType)o1).getCharSequence(); CharSequence s2 = ((ClobType)o2).getCharSequence(); return comparePadded(s1, s2); } return ((Comparable<Object>)o1).compareTo(o2); } };
private static int getMultiValuedSize(Expression value) { if (value instanceof Constant && ((Constant)value).isMultiValued()) { return ((List<?>)((Constant)value).getValue()).size(); } return 1; }
@Test public void testInteger() { Integer i = new Integer(5); Constant c = new Constant(i); assertEquals("Value is incorrect: ", i, c.getValue()); //$NON-NLS-1$ assertEquals("Type is incorrect: ", DataTypeManager.DefaultDataClasses.INTEGER, c.getType()); //$NON-NLS-1$ assertEquals("Should be non-null: ", false, c.isNull()); //$NON-NLS-1$ assertEquals("Object does not equal itself", c, c); //$NON-NLS-1$ Constant c2 = new Constant(i); assertEquals("Constants for same object aren't equal: ", c, c2); //$NON-NLS-1$ Constant cc = (Constant) c.clone(); assertEquals("Cloned object not equal to original: ", c, cc); //$NON-NLS-1$ }
if (format.equals(c.getValue())) { Expression arg = function.getArg(0); if ((arg instanceof Function) if (format.equals(c.getValue())) { return rewriteExpressionDirect(ResolverUtil.getConversion(function.getArg(0), DataTypeManager.getDataTypeName(function.getArg(0).getType()), DataTypeManager.DefaultDataTypes.STRING, false, metadata.getFunctionLibrary())); case 0: { //space(x) => repeat(' ', x) Function result = new Function(SourceSystemFunctions.REPEAT, new Expression[] {new Constant(" "), function.getArg(0)}); //$NON-NLS-1$ Constant nullConstant = new Constant(null, function.getType()); List then = Arrays.asList(new Expression[] {nullConstant}); SearchedCaseExpression caseExpr = new SearchedCaseExpression(when, then); if (new Constant(" ").equals(function.getArg(1))) { //$NON-NLS-1$ String spec = (String)((Constant)function.getArg(0)).getValue(); Expression string = function.getArg(2); if (!SQLConstants.Reserved.TRAILING.equalsIgnoreCase(spec)) { if (function.getArg(1) instanceof Constant) { Constant c = (Constant)function.getArg(1); if (!c.isMultiValued() && !c.isNull()) { int val = (Integer) c.getValue(); if (val == 0) { function.getArgs()[1] = new Constant(1); if (isNull(ex)) { if (!function.getFunctionDescriptor().isNullDependent()) {
@Override public void visit( Constant obj ) { Class<?> type = obj.getType(); boolean multiValued = obj.isMultiValued(); Object value = obj.getValue(); outputLiteral(type, multiValued, value); }
private List<Constant> convertValuesToConstants(List<?> values, List<ElementSymbol> elements) { ArrayList<Constant> constants = new ArrayList<Constant>(values.size()); for(int i=0; i<elements.size(); i++) { ElementSymbol es = elements.get(i); Class<?> type = es.getType(); constants.add(new Constant(values.get(i),type)); } return constants; }
value = new Constant(Evaluator.evaluate(value)); } catch (ExpressionEvaluationException err) { if(((Constant)value).isNull() && ! getMetadata().elementSupports(elementID.getMetadataID(), SupportConstants.Element.NULL)) { handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0060", SQLStringVisitor.getSQLString(elementID)), elementID); //$NON-NLS-1$
Constant result = ResolverUtil.convertConstant(DataTypeManager.getDataTypeName(rightConstant.getType()), leftExprTypeName, rightConstant); if (result == null) { return getSimpliedCriteria(crit, leftExpr, crit.getOperator() != CompareCriteria.EQ, true); Constant other = ResolverUtil.convertConstant(leftExprTypeName, DataTypeManager.getDataTypeName(rightConstant.getType()), result); if (other == null || rightConstant.compareTo(other) != 0) { return getSimpliedCriteria(crit, leftExpr, crit.getOperator() != CompareCriteria.EQ, true); if (!DataTypeManager.isImplicitConversion(leftExprTypeName, DataTypeManager.getDataTypeName(rightConstant.getType()))) { return crit;
@Test public void testClone() { // Use this object as the "object"-type value for c1 StringBuffer value = new StringBuffer("x"); //$NON-NLS-1$ Constant c1 = new Constant(value, DataTypeManager.DefaultDataClasses.OBJECT); Constant copy = (Constant) c1.clone(); // Check equality assertEquals("Cloned object not equal to original: ", c1, copy); //$NON-NLS-1$ // Check that modifying original value changes c1 and clone - this is expected as Constant // uses a shallow clone value.append("y"); //$NON-NLS-1$ assertTrue("Original object has not changed, but should have", ((StringBuffer)c1.getValue()).toString().equals("xy")); //$NON-NLS-1$ //$NON-NLS-2$ assertTrue("Cloned object has not changed, but should have", ((StringBuffer)copy.getValue()).toString().equals("xy")); //$NON-NLS-1$ //$NON-NLS-2$ }
private Limit rewriteLimitClause(Limit limit) throws TeiidComponentException, TeiidProcessingException{ if (limit.getOffset() != null) { if (!processing) { limit.setOffset(rewriteExpressionDirect(limit.getOffset())); } else { Constant c = evaluate(limit.getOffset(), false); limit.setOffset(c); ValidationVisitor.LIMIT_CONSTRAINT.validate(c.getValue()); } if (ZERO_CONSTANT.equals(limit.getOffset())) { limit.setOffset(null); } } if (limit.getRowLimit() != null) { if (!processing) { limit.setRowLimit(rewriteExpressionDirect(limit.getRowLimit())); } else { Constant c = evaluate(limit.getRowLimit(), false); limit.setRowLimit(c); ValidationVisitor.LIMIT_CONSTRAINT.validate(c.getValue()); } } return limit; } }
public static boolean isNull(Expression expr) { return expr instanceof Constant && ((Constant)expr).isNull(); }
public static void setDefault(BaseColumn column, Expression value) { if ((value instanceof Constant) && value.getType() == DataTypeManager.DefaultDataClasses.STRING) { column.setDefaultValue(((Constant)value).getValue().toString()); } else { //it's an expression column.setProperty(BaseColumn.DEFAULT_HANDLING, BaseColumn.EXPRESSION_DEFAULT); column.setDefaultValue(value.toString()); } } }
static Comparator<Object> getComparator(String localeString, final boolean padSpace) { if (localeString == null) { return getComparator(padSpace); } else { LogManager.logError(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30564, localeString)); return getComparator(padSpace);