Beispiel #1
0
 public void reduce(KeyWritable key, Iterable<BytesWritable> values, Context ctx)
     throws IOException, InterruptedException {
   for (BytesWritable value : values) {
     long startTime = System.currentTimeMillis();
     ctx.write(key, value);
     long elapsedTime = System.currentTimeMillis() - startTime;
     ctx.getCounter(Counters.ELAPSED_TIME_MS).increment(elapsedTime);
     ctx.getCounter(Counters.NUM_CELLS).increment(1);
   }
 }
  public void createTable(String tableName, String[] columnFamily) {
    try {
      /* drop existing tables */
      boolean if_exists = true;
      client.table_drop(namespace, tableName, if_exists);

      Schema schema = new Schema();

      Map<String, ColumnFamilySpec> column_families = new HashMap<String, ColumnFamilySpec>();

      ColumnFamilySpec cf;
      for (String column : columnFamily) {
        cf = new ColumnFamilySpec();
        cf.setName(column);
        column_families.put(column, cf);
      }

      schema.setColumn_families(column_families);
      client.table_create(namespace, tableName, schema);

    } catch (ClientException e) {
      System.out.println(e.message);
      System.exit(1);
    } catch (TException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Beispiel #3
0
  public static void main(String[] args) throws Exception {

    LoadTest test = new LoadTest();
    System.exit(test.run(args));
  }
Beispiel #4
0
  /**
   * Updates the ScanSpec by setting the row interval to match this split
   *
   * @param scan_spec The base ScanSpec to start with
   * @return a new scan_spec object with a row interval matching this split
   */
  public ScanSpec createScanSpec(ScanSpec base_spec) {
    ScanSpec scan_spec = new ScanSpec(base_spec);

    RowInterval interval = new RowInterval();

    scan_spec.unsetRow_intervals();

    try {

      if (m_startrow != null && m_startrow.limit() > 0) {
        interval.setStart_row_binary(m_startrow);
        interval.setStart_inclusive(false);
        interval.setStart_inclusiveIsSet(true);
      }

      if (m_endrow != null && m_endrow.limit() > 0) {
        interval.setEnd_row_binary(m_endrow);
        interval.setEnd_inclusive(true);
        interval.setEnd_inclusiveIsSet(true);
      }

      ByteBuffer riStartRow;
      ByteBuffer riEndRow;
      Charset charset = Charset.forName("UTF-8");
      CharsetEncoder encoder = charset.newEncoder();

      if (base_spec.isSetRow_intervals()) {
        for (RowInterval ri : base_spec.getRow_intervals()) {
          riStartRow =
              (ri != null && ri.isSetStart_row())
                  ? encoder.encode(CharBuffer.wrap(ri.getStart_row()))
                  : null;
          riEndRow =
              (ri != null && ri.isSetEnd_row())
                  ? encoder.encode(CharBuffer.wrap(ri.getEnd_row()))
                  : null;
          if (riStartRow != null) {
            if (m_startrow == null
                || m_startrow.limit() == 0
                || riStartRow.compareTo(m_startrow) > 0) {
              interval.setStart_row_binary(riStartRow);
              interval.setStart_inclusive(ri.isStart_inclusive());
              interval.setStart_inclusiveIsSet(true);
            }
          }
          if (riEndRow != null) {
            if (m_endrow == null || m_endrow.limit() == 0 || riEndRow.compareTo(m_endrow) < 0) {
              interval.setEnd_row_binary(riEndRow);
              interval.setEnd_inclusive(ri.isEnd_inclusive());
              interval.setEnd_inclusiveIsSet(true);
            }
          }
          // Only allowing a single row interval
          break;
        }
      }

    } catch (CharacterCodingException e) {
      e.printStackTrace();
      System.exit(-1);
    }

    if (interval.isSetStart_row_binary() || interval.isSetEnd_row_binary()) {
      scan_spec.addToRow_intervals(interval);
      scan_spec.setRow_intervalsIsSet(true);
    }

    return scan_spec;
  }