Beispiel #1
0
def _cast_to_ir(ir_set: irast.Set,
                cast: s_casts.Cast,
                orig_stype: s_types.Type,
                new_stype: s_types.Type,
                cardinality_mod: Optional[qlast.CardinalityModifier] = None,
                *,
                ctx: context.ContextLevel) -> irast.Set:

    orig_typeref = typegen.type_to_typeref(orig_stype, env=ctx.env)
    new_typeref = typegen.type_to_typeref(new_stype, env=ctx.env)
    cast_name = cast.get_name(ctx.env.schema)
    cast_ir = irast.TypeCast(
        expr=ir_set,
        from_type=orig_typeref,
        to_type=new_typeref,
        cardinality_mod=cardinality_mod,
        cast_name=cast_name,
        cast_module_id=ctx.env.schema.get_global(s_mod.Module,
                                                 cast_name.module).id,
        sql_function=cast.get_from_function(ctx.env.schema),
        sql_cast=cast.get_from_cast(ctx.env.schema),
        sql_expr=bool(cast.get_code(ctx.env.schema)),
    )

    return setgen.ensure_set(cast_ir, ctx=ctx)
Beispiel #2
0
def _cast_to_ir(ir_set: irast.Set, cast: s_casts.Cast,
                orig_stype: s_types.Type, new_stype: s_types.Type, *,
                ctx: context.ContextLevel) -> irast.Set:

    orig_typeref = irtyputils.type_to_typeref(ctx.env.schema, orig_stype)
    new_typeref = irtyputils.type_to_typeref(ctx.env.schema, new_stype)
    cast_name = cast.get_name(ctx.env.schema)
    cast_ir = irast.TypeCast(
        expr=ir_set,
        from_type=orig_typeref,
        to_type=new_typeref,
        cast_name=cast_name,
        cast_module_id=ctx.env.schema.get_global(s_mod.Module,
                                                 cast_name.module).id,
        sql_function=cast.get_from_function(ctx.env.schema),
        sql_cast=cast.get_from_cast(ctx.env.schema),
        sql_expr=bool(cast.get_code(ctx.env.schema)),
    )

    return setgen.ensure_set(cast_ir, ctx=ctx)