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

Method processOnSchedule

extensions/sql/processors/QueryDatabaseTable.cpp:229–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

227}
228
229void QueryDatabaseTable::processOnSchedule(core::ProcessContext &context) {
230 initOutputFormat(context);
231
232 context.getProperty(s_tableName.getName(), tableName_);
233 context.getProperty(s_columnNames.getName(), columnNames_);
234
235 context.getProperty(s_maxValueColumnNames.getName(), maxValueColumnNames_);
236 listMaxValueColumnName_ = utils::inputStringToList(maxValueColumnNames_);
237
238 context.getProperty(s_whereClause.getName(), whereClause_);
239 context.getProperty(s_sqlQuery.getName(), sqlQuery_);
240 context.getProperty(s_maxRowsPerFlowFile.getName(), maxRowsPerFlowFile_);
241
242 mapState_.clear();
243
244 state_manager_ = context.getStateManager();
245 if (state_manager_ == nullptr) {
246 throw Exception(PROCESSOR_EXCEPTION, "Failed to get StateManager");
247 }
248
249 std::unordered_map<std::string, std::string> state_map;
250 if (state_manager_->get(state_map)) {
251 if (state_map[TABLENAME_KEY] != tableName_) {
252 state_manager_->clear();
253 } else {
254 for (auto&& elem : state_map) {
255 if (elem.first.find(MAXVALUE_KEY_PREFIX) == 0) {
256 mapState_.emplace(elem.first.substr(MAXVALUE_KEY_PREFIX.length()), std::move(elem.second));
257 }
258 }
259 }
260 } else {
261 // Try to migrate legacy state file
262 std::string stateDir;
263 context.getProperty(s_stateDirectory.getName(), stateDir);
264 if (!stateDir.empty()) {
265 LegacyState legacyState(tableName_, stateDir, getUUIDStr(), logger_);
266 if (legacyState) {
267 mapState_ = legacyState.getStateMap();
268 if (saveState() && state_manager_->persist()) {
269 logger_->log_info("State migration successful");
270 legacyState.moveStateFileToMigrated();
271 } else {
272 logger_->log_warn("Failed to persists migrated state");
273 }
274 } else {
275 logger_->log_warn("Could not migrate state from specified State Directory %s", stateDir);
276 }
277 }
278 }
279
280 // If 'listMaxValueColumnName_' doesn't match columns in mapState_, then clear mapState_.
281 if (listMaxValueColumnName_.size() != mapState_.size()) {
282 mapState_.clear();
283 } else {
284 for (const auto& columName : listMaxValueColumnName_) {
285 if (0 == mapState_.count(columName)) {
286 mapState_.clear();

Callers

nothing calls this directly

Calls 15

inputStringToListFunction · 0.85
ExceptionClass · 0.85
getUUIDStrFunction · 0.85
toLowerFunction · 0.85
lengthMethod · 0.80
log_infoMethod · 0.80
log_warnMethod · 0.80
getPropertyMethod · 0.45
getNameMethod · 0.45
clearMethod · 0.45
getStateManagerMethod · 0.45

Tested by

no test coverage detected