Skip to content

[C++] "case_when" test failure on random union inputs #15192

Closed

Description

@pitrou

Describe the bug, including details regarding any error messages, version, and platform.

Enabling this commented out test in scalar_if_else_test_.cc produces test failures:

// TEST(TestCaseWhen, UnionBoolStringRandom) {
//   for (const auto& type : std::vector<std::shared_ptr<DataType>>{
//            sparse_union({field("a", boolean()), field("b", utf8())}, {2, 7}),
//            dense_union({field("a", boolean()), field("b", utf8())}, {2, 7})}) {
//     ARROW_SCOPED_TRACE(type->ToString());
//     TestCaseWhenRandom(type);
//   }
// }

Component(s)

C++

Activity

  1. pitrou commented on Jan 4, 2023

    @pitrou
    MemberAuthor
  2. pitrou commented on Jan 4, 2023

    @pitrou
    MemberAuthor

    (#15131 is needed to reproduce)

  3. zanmato1984 commented on Dec 19, 2023

    @zanmato1984
    Contributor

    Looked a bit. The error message is

    '::arrow::internal::ValidateArrayFull(output)' failed with Invalid: Union value at position 0 has invalid type id 0
    

    , assuming this is the error that this issue encountered.

    The reason of this failure is:

    1. The random array generation for union types doesn't take into account the type code specified in the UnionDataType object:
      // Trivial type codes map
    2. The function case_when executes fine because the type id generation is also trivial
      // Generate array of type ids
    3. Finally a full validation is conducted on the function output
      ValidateOutputImpl(*output.array());

      , which checks if type ids in the buffer match the ones specified in the data type (and they don't)
      return Status::Invalid("Union value at position ", i, " has invalid type id ",

    I think I can take this and make random array generation respect the type ids specified in the data type, instead of generating trivial type ids.

  4. zanmato1984 commented on Dec 19, 2023

    @zanmato1984
    Contributor

    I found that we can bring the test back alive by simply removing passing customized type codes, drafted here: #39308
    And I think it's acceptable for this specific case because the case is about testing case_when rather than the "type code mapping" thing for union types.
    Of course this will leave the potential issue of mismatched type codes between in data type and actual data unchanged. So I'm also open to do a thorough change, i.e., making random union array generation respect the type ids specified in the data type.
    Any comments will be helpful. Thanks.
    cc @pitrou

  5. pitrou commented on Dec 20, 2023

    @pitrou
    MemberAuthor

    @zanmato1984 Thanks for the investigation! I think it would be better to make random union array generation conformant, indeed.

  6. zanmato1984 commented on Dec 20, 2023

    @zanmato1984
    Contributor

    @zanmato1984 Thanks for the investigation! I think it would be better to make random union array generation conformant, indeed.

    Sure, will do. Thanks @pitrou !

  7. zanmato1984 commented on Dec 20, 2023

    @zanmato1984
    Contributor

    One quick question:
    In order to generate conformant type ids for random union array, I'll have to pass either UnionDataType or type codes into the following functions:

    std::shared_ptr<Array> SparseUnion(const ArrayVector& fields, int64_t size,
    int64_t alignment = kDefaultBufferAlignment,
    MemoryPool* memory_pool = default_memory_pool());

    std::shared_ptr<Array> DenseUnion(const ArrayVector& fields, int64_t size,
    int64_t alignment = kDefaultBufferAlignment,
    MemoryPool* memory_pool = default_memory_pool());

    However they seem to be public APIs, even though they belong to arrow-testing library. Do I have to make overloads of them or am I free to change the signatures?

    I appreciate if you can enlighten me about this? Thanks @pitrou !

  8. pitrou commented on Dec 20, 2023

    @pitrou
    MemberAuthor

    arrow-testing is not really for public usage, so you can change those APIs.

  9. zanmato1984 commented on Dec 21, 2023

    @zanmato1984
    Contributor

    Just found that #36018 already addressed the aforementioned problem. I made a mistake, my local branch was too old.

    Now this test case can be brought back alive without other changes, updated in #39308.

    So sad. And my apology for the unnecessary trouble :-(

  10. added a commit that references this issue on Dec 21, 2023
  11. added this to the 15.0.0 milestone on Dec 21, 2023
  12. added a commit that references this issue on Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions