incubator-hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edwardy...@apache.org
Subject svn commit: r695716 - in /incubator/hama/trunk: CHANGES.txt src/java/org/apache/hama/AbstractMatrix.java src/java/org/apache/hama/Constants.java src/java/org/apache/hama/Matrix.java src/test/org/apache/hama/TestDenseMatrix.java
Date Tue, 16 Sep 2008 03:18:47 GMT
Author: edwardyoon
Date: Mon Sep 15 20:18:46 2008
New Revision: 695716

URL: http://svn.apache.org/viewvc?rev=695716&view=rev
Log:
Add get/setRowAttribute() method

Modified:
    incubator/hama/trunk/CHANGES.txt
    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/test/org/apache/hama/TestDenseMatrix.java

Modified: incubator/hama/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/CHANGES.txt?rev=695716&r1=695715&r2=695716&view=diff
==============================================================================
--- incubator/hama/trunk/CHANGES.txt (original)
+++ incubator/hama/trunk/CHANGES.txt Mon Sep 15 20:18:46 2008
@@ -4,6 +4,7 @@
 
   NEW FEATURES
     
+    HAMA-51: Add get/setRowAttribute() method (edwardyoon)
     HAMA-13: Matrix multiplication (edwardyoon)
     HAMA-48: Add getColumn(int column) method which returns column vector (edwardyoon)
     HAMA-49: Add iterator() method to vector (edwardyoon)

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=695716&r1=695715&r2=695716&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java Mon Sep 15 20:18:46
2008
@@ -28,6 +28,7 @@
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.io.BatchUpdate;
 import org.apache.hadoop.hbase.io.Cell;
+import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.mapred.JobClient;
 import org.apache.hadoop.mapred.JobConf;
 import org.apache.hadoop.mapred.RunningJob;
@@ -71,6 +72,7 @@
   protected void create() {
     try {
       tableDesc.addFamily(new HColumnDescriptor(Constants.METADATA));
+      tableDesc.addFamily(new HColumnDescriptor(Constants.ATTRIBUTE));
       LOG.info("Initializing the matrix storage.");
       admin.createTable(tableDesc);
     } catch (IOException e) {
@@ -86,9 +88,9 @@
         .getCounter();
     // TODO : Thinking about more efficient method.
     int columns = result.getRow(0).size();
-    result.setDimension((int)rows, columns);
+    result.setDimension((int) rows, columns);
   }
-  
+
   /** {@inheritDoc} */
   public double get(int i, int j) throws IOException {
     double result = -1;
@@ -133,6 +135,21 @@
     table.commit(b);
   }
 
+  public String getRowAttribute(int row) throws IOException {
+    Cell rows = null;
+    rows = table.get(Numeric.intToBytes(row), Bytes.toBytes(Constants.ATTRIBUTE
+        + "string"));
+
+    return (rows != null) ? Bytes.toString(rows.getValue()) : null;
+  }
+
+  public void setRowAttribute(int row, String name) throws IOException {
+    BatchUpdate b = new BatchUpdate(Numeric.intToBytes(row));
+    b.put(Constants.ATTRIBUTE + "string", Bytes.toBytes(name));
+
+    table.commit(b);
+  }
+
   /** {@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=695716&r1=695715&r2=695716&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/Constants.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/Constants.java Mon Sep 15 20:18:46 2008
@@ -44,6 +44,11 @@
    */
   public final static String METADATA_TYPE = "metadata:type";
   
+  /**
+   * The attribute of the indices
+   */
+  public final static String ATTRIBUTE = "attribute:";
+  
   /** 
    * 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=695716&r1=695715&r2=695716&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/Matrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/Matrix.java Mon Sep 15 20:18:46 2008
@@ -55,7 +55,7 @@
   public Vector getColumn(int column) throws IOException;
 
   /**
-   * Get a number of row of the matrix from the meta-data column
+   * Get the number of row of the matrix from the meta-data column
    * 
    * @return a number of rows of the matrix
    * @throws IOException 
@@ -63,7 +63,7 @@
   public int getRows() throws IOException;
 
   /**
-   * Get a number of column of the matrix from the meta-data column
+   * Get the number of column of the matrix from the meta-data column
    * 
    * @return a number of columns of the matrix
    * @throws IOException 
@@ -71,6 +71,22 @@
   public int getColumns() throws IOException;
 
   /**
+   * Gets the attribute of the row
+   * 
+   * @throws IOException
+   */
+  public String getRowAttribute(int row) throws IOException;
+  
+  /**
+   * Sets the attribute of the row
+   * 
+   * @param row
+   * @param name
+   * @throws IOException
+   */
+  public void setRowAttribute(int row, String name) throws IOException;
+  
+  /**
    * Sets the double value of (i, j)
    * 
    * @param i ith row of the matrix
@@ -191,7 +207,7 @@
     /** Largest entry in absolute value */
     Infinity
   }
-
+  
   /**
    * Return the matrix name
    * 

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=695716&r1=695715&r2=695716&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java Mon Sep 15 20:18:46
2008
@@ -72,6 +72,12 @@
     }
   }
 
+  public void testGetSetAttribute() throws IOException {
+    m1.setRowAttribute(0, "test1");
+    assertEquals(m1.getRowAttribute(0), "test1");
+    assertEquals(m1.getRowAttribute(1), null);
+  }
+  
   /**
    * Test matrices addition
    * 



Mime
View raw message