You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "paleolimbot (via GitHub)" <gi...@apache.org> on 2026/04/07 03:13:12 UTC

[I] `RecordBatch::MakeEmpty()` may drop ordered flag when creating dictionary-encoded column [arrow]

paleolimbot opened a new issue, #49674:
URL: https://github.com/apache/arrow/issues/49674

   ### Describe the bug, including details regarding any error messages, version, and platform.
   
   Found when working on dictionary encoding in nanoarrow in https://github.com/apache/arrow-nanoarrow/pull/861 ...I have yet to confirm independently of that. The bit of code this affects for me checking a roundtrip of an empty record batch through IPC...I am not sure it actually makes sense for any practical purpose to have an empty (but ordered) dictionary.
   
   ```c
     EXPECT_EQ(maybe_batch.ValueUnsafe()->ToString(), empty->ToString());
     if (data_type->id() != arrow::Type::DICTIONARY ||
         !std::static_pointer_cast<arrow::DictionaryType>(data_type)->ordered()) {
       EXPECT_TRUE(maybe_batch.ValueUnsafe()->Equals(*empty)) << empty->ToString();
     }
   ```
   
   
   
   ### Component(s)
   
   C++


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [C++] `RecordBatch::MakeEmpty()` may drop ordered flag when creating dictionary-encoded column [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on issue #49674:
URL: https://github.com/apache/arrow/issues/49674#issuecomment-4274969458

   Hi @paleolimbot, I have opened a PR for this issue #49798 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] `RecordBatch::MakeEmpty()` may drop ordered flag when creating dictionary-encoded column [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on issue #49674:
URL: https://github.com/apache/arrow/issues/49674#issuecomment-4270679904

   Okay, will wait for your confirmation on whether this turns out to be on the Arrow C++ side.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] `RecordBatch::MakeEmpty()` may drop ordered flag when creating dictionary-encoded column [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on issue #49674:
URL: https://github.com/apache/arrow/issues/49674#issuecomment-4273451771

   Hi @paleolimbot, I was able to reproduce this. The issue occurs because `DictionaryBuilder`reconstructs the `DictionaryType` without preserving the ordered flag, which defaults to false. 
   
   I implemented a fix in `MakeEmptyArray` to restore the original type after building the array, and added a test that verifies the ordered flag is preserved.
   
   Before opening a PR, I wanted to confirm whether this scoped fix is preferred, or if you'd rather address it at the `DictionaryBuilder` level.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] `RecordBatch::MakeEmpty()` may drop ordered flag when creating dictionary-encoded column [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on issue #49674:
URL: https://github.com/apache/arrow/issues/49674#issuecomment-4270528787

   I tried to reproduce this using `RecordBatch::MakeEmpty()` and IPC roundtrips with ordered dictionary types, but I wasn’t able to observe the ordered flag being dropped.
   
   Is this specific to a case where the dictionary array has actual dictionary values (e.g., non-empty dictionary with empty indices), or does it require a particular nanoarrow workflow?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [C++] `RecordBatch::MakeEmpty()` may drop ordered flag when creating dictionary-encoded column [arrow]

Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on issue #49674:
URL: https://github.com/apache/arrow/issues/49674#issuecomment-4274378576

   I'm not an expert on these internals, but I can see how the DictionaryBuilder might not be able to guarantee the ordering of the keys that come out of it while preserving the dictionary indices emitted for previous rows. It seems like your approach is reasonable...make a PR and we can discuss there! 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [C++] `RecordBatch::MakeEmpty()` may drop ordered flag and unsignedness of dictionary types when creating dictionary-encoded column [arrow]

Posted by "thisisnic (via GitHub) via github" <gi...@arrow.apache.org>.
thisisnic commented on issue #49674:
URL: https://github.com/apache/arrow/issues/49674#issuecomment-6994106031

   @paleolimbot I think this is fixed as of 26.0.0, but mind checking this as it's from Claude and I'm not totally sure?  Cheers!
   
   ---
   
   :robot: :
   
   `RecordBatch::MakeEmpty()` now keeps both the `ordered` flag (#49937, in 25.0.0) and unsigned index types (#50475, in 26.0.0).
   
   An empty batch with an ordered or unsigned-index dictionary column has the same column type as its schema and compares equal  after an IPC round trip on 26.0.0, where on 24.0.0 it did not.
   
   Does that match what you see from the nanoarrow side? If so, are you happy for this to be closed? The workaround in `decoder_test.cc` should be removable once nanoarrow's CI builds against 26.0.0.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] `RecordBatch::MakeEmpty()` may drop ordered flag when creating dictionary-encoded column [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on issue #49674:
URL: https://github.com/apache/arrow/issues/49674#issuecomment-4273003623

   That makes sense, I was only checking the schema before, but I can reproduce the issue when inspecting the array type. I’ll take a closer look at how the array is constructed in MakeEmpty().


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] `RecordBatch::MakeEmpty()` may drop ordered flag when creating dictionary-encoded column [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on issue #49674:
URL: https://github.com/apache/arrow/issues/49674#issuecomment-4270122311

   Hi @paleolimbot, just to confirm the expected behavior here: should `RecordBatch::MakeEmpty()` preserve the `ordered` flag for `DictionaryType`, or is it acceptable for that information to be lost for empty batches?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] `RecordBatch::MakeEmpty()` may drop ordered flag when creating dictionary-encoded column [arrow]

Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on issue #49674:
URL: https://github.com/apache/arrow/issues/49674#issuecomment-4271459964

   CoPilot via Opus 4.5 generated this (rather dramatic, if I may say so) confirmation of the bug. Basically, the schema is correct but NOT the data type of column.
   
   ```
   // Diagnostic test to demonstrate Arrow C++ MakeEmpty() bug
   // The schema has ordered=1, but the array type created by MakeEmpty() has ordered=0
   TEST(NanoarrowIpcTest, ArrowMakeEmptyLosesOrderedFlag) {
     // Create an ordered dictionary type
     auto data_type = arrow::dictionary(arrow::int32(), arrow::utf8(), /*ordered=*/true);
     std::shared_ptr<arrow::Schema> schema =
         arrow::schema({arrow::field("col", data_type)});
   
     // MakeEmpty should create a batch with ordered=true arrays
     auto maybe_empty = arrow::RecordBatch::MakeEmpty(schema);
     ASSERT_TRUE(maybe_empty.ok()) << maybe_empty.status();
     auto empty = maybe_empty.ValueUnsafe();
   
     // Schema correctly has ordered=1
     auto schema_dict_type =
         std::static_pointer_cast<arrow::DictionaryType>(empty->schema()->field(0)->type());
     EXPECT_TRUE(schema_dict_type->ordered()) << "Schema should have ordered=true";
   
     // BUG: Array type has ordered=0
     auto array_dict_type =
         std::static_pointer_cast<arrow::DictionaryType>(empty->column(0)->type());
     // This is the bug in Arrow C++ MakeEmpty() - the array type loses ordered flag
     // https://github.com/apache/arrow/issues/49674
     EXPECT_FALSE(array_dict_type->ordered())
         << "BUG CONFIRMED: MakeEmpty() array has ordered=0 (should be 1)";
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [C++] `RecordBatch::MakeEmpty()` may drop ordered flag when creating dictionary-encoded column [arrow]

Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on issue #49674:
URL: https://github.com/apache/arrow/issues/49674#issuecomment-4427199775

   in https://github.com/apache/arrow-nanoarrow/pull/882 I also found that it may be dropping the unsigned-ness from unsigned dictionary types!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] `RecordBatch::MakeEmpty()` may drop ordered flag when creating dictionary-encoded column [arrow]

Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on issue #49674:
URL: https://github.com/apache/arrow/issues/49674#issuecomment-4270134331

   I think it should be preserved...having the schema of a batch not equal the schema used to create it caused errors in my tests and I think is the intention of MakeEmpty.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] `RecordBatch::MakeEmpty()` may drop ordered flag when creating dictionary-encoded column [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on issue #49674:
URL: https://github.com/apache/arrow/issues/49674#issuecomment-4270287699

   Thanks @paleolimbot for confirming, I’ll try to reproduce this and look into where the ordered flag is being dropped during MakeEmpty().


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] `RecordBatch::MakeEmpty()` may drop ordered flag when creating dictionary-encoded column [arrow]

Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on issue #49674:
URL: https://github.com/apache/arrow/issues/49674#issuecomment-4270654725

   Thank you for looking!
   
   It looks like the place I ran across that was here:
   
   https://github.com/apache/arrow-nanoarrow/pull/861/changes#diff-809791cd3b01ea5de2038a046f68a5e5649126a74d9e2ac9ac18217c65f395dfR1326
   
   ...where there's quite a few nanoarrow things going on too. I will double check that from my end to make sure this is actually an Arrow C++ issue 😬 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org