Example #1
0
uint32_t TabletReader::CountExactByColumn(column_t column, const std::string &value) const {
  rocksdb::Status status;
  ReadStoreKey key{column, value};
  std::string result;

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

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

  return bitArray.numberOfOnes();
}
Example #2
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);
  });
}