You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "martinzink (via GitHub)" <gi...@apache.org> on 2024/04/19 11:43:45 UTC

[PR] MINIFICPP-2311 Initial support for recordset readers and writers [nifi-minifi-cpp]

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

   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-2311 Initial support for recordset readers and writers [nifi-minifi-cpp]

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


##########
extensions/standard-processors/tests/unit/JsonRecordTests.cpp:
##########
@@ -0,0 +1,145 @@
+/**
+* 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.c
+ */
+
+#include <numbers>
+#include <variant>
+
+#include "Catch.h"
+#include "RecordSetTesters.h"
+#include "TestBase.h"
+#include "TestRecord.h"
+#include "controllers/JsonRecordSetReader.h"
+#include "controllers/JsonRecordSetWriter.h"
+#include "core/Record.h"
+
+namespace org::apache::nifi::minifi::standard::test {
+
+constexpr std::string_view record_per_line_str = R"({"baz":3.14,"qux":[true,false,true],"is_test":true,"bar":123,"quux":{"Aprikose":"apricot","Birne":"pear","Apfel":"apple"},"foo":"asd","when":"2012-07-01T09:53:00Z"}
+{"baz":3.141592653589793,"qux":[false,false,true],"is_test":true,"bar":98402134,"quux":{"Aprikose":"abricot","Birne":"poire","Apfel":"pomme"},"foo":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","when":"2022-11-01T19:52:11Z"}
+)";
+constexpr std::string_view array_compressed_str = R"([{"baz":3.14,"qux":[true,false,true],"is_test":true,"bar":123,"quux":{"Aprikose":"apricot","Birne":"pear","Apfel":"apple"},"foo":"asd","when":"2012-07-01T09:53:00Z"},{"baz":3.141592653589793,"qux":[false,false,true],"is_test":true,"bar":98402134,"quux":{"Aprikose":"abricot","Birne":"poire","Apfel":"pomme"},"foo":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","when":"2022-11-01T19:52:11Z"}])";
+constexpr std::string_view array_pretty_str = R"([
+    {
+        "baz": 3.14,
+        "qux": [
+            true,
+            false,
+            true
+        ],
+        "is_test": true,
+        "bar": 123,
+        "quux": {
+            "Aprikose": "apricot",
+            "Birne": "pear",
+            "Apfel": "apple"
+        },
+        "foo": "asd",
+        "when": "2012-07-01T09:53:00Z"
+    },
+    {
+        "baz": 3.141592653589793,
+        "qux": [
+            false,
+            false,
+            true
+        ],
+        "is_test": true,
+        "bar": 98402134,
+        "quux": {
+            "Aprikose": "abricot",
+            "Birne": "poire",
+            "Apfel": "pomme"
+        },
+        "foo": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
+        "when": "2022-11-01T19:52:11Z"
+    }
+])";
+
+bool test_json_equality(const std::string_view expected_str, const std::string_view actual_str) {

Review Comment:
   👍  https://github.com/apache/nifi-minifi-cpp/pull/1763/commits/c9aa16d7cd2ea2bd69e0345f365213f5a403cda2#diff-57d2adaddec9ace677119724e550df7ec037b8cad18b8cf32dca577d73787014R73



-- 
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-2311 Initial support for recordset readers and writers [nifi-minifi-cpp]

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


##########
extensions/standard-processors/controllers/JsonRecordSetWriter.h:
##########
@@ -0,0 +1,93 @@
+/**
+* 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 "PropertyDefinitionBuilder.h"
+#include "Record.h"
+#include "controllers/RecordSetWriter.h"
+#include "core/FlowFile.h"
+#include "core/ProcessSession.h"
+#include "utils/Enum.h"
+
+namespace org::apache::nifi::minifi::standard {
+
+enum class OutputGroupingType {
+  Array,
+  OneLinePerObject
+};
+
+class JsonRecordSetWriter final : public core::RecordSetWriter {
+ public:
+  explicit JsonRecordSetWriter(const std::string& name, const utils::Identifier& uuid = {});
+  explicit JsonRecordSetWriter(const std::string& name, const std::shared_ptr<Configure>& configuration);
+
+  JsonRecordSetWriter(JsonRecordSetWriter&&) = delete;
+  JsonRecordSetWriter(const JsonRecordSetWriter&) = delete;
+  JsonRecordSetWriter& operator=(JsonRecordSetWriter&&) = delete;
+  JsonRecordSetWriter& operator=(const JsonRecordSetWriter&) = delete;
+
+  ~JsonRecordSetWriter() override = default;
+
+  EXTENSIONAPI static constexpr const char* Description =
+      "Writes the results of a RecordSet as either a JSON Array or one JSON object per line. "
+      "If using Array output, then even if the RecordSet consists of a single row, it will be written as an array with a single element. "
+      "If using One Line Per Object output, the JSON objects cannot be pretty-printed.";
+
+  EXTENSIONAPI static constexpr auto OutputGrouping = core::PropertyDefinitionBuilder<magic_enum::enum_count<OutputGroupingType>()>::createProperty("Output Grouping")
+    .withDescription("Specifies how the writer should output the JSON records (as an array or one object per line, e.g.) "
+                    "Note that if 'One Line Per Object' is selected, then Pretty Print JSON must be false.")

Review Comment:
   agree 👍  https://github.com/apache/nifi-minifi-cpp/pull/1763/commits/c9aa16d7cd2ea2bd69e0345f365213f5a403cda2#diff-f10913418d7471adbf70fd555a46415f88c6cc031efb380861ab93d744c5c94dR76
   
   https://github.com/apache/nifi-minifi-cpp/pull/1763/commits/c9aa16d7cd2ea2bd69e0345f365213f5a403cda2#diff-f10913418d7471adbf70fd555a46415f88c6cc031efb380861ab93d744c5c94dR31-R48



-- 
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-2311 Initial support for recordset readers and writers [nifi-minifi-cpp]

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


##########
extensions/standard-processors/controllers/JsonRecordSetWriter.h:
##########
@@ -0,0 +1,107 @@
+/**
+* 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 "PropertyDefinitionBuilder.h"
+#include "Record.h"
+#include "controllers/RecordSetWriter.h"
+#include "core/FlowFile.h"
+#include "core/ProcessSession.h"
+#include "utils/Enum.h"
+
+namespace org::apache::nifi::minifi::standard {
+enum class OutputGroupingType {
+  ARRAY,
+  ONE_LINE_PER_OBJECT
+};
+}  // namespace org::apache::nifi::minifi::standard
+
+namespace magic_enum::customize {
+using OutputGroupingType = org::apache::nifi::minifi::standard::OutputGroupingType;
+
+template <>
+constexpr customize_t enum_name<OutputGroupingType>(OutputGroupingType value) noexcept {
+  switch (value) {
+    case OutputGroupingType::ARRAY:
+      return "Array";
+    case OutputGroupingType::ONE_LINE_PER_OBJECT:
+      return "One Line Per Object";
+  }
+  return invalid_tag;
+}
+}  // namespace magic_enum::customize
+
+namespace org::apache::nifi::minifi::standard {
+
+class JsonRecordSetWriter final : public core::RecordSetWriter {
+ public:
+  explicit JsonRecordSetWriter(const std::string_view name, const utils::Identifier& uuid = {}) : RecordSetWriter(name, uuid) {}
+
+  JsonRecordSetWriter(JsonRecordSetWriter&&) = delete;
+  JsonRecordSetWriter(const JsonRecordSetWriter&) = delete;
+  JsonRecordSetWriter& operator=(JsonRecordSetWriter&&) = delete;
+  JsonRecordSetWriter& operator=(const JsonRecordSetWriter&) = delete;
+
+  ~JsonRecordSetWriter() override = default;
+
+  EXTENSIONAPI static constexpr const char* Description =
+      "Writes the results of a RecordSet as either a JSON Array or one JSON object per line. "
+      "If using Array output, then even if the RecordSet consists of a single row, it will be written as an array with a single element. "
+      "If using One Line Per Object output, the JSON objects cannot be pretty-printed.";
+
+  EXTENSIONAPI static constexpr auto OutputGrouping = core::PropertyDefinitionBuilder<magic_enum::enum_count<OutputGroupingType>()>::createProperty("Output Grouping")
+    .withDescription("Specifies how the writer should output the JSON records (as an array or one object per line, e.g.) "
+                    "Note that if 'One Line Per Object' is selected, then Pretty Print JSON is ignored.")

Review Comment:
   good point, originally I just copy pasted NiFi's description, but admitedly it can be improved https://github.com/apache/nifi-minifi-cpp/pull/1763/commits/a96de10e7be3ded6e2ac3e835673fd759b948294



-- 
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-2311 Initial support for recordset readers and writers [nifi-minifi-cpp]

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


##########
libminifi/test/RecordSetTesters.h:
##########
@@ -0,0 +1,82 @@
+/**
+*
+ * 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 "controllers/RecordSetReader.h"
+#include "controllers/RecordSetWriter.h"
+#include "core/Record.h"
+#include "TestBase.h"
+
+namespace org::apache::nifi::minifi::core::test {
+
+class RecordSetFixture {
+ public:
+  explicit RecordSetFixture(TestController::PlanConfig config = {}): plan_config_(std::move(config)) {}
+
+  [[nodiscard]] ProcessSession& processSession() const { return *process_session_; }
+
+  [[nodiscard]] const Relationship& getRelationship() const { return relationship_; }
+ private:
+  TestController test_controller_{};
+  TestController::PlanConfig plan_config_{};
+  std::shared_ptr<TestPlan> test_plan_ = test_controller_.createPlan(plan_config_);
+  std::shared_ptr<Processor> dummy_processor_ = test_plan_->addProcessor("DummyProcessor", "dummyProcessor");
+  std::shared_ptr<ProcessContext> context_ = [this] { test_plan_->runNextProcessor(); return test_plan_->getCurrentContext(); }();
+  std::unique_ptr<ProcessSession> process_session_ = std::make_unique<ProcessSession>(context_);
+
+  const Relationship relationship_{"success", "description"};
+};
+
+bool testRecordWriter(RecordSetWriter& record_set_writer, const RecordSet& record_set, auto tester) {
+  const RecordSetFixture fixture;
+  ProcessSession& process_session = fixture.processSession();
+
+  const auto flow_file = process_session.create();
+
+  record_set_writer.write(record_set, flow_file, process_session);
+  process_session.transfer(flow_file, fixture.getRelationship());
+  process_session.commit();
+  const auto input_stream = process_session.getFlowFileContentStream(*flow_file);
+  std::array<std::byte, 2048> buffer{};
+  const auto buffer_size = input_stream->read(buffer);
+  const std::string flow_file_content(reinterpret_cast<char*>(buffer.data()), buffer_size);
+
+  return tester(flow_file_content);
+}
+
+inline bool testRecordReader(RecordSetReader& record_set_reader, const std::string_view serialized_record_set, const RecordSet& expected_record_set) {
+  const RecordSetFixture fixture;
+  ProcessSession& process_session = fixture.processSession();
+
+  const auto flow_file = process_session.create();
+  process_session.writeBuffer(flow_file, serialized_record_set);
+  process_session.transfer(flow_file, fixture.getRelationship());
+  process_session.commit();
+
+  const auto record_set = record_set_reader.read(flow_file, process_session);
+  if (!record_set)
+    return false;
+  auto& record_set_0 = (*record_set)[0];
+  auto& expected_set_0 = expected_record_set[0];
+  CHECK(record_set_0 == expected_set_0);

Review Comment:
   Its probably some leftover debugging code, removed it in https://github.com/apache/nifi-minifi-cpp/pull/1763/commits/c9aa16d7cd2ea2bd69e0345f365213f5a403cda2#diff-405287f5b19cb14a6586eb31ccd3080ef179beac643489539f7f72dfbda002bfL75-L77 👍 



-- 
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-2311 Initial support for recordset readers and writers [nifi-minifi-cpp]

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


##########
extensions/standard-processors/controllers/JsonRecordSetReader.h:
##########


Review Comment:
   Good point. I've added JsonRecordSetReader and Writer to Controllers.md
   I like the idea of a how to recordset documentation but maybe thats out of the scope of this PR. I think we should address that if we feel the interface of the RecordSet is stable (multiple users of the RecordSet controllers to iron out the possible kinks)



-- 
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-2311 Initial support for recordset readers and writers [nifi-minifi-cpp]

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


##########
libminifi/include/controllers/RecordSetWriter.h:
##########
@@ -0,0 +1,34 @@
+/**
+* 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/controller/ControllerService.h"
+
+#include "core/FlowFile.h"
+#include "core/ProcessSession.h"
+#include "Record.h"
+
+namespace org::apache::nifi::minifi::core {
+
+class RecordSetWriter : public controller::ControllerService {
+ public:
+  using ControllerService::ControllerService;
+
+  virtual void write(const RecordSet& record_set, const std::shared_ptr<FlowFile>& flow_file, ProcessSession& session) = 0;

Review Comment:
   Unfortunetly we'd need to refactor ProcessSession::read/ProcessSession::write for that



##########
libminifi/include/controllers/RecordSetReader.h:
##########
@@ -0,0 +1,39 @@
+/**
+* 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/controller/ControllerService.h"
+
+#include "core/FlowFile.h"
+#include "core/ProcessSession.h"
+#include "Record.h"
+#include "utils/Enum.h"
+#include "utils/ProcessorConfigUtils.h"
+
+
+namespace org::apache::nifi::minifi::core {
+
+class RecordSetReader : public controller::ControllerService {
+ public:
+  using ControllerService::ControllerService;
+
+
+  virtual nonstd::expected<RecordSet, std::error_code> read(const std::shared_ptr<FlowFile>& flow_file, ProcessSession& session) = 0;

Review Comment:
   Unfortunetly we'd need to refactor ProcessSession::read/ProcessSession::write for that



-- 
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-2311 Initial support for recordset readers and writers [nifi-minifi-cpp]

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


##########
libminifi/include/controllers/RecordSetReader.h:
##########
@@ -0,0 +1,39 @@
+/**
+* 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/controller/ControllerService.h"
+
+#include "core/FlowFile.h"
+#include "core/ProcessSession.h"
+#include "Record.h"
+#include "utils/Enum.h"
+#include "utils/ProcessorConfigUtils.h"
+
+
+namespace org::apache::nifi::minifi::core {
+
+class RecordSetReader : public controller::ControllerService {
+ public:
+  using ControllerService::ControllerService;
+
+
+  virtual nonstd::expected<RecordSet, std::error_code> read(const std::shared_ptr<FlowFile>& flow_file, ProcessSession& session) = 0;

Review Comment:
   Could this be changed to take FlowFile& instead of shared_ptr?



##########
libminifi/include/controllers/RecordSetWriter.h:
##########
@@ -0,0 +1,34 @@
+/**
+* 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/controller/ControllerService.h"
+
+#include "core/FlowFile.h"
+#include "core/ProcessSession.h"
+#include "Record.h"
+
+namespace org::apache::nifi::minifi::core {
+
+class RecordSetWriter : public controller::ControllerService {
+ public:
+  using ControllerService::ControllerService;
+
+  virtual void write(const RecordSet& record_set, const std::shared_ptr<FlowFile>& flow_file, ProcessSession& session) = 0;

Review Comment:
   Could this be changed to take `FlowFile&` instead of `shared_ptr`?



-- 
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-2311 Initial support for recordset readers and writers [nifi-minifi-cpp]

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


##########
extensions/standard-processors/controllers/JsonRecordSetWriter.h:
##########
@@ -0,0 +1,93 @@
+/**
+* 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 "PropertyDefinitionBuilder.h"
+#include "Record.h"
+#include "controllers/RecordSetWriter.h"
+#include "core/FlowFile.h"
+#include "core/ProcessSession.h"
+#include "utils/Enum.h"
+
+namespace org::apache::nifi::minifi::standard {
+
+enum class OutputGroupingType {
+  Array,
+  OneLinePerObject
+};
+
+class JsonRecordSetWriter final : public core::RecordSetWriter {
+ public:
+  explicit JsonRecordSetWriter(const std::string& name, const utils::Identifier& uuid = {});
+  explicit JsonRecordSetWriter(const std::string& name, const std::shared_ptr<Configure>& configuration);
+
+  JsonRecordSetWriter(JsonRecordSetWriter&&) = delete;
+  JsonRecordSetWriter(const JsonRecordSetWriter&) = delete;
+  JsonRecordSetWriter& operator=(JsonRecordSetWriter&&) = delete;
+  JsonRecordSetWriter& operator=(const JsonRecordSetWriter&) = delete;
+
+  ~JsonRecordSetWriter() override = default;
+
+  EXTENSIONAPI static constexpr const char* Description =
+      "Writes the results of a RecordSet as either a JSON Array or one JSON object per line. "
+      "If using Array output, then even if the RecordSet consists of a single row, it will be written as an array with a single element. "
+      "If using One Line Per Object output, the JSON objects cannot be pretty-printed.";
+
+  EXTENSIONAPI static constexpr auto OutputGrouping = core::PropertyDefinitionBuilder<magic_enum::enum_count<OutputGroupingType>()>::createProperty("Output Grouping")
+    .withDescription("Specifies how the writer should output the JSON records (as an array or one object per line, e.g.) "
+                    "Note that if 'One Line Per Object' is selected, then Pretty Print JSON must be false.")
+    .withDefaultValue(magic_enum::enum_name(OutputGroupingType::Array))
+    .withAllowedValues(magic_enum::enum_names<OutputGroupingType>())
+    .supportsExpressionLanguage(false)
+    .isRequired(true)
+    .build();
+
+  EXTENSIONAPI static constexpr auto PrettyPrint = core::PropertyDefinitionBuilder<>::createProperty("Pretty Print JSON")
+    .withDescription("Specifies whether or not the JSON should be pretty printed")

Review Comment:
   Good idea https://github.com/apache/nifi-minifi-cpp/pull/1763/commits/c9aa16d7cd2ea2bd69e0345f365213f5a403cda2#diff-f10913418d7471adbf70fd555a46415f88c6cc031efb380861ab93d744c5c94dR76



-- 
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-2311 Initial support for recordset readers and writers [nifi-minifi-cpp]

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


##########
libminifi/test/TestRecord.h:
##########


Review Comment:
   Those example record contain all the fields that Record support, and there is nothing that Json specific, any new RecordSetReader/RecordSetWriter could use these to show how their serialization/deserialization work.



-- 
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-2311 Initial support for recordset readers and writers [nifi-minifi-cpp]

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


##########
extensions/standard-processors/tests/unit/JsonRecordTests.cpp:
##########
@@ -0,0 +1,145 @@
+/**
+* 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.c
+ */
+
+#include <numbers>
+#include <variant>
+
+#include "Catch.h"
+#include "RecordSetTesters.h"
+#include "TestBase.h"
+#include "TestRecord.h"
+#include "controllers/JsonRecordSetReader.h"
+#include "controllers/JsonRecordSetWriter.h"
+#include "core/Record.h"
+
+namespace org::apache::nifi::minifi::standard::test {
+
+constexpr std::string_view record_per_line_str = R"({"baz":3.14,"qux":[true,false,true],"is_test":true,"bar":123,"quux":{"Aprikose":"apricot","Birne":"pear","Apfel":"apple"},"foo":"asd","when":"2012-07-01T09:53:00Z"}
+{"baz":3.141592653589793,"qux":[false,false,true],"is_test":true,"bar":98402134,"quux":{"Aprikose":"abricot","Birne":"poire","Apfel":"pomme"},"foo":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","when":"2022-11-01T19:52:11Z"}
+)";
+constexpr std::string_view array_compressed_str = R"([{"baz":3.14,"qux":[true,false,true],"is_test":true,"bar":123,"quux":{"Aprikose":"apricot","Birne":"pear","Apfel":"apple"},"foo":"asd","when":"2012-07-01T09:53:00Z"},{"baz":3.141592653589793,"qux":[false,false,true],"is_test":true,"bar":98402134,"quux":{"Aprikose":"abricot","Birne":"poire","Apfel":"pomme"},"foo":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","when":"2022-11-01T19:52:11Z"}])";
+constexpr std::string_view array_pretty_str = R"([
+    {
+        "baz": 3.14,
+        "qux": [
+            true,
+            false,
+            true
+        ],
+        "is_test": true,
+        "bar": 123,
+        "quux": {
+            "Aprikose": "apricot",
+            "Birne": "pear",
+            "Apfel": "apple"
+        },
+        "foo": "asd",
+        "when": "2012-07-01T09:53:00Z"
+    },
+    {
+        "baz": 3.141592653589793,
+        "qux": [
+            false,
+            false,
+            true
+        ],
+        "is_test": true,
+        "bar": 98402134,
+        "quux": {
+            "Aprikose": "abricot",
+            "Birne": "poire",
+            "Apfel": "pomme"
+        },
+        "foo": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
+        "when": "2022-11-01T19:52:11Z"
+    }
+])";
+
+bool test_json_equality(const std::string_view expected_str, const std::string_view actual_str) {
+  rapidjson::Document expected;
+  expected.Parse(expected_str.data());
+  rapidjson::Document actual;
+  actual.Parse(actual_str.data());
+  return actual == expected;
+}
+
+TEST_CASE("JsonRecordSetWriter test Record Per Line") {
+  core::RecordSet record_set;
+  record_set.push_back(core::test::createSampleRecord());
+  record_set.push_back(core::test::createSampleRecord2());
+
+  JsonRecordSetWriter json_record_set_writer;
+  json_record_set_writer.initialize();
+  CHECK(json_record_set_writer.setProperty(JsonRecordSetWriter::OutputGrouping, "OneLinePerObject"));
+  json_record_set_writer.onEnable();
+  CHECK(core::test::testRecordWriter(json_record_set_writer, record_set, [](auto serialized_record_set) -> bool {
+    return test_json_equality(record_per_line_str, serialized_record_set);
+  }));
+}
+
+TEST_CASE("JsonRecordSetWriter test array") {
+  core::RecordSet record_set;
+  record_set.push_back(core::test::createSampleRecord());
+  record_set.push_back(core::test::createSampleRecord2());
+
+  JsonRecordSetWriter json_record_set_writer;
+  CHECK(core::test::testRecordWriter(json_record_set_writer, record_set, [](auto serialized_record_set) -> bool {
+    return test_json_equality(array_compressed_str, serialized_record_set);
+  }));
+}
+
+TEST_CASE("JsonRecordSetWriter test pretty array") {
+  core::RecordSet record_set;
+  record_set.push_back(core::test::createSampleRecord());
+  record_set.push_back(core::test::createSampleRecord2());
+
+  JsonRecordSetWriter json_record_set_writer;
+  json_record_set_writer.initialize();
+  CHECK(json_record_set_writer.setProperty(JsonRecordSetWriter::PrettyPrint, "true"));
+  json_record_set_writer.onEnable();
+  CHECK(core::test::testRecordWriter(json_record_set_writer, record_set, [](auto serialized_record_set) -> bool {
+    return test_json_equality(array_pretty_str, serialized_record_set);
+  }));
+}
+
+TEST_CASE("JsonRecordSetReader per line") {

Review Comment:
   Good idea 👍 https://github.com/apache/nifi-minifi-cpp/pull/1763/commits/c9aa16d7cd2ea2bd69e0345f365213f5a403cda2#diff-57d2adaddec9ace677119724e550df7ec037b8cad18b8cf32dca577d73787014R106



-- 
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-2311 Initial support for recordset readers and writers [nifi-minifi-cpp]

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


##########
extensions/standard-processors/controllers/JsonRecordSetReader.h:
##########
@@ -0,0 +1,58 @@
+/**
+* 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 "Record.h"
+#include "controllers/RecordSetReader.h"
+#include "core/FlowFile.h"
+#include "core/ProcessSession.h"
+
+namespace org::apache::nifi::minifi::standard {
+
+class JsonRecordSetReader final : public core::RecordSetReader {
+ public:
+  explicit JsonRecordSetReader(const std::string& name, const utils::Identifier& uuid = {});
+  explicit JsonRecordSetReader(const std::string& name, const std::shared_ptr<Configure>& configuration);
+
+  JsonRecordSetReader(JsonRecordSetReader&&) = delete;
+  JsonRecordSetReader(const JsonRecordSetReader&) = delete;
+  JsonRecordSetReader& operator=(JsonRecordSetReader&&) = delete;
+  JsonRecordSetReader& operator=(const JsonRecordSetReader&) = delete;
+
+  ~JsonRecordSetReader() override = default;
+
+  EXTENSIONAPI static constexpr const char* Description = "Parses JSON into individual Record objects. "
+    "While the reader expects each record to be well-formed JSON, the content of a FlowFile may consist of many records, "
+    "each as a well-formed JSON array or JSON object with optional whitespace between them, such as the common 'JSON-per-line' format. "
+    "If an array is encountered, each element in that array will be treated as a separate record. "
+    "If the schema that is configured contains a field that is not present in the JSON, a null value will be used. "
+    "If the JSON contains a field that is not present in the schema, that field will be skipped.";
+
+
+  EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
+  ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
+
+  using RecordSetReader::RecordSetReader;
+
+  nonstd::expected<core::RecordSet, std::error_code> read(const std::shared_ptr<core::FlowFile>& flow_file, core::ProcessSession& session) override;
+
+  void yield() override {}
+  bool isRunning() const override {    return getState() == core::controller::ControllerServiceState::ENABLED; }

Review Comment:
   Not intentional thats for sure, fixed it in https://github.com/apache/nifi-minifi-cpp/pull/1763/commits/c9aa16d7cd2ea2bd69e0345f365213f5a403cda2#diff-ec967d9d271148d68545eaaf57fa6506ac38db9525253959af285d2583e01b67L54



-- 
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-2311 Initial support for recordset readers and writers [nifi-minifi-cpp]

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


##########
extensions/standard-processors/controllers/JsonRecordSetReader.h:
##########
@@ -0,0 +1,58 @@
+/**
+* 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 "Record.h"
+#include "controllers/RecordSetReader.h"
+#include "core/FlowFile.h"
+#include "core/ProcessSession.h"
+
+namespace org::apache::nifi::minifi::standard {
+
+class JsonRecordSetReader final : public core::RecordSetReader {
+ public:
+  explicit JsonRecordSetReader(const std::string& name, const utils::Identifier& uuid = {});
+  explicit JsonRecordSetReader(const std::string& name, const std::shared_ptr<Configure>& configuration);
+
+  JsonRecordSetReader(JsonRecordSetReader&&) = delete;
+  JsonRecordSetReader(const JsonRecordSetReader&) = delete;
+  JsonRecordSetReader& operator=(JsonRecordSetReader&&) = delete;
+  JsonRecordSetReader& operator=(const JsonRecordSetReader&) = delete;
+
+  ~JsonRecordSetReader() override = default;
+
+  EXTENSIONAPI static constexpr const char* Description = "Parses JSON into individual Record objects. "
+    "While the reader expects each record to be well-formed JSON, the content of a FlowFile may consist of many records, "
+    "each as a well-formed JSON array or JSON object with optional whitespace between them, such as the common 'JSON-per-line' format. "
+    "If an array is encountered, each element in that array will be treated as a separate record. "
+    "If the schema that is configured contains a field that is not present in the JSON, a null value will be used. "
+    "If the JSON contains a field that is not present in the schema, that field will be skipped.";
+
+
+  EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
+  ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
+
+  using RecordSetReader::RecordSetReader;
+
+  nonstd::expected<core::RecordSet, std::error_code> read(const std::shared_ptr<core::FlowFile>& flow_file, core::ProcessSession& session) override;
+
+  void yield() override {}
+  bool isRunning() const override {    return getState() == core::controller::ControllerServiceState::ENABLED; }

Review Comment:
   What's the reason for the multiple spaces before `return`?



##########
extensions/standard-processors/controllers/JsonRecordSetWriter.h:
##########
@@ -0,0 +1,93 @@
+/**
+* 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 "PropertyDefinitionBuilder.h"
+#include "Record.h"
+#include "controllers/RecordSetWriter.h"
+#include "core/FlowFile.h"
+#include "core/ProcessSession.h"
+#include "utils/Enum.h"
+
+namespace org::apache::nifi::minifi::standard {
+
+enum class OutputGroupingType {
+  Array,
+  OneLinePerObject
+};
+
+class JsonRecordSetWriter final : public core::RecordSetWriter {
+ public:
+  explicit JsonRecordSetWriter(const std::string& name, const utils::Identifier& uuid = {});
+  explicit JsonRecordSetWriter(const std::string& name, const std::shared_ptr<Configure>& configuration);
+
+  JsonRecordSetWriter(JsonRecordSetWriter&&) = delete;
+  JsonRecordSetWriter(const JsonRecordSetWriter&) = delete;
+  JsonRecordSetWriter& operator=(JsonRecordSetWriter&&) = delete;
+  JsonRecordSetWriter& operator=(const JsonRecordSetWriter&) = delete;
+
+  ~JsonRecordSetWriter() override = default;
+
+  EXTENSIONAPI static constexpr const char* Description =
+      "Writes the results of a RecordSet as either a JSON Array or one JSON object per line. "
+      "If using Array output, then even if the RecordSet consists of a single row, it will be written as an array with a single element. "
+      "If using One Line Per Object output, the JSON objects cannot be pretty-printed.";
+
+  EXTENSIONAPI static constexpr auto OutputGrouping = core::PropertyDefinitionBuilder<magic_enum::enum_count<OutputGroupingType>()>::createProperty("Output Grouping")
+    .withDescription("Specifies how the writer should output the JSON records (as an array or one object per line, e.g.) "
+                    "Note that if 'One Line Per Object' is selected, then Pretty Print JSON must be false.")

Review Comment:
   I'm not sure in this case "Pretty Print JSON must be false", I think the option is rather ignored. Also I think it's the option is `OneLinePerObject` as the enum names are using the default converted values. Should we customize the value names?



##########
extensions/standard-processors/controllers/JsonRecordSetWriter.h:
##########
@@ -0,0 +1,93 @@
+/**
+* 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 "PropertyDefinitionBuilder.h"
+#include "Record.h"
+#include "controllers/RecordSetWriter.h"
+#include "core/FlowFile.h"
+#include "core/ProcessSession.h"
+#include "utils/Enum.h"
+
+namespace org::apache::nifi::minifi::standard {
+
+enum class OutputGroupingType {
+  Array,
+  OneLinePerObject
+};
+
+class JsonRecordSetWriter final : public core::RecordSetWriter {
+ public:
+  explicit JsonRecordSetWriter(const std::string& name, const utils::Identifier& uuid = {});
+  explicit JsonRecordSetWriter(const std::string& name, const std::shared_ptr<Configure>& configuration);
+
+  JsonRecordSetWriter(JsonRecordSetWriter&&) = delete;
+  JsonRecordSetWriter(const JsonRecordSetWriter&) = delete;
+  JsonRecordSetWriter& operator=(JsonRecordSetWriter&&) = delete;
+  JsonRecordSetWriter& operator=(const JsonRecordSetWriter&) = delete;
+
+  ~JsonRecordSetWriter() override = default;
+
+  EXTENSIONAPI static constexpr const char* Description =
+      "Writes the results of a RecordSet as either a JSON Array or one JSON object per line. "
+      "If using Array output, then even if the RecordSet consists of a single row, it will be written as an array with a single element. "
+      "If using One Line Per Object output, the JSON objects cannot be pretty-printed.";
+
+  EXTENSIONAPI static constexpr auto OutputGrouping = core::PropertyDefinitionBuilder<magic_enum::enum_count<OutputGroupingType>()>::createProperty("Output Grouping")
+    .withDescription("Specifies how the writer should output the JSON records (as an array or one object per line, e.g.) "
+                    "Note that if 'One Line Per Object' is selected, then Pretty Print JSON must be false.")
+    .withDefaultValue(magic_enum::enum_name(OutputGroupingType::Array))
+    .withAllowedValues(magic_enum::enum_names<OutputGroupingType>())
+    .supportsExpressionLanguage(false)
+    .isRequired(true)
+    .build();
+
+  EXTENSIONAPI static constexpr auto PrettyPrint = core::PropertyDefinitionBuilder<>::createProperty("Pretty Print JSON")
+    .withDescription("Specifies whether or not the JSON should be pretty printed")

Review Comment:
   Maybe this can be appended with something like "... only used when Array output is selected"



##########
libminifi/test/TestRecord.h:
##########


Review Comment:
   These record examples are only used in the JsonRecordTests and the content of record 1 and 2 only makes sense in the context of that file, I think these functions should be moved there or make them parameterized with data, to be able to create any generic record object for other tests.



##########
extensions/standard-processors/controllers/JsonRecordSetReader.h:
##########


Review Comment:
   Both JsonRecordSetReader and JsonRecordSetWriter should be documented in CONTROLLERS.md. Maybe we could add some information on the general implementation "how to" of the recordset readers and writers.



##########
extensions/standard-processors/tests/unit/JsonRecordTests.cpp:
##########
@@ -0,0 +1,145 @@
+/**
+* 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.c
+ */
+
+#include <numbers>
+#include <variant>
+
+#include "Catch.h"
+#include "RecordSetTesters.h"
+#include "TestBase.h"
+#include "TestRecord.h"
+#include "controllers/JsonRecordSetReader.h"
+#include "controllers/JsonRecordSetWriter.h"
+#include "core/Record.h"
+
+namespace org::apache::nifi::minifi::standard::test {
+
+constexpr std::string_view record_per_line_str = R"({"baz":3.14,"qux":[true,false,true],"is_test":true,"bar":123,"quux":{"Aprikose":"apricot","Birne":"pear","Apfel":"apple"},"foo":"asd","when":"2012-07-01T09:53:00Z"}
+{"baz":3.141592653589793,"qux":[false,false,true],"is_test":true,"bar":98402134,"quux":{"Aprikose":"abricot","Birne":"poire","Apfel":"pomme"},"foo":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","when":"2022-11-01T19:52:11Z"}
+)";
+constexpr std::string_view array_compressed_str = R"([{"baz":3.14,"qux":[true,false,true],"is_test":true,"bar":123,"quux":{"Aprikose":"apricot","Birne":"pear","Apfel":"apple"},"foo":"asd","when":"2012-07-01T09:53:00Z"},{"baz":3.141592653589793,"qux":[false,false,true],"is_test":true,"bar":98402134,"quux":{"Aprikose":"abricot","Birne":"poire","Apfel":"pomme"},"foo":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","when":"2022-11-01T19:52:11Z"}])";
+constexpr std::string_view array_pretty_str = R"([
+    {
+        "baz": 3.14,
+        "qux": [
+            true,
+            false,
+            true
+        ],
+        "is_test": true,
+        "bar": 123,
+        "quux": {
+            "Aprikose": "apricot",
+            "Birne": "pear",
+            "Apfel": "apple"
+        },
+        "foo": "asd",
+        "when": "2012-07-01T09:53:00Z"
+    },
+    {
+        "baz": 3.141592653589793,
+        "qux": [
+            false,
+            false,
+            true
+        ],
+        "is_test": true,
+        "bar": 98402134,
+        "quux": {
+            "Aprikose": "abricot",
+            "Birne": "poire",
+            "Apfel": "pomme"
+        },
+        "foo": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
+        "when": "2022-11-01T19:52:11Z"
+    }
+])";
+
+bool test_json_equality(const std::string_view expected_str, const std::string_view actual_str) {

Review Comment:
   The function name should use camelCase



##########
extensions/standard-processors/tests/unit/JsonRecordTests.cpp:
##########
@@ -0,0 +1,145 @@
+/**
+* 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.c
+ */
+
+#include <numbers>
+#include <variant>
+
+#include "Catch.h"
+#include "RecordSetTesters.h"
+#include "TestBase.h"
+#include "TestRecord.h"
+#include "controllers/JsonRecordSetReader.h"
+#include "controllers/JsonRecordSetWriter.h"
+#include "core/Record.h"
+
+namespace org::apache::nifi::minifi::standard::test {
+
+constexpr std::string_view record_per_line_str = R"({"baz":3.14,"qux":[true,false,true],"is_test":true,"bar":123,"quux":{"Aprikose":"apricot","Birne":"pear","Apfel":"apple"},"foo":"asd","when":"2012-07-01T09:53:00Z"}
+{"baz":3.141592653589793,"qux":[false,false,true],"is_test":true,"bar":98402134,"quux":{"Aprikose":"abricot","Birne":"poire","Apfel":"pomme"},"foo":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","when":"2022-11-01T19:52:11Z"}
+)";
+constexpr std::string_view array_compressed_str = R"([{"baz":3.14,"qux":[true,false,true],"is_test":true,"bar":123,"quux":{"Aprikose":"apricot","Birne":"pear","Apfel":"apple"},"foo":"asd","when":"2012-07-01T09:53:00Z"},{"baz":3.141592653589793,"qux":[false,false,true],"is_test":true,"bar":98402134,"quux":{"Aprikose":"abricot","Birne":"poire","Apfel":"pomme"},"foo":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.","when":"2022-11-01T19:52:11Z"}])";
+constexpr std::string_view array_pretty_str = R"([
+    {
+        "baz": 3.14,
+        "qux": [
+            true,
+            false,
+            true
+        ],
+        "is_test": true,
+        "bar": 123,
+        "quux": {
+            "Aprikose": "apricot",
+            "Birne": "pear",
+            "Apfel": "apple"
+        },
+        "foo": "asd",
+        "when": "2012-07-01T09:53:00Z"
+    },
+    {
+        "baz": 3.141592653589793,
+        "qux": [
+            false,
+            false,
+            true
+        ],
+        "is_test": true,
+        "bar": 98402134,
+        "quux": {
+            "Aprikose": "abricot",
+            "Birne": "poire",
+            "Apfel": "pomme"
+        },
+        "foo": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
+        "when": "2022-11-01T19:52:11Z"
+    }
+])";
+
+bool test_json_equality(const std::string_view expected_str, const std::string_view actual_str) {
+  rapidjson::Document expected;
+  expected.Parse(expected_str.data());
+  rapidjson::Document actual;
+  actual.Parse(actual_str.data());
+  return actual == expected;
+}
+
+TEST_CASE("JsonRecordSetWriter test Record Per Line") {
+  core::RecordSet record_set;
+  record_set.push_back(core::test::createSampleRecord());
+  record_set.push_back(core::test::createSampleRecord2());
+
+  JsonRecordSetWriter json_record_set_writer;
+  json_record_set_writer.initialize();
+  CHECK(json_record_set_writer.setProperty(JsonRecordSetWriter::OutputGrouping, "OneLinePerObject"));
+  json_record_set_writer.onEnable();
+  CHECK(core::test::testRecordWriter(json_record_set_writer, record_set, [](auto serialized_record_set) -> bool {
+    return test_json_equality(record_per_line_str, serialized_record_set);
+  }));
+}
+
+TEST_CASE("JsonRecordSetWriter test array") {
+  core::RecordSet record_set;
+  record_set.push_back(core::test::createSampleRecord());
+  record_set.push_back(core::test::createSampleRecord2());
+
+  JsonRecordSetWriter json_record_set_writer;
+  CHECK(core::test::testRecordWriter(json_record_set_writer, record_set, [](auto serialized_record_set) -> bool {
+    return test_json_equality(array_compressed_str, serialized_record_set);
+  }));
+}
+
+TEST_CASE("JsonRecordSetWriter test pretty array") {
+  core::RecordSet record_set;
+  record_set.push_back(core::test::createSampleRecord());
+  record_set.push_back(core::test::createSampleRecord2());
+
+  JsonRecordSetWriter json_record_set_writer;
+  json_record_set_writer.initialize();
+  CHECK(json_record_set_writer.setProperty(JsonRecordSetWriter::PrettyPrint, "true"));
+  json_record_set_writer.onEnable();
+  CHECK(core::test::testRecordWriter(json_record_set_writer, record_set, [](auto serialized_record_set) -> bool {
+    return test_json_equality(array_pretty_str, serialized_record_set);
+  }));
+}
+
+TEST_CASE("JsonRecordSetReader per line") {

Review Comment:
   It seems that only the input is different for all reader tests, could we merge them and use catch2 generators instead?



##########
libminifi/test/RecordSetTesters.h:
##########
@@ -0,0 +1,82 @@
+/**
+*
+ * 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 "controllers/RecordSetReader.h"
+#include "controllers/RecordSetWriter.h"
+#include "core/Record.h"
+#include "TestBase.h"
+
+namespace org::apache::nifi::minifi::core::test {
+
+class RecordSetFixture {
+ public:
+  explicit RecordSetFixture(TestController::PlanConfig config = {}): plan_config_(std::move(config)) {}
+
+  [[nodiscard]] ProcessSession& processSession() const { return *process_session_; }
+
+  [[nodiscard]] const Relationship& getRelationship() const { return relationship_; }
+ private:
+  TestController test_controller_{};
+  TestController::PlanConfig plan_config_{};
+  std::shared_ptr<TestPlan> test_plan_ = test_controller_.createPlan(plan_config_);
+  std::shared_ptr<Processor> dummy_processor_ = test_plan_->addProcessor("DummyProcessor", "dummyProcessor");
+  std::shared_ptr<ProcessContext> context_ = [this] { test_plan_->runNextProcessor(); return test_plan_->getCurrentContext(); }();
+  std::unique_ptr<ProcessSession> process_session_ = std::make_unique<ProcessSession>(context_);
+
+  const Relationship relationship_{"success", "description"};
+};
+
+bool testRecordWriter(RecordSetWriter& record_set_writer, const RecordSet& record_set, auto tester) {
+  const RecordSetFixture fixture;
+  ProcessSession& process_session = fixture.processSession();
+
+  const auto flow_file = process_session.create();
+
+  record_set_writer.write(record_set, flow_file, process_session);
+  process_session.transfer(flow_file, fixture.getRelationship());
+  process_session.commit();
+  const auto input_stream = process_session.getFlowFileContentStream(*flow_file);
+  std::array<std::byte, 2048> buffer{};
+  const auto buffer_size = input_stream->read(buffer);
+  const std::string flow_file_content(reinterpret_cast<char*>(buffer.data()), buffer_size);
+
+  return tester(flow_file_content);
+}
+
+inline bool testRecordReader(RecordSetReader& record_set_reader, const std::string_view serialized_record_set, const RecordSet& expected_record_set) {
+  const RecordSetFixture fixture;
+  ProcessSession& process_session = fixture.processSession();
+
+  const auto flow_file = process_session.create();
+  process_session.writeBuffer(flow_file, serialized_record_set);
+  process_session.transfer(flow_file, fixture.getRelationship());
+  process_session.commit();
+
+  const auto record_set = record_set_reader.read(flow_file, process_session);
+  if (!record_set)
+    return false;
+  auto& record_set_0 = (*record_set)[0];
+  auto& expected_set_0 = expected_record_set[0];
+  CHECK(record_set_0 == expected_set_0);

Review Comment:
   Why are we checking the first element separately?



-- 
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-2311 Initial support for recordset readers and writers [nifi-minifi-cpp]

Posted by "fgerlits (via GitHub)" <gi...@apache.org>.
fgerlits closed pull request #1763: MINIFICPP-2311 Initial support for recordset readers and writers
URL: https://github.com/apache/nifi-minifi-cpp/pull/1763


-- 
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-2311 Initial support for recordset readers and writers [nifi-minifi-cpp]

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


##########
extensions/standard-processors/controllers/JsonRecordSetWriter.h:
##########
@@ -0,0 +1,107 @@
+/**
+* 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 "PropertyDefinitionBuilder.h"
+#include "Record.h"
+#include "controllers/RecordSetWriter.h"
+#include "core/FlowFile.h"
+#include "core/ProcessSession.h"
+#include "utils/Enum.h"
+
+namespace org::apache::nifi::minifi::standard {
+enum class OutputGroupingType {
+  ARRAY,
+  ONE_LINE_PER_OBJECT
+};
+}  // namespace org::apache::nifi::minifi::standard
+
+namespace magic_enum::customize {
+using OutputGroupingType = org::apache::nifi::minifi::standard::OutputGroupingType;
+
+template <>
+constexpr customize_t enum_name<OutputGroupingType>(OutputGroupingType value) noexcept {
+  switch (value) {
+    case OutputGroupingType::ARRAY:
+      return "Array";
+    case OutputGroupingType::ONE_LINE_PER_OBJECT:
+      return "One Line Per Object";
+  }
+  return invalid_tag;
+}
+}  // namespace magic_enum::customize
+
+namespace org::apache::nifi::minifi::standard {
+
+class JsonRecordSetWriter final : public core::RecordSetWriter {
+ public:
+  explicit JsonRecordSetWriter(const std::string_view name, const utils::Identifier& uuid = {}) : RecordSetWriter(name, uuid) {}
+
+  JsonRecordSetWriter(JsonRecordSetWriter&&) = delete;
+  JsonRecordSetWriter(const JsonRecordSetWriter&) = delete;
+  JsonRecordSetWriter& operator=(JsonRecordSetWriter&&) = delete;
+  JsonRecordSetWriter& operator=(const JsonRecordSetWriter&) = delete;
+
+  ~JsonRecordSetWriter() override = default;
+
+  EXTENSIONAPI static constexpr const char* Description =
+      "Writes the results of a RecordSet as either a JSON Array or one JSON object per line. "
+      "If using Array output, then even if the RecordSet consists of a single row, it will be written as an array with a single element. "
+      "If using One Line Per Object output, the JSON objects cannot be pretty-printed.";
+
+  EXTENSIONAPI static constexpr auto OutputGrouping = core::PropertyDefinitionBuilder<magic_enum::enum_count<OutputGroupingType>()>::createProperty("Output Grouping")
+    .withDescription("Specifies how the writer should output the JSON records (as an array or one object per line, e.g.) "
+                    "Note that if 'One Line Per Object' is selected, then Pretty Print JSON is ignored.")

Review Comment:
   Minor, but it's not clear what the `e.g.` refers to; also I would remove the whole `(...)` part, as the list of allowed values already contains the same info.



-- 
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