Skip to content

substr on Dictionary(_, Utf8) inserts implicit CAST to Utf8View #26170

Closed

Description

@Rich-T-kid

substr on a dictionary-encoded string column plans an implicit cast to Utf8View, materializing the dictionary before the scalar function runs.

Repro (datafusion-cli 54.0.0):

CREATE TABLE t AS
SELECT arrow_cast('hello' || i::VARCHAR, 'Dictionary(Int32, Utf8)') AS k
FROM generate_series(1, 10) AS s(i);

EXPLAIN SELECT substr(k, 1, 4) FROM t;

Plan:

ProjectionExec: expr=[substr(CAST(k@0 AS Utf8View), 1, 4) as substr(t.k,Int64(1),Int64(4))]
  DataSourceExec: ...

The arrow-rs substring kernel already handles this by delegating to dictionary.values() and reusing the keys (arrow-string/src/substring.rs:79-82). SubstrFunc's signature in datafusion/functions/src/unicode/substr.rs doesn't advertise Dictionary support, so type coercion inserts the cast. This should be avoided for performance!

Activity

  1. Rich-T-kid commented on Oct 9, 2026

    @Rich-T-kid
    ContributorAuthor

    take

  2. added 4 commits that reference this issue on Oct 9, 2026
    497b608
    6318fb4
    d172c89
    c11a73c
  3. added a commit that references this issue on Oct 25, 2026
    895f473
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions