Skip to content

add a udf to improve performance by replacing array_contain - #1

Merged
dongatnb merged 1 commit into
ParticleMedia:masterfrom
dongatnb:dongye/add_a_udf
Nov 24, 2025
Merged

dongatnb merged 1 commit into
ParticleMedia:masterfrom
dongatnb:dongye/add_a_udf

Conversation

@dongatnb

@dongatnb dongatnb commented Nov 24, 2025 •

Copy link
Copy Markdown
Collaborator

Optimize performance of the following snippet in a hive query:

        transform(
            a.buckets,
            x->if(
                array_contains(c.names, split(x, '-') [0]),
                x,
                null
            )
        ) as buckets,

and

        transform(
            split(bucket, ','),
            x->if(
                array_contains(c.names, split(x, '-') [0]),
                x,
                null
            )
        ) as buckets,

array_contains has time complexity o(N) and it is applied to multiple elements in an array which sums to O(MN) time complexity.

Solution: Convert c.names into a HashSet which can be used across multiple rows.

@dongatnb
dongatnb marked this pull request as draft November 24, 2025 18:32
@dongatnb
dongatnb marked this pull request as ready for review November 24, 2025 18:32
@dongatnb
dongatnb merged commit e280884 into ParticleMedia:master Nov 24, 2025
1 check passed
@dongatnb
dongatnb deleted the dongye/add_a_udf branch November 25, 2025 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants