This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 7548c3dd16 GH-47552: [C++] Fix creating wrong object by 
`FixedShapeTensorType::MakeArray()` (#47533)
7548c3dd16 is described below

commit 7548c3dd161ca875562b461469ac57400b415bd1
Author: corpoverlords <[email protected]>
AuthorDate: Sun Sep 14 00:53:31 2025 -0700

    GH-47552: [C++] Fix creating wrong object by 
`FixedShapeTensorType::MakeArray()` (#47533)
    
    ### Rationale for this change
    
    The builder should return the correct type.
    
    ### What changes are included in this PR?
    
    One liner
    
    ### Are these changes tested?
    
    Yes
    
    ### Are there any user-facing changes?
    
    No
    * GitHub Issue: #47552
    
    Lead-authored-by: Fan Jiang <[email protected]>
    Co-authored-by: Fan Jiang <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 cpp/src/arrow/extension/fixed_shape_tensor.cc      |  2 +-
 cpp/src/arrow/extension/fixed_shape_tensor_test.cc | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/cpp/src/arrow/extension/fixed_shape_tensor.cc 
b/cpp/src/arrow/extension/fixed_shape_tensor.cc
index d8fed85b1e..bb7082e697 100644
--- a/cpp/src/arrow/extension/fixed_shape_tensor.cc
+++ b/cpp/src/arrow/extension/fixed_shape_tensor.cc
@@ -202,7 +202,7 @@ std::shared_ptr<Array> FixedShapeTensorType::MakeArray(
   DCHECK_EQ(data->type->id(), Type::EXTENSION);
   DCHECK_EQ("arrow.fixed_shape_tensor",
             internal::checked_cast<const 
ExtensionType&>(*data->type).extension_name());
-  return std::make_shared<ExtensionArray>(data);
+  return std::make_shared<FixedShapeTensorArray>(data);
 }
 
 Result<std::shared_ptr<Tensor>> FixedShapeTensorType::MakeTensor(
diff --git a/cpp/src/arrow/extension/fixed_shape_tensor_test.cc 
b/cpp/src/arrow/extension/fixed_shape_tensor_test.cc
index cfc1265696..6d4d2de326 100644
--- a/cpp/src/arrow/extension/fixed_shape_tensor_test.cc
+++ b/cpp/src/arrow/extension/fixed_shape_tensor_test.cc
@@ -152,6 +152,28 @@ TEST_F(TestExtensionType, CreateFromArray) {
   ASSERT_EQ(ext_arr->null_count(), 0);
 }
 
+TEST_F(TestExtensionType, MakeArrayCanGetCorrectScalarType) {
+  ASSERT_OK_AND_ASSIGN(auto tensor,
+                       Tensor::Make(value_type_, Buffer::Wrap(values_), 
shape_));
+
+  auto exact_ext_type = 
internal::checked_pointer_cast<FixedShapeTensorType>(ext_type_);
+  ASSERT_OK_AND_ASSIGN(auto ext_arr, 
FixedShapeTensorArray::FromTensor(tensor));
+
+  auto data = ext_arr->data();
+  auto array = internal::checked_pointer_cast<FixedShapeTensorArray>(
+      exact_ext_type->MakeArray(data));
+  ASSERT_EQ(array->length(), shape_[0]);
+  ASSERT_EQ(array->null_count(), 0);
+
+  // Check that we can get the first element of the array
+  ASSERT_OK_AND_ASSIGN(auto first_element, array->GetScalar(0));
+  ASSERT_EQ(*(first_element->type),
+            *(fixed_shape_tensor(value_type_, element_shape_, {0, 1})));
+
+  ASSERT_OK_AND_ASSIGN(auto tensor_from_array, array->ToTensor());
+  ASSERT_TRUE(tensor->Equals(*tensor_from_array));
+}
+
 void CheckSerializationRoundtrip(const std::shared_ptr<DataType>& ext_type) {
   auto fst_type = 
internal::checked_pointer_cast<FixedShapeTensorType>(ext_type);
   auto serialized = fst_type->Serialize();

Reply via email to