Package org.apache.hadoop.zebra.io

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


  public void testRead2() throws IOException, ParseException {
    String projection = new String("c2");
    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 read 2:row: " + RowValue.toString());
    // test read 2:row:
    // ({((1,record1_string1),hello1),((2,record2_string1),hello2)})
    Iterator<Tuple> it = ((DataBag) RowValue.get(0)).iterator();
    int list = 0;
    while (it.hasNext()) {
      Tuple cur = it.next();
      System.out.println(cur.get(0)); // (1,record1_string1)
      list++;
      if (list == 1) {
        Assert.assertEquals(1, ((Tuple) cur.get(0)).get(0));
        Assert.assertEquals("record1_string1", ((Tuple) cur.get(0)).get(1));
        Assert.assertEquals("hello1", cur.get(1));

      }
      if (list == 2) {
        Assert.assertEquals(2, ((Tuple) cur.get(0)).get(0));
        Assert.assertEquals("record2_string1", ((Tuple) cur.get(0)).get(1));
        Assert.assertEquals("hello2", cur.get(1));

      }
    }
    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 testReadRecordOfRecord2() throws IOException, ParseException {
    String projection2 = new String("r1.f1, r2.r3.f3");
    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);
    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));
    Assert.assertEquals(1.3, RowValue.get(1));
    scanner.advance();

    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k12".getBytes()));
    scanner.getValue(RowValue);
    Assert.assertEquals(2, RowValue.get(0));
    Assert.assertEquals(2.3, RowValue.get(1));
    reader.close();
  }
View Full Code Here

  public void testReadRecordOfRecord3() throws IOException, ParseException {
    String projection3 = new String("r1, r2, r1.f2#{x|z}");
    BasicTable.Reader reader = new BasicTable.Reader(path, conf);
    reader.setProjection(projection3);
    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, ((Tuple) RowValue.get(0)).get(0));
    Long expected = 1001L;
    Assert.assertEquals(expected, ((Map<String, Long>) RowValue.get(2))
        .get("x"));
    Assert.assertEquals(null, ((Map<String, Long>) RowValue.get(2)).get("y"));
    Assert.assertEquals(null, ((Map<String, Long>) RowValue.get(2)).get("z"));
    Tuple r2 = (Tuple) RowValue.get(1);
    Tuple r3 = (Tuple) r2.get(0);
    Map<String, Integer> f4 = (Map<String, Integer>) r3.get(1);
    Integer tmp = 1;
    Assert.assertEquals(tmp, f4.get("a"));
    tmp = 2;
    Assert.assertEquals(tmp, f4.get("b"));
    tmp = 3;
    Assert.assertEquals(tmp, f4.get("c"));
    Assert.assertEquals(1.3, ((Tuple) ((Tuple) RowValue.get(1)).get(0)).get(0));

    scanner.advance();

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

  public void testReadRecordOfRecord4() throws IOException, ParseException {
    String projection3 = new String("r2.r3.f4");
    BasicTable.Reader reader = new BasicTable.Reader(path, conf);
    reader.setProjection(projection3);
    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);

    Map<String, Integer> f4 = (Map<String, Integer>) RowValue.get(0);
    Integer tmp = 1;
    Assert.assertEquals(tmp, f4.get("a"));
    tmp = 2;
    Assert.assertEquals(tmp, f4.get("b"));
    tmp = 3;
    Assert.assertEquals(tmp, f4.get("c"));
    Assert.assertEquals(null, f4.get("x"));

    scanner.advance();

    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k12".getBytes()));
    scanner.getValue(RowValue);

    f4 = (Map<String, Integer>) RowValue.get(0);
    tmp = 11;
    Assert.assertEquals(tmp, f4.get("x"));
    tmp = 12;
View Full Code Here

  public void testReadNegative1() throws IOException, ParseException {
    String projection4 = new String("r3");
    BasicTable.Reader reader = new BasicTable.Reader(path, conf);
    reader.setProjection(projection4);
    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(null, RowValue.get(0));
    reader.close();

  }
View Full Code Here

  public void testReadSimpleMap() throws IOException, ParseException {
    String projection = new String("m1#{a}");
    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("{a=A}", RowValue.get(0).toString());

    scanner.advance();
    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k12".getBytes()));
    scanner.getValue(RowValue);
    Assert.assertEquals("{a=A2}", RowValue.get(0).toString());

    reader.close();
  }
View Full Code Here

  public void testReadMapOfMap() throws IOException, ParseException {
    String projection2 = new String("m1#{b}, m2#{x|z}");
    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("B", ((Map) RowValue.get(0)).get("b"));
    Assert.assertEquals(321, ((Map) ((Map) RowValue.get(1)).get("x"))
        .get("m321"));
    Assert.assertEquals(311, ((Map) ((Map) RowValue.get(1)).get("x"))
        .get("m311"));
    Assert.assertEquals(331, ((Map) ((Map) RowValue.get(1)).get("x"))
        .get("m331"));
    Assert.assertEquals(null, ((Map) ((Map) RowValue.get(1)).get("x"))
        .get("m341"));
    Assert.assertEquals(null, ((Map) ((Map) RowValue.get(1)).get("z")));
    Assert.assertEquals(null, ((Map) ((Map) RowValue.get(0)).get("a")));
    Assert.assertEquals(null, ((Map) ((Map) RowValue.get(0)).get("c")));

    System.out.println(RowValue.get(1).toString());

    scanner.advance();

    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k12".getBytes()));
    scanner.getValue(RowValue);
    Assert.assertEquals(null, ((Map) RowValue.get(0)).get("b"));
    Assert.assertEquals(null, ((Map) ((Map) RowValue.get(1)).get("x")));
    Assert.assertEquals(323, ((Map) ((Map) RowValue.get(1)).get("z"))
        .get("m323"));
    Assert.assertEquals(322, ((Map) ((Map) RowValue.get(1)).get("z"))
View Full Code Here

  public void testReadMapOfRecord1() throws IOException, ParseException {
    String projection2 = new String("m1#{b}, m4#{a4|c4}");
    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("B", ((Map) RowValue.get(0)).get("b"));
    System.out.println(RowValue.get(1).toString());

    Assert.assertEquals(11, ((Tuple) ((Map) ((Map) RowValue.get(1)).get("a4"))
        .get("ma4")).get(0));
    Assert.assertEquals("record row 1.1", ((Tuple) ((Map) ((Map) RowValue
        .get(1)).get("a4")).get("ma4")).get(1));
    Assert.assertEquals(12, ((Tuple) ((Map) ((Map) RowValue.get(1)).get("a4"))
        .get("mb4")).get(0));
    Assert.assertEquals("record row 1.2", ((Tuple) ((Map) ((Map) RowValue
        .get(1)).get("a4")).get("mb4")).get(1));
    Assert.assertEquals(13, ((Tuple) ((Map) ((Map) RowValue.get(1)).get("a4"))
        .get("mc4")).get(0));
    Assert.assertEquals("record row 1.3", ((Tuple) ((Map) ((Map) RowValue
        .get(1)).get("a4")).get("mc4")).get(1));

    Assert.assertEquals(13, ((Tuple) ((Map) ((Map) RowValue.get(1)).get("c4"))
        .get("ma43")).get(0));
    Assert.assertEquals("record row 1.3", ((Tuple) ((Map) ((Map) RowValue
        .get(1)).get("c4")).get("ma43")).get(1));

    Assert.assertEquals(null, (((Map) ((Map) RowValue.get(1)).get("c4"))
        .get("mc4")));
    Assert.assertEquals(null, (((Map) ((Map) RowValue.get(1)).get("c4"))
        .get("mb4")));

    scanner.advance();

    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k12".getBytes()));
    scanner.getValue(RowValue);
    System.out.println(RowValue.get(1).toString());
    Assert.assertEquals(21, ((Tuple) ((Map) ((Map) RowValue.get(1)).get("a4"))
        .get("ma4")).get(0));
    Assert.assertEquals("record row 2.1", ((Tuple) ((Map) ((Map) RowValue
        .get(1)).get("a4")).get("ma4")).get(1));
View Full Code Here

  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

    // 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

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.