bkietz commented on a change in pull request #7026:
URL: https://github.com/apache/arrow/pull/7026#discussion_r417341382
##########
File path: cpp/src/arrow/scalar.cc
##########
@@ -252,6 +270,100 @@ Result<std::shared_ptr<Scalar>> Scalar::Parse(const
std::shared_ptr<DataType>& t
return ScalarParseImpl{type, s}.Finish();
}
+struct ScalarFromArraySlotImpl {
+ template <typename T>
+ using ScalarType = typename TypeTraits<T>::ScalarType;
+
+ Status Visit(const NullArray& a) {
+ out_ = std::make_shared<NullScalar>();
+ return Status::OK();
+ }
+
+ Status Visit(const BooleanArray& a) { return Finish(a.Value(index_)); }
+
+ template <typename T>
+ Status Visit(const NumericArray<T>& a) {
+ return Finish(a.Value(index_));
+ }
+
+ template <typename T>
+ Status Visit(const BaseBinaryArray<T>& a) {
+ return Finish(a.GetString(index_));
+ }
+
+ Status Visit(const FixedSizeBinaryArray& a) { return
Finish(a.GetString(index_)); }
+
+ Status Visit(const DayTimeIntervalArray& a) { return
Finish(a.Value(index_)); }
+
+ template <typename T>
+ Status Visit(const BaseListArray<T>& a) {
+ return Finish(a.value_slice(index_));
+ }
+
+ Status Visit(const FixedSizeListArray& a) { return
Finish(a.value_slice(index_)); }
+
+ Status Visit(const StructArray& a) {
+ ScalarVector children;
+ for (const auto& child : a.fields()) {
+ children.emplace_back();
+ ARROW_ASSIGN_OR_RAISE(children.back(), Scalar::FromArraySlot(*child,
index_));
+ }
+ return Finish(std::move(children));
+ }
+
+ Status Visit(const UnionArray& a) {
+ return Status::NotImplemented("Non-null UnionScalar");
+ }
+
+ Status Visit(const DictionaryArray& a) {
+ ARROW_ASSIGN_OR_RAISE(auto index, Scalar::FromArraySlot(*a.indices(),
index_));
Review comment:
I'll add `int64_t DictionaryArray::GetValueIndex(int64_t row_index)`,
that's a nice helper
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]