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

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


        colsToIndex.add(putEntry.getKey());
      }
    }

    // first read the existing indexed values to find which have changed and need to be updated
    Row existingRow = table.get(dataRow, colsToIndex.toArray(new byte[colsToIndex.size()][]));
    if (existingRow != null) {
      for (Map.Entry<byte[], byte[]> entry : existingRow.getColumns().entrySet()) {
        if (!Arrays.equals(entry.getValue(), putColumns.get(entry.getKey()))) {
          index.delete(createIndexKey(dataRow, entry.getKey(), entry.getValue()), IDX_COL);
        } else {
          // value already indexed
          colsToIndex.remove(entry.getKey());
View Full Code Here


    delete(delete.getRow(), delete.getColumns().toArray(new byte[0][]));
  }

  @Override
  public void delete(byte[] row) {
    Row existingRow = table.get(row);
    if (existingRow == null) {
      // no row to delete
      return;
    }
View Full Code Here

    delete(row, new byte[][]{ column });
  }

  @Override
  public void delete(byte[] row, byte[][] columns) {
    Row existingRow = table.get(row, columns);
    if (existingRow == null) {
      // no row to delete
      return;
    }
View Full Code Here

   */
  @Override
  public Row incrementAndGet(byte[] row, byte[][] columns, long[] amounts) {
    Preconditions.checkArgument(columns.length == amounts.length, "Size of columns and amounts arguments must match");

    Row existingRow = table.get(row, columns);
    byte[][] updatedValues = new byte[columns.length][];
    NavigableMap<byte[], byte[]> result = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);

    for (int i = 0; i < columns.length; i++) {
      long existingValue = 0L;
      if (existingRow != null) {
        byte[] existingBytes = existingRow.get(columns[i]);
        if (existingBytes != null) {
          if (existingBytes.length != Bytes.SIZEOF_LONG) {
            throw new NumberFormatException("Attempted to increment a value that is not convertible to long," +
                                              " row: " + Bytes.toStringBinary(row) +
                                              " column: " + Bytes.toStringBinary(columns[i]));
View Full Code Here

    @Nullable
    @Override
    public Row next() {
      // TODO: retrieve results in batches to minimize RPC overhead (requires multi-get support in table)
      Row dataRow = null;
      // keep going until we hit a non-null, non-empty data row, or we exhaust the index
      while (dataRow == null) {
        Row indexRow = baseScanner.next();
        if (indexRow == null) {
          // end of index
          return null;
        }
        byte[] rowkey = indexRow.get(IDX_COL);
        // verify that datarow matches the expected row key to avoid issues with column name or value
        // containing the delimiter used
        if (rowkey != null && Bytes.equals(indexRow.getRow(), Bytes.add(rowKeyPrefix, rowkey))) {
          dataRow = table.get(rowkey);
        }
      }
      return dataRow;
    }
View Full Code Here

      }
      return endOfData();
    }

    private Iterator<Map.Entry<byte[], byte[]>> createIterator(byte[] row) {
      Row currentRow = table.get(row,
                                 // we only need to set left bound on the first row: others cannot have records
                                 // with the timestamp less than startTime
                                 (rowScanned == 0) ? startColumnName : null,
                                 // we only need to set right bound on the last row: others cannot have records
                                 // with the timestamp greater than startTime
                                 (rowScanned == timeIntervalsCount - 1) ? endColumnName : null,
                                 // read all
                                 -1);

      if (!currentRow.isEmpty()) {
        return currentRow.getColumns().entrySet().iterator();
      }

      return null;
    }
View Full Code Here

    return new AbstractCloseableIterator<KeyValue<byte[], byte[]>>() {
      private boolean closed = false;
      @Override
      protected KeyValue<byte[], byte[]> computeNext() {
        Preconditions.checkState(!closed);
        Row next = scanner.next();
        if (next != null) {
          return new KeyValue<byte[], byte[]>(next.getRow(), next.get(KEY_COLUMN));
        }
        close();
        return null;
      }
View Full Code Here

  public List<T> readAllByIndex(byte[] secondaryKey) {
    ImmutableList.Builder<T> resultList = ImmutableList.builder();
    //Lookup the secondaryKey and get all the keys in primary
    //Each row with secondaryKey as rowKey contains column named as the primary key
    // of every object that can be looked up using the secondaryKey
    Row row = index.get(secondaryKey);

    // if the index has no match, return nothing
    if (!row.isEmpty()) {
      for (byte[] column : row.getColumns().keySet()) {
        T obj = objectStore.read(column);
        resultList.add(obj);
      }
    }
    return resultList.build();
View Full Code Here

    //logic:
    //  - Get existing secondary keys
    //  - Compute diff between existing secondary keys and new secondary keys
    //  - Remove the secondaryKeys that are removed
    //  - Add the new keys that are added
    Row row = index.get(getPrefixedPrimaryKey(key));
    Set<byte[]> existingSecondaryKeys = Sets.newTreeSet(new Bytes.ByteArrayComparator());

    if (!row.isEmpty()) {
      existingSecondaryKeys = row.getColumns().keySet();
    }

    Set<byte[]> newSecondaryKeys = new TreeSet<byte[]>(new Bytes.ByteArrayComparator());
    newSecondaryKeys.addAll(Arrays.asList(secondaryKeys));
View Full Code Here

  private void writeToObjectStore(byte[] key, T object) {
    objectStore.write(key, object);
  }

  public void write(byte[] key, T object) {
    Row row = index.get(getPrefixedPrimaryKey(key));
    if (!row.isEmpty()) {
      Set<byte[]> columnsToDelete = row.getColumns().keySet();
      deleteSecondaryKeys(key, columnsToDelete.toArray(new byte[columnsToDelete.size()][]));
    }
    writeToObjectStore(key, object);
  }
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.