Search in sources :

Example 1 with SqlUserDefinedTypeNameSpec

use of org.apache.calcite.sql.SqlUserDefinedTypeNameSpec in project hazelcast by hazelcast.

the class HazelcastTypeCoercion method coerceNode.

private boolean coerceNode(SqlValidatorScope scope, SqlNode node, RelDataType targetType, Consumer<SqlNode> replaceFn) {
    // Just update the inferred type if casting is not needed
    if (!requiresCast(scope, node, targetType)) {
        updateInferredType(node, targetType);
        return false;
    }
    SqlDataTypeSpec targetTypeSpec;
    if (targetType instanceof HazelcastIntegerType) {
        targetTypeSpec = new SqlDataTypeSpec(new HazelcastIntegerTypeNameSpec((HazelcastIntegerType) targetType), SqlParserPos.ZERO);
    } else if (targetType.getSqlTypeName() == ANY) {
        // without this the subsequent call to UnsupportedOperationVerifier will fail with "we do not support ANY"
        targetTypeSpec = new SqlDataTypeSpec(new SqlUserDefinedTypeNameSpec("OBJECT", SqlParserPos.ZERO), SqlParserPos.ZERO).withNullable(targetType.isNullable());
    } else if (targetType.getFamily() == HazelcastJsonType.FAMILY) {
        targetTypeSpec = HazelcastJsonType.TYPE_SPEC;
    } else {
        targetTypeSpec = SqlTypeUtil.convertTypeToSpec(targetType);
    }
    SqlNode cast = cast(node, targetTypeSpec);
    replaceFn.accept(cast);
    validator.deriveType(scope, cast);
    return true;
}
Also used : SqlUserDefinedTypeNameSpec(org.apache.calcite.sql.SqlUserDefinedTypeNameSpec) SqlDataTypeSpec(org.apache.calcite.sql.SqlDataTypeSpec) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

SqlDataTypeSpec (org.apache.calcite.sql.SqlDataTypeSpec)1 SqlNode (org.apache.calcite.sql.SqlNode)1 SqlUserDefinedTypeNameSpec (org.apache.calcite.sql.SqlUserDefinedTypeNameSpec)1