22 #ifndef Hypertable_Lib_ScanSpec_h
23 #define Hypertable_Lib_ScanSpec_h
34 #include <boost/noncopyable.hpp>
60 : columns(CstrAlloc(arena)),
61 row_intervals(RowIntervalAlloc(arena)),
62 cell_intervals(CellIntervalAlloc(arena)),
63 column_predicates(ColumnPredicateAlloc(arena)),
66 ScanSpec(
const uint8_t **bufp,
size_t *remainp) { decode(bufp, remainp); }
71 const string render_hql(
const string &table)
const;
76 cell_limit_per_family = 0;
81 row_intervals.clear();
82 cell_intervals.clear();
83 column_predicates.clear();
86 rebuild_indices.clear();
88 return_deletes =
false;
91 scan_and_filter_rows =
false;
93 and_column_predicates =
false;
124 if (do_not_cache || rebuild_indices)
126 else if (row_intervals.size() == 1) {
127 HT_ASSERT(row_intervals[0].start && row_intervals[0].end);
128 if (!strcmp(row_intervals[0].start, row_intervals[0].end))
131 else if (cell_intervals.size() == 1) {
132 HT_ASSERT(cell_intervals[0].start_row && cell_intervals[0].end_row);
133 if (!strcmp(cell_intervals[0].start_row, cell_intervals[0].end_row))
140 if (!row_intervals.empty())
141 return row_intervals[0].start;
142 else if (!cell_intervals.empty())
143 return cell_intervals[0].start_row;
149 columns.push_back(arena.
dup(str));
163 static void parse_column(
const char *column_str,
string &family,
164 const char **qualifier,
size_t *qualifier_len,
165 bool *has_qualifier,
bool *is_regexp,
169 if (cell_intervals.size())
175 row_intervals.push_back(ri);
181 row_regexp = arena.
dup(regexp);
185 if (value_regexp != 0)
187 value_regexp = arena.
dup(regexp);
191 const string &start,
bool start_inclusive,
192 const string &end,
bool end_inclusive) {
193 if (cell_intervals.size())
201 row_intervals.push_back(ri);
205 if (row_intervals.size())
212 cell_intervals.push_back(ci);
216 const string &start_row,
const string &start_column,
217 bool start_inclusive,
const string &end_row,
218 const string &end_column,
bool end_inclusive) {
219 if (row_intervals.size())
229 cell_intervals.push_back(ci);
233 const char *column_qualifier, uint32_t operation,
234 const char *value, uint32_t value_len = 0) {
239 if (column_predicates.size() == 32)
249 cp.
value_len = value_len ? value_len : strlen(value);
252 column_predicates.push_back(cp);
256 time_interval.first = start;
257 time_interval.second = end;
261 time_interval.first = start;
265 time_interval.second = end;
268 int32_t row_limit {};
269 int32_t cell_limit {};
270 int32_t cell_limit_per_family {};
271 int32_t row_offset {};
272 int32_t cell_offset {};
273 uint32_t max_versions {};
279 const char *row_regexp {};
280 const char *value_regexp {};
281 bool return_deletes {};
283 bool scan_and_filter_rows {};
284 bool do_not_cache {};
285 bool and_column_predicates {};
292 uint8_t encoding_version()
const override;
297 size_t encoded_length_internal()
const override;
301 void encode_internal(uint8_t **bufp)
const override;
309 void decode_internal(uint8_t version,
const uint8_t **bufp,
310 size_t *remainp)
override;
324 m_arena(page_size), m_scan_spec(m_arena) { }
330 m_arena(page_size), m_scan_spec(m_arena, ss) {}
333 m_scan_spec =
ScanSpec(m_arena, ss);
364 if (n && m_scan_spec.cell_offset)
366 "combination with cell_offset");
367 m_scan_spec.row_offset = n;
376 if (n && m_scan_spec.row_offset)
378 "combination with row_offset");
379 m_scan_spec.cell_offset = n;
394 void set_row_regexp(
const char* regexp) { m_scan_spec.set_row_regexp(m_arena, regexp); }
401 void set_value_regexp(
const char* regexp) { m_scan_spec.set_value_regexp(m_arena, regexp); }
409 m_scan_spec.add_column(m_arena, str);
427 uint32_t operation,
const char *value,
428 uint32_t value_len = 0) {
429 m_scan_spec.add_column_predicate(m_arena, column_family, column_qualifier,
430 operation, value, value_len);
442 m_scan_spec.add_row(m_arena, str);
456 const string &end,
bool end_inclusive) {
457 m_scan_spec.add_row_interval(m_arena, start, start_inclusive,
467 void add_cell(
const string &row,
const string &column) {
468 m_scan_spec.add_cell(m_arena, row, column);
486 bool start_inclusive,
const string &end_row,
487 const string &end_column,
bool end_inclusive) {
488 m_scan_spec.add_cell_interval(m_arena, start_row, start_column,
489 start_inclusive, end_row, end_column, end_inclusive);
500 m_scan_spec.set_time_interval(start, end);
504 m_scan_spec.time_interval.first = start;
508 m_scan_spec.time_interval.second = end;
515 m_scan_spec.keys_only = val;
522 m_scan_spec.return_deletes = val;
529 m_scan_spec.scan_and_filter_rows = val;
536 m_scan_spec.do_not_cache = val;
542 m_scan_spec.rebuild_indices = parts;
549 m_scan_spec.and_column_predicates = val;
577 #endif // Hypertable_Lib_ScanSpec_h
void set_end_time(int64_t end)
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)
void set_row_offset(int32_t n)
Sets the number of rows to be skipped at the beginning of the query.
PageArenaAllocator< const char * > CstrAlloc
void clear()
Clears the state.
void reserve_rows(size_t s)
ColumnPredicates column_predicates
const char * column_family
void add_cell(CharArena &arena, const string &row, const string &column)
const char * cache_key() const
Po::typed_value< String > * str(String *v=0)
pair< int64_t, int64_t > time_interval
const char * value_regexp
void add_column(CharArena &arena, const string &str)
void add_row(const string &str)
Adds a row to be returned in the scan.
PageArena memory allocator for STL classes.
The PageArenaAllocator is a STL allocator based on PageArena.
ScanSpecBuilder(size_t page_size=8192)
Constructor.
void set_start_time(int64_t start)
vector< ColumnPredicate, ColumnPredicateAlloc > ColumnPredicates
void set_start_time(int64_t start)
void set_value_regexp(const char *regexp)
Sets the regexp to filter cell values by.
Represents a set of table parts (sub-tables).
static const int64_t TIMESTAMP_MIN
Represents a row interval.
void set_row_regexp(CharArena &arena, const char *regexp)
vector< RowInterval, RowIntervalAlloc > RowIntervals
Scan predicate and control specification.
vector< CellInterval, CellIntervalAlloc > CellIntervals
void set_cell_limit(int32_t n)
Sets the maximum number of cells to return.
void set_end_time(int64_t end)
CharT * dup(const CharT *s)
Duplicate a null terminated string; memory is allocated from the pool.
int32_t cell_limit_per_family
void set_row_regexp(const char *regexp)
Sets the regexp to filter rows by.
void set_time_interval(int64_t start, int64_t end)
void set_keys_only(bool val)
Return only keys (no values)
void base_copy(ScanSpec &other) const
Initialize another ScanSpec object with this copy sans the intervals.
bool and_column_predicates
ostream & operator<<(ostream &os, const CellInterval &ci)
TableParts rebuild_indices
void reserve_column_predicates(size_t s)
void add_cell(const string &row, const string &column)
Adds a cell to be returned in the scan.
The PageArena allocator is simple and fast, avoiding individual mallocs/frees.
void set_return_deletes(bool val)
Internal use only.
Helper class for building a ScanSpec.
void set_cell_limit_per_family(int32_t n)
Sets the maximum number of cells to return per column family.
void set_do_not_cache(bool val)
Don't cache.
Represents a column predicate (e.g.
vector< const char *, CstrAlloc > CstrColumns
PageArenaAllocator< RowInterval > RowIntervalAlloc
Declarations for Serializable.
void add_row_interval(CharArena &arena, const string &start, bool start_inclusive, const string &end, bool end_inclusive)
void set_time_interval(int64_t start, int64_t end)
Sets the time interval of the scan.
PageArenaAllocator< CellInterval > CellIntervalAlloc
static const int64_t TIMESTAMP_MAX
void add_column(const string &str)
Adds a column family to be returned by the scan.
void add_row_interval(const string &start, bool start_inclusive, const string &end, bool end_inclusive)
Adds a row interval to be returned in the scan.
void set_rebuild_indices(TableParts parts)
Rebuild indices.
Mixin class that provides a standard serialization interface.
ScanSpec(CharArena &arena)
const char * start_column
#define HT_THROWF(_code_, _fmt_,...)
ScanSpec(const uint8_t **bufp, size_t *remainp)
RowIntervals row_intervals
void set_value_regexp(CharArena &arena, const char *regexp)
const char * column_qualifier
bool scan_and_filter_rows
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)
void set_and_column_predicates(bool val)
AND together the column predicates.
Represents a cell interval.
void add_cell_interval(const string &start_row, const string &start_column, bool start_inclusive, const string &end_row, const string &end_column, bool end_inclusive)
Adds a cell interval to be returned in the scan.
uint32_t column_qualifier_len
void add_column_predicate(const string &column_family, const char *column_qualifier, uint32_t operation, const char *value, uint32_t value_len=0)
Adds a column predicate to the scan.
void reserve_cells(size_t s)
CellIntervals cell_intervals
ScanSpecBuilder & operator=(const ScanSpec &ss)
PageArenaAllocator< ColumnPredicate > ColumnPredicateAlloc
void set_row_limit(int32_t n)
Sets the maximum number of rows to return in the scan.
void set_max_versions(uint32_t n)
Sets the maximum number of revisions of each cell to return in the scan.
void reserve_columns(size_t s)
ScanSpecBuilder(const ScanSpec &ss, size_t page_size=8192)
Copy constructor from a ScanSpec.
#define HT_THROW(_code_, _msg_)
static const char * END_ROW_MARKER
void set_scan_and_filter_rows(bool val)
Scan and filter rows.
void set_cell_offset(int32_t n)
Sets the number of cells to be skipped at the beginning of the query.
void add_row(CharArena &arena, const string &str)
Declarations for TableParts.