imay commented on a change in pull request #1515: Add storage rowwise iterator
URL: https://github.com/apache/incubator-doris/pull/1515#discussion_r305650455
 
 

 ##########
 File path: be/src/olap/generic_iterators.cpp
 ##########
 @@ -0,0 +1,346 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "olap/iterators.h"
+
+#include <queue>
+
+#include "olap/row_block2.h"
+#include "util/arena.h"
+
+namespace doris {
+
+// This iterator will generate ordered data. For example for schema
+// (int, int) this iterator will generator data like
+// (0, 1), (1, 2), (2, 4), (3, 4)...
+//
+// Usage:
+//      SchemaV2 schema;
+//      AutoIncrementIterator iter(schema, 1000);
+//      StorageReadOptions opts;
+//      RETURN_IF_ERROR(iter.init(opts));
+//      RowBlockV2 block;
+//      do {
+//          st = iter.next_batch(&block);
+//      } while (st.ok());
+class AutoIncrementIterator : public RowwiseIterator {
+public:
+    // Will generate num_rows rows in total
+    AutoIncrementIterator(const SchemaV2& schema, size_t num_rows)
+        : _schema(schema), _num_rows(num_rows), _rows_returned(0) {
+    }
+    ~AutoIncrementIterator() override { }
+
+    // NOTE: Currently, this function will ignore StorageReadOptions
+    Status init(const StorageReadOptions& opts) override;
+    Status next_batch(RowBlockV2* block) override;
+
+    const SchemaV2& schema() const override { return _schema; }
+private:
+    SchemaV2 _schema;
+    size_t _num_rows;
+    size_t _rows_returned;
+};
+
+Status AutoIncrementIterator::init(const StorageReadOptions& opts) {
+    return Status::OK();
+}
+
+Status AutoIncrementIterator::next_batch(RowBlockV2* block) {
+    int row_idx = 0;
+    while (row_idx < block->capacity() && _rows_returned < _num_rows) {
+        RowBlockRow row = block->row(row_idx);
+
+        for (int i = 0; i < _schema.column_schemas().size(); ++i) {
+            row.set_is_null(i, false);
+            auto& col_schema = _schema.column_schemas()[i];
+            switch (col_schema.type()) {
 
 Review comment:
   The comment's case is (0, 1), (1, 2)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to