Example #1
0
void TabletReader::QueryWhere(const Query_Predicate &predicate, offsetType limit, std::function<void(const Record &)> callback) const {
  BitArray bit_array = WhereClause(predicate);

  Record record;
  rocksdb::Status status;
  rocksdb::Slice new_key;
  std::string buffer;

  bit_array.iterateSetBits(limit, [&] (uint64_t pos) {
    new_key = ReadStoreKey::MaterializedRowKey(pos).ToSlice();
    status = db_->Get(
        env_->getReadStoreReadOptions(),
        new_key,
        &buffer
    );
    if (status.IsNotFound()) {
      return;
    }
    if (!status.ok()) {
      throw TabletLevelDbException{status};
    }
    record.ParseFromString(buffer);
    callback(record);
  });
}
Example #2
0
void TabletReader::OrderBy(column_t column, std::function<void(const Record &)> callback) const {
  std::string buffer;
  Record record;
  GetBitArrays(column, ReadStoreKey::EmptyColumnKey(column), ReadStoreKey::EmptyColumnKey(column + 1), [this, &record, &buffer, &callback] (BitArray bit_array) {
    bit_array.iterateSetBits(std::numeric_limits<offsetType>::max(), [&] (uint64_t pos) {

      rocksdb::Status status = db_->Get(
          env_->getReadStoreReadOptions(),
          ReadStoreKey::MaterializedRowKey(pos).ToSlice(),
          &buffer
      );

      if (status.IsNotFound()) {
        return;
      }
      if (!status.ok()) {
        throw TabletLevelDbException(status);
      }
      record.ParseFromString(buffer);
      callback(record);
    });
  });
}
Example #3
0
void TabletReader::QueryExactByColumn(column_t column, const std::string &value, std::function<void(const Record &)> callable) const {
  rocksdb::Status status;
  ReadStoreKey key{column, value};
  std::string result;

  status = db_->Get(env_->getReadStoreReadOptions(), key.ToSlice(), &result);
  if (status.IsNotFound()) {
    return;
  } else if (!status.ok()) {
    throw TabletLevelDbException{status};
  }

  BitArray bitArray;
  bitArray.readStream(result.data(), result.size());

  result.clear();
  Record currentRecord;

  bitArray.iterateSetBits(static_cast<offsetType>(-1), [&] (uint64_t pos) {
    rocksdb::Slice newKey = ReadStoreKey::MaterializedRowKey(pos).ToSlice();
    status = db_->Get(
        env_->getReadStoreReadOptions(),
        newKey,
        &result
    );
    if (status.IsNotFound()) {
      return;
    }
    if (!status.ok()) {
      throw TabletLevelDbException{status};
    }

    currentRecord.ParseFromString(result);
    callable(currentRecord);
  });
}