Package org.apache.hadoop.hbase.mapreduce.ImportTsv

Examples of org.apache.hadoop.hbase.mapreduce.ImportTsv.TsvParser


    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");
    parser.parse(line, line.length);
  }
View Full Code Here


    parser.parse(line, line.length);
  }

  @Test(expected = BadTsvLineException.class)
  public void testTsvParserInvalidTimestamp() throws BadTsvLineException {
    TsvParser parser = new TsvParser("HBASE_ROW_KEY,HBASE_TS_KEY,col_a,", "\t");
    assertEquals(1, parser.getTimestampKeyColumnIndex());
    byte[] line = Bytes.toBytes("rowkey\ttimestamp\tval_a");
    ParsedLine parsed = parser.parse(line, line.length);
    assertEquals(-1, parsed.getTimestamp(-1));
    checkParsing(parsed, Splitter.on("\t").split(Bytes.toString(line)));
  }
View Full Code Here

    checkParsing(parsed, Splitter.on("\t").split(Bytes.toString(line)));
  }

  @Test(expected = BadTsvLineException.class)
  public void testTsvParserNoTimestampValue() throws BadTsvLineException {
    TsvParser parser = new TsvParser("HBASE_ROW_KEY,col_a,HBASE_TS_KEY", "\t");
    assertEquals(2, parser.getTimestampKeyColumnIndex());
    byte[] line = Bytes.toBytes("rowkey\tval_a");
    parser.parse(line, line.length);
  }
View Full Code Here

    parser.parse(line, line.length);
  }

  @Test
  public void testTsvParserParseRowKey() throws BadTsvLineException {
    TsvParser parser = new TsvParser("HBASE_ROW_KEY,col_a,HBASE_TS_KEY", "\t");
    assertEquals(0, parser.getRowKeyColumnIndex());
    byte[] line = Bytes.toBytes("rowkey\tval_a\t1234");
    Pair<Integer, Integer> rowKeyOffsets = parser.parseRowKey(line, line.length);
    assertEquals(0, rowKeyOffsets.getFirst().intValue());
    assertEquals(6, rowKeyOffsets.getSecond().intValue());
    try {
      line = Bytes.toBytes("\t\tval_a\t1234");
      parser.parseRowKey(line, line.length);
      fail("Should get BadTsvLineException on empty rowkey.");
    } catch (BadTsvLineException b) {

    }
    parser = new TsvParser("col_a,HBASE_ROW_KEY,HBASE_TS_KEY", "\t");
    assertEquals(1, parser.getRowKeyColumnIndex());
    line = Bytes.toBytes("val_a\trowkey\t1234");
    rowKeyOffsets = parser.parseRowKey(line, line.length);
    assertEquals(6, rowKeyOffsets.getFirst().intValue());
    assertEquals(6, rowKeyOffsets.getSecond().intValue());
    try {
      line = Bytes.toBytes("val_a");
      rowKeyOffsets = parser.parseRowKey(line, line.length);
      fail("Should get BadTsvLineException when number of columns less than rowkey position.");
    } catch (BadTsvLineException b) {

    }
    parser = new TsvParser("col_a,HBASE_TS_KEY,HBASE_ROW_KEY", "\t");
    assertEquals(2, parser.getRowKeyColumnIndex());
    line = Bytes.toBytes("val_a\t1234\trowkey");
    rowKeyOffsets = parser.parseRowKey(line, line.length);
    assertEquals(11, rowKeyOffsets.getFirst().intValue());
    assertEquals(6, rowKeyOffsets.getSecond().intValue());
  }
View Full Code Here

    assertEquals(6, rowKeyOffsets.getSecond().intValue());
  }

  @Test
  public void testTsvParseAttributesKey() throws BadTsvLineException {
    TsvParser parser = new TsvParser("HBASE_ROW_KEY,col_a,HBASE_TS_KEY,HBASE_ATTRIBUTES_KEY", "\t");
    assertEquals(0, parser.getRowKeyColumnIndex());
    byte[] line = Bytes.toBytes("rowkey\tval_a\t1234\tkey=>value");
    ParsedLine parse = parser.parse(line, line.length);
    assertEquals(18, parse.getAttributeKeyOffset());
    assertEquals(3, parser.getAttributesKeyColumnIndex());
    String attributes[] = parse.getIndividualAttributes();
    assertEquals(attributes[0], "key=>value");
    try {
      line = Bytes.toBytes("rowkey\tval_a\t1234");
      parser.parse(line, line.length);
      fail("Should get BadTsvLineException on empty rowkey.");
    } catch (BadTsvLineException b) {

    }
    parser = new TsvParser("HBASE_ATTRIBUTES_KEY,col_a,HBASE_ROW_KEY,HBASE_TS_KEY", "\t");
    assertEquals(2, parser.getRowKeyColumnIndex());
    line = Bytes.toBytes("key=>value\tval_a\trowkey\t1234");
    parse = parser.parse(line, line.length);
    assertEquals(0, parse.getAttributeKeyOffset());
    assertEquals(0, parser.getAttributesKeyColumnIndex());
    attributes = parse.getIndividualAttributes();
    assertEquals(attributes[0], "key=>value");
    try {
      line = Bytes.toBytes("val_a");
      ParsedLine parse2 = parser.parse(line, line.length);
      fail("Should get BadTsvLineException when number of columns less than rowkey position.");
    } catch (BadTsvLineException b) {

    }
    parser = new TsvParser("col_a,HBASE_ATTRIBUTES_KEY,HBASE_TS_KEY,HBASE_ROW_KEY", "\t");
    assertEquals(3, parser.getRowKeyColumnIndex());
    line = Bytes.toBytes("val_a\tkey0=>value0,key1=>value1,key2=>value2\t1234\trowkey");
    parse = parser.parse(line, line.length);
    assertEquals(1, parser.getAttributesKeyColumnIndex());
    assertEquals(6, parse.getAttributeKeyOffset());
    String[] attr = parse.getIndividualAttributes();
    int i = 0;
    for(String str :  attr) {
      assertEquals(("key"+i+"=>"+"value"+i), str );
View Full Code Here

    }
  }

  @Test
  public void testTsvParserWithCellVisibilityCol() throws BadTsvLineException {
    TsvParser parser = new TsvParser(
        "HBASE_ROW_KEY,col_a,HBASE_TS_KEY,HBASE_ATTRIBUTES_KEY,HBASE_CELL_VISIBILITY", "\t");
    assertEquals(0, parser.getRowKeyColumnIndex());
    assertEquals(4, parser.getCellVisibilityColumnIndex());
    byte[] line = Bytes.toBytes("rowkey\tval_a\t1234\tkey=>value\tPRIVATE&SECRET");
    ParsedLine parse = parser.parse(line, line.length);
    assertEquals(18, parse.getAttributeKeyOffset());
    assertEquals(3, parser.getAttributesKeyColumnIndex());
    String attributes[] = parse.getIndividualAttributes();
    assertEquals(attributes[0], "key=>value");
    assertEquals(29, parse.getCellVisibilityColumnOffset());
  }
View Full Code Here

    checkParsing(parsed, Splitter.on("\t").split(Bytes.toString(line)));
  }

  @Test(expected = BadTsvLineException.class)
  public void testTsvParserNoTimestampValue() throws BadTsvLineException {
    TsvParser parser = new TsvParser("HBASE_ROW_KEY,col_a,HBASE_TS_KEY", "\t");
    assertEquals(2, parser.getTimestampKeyColumnIndex());
    byte[] line = Bytes.toBytes("rowkey\tval_a");
    parser.parse(line, line.length);
  }
View Full Code Here

    parser.parse(line, line.length);
  }

  @Test
  public void testTsvParserParseRowKey() throws BadTsvLineException {
    TsvParser parser = new TsvParser("HBASE_ROW_KEY,col_a,HBASE_TS_KEY", "\t");
    assertEquals(0, parser.getRowKeyColumnIndex());
    byte[] line = Bytes.toBytes("rowkey\tval_a\t1234");
    Pair<Integer, Integer> rowKeyOffsets = parser.parseRowKey(line, line.length);
    assertEquals(0, rowKeyOffsets.getFirst().intValue());
    assertEquals(6, rowKeyOffsets.getSecond().intValue());
    try {
      line = Bytes.toBytes("\t\tval_a\t1234");
      parser.parseRowKey(line, line.length);
      fail("Should get BadTsvLineException on empty rowkey.");
    } catch (BadTsvLineException b) {

    }
    parser = new TsvParser("col_a,HBASE_ROW_KEY,HBASE_TS_KEY", "\t");
    assertEquals(1, parser.getRowKeyColumnIndex());
    line = Bytes.toBytes("val_a\trowkey\t1234");
    rowKeyOffsets = parser.parseRowKey(line, line.length);
    assertEquals(6, rowKeyOffsets.getFirst().intValue());
    assertEquals(6, rowKeyOffsets.getSecond().intValue());
    try {
      line = Bytes.toBytes("val_a");
      rowKeyOffsets = parser.parseRowKey(line, line.length);
      fail("Should get BadTsvLineException when number of columns less than rowkey position.");
    } catch (BadTsvLineException b) {

    }
    parser = new TsvParser("col_a,HBASE_TS_KEY,HBASE_ROW_KEY", "\t");
    assertEquals(2, parser.getRowKeyColumnIndex());
    line = Bytes.toBytes("val_a\t1234\trowkey");
    rowKeyOffsets = parser.parseRowKey(line, line.length);
    assertEquals(11, rowKeyOffsets.getFirst().intValue());
    assertEquals(6, rowKeyOffsets.getSecond().intValue());
  }
View Full Code Here

    assertEquals(6, rowKeyOffsets.getSecond().intValue());
  }

  @Test
  public void testTsvParseAttributesKey() throws BadTsvLineException {
    TsvParser parser = new TsvParser("HBASE_ROW_KEY,col_a,HBASE_TS_KEY,HBASE_ATTRIBUTES_KEY", "\t");
    assertEquals(0, parser.getRowKeyColumnIndex());
    byte[] line = Bytes.toBytes("rowkey\tval_a\t1234\tkey=>value");
    ParsedLine parse = parser.parse(line, line.length);
    assertEquals(18, parse.getAttributeKeyOffset());
    assertEquals(3, parser.getAttributesKeyColumnIndex());
    String attributes[] = parse.getIndividualAttributes();
    assertEquals(attributes[0], "key=>value");
    try {
      line = Bytes.toBytes("rowkey\tval_a\t1234");
      parser.parse(line, line.length);
      fail("Should get BadTsvLineException on empty rowkey.");
    } catch (BadTsvLineException b) {

    }
    parser = new TsvParser("HBASE_ATTRIBUTES_KEY,col_a,HBASE_ROW_KEY,HBASE_TS_KEY", "\t");
    assertEquals(2, parser.getRowKeyColumnIndex());
    line = Bytes.toBytes("key=>value\tval_a\trowkey\t1234");
    parse = parser.parse(line, line.length);
    assertEquals(0, parse.getAttributeKeyOffset());
    assertEquals(0, parser.getAttributesKeyColumnIndex());
    attributes = parse.getIndividualAttributes();
    assertEquals(attributes[0], "key=>value");
    try {
      line = Bytes.toBytes("val_a");
      ParsedLine parse2 = parser.parse(line, line.length);
      fail("Should get BadTsvLineException when number of columns less than rowkey position.");
    } catch (BadTsvLineException b) {

    }
    parser = new TsvParser("col_a,HBASE_ATTRIBUTES_KEY,HBASE_TS_KEY,HBASE_ROW_KEY", "\t");
    assertEquals(3, parser.getRowKeyColumnIndex());
    line = Bytes.toBytes("val_a\tkey0=>value0,key1=>value1,key2=>value2\t1234\trowkey");
    parse = parser.parse(line, line.length);
    assertEquals(1, parser.getAttributesKeyColumnIndex());
    assertEquals(6, parse.getAttributeKeyOffset());
    String[] attr = parse.getIndividualAttributes();
    int i = 0;
    for(String str :  attr) {
      assertEquals(("key"+i+"=>"+"value"+i), str );
View Full Code Here

    }
  }

  @Test
  public void testTsvParserWithCellVisibilityCol() throws BadTsvLineException {
    TsvParser parser = new TsvParser(
        "HBASE_ROW_KEY,col_a,HBASE_TS_KEY,HBASE_ATTRIBUTES_KEY,HBASE_CELL_VISIBILITY", "\t");
    assertEquals(0, parser.getRowKeyColumnIndex());
    assertEquals(4, parser.getCellVisibilityColumnIndex());
    byte[] line = Bytes.toBytes("rowkey\tval_a\t1234\tkey=>value\tPRIVATE&SECRET");
    ParsedLine parse = parser.parse(line, line.length);
    assertEquals(18, parse.getAttributeKeyOffset());
    assertEquals(3, parser.getAttributesKeyColumnIndex());
    String attributes[] = parse.getIndividualAttributes();
    assertEquals(attributes[0], "key=>value");
    assertEquals(29, parse.getCellVisibilityColumnOffset());
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.mapreduce.ImportTsv.TsvParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.