Fix table UDF result block splitting - #18310
Closed
ColinLeeo wants to merge 2 commits into
Closed
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #18310 +/- ##
=========================================
Coverage ? 43.22%
Complexity ? 374
=========================================
Files ? 5363
Lines ? 382084
Branches ? 49638
=========================================
Hits ? 165156
Misses ? 216928
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
Author
|
Superseded by #18333 after renaming the head branch to |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.




Description
Problem
A table-model UDF may produce a large result block when processing a partition containing a large device. Previously,
TableFunctionOperatorreturned the generatedTsBlockdirectly without enforcing the configured row-count or byte-size limits.As a result, a sufficiently large UDF result could eventually exceed the RPC frame limit, for example the 64 MB Thrift frame limit.
Design
TableFunctionOperatornow splits generated result blocks before returning them to downstream operators.For each output fragment, the operator:
max_tsblock_line_number.max_tsblock_size_in_bytes.next().Binary search was selected because row sizes may vary significantly for variable-width types such as
TEXT,STRING, andBLOB. Calculating a fixed row count from the average size of an earlier block would be cheaper, but could allow later blocks containing wider values to exceed the configured byte-size limit.The size check uses a copied region instead of
TsBlock.getRegion(). A zero-copy region keeps the source columns' backing arrays, so its reported size may reflect backing capacity rather than the exact logical contents of the selected rows. Copying the selected region provides an accurate size for variable-width data and prevents a small returned fragment from retaining a large source block.The splitting logic is applied when results are dequeued, so blocks generated by both
process()andfinish()follow the same path. This also keeps the splitting behavior independent of pass-through column construction.Configuration and behavior
This PR introduces no new configuration.
The implementation uses the existing configurations:
max_tsblock_size_in_bytes, whose default value is131072.max_tsblock_line_number, whose default value is1000.The existing configuration validation remains unchanged. The operator defensively returns at least one row per call so that execution always makes progress, even if the configured line limit is invalid or a single row is larger than the byte-size target.
Rows are indivisible. Therefore, if one individual row is larger than
max_tsblock_size_in_bytes, that row is returned alone. Preventing a single value larger than the RPC frame limit would require a separate rejection or value-level fragmentation policy.The following behaviors are preserved:
Alternative designs
An alternative was to calculate a fixed maximum row count from the average row size of the first result block. Although this avoids repeated size checks, it is not reliable when different calls produce values with significantly different widths.
Another alternative was to serialize every candidate block and use its serialized length directly. This would closely match the transport representation but would couple the execution operator to the serialization layer and add repeated serialization overhead. The implemented design follows the existing operator memory-size contract, while the unit test additionally verifies that the serialized result also remains within the configured limit.
Tests
Added
testVariableWidthResultsAreSplitByActualSizeto cover variable-width output:process()first produces a narrowTEXTresult.finish()then produces a wideTEXTresult exceeding both the configured row-count and byte-size limits.max_tsblock_line_number.max_tsblock_size_in_bytes.The following targeted test was run successfully:
mvn test -pl iotdb-core/datanode -am \ -Dtest=TableFunctionOperatorTest \ -DfailIfNoTests=false \ -Dsurefire.failIfNoSpecifiedTests=falseThis PR has:
Key changed/added classes
TableFunctionOperatorTableFunctionOperatorTest