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:
[email protected]


With regards,
Apache Git Services

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

Reply via email to