You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hama.apache.org by ed...@apache.org on 2008/09/16 09:45:20 UTC

svn commit: r695756 - in /incubator/hama/trunk/src: java/org/apache/hama/AbstractMatrix.java java/org/apache/hama/Constants.java java/org/apache/hama/Matrix.java java/org/apache/hama/io/VectorUpdate.java test/org/apache/hama/TestDenseMatrix.java

Author: edwardyoon
Date: Tue Sep 16 00:45:19 2008
New Revision: 695756

URL: http://svn.apache.org/viewvc?rev=695756&view=rev
Log: (empty)

Modified:
    incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java
    incubator/hama/trunk/src/java/org/apache/hama/Constants.java
    incubator/hama/trunk/src/java/org/apache/hama/Matrix.java
    incubator/hama/trunk/src/java/org/apache/hama/io/VectorUpdate.java
    incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java

Modified: incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java?rev=695756&r1=695755&r2=695756&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java Tue Sep 16 00:45:19 2008
@@ -71,7 +71,6 @@
    */
   protected void create() {
     try {
-      this.tableDesc.addFamily(new HColumnDescriptor(Constants.METADATA));
       this.tableDesc.addFamily(new HColumnDescriptor(Constants.ATTRIBUTE));
       LOG.info("Initializing the matrix storage.");
       this.admin.createTable(this.tableDesc);
@@ -149,6 +148,19 @@
     table.commit(update.getBatchUpdate());
   }
 
+  public String getColumnAttribute(int column) throws IOException {
+    Cell rows = null;
+    rows = table.get(Constants.COLUMN_INDEX, 
+        (Constants.ATTRIBUTE + column));
+    return (rows != null) ? Bytes.toString(rows.getValue()) : null;
+  }
+
+  public void setColumnAttribute(int column, String name) throws IOException {
+    VectorUpdate update = new VectorUpdate(Constants.COLUMN_INDEX);
+    update.put(column, name);
+    table.commit(update.getBatchUpdate());
+  }
+
   /** {@inheritDoc} */
   public String getName() {
     return (matrixName != null) ? matrixName : null;

Modified: incubator/hama/trunk/src/java/org/apache/hama/Constants.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/Constants.java?rev=695756&r1=695755&r2=695756&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/Constants.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/Constants.java Tue Sep 16 00:45:19 2008
@@ -27,27 +27,32 @@
   /** 
    * Meta-columnFamily to store the matrix-info 
    */
-  public final static String METADATA = "metadata:";
+  public final static String METADATA = "metadata";
+  
+  /**
+   * Column index & attributes
+   */
+  public final static String COLUMN_INDEX = "columnIndex";
+  
+  /**
+   * The attribute column family
+   */
+  public final static String ATTRIBUTE = "attribute:";
   
   /** 
    * The number of the matrix rows 
    */
-  public final static String METADATA_ROWS = "metadata:rows";
+  public final static String METADATA_ROWS = "attribute:rows";
   
   /** 
    * The number of the matrix columns 
    */
-  public final static String METADATA_COLUMNS = "metadata:columns";
+  public final static String METADATA_COLUMNS = "attribute:columns";
   
   /** 
    * The type of the matrix
    */
-  public final static String METADATA_TYPE = "metadata:type";
-  
-  /**
-   * The attribute of the indices
-   */
-  public final static String ATTRIBUTE = "attribute:";
+  public final static String METADATA_TYPE = "attribute:type";
   
   /** 
    * Default columnFamily name 

Modified: incubator/hama/trunk/src/java/org/apache/hama/Matrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/Matrix.java?rev=695756&r1=695755&r2=695756&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/Matrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/Matrix.java Tue Sep 16 00:45:19 2008
@@ -87,6 +87,22 @@
   public void setRowAttribute(int row, String name) throws IOException;
   
   /**
+   * Gets the attribute of the column
+   * 
+   * @throws IOException
+   */
+  public String getColumnAttribute(int column) throws IOException;
+  
+  /**
+   * Sets the attribute of the column
+   * 
+   * @param column
+   * @param name
+   * @throws IOException
+   */
+  public void setColumnAttribute(int column, String name) throws IOException;
+  
+  /**
    * Sets the double value of (i, j)
    * 
    * @param i ith row of the matrix

Modified: incubator/hama/trunk/src/java/org/apache/hama/io/VectorUpdate.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/io/VectorUpdate.java?rev=695756&r1=695755&r2=695756&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/io/VectorUpdate.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/io/VectorUpdate.java Tue Sep 16 00:45:19 2008
@@ -25,6 +25,7 @@
 
 import org.apache.hadoop.hbase.io.BatchUpdate;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hama.Constants;
 import org.apache.hama.util.Numeric;
 
 public class VectorUpdate {
@@ -34,8 +35,12 @@
     this.batchUpdate = new BatchUpdate(Numeric.intToBytes(i));
   }
 
-  public VectorUpdate(String metadata) {
-    this.batchUpdate = new BatchUpdate(metadata);
+  public VectorUpdate(String row) {
+    this.batchUpdate = new BatchUpdate(row);
+  }
+
+  public VectorUpdate(byte[] row) {
+    this.batchUpdate = new BatchUpdate(row);
   }
 
   public void put(int j, double value) {
@@ -43,12 +48,17 @@
         .doubleToBytes(value));
   }
 
-  public void put(String column, String val) {
-    this.batchUpdate.put(column, Bytes.toBytes(val));
+  public void put(int j, String name) {
+    this.batchUpdate.put(Bytes.toBytes((Constants.ATTRIBUTE + j)), Bytes
+        .toBytes(name));
+  }
+
+  public void put(String j, String val) {
+    this.batchUpdate.put(j, Bytes.toBytes(val));
   }
 
-  public void put(String metadataRows, int rows) {
-    this.batchUpdate.put(metadataRows, Numeric.intToBytes(rows));
+  public void put(String row, int val) {
+    this.batchUpdate.put(row, Numeric.intToBytes(val));
   }
 
   public BatchUpdate getBatchUpdate() {

Modified: incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java?rev=695756&r1=695755&r2=695756&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java Tue Sep 16 00:45:19 2008
@@ -73,9 +73,13 @@
   }
 
   public void testGetSetAttribute() throws IOException {
-    m1.setRowAttribute(0, "test1");
-    assertEquals(m1.getRowAttribute(0), "test1");
+    m1.setRowAttribute(0, "row1");
+    assertEquals(m1.getRowAttribute(0), "row1");
     assertEquals(m1.getRowAttribute(1), null);
+    
+    m1.setColumnAttribute(0, "column1");
+    assertEquals(m1.getColumnAttribute(0), "column1");
+    assertEquals(m1.getColumnAttribute(1), null);
   }
   
   /**