Skip to content

chore: Use native impl of elt function - #5040

Open
kazantsev-maksim wants to merge 70 commits into
apache:mainfrom
kazantsev-maksim:native_elt_func
Open

chore: Use native impl of elt function#5040
kazantsev-maksim wants to merge 70 commits into
apache:mainfrom
kazantsev-maksim:native_elt_func

Conversation

@kazantsev-maksim

@kazantsev-maksim kazantsev-maksim commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

  • N/A

Rationale for this change

This PR migrates the elt string function from Comet's codegen-based dispatch path to the shared datafusion-spark implementation, registering it as a native scalar UDF.

What changes are included in this PR?

  • Register the SparkElt scalar UDF in register_datafusion_spark_function so it is available to the DataFusion session context alongside the other Spark-compatible UDFs.
  • Change CometElt from CometCodegenDispatch[Elt] to CometScalarFunction[Elt]("elt")

How are these changes tested?

Significantly expand the test coverage with many additional inputs to exercise edge cases

@comphead comphead left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kazantsev-maksim

CI pending

@kazantsev-maksim

Copy link
Copy Markdown
Contributor Author

Thanks @comphead!

@andygrove andygrove left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the upstream elt implementation is Spark-compatible? It doesn't implement ANSI mode, for example.

From DF 54.1.0:

        // TODO: if spark.sql.ansi.enabled is true,
        //  throw ArrayIndexOutOfBoundsException for invalid indices;
        //  if false, return NULL instead (current behavior).
        if index < 1 || (index as usize) > num_values {
            builder.append_null();
            continue;
        }

@andygrove

Copy link
Copy Markdown
Member

I don't think the upstream elt implementation is Spark-compatible? It doesn't implement ANSI mode, for example.

From DF 54.1.0:

        // TODO: if spark.sql.ansi.enabled is true,
        //  throw ArrayIndexOutOfBoundsException for invalid indices;
        //  if false, return NULL instead (current behavior).
        if index < 1 || (index as usize) > num_values {
            builder.append_null();
            continue;
        }

One option would be to mix in CodegenDispatchFallback and return Incompatible when expr.failOnError is true. It would be good to file an issue upstream for implementing ANSI support too.

@comphead

Copy link
Copy Markdown
Contributor

I don't think the upstream elt implementation is Spark-compatible? It doesn't implement ANSI mode, for example.
From DF 54.1.0:

        // TODO: if spark.sql.ansi.enabled is true,
        //  throw ArrayIndexOutOfBoundsException for invalid indices;
        //  if false, return NULL instead (current behavior).
        if index < 1 || (index as usize) > num_values {
            builder.append_null();
            continue;
        }

One option would be to mix in CodegenDispatchFallback and return Incompatible when expr.failOnError is true. It would be good to file an issue upstream for implementing ANSI support too.

Thanks @andygrove for catching this. for ANSI we should start an epic there. The ANSI flag is already there, and we can try it on elt

@comphead

Copy link
Copy Markdown
Contributor

Created apache/datafusion#23928

@comphead comphead mentioned this pull request Jul 28, 2026
3 tasks
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.

3 participants