parameters: (schema, filehandle, db_madlib_ver)
return_statement: return 0
docstring: Upgrade MADlib
          @param schema MADlib schema name
          @param filehandle Handle to output file
          @param db_madlib_ver DB-level MADlib version
docstring_summary: Upgrade MADlib
docstring_tokens: Upgrade MADlib
function: def _db_upgrade(schema, filehandle, db_madlib_ver):
      """
      Upgrade MADlib
          @param schema MADlib schema name
          @param filehandle Handle to output file
          @param db_madlib_ver DB-level MADlib version
      """
      if is_rev_gte(get_rev_num(db_madlib_ver), get_rev_num(new_madlib_ver)):
          info_(this, "Current MADlib version already up to date.", True)
          return 1
  
      if is_rev_gte(get_rev_num('1.9.1'), get_rev_num(db_madlib_ver)):
          error_(this, """
              MADlib versions prior to v1.10 are not supported for upgrade.
              Please try upgrading to v1.10 and then upgrade to this version.
              """, True)
          return 1
  
      info_(this, "Upgrading MADlib into %s schema..." % schema, True)
      info_(this, "\tDetecting dependencies...", True)
  
      info_(this, "\tLoading change list...", True)
      ch = uu.ChangeHandler(schema, portid, con_args, maddir, db_madlib_ver, filehandle)
  
      info_(this, "\tDetecting table dependencies...", True)
      td = uu.TableDependency(schema, portid, con_args)
  
      info_(this, "\tDetecting view dependencies...", True)
      vd = uu.ViewDependency(schema, portid, con_args)
  
      abort = False
      if td.has_dependency():
          info_(this, "*" * 50, True)
          info_(this, "\tFollowing user tables/indexes are dependent on MADlib objects:", True)
          info_(this, td.get_dependency_str(), True)
          info_(this, "*" * 50, True)
          cd_udt = [udt for udt in td.get_depended_udt() if udt in ch.udt]
          if len(cd_udt) > 0:
              error_(this, """
                  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)
  
              # we add special handling for 'linregr_result'
              if 'linregr_result' in cd_udt:
                  info_(this, """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://madlib.apache.org/docs/latest/group__grp__linreg.html#warning>
                          for the recommended solution.
                          """, False)
              abort = True
  
          c_udoc = ch.get_udoc_oids()
          d_udoc = td.get_depended_udoc_oids()
          cd_udoc = [udoc for udoc in d_udoc if udoc in c_udoc]
          if len(cd_udoc) > 0:
              error_(this, """
                  User has objects dependent on the following updated MADlib operator classes!
                          oid={0}
                  These objects need to be dropped before upgrading.
                  """.format('\n\t\t\t'.join(cd_udoc)), False)
              abort = True
  
      if vd.has_dependency():
          info_(this, "*" * 50, True)
          info_(this, "\tFollowing user views are dependent on MADlib objects:", True)
          info_(this, vd.get_dependency_graph_str(), True)
          info_(this, "*" * 50, True)
  
          d_udf = vd.get_depended_func_signature('UDF')
          if len(d_udf) > 0:
              error_(this, """
                  User has objects dependent on following updated MADlib functions!
                      {0}
                  These objects might fail to work with the updated functions and
                  need to be dropped before starting upgrade again.
                  """.format('\n\t\t\t\t\t'.join(d_udf)), False)
              abort = True
  
          d_uda = vd.get_depended_func_signature('UDA')
          if len(d_uda) > 0:
              error_(this, """
                  User has objects dependent on following updated MADlib aggregates!
                      {0}
                  These objects might fail to work with the new aggregates and
                  need to be dropped before starting upgrade again.
                  """.format('\n\t\t\t\t\t'.join(d_uda)), False)
              abort = True
  
          d_udo = vd.get_depended_opr_oids()
          if len(d_udo) > 0:
              error_(this, """
                  User has objects dependent on following updated MADlib operators!
                      oid={0}
                  These objects might fail to work with the new operators and
                  need to be dropped before starting upgrade again.
                  """.format('\n\t\t\t\t\t'.join(d_udo)), False)
              abort = True
  
      if abort:
          error_(this, """------- Upgrade aborted. -------
                  Backup and drop all objects that depend on MADlib before trying upgrade again.
                  Use madpack reinstall to automatically drop these objects only if appropriate.""", True)
      else:
          info_(this, "No dependency problem found, continuing to upgrade ...", True)
  
      info_(this, "\tReading existing UDAs/UDTs...", False)
      sc = uu.ScriptCleaner(schema, portid, con_args, ch)
      info_(this, "Script Cleaner initialized ...", False)
  
      function_drop_str = get_madlib_function_drop_str(schema)
      flist = function_drop_str.split("\n\n")
      for i in flist:
          _internal_run_query(i, True)
  
      operator_drop_str = get_madlib_operator_drop_str(schema)
      _internal_run_query(operator_drop_str, True)
      ch.drop_changed_udc()
      ch.drop_changed_udt()  # assume dependent udf for udt does not change
      _db_create_objects(schema, filehandle, True, sc)
      return 0
function_tokens: def _db_upgrade ( schema , filehandle , db_madlib_ver ) : if is_rev_gte ( get_rev_num ( db_madlib_ver ) , get_rev_num ( new_madlib_ver ) ) : info_ ( this , "Current MADlib version already up to date." , True ) return 1 if is_rev_gte ( get_rev_num ( '1.9.1' ) , get_rev_num ( db_madlib_ver ) ) : error_ ( this , """
              MADlib versions prior to v1.10 are not supported for upgrade.
              Please try upgrading to v1.10 and then upgrade to this version.
              """ , True ) return 1 info_ ( this , "Upgrading MADlib into %s schema..." % schema , True ) info_ ( this , "\tDetecting dependencies..." , True ) info_ ( this , "\tLoading change list..." , True ) ch = uu . ChangeHandler ( schema , portid , con_args , maddir , db_madlib_ver , filehandle ) info_ ( this , "\tDetecting table dependencies..." , True ) td = uu . TableDependency ( schema , portid , con_args ) info_ ( this , "\tDetecting view dependencies..." , True ) vd = uu . ViewDependency ( schema , portid , con_args ) abort = False if td . has_dependency ( ) : info_ ( this , "*" * 50 , True ) info_ ( this , "\tFollowing user tables/indexes are dependent on MADlib objects:" , True ) info_ ( this , td . get_dependency_str ( ) , True ) info_ ( this , "*" * 50 , True ) cd_udt = [ udt for udt in td . get_depended_udt ( ) if udt in ch . udt ] if len ( cd_udt ) > 0 : error_ ( this , """
                  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 ) # we add special handling for 'linregr_result' if 'linregr_result' in cd_udt : info_ ( this , """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://madlib.apache.org/docs/latest/group__grp__linreg.html#warning>
                          for the recommended solution.
                          """ , False ) abort = True c_udoc = ch . get_udoc_oids ( ) d_udoc = td . get_depended_udoc_oids ( ) cd_udoc = [ udoc for udoc in d_udoc if udoc in c_udoc ] if len ( cd_udoc ) > 0 : error_ ( this , """
                  User has objects dependent on the following updated MADlib operator classes!
                          oid={0}
                  These objects need to be dropped before upgrading.
                  """ . format ( '\n\t\t\t' . join ( cd_udoc ) ) , False ) abort = True if vd . has_dependency ( ) : info_ ( this , "*" * 50 , True ) info_ ( this , "\tFollowing user views are dependent on MADlib objects:" , True ) info_ ( this , vd . get_dependency_graph_str ( ) , True ) info_ ( this , "*" * 50 , True ) d_udf = vd . get_depended_func_signature ( 'UDF' ) if len ( d_udf ) > 0 : error_ ( this , """
                  User has objects dependent on following updated MADlib functions!
                      {0}
                  These objects might fail to work with the updated functions and
                  need to be dropped before starting upgrade again.
                  """ . format ( '\n\t\t\t\t\t' . join ( d_udf ) ) , False ) abort = True d_uda = vd . get_depended_func_signature ( 'UDA' ) if len ( d_uda ) > 0 : error_ ( this , """
                  User has objects dependent on following updated MADlib aggregates!
                      {0}
                  These objects might fail to work with the new aggregates and
                  need to be dropped before starting upgrade again.
                  """ . format ( '\n\t\t\t\t\t' . join ( d_uda ) ) , False ) abort = True d_udo = vd . get_depended_opr_oids ( ) if len ( d_udo ) > 0 : error_ ( this , """
                  User has objects dependent on following updated MADlib operators!
                      oid={0}
                  These objects might fail to work with the new operators and
                  need to be dropped before starting upgrade again.
                  """ . format ( '\n\t\t\t\t\t' . join ( d_udo ) ) , False ) abort = True if abort : error_ ( this , """------- Upgrade aborted. -------
                  Backup and drop all objects that depend on MADlib before trying upgrade again.
                  Use madpack reinstall to automatically drop these objects only if appropriate.""" , True ) else : info_ ( this , "No dependency problem found, continuing to upgrade ..." , True ) info_ ( this , "\tReading existing UDAs/UDTs..." , False ) sc = uu . ScriptCleaner ( schema , portid , con_args , ch ) info_ ( this , "Script Cleaner initialized ..." , False ) function_drop_str = get_madlib_function_drop_str ( schema ) flist = function_drop_str . split ( "\n\n" ) for i in flist : _internal_run_query ( i , True ) operator_drop_str = get_madlib_operator_drop_str ( schema ) _internal_run_query ( operator_drop_str , True ) ch . drop_changed_udc ( ) ch . drop_changed_udt ( ) # assume dependent udf for udt does not change _db_create_objects ( schema , filehandle , True , sc ) return 0