Package co.cask.cdap.api.dataset.table

Examples of co.cask.cdap.api.dataset.table.Row


        // exhausted persisted scanner is the same as buffer row coming first
        order = -1;
      } else {
        order = Bytes.compareTo(currentKey, currentRow.getRow());
      }
      Row result = null;
      if (order > 0) {
        // persisted row comes first or buffer is empty
        result = currentRow;
        currentRow = persistedScanner.next();
      } else if (order < 0) {
View Full Code Here


  public void deleteRange(@Nullable byte[] start, @Nullable byte[] stop, @Nullable byte[][] columns,
                          @Nullable FuzzyRowFilter filter) {
    Scanner scanner = this.scan(start, stop, columns, filter);

    try {
      Row rowValues;
      while ((rowValues = scanner.next()) != null) {
        byte[] row = rowValues.getRow();
        for (byte[] column : rowValues.getColumns().keySet()) {
          InMemoryOrderedTableService.deleteColumns(tableName, row, column);
        }
      }
    } finally {
      scanner.close();
View Full Code Here

  // returns first that matches
  @Nullable
  public <T> T get(Key id, Class<T> classOfT) {
    try {
      Scanner scan = table.scan(id.getKey(), Bytes.stopKeyForPrefix(id.getKey()));
      Row row = scan.next();
      if (row == null || row.isEmpty()) {
        return null;
      }

      byte[] value = row.get(COLUMN);
      if (value == null) {
        return null;
      }

      return deserialize(value, classOfT);
View Full Code Here

    byte[] stopKey = stopId == null ? Bytes.stopKeyForPrefix(startKey) : stopId.getKey();

    try {
      List<T> list = Lists.newArrayList();
      Scanner scan = table.scan(startKey, stopKey);
      Row next;
      while ((limit-- > 0) && (next = scan.next()) != null) {
        byte[] columnValue = next.get(COLUMN);
        if (columnValue == null) {
          continue;
        }
        T value = deserialize(columnValue, classOfT);
        list.add(value);
View Full Code Here

    byte[] prefix = id.getKey();
    byte[] stopKey = Bytes.stopKeyForPrefix(prefix);

    try {
      Scanner scan = table.scan(prefix, stopKey);
      Row next;
      while ((next = scan.next()) != null) {
        String columnValue = next.getString(COLUMN);
        if (columnValue == null) {
          continue;
        }
        table.delete(new Delete(next.getRow()).add(COLUMN));
      }
    } catch (Exception e) {
      throw Throwables.propagate(e);
    }
  }
View Full Code Here

    DBIterator deleteIterator = db.iterator();
    seekToStart(deleteIterator, startRow);
    final int deletesPerRound = 1024; // todo make configurable
    try {
      Row rowValues;
      WriteBatch batch = db.createWriteBatch();
      int deletesInBatch = 0;

      // go through all matching cells and delete them in batches.
      while ((rowValues = scanner.next()) != null) {
        byte[] row = rowValues.getRow();
        for (byte[] column : rowValues.getColumns().keySet()) {
          addToDeleteBatch(batch, deleteIterator, row, column);
          deletesInBatch++;

          // perform the deletes when we have built up a batch.
          if (deletesInBatch >= deletesPerRound) {
View Full Code Here

    byte[] stopKey = createStopKey(prefix);

    try {
      Map<String, T> map = Maps.newHashMap();
      Scanner scan = table.scan(prefix, stopKey);
      Row next;
      while ((next = scan.next()) != null) {
        byte[] columnValue = next.get(COLUMN);
        T value = GSON.fromJson(new String(columnValue, Charsets.UTF_8), classOfT);
        String key = new String(next.getRow(), prefix.length, next.getRow().length - prefix.length, Charsets.UTF_8);
        map.put(key, value);
      }
      return map;
    } catch (Exception e) {
      throw Throwables.propagate(e);
View Full Code Here

  protected final void deleteAll(byte[] prefix) {
    byte[] stopKey = createStopKey(prefix);

    try {
      Scanner scan = table.scan(prefix, stopKey);
      Row next;
      while ((next = scan.next()) != null) {
        table.delete(next.getRow());
      }
    } catch (Exception e) {
      throw Throwables.propagate(e);
    }
  }
View Full Code Here

  protected QueueScanner getScanner(byte[] startRow, byte[] stopRow, int numRows) throws IOException {
    final Scanner scanner = core.scan(startRow, stopRow, null, null, Transaction.ALL_VISIBLE_LATEST);
    return new QueueScanner() {
      @Override
      public ImmutablePair<byte[], Map<byte[], byte[]>> next() throws IOException {
        Row next = scanner.next();
        if (next == null) {
          return null;
        }
        return new ImmutablePair<byte[], Map<byte[], byte[]>>(next.getRow(), next.getColumns());
      }

      @Override
      public void close() throws IOException {
        scanner.close();
View Full Code Here

    return result;
  }

  private synchronized int doEvict(Transaction transaction) throws IOException {
    final byte[] stopRow = QueueEntryRow.getStopRowForTransaction(queueRowPrefix, transaction);
    Row row;
    List<byte[]> rowsToDelete = Lists.newArrayList();
    // the scan must be non-transactional in order to see the state columns (which have latest timestamp)
    Scanner scanner = core.scan(queueRowPrefix, stopRow, null, null, Transaction.ALL_VISIBLE_LATEST);
    try {
      while ((row = scanner.next()) != null) {
        int processed = 0;
        for (Map.Entry<byte[], byte[]> entry : row.getColumns().entrySet()) {
          // is it a state column for a consumer instance?
          if (!QueueEntryRow.isStateColumn(entry.getKey())) {
            continue;
          }
          // is the write pointer of this state committed w.r.t. the current transaction, and is it processed?
          if (QueueEntryRow.isCommittedProcessed(entry.getValue(), transaction)) {
            ++processed;
          }
        }
        if (processed >= numGroups) {
          rowsToDelete.add(row.getRow());
        }
      }
    } finally {
      scanner.close();
    }
View Full Code Here

TOP

Related Classes of co.cask.cdap.api.dataset.table.Row

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.