hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r667684 - in /hadoop/hbase/trunk: bin/ conf/ src/java/org/apache/hadoop/hbase/ src/java/org/apache/hadoop/hbase/master/ src/java/org/apache/hadoop/hbase/regionserver/ src/test/org/apache/hadoop/hbase/
Date Fri, 13 Jun 2008 22:42:11 GMT
Author: stack
Date: Fri Jun 13 15:42:11 2008
New Revision: 667684

URL: http://svn.apache.org/viewvc?rev=667684&view=rev
Log:
HBASE-487 Replace hql w/ a hbase-friendly jirb or jython shell
This commit finishes up the DDL
M  src/test/org/apache/hadoop/hbase/TestBloomFilters.java
    Changed name of default constants.
M  src/java/org/apache/hadoop/hbase/HColumnDescriptor.java
    Changed name of default constants.
    (getNameAsString): Added.
M  src/java/org/apache/hadoop/hbase/master/ModifyColumn.java
    toString column family byte array name.
M  bin/HBase.rb
    (alter, hcd): Added.
M  bin/hirb.rb
    More help doc.
    (alter, admin): Added.

Modified:
    hadoop/hbase/trunk/bin/HBase.rb
    hadoop/hbase/trunk/bin/hirb.rb
    hadoop/hbase/trunk/conf/hbase-env.sh
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HColumnDescriptor.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/ModifyColumn.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HStoreFile.java
    hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestBloomFilters.java

Modified: hadoop/hbase/trunk/bin/HBase.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/bin/HBase.rb?rev=667684&r1=667683&r2=667684&view=diff
==============================================================================
--- hadoop/hbase/trunk/bin/HBase.rb (original)
+++ hadoop/hbase/trunk/bin/HBase.rb Fri Jun 13 15:42:11 2008
@@ -73,23 +73,54 @@
       for arg in args
         raise TypeError.new(arg.class.to_s + " of " + arg.to_s + " is not of Hash type")
\
           unless arg.instance_of? Hash
-        name = arg[NAME]
-        raise ArgumentError.new("Column family " + arg + " must have a name at least") \
-          unless name
-        # TODO: Process all other parameters for column family
-        # Check the family name for colon.  Add it if missing.
-        index = name.index(':')
-        if not index
-          # Add a colon.  If already a colon, its in the right place,
-          # or an exception will come up out of the addFamily
-          name << ':'
-        end
-        htd.addFamily(HColumnDescriptor.new(name))
+        htd.addFamily(hcd(arg))
       end
       @admin.createTable(htd)
       @formatter.header()
       @formatter.footer(now)
     end
+
+    def alter(tableName, args)
+      now = Time.now 
+      raise TypeError.new("Table name must be of type String") \
+        unless tableName.instance_of? String
+      descriptor = hcd(args)
+      @admin.modifyColumn(tableName, descriptor.getNameAsString(), descriptor);
+      @formatter.header()
+      @formatter.footer(now)
+    end
+
+    def hcd(arg)
+      # Return a new HColumnDescriptor made of passed args
+      # TODO: This is brittle code.
+      # Here is current HCD constructor:
+      # public HColumnDescriptor(final byte [] columnName, final int maxVersions,
+      # final CompressionType compression, final boolean inMemory,
+      # final boolean blockCacheEnabled,
+      # final int maxValueLength, final int timeToLive,
+      # BloomFilterDescriptor bloomFilter)
+      name = arg[NAME]
+      raise ArgumentError.new("Column family " + arg + " must have a name") \
+        unless name
+      # Check the family name for colon.  Add it if missing.
+      index = name.index(':')
+      if not index
+        # Add a colon.  If already a colon, its in the right place,
+        # or an exception will come up out of the addFamily
+        name << ':'
+      end
+      # TODO: What encoding are Strings in jruby?
+      return HColumnDescriptor.new(name.to_java_bytes,
+        # JRuby uses longs for ints. Need to convert.  Also constants are String 
+        arg[MAX_VERSIONS]? arg[MAX_VERSIONS]: HColumnDescriptor::DEFAULT_MAX_VERSIONS,
+        arg[COMPRESSION]? HColumnDescriptor::CompressionType::valueOf(arg[COMPRESSION]):
+          HColumnDescriptor::DEFAULT_COMPRESSION,
+        arg[IN_MEMORY]? arg[IN_MEMORY]: HColumnDescriptor::DEFAULT_IN_MEMORY,
+        arg[BLOCKCACHE]? arg[BLOCKCACHE]: HColumnDescriptor::DEFAULT_BLOCKCACHE,
+        arg[MAX_LENGTH]? arg[MAX_LENGTH]: HColumnDescriptor::DEFAULT_MAX_LENGTH,
+        arg[TTL]? arg[TTL]: HColumnDescriptor::DEFAULT_TTL,
+        arg[BLOOMFILTER]? arg[BLOOMFILTER]: HColumnDescriptor::DEFAULT_BLOOMFILTER)
+    end
   end
 
   class Table

Modified: hadoop/hbase/trunk/bin/hirb.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/bin/hirb.rb?rev=667684&r1=667683&r2=667684&view=diff
==============================================================================
--- hadoop/hbase/trunk/bin/hirb.rb (original)
+++ hadoop/hbase/trunk/bin/hirb.rb Fri Jun 13 15:42:11 2008
@@ -71,12 +71,13 @@
 
 # Promote hbase constants to be constants of this module so can
 # be used bare as keys in 'create', 'alter', etc. To see constants
-# in IRB, type 'Object.constants'.
+# in IRB, type 'Object.constants'. Don't promote defaults because
+# flattens all types to String.  Can be confusing.
 def promoteConstants(constants)
   # The constants to import are all in uppercase
   for c in constants
     if c == c.upcase
-      eval("%s = \"%s\"" % [c, c])
+      eval("%s = \"%s\"" % [c, c]) unless c =~ /DEFAULT_.*/
     end
   end
 end
@@ -95,6 +96,15 @@
   # TODO: Add help to the commands themselves rather than keep it distinct
   h  = <<HERE
 HBASE SHELL COMMANDS:
+ alter     Alter column family schema in a table.  Pass table name and a
+           dictionary specifying the new column family schema. Dictionaries
+           are described below in the GENERAL NOTES section.  Dictionary must
+           include name of column family to alter.  For example, to change
+           the 'f1' column family in table 't1' to have a MAX_VERSIONS of 5,
+           do:
+
+           hbase> alter 't1', {NAME => 'f1', MAX_VERSIONS => 5}
+
  create    Create table; pass a table name, a dictionary of specifications per
            column family, and optionally, named parameters of table options.
            Dictionaries are described below in the GENERAL NOTES section. Named
@@ -102,9 +112,12 @@
            (constants) as keys and a '=>' key/value delimiter.  Parameters are
            comma-delimited.  For example, to create a table named 't1' with an
            alternate maximum region size and a single family named 'f1' with an
-           alternate maximum number of cells, type:
+           alternate maximum number of cells and 'record' compression, type:
+
+           hbase> create 't1' {NAME => 'f1', MAX_VERSIONS => 5, \
+               COMPRESSION => 'RECORD'}, REGION_SIZE => 1024
 
-             create 't1' {NAME => 'f1', MAX_VERSIONS => 5}, REGION_SIZE => 123
+           For compression types, pass one of 'NONE', 'RECORD', or 'BLOCK'
 
  describe  Describe the named table. Outputs the table and family descriptors
  drop      Drop the named table.  Table must first be disabled
@@ -119,15 +132,12 @@
 Quote all names in the hbase shell such as table and column names.  Don't
 forget commas delimiting command parameters. Dictionaries of configuration used
 in the creation and alteration of tables are ruby-style Hashes. They look like
-this:
-
-  { 'key1' => 'value1', 'key2' => 'value2', ...}
-
-They are opened and closed with curley-braces.  Key/values are delimited by
-the '=>' character combination.  Usually keys are predefined constants that
-do not need to be quoted such as NAME, MAX_VERSIONS, MAX_LENGTH, TTL, etc.
-Type 'Object.constants' to see a (messy) list of all constants in the
-environment.
+this: { 'key1' => 'value1', 'key2' => 'value2', ...}.  They are opened and
+closed with curley-braces.  Key/values are delimited by the '=>' character
+combination.  Usually keys are predefined constants such as NAME, MAX_VERSIONS,
+COMPRESSION, MAX_LENGTH, TTL, etc.  Constants do not need to be quoted.  Type
+'Object.constants' to see a (messy) list of all constants in the environment.
+See http://wiki.apache.org/hadoop/Hbase/Shell for more on the HBase Shell.
 HERE
   puts h
 end
@@ -141,45 +151,43 @@
 
 # DDL
 
-def create(table_name, *args)
+def admin()
   @admin = HBase::Admin.new(@configuration, @formatter) unless @admin
-  @admin.create(table_name, args)
+  @admin
+end
+
+def create(table_name, *args)
+  admin().create(table_name, args)
 end
 
 def drop(table_name)
-  @admin = HBase::Admin.new(@configuration, @formatter) unless @admin
-  @admin.drop(table_name)
+  admin().drop(table_name)
 end
 
-def alter(table_name, *args)
-  puts "Not implemented yet"
+def alter(table_name, args)
+  admin().alter(table_name, args) 
 end
 
 # Administration
 
 def list
-  @admin = HBase::Admin.new(@configuration, @formatter) unless @admin
-  @admin.list()
+  admin().list()
 end
 
 def describe(table_name)
-  @admin = HBase::Admin.new(@configuration, @formatter) unless @admin
-  @admin.describe(table_name)
+  admin().describe(table_name)
 end
   
 def enable(table_name)
-  @admin = HBase::Admin.new(@configuration, @formatter) unless @admin
-  @admin.enable(table_name)
+  admin().enable(table_name)
 end
 
 def disable(table_name)
-  @admin = HBase::Admin.new(@configuration, @formatter) unless @admin
-  @admin.disable(table_name)
+  admin().disable(table_name)
 end
 
 def exists(table_name)
-  @admin = HBase::Admin.new(@configuration, @formatter) unless @admin
-  @admin.exists(table_name)
+  admin().exists(table_name)
 end
   
 # CRUD
@@ -201,7 +209,9 @@
 end
 
 # Output a banner message that tells users where to go for help
-puts "HBase Shell; type 'help<RETURN>' for the list of supported HBase commands"
+puts <<HERE
+HBase Shell; enter 'help<RETURN>' for list of supported commands.
+HERE
 version
 
 require "irb"

Modified: hadoop/hbase/trunk/conf/hbase-env.sh
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/conf/hbase-env.sh?rev=667684&r1=667683&r2=667684&view=diff
==============================================================================
--- hadoop/hbase/trunk/conf/hbase-env.sh (original)
+++ hadoop/hbase/trunk/conf/hbase-env.sh Fri Jun 13 15:42:11 2008
@@ -23,6 +23,7 @@
 
 # The java implementation to use.  Required.
 # export JAVA_HOME=/usr/lib/j2sdk1.5-sun
+export JAVA_HOME=/usr
 
 # Extra Java CLASSPATH elements.  Optional.
 # export HBASE_CLASSPATH=

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HColumnDescriptor.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HColumnDescriptor.java?rev=667684&r1=667683&r2=667684&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HColumnDescriptor.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HColumnDescriptor.java Fri Jun 13
15:42:11 2008
@@ -55,17 +55,33 @@
     /** Compress sequences of records together in blocks. */
     BLOCK
   }
-  
+
+  // Defines for jruby/shell
+  public static final String NAME = "NAME";
+  public static final String MAX_VERSIONS = "MAX_VERSIONS";
+  public static final String COMPRESSION = "COMPRESSION";
+  public static final String IN_MEMORY = "IN_MEMORY";
+  public static final String BLOCKCACHE = "BLOCKCACHE";
+  public static final String MAX_LENGTH = "MAX_LENGTH";
+  public static final String TTL = "TTL";
+  public static final String BLOOMFILTER = "BLOOMFILTER";
+  public static final String FOREVER = "FOREVER";
+
   /**
    * Default compression type.
    */
-  public static final CompressionType DEFAULT_COMPRESSION_TYPE =
+  public static final CompressionType DEFAULT_COMPRESSION =
     CompressionType.NONE;
 
   /**
    * Default number of versions of a record to keep.
    */
-  public static final int DEFAULT_N_VERSIONS = 3;
+  public static final int DEFAULT_MAX_VERSIONS = 3;
+
+  /**
+   * Default maximum cell length.
+   */
+  public static final int DEFAULT_MAX_LENGTH = Integer.MAX_VALUE;
 
   /**
    * Default setting for whether to serve from memory or not.
@@ -75,7 +91,7 @@
   /**
    * Default setting for whether to use a block cache or not.
    */
-  public static final boolean DEFAULT_BLOCK_CACHE_ENABLED = false;
+  public static final boolean DEFAULT_BLOCKCACHE = false;
 
   /**
    * Default maximum length of cell contents.
@@ -85,43 +101,31 @@
   /**
    * Default time to live of cell contents.
    */
-  public static final int DEFAULT_TIME_TO_LIVE = HConstants.FOREVER;
+  public static final int DEFAULT_TTL = HConstants.FOREVER;
 
   /**
    * Default bloom filter description.
    */
-  public static final BloomFilterDescriptor DEFAULT_BLOOM_FILTER_DESCRIPTOR =
-    null;
-
-  // Defines for jruby/shell
-  public static final String NAME = "NAME";
-  public static final String MAX_VERSIONS = "MAX_VERSIONS";
-  public static final String COMPRESSION = "COMPRESSION";
-  public static final String IN_MEMORY = "IN_MEMORY";
-  public static final String BLOCKCACHE = "BLOCKCACHE";
-  public static final String MAX_LENGTH = "MAX_LENGTH";
-  public static final String TTL = "TTL";
-  public static final String BLOOMFILTER = "BLOOMFILTER";
-  public static final String FOREVER = "FOREVER";
+  public static final BloomFilterDescriptor DEFAULT_BLOOMFILTER = null;
 
   // Column family name
   private byte [] name;
   // Number of versions to keep
-  private int maxVersions = DEFAULT_N_VERSIONS;
+  private int maxVersions = DEFAULT_MAX_VERSIONS;
   // Compression setting if any
-  private CompressionType compressionType = DEFAULT_COMPRESSION_TYPE;
+  private CompressionType compressionType = DEFAULT_COMPRESSION;
   // Serve reads from in-memory cache
   private boolean inMemory = DEFAULT_IN_MEMORY;
   // Serve reads from in-memory block cache
-  private boolean blockCacheEnabled = DEFAULT_BLOCK_CACHE_ENABLED;
+  private boolean blockCacheEnabled = DEFAULT_BLOCKCACHE;
   // Maximum value size
-  private int maxValueLength = Integer.MAX_VALUE;
+  private int maxValueLength = DEFAULT_MAX_LENGTH;
   // Time to live of cell contents, in seconds from last timestamp
-  private int timeToLive = HConstants.FOREVER;
+  private int timeToLive = DEFAULT_TTL;
   // True if bloom filter was specified
   private boolean bloomFilterSpecified = false;
   // Descriptor of bloom filter
-  private BloomFilterDescriptor bloomFilter = DEFAULT_BLOOM_FILTER_DESCRIPTOR;
+  private BloomFilterDescriptor bloomFilter = DEFAULT_BLOOMFILTER;
 
   /**
    * Default constructor. Must be present for Writable.
@@ -159,10 +163,10 @@
   public HColumnDescriptor(final byte [] columnName) {
     this (columnName == null || columnName.length <= 0?
       HConstants.EMPTY_BYTE_ARRAY: columnName,
-      DEFAULT_N_VERSIONS, DEFAULT_COMPRESSION_TYPE, DEFAULT_IN_MEMORY,
-      DEFAULT_BLOCK_CACHE_ENABLED, 
-      Integer.MAX_VALUE, DEFAULT_TIME_TO_LIVE,
-      DEFAULT_BLOOM_FILTER_DESCRIPTOR);
+      DEFAULT_MAX_VERSIONS, DEFAULT_COMPRESSION, DEFAULT_IN_MEMORY,
+      DEFAULT_BLOCKCACHE, 
+      Integer.MAX_VALUE, DEFAULT_TTL,
+      DEFAULT_BLOOMFILTER);
   }
 
   /**
@@ -245,6 +249,13 @@
     return name;
   }
 
+  /**
+   * @return Name of this column family
+   */
+  public String getNameAsString() {
+    return Bytes.toString(this.name);
+  }
+
   /** @return compression type being used for the column family */
   public CompressionType getCompression() {
     return this.compressionType;
@@ -302,8 +313,8 @@
   public String toString() {
     return "{" + NAME + " => '" + Bytes.toString(name) +
       "', " + MAX_VERSIONS + " => " + maxVersions +
-      ", " + COMPRESSION + " => " + this.compressionType +
-      ", " + IN_MEMORY + " => " + inMemory +
+      ", " + COMPRESSION + " => '" + this.compressionType +
+      "', " + IN_MEMORY + " => " + inMemory +
       ", " + BLOCKCACHE + " => " + blockCacheEnabled +
       ", " + MAX_LENGTH + " => " + maxValueLength +
       ", " + TTL + " => " +

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/ModifyColumn.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/ModifyColumn.java?rev=667684&r1=667683&r2=667684&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/ModifyColumn.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/ModifyColumn.java Fri Jun 13
15:42:11 2008
@@ -24,6 +24,7 @@
 import org.apache.hadoop.hbase.HColumnDescriptor;
 import org.apache.hadoop.hbase.InvalidColumnNameException;
 import org.apache.hadoop.hbase.ipc.HRegionInterface;
+import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.HRegionInfo;
 
 /** Instantiated to modify an existing column family on a table */
@@ -47,7 +48,8 @@
         i.getTableDesc().addFamily(descriptor);
         updateRegionInfo(server, m.getRegionName(), i);
       } else { // otherwise, we have an error.
-        throw new InvalidColumnNameException("Column family '" + columnName + 
+        throw new InvalidColumnNameException("Column family '" +
+          Bytes.toString(columnName) + 
           "' doesn't exist, so cannot be modified.");
       }
     }

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HStoreFile.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HStoreFile.java?rev=667684&r1=667683&r2=667684&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HStoreFile.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HStoreFile.java Fri Jun
13 15:42:11 2008
@@ -990,4 +990,4 @@
       return super.seek(key);
     }
   }
-}
+}
\ No newline at end of file

Modified: hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestBloomFilters.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestBloomFilters.java?rev=667684&r1=667683&r2=667684&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestBloomFilters.java (original)
+++ hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestBloomFilters.java Fri Jun 13 15:42:11
2008
@@ -172,9 +172,9 @@
             1,                                        // Max versions
             HColumnDescriptor.CompressionType.NONE,   // no compression
             HColumnDescriptor.DEFAULT_IN_MEMORY,      // not in memory
-            HColumnDescriptor.DEFAULT_BLOCK_CACHE_ENABLED,
+            HColumnDescriptor.DEFAULT_BLOCKCACHE,
             HColumnDescriptor.DEFAULT_MAX_VALUE_LENGTH,
-            HColumnDescriptor.DEFAULT_TIME_TO_LIVE,
+            HColumnDescriptor.DEFAULT_TTL,
             bloomFilter
         )
     );
@@ -238,9 +238,9 @@
             1,                                        // Max versions
             HColumnDescriptor.CompressionType.NONE,   // no compression
             HColumnDescriptor.DEFAULT_IN_MEMORY,      // not in memory
-            HColumnDescriptor.DEFAULT_BLOCK_CACHE_ENABLED,
+            HColumnDescriptor.DEFAULT_BLOCKCACHE,
             HColumnDescriptor.DEFAULT_MAX_VALUE_LENGTH,
-            HColumnDescriptor.DEFAULT_TIME_TO_LIVE,
+            HColumnDescriptor.DEFAULT_TTL,
             bloomFilter
         )
     );



Mime
View raw message