wjones127 commented on code in PR #13859: URL: https://github.com/apache/arrow/pull/13859#discussion_r968857981
########## docs/source/cpp/tutorials/basic_arrow.rst: ########## @@ -0,0 +1,283 @@ +.. Licensed to the Apache Software Foundation (ASF) under one +.. or more contributor license agreements. See the NOTICE file +.. distributed with this work for additional information +.. regarding copyright ownership. The ASF licenses this file +.. to you under the Apache License, Version 2.0 (the +.. "License"); you may not use this file except in compliance +.. with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, +.. software distributed under the License is distributed on an +.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +.. KIND, either express or implied. See the License for the +.. specific language governing permissions and limitations +.. under the License. + +.. default-domain:: cpp +.. highlight:: cpp + +.. cpp:namespace:: arrow + +=========================== +Basic Arrow Data Structures +=========================== + +Apache Arrow provides fundamental data structures for representing data: +:class:`Array`, :class:`ChunkedArray`, :class:`RecordBatch`, and :class:`Table`. +This article shows how to construct these data structures from primitive +data types; specifically, we will work with integers of varying size +representing days, months, and years. We will use them to create the following data structures: + +#. Arrow :class:`Arrays <Array>` +#. :class:`ChunkedArrays<ChunkedArray>` +#. :class:`RecordBatch`, from :class:`Arrays <Array>` +#. :class:`Table`, from :class:`ChunkedArrays<ChunkedArray>` + +Pre-requisites +-------------- +Before continuing, make sure you have: + +#. An Arrow installation +#. Understanding of how to use basic C++ data structures +#. Understanding of basic C++ data types + + +Setup +----- + +Before trying out Arrow, we need to fill in a couple gaps: + +1. We need to include necessary headers. + +2. ``A main()`` is needed to glue things together. + +Includes +^^^^^^^^ + +First, as ever, we need some includes. We'll get ``iostream`` for output, then import Arrow's basic +functionality from ``api.h``, like so: + +.. literalinclude:: ../../../../cpp/examples/tutorial_examples/arrow_example.cc + :language: cpp + :start-after: (Doc section: Includes) + :end-before: (Doc section: Includes) + +Main() +^^^^^^ + +Next, we need a ``main()`` – a common pattern with Arrow looks like the +following: + +.. literalinclude:: ../../../../cpp/examples/tutorial_examples/arrow_example.cc + :language: cpp + :start-after: (Doc section: Main) + :end-before: (Doc section: Main) + +This allows us to easily use Arrow’s error-handling macros, which will +return back to ``main()`` with a :class:`arrow::Status` object if a failure occurs – and +this ``main()`` will report the error. Note that this means Arrow never +raises exceptions, instead relying upon returning :class:`Status`. For more on +that, read here: <LINK TO CONCEPTUAL OVERVIEW> + +To accompany this ``main()``, we have a ``RunMain()`` from which any :class:`Status` +objects can return – this is where we’ll write the rest of the program: + +.. literalinclude:: ../../../../cpp/examples/tutorial_examples/arrow_example.cc + :language: cpp + :start-after: (Doc section: RunMain Start) + :end-before: (Doc section: RunMain Start) + + +Making an Arrow Array +--------------------- + +Building int8 Arrays +^^^^^^^^^^^^^^^^^^^^ + +Given that we have some data in standard C++ arrays, and want to use Arrow, we need to move +the data from said arrays into Arrow arrays. We still guarantee contiguity of memory in an +:class:`Array`, so no worries about a performance loss when using :class:`Array` vs C++ arrays. +The easiest way to construct an :class:`Array` uses an :class:`ArrayBuilder`. <RST +NOTE NEAR HERE: for more technical details, check out…> Review Comment: Yes to be clear I'm not advocating for prose within this article, but a "see also" callout. My intuition is that a C++ programmer would want to know immediately how access the values. -- 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]
