use of com.hazelcast.sql.impl.type.QueryDataTypeFamily in project hazelcast by hazelcast.
the class HazelcastRexBuilder method makeLiteral.
@Override
public RexNode makeLiteral(Object value, RelDataType type, boolean allowCast) {
if (type.getSqlTypeName() == ANY && value instanceof Number) {
Converter converter = Converters.getConverter(value.getClass());
if (converter != null) {
QueryDataTypeFamily typeFamily = converter.getTypeFamily();
if (typeFamily.isNumericInteger()) {
int bitWidth = HazelcastIntegerType.bitWidthOf(((Number) value).longValue());
type = HazelcastIntegerType.create(bitWidth, false);
} else {
SqlTypeName typeName = HazelcastTypeUtils.toCalciteType(typeFamily);
type = HazelcastTypeFactory.INSTANCE.createSqlType(typeName);
}
}
}
return super.makeLiteral(value, type, allowCast);
}
use of com.hazelcast.sql.impl.type.QueryDataTypeFamily in project hazelcast by hazelcast.
the class WindowOperandMetadata method checkOperandTypes.
private boolean checkOperandTypes(HazelcastCallBinding binding, boolean throwOnFailure, int columnIndex) {
SqlNode lag = binding.operand(columnIndex);
HazelcastSqlValidator validator = binding.getValidator();
SqlTypeName orderingColumnType = getOrderingColumnType(binding, 1).getSqlTypeName();
boolean result;
SqlTypeName lagType = ((SqlValidator) validator).getValidatedNodeType(lag).getSqlTypeName();
if (SqlTypeName.INT_TYPES.contains(orderingColumnType)) {
result = SqlTypeName.INT_TYPES.contains(lagType);
} else if (SqlTypeName.DATETIME_TYPES.contains(orderingColumnType)) {
result = lagType.getFamily() == SqlTypeFamily.INTERVAL_DAY_TIME;
} else {
result = false;
}
if (!result && throwOnFailure) {
QueryDataTypeFamily hzOrderingColumnType = toHazelcastTypeFromSqlTypeName(orderingColumnType).getTypeFamily();
QueryDataTypeFamily hzLagType = toHazelcastTypeFromSqlTypeName(lagType).getTypeFamily();
throw validator.newValidationError(binding.getCall(), RESOURCES.windowFunctionTypeMismatch(hzOrderingColumnType.toString(), hzLagType.toString()));
}
return result;
}
use of com.hazelcast.sql.impl.type.QueryDataTypeFamily in project hazelcast by hazelcast.
the class MultiplyFunction 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 MinusFunction 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 RemainderFunction 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);
}
Aggregations