MINIFICPP-2862 Add StandardValidator::NUMBER_VALIDATOR#2213
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new standard numeric property validator to MiNiFi C++ and updates the parsing utilities to support stricter floating-point parsing via std::from_chars, then wires the validator through the C API mappings and validates behavior with unit tests.
Changes:
- Introduces
StandardPropertyValidators::NUMBER_VALIDATORand exposes it through the C API enum/mapping. - Replaces
parseFloatwith a templatedparseFloatingPoint<T>implementation usingstd::from_chars. - Adds/updates property parsing helpers and a unit test covering numeric validation.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| minifi-api/include/minifi-api.h | Adds MINIFI_VALIDATOR_NUMBER to the C API validator enum. |
| minifi-api/common/include/minifi-cpp/core/PropertyValidator.h | Adds NumberValidator and exposes it as a standard validator; refactors validator classes. |
| libminifi/test/unit/PropertyValidationTests.cpp | Adds unit test coverage for the new number validator. |
| libminifi/src/minifi-api.cpp | Maps the new C API enum value to the C++ standard validator instance. |
| extension-framework/include/utils/ProcessorConfigUtils.h | Adds float parsing helpers and switches optional float parsing to parseFloatingPoint<float>. |
| extension-framework/cpp-extension-lib/src/utils/minifi-c-utils.cpp | Adds reverse-mapping from NUMBER_VALIDATOR to MINIFI_VALIDATOR_NUMBER. |
| extension-framework/cpp-extension-lib/include/api/utils/ProcessorConfigUtils.h | Switches optional float parsing to parseFloatingPoint<float>. |
| core-framework/common/src/utils/ParsingUtils.cpp | Removes the old parseFloat implementation. |
| core-framework/common/include/utils/ParsingUtils.h | Adds templated parseFloatingPoint<T> implementation using std::from_chars. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const auto trimmed_input = utils::string::trim(input); | ||
| T value{}; | ||
|
|
||
| const auto [ptr, ec] = std::from_chars(trimmed_input.data(), trimmed_input.data() + trimmed_input.size(), value); |
There was a problem hiding this comment.
Unlike other parsing functions in C++ and C libraries, std::from_chars is locale-independent, non-allocating, and non-throwing.
fgerlits
left a comment
There was a problem hiding this comment.
LGTM, but do we want to implement NUMBER_VALIDATOR in Python, too, now that we can?
sure, good idea add NUMBER_VALIDATOR to python |
| } | ||
| gsl_FailFast(); |
There was a problem hiding this comment.
if we crash on unknown enum values, then adding another validator later can't be done without breaking API
There was a problem hiding this comment.
yeah i hoped we can merge this in faster than the release 🤞
There was a problem hiding this comment.
I think we could just fallback on ALWAYS_VALID, for c api extensions, the parsing happens on the extension side anyway
… but we would like to use them optionally we cant add this validator because it breaks the setting the value to "" to disable workflow
|
I think I'd rather stop breaking the API now in preparation for a release, and add this feature in a future version. |
|
I converted this to draft since its an API breaking change which we would like to avoid for now. |
|
I've retargeted the PR to api-bump branch, we can merge it if it comes to that then we can deal with the PRs collected there when we want to bump the api |
szaszm
left a comment
There was a problem hiding this comment.
+1 for merging to the api_bump branch, I would just hold off of merging to main for now
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:
For documentation related changes:
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.