30 #include <boost/algorithm/string.hpp>
56 rebuild_indices.encoded_length();
57 for (
auto c : columns)
59 for (
auto &ri : row_intervals)
60 len += ri.encoded_length();
61 for (
auto &ci : cell_intervals)
62 len += ci.encoded_length();
63 for (
auto &cp : column_predicates)
64 len += cp.encoded_length();
65 return len + 8 + 8 + 5;
113 for (
auto & ri : row_intervals) ri.encode(bufp);
115 for (
auto & ci : cell_intervals) ci.encode(bufp);
117 for (
auto & cp : column_predicates) cp.encode(bufp);
125 rebuild_indices.encode(bufp);
133 HT_TRY(
"decoding scan spec",
146 row_intervals.push_back(ri);
150 cell_intervals.push_back(ci);
154 column_predicates.push_back(cp);
163 rebuild_indices.decode(bufp, remainp));
169 hql.append(
"SELECT ");
175 for (
auto column : columns) {
186 hql.append(
" FROM ");
189 char const *bool_op =
" AND ";
193 for (
auto & ri : row_intervals) {
195 hql.append(
" WHERE ");
200 hql.append(ri.render_hql());
205 hql.append(
" WHERE ");
210 hql.append(
format(
"ROW REGEXP \"%s\"", row_regexp));
215 hql.append(
" WHERE ");
220 hql.append(
format(
"VALUE REGEXP \"%s\"", value_regexp));
225 for (
auto & ci : cell_intervals) {
227 hql.append(
" WHERE ");
232 hql.append(ci.render_hql());
235 if (!and_column_predicates)
239 for (
auto & cp : column_predicates) {
241 hql.append(
" WHERE ");
246 hql.append(cp.render_hql());
254 hql.append(
format(
"%lld", (
Lld)time_interval.first));
257 hql.append(
"TIMESTAMP");
260 hql.append(
format(
"%lld", (
Lld)time_interval.second));
265 hql.append(
format(
" ROW_OFFSET %d", (
int)row_offset));
268 hql.append(
format(
" ROW_LIMIT %d", (
int)row_limit));
271 hql.append(
format(
" CELL_OFFSET %d", (
int)cell_offset));
274 hql.append(
format(
" CELL_LIMIT %d", (
int)cell_limit));
276 if (cell_limit_per_family)
277 hql.append(
format(
" CELL_LIMIT_PER_FAMILY %d", (
int)cell_limit_per_family));
280 hql.append(
format(
" MAX_VERSIONS %d", (
int)max_versions));
283 hql.append(
" RETURN_DELETES");
286 hql.append(
" KEYS_ONLY");
288 if (scan_and_filter_rows)
289 hql.append(
" SCAN_AND_FILTER_ROWS");
292 hql.append(
" DO_NOT_CACHE");
295 hql.append(
format(
" REBUILD_INDICES %s", rebuild_indices.to_string().c_str()));
312 for (
auto column : scan_spec.
columns) {
348 os <<
" row_limit="<< scan_spec.
row_limit;
363 os <<
" return_deletes";
375 os <<
" scan_and_filter_rows";
378 os <<
" do_not_cache";
381 os <<
" and_column_predicates";
393 : row_limit(ss.row_limit), cell_limit(ss.cell_limit),
394 cell_limit_per_family(ss.cell_limit_per_family),
395 row_offset(ss.row_offset), cell_offset(ss.cell_offset),
396 max_versions(ss.max_versions), columns(
CstrAlloc(arena)),
400 time_interval(ss.time_interval.first, ss.time_interval.second),
401 row_regexp(arena.dup(ss.row_regexp)), value_regexp(arena.dup(ss.value_regexp)),
402 return_deletes(ss.return_deletes), keys_only(ss.keys_only),
403 scan_and_filter_rows(ss.scan_and_filter_rows),
404 do_not_cache(ss.do_not_cache), and_column_predicates(ss.and_column_predicates),
405 rebuild_indices(ss.rebuild_indices) {
416 ri.end, ri.end_inclusive);
420 ci.end_row, ci.end_column, ci.end_inclusive);
424 cp.operation, cp.value, cp.value_len);
429 const char **qualifier,
size_t *qualifier_len,
430 bool *has_qualifier,
bool *is_regexp,
bool *is_prefix)
432 const char *raw_qualifier;
433 size_t raw_qualifier_len;
434 const char *colon = strchr(column_str,
':');
441 *has_qualifier =
false;
445 *has_qualifier =
true;
447 family =
String(column_str, (
size_t)(colon-column_str));
449 raw_qualifier = colon+1;
450 raw_qualifier_len = strlen(raw_qualifier);
452 if (raw_qualifier_len == 0)
455 if (raw_qualifier_len > 2 &&
456 raw_qualifier[0] ==
'/' && raw_qualifier[raw_qualifier_len-1] ==
'/') {
458 *qualifier = raw_qualifier+1;
459 *qualifier_len = raw_qualifier_len - 2;
461 else if (*raw_qualifier ==
'*') {
465 if (*raw_qualifier ==
'^') {
468 qualifier, qualifier_len);
472 qualifier, qualifier_len);
void add_column_predicate(CharArena &arena, const string &column_family, const char *column_qualifier, uint32_t operation, const char *value, uint32_t value_len=0)
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
size_t encoded_length_internal() const override
Returns internal serialized length.
std::string String
A String is simply a typedef to std::string.
ColumnPredicates column_predicates
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
pair< int64_t, int64_t > time_interval
const char * value_regexp
void add_column(CharArena &arena, const string &str)
The PageArenaAllocator is a STL allocator based on PageArena.
size_t encoded_length_vstr(size_t len)
Computes the encoded length of vstr (vint64, data, null)
static const int64_t TIMESTAMP_MIN
Represents a row interval.
const string render_hql(const string &table) const
Renders scan spec as an HQL SELECT statement.
Scan predicate and control specification.
uint64_t decode_i64(const uint8_t **bufp, size_t *remainp)
Decode a 64-bit integer in little-endian order.
int encoded_length_vi32(uint32_t val)
Length of a variable length encoded 32-bit integer (up to 5 bytes)
int32_t cell_limit_per_family
bool strip_enclosing_quotes(const char *input, size_t input_len, const char **output, size_t *output_len)
Strips enclosing quotes.
bool decode_bool(const uint8_t **bufp, size_t *remainp)
Decodes a boolean value from the given buffer.
bool and_column_predicates
ostream & operator<<(ostream &os, const CellInterval &ci)
TableParts rebuild_indices
Compatibility Macros for C/C++.
The PageArena allocator is simple and fast, avoiding individual mallocs/frees.
void encode_i64(uint8_t **bufp, uint64_t val)
Encode a 64-bit integer in little-endian order.
Functions to serialize/deserialize primitives to/from a memory buffer.
uint8_t encoding_version() const override
Returns encoding version.
Represents a column predicate (e.g.
virtual void decode(const uint8_t **bufp, size_t *remainp)
Reads serialized representation of object from a buffer.
static void parse_column(const char *column_str, string &family, const char **qualifier, size_t *qualifier_len, bool *has_qualifier, bool *is_regexp, bool *is_prefix)
Parses a column string into column family, qualifier and whether the qualifier is a regexp or not...
void encode_vstr(uint8_t **bufp, const void *buf, size_t len)
Encode a buffer as variable length string (vint64, data, null)
void add_row_interval(CharArena &arena, const string &start, bool start_inclusive, const string &end, bool end_inclusive)
long long int Lld
Shortcut for printf formats.
void encode_vi32(uint8_t **bufp, uint32_t val)
Encode a integer (up to 32-bit) in variable length encoding.
static const int64_t TIMESTAMP_MAX
void encode_bool(uint8_t **bufp, bool bval)
Encodes a boolean into the given buffer.
RowIntervals row_intervals
const std::string to_string() const
Returns human readable string describing table parts.
bool scan_and_filter_rows
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
void add_cell_interval(CharArena &arena, const string &start_row, const string &start_column, bool start_inclusive, const string &end_row, const string &end_column, bool end_inclusive)
Represents a cell interval.
CellIntervals cell_intervals
#define HT_TRY(_s_, _code_)
uint32_t decode_vi32(const uint8_t **bufp, size_t *remainp)
Decode a variable length encoded integer up to 32-bit.
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.