bkietz commented on code in PR #46675:
URL: https://github.com/apache/arrow/pull/46675#discussion_r2152530709
##########
cpp/src/arrow/array/util.cc:
##########
@@ -829,7 +829,17 @@ class RepeatedArrayFactory {
}
Status Visit(const ExtensionType& type) {
- return Status::NotImplemented("construction from scalar of type ",
*scalar_.type);
+ // Retrieve the underlying storage scalar from the ExtensionScalar
+ const auto& ext_scalar = checked_cast<const ExtensionScalar&>(scalar_);
+ const auto& storage_scalar = ext_scalar.value;
+
+ // Create an array from the storage scalar
+ ARROW_ASSIGN_OR_RAISE(auto storage_array,
+ MakeArrayFromScalar(*storage_scalar, length_,
pool_));
+
+ // Wrap the storage array in the ExtensionType
+ out_ = type.MakeArray(storage_array->data());
Review Comment:
For this you want
[WrapArray](https://github.com/apache/arrow/blob/3917b605ef1851ad036fb62856efcc83e32f8580/cpp/src/arrow/extension_type.h#L90-L92);
[SmallintType::MakeArray](https://github.com/apache/arrow/blob/639201bfa412db26ce45e73851432018af6c945e/cpp/src/arrow/testing/gtest_util.cc#L859)
assumes that the argument is a fully correct ArrayData (including
ArrayData::type).
This requirement isn't documented in the declaration of
[ExtensionType::MakeArray](https://github.com/apache/arrow/blob/3917b605ef1851ad036fb62856efcc83e32f8580/cpp/src/arrow/extension_type.h#L71-L73),
so either
- we should add to the doccomment that `The argument must valid data for the
extension type, including its .type member; subclasses are not required to
coerce whatsoever. See also WrapArray`
- we should specify what coercion/validation subclasses are expected to
implement and fix the smallint
@pitrou WDYT?
##########
cpp/src/arrow/array/array_test.cc:
##########
@@ -815,6 +815,23 @@ TEST_F(TestArray, TestMakeArrayFromMapScalar) {
AssertAppendScalar(pool_, std::make_shared<MapScalar>(scalar));
}
+TEST_F(TestArray, TestMakeArrayFromScalar_SmallintExtensionType) {
Review Comment:
Underscores are used in name mangling of gtest cases, so [test case names
should not contain
them](https://google.github.io/googletest/faq.html#why-should-test-suite-names-and-test-names-not-contain-underscore)
```suggestion
TEST_F(TestArray, TestMakeArrayFromScalarSmallintExtensionType) {
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]