예제 #1
0
파일: pathctx.py 프로젝트: versada/edgedb
def assign_set_scope(ir_set: irast.Set,
                     scope: typing.Optional[irast.ScopeTreeNode], *,
                     ctx: context.ContextLevel) -> irast.Set:
    if scope is None:
        ir_set.path_scope_id = None
    else:
        if scope.unique_id is None:
            scope.unique_id = ctx.scope_id_ctr.nextval()
        ir_set.path_scope_id = scope.unique_id

    return ir_set
예제 #2
0
파일: pathctx.py 프로젝트: 1st1/edgedb
def assign_set_scope(ir_set: irast.Set,
                     scope: typing.Optional[irast.ScopeTreeNode], *,
                     ctx: context.ContextLevel) -> irast.Set:
    if scope is None:
        ir_set.path_scope_id = None
    else:
        if scope.unique_id is None:
            scope.unique_id = ctx.scope_id_ctr.nextval()
        ir_set.path_scope_id = scope.unique_id
        if scope.find_child(ir_set.path_id):
            raise RuntimeError('scoped set must not contain itself')

    return ir_set
예제 #3
0
파일: stmt.py 프로젝트: versada/edgedb
def compile_query_subject(
        expr: irast.Set, *,
        shape: typing.Optional[typing.List[qlast.ShapeElement]]=None,
        view_rptr: typing.Optional[context.ViewRPtr]=None,
        view_name: typing.Optional[s_name.SchemaName]=None,
        result_alias: typing.Optional[str]=None,
        view_scls: typing.Optional[s_types.Type]=None,
        compile_views: bool=True,
        is_insert: bool=False,
        is_update: bool=False,
        ctx: context.ContextLevel) -> irast.Set:

    if shape is not None and view_scls is None:
        if (view_name is None and
                isinstance(result_alias, s_name.SchemaName)):
            view_name = result_alias
        inner_path_id = expr.path_id

        view_scls = viewgen.process_view(
            scls=expr.scls, path_id=expr.path_id,
            elements=shape, view_rptr=view_rptr,
            view_name=view_name, is_insert=is_insert,
            is_update=is_update, ctx=ctx)
    else:
        inner_path_id = None

    if view_scls is not None:
        expr.scls = view_scls

    if compile_views and expr.scls is not None:
        rptr = view_rptr.rptr if view_rptr is not None else None
        viewgen.compile_view_shapes(expr, rptr=rptr, ctx=ctx)

    if inner_path_id is not None and len(inner_path_id) == 1:
        ctx.class_view_overrides[inner_path_id[0].name] = expr.scls

    return expr
예제 #4
0
파일: stmt.py 프로젝트: mcaramma/edgedb
def compile_query_subject(
        expr: irast.Set, *,
        shape: typing.Optional[typing.List[qlast.ShapeElement]]=None,
        view_rptr: typing.Optional[context.ViewRPtr]=None,
        view_name: typing.Optional[s_name.SchemaName]=None,
        result_alias: typing.Optional[str]=None,
        view_scls: typing.Optional[s_types.Type]=None,
        compile_views: bool=True,
        is_insert: bool=False,
        is_update: bool=False,
        ctx: context.ContextLevel) -> irast.Set:

    need_rptr_derivation = (
        view_rptr is not None and
        view_rptr.ptrcls is None and
        view_rptr.ptrcls_name is not None
    )

    if need_rptr_derivation:
        matching_type = (
            expr.rptr is not None and
            view_rptr.ptrcls_is_linkprop ==
            expr.rptr.ptrcls.is_link_property())
        if matching_type:
            # We are inside an expression that defines a link alias in
            # the parent shape, ie. Spam { alias := Foo.bar }, so
            # `Spam.alias` should be a subclass of `Foo.bar` inheriting
            # its properties.
            view_rptr.base_ptrcls = expr.rptr.ptrcls
        else:
            if expr.path_id.is_objtype_path():
                ptr_metacls = s_links.Link
            else:
                ptr_metacls = s_props.Property

            view_rptr.base_ptrcls = ptr_metacls(name=view_rptr.ptrcls_name)

    if shape is not None and view_scls is None:
        if (view_name is None and
                isinstance(result_alias, s_name.SchemaName)):
            view_name = result_alias

        view_scls = viewgen.process_view(
            scls=expr.scls, path_id=expr.path_id,
            elements=shape, view_rptr=view_rptr,
            view_name=view_name, is_insert=is_insert,
            is_update=is_update, ctx=ctx)

    if need_rptr_derivation and view_rptr.ptrcls is None:
        target = view_scls if view_scls is not None else expr.scls
        viewgen.derive_ptrcls(view_rptr, target_scls=target, ctx=ctx)

    if view_scls is not None:
        expr.scls = view_scls

    if compile_views and expr.scls is not None:
        rptr = view_rptr.rptr if view_rptr is not None else None
        viewgen.compile_view_shapes(expr, rptr=rptr, ctx=ctx)

    if (shape is not None or view_scls is not None) and len(expr.path_id) == 1:
        ctx.class_view_overrides[expr.path_id.target.name] = expr.scls

    return expr