Package org.apache.hadoop.zebra.io

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


  public void testRead2() 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);
    System.out.println("map of map: " + RowValue.toString());
    // map of map: ([b#B],[z#,x#{m311=311, m321=321, m331=331}])
    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): " + RowValue.get(1).toString());
    // rowValue.get)1): {z=null, x={m311=311, m321=321, m331=331}}

    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


    String projection = new String("m5");
    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(false, RowValue.isNull());
    Assert.assertEquals(null, RowValue.get(0));
    Assert.assertEquals(1, RowValue.size());

    scanner.advance();
    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k12".getBytes()));
    scanner.getValue(RowValue);
    Assert.assertEquals(false, RowValue.isNull());
    Assert.assertEquals(null, RowValue.get(0));
    Assert.assertEquals(1, RowValue.size());
    reader.close();
  }
View Full Code Here

  public void testRead4() throws IOException, ParseException {
    String projection = new String("m1#{nonexist}");
    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("read1 : " + RowValue.toString());
    Assert.assertEquals("{}", RowValue.get(0).toString());

    scanner.advance();
    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k12".getBytes()));
    scanner.getValue(RowValue);
    System.out.println(RowValue.get(0).toString());
    Assert.assertEquals("{}", RowValue.get(0).toString());

    reader.close();
  }
View Full Code Here

    // Starting read
    String projection = new String("group");
    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("hello world 1", RowValue.get(0));

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


    reader.close();
View Full Code Here

    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.1, 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.1, RowValue.get(2));
    Assert.assertEquals("hello world 2", RowValue.get(1));
View Full Code Here

    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

    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(2);
    Assert.assertEquals(1, recordTuple.get(0));
    Assert.assertEquals(1001L, recordTuple.get(1));
    Assert.assertEquals(true, value.get(0));
View Full Code Here

    ColumnGroup.Reader reader = new ColumnGroup.Reader(path, conf);
    if (projection != null) {
      reader.setProjection(projection);
    }
    int totalRows = 0;
    TableScanner scanner = reader.getScanner(null, true);
    for (; !scanner.atEnd(); scanner.advance()) {
      ++totalRows;
    }
    scanner.close();
    return totalRows;
  }
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();
    if(!scanner.atEnd()) {
      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

    String projection = new String("a,b,c,d,e,f,r1,m1");
   
    BasicTable.Reader reader = new BasicTable.Reader(pathTable2, 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(7).toString());
    System.out.println("read string: " + RowValue.get(6).toString());
  
    scanner.advance();
    if(!scanner.atEnd()) {
      scanner.getValue(RowValue);
      System.out.println("read float in 2nd row: "+ RowValue.get(6).toString());
      System.out.println("done insert table");
   

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.