susumu.yata
null+****@clear*****
Thu Sep 25 12:11:18 JST 2014
susumu.yata 2014-09-25 12:11:18 +0900 (Thu, 25 Sep 2014) New Revision: c68fc30b5e654f38461bde2decce47f54c2c7c16 https://github.com/groonga/grnxx/commit/c68fc30b5e654f38461bde2decce47f54c2c7c16 Message: Update the interface of Cursor. (#72) Modified files: include/grnxx/cursor.hpp lib/grnxx/cursor.cpp lib/grnxx/index.cpp lib/grnxx/pipeline.cpp lib/grnxx/table.cpp test/test_expression.cpp test/test_index.cpp test/test_issue_62.cpp test/test_merger.cpp test/test_sorter.cpp test/test_table.cpp Modified: include/grnxx/cursor.hpp (+23 -12) =================================================================== --- include/grnxx/cursor.hpp 2014-09-24 13:37:47 +0900 (a29837d) +++ include/grnxx/cursor.hpp 2014-09-25 12:11:18 +0900 (5fba651) @@ -5,6 +5,11 @@ namespace grnxx { +struct CursorResult { + bool is_ok; + Int count; +}; + class Cursor { public: virtual ~Cursor() {} @@ -18,26 +23,32 @@ class Cursor { // // Reads at most "max_count" records into "*records". // - // On success, returns the number of records read. - // On failure, returns -1 and stores error information into "*error" if - // "error" != nullptr. - virtual Int read(Error *error, Int max_count, Array<Record> *records); + // On success, returns true and the number of records read. + // On failure, returns false and the number of records read and stores error + // information into "*error" if "error" != nullptr. + virtual CursorResult read(Error *error, + Int max_count, + Array<Record> *records); // Read the next records. // // Reads at most "records.size()" records into "records". // - // On success, returns the number of records read. - // On failure, returns -1 and stores error information into "*error" if - // "error" != nullptr. - virtual Int read(Error *error, ArrayRef<Record> records) = 0; + // On success, returns true and the number of records read. + // On failure, returns false and the number of records read and stores error + // information into "*error" if "error" != nullptr. + virtual CursorResult read(Error *error, + ArrayRef<Record> records) = 0; // Read all the remaining records. // - // On success, returns the number of records read. - // On failure, returns -1 and stores error information into "*error" if - // "error" != nullptr. - virtual Int read_all(Error *error, Array<Record> *records); + // Reads records into "*records". + // + // On success, returns true and the number of records read. + // On failure, returns false and the number of records read and stores error + // information into "*error" if "error" != nullptr. + virtual CursorResult read_all(Error *error, + Array<Record> *records); protected: const Table *table_; Modified: lib/grnxx/cursor.cpp (+30 -32) =================================================================== --- lib/grnxx/cursor.cpp 2014-09-24 13:37:47 +0900 (d991ea8) +++ lib/grnxx/cursor.cpp 2014-09-25 12:11:18 +0900 (d89d5cc) @@ -7,10 +7,12 @@ constexpr Int CURSOR_BLOCK_SIZE = 1024; } // namespace -Int Cursor::read(Error *error, Int max_count, Array<Record> *records) { +CursorResult Cursor::read(Error *error, + Int max_count, + Array<Record> *records) { if (max_count < 0) { GRNXX_ERROR_SET(error, INVALID_ARGUMENT, "Invalid argument"); - return -1; + return { false, 0 }; } else if (max_count == 0) { return read(error, records->ref(0, 0)); } @@ -25,9 +27,9 @@ Int Cursor::read(Error *error, Int max_count, Array<Record> *records) { if (next_size <= records->capacity()) { // There are enough space for requested records. records->resize(nullptr, next_size); - Int count = read(error, records->ref(offset, max_count)); - records->resize(nullptr, offset + ((count != -1) ? count : 0)); - return count; + auto result = read(error, records->ref(offset, max_count)); + records->resize(nullptr, offset + result.count); + return result; } // Read the first block. @@ -36,46 +38,42 @@ Int Cursor::read(Error *error, Int max_count, Array<Record> *records) { block_size = CURSOR_BLOCK_SIZE; } if (!records->resize(error, offset + block_size)) { - return -1; + return { false, 0 }; } - Int count = read(error, records->ref(offset, block_size)); - if (count != block_size) { - records->resize(nullptr, offset + ((count != -1) ? count : 0)); - if (count <= 0) { - return count; - } + auto result = read(error, records->ref(offset, block_size)); + if (result.count != block_size) { + records->resize(nullptr, offset + result.count); + } + if (!result.is_ok || (result.count == 0)) { + return result; } // Read the remaining blocks. - while (count < max_count) { - block_size = max_count - count; + while (result.count < max_count) { + block_size = max_count - result.count; if (block_size > CURSOR_BLOCK_SIZE) { block_size = CURSOR_BLOCK_SIZE; } - Int this_offset = offset + count; + Int this_offset = offset + result.count; if (!records->resize(error, this_offset + block_size)) { - return count; + result.is_ok = false; + return result; } - Int this_count = read(error, records->ref(this_offset, block_size)); - if (this_count != block_size) { - records->resize(nullptr, - this_offset + ((this_count != -1) ? this_count : 0)); - if (this_count <= 0) { - return count; - } + auto this_result = read(error, records->ref(this_offset, block_size)); + if (this_result.count != block_size) { + records->resize(nullptr, this_offset + this_result.count); + } + result.is_ok = this_result.is_ok; + result.count += this_result.count; + if (!this_result.is_ok || (this_result.count == 0)) { + return result; } - count += this_count; } - return count; + return result; } -Int Cursor::read_all(Error *error, Array<Record> *records) { - Int total_count = 0; - Int count; - while ((count = read(error, numeric_limits<Int>::max(), records)) > 0) { - total_count += count; - } - return (count == 0) ? total_count : count; +CursorResult Cursor::read_all(Error *error, Array<Record> *records) { + return read(error, numeric_limits<Int>::max(), records); } } // namespace grnxx Modified: lib/grnxx/index.cpp (+31 -31) =================================================================== --- lib/grnxx/index.cpp 2014-09-24 13:37:47 +0900 (342dfd9) +++ lib/grnxx/index.cpp 2014-09-25 12:11:18 +0900 (2eaa60e) @@ -115,11 +115,11 @@ class EmptyCursor : public Cursor { public: EmptyCursor(const Table *table) : Cursor(table) {} - Int read(Error *error, ArrayRef<Record> records); + CursorResult read(Error *error, ArrayRef<Record> records); }; -Int EmptyCursor::read(Error *, ArrayRef<Record>) { - return 0; +CursorResult EmptyCursor::read(Error *, ArrayRef<Record>) { + return CursorResult{ true, 0 }; } // Create an empty cursor. @@ -152,7 +152,7 @@ class IteratorCursor : public Cursor { limit_left_(limit) {} ~IteratorCursor() {} - Int read(Error *error, ArrayRef<Record> records); + CursorResult read(Error *error, ArrayRef<Record> records); private: Iterator begin_; @@ -163,13 +163,13 @@ class IteratorCursor : public Cursor { }; template <typename T> -Int IteratorCursor<T>::read(Error *, ArrayRef<Record> records) { +CursorResult IteratorCursor<T>::read(Error *, ArrayRef<Record> records) { Int max_count = records.size(); if (max_count > limit_left_) { max_count = limit_left_; } if (max_count <= 0) { - return 0; + return { true, 0 }; } Int count = 0; while ((offset_left_ > 0) && (it_ != end_)) { @@ -182,7 +182,7 @@ Int IteratorCursor<T>::read(Error *, ArrayRef<Record> records) { ++it_; } limit_left_ -= count; - return count; + return { true, count }; } // Helper function to create an iterator cursor. @@ -255,7 +255,7 @@ class MapSetCursor : public Cursor { } ~MapSetCursor() {} - Int read(Error *error, ArrayRef<Record> records); + CursorResult read(Error *error, ArrayRef<Record> records); private: MapIterator map_begin_; @@ -269,13 +269,13 @@ class MapSetCursor : public Cursor { }; template <typename T> -Int MapSetCursor<T>::read(Error *, ArrayRef<Record> records) { +CursorResult MapSetCursor<T>::read(Error *, ArrayRef<Record> records) { Int max_count = records.size(); if (max_count > limit_left_) { max_count = limit_left_; } if (max_count <= 0) { - return 0; + return { true, 0 }; } Int count = 0; while ((count < max_count) && (map_it_ != map_end_)) { @@ -300,7 +300,7 @@ Int MapSetCursor<T>::read(Error *, ArrayRef<Record> records) { ++set_it_; } limit_left_ -= count; - return count; + return { true, count }; } // Helper function to create a map set cursor. @@ -370,7 +370,7 @@ class ArrayCursor : public Cursor { } ~ArrayCursor() {} - Int read(Error *error, ArrayRef<Record> records); + CursorResult read(Error *error, ArrayRef<Record> records); private: Array<Map::iterator> array_; @@ -381,13 +381,13 @@ class ArrayCursor : public Cursor { Int limit_left_; }; -Int ArrayCursor::read(Error *, ArrayRef<Record> records) { +CursorResult ArrayCursor::read(Error *, ArrayRef<Record> records) { Int max_count = records.size(); if (max_count > limit_left_) { max_count = limit_left_; } if (max_count <= 0) { - return 0; + return { true, 0 }; } Int count = 0; while ((count < max_count) && (pos_ < array_.size())) { @@ -412,7 +412,7 @@ Int ArrayCursor::read(Error *, ArrayRef<Record> records) { ++it_; } limit_left_ -= count; - return count; + return { true, count }; } // -- TreeIndex<Bool> -- @@ -437,13 +437,13 @@ unique_ptr<TreeIndex<Bool>> TreeIndex<Bool>::create( auto typed_column = static_cast<ColumnImpl<Bool> *>(column); Array<Record> records; for ( ; ; ) { - Int count = cursor->read(error, 1024, &records); - if (count < 0) { + auto result = cursor->read(error, 1024, &records); + if (!result.is_ok) { return nullptr; - } else if (count == 0) { + } else if (result.count == 0) { break; } - for (Int i = 0; i < count; ++i) { + for (Int i = 0; i < result.count; ++i) { Int row_id = records.get_row_id(i); if (!index->insert(error, row_id, typed_column->get(row_id))) { return nullptr; @@ -595,13 +595,13 @@ unique_ptr<TreeIndex<Int>> TreeIndex<Int>::create( auto typed_column = static_cast<ColumnImpl<Int> *>(column); Array<Record> records; for ( ; ; ) { - Int count = cursor->read(error, 1024, &records); - if (count < 0) { + auto result = cursor->read(error, 1024, &records); + if (!result.is_ok) { return nullptr; - } else if (count == 0) { + } else if (result.count == 0) { break; } - for (Int i = 0; i < count; ++i) { + for (Int i = 0; i < result.count; ++i) { Int row_id = records.get_row_id(i); if (!index->insert(error, row_id, typed_column->get(row_id))) { return nullptr; @@ -753,13 +753,13 @@ unique_ptr<TreeIndex<Float>> TreeIndex<Float>::create( auto typed_column = static_cast<ColumnImpl<Float> *>(column); Array<Record> records; for ( ; ; ) { - Int count = cursor->read(error, 1024, &records); - if (count < 0) { + auto result = cursor->read(error, 1024, &records); + if (!result.is_ok) { return nullptr; - } else if (count == 0) { + } else if (result.count == 0) { break; } - for (Int i = 0; i < count; ++i) { + for (Int i = 0; i < result.count; ++i) { Int row_id = records.get_row_id(i); if (!index->insert(error, row_id, typed_column->get(row_id))) { return nullptr; @@ -922,13 +922,13 @@ unique_ptr<TreeIndex<Text>> TreeIndex<Text>::create( auto typed_column = static_cast<ColumnImpl<Text> *>(column); Array<Record> records; for ( ; ; ) { - Int count = cursor->read(error, 1024, &records); - if (count < 0) { + auto result = cursor->read(error, 1024, &records); + if (!result.is_ok) { return nullptr; - } else if (count == 0) { + } else if (result.count == 0) { break; } - for (Int i = 0; i < count; ++i) { + for (Int i = 0; i < result.count; ++i) { Int row_id = records.get_row_id(i); if (!index->insert(error, row_id, typed_column->get(row_id))) { return nullptr; Modified: lib/grnxx/pipeline.cpp (+10 -2) =================================================================== --- lib/grnxx/pipeline.cpp 2014-09-24 13:37:47 +0900 (67ca13c) +++ lib/grnxx/pipeline.cpp 2014-09-25 12:11:18 +0900 (1ddea6e) @@ -50,11 +50,19 @@ class CursorNode : public Node { Int CursorNode::read_next(Error *error, Array<Record> *records) { // TODO: The following block size (1024) should be optimized. - return cursor_->read(error, 1024, records); + auto result = cursor_->read(error, 1024, records); + if (!result.is_ok) { + return -1; + } + return result.count; } Int CursorNode::read_all(Error *error, Array<Record> *records) { - return cursor_->read_all(error, records); + auto result = cursor_->read_all(error, records); + if (!result.is_ok) { + return -1; + } + return result.count; } // --- FilterNode --- Modified: lib/grnxx/table.cpp (+12 -12) =================================================================== --- lib/grnxx/table.cpp 2014-09-24 13:37:47 +0900 (bc9ed21) +++ lib/grnxx/table.cpp 2014-09-25 12:11:18 +0900 (b433d80) @@ -16,7 +16,7 @@ class TableCursor : public Cursor { ~TableCursor() {} - Int read(Error *error, ArrayRef<Record> records); + CursorResult read(Error *error, ArrayRef<Record> records); // -- Internal API -- @@ -30,10 +30,10 @@ class TableCursor : public Cursor { const CursorOptions &options); // Read records in regular order. - Int regular_read(Error *error, ArrayRef<Record> records); + CursorResult regular_read(Error *error, ArrayRef<Record> records); // Read records in reverse order. - Int reverse_read(Error *error, ArrayRef<Record> records); + CursorResult reverse_read(Error *error, ArrayRef<Record> records); private: Int offset_left_; @@ -44,9 +44,9 @@ class TableCursor : public Cursor { explicit TableCursor(const Table *table); }; -Int TableCursor::read(Error *error, ArrayRef<Record> records) { +CursorResult TableCursor::read(Error *error, ArrayRef<Record> records) { if (records.size() <= 0) { - return 0; + return { true, 0 }; } switch (order_type_) { case REGULAR_ORDER: { @@ -57,7 +57,7 @@ Int TableCursor::read(Error *error, ArrayRef<Record> records) { } default: { GRNXX_ERROR_SET(error, BROKEN, "Broken cursor"); - return -1; + return { false, 0 }; } } } @@ -98,7 +98,7 @@ TableCursor::TableCursor(const Table *table) order_type_(), next_row_id_() {} -Int TableCursor::regular_read(Error *, ArrayRef<Record> records) { +CursorResult TableCursor::regular_read(Error *, ArrayRef<Record> records) { Int count = 0; bool has_false_bit = table_->num_rows() != (table_->max_row_id() - MIN_ROW_ID + 1); @@ -109,7 +109,7 @@ Int TableCursor::regular_read(Error *, ArrayRef<Record> records) { if (offset_left_ >= num_remaining_records) { next_row_id_ += num_remaining_records; offset_left_ -= num_remaining_records; - return 0; + return { true, 0 }; } num_remaining_records -= offset_left_; next_row_id_ += offset_left_; @@ -149,10 +149,10 @@ Int TableCursor::regular_read(Error *, ArrayRef<Record> records) { } } } - return count; + return { true, count }; } -Int TableCursor::reverse_read(Error *, ArrayRef<Record> records) { +CursorResult TableCursor::reverse_read(Error *, ArrayRef<Record> records) { Int count = 0; bool has_false_bit = table_->num_rows() != (table_->max_row_id() - MIN_ROW_ID + 1); @@ -163,7 +163,7 @@ Int TableCursor::reverse_read(Error *, ArrayRef<Record> records) { if (offset_left_ >= num_remaining_records) { next_row_id_ -= num_remaining_records; offset_left_ -= num_remaining_records; - return 0; + return { true, 0 }; } num_remaining_records -= offset_left_; next_row_id_ -= offset_left_; @@ -203,7 +203,7 @@ Int TableCursor::reverse_read(Error *, ArrayRef<Record> records) { } } } - return count; + return { true, count }; } // -- Table -- Modified: test/test_expression.cpp (+276 -102) =================================================================== --- test/test_expression.cpp 2014-09-24 13:37:47 +0900 (a7dbed1) +++ test/test_expression.cpp 2014-09-25 12:11:18 +0900 (720d972) @@ -407,7 +407,9 @@ void test_constant() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> bool_results; assert(expression->evaluate(&error, records, &bool_results)); @@ -441,7 +443,9 @@ void test_constant() { cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> int_results; assert(expression->evaluate(&error, records, &int_results)); @@ -578,7 +582,9 @@ void test_row_id() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> id_results; assert(expression->evaluate(&error, records, &id_results)); @@ -603,7 +609,9 @@ void test_score() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Float> score_results; assert(expression->evaluate(&error, records, &score_results)); @@ -634,7 +642,9 @@ void test_column() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> bool_results; assert(expression->evaluate(&error, records, &bool_results)); @@ -662,7 +672,9 @@ void test_column() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> int_results; assert(expression->evaluate(&error, records, &int_results)); @@ -713,7 +725,9 @@ void test_column() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Text> text_results; assert(expression->evaluate(&error, records, &text_results)); @@ -731,7 +745,9 @@ void test_column() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::BoolVector> bool_vector_results; assert(expression->evaluate(&error, records, &bool_vector_results)); @@ -749,7 +765,9 @@ void test_column() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::IntVector> int_vector_results; assert(expression->evaluate(&error, records, &int_vector_results)); @@ -767,7 +785,9 @@ void test_column() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::FloatVector> float_vector_results; assert(expression->evaluate(&error, records, &float_vector_results)); @@ -785,7 +805,9 @@ void test_column() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::GeoPointVector> geo_point_vector_results; assert(expression->evaluate(&error, records, &geo_point_vector_results)); @@ -803,7 +825,9 @@ void test_column() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::TextVector> text_vector_results; assert(expression->evaluate(&error, records, &text_vector_results)); @@ -821,7 +845,9 @@ void test_column() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> ref_results; assert(expression->evaluate(&error, records, &ref_results)); @@ -839,7 +865,9 @@ void test_column() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::IntVector> ref_vector_results; assert(expression->evaluate(&error, records, &ref_vector_results)); @@ -866,7 +894,9 @@ void test_logical_not() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> bool_results; assert(expression->evaluate(&error, records, &bool_results)); @@ -903,7 +933,9 @@ void test_bitwise_not() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> bool_results; assert(expression->evaluate(&error, records, &bool_results)); @@ -932,7 +964,9 @@ void test_bitwise_not() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> int_results; assert(expression->evaluate(&error, records, &int_results)); @@ -959,7 +993,9 @@ void test_positive() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> int_results; assert(expression->evaluate(&error, records, &int_results)); @@ -978,7 +1014,9 @@ void test_positive() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Float> float_results; assert(expression->evaluate(&error, records, &float_results)); @@ -1012,7 +1050,9 @@ void test_negative() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> int_results; assert(expression->evaluate(&error, records, &int_results)); @@ -1031,7 +1071,9 @@ void test_negative() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Float> float_results; assert(expression->evaluate(&error, records, &float_results)); @@ -1065,7 +1107,9 @@ void test_to_int() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> int_results; assert(expression->evaluate(&error, records, &int_results)); @@ -1093,7 +1137,9 @@ void test_to_float() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Float> float_results; assert(expression->evaluate(&error, records, &float_results)); @@ -1130,7 +1176,9 @@ void test_logical_and() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> bool_results; assert(expression->evaluate(&error, records, &bool_results)); @@ -1169,7 +1217,9 @@ void test_logical_or() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> bool_results; assert(expression->evaluate(&error, records, &bool_results)); @@ -1208,7 +1258,9 @@ void test_equal() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> results; assert(expression->evaluate(&error, records, &results)); @@ -1239,7 +1291,9 @@ void test_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1270,7 +1324,9 @@ void test_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1301,7 +1357,9 @@ void test_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1332,7 +1390,9 @@ void test_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1363,7 +1423,9 @@ void test_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1394,7 +1456,9 @@ void test_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1425,7 +1489,9 @@ void test_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1456,7 +1522,9 @@ void test_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1487,7 +1555,9 @@ void test_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1526,7 +1596,9 @@ void test_not_equal() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> results; assert(expression->evaluate(&error, records, &results)); @@ -1557,7 +1629,9 @@ void test_not_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1588,7 +1662,9 @@ void test_not_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1619,7 +1695,9 @@ void test_not_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1650,7 +1728,9 @@ void test_not_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1681,7 +1761,9 @@ void test_not_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1712,7 +1794,9 @@ void test_not_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1743,7 +1827,9 @@ void test_not_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1774,7 +1860,9 @@ void test_not_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1805,7 +1893,9 @@ void test_not_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1844,7 +1934,9 @@ void test_less() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> results; assert(expression->evaluate(&error, records, &results)); @@ -1875,7 +1967,9 @@ void test_less() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1906,7 +2000,9 @@ void test_less() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -1945,7 +2041,9 @@ void test_less_equal() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> results; assert(expression->evaluate(&error, records, &results)); @@ -1976,7 +2074,9 @@ void test_less_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -2007,7 +2107,9 @@ void test_less_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -2038,7 +2140,9 @@ void test_less_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -2077,7 +2181,9 @@ void test_greater() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> results; assert(expression->evaluate(&error, records, &results)); @@ -2108,7 +2214,9 @@ void test_greater() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -2139,7 +2247,9 @@ void test_greater() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -2178,7 +2288,9 @@ void test_greater_equal() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> results; assert(expression->evaluate(&error, records, &results)); @@ -2209,7 +2321,9 @@ void test_greater_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -2240,7 +2354,9 @@ void test_greater_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -2271,7 +2387,9 @@ void test_greater_equal() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); results.clear(); assert(expression->evaluate(&error, records, &results)); @@ -2310,7 +2428,9 @@ void test_bitwise_and() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> bool_results; assert(expression->evaluate(&error, records, &bool_results)); @@ -2341,7 +2461,9 @@ void test_bitwise_and() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> int_results; assert(expression->evaluate(&error, records, &int_results)); @@ -2370,7 +2492,9 @@ void test_bitwise_or() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> bool_results; assert(expression->evaluate(&error, records, &bool_results)); @@ -2401,7 +2525,9 @@ void test_bitwise_or() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> int_results; assert(expression->evaluate(&error, records, &int_results)); @@ -2430,7 +2556,9 @@ void test_bitwise_xor() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> bool_results; assert(expression->evaluate(&error, records, &bool_results)); @@ -2461,7 +2589,9 @@ void test_bitwise_xor() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> int_results; assert(expression->evaluate(&error, records, &int_results)); @@ -2490,7 +2620,9 @@ void test_plus() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> int_results; assert(expression->evaluate(&error, records, &int_results)); @@ -2511,7 +2643,9 @@ void test_plus() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Float> float_results; assert(expression->evaluate(&error, records, &float_results)); @@ -2548,7 +2682,9 @@ void test_minus() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> int_results; assert(expression->evaluate(&error, records, &int_results)); @@ -2569,7 +2705,9 @@ void test_minus() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Float> float_results; assert(expression->evaluate(&error, records, &float_results)); @@ -2606,7 +2744,9 @@ void test_multiplication() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> int_results; assert(expression->evaluate(&error, records, &int_results)); @@ -2627,7 +2767,9 @@ void test_multiplication() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Float> float_results; assert(expression->evaluate(&error, records, &float_results)); @@ -2665,7 +2807,9 @@ void test_division() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> int_results; assert(!expression->evaluate(&error, records, &int_results)); @@ -2682,7 +2826,9 @@ void test_division() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); int_results.clear(); assert(expression->evaluate(&error, records, &int_results)); @@ -2703,7 +2849,9 @@ void test_division() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Float> float_results; assert(expression->evaluate(&error, records, &float_results)); @@ -2741,7 +2889,9 @@ void test_modulus() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> int_results; assert(!expression->evaluate(&error, records, &int_results)); @@ -2758,7 +2908,9 @@ void test_modulus() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); int_results.clear(); assert(expression->evaluate(&error, records, &int_results)); @@ -2787,7 +2939,9 @@ void test_subscript() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> bool_results; assert(expression->evaluate(&error, records, &bool_results)); @@ -2827,7 +2981,9 @@ void test_subscript() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> int_results; assert(expression->evaluate(&error, records, &int_results)); @@ -2853,7 +3009,9 @@ void test_subscript() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Float> float_results; assert(expression->evaluate(&error, records, &float_results)); @@ -2892,7 +3050,9 @@ void test_subscript() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::GeoPoint> geo_point_results; assert(expression->evaluate(&error, records, &geo_point_results)); @@ -2918,7 +3078,9 @@ void test_subscript() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Text> text_results; assert(expression->evaluate(&error, records, &text_results)); @@ -2953,7 +3115,9 @@ void test_subexpression() { grnxx::Array<grnxx::Record> records; auto cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Bool> bool_results; assert(expression->evaluate(&error, records, &bool_results)); @@ -2988,7 +3152,9 @@ void test_subexpression() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Float> float_results; assert(expression->evaluate(&error, records, &float_results)); @@ -3022,7 +3188,9 @@ void test_subexpression() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Text> text_results; assert(expression->evaluate(&error, records, &text_results)); @@ -3049,7 +3217,9 @@ void test_subexpression() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::Int> int_results; assert(expression->evaluate(&error, records, &int_results)); @@ -3073,7 +3243,9 @@ void test_subexpression() { records.clear(); cursor = test.table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); grnxx::Array<grnxx::IntVector> int_vector_results; assert(expression->evaluate(&error, records, &int_vector_results)); @@ -3113,10 +3285,10 @@ void test_sequential_filter() { grnxx::Array<grnxx::Record> records; grnxx::Int offset = 0; for ( ; ; ) { - grnxx::Int num_new_records = cursor->read(&error, 1024, &records); - assert(num_new_records != -1); - assert((offset + num_new_records) == records.size()); - if (num_new_records == 0) { + auto result = cursor->read(&error, 1024, &records); + assert(result.is_ok); + assert((offset + result.count) == records.size()); + if (result.count == 0) { break; } assert(expression->filter(&error, &records, offset)); @@ -3155,14 +3327,14 @@ void test_sequential_adjust() { grnxx::Array<grnxx::Record> records; grnxx::Int offset = 0; for ( ; ; ) { - grnxx::Int num_new_records = cursor->read(&error, 1024, &records); - assert(num_new_records != -1); - assert((offset + num_new_records) == records.size()); - if (num_new_records == 0) { + auto result = cursor->read(&error, 1024, &records); + assert(result.is_ok); + assert((offset + result.count) == records.size()); + if (result.count == 0) { break; } assert(expression->adjust(&error, &records, offset)); - offset += num_new_records; + offset += result.count; } assert(records.size() == test.table->num_rows()); @@ -3198,16 +3370,16 @@ void test_sequential_evaluate() { grnxx::Array<grnxx::Int> results; grnxx::Int offset = 0; for ( ; ; ) { - grnxx::Int num_new_records = cursor->read(&error, 1024, &records); - assert(num_new_records != -1); - assert((offset + num_new_records) == records.size()); - if (num_new_records == 0) { + auto result = cursor->read(&error, 1024, &records); + assert(result.is_ok); + assert((offset + result.count) == records.size()); + if (result.count == 0) { break; } - assert(results.resize(&error, offset + num_new_records)); + assert(results.resize(&error, offset + result.count)); assert(expression->evaluate(&error, records.ref(offset), results.ref(offset))); - offset += num_new_records; + offset += result.count; } assert(records.size() == test.table->num_rows()); @@ -3239,7 +3411,9 @@ void test_partial_filter() { auto cursor = test.table->create_cursor(&error); assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); // Extract a part of true records. constexpr grnxx::Int OFFSET = 12345; Modified: test/test_index.cpp (+40 -17) =================================================================== --- test/test_index.cpp 2014-09-24 13:37:47 +0900 (c584b00) +++ test/test_index.cpp 2014-09-25 12:11:18 +0900 (3049942) @@ -98,7 +98,9 @@ void test_set_and_index() { assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) == NUM_ROWS); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == NUM_ROWS); for (grnxx::Int i = 1; i < NUM_ROWS; ++i) { assert(values[records.get_row_id(i - 1)] <= values[records.get_row_id(i)]); } @@ -147,7 +149,9 @@ void test_index_and_set() { assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) == NUM_ROWS); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == NUM_ROWS); for (grnxx::Int i = 1; i < NUM_ROWS; ++i) { assert(values[records.get_row_id(i - 1)] <= values[records.get_row_id(i)]); } @@ -202,7 +206,9 @@ void test_remove() { assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) == (NUM_ROWS / 2)); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == NUM_ROWS / 2); for (grnxx::Int i = 1; i < (NUM_ROWS / 2); ++i) { assert(values[records.get_row_id(i - 1)] <= values[records.get_row_id(i)]); } @@ -255,7 +261,8 @@ void test_bool_exact_match() { assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) != -1); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); for (grnxx::Int i = 1; i < records.size(); ++i) { assert(values[records.get_row_id(i)] == value); } @@ -314,7 +321,8 @@ void test_int_exact_match() { assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) != -1); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); for (grnxx::Int i = 1; i < records.size(); ++i) { assert(values[records.get_row_id(i)] == value); } @@ -375,7 +383,8 @@ void test_float_exact_match() { assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) != -1); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); for (grnxx::Int i = 1; i < records.size(); ++i) { assert(values[records.get_row_id(i)] == value); } @@ -440,7 +449,8 @@ void test_text_exact_match() { assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) != -1); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); for (grnxx::Int i = 1; i < records.size(); ++i) { assert(values[records.get_row_id(i)] == value); } @@ -501,7 +511,8 @@ void test_int_range() { assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) != -1); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); for (grnxx::Int i = 1; i < records.size(); ++i) { assert(values[records.get_row_id(i - 1)] <= values[records.get_row_id(i)]); } @@ -561,7 +572,8 @@ void test_float_range() { assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) != -1); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); for (grnxx::Int i = 1; i < records.size(); ++i) { assert(values[records.get_row_id(i - 1)] <= values[records.get_row_id(i)]); } @@ -625,7 +637,8 @@ void test_text_range() { assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) != -1); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); for (grnxx::Int i = 1; i < records.size(); ++i) { assert(values[records.get_row_id(i - 1)] <= values[records.get_row_id(i)]); } @@ -716,7 +729,8 @@ void test_text_find_starts_with() { assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) != -1); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); for (grnxx::Int i = 1; i < records.size(); ++i) { assert(inclusive_starts_with(values[records.get_row_id(i)], value)); } @@ -741,7 +755,8 @@ void test_text_find_starts_with() { assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) != -1); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); for (grnxx::Int i = 1; i < records.size(); ++i) { assert(exclusive_starts_with(values[records.get_row_id(i)], value)); } @@ -805,7 +820,8 @@ void test_text_find_prefixes() { assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) != -1); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); for (grnxx::Int i = 1; i < records.size(); ++i) { assert(inclusive_starts_with(value, values[records.get_row_id(i)])); } @@ -868,7 +884,8 @@ void test_reverse() { assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) != -1); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); for (grnxx::Int i = 1; i < records.size(); ++i) { assert(values[records.get_row_id(i - 1)] >= values[records.get_row_id(i)]); } @@ -925,7 +942,9 @@ void test_offset_and_limit() { assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) == NUM_ROWS); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == NUM_ROWS); constexpr grnxx::Int OFFSET = 1000; @@ -935,7 +954,9 @@ void test_offset_and_limit() { cursor = index->find_in_range(&error, grnxx::IndexRange(), options); grnxx::Array<grnxx::Record> records_with_offset; - assert(cursor->read_all(&error, &records_with_offset) == (NUM_ROWS - OFFSET)); + result = cursor->read_all(&error, &records_with_offset); + assert(result.is_ok); + assert(result.count == (NUM_ROWS - OFFSET)); for (grnxx::Int i = 0; i < records_with_offset.size(); ++i) { assert(records.get_row_id(OFFSET + i) == @@ -949,7 +970,9 @@ void test_offset_and_limit() { cursor = index->find_in_range(&error, grnxx::IndexRange(), options); grnxx::Array<grnxx::Record> records_with_offset_and_limit; - assert(cursor->read_all(&error, &records_with_offset_and_limit) == LIMIT); + result = cursor->read_all(&error, &records_with_offset_and_limit); + assert(result.is_ok); + assert(result.count == LIMIT); for (grnxx::Int i = 0; i < records_with_offset_and_limit.size(); ++i) { assert(records.get_row_id(OFFSET + i) == Modified: test/test_issue_62.cpp (+3 -1) =================================================================== --- test/test_issue_62.cpp 2014-09-24 13:37:47 +0900 (8bc0c75) +++ test/test_issue_62.cpp 2014-09-25 12:11:18 +0900 (9f2f117) @@ -76,7 +76,9 @@ void test_scored_subexpression() { grnxx::Array<grnxx::Record> records; auto cursor = table->create_cursor(&error); assert(cursor); - assert(cursor->read_all(&error, &records) == table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == table->num_rows()); // Set scores (Float). auto builder = grnxx::ExpressionBuilder::create(&error, table); Modified: test/test_merger.cpp (+3 -1) =================================================================== --- test/test_merger.cpp 2014-09-24 13:37:47 +0900 (7ef50d2) +++ test/test_merger.cpp 2014-09-25 12:11:18 +0900 (71a1709) @@ -107,7 +107,9 @@ grnxx::Array<grnxx::Record> create_input(const char *bool_name, // Read all the records. grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); // Create an object to create expressions. auto expression_builder = Modified: test/test_sorter.cpp (+15 -5) =================================================================== --- test/test_sorter.cpp 2014-09-24 13:37:47 +0900 (bc3ec5b) +++ test/test_sorter.cpp 2014-09-25 12:11:18 +0900 (19bdecb) @@ -115,7 +115,9 @@ void test_bool() { auto cursor = test.table->create_cursor(&error); assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); // Create an object for building expressions. auto expression_builder = @@ -193,7 +195,9 @@ void test_int() { auto cursor = test.table->create_cursor(&error); assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); // Create an object for building expressions. auto expression_builder = @@ -289,7 +293,9 @@ void test_float() { auto cursor = test.table->create_cursor(&error); assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); // Create an object for building expressions. auto expression_builder = @@ -367,7 +373,9 @@ void test_text() { auto cursor = test.table->create_cursor(&error); assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); // Create an object for building expressions. auto expression_builder = @@ -445,7 +453,9 @@ void test_composite() { auto cursor = test.table->create_cursor(&error); assert(cursor); grnxx::Array<grnxx::Record> records; - assert(cursor->read_all(&error, &records) == test.table->num_rows()); + auto result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == test.table->num_rows()); // Create an object for building expressions. auto expression_builder = Modified: test/test_table.cpp (+18 -6) =================================================================== --- test/test_table.cpp 2014-09-24 13:37:47 +0900 (c696a49) +++ test/test_table.cpp 2014-09-25 12:11:18 +0900 (322225a) @@ -245,13 +245,19 @@ void test_cursor() { // Read records from the cursor. grnxx::Array<grnxx::Record> records; - assert(cursor->read(&error, 0, &records) == 0); + auto result = cursor->read(&error, 0, &records); + assert(result.is_ok); + assert(result.count == 0); - assert(cursor->read(&error, 1, &records) == 1); + result = cursor->read(&error, 1, &records); + assert(result.is_ok); + assert(result.count == 1); assert(records.size() == 1); assert(records.get(0).row_id == 1); - assert(cursor->read(&error, 2, &records) == 1); + result = cursor->read(&error, 2, &records); + assert(result.is_ok); + assert(result.count == 1); assert(records.size() == 2); assert(records.get(0).row_id == 1); assert(records.get(1).row_id == 3); @@ -264,7 +270,9 @@ void test_cursor() { cursor = table->create_cursor(&error, cursor_options); assert(cursor); - assert(cursor->read_all(&error, &records) == 2); + result = cursor->read_all(&error, &records); + assert(result.is_ok); + assert(result.count == 2); assert(records.size() == 2); assert(records.get(0).row_id == 3); assert(records.get(1).row_id == 1); @@ -274,11 +282,15 @@ void test_cursor() { cursor = table->create_cursor(&error, cursor_options); assert(cursor); - assert(cursor->read(&error, 1, &records) == 1); + result = cursor->read(&error, 1, &records); + assert(result.is_ok); + assert(result.count == 1); assert(records.size() == 1); assert(records.get(0).row_id == 3); - assert(cursor->read(&error, 2, &records) == 1); + result = cursor->read(&error, 2, &records); + assert(result.is_ok); + assert(result.count == 1); assert(records.size() == 2); assert(records.get(0).row_id == 3); assert(records.get(1).row_id == 1);