Github user xunzhang commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq/pull/701#discussion_r66717644
  
    --- Diff: depends/thirdparty/orc/tools/src/HdfsFileMemory.cc ---
    @@ -0,0 +1,151 @@
    +/**
    + * 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 <string>
    +#include <memory>
    +#include <iostream>
    +#include <map>
    +#include <exception>
    +
    +#include "orc/orc-config.hh"
    +#include "orc/ColumnPrinter.hh"
    +#include "Exceptions.hh"
    +
    +#include "wrap/libhdfs3-wrapper.h"
    +
    +class TestMemoryPool: public orc::MemoryPool {
    +private:
    +  std::map<char*, uint64_t> blocks;
    +  uint64_t totalMemory;
    +  uint64_t maxMemory;
    +
    +public:
    +  char* malloc(uint64_t size) override {
    +    char* p = static_cast<char*>(std::malloc(size));
    +    blocks[p] = size ;
    +    totalMemory += size;
    +    if (maxMemory < totalMemory) {
    +      maxMemory = totalMemory;
    +    }
    +    return p;
    +  }
    +
    +  void free(char* p) override {
    +    std::free(p);
    +    totalMemory -= blocks[p] ;
    +    blocks.erase(p);
    +  }
    +
    +  uint64_t getMaxMemory() {
    +    return maxMemory ;
    +  }
    +
    +  TestMemoryPool(): totalMemory(0), maxMemory(0) {}
    +  ~TestMemoryPool();
    +};
    +
    +TestMemoryPool::~TestMemoryPool() {}
    +
    +void processFile(const char* filename,
    +                 const std::list<uint64_t>& cols,
    +                 uint32_t batchSize) {
    +  orc::ReaderOptions opts;
    +  if (cols.size() > 0) {
    +    opts.include(cols);
    +  }
    +  std::unique_ptr<orc::MemoryPool> pool(new TestMemoryPool());
    +  opts.setMemoryPool(*(pool.get()));
    +    
    +  auto addr = std::getenv("LIBHDFS3_NAMENODE_ADDRESS");
    +  std::string nn = "localhost";
    +  if(addr != NULL) {
    +    nn = std::string(addr);
    +  }
    +  auto portStr = std::getenv("LIBHDFS3_NAMENODE_PORT");
    +  tPort port = 8020;
    +  if (portStr != NULL) {
    +    port = static_cast<tPort>(atoi(portStr));
    +  }
    +  hdfsFS fs = hdfsConnect(nn.c_str(), port);
    +
    +  std::unique_ptr<orc::Reader> reader =
    +    orc::createReader(orc::readHdfsFile(fs, std::string(filename)), opts);
    +
    +  std::unique_ptr<orc::ColumnVectorBatch> batch =
    +      reader->createRowBatch(batchSize);
    +  uint64_t readerMemory = reader->getMemoryUse();
    +  uint64_t batchMemory = batch->getMemoryUsage();
    +  while (reader->next(*batch)) {}
    +  uint64_t actualMemory =
    +      static_cast<TestMemoryPool*>(pool.get())->getMaxMemory();
    +  std::cout << "Reader memory estimate: " << readerMemory
    +            << "\nBatch memory estimate:  " ;
    +  if (batch->hasVariableLength()) {
    +    std::cout << "Cannot estimate because reading ARRAY or MAP columns";
    +  } else {
    +    std::cout << batchMemory
    +              << "\nTotal memory estimate:  " << readerMemory + 
batchMemory;
    +  }
    +  std::cout << "\nActual max memory used: " << actualMemory << "\n";
    +}
    +
    +int main(int argc, char* argv[]) {
    +  if (argc < 2) {
    +    std::cout << "Usage: hdfs-orc-memory [--columns=column1,column2,...] "
    +        << "[--batch=rows_in_batch] <filename> \n";
    +    return 1;
    +  }
    +
    +  const std::string COLUMNS_PREFIX = "--columns=";
    +  const std::string BATCH_PREFIX = "--batch=";
    +  char* filename = ORC_NULLPTR;
    +
    +  // Default parameters
    +  std::list<uint64_t> cols;
    +  uint32_t batchSize = 1000;
    --- End diff --
    
    Ditto


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to