| 322 | } |
| 323 | |
| 324 | void QueryDatabaseTable::processOnTrigger(core::ProcessSession& session) { |
| 325 | const auto& selectQuery = getSelectQuery(); |
| 326 | |
| 327 | logger_->log_info("QueryDatabaseTable: selectQuery: '%s'", selectQuery.c_str()); |
| 328 | |
| 329 | auto statement = connection_->prepareStatement(selectQuery); |
| 330 | |
| 331 | auto rowset = statement->execute(); |
| 332 | |
| 333 | int count = 0; |
| 334 | size_t rowCount = 0; |
| 335 | sql::MaxCollector maxCollector(selectQuery, maxValueColumnNames_, mapState_); |
| 336 | sql::JSONSQLWriter sqlWriter(isJSONPretty()); |
| 337 | sql::SQLRowsetProcessor sqlRowsetProcessor(rowset, {&sqlWriter, &maxCollector}); |
| 338 | |
| 339 | // Process rowset. |
| 340 | do { |
| 341 | rowCount = sqlRowsetProcessor.process(maxRowsPerFlowFile_ == 0 ? std::numeric_limits<size_t>::max() : maxRowsPerFlowFile_); |
| 342 | count++; |
| 343 | if (rowCount == 0) |
| 344 | break; |
| 345 | |
| 346 | const auto output = sqlWriter.toString(); |
| 347 | if (!output.empty()) { |
| 348 | WriteCallback writer(output); |
| 349 | auto newflow = session.create(); |
| 350 | newflow->addAttribute(ResultRowCount, std::to_string(rowCount)); |
| 351 | newflow->addAttribute(ResultTableName, tableName_); |
| 352 | session.write(newflow, &writer); |
| 353 | session.transfer(newflow, s_success); |
| 354 | } |
| 355 | } while (rowCount > 0); |
| 356 | |
| 357 | const auto mapState = mapState_; |
| 358 | if (maxCollector.updateMapState()) { |
| 359 | try { |
| 360 | session.commit(); |
| 361 | } catch (std::exception& e) { |
| 362 | mapState_ = mapState; |
| 363 | throw; |
| 364 | } |
| 365 | |
| 366 | saveState(); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | std::string QueryDatabaseTable::getSelectQuery() { |
| 371 | std::string ret; |
nothing calls this directly
no test coverage detected