我正在使用 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());
}
}
};