コード例 #1
0
ファイル: translator.py プロジェクト: NCI-GDC/psqlgraph
def translate_edge_range(_args):
    args, offset = _args
    src = PsqlGraphDriver(
        args.source_host, args.source_user, args.source_password,
        args.source, **driver_kwargs)
    dst = PsqlGraphDriver(
        args.dest_host, args.dest_user, args.dest_password,
        args.dest, **driver_kwargs)

    print '{}-{}'.format(offset, offset+BLOCK)
    sys.stdout.flush()
    with src.session_scope() as session:
        with dst.session_scope() as session:
            for old in src.edges(OldEdge)\
                          .order_by((OldEdge.src_id),
                                    (OldEdge.dst_id),
                                    (OldEdge.label))\
                          .options(joinedload(OldEdge.src))\
                          .options(joinedload(OldEdge.dst))\
                          .offset(offset)\
                          .limit(BLOCK).all():
                try:
                    Type = dst.get_edge_by_labels(
                        old.src.label, old.label, old.dst.label)
                    print Type.__name__
                    new = Type(
                        src_id=old.src_id,
                        dst_id=old.dst_id,
                        properties=old.properties,
                        system_annotations=old.system_annotations,
                        label=old.label,
                    )
                    new.created = old.created
                    session.merge(new)
                except Exception as e:
                    logging.error("unable to add edge {}, {}".format(
                        old.label, old.src_id, old.dst_id))
                    logging.error(e)

            try:
                session.commit()
            except Exception as e:
                logging.error(e)
コード例 #2
0
def translate_edge_range(_args):
    args, offset = _args
    src = PsqlGraphDriver(args.source_host, args.source_user,
                          args.source_password, args.source, **driver_kwargs)
    dst = PsqlGraphDriver(args.dest_host, args.dest_user, args.dest_password,
                          args.dest, **driver_kwargs)

    print '{}-{}'.format(offset, offset + BLOCK)
    sys.stdout.flush()
    with src.session_scope() as session:
        with dst.session_scope() as session:
            for old in src.edges(OldEdge)\
                          .order_by((OldEdge.src_id),
                                    (OldEdge.dst_id),
                                    (OldEdge.label))\
                          .options(joinedload(OldEdge.src))\
                          .options(joinedload(OldEdge.dst))\
                          .offset(offset)\
                          .limit(BLOCK).all():
                try:
                    Type = dst.get_edge_by_labels(old.src.label, old.label,
                                                  old.dst.label)
                    print Type.__name__
                    new = Type(
                        src_id=old.src_id,
                        dst_id=old.dst_id,
                        properties=old.properties,
                        system_annotations=old.system_annotations,
                        label=old.label,
                    )
                    new.created = old.created
                    session.merge(new)
                except Exception as e:
                    logging.error("unable to add edge {}, {}".format(
                        old.label, old.src_id, old.dst_id))
                    logging.error(e)

            try:
                session.commit()
            except Exception as e:
                logging.error(e)