NIFI-15674: Add isValidDate and isValidInstant Expression Language fu…#10975
NIFI-15674: Add isValidDate and isValidInstant Expression Language fu…#10975Scrooge-McDucks wants to merge 1 commit intoapache:mainfrom
Conversation
|
Just a gentle nudge on this one when anyone has a chance! |
6c70cc8 to
fa23f48
Compare
| booleanFunctionRef : zeroArgBool | oneArgBool | multiArgBool | oneOrTwoArgBool; | ||
| numberFunctionRef : zeroArgNum | oneArgNum | zeroOrTwoArgNum | oneOrTwoArgNum | zeroOrOneOrTwoArgNum; | ||
|
|
||
| anyArg : WHOLE_NUMBER | DECIMAL | numberFunctionRef | STRING_LITERAL | zeroArgString | oneArgString | twoArgString | fiveArgString | booleanLiteral | zeroArgBool | oneArgBool | multiArgBool |
There was a problem hiding this comment.
oneOrTwoArgBool needs to be added there
|
|
||
| // Use parseUnresolved to get raw field values without lenient resolution | ||
| final ParsePosition pos = new ParsePosition(0); | ||
| final TemporalAccessor parsed = dtf.parseUnresolved(subjectValue, pos); |
There was a problem hiding this comment.
You are not using trim() here while you are in the other class. Is it on purpose?
INSTANT_FORMATTER.parse(subjectValue.trim(), Instant::from);
| final ZoneId zone = dtf.getZone(); | ||
| zoneRules = (zone != null && !(zone instanceof ZoneOffset)) ? zone.getRules() : null; | ||
| } | ||
| if (zoneRules != null && month != -1 && parsed.isSupported(ChronoField.HOUR_OF_DAY)) { |
There was a problem hiding this comment.
The DST gap check only activates when ChronoField.HOUR_OF_DAY is present in the parsed result. Format patterns using 12-hour time with AM/PM markers (e.g., hh:mm a) produce HOUR_OF_AMPM and AMPM_OF_DAY fields instead of HOUR_OF_DAY, so DST gap validation would be silently skipped for those formats. This is a minor edge case but worth documenting or addressing.
e5fd43e to
6764179
Compare
|
Thanks for the review @pvillard31! Fixed all three - the grammar was an oversight and trim were an oversight. the 12-hour clock edge case was a good catch, and one I didn't think of! Added tests for the DST gap with hh:mm a format too. |
1604240 to
63155c2
Compare
…nctions - isValidDate(format[, timezone]) returns true if the subject parses as a valid calendar date using the given format and optional timezone; rejects invalid calendar combinations (e.g. Feb 31), DST gap times, and supports both 24-hour (HH) and 12-hour (hh a) clock formats - isValidInstant() returns true if the subject parses as a valid ISO-8601 instant (ISO_INSTANT, ISO_OFFSET_DATE_TIME, RFC_1123) - Added oneOrTwoArgBool to anyArg in parser grammar so isValidDate can appear as an argument to other functions
63155c2 to
51d4224
Compare
Summary
NIFI-15674
Adds two new Expression Language validation functions:
isValidDate(format[, timezone])isValidInstant()These functions allow flows to validate date and instant values before attempting conversion.
Motivation
NiFi currently does not provide a simple top-level Expression Language function for validating whether a value can be parsed as a date or instant.
Today, users often need to rely on regex, nested expressions, or extra processor logic in places like
UpdateAttributeorRouteOnAttributeto guard parsing. Regex can validate shape, but it is not calendar-aware, so values like31-02-2026may still appear valid even though they are not real dates.This also creates operational risk. If invalid values are parsed directly, expression evaluation can fail, which in some flows can lead to repeated retries or queue looping instead of clean handling.
These functions provide a lightweight and safe way to keep validation logic visible at the top level of an expression.
Behavior
isValidDate(format)Returns
trueif the subject can be parsed as a valid date using the supplied format, otherwisefalse.isValidDate(format, timezone)Returns
trueif the subject can be parsed as a valid date using the supplied format and timezone, otherwisefalse.isValidInstant()Returns
trueif the subject can be parsed as a valid ISO-8601 instant, otherwisefalse.Invalid input returns
falserather than throwing an evaluation error.Examples
${myDate:isValidDate("dd-MM-yyyy"):ifElse("valid","invalid")}${myDate:isValidDate("yyyy-MM-dd HH:mm:ss", "UTC")}${eventTime:isValidInstant():ifElse("valid-instant","invalid-instant")}Tracking
Please complete the following tracking steps prior to pull request creation.
Issue Tracking
Pull Request Tracking
NIFI-00000NIFI-00000VerifiedstatusPull Request Formatting
mainbranchVerification
Please indicate the verification steps performed prior to pull request creation.
Build
./mvnw clean install -P contrib-checkLicensing
LICENSEandNOTICEfilesDocumentation