hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1026483 - in /hbase/trunk: CHANGES.txt src/main/java/org/apache/hadoop/hbase/mapreduce/ImportTsv.java src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportTsv.java
Date Fri, 22 Oct 2010 20:25:00 GMT
Author: todd
Date: Fri Oct 22 20:24:59 2010
New Revision: 1026483

URL: http://svn.apache.org/viewvc?rev=1026483&view=rev
Log:
HBASE-3145. importtsv fails when the line contains no data (Kazuki Ohta via Todd Lipcon)

Modified:
    hbase/trunk/CHANGES.txt
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/mapreduce/ImportTsv.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportTsv.java

Modified: hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=1026483&r1=1026482&r2=1026483&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Fri Oct 22 20:24:59 2010
@@ -604,6 +604,8 @@ Release 0.21.0 - Unreleased
    HBASE-3140  Rest schema modification throw null pointer exception
                (David Worms via Stack)
    HBASE-2998  rolling-restart.sh shouldn't rely on zoo.cfg
+   HBASE-3145  importtsv fails when the line contains no data
+               (Kazuki Ohta via Todd Lipcon)
 
 
   IMPROVEMENTS

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/mapreduce/ImportTsv.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/mapreduce/ImportTsv.java?rev=1026483&r1=1026482&r2=1026483&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/mapreduce/ImportTsv.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/mapreduce/ImportTsv.java Fri Oct 22
20:24:59 2010
@@ -130,11 +130,17 @@ public class ImportTsv {
           tabOffsets.add(i);
         }
       }
+      if (tabOffsets.isEmpty()) {
+        throw new BadTsvLineException("No delimiter");
+      }
+
       tabOffsets.add(length);
+
       if (tabOffsets.size() > families.length) {
-        throw new BadTsvLineException("Bad line:\n");
+        throw new BadTsvLineException("Excessive columns");
+      } else if (tabOffsets.size() <= getRowKeyColumnIndex()) {
+        throw new BadTsvLineException("No row key");
       }
-
       return new ParsedLine(tabOffsets, lineBytes);
     }
     
@@ -353,6 +359,12 @@ public class ImportTsv {
       System.exit(-1);
     }
 
+    // Make sure one or more columns are specified
+    if (columns.length < 2) {
+      usage("One or more columns in addition to the row key are required");
+      System.exit(-1);
+    }
+
     Job job = createSubmittableJob(conf, otherArgs);
     System.exit(job.waitForCompletion(true) ? 0 : 1);
   }

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportTsv.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportTsv.java?rev=1026483&r1=1026482&r2=1026483&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportTsv.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportTsv.java Fri Oct
22 20:24:59 2010
@@ -36,6 +36,32 @@ import static org.junit.Assert.*;
 
 public class TestImportTsv {
   @Test
+  public void testTsvParserSpecParsing() {
+    TsvParser parser;
+
+    parser = new TsvParser("HBASE_ROW_KEY", "\t");
+    assertNull(parser.getFamily(0));
+    assertNull(parser.getQualifier(0));
+    assertEquals(0, parser.getRowKeyColumnIndex());
+
+    parser = new TsvParser("HBASE_ROW_KEY,col1:scol1", "\t");
+    assertNull(parser.getFamily(0));
+    assertNull(parser.getQualifier(0));
+    assertBytesEquals(Bytes.toBytes("col1"), parser.getFamily(1));
+    assertBytesEquals(Bytes.toBytes("scol1"), parser.getQualifier(1));
+    assertEquals(0, parser.getRowKeyColumnIndex());
+
+    parser = new TsvParser("HBASE_ROW_KEY,col1:scol1,col1:scol2", "\t");
+    assertNull(parser.getFamily(0));
+    assertNull(parser.getQualifier(0));
+    assertBytesEquals(Bytes.toBytes("col1"), parser.getFamily(1));
+    assertBytesEquals(Bytes.toBytes("scol1"), parser.getQualifier(1));
+    assertBytesEquals(Bytes.toBytes("col1"), parser.getFamily(2));
+    assertBytesEquals(Bytes.toBytes("scol2"), parser.getQualifier(2));
+    assertEquals(0, parser.getRowKeyColumnIndex());
+  }
+
+  @Test
   public void testTsvParser() throws BadTsvLineException {
     TsvParser parser = new TsvParser("col_a,col_b:qual,HBASE_ROW_KEY,col_d", "\t");
     assertBytesEquals(Bytes.toBytes("col_a"), parser.getFamily(0));
@@ -44,11 +70,11 @@ public class TestImportTsv {
     assertBytesEquals(Bytes.toBytes("qual"), parser.getQualifier(1));
     assertNull(parser.getFamily(2));
     assertNull(parser.getQualifier(2));
+    assertEquals(2, parser.getRowKeyColumnIndex());
     
     byte[] line = Bytes.toBytes("val_a\tval_b\tval_c\tval_d");
     ParsedLine parsed = parser.parse(line, line.length);
     checkParsing(parsed, Splitter.on("\t").split(Bytes.toString(line)));
-    assertEquals(2, parser.getRowKeyColumnIndex());
   }
 
   private void checkParsing(ParsedLine parsed, Iterable<String> expected) {
@@ -68,4 +94,35 @@ public class TestImportTsv {
   private void assertBytesEquals(byte[] a, byte[] b) {
     assertEquals(Bytes.toStringBinary(a), Bytes.toStringBinary(b));
   }
+
+  /**
+   * Test cases that throw BadTsvLineException
+   */
+  @Test(expected=BadTsvLineException.class)
+  public void testTsvParserBadTsvLineExcessiveColumns() throws BadTsvLineException {
+    TsvParser parser = new TsvParser("HBASE_ROW_KEY,col_a", "\t");
+    byte[] line = Bytes.toBytes("val_a\tval_b\tval_c");
+    ParsedLine parsed = parser.parse(line, line.length);
+  }
+
+  @Test(expected=BadTsvLineException.class)
+  public void testTsvParserBadTsvLineZeroColumn() throws BadTsvLineException {
+    TsvParser parser = new TsvParser("HBASE_ROW_KEY,col_a", "\t");
+    byte[] line = Bytes.toBytes("");
+    ParsedLine parsed = parser.parse(line, line.length);
+  }
+
+  @Test(expected=BadTsvLineException.class)
+  public void testTsvParserBadTsvLineOnlyKey() throws BadTsvLineException {
+    TsvParser parser = new TsvParser("HBASE_ROW_KEY,col_a", "\t");
+    byte[] line = Bytes.toBytes("key_only");
+    ParsedLine parsed = parser.parse(line, line.length);
+  }
+
+  @Test(expected=BadTsvLineException.class)
+  public void testTsvParserBadTsvLineNoRowKey() throws BadTsvLineException {
+    TsvParser parser = new TsvParser("col_a,HBASE_ROW_KEY", "\t");
+    byte[] line = Bytes.toBytes("only_cola_data_and_no_row_key");
+    ParsedLine parsed = parser.parse(line, line.length);
+  }
 }



Mime
View raw message