Search in sources :

Example 1 with QueryDataTypeFamily

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);
}
Also used : QueryDataTypeFamily(com.hazelcast.sql.impl.type.QueryDataTypeFamily) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) Converter(com.hazelcast.sql.impl.type.converter.Converter)

Example 2 with QueryDataTypeFamily

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;
}
Also used : QueryDataTypeFamily(com.hazelcast.sql.impl.type.QueryDataTypeFamily) HazelcastTypeUtils.toHazelcastTypeFromSqlTypeName(com.hazelcast.jet.sql.impl.validate.types.HazelcastTypeUtils.toHazelcastTypeFromSqlTypeName) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) HazelcastSqlValidator(com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator) SqlNode(org.apache.calcite.sql.SqlNode)

Example 3 with QueryDataTypeFamily

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);
}
Also used : QueryDataTypeFamily(com.hazelcast.sql.impl.type.QueryDataTypeFamily) DECIMAL_MATH_CONTEXT(com.hazelcast.sql.impl.expression.math.ExpressionMath.DECIMAL_MATH_CONTEXT)

Example 4 with QueryDataTypeFamily

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);
}
Also used : QueryDataTypeFamily(com.hazelcast.sql.impl.type.QueryDataTypeFamily) DECIMAL_MATH_CONTEXT(com.hazelcast.sql.impl.expression.math.ExpressionMath.DECIMAL_MATH_CONTEXT)

Example 5 with QueryDataTypeFamily

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);
}
Also used : QueryDataTypeFamily(com.hazelcast.sql.impl.type.QueryDataTypeFamily) DECIMAL_MATH_CONTEXT(com.hazelcast.sql.impl.expression.math.ExpressionMath.DECIMAL_MATH_CONTEXT)

Aggregations

QueryDataTypeFamily (com.hazelcast.sql.impl.type.QueryDataTypeFamily)11 DECIMAL_MATH_CONTEXT (com.hazelcast.sql.impl.expression.math.ExpressionMath.DECIMAL_MATH_CONTEXT)5 SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)2 HazelcastSqlValidator (com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator)1 HazelcastTypeUtils.toHazelcastTypeFromSqlTypeName (com.hazelcast.jet.sql.impl.validate.types.HazelcastTypeUtils.toHazelcastTypeFromSqlTypeName)1 SqlDaySecondInterval (com.hazelcast.sql.impl.type.SqlDaySecondInterval)1 SqlYearMonthInterval (com.hazelcast.sql.impl.type.SqlYearMonthInterval)1 Converter (com.hazelcast.sql.impl.type.converter.Converter)1 HashSet (java.util.HashSet)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 RexCall (org.apache.calcite.rex.RexCall)1 RexInputRef (org.apache.calcite.rex.RexInputRef)1 RexNode (org.apache.calcite.rex.RexNode)1 SqlNode (org.apache.calcite.sql.SqlNode)1