Examples of TableScanner


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

  public void testReadSimpleStitch() throws IOException, ParseException {
    String projection2 = new String("s5, s1");
    BasicTable.Reader reader = new BasicTable.Reader(path, conf);
    reader.setProjection(projection2);
    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("hello world 1", RowValue.get(0));
    Assert.assertEquals(true, RowValue.get(1));

    scanner.advance();

    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k12".getBytes()));
    scanner.getValue(RowValue);
    Assert.assertEquals("hello world 2", RowValue.get(0));
    Assert.assertEquals(false, RowValue.get(1));

    reader.close();
  }
View Full Code Here

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

    // Starting read , simple projection 0, not record of record level. PASS
    String projection0 = new String("r1.f1, r1.f2");
    BasicTable.Reader reader = new BasicTable.Reader(path, conf);
    reader.setProjection(projection0);
    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(1, RowValue.get(0));
    Long expected = 1001L;
    Assert.assertEquals(expected, ((Map<String, Long>) RowValue.get(1))
        .get("x"));
    Assert.assertEquals(null, ((Map<String, Long>) RowValue.get(1)).get("y"));
    Assert.assertEquals(null, ((Map<String, Long>) RowValue.get(1)).get("a"));
    Assert.assertEquals(null, ((Map<String, Long>) RowValue.get(1)).get("z"));

    scanner.advance();
    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k12".getBytes()));
    scanner.getValue(RowValue);
    Assert.assertEquals(2, RowValue.get(0));
    expected = 1002L;
    Assert.assertEquals(expected, ((Map<String, Long>) RowValue.get(1))
        .get("y"));
    Assert.assertEquals(null, ((Map<String, Long>) RowValue.get(1)).get("x"));
View Full Code Here

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

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

  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

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

  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

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

  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

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

  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

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

  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

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

  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

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

    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
TOP
Copyright © 2018 www.massapi.com. 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.