wjones127 commented on a change in pull request #166:
URL: https://github.com/apache/arrow-cookbook/pull/166#discussion_r830384427



##########
File path: cpp/source/basic.rst
##########
@@ -48,3 +48,29 @@ boilerplate for you.  It will run the contained expression 
and check the resulti
 .. recipe:: ../code/basic_arrow.cc ReturnNotOk
   :caption: Using ARROW_RETURN_NOT_OK to check the status
   :dedent: 2
+
+
+Using the Visitor Pattern
+=========================
+
+Arrow classes like DataType, Scalar, and Array have specialized subclasses for
+each Arrow type. In order to work with them, use the visitor pattern. These 
+types provide an Accept method and have associated Visitor classes.
+
+As an example, below we implement a :cpp:class:`arrow::TypeVisitor` that counts
+the number of  primitive and nested types.
+
+To implement a TypeVisitor we have to implement a Visit method for every 
possible
+DataType we wish to handle. Fortunately, we can often use templates and type
+traits to make this less verbose.
+
+.. literalinclude:: ../code/basic_arrow.cc
+   :language: cpp
+   :linenos:
+   :start-at: class TypeCountVisitor
+   :end-at: };  // TypeCountVisitor
+   :caption: TypeVisitor that counts nested and non-nested types

Review comment:
       I've created two new examples. One is a class that generates a random 
record batch given a schema and row count, which showcases an approach to 
handling nested types.
   
   The other is a class that can sum across columns of varied number types, 
which showcases how to use the type traits to avoid repetitive implementations 
for similar types.
   
   I think these are better use cases that my original. The first is something 
I've seen in the wild (and is also inspired by our internal test functions).




-- 
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]


Reply via email to