[FLINK-38822] Extend URL_DECODE with optional recursive decoding #27351
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
Apache Flink SQL currently provides
URL_DECODE(str)to decode strings inapplication/x-www-form-urlencodedformat (introduced in FLINK-34108). In practice, log data, tracking data, or external system inputs may contain multi-level URL-encoded values, for example strings encoded multiple times by upstream systems or intermediate components such as redirects or proxies.The existing function performs only a single decoding pass, which requires users to manually apply the function multiple times to fully decode such values.
Problem
Single-pass decoding is insufficient for handling multi-level URL-encoded values.
Repeated manual application of
URL_DECODEreduces SQL readability and increases the risk of errors.Solution
Extend URL decoding support by introducing an additional built-in function that accepts a boolean flag to control recursive decoding.
Signature
Behavior
When
recursiveisFALSEorNULL, the function performs a single decoding pass.When
recursiveisTRUE, the function repeatedly applies URL decoding until:If the input value is
NULL, the function returnsNULL.If a decoding error occurs:
NULL;NULLif no decoding step succeeds.Examples
Compatibility
This change is fully backward-compatible. Existing queries using
URL_DECODE(str)are unaffected.Notes
Recursive decoding terminates when the decoded value stabilizes or when the maximum iteration limit is reached. This functionality is useful for data cleansing, normalization, and processing multi-level URL-encoded inputs.