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 ¶ms, 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org