fsaintjacques commented on a change in pull request #7026:
URL: https://github.com/apache/arrow/pull/7026#discussion_r417218364



##########
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:
       Multiple problems here:
   
   1. Confusing naming with `index`, `index_`, `index64`, 
   2. We shouldn't use Scalar because its dynamic typing is convenient,, it 
should stick to C++ type system. You can add a method `int64_t 
DictionaryArray::GetValueIndex(int64_t row_index)` that will properly upcast to 
int64_t independent of `indices` type. This Visit method becomes trivial 
afterward.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to