mirror of
https://github.com/apache/arrow.git
synced 2026-10-29 09:05:47 +08:00
Update documentation
This commit is contained in:
1 parent
1a3743e002
commit
8b472da8a4
5 files changed
+74
-24
No files matched your search
+3
-3
@@ -85,7 +85,7 @@ struct ConversionTraits<std::vector<value_c_type>>
|
||||
typename ConversionTraits<value_c_type>::ArrowType>::BuilderType;
|
||||
ARROW_RETURN_NOT_OK(builder.Append());
|
||||
ElementBuilderType& value_builder =
|
||||
static_cast<ElementBuilderType&>(*builder.value_builder());
|
||||
::arrow::internal::checked_cast<ElementBuilderType&>(*builder.value_builder());
|
||||
for (auto const& value : cell) {
|
||||
ARROW_RETURN_NOT_OK(
|
||||
ConversionTraits<value_c_type>::AppendRow(value_builder, value));
|
||||
@@ -227,7 +227,7 @@ struct RowIterator {
|
||||
using BuilderType =
|
||||
typename TypeTraits<typename ConversionTraits<Element>::ArrowType>::BuilderType;
|
||||
|
||||
BuilderType& builder = static_cast<BuilderType&>(*builders[N - 1]);
|
||||
BuilderType& builder = ::arrow::internal::checked_cast<BuilderType&>(*builders[N - 1]);
|
||||
ARROW_RETURN_NOT_OK(ConversionTraits<Element>::AppendRow(builder, get<N - 1>(row)));
|
||||
|
||||
return RowIterator<Tuple, N - 1>::Append(builders, row);
|
||||
@@ -309,7 +309,7 @@ template <typename Range>
|
||||
Status TableFromTupleRange(MemoryPool* pool, const Range& rows,
|
||||
const std::vector<std::string>& names,
|
||||
std::shared_ptr<Table>* table) {
|
||||
using row_type = typename std::decay<decltype(*std::begin(rows))>::type;
|
||||
using row_type = typename std::iterator_traits<decltype(std::begin(rows))>::value_type;
|
||||
constexpr std::size_t n_columns = std::tuple_size<row_type>::value;
|
||||
|
||||
std::shared_ptr<Schema> schema = SchemaFromTuple<row_type>::MakeSchema(names);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
.. 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.
|
||||
|
||||
Examples
|
||||
========
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
row_columnar_conversion
|
||||
std::tuple-like ranges to Arrow <tuple_range_conversion>
|
||||
@@ -0,0 +1,27 @@
|
||||
.. 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
|
||||
|
||||
Row to columnar conversion
|
||||
==========================
|
||||
|
||||
The following example converts an array of structs to a :class:`arrow::Table`
|
||||
instance, and then converts it back to the original array of structs.
|
||||
|
||||
.. literalinclude:: ../../../../cpp/examples/arrow/row-wise-conversion-example.cc
|
||||
+18
-20
@@ -18,19 +18,8 @@
|
||||
.. default-domain:: cpp
|
||||
.. highlight:: cpp
|
||||
|
||||
Examples
|
||||
========
|
||||
|
||||
Row to columnar conversion
|
||||
--------------------------
|
||||
|
||||
The following example converts an array of structs to a :class:`arrow::Table`
|
||||
instance, and then converts it back to the original array of structs.
|
||||
|
||||
.. literalinclude:: ../../../cpp/examples/arrow/row-wise-conversion-example.cc
|
||||
|
||||
Conversion of range of ``std::tuple``-like to ``Table`` instances
|
||||
-----------------------------------------------------------------
|
||||
=================================================================
|
||||
|
||||
While the above example shows a quite manual approach of a row to columnar
|
||||
conversion, Arrow also provides some template logic to convert ranges of
|
||||
@@ -71,23 +60,31 @@ pre-allocated range with the data from a ``Table`` instance.
|
||||
|
||||
Arrow itself already supports some C(++) data types for this conversion. If you
|
||||
want to support additional data types, you need to implement a specialization
|
||||
of ``arrow::stl::ConversionTraits<T>``.
|
||||
of ``arrow::stl::ConversionTraits<T>`` and the more general
|
||||
``arrow::CTypeTraits<T>``.
|
||||
|
||||
|
||||
.. code::
|
||||
|
||||
namespace arrow {
|
||||
|
||||
template<>
|
||||
struct CTypeTraits<boost::posix_time::ptime> {
|
||||
using ArrowType = ::arrow::TimestampType;
|
||||
|
||||
static std::shared_ptr<::arrow::DataType> type_singleton() {
|
||||
return ::arrow::timestamp(::arrow::TimeUnit::MICRO);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace arrow { namespace stl {
|
||||
|
||||
template <>
|
||||
struct ConversionTraits<boost::posix_time::ptime> {
|
||||
struct ConversionTraits<boost::posix_time::ptime> : public CTypeTraits<boost::posix_time::ptime> {
|
||||
constexpr static bool nullable = false;
|
||||
|
||||
using ArrowType = ::arrow::TimestampType;
|
||||
|
||||
static std::shared_ptr<::arrow::DataType> arrow_type() {
|
||||
return ::arrow::timestamp(::arrow::TimeUnit::MICRO);
|
||||
}
|
||||
|
||||
// This is the specialization to load a scalar value into an Arrow builder.
|
||||
static Status AppendRow(
|
||||
typename TypeTraits<TimestampType>::BuilderType& builder,
|
||||
@@ -106,3 +103,4 @@ of ``arrow::stl::ConversionTraits<T>``.
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -22,7 +22,7 @@ C++ Implementation
|
||||
:maxdepth: 2
|
||||
|
||||
getting_started
|
||||
examples
|
||||
Examples <examples/index>
|
||||
api
|
||||
|
||||
.. TODO add "topics" chapter
|
||||
|
||||
Reference in new issue
Block a user