Package org.apache.hadoop.zebra.io

Examples of org.apache.hadoop.zebra.io.TableScanner


  public void testReadRecordOfMap1() throws IOException, ParseException {
    String projection1 = new String("r2.r3.f4#{a|b}, r2.r3.f3");
    BasicTable.Reader reader = new BasicTable.Reader(path, conf);
    reader.setProjection(projection1);
    List<RangeSplit> splits = reader.rangeSplit(1);
    TableScanner scanner = reader.getScanner(splits.get(0), true);
    scanner = reader.getScanner(splits.get(0), true);
    BytesWritable key = new BytesWritable();
    Tuple RowValue = TypesUtils.createTuple(scanner.getSchema());

    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k11".getBytes()));
    scanner.getValue(RowValue);
    Assert.assertEquals(1, ((Map) (RowValue.get(0))).get("a"));
    Assert.assertEquals(2, ((Map) RowValue.get(0)).get("b"));
    Assert.assertEquals(null, ((Map) (RowValue.get(0))).get("x"));
    Assert.assertEquals(null, ((Map) RowValue.get(0)).get("y"));
    Assert.assertEquals(1.3, RowValue.get(1));

    scanner.advance();
    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k12".getBytes()));
    scanner.getValue(RowValue);
    Assert.assertEquals(null, ((Map) RowValue.get(0)).get("a"));
    Assert.assertEquals(null, ((Map) RowValue.get(0)).get("b"));
    Assert.assertEquals(null, ((Map) RowValue.get(0)).get("x"));
    Assert.assertEquals(null, ((Map) RowValue.get(0)).get("y"));
    Assert.assertEquals(null, ((Map) RowValue.get(0)).get("c"));
View Full Code Here


  public void testRead3() throws IOException, ParseException {
    String projection = new String("c3");
    BasicTable.Reader reader = new BasicTable.Reader(path, conf);
    reader.setProjection(projection);
    List<RangeSplit> splits = reader.rangeSplit(1);
    TableScanner scanner = reader.getScanner(splits.get(0), true);
    BytesWritable key = new BytesWritable();
    Tuple RowValue = TypesUtils.createTuple(scanner.getSchema());

    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k11".getBytes()));
    scanner.getValue(RowValue);
    System.out.println("test record 3: row: " + RowValue.toString());
    // test record 3: row: ({(1,true),(2,false),(3,true),(4,false)})
    Iterator<Tuple> it = ((DataBag) RowValue.get(0)).iterator();
    int list = 0;
    while (it.hasNext()) {
      Tuple cur = it.next();
      System.out.println(cur.get(0)); // 3
      list++;
      if (list == 1) {
        Assert.assertEquals(1, cur.get(0));
        Assert.assertEquals(true, cur.get(1));
      }
      if (list == 2) {
        Assert.assertEquals(2, cur.get(0));
        Assert.assertEquals(false, cur.get(1));
      }
      if (list == 3) {
        Assert.assertEquals(3, cur.get(0));
        Assert.assertEquals(true, cur.get(1));
      }
      if (list == 4) {
        Assert.assertEquals(4, cur.get(0));
        Assert.assertEquals(false, cur.get(1));
      }
    }
    scanner.advance();
    scanner.getValue(RowValue);
    System.out.println("row: " + RowValue.toString());
    // row: ({(5,true),(6,false),(7,true),(8,false)})
    Iterator<Tuple> it2 = ((DataBag) RowValue.get(0)).iterator();
    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k12".getBytes()));
    int list2 = 0;
    while (it2.hasNext()) {
      Tuple cur = it2.next();
      System.out.println(cur.get(0));
View Full Code Here

  public void xtestReadNeg1() throws IOException, ParseException {
    String projection = new String("d");
    BasicTable.Reader reader = new BasicTable.Reader(path, conf);
    reader.setProjection(projection);
    List<RangeSplit> splits = reader.rangeSplit(1);
    TableScanner scanner = reader.getScanner(splits.get(0), true);
    BytesWritable key = new BytesWritable();
    Tuple RowValue = TypesUtils.createTuple(scanner.getSchema());

    scanner.getKey(key);
    // Assert.assertEquals(key, new BytesWritable("k11".getBytes()));
    scanner.getValue(RowValue);
    System.out.println("row: " + RowValue.toString());
    System.out.println("row1: " + RowValue.get(0));
    Assert.assertEquals(false, RowValue.isNull());
    Assert.assertEquals(null, RowValue.get(0));
    Assert.assertEquals(1, RowValue.size());
View Full Code Here

  public void xtestRead7() throws IOException, ParseException {
    String projection = new String("c2.r1.f1");
    BasicTable.Reader reader = new BasicTable.Reader(path, conf);
    reader.setProjection(projection);
    List<RangeSplit> splits = reader.rangeSplit(1);
    TableScanner scanner = reader.getScanner(splits.get(0), true);
    scanner = reader.getScanner(splits.get(0), true);

    BytesWritable key = new BytesWritable();
    Tuple RowValue = TypesUtils.createTuple(scanner.getSchema());

    scanner.getKey(key);
    // Assert.assertEquals(key, new BytesWritable("k11".getBytes()));
    scanner.getValue(RowValue);
    System.out.println("row: " + RowValue.toString());
    Iterator<Tuple> it = ((DataBag) RowValue.get(0)).iterator();
    int list = 0;
    while (it.hasNext()) {
      Tuple cur = it.next();
      System.out.println(cur.get(0));
      list++;
      if (list == 1) {
        Assert.assertEquals(1, ((Tuple) cur.get(0)).get(0));
        Assert.assertEquals("record1_string1", ((Tuple) cur.get(0)).get(1));
        try {
          cur.get(1);
          Assert.fail("Should throw index out of bounds exception");
        } catch (Exception e) {
          System.out.println(e);
        }

      }
      if (list == 2) {
        Assert.assertEquals(2, ((Tuple) cur.get(0)).get(0));
        Assert.assertEquals("record2_string1", ((Tuple) cur.get(0)).get(1));
        try {
          cur.get(1);
          Assert.fail("Should throw index out of bounds exception");
        } catch (Exception e) {
          System.out.println(e);
        }
      }
    }
    scanner.advance();
    scanner.getValue(RowValue);
    Iterator<Tuple> it2 = ((DataBag) RowValue.get(0)).iterator();
    int list2 = 0;
    while (it2.hasNext()) {
      Tuple cur = it2.next();
      System.out.println(cur.get(0));
View Full Code Here

  public void xtestRead8() throws IOException, ParseException {
    String projection = new String("c3.c3_1.e");
    BasicTable.Reader reader = new BasicTable.Reader(path, conf);
    reader.setProjection(projection);
    List<RangeSplit> splits = reader.rangeSplit(1);
    TableScanner scanner = null;
    scanner = reader.getScanner(splits.get(0), true);

    scanner = reader.getScanner(splits.get(0), true);

    BytesWritable key = new BytesWritable();
    Tuple RowValue = TypesUtils.createTuple(scanner.getSchema());

    scanner.getKey(key);
    // Assert.assertEquals(key, new BytesWritable("k11".getBytes()));
    scanner.getValue(RowValue);
    System.out.println("row: " + RowValue.toString());
    Iterator<Tuple> it = ((DataBag) RowValue.get(0)).iterator();
    int list = 0;
    while (it.hasNext()) {
      Tuple cur = it.next();
      System.out.println(cur.get(0));
      list++;
      if (list == 1) {
        Assert.assertEquals(1, ((Tuple) cur.get(0)).get(0));
        Assert.assertEquals("record1_string1", ((Tuple) cur.get(0)).get(1));
        try {
          cur.get(1);
          Assert.fail("Should throw index out of bounds exception");
        } catch (Exception e) {
          System.out.println(e);
        }

      }
      if (list == 2) {
        Assert.assertEquals(2, ((Tuple) cur.get(0)).get(0));
        Assert.assertEquals("record2_string1", ((Tuple) cur.get(0)).get(1));
        try {
          cur.get(1);
          Assert.fail("Should throw index out of bounds exception");
        } catch (Exception e) {
          System.out.println(e);
        }
      }
    }
    scanner.advance();
    scanner.getValue(RowValue);
    Iterator<Tuple> it2 = ((DataBag) RowValue.get(0)).iterator();
    int list2 = 0;
    while (it2.hasNext()) {
      Tuple cur = it2.next();
      System.out.println(cur.get(0));
View Full Code Here

  public void testReadSimple1() throws IOException, ParseException {
    String projection = new String("s6,s5,s4,s3,s2,s1");
    BasicTable.Reader reader = new BasicTable.Reader(path, conf);
    reader.setProjection(projection);
    List<RangeSplit> splits = reader.rangeSplit(1);
    TableScanner scanner = reader.getScanner(splits.get(0), true);
    BytesWritable key = new BytesWritable();
    Tuple RowValue = TypesUtils.createTuple(scanner.getSchema());

    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k11".getBytes()));
    scanner.getValue(RowValue);
    Assert.assertEquals(true, RowValue.get(5));
    Assert.assertEquals(1, RowValue.get(4));
    Assert.assertEquals(1001L, RowValue.get(3));
    Assert.assertEquals(1.1f, RowValue.get(2));
    Assert.assertEquals("hello world 1", RowValue.get(1));
    Assert.assertEquals("hello byte 1", RowValue.get(0).toString());
    scanner.advance();
    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k12".getBytes()));
    scanner.getValue(RowValue);
    Assert.assertEquals(false, RowValue.get(5));
    Assert.assertEquals(2, RowValue.get(4));
    Assert.assertEquals(1002L, RowValue.get(3));
    Assert.assertEquals(3.1f, RowValue.get(2));
    Assert.assertEquals("hello world 2", RowValue.get(1));
View Full Code Here

  public void testRead2() throws IOException, ParseException {
    String projection = new String("d");
    BasicTable.Reader reader = new BasicTable.Reader(path, conf);
    reader.setProjection(projection);
    List<RangeSplit> splits = reader.rangeSplit(1);
    TableScanner scanner = reader.getScanner(splits.get(0), true);
    BytesWritable key = new BytesWritable();
    Tuple RowValue = TypesUtils.createTuple(scanner.getSchema());

    scanner.getKey(key);
    // Assert.assertEquals(key, new BytesWritable("k11".getBytes()));
    scanner.getValue(RowValue);
    // RowValue is an emplty record
    Assert.assertEquals(false, RowValue.isNull());
    Assert.assertEquals(null, RowValue.get(0));
    Assert.assertEquals(1, RowValue.size());
    reader.close();
View Full Code Here

    List<RangeSplit> splits = reader.rangeSplit(1);
    reader.close();
    reader = new BasicTable.Reader(path, conf);
    reader.setProjection(projection);
    TableScanner scanner = reader.getScanner(splits.get(0), true);
    BytesWritable key = new BytesWritable();
    Tuple value = TypesUtils.createTuple(scanner.getSchema());

    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k11".getBytes()));
    scanner.getValue(value);

    Assert.assertEquals(1001L, value.get(0));
    Assert.assertEquals(true, value.get(1));

    scanner.advance();
    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k12".getBytes()));
    scanner.getValue(value);
    Assert.assertEquals(1002L, value.get(0));
    Assert.assertEquals(false, value.get(1));

    reader.close();
  }
View Full Code Here

    String projection = new String("a,b,c,d,e,f,r1,m1");
   
    BasicTable.Reader reader = new BasicTable.Reader(pathTable1, conf);
    reader.setProjection(projection);
    List<RangeSplit> splits = reader.rangeSplit(1);
    TableScanner scanner = reader.getScanner(splits.get(0), true);
    Tuple RowValue = TypesUtils.createTuple(scanner.getSchema());
 
    scanner.getValue(RowValue);
    System.out.println("rowvalue size:"+RowValue.size());
    System.out.println("read a : " + RowValue.get(0).toString());
    System.out.println("read string: " + RowValue.get(1).toString());
 
    scanner.advance();
    scanner.getValue(RowValue);
    System.out.println("read float in 2nd row: "+ RowValue.get(1).toString());
    System.out.println("done insert table");
 
    reader.close();
   
View Full Code Here

    List<RangeSplit> splits = reader.rangeSplit(1);
    reader.close();
    reader = new BasicTable.Reader(path, conf);
    reader.setProjection(projection);
    TableScanner scanner = reader.getScanner(splits.get(0), true);
    BytesWritable key = new BytesWritable();
    Tuple value = TypesUtils.createTuple(scanner.getSchema());

    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k11".getBytes()));
    scanner.getValue(value);

    Tuple recordTuple = (Tuple) value.get(1);
    Assert.assertEquals(1, recordTuple.get(0));
    Assert.assertEquals(1001L, recordTuple.get(1));
    Assert.assertEquals(true, value.get(0));
View Full Code Here

TOP

Related Classes of org.apache.hadoop.zebra.io.TableScanner

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.