Skip to content

[datafusion-spark] Implement size function #5338

Closed

Description

@iajoiner

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
There is a user on Discord that wants size akin to the PySpark function with the same name to be implemented.

Describe the solution you'd like
A clear and concise description of what you want to happen.
Implement size as a BuiltinScalarFunction for ListArray, LargeListArray and MapArray.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Activity

  1. comphead commented on Feb 20, 2023

    @comphead
    Contributor

    btw, there is no size function in PG. There are cardinality function or array_length.
    Its again should we support both spark/PG syntax ?

  2. alamb commented on Feb 20, 2023

    @alamb
    Contributor

    Its again should we support both spark/PG syntax ?

    I would personally suggest supporting postgres syntax unless postgres doesn't support the feature -- and in that case we could follow spark

  3. iajoiner commented on Feb 20, 2023

    @iajoiner
    ContributorAuthor

    @alamb Sure! So I guess array_length should be the correct name here.

  4. iajoiner commented on Feb 20, 2023

    @iajoiner
    ContributorAuthor

    @alamb Wait. In Postgres https://www.postgresql.org/docs/15/functions-array.html it is necessary to have compatibility to have nested arrays so it does make sense to have array_length(array, dimension). For us this makes less sense since we can have arrays that look like [[2, 3], [4, 5, 6]] and even lists of maps. cardinality does make more sense but it doesn't suit our current use case. size from Spark probably makes the most sense here.

  5. changed the title [-]Add `size` as a `BuiltinScalarFunction`[/-] [+][datafusion-spark] Implement `size` function[/+] on Oct 20, 2025
  6. Jefffrey commented on Oct 20, 2025

    @Jefffrey
    Contributor

    I'll rebrand this as a Spark function issue.

    Reference: https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.functions.size.html

    We want to support size() function on array + map types. Though we do have array_length already, this is meant for arrays so can be confusing to extend it to support maps.

  7. Jefffrey commented on Oct 20, 2025

    @Jefffrey
    Contributor

    I'll mark as good first issue, some pointers:

    • See existing Spark function PRs to see what needs to be done for adding Spark functions, e.g. Impl spark bit not function #18018
    • Can see existing array_length implementation in DataFusion for reference as I mentioned above; can ignore all the code around handling dimensions though since Spark size doesn't do that
  8. CuteChuanChuan commented on Oct 27, 2025

    @CuteChuanChuan
    Contributor

    take

  9. Yuvraj-cyborg commented on Dec 11, 2025

    @Yuvraj-cyborg
    Contributor

    @Jefffrey is this issue resolved yet or can I work on it ??

  10. CuteChuanChuan commented on Dec 11, 2025

    @CuteChuanChuan
    Contributor

    Hi @Yuvraj-cyborg,
    I am currently working on this. Will submit a PR soon.

  11. added a commit that references this issue on Jan 13, 2026
    803cce8
  12. added a commit that references this issue on Mar 24, 2026
    5b93b6e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions