Skip to content

Conversation

@heisenbergs-uncertainty
Copy link
Contributor

Purpose

Introduce Pipeline Element Processors that allow a user to implement the "Switch" operator. I have often found myself wanting to setup a pipeline that uses the "Switch" operator but have had to use a complicated set of boolean conditions to try and implement it or I eventually end up just using a JavaScript processor to use the switch statement. The processors reflect the following block.

switch(String x) {
  case "test":
   do something;
   break;
  case "test 2":
   do something else;
   break;
  default:
   do this if nothing else works;
   break;
}

The proposed updates introduce three processors, each which have the purpose of handling a different input type. I have implemented a Boolean Input processor, String input processor, and Numerical input processor. This is done primarily for the sake of cleaner code along with simplifying the detection of the incoming event property. These three processors could be combined into one "Switch Operator Processor" if there was the introduction of some "Conditional Requirements" component.

image

image

image

image

Remarks

I have written unit tests for the numerical processor locally but ran into issues when I transferred the updates from my custom extensions repo to the main streampipes codebase. If someone has input on the right way to write tests for streampipes or would like to write the unit tests themselves that would be welcome.

PR introduces (a) breaking change(s): no
PR introduces (a) deprecation(s): no

…es pipelines.

- define "Switch" input. e.g. switch(event.switch_input)
- define "cases" which output string types
- define "default" case which evaluates if all other cases fail
- creates "switch-filter-result" output
- add SwitchOperatorProcessor to TransformationExtensionModuleExport
- added documentation.md based on generated template
- added strings.en resources
- added new icon of switch to indicate function of processor

chore: Rename the processor to use the correct format of org.apache.org...
- Need to fix test issues of Mockito not being able to mock
- Update to return primitive data types based on user selection
- Updated tests to cover functionality
@github-actions github-actions bot added java Pull requests that update Java code pipeline elements Relates to pipeline elements backend Everything that is related to the StreamPipes backend documentation Everything related to documentation testing Relates to any kind of test (unit test, integration, or E2E test). labels Jun 2, 2025
@tenthe
Copy link
Contributor

tenthe commented Jun 3, 2025

Hi @heisenbergs-uncertainty,

Thanks a lot for the PR — these are great new processing elements, and your description makes it easy to review.

  • For unit tests, you can use the ProcessingElementTestExecutor helper class.

  • See TransformToBooleanProcessorTest or NumericalFilterProcessorTest for examples.

Would you like to add some unit tests for your elements?
Feel free to reach out if you have any questions or suggestions for improving the test framework.

Hope this helps!

…nput processors for improved structure and maintainability

- Refactored to use AbstractSwitchOperatorProcessor to pull out common methods
- Overall Renaming of methods and names for better consistency and descriptions of functionality
- moved general implementation of onEvent() to AbstractSwitchOperatorProcessor which utilizes findMatchingResult which is then given class specific implementations
… add unit tests for boolean, numerical, and string input processors
… Operator with updated documentation and license headers

- Updated documentation.md and strings.en to reflect the changes made in optimization refactor
- Unit tests added to cover general functionality and edge cases
- Utilized ProcessingElementTestExecutor for the unit tests
- Added Licenses to top of Test files and new optimized classes
@heisenbergs-uncertainty
Copy link
Contributor Author

Hi @heisenbergs-uncertainty,

Thanks a lot for the PR — these are great new processing elements, and your description makes it easy to review.

  • For unit tests, you can use the ProcessingElementTestExecutor helper class.
  • See TransformToBooleanProcessorTest or NumericalFilterProcessorTest for examples.

Would you like to add some unit tests for your elements? Feel free to reach out if you have any questions or suggestions for improving the test framework.

Hope this helps!

Hey @tenthe! Thank you for the testing recommendation, that was super useful and made writing the tests much simpler. Props to whoever wrote that suite!

I have gone ahead and added unit tests for the processors and made quite a few updates that they helped me catch. From my testing it should be good to go at this point.

Copy link
Contributor

@tenthe tenthe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the changes.
I just had a minor comment, but I think the code looks good from my side.

I look forward to use the processors.
Cheers,
Philipp

* @param staticPropertyExtractor Extractor for the current switch case group.
* @return A SwitchCaseEntry object.
*/
protected SwitchCaseEntry parseSwitchCaseEntry(StaticPropertyExtractor staticPropertyExtractor) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be an abstract method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. Switching it to abstract is causing the classes that extend it to refuse to implement the class.

But I am still refreshing my understanding of Java so I will default to your decision.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your response. This was just a small point I noticed while reviewing the code. I'll trigger the GitHub Action validation now. Once it passes, we can proceed with merging your PR.

@tenthe tenthe merged commit 70f3e70 into apache:dev Jun 6, 2025
19 checks passed
@dominikriemer dominikriemer added this to the 0.98.0 milestone Nov 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Everything that is related to the StreamPipes backend documentation Everything related to documentation java Pull requests that update Java code pipeline elements Relates to pipeline elements testing Relates to any kind of test (unit test, integration, or E2E test).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants