alter

in linkis-engineconn-plugins/hbase/hbase-shims-1.2.0/src/main/resources/hbase-ruby/hbase/admin.rb [507:657]


    def alter(table_name, wait = true, *args)
      
      raise(ArgumentError, "Table name must be of type String") unless table_name.kind_of?(String)

      
      raise(ArgumentError, "Can't find a table: #{table_name}") unless exists?(table_name)

      
      raise(ArgumentError, "There should be at least one argument but the table name") if args.empty?

      
      htd = @admin.getTableDescriptor(TableName.valueOf(table_name))

      
      args.each do |arg|


        
        arg = { NAME => arg } if arg.kind_of?(String)

        
        arg = { METHOD => 'delete', NAME => arg['delete'] } if arg['delete']

        
        
        method = arg.delete(METHOD)
        if method == nil and arg.has_key?(NAME)
          descriptor = hcd(arg, htd)
          column_name = descriptor.getNameAsString

          
          if htd.hasFamily(column_name.to_java_bytes)
            @admin.modifyColumn(table_name, descriptor)
          else
            @admin.addColumn(table_name, descriptor)
          end

          if wait == true
            puts "Updating all regions with the new schema..."
            alter_status(table_name)
          end

          
          htd = @admin.getTableDescriptor(TableName.valueOf(table_name))
          next
        end

        
        name = arg.delete(NAME)
        if method != nil and method != "table_att"
          
          if method == "delete"
            raise(ArgumentError, "NAME parameter missing for delete method") unless name
            @admin.deleteColumn(table_name, name)
          
          elsif method == "table_att_unset"
            raise(ArgumentError, "NAME parameter missing for table_att_unset method") unless name
            if name.kind_of?(Array)
              name.each do |key|
                if (htd.getValue(key) == nil)
                  raise ArgumentError, "Could not find attribute: #{key}"
                end
                htd.remove(key)
              end
            else
              if (htd.getValue(name) == nil)
                raise ArgumentError, "Could not find attribute: #{name}"
              end
              htd.remove(name)
            end
            @admin.modifyTable(table_name.to_java_bytes, htd)
          
          else
            raise ArgumentError, "Unknown method: #{method}"
          end

          arg.each_key do |unknown_key|
            puts("Unknown argument ignored: %s" % [unknown_key])
          end

          if wait == true
            puts "Updating all regions with the new schema..."
            alter_status(table_name)
          end

          if method == "delete"
            
            htd = @admin.getTableDescriptor(TableName.valueOf(table_name))
          end
          next
        end

        
        raise(ArgumentError, "NAME argument in an unexpected place") if name
        htd.setOwnerString(arg.delete(OWNER)) if arg[OWNER]
        htd.setMaxFileSize(JLong.valueOf(arg.delete(MAX_FILESIZE))) if arg[MAX_FILESIZE]
        htd.setReadOnly(JBoolean.valueOf(arg.delete(READONLY))) if arg[READONLY]
        htd.setCompactionEnabled(JBoolean.valueOf(arg.delete(COMPACTION_ENABLED))) if arg[COMPACTION_ENABLED]
        parse_htd_args(htd, arg)
        htd.setMemStoreFlushSize(JLong.valueOf(arg.delete(MEMSTORE_FLUSHSIZE))) if arg[MEMSTORE_FLUSHSIZE]
        
        
        if arg.include?(DEFERRED_LOG_FLUSH)
          if arg.delete(DEFERRED_LOG_FLUSH).to_s.upcase == "TRUE"
            htd.setDurability(org.apache.hadoop.hbase.client.Durability.valueOf("ASYNC_WAL"))
          else
            htd.setDurability(org.apache.hadoop.hbase.client.Durability.valueOf("SYNC_WAL"))
          end
        end
        htd.setDurability(org.apache.hadoop.hbase.client.Durability.valueOf(arg.delete(DURABILITY))) if arg[DURABILITY]
        htd.setFlushPolicyClassName(arg.delete(FLUSH_POLICY)) if arg[FLUSH_POLICY]
        htd.setRegionSplitPolicyClassName(arg.delete(SPLIT_POLICY)) if arg[SPLIT_POLICY]
        htd.setRegionMemstoreReplication(JBoolean.valueOf(arg.delete(REGION_MEMSTORE_REPLICATION))) if arg[REGION_MEMSTORE_REPLICATION]
        htd.setRegionReplication(JInteger.valueOf(arg.delete(REGION_REPLICATION))) if arg[REGION_REPLICATION]
        set_user_metadata(htd, arg.delete(METADATA)) if arg[METADATA]
        set_descriptor_config(htd, arg.delete(CONFIGURATION)) if arg[CONFIGURATION]

        
        valid_coproc_keys = []
        if arg.kind_of?(Hash)
          arg.each do |key, value|
            k = String.new(key) 
            k.strip!

            if (k =~ /coprocessor/i)
              v = String.new(value)
              v.strip!
              htd.addCoprocessorWithSpec(v)
              valid_coproc_keys << key
            end
          end

          valid_coproc_keys.each do |key|
            arg.delete(key)
          end

          @admin.modifyTable(table_name.to_java_bytes, htd)

          arg.each_key do |unknown_key|
            puts("Unknown argument ignored: %s" % [unknown_key])
          end

          if wait == true
            puts "Updating all regions with the new schema..."
            alter_status(table_name)
          end
          next
        end
      end
    end