Search in sources :

Example 61 with QueryDataType

use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.

the class TypedOperandChecker method coerce.

@Override
@SuppressWarnings("checkstyle:BooleanExpressionComplexity")
protected boolean coerce(HazelcastSqlValidator validator, HazelcastCallBinding callBinding, SqlNode operand, RelDataType operandType, int operandIndex) {
    if (targetTypeName == SqlTypeName.ROW || targetTypeName == SqlTypeName.COLUMN_LIST) {
        return false;
    }
    QueryDataType targetType0 = getTargetHazelcastType();
    QueryDataType operandType0 = HazelcastTypeUtils.toHazelcastType(operandType);
    boolean canCoerce = isTemporalType(operandType) && isTemporalType(targetTypeName) || isNumericType(operandType) && isNumericType(targetTypeName) || // we can assign VARCHAR to JSON fields
    operandType.getSqlTypeName() == SqlTypeName.VARCHAR && type != null && type.getFamily() == HazelcastJsonType.FAMILY;
    if (!canCoerce) {
        return false;
    }
    if (targetType0.getTypeFamily().getPrecedence() < operandType0.getTypeFamily().getPrecedence()) {
        // Cannot convert type with higher precedence to lower precedence (e.g. DOUBLE to INTEGER)
        return false;
    }
    // Otherwise, we are good to go. Construct the new type of the operand.
    RelDataType newOperandType = getTargetType(validator.getTypeFactory(), operandType.isNullable());
    // Perform coercion
    validator.getTypeCoercion().coerceOperandType(callBinding.getScope(), callBinding.getCall(), operandIndex, newOperandType);
    return true;
}
Also used : QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) RelDataType(org.apache.calcite.rel.type.RelDataType)

Aggregations

QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)61 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)23 MappingField (com.hazelcast.sql.impl.schema.MappingField)17 ArrayList (java.util.ArrayList)16 TableField (com.hazelcast.sql.impl.schema.TableField)14 MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)13 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)10 RelDataType (org.apache.calcite.rel.type.RelDataType)7 OptimizerTestSupport (com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport)6 IndexScanMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel)6 FullScanPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.FullScanPhysicalRel)5 Nonnull (javax.annotation.Nonnull)5 IndexEqualsFilter (com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter)4 Test (org.junit.Test)4 IndexType (com.hazelcast.config.IndexType)3 KvMetadata (com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 HashMap (java.util.HashMap)3 List (java.util.List)3