You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "pw42020 (via GitHub)" <gi...@apache.org> on 2025/06/16 13:10:23 UTC
[I] [C++] [arrow]
pw42020 opened a new issue, #46824:
URL: https://github.com/apache/arrow/issues/46824
### Describe the bug, including details regarding any error messages, version, and platform.
**Describe the bug, including details regarding any error messages, version, and platform.**
When attempting to use ` arrow::StructArray::Make` to nest fields in our example below, we find our "Hour" and "Minute" fields are turned into "child 0" and "child 1" respectively.
```cpp
#include <arrow/api.h>
#include <iostream>
arrow::Status RunTest()
{
// Sample Data
int16_t hours[2][1] = { { 9 }, { 8 } };
int16_t minutes[2][1] = { { 3 }, { 45 } };
int16_t days[2] = { 1, 2 };
// Create Field Vector for Struct Array
const arrow::FieldVector f_time = { arrow::field( "Hour", arrow::int16() ),
arrow::field( "Minute", arrow::int16() ) };
// Create Arrays an StructArray
std::shared_ptr< arrow::Array > v_hours;
std::shared_ptr< arrow::Array > v_minutes;
std::shared_ptr< arrow::Array > v_days;
std::shared_ptr< arrow::StructArray > v_timestamp;
// Build Arrays and Struct Array
arrow::Int16Builder builder;
ARROW_RETURN_NOT_OK( builder.AppendValues( hours[0], 1 ) );
ARROW_RETURN_NOT_OK( builder.AppendValues( hours[1], 1 ) );
ARROW_ASSIGN_OR_RAISE( v_hours, builder.Finish() );
ARROW_RETURN_NOT_OK( builder.AppendValues( minutes[0], 1 ) );
ARROW_RETURN_NOT_OK( builder.AppendValues( minutes[1], 1 ) );
ARROW_ASSIGN_OR_RAISE( v_minutes, builder.Finish() );
ARROW_ASSIGN_OR_RAISE( v_timestamp, arrow::StructArray::Make( { v_hours, v_minutes }, f_time ) );
ARROW_RETURN_NOT_OK( builder.AppendValues( days, 2 ) );
ARROW_ASSIGN_OR_RAISE( v_days, builder.Finish() );
// Create Schema
std::shared_ptr< arrow::Field > f_days = arrow::field( "Day", arrow::int16() );
std::shared_ptr< arrow::Field > f_timestamp = arrow::field( "Timestamp", arrow::int16() );
auto schema = arrow::schema( { f_days, f_timestamp } );
// Create Record Batch
auto rbatch = arrow::RecordBatch::Make( schema, 2, { v_days, v_timestamp } );
// Print Record Batch
std::cout << rbatch->ToString();
return arrow::Status::OK();
}
int main()
{
arrow::Status st = RunTest();
if ( !st.ok() )
{
std::cerr << st << std::endl;
return 1;
}
return 0;
}
```
The output yields
```sh
Day: [
1,
2
]
Timestamp: -- is_valid: all not null
-- child 0 type: int16
[
9,
8
]
-- child 1 type: int16
[
3,
45
]
```
**Expected Results**
```sh
Day: [
1,
2
]
Timestamp: -- is_valid: all not null
-- Hour type: int16
[
9,
8
]
-- Minute type: int16
[
3,
45
]
```
**Any error messages, version, and platform.**
No error messages or warnings were received.
**Version and Platform**
Version of Arrow: 20.0.0
`lsb_release -a`
```sh
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 24.04.2 LTS
Release: 24.04
Codename: noble
```
Linux Kernel: 6.8.0-48-generic
`uname -m`
```sh
x86_64
```
### 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++] Field names in arrow::StructArray::Make get set to default [arrow]
Posted by "pw42020 (via GitHub)" <gi...@apache.org>.
pw42020 closed issue #46824: [C++] Field names in arrow::StructArray::Make get set to default
URL: https://github.com/apache/arrow/issues/46824
--
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
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [C++] Field names in arrow::StructArray::Make get set to default [arrow]
Posted by "pw42020 (via GitHub)" <gi...@apache.org>.
pw42020 commented on issue #46824:
URL: https://github.com/apache/arrow/issues/46824#issuecomment-2980276016
Ah thank you! I didn't think to check the function itself. Thanks for your help.
--
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++] Field names in arrow::StructArray::Make get set to default [arrow]
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on issue #46824:
URL: https://github.com/apache/arrow/issues/46824#issuecomment-2978645167
This may be what you want:
```diff
diff --git a/cpp/src/arrow/pretty_print.cc b/cpp/src/arrow/pretty_print.cc
index 807498b6bf..64cd647330 100644
--- a/cpp/src/arrow/pretty_print.cc
+++ b/cpp/src/arrow/pretty_print.cc
@@ -215,7 +215,7 @@ class ArrayPrinter : public PrettyPrinter {
Write("\n"); // Always want newline before child array description
Indent();
std::stringstream ss;
- ss << "-- child " << i << " type: " << fields[i]->type()->ToString() << "\n";
+ ss << "-- child " << i << " (" << fields[i].name() << ") type: " << fields[i]->type()->ToString() << "\n";
Write(ss.str());
// Indent();
```
--
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++] Field names in arrow::StructArray::Make get set to default [arrow]
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on issue #46824:
URL: https://github.com/apache/arrow/issues/46824#issuecomment-2981916926
If you want this change, please re-open this issue and open a PR for the change? (We may need to update expected values in our tests.)
--
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