【问题标题】:How to read data from columns not having the same number of rows in HP vertica DB?如何从 HP vertica DB 中行数不同的列中读取数据?
【发布时间】:2016-08-03 16:19:34
【问题描述】:

我正在使用 HP Vertica 数据库创建一个 C++ 转换函数,我想从 2 个不同表的 2 列中读取数据并将它们存储到 2 个向量中。 然后它将输出一个向量的每个元素在第二个向量中的出现次数。 问题是这些列的行数不同。当我记录我使用的代码时,我发现它读取输入的时间比表格大小要好得多。 这是我正在使用的代码。

  virtual void processPartition(ServerInterface &srvInterface,
                              PartitionReader &inputReader,
                              PartitionWriter &outputWriter)
{

            try {
            std::vector<string> vectcomb;
            std::vector<string> vectrule;
        if (inputReader.getNumCols() != 2)
            vt_report_error(0, "Function only accepts 2 argument, but %zu provided", inputReader.getNumCols());

            try{
            int a=0 ;
        do {


            srvInterface.log("[occurence] data load %d ",a);
            a++;

            if(inputReader.isNull(1)){vectcomb.emplace_back(inputReader.getStringRef(0).str());}
            else {vectcomb.emplace_back(inputReader.getStringRef(0).str());
            vectrule.emplace_back(inputReader.getStringRef(1).str());}

        } while (inputReader.next());
            }catch(exception& e){ srvInterface.log("[occurence] exception catched");}

            for(int i=0;i<vectcomb.size();i++) {
                    int occ=0;
                    srvInterface.log("[occurence] test %d ",i);
                    for(int j=0;j<vectrule.size();j++) {
                            if(vectrule.at(j).find(vectcomb.at(i)) != std::string::npos) {occ++ ;}
                                                              }
                            outputWriter.setInt(0,occ) ; outputWriter.next() ;
                    }

    } catch(exception& e) {
        // Standard exception. Quit.
        vt_report_error(0, "Exception while processing partition: [%s]", e.what());
    }
}
};

【问题讨论】:

    标签: c++ input vertica vsql


    【解决方案1】:

    有些东西对我来说不是场景,UDX 基本上是在查询结果集的顶部运行,所以我假设 UDX 从结果集中获取两列作为输入,说你提到的问题是无效的并且不能存在。如果您能够提供有关您计划如何执行此 UDX 的更多信息,这将非常有用。

    【讨论】:

      猜你喜欢
      • 2014-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-09
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多