You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "lordgamez (via GitHub)" <gi...@apache.org> on 2024/09/12 08:15:38 UTC

[PR] MINIFICPP-2454 Create SplitRecord processor [nifi-minifi-cpp]

lordgamez opened a new pull request, #1866:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1866

   https://issues.apache.org/jira/browse/MINIFICPP-2454
   
   ----------------
   Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced
        in the commit message?
   
   - [ ] Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically main)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   ### For code changes:
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   - [ ] If applicable, have you updated the LICENSE file?
   - [ ] If applicable, have you updated the NOTICE file?
   
   ### For documentation related changes:
   - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
   
   ### Note:
   Please ensure that once the PR is submitted, you check GitHub Actions CI results for build issues and submit an update to your PR as soon as possible.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2454 Create SplitRecord processor [nifi-minifi-cpp]

Posted by "szaszm (via GitHub)" <gi...@apache.org>.
szaszm commented on code in PR #1866:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1866#discussion_r1760014731


##########
extensions/standard-processors/processors/SplitRecord.cpp:
##########
@@ -0,0 +1,125 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "SplitRecord.h"
+
+#include "core/Resource.h"
+#include "nonstd/expected.hpp"
+
+namespace org::apache::nifi::minifi::processors {
+namespace {
+template<typename RecordSetIO>
+std::shared_ptr<RecordSetIO> getRecordSetIO(core::ProcessContext& context, const core::PropertyReference& property) {
+  std::string service_name;
+  if (context.getProperty(property, service_name) && !IsNullOrEmpty(service_name)) {
+    auto record_set_io = std::dynamic_pointer_cast<RecordSetIO>(context.getControllerService(service_name));
+    if (!record_set_io)
+      return nullptr;
+    return record_set_io;
+  }
+  return nullptr;
+}
+}  // namespace
+
+SplitRecord::SplitRecord(std::string_view name, const utils::Identifier& uuid)
+    : Processor(name, uuid), logger_{core::logging::LoggerFactory<SplitRecord>::getLogger(uuid)} {}
+
+void SplitRecord::initialize() {
+  setSupportedProperties(Properties);
+  setSupportedRelationships(Relationships);
+}
+
+void SplitRecord::onSchedule(core::ProcessContext& context, core::ProcessSessionFactory&) {
+  record_set_reader_ = getRecordSetIO<core::RecordSetReader>(context, SplitRecord::RecordReader);
+  if (!record_set_reader_) {
+    throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Reader set is missing or invalid");
+  }
+  record_set_writer_ = getRecordSetIO<core::RecordSetWriter>(context, SplitRecord::RecordWriter);
+  if (!record_set_writer_) {
+    throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Writer set is missing or invalid");
+  }
+}
+
+nonstd::expected<std::size_t, std::string> SplitRecord::readRecordsPerSplit(core::ProcessContext& context, const std::shared_ptr<core::FlowFile>& original_flow_file) {

Review Comment:
   The flow file should be passed by reference, not a shared_ptr.
   
   Ideally the unexpected type of the result would be something more lightweight, like an enum or std::error_code. Converting them to an error message could be done separately.



##########
extensions/standard-processors/processors/SplitRecord.h:
##########
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include "core/Annotation.h"
+#include "core/Processor.h"
+#include "core/ProcessContext.h"
+#include "core/ProcessSession.h"
+#include "core/ProcessSessionFactory.h"
+#include "core/PropertyDefinition.h"
+#include "core/PropertyDefinitionBuilder.h"
+#include "core/RelationshipDefinition.h"
+#include "core/logging/Logger.h"
+#include "controllers/RecordSetReader.h"
+#include "controllers/RecordSetWriter.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+class SplitRecord : public core::Processor {
+ public:
+  EXTENSIONAPI static constexpr const char* Description = "Splits up an input FlowFile that is in a record-oriented data format into multiple smaller FlowFiles";
+
+  EXTENSIONAPI static constexpr auto RecordReader = core::PropertyDefinitionBuilder<>::createProperty("Record Reader")
+      .withDescription("Specifies the Controller Service to use for reading incoming data")
+      .isRequired(true)
+      .withAllowedTypes<minifi::core::RecordSetReader>()
+      .build();
+  EXTENSIONAPI static constexpr auto RecordWriter = core::PropertyDefinitionBuilder<>::createProperty("Record Writer")
+      .withDescription("Specifies the Controller Service to use for writing out the records")
+      .isRequired(true)
+      .withAllowedTypes<minifi::core::RecordSetWriter>()
+      .build();
+  EXTENSIONAPI static constexpr auto RecordsPerSplit = core::PropertyDefinitionBuilder<>::createProperty("Records Per Split")
+      .withDescription("Specifies how many records should be written to each 'split' or 'segment' FlowFile")
+      .isRequired(true)
+      .supportsExpressionLanguage(true)
+      .build();
+
+  EXTENSIONAPI static constexpr auto Properties = std::to_array<core::PropertyReference>({
+      RecordReader,
+      RecordWriter,
+      RecordsPerSplit
+  });
+
+  EXTENSIONAPI static constexpr auto Failure = core::RelationshipDefinition{"failure",
+      "If a FlowFile cannot be transformed from the configured input format to the configured output format, the unchanged FlowFile will be routed to this relationship."};
+  EXTENSIONAPI static constexpr auto Splits = core::RelationshipDefinition{"splits",
+      "The individual 'segments' of the original FlowFile will be routed to this relationship."};
+  EXTENSIONAPI static constexpr auto Original = core::RelationshipDefinition{"original",
+      "Upon successfully splitting an input FlowFile, the original FlowFile will be sent to this relationship."};
+  EXTENSIONAPI static constexpr auto Relationships = std::array{Failure, Splits, Original};
+
+  EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
+  EXTENSIONAPI static constexpr bool SupportsDynamicRelationships = false;
+  EXTENSIONAPI static constexpr core::annotation::Input InputRequirement = core::annotation::Input::INPUT_REQUIRED;
+  EXTENSIONAPI static constexpr bool IsSingleThreaded = false;
+
+  ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS

Review Comment:
   Check out the AbstractProcessor CRTP class I made a while ago. It's meant to get the same thing done, but without macros.



##########
extensions/standard-processors/processors/SplitRecord.cpp:
##########
@@ -0,0 +1,125 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "SplitRecord.h"
+
+#include "core/Resource.h"
+#include "nonstd/expected.hpp"
+
+namespace org::apache::nifi::minifi::processors {
+namespace {
+template<typename RecordSetIO>
+std::shared_ptr<RecordSetIO> getRecordSetIO(core::ProcessContext& context, const core::PropertyReference& property) {
+  std::string service_name;
+  if (context.getProperty(property, service_name) && !IsNullOrEmpty(service_name)) {
+    auto record_set_io = std::dynamic_pointer_cast<RecordSetIO>(context.getControllerService(service_name));
+    if (!record_set_io)
+      return nullptr;
+    return record_set_io;
+  }
+  return nullptr;
+}
+}  // namespace
+
+SplitRecord::SplitRecord(std::string_view name, const utils::Identifier& uuid)
+    : Processor(name, uuid), logger_{core::logging::LoggerFactory<SplitRecord>::getLogger(uuid)} {}
+
+void SplitRecord::initialize() {
+  setSupportedProperties(Properties);
+  setSupportedRelationships(Relationships);
+}
+
+void SplitRecord::onSchedule(core::ProcessContext& context, core::ProcessSessionFactory&) {
+  record_set_reader_ = getRecordSetIO<core::RecordSetReader>(context, SplitRecord::RecordReader);
+  if (!record_set_reader_) {
+    throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Reader set is missing or invalid");
+  }
+  record_set_writer_ = getRecordSetIO<core::RecordSetWriter>(context, SplitRecord::RecordWriter);
+  if (!record_set_writer_) {
+    throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Writer set is missing or invalid");
+  }
+}
+
+nonstd::expected<std::size_t, std::string> SplitRecord::readRecordsPerSplit(core::ProcessContext& context, const std::shared_ptr<core::FlowFile>& original_flow_file) {
+  std::string value;
+  std::size_t records_per_split = 0;
+  if (context.getProperty(RecordsPerSplit, value, original_flow_file.get())) {
+    if (!core::Property::StringToInt(value, records_per_split)) {
+      return nonstd::make_unexpected("Failed to convert Records Per Split property to an integer");
+    } else if (records_per_split < 1) {
+      return nonstd::make_unexpected("Records per split should be set to a number larger than 0");
+    }
+  } else {
+    return nonstd::make_unexpected("Records per split should be set to a valid number larger than 0");
+  }
+  return records_per_split;
+}
+
+void SplitRecord::onTrigger(core::ProcessContext& context, core::ProcessSession& session) {
+  const auto original_flow_file = session.get();
+  if (!original_flow_file) {
+    yield();
+    return;
+  }
+
+  auto records_per_split = readRecordsPerSplit(context, original_flow_file);
+  if (!records_per_split) {
+    logger_->log_error("Failed to read Records Per Split property: {}", records_per_split.error());
+    session.transfer(original_flow_file, Failure);
+    return;
+  }
+
+  auto record_set = record_set_reader_->read(original_flow_file, session);
+  if (!record_set) {
+    logger_->log_error("Failed to read record set from flow file: {}", record_set.error().message());
+    session.transfer(original_flow_file, Failure);
+    return;
+  }
+
+  std::size_t current_index = 0;
+  const auto fragment_identifier = utils::IdGenerator::getIdGenerator()->generate().to_string();
+  std::size_t fragment_index = 0;
+  std::size_t fragment_count = record_set->size() / records_per_split.value() + (record_set->size() % records_per_split.value() == 0 ? 0 : 1);

Review Comment:
   ```suggestion
     const auto fragment_count = utils::intdiv_ceil(record_set->size(), records_per_split.value());
   ```



##########
extensions/standard-processors/processors/SplitRecord.cpp:
##########
@@ -0,0 +1,125 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "SplitRecord.h"
+
+#include "core/Resource.h"
+#include "nonstd/expected.hpp"
+
+namespace org::apache::nifi::minifi::processors {
+namespace {
+template<typename RecordSetIO>
+std::shared_ptr<RecordSetIO> getRecordSetIO(core::ProcessContext& context, const core::PropertyReference& property) {
+  std::string service_name;
+  if (context.getProperty(property, service_name) && !IsNullOrEmpty(service_name)) {
+    auto record_set_io = std::dynamic_pointer_cast<RecordSetIO>(context.getControllerService(service_name));
+    if (!record_set_io)
+      return nullptr;
+    return record_set_io;
+  }
+  return nullptr;
+}
+}  // namespace
+
+SplitRecord::SplitRecord(std::string_view name, const utils::Identifier& uuid)
+    : Processor(name, uuid), logger_{core::logging::LoggerFactory<SplitRecord>::getLogger(uuid)} {}
+
+void SplitRecord::initialize() {
+  setSupportedProperties(Properties);
+  setSupportedRelationships(Relationships);
+}
+
+void SplitRecord::onSchedule(core::ProcessContext& context, core::ProcessSessionFactory&) {
+  record_set_reader_ = getRecordSetIO<core::RecordSetReader>(context, SplitRecord::RecordReader);
+  if (!record_set_reader_) {
+    throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Reader set is missing or invalid");
+  }
+  record_set_writer_ = getRecordSetIO<core::RecordSetWriter>(context, SplitRecord::RecordWriter);
+  if (!record_set_writer_) {
+    throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Writer set is missing or invalid");
+  }
+}
+
+nonstd::expected<std::size_t, std::string> SplitRecord::readRecordsPerSplit(core::ProcessContext& context, const std::shared_ptr<core::FlowFile>& original_flow_file) {
+  std::string value;
+  std::size_t records_per_split = 0;
+  if (context.getProperty(RecordsPerSplit, value, original_flow_file.get())) {
+    if (!core::Property::StringToInt(value, records_per_split)) {
+      return nonstd::make_unexpected("Failed to convert Records Per Split property to an integer");
+    } else if (records_per_split < 1) {
+      return nonstd::make_unexpected("Records per split should be set to a number larger than 0");
+    }
+  } else {
+    return nonstd::make_unexpected("Records per split should be set to a valid number larger than 0");
+  }
+  return records_per_split;
+}
+
+void SplitRecord::onTrigger(core::ProcessContext& context, core::ProcessSession& session) {
+  const auto original_flow_file = session.get();
+  if (!original_flow_file) {
+    yield();
+    return;
+  }
+
+  auto records_per_split = readRecordsPerSplit(context, original_flow_file);
+  if (!records_per_split) {
+    logger_->log_error("Failed to read Records Per Split property: {}", records_per_split.error());
+    session.transfer(original_flow_file, Failure);
+    return;
+  }
+
+  auto record_set = record_set_reader_->read(original_flow_file, session);
+  if (!record_set) {
+    logger_->log_error("Failed to read record set from flow file: {}", record_set.error().message());
+    session.transfer(original_flow_file, Failure);
+    return;
+  }
+
+  std::size_t current_index = 0;
+  const auto fragment_identifier = utils::IdGenerator::getIdGenerator()->generate().to_string();
+  std::size_t fragment_index = 0;
+  std::size_t fragment_count = record_set->size() / records_per_split.value() + (record_set->size() % records_per_split.value() == 0 ? 0 : 1);
+  while (current_index < record_set->size()) {
+    auto split_flow_file = session.create(original_flow_file.get());
+    if (!split_flow_file) {
+      logger_->log_error("Failed to create a new flow file for record set");
+      session.transfer(original_flow_file, Failure);
+      return;
+    }
+
+    core::RecordSet slice_record_set;

Review Comment:
   ```suggestion
       core::RecordSet slice_record_set;
       slice_record_set.reserve(*records_per_split);
   ```



##########
extensions/standard-processors/processors/SplitRecord.cpp:
##########


Review Comment:
   I'd prefer removing the redundant namespace and scope prefixes. All of the grayed out text (except legacy enums like ExceptionType) on the screenshot, + more elsewhere.
   ![Screenshot_20240915_125418](https://github.com/user-attachments/assets/3fd912cc-b24d-40a9-a20a-74148a138cdc)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2454 Create SplitRecord processor [nifi-minifi-cpp]

Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #1866:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1866#discussion_r1842192454


##########
extensions/standard-processors/processors/SplitRecord.h:
##########
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include "core/Annotation.h"
+#include "core/ProcessContext.h"
+#include "core/ProcessSession.h"
+#include "core/ProcessSessionFactory.h"
+#include "core/PropertyDefinition.h"
+#include "core/PropertyDefinitionBuilder.h"
+#include "core/RelationshipDefinition.h"
+#include "core/logging/Logger.h"
+#include "controllers/RecordSetReader.h"
+#include "controllers/RecordSetWriter.h"
+#include "core/AbstractProcessor.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+class SplitRecord final : public core::AbstractProcessor<SplitRecord> {
+ public:
+  using core::AbstractProcessor<SplitRecord>::AbstractProcessor;
+
+  EXTENSIONAPI static constexpr const char* Description = "Splits up an input FlowFile that is in a record-oriented data format into multiple smaller FlowFiles";
+
+  EXTENSIONAPI static constexpr auto RecordReader = core::PropertyDefinitionBuilder<>::createProperty("Record Reader")
+      .withDescription("Specifies the Controller Service to use for reading incoming data")
+      .isRequired(true)
+      .withAllowedTypes<minifi::core::RecordSetReader>()
+      .build();
+  EXTENSIONAPI static constexpr auto RecordWriter = core::PropertyDefinitionBuilder<>::createProperty("Record Writer")
+      .withDescription("Specifies the Controller Service to use for writing out the records")
+      .isRequired(true)
+      .withAllowedTypes<minifi::core::RecordSetWriter>()
+      .build();
+  EXTENSIONAPI static constexpr auto RecordsPerSplit = core::PropertyDefinitionBuilder<>::createProperty("Records Per Split")
+      .withDescription("Specifies how many records should be written to each 'split' or 'segment' FlowFile")
+      .isRequired(true)
+      .supportsExpressionLanguage(true)
+      .build();
+
+  EXTENSIONAPI static constexpr auto Properties = std::to_array<core::PropertyReference>({
+      RecordReader,
+      RecordWriter,
+      RecordsPerSplit
+  });
+
+  EXTENSIONAPI static constexpr auto Failure = core::RelationshipDefinition{"failure",
+      "If a FlowFile cannot be transformed from the configured input format to the configured output format, the unchanged FlowFile will be routed to this relationship."};
+  EXTENSIONAPI static constexpr auto Splits = core::RelationshipDefinition{"splits",
+      "The individual 'segments' of the original FlowFile will be routed to this relationship."};
+  EXTENSIONAPI static constexpr auto Original = core::RelationshipDefinition{"original",
+      "Upon successfully splitting an input FlowFile, the original FlowFile will be sent to this relationship."};
+  EXTENSIONAPI static constexpr auto Relationships = std::array{Failure, Splits, Original};
+

Review Comment:
   Added in https://github.com/apache/nifi-minifi-cpp/pull/1866/commits/b9de420231ec51690b584cab09189236bfe2eabd



##########
extensions/standard-processors/processors/SplitRecord.cpp:
##########
@@ -0,0 +1,119 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "SplitRecord.h"
+
+#include "core/Resource.h"
+#include "nonstd/expected.hpp"
+#include "utils/GeneralUtils.h"
+
+namespace org::apache::nifi::minifi::processors {
+namespace {
+template<typename RecordSetIO>
+std::shared_ptr<RecordSetIO> getRecordSetIO(core::ProcessContext& context, const core::PropertyReference& property) {
+  std::string service_name;
+  if (context.getProperty(property, service_name) && !IsNullOrEmpty(service_name)) {
+    auto record_set_io = std::dynamic_pointer_cast<RecordSetIO>(context.getControllerService(service_name));
+    if (!record_set_io)
+      return nullptr;
+    return record_set_io;
+  }
+  return nullptr;
+}
+}  // namespace
+
+void SplitRecord::onSchedule(core::ProcessContext& context, core::ProcessSessionFactory&) {
+  record_set_reader_ = getRecordSetIO<core::RecordSetReader>(context, RecordReader);
+  if (!record_set_reader_) {
+    throw Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Reader set is missing or invalid");
+  }
+  record_set_writer_ = getRecordSetIO<core::RecordSetWriter>(context, RecordWriter);
+  if (!record_set_writer_) {
+    throw Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Writer set is missing or invalid");
+  }
+}
+
+nonstd::expected<std::size_t, std::string> SplitRecord::readRecordsPerSplit(core::ProcessContext& context, const core::FlowFile& original_flow_file) {
+  std::string value;
+  std::size_t records_per_split = 0;
+  if (context.getProperty(RecordsPerSplit, value, &original_flow_file)) {
+    if (!core::Property::StringToInt(value, records_per_split)) {
+      return nonstd::make_unexpected("Failed to convert Records Per Split property to an integer");
+    } else if (records_per_split < 1) {
+      return nonstd::make_unexpected("Records per split should be set to a number larger than 0");
+    }
+  } else {
+    return nonstd::make_unexpected("Records per split should be set to a valid number larger than 0");

Review Comment:
   Fixed in https://github.com/apache/nifi-minifi-cpp/pull/1866/commits/b9de420231ec51690b584cab09189236bfe2eabd



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2454 Create SplitRecord processor [nifi-minifi-cpp]

Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #1866:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1866#discussion_r1842192329


##########
PROCESSORS.md:
##########
@@ -2875,6 +2877,41 @@ In the list below, the names of required properties appear in bold. Any other pr
 | segment.original.filename |              | The filename of the parent FlowFile                                                                                            |
 
 
+## SplitRecord
+
+### Description
+
+Splits up an input FlowFile that is in a record-oriented data format into multiple smaller FlowFiles
+
+### Properties
+
+In the list below, the names of required properties appear in bold. Any other properties (not in bold) are considered optional. The table also indicates any default values, and whether a property supports the NiFi Expression Language.
+
+| Name                  | Default Value | Allowable Values | Description                                                                                                                   |
+|-----------------------|---------------|------------------|-------------------------------------------------------------------------------------------------------------------------------|
+| **Record Reader**     |               |                  | Specifies the Controller Service to use for reading incoming data                                                             |
+| **Record Writer**     |               |                  | Specifies the Controller Service to use for writing out the records                                                           |
+| **Records Per Split** |               |                  | Specifies how many records should be written to each 'split' or 'segment' FlowFile<br/>**Supports Expression Language: true** |
+
+### Relationships
+
+| Name     | Description                                                                                                                                                       |
+|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| failure  | If a FlowFile cannot be transformed from the configured input format to the configured output format, the unchanged FlowFile will be routed to this relationship. |
+| original | Upon successfully splitting an input FlowFile, the original FlowFile will be sent to this relationship.                                                           |
+| splits   | The individual 'segments' of the original FlowFile will be routed to this relationship.                                                                           |
+
+### Output Attributes
+
+| Attribute                 | Relationship | Description                                                                                                                    |
+|---------------------------|--------------|--------------------------------------------------------------------------------------------------------------------------------|
+| record.count              |              | The number of records in the FlowFile. This is added to FlowFiles that are routed to the 'splits' Relationship.                |
+| fragment.identifier       |              | All split FlowFiles produced from the same parent FlowFile will have the same randomly generated UUID added for this attribute |

Review Comment:
   Good point, updated in b34afbfa89aae6398cfdafcb017e70e13934639c



##########
extensions/standard-processors/processors/SplitRecord.cpp:
##########
@@ -0,0 +1,119 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "SplitRecord.h"
+
+#include "core/Resource.h"
+#include "nonstd/expected.hpp"
+#include "utils/GeneralUtils.h"
+
+namespace org::apache::nifi::minifi::processors {
+namespace {
+template<typename RecordSetIO>
+std::shared_ptr<RecordSetIO> getRecordSetIO(core::ProcessContext& context, const core::PropertyReference& property) {
+  std::string service_name;
+  if (context.getProperty(property, service_name) && !IsNullOrEmpty(service_name)) {
+    auto record_set_io = std::dynamic_pointer_cast<RecordSetIO>(context.getControllerService(service_name));
+    if (!record_set_io)
+      return nullptr;
+    return record_set_io;
+  }
+  return nullptr;
+}
+}  // namespace
+
+void SplitRecord::onSchedule(core::ProcessContext& context, core::ProcessSessionFactory&) {
+  record_set_reader_ = getRecordSetIO<core::RecordSetReader>(context, RecordReader);
+  if (!record_set_reader_) {
+    throw Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Reader set is missing or invalid");
+  }
+  record_set_writer_ = getRecordSetIO<core::RecordSetWriter>(context, RecordWriter);
+  if (!record_set_writer_) {
+    throw Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Writer set is missing or invalid");

Review Comment:
   Fixed in b34afbfa89aae6398cfdafcb017e70e13934639c



##########
extensions/standard-processors/processors/SplitRecord.cpp:
##########
@@ -0,0 +1,119 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "SplitRecord.h"
+
+#include "core/Resource.h"
+#include "nonstd/expected.hpp"
+#include "utils/GeneralUtils.h"
+
+namespace org::apache::nifi::minifi::processors {
+namespace {
+template<typename RecordSetIO>
+std::shared_ptr<RecordSetIO> getRecordSetIO(core::ProcessContext& context, const core::PropertyReference& property) {
+  std::string service_name;
+  if (context.getProperty(property, service_name) && !IsNullOrEmpty(service_name)) {
+    auto record_set_io = std::dynamic_pointer_cast<RecordSetIO>(context.getControllerService(service_name));
+    if (!record_set_io)
+      return nullptr;
+    return record_set_io;
+  }
+  return nullptr;
+}
+}  // namespace
+
+void SplitRecord::onSchedule(core::ProcessContext& context, core::ProcessSessionFactory&) {
+  record_set_reader_ = getRecordSetIO<core::RecordSetReader>(context, RecordReader);
+  if (!record_set_reader_) {
+    throw Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Reader set is missing or invalid");
+  }
+  record_set_writer_ = getRecordSetIO<core::RecordSetWriter>(context, RecordWriter);
+  if (!record_set_writer_) {
+    throw Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Writer set is missing or invalid");
+  }
+}
+
+nonstd::expected<std::size_t, std::string> SplitRecord::readRecordsPerSplit(core::ProcessContext& context, const core::FlowFile& original_flow_file) {
+  std::string value;
+  std::size_t records_per_split = 0;
+  if (context.getProperty(RecordsPerSplit, value, &original_flow_file)) {
+    if (!core::Property::StringToInt(value, records_per_split)) {
+      return nonstd::make_unexpected("Failed to convert Records Per Split property to an integer");
+    } else if (records_per_split < 1) {
+      return nonstd::make_unexpected("Records per split should be set to a number larger than 0");
+    }
+  } else {
+    return nonstd::make_unexpected("Records per split should be set to a valid number larger than 0");

Review Comment:
   Fixed in b34afbfa89aae6398cfdafcb017e70e13934639c



##########
extensions/standard-processors/processors/SplitRecord.h:
##########
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include "core/Annotation.h"
+#include "core/ProcessContext.h"
+#include "core/ProcessSession.h"
+#include "core/ProcessSessionFactory.h"
+#include "core/PropertyDefinition.h"
+#include "core/PropertyDefinitionBuilder.h"
+#include "core/RelationshipDefinition.h"
+#include "core/logging/Logger.h"
+#include "controllers/RecordSetReader.h"
+#include "controllers/RecordSetWriter.h"
+#include "core/AbstractProcessor.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+class SplitRecord final : public core::AbstractProcessor<SplitRecord> {
+ public:
+  using core::AbstractProcessor<SplitRecord>::AbstractProcessor;
+
+  EXTENSIONAPI static constexpr const char* Description = "Splits up an input FlowFile that is in a record-oriented data format into multiple smaller FlowFiles";
+
+  EXTENSIONAPI static constexpr auto RecordReader = core::PropertyDefinitionBuilder<>::createProperty("Record Reader")
+      .withDescription("Specifies the Controller Service to use for reading incoming data")
+      .isRequired(true)
+      .withAllowedTypes<minifi::core::RecordSetReader>()
+      .build();
+  EXTENSIONAPI static constexpr auto RecordWriter = core::PropertyDefinitionBuilder<>::createProperty("Record Writer")
+      .withDescription("Specifies the Controller Service to use for writing out the records")
+      .isRequired(true)
+      .withAllowedTypes<minifi::core::RecordSetWriter>()
+      .build();
+  EXTENSIONAPI static constexpr auto RecordsPerSplit = core::PropertyDefinitionBuilder<>::createProperty("Records Per Split")
+      .withDescription("Specifies how many records should be written to each 'split' or 'segment' FlowFile")
+      .isRequired(true)
+      .supportsExpressionLanguage(true)
+      .build();
+
+  EXTENSIONAPI static constexpr auto Properties = std::to_array<core::PropertyReference>({
+      RecordReader,
+      RecordWriter,
+      RecordsPerSplit
+  });
+
+  EXTENSIONAPI static constexpr auto Failure = core::RelationshipDefinition{"failure",
+      "If a FlowFile cannot be transformed from the configured input format to the configured output format, the unchanged FlowFile will be routed to this relationship."};
+  EXTENSIONAPI static constexpr auto Splits = core::RelationshipDefinition{"splits",
+      "The individual 'segments' of the original FlowFile will be routed to this relationship."};
+  EXTENSIONAPI static constexpr auto Original = core::RelationshipDefinition{"original",
+      "Upon successfully splitting an input FlowFile, the original FlowFile will be sent to this relationship."};
+  EXTENSIONAPI static constexpr auto Relationships = std::array{Failure, Splits, Original};
+

Review Comment:
   Added in b34afbfa89aae6398cfdafcb017e70e13934639c



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2454 Create SplitRecord processor [nifi-minifi-cpp]

Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #1866:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1866#discussion_r1843401361


##########
extensions/standard-processors/processors/SplitRecord.h:
##########
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include "core/Annotation.h"
+#include "core/ProcessContext.h"
+#include "core/ProcessSession.h"
+#include "core/ProcessSessionFactory.h"
+#include "core/PropertyDefinition.h"
+#include "core/PropertyDefinitionBuilder.h"
+#include "core/RelationshipDefinition.h"
+#include "core/logging/Logger.h"
+#include "controllers/RecordSetReader.h"
+#include "controllers/RecordSetWriter.h"
+#include "core/AbstractProcessor.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+class SplitRecord final : public core::AbstractProcessor<SplitRecord> {
+ public:
+  using core::AbstractProcessor<SplitRecord>::AbstractProcessor;
+
+  EXTENSIONAPI static constexpr const char* Description = "Splits up an input FlowFile that is in a record-oriented data format into multiple smaller FlowFiles";
+
+  EXTENSIONAPI static constexpr auto RecordReader = core::PropertyDefinitionBuilder<>::createProperty("Record Reader")
+      .withDescription("Specifies the Controller Service to use for reading incoming data")
+      .isRequired(true)
+      .withAllowedTypes<minifi::core::RecordSetReader>()
+      .build();
+  EXTENSIONAPI static constexpr auto RecordWriter = core::PropertyDefinitionBuilder<>::createProperty("Record Writer")
+      .withDescription("Specifies the Controller Service to use for writing out the records")
+      .isRequired(true)
+      .withAllowedTypes<minifi::core::RecordSetWriter>()
+      .build();
+  EXTENSIONAPI static constexpr auto RecordsPerSplit = core::PropertyDefinitionBuilder<>::createProperty("Records Per Split")
+      .withDescription("Specifies how many records should be written to each 'split' or 'segment' FlowFile")
+      .isRequired(true)
+      .supportsExpressionLanguage(true)
+      .build();
+
+  EXTENSIONAPI static constexpr auto Properties = std::to_array<core::PropertyReference>({
+      RecordReader,
+      RecordWriter,
+      RecordsPerSplit
+  });
+
+  EXTENSIONAPI static constexpr auto Failure = core::RelationshipDefinition{"failure",
+      "If a FlowFile cannot be transformed from the configured input format to the configured output format, the unchanged FlowFile will be routed to this relationship."};
+  EXTENSIONAPI static constexpr auto Splits = core::RelationshipDefinition{"splits",
+      "The individual 'segments' of the original FlowFile will be routed to this relationship."};
+  EXTENSIONAPI static constexpr auto Original = core::RelationshipDefinition{"original",
+      "Upon successfully splitting an input FlowFile, the original FlowFile will be sent to this relationship."};
+  EXTENSIONAPI static constexpr auto Relationships = std::array{Failure, Splits, Original};
+
+  EXTENSIONAPI static constexpr auto RecordCount = core::OutputAttributeDefinition<1>{"record.count", {Splits},
+    "The number of records in the FlowFile. This is added to FlowFiles that are routed to the 'splits' Relationship."};
+  EXTENSIONAPI static constexpr auto FragmentIdentifier = core::OutputAttributeDefinition<1>{"fragment.identifier", {Splits},
+    "All split FlowFiles produced from the same parent FlowFile will have the same randomly generated UUID added for this attribute"};

Review Comment:
   Updated in https://github.com/apache/nifi-minifi-cpp/pull/1866/commits/47bd773cb2b6e77b6fcd57fdfc863b6f32408f90



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2454 Create SplitRecord processor [nifi-minifi-cpp]

Posted by "fgerlits (via GitHub)" <gi...@apache.org>.
fgerlits commented on code in PR #1866:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1866#discussion_r1842621678


##########
extensions/standard-processors/processors/SplitRecord.h:
##########
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include "core/Annotation.h"
+#include "core/ProcessContext.h"
+#include "core/ProcessSession.h"
+#include "core/ProcessSessionFactory.h"
+#include "core/PropertyDefinition.h"
+#include "core/PropertyDefinitionBuilder.h"
+#include "core/RelationshipDefinition.h"
+#include "core/logging/Logger.h"
+#include "controllers/RecordSetReader.h"
+#include "controllers/RecordSetWriter.h"
+#include "core/AbstractProcessor.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+class SplitRecord final : public core::AbstractProcessor<SplitRecord> {
+ public:
+  using core::AbstractProcessor<SplitRecord>::AbstractProcessor;
+
+  EXTENSIONAPI static constexpr const char* Description = "Splits up an input FlowFile that is in a record-oriented data format into multiple smaller FlowFiles";
+
+  EXTENSIONAPI static constexpr auto RecordReader = core::PropertyDefinitionBuilder<>::createProperty("Record Reader")
+      .withDescription("Specifies the Controller Service to use for reading incoming data")
+      .isRequired(true)
+      .withAllowedTypes<minifi::core::RecordSetReader>()
+      .build();
+  EXTENSIONAPI static constexpr auto RecordWriter = core::PropertyDefinitionBuilder<>::createProperty("Record Writer")
+      .withDescription("Specifies the Controller Service to use for writing out the records")
+      .isRequired(true)
+      .withAllowedTypes<minifi::core::RecordSetWriter>()
+      .build();
+  EXTENSIONAPI static constexpr auto RecordsPerSplit = core::PropertyDefinitionBuilder<>::createProperty("Records Per Split")
+      .withDescription("Specifies how many records should be written to each 'split' or 'segment' FlowFile")
+      .isRequired(true)
+      .supportsExpressionLanguage(true)
+      .build();
+
+  EXTENSIONAPI static constexpr auto Properties = std::to_array<core::PropertyReference>({
+      RecordReader,
+      RecordWriter,
+      RecordsPerSplit
+  });
+
+  EXTENSIONAPI static constexpr auto Failure = core::RelationshipDefinition{"failure",
+      "If a FlowFile cannot be transformed from the configured input format to the configured output format, the unchanged FlowFile will be routed to this relationship."};
+  EXTENSIONAPI static constexpr auto Splits = core::RelationshipDefinition{"splits",
+      "The individual 'segments' of the original FlowFile will be routed to this relationship."};
+  EXTENSIONAPI static constexpr auto Original = core::RelationshipDefinition{"original",
+      "Upon successfully splitting an input FlowFile, the original FlowFile will be sent to this relationship."};
+  EXTENSIONAPI static constexpr auto Relationships = std::array{Failure, Splits, Original};
+
+  EXTENSIONAPI static constexpr auto RecordCount = core::OutputAttributeDefinition<1>{"record.count", {Splits},
+    "The number of records in the FlowFile. This is added to FlowFiles that are routed to the 'splits' Relationship."};
+  EXTENSIONAPI static constexpr auto FragmentIdentifier = core::OutputAttributeDefinition<1>{"fragment.identifier", {Splits},
+    "All split FlowFiles produced from the same parent FlowFile will have the same randomly generated UUID added for this attribute"};

Review Comment:
   I missed this in SegmentContent, too, but "randomly generated" is no longer true
   ```suggestion
     EXTENSIONAPI static constexpr auto FragmentIdentifier = core::OutputAttributeDefinition<1>{"fragment.identifier", {Splits},
       "All split FlowFiles produced from the same parent FlowFile will have this attribute set to the same UUID (which is the UUID of the parent FlowFile, if available)"};
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2454 Create SplitRecord processor [nifi-minifi-cpp]

Posted by "fgerlits (via GitHub)" <gi...@apache.org>.
fgerlits commented on code in PR #1866:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1866#discussion_r1838403782


##########
extensions/standard-processors/processors/SplitRecord.h:
##########
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include "core/Annotation.h"
+#include "core/ProcessContext.h"
+#include "core/ProcessSession.h"
+#include "core/ProcessSessionFactory.h"
+#include "core/PropertyDefinition.h"
+#include "core/PropertyDefinitionBuilder.h"
+#include "core/RelationshipDefinition.h"
+#include "core/logging/Logger.h"
+#include "controllers/RecordSetReader.h"
+#include "controllers/RecordSetWriter.h"
+#include "core/AbstractProcessor.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+class SplitRecord final : public core::AbstractProcessor<SplitRecord> {
+ public:
+  using core::AbstractProcessor<SplitRecord>::AbstractProcessor;
+
+  EXTENSIONAPI static constexpr const char* Description = "Splits up an input FlowFile that is in a record-oriented data format into multiple smaller FlowFiles";
+
+  EXTENSIONAPI static constexpr auto RecordReader = core::PropertyDefinitionBuilder<>::createProperty("Record Reader")
+      .withDescription("Specifies the Controller Service to use for reading incoming data")
+      .isRequired(true)
+      .withAllowedTypes<minifi::core::RecordSetReader>()
+      .build();
+  EXTENSIONAPI static constexpr auto RecordWriter = core::PropertyDefinitionBuilder<>::createProperty("Record Writer")
+      .withDescription("Specifies the Controller Service to use for writing out the records")
+      .isRequired(true)
+      .withAllowedTypes<minifi::core::RecordSetWriter>()
+      .build();
+  EXTENSIONAPI static constexpr auto RecordsPerSplit = core::PropertyDefinitionBuilder<>::createProperty("Records Per Split")
+      .withDescription("Specifies how many records should be written to each 'split' or 'segment' FlowFile")
+      .isRequired(true)
+      .supportsExpressionLanguage(true)
+      .build();
+
+  EXTENSIONAPI static constexpr auto Properties = std::to_array<core::PropertyReference>({
+      RecordReader,
+      RecordWriter,
+      RecordsPerSplit
+  });
+
+  EXTENSIONAPI static constexpr auto Failure = core::RelationshipDefinition{"failure",
+      "If a FlowFile cannot be transformed from the configured input format to the configured output format, the unchanged FlowFile will be routed to this relationship."};
+  EXTENSIONAPI static constexpr auto Splits = core::RelationshipDefinition{"splits",
+      "The individual 'segments' of the original FlowFile will be routed to this relationship."};
+  EXTENSIONAPI static constexpr auto Original = core::RelationshipDefinition{"original",
+      "Upon successfully splitting an input FlowFile, the original FlowFile will be sent to this relationship."};
+  EXTENSIONAPI static constexpr auto Relationships = std::array{Failure, Splits, Original};
+

Review Comment:
   Output attribute documentation can also be auto-generated (search for `OutputAttributeDefinition` for examples).



##########
extensions/standard-processors/processors/SplitRecord.cpp:
##########
@@ -0,0 +1,119 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "SplitRecord.h"
+
+#include "core/Resource.h"
+#include "nonstd/expected.hpp"
+#include "utils/GeneralUtils.h"
+
+namespace org::apache::nifi::minifi::processors {
+namespace {
+template<typename RecordSetIO>
+std::shared_ptr<RecordSetIO> getRecordSetIO(core::ProcessContext& context, const core::PropertyReference& property) {
+  std::string service_name;
+  if (context.getProperty(property, service_name) && !IsNullOrEmpty(service_name)) {
+    auto record_set_io = std::dynamic_pointer_cast<RecordSetIO>(context.getControllerService(service_name));
+    if (!record_set_io)
+      return nullptr;
+    return record_set_io;
+  }
+  return nullptr;
+}
+}  // namespace
+
+void SplitRecord::onSchedule(core::ProcessContext& context, core::ProcessSessionFactory&) {
+  record_set_reader_ = getRecordSetIO<core::RecordSetReader>(context, RecordReader);
+  if (!record_set_reader_) {
+    throw Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Reader set is missing or invalid");
+  }
+  record_set_writer_ = getRecordSetIO<core::RecordSetWriter>(context, RecordWriter);
+  if (!record_set_writer_) {
+    throw Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Writer set is missing or invalid");

Review Comment:
   why "set"? I would say "property"
   ```suggestion
     if (!record_set_reader_) {
       throw Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Reader property is missing or invalid");
     }
     record_set_writer_ = getRecordSetIO<core::RecordSetWriter>(context, RecordWriter);
     if (!record_set_writer_) {
       throw Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Writer property is missing or invalid");
   ```



##########
PROCESSORS.md:
##########
@@ -2875,6 +2877,41 @@ In the list below, the names of required properties appear in bold. Any other pr
 | segment.original.filename |              | The filename of the parent FlowFile                                                                                            |
 
 
+## SplitRecord
+
+### Description
+
+Splits up an input FlowFile that is in a record-oriented data format into multiple smaller FlowFiles
+
+### Properties
+
+In the list below, the names of required properties appear in bold. Any other properties (not in bold) are considered optional. The table also indicates any default values, and whether a property supports the NiFi Expression Language.
+
+| Name                  | Default Value | Allowable Values | Description                                                                                                                   |
+|-----------------------|---------------|------------------|-------------------------------------------------------------------------------------------------------------------------------|
+| **Record Reader**     |               |                  | Specifies the Controller Service to use for reading incoming data                                                             |
+| **Record Writer**     |               |                  | Specifies the Controller Service to use for writing out the records                                                           |
+| **Records Per Split** |               |                  | Specifies how many records should be written to each 'split' or 'segment' FlowFile<br/>**Supports Expression Language: true** |
+
+### Relationships
+
+| Name     | Description                                                                                                                                                       |
+|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| failure  | If a FlowFile cannot be transformed from the configured input format to the configured output format, the unchanged FlowFile will be routed to this relationship. |
+| original | Upon successfully splitting an input FlowFile, the original FlowFile will be sent to this relationship.                                                           |
+| splits   | The individual 'segments' of the original FlowFile will be routed to this relationship.                                                                           |
+
+### Output Attributes
+
+| Attribute                 | Relationship | Description                                                                                                                    |
+|---------------------------|--------------|--------------------------------------------------------------------------------------------------------------------------------|
+| record.count              |              | The number of records in the FlowFile. This is added to FlowFiles that are routed to the 'splits' Relationship.                |
+| fragment.identifier       |              | All split FlowFiles produced from the same parent FlowFile will have the same randomly generated UUID added for this attribute |

Review Comment:
   We changed this to the ID of the parent flow file for `SegmentContent`; I think we should change it in the same way here for the same reason, and also to be consistent with `SegmentContent`.



##########
extensions/standard-processors/processors/SplitRecord.cpp:
##########
@@ -0,0 +1,119 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "SplitRecord.h"
+
+#include "core/Resource.h"
+#include "nonstd/expected.hpp"
+#include "utils/GeneralUtils.h"
+
+namespace org::apache::nifi::minifi::processors {
+namespace {
+template<typename RecordSetIO>
+std::shared_ptr<RecordSetIO> getRecordSetIO(core::ProcessContext& context, const core::PropertyReference& property) {
+  std::string service_name;
+  if (context.getProperty(property, service_name) && !IsNullOrEmpty(service_name)) {
+    auto record_set_io = std::dynamic_pointer_cast<RecordSetIO>(context.getControllerService(service_name));
+    if (!record_set_io)
+      return nullptr;
+    return record_set_io;
+  }
+  return nullptr;
+}
+}  // namespace
+
+void SplitRecord::onSchedule(core::ProcessContext& context, core::ProcessSessionFactory&) {
+  record_set_reader_ = getRecordSetIO<core::RecordSetReader>(context, RecordReader);
+  if (!record_set_reader_) {
+    throw Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Reader set is missing or invalid");
+  }
+  record_set_writer_ = getRecordSetIO<core::RecordSetWriter>(context, RecordWriter);
+  if (!record_set_writer_) {
+    throw Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Writer set is missing or invalid");
+  }
+}
+
+nonstd::expected<std::size_t, std::string> SplitRecord::readRecordsPerSplit(core::ProcessContext& context, const core::FlowFile& original_flow_file) {
+  std::string value;
+  std::size_t records_per_split = 0;
+  if (context.getProperty(RecordsPerSplit, value, &original_flow_file)) {
+    if (!core::Property::StringToInt(value, records_per_split)) {
+      return nonstd::make_unexpected("Failed to convert Records Per Split property to an integer");
+    } else if (records_per_split < 1) {
+      return nonstd::make_unexpected("Records per split should be set to a number larger than 0");
+    }
+  } else {
+    return nonstd::make_unexpected("Records per split should be set to a valid number larger than 0");

Review Comment:
   ```suggestion
         return nonstd::make_unexpected("Records Per Split should be set to a number larger than 0");
       }
     } else {
       return nonstd::make_unexpected("Records Per Split should be set to a valid number larger than 0");
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2454 Create SplitRecord processor [nifi-minifi-cpp]

Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #1866:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1866#discussion_r1761096899


##########
extensions/standard-processors/processors/SplitRecord.cpp:
##########
@@ -0,0 +1,125 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "SplitRecord.h"
+
+#include "core/Resource.h"
+#include "nonstd/expected.hpp"
+
+namespace org::apache::nifi::minifi::processors {
+namespace {
+template<typename RecordSetIO>
+std::shared_ptr<RecordSetIO> getRecordSetIO(core::ProcessContext& context, const core::PropertyReference& property) {
+  std::string service_name;
+  if (context.getProperty(property, service_name) && !IsNullOrEmpty(service_name)) {
+    auto record_set_io = std::dynamic_pointer_cast<RecordSetIO>(context.getControllerService(service_name));
+    if (!record_set_io)
+      return nullptr;
+    return record_set_io;
+  }
+  return nullptr;
+}
+}  // namespace
+
+SplitRecord::SplitRecord(std::string_view name, const utils::Identifier& uuid)
+    : Processor(name, uuid), logger_{core::logging::LoggerFactory<SplitRecord>::getLogger(uuid)} {}
+
+void SplitRecord::initialize() {
+  setSupportedProperties(Properties);
+  setSupportedRelationships(Relationships);
+}
+
+void SplitRecord::onSchedule(core::ProcessContext& context, core::ProcessSessionFactory&) {
+  record_set_reader_ = getRecordSetIO<core::RecordSetReader>(context, SplitRecord::RecordReader);
+  if (!record_set_reader_) {
+    throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Reader set is missing or invalid");
+  }
+  record_set_writer_ = getRecordSetIO<core::RecordSetWriter>(context, SplitRecord::RecordWriter);
+  if (!record_set_writer_) {
+    throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Writer set is missing or invalid");
+  }
+}
+
+nonstd::expected<std::size_t, std::string> SplitRecord::readRecordsPerSplit(core::ProcessContext& context, const std::shared_ptr<core::FlowFile>& original_flow_file) {

Review Comment:
   Changed parameter to reference in cd1fd88b37b81b1852928546b042491154b4dc01
   
   In this case I would keep the string error value, as the return value is only used once and it needs an error message, introducing an error code would only result one more step of retrieving the error message without any additional value.



##########
extensions/standard-processors/processors/SplitRecord.cpp:
##########
@@ -0,0 +1,125 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "SplitRecord.h"
+
+#include "core/Resource.h"
+#include "nonstd/expected.hpp"
+
+namespace org::apache::nifi::minifi::processors {
+namespace {
+template<typename RecordSetIO>
+std::shared_ptr<RecordSetIO> getRecordSetIO(core::ProcessContext& context, const core::PropertyReference& property) {
+  std::string service_name;
+  if (context.getProperty(property, service_name) && !IsNullOrEmpty(service_name)) {
+    auto record_set_io = std::dynamic_pointer_cast<RecordSetIO>(context.getControllerService(service_name));
+    if (!record_set_io)
+      return nullptr;
+    return record_set_io;
+  }
+  return nullptr;
+}
+}  // namespace
+
+SplitRecord::SplitRecord(std::string_view name, const utils::Identifier& uuid)
+    : Processor(name, uuid), logger_{core::logging::LoggerFactory<SplitRecord>::getLogger(uuid)} {}
+
+void SplitRecord::initialize() {
+  setSupportedProperties(Properties);
+  setSupportedRelationships(Relationships);
+}
+
+void SplitRecord::onSchedule(core::ProcessContext& context, core::ProcessSessionFactory&) {
+  record_set_reader_ = getRecordSetIO<core::RecordSetReader>(context, SplitRecord::RecordReader);
+  if (!record_set_reader_) {
+    throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Reader set is missing or invalid");
+  }
+  record_set_writer_ = getRecordSetIO<core::RecordSetWriter>(context, SplitRecord::RecordWriter);
+  if (!record_set_writer_) {
+    throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Writer set is missing or invalid");
+  }
+}
+
+nonstd::expected<std::size_t, std::string> SplitRecord::readRecordsPerSplit(core::ProcessContext& context, const std::shared_ptr<core::FlowFile>& original_flow_file) {
+  std::string value;
+  std::size_t records_per_split = 0;
+  if (context.getProperty(RecordsPerSplit, value, original_flow_file.get())) {
+    if (!core::Property::StringToInt(value, records_per_split)) {
+      return nonstd::make_unexpected("Failed to convert Records Per Split property to an integer");
+    } else if (records_per_split < 1) {
+      return nonstd::make_unexpected("Records per split should be set to a number larger than 0");
+    }
+  } else {
+    return nonstd::make_unexpected("Records per split should be set to a valid number larger than 0");
+  }
+  return records_per_split;
+}
+
+void SplitRecord::onTrigger(core::ProcessContext& context, core::ProcessSession& session) {
+  const auto original_flow_file = session.get();
+  if (!original_flow_file) {
+    yield();
+    return;
+  }
+
+  auto records_per_split = readRecordsPerSplit(context, original_flow_file);
+  if (!records_per_split) {
+    logger_->log_error("Failed to read Records Per Split property: {}", records_per_split.error());
+    session.transfer(original_flow_file, Failure);
+    return;
+  }
+
+  auto record_set = record_set_reader_->read(original_flow_file, session);
+  if (!record_set) {
+    logger_->log_error("Failed to read record set from flow file: {}", record_set.error().message());
+    session.transfer(original_flow_file, Failure);
+    return;
+  }
+
+  std::size_t current_index = 0;
+  const auto fragment_identifier = utils::IdGenerator::getIdGenerator()->generate().to_string();
+  std::size_t fragment_index = 0;
+  std::size_t fragment_count = record_set->size() / records_per_split.value() + (record_set->size() % records_per_split.value() == 0 ? 0 : 1);

Review Comment:
   Updated in cd1fd88b37b81b1852928546b042491154b4dc01



##########
extensions/standard-processors/processors/SplitRecord.cpp:
##########
@@ -0,0 +1,125 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "SplitRecord.h"
+
+#include "core/Resource.h"
+#include "nonstd/expected.hpp"
+
+namespace org::apache::nifi::minifi::processors {
+namespace {
+template<typename RecordSetIO>
+std::shared_ptr<RecordSetIO> getRecordSetIO(core::ProcessContext& context, const core::PropertyReference& property) {
+  std::string service_name;
+  if (context.getProperty(property, service_name) && !IsNullOrEmpty(service_name)) {
+    auto record_set_io = std::dynamic_pointer_cast<RecordSetIO>(context.getControllerService(service_name));
+    if (!record_set_io)
+      return nullptr;
+    return record_set_io;
+  }
+  return nullptr;
+}
+}  // namespace
+
+SplitRecord::SplitRecord(std::string_view name, const utils::Identifier& uuid)
+    : Processor(name, uuid), logger_{core::logging::LoggerFactory<SplitRecord>::getLogger(uuid)} {}
+
+void SplitRecord::initialize() {
+  setSupportedProperties(Properties);
+  setSupportedRelationships(Relationships);
+}
+
+void SplitRecord::onSchedule(core::ProcessContext& context, core::ProcessSessionFactory&) {
+  record_set_reader_ = getRecordSetIO<core::RecordSetReader>(context, SplitRecord::RecordReader);
+  if (!record_set_reader_) {
+    throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Reader set is missing or invalid");
+  }
+  record_set_writer_ = getRecordSetIO<core::RecordSetWriter>(context, SplitRecord::RecordWriter);
+  if (!record_set_writer_) {
+    throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Writer set is missing or invalid");
+  }
+}
+
+nonstd::expected<std::size_t, std::string> SplitRecord::readRecordsPerSplit(core::ProcessContext& context, const std::shared_ptr<core::FlowFile>& original_flow_file) {
+  std::string value;
+  std::size_t records_per_split = 0;
+  if (context.getProperty(RecordsPerSplit, value, original_flow_file.get())) {
+    if (!core::Property::StringToInt(value, records_per_split)) {
+      return nonstd::make_unexpected("Failed to convert Records Per Split property to an integer");
+    } else if (records_per_split < 1) {
+      return nonstd::make_unexpected("Records per split should be set to a number larger than 0");
+    }
+  } else {
+    return nonstd::make_unexpected("Records per split should be set to a valid number larger than 0");
+  }
+  return records_per_split;
+}
+
+void SplitRecord::onTrigger(core::ProcessContext& context, core::ProcessSession& session) {
+  const auto original_flow_file = session.get();
+  if (!original_flow_file) {
+    yield();
+    return;
+  }
+
+  auto records_per_split = readRecordsPerSplit(context, original_flow_file);
+  if (!records_per_split) {
+    logger_->log_error("Failed to read Records Per Split property: {}", records_per_split.error());
+    session.transfer(original_flow_file, Failure);
+    return;
+  }
+
+  auto record_set = record_set_reader_->read(original_flow_file, session);
+  if (!record_set) {
+    logger_->log_error("Failed to read record set from flow file: {}", record_set.error().message());
+    session.transfer(original_flow_file, Failure);
+    return;
+  }
+
+  std::size_t current_index = 0;
+  const auto fragment_identifier = utils::IdGenerator::getIdGenerator()->generate().to_string();
+  std::size_t fragment_index = 0;
+  std::size_t fragment_count = record_set->size() / records_per_split.value() + (record_set->size() % records_per_split.value() == 0 ? 0 : 1);
+  while (current_index < record_set->size()) {
+    auto split_flow_file = session.create(original_flow_file.get());
+    if (!split_flow_file) {
+      logger_->log_error("Failed to create a new flow file for record set");
+      session.transfer(original_flow_file, Failure);
+      return;
+    }
+
+    core::RecordSet slice_record_set;

Review Comment:
   Updated in cd1fd88b37b81b1852928546b042491154b4dc01



##########
extensions/standard-processors/processors/SplitRecord.cpp:
##########


Review Comment:
   Updated in cd1fd88b37b81b1852928546b042491154b4dc01



##########
extensions/standard-processors/processors/SplitRecord.h:
##########
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include "core/Annotation.h"
+#include "core/Processor.h"
+#include "core/ProcessContext.h"
+#include "core/ProcessSession.h"
+#include "core/ProcessSessionFactory.h"
+#include "core/PropertyDefinition.h"
+#include "core/PropertyDefinitionBuilder.h"
+#include "core/RelationshipDefinition.h"
+#include "core/logging/Logger.h"
+#include "controllers/RecordSetReader.h"
+#include "controllers/RecordSetWriter.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+class SplitRecord : public core::Processor {
+ public:
+  EXTENSIONAPI static constexpr const char* Description = "Splits up an input FlowFile that is in a record-oriented data format into multiple smaller FlowFiles";
+
+  EXTENSIONAPI static constexpr auto RecordReader = core::PropertyDefinitionBuilder<>::createProperty("Record Reader")
+      .withDescription("Specifies the Controller Service to use for reading incoming data")
+      .isRequired(true)
+      .withAllowedTypes<minifi::core::RecordSetReader>()
+      .build();
+  EXTENSIONAPI static constexpr auto RecordWriter = core::PropertyDefinitionBuilder<>::createProperty("Record Writer")
+      .withDescription("Specifies the Controller Service to use for writing out the records")
+      .isRequired(true)
+      .withAllowedTypes<minifi::core::RecordSetWriter>()
+      .build();
+  EXTENSIONAPI static constexpr auto RecordsPerSplit = core::PropertyDefinitionBuilder<>::createProperty("Records Per Split")
+      .withDescription("Specifies how many records should be written to each 'split' or 'segment' FlowFile")
+      .isRequired(true)
+      .supportsExpressionLanguage(true)
+      .build();
+
+  EXTENSIONAPI static constexpr auto Properties = std::to_array<core::PropertyReference>({
+      RecordReader,
+      RecordWriter,
+      RecordsPerSplit
+  });
+
+  EXTENSIONAPI static constexpr auto Failure = core::RelationshipDefinition{"failure",
+      "If a FlowFile cannot be transformed from the configured input format to the configured output format, the unchanged FlowFile will be routed to this relationship."};
+  EXTENSIONAPI static constexpr auto Splits = core::RelationshipDefinition{"splits",
+      "The individual 'segments' of the original FlowFile will be routed to this relationship."};
+  EXTENSIONAPI static constexpr auto Original = core::RelationshipDefinition{"original",
+      "Upon successfully splitting an input FlowFile, the original FlowFile will be sent to this relationship."};
+  EXTENSIONAPI static constexpr auto Relationships = std::array{Failure, Splits, Original};
+
+  EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
+  EXTENSIONAPI static constexpr bool SupportsDynamicRelationships = false;
+  EXTENSIONAPI static constexpr core::annotation::Input InputRequirement = core::annotation::Input::INPUT_REQUIRED;
+  EXTENSIONAPI static constexpr bool IsSingleThreaded = false;
+
+  ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS

Review Comment:
   Thanks for the suggestion, replaced the macro with the AbstractProcessor class in cd1fd88b37b81b1852928546b042491154b4dc01



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2454 Create SplitRecord processor [nifi-minifi-cpp]

Posted by "martinzink (via GitHub)" <gi...@apache.org>.
martinzink commented on code in PR #1866:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1866#discussion_r1799556788


##########
extensions/standard-processors/tests/unit/SplitRecordTests.cpp:
##########
@@ -0,0 +1,96 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "unit/TestBase.h"
+#include "unit/Catch.h"
+#include "processors/SplitRecord.h"
+#include "unit/SingleProcessorTestController.h"
+#include "utils/StringUtils.h"
+#include "rapidjson/document.h"
+
+namespace org::apache::nifi::minifi::test {
+
+class SplitRecordTestController : public TestController {
+ public:
+  SplitRecordTestController() {
+    controller_.plan->addController("JsonRecordSetReader", "JsonRecordSetReader");
+    controller_.plan->addController("JsonRecordSetWriter", "JsonRecordSetWriter");
+    proc_->setProperty(processors::SplitRecord::RecordReader, "JsonRecordSetReader");
+    proc_->setProperty(processors::SplitRecord::RecordWriter, "JsonRecordSetWriter");
+  }
+
+  void verifyResults(const ProcessorTriggerResult& results, const std::vector<std::string>& expected_contents) const {
+    REQUIRE(results.at(processors::SplitRecord::Original).size() == 1);
+    REQUIRE(results.at(processors::SplitRecord::Splits).size() == expected_contents.size());
+    auto& split_results = results.at(processors::SplitRecord::Splits);
+    const auto fragment_identifier = split_results[0]->getAttribute("fragment.identifier").value();
+    const auto original_filename = results.at(processors::SplitRecord::Original)[0]->getAttribute("filename").value();
+    for (size_t i = 0; i < expected_contents.size(); ++i) {
+      rapidjson::Document result_document;
+      result_document.Parse(controller_.plan->getContent(split_results[i]).c_str());
+      rapidjson::Document expected_document;
+      expected_document.Parse(expected_contents[i].c_str());
+      CHECK(result_document == expected_document);
+      CHECK(split_results[i]->getAttribute("record.count").value() ==   std::to_string(minifi::utils::string::split(expected_contents[i], "},{").size()));
+      CHECK(split_results[i]->getAttribute("fragment.index").value() == std::to_string(i));
+      CHECK(split_results[i]->getAttribute("fragment.count").value() == std::to_string(expected_contents.size()));
+      CHECK(split_results[i]->getAttribute("fragment.identifier").value() == fragment_identifier);
+      CHECK(split_results[i]->getAttribute("segment.original.filename").value() == original_filename);
+    }
+  }
+
+ protected:
+  std::shared_ptr<core::Processor> proc_ = std::make_shared<processors::SplitRecord>("SplitRecord");
+  SingleProcessorTestController controller_{proc_};
+};
+
+TEST_CASE_METHOD(SplitRecordTestController, "Invalid Records Per Split property", "[splitrecord]") {
+  proc_->setProperty(processors::SplitRecord::RecordsPerSplit, "invalid");
+  auto results = controller_.trigger({InputFlowFileData{"{\"name\": \"John\"}\n{\"name\": \"Jill\"}"}});
+  REQUIRE(results[processors::SplitRecord::Failure].size() == 1);
+  REQUIRE(LogTestController::getInstance().contains("Failed to convert Records Per Split property to an integer", 1s));
+}
+
+TEST_CASE_METHOD(SplitRecordTestController, "Records Per Split property should be greater than zero", "[splitrecord]") {
+  proc_->setProperty(processors::SplitRecord::RecordsPerSplit, "${id}");
+  auto results = controller_.trigger({InputFlowFileData{"{\"name\": \"John\"}\n{\"name\": \"Jill\"}", {{"id", "0"}}}});
+  REQUIRE(results[processors::SplitRecord::Failure].size() == 1);
+  REQUIRE(LogTestController::getInstance().contains("Records per split should be set to a number larger than 0", 1s));
+}

Review Comment:
   I think we might want to consider restructuring tests so we can separate tests which need additional extensions, but that seems out of the scope of this PR. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2454 Create SplitRecord processor [nifi-minifi-cpp]

Posted by "fgerlits (via GitHub)" <gi...@apache.org>.
fgerlits closed pull request #1866: MINIFICPP-2454 Create SplitRecord processor
URL: https://github.com/apache/nifi-minifi-cpp/pull/1866


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2454 Create SplitRecord processor [nifi-minifi-cpp]

Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #1866:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1866#discussion_r1842192376


##########
extensions/standard-processors/processors/SplitRecord.cpp:
##########
@@ -0,0 +1,119 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "SplitRecord.h"
+
+#include "core/Resource.h"
+#include "nonstd/expected.hpp"
+#include "utils/GeneralUtils.h"
+
+namespace org::apache::nifi::minifi::processors {
+namespace {
+template<typename RecordSetIO>
+std::shared_ptr<RecordSetIO> getRecordSetIO(core::ProcessContext& context, const core::PropertyReference& property) {
+  std::string service_name;
+  if (context.getProperty(property, service_name) && !IsNullOrEmpty(service_name)) {
+    auto record_set_io = std::dynamic_pointer_cast<RecordSetIO>(context.getControllerService(service_name));
+    if (!record_set_io)
+      return nullptr;
+    return record_set_io;
+  }
+  return nullptr;
+}
+}  // namespace
+
+void SplitRecord::onSchedule(core::ProcessContext& context, core::ProcessSessionFactory&) {
+  record_set_reader_ = getRecordSetIO<core::RecordSetReader>(context, RecordReader);
+  if (!record_set_reader_) {
+    throw Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Reader set is missing or invalid");
+  }
+  record_set_writer_ = getRecordSetIO<core::RecordSetWriter>(context, RecordWriter);
+  if (!record_set_writer_) {
+    throw Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Record Writer set is missing or invalid");

Review Comment:
   Fixed in https://github.com/apache/nifi-minifi-cpp/pull/1866/commits/b9de420231ec51690b584cab09189236bfe2eabd



##########
PROCESSORS.md:
##########
@@ -2875,6 +2877,41 @@ In the list below, the names of required properties appear in bold. Any other pr
 | segment.original.filename |              | The filename of the parent FlowFile                                                                                            |
 
 
+## SplitRecord
+
+### Description
+
+Splits up an input FlowFile that is in a record-oriented data format into multiple smaller FlowFiles
+
+### Properties
+
+In the list below, the names of required properties appear in bold. Any other properties (not in bold) are considered optional. The table also indicates any default values, and whether a property supports the NiFi Expression Language.
+
+| Name                  | Default Value | Allowable Values | Description                                                                                                                   |
+|-----------------------|---------------|------------------|-------------------------------------------------------------------------------------------------------------------------------|
+| **Record Reader**     |               |                  | Specifies the Controller Service to use for reading incoming data                                                             |
+| **Record Writer**     |               |                  | Specifies the Controller Service to use for writing out the records                                                           |
+| **Records Per Split** |               |                  | Specifies how many records should be written to each 'split' or 'segment' FlowFile<br/>**Supports Expression Language: true** |
+
+### Relationships
+
+| Name     | Description                                                                                                                                                       |
+|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| failure  | If a FlowFile cannot be transformed from the configured input format to the configured output format, the unchanged FlowFile will be routed to this relationship. |
+| original | Upon successfully splitting an input FlowFile, the original FlowFile will be sent to this relationship.                                                           |
+| splits   | The individual 'segments' of the original FlowFile will be routed to this relationship.                                                                           |
+
+### Output Attributes
+
+| Attribute                 | Relationship | Description                                                                                                                    |
+|---------------------------|--------------|--------------------------------------------------------------------------------------------------------------------------------|
+| record.count              |              | The number of records in the FlowFile. This is added to FlowFiles that are routed to the 'splits' Relationship.                |
+| fragment.identifier       |              | All split FlowFiles produced from the same parent FlowFile will have the same randomly generated UUID added for this attribute |

Review Comment:
   Good point, updated in https://github.com/apache/nifi-minifi-cpp/pull/1866/commits/b9de420231ec51690b584cab09189236bfe2eabd



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org