MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / processOnTrigger

Method processOnTrigger

extensions/sql/processors/QueryDatabaseTable.cpp:324–368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

322}
323
324void 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
370std::string QueryDatabaseTable::getSelectQuery() {
371 std::string ret;

Callers

nothing calls this directly

Calls 14

log_infoMethod · 0.80
c_strMethod · 0.80
prepareStatementMethod · 0.80
updateMapStateMethod · 0.80
to_stringFunction · 0.50
executeMethod · 0.45
processMethod · 0.45
toStringMethod · 0.45
emptyMethod · 0.45
createMethod · 0.45
addAttributeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected