Refactor: columnvalues to use strings builder#353
Open
micyen wants to merge 3 commits intodatabricks:mainfrom
Open
Refactor: columnvalues to use strings builder#353micyen wants to merge 3 commits intodatabricks:mainfrom
micyen wants to merge 3 commits intodatabricks:mainfrom
Conversation
…ValueContainer.Value() Signed-off-by: Michael Yen <29710093+micyen@users.noreply.github.com>
…alueContainer.Value() Signed-off-by: Michael Yen <29710093+micyen@users.noreply.github.com>
…ctValueContainer.Value() Signed-off-by: Michael Yen <29710093+micyen@users.noreply.github.com>
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.
Summary
Replace repeated string concatenation with strings.Builder in complex type Value() methods to improve performance.
Problem
listValueContainer, mapValueContainer, and structValueContainer build strings using + inside loops, resulting in O(n^2) time complexity.
In cases like COLLECT_SET(...) returning many elements, this can make rows.Next() / rows.Scan() hang, with most time spent in runtime.concatstring2.
Observed Workaround
Changing the SQL from COLLECT_SET() (array type) to ARRAY_JOIN(COLLECT_SET(...), '\n') (string type) bypasses the problem because the driver reads the column as a plain string value, avoiding calls to the complex type Value() methods.
Fix
Use strings.Builder for string construction in all three Value() methods, which reduces time complexity from O(n^2) to O(n).
Testing
Pre-existing unit tests passed, no tests added.
Notes
No behavioral changes, output format identical.
Signed-off-by: Michael Yen 29710093+micyen@users.noreply.github.com