Package org.apache.hadoop.zebra.io

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


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


    List<RangeSplit> splits = reader.rangeSplit(1);
    reader.close();
    reader = new BasicTable.Reader(pathTable, conf);
    reader.setProjection(projection);

    TableScanner scanner = reader.getScanner(splits.get(0), true);
    BytesWritable key = new BytesWritable();
    Tuple value = TypesUtils.createTuple(scanner.getSchema());
    // HashMap<String, Object> mapval;
    while (!scanner.atEnd()) {
      scanner.getKey(key);
      // Assert.assertEquals(key, new BytesWritable("key0".getBytes()));
      scanner.getValue(value);
      System.out.println("key = " + key + " value = " + value);

      // mapval = (HashMap<String, Object>) value.get(0);
      // Assert.assertEquals("x", mapval.get("a"));
      // Assert.assertEquals(null, mapval.get("b"));
      // Assert.assertEquals(null, mapval.get("c"));
      scanner.advance();
    }
    reader.close();
  }
View Full Code Here

    List<RangeSplit> splits = reader.rangeSplit(1);
    reader.close();
    reader = new BasicTable.Reader(pathTable, conf);
    reader.setProjection(projection);

    TableScanner scanner = reader.getScanner(splits.get(0), true);
    BytesWritable key = new BytesWritable();
    Tuple value = TypesUtils.createTuple(scanner.getSchema());
    // HashMap<String, Object> mapval;
    while (!scanner.atEnd()) {
      scanner.getKey(key);
      // Assert.assertEquals(key, new BytesWritable("key0".getBytes()));
      scanner.getValue(value);
      System.out.println("key = " + key + " value = " + value);

      // mapval = (HashMap<String, Object>) value.get(0);
      // Assert.assertEquals("x", mapval.get("a"));
      // Assert.assertEquals(null, mapval.get("b"));
      // Assert.assertEquals(null, mapval.get("c"));
      scanner.advance();
    }
    reader.close();
  }
View Full Code Here

    // test without beginKey/endKey
    ColumnGroup.Reader reader = new ColumnGroup.Reader(path, conf);
    List<CGRangeSplit> listRanges = reader.rangeSplit(2);
    // TableScanner scanner = reader.getScanner(null, null, false);
    TableScanner scanner = reader.getScanner(listRanges.get(0), false);
    BytesWritable key = new BytesWritable();
    scanner.getKey(key);
    Assert
        .assertTrue(key.compareTo(new BytesWritable("key11".getBytes())) == 0);
    TypesUtils.resetTuple(row);
    scanner.getValue(row);
    Assert.assertEquals("val1", row.get(0));
    Map<String, String> mapFld2 = (Map<String, String>) row.get(1);
    Assert.assertEquals("boy", mapFld2.get("john"));
    scanner.close();
    scanner = null;

    // test with beginKey
    BytesWritable key22 = new BytesWritable("key22".getBytes());
    // TableScanner scanner2 = reader.getScanner(key22, null, true); // for
    // sorted
    TableScanner scanner2 = reader.getScanner(listRanges.get(1), true);
    BytesWritable key2 = new BytesWritable();
    scanner2.advance();// not for sorted
    scanner2.getKey(key2);
    Assert.assertEquals(key2, key22);
    TypesUtils.resetTuple(row);
    scanner2.getValue(row);
    Assert.assertEquals("val2", row.get(0));

    // test advance
    scanner2.advance();
    BytesWritable key4 = new BytesWritable();
    scanner2.getKey(key4);
    Assert
        .assertTrue(key4.compareTo(new BytesWritable("key23".getBytes())) == 0);
    TypesUtils.resetTuple(row);
    scanner2.getValue(row);
    Assert.assertEquals("val2", row.get(0));

    Map<String, String> mapFld5 = (Map<String, String>) row.get(1);
    Assert.assertEquals("girl", mapFld5.get("jane"));
View Full Code Here

  }

  private static void readInSequence(int count) throws IOException,
      ExecException, ParseException {
    ColumnGroup.Reader reader = new ColumnGroup.Reader(path, conf);
    TableScanner scanner = reader.getScanner(null, true);

    Tuple row = TypesUtils.createTuple(reader.getSchema());
    BytesWritable key = new BytesWritable();
    for (int partIdx = 0; partIdx < count; ++partIdx) {
      for (int keyIdx = 0; keyIdx < partIdx + 1; keyIdx++) {
        scanner.getKey(key);
        String keyString = String
            .format("key%02d%02d", partIdx + 1, keyIdx + 1);
        Assert.assertTrue(new String(key.get()) + " != " + keyString, key
            .equals(new BytesWritable(keyString.getBytes())));
        scanner.advance();
      }
    }

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

  }

  private static void readOnePart(int count) throws IOException, ExecException,
    ParseException {
    ColumnGroup.Reader reader = new ColumnGroup.Reader(path, conf);
    TableScanner scanner = reader.getScanner(reader.rangeSplit(5)
        .get(count - 1), true);

    Tuple row = TypesUtils.createTuple(reader.getSchema());
    BytesWritable key = new BytesWritable();
    for (int nx = 0; nx < count; ++nx) {
      scanner.getKey(key);
      String keyString = String.format("key%02d%02d", count, nx + 1);
      Assert.assertTrue("Not equal to " + keyString, key
          .equals(new BytesWritable(keyString.getBytes())));
      TypesUtils.resetTuple(row);
      scanner.getValue(row);

      String simpVal = String.format("smpcol%02d%02d", count, nx + 1);
      Assert.assertEquals(simpVal, row.get(0));

      String mapKey = String.format("mapcolkey%02d%02d", count, nx + 1);
      String mapVal = String.format("mapcolvalue%02d%02d", count, nx + 1);
      Map<String, String> mapFld2 = (Map<String, String>) row.get(1);
      Assert.assertEquals(mapVal, mapFld2.get(mapKey));

      String val3 = String.format("col3_%02d%02d", count, nx + 1);
      Assert.assertEquals(val3, row.get(2));

      if (nx < count - 1) {
        scanner.advance();
      }
    }
    scanner.close();
    scanner = null;
    reader.close();
  }
View Full Code Here

  private static void readProjection(int count) throws IOException,
      ExecException, ParseException {
    ColumnGroup.Reader reader = new ColumnGroup.Reader(path, conf);
    reader.setProjection("col2, col3, foo, col1");
    TableScanner scanner = reader.getScanner(null, true);

    Tuple row = TypesUtils.createTuple(reader.getSchema());
    BytesWritable key = new BytesWritable();
    scanner.getKey(key);

    String keyString = String.format("key%02d%02d", 1, 1);
    Assert.assertTrue("Not equal to " + keyString, key
        .equals(new BytesWritable(keyString.getBytes())));
    TypesUtils.resetTuple(row);
    scanner.getValue(row);

    // physical 3, logical 2
    String val3 = String.format("col3_%02d%02d", 1, 1);
    Assert.assertEquals(val3, row.get(1));

    // physical 2, logical 1
    String mapKey = String.format("mapcolkey%02d%02d", 1, 1);
    String mapVal = String.format("mapcolvalue%02d%02d", 1, 1);
    Map<String, String> mapFld2 = (Map<String, String>) row.get(0);
    Assert.assertEquals(mapVal, mapFld2.get(mapKey));

    // physical NONE, logical 3
    Assert.assertNull(row.get(2));

    String simpVal = String.format("smpcol%02d%02d", 1, 1);
    Assert.assertEquals(simpVal, row.get(3));

    // move to next row
    scanner.advance();
    scanner.getValue(row);

    simpVal = String.format("smpcol%02d%02d", 2, 1);
    Assert.assertEquals(simpVal, row.get(3));

    scanner.close();
    scanner = null;
    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("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);
    System.out.println("read1 : " + RowValue.toString());
    Assert.assertEquals("{a=A}", 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("{a=A2}", RowValue.get(0).toString());

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