You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2019/12/24 11:39:05 UTC

[GitHub] [incubator-doris] HangyuanLiu opened a new pull request #2554: Support load orc format in Apache Doris

HangyuanLiu opened a new pull request #2554: Support load orc format in Apache Doris
URL: https://github.com/apache/incubator-doris/pull/2554
 
 
   Support load orc format in Apache Doris
   #2491 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361907113
 
 

 ##########
 File path: be/src/exec/orc_scanner.h
 ##########
 @@ -0,0 +1,144 @@
+// 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.
+
+#ifndef ORC_SCANNER_H
+#define ORC_SCANNER_H
+
+#include <memory>
+#include <vector>
+#include <string>
+#include <map>
+#include <sstream>
+#include <orc/OrcFile.hh>
+
+#include "exec/base_scanner.h"
+#include "exec/file_reader.h"
+#include "common/status.h"
+#include "gen_cpp/PlanNodes_types.h"
+#include "gen_cpp/Types_types.h"
+#include "runtime/mem_pool.h"
+#include "runtime/row_batch.h"
+#include "runtime/tuple.h"
+#include "util/slice.h"
+#include "util/runtime_profile.h"
+
+namespace doris {
+
+class FileReader;
+class Tuple;
+class SlotDescriptor;
+class Slice;
+class ParquetReaderWrap;
+class RuntimeState;
+class ExprContext;
+class TupleDescriptor;
+class TupleRow;
+class RowDescriptor;
+class MemTracker;
+class RuntimeProfile;
+class StreamLoadPipe;
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(filename) {
+    }
+
+    ~ORCFileStream();
 
 Review comment:
   ```suggestion
       ~ORCFileStream() override;
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361154627
 
 

 ##########
 File path: be/src/exec/orc_scanner.h
 ##########
 @@ -0,0 +1,178 @@
+// 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.
+
+#ifndef ORC_SCANNER_H
+#define ORC_SCANNER_H
+
+#include <memory>
+#include <vector>
+#include <string>
+#include <map>
+#include <sstream>
+
+#include "exec/base_scanner.h"
+#include "exec/file_reader.h"
+#include "common/status.h"
+#include "gen_cpp/PlanNodes_types.h"
+#include "gen_cpp/Types_types.h"
+#include "runtime/mem_pool.h"
+#include "runtime/row_batch.h"
+#include "runtime/tuple.h"
+#include "util/slice.h"
+#include "util/runtime_profile.h"
+#include "orc/OrcFile.hh"
+
+namespace doris {
+
+class FileReader;
+class Tuple;
+class SlotDescriptor;
+class Slice;
+class ParquetReaderWrap;
+class RuntimeState;
+class ExprContext;
+class TupleDescriptor;
+class TupleRow;
+class RowDescriptor;
+class MemTracker;
+class RuntimeProfile;
+class StreamLoadPipe;
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(filename) {
+    }
+
+    ~ORCFileStream() {
+        if (_file) {
+            _file->close();
+            delete _file;
+            _file = nullptr;
+        }
+    }
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const {
+        return _file->size();
+    }
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const {
+        return 128 * 1024;
+    }
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+     void 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));
+        }
+    }
+
+    /**
+     * Get the name of the stream for error messages.
+     */
+    const std::string &getName() const {
+        return _filename;
+    }
+
+private:
+    FileReader *_file;
+    std::string _filename;
+};
+// Broker scanner convert the data read from broker to doris's tuple.
+class ORCScanner : public BaseScanner {
+public:
+    ORCScanner(RuntimeState* state,
+    RuntimeProfile *profile,
+    const TBrokerScanRangeParams &params,
+    const std::vector<TBrokerRangeDesc> &ranges,
+    const std::vector<TNetworkAddress> &broker_addresses,ScannerCounter* counter);
+
+    ~ORCScanner();
+
+    // Open this scanner, will initialize information need to
+    virtual Status open();
+
+    // Get next tuple
+    virtual Status get_next(Tuple *tuple, MemPool *tuple_pool, bool *eof);
+
+    // Close this scanner
+    virtual void close();
+
+private:
+    // Read next buffer from reader
+    Status open_next_reader();
+
+private:
+    const std::vector<TBrokerRangeDesc> &_ranges;
+    const std::vector<TNetworkAddress> &_broker_addresses;
+
+    // Reader
+    int _next_range;
+    bool _cur_file_eof;
+    bool _scanner_eof;
+
+    // orc file reader object
+    orc::ReaderOptions _options;
+    orc::RowReaderOptions _rowReaderOptions;
+    std::shared_ptr<orc::ColumnVectorBatch> _batch;
+    std::unique_ptr<orc::Reader> _reader;
+    std::unique_ptr<orc::RowReader> _row_reader;
+    std::list<std::string> _includes; // include columns in orc file
+    // The batch after reading from orc data is arranged in the original order,
+    // so we need to record the index in the original order to correspond the column names to the order
+    std::map<std::string, int> _column_name_map_orc_index;
+    int _num_of_columns_from_file;
+
+    int _total_groups; // groups in a orc file
+    int _current_group;
+    int _rows_of_group; // rows in a group.
 
 Review comment:
   is `int` enough?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361154932
 
 

 ##########
 File path: be/src/exec/orc_scanner.h
 ##########
 @@ -0,0 +1,178 @@
+// 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.
+
+#ifndef ORC_SCANNER_H
+#define ORC_SCANNER_H
+
+#include <memory>
+#include <vector>
+#include <string>
+#include <map>
+#include <sstream>
+
+#include "exec/base_scanner.h"
+#include "exec/file_reader.h"
+#include "common/status.h"
+#include "gen_cpp/PlanNodes_types.h"
+#include "gen_cpp/Types_types.h"
+#include "runtime/mem_pool.h"
+#include "runtime/row_batch.h"
+#include "runtime/tuple.h"
+#include "util/slice.h"
+#include "util/runtime_profile.h"
+#include "orc/OrcFile.hh"
+
+namespace doris {
+
+class FileReader;
+class Tuple;
+class SlotDescriptor;
+class Slice;
+class ParquetReaderWrap;
+class RuntimeState;
+class ExprContext;
+class TupleDescriptor;
+class TupleRow;
+class RowDescriptor;
+class MemTracker;
+class RuntimeProfile;
+class StreamLoadPipe;
+
+class ORCFileStream : public orc::InputStream {
 
 Review comment:
   why not define this in cpp file?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361156814
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,261 @@
+// 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/tuple.h"
+#include "exprs/expr.h"
+#include "exec/text_converter.h"
+#include "exec/text_converter.hpp"
+#include "exec/local_file_reader.h"
+#include "exec/broker_reader.h"
+
+namespace doris {
+
+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) {}
+
+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();
+                std::cout << "rows of group "<< _rows_of_group << std::endl;
+                _batch = _row_reader->createRowBatch(_rows_of_group);
+                _row_reader->next(*_batch.get());
+
+                _current_line_of_group = 0;
+                ++_current_group;
+            }
+
+            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];
+                orc::ColumnVectorBatch *cvb = _batch_vec[_column_name_map_orc_index.find(
+                        slot_desc->col_name())->second];
+
+                if (cvb->hasNulls && !cvb->notNull[_current_line_of_group]) {
+                    if (!slot_desc->is_nullable()) {
+                        std::stringstream str_error;
+                        str_error << "The field name(" << slot_desc->col_name()
+                                  << ") is not allowed null, but ORC field is NULL.";
+                        LOG(WARNING) << str_error.str();
+                        return Status::RuntimeError(str_error.str());
+                    }
+                    _src_tuple->set_null(slot_desc->null_indicator_offset());
+                } else {
+                    int32_t wbytes = 0;
+                    uint8_t tmp_buf[128] = {0};
+                    _src_tuple->set_not_null(slot_desc->null_indicator_offset());
+                    void *slot = _src_tuple->get_slot(slot_desc->tuple_offset());
+                    StringValue *str_slot = reinterpret_cast<StringValue *>(slot);
+
+                    switch (_reader->getType().getSubtype(column_ipos)->getKind()) {
+                        case orc::BOOLEAN: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            if (value == 0) {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(5));
+                                memcpy(str_slot->ptr, "false", 5);
+                                str_slot->len = 5;
+                            } else {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(4));
+                                memcpy(str_slot->ptr, "true", 4);
+                                str_slot->len = 4;
+                            }
+                            break;
+                        }
+                        case orc::INT:
+                        case orc::SHORT:
+                        case orc::LONG:
+                        case orc::DATE: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            std::cout << "value : " << value << std::endl;
+                            wbytes = sprintf((char *) tmp_buf, "%ld", value);
 
 Review comment:
   does it work for date type?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r363144884
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,328 @@
+// 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 "exec/broker_reader.h"
+#include "exec/local_file_reader.h"
+#include "exprs/expr.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"
+
+namespace doris {
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(std::move(filename)) {
+    }
+
+    ~ORCFileStream() override {
+        if (_file) {
+            _file->close();
+            delete _file;
+            _file = nullptr;
+        }
+    }
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const override {
+        return _file->size();
+    }
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const override {
+        return 128 * 1024;
+    }
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+    void read(void *buf, uint64_t length, uint64_t offset) override {
+        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));
+        }
+    }
+
+    /**
+     * Get the name of the stream for error messages.
+     */
+    const std::string &getName() const override {
+        return _filename;
+    }
+private:
+    FileReader *_file;
+    std::string _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];
+                orc::ColumnVectorBatch *cvb = batch_vec[_position_in_orc_original[column_ipos]];
+
+                if (cvb->hasNulls && !cvb->notNull[_current_line_of_group]) {
+                    //all src tuple is nullable , judge null in dest_tuple
+                    _src_tuple->set_null(slot_desc->null_indicator_offset());
+                } else {
+                    int32_t wbytes = 0;
+                    uint8_t tmp_buf[128] = {0};
+                    _src_tuple->set_not_null(slot_desc->null_indicator_offset());
+                    void *slot = _src_tuple->get_slot(slot_desc->tuple_offset());
+                    StringValue *str_slot = reinterpret_cast<StringValue *>(slot);
+
+                    switch (_row_reader->getSelectedType().getSubtype(_position_in_orc_original[column_ipos])->getKind()) {
+                        case orc::BOOLEAN: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            if (value == 0) {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(5));
+                                memcpy(str_slot->ptr, "false", 5);
+                                str_slot->len = 5;
+                            } else {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(4));
+                                memcpy(str_slot->ptr, "true", 4);
+                                str_slot->len = 4;
+                            }
+                            break;
+                        }
+                        case orc::INT:
+                        case orc::SHORT:
+                        case orc::LONG:
+                        case orc::DATE: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%ld", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::FLOAT:
+                        case orc::DOUBLE: {
+                            double value = ((orc::DoubleVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%f", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::BINARY:
+                        case orc::CHAR:
+                        case orc::VARCHAR:
+                        case orc::STRING: {
+                            char *value = ((orc::StringVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = ((orc::StringVectorBatch *) cvb)->length[_current_line_of_group];
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, value, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                            //TODO (lhy) : support more orc type
+                        case orc::TIMESTAMP:
+                        case orc::DECIMAL:
+                        default: {
+                            std::stringstream str_error;
+                            str_error << "The field name(" << slot_desc->col_name() << ") type not support. ";
+                            LOG(WARNING) << str_error.str();
+                            return Status::InternalError(str_error.str());
+                        }
+                    }
+                }
+            }
+            ++_current_line_of_group;
+
+            // range of current file
+            const TBrokerRangeDesc &range = _ranges.at(_next_range - 1);
+            if (range.__isset.num_of_columns_from_file) {
+                fill_slots_of_columns_from_path(range.num_of_columns_from_file, range.columns_from_path);
+            }
+            COUNTER_UPDATE(_rows_read_counter, 1);
+            SCOPED_TIMER(_materialize_timer);
+            if (fill_dest_tuple(Slice(), tuple, tuple_pool)) {
+                break; // get one line, break from while
+            } // else skip this line and continue get_next to return
+        }
+        return Status::OK();
+    } catch (orc::ParseError &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    } catch (orc::InvalidArgument &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    }
+}
+
+Status ORCScanner::open_next_reader() {
+    while (true) {
+        if (_next_range >= _ranges.size()) {
+            _scanner_eof = true;
+            return Status::OK();
+        }
+        const TBrokerRangeDesc &range = _ranges[_next_range++];
+        std::unique_ptr<FileReader> file_reader;
+        switch (range.file_type) {
+            case TFileType::FILE_LOCAL: {
+                file_reader.reset(new LocalFileReader(range.path, range.start_offset));
+                break;
+            }
+            case TFileType::FILE_BROKER: {
+                int64_t file_size = 0;
+                // for compatibility
+                if (range.__isset.file_size) { file_size = range.file_size; }
+                file_reader.reset(new BrokerReader(_state->exec_env(), _broker_addresses, _params.properties,
+                                                   range.path, range.start_offset, file_size));
+                break;
+            }
+            default: {
+                std::stringstream ss;
+                ss << "Unknown file type, type=" << range.file_type;
+                return Status::InternalError(ss.str());
+            }
+        }
+        RETURN_IF_ERROR(file_reader->open());
+        if (file_reader->size() == 0) {
+            file_reader->close();
+            continue;
+        }
+
+        std::unique_ptr<orc::InputStream> inStream = std::unique_ptr<orc::InputStream>(
+                new ORCFileStream(file_reader.release(), range.path));
+        _reader = orc::createReader(std::move(inStream), _options);
+
+        _total_groups = _reader->getNumberOfStripes();
+        _current_group = 0;
+        _rows_of_group = 0;
+        _current_line_of_group = 0;
+
+        _includes.clear();
+        _num_of_columns_from_file =
+                range.__isset.num_of_columns_from_file ? range.num_of_columns_from_file : _src_slot_descs.size();
+        for (int i = 0; i < _num_of_columns_from_file; i++) {
+            auto slot_desc = _src_slot_descs.at(i);
+            _includes.push_back(slot_desc->col_name());
+        }
+        _rowReaderOptions.include(_includes);
 
 Review comment:
   why not use a local variable? It seems that it is only used in this function

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r363141591
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,328 @@
+// 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 "exec/broker_reader.h"
+#include "exec/local_file_reader.h"
+#include "exprs/expr.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"
+
+namespace doris {
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(std::move(filename)) {
+    }
+
+    ~ORCFileStream() override {
+        if (_file) {
+            _file->close();
+            delete _file;
+            _file = nullptr;
+        }
+    }
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const override {
+        return _file->size();
+    }
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const override {
+        return 128 * 1024;
+    }
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+    void read(void *buf, uint64_t length, uint64_t offset) override {
+        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));
+        }
+    }
+
+    /**
+     * Get the name of the stream for error messages.
+     */
+    const std::string &getName() const override {
 
 Review comment:
   ```suggestion
       const std::string& getName() const override {
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] HangyuanLiu commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
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_r361886379
 
 

 ##########
 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;
+                orc::ColumnVectorBatch *cvb = batch_vec[position_in_orc];
+
+                if (cvb->hasNulls && !cvb->notNull[_current_line_of_group]) {
+                    //all src tuple is nullable , judge null in dest_tuple
+                    _src_tuple->set_null(slot_desc->null_indicator_offset());
+                } else {
+                    int32_t wbytes = 0;
+                    uint8_t tmp_buf[128] = {0};
+                    _src_tuple->set_not_null(slot_desc->null_indicator_offset());
+                    void *slot = _src_tuple->get_slot(slot_desc->tuple_offset());
+                    StringValue *str_slot = reinterpret_cast<StringValue *>(slot);
+
+                    switch (_row_reader->getSelectedType().getSubtype(position_in_orc)->getKind()) {
+                        case orc::BOOLEAN: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            if (value == 0) {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(5));
+                                memcpy(str_slot->ptr, "false", 5);
+                                str_slot->len = 5;
+                            } else {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(4));
+                                memcpy(str_slot->ptr, "true", 4);
+                                str_slot->len = 4;
+                            }
+                            break;
+                        }
+                        case orc::INT:
+                        case orc::SHORT:
+                        case orc::LONG:
+                        case orc::DATE: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%ld", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::FLOAT:
+                        case orc::DOUBLE: {
+                            double value = ((orc::DoubleVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%f", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::BINARY:
+                        case orc::CHAR:
+                        case orc::VARCHAR:
+                        case orc::STRING: {
+                            char *value = ((orc::StringVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = ((orc::StringVectorBatch *) cvb)->length[_current_line_of_group];
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, value, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                            //TODO (lhy) : support more orc type
+                        case orc::TIMESTAMP:
+                        case orc::DECIMAL:
+                        default: {
+                            std::stringstream str_error;
+                            str_error << "The field name(" << slot_desc->col_name() << ") type not support. ";
+                            LOG(WARNING) << str_error.str();
+                            return Status::InternalError(str_error.str());
+                        }
+                    }
+                }
+            }
+            ++_current_line_of_group;
+
+            // range of current file
+            const TBrokerRangeDesc &range = _ranges.at(_next_range - 1);
+            if (range.__isset.num_of_columns_from_file) {
+                fill_slots_of_columns_from_path(range.num_of_columns_from_file, range.columns_from_path);
+            }
+            COUNTER_UPDATE(_rows_read_counter, 1);
+            SCOPED_TIMER(_materialize_timer);
+            if (fill_dest_tuple(Slice(), tuple, tuple_pool)) {
+                break; // get one line, break from while
+            } // else skip this line and continue get_next to return
+        }
+        return Status::OK();
+    } catch (orc::ParseError &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    } catch (orc::InvalidArgument &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    }
+}
+
+Status ORCScanner::open_next_reader() {
+    while (true) {
+        if (_next_range >= _ranges.size()) {
+            _scanner_eof = true;
+            return Status::OK();
+        }
+        const TBrokerRangeDesc &range = _ranges[_next_range++];
+        std::unique_ptr<FileReader> file_reader;
+        switch (range.file_type) {
+            case TFileType::FILE_LOCAL: {
+                file_reader.reset(new LocalFileReader(range.path, range.start_offset));
+                break;
+            }
+            case TFileType::FILE_BROKER: {
+                int64_t file_size = 0;
+                // for compatibility
+                if (range.__isset.file_size) { file_size = range.file_size; }
+                file_reader.reset(new BrokerReader(_state->exec_env(), _broker_addresses, _params.properties,
+                                                   range.path, range.start_offset, file_size));
+                break;
+            }
+            default: {
+                std::stringstream ss;
+                ss << "Unknown file type, type=" << range.file_type;
+                return Status::InternalError(ss.str());
+            }
+        }
+        RETURN_IF_ERROR(file_reader->open());
+        if (file_reader->size() == 0) {
+            file_reader->close();
+            continue;
+        }
+
+        std::unique_ptr<orc::InputStream> inStream = std::unique_ptr<orc::InputStream>(
+                new ORCFileStream(file_reader.release(), range.path));
+        _reader = orc::createReader(std::move(inStream), _options);
 
 Review comment:
   Hi, why add new function?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r363141699
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,328 @@
+// 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 "exec/broker_reader.h"
+#include "exec/local_file_reader.h"
+#include "exprs/expr.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"
+
+namespace doris {
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(std::move(filename)) {
+    }
+
+    ~ORCFileStream() override {
+        if (_file) {
+            _file->close();
+            delete _file;
+            _file = nullptr;
+        }
+    }
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const override {
+        return _file->size();
+    }
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const override {
+        return 128 * 1024;
+    }
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+    void read(void *buf, uint64_t length, uint64_t offset) override {
+        if (!buf) {
 
 Review comment:
   ```suggestion
           if (buf == nullptr) {
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361155019
 
 

 ##########
 File path: be/src/exec/orc_scanner.h
 ##########
 @@ -0,0 +1,178 @@
+// 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.
+
+#ifndef ORC_SCANNER_H
+#define ORC_SCANNER_H
+
+#include <memory>
+#include <vector>
+#include <string>
+#include <map>
+#include <sstream>
+
+#include "exec/base_scanner.h"
+#include "exec/file_reader.h"
+#include "common/status.h"
+#include "gen_cpp/PlanNodes_types.h"
+#include "gen_cpp/Types_types.h"
+#include "runtime/mem_pool.h"
+#include "runtime/row_batch.h"
+#include "runtime/tuple.h"
+#include "util/slice.h"
+#include "util/runtime_profile.h"
+#include "orc/OrcFile.hh"
 
 Review comment:
   use <> for thirdparty header

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r363143108
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,328 @@
+// 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 "exec/broker_reader.h"
+#include "exec/local_file_reader.h"
+#include "exprs/expr.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"
+
+namespace doris {
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(std::move(filename)) {
+    }
+
+    ~ORCFileStream() override {
+        if (_file) {
 
 Review comment:
   ```suggestion
           if (_file != nullptr) {
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361156074
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,261 @@
+// 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/tuple.h"
+#include "exprs/expr.h"
+#include "exec/text_converter.h"
+#include "exec/text_converter.hpp"
+#include "exec/local_file_reader.h"
+#include "exec/broker_reader.h"
+
+namespace doris {
+
+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) {}
+
+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();
+                std::cout << "rows of group "<< _rows_of_group << std::endl;
 
 Review comment:
   remove debug log

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361157107
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,261 @@
+// 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/tuple.h"
+#include "exprs/expr.h"
+#include "exec/text_converter.h"
+#include "exec/text_converter.hpp"
+#include "exec/local_file_reader.h"
+#include "exec/broker_reader.h"
+
+namespace doris {
+
+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) {}
+
+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();
+                std::cout << "rows of group "<< _rows_of_group << std::endl;
+                _batch = _row_reader->createRowBatch(_rows_of_group);
+                _row_reader->next(*_batch.get());
+
+                _current_line_of_group = 0;
+                ++_current_group;
+            }
+
+            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];
+                orc::ColumnVectorBatch *cvb = _batch_vec[_column_name_map_orc_index.find(
+                        slot_desc->col_name())->second];
+
+                if (cvb->hasNulls && !cvb->notNull[_current_line_of_group]) {
+                    if (!slot_desc->is_nullable()) {
+                        std::stringstream str_error;
+                        str_error << "The field name(" << slot_desc->col_name()
+                                  << ") is not allowed null, but ORC field is NULL.";
+                        LOG(WARNING) << str_error.str();
+                        return Status::RuntimeError(str_error.str());
 
 Review comment:
   It is not a good choice to make all scan fail because of one bad field.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361155198
 
 

 ##########
 File path: be/src/exec/orc_scanner.h
 ##########
 @@ -0,0 +1,178 @@
+// 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.
+
+#ifndef ORC_SCANNER_H
+#define ORC_SCANNER_H
+
+#include <memory>
+#include <vector>
+#include <string>
+#include <map>
+#include <sstream>
+
+#include "exec/base_scanner.h"
+#include "exec/file_reader.h"
+#include "common/status.h"
+#include "gen_cpp/PlanNodes_types.h"
+#include "gen_cpp/Types_types.h"
+#include "runtime/mem_pool.h"
+#include "runtime/row_batch.h"
+#include "runtime/tuple.h"
+#include "util/slice.h"
+#include "util/runtime_profile.h"
+#include "orc/OrcFile.hh"
+
+namespace doris {
+
+class FileReader;
+class Tuple;
+class SlotDescriptor;
+class Slice;
+class ParquetReaderWrap;
+class RuntimeState;
+class ExprContext;
+class TupleDescriptor;
+class TupleRow;
+class RowDescriptor;
+class MemTracker;
+class RuntimeProfile;
+class StreamLoadPipe;
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(filename) {
+    }
+
+    ~ORCFileStream() {
+        if (_file) {
+            _file->close();
+            delete _file;
+            _file = nullptr;
+        }
+    }
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const {
+        return _file->size();
+    }
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const {
+        return 128 * 1024;
+    }
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+     void 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));
+        }
+    }
+
+    /**
+     * Get the name of the stream for error messages.
+     */
+    const std::string &getName() const {
 
 Review comment:
   ```suggestion
       const std::string& getName() const {
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r363144752
 
 

 ##########
 File path: be/src/exec/orc_scanner.h
 ##########
 @@ -0,0 +1,78 @@
+// 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.
+
+#ifndef ORC_SCANNER_H
+#define ORC_SCANNER_H
+
+#include <orc/OrcFile.hh>
+#include "exec/base_scanner.h"
+
+namespace doris {
+
+// Broker scanner convert the data read from broker to doris's tuple.
+class ORCScanner : public BaseScanner {
+public:
+    ORCScanner(RuntimeState *state,
+               RuntimeProfile *profile,
+               const TBrokerScanRangeParams& params,
+               const std::vector<TBrokerRangeDesc>& ranges,
+               const std::vector<TNetworkAddress>& broker_addresses, ScannerCounter *counter);
+
+    ~ORCScanner() override;
+
+    // Open this scanner, will initialize information need to
+    Status open() override;
+
+    // Get next tuple
+    Status get_next(Tuple *tuple, MemPool *tuple_pool, bool *eof) override;
+
+    // Close this scanner
+    void close() override;
+
+private:
+    // Read next buffer from reader
+    Status open_next_reader();
+
+private:
+    const std::vector<TBrokerRangeDesc>& _ranges;
+    const std::vector<TNetworkAddress>& _broker_addresses;
+
+    // Reader
+    int _next_range;
+    bool _cur_file_eof;
+    bool _scanner_eof;
+
+    // orc file reader object
+    orc::ReaderOptions _options;
+    orc::RowReaderOptions _rowReaderOptions;
 
 Review comment:
   ```suggestion
       orc::RowReaderOptions _row_reader_options;
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r363141655
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,328 @@
+// 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 "exec/broker_reader.h"
+#include "exec/local_file_reader.h"
+#include "exprs/expr.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"
+
+namespace doris {
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(std::move(filename)) {
+    }
+
+    ~ORCFileStream() override {
+        if (_file) {
+            _file->close();
+            delete _file;
+            _file = nullptr;
+        }
+    }
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const override {
+        return _file->size();
+    }
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const override {
+        return 128 * 1024;
+    }
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+    void read(void *buf, uint64_t length, uint64_t offset) override {
 
 Review comment:
   ```suggestion
       void read(void* buf, uint64_t length, uint64_t offset) override {
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] HangyuanLiu commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
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_r361423834
 
 

 ##########
 File path: be/src/exec/orc_scanner.h
 ##########
 @@ -0,0 +1,178 @@
+// 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.
+
+#ifndef ORC_SCANNER_H
+#define ORC_SCANNER_H
+
+#include <memory>
+#include <vector>
+#include <string>
+#include <map>
+#include <sstream>
+
+#include "exec/base_scanner.h"
+#include "exec/file_reader.h"
+#include "common/status.h"
+#include "gen_cpp/PlanNodes_types.h"
+#include "gen_cpp/Types_types.h"
+#include "runtime/mem_pool.h"
+#include "runtime/row_batch.h"
+#include "runtime/tuple.h"
+#include "util/slice.h"
+#include "util/runtime_profile.h"
+#include "orc/OrcFile.hh"
+
+namespace doris {
+
+class FileReader;
+class Tuple;
+class SlotDescriptor;
+class Slice;
+class ParquetReaderWrap;
+class RuntimeState;
+class ExprContext;
+class TupleDescriptor;
+class TupleRow;
+class RowDescriptor;
+class MemTracker;
+class RuntimeProfile;
+class StreamLoadPipe;
+
+class ORCFileStream : public orc::InputStream {
 
 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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361906970
 
 

 ##########
 File path: be/src/exec/orc_scanner.h
 ##########
 @@ -0,0 +1,144 @@
+// 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.
+
+#ifndef ORC_SCANNER_H
+#define ORC_SCANNER_H
+
+#include <memory>
+#include <vector>
+#include <string>
+#include <map>
+#include <sstream>
+#include <orc/OrcFile.hh>
+
+#include "exec/base_scanner.h"
+#include "exec/file_reader.h"
+#include "common/status.h"
+#include "gen_cpp/PlanNodes_types.h"
+#include "gen_cpp/Types_types.h"
+#include "runtime/mem_pool.h"
+#include "runtime/row_batch.h"
+#include "runtime/tuple.h"
+#include "util/slice.h"
+#include "util/runtime_profile.h"
+
+namespace doris {
+
+class FileReader;
+class Tuple;
+class SlotDescriptor;
+class Slice;
+class ParquetReaderWrap;
+class RuntimeState;
+class ExprContext;
+class TupleDescriptor;
+class TupleRow;
+class RowDescriptor;
+class MemTracker;
+class RuntimeProfile;
+class StreamLoadPipe;
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(filename) {
 
 Review comment:
   ```suggestion
       ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(std::move(filename)) {
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361157345
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,261 @@
+// 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/tuple.h"
+#include "exprs/expr.h"
+#include "exec/text_converter.h"
+#include "exec/text_converter.hpp"
+#include "exec/local_file_reader.h"
+#include "exec/broker_reader.h"
+
+namespace doris {
+
+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) {}
+
+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();
+                std::cout << "rows of group "<< _rows_of_group << std::endl;
+                _batch = _row_reader->createRowBatch(_rows_of_group);
+                _row_reader->next(*_batch.get());
+
+                _current_line_of_group = 0;
+                ++_current_group;
+            }
+
+            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];
+                orc::ColumnVectorBatch *cvb = _batch_vec[_column_name_map_orc_index.find(
+                        slot_desc->col_name())->second];
+
+                if (cvb->hasNulls && !cvb->notNull[_current_line_of_group]) {
+                    if (!slot_desc->is_nullable()) {
+                        std::stringstream str_error;
+                        str_error << "The field name(" << slot_desc->col_name()
+                                  << ") is not allowed null, but ORC field is NULL.";
+                        LOG(WARNING) << str_error.str();
+                        return Status::RuntimeError(str_error.str());
+                    }
+                    _src_tuple->set_null(slot_desc->null_indicator_offset());
+                } else {
+                    int32_t wbytes = 0;
+                    uint8_t tmp_buf[128] = {0};
+                    _src_tuple->set_not_null(slot_desc->null_indicator_offset());
 
 Review comment:
   should check if slot_desc is nullable

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361907244
 
 

 ##########
 File path: be/src/exec/orc_scanner.h
 ##########
 @@ -0,0 +1,144 @@
+// 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.
+
+#ifndef ORC_SCANNER_H
+#define ORC_SCANNER_H
+
+#include <memory>
+#include <vector>
+#include <string>
+#include <map>
+#include <sstream>
+#include <orc/OrcFile.hh>
+
+#include "exec/base_scanner.h"
+#include "exec/file_reader.h"
+#include "common/status.h"
+#include "gen_cpp/PlanNodes_types.h"
+#include "gen_cpp/Types_types.h"
+#include "runtime/mem_pool.h"
+#include "runtime/row_batch.h"
+#include "runtime/tuple.h"
+#include "util/slice.h"
+#include "util/runtime_profile.h"
+
+namespace doris {
+
+class FileReader;
+class Tuple;
+class SlotDescriptor;
+class Slice;
+class ParquetReaderWrap;
+class RuntimeState;
+class ExprContext;
+class TupleDescriptor;
+class TupleRow;
+class RowDescriptor;
+class MemTracker;
+class RuntimeProfile;
+class StreamLoadPipe;
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(filename) {
+    }
+
+    ~ORCFileStream();
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const;
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const;
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+    void read(void *buf, uint64_t length, uint64_t offset);
+
+    /**
+     * Get the name of the stream for error messages.
+     */
+    const std::string& getName() const;
+
+private:
+    FileReader *_file;
+    std::string _filename;
+};
+
+// Broker scanner convert the data read from broker to doris's tuple.
+class ORCScanner : public BaseScanner {
+public:
+    ORCScanner(RuntimeState *state,
+               RuntimeProfile *profile,
+               const TBrokerScanRangeParams& params,
+               const std::vector<TBrokerRangeDesc>& ranges,
+               const std::vector<TNetworkAddress>& broker_addresses, ScannerCounter *counter);
+
+    ~ORCScanner();
+
+    // Open this scanner, will initialize information need to
+    virtual Status open();
 
 Review comment:
   ```suggestion
       Status open() override;
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r363141615
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,328 @@
+// 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 "exec/broker_reader.h"
+#include "exec/local_file_reader.h"
+#include "exprs/expr.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"
+
+namespace doris {
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(std::move(filename)) {
+    }
+
+    ~ORCFileStream() override {
+        if (_file) {
+            _file->close();
+            delete _file;
+            _file = nullptr;
+        }
+    }
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const override {
+        return _file->size();
+    }
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const override {
+        return 128 * 1024;
+    }
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+    void read(void *buf, uint64_t length, uint64_t offset) override {
+        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));
+        }
+    }
+
+    /**
+     * Get the name of the stream for error messages.
+     */
+    const std::string &getName() const override {
+        return _filename;
+    }
+private:
+    FileReader *_file;
 
 Review comment:
   ```suggestion
       FileReader* _file;
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361156377
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,261 @@
+// 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/tuple.h"
+#include "exprs/expr.h"
+#include "exec/text_converter.h"
+#include "exec/text_converter.hpp"
+#include "exec/local_file_reader.h"
+#include "exec/broker_reader.h"
+
+namespace doris {
+
+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) {}
+
+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();
+                std::cout << "rows of group "<< _rows_of_group << std::endl;
+                _batch = _row_reader->createRowBatch(_rows_of_group);
+                _row_reader->next(*_batch.get());
+
+                _current_line_of_group = 0;
+                ++_current_group;
+            }
+
+            std::vector<orc::ColumnVectorBatch *> _batch_vec = ((orc::StructVectorBatch *) _batch.get())->fields;
 
 Review comment:
   why not use const reference?
   and remove its name's leading `_`

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361155085
 
 

 ##########
 File path: be/src/exec/orc_scanner.h
 ##########
 @@ -0,0 +1,178 @@
+// 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.
+
+#ifndef ORC_SCANNER_H
+#define ORC_SCANNER_H
+
+#include <memory>
+#include <vector>
+#include <string>
+#include <map>
+#include <sstream>
+
+#include "exec/base_scanner.h"
+#include "exec/file_reader.h"
+#include "common/status.h"
+#include "gen_cpp/PlanNodes_types.h"
+#include "gen_cpp/Types_types.h"
+#include "runtime/mem_pool.h"
+#include "runtime/row_batch.h"
+#include "runtime/tuple.h"
+#include "util/slice.h"
+#include "util/runtime_profile.h"
+#include "orc/OrcFile.hh"
+
+namespace doris {
+
+class FileReader;
+class Tuple;
+class SlotDescriptor;
+class Slice;
+class ParquetReaderWrap;
+class RuntimeState;
+class ExprContext;
+class TupleDescriptor;
+class TupleRow;
+class RowDescriptor;
+class MemTracker;
+class RuntimeProfile;
+class StreamLoadPipe;
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(filename) {
+    }
+
+    ~ORCFileStream() {
+        if (_file) {
+            _file->close();
+            delete _file;
+            _file = nullptr;
+        }
+    }
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const {
+        return _file->size();
+    }
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const {
+        return 128 * 1024;
+    }
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+     void 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));
+        }
+    }
+
+    /**
+     * Get the name of the stream for error messages.
+     */
+    const std::string &getName() const {
+        return _filename;
+    }
+
+private:
+    FileReader *_file;
+    std::string _filename;
+};
+// Broker scanner convert the data read from broker to doris's tuple.
+class ORCScanner : public BaseScanner {
+public:
+    ORCScanner(RuntimeState* state,
+    RuntimeProfile *profile,
+    const TBrokerScanRangeParams &params,
+    const std::vector<TBrokerRangeDesc> &ranges,
+    const std::vector<TNetworkAddress> &broker_addresses,ScannerCounter* counter);
+
+    ~ORCScanner();
+
+    // Open this scanner, will initialize information need to
+    virtual Status open();
+
+    // Get next tuple
+    virtual Status get_next(Tuple *tuple, MemPool *tuple_pool, bool *eof);
+
+    // Close this scanner
+    virtual void close();
+
+private:
+    // Read next buffer from reader
+    Status open_next_reader();
+
+private:
+    const std::vector<TBrokerRangeDesc> &_ranges;
 
 Review comment:
   ```suggestion
       const std::vector<TBrokerRangeDesc>& _ranges;
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361156792
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,261 @@
+// 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/tuple.h"
+#include "exprs/expr.h"
+#include "exec/text_converter.h"
+#include "exec/text_converter.hpp"
+#include "exec/local_file_reader.h"
+#include "exec/broker_reader.h"
+
+namespace doris {
+
+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) {}
+
+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();
+                std::cout << "rows of group "<< _rows_of_group << std::endl;
+                _batch = _row_reader->createRowBatch(_rows_of_group);
+                _row_reader->next(*_batch.get());
+
+                _current_line_of_group = 0;
+                ++_current_group;
+            }
+
+            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];
+                orc::ColumnVectorBatch *cvb = _batch_vec[_column_name_map_orc_index.find(
+                        slot_desc->col_name())->second];
+
+                if (cvb->hasNulls && !cvb->notNull[_current_line_of_group]) {
+                    if (!slot_desc->is_nullable()) {
+                        std::stringstream str_error;
+                        str_error << "The field name(" << slot_desc->col_name()
+                                  << ") is not allowed null, but ORC field is NULL.";
+                        LOG(WARNING) << str_error.str();
+                        return Status::RuntimeError(str_error.str());
+                    }
+                    _src_tuple->set_null(slot_desc->null_indicator_offset());
+                } else {
+                    int32_t wbytes = 0;
+                    uint8_t tmp_buf[128] = {0};
+                    _src_tuple->set_not_null(slot_desc->null_indicator_offset());
+                    void *slot = _src_tuple->get_slot(slot_desc->tuple_offset());
+                    StringValue *str_slot = reinterpret_cast<StringValue *>(slot);
+
+                    switch (_reader->getType().getSubtype(column_ipos)->getKind()) {
+                        case orc::BOOLEAN: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            if (value == 0) {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(5));
+                                memcpy(str_slot->ptr, "false", 5);
+                                str_slot->len = 5;
+                            } else {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(4));
+                                memcpy(str_slot->ptr, "true", 4);
+                                str_slot->len = 4;
+                            }
+                            break;
+                        }
+                        case orc::INT:
+                        case orc::SHORT:
+                        case orc::LONG:
+                        case orc::DATE: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            std::cout << "value : " << value << std::endl;
 
 Review comment:
   remove debug

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r363145103
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,328 @@
+// 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 "exec/broker_reader.h"
+#include "exec/local_file_reader.h"
+#include "exprs/expr.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"
+
+namespace doris {
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(std::move(filename)) {
+    }
+
+    ~ORCFileStream() override {
+        if (_file) {
+            _file->close();
+            delete _file;
+            _file = nullptr;
+        }
+    }
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const override {
+        return _file->size();
+    }
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const override {
+        return 128 * 1024;
+    }
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+    void read(void *buf, uint64_t length, uint64_t offset) override {
+        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));
+        }
+    }
+
+    /**
+     * Get the name of the stream for error messages.
+     */
+    const std::string &getName() const override {
+        return _filename;
+    }
+private:
+    FileReader *_file;
+    std::string _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];
+                orc::ColumnVectorBatch *cvb = batch_vec[_position_in_orc_original[column_ipos]];
+
+                if (cvb->hasNulls && !cvb->notNull[_current_line_of_group]) {
+                    //all src tuple is nullable , judge null in dest_tuple
+                    _src_tuple->set_null(slot_desc->null_indicator_offset());
+                } else {
+                    int32_t wbytes = 0;
+                    uint8_t tmp_buf[128] = {0};
+                    _src_tuple->set_not_null(slot_desc->null_indicator_offset());
+                    void *slot = _src_tuple->get_slot(slot_desc->tuple_offset());
+                    StringValue *str_slot = reinterpret_cast<StringValue *>(slot);
+
+                    switch (_row_reader->getSelectedType().getSubtype(_position_in_orc_original[column_ipos])->getKind()) {
+                        case orc::BOOLEAN: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            if (value == 0) {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(5));
+                                memcpy(str_slot->ptr, "false", 5);
+                                str_slot->len = 5;
+                            } else {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(4));
+                                memcpy(str_slot->ptr, "true", 4);
+                                str_slot->len = 4;
+                            }
+                            break;
+                        }
+                        case orc::INT:
+                        case orc::SHORT:
+                        case orc::LONG:
+                        case orc::DATE: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%ld", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::FLOAT:
+                        case orc::DOUBLE: {
+                            double value = ((orc::DoubleVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%f", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::BINARY:
+                        case orc::CHAR:
+                        case orc::VARCHAR:
+                        case orc::STRING: {
+                            char *value = ((orc::StringVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = ((orc::StringVectorBatch *) cvb)->length[_current_line_of_group];
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, value, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                            //TODO (lhy) : support more orc type
+                        case orc::TIMESTAMP:
+                        case orc::DECIMAL:
+                        default: {
+                            std::stringstream str_error;
+                            str_error << "The field name(" << slot_desc->col_name() << ") type not support. ";
+                            LOG(WARNING) << str_error.str();
+                            return Status::InternalError(str_error.str());
+                        }
+                    }
+                }
+            }
+            ++_current_line_of_group;
+
+            // range of current file
+            const TBrokerRangeDesc &range = _ranges.at(_next_range - 1);
+            if (range.__isset.num_of_columns_from_file) {
+                fill_slots_of_columns_from_path(range.num_of_columns_from_file, range.columns_from_path);
+            }
+            COUNTER_UPDATE(_rows_read_counter, 1);
+            SCOPED_TIMER(_materialize_timer);
+            if (fill_dest_tuple(Slice(), tuple, tuple_pool)) {
+                break; // get one line, break from while
+            } // else skip this line and continue get_next to return
+        }
+        return Status::OK();
+    } catch (orc::ParseError &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    } catch (orc::InvalidArgument &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    }
+}
+
+Status ORCScanner::open_next_reader() {
+    while (true) {
+        if (_next_range >= _ranges.size()) {
+            _scanner_eof = true;
+            return Status::OK();
+        }
+        const TBrokerRangeDesc &range = _ranges[_next_range++];
+        std::unique_ptr<FileReader> file_reader;
+        switch (range.file_type) {
+            case TFileType::FILE_LOCAL: {
+                file_reader.reset(new LocalFileReader(range.path, range.start_offset));
+                break;
+            }
+            case TFileType::FILE_BROKER: {
+                int64_t file_size = 0;
+                // for compatibility
+                if (range.__isset.file_size) { file_size = range.file_size; }
+                file_reader.reset(new BrokerReader(_state->exec_env(), _broker_addresses, _params.properties,
+                                                   range.path, range.start_offset, file_size));
+                break;
+            }
+            default: {
+                std::stringstream ss;
+                ss << "Unknown file type, type=" << range.file_type;
+                return Status::InternalError(ss.str());
+            }
+        }
+        RETURN_IF_ERROR(file_reader->open());
+        if (file_reader->size() == 0) {
+            file_reader->close();
+            continue;
+        }
+
+        std::unique_ptr<orc::InputStream> inStream = std::unique_ptr<orc::InputStream>(
+                new ORCFileStream(file_reader.release(), range.path));
+        _reader = orc::createReader(std::move(inStream), _options);
+
+        _total_groups = _reader->getNumberOfStripes();
+        _current_group = 0;
+        _rows_of_group = 0;
+        _current_line_of_group = 0;
+
+        _includes.clear();
+        _num_of_columns_from_file =
+                range.__isset.num_of_columns_from_file ? range.num_of_columns_from_file : _src_slot_descs.size();
+        for (int i = 0; i < _num_of_columns_from_file; i++) {
+            auto slot_desc = _src_slot_descs.at(i);
+            _includes.push_back(slot_desc->col_name());
+        }
+        _rowReaderOptions.include(_includes);
 
 Review comment:
   this should be done once, unnecessary for each reader

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r363145173
 
 

 ##########
 File path: be/src/exec/orc_scanner.h
 ##########
 @@ -0,0 +1,78 @@
+// 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.
+
+#ifndef ORC_SCANNER_H
+#define ORC_SCANNER_H
+
+#include <orc/OrcFile.hh>
+#include "exec/base_scanner.h"
+
+namespace doris {
+
+// Broker scanner convert the data read from broker to doris's tuple.
+class ORCScanner : public BaseScanner {
+public:
+    ORCScanner(RuntimeState *state,
+               RuntimeProfile *profile,
+               const TBrokerScanRangeParams& params,
+               const std::vector<TBrokerRangeDesc>& ranges,
+               const std::vector<TNetworkAddress>& broker_addresses, ScannerCounter *counter);
+
+    ~ORCScanner() override;
+
+    // Open this scanner, will initialize information need to
+    Status open() override;
+
+    // Get next tuple
+    Status get_next(Tuple *tuple, MemPool *tuple_pool, bool *eof) override;
+
+    // Close this scanner
+    void close() override;
+
+private:
+    // Read next buffer from reader
+    Status open_next_reader();
+
+private:
+    const std::vector<TBrokerRangeDesc>& _ranges;
+    const std::vector<TNetworkAddress>& _broker_addresses;
+
+    // Reader
+    int _next_range;
+    bool _cur_file_eof;
+    bool _scanner_eof;
+
+    // orc file reader object
+    orc::ReaderOptions _options;
+    orc::RowReaderOptions _rowReaderOptions;
+    std::shared_ptr<orc::ColumnVectorBatch> _batch;
+    std::unique_ptr<orc::Reader> _reader;
+    std::unique_ptr<orc::RowReader> _row_reader;
+    std::list<std::string> _includes; // include columns in orc file
 
 Review comment:
   ```suggestion
       std::list<std::string> _include_cols; // include columns in orc file
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361907199
 
 

 ##########
 File path: be/src/exec/orc_scanner.h
 ##########
 @@ -0,0 +1,144 @@
+// 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.
+
+#ifndef ORC_SCANNER_H
+#define ORC_SCANNER_H
+
+#include <memory>
+#include <vector>
+#include <string>
+#include <map>
+#include <sstream>
+#include <orc/OrcFile.hh>
+
+#include "exec/base_scanner.h"
+#include "exec/file_reader.h"
+#include "common/status.h"
+#include "gen_cpp/PlanNodes_types.h"
+#include "gen_cpp/Types_types.h"
+#include "runtime/mem_pool.h"
+#include "runtime/row_batch.h"
+#include "runtime/tuple.h"
+#include "util/slice.h"
+#include "util/runtime_profile.h"
+
+namespace doris {
+
+class FileReader;
+class Tuple;
+class SlotDescriptor;
+class Slice;
+class ParquetReaderWrap;
+class RuntimeState;
+class ExprContext;
+class TupleDescriptor;
+class TupleRow;
+class RowDescriptor;
+class MemTracker;
+class RuntimeProfile;
+class StreamLoadPipe;
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(filename) {
+    }
+
+    ~ORCFileStream();
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const;
 
 Review comment:
   Better to add overred to inherited virtual function 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r363145345
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,328 @@
+// 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 "exec/broker_reader.h"
+#include "exec/local_file_reader.h"
+#include "exprs/expr.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"
+
+namespace doris {
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(std::move(filename)) {
+    }
+
+    ~ORCFileStream() override {
+        if (_file) {
+            _file->close();
+            delete _file;
+            _file = nullptr;
+        }
+    }
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const override {
+        return _file->size();
+    }
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const override {
+        return 128 * 1024;
+    }
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+    void read(void *buf, uint64_t length, uint64_t offset) override {
+        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));
+        }
+    }
+
+    /**
+     * Get the name of the stream for error messages.
+     */
+    const std::string &getName() const override {
+        return _filename;
+    }
+private:
+    FileReader *_file;
+    std::string _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];
+                orc::ColumnVectorBatch *cvb = batch_vec[_position_in_orc_original[column_ipos]];
+
+                if (cvb->hasNulls && !cvb->notNull[_current_line_of_group]) {
+                    //all src tuple is nullable , judge null in dest_tuple
+                    _src_tuple->set_null(slot_desc->null_indicator_offset());
+                } else {
+                    int32_t wbytes = 0;
+                    uint8_t tmp_buf[128] = {0};
+                    _src_tuple->set_not_null(slot_desc->null_indicator_offset());
+                    void *slot = _src_tuple->get_slot(slot_desc->tuple_offset());
+                    StringValue *str_slot = reinterpret_cast<StringValue *>(slot);
+
+                    switch (_row_reader->getSelectedType().getSubtype(_position_in_orc_original[column_ipos])->getKind()) {
+                        case orc::BOOLEAN: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            if (value == 0) {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(5));
+                                memcpy(str_slot->ptr, "false", 5);
+                                str_slot->len = 5;
+                            } else {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(4));
+                                memcpy(str_slot->ptr, "true", 4);
+                                str_slot->len = 4;
+                            }
+                            break;
+                        }
+                        case orc::INT:
+                        case orc::SHORT:
+                        case orc::LONG:
+                        case orc::DATE: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%ld", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::FLOAT:
+                        case orc::DOUBLE: {
+                            double value = ((orc::DoubleVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%f", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::BINARY:
+                        case orc::CHAR:
+                        case orc::VARCHAR:
+                        case orc::STRING: {
+                            char *value = ((orc::StringVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = ((orc::StringVectorBatch *) cvb)->length[_current_line_of_group];
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, value, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                            //TODO (lhy) : support more orc type
+                        case orc::TIMESTAMP:
+                        case orc::DECIMAL:
+                        default: {
+                            std::stringstream str_error;
+                            str_error << "The field name(" << slot_desc->col_name() << ") type not support. ";
+                            LOG(WARNING) << str_error.str();
+                            return Status::InternalError(str_error.str());
+                        }
+                    }
+                }
+            }
+            ++_current_line_of_group;
+
+            // range of current file
+            const TBrokerRangeDesc &range = _ranges.at(_next_range - 1);
+            if (range.__isset.num_of_columns_from_file) {
+                fill_slots_of_columns_from_path(range.num_of_columns_from_file, range.columns_from_path);
+            }
+            COUNTER_UPDATE(_rows_read_counter, 1);
+            SCOPED_TIMER(_materialize_timer);
+            if (fill_dest_tuple(Slice(), tuple, tuple_pool)) {
+                break; // get one line, break from while
+            } // else skip this line and continue get_next to return
+        }
+        return Status::OK();
+    } catch (orc::ParseError &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    } catch (orc::InvalidArgument &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    }
+}
+
+Status ORCScanner::open_next_reader() {
+    while (true) {
+        if (_next_range >= _ranges.size()) {
+            _scanner_eof = true;
+            return Status::OK();
+        }
+        const TBrokerRangeDesc &range = _ranges[_next_range++];
+        std::unique_ptr<FileReader> file_reader;
+        switch (range.file_type) {
+            case TFileType::FILE_LOCAL: {
+                file_reader.reset(new LocalFileReader(range.path, range.start_offset));
+                break;
+            }
+            case TFileType::FILE_BROKER: {
+                int64_t file_size = 0;
+                // for compatibility
+                if (range.__isset.file_size) { file_size = range.file_size; }
+                file_reader.reset(new BrokerReader(_state->exec_env(), _broker_addresses, _params.properties,
+                                                   range.path, range.start_offset, file_size));
+                break;
+            }
+            default: {
+                std::stringstream ss;
+                ss << "Unknown file type, type=" << range.file_type;
+                return Status::InternalError(ss.str());
+            }
+        }
+        RETURN_IF_ERROR(file_reader->open());
+        if (file_reader->size() == 0) {
+            file_reader->close();
+            continue;
+        }
+
+        std::unique_ptr<orc::InputStream> inStream = std::unique_ptr<orc::InputStream>(
+                new ORCFileStream(file_reader.release(), range.path));
+        _reader = orc::createReader(std::move(inStream), _options);
+
+        _total_groups = _reader->getNumberOfStripes();
+        _current_group = 0;
+        _rows_of_group = 0;
+        _current_line_of_group = 0;
+
+        _includes.clear();
+        _num_of_columns_from_file =
+                range.__isset.num_of_columns_from_file ? range.num_of_columns_from_file : _src_slot_descs.size();
+        for (int i = 0; i < _num_of_columns_from_file; i++) {
+            auto slot_desc = _src_slot_descs.at(i);
+            _includes.push_back(slot_desc->col_name());
+        }
+        _rowReaderOptions.include(_includes);
+
+        int orc_index = 0;
+        std::map<std::string, int> column_name_map_orc_index;
+        for (int i = 0; i < _reader->getType().getSubtypeCount(); ++i) {
+            if (std::find(_includes.begin(), _includes.end(), _reader->getType().getFieldName(i)) != _includes.end()) {
+                column_name_map_orc_index.emplace(_reader->getType().getFieldName(i), orc_index++);
+            }
 
 Review comment:
   else should return bad status

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] HangyuanLiu commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361907224
 
 

 ##########
 File path: be/src/exec/orc_scanner.h
 ##########
 @@ -0,0 +1,144 @@
+// 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.
+
+#ifndef ORC_SCANNER_H
+#define ORC_SCANNER_H
+
+#include <memory>
+#include <vector>
+#include <string>
+#include <map>
+#include <sstream>
+#include <orc/OrcFile.hh>
+
+#include "exec/base_scanner.h"
+#include "exec/file_reader.h"
+#include "common/status.h"
+#include "gen_cpp/PlanNodes_types.h"
+#include "gen_cpp/Types_types.h"
+#include "runtime/mem_pool.h"
+#include "runtime/row_batch.h"
+#include "runtime/tuple.h"
+#include "util/slice.h"
+#include "util/runtime_profile.h"
+
+namespace doris {
+
+class FileReader;
+class Tuple;
+class SlotDescriptor;
+class Slice;
+class ParquetReaderWrap;
+class RuntimeState;
+class ExprContext;
+class TupleDescriptor;
+class TupleRow;
+class RowDescriptor;
+class MemTracker;
+class RuntimeProfile;
+class StreamLoadPipe;
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(filename) {
+    }
+
+    ~ORCFileStream();
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const;
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const;
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+    void read(void *buf, uint64_t length, uint64_t offset);
+
+    /**
+     * Get the name of the stream for error messages.
+     */
+    const std::string& getName() const;
+
+private:
+    FileReader *_file;
+    std::string _filename;
+};
+
+// Broker scanner convert the data read from broker to doris's tuple.
+class ORCScanner : public BaseScanner {
+public:
+    ORCScanner(RuntimeState *state,
+               RuntimeProfile *profile,
+               const TBrokerScanRangeParams& params,
+               const std::vector<TBrokerRangeDesc>& ranges,
+               const std::vector<TNetworkAddress>& broker_addresses, ScannerCounter *counter);
+
+    ~ORCScanner();
 
 Review comment:
   ```suggestion
       ~ORCScanner() override;
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361907394
 
 

 ##########
 File path: be/src/exec/orc_scanner.h
 ##########
 @@ -0,0 +1,144 @@
+// 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.
+
+#ifndef ORC_SCANNER_H
+#define ORC_SCANNER_H
+
+#include <memory>
+#include <vector>
+#include <string>
+#include <map>
+#include <sstream>
+#include <orc/OrcFile.hh>
+
+#include "exec/base_scanner.h"
+#include "exec/file_reader.h"
+#include "common/status.h"
+#include "gen_cpp/PlanNodes_types.h"
+#include "gen_cpp/Types_types.h"
+#include "runtime/mem_pool.h"
+#include "runtime/row_batch.h"
+#include "runtime/tuple.h"
+#include "util/slice.h"
+#include "util/runtime_profile.h"
 
 Review comment:
   Does all of these files should be included here?
   Better to use forward declaration than include.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361155167
 
 

 ##########
 File path: be/src/exec/orc_scanner.h
 ##########
 @@ -0,0 +1,178 @@
+// 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.
+
+#ifndef ORC_SCANNER_H
+#define ORC_SCANNER_H
+
+#include <memory>
+#include <vector>
+#include <string>
+#include <map>
+#include <sstream>
+
+#include "exec/base_scanner.h"
+#include "exec/file_reader.h"
+#include "common/status.h"
+#include "gen_cpp/PlanNodes_types.h"
+#include "gen_cpp/Types_types.h"
+#include "runtime/mem_pool.h"
+#include "runtime/row_batch.h"
+#include "runtime/tuple.h"
+#include "util/slice.h"
+#include "util/runtime_profile.h"
+#include "orc/OrcFile.hh"
+
+namespace doris {
+
+class FileReader;
+class Tuple;
+class SlotDescriptor;
+class Slice;
+class ParquetReaderWrap;
+class RuntimeState;
+class ExprContext;
+class TupleDescriptor;
+class TupleRow;
+class RowDescriptor;
+class MemTracker;
+class RuntimeProfile;
+class StreamLoadPipe;
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(filename) {
+    }
+
+    ~ORCFileStream() {
+        if (_file) {
+            _file->close();
+            delete _file;
+            _file = nullptr;
+        }
+    }
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const {
+        return _file->size();
+    }
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const {
+        return 128 * 1024;
+    }
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+     void 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));
+        }
+    }
+
+    /**
+     * Get the name of the stream for error messages.
+     */
+    const std::string &getName() const {
+        return _filename;
+    }
+
+private:
+    FileReader *_file;
+    std::string _filename;
+};
+// Broker scanner convert the data read from broker to doris's tuple.
+class ORCScanner : public BaseScanner {
+public:
+    ORCScanner(RuntimeState* state,
+    RuntimeProfile *profile,
+    const TBrokerScanRangeParams &params,
 
 Review comment:
   ```suggestion
       const TBrokerScanRangeParams& params,
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] HangyuanLiu commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
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_r363262803
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,328 @@
+// 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 "exec/broker_reader.h"
+#include "exec/local_file_reader.h"
+#include "exprs/expr.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"
+
+namespace doris {
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(std::move(filename)) {
+    }
+
+    ~ORCFileStream() override {
+        if (_file) {
+            _file->close();
+            delete _file;
+            _file = nullptr;
+        }
+    }
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const override {
+        return _file->size();
+    }
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const override {
+        return 128 * 1024;
+    }
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+    void read(void *buf, uint64_t length, uint64_t offset) override {
+        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));
+        }
+    }
+
+    /**
+     * Get the name of the stream for error messages.
+     */
+    const std::string &getName() const override {
+        return _filename;
+    }
+private:
+    FileReader *_file;
+    std::string _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];
+                orc::ColumnVectorBatch *cvb = batch_vec[_position_in_orc_original[column_ipos]];
+
+                if (cvb->hasNulls && !cvb->notNull[_current_line_of_group]) {
+                    //all src tuple is nullable , judge null in dest_tuple
+                    _src_tuple->set_null(slot_desc->null_indicator_offset());
+                } else {
+                    int32_t wbytes = 0;
+                    uint8_t tmp_buf[128] = {0};
+                    _src_tuple->set_not_null(slot_desc->null_indicator_offset());
+                    void *slot = _src_tuple->get_slot(slot_desc->tuple_offset());
+                    StringValue *str_slot = reinterpret_cast<StringValue *>(slot);
+
+                    switch (_row_reader->getSelectedType().getSubtype(_position_in_orc_original[column_ipos])->getKind()) {
+                        case orc::BOOLEAN: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            if (value == 0) {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(5));
+                                memcpy(str_slot->ptr, "false", 5);
+                                str_slot->len = 5;
+                            } else {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(4));
+                                memcpy(str_slot->ptr, "true", 4);
+                                str_slot->len = 4;
+                            }
+                            break;
+                        }
+                        case orc::INT:
+                        case orc::SHORT:
+                        case orc::LONG:
+                        case orc::DATE: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%ld", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::FLOAT:
+                        case orc::DOUBLE: {
+                            double value = ((orc::DoubleVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%f", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::BINARY:
+                        case orc::CHAR:
+                        case orc::VARCHAR:
+                        case orc::STRING: {
+                            char *value = ((orc::StringVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = ((orc::StringVectorBatch *) cvb)->length[_current_line_of_group];
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, value, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                            //TODO (lhy) : support more orc type
+                        case orc::TIMESTAMP:
+                        case orc::DECIMAL:
+                        default: {
+                            std::stringstream str_error;
+                            str_error << "The field name(" << slot_desc->col_name() << ") type not support. ";
+                            LOG(WARNING) << str_error.str();
+                            return Status::InternalError(str_error.str());
+                        }
+                    }
+                }
+            }
+            ++_current_line_of_group;
+
+            // range of current file
+            const TBrokerRangeDesc &range = _ranges.at(_next_range - 1);
+            if (range.__isset.num_of_columns_from_file) {
+                fill_slots_of_columns_from_path(range.num_of_columns_from_file, range.columns_from_path);
+            }
+            COUNTER_UPDATE(_rows_read_counter, 1);
+            SCOPED_TIMER(_materialize_timer);
+            if (fill_dest_tuple(Slice(), tuple, tuple_pool)) {
+                break; // get one line, break from while
+            } // else skip this line and continue get_next to return
+        }
+        return Status::OK();
+    } catch (orc::ParseError &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    } catch (orc::InvalidArgument &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    }
+}
+
+Status ORCScanner::open_next_reader() {
+    while (true) {
+        if (_next_range >= _ranges.size()) {
+            _scanner_eof = true;
+            return Status::OK();
+        }
+        const TBrokerRangeDesc &range = _ranges[_next_range++];
+        std::unique_ptr<FileReader> file_reader;
+        switch (range.file_type) {
+            case TFileType::FILE_LOCAL: {
+                file_reader.reset(new LocalFileReader(range.path, range.start_offset));
+                break;
+            }
+            case TFileType::FILE_BROKER: {
+                int64_t file_size = 0;
+                // for compatibility
+                if (range.__isset.file_size) { file_size = range.file_size; }
+                file_reader.reset(new BrokerReader(_state->exec_env(), _broker_addresses, _params.properties,
+                                                   range.path, range.start_offset, file_size));
+                break;
+            }
+            default: {
+                std::stringstream ss;
+                ss << "Unknown file type, type=" << range.file_type;
+                return Status::InternalError(ss.str());
+            }
+        }
+        RETURN_IF_ERROR(file_reader->open());
+        if (file_reader->size() == 0) {
+            file_reader->close();
+            continue;
+        }
+
+        std::unique_ptr<orc::InputStream> inStream = std::unique_ptr<orc::InputStream>(
+                new ORCFileStream(file_reader.release(), range.path));
+        _reader = orc::createReader(std::move(inStream), _options);
+
+        _total_groups = _reader->getNumberOfStripes();
+        _current_group = 0;
+        _rows_of_group = 0;
+        _current_line_of_group = 0;
+
+        _includes.clear();
+        _num_of_columns_from_file =
+                range.__isset.num_of_columns_from_file ? range.num_of_columns_from_file : _src_slot_descs.size();
+        for (int i = 0; i < _num_of_columns_from_file; i++) {
+            auto slot_desc = _src_slot_descs.at(i);
+            _includes.push_back(slot_desc->col_name());
+        }
+        _rowReaderOptions.include(_includes);
 
 Review comment:
   Consider that different files may not have exactly the same format in the same directory, so I judge it when  open  file

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay merged pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay merged pull request #2554: Support load orc format in Apache Doris
URL: https://github.com/apache/incubator-doris/pull/2554
 
 
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361154774
 
 

 ##########
 File path: be/src/exec/orc_scanner.h
 ##########
 @@ -0,0 +1,178 @@
+// 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.
+
+#ifndef ORC_SCANNER_H
+#define ORC_SCANNER_H
+
+#include <memory>
+#include <vector>
+#include <string>
+#include <map>
+#include <sstream>
+
+#include "exec/base_scanner.h"
+#include "exec/file_reader.h"
+#include "common/status.h"
+#include "gen_cpp/PlanNodes_types.h"
+#include "gen_cpp/Types_types.h"
+#include "runtime/mem_pool.h"
+#include "runtime/row_batch.h"
+#include "runtime/tuple.h"
+#include "util/slice.h"
+#include "util/runtime_profile.h"
+#include "orc/OrcFile.hh"
+
+namespace doris {
+
+class FileReader;
+class Tuple;
+class SlotDescriptor;
+class Slice;
+class ParquetReaderWrap;
+class RuntimeState;
+class ExprContext;
+class TupleDescriptor;
+class TupleRow;
+class RowDescriptor;
+class MemTracker;
+class RuntimeProfile;
+class StreamLoadPipe;
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(filename) {
+    }
+
+    ~ORCFileStream() {
+        if (_file) {
+            _file->close();
+            delete _file;
+            _file = nullptr;
+        }
+    }
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const {
+        return _file->size();
+    }
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const {
+        return 128 * 1024;
+    }
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+     void 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));
+        }
+    }
+
+    /**
+     * Get the name of the stream for error messages.
+     */
+    const std::string &getName() const {
+        return _filename;
+    }
+
+private:
+    FileReader *_file;
+    std::string _filename;
+};
+// Broker scanner convert the data read from broker to doris's tuple.
+class ORCScanner : public BaseScanner {
+public:
+    ORCScanner(RuntimeState* state,
+    RuntimeProfile *profile,
+    const TBrokerScanRangeParams &params,
+    const std::vector<TBrokerRangeDesc> &ranges,
+    const std::vector<TNetworkAddress> &broker_addresses,ScannerCounter* counter);
+
+    ~ORCScanner();
+
+    // Open this scanner, will initialize information need to
+    virtual Status open();
+
+    // Get next tuple
+    virtual Status get_next(Tuple *tuple, MemPool *tuple_pool, bool *eof);
+
+    // Close this scanner
+    virtual void close();
+
+private:
+    // Read next buffer from reader
+    Status open_next_reader();
+
+private:
+    const std::vector<TBrokerRangeDesc> &_ranges;
+    const std::vector<TNetworkAddress> &_broker_addresses;
+
+    // Reader
+    int _next_range;
+    bool _cur_file_eof;
+    bool _scanner_eof;
+
+    // orc file reader object
+    orc::ReaderOptions _options;
+    orc::RowReaderOptions _rowReaderOptions;
+    std::shared_ptr<orc::ColumnVectorBatch> _batch;
+    std::unique_ptr<orc::Reader> _reader;
+    std::unique_ptr<orc::RowReader> _row_reader;
+    std::list<std::string> _includes; // include columns in orc file
+    // The batch after reading from orc data is arranged in the original order,
+    // so we need to record the index in the original order to correspond the column names to the order
+    std::map<std::string, int> _column_name_map_orc_index;
+    int _num_of_columns_from_file;
+
+    int _total_groups; // groups in a orc file
+    int _current_group;
+    int _rows_of_group; // rows in a group.
+    int _current_line_of_group;
 
 Review comment:
   all the members should be given a default value when constructing

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] HangyuanLiu commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
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_r361423429
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,261 @@
+// 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/tuple.h"
+#include "exprs/expr.h"
+#include "exec/text_converter.h"
+#include "exec/text_converter.hpp"
+#include "exec/local_file_reader.h"
+#include "exec/broker_reader.h"
+
+namespace doris {
+
+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) {}
+
+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();
+                std::cout << "rows of group "<< _rows_of_group << std::endl;
+                _batch = _row_reader->createRowBatch(_rows_of_group);
+                _row_reader->next(*_batch.get());
+
+                _current_line_of_group = 0;
+                ++_current_group;
+            }
+
+            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];
+                orc::ColumnVectorBatch *cvb = _batch_vec[_column_name_map_orc_index.find(
+                        slot_desc->col_name())->second];
+
+                if (cvb->hasNulls && !cvb->notNull[_current_line_of_group]) {
+                    if (!slot_desc->is_nullable()) {
+                        std::stringstream str_error;
+                        str_error << "The field name(" << slot_desc->col_name()
+                                  << ") is not allowed null, but ORC field is NULL.";
+                        LOG(WARNING) << str_error.str();
+                        return Status::RuntimeError(str_error.str());
+                    }
+                    _src_tuple->set_null(slot_desc->null_indicator_offset());
+                } else {
+                    int32_t wbytes = 0;
+                    uint8_t tmp_buf[128] = {0};
+                    _src_tuple->set_not_null(slot_desc->null_indicator_offset());
 
 Review comment:
   all src tuple is nullable , so we judge null in dest_tuple and report error row

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361907949
 
 

 ##########
 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:
   we do this map find for each fields of each row, I think it is bad for performance.
   Because the column handle serial is the same for every row, we can get the positition vector when preparing.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] HangyuanLiu commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
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_r363262986
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,328 @@
+// 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 "exec/broker_reader.h"
+#include "exec/local_file_reader.h"
+#include "exprs/expr.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"
+
+namespace doris {
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(std::move(filename)) {
+    }
+
+    ~ORCFileStream() override {
+        if (_file) {
+            _file->close();
+            delete _file;
+            _file = nullptr;
+        }
+    }
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const override {
+        return _file->size();
+    }
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const override {
+        return 128 * 1024;
+    }
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+    void read(void *buf, uint64_t length, uint64_t offset) override {
+        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));
+        }
+    }
+
+    /**
+     * Get the name of the stream for error messages.
+     */
+    const std::string &getName() const override {
+        return _filename;
+    }
+private:
+    FileReader *_file;
+    std::string _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];
+                orc::ColumnVectorBatch *cvb = batch_vec[_position_in_orc_original[column_ipos]];
+
+                if (cvb->hasNulls && !cvb->notNull[_current_line_of_group]) {
+                    //all src tuple is nullable , judge null in dest_tuple
+                    _src_tuple->set_null(slot_desc->null_indicator_offset());
+                } else {
+                    int32_t wbytes = 0;
+                    uint8_t tmp_buf[128] = {0};
+                    _src_tuple->set_not_null(slot_desc->null_indicator_offset());
+                    void *slot = _src_tuple->get_slot(slot_desc->tuple_offset());
+                    StringValue *str_slot = reinterpret_cast<StringValue *>(slot);
+
+                    switch (_row_reader->getSelectedType().getSubtype(_position_in_orc_original[column_ipos])->getKind()) {
+                        case orc::BOOLEAN: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            if (value == 0) {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(5));
+                                memcpy(str_slot->ptr, "false", 5);
+                                str_slot->len = 5;
+                            } else {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(4));
+                                memcpy(str_slot->ptr, "true", 4);
+                                str_slot->len = 4;
+                            }
+                            break;
+                        }
+                        case orc::INT:
+                        case orc::SHORT:
+                        case orc::LONG:
+                        case orc::DATE: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%ld", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::FLOAT:
+                        case orc::DOUBLE: {
+                            double value = ((orc::DoubleVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%f", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::BINARY:
+                        case orc::CHAR:
+                        case orc::VARCHAR:
+                        case orc::STRING: {
+                            char *value = ((orc::StringVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = ((orc::StringVectorBatch *) cvb)->length[_current_line_of_group];
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, value, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                            //TODO (lhy) : support more orc type
+                        case orc::TIMESTAMP:
+                        case orc::DECIMAL:
+                        default: {
+                            std::stringstream str_error;
+                            str_error << "The field name(" << slot_desc->col_name() << ") type not support. ";
+                            LOG(WARNING) << str_error.str();
+                            return Status::InternalError(str_error.str());
+                        }
+                    }
+                }
+            }
+            ++_current_line_of_group;
+
+            // range of current file
+            const TBrokerRangeDesc &range = _ranges.at(_next_range - 1);
+            if (range.__isset.num_of_columns_from_file) {
+                fill_slots_of_columns_from_path(range.num_of_columns_from_file, range.columns_from_path);
+            }
+            COUNTER_UPDATE(_rows_read_counter, 1);
+            SCOPED_TIMER(_materialize_timer);
+            if (fill_dest_tuple(Slice(), tuple, tuple_pool)) {
+                break; // get one line, break from while
+            } // else skip this line and continue get_next to return
+        }
+        return Status::OK();
+    } catch (orc::ParseError &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    } catch (orc::InvalidArgument &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    }
+}
+
+Status ORCScanner::open_next_reader() {
+    while (true) {
+        if (_next_range >= _ranges.size()) {
+            _scanner_eof = true;
+            return Status::OK();
+        }
+        const TBrokerRangeDesc &range = _ranges[_next_range++];
+        std::unique_ptr<FileReader> file_reader;
+        switch (range.file_type) {
+            case TFileType::FILE_LOCAL: {
+                file_reader.reset(new LocalFileReader(range.path, range.start_offset));
+                break;
+            }
+            case TFileType::FILE_BROKER: {
+                int64_t file_size = 0;
+                // for compatibility
+                if (range.__isset.file_size) { file_size = range.file_size; }
+                file_reader.reset(new BrokerReader(_state->exec_env(), _broker_addresses, _params.properties,
+                                                   range.path, range.start_offset, file_size));
+                break;
+            }
+            default: {
+                std::stringstream ss;
+                ss << "Unknown file type, type=" << range.file_type;
+                return Status::InternalError(ss.str());
+            }
+        }
+        RETURN_IF_ERROR(file_reader->open());
+        if (file_reader->size() == 0) {
+            file_reader->close();
+            continue;
+        }
+
+        std::unique_ptr<orc::InputStream> inStream = std::unique_ptr<orc::InputStream>(
+                new ORCFileStream(file_reader.release(), range.path));
+        _reader = orc::createReader(std::move(inStream), _options);
+
+        _total_groups = _reader->getNumberOfStripes();
+        _current_group = 0;
+        _rows_of_group = 0;
+        _current_line_of_group = 0;
+
+        _includes.clear();
+        _num_of_columns_from_file =
+                range.__isset.num_of_columns_from_file ? range.num_of_columns_from_file : _src_slot_descs.size();
+        for (int i = 0; i < _num_of_columns_from_file; i++) {
+            auto slot_desc = _src_slot_descs.at(i);
+            _includes.push_back(slot_desc->col_name());
+        }
+        _rowReaderOptions.include(_includes);
+
+        int orc_index = 0;
+        std::map<std::string, int> column_name_map_orc_index;
+        for (int i = 0; i < _reader->getType().getSubtypeCount(); ++i) {
+            if (std::find(_includes.begin(), _includes.end(), _reader->getType().getFieldName(i)) != _includes.end()) {
+                column_name_map_orc_index.emplace(_reader->getType().getFieldName(i), orc_index++);
+            }
 
 Review comment:
   include columns must in reader field, otherwise createRowReader will throw exception

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r363145420
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,328 @@
+// 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 "exec/broker_reader.h"
+#include "exec/local_file_reader.h"
+#include "exprs/expr.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"
+
+namespace doris {
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(std::move(filename)) {
+    }
+
+    ~ORCFileStream() override {
+        if (_file) {
+            _file->close();
+            delete _file;
+            _file = nullptr;
+        }
+    }
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const override {
+        return _file->size();
+    }
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const override {
+        return 128 * 1024;
+    }
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+    void read(void *buf, uint64_t length, uint64_t offset) override {
+        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));
+        }
+    }
+
+    /**
+     * Get the name of the stream for error messages.
+     */
+    const std::string &getName() const override {
+        return _filename;
+    }
+private:
+    FileReader *_file;
+    std::string _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];
+                orc::ColumnVectorBatch *cvb = batch_vec[_position_in_orc_original[column_ipos]];
+
+                if (cvb->hasNulls && !cvb->notNull[_current_line_of_group]) {
+                    //all src tuple is nullable , judge null in dest_tuple
+                    _src_tuple->set_null(slot_desc->null_indicator_offset());
+                } else {
+                    int32_t wbytes = 0;
+                    uint8_t tmp_buf[128] = {0};
+                    _src_tuple->set_not_null(slot_desc->null_indicator_offset());
+                    void *slot = _src_tuple->get_slot(slot_desc->tuple_offset());
+                    StringValue *str_slot = reinterpret_cast<StringValue *>(slot);
+
+                    switch (_row_reader->getSelectedType().getSubtype(_position_in_orc_original[column_ipos])->getKind()) {
+                        case orc::BOOLEAN: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            if (value == 0) {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(5));
+                                memcpy(str_slot->ptr, "false", 5);
+                                str_slot->len = 5;
+                            } else {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(4));
+                                memcpy(str_slot->ptr, "true", 4);
+                                str_slot->len = 4;
+                            }
+                            break;
+                        }
+                        case orc::INT:
+                        case orc::SHORT:
+                        case orc::LONG:
+                        case orc::DATE: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%ld", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::FLOAT:
+                        case orc::DOUBLE: {
+                            double value = ((orc::DoubleVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%f", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::BINARY:
+                        case orc::CHAR:
+                        case orc::VARCHAR:
+                        case orc::STRING: {
+                            char *value = ((orc::StringVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = ((orc::StringVectorBatch *) cvb)->length[_current_line_of_group];
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, value, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                            //TODO (lhy) : support more orc type
+                        case orc::TIMESTAMP:
+                        case orc::DECIMAL:
+                        default: {
+                            std::stringstream str_error;
+                            str_error << "The field name(" << slot_desc->col_name() << ") type not support. ";
+                            LOG(WARNING) << str_error.str();
+                            return Status::InternalError(str_error.str());
+                        }
+                    }
+                }
+            }
+            ++_current_line_of_group;
+
+            // range of current file
+            const TBrokerRangeDesc &range = _ranges.at(_next_range - 1);
+            if (range.__isset.num_of_columns_from_file) {
+                fill_slots_of_columns_from_path(range.num_of_columns_from_file, range.columns_from_path);
+            }
+            COUNTER_UPDATE(_rows_read_counter, 1);
+            SCOPED_TIMER(_materialize_timer);
+            if (fill_dest_tuple(Slice(), tuple, tuple_pool)) {
+                break; // get one line, break from while
+            } // else skip this line and continue get_next to return
+        }
+        return Status::OK();
+    } catch (orc::ParseError &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    } catch (orc::InvalidArgument &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    }
+}
+
+Status ORCScanner::open_next_reader() {
+    while (true) {
+        if (_next_range >= _ranges.size()) {
+            _scanner_eof = true;
+            return Status::OK();
+        }
+        const TBrokerRangeDesc &range = _ranges[_next_range++];
+        std::unique_ptr<FileReader> file_reader;
+        switch (range.file_type) {
+            case TFileType::FILE_LOCAL: {
+                file_reader.reset(new LocalFileReader(range.path, range.start_offset));
+                break;
+            }
+            case TFileType::FILE_BROKER: {
+                int64_t file_size = 0;
+                // for compatibility
+                if (range.__isset.file_size) { file_size = range.file_size; }
+                file_reader.reset(new BrokerReader(_state->exec_env(), _broker_addresses, _params.properties,
+                                                   range.path, range.start_offset, file_size));
+                break;
+            }
+            default: {
+                std::stringstream ss;
+                ss << "Unknown file type, type=" << range.file_type;
+                return Status::InternalError(ss.str());
+            }
+        }
+        RETURN_IF_ERROR(file_reader->open());
+        if (file_reader->size() == 0) {
+            file_reader->close();
+            continue;
+        }
+
+        std::unique_ptr<orc::InputStream> inStream = std::unique_ptr<orc::InputStream>(
+                new ORCFileStream(file_reader.release(), range.path));
+        _reader = orc::createReader(std::move(inStream), _options);
+
+        _total_groups = _reader->getNumberOfStripes();
+        _current_group = 0;
+        _rows_of_group = 0;
+        _current_line_of_group = 0;
+
+        _includes.clear();
+        _num_of_columns_from_file =
+                range.__isset.num_of_columns_from_file ? range.num_of_columns_from_file : _src_slot_descs.size();
+        for (int i = 0; i < _num_of_columns_from_file; i++) {
+            auto slot_desc = _src_slot_descs.at(i);
+            _includes.push_back(slot_desc->col_name());
+        }
+        _rowReaderOptions.include(_includes);
+
+        int orc_index = 0;
+        std::map<std::string, int> column_name_map_orc_index;
+        for (int i = 0; i < _reader->getType().getSubtypeCount(); ++i) {
+            if (std::find(_includes.begin(), _includes.end(), _reader->getType().getFieldName(i)) != _includes.end()) {
 
 Review comment:
   you can fill _position_in_orc_original directly.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] HangyuanLiu commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
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_r361423691
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,261 @@
+// 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/tuple.h"
+#include "exprs/expr.h"
+#include "exec/text_converter.h"
+#include "exec/text_converter.hpp"
+#include "exec/local_file_reader.h"
+#include "exec/broker_reader.h"
+
+namespace doris {
+
+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) {}
+
+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();
+                std::cout << "rows of group "<< _rows_of_group << std::endl;
+                _batch = _row_reader->createRowBatch(_rows_of_group);
+                _row_reader->next(*_batch.get());
+
+                _current_line_of_group = 0;
+                ++_current_group;
+            }
+
+            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];
+                orc::ColumnVectorBatch *cvb = _batch_vec[_column_name_map_orc_index.find(
+                        slot_desc->col_name())->second];
+
+                if (cvb->hasNulls && !cvb->notNull[_current_line_of_group]) {
+                    if (!slot_desc->is_nullable()) {
+                        std::stringstream str_error;
+                        str_error << "The field name(" << slot_desc->col_name()
+                                  << ") is not allowed null, but ORC field is NULL.";
+                        LOG(WARNING) << str_error.str();
+                        return Status::RuntimeError(str_error.str());
+                    }
+                    _src_tuple->set_null(slot_desc->null_indicator_offset());
+                } else {
+                    int32_t wbytes = 0;
+                    uint8_t tmp_buf[128] = {0};
+                    _src_tuple->set_not_null(slot_desc->null_indicator_offset());
+                    void *slot = _src_tuple->get_slot(slot_desc->tuple_offset());
+                    StringValue *str_slot = reinterpret_cast<StringValue *>(slot);
+
+                    switch (_reader->getType().getSubtype(column_ipos)->getKind()) {
+                        case orc::BOOLEAN: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            if (value == 0) {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(5));
+                                memcpy(str_slot->ptr, "false", 5);
+                                str_slot->len = 5;
+                            } else {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(4));
+                                memcpy(str_slot->ptr, "true", 4);
+                                str_slot->len = 4;
+                            }
+                            break;
+                        }
+                        case orc::INT:
+                        case orc::SHORT:
+                        case orc::LONG:
+                        case orc::DATE: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            std::cout << "value : " << value << std::endl;
+                            wbytes = sprintf((char *) tmp_buf, "%ld", value);
 
 Review comment:
   orc::DATE is only day such as "20191111" , date time type is orc::TIMESTAMP. I will support in next PR

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r361155735
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,261 @@
+// 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/tuple.h"
+#include "exprs/expr.h"
+#include "exec/text_converter.h"
+#include "exec/text_converter.hpp"
+#include "exec/local_file_reader.h"
+#include "exec/broker_reader.h"
+
+namespace doris {
+
+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) {}
+
+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();
+                std::cout << "rows of group "<< _rows_of_group << std::endl;
+                _batch = _row_reader->createRowBatch(_rows_of_group);
+                _row_reader->next(*_batch.get());
+
+                _current_line_of_group = 0;
+                ++_current_group;
+            }
+
+            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];
+                orc::ColumnVectorBatch *cvb = _batch_vec[_column_name_map_orc_index.find(
+                        slot_desc->col_name())->second];
+
+                if (cvb->hasNulls && !cvb->notNull[_current_line_of_group]) {
+                    if (!slot_desc->is_nullable()) {
+                        std::stringstream str_error;
+                        str_error << "The field name(" << slot_desc->col_name()
+                                  << ") is not allowed null, but ORC field is NULL.";
+                        LOG(WARNING) << str_error.str();
+                        return Status::RuntimeError(str_error.str());
+                    }
+                    _src_tuple->set_null(slot_desc->null_indicator_offset());
+                } else {
+                    int32_t wbytes = 0;
+                    uint8_t tmp_buf[128] = {0};
+                    _src_tuple->set_not_null(slot_desc->null_indicator_offset());
+                    void *slot = _src_tuple->get_slot(slot_desc->tuple_offset());
+                    StringValue *str_slot = reinterpret_cast<StringValue *>(slot);
+
+                    switch (_reader->getType().getSubtype(column_ipos)->getKind()) {
+                        case orc::BOOLEAN: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            if (value == 0) {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(5));
+                                memcpy(str_slot->ptr, "false", 5);
+                                str_slot->len = 5;
+                            } else {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(4));
+                                memcpy(str_slot->ptr, "true", 4);
+                                str_slot->len = 4;
+                            }
+                            break;
+                        }
+                        case orc::INT:
+                        case orc::SHORT:
+                        case orc::LONG:
+                        case orc::DATE: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            std::cout << "value : " << value << std::endl;
+                            wbytes = sprintf((char *) tmp_buf, "%ld", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::FLOAT:
+                        case orc::DOUBLE: {
+                            double value = ((orc::DoubleVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%f", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::BINARY:
+                        case orc::CHAR:
+                        case orc::VARCHAR:
+                        case orc::STRING: {
+                            char *value = ((orc::StringVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = ((orc::StringVectorBatch *) cvb)->length[_current_line_of_group];
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, value, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        //TODO (lhy) : support more orc type
+                        case orc::TIMESTAMP:
+                        case orc::DECIMAL:
+                        default: {
+                            std::stringstream str_error;
+                            str_error << "The field name(" << slot_desc->col_name() << ") type not support. ";
+                            LOG(WARNING) << str_error.str();
+                            return Status::InternalError(str_error.str());
+                        }
+                    }
+                }
+            }
+            ++_current_line_of_group;
+
+            // range of current file
+            const TBrokerRangeDesc &range = _ranges.at(_next_range - 1);
+            if (range.__isset.num_of_columns_from_file) {
+                fill_slots_of_columns_from_path(range.num_of_columns_from_file, range.columns_from_path);
+            }
+            COUNTER_UPDATE(_rows_read_counter, 1);
+            SCOPED_TIMER(_materialize_timer);
+            if (!fill_dest_tuple(Slice(), tuple, tuple_pool)) {
+                std::stringstream str_error;
+                str_error << "fill_dest_tuple error";
+                LOG(WARNING) << str_error.str();
+                return Status::InternalError(str_error.str());
+            }
+            break; // get one line, break from while
+        }
+        return Status::OK();
+    } catch (orc::ParseError& e) {
+        std::stringstream str_error;
+        str_error <<"ParseError : "<<  e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    } catch (orc::InvalidArgument& e) {
+        std::stringstream str_error;
+        str_error <<"ParseError : "<<  e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    }
+}
+
+Status ORCScanner::open_next_reader() {
+    while (true) {
+        if (_next_range >= _ranges.size()) {
+            _scanner_eof = true;
+            return Status::OK();
+        }
+        const TBrokerRangeDesc &range = _ranges[_next_range++];
+        std::unique_ptr<FileReader> file_reader;
+        switch (range.file_type) {
+            case TFileType::FILE_LOCAL: {
+                file_reader.reset(new LocalFileReader(range.path, range.start_offset));
+                break;
+            }
+            case TFileType::FILE_BROKER: {
+                int64_t file_size = 0;
+                // for compatibility
+                if (range.__isset.file_size) { file_size = range.file_size; }
+                file_reader.reset(new BrokerReader(_state->exec_env(), _broker_addresses, _params.properties,
+                                                   range.path, range.start_offset, file_size));
+                break;
+            }
+            default: {
+                std::stringstream ss;
+                ss << "Unknown file type, type=" << range.file_type;
+                return Status::InternalError(ss.str());
+            }
+        }
+        RETURN_IF_ERROR(file_reader->open());
+        if (file_reader->size() == 0) {
+            file_reader->close();
+            continue;
+        }
+
+        std::unique_ptr<orc::InputStream> inStream = std::unique_ptr<orc::InputStream>(new ORCFileStream(file_reader.release(), range.path));
+        _reader = orc::createReader(std::move(inStream), _options);
+
+        _total_groups = _reader->getNumberOfStripes();
+        _current_group = 0;
+        _rows_of_group = 0;
+        _current_line_of_group = 0;
+
+        _includes.clear();
+        _num_of_columns_from_file =
+                range.__isset.num_of_columns_from_file ? range.num_of_columns_from_file : _src_slot_descs.size();
+        for (int i = 0; i < _num_of_columns_from_file; i++) {
+            auto slot_desc = _src_slot_descs.at(i);
+            _includes.push_back(slot_desc->col_name());
+        }
+        _rowReaderOptions.include(_includes);
+
+        std::vector<std::string> orc_file_columns;
+        int orc_index = 0;
+        for (int i = 0; i < _reader->getType().getSubtypeCount(); ++i) {
+            if(std::find(_includes.begin(), _includes.end(), _reader->getType().getFieldName(i)) != _includes.end()) {
 
 Review comment:
   ```suggestion
               if( std::find(_includes.begin(), _includes.end(), _reader->getType().getFieldName(i)) != _includes.end()) {
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] imay commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
imay 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_r363145284
 
 

 ##########
 File path: be/src/exec/orc_scanner.cpp
 ##########
 @@ -0,0 +1,328 @@
+// 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 "exec/broker_reader.h"
+#include "exec/local_file_reader.h"
+#include "exprs/expr.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"
+
+namespace doris {
+
+class ORCFileStream : public orc::InputStream {
+public:
+    ORCFileStream(FileReader *file, std::string filename) : _file(file), _filename(std::move(filename)) {
+    }
+
+    ~ORCFileStream() override {
+        if (_file) {
+            _file->close();
+            delete _file;
+            _file = nullptr;
+        }
+    }
+
+    /**
+     * Get the total length of the file in bytes.
+     */
+    uint64_t getLength() const override {
+        return _file->size();
+    }
+
+    /**
+     * Get the natural size for reads.
+     * @return the number of bytes that should be read at once
+     */
+    uint64_t getNaturalReadSize() const override {
+        return 128 * 1024;
+    }
+
+    /**
+     * Read length bytes from the file starting at offset into
+     * the buffer starting at buf.
+     * @param buf the starting position of a buffer.
+     * @param length the number of bytes to read.
+     * @param offset the position in the stream to read from.
+     */
+    void read(void *buf, uint64_t length, uint64_t offset) override {
+        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));
+        }
+    }
+
+    /**
+     * Get the name of the stream for error messages.
+     */
+    const std::string &getName() const override {
+        return _filename;
+    }
+private:
+    FileReader *_file;
+    std::string _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];
+                orc::ColumnVectorBatch *cvb = batch_vec[_position_in_orc_original[column_ipos]];
+
+                if (cvb->hasNulls && !cvb->notNull[_current_line_of_group]) {
+                    //all src tuple is nullable , judge null in dest_tuple
+                    _src_tuple->set_null(slot_desc->null_indicator_offset());
+                } else {
+                    int32_t wbytes = 0;
+                    uint8_t tmp_buf[128] = {0};
+                    _src_tuple->set_not_null(slot_desc->null_indicator_offset());
+                    void *slot = _src_tuple->get_slot(slot_desc->tuple_offset());
+                    StringValue *str_slot = reinterpret_cast<StringValue *>(slot);
+
+                    switch (_row_reader->getSelectedType().getSubtype(_position_in_orc_original[column_ipos])->getKind()) {
+                        case orc::BOOLEAN: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            if (value == 0) {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(5));
+                                memcpy(str_slot->ptr, "false", 5);
+                                str_slot->len = 5;
+                            } else {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(4));
+                                memcpy(str_slot->ptr, "true", 4);
+                                str_slot->len = 4;
+                            }
+                            break;
+                        }
+                        case orc::INT:
+                        case orc::SHORT:
+                        case orc::LONG:
+                        case orc::DATE: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%ld", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::FLOAT:
+                        case orc::DOUBLE: {
+                            double value = ((orc::DoubleVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%f", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::BINARY:
+                        case orc::CHAR:
+                        case orc::VARCHAR:
+                        case orc::STRING: {
+                            char *value = ((orc::StringVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = ((orc::StringVectorBatch *) cvb)->length[_current_line_of_group];
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, value, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                            //TODO (lhy) : support more orc type
+                        case orc::TIMESTAMP:
+                        case orc::DECIMAL:
+                        default: {
+                            std::stringstream str_error;
+                            str_error << "The field name(" << slot_desc->col_name() << ") type not support. ";
+                            LOG(WARNING) << str_error.str();
+                            return Status::InternalError(str_error.str());
+                        }
+                    }
+                }
+            }
+            ++_current_line_of_group;
+
+            // range of current file
+            const TBrokerRangeDesc &range = _ranges.at(_next_range - 1);
+            if (range.__isset.num_of_columns_from_file) {
+                fill_slots_of_columns_from_path(range.num_of_columns_from_file, range.columns_from_path);
+            }
+            COUNTER_UPDATE(_rows_read_counter, 1);
+            SCOPED_TIMER(_materialize_timer);
+            if (fill_dest_tuple(Slice(), tuple, tuple_pool)) {
+                break; // get one line, break from while
+            } // else skip this line and continue get_next to return
+        }
+        return Status::OK();
+    } catch (orc::ParseError &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    } catch (orc::InvalidArgument &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    }
+}
+
+Status ORCScanner::open_next_reader() {
+    while (true) {
+        if (_next_range >= _ranges.size()) {
+            _scanner_eof = true;
+            return Status::OK();
+        }
+        const TBrokerRangeDesc &range = _ranges[_next_range++];
+        std::unique_ptr<FileReader> file_reader;
+        switch (range.file_type) {
+            case TFileType::FILE_LOCAL: {
+                file_reader.reset(new LocalFileReader(range.path, range.start_offset));
+                break;
+            }
+            case TFileType::FILE_BROKER: {
+                int64_t file_size = 0;
+                // for compatibility
+                if (range.__isset.file_size) { file_size = range.file_size; }
+                file_reader.reset(new BrokerReader(_state->exec_env(), _broker_addresses, _params.properties,
+                                                   range.path, range.start_offset, file_size));
+                break;
+            }
+            default: {
+                std::stringstream ss;
+                ss << "Unknown file type, type=" << range.file_type;
+                return Status::InternalError(ss.str());
+            }
+        }
+        RETURN_IF_ERROR(file_reader->open());
+        if (file_reader->size() == 0) {
+            file_reader->close();
+            continue;
+        }
+
+        std::unique_ptr<orc::InputStream> inStream = std::unique_ptr<orc::InputStream>(
+                new ORCFileStream(file_reader.release(), range.path));
+        _reader = orc::createReader(std::move(inStream), _options);
+
+        _total_groups = _reader->getNumberOfStripes();
+        _current_group = 0;
+        _rows_of_group = 0;
+        _current_line_of_group = 0;
+
+        _includes.clear();
+        _num_of_columns_from_file =
+                range.__isset.num_of_columns_from_file ? range.num_of_columns_from_file : _src_slot_descs.size();
+        for (int i = 0; i < _num_of_columns_from_file; i++) {
+            auto slot_desc = _src_slot_descs.at(i);
+            _includes.push_back(slot_desc->col_name());
+        }
+        _rowReaderOptions.include(_includes);
+
+        int orc_index = 0;
+        std::map<std::string, int> column_name_map_orc_index;
 
 Review comment:
   do we need a map? I think a vector is enough. 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] Wsyzxxn commented on a change in pull request #2554: Support load orc format in Apache Doris

Posted by GitBox <gi...@apache.org>.
Wsyzxxn 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_r361777131
 
 

 ##########
 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;
+                orc::ColumnVectorBatch *cvb = batch_vec[position_in_orc];
+
+                if (cvb->hasNulls && !cvb->notNull[_current_line_of_group]) {
+                    //all src tuple is nullable , judge null in dest_tuple
+                    _src_tuple->set_null(slot_desc->null_indicator_offset());
+                } else {
+                    int32_t wbytes = 0;
+                    uint8_t tmp_buf[128] = {0};
+                    _src_tuple->set_not_null(slot_desc->null_indicator_offset());
+                    void *slot = _src_tuple->get_slot(slot_desc->tuple_offset());
+                    StringValue *str_slot = reinterpret_cast<StringValue *>(slot);
+
+                    switch (_row_reader->getSelectedType().getSubtype(position_in_orc)->getKind()) {
+                        case orc::BOOLEAN: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            if (value == 0) {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(5));
+                                memcpy(str_slot->ptr, "false", 5);
+                                str_slot->len = 5;
+                            } else {
+                                str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(4));
+                                memcpy(str_slot->ptr, "true", 4);
+                                str_slot->len = 4;
+                            }
+                            break;
+                        }
+                        case orc::INT:
+                        case orc::SHORT:
+                        case orc::LONG:
+                        case orc::DATE: {
+                            int64_t value = ((orc::LongVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%ld", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::FLOAT:
+                        case orc::DOUBLE: {
+                            double value = ((orc::DoubleVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = sprintf((char *) tmp_buf, "%f", value);
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, tmp_buf, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                        case orc::BINARY:
+                        case orc::CHAR:
+                        case orc::VARCHAR:
+                        case orc::STRING: {
+                            char *value = ((orc::StringVectorBatch *) cvb)->data[_current_line_of_group];
+                            wbytes = ((orc::StringVectorBatch *) cvb)->length[_current_line_of_group];
+                            str_slot->ptr = reinterpret_cast<char *>(tuple_pool->allocate(wbytes));
+                            memcpy(str_slot->ptr, value, wbytes);
+                            str_slot->len = wbytes;
+                            break;
+                        }
+                            //TODO (lhy) : support more orc type
+                        case orc::TIMESTAMP:
+                        case orc::DECIMAL:
+                        default: {
+                            std::stringstream str_error;
+                            str_error << "The field name(" << slot_desc->col_name() << ") type not support. ";
+                            LOG(WARNING) << str_error.str();
+                            return Status::InternalError(str_error.str());
+                        }
+                    }
+                }
+            }
+            ++_current_line_of_group;
+
+            // range of current file
+            const TBrokerRangeDesc &range = _ranges.at(_next_range - 1);
+            if (range.__isset.num_of_columns_from_file) {
+                fill_slots_of_columns_from_path(range.num_of_columns_from_file, range.columns_from_path);
+            }
+            COUNTER_UPDATE(_rows_read_counter, 1);
+            SCOPED_TIMER(_materialize_timer);
+            if (fill_dest_tuple(Slice(), tuple, tuple_pool)) {
+                break; // get one line, break from while
+            } // else skip this line and continue get_next to return
+        }
+        return Status::OK();
+    } catch (orc::ParseError &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    } catch (orc::InvalidArgument &e) {
+        std::stringstream str_error;
+        str_error << "ParseError : " << e.what();
+        LOG(WARNING) << str_error.str();
+        return Status::InternalError(str_error.str());
+    }
+}
+
+Status ORCScanner::open_next_reader() {
+    while (true) {
+        if (_next_range >= _ranges.size()) {
+            _scanner_eof = true;
+            return Status::OK();
+        }
+        const TBrokerRangeDesc &range = _ranges[_next_range++];
+        std::unique_ptr<FileReader> file_reader;
+        switch (range.file_type) {
+            case TFileType::FILE_LOCAL: {
+                file_reader.reset(new LocalFileReader(range.path, range.start_offset));
+                break;
+            }
+            case TFileType::FILE_BROKER: {
+                int64_t file_size = 0;
+                // for compatibility
+                if (range.__isset.file_size) { file_size = range.file_size; }
+                file_reader.reset(new BrokerReader(_state->exec_env(), _broker_addresses, _params.properties,
+                                                   range.path, range.start_offset, file_size));
+                break;
+            }
+            default: {
+                std::stringstream ss;
+                ss << "Unknown file type, type=" << range.file_type;
+                return Status::InternalError(ss.str());
+            }
+        }
+        RETURN_IF_ERROR(file_reader->open());
+        if (file_reader->size() == 0) {
+            file_reader->close();
+            continue;
+        }
+
+        std::unique_ptr<orc::InputStream> inStream = std::unique_ptr<orc::InputStream>(
+                new ORCFileStream(file_reader.release(), range.path));
+        _reader = orc::createReader(std::move(inStream), _options);
 
 Review comment:
   propose orc file reader add new function to realize,3ks

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org