Package org.apache.hadoop.zebra.io

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


    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);
    BytesWritable key = new BytesWritable();
    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);
    BytesWritable key = new BytesWritable();
    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

    // test without beginKey/endKey
    ColumnGroup.Reader reader = new ColumnGroup.Reader(path, conf);
    reader.setProjection("f1");

    Tuple row = TypesUtils.createTuple(reader.getSchema());
    TableScanner scanner = reader.getScanner(null, false);
    BytesWritable key = new BytesWritable();

    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k1".getBytes()));
    scanner.getValue(row);
    Assert.assertEquals(true, row.get(0));
    try {
      row.get(1);
      Assert.fail("Failed to catch 'out of boundary' exceptions.");
    } catch (IndexOutOfBoundsException e) {
      // no op, expecting out of bounds exceptions
    }

    scanner.advance();
    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k2".getBytes()));
    TypesUtils.resetTuple(row);
    scanner.getValue(row);
    Assert.assertEquals(false, row.get(0));

    scanner.close();
    reader.close();
  }
View Full Code Here

    System.out.println("testOneRecordColumnProjection");
    ColumnGroup.Reader reader = new ColumnGroup.Reader(path, conf);
    reader.setProjection("r.f12, r.XYZ");

    Tuple row = TypesUtils.createTuple(reader.getSchema());
    TableScanner scanner = reader.getScanner(null, false);
    BytesWritable key = new BytesWritable();

    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k1".getBytes()));
    scanner.getValue(row);
    Assert.assertEquals(1001L, row.get(0));
    Assert.assertNull(row.get(1));
    try {
      row.get(2);
      Assert.fail("Failed to catch 'out of boundary' exceptions.");
    } catch (IndexOutOfBoundsException e) {
      // no op, expecting out of bounds exceptions
    }

    scanner.advance();
    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k2".getBytes()));
    TypesUtils.resetTuple(row);
    scanner.getValue(row);
    Assert.assertEquals(1002L, row.get(0));
    Assert.assertNull(row.get(1));

    scanner.close();
    reader.close();
  }
View Full Code Here

    System.out.println("testOneCollectionColumnProjection");
    ColumnGroup.Reader reader = new ColumnGroup.Reader(path, conf);
    reader.setProjection("c.f13, f1, c.XYZ");

    Tuple row = TypesUtils.createTuple(reader.getSchema());
    TableScanner scanner = reader.getScanner(null, false);
    BytesWritable key = new BytesWritable();

    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k1".getBytes()));
    scanner.getValue(row);
    DataBag bagColl = (DataBag) row.get(0);

    boolean f1 = (Boolean) (row.get(1));
    Assert.assertEquals(true, f1);

    Iterator<Tuple> itorColl = bagColl.iterator();
    Tuple tupColl = itorColl.next();
    Assert.assertEquals(3.1415926, tupColl.get(0));
    try {
      Object obj = tupColl.get(1);
      Assert.fail("Failed to catch 'out of boundary' exceptions.");
    } catch (IndexOutOfBoundsException e) {
      // no op, expecting out of bounds exceptions
    }
    tupColl = itorColl.next();
    Assert.assertEquals(123.456789, tupColl.get(0));
    Assert.assertNull(row.get(2));
    try {
      row.get(3);
      Assert.fail("Failed to catch 'out of boundary' exceptions.");
    } catch (IndexOutOfBoundsException e) {
      // no op, expecting out of bounds exceptions
    }

    scanner.advance();
    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k2".getBytes()));
    TypesUtils.resetTuple(row);
    scanner.getValue(row);

    f1 = (Boolean) row.get(1);
    Assert.assertEquals(false, f1);

    bagColl.clear();
    bagColl = (DataBag) row.get(0);
    itorColl = bagColl.iterator();
    tupColl = itorColl.next();
    Assert.assertEquals(7654.321, tupColl.get(0));
    tupColl = itorColl.next();
    Assert.assertEquals(0.123456789, tupColl.get(0));
    Assert.assertNull(row.get(2));

    scanner.close();
    reader.close();
  }
View Full Code Here

    ColumnGroup.Reader reader = new ColumnGroup.Reader(path, conf);
    // TODO: add map field later
    reader.setProjection("c.f14, f1, r.f11, XYZ");

    Tuple row = TypesUtils.createTuple(reader.getSchema());
    TableScanner scanner = reader.getScanner(null, false);
    BytesWritable key = new BytesWritable();

    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k1".getBytes()));
    scanner.getValue(row);
    DataBag bagColl = (DataBag) row.get(0);
    Iterator<Tuple> itorColl = bagColl.iterator();
    Tuple tupColl = itorColl.next();
    Assert.assertEquals(1.6, tupColl.get(0));
    // make sure only 1 element returned in the collection
    try {
      Object obj = tupColl.get(1);
      Assert.fail("Failed to catch 'out of boundary' exceptions.");
    } catch (IndexOutOfBoundsException e) {
      // no op, expecting out of bounds exceptions
    }
    tupColl = itorColl.next();
    Assert.assertEquals(100, tupColl.get(0));
    try {
      Object obj = tupColl.get(1);
      Assert.fail("Failed to catch 'out of boundary' exceptions.");
    } catch (IndexOutOfBoundsException e) {
      // no op, expecting out of bounds exceptions
    }
    Assert.assertFalse(itorColl.hasNext());
    Assert.assertEquals(true, row.get(1));
    Assert.assertEquals(1, row.get(2));
    Assert.assertNull(row.get(3));
    try {
      Object obj = row.get(4);
      Assert.fail("Failed to catch 'out of boundary' exceptions.");
    } catch (IndexOutOfBoundsException e) {
      // no op, expecting out of bounds exceptions
    }

    scanner.advance();
    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k2".getBytes()));
    TypesUtils.resetTuple(row);
    scanner.getValue(row);
    bagColl.clear();
    bagColl = (DataBag) row.get(0);
    itorColl = bagColl.iterator();
    tupColl = itorColl.next();
    Assert.assertEquals(0.0001, tupColl.get(0));
    tupColl = itorColl.next();
    Assert.assertEquals(0.3333, tupColl.get(0));
    Assert.assertEquals(false, row.get(1));
    Assert.assertEquals(2, row.get(2));
    Assert.assertNull(row.get(3));

    scanner.close();
    reader.close();
  }
View Full Code Here

    // test without beginKey/endKey
    ColumnGroup.Reader reader = new ColumnGroup.Reader(path, conf);
    reader.setProjection("m#{c|b}, f1, m#{a}");

    Tuple row = TypesUtils.createTuple(reader.getSchema());
    TableScanner scanner = reader.getScanner(null, false);
    BytesWritable key = new BytesWritable();

    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k1".getBytes()));
    scanner.getValue(row);
    String mapVal = (String) (((Map<String, Object>) (row.get(0))).get("c"));

    boolean f1 = (Boolean) (row.get(1));
    Assert.assertEquals(true, f1);

    Assert.assertEquals("z", mapVal);
    mapVal = (String) (((Map<String, Object>) (row.get(0))).get("b"));
    Assert.assertEquals("y", mapVal);
    mapVal = (String) (((Map<String, Object>) (row.get(2))).get("a"));
    Assert.assertEquals("x", mapVal);
    try {
      row.get(3);
      Assert.fail("Failed to catch 'out of boundary' exceptions.");
    } catch (IndexOutOfBoundsException e) {
      // no op, expecting out of bounds exceptions
    }

    scanner.advance();
    scanner.getKey(key);
    Assert.assertEquals(key, new BytesWritable("k2".getBytes()));
    TypesUtils.resetTuple(row);
    scanner.getValue(row);

    f1 = (Boolean) row.get(1);
    Assert.assertEquals(false, f1);

    mapVal = (String) (((Map<String, Object>) (row.get(0))).get("c"));
    Assert.assertEquals(null, mapVal);

    scanner.close();
    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

    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

  public void testRead1() throws IOException, ParseException {
    String projection = new String("c");
    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 1: row: " + RowValue.toString());
    // test read 1: row: ({(3.1415926,1.6, ),(123.456789,100,)})
    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(3.1415926, cur.get(0));
        Assert.assertEquals(1.6, cur.get(1));
        System.out
            .println("byte 0: " + ((DataByteArray) cur.get(2)).toString());

      }
      if (list == 2) {
        Assert.assertEquals(123.456789, cur.get(0));
        Assert.assertEquals(100, cur.get(1));
        // Assert.assertEquals(3.1415926, cur.get(2));
      }
    }
    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

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.