Description
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
- Add expr matching pattern in Gluten; Gluten issue refers to Gluten 9106
- Register these functions and provide implementations in Velox.