Пример #1
0
def rel_join(query: pgast.Query, right_rvar: pgast.BaseRangeVar, *,
             ctx: context.CompilerContextLevel) -> None:
    condition = None

    for path_id in right_rvar.path_scope:
        lref = maybe_get_path_var(query, path_id, aspect='identity', ctx=ctx)
        if lref is None:
            lref = maybe_get_path_var(query, path_id, aspect='value', ctx=ctx)
        if lref is None:
            continue

        rref = pathctx.get_rvar_path_identity_var(right_rvar,
                                                  path_id,
                                                  env=ctx.env)

        path_cond = astutils.join_condition(lref, rref)
        condition = astutils.extend_binop(condition, path_cond)

    if condition is None:
        join_type = 'cross'
    else:
        join_type = 'inner'

    if not query.from_clause:
        query.from_clause.append(right_rvar)
        if condition is not None:
            query.where_clause = astutils.extend_binop(query.where_clause,
                                                       condition)
    else:
        larg = query.from_clause[0]
        rarg = right_rvar

        query.from_clause[0] = pgast.JoinExpr(type=join_type,
                                              larg=larg,
                                              rarg=rarg,
                                              quals=condition)
        if join_type == 'left':
            right_rvar.nullable = True

    if not right_rvar.is_distinct:
        query.is_distinct = False
Пример #2
0
def put_rvar_path_output(rvar: pgast.BaseRangeVar, path_id: irast.PathId,
                         aspect: str, var: pgast.OutputVar, *,
                         env: context.Environment) -> None:
    rvar.path_outputs[path_id, aspect] = var