Skip to content

Add support for CharVarcharCodegenUtils functions in Velox. #12772

Open
@Yifeng-Wang

Description

@Yifeng-Wang

Description

Description

Gluten Velox Plan has below fallbacks caused by unsupported functions in spark's CharVarcharCodegenUtils. Such static functions are called by wrapping within a StaticInvoke, with fallback infos like :

Not supported to map spark function name to substrait function name: staticinvoke(class org.apache.spark.sql.catalyst.util.CharVarcharCodegenUtils, StringType, readSidePadding, id#109, 3, true, false, true), class name: StaticInvoke.;

or sth like,

Not supported to map spark function name to substrait function name: staticinvoke(class org.apache.spark.sql.catalyst.util.CharVarcharCodegenUtils, StringType, charTypeWriteSideCheck, staticinvoke(class org.apache.spark.sql.catalyst.util.CharVarcharCodegenUtils, StringType, readSidePadding, id#109, 3, true, false, true), 3, true, false, true), class name: StaticInvoke.

The 3 functions in CharVarcharCodegenUtils are charTypeWriteSideCheck, varcharTypeWriteSideCheck and readSidePadding(introduced in Spark3.4) in org.apache.spark.sql.catalyst.util.CharVarcharCodegenUtils.
CharVarcharCodegenUtils.java


How to trigger?

  • charTypeWriteSideCheck, varcharTypeWriteSideCheck get triggered when try to insert string into varchar/char columns.
  • readSidePadding gets triggered when try to select or do filter predicates.

The minimum test case can be given as:

create table src(id string) stored as parquet;
create table tgtvarchar(id varchar(3)) stored as parquet;
create table tgtchar(id char(3)) stored as parquet;

insert into srcchar values ('ab');

insert into tgtvarchar select id from src; -- fallback due to unsuported varcharTypeWriteSideCheck
insert into tgtchar select id from src; -- fallback due to unsuported charTypeWriteSideCheck

select id from tgtchar; -- fallback due to unsuported readSidePadding

What is the significance?
Inserting operations that triggered these functions are common in our users' production environments. Read-side padding for CHAR cols is a default behaviour since Spark 3.4.
These fallbacks introduce R2C in the middle of the execution plan, which we observed, harms Spark gluten performance. Thus, offloading StaticInvokes functions in CharVarcharCodegenUtils to native need to be supported.


Describe the solution

  1. Add expr matching pattern in Gluten; Gluten issue refers to Gluten 9106
  2. Register these functions and provide implementations in Velox.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions