コード例 #1
0
ファイル: madpack.py プロジェクト: gigfork/madlib
def __db_upgrade(schema, dbrev):
    __info("Upgrading MADlib into %s schema..." % schema.upper(), True)
    __info("\tDetecting dependencies...", True)

    __info("\tLoading change list...", True)
    ch = ChangeHandler(schema, portid, con_args, maddir, dbrev)

    __info("\tDetecting table dependencies...", True)
    td = TableDependency(schema, portid, con_args)

    __info("\tDetecting view dependencies...", True)
    vd = ViewDependency(schema, portid, con_args)

    # if no dependency found
    if not td.has_dependency() and not vd.has_dependency():
        __info("\tNo dependency issues found, continuing upgrade...", True)
        __info("\tReading existing UDAs/UDTs...", False)
        sc = ScriptCleaner(schema, portid, con_args, ch)

        ch.drop_changed_uda()
        ch.drop_changed_udt()
        ch.drop_changed_udc()
        ch.drop_changed_udf()
        __db_create_objects(schema, None, True, sc)
        __info("MADlib %s upgraded successfully in %s schema." % (rev, schema.upper()), True)
        return

    cd_udt = []
    if td.has_dependency():
        __info("\tFollowing user tables are dependent on updated MADlib types:", True)
        __info(td.get_dependency_str(), True)
        d_udt = td.get_depended_udt()
        c_udt = ch.get_udt()
        for udt in d_udt:
            if udt in c_udt:
                cd_udt.append(udt)

    cd_udf = []
    cd_uda = []
    if vd.has_dependency():
        __info("\tFollowing user views are dependent on updated MADlib objects:", True)
        __info(vd.get_dependency_graph_str(), True)

        c_udf = ch.get_udf_signature()
        d_udf = vd.get_depended_func_signature(False)
        for udf in d_udf:
            if udf in c_udf:
                cd_udf.append(udf)

        c_uda = ch.get_uda_signature()
        d_uda = vd.get_depended_func_signature(True)
        for uda in d_uda:
            if uda in c_uda:
                cd_uda.append(uda)

    abort = False
    if len(cd_udt)  > 0:
        __error("""
            User has objects dependent on updated MADlib types (%s)! Aborting upgrade ...
            """ % str(cd_udt), False)
        abort = True
    if len(cd_udf)  > 0:
        __error("""
            User has objects dependent on updated MADlib functions (%s)! Aborting upgrade ...
            """ % str(cd_udf), False)
        abort = True
    if len(cd_uda)  > 0:
        __error("""
            User has objects dependent on udpated MADlib aggregates (%s)! Aborting upgrade ...
            """ % str(cd_uda), False)
        abort = True

    if abort:
        __error('Upgrade aborted.', True)
    else:
        __info("No explicit dependency problem found, continuing to upgrade ...", True)
        vd.save_and_drop()

    __info("\tReading existing UDAs/UDTs...", False)
    sc = ScriptCleaner(schema, portid, con_args, ch)

    ch.drop_changed_uda()
    ch.drop_changed_udt()
    ch.drop_changed_udc()
    ch.drop_changed_udf()
    __db_create_objects(schema, None, True, sc)

    if vd.has_dependency():
        vd.restore()
    __info("MADlib %s upgraded successfully in %s schema." % (rev, schema.upper()), True)
コード例 #2
0
ファイル: madpack.py プロジェクト: rudedev/madlib
def __db_upgrade(schema, dbrev):
    if __get_rev_num(dbrev) >= __get_rev_num(rev):
        __info("Current MADlib version already up to date.", True)
        return

    __info("Upgrading MADlib into %s schema..." % schema.upper(), True)
    __info("\tDetecting dependencies...", True)

    __info("\tLoading change list...", True)
    ch = ChangeHandler(schema, portid, con_args, maddir, dbrev)

    __info("\tDetecting table dependencies...", True)
    td = TableDependency(schema, portid, con_args)

    __info("\tDetecting view dependencies...", True)
    vd = ViewDependency(schema, portid, con_args)

    abort = False
    if td.has_dependency():
        __info("*" * 50, True)
        __info("\tFollowing user tables are dependent on updated MADlib types:", True)
        __info(td.get_dependency_str(), True)
        __info("*" * 50, True)
        cd_udt = [udt for udt in td.get_depended_udt() if udt in ch.udt]
        if len(cd_udt) > 0:
            __error(
                """
                User has objects dependent on following updated MADlib types!
                        {0}
                These objects need to be dropped before upgrading.
                """.format(
                    "\n\t\t\t".join(cd_udt)
                ),
                False,
            )

            # TODO: Remove this after v1.3
            # we add special handling for 'linregr_result'
            if "linregr_result" in cd_udt:
                __info(
                    """Dependency on 'linregr_result' could be due to objects
                        created from the output of the aggregate 'linregr'.
                        Please refer to the Linear Regression documentation
                        <http://doc.madlib.net/latest/group__grp__linreg.html#warning>
                        for the recommended solution.
                        """,
                    False,
                )
            abort = True

    if vd.has_dependency():
        __info("*" * 50, True)
        __info("\tFollowing user views are dependent on updated MADlib objects:", True)
        __info(vd.get_dependency_graph_str(), True)
        __info("*" * 50, True)

        c_udf = ch.get_udf_signature()
        d_udf = vd.get_depended_func_signature(False)
        cd_udf = [udf for udf in d_udf if udf in c_udf]
        if len(cd_udf) > 0:
            __error(
                """
                User has objects dependent on following updated MADlib functions!
                    {0}
                These objects will fail to work with the updated functions and
                need to be dropped before starting upgrade again.
                """.format(
                    "\n\t\t\t\t\t".join(cd_udf)
                ),
                False,
            )
            abort = True

        c_uda = ch.get_uda_signature()
        d_uda = vd.get_depended_func_signature(True)
        cd_uda = [uda for uda in d_uda if uda in c_uda]
        if len(cd_uda) > 0:
            __error(
                """
                User has objects dependent on following updated MADlib aggregates!
                    {0}
                These objects will fail to work with the new aggregates and
                need to be dropped before starting upgrade again.
                """.format(
                    "\n\t\t\t\t\t".join(cd_uda)
                ),
                False,
            )
            abort = True

    if abort:
        __error("------- Upgrade aborted. -------", True)
    else:
        __info("No dependency problem found, continuing to upgrade ...", True)
        if vd.has_dependency():
            vd.save_and_drop()

    __info("\tReading existing UDAs/UDTs...", False)
    try:
        sc = ScriptCleaner(schema, portid, con_args, ch)
    except Exception as e:
        __info(str(e), True)
        raise e
    __info("Script Cleaner initialized ...", False)

    # __info("\tChanged functions: " + str(ch.udf), True)
    # __info("\tChanged aggregates: " + str(ch.uda), True)
    # __info("\tChanged types: " + str(ch.udt), True)
    # __info("\tChanged casts: " + str(ch.udc), True)

    ch.drop_changed_uda()
    ch.drop_changed_udt()
    ch.drop_changed_udc()
    ch.drop_changed_udf()
    __db_create_objects(schema, None, True, sc)

    if vd.has_dependency():
        vd.restore()
    __info("MADlib %s upgraded successfully in %s schema." % (rev, schema.upper()), True)
コード例 #3
0
ファイル: madpack.py プロジェクト: zahidabasher/madlib
def __db_upgrade(schema, dbrev):
    if __get_rev_num(dbrev) >= __get_rev_num(rev):
        __info("Current MADlib version already up to date.", True)
        return

    __info("Upgrading MADlib into %s schema..." % schema.upper(), True)
    __info("\tDetecting dependencies...", True)

    __info("\tLoading change list...", True)
    ch = ChangeHandler(schema, portid, con_args, maddir, dbrev)

    __info("\tDetecting table dependencies...", True)
    td = TableDependency(schema, portid, con_args)

    __info("\tDetecting view dependencies...", True)
    vd = ViewDependency(schema, portid, con_args)

    abort = False
    if td.has_dependency():
        __info("*"*50, True)
        __info("\tFollowing user tables are dependent on updated MADlib types:", True)
        __info(td.get_dependency_str(), True)
        __info("*"*50, True)
        cd_udt = [udt for udt in td.get_depended_udt()
                      if udt in ch.udt]
        if len(cd_udt) > 0:
            __error("""
                User has objects dependent on following updated MADlib types!
                        {0}
                These objects need to be dropped before upgrading.
                """.format('\n\t\t\t'.join(cd_udt)), False)

            # TODO: Remove this after v1.3
            # we add special handling for 'linregr_result'
            if 'linregr_result' in cd_udt:
                __info("""Dependency on 'linregr_result' could be due to objects
                        created from the output of the aggregate 'linregr'.
                        Please refer to the Linear Regression documentation
                        <http://doc.madlib.net/latest/group__grp__linreg.html#warning>
                        for the recommended solution.
                        """, False)
            abort = True

    if vd.has_dependency():
        __info("*"*50, True)
        __info("\tFollowing user views are dependent on updated MADlib objects:", True)
        __info(vd.get_dependency_graph_str(), True)
        __info("*"*50, True)

        c_udf = ch.get_udf_signature()
        d_udf = vd.get_depended_func_signature(False)
        cd_udf = [udf for udf in d_udf if udf in c_udf]
        if len(cd_udf) > 0:
            __error("""
                User has objects dependent on following updated MADlib functions!
                    {0}
                These objects will fail to work with the updated functions and
                need to be dropped before starting upgrade again.
                """.format('\n\t\t\t\t\t'.join(cd_udf)), False)
            abort = True

        c_uda = ch.get_uda_signature()
        d_uda = vd.get_depended_func_signature(True)
        cd_uda = [uda for uda in d_uda if uda in c_uda]
        if len(cd_uda) > 0:
            __error("""
                User has objects dependent on following updated MADlib aggregates!
                    {0}
                These objects will fail to work with the new aggregates and
                need to be dropped before starting upgrade again.
                """.format('\n\t\t\t\t\t'.join(cd_uda)), False)
            abort = True

    if abort:
        __error('------- Upgrade aborted. -------', True)
    else:
        __info("No dependency problem found, continuing to upgrade ...", True)
        if vd.has_dependency():
            vd.save_and_drop()

    __info("\tReading existing UDAs/UDTs...", False)
    try:
        sc = ScriptCleaner(schema, portid, con_args, ch)
    except Exception as e:
        __info(str(e), True)
        raise e
    __info("Script Cleaner initialized ...", False)


    # __info("\tChanged functions: " + str(ch.udf), True)
    # __info("\tChanged aggregates: " + str(ch.uda), True)
    # __info("\tChanged types: " + str(ch.udt), True)
    # __info("\tChanged casts: " + str(ch.udc), True)

    ch.drop_changed_uda()
    ch.drop_changed_udt()
    ch.drop_changed_udc()
    ch.drop_changed_udf()
    __db_create_objects(schema, None, True, sc)

    if vd.has_dependency():
        vd.restore()
    __info("MADlib %s upgraded successfully in %s schema." % (rev, schema.upper()), True)
コード例 #4
0
def __db_upgrade(schema, dbrev):
    __info("Upgrading MADlib into %s schema..." % schema.upper(), True)
    __info("\tDetecting dependencies...", True)

    __info("\tLoading change list...", True)
    ch = ChangeHandler(schema, portid, con_args, maddir, dbrev)

    __info("\tDetecting table dependencies...", True)
    td = TableDependency(schema, portid, con_args)

    __info("\tDetecting view dependencies...", True)
    vd = ViewDependency(schema, portid, con_args)

    abort = False
    if td.has_dependency():
        __info(
            "\tFollowing user tables are dependent on updated MADlib types:",
            True)
        __info(td.get_dependency_str(), True)
        cd_udt = [udt for udt in td.get_depended_udt() if udt in ch.get_udt()]
        if len(cd_udt) > 0:
            __error(
                """
                User has objects dependent on updated MADlib types ({0})!
                These objects need to be dropped before starting upgrade again. Aborting upgrade ...
                """.format('\n'.join(cd_udt)), False)
            abort = True

    if vd.has_dependency():
        __info(
            "\tFollowing user views are dependent on updated MADlib objects:",
            True)
        __info(vd.get_dependency_graph_str(), True)

        c_udf = ch.get_udf_signature()
        d_udf = vd.get_depended_func_signature(False)
        cd_udf = [udf for udf in d_udf if udf in c_udf]
        if len(cd_udf) > 0:
            __error(
                """
                User has objects dependent on updated MADlib functions ({0})!
                These objects will not fail to work with the new functions and
                need to be dropped before starting upgrade again. Aborting upgrade ...
                """.format('\n'.join(cd_udf)), False)
            abort = True
        c_uda = ch.get_uda_signature()
        d_uda = vd.get_depended_func_signature(True)
        cd_uda = [uda for uda in d_uda if uda in c_uda]
        if len(cd_uda) > 0:
            __error(
                """
                User has objects dependent on updated MADlib functions ({0})!
                These objects will not fail to work with the new aggregates and
                need to be dropped before starting upgrade again. Aborting upgrade ...
                """.format('\n'.join(cd_uda)), False)
            abort = True

    if abort:
        __error('------- Upgrade aborted. -------', True)
    else:
        __info(
            "No explicit dependency problem found, continuing to upgrade ...",
            True)
        if vd.has_dependency():
            vd.save_and_drop()

    __info("\tReading existing UDAs/UDTs...", False)
    sc = ScriptCleaner(schema, portid, con_args, ch)

    ch.drop_changed_uda()
    ch.drop_changed_udt()
    ch.drop_changed_udc()
    ch.drop_changed_udf()
    __db_create_objects(schema, None, True, sc)

    if vd.has_dependency():
        vd.restore()
    __info(
        "MADlib %s upgraded successfully in %s schema." %
        (rev, schema.upper()), True)
コード例 #5
0
ファイル: madpack.py プロジェクト: akode/madlib
def __db_upgrade(schema, dbrev):
    __info("Upgrading MADlib into %s schema..." % schema.upper(), True)
    __info("\tDetecting dependencies...", True)

    __info("\tLoading change list...", True)
    ch = ChangeHandler(schema, portid, con_args, maddir, dbrev)

    __info("\tDetecting table dependencies...", True)
    td = TableDependency(schema, portid, con_args)

    __info("\tDetecting view dependencies...", True)
    vd = ViewDependency(schema, portid, con_args)

    abort = False
    if td.has_dependency():
        __info("\tFollowing user tables are dependent on updated MADlib types:", True)
        __info(td.get_dependency_str(), True)
        cd_udt = [udt for udt in td.get_depended_udt()
                      if udt in ch.get_udt()]
        if len(cd_udt) > 0:
            __error("""
                User has objects dependent on updated MADlib types ({0})!
                These objects need to be dropped before starting upgrade again. Aborting upgrade ...
                """.format('\n'.join(cd_udt)), False)
            abort = True

    if vd.has_dependency():
        __info("\tFollowing user views are dependent on updated MADlib objects:", True)
        __info(vd.get_dependency_graph_str(), True)

        c_udf = ch.get_udf_signature()
        d_udf = vd.get_depended_func_signature(False)
        cd_udf = [udf for udf in d_udf if udf in c_udf]
        if len(cd_udf) > 0:
            __error("""
                User has objects dependent on updated MADlib functions ({0})!
                These objects will not fail to work with the new functions and
                need to be dropped before starting upgrade again. Aborting upgrade ...
                """.format('\n'.join(cd_udf)), False)
            abort = True
        c_uda = ch.get_uda_signature()
        d_uda = vd.get_depended_func_signature(True)
        cd_uda = [uda for uda in d_uda if uda in c_uda]
        if len(cd_uda) > 0:
            __error("""
                User has objects dependent on updated MADlib functions ({0})!
                These objects will not fail to work with the new aggregates and
                need to be dropped before starting upgrade again. Aborting upgrade ...
                """.format('\n'.join(cd_uda)), False)
            abort = True

    if abort:
        __error('------- Upgrade aborted. -------', True)
    else:
        __info("No explicit dependency problem found, continuing to upgrade ...", True)
        if vd.has_dependency():
            vd.save_and_drop()

    __info("\tReading existing UDAs/UDTs...", False)
    sc = ScriptCleaner(schema, portid, con_args, ch)

    ch.drop_changed_uda()
    ch.drop_changed_udt()
    ch.drop_changed_udc()
    ch.drop_changed_udf()
    __db_create_objects(schema, None, True, sc)

    if vd.has_dependency():
        vd.restore()
    __info("MADlib %s upgraded successfully in %s schema." % (rev, schema.upper()), True)