Skip to content

Read string as Utf8View in sqllogictest #13408

Closed

Description

@jayzhan211

Is your feature request related to a problem or challenge?

This is the simplest way to create a string column

statement ok
create table t(a varchar) as values ('1'), ('2');

query T
select arrow_typeof(a) from t;
----
Utf8
Utf8

statement ok
drop table t

I'm finding a simple way to create Utf8View column. We can achieve this with casting (See datafusion/sqllogictest/test_files/string/string_view.slt) but I think we can have a more simpler way to do this.

Describe the solution you'd like

I have two idea but not sure which one is better

Approach 1

Set the configuration with use_string_view = true, and we will read the column (varchar) as string view type instead of string type.

Something like

set datafusion.xxx.use_string_view = true

statement ok
create table t(a varchar) as values ('1'), ('2');

query T
select arrow_typeof(a) from t;
----
Utf8View
Utf8View

statement ok
drop table t

This avoid adding new syntax.

Approach 2

introduce string_view syntax like varchar_view so we know we want to read it as string view type

Something like

statement ok
create table t(a varchar_view) as values ('1'), ('2');

query T
select arrow_typeof(a) from t;
----
Utf8View
Utf8View

statement ok
drop table t

This adds complexity of understanding of string view type for people from Postgres.

Describe alternatives you've considered

No response

Additional context

No response

Activity

  1. changed the title [-]Configure string view as default type in sqllogictest[/-] [+]Read string as Utf8View in sqllogictest[/+] on Nov 14, 2024
  2. jayzhan211 commented on Nov 14, 2024

    @jayzhan211
    ContributorAuthor

    Now I would prefer the first approach since string view type is more to a "physical type" concept, add this to parser doesn't fit very well.

  3. Omega359 commented on Nov 15, 2024

    @Omega359
    Contributor

    The first approach 100%

  4. Weijun-H commented on Nov 16, 2024

    @Weijun-H
    Member

    vote for 1st approach

  5. findepi commented on Nov 16, 2024

    @findepi
    Member

    statement ok
    create table t(a varchar) as values ('1'), ('2');

    query T
    select arrow_typeof(a) from t;

    Utf8View
    Utf8View

    if the table t is created internally using Utf8View, then i agree that SLT should return that on query output.
    if the table t is created internally using Utf8, SLT should continue to read it as Utf8, unless DF engine generally replaces Utf8View with Utf8 (which i think it does not)

    So, do we need a new config after all?

  6. alamb commented on Dec 17, 2024

    @alamb
    Contributor

    The first approach 100%

    Likewise, I think the first approach is good

  7. alamb commented on Jan 27, 2025

    @alamb
    Contributor

    I am not sure if you have seen the great string patter in sqllogictest from @goldmedal yet: https://github.com/apache/datafusion/tree/main/datafusion/sqllogictest/test_files/string

    Basically it lets you write one set of tests and then verify those tests work with all the different types of string array (Utf8, Utf8View, LargeUtf8View, Dictionary(...), etc)

    If this ticket is just about making it easier to write slt tests, I think the string tests might be enough

    However, at least part of this ticket seems to be suggesting changing what Arrow DataType is used for varchar -- if that is what you are proposing then I think the string slt is not enough 🤔

  8. Jefffrey commented on Oct 4, 2025

    @Jefffrey
    Contributor

    Resolved by #15096; varchar should now be Utf8View type by default

  9. findepi commented on Oct 4, 2025

    @findepi
    Member

    at dbt, we also had a problem of hard-to-provide test coverage for Utf8, Utf8View.
    A varchar can be one of them, but the code (eg UDFs) ultimately needs to accept both
    what we ended up doing is fuzzing in SLT tests. At the test start we generate a random number. Then every string literal is either Utf8, Utf8View or LargeUtf8 -- deterministically based on its value and this random number.
    This helped identify many places too rigid or with missing coercion logic (often not only string related), while still allowing us to reproduce any test failures observed on CI.

  10. Jefffrey commented on Oct 6, 2025

    @Jefffrey
    Contributor

    at dbt, we also had a problem of hard-to-provide test coverage for Utf8, Utf8View. A varchar can be one of them, but the code (eg UDFs) ultimately needs to accept both what we ended up doing is fuzzing in SLT tests. At the test start we generate a random number. Then every string literal is either Utf8, Utf8View or LargeUtf8 -- deterministically based on its value and this random number. This helped identify many places too rigid or with missing coercion logic (often not only string related), while still allowing us to reproduce any test failures observed on CI.

    Should we raise a new issue to track this idea? To fuzz not only strings but also lists (largelist, list, fixedsize) and binary/fixedbinary?

  11. alamb commented on Oct 6, 2025

    @alamb
    Contributor

    at dbt, we also had a problem of hard-to-provide test coverage for Utf8, Utf8View. A varchar can be one of them, but the code (eg UDFs) ultimately needs to accept both what we ended up doing is fuzzing in SLT tests. At the test start we generate a random number. Then every string literal is either Utf8, Utf8View or LargeUtf8 -- deterministically based on its value and this random number. This helped identify many places too rigid or with missing coercion logic (often not only string related), while still allowing us to reproduce any test failures observed on CI.

    Should we raise a new issue to track this idea? To fuzz not only strings but also lists (largelist, list, fixedsize) and binary/fixedbinary?

    Yes for sure!

  12. Jefffrey commented on Oct 7, 2025

    @Jefffrey
    Contributor

    Raised #17947 for tracking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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