HangyuanLiu commented on a change in pull request #2554: Support load orc 
format in Apache Doris
URL: https://github.com/apache/incubator-doris/pull/2554#discussion_r361941354
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,298 @@
+// 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 "exec/orc_scanner.h"
+
+#include "runtime/descriptors.h"
+#include "runtime/exec_env.h"
+#include "runtime/mem_tracker.h"
+#include "runtime/raw_value.h"
+#include "runtime/runtime_state.h"
+#include "runtime/tuple.h"
+#include "exprs/expr.h"
+#include "exec/local_file_reader.h"
+#include "exec/broker_reader.h"
+
+namespace doris {
+
+ORCFileStream::~ORCFileStream() {
+    if (_file) {
+        _file->close();
+        delete _file;
+        _file = nullptr;
+    }
+}
+
+uint64_t ORCFileStream::getLength() const {
+    return _file->size();
+}
+
+uint64_t ORCFileStream::getNaturalReadSize() const {
+    return 128 * 1024;
+}
+
+void ORCFileStream::read(void *buf, uint64_t length, uint64_t offset) {
+    if (!buf) {
+        throw orc::ParseError("Buffer is null");
+    }
+
+    int64_t bytes_read = 0;
+    int64_t reads = 0;
+    while (bytes_read < length) {
+        Status result = _file->readat(offset, length - bytes_read, &reads, 
buf);
+        if (!result.ok()) {
+            throw orc::ParseError("Bad read of " + _filename);
+        }
+        if (reads == 0) {
+            break;
+        }
+        bytes_read += reads;// total read bytes
+        offset += reads;
+        buf = (char *) buf + reads;
+    }
+    if (length != bytes_read) {
+        throw orc::ParseError("Short read of " + _filename
+                              + ". expected :" + std::to_string(length) + ", 
actual : " + std::to_string(bytes_read));
+    }
+}
+
+const std::string& ORCFileStream::getName() const {
+    return _filename;
+}
+
+ORCScanner::ORCScanner(RuntimeState *state,
+        RuntimeProfile *profile,
+        const TBrokerScanRangeParams &params,
+        const std::vector<TBrokerRangeDesc> &ranges,
+        const std::vector<TNetworkAddress> &broker_addresses,
+        ScannerCounter *counter) : BaseScanner(state, profile, params, 
counter),
+            _ranges(ranges),
+            _broker_addresses(broker_addresses),
+            // _splittable(params.splittable),
+            _next_range(0),
+            _cur_file_eof(true),
+            _scanner_eof(false),
+            _total_groups(0),
+            _current_group(0),
+            _rows_of_group(0),
+            _current_line_of_group(0) {}
+
+ORCScanner::~ORCScanner() {
+    close();
+}
+
+Status ORCScanner::open() {
+    return BaseScanner::open();
+}
+
+Status ORCScanner::get_next(Tuple *tuple, MemPool *tuple_pool, bool *eof) {
+    try {
+        SCOPED_TIMER(_read_timer);
+        // Get one line
+        while (!_scanner_eof) {
+            if (_cur_file_eof) {
+                RETURN_IF_ERROR(open_next_reader());
+                if (_scanner_eof) {
+                    *eof = true;
+                    return Status::OK();
+                } else {
+                    _cur_file_eof = false;
+                }
+            }
+            if (_current_line_of_group >= _rows_of_group) { // read next stripe
+                if (_current_group >= _total_groups) {
+                    _cur_file_eof = true;
+                    continue;
+                }
+                _rows_of_group = 
_reader->getStripe(_current_group)->getNumberOfRows();
+                _batch = _row_reader->createRowBatch(_rows_of_group);
+                _row_reader->next(*_batch.get());
+
+                _current_line_of_group = 0;
+                ++_current_group;
+            }
+
+            const std::vector<orc::ColumnVectorBatch *>& batch_vec = 
((orc::StructVectorBatch *) _batch.get())->fields;
+            for (int column_ipos = 0; column_ipos < _num_of_columns_from_file; 
++column_ipos) {
+                auto slot_desc = _src_slot_descs[column_ipos];
+                int position_in_orc = 
_column_name_map_orc_index.find(slot_desc->col_name())->second;
 
 Review comment:
   Done

----------------------------------------------------------------
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