-2
我正在用HP Vertica數據庫創建C++轉換函數,我想從2個不同表中的2列中讀取數據,並將它們存儲到2個向量中。 然後它將輸出第二個矢量中每個元素的出現次數。 問題是這些列沒有相同的行數。當我登錄我使用的代碼時,我發現它讀取的輸入比表格大小多了很多倍。 這是我使用的代碼。如何從HP Vertica DB中的行數不同的列中讀取數據?
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());
}
}
};