use of com.hazelcast.sql.impl.type.QueryDataTypeFamily in project hazelcast by hazelcast.
the class IntervalConverter method convertToSelf.
@Override
public Object convertToSelf(Converter converter, Object val) {
Object val0 = converter.asObject(val);
if (val0 == null) {
return null;
}
QueryDataTypeFamily family = getTypeFamily();
if (family == INTERVAL_YEAR_MONTH) {
if (val0 instanceof SqlYearMonthInterval) {
return val0;
}
} else {
assert family == INTERVAL_DAY_SECOND;
if (val0 instanceof SqlDaySecondInterval) {
return val0;
}
}
throw converter.cannotConvertError(family);
}
use of com.hazelcast.sql.impl.type.QueryDataTypeFamily in project hazelcast by hazelcast.
the class UnaryMinusFunction method eval.
@SuppressWarnings("unchecked")
@Override
public T eval(Row row, ExpressionEvalContext context) {
Object value = operand.eval(row, context);
if (value == null) {
return null;
}
QueryDataTypeFamily family = resultType.getTypeFamily();
return (T) evalNumeric((Number) value, family);
}
use of com.hazelcast.sql.impl.type.QueryDataTypeFamily in project hazelcast by hazelcast.
the class DivideFunction method eval.
@SuppressWarnings("unchecked")
@Override
public T eval(Row row, ExpressionEvalContext context) {
Object left = operand1.eval(row, context);
if (left == null) {
return null;
}
Object right = operand2.eval(row, context);
if (right == null) {
return null;
}
QueryDataTypeFamily family = resultType.getTypeFamily();
if (family.isTemporal()) {
throw new UnsupportedOperationException("temporal types are unsupported currently");
}
return (T) evalNumeric((Number) left, (Number) right, family);
}
use of com.hazelcast.sql.impl.type.QueryDataTypeFamily in project hazelcast by hazelcast.
the class PlusFunction method eval.
@SuppressWarnings("unchecked")
@Override
public T eval(Row row, ExpressionEvalContext context) {
Object left = operand1.eval(row, context);
if (left == null) {
return null;
}
Object right = operand2.eval(row, context);
if (right == null) {
return null;
}
QueryDataTypeFamily family = resultType.getTypeFamily();
if (family.isTemporal()) {
return (T) evalTemporal(left, right, family);
}
return (T) evalNumeric((Number) left, (Number) right, family);
}
use of com.hazelcast.sql.impl.type.QueryDataTypeFamily in project hazelcast by hazelcast.
the class IndexResolver method removeCastIfPossible.
/**
* Removes CAST operator from the column expression when possible.
* <p>
* The following expression might be found: {@code CAST(a AS BIGINT) > ?}. This may happen either due to type coercion
* during sql->rel conversion, or due to explicit user request. In the general case, a function applied to the column makes
* usage of the index on that column impossible.
* <p>
* In case of the {@code CAST} operator we may try to remove the CAST, thus relying on internal index converters to
* downcast the other side of the comparison expression. See {@link TypeConverters}.
*
* @param node original node, possibly CAST
* @return original node if there is nothing to unwrap, or the operand of the CAST
*/
@SuppressWarnings("checkstyle:NestedIfDepth")
private static RexNode removeCastIfPossible(RexNode node) {
if (node.getKind() == SqlKind.CAST) {
RexCall node0 = (RexCall) node;
RexNode from = node0.getOperands().get(0);
if (from instanceof RexInputRef) {
RelDataType fromType = from.getType();
RelDataType toType = node0.getType();
if (fromType.equals(toType)) {
// Redundant conversion => unwrap
return from;
}
QueryDataTypeFamily fromFamily = HazelcastTypeUtils.toHazelcastType(fromType).getTypeFamily();
QueryDataTypeFamily toFamily = HazelcastTypeUtils.toHazelcastType(toType).getTypeFamily();
if (QueryDataTypeUtils.isNumeric(fromFamily) && QueryDataTypeUtils.isNumeric(toFamily)) {
// Converting between numeric types
if (toFamily.getPrecedence() > fromFamily.getPrecedence()) {
// overflow error is possible, so we cannot remove the CAST.
return from;
}
}
}
}
return node;
}
Aggregations