if (keyComparable != null) {
expression.setKeyComparable(keyComparable);
}
else if (TClass.comparisonNeedsCasting(leftTInst, rightTInst)) {
boolean needCasts = true;
TCastResolver casts = registry.getCastsResolver();
if ( (left.getClass() == ColumnExpression.class)&& (right.getClass() == ConstantExpression.class)) {
// Left is a Column, right is a Constant. Ideally, we'd like to keep the Column as a Column,
// and not a CAST(Column AS _) -- otherwise, we can't use it in an index lookup.
// So, try to cast the const to the column's type. To do this, CAST(Const -> Column) must be
// indexFriendly, *and* casting this result back to the original Const type must equal the same
// const.
if (rightTInst == null) {
// literal null, so a comparison always returns UNKNOWN
return new BooleanConstantExpression(null);
}
if (casts.isIndexFriendly(tclass(leftTInst), tclass(rightTInst))) {
TInstance columnType = type(left);
TInstance constType = type(right);
TCast constToCol = casts.cast(constType, columnType);
if (constToCol != null) {
TCast colToConst = casts.cast(columnType, constType);
if (colToConst != null) {
TPreptimeValue constValue = right.getPreptimeValue();
ValueSource asColType = castValue(constToCol, constValue, columnType);
TPreptimeValue asColTypeTpv = (asColType == null)
? null