worker24h commented on a change in pull request #1173: load data from Parquet 
file (Issues #911)
URL: https://github.com/apache/incubator-doris/pull/1173#discussion_r289669326
 
 

 ##########
 File path: be/src/exec/parquet_reader.cpp
 ##########
 @@ -0,0 +1,461 @@
+// 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/parquet_reader.h"
+
+#include <arrow/status.h>
+#include <arrow/array.h>
+#include "exec/file_reader.h"
+#include "common/logging.h"
+#include "gen_cpp/PaloBrokerService_types.h"
+#include "gen_cpp/TPaloBrokerService.h"
+#include "runtime/broker_mgr.h"
+#include "runtime/client_cache.h"
+#include "runtime/exec_env.h"
+#include "util/thrift_util.h"
+#include "runtime/tuple.h"
+#include "runtime/descriptors.h"
+#include "runtime/mem_pool.h"
+
+namespace doris {
+
+// Broker
+
+ParquetReaderWrap::ParquetReaderWrap(FileReader *file_reader) :
+           _total_groups(0), _current_group(0), _rows_of_group(0), 
_current_line_of_group(0) {
+    _parquet = std::shared_ptr<ParquetFile>(new ParquetFile(file_reader));
+    _properties = parquet::ReaderProperties();
+    _properties.enable_buffered_stream();
+    _properties.set_buffer_size(65535);
+}
+
+ParquetReaderWrap::~ParquetReaderWrap() {
+    close();
+}
+
+#ifdef BE_TEST
+inline BrokerServiceClientCache* client_cache(ExecEnv* env) {
+    static BrokerServiceClientCache s_client_cache;
+    return &s_client_cache;
+}
+
+inline const std::string& client_id(ExecEnv* env, const TNetworkAddress& addr) 
{
+    static std::string s_client_id = "doris_unit_test";
+    return s_client_id;
+}
+#else
+inline BrokerServiceClientCache* client_cache(ExecEnv* env) {
+    return env->broker_client_cache();
+}
+
+inline const std::string& client_id(ExecEnv* env, const TNetworkAddress& addr) 
{
+    return env->broker_mgr()->get_client_id(addr);
+}
+#endif
+
+void ParquetReaderWrap::inital_parquet_reader() {
+    //new file reader for parquet file
+    reader.reset(new parquet::arrow::FileReader(arrow::default_memory_pool(),
+            std::move(parquet::ParquetFileReader::Open(_parquet, 
_properties))));
+
+    _file_metadata = reader->parquet_reader()->metadata();
+    // initial members
+    _total_groups = _file_metadata->num_row_groups();
+    _rows_of_group = _file_metadata->RowGroup(0)->num_rows();
+
+    // map
+    const parquet::SchemaDescriptor* schemaDescriptor = 
_file_metadata->schema();
+    for (int i = 0; i < _file_metadata->num_columns(); ++i) {
+        // Get the Column Reader for the boolean column
+        _mapColumn.insert(std::pair<std::string, 
int>(schemaDescriptor->Column(i)->name(), i));
+    }
+
+    column_ids.resize(_file_metadata->num_columns());
+}
+
+void ParquetReaderWrap::close() {
+    _parquet->Close();
+}
+
+Status ParquetReaderWrap::size(int64_t* size) {
+    _parquet->GetSize(size);
+    return Status::OK;
+}
+
+void ParquetReaderWrap::fill_solt(Tuple* tuple, SlotDescriptor* slot_desc, 
MemPool* mem_pool, const uint8_t* value, int32_t len) {
+    if (len != 0) {
+        tuple->set_not_null(slot_desc->null_indicator_offset());
+        void* slot = tuple->get_slot(slot_desc->tuple_offset());
+        StringValue* str_slot = reinterpret_cast<StringValue*>(slot);
+        str_slot->ptr = reinterpret_cast<char*>(mem_pool->allocate(len));
+        memcpy(str_slot->ptr, value, len);
+        str_slot->len = len;
+    }
+    return;
+}
+
+Status ParquetReaderWrap::column_indices(const std::vector<SlotDescriptor*>& 
tuple_slot_descs)
+{
+    for (auto slot_desc : tuple_slot_descs) {
+        // Get the Column Reader for the boolean column
+        auto iter = _mapColumn.find(slot_desc->col_name());
 
 Review comment:
   ok

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