Skip to content

left, right, and substr always return Utf8View for Utf8 input #23329

Description

@xudong963

Is your feature request related to a problem or challenge?

left, right, and substr currently return Utf8View even when their first argument is Utf8 or LargeUtf8.

This makes these functions inconsistent with other string-producing functions such as lower, upper, reverse, translate, and substr_index, which preserve the first argument's string type. It also means users cannot keep Utf8 flowing through these functions even when they explicitly opt out of view types with datafusion.sql_parser.map_string_types_to_utf8view=false and datafusion.execution.parquet.schema_force_view_types=false.

This is especially surprising for systems that intentionally avoid view types at API or materialization boundaries: a query such as substr(utf8_col, 1, 3) silently produces Utf8View and then downstream code has to add explicit casts back to Utf8.

Describe the solution you'd like

Make left, right, and substr preserve the first argument's string type:

  • Utf8 -> Utf8
  • LargeUtf8 -> LargeUtf8
  • Utf8View -> Utf8View

This matches the behavior of lower / upper and still keeps the optimized view-array path for Utf8View inputs.

Describe alternatives you've considered

The current behavior was introduced for performance because Utf8View can represent slices without copying for regular string input. Another possible design would be an explicit configuration option, but the return type of scalar functions is currently not configuration-driven, so input-driven return types are simpler and consistent with nearby string functions.

Additional context

This revisits the tradeoff from #21441 / #21442 and the similar substr optimization. The goal is not to remove Utf8View support, but to avoid forcing it when callers use Utf8 / LargeUtf8 input.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions