Search in sources :

Example 1 with ReadOnly

use of io.cdap.cdap.api.annotation.ReadOnly in project cdap by caskdata.

the class IndexedTable method readByIndex.

/**
 * Reads table rows by the given secondary index key.  If no rows are indexed by the given key, then a
 * {@link io.cdap.cdap.api.dataset.table.Scanner} with no results will be returned.
 *
 * @return a Scanner returning rows from the data table, whose stored value for the given column matches the
 * given value.
 * @throws java.lang.IllegalArgumentException if the given column is not configured for indexing.
 */
@ReadOnly
public Scanner readByIndex(byte[] column, byte[] value) {
    assertIndexedColumn(column);
    byte[] rowKeyPrefix = Bytes.concat(keyPrefix, column, KEY_DELIMITER, value, KEY_DELIMITER);
    byte[] stopRow = Bytes.stopKeyForPrefix(rowKeyPrefix);
    Scanner indexScan = index.scan(rowKeyPrefix, stopRow);
    return new IndexScanner(indexScan, column, value);
}
Also used : Scanner(io.cdap.cdap.api.dataset.table.Scanner) RecordScanner(io.cdap.cdap.api.data.batch.RecordScanner) ReadOnly(io.cdap.cdap.api.annotation.ReadOnly)

Example 2 with ReadOnly

use of io.cdap.cdap.api.annotation.ReadOnly in project cdap by caskdata.

the class IndexedTable method scanByIndex.

/**
 * Reads table rows within the given secondary index key range. If no rows are indexed, falling within the given
 * range, then a {@link io.cdap.cdap.api.dataset.table.Scanner} with no results will be returned.
 *
 * @param column the column to use for the index lookup
 * @param startValue the inclusive start of the range for which rows must fall within to be returned in the scan.
 *                   {@code null} means start from first row of the table
 * @param endValue the exclusive end of the range for which rows must fall within to be returned in the scan
 *                 {@code null} means end with the last row of the table
 * @return a Scanner returning rows from the data table, whose stored value for the given column is within the the
 *         given range.
 * @throws java.lang.IllegalArgumentException if the given column is not configured for indexing.
 */
@ReadOnly
public Scanner scanByIndex(byte[] column, @Nullable byte[] startValue, @Nullable byte[] endValue) {
    assertIndexedColumn(column);
    // KEY_DELIMITER is not used at the end of the rowKeys, because they are used for a range scan,
    // instead of a fixed-match lookup
    byte[] startRow = startValue == null ? Bytes.concat(keyPrefix, column, KEY_DELIMITER) : Bytes.concat(keyPrefix, column, KEY_DELIMITER, startValue);
    byte[] stopRow = endValue == null ? Bytes.stopKeyForPrefix(Bytes.concat(keyPrefix, column, KEY_DELIMITER)) : Bytes.concat(keyPrefix, column, KEY_DELIMITER, endValue);
    Scanner indexScan = index.scan(startRow, stopRow);
    return new IndexRangeScanner(indexScan, column, startValue, endValue);
}
Also used : Scanner(io.cdap.cdap.api.dataset.table.Scanner) RecordScanner(io.cdap.cdap.api.data.batch.RecordScanner) ReadOnly(io.cdap.cdap.api.annotation.ReadOnly)

Example 3 with ReadOnly

use of io.cdap.cdap.api.annotation.ReadOnly in project cdap by caskdata.

the class HBaseTable method getInternal.

// columns being null means to get all rows; empty columns means get no rows.
@ReadOnly
private NavigableMap<byte[], byte[]> getInternal(byte[] row, @Nullable byte[][] columns) throws IOException {
    if (columns != null && columns.length == 0) {
        return EMPTY_ROW_MAP;
    }
    Get get = createGet(row, columns);
    Result result = table.get(get);
    // no tx logic needed
    if (tx == null) {
        return result.isEmpty() ? EMPTY_ROW_MAP : result.getFamilyMap(columnFamily);
    }
    return getRowMap(result, columnFamily);
}
Also used : Get(org.apache.hadoop.hbase.client.Get) Result(org.apache.hadoop.hbase.client.Result) ReadOnly(io.cdap.cdap.api.annotation.ReadOnly)

Example 4 with ReadOnly

use of io.cdap.cdap.api.annotation.ReadOnly in project cdap by caskdata.

the class BufferingTable method get.

@ReadOnly
@Override
public Row get(byte[] row, byte[][] columns) {
    ensureTransactionIsStarted();
    reportRead(1);
    try {
        return new Result(row, getRowMap(row, columns));
    } catch (Exception e) {
        LOG.debug("get failed for table: " + getTransactionAwareName() + ", row: " + Bytes.toStringBinary(row), e);
        throw new DataSetException("get failed", e);
    }
}
Also used : DataSetException(io.cdap.cdap.api.dataset.DataSetException) DataSetException(io.cdap.cdap.api.dataset.DataSetException) IOException(java.io.IOException) Result(io.cdap.cdap.api.dataset.table.Result) ReadOnly(io.cdap.cdap.api.annotation.ReadOnly)

Example 5 with ReadOnly

use of io.cdap.cdap.api.annotation.ReadOnly in project cdap by caskdata.

the class LevelDBTable method scanPersisted.

@ReadOnly
@Override
protected Scanner scanPersisted(Scan scan) throws Exception {
    FuzzyRowFilter filter = null;
    if (scan.getFilter() != null) {
        // todo: currently we support only FuzzyRowFilter as an experimental feature
        if (scan.getFilter() instanceof FuzzyRowFilter) {
            filter = (FuzzyRowFilter) scan.getFilter();
        } else {
            throw new DataSetException("Unknown filter type: " + scan.getFilter());
        }
    }
    final Scanner scanner = core.scan(scan.getStartRow(), scan.getStopRow(), filter, null, tx);
    return new Scanner() {

        @Nullable
        @Override
        public Row next() {
            return LevelDBTable.this.next(scanner);
        }

        @Override
        public void close() {
            scanner.close();
        }
    };
}
Also used : Scanner(io.cdap.cdap.api.dataset.table.Scanner) DataSetException(io.cdap.cdap.api.dataset.DataSetException) FuzzyRowFilter(io.cdap.cdap.data2.dataset2.lib.table.FuzzyRowFilter) ReadOnly(io.cdap.cdap.api.annotation.ReadOnly)

Aggregations

ReadOnly (io.cdap.cdap.api.annotation.ReadOnly)13 DataSetException (io.cdap.cdap.api.dataset.DataSetException)7 IOException (java.io.IOException)5 Result (io.cdap.cdap.api.dataset.table.Result)4 Row (io.cdap.cdap.api.dataset.table.Row)4 Scanner (io.cdap.cdap.api.dataset.table.Scanner)3 RecordScanner (io.cdap.cdap.api.data.batch.RecordScanner)2 NavigableMap (java.util.NavigableMap)2 PartitionAlreadyExistsException (io.cdap.cdap.api.dataset.lib.PartitionAlreadyExistsException)1 Get (io.cdap.cdap.api.dataset.table.Get)1 FuzzyRowFilter (io.cdap.cdap.data2.dataset2.lib.table.FuzzyRowFilter)1 ScanBuilder (io.cdap.cdap.data2.util.hbase.ScanBuilder)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)1 Get (org.apache.hadoop.hbase.client.Get)1 Result (org.apache.hadoop.hbase.client.Result)1 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)1 Location (org.apache.twill.filesystem.Location)1