Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +2 -0
- parrot/lib/libreadline.so +3 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/acero/hash_join.h +75 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/adapters/orc/adapter.h +323 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/array_dict.h +182 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/array_nested.h +898 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/array_primitive.h +202 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/array_run_end.h +133 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/builder_adaptive.h +215 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/builder_binary.h +971 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/builder_decimal.h +102 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/builder_primitive.h +556 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/builder_time.h +66 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/diff.h +76 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/util.h +96 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/api.h +25 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/dictionary.h +177 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/feather.h +150 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/json_simple.h +71 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/message.h +565 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/options.h +178 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/reader.h +638 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/test_common.h +189 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/type_fwd.h +68 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/writer.h +475 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/arrow_to_pandas.h +146 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/async.h +60 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/csv.h +42 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/gdb.h +29 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/helpers.h +162 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/inference.h +64 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/init.h +26 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/io.h +121 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/numpy_convert.h +122 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/numpy_to_arrow.h +72 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/parquet_encryption.h +132 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/platform.h +41 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/pyarrow.h +89 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/python_test.h +42 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/udf.h +81 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/tensor/converter.h +67 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/async_util.h +460 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/basic_decimal.h +492 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/benchmark_util.h +211 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/bit_block_counter.h +570 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/bitmap_ops.h +244 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/bitmap_reader.h +273 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/bpacking64_default.h +0 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/bpacking_avx2.h +28 -0
- parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/bpacking_default.h +0 -0
.gitattributes
CHANGED
|
@@ -115,3 +115,5 @@ parrot/lib/python3.10/site-packages/pyarrow/_hdfs.cpython-310-x86_64-linux-gnu.s
|
|
| 115 |
parrot/lib/python3.10/site-packages/pyarrow/_substrait.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 116 |
parrot/lib/python3.10/site-packages/pyarrow/_json.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 117 |
parrot/lib/python3.10/site-packages/pyarrow/_azurefs.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 115 |
parrot/lib/python3.10/site-packages/pyarrow/_substrait.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 116 |
parrot/lib/python3.10/site-packages/pyarrow/_json.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 117 |
parrot/lib/python3.10/site-packages/pyarrow/_azurefs.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 118 |
+
parrot/lib/libreadline.so filter=lfs diff=lfs merge=lfs -text
|
| 119 |
+
parrot/lib/python3.10/site-packages/pyarrow/tests/__pycache__/test_array.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
parrot/lib/libreadline.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0b6a9d66a73115c872272bb479c8f29df1bf7d9b16e5913e083d64b7753ce1c6
|
| 3 |
+
size 411464
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/acero/hash_join.h
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <functional>
|
| 21 |
+
#include <memory>
|
| 22 |
+
#include <vector>
|
| 23 |
+
|
| 24 |
+
#include "arrow/acero/accumulation_queue.h"
|
| 25 |
+
#include "arrow/acero/bloom_filter.h"
|
| 26 |
+
#include "arrow/acero/options.h"
|
| 27 |
+
#include "arrow/acero/query_context.h"
|
| 28 |
+
#include "arrow/acero/schema_util.h"
|
| 29 |
+
#include "arrow/acero/task_util.h"
|
| 30 |
+
#include "arrow/result.h"
|
| 31 |
+
#include "arrow/status.h"
|
| 32 |
+
#include "arrow/type.h"
|
| 33 |
+
#include "arrow/util/tracing.h"
|
| 34 |
+
|
| 35 |
+
namespace arrow {
|
| 36 |
+
namespace acero {
|
| 37 |
+
|
| 38 |
+
using util::AccumulationQueue;
|
| 39 |
+
|
| 40 |
+
class HashJoinImpl {
|
| 41 |
+
public:
|
| 42 |
+
using OutputBatchCallback = std::function<Status(int64_t, ExecBatch)>;
|
| 43 |
+
using BuildFinishedCallback = std::function<Status(size_t)>;
|
| 44 |
+
using FinishedCallback = std::function<Status(int64_t)>;
|
| 45 |
+
using RegisterTaskGroupCallback = std::function<int(
|
| 46 |
+
std::function<Status(size_t, int64_t)>, std::function<Status(size_t)>)>;
|
| 47 |
+
using StartTaskGroupCallback = std::function<Status(int, int64_t)>;
|
| 48 |
+
using AbortContinuationImpl = std::function<void()>;
|
| 49 |
+
|
| 50 |
+
virtual ~HashJoinImpl() = default;
|
| 51 |
+
virtual Status Init(QueryContext* ctx, JoinType join_type, size_t num_threads,
|
| 52 |
+
const HashJoinProjectionMaps* proj_map_left,
|
| 53 |
+
const HashJoinProjectionMaps* proj_map_right,
|
| 54 |
+
std::vector<JoinKeyCmp> key_cmp, Expression filter,
|
| 55 |
+
RegisterTaskGroupCallback register_task_group_callback,
|
| 56 |
+
StartTaskGroupCallback start_task_group_callback,
|
| 57 |
+
OutputBatchCallback output_batch_callback,
|
| 58 |
+
FinishedCallback finished_callback) = 0;
|
| 59 |
+
|
| 60 |
+
virtual Status BuildHashTable(size_t thread_index, AccumulationQueue batches,
|
| 61 |
+
BuildFinishedCallback on_finished) = 0;
|
| 62 |
+
virtual Status ProbeSingleBatch(size_t thread_index, ExecBatch batch) = 0;
|
| 63 |
+
virtual Status ProbingFinished(size_t thread_index) = 0;
|
| 64 |
+
virtual void Abort(TaskScheduler::AbortContinuationImpl pos_abort_callback) = 0;
|
| 65 |
+
virtual std::string ToString() const = 0;
|
| 66 |
+
|
| 67 |
+
static Result<std::unique_ptr<HashJoinImpl>> MakeBasic();
|
| 68 |
+
static Result<std::unique_ptr<HashJoinImpl>> MakeSwiss();
|
| 69 |
+
|
| 70 |
+
protected:
|
| 71 |
+
arrow::util::tracing::Span span_;
|
| 72 |
+
};
|
| 73 |
+
|
| 74 |
+
} // namespace acero
|
| 75 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/adapters/orc/adapter.h
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <cstdint>
|
| 21 |
+
#include <memory>
|
| 22 |
+
#include <vector>
|
| 23 |
+
|
| 24 |
+
#include "arrow/adapters/orc/options.h"
|
| 25 |
+
#include "arrow/io/interfaces.h"
|
| 26 |
+
#include "arrow/memory_pool.h"
|
| 27 |
+
#include "arrow/record_batch.h"
|
| 28 |
+
#include "arrow/status.h"
|
| 29 |
+
#include "arrow/type.h"
|
| 30 |
+
#include "arrow/type_fwd.h"
|
| 31 |
+
#include "arrow/util/macros.h"
|
| 32 |
+
#include "arrow/util/visibility.h"
|
| 33 |
+
|
| 34 |
+
namespace arrow {
|
| 35 |
+
namespace adapters {
|
| 36 |
+
namespace orc {
|
| 37 |
+
|
| 38 |
+
/// \brief Information about an ORC stripe
|
| 39 |
+
struct StripeInformation {
|
| 40 |
+
/// \brief Offset of the stripe from the start of the file, in bytes
|
| 41 |
+
int64_t offset;
|
| 42 |
+
/// \brief Length of the stripe, in bytes
|
| 43 |
+
int64_t length;
|
| 44 |
+
/// \brief Number of rows in the stripe
|
| 45 |
+
int64_t num_rows;
|
| 46 |
+
/// \brief Index of the first row of the stripe
|
| 47 |
+
int64_t first_row_id;
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
/// \class ORCFileReader
|
| 51 |
+
/// \brief Read an Arrow Table or RecordBatch from an ORC file.
|
| 52 |
+
class ARROW_EXPORT ORCFileReader {
|
| 53 |
+
public:
|
| 54 |
+
~ORCFileReader();
|
| 55 |
+
|
| 56 |
+
/// \brief Creates a new ORC reader
|
| 57 |
+
///
|
| 58 |
+
/// \param[in] file the data source
|
| 59 |
+
/// \param[in] pool a MemoryPool to use for buffer allocations
|
| 60 |
+
/// \return the returned reader object
|
| 61 |
+
static Result<std::unique_ptr<ORCFileReader>> Open(
|
| 62 |
+
const std::shared_ptr<io::RandomAccessFile>& file, MemoryPool* pool);
|
| 63 |
+
|
| 64 |
+
/// \brief Return the schema read from the ORC file
|
| 65 |
+
///
|
| 66 |
+
/// \return the returned Schema object
|
| 67 |
+
Result<std::shared_ptr<Schema>> ReadSchema();
|
| 68 |
+
|
| 69 |
+
/// \brief Read the file as a Table
|
| 70 |
+
///
|
| 71 |
+
/// The table will be composed of one record batch per stripe.
|
| 72 |
+
///
|
| 73 |
+
/// \return the returned Table
|
| 74 |
+
Result<std::shared_ptr<Table>> Read();
|
| 75 |
+
|
| 76 |
+
/// \brief Read the file as a Table
|
| 77 |
+
///
|
| 78 |
+
/// The table will be composed of one record batch per stripe.
|
| 79 |
+
///
|
| 80 |
+
/// \param[in] schema the Table schema
|
| 81 |
+
/// \return the returned Table
|
| 82 |
+
Result<std::shared_ptr<Table>> Read(const std::shared_ptr<Schema>& schema);
|
| 83 |
+
|
| 84 |
+
/// \brief Read the file as a Table
|
| 85 |
+
///
|
| 86 |
+
/// The table will be composed of one record batch per stripe.
|
| 87 |
+
///
|
| 88 |
+
/// \param[in] include_indices the selected field indices to read
|
| 89 |
+
/// \return the returned Table
|
| 90 |
+
Result<std::shared_ptr<Table>> Read(const std::vector<int>& include_indices);
|
| 91 |
+
|
| 92 |
+
/// \brief Read the file as a Table
|
| 93 |
+
///
|
| 94 |
+
/// The table will be composed of one record batch per stripe.
|
| 95 |
+
///
|
| 96 |
+
/// \param[in] include_names the selected field names to read
|
| 97 |
+
/// \return the returned Table
|
| 98 |
+
Result<std::shared_ptr<Table>> Read(const std::vector<std::string>& include_names);
|
| 99 |
+
|
| 100 |
+
/// \brief Read the file as a Table
|
| 101 |
+
///
|
| 102 |
+
/// The table will be composed of one record batch per stripe.
|
| 103 |
+
///
|
| 104 |
+
/// \param[in] schema the Table schema
|
| 105 |
+
/// \param[in] include_indices the selected field indices to read
|
| 106 |
+
/// \return the returned Table
|
| 107 |
+
Result<std::shared_ptr<Table>> Read(const std::shared_ptr<Schema>& schema,
|
| 108 |
+
const std::vector<int>& include_indices);
|
| 109 |
+
|
| 110 |
+
/// \brief Read a single stripe as a RecordBatch
|
| 111 |
+
///
|
| 112 |
+
/// \param[in] stripe the stripe index
|
| 113 |
+
/// \return the returned RecordBatch
|
| 114 |
+
Result<std::shared_ptr<RecordBatch>> ReadStripe(int64_t stripe);
|
| 115 |
+
|
| 116 |
+
/// \brief Read a single stripe as a RecordBatch
|
| 117 |
+
///
|
| 118 |
+
/// \param[in] stripe the stripe index
|
| 119 |
+
/// \param[in] include_indices the selected field indices to read
|
| 120 |
+
/// \return the returned RecordBatch
|
| 121 |
+
Result<std::shared_ptr<RecordBatch>> ReadStripe(
|
| 122 |
+
int64_t stripe, const std::vector<int>& include_indices);
|
| 123 |
+
|
| 124 |
+
/// \brief Read a single stripe as a RecordBatch
|
| 125 |
+
///
|
| 126 |
+
/// \param[in] stripe the stripe index
|
| 127 |
+
/// \param[in] include_names the selected field names to read
|
| 128 |
+
/// \return the returned RecordBatch
|
| 129 |
+
Result<std::shared_ptr<RecordBatch>> ReadStripe(
|
| 130 |
+
int64_t stripe, const std::vector<std::string>& include_names);
|
| 131 |
+
|
| 132 |
+
/// \brief Seek to designated row. Invoke NextStripeReader() after seek
|
| 133 |
+
/// will return stripe reader starting from designated row.
|
| 134 |
+
///
|
| 135 |
+
/// \param[in] row_number the rows number to seek
|
| 136 |
+
Status Seek(int64_t row_number);
|
| 137 |
+
|
| 138 |
+
/// \brief Get a stripe level record batch iterator.
|
| 139 |
+
///
|
| 140 |
+
/// Each record batch will have up to `batch_size` rows.
|
| 141 |
+
/// NextStripeReader serves as a fine-grained alternative to ReadStripe
|
| 142 |
+
/// which may cause OOM issues by loading the whole stripe into memory.
|
| 143 |
+
///
|
| 144 |
+
/// Note this will only read rows for the current stripe, not the entire
|
| 145 |
+
/// file.
|
| 146 |
+
///
|
| 147 |
+
/// \param[in] batch_size the maximum number of rows in each record batch
|
| 148 |
+
/// \return the returned stripe reader
|
| 149 |
+
Result<std::shared_ptr<RecordBatchReader>> NextStripeReader(int64_t batch_size);
|
| 150 |
+
|
| 151 |
+
/// \brief Get a stripe level record batch iterator.
|
| 152 |
+
///
|
| 153 |
+
/// Each record batch will have up to `batch_size` rows.
|
| 154 |
+
/// NextStripeReader serves as a fine-grained alternative to ReadStripe
|
| 155 |
+
/// which may cause OOM issues by loading the whole stripe into memory.
|
| 156 |
+
///
|
| 157 |
+
/// Note this will only read rows for the current stripe, not the entire
|
| 158 |
+
/// file.
|
| 159 |
+
///
|
| 160 |
+
/// \param[in] batch_size the maximum number of rows in each record batch
|
| 161 |
+
/// \param[in] include_indices the selected field indices to read
|
| 162 |
+
/// \return the stripe reader
|
| 163 |
+
Result<std::shared_ptr<RecordBatchReader>> NextStripeReader(
|
| 164 |
+
int64_t batch_size, const std::vector<int>& include_indices);
|
| 165 |
+
|
| 166 |
+
/// \brief Get a record batch iterator for the entire file.
|
| 167 |
+
///
|
| 168 |
+
/// Each record batch will have up to `batch_size` rows.
|
| 169 |
+
///
|
| 170 |
+
/// \param[in] batch_size the maximum number of rows in each record batch
|
| 171 |
+
/// \param[in] include_names the selected field names to read, if not empty
|
| 172 |
+
/// (otherwise all fields are read)
|
| 173 |
+
/// \return the record batch iterator
|
| 174 |
+
Result<std::shared_ptr<RecordBatchReader>> GetRecordBatchReader(
|
| 175 |
+
int64_t batch_size, const std::vector<std::string>& include_names);
|
| 176 |
+
|
| 177 |
+
/// \brief The number of stripes in the file
|
| 178 |
+
int64_t NumberOfStripes();
|
| 179 |
+
|
| 180 |
+
/// \brief The number of rows in the file
|
| 181 |
+
int64_t NumberOfRows();
|
| 182 |
+
|
| 183 |
+
/// \brief StripeInformation for each stripe.
|
| 184 |
+
StripeInformation GetStripeInformation(int64_t stripe);
|
| 185 |
+
|
| 186 |
+
/// \brief Get the format version of the file.
|
| 187 |
+
/// Currently known values are 0.11 and 0.12.
|
| 188 |
+
///
|
| 189 |
+
/// \return The FileVersion of the ORC file.
|
| 190 |
+
FileVersion GetFileVersion();
|
| 191 |
+
|
| 192 |
+
/// \brief Get the software instance and version that wrote this file.
|
| 193 |
+
///
|
| 194 |
+
/// \return a user-facing string that specifies the software version
|
| 195 |
+
std::string GetSoftwareVersion();
|
| 196 |
+
|
| 197 |
+
/// \brief Get the compression kind of the file.
|
| 198 |
+
///
|
| 199 |
+
/// \return The kind of compression in the ORC file.
|
| 200 |
+
Result<Compression::type> GetCompression();
|
| 201 |
+
|
| 202 |
+
/// \brief Get the buffer size for the compression.
|
| 203 |
+
///
|
| 204 |
+
/// \return Number of bytes to buffer for the compression codec.
|
| 205 |
+
int64_t GetCompressionSize();
|
| 206 |
+
|
| 207 |
+
/// \brief Get the number of rows per an entry in the row index.
|
| 208 |
+
/// \return the number of rows per an entry in the row index or 0 if there
|
| 209 |
+
/// is no row index.
|
| 210 |
+
int64_t GetRowIndexStride();
|
| 211 |
+
|
| 212 |
+
/// \brief Get ID of writer that generated the file.
|
| 213 |
+
///
|
| 214 |
+
/// \return UNKNOWN_WRITER if the writer ID is undefined
|
| 215 |
+
WriterId GetWriterId();
|
| 216 |
+
|
| 217 |
+
/// \brief Get the writer id value when getWriterId() returns an unknown writer.
|
| 218 |
+
///
|
| 219 |
+
/// \return the integer value of the writer ID.
|
| 220 |
+
int32_t GetWriterIdValue();
|
| 221 |
+
|
| 222 |
+
/// \brief Get the version of the writer.
|
| 223 |
+
///
|
| 224 |
+
/// \return the version of the writer.
|
| 225 |
+
|
| 226 |
+
WriterVersion GetWriterVersion();
|
| 227 |
+
|
| 228 |
+
/// \brief Get the number of stripe statistics in the file.
|
| 229 |
+
///
|
| 230 |
+
/// \return the number of stripe statistics
|
| 231 |
+
int64_t GetNumberOfStripeStatistics();
|
| 232 |
+
|
| 233 |
+
/// \brief Get the length of the data stripes in the file.
|
| 234 |
+
///
|
| 235 |
+
/// \return return the number of bytes in stripes
|
| 236 |
+
int64_t GetContentLength();
|
| 237 |
+
|
| 238 |
+
/// \brief Get the length of the file stripe statistics.
|
| 239 |
+
///
|
| 240 |
+
/// \return the number of compressed bytes in the file stripe statistics
|
| 241 |
+
int64_t GetStripeStatisticsLength();
|
| 242 |
+
|
| 243 |
+
/// \brief Get the length of the file footer.
|
| 244 |
+
///
|
| 245 |
+
/// \return the number of compressed bytes in the file footer
|
| 246 |
+
int64_t GetFileFooterLength();
|
| 247 |
+
|
| 248 |
+
/// \brief Get the length of the file postscript.
|
| 249 |
+
///
|
| 250 |
+
/// \return the number of bytes in the file postscript
|
| 251 |
+
int64_t GetFilePostscriptLength();
|
| 252 |
+
|
| 253 |
+
/// \brief Get the total length of the file.
|
| 254 |
+
///
|
| 255 |
+
/// \return the number of bytes in the file
|
| 256 |
+
int64_t GetFileLength();
|
| 257 |
+
|
| 258 |
+
/// \brief Get the serialized file tail.
|
| 259 |
+
/// Useful if another reader of the same file wants to avoid re-reading
|
| 260 |
+
/// the file tail. See ReadOptions.SetSerializedFileTail().
|
| 261 |
+
///
|
| 262 |
+
/// \return a string of bytes with the file tail
|
| 263 |
+
std::string GetSerializedFileTail();
|
| 264 |
+
|
| 265 |
+
/// \brief Return the metadata read from the ORC file
|
| 266 |
+
///
|
| 267 |
+
/// \return A KeyValueMetadata object containing the ORC metadata
|
| 268 |
+
Result<std::shared_ptr<const KeyValueMetadata>> ReadMetadata();
|
| 269 |
+
|
| 270 |
+
private:
|
| 271 |
+
class Impl;
|
| 272 |
+
std::unique_ptr<Impl> impl_;
|
| 273 |
+
ORCFileReader();
|
| 274 |
+
};
|
| 275 |
+
|
| 276 |
+
/// \class ORCFileWriter
|
| 277 |
+
/// \brief Write an Arrow Table or RecordBatch to an ORC file.
|
| 278 |
+
class ARROW_EXPORT ORCFileWriter {
|
| 279 |
+
public:
|
| 280 |
+
~ORCFileWriter();
|
| 281 |
+
/// \brief Creates a new ORC writer.
|
| 282 |
+
///
|
| 283 |
+
/// \param[in] output_stream a pointer to the io::OutputStream to write into
|
| 284 |
+
/// \param[in] write_options the ORC writer options for Arrow
|
| 285 |
+
/// \return the returned writer object
|
| 286 |
+
static Result<std::unique_ptr<ORCFileWriter>> Open(
|
| 287 |
+
io::OutputStream* output_stream,
|
| 288 |
+
const WriteOptions& write_options = WriteOptions());
|
| 289 |
+
|
| 290 |
+
/// \brief Write a table. This can be called multiple times.
|
| 291 |
+
///
|
| 292 |
+
/// Tables passed in subsequent calls must match the schema of the table that was
|
| 293 |
+
/// written first.
|
| 294 |
+
///
|
| 295 |
+
/// \param[in] table the Arrow table from which data is extracted.
|
| 296 |
+
/// \return Status
|
| 297 |
+
Status Write(const Table& table);
|
| 298 |
+
|
| 299 |
+
/// \brief Write a RecordBatch. This can be called multiple times.
|
| 300 |
+
///
|
| 301 |
+
/// RecordBatches passed in subsequent calls must match the schema of the
|
| 302 |
+
/// RecordBatch that was written first.
|
| 303 |
+
///
|
| 304 |
+
/// \param[in] record_batch the Arrow RecordBatch from which data is extracted.
|
| 305 |
+
/// \return Status
|
| 306 |
+
Status Write(const RecordBatch& record_batch);
|
| 307 |
+
|
| 308 |
+
/// \brief Close an ORC writer (orc::Writer)
|
| 309 |
+
///
|
| 310 |
+
/// \return Status
|
| 311 |
+
Status Close();
|
| 312 |
+
|
| 313 |
+
private:
|
| 314 |
+
class Impl;
|
| 315 |
+
std::unique_ptr<Impl> impl_;
|
| 316 |
+
|
| 317 |
+
private:
|
| 318 |
+
ORCFileWriter();
|
| 319 |
+
};
|
| 320 |
+
|
| 321 |
+
} // namespace orc
|
| 322 |
+
} // namespace adapters
|
| 323 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/array_dict.h
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <cstdint>
|
| 21 |
+
#include <memory>
|
| 22 |
+
|
| 23 |
+
#include "arrow/array/array_base.h"
|
| 24 |
+
#include "arrow/array/data.h"
|
| 25 |
+
#include "arrow/result.h"
|
| 26 |
+
#include "arrow/status.h"
|
| 27 |
+
#include "arrow/type.h"
|
| 28 |
+
#include "arrow/util/macros.h"
|
| 29 |
+
#include "arrow/util/visibility.h"
|
| 30 |
+
|
| 31 |
+
namespace arrow {
|
| 32 |
+
|
| 33 |
+
// ----------------------------------------------------------------------
|
| 34 |
+
// DictionaryArray
|
| 35 |
+
|
| 36 |
+
/// \brief Array type for dictionary-encoded data with a
|
| 37 |
+
/// data-dependent dictionary
|
| 38 |
+
///
|
| 39 |
+
/// A dictionary array contains an array of non-negative integers (the
|
| 40 |
+
/// "dictionary indices") along with a data type containing a "dictionary"
|
| 41 |
+
/// corresponding to the distinct values represented in the data.
|
| 42 |
+
///
|
| 43 |
+
/// For example, the array
|
| 44 |
+
///
|
| 45 |
+
/// ["foo", "bar", "foo", "bar", "foo", "bar"]
|
| 46 |
+
///
|
| 47 |
+
/// with dictionary ["bar", "foo"], would have dictionary array representation
|
| 48 |
+
///
|
| 49 |
+
/// indices: [1, 0, 1, 0, 1, 0]
|
| 50 |
+
/// dictionary: ["bar", "foo"]
|
| 51 |
+
///
|
| 52 |
+
/// The indices in principle may be any integer type.
|
| 53 |
+
class ARROW_EXPORT DictionaryArray : public Array {
|
| 54 |
+
public:
|
| 55 |
+
using TypeClass = DictionaryType;
|
| 56 |
+
|
| 57 |
+
explicit DictionaryArray(const std::shared_ptr<ArrayData>& data);
|
| 58 |
+
|
| 59 |
+
DictionaryArray(const std::shared_ptr<DataType>& type,
|
| 60 |
+
const std::shared_ptr<Array>& indices,
|
| 61 |
+
const std::shared_ptr<Array>& dictionary);
|
| 62 |
+
|
| 63 |
+
/// \brief Construct DictionaryArray from dictionary and indices
|
| 64 |
+
/// array and validate
|
| 65 |
+
///
|
| 66 |
+
/// This function does the validation of the indices and input type. It checks if
|
| 67 |
+
/// all indices are non-negative and smaller than the size of the dictionary.
|
| 68 |
+
///
|
| 69 |
+
/// \param[in] type a dictionary type
|
| 70 |
+
/// \param[in] dictionary the dictionary with same value type as the
|
| 71 |
+
/// type object
|
| 72 |
+
/// \param[in] indices an array of non-negative integers smaller than the
|
| 73 |
+
/// size of the dictionary
|
| 74 |
+
static Result<std::shared_ptr<Array>> FromArrays(
|
| 75 |
+
const std::shared_ptr<DataType>& type, const std::shared_ptr<Array>& indices,
|
| 76 |
+
const std::shared_ptr<Array>& dictionary);
|
| 77 |
+
|
| 78 |
+
static Result<std::shared_ptr<Array>> FromArrays(
|
| 79 |
+
const std::shared_ptr<Array>& indices, const std::shared_ptr<Array>& dictionary) {
|
| 80 |
+
return FromArrays(::arrow::dictionary(indices->type(), dictionary->type()), indices,
|
| 81 |
+
dictionary);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/// \brief Transpose this DictionaryArray
|
| 85 |
+
///
|
| 86 |
+
/// This method constructs a new dictionary array with the given dictionary
|
| 87 |
+
/// type, transposing indices using the transpose map. The type and the
|
| 88 |
+
/// transpose map are typically computed using DictionaryUnifier.
|
| 89 |
+
///
|
| 90 |
+
/// \param[in] type the new type object
|
| 91 |
+
/// \param[in] dictionary the new dictionary
|
| 92 |
+
/// \param[in] transpose_map transposition array of this array's indices
|
| 93 |
+
/// into the target array's indices
|
| 94 |
+
/// \param[in] pool a pool to allocate the array data from
|
| 95 |
+
Result<std::shared_ptr<Array>> Transpose(
|
| 96 |
+
const std::shared_ptr<DataType>& type, const std::shared_ptr<Array>& dictionary,
|
| 97 |
+
const int32_t* transpose_map, MemoryPool* pool = default_memory_pool()) const;
|
| 98 |
+
|
| 99 |
+
Result<std::shared_ptr<Array>> Compact(MemoryPool* pool = default_memory_pool()) const;
|
| 100 |
+
|
| 101 |
+
/// \brief Determine whether dictionary arrays may be compared without unification
|
| 102 |
+
bool CanCompareIndices(const DictionaryArray& other) const;
|
| 103 |
+
|
| 104 |
+
/// \brief Return the dictionary for this array, which is stored as
|
| 105 |
+
/// a member of the ArrayData internal structure
|
| 106 |
+
const std::shared_ptr<Array>& dictionary() const;
|
| 107 |
+
const std::shared_ptr<Array>& indices() const;
|
| 108 |
+
|
| 109 |
+
/// \brief Return the ith value of indices, cast to int64_t. Not recommended
|
| 110 |
+
/// for use in performance-sensitive code. Does not validate whether the
|
| 111 |
+
/// value is null or out-of-bounds.
|
| 112 |
+
int64_t GetValueIndex(int64_t i) const;
|
| 113 |
+
|
| 114 |
+
const DictionaryType* dict_type() const { return dict_type_; }
|
| 115 |
+
|
| 116 |
+
private:
|
| 117 |
+
void SetData(const std::shared_ptr<ArrayData>& data);
|
| 118 |
+
const DictionaryType* dict_type_;
|
| 119 |
+
std::shared_ptr<Array> indices_;
|
| 120 |
+
|
| 121 |
+
// Lazily initialized when invoking dictionary()
|
| 122 |
+
mutable std::shared_ptr<Array> dictionary_;
|
| 123 |
+
};
|
| 124 |
+
|
| 125 |
+
/// \brief Helper class for incremental dictionary unification
|
| 126 |
+
class ARROW_EXPORT DictionaryUnifier {
|
| 127 |
+
public:
|
| 128 |
+
virtual ~DictionaryUnifier() = default;
|
| 129 |
+
|
| 130 |
+
/// \brief Construct a DictionaryUnifier
|
| 131 |
+
/// \param[in] value_type the data type of the dictionaries
|
| 132 |
+
/// \param[in] pool MemoryPool to use for memory allocations
|
| 133 |
+
static Result<std::unique_ptr<DictionaryUnifier>> Make(
|
| 134 |
+
std::shared_ptr<DataType> value_type, MemoryPool* pool = default_memory_pool());
|
| 135 |
+
|
| 136 |
+
/// \brief Unify dictionaries across array chunks
|
| 137 |
+
///
|
| 138 |
+
/// The dictionaries in the array chunks will be unified, their indices
|
| 139 |
+
/// accordingly transposed.
|
| 140 |
+
///
|
| 141 |
+
/// Only dictionaries with a primitive value type are currently supported.
|
| 142 |
+
/// However, dictionaries nested inside a more complex type are correctly unified.
|
| 143 |
+
static Result<std::shared_ptr<ChunkedArray>> UnifyChunkedArray(
|
| 144 |
+
const std::shared_ptr<ChunkedArray>& array,
|
| 145 |
+
MemoryPool* pool = default_memory_pool());
|
| 146 |
+
|
| 147 |
+
/// \brief Unify dictionaries across the chunks of each table column
|
| 148 |
+
///
|
| 149 |
+
/// The dictionaries in each table column will be unified, their indices
|
| 150 |
+
/// accordingly transposed.
|
| 151 |
+
///
|
| 152 |
+
/// Only dictionaries with a primitive value type are currently supported.
|
| 153 |
+
/// However, dictionaries nested inside a more complex type are correctly unified.
|
| 154 |
+
static Result<std::shared_ptr<Table>> UnifyTable(
|
| 155 |
+
const Table& table, MemoryPool* pool = default_memory_pool());
|
| 156 |
+
|
| 157 |
+
/// \brief Append dictionary to the internal memo
|
| 158 |
+
virtual Status Unify(const Array& dictionary) = 0;
|
| 159 |
+
|
| 160 |
+
/// \brief Append dictionary and compute transpose indices
|
| 161 |
+
/// \param[in] dictionary the dictionary values to unify
|
| 162 |
+
/// \param[out] out_transpose a Buffer containing computed transpose indices
|
| 163 |
+
/// as int32_t values equal in length to the passed dictionary. The value in
|
| 164 |
+
/// each slot corresponds to the new index value for each original index
|
| 165 |
+
/// for a DictionaryArray with the old dictionary
|
| 166 |
+
virtual Status Unify(const Array& dictionary,
|
| 167 |
+
std::shared_ptr<Buffer>* out_transpose) = 0;
|
| 168 |
+
|
| 169 |
+
/// \brief Return a result DictionaryType with the smallest possible index
|
| 170 |
+
/// type to accommodate the unified dictionary. The unifier cannot be used
|
| 171 |
+
/// after this is called
|
| 172 |
+
virtual Status GetResult(std::shared_ptr<DataType>* out_type,
|
| 173 |
+
std::shared_ptr<Array>* out_dict) = 0;
|
| 174 |
+
|
| 175 |
+
/// \brief Return a unified dictionary with the given index type. If
|
| 176 |
+
/// the index type is not large enough then an invalid status will be returned.
|
| 177 |
+
/// The unifier cannot be used after this is called
|
| 178 |
+
virtual Status GetResultWithIndexType(const std::shared_ptr<DataType>& index_type,
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
// Array accessor classes for List, LargeList, ListView, LargeListView, FixedSizeList,
|
| 19 |
+
// Map, Struct, and Union
|
| 20 |
+
|
| 21 |
+
#pragma once
|
| 22 |
+
|
| 23 |
+
#include <cstdint>
|
| 24 |
+
#include <memory>
|
| 25 |
+
#include <string>
|
| 26 |
+
#include <utility>
|
| 27 |
+
#include <vector>
|
| 28 |
+
|
| 29 |
+
#include "arrow/array/array_base.h"
|
| 30 |
+
#include "arrow/array/data.h"
|
| 31 |
+
#include "arrow/result.h"
|
| 32 |
+
#include "arrow/status.h"
|
| 33 |
+
#include "arrow/type.h"
|
| 34 |
+
#include "arrow/type_fwd.h"
|
| 35 |
+
#include "arrow/util/checked_cast.h"
|
| 36 |
+
#include "arrow/util/macros.h"
|
| 37 |
+
#include "arrow/util/visibility.h"
|
| 38 |
+
|
| 39 |
+
namespace arrow {
|
| 40 |
+
|
| 41 |
+
/// \addtogroup nested-arrays
|
| 42 |
+
///
|
| 43 |
+
/// @{
|
| 44 |
+
|
| 45 |
+
// ----------------------------------------------------------------------
|
| 46 |
+
// VarLengthListLikeArray
|
| 47 |
+
|
| 48 |
+
template <typename TYPE>
|
| 49 |
+
class VarLengthListLikeArray;
|
| 50 |
+
|
| 51 |
+
namespace internal {
|
| 52 |
+
|
| 53 |
+
// Private helper for [Large]List[View]Array::SetData.
|
| 54 |
+
// Unfortunately, trying to define VarLengthListLikeArray::SetData outside of this header
|
| 55 |
+
// doesn't play well with MSVC.
|
| 56 |
+
template <typename TYPE>
|
| 57 |
+
void SetListData(VarLengthListLikeArray<TYPE>* self,
|
| 58 |
+
const std::shared_ptr<ArrayData>& data,
|
| 59 |
+
Type::type expected_type_id = TYPE::type_id);
|
| 60 |
+
|
| 61 |
+
/// \brief A version of Flatten that keeps recursively flattening until an array of
|
| 62 |
+
/// non-list values is reached.
|
| 63 |
+
///
|
| 64 |
+
/// Array types considered to be lists by this function:
|
| 65 |
+
/// - list
|
| 66 |
+
/// - large_list
|
| 67 |
+
/// - list_view
|
| 68 |
+
/// - large_list_view
|
| 69 |
+
/// - fixed_size_list
|
| 70 |
+
///
|
| 71 |
+
/// \see ListArray::Flatten
|
| 72 |
+
ARROW_EXPORT Result<std::shared_ptr<Array>> FlattenLogicalListRecursively(
|
| 73 |
+
const Array& in_array, MemoryPool* memory_pool);
|
| 74 |
+
|
| 75 |
+
} // namespace internal
|
| 76 |
+
|
| 77 |
+
/// Base class for variable-sized list and list-view arrays, regardless of offset size.
|
| 78 |
+
template <typename TYPE>
|
| 79 |
+
class VarLengthListLikeArray : public Array {
|
| 80 |
+
public:
|
| 81 |
+
using TypeClass = TYPE;
|
| 82 |
+
using offset_type = typename TypeClass::offset_type;
|
| 83 |
+
|
| 84 |
+
const TypeClass* var_length_list_like_type() const { return this->list_type_; }
|
| 85 |
+
|
| 86 |
+
/// \brief Return array object containing the list's values
|
| 87 |
+
///
|
| 88 |
+
/// Note that this buffer does not account for any slice offset or length.
|
| 89 |
+
const std::shared_ptr<Array>& values() const { return values_; }
|
| 90 |
+
|
| 91 |
+
/// Note that this buffer does not account for any slice offset or length.
|
| 92 |
+
const std::shared_ptr<Buffer>& value_offsets() const { return data_->buffers[1]; }
|
| 93 |
+
|
| 94 |
+
const std::shared_ptr<DataType>& value_type() const { return list_type_->value_type(); }
|
| 95 |
+
|
| 96 |
+
/// Return pointer to raw value offsets accounting for any slice offset
|
| 97 |
+
const offset_type* raw_value_offsets() const {
|
| 98 |
+
return raw_value_offsets_ + data_->offset;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
// The following functions will not perform boundschecking
|
| 102 |
+
|
| 103 |
+
offset_type value_offset(int64_t i) const {
|
| 104 |
+
return raw_value_offsets_[i + data_->offset];
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/// \brief Return the size of the value at a particular index
|
| 108 |
+
///
|
| 109 |
+
/// Since non-empty null lists and list-views are possible, avoid calling this
|
| 110 |
+
/// function when the list at slot i is null.
|
| 111 |
+
///
|
| 112 |
+
/// \pre IsValid(i)
|
| 113 |
+
virtual offset_type value_length(int64_t i) const = 0;
|
| 114 |
+
|
| 115 |
+
/// \pre IsValid(i)
|
| 116 |
+
std::shared_ptr<Array> value_slice(int64_t i) const {
|
| 117 |
+
return values_->Slice(value_offset(i), value_length(i));
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/// \brief Flatten all level recursively until reach a non-list type, and return
|
| 121 |
+
/// a non-list type Array.
|
| 122 |
+
///
|
| 123 |
+
/// \see internal::FlattenLogicalListRecursively
|
| 124 |
+
Result<std::shared_ptr<Array>> FlattenRecursively(
|
| 125 |
+
MemoryPool* memory_pool = default_memory_pool()) const {
|
| 126 |
+
return internal::FlattenLogicalListRecursively(*this, memory_pool);
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
protected:
|
| 130 |
+
friend void internal::SetListData<TYPE>(VarLengthListLikeArray<TYPE>* self,
|
| 131 |
+
const std::shared_ptr<ArrayData>& data,
|
| 132 |
+
Type::type expected_type_id);
|
| 133 |
+
|
| 134 |
+
const TypeClass* list_type_ = NULLPTR;
|
| 135 |
+
std::shared_ptr<Array> values_;
|
| 136 |
+
const offset_type* raw_value_offsets_ = NULLPTR;
|
| 137 |
+
};
|
| 138 |
+
|
| 139 |
+
// ----------------------------------------------------------------------
|
| 140 |
+
// ListArray / LargeListArray
|
| 141 |
+
|
| 142 |
+
template <typename TYPE>
|
| 143 |
+
class BaseListArray : public VarLengthListLikeArray<TYPE> {
|
| 144 |
+
public:
|
| 145 |
+
using TypeClass = TYPE;
|
| 146 |
+
using offset_type = typename TYPE::offset_type;
|
| 147 |
+
|
| 148 |
+
const TypeClass* list_type() const { return this->var_length_list_like_type(); }
|
| 149 |
+
|
| 150 |
+
/// \brief Return the size of the value at a particular index
|
| 151 |
+
///
|
| 152 |
+
/// Since non-empty null lists are possible, avoid calling this
|
| 153 |
+
/// function when the list at slot i is null.
|
| 154 |
+
///
|
| 155 |
+
/// \pre IsValid(i)
|
| 156 |
+
offset_type value_length(int64_t i) const final {
|
| 157 |
+
i += this->data_->offset;
|
| 158 |
+
return this->raw_value_offsets_[i + 1] - this->raw_value_offsets_[i];
|
| 159 |
+
}
|
| 160 |
+
};
|
| 161 |
+
|
| 162 |
+
/// Concrete Array class for list data
|
| 163 |
+
class ARROW_EXPORT ListArray : public BaseListArray<ListType> {
|
| 164 |
+
public:
|
| 165 |
+
explicit ListArray(std::shared_ptr<ArrayData> data);
|
| 166 |
+
|
| 167 |
+
ListArray(std::shared_ptr<DataType> type, int64_t length,
|
| 168 |
+
std::shared_ptr<Buffer> value_offsets, std::shared_ptr<Array> values,
|
| 169 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR,
|
| 170 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0);
|
| 171 |
+
|
| 172 |
+
/// \brief Construct ListArray from array of offsets and child value array
|
| 173 |
+
///
|
| 174 |
+
/// This function does the bare minimum of validation of the offsets and
|
| 175 |
+
/// input types, and will allocate a new offsets array if necessary (i.e. if
|
| 176 |
+
/// the offsets contain any nulls). If the offsets do not have nulls, they
|
| 177 |
+
/// are assumed to be well-formed.
|
| 178 |
+
///
|
| 179 |
+
/// If a null_bitmap is not provided, the nulls will be inferred from the offsets'
|
| 180 |
+
/// null bitmap. But if a null_bitmap is provided, the offsets array can't have nulls.
|
| 181 |
+
///
|
| 182 |
+
/// And when a null_bitmap is provided, the offsets array cannot be a slice (i.e. an
|
| 183 |
+
/// array with offset() > 0).
|
| 184 |
+
///
|
| 185 |
+
/// \param[in] offsets Array containing n + 1 offsets encoding length and
|
| 186 |
+
/// size. Must be of int32 type
|
| 187 |
+
/// \param[in] values Array containing list values
|
| 188 |
+
/// \param[in] pool MemoryPool in case new offsets array needs to be
|
| 189 |
+
/// allocated because of null values
|
| 190 |
+
/// \param[in] null_bitmap Optional validity bitmap
|
| 191 |
+
/// \param[in] null_count Optional null count in null_bitmap
|
| 192 |
+
static Result<std::shared_ptr<ListArray>> FromArrays(
|
| 193 |
+
const Array& offsets, const Array& values, MemoryPool* pool = default_memory_pool(),
|
| 194 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR,
|
| 195 |
+
int64_t null_count = kUnknownNullCount);
|
| 196 |
+
|
| 197 |
+
static Result<std::shared_ptr<ListArray>> FromArrays(
|
| 198 |
+
std::shared_ptr<DataType> type, const Array& offsets, const Array& values,
|
| 199 |
+
MemoryPool* pool = default_memory_pool(),
|
| 200 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR,
|
| 201 |
+
int64_t null_count = kUnknownNullCount);
|
| 202 |
+
|
| 203 |
+
/// \brief Build a ListArray from a ListViewArray
|
| 204 |
+
static Result<std::shared_ptr<ListArray>> FromListView(const ListViewArray& source,
|
| 205 |
+
MemoryPool* pool);
|
| 206 |
+
|
| 207 |
+
/// \brief Return an Array that is a concatenation of the lists in this array.
|
| 208 |
+
///
|
| 209 |
+
/// Note that it's different from `values()` in that it takes into
|
| 210 |
+
/// consideration of this array's offsets as well as null elements backed
|
| 211 |
+
/// by non-empty lists (they are skipped, thus copying may be needed).
|
| 212 |
+
Result<std::shared_ptr<Array>> Flatten(
|
| 213 |
+
MemoryPool* memory_pool = default_memory_pool()) const;
|
| 214 |
+
|
| 215 |
+
/// \brief Return list offsets as an Int32Array
|
| 216 |
+
///
|
| 217 |
+
/// The returned array will not have a validity bitmap, so you cannot expect
|
| 218 |
+
/// to pass it to ListArray::FromArrays() and get back the same list array
|
| 219 |
+
/// if the original one has nulls.
|
| 220 |
+
std::shared_ptr<Array> offsets() const;
|
| 221 |
+
|
| 222 |
+
protected:
|
| 223 |
+
// This constructor defers SetData to a derived array class
|
| 224 |
+
ListArray() = default;
|
| 225 |
+
|
| 226 |
+
void SetData(const std::shared_ptr<ArrayData>& data);
|
| 227 |
+
};
|
| 228 |
+
|
| 229 |
+
/// Concrete Array class for large list data (with 64-bit offsets)
|
| 230 |
+
class ARROW_EXPORT LargeListArray : public BaseListArray<LargeListType> {
|
| 231 |
+
public:
|
| 232 |
+
explicit LargeListArray(const std::shared_ptr<ArrayData>& data);
|
| 233 |
+
|
| 234 |
+
LargeListArray(const std::shared_ptr<DataType>& type, int64_t length,
|
| 235 |
+
const std::shared_ptr<Buffer>& value_offsets,
|
| 236 |
+
const std::shared_ptr<Array>& values,
|
| 237 |
+
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
|
| 238 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0);
|
| 239 |
+
|
| 240 |
+
/// \brief Construct LargeListArray from array of offsets and child value array
|
| 241 |
+
///
|
| 242 |
+
/// This function does the bare minimum of validation of the offsets and
|
| 243 |
+
/// input types, and will allocate a new offsets array if necessary (i.e. if
|
| 244 |
+
/// the offsets contain any nulls). If the offsets do not have nulls, they
|
| 245 |
+
/// are assumed to be well-formed.
|
| 246 |
+
///
|
| 247 |
+
/// If a null_bitmap is not provided, the nulls will be inferred from the offsets'
|
| 248 |
+
/// null bitmap. But if a null_bitmap is provided, the offsets array can't have nulls.
|
| 249 |
+
///
|
| 250 |
+
/// And when a null_bitmap is provided, the offsets array cannot be a slice (i.e. an
|
| 251 |
+
/// array with offset() > 0).
|
| 252 |
+
///
|
| 253 |
+
/// \param[in] offsets Array containing n + 1 offsets encoding length and
|
| 254 |
+
/// size. Must be of int64 type
|
| 255 |
+
/// \param[in] values Array containing list values
|
| 256 |
+
/// \param[in] pool MemoryPool in case new offsets array needs to be
|
| 257 |
+
/// allocated because of null values
|
| 258 |
+
/// \param[in] null_bitmap Optional validity bitmap
|
| 259 |
+
/// \param[in] null_count Optional null count in null_bitmap
|
| 260 |
+
static Result<std::shared_ptr<LargeListArray>> FromArrays(
|
| 261 |
+
const Array& offsets, const Array& values, MemoryPool* pool = default_memory_pool(),
|
| 262 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR,
|
| 263 |
+
int64_t null_count = kUnknownNullCount);
|
| 264 |
+
|
| 265 |
+
static Result<std::shared_ptr<LargeListArray>> FromArrays(
|
| 266 |
+
std::shared_ptr<DataType> type, const Array& offsets, const Array& values,
|
| 267 |
+
MemoryPool* pool = default_memory_pool(),
|
| 268 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR,
|
| 269 |
+
int64_t null_count = kUnknownNullCount);
|
| 270 |
+
|
| 271 |
+
/// \brief Build a LargeListArray from a LargeListViewArray
|
| 272 |
+
static Result<std::shared_ptr<LargeListArray>> FromListView(
|
| 273 |
+
const LargeListViewArray& source, MemoryPool* pool);
|
| 274 |
+
|
| 275 |
+
/// \brief Return an Array that is a concatenation of the lists in this array.
|
| 276 |
+
///
|
| 277 |
+
/// Note that it's different from `values()` in that it takes into
|
| 278 |
+
/// consideration of this array's offsets as well as null elements backed
|
| 279 |
+
/// by non-empty lists (they are skipped, thus copying may be needed).
|
| 280 |
+
Result<std::shared_ptr<Array>> Flatten(
|
| 281 |
+
MemoryPool* memory_pool = default_memory_pool()) const;
|
| 282 |
+
|
| 283 |
+
/// \brief Return list offsets as an Int64Array
|
| 284 |
+
std::shared_ptr<Array> offsets() const;
|
| 285 |
+
|
| 286 |
+
protected:
|
| 287 |
+
void SetData(const std::shared_ptr<ArrayData>& data);
|
| 288 |
+
};
|
| 289 |
+
|
| 290 |
+
// ----------------------------------------------------------------------
|
| 291 |
+
// ListViewArray / LargeListViewArray
|
| 292 |
+
|
| 293 |
+
template <typename TYPE>
|
| 294 |
+
class BaseListViewArray : public VarLengthListLikeArray<TYPE> {
|
| 295 |
+
public:
|
| 296 |
+
using TypeClass = TYPE;
|
| 297 |
+
using offset_type = typename TYPE::offset_type;
|
| 298 |
+
|
| 299 |
+
const TypeClass* list_view_type() const { return this->var_length_list_like_type(); }
|
| 300 |
+
|
| 301 |
+
/// \brief Note that this buffer does not account for any slice offset or length.
|
| 302 |
+
const std::shared_ptr<Buffer>& value_sizes() const { return this->data_->buffers[2]; }
|
| 303 |
+
|
| 304 |
+
/// \brief Return pointer to raw value offsets accounting for any slice offset
|
| 305 |
+
const offset_type* raw_value_sizes() const {
|
| 306 |
+
return raw_value_sizes_ + this->data_->offset;
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
/// \brief Return the size of the value at a particular index
|
| 310 |
+
///
|
| 311 |
+
/// This should not be called if the list-view at slot i is null.
|
| 312 |
+
/// The returned size in those cases could be any value from 0 to the
|
| 313 |
+
/// length of the child values array.
|
| 314 |
+
///
|
| 315 |
+
/// \pre IsValid(i)
|
| 316 |
+
offset_type value_length(int64_t i) const final {
|
| 317 |
+
return this->raw_value_sizes_[i + this->data_->offset];
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
protected:
|
| 321 |
+
const offset_type* raw_value_sizes_ = NULLPTR;
|
| 322 |
+
};
|
| 323 |
+
|
| 324 |
+
/// \brief Concrete Array class for list-view data
|
| 325 |
+
class ARROW_EXPORT ListViewArray : public BaseListViewArray<ListViewType> {
|
| 326 |
+
public:
|
| 327 |
+
explicit ListViewArray(std::shared_ptr<ArrayData> data);
|
| 328 |
+
|
| 329 |
+
ListViewArray(std::shared_ptr<DataType> type, int64_t length,
|
| 330 |
+
std::shared_ptr<Buffer> value_offsets,
|
| 331 |
+
std::shared_ptr<Buffer> value_sizes, std::shared_ptr<Array> values,
|
| 332 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR,
|
| 333 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0);
|
| 334 |
+
|
| 335 |
+
/// \brief Construct ListViewArray from array of offsets, sizes, and child
|
| 336 |
+
/// value array
|
| 337 |
+
///
|
| 338 |
+
/// Construct a ListViewArray using buffers from offsets and sizes arrays
|
| 339 |
+
/// that project views into the child values array.
|
| 340 |
+
///
|
| 341 |
+
/// This function does the bare minimum of validation of the offsets/sizes and
|
| 342 |
+
/// input types. The offset and length of the offsets and sizes arrays must
|
| 343 |
+
/// match and that will be checked, but their contents will be assumed to be
|
| 344 |
+
/// well-formed.
|
| 345 |
+
///
|
| 346 |
+
/// If a null_bitmap is not provided, the nulls will be inferred from the
|
| 347 |
+
/// offsets's null bitmap. But if a null_bitmap is provided, the offsets array
|
| 348 |
+
/// can't have nulls.
|
| 349 |
+
///
|
| 350 |
+
/// And when a null_bitmap is provided, neither the offsets or sizes array can be a
|
| 351 |
+
/// slice (i.e. an array with offset() > 0).
|
| 352 |
+
///
|
| 353 |
+
/// \param[in] offsets An array of int32 offsets into the values array. NULL values are
|
| 354 |
+
/// supported if the corresponding values in sizes is NULL or 0.
|
| 355 |
+
/// \param[in] sizes An array containing the int32 sizes of every view. NULL values are
|
| 356 |
+
/// taken to represent a NULL list-view in the array being created.
|
| 357 |
+
/// \param[in] values Array containing list values
|
| 358 |
+
/// \param[in] pool MemoryPool
|
| 359 |
+
/// \param[in] null_bitmap Optional validity bitmap
|
| 360 |
+
/// \param[in] null_count Optional null count in null_bitmap
|
| 361 |
+
static Result<std::shared_ptr<ListViewArray>> FromArrays(
|
| 362 |
+
const Array& offsets, const Array& sizes, const Array& values,
|
| 363 |
+
MemoryPool* pool = default_memory_pool(),
|
| 364 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR,
|
| 365 |
+
int64_t null_count = kUnknownNullCount);
|
| 366 |
+
|
| 367 |
+
static Result<std::shared_ptr<ListViewArray>> FromArrays(
|
| 368 |
+
std::shared_ptr<DataType> type, const Array& offsets, const Array& sizes,
|
| 369 |
+
const Array& values, MemoryPool* pool = default_memory_pool(),
|
| 370 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR,
|
| 371 |
+
int64_t null_count = kUnknownNullCount);
|
| 372 |
+
|
| 373 |
+
/// \brief Build a ListViewArray from a ListArray
|
| 374 |
+
static Result<std::shared_ptr<ListViewArray>> FromList(const ListArray& list_array,
|
| 375 |
+
MemoryPool* pool);
|
| 376 |
+
|
| 377 |
+
/// \brief Return an Array that is a concatenation of the list-views in this array.
|
| 378 |
+
///
|
| 379 |
+
/// Note that it's different from `values()` in that it takes into
|
| 380 |
+
/// consideration this array's offsets (which can be in any order)
|
| 381 |
+
/// and sizes. Nulls are skipped.
|
| 382 |
+
///
|
| 383 |
+
/// This function invokes Concatenate() if list-views are non-contiguous. It
|
| 384 |
+
/// will try to minimize the number of array slices passed to Concatenate() by
|
| 385 |
+
/// maximizing the size of each slice (containing as many contiguous
|
| 386 |
+
/// list-views as possible).
|
| 387 |
+
Result<std::shared_ptr<Array>> Flatten(
|
| 388 |
+
MemoryPool* memory_pool = default_memory_pool()) const;
|
| 389 |
+
|
| 390 |
+
/// \brief Return list-view offsets as an Int32Array
|
| 391 |
+
///
|
| 392 |
+
/// The returned array will not have a validity bitmap, so you cannot expect
|
| 393 |
+
/// to pass it to ListArray::FromArrays() and get back the same list array
|
| 394 |
+
/// if the original one has nulls.
|
| 395 |
+
std::shared_ptr<Array> offsets() const;
|
| 396 |
+
|
| 397 |
+
/// \brief Return list-view sizes as an Int32Array
|
| 398 |
+
///
|
| 399 |
+
/// The returned array will not have a validity bitmap, so you cannot expect
|
| 400 |
+
/// to pass it to ListViewArray::FromArrays() and get back the same list
|
| 401 |
+
/// array if the original one has nulls.
|
| 402 |
+
std::shared_ptr<Array> sizes() const;
|
| 403 |
+
|
| 404 |
+
protected:
|
| 405 |
+
// This constructor defers SetData to a derived array class
|
| 406 |
+
ListViewArray() = default;
|
| 407 |
+
|
| 408 |
+
void SetData(const std::shared_ptr<ArrayData>& data);
|
| 409 |
+
};
|
| 410 |
+
|
| 411 |
+
/// \brief Concrete Array class for large list-view data (with 64-bit offsets
|
| 412 |
+
/// and sizes)
|
| 413 |
+
class ARROW_EXPORT LargeListViewArray : public BaseListViewArray<LargeListViewType> {
|
| 414 |
+
public:
|
| 415 |
+
explicit LargeListViewArray(std::shared_ptr<ArrayData> data);
|
| 416 |
+
|
| 417 |
+
LargeListViewArray(std::shared_ptr<DataType> type, int64_t length,
|
| 418 |
+
std::shared_ptr<Buffer> value_offsets,
|
| 419 |
+
std::shared_ptr<Buffer> value_sizes, std::shared_ptr<Array> values,
|
| 420 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR,
|
| 421 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0);
|
| 422 |
+
|
| 423 |
+
/// \brief Construct LargeListViewArray from array of offsets, sizes, and child
|
| 424 |
+
/// value array
|
| 425 |
+
///
|
| 426 |
+
/// Construct an LargeListViewArray using buffers from offsets and sizes arrays
|
| 427 |
+
/// that project views into the values array.
|
| 428 |
+
///
|
| 429 |
+
/// This function does the bare minimum of validation of the offsets/sizes and
|
| 430 |
+
/// input types. The offset and length of the offsets and sizes arrays must
|
| 431 |
+
/// match and that will be checked, but their contents will be assumed to be
|
| 432 |
+
/// well-formed.
|
| 433 |
+
///
|
| 434 |
+
/// If a null_bitmap is not provided, the nulls will be inferred from the offsets' or
|
| 435 |
+
/// sizes' null bitmap. Only one of these two is allowed to have a null bitmap. But if a
|
| 436 |
+
/// null_bitmap is provided, the offsets array and the sizes array can't have nulls.
|
| 437 |
+
///
|
| 438 |
+
/// And when a null_bitmap is provided, neither the offsets or sizes array can be a
|
| 439 |
+
/// slice (i.e. an array with offset() > 0).
|
| 440 |
+
///
|
| 441 |
+
/// \param[in] offsets An array of int64 offsets into the values array. NULL values are
|
| 442 |
+
/// supported if the corresponding values in sizes is NULL or 0.
|
| 443 |
+
/// \param[in] sizes An array containing the int64 sizes of every view. NULL values are
|
| 444 |
+
/// taken to represent a NULL list-view in the array being created.
|
| 445 |
+
/// \param[in] values Array containing list values
|
| 446 |
+
/// \param[in] pool MemoryPool
|
| 447 |
+
/// \param[in] null_bitmap Optional validity bitmap
|
| 448 |
+
/// \param[in] null_count Optional null count in null_bitmap
|
| 449 |
+
static Result<std::shared_ptr<LargeListViewArray>> FromArrays(
|
| 450 |
+
const Array& offsets, const Array& sizes, const Array& values,
|
| 451 |
+
MemoryPool* pool = default_memory_pool(),
|
| 452 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR,
|
| 453 |
+
int64_t null_count = kUnknownNullCount);
|
| 454 |
+
|
| 455 |
+
static Result<std::shared_ptr<LargeListViewArray>> FromArrays(
|
| 456 |
+
std::shared_ptr<DataType> type, const Array& offsets, const Array& sizes,
|
| 457 |
+
const Array& values, MemoryPool* pool = default_memory_pool(),
|
| 458 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR,
|
| 459 |
+
int64_t null_count = kUnknownNullCount);
|
| 460 |
+
|
| 461 |
+
/// \brief Build a LargeListViewArray from a LargeListArray
|
| 462 |
+
static Result<std::shared_ptr<LargeListViewArray>> FromList(
|
| 463 |
+
const LargeListArray& list_array, MemoryPool* pool);
|
| 464 |
+
|
| 465 |
+
/// \brief Return an Array that is a concatenation of the large list-views in this
|
| 466 |
+
/// array.
|
| 467 |
+
///
|
| 468 |
+
/// Note that it's different from `values()` in that it takes into
|
| 469 |
+
/// consideration this array's offsets (which can be in any order)
|
| 470 |
+
/// and sizes. Nulls are skipped.
|
| 471 |
+
Result<std::shared_ptr<Array>> Flatten(
|
| 472 |
+
MemoryPool* memory_pool = default_memory_pool()) const;
|
| 473 |
+
|
| 474 |
+
/// \brief Return list-view offsets as an Int64Array
|
| 475 |
+
///
|
| 476 |
+
/// The returned array will not have a validity bitmap, so you cannot expect
|
| 477 |
+
/// to pass it to LargeListArray::FromArrays() and get back the same list array
|
| 478 |
+
/// if the original one has nulls.
|
| 479 |
+
std::shared_ptr<Array> offsets() const;
|
| 480 |
+
|
| 481 |
+
/// \brief Return list-view sizes as an Int64Array
|
| 482 |
+
///
|
| 483 |
+
/// The returned array will not have a validity bitmap, so you cannot expect
|
| 484 |
+
/// to pass it to LargeListViewArray::FromArrays() and get back the same list
|
| 485 |
+
/// array if the original one has nulls.
|
| 486 |
+
std::shared_ptr<Array> sizes() const;
|
| 487 |
+
|
| 488 |
+
protected:
|
| 489 |
+
// This constructor defers SetData to a derived array class
|
| 490 |
+
LargeListViewArray() = default;
|
| 491 |
+
|
| 492 |
+
void SetData(const std::shared_ptr<ArrayData>& data);
|
| 493 |
+
};
|
| 494 |
+
|
| 495 |
+
// ----------------------------------------------------------------------
|
| 496 |
+
// MapArray
|
| 497 |
+
|
| 498 |
+
/// Concrete Array class for map data
|
| 499 |
+
///
|
| 500 |
+
/// NB: "value" in this context refers to a pair of a key and the corresponding item
|
| 501 |
+
class ARROW_EXPORT MapArray : public ListArray {
|
| 502 |
+
public:
|
| 503 |
+
using TypeClass = MapType;
|
| 504 |
+
|
| 505 |
+
explicit MapArray(const std::shared_ptr<ArrayData>& data);
|
| 506 |
+
|
| 507 |
+
MapArray(const std::shared_ptr<DataType>& type, int64_t length,
|
| 508 |
+
const std::shared_ptr<Buffer>& value_offsets,
|
| 509 |
+
const std::shared_ptr<Array>& keys, const std::shared_ptr<Array>& items,
|
| 510 |
+
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
|
| 511 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0);
|
| 512 |
+
|
| 513 |
+
MapArray(const std::shared_ptr<DataType>& type, int64_t length, BufferVector buffers,
|
| 514 |
+
const std::shared_ptr<Array>& keys, const std::shared_ptr<Array>& items,
|
| 515 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0);
|
| 516 |
+
|
| 517 |
+
MapArray(const std::shared_ptr<DataType>& type, int64_t length,
|
| 518 |
+
const std::shared_ptr<Buffer>& value_offsets,
|
| 519 |
+
const std::shared_ptr<Array>& values,
|
| 520 |
+
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
|
| 521 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0);
|
| 522 |
+
|
| 523 |
+
/// \brief Construct MapArray from array of offsets and child key, item arrays
|
| 524 |
+
///
|
| 525 |
+
/// This function does the bare minimum of validation of the offsets and
|
| 526 |
+
/// input types, and will allocate a new offsets array if necessary (i.e. if
|
| 527 |
+
/// the offsets contain any nulls). If the offsets do not have nulls, they
|
| 528 |
+
/// are assumed to be well-formed
|
| 529 |
+
///
|
| 530 |
+
/// \param[in] offsets Array containing n + 1 offsets encoding length and
|
| 531 |
+
/// size. Must be of int32 type
|
| 532 |
+
/// \param[in] keys Array containing key values
|
| 533 |
+
/// \param[in] items Array containing item values
|
| 534 |
+
/// \param[in] pool MemoryPool in case new offsets array needs to be
|
| 535 |
+
/// \param[in] null_bitmap Optional validity bitmap
|
| 536 |
+
/// allocated because of null values
|
| 537 |
+
static Result<std::shared_ptr<Array>> FromArrays(
|
| 538 |
+
const std::shared_ptr<Array>& offsets, const std::shared_ptr<Array>& keys,
|
| 539 |
+
const std::shared_ptr<Array>& items, MemoryPool* pool = default_memory_pool(),
|
| 540 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR);
|
| 541 |
+
|
| 542 |
+
static Result<std::shared_ptr<Array>> FromArrays(
|
| 543 |
+
std::shared_ptr<DataType> type, const std::shared_ptr<Array>& offsets,
|
| 544 |
+
const std::shared_ptr<Array>& keys, const std::shared_ptr<Array>& items,
|
| 545 |
+
MemoryPool* pool = default_memory_pool(),
|
| 546 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR);
|
| 547 |
+
|
| 548 |
+
const MapType* map_type() const { return map_type_; }
|
| 549 |
+
|
| 550 |
+
/// \brief Return array object containing all map keys
|
| 551 |
+
const std::shared_ptr<Array>& keys() const { return keys_; }
|
| 552 |
+
|
| 553 |
+
/// \brief Return array object containing all mapped items
|
| 554 |
+
const std::shared_ptr<Array>& items() const { return items_; }
|
| 555 |
+
|
| 556 |
+
/// Validate child data before constructing the actual MapArray.
|
| 557 |
+
static Status ValidateChildData(
|
| 558 |
+
const std::vector<std::shared_ptr<ArrayData>>& child_data);
|
| 559 |
+
|
| 560 |
+
protected:
|
| 561 |
+
void SetData(const std::shared_ptr<ArrayData>& data);
|
| 562 |
+
|
| 563 |
+
static Result<std::shared_ptr<Array>> FromArraysInternal(
|
| 564 |
+
std::shared_ptr<DataType> type, const std::shared_ptr<Array>& offsets,
|
| 565 |
+
const std::shared_ptr<Array>& keys, const std::shared_ptr<Array>& items,
|
| 566 |
+
MemoryPool* pool, std::shared_ptr<Buffer> null_bitmap = NULLPTR);
|
| 567 |
+
|
| 568 |
+
private:
|
| 569 |
+
const MapType* map_type_;
|
| 570 |
+
std::shared_ptr<Array> keys_, items_;
|
| 571 |
+
};
|
| 572 |
+
|
| 573 |
+
// ----------------------------------------------------------------------
|
| 574 |
+
// FixedSizeListArray
|
| 575 |
+
|
| 576 |
+
/// Concrete Array class for fixed size list data
|
| 577 |
+
class ARROW_EXPORT FixedSizeListArray : public Array {
|
| 578 |
+
public:
|
| 579 |
+
using TypeClass = FixedSizeListType;
|
| 580 |
+
using offset_type = TypeClass::offset_type;
|
| 581 |
+
|
| 582 |
+
explicit FixedSizeListArray(const std::shared_ptr<ArrayData>& data);
|
| 583 |
+
|
| 584 |
+
FixedSizeListArray(const std::shared_ptr<DataType>& type, int64_t length,
|
| 585 |
+
const std::shared_ptr<Array>& values,
|
| 586 |
+
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
|
| 587 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0);
|
| 588 |
+
|
| 589 |
+
const FixedSizeListType* list_type() const;
|
| 590 |
+
|
| 591 |
+
/// \brief Return array object containing the list's values
|
| 592 |
+
const std::shared_ptr<Array>& values() const;
|
| 593 |
+
|
| 594 |
+
const std::shared_ptr<DataType>& value_type() const;
|
| 595 |
+
|
| 596 |
+
// The following functions will not perform boundschecking
|
| 597 |
+
int64_t value_offset(int64_t i) const {
|
| 598 |
+
i += data_->offset;
|
| 599 |
+
return list_size_ * i;
|
| 600 |
+
}
|
| 601 |
+
/// \brief Return the fixed-size of the values
|
| 602 |
+
///
|
| 603 |
+
/// No matter the value of the index parameter, the result is the same.
|
| 604 |
+
/// So even when the value at slot i is null, this function will return a
|
| 605 |
+
/// non-zero size.
|
| 606 |
+
///
|
| 607 |
+
/// \pre IsValid(i)
|
| 608 |
+
int32_t value_length(int64_t i = 0) const {
|
| 609 |
+
ARROW_UNUSED(i);
|
| 610 |
+
return list_size_;
|
| 611 |
+
}
|
| 612 |
+
/// \pre IsValid(i)
|
| 613 |
+
std::shared_ptr<Array> value_slice(int64_t i) const {
|
| 614 |
+
return values_->Slice(value_offset(i), value_length(i));
|
| 615 |
+
}
|
| 616 |
+
|
| 617 |
+
/// \brief Return an Array that is a concatenation of the lists in this array.
|
| 618 |
+
///
|
| 619 |
+
/// Note that it's different from `values()` in that it takes into
|
| 620 |
+
/// consideration null elements (they are skipped, thus copying may be needed).
|
| 621 |
+
Result<std::shared_ptr<Array>> Flatten(
|
| 622 |
+
MemoryPool* memory_pool = default_memory_pool()) const;
|
| 623 |
+
|
| 624 |
+
/// \brief Flatten all level recursively until reach a non-list type, and return
|
| 625 |
+
/// a non-list type Array.
|
| 626 |
+
///
|
| 627 |
+
/// \see internal::FlattenLogicalListRecursively
|
| 628 |
+
Result<std::shared_ptr<Array>> FlattenRecursively(
|
| 629 |
+
MemoryPool* memory_pool = default_memory_pool()) const {
|
| 630 |
+
return internal::FlattenLogicalListRecursively(*this, memory_pool);
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
/// \brief Construct FixedSizeListArray from child value array and value_length
|
| 634 |
+
///
|
| 635 |
+
/// \param[in] values Array containing list values
|
| 636 |
+
/// \param[in] list_size The fixed length of each list
|
| 637 |
+
/// \param[in] null_bitmap Optional validity bitmap
|
| 638 |
+
/// \param[in] null_count Optional null count in null_bitmap
|
| 639 |
+
/// \return Will have length equal to values.length() / list_size
|
| 640 |
+
static Result<std::shared_ptr<Array>> FromArrays(
|
| 641 |
+
const std::shared_ptr<Array>& values, int32_t list_size,
|
| 642 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR,
|
| 643 |
+
int64_t null_count = kUnknownNullCount);
|
| 644 |
+
|
| 645 |
+
/// \brief Construct FixedSizeListArray from child value array and type
|
| 646 |
+
///
|
| 647 |
+
/// \param[in] values Array containing list values
|
| 648 |
+
/// \param[in] type The fixed sized list type
|
| 649 |
+
/// \param[in] null_bitmap Optional validity bitmap
|
| 650 |
+
/// \param[in] null_count Optional null count in null_bitmap
|
| 651 |
+
/// \return Will have length equal to values.length() / type.list_size()
|
| 652 |
+
static Result<std::shared_ptr<Array>> FromArrays(
|
| 653 |
+
const std::shared_ptr<Array>& values, std::shared_ptr<DataType> type,
|
| 654 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR,
|
| 655 |
+
int64_t null_count = kUnknownNullCount);
|
| 656 |
+
|
| 657 |
+
protected:
|
| 658 |
+
void SetData(const std::shared_ptr<ArrayData>& data);
|
| 659 |
+
int32_t list_size_;
|
| 660 |
+
|
| 661 |
+
private:
|
| 662 |
+
std::shared_ptr<Array> values_;
|
| 663 |
+
};
|
| 664 |
+
|
| 665 |
+
// ----------------------------------------------------------------------
|
| 666 |
+
// Struct
|
| 667 |
+
|
| 668 |
+
/// Concrete Array class for struct data
|
| 669 |
+
class ARROW_EXPORT StructArray : public Array {
|
| 670 |
+
public:
|
| 671 |
+
using TypeClass = StructType;
|
| 672 |
+
|
| 673 |
+
explicit StructArray(const std::shared_ptr<ArrayData>& data);
|
| 674 |
+
|
| 675 |
+
StructArray(const std::shared_ptr<DataType>& type, int64_t length,
|
| 676 |
+
const std::vector<std::shared_ptr<Array>>& children,
|
| 677 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR,
|
| 678 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0);
|
| 679 |
+
|
| 680 |
+
/// \brief Return a StructArray from child arrays and field names.
|
| 681 |
+
///
|
| 682 |
+
/// The length and data type are automatically inferred from the arguments.
|
| 683 |
+
/// There should be at least one child array.
|
| 684 |
+
static Result<std::shared_ptr<StructArray>> Make(
|
| 685 |
+
const ArrayVector& children, const std::vector<std::string>& field_names,
|
| 686 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR,
|
| 687 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0);
|
| 688 |
+
|
| 689 |
+
/// \brief Return a StructArray from child arrays and fields.
|
| 690 |
+
///
|
| 691 |
+
/// The length is automatically inferred from the arguments.
|
| 692 |
+
/// There should be at least one child array. This method does not
|
| 693 |
+
/// check that field types and child array types are consistent.
|
| 694 |
+
static Result<std::shared_ptr<StructArray>> Make(
|
| 695 |
+
const ArrayVector& children, const FieldVector& fields,
|
| 696 |
+
std::shared_ptr<Buffer> null_bitmap = NULLPTR,
|
| 697 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0);
|
| 698 |
+
|
| 699 |
+
const StructType* struct_type() const;
|
| 700 |
+
|
| 701 |
+
// Return a shared pointer in case the requestor desires to share ownership
|
| 702 |
+
// with this array. The returned array has its offset, length and null
|
| 703 |
+
// count adjusted.
|
| 704 |
+
const std::shared_ptr<Array>& field(int pos) const;
|
| 705 |
+
|
| 706 |
+
const ArrayVector& fields() const;
|
| 707 |
+
|
| 708 |
+
/// Returns null if name not found
|
| 709 |
+
std::shared_ptr<Array> GetFieldByName(const std::string& name) const;
|
| 710 |
+
|
| 711 |
+
/// Indicate if field named `name` can be found unambiguously in the struct.
|
| 712 |
+
Status CanReferenceFieldByName(const std::string& name) const;
|
| 713 |
+
|
| 714 |
+
/// Indicate if fields named `names` can be found unambiguously in the struct.
|
| 715 |
+
Status CanReferenceFieldsByNames(const std::vector<std::string>& names) const;
|
| 716 |
+
|
| 717 |
+
/// \brief Flatten this array as a vector of arrays, one for each field
|
| 718 |
+
///
|
| 719 |
+
/// \param[in] pool The pool to allocate null bitmaps from, if necessary
|
| 720 |
+
Result<ArrayVector> Flatten(MemoryPool* pool = default_memory_pool()) const;
|
| 721 |
+
|
| 722 |
+
/// \brief Get one of the child arrays, combining its null bitmap
|
| 723 |
+
/// with the parent struct array's bitmap.
|
| 724 |
+
///
|
| 725 |
+
/// \param[in] index Which child array to get
|
| 726 |
+
/// \param[in] pool The pool to allocate null bitmaps from, if necessary
|
| 727 |
+
Result<std::shared_ptr<Array>> GetFlattenedField(
|
| 728 |
+
int index, MemoryPool* pool = default_memory_pool()) const;
|
| 729 |
+
|
| 730 |
+
private:
|
| 731 |
+
// For caching boxed child data
|
| 732 |
+
// XXX This is not handled in a thread-safe manner.
|
| 733 |
+
mutable ArrayVector boxed_fields_;
|
| 734 |
+
};
|
| 735 |
+
|
| 736 |
+
// ----------------------------------------------------------------------
|
| 737 |
+
// Union
|
| 738 |
+
|
| 739 |
+
/// Base class for SparseUnionArray and DenseUnionArray
|
| 740 |
+
class ARROW_EXPORT UnionArray : public Array {
|
| 741 |
+
public:
|
| 742 |
+
using type_code_t = int8_t;
|
| 743 |
+
|
| 744 |
+
/// Note that this buffer does not account for any slice offset
|
| 745 |
+
const std::shared_ptr<Buffer>& type_codes() const { return data_->buffers[1]; }
|
| 746 |
+
|
| 747 |
+
const type_code_t* raw_type_codes() const { return raw_type_codes_ + data_->offset; }
|
| 748 |
+
|
| 749 |
+
/// The logical type code of the value at index.
|
| 750 |
+
type_code_t type_code(int64_t i) const { return raw_type_codes_[i + data_->offset]; }
|
| 751 |
+
|
| 752 |
+
/// The physical child id containing value at index.
|
| 753 |
+
int child_id(int64_t i) const {
|
| 754 |
+
return union_type_->child_ids()[raw_type_codes_[i + data_->offset]];
|
| 755 |
+
}
|
| 756 |
+
|
| 757 |
+
const UnionType* union_type() const { return union_type_; }
|
| 758 |
+
|
| 759 |
+
UnionMode::type mode() const { return union_type_->mode(); }
|
| 760 |
+
|
| 761 |
+
/// \brief Return the given field as an individual array.
|
| 762 |
+
///
|
| 763 |
+
/// For sparse unions, the returned array has its offset, length and null
|
| 764 |
+
/// count adjusted.
|
| 765 |
+
std::shared_ptr<Array> field(int pos) const;
|
| 766 |
+
|
| 767 |
+
protected:
|
| 768 |
+
void SetData(std::shared_ptr<ArrayData> data);
|
| 769 |
+
|
| 770 |
+
const type_code_t* raw_type_codes_;
|
| 771 |
+
const UnionType* union_type_;
|
| 772 |
+
|
| 773 |
+
// For caching boxed child data
|
| 774 |
+
mutable std::vector<std::shared_ptr<Array>> boxed_fields_;
|
| 775 |
+
};
|
| 776 |
+
|
| 777 |
+
/// Concrete Array class for sparse union data
|
| 778 |
+
class ARROW_EXPORT SparseUnionArray : public UnionArray {
|
| 779 |
+
public:
|
| 780 |
+
using TypeClass = SparseUnionType;
|
| 781 |
+
|
| 782 |
+
explicit SparseUnionArray(std::shared_ptr<ArrayData> data);
|
| 783 |
+
|
| 784 |
+
SparseUnionArray(std::shared_ptr<DataType> type, int64_t length, ArrayVector children,
|
| 785 |
+
std::shared_ptr<Buffer> type_ids, int64_t offset = 0);
|
| 786 |
+
|
| 787 |
+
/// \brief Construct SparseUnionArray from type_ids and children
|
| 788 |
+
///
|
| 789 |
+
/// This function does the bare minimum of validation of the input types.
|
| 790 |
+
///
|
| 791 |
+
/// \param[in] type_ids An array of logical type ids for the union type
|
| 792 |
+
/// \param[in] children Vector of children Arrays containing the data for each type.
|
| 793 |
+
/// \param[in] type_codes Vector of type codes.
|
| 794 |
+
static Result<std::shared_ptr<Array>> Make(const Array& type_ids, ArrayVector children,
|
| 795 |
+
std::vector<type_code_t> type_codes) {
|
| 796 |
+
return Make(std::move(type_ids), std::move(children), std::vector<std::string>{},
|
| 797 |
+
std::move(type_codes));
|
| 798 |
+
}
|
| 799 |
+
|
| 800 |
+
/// \brief Construct SparseUnionArray with custom field names from type_ids and children
|
| 801 |
+
///
|
| 802 |
+
/// This function does the bare minimum of validation of the input types.
|
| 803 |
+
///
|
| 804 |
+
/// \param[in] type_ids An array of logical type ids for the union type
|
| 805 |
+
/// \param[in] children Vector of children Arrays containing the data for each type.
|
| 806 |
+
/// \param[in] field_names Vector of strings containing the name of each field.
|
| 807 |
+
/// \param[in] type_codes Vector of type codes.
|
| 808 |
+
static Result<std::shared_ptr<Array>> Make(const Array& type_ids, ArrayVector children,
|
| 809 |
+
std::vector<std::string> field_names = {},
|
| 810 |
+
std::vector<type_code_t> type_codes = {});
|
| 811 |
+
|
| 812 |
+
const SparseUnionType* union_type() const {
|
| 813 |
+
return internal::checked_cast<const SparseUnionType*>(union_type_);
|
| 814 |
+
}
|
| 815 |
+
|
| 816 |
+
/// \brief Get one of the child arrays, adjusting its null bitmap
|
| 817 |
+
/// where the union array type code does not match.
|
| 818 |
+
///
|
| 819 |
+
/// \param[in] index Which child array to get (i.e. the physical index, not the type
|
| 820 |
+
/// code) \param[in] pool The pool to allocate null bitmaps from, if necessary
|
| 821 |
+
Result<std::shared_ptr<Array>> GetFlattenedField(
|
| 822 |
+
int index, MemoryPool* pool = default_memory_pool()) const;
|
| 823 |
+
|
| 824 |
+
protected:
|
| 825 |
+
void SetData(std::shared_ptr<ArrayData> data);
|
| 826 |
+
};
|
| 827 |
+
|
| 828 |
+
/// \brief Concrete Array class for dense union data
|
| 829 |
+
///
|
| 830 |
+
/// Note that union types do not have a validity bitmap
|
| 831 |
+
class ARROW_EXPORT DenseUnionArray : public UnionArray {
|
| 832 |
+
public:
|
| 833 |
+
using TypeClass = DenseUnionType;
|
| 834 |
+
|
| 835 |
+
explicit DenseUnionArray(const std::shared_ptr<ArrayData>& data);
|
| 836 |
+
|
| 837 |
+
DenseUnionArray(std::shared_ptr<DataType> type, int64_t length, ArrayVector children,
|
| 838 |
+
std::shared_ptr<Buffer> type_ids,
|
| 839 |
+
std::shared_ptr<Buffer> value_offsets = NULLPTR, int64_t offset = 0);
|
| 840 |
+
|
| 841 |
+
/// \brief Construct DenseUnionArray from type_ids, value_offsets, and children
|
| 842 |
+
///
|
| 843 |
+
/// This function does the bare minimum of validation of the offsets and
|
| 844 |
+
/// input types.
|
| 845 |
+
///
|
| 846 |
+
/// \param[in] type_ids An array of logical type ids for the union type
|
| 847 |
+
/// \param[in] value_offsets An array of signed int32 values indicating the
|
| 848 |
+
/// relative offset into the respective child array for the type in a given slot.
|
| 849 |
+
/// The respective offsets for each child value array must be in order / increasing.
|
| 850 |
+
/// \param[in] children Vector of children Arrays containing the data for each type.
|
| 851 |
+
/// \param[in] type_codes Vector of type codes.
|
| 852 |
+
static Result<std::shared_ptr<Array>> Make(const Array& type_ids,
|
| 853 |
+
const Array& value_offsets,
|
| 854 |
+
ArrayVector children,
|
| 855 |
+
std::vector<type_code_t> type_codes) {
|
| 856 |
+
return Make(type_ids, value_offsets, std::move(children), std::vector<std::string>{},
|
| 857 |
+
std::move(type_codes));
|
| 858 |
+
}
|
| 859 |
+
|
| 860 |
+
/// \brief Construct DenseUnionArray with custom field names from type_ids,
|
| 861 |
+
/// value_offsets, and children
|
| 862 |
+
///
|
| 863 |
+
/// This function does the bare minimum of validation of the offsets and
|
| 864 |
+
/// input types.
|
| 865 |
+
///
|
| 866 |
+
/// \param[in] type_ids An array of logical type ids for the union type
|
| 867 |
+
/// \param[in] value_offsets An array of signed int32 values indicating the
|
| 868 |
+
/// relative offset into the respective child array for the type in a given slot.
|
| 869 |
+
/// The respective offsets for each child value array must be in order / increasing.
|
| 870 |
+
/// \param[in] children Vector of children Arrays containing the data for each type.
|
| 871 |
+
/// \param[in] field_names Vector of strings containing the name of each field.
|
| 872 |
+
/// \param[in] type_codes Vector of type codes.
|
| 873 |
+
static Result<std::shared_ptr<Array>> Make(const Array& type_ids,
|
| 874 |
+
const Array& value_offsets,
|
| 875 |
+
ArrayVector children,
|
| 876 |
+
std::vector<std::string> field_names = {},
|
| 877 |
+
std::vector<type_code_t> type_codes = {});
|
| 878 |
+
|
| 879 |
+
const DenseUnionType* union_type() const {
|
| 880 |
+
return internal::checked_cast<const DenseUnionType*>(union_type_);
|
| 881 |
+
}
|
| 882 |
+
|
| 883 |
+
/// Note that this buffer does not account for any slice offset
|
| 884 |
+
const std::shared_ptr<Buffer>& value_offsets() const { return data_->buffers[2]; }
|
| 885 |
+
|
| 886 |
+
int32_t value_offset(int64_t i) const { return raw_value_offsets_[i + data_->offset]; }
|
| 887 |
+
|
| 888 |
+
const int32_t* raw_value_offsets() const { return raw_value_offsets_ + data_->offset; }
|
| 889 |
+
|
| 890 |
+
protected:
|
| 891 |
+
const int32_t* raw_value_offsets_;
|
| 892 |
+
|
| 893 |
+
void SetData(const std::shared_ptr<ArrayData>& data);
|
| 894 |
+
};
|
| 895 |
+
|
| 896 |
+
/// @}
|
| 897 |
+
|
| 898 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/array_primitive.h
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
// Array accessor types for primitive/C-type-based arrays, such as numbers,
|
| 19 |
+
// boolean, and temporal types.
|
| 20 |
+
|
| 21 |
+
#pragma once
|
| 22 |
+
|
| 23 |
+
#include <cstdint>
|
| 24 |
+
#include <memory>
|
| 25 |
+
|
| 26 |
+
#include "arrow/array/array_base.h"
|
| 27 |
+
#include "arrow/array/data.h"
|
| 28 |
+
#include "arrow/stl_iterator.h"
|
| 29 |
+
#include "arrow/type.h"
|
| 30 |
+
#include "arrow/type_fwd.h" // IWYU pragma: export
|
| 31 |
+
#include "arrow/type_traits.h"
|
| 32 |
+
#include "arrow/util/bit_util.h"
|
| 33 |
+
#include "arrow/util/macros.h"
|
| 34 |
+
#include "arrow/util/visibility.h"
|
| 35 |
+
|
| 36 |
+
namespace arrow {
|
| 37 |
+
|
| 38 |
+
/// Concrete Array class for boolean data
|
| 39 |
+
class ARROW_EXPORT BooleanArray : public PrimitiveArray {
|
| 40 |
+
public:
|
| 41 |
+
using TypeClass = BooleanType;
|
| 42 |
+
using IteratorType = stl::ArrayIterator<BooleanArray>;
|
| 43 |
+
|
| 44 |
+
explicit BooleanArray(const std::shared_ptr<ArrayData>& data);
|
| 45 |
+
|
| 46 |
+
BooleanArray(int64_t length, const std::shared_ptr<Buffer>& data,
|
| 47 |
+
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
|
| 48 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0);
|
| 49 |
+
|
| 50 |
+
bool Value(int64_t i) const {
|
| 51 |
+
return bit_util::GetBit(reinterpret_cast<const uint8_t*>(raw_values_),
|
| 52 |
+
i + data_->offset);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
bool GetView(int64_t i) const { return Value(i); }
|
| 56 |
+
|
| 57 |
+
std::optional<bool> operator[](int64_t i) const { return *IteratorType(*this, i); }
|
| 58 |
+
|
| 59 |
+
/// \brief Return the number of false (0) values among the valid
|
| 60 |
+
/// values. Result is not cached.
|
| 61 |
+
int64_t false_count() const;
|
| 62 |
+
|
| 63 |
+
/// \brief Return the number of true (1) values among the valid
|
| 64 |
+
/// values. Result is not cached.
|
| 65 |
+
int64_t true_count() const;
|
| 66 |
+
|
| 67 |
+
IteratorType begin() const { return IteratorType(*this); }
|
| 68 |
+
|
| 69 |
+
IteratorType end() const { return IteratorType(*this, length()); }
|
| 70 |
+
|
| 71 |
+
protected:
|
| 72 |
+
using PrimitiveArray::PrimitiveArray;
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
/// \addtogroup numeric-arrays
|
| 76 |
+
///
|
| 77 |
+
/// @{
|
| 78 |
+
|
| 79 |
+
/// \brief Concrete Array class for numeric data with a corresponding C type
|
| 80 |
+
///
|
| 81 |
+
/// This class is templated on the corresponding DataType subclass for the
|
| 82 |
+
/// given data, for example NumericArray<Int8Type> or NumericArray<Date32Type>.
|
| 83 |
+
///
|
| 84 |
+
/// Note that convenience aliases are available for all accepted types
|
| 85 |
+
/// (for example Int8Array for NumericArray<Int8Type>).
|
| 86 |
+
template <typename TYPE>
|
| 87 |
+
class NumericArray : public PrimitiveArray {
|
| 88 |
+
public:
|
| 89 |
+
using TypeClass = TYPE;
|
| 90 |
+
using value_type = typename TypeClass::c_type;
|
| 91 |
+
using IteratorType = stl::ArrayIterator<NumericArray<TYPE>>;
|
| 92 |
+
|
| 93 |
+
explicit NumericArray(const std::shared_ptr<ArrayData>& data) : PrimitiveArray(data) {}
|
| 94 |
+
|
| 95 |
+
// Only enable this constructor without a type argument for types without additional
|
| 96 |
+
// metadata
|
| 97 |
+
template <typename T1 = TYPE>
|
| 98 |
+
NumericArray(enable_if_parameter_free<T1, int64_t> length,
|
| 99 |
+
const std::shared_ptr<Buffer>& data,
|
| 100 |
+
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
|
| 101 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0)
|
| 102 |
+
: PrimitiveArray(TypeTraits<T1>::type_singleton(), length, data, null_bitmap,
|
| 103 |
+
null_count, offset) {}
|
| 104 |
+
|
| 105 |
+
const value_type* raw_values() const {
|
| 106 |
+
return reinterpret_cast<const value_type*>(raw_values_) + data_->offset;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
value_type Value(int64_t i) const { return raw_values()[i]; }
|
| 110 |
+
|
| 111 |
+
// For API compatibility with BinaryArray etc.
|
| 112 |
+
value_type GetView(int64_t i) const { return Value(i); }
|
| 113 |
+
|
| 114 |
+
std::optional<value_type> operator[](int64_t i) const {
|
| 115 |
+
return *IteratorType(*this, i);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
IteratorType begin() const { return IteratorType(*this); }
|
| 119 |
+
|
| 120 |
+
IteratorType end() const { return IteratorType(*this, length()); }
|
| 121 |
+
|
| 122 |
+
protected:
|
| 123 |
+
using PrimitiveArray::PrimitiveArray;
|
| 124 |
+
};
|
| 125 |
+
|
| 126 |
+
/// DayTimeArray
|
| 127 |
+
/// ---------------------
|
| 128 |
+
/// \brief Array of Day and Millisecond values.
|
| 129 |
+
class ARROW_EXPORT DayTimeIntervalArray : public PrimitiveArray {
|
| 130 |
+
public:
|
| 131 |
+
using TypeClass = DayTimeIntervalType;
|
| 132 |
+
using IteratorType = stl::ArrayIterator<DayTimeIntervalArray>;
|
| 133 |
+
|
| 134 |
+
explicit DayTimeIntervalArray(const std::shared_ptr<ArrayData>& data);
|
| 135 |
+
|
| 136 |
+
DayTimeIntervalArray(const std::shared_ptr<DataType>& type, int64_t length,
|
| 137 |
+
const std::shared_ptr<Buffer>& data,
|
| 138 |
+
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
|
| 139 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0);
|
| 140 |
+
|
| 141 |
+
DayTimeIntervalArray(int64_t length, const std::shared_ptr<Buffer>& data,
|
| 142 |
+
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
|
| 143 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0);
|
| 144 |
+
|
| 145 |
+
TypeClass::DayMilliseconds GetValue(int64_t i) const;
|
| 146 |
+
TypeClass::DayMilliseconds Value(int64_t i) const { return GetValue(i); }
|
| 147 |
+
|
| 148 |
+
// For compatibility with Take kernel.
|
| 149 |
+
TypeClass::DayMilliseconds GetView(int64_t i) const { return GetValue(i); }
|
| 150 |
+
|
| 151 |
+
IteratorType begin() const { return IteratorType(*this); }
|
| 152 |
+
|
| 153 |
+
IteratorType end() const { return IteratorType(*this, length()); }
|
| 154 |
+
|
| 155 |
+
std::optional<TypeClass::DayMilliseconds> operator[](int64_t i) const {
|
| 156 |
+
return *IteratorType(*this, i);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
int32_t byte_width() const { return sizeof(TypeClass::DayMilliseconds); }
|
| 160 |
+
|
| 161 |
+
const uint8_t* raw_values() const { return raw_values_ + data_->offset * byte_width(); }
|
| 162 |
+
};
|
| 163 |
+
|
| 164 |
+
/// \brief Array of Month, Day and nanosecond values.
|
| 165 |
+
class ARROW_EXPORT MonthDayNanoIntervalArray : public PrimitiveArray {
|
| 166 |
+
public:
|
| 167 |
+
using TypeClass = MonthDayNanoIntervalType;
|
| 168 |
+
using IteratorType = stl::ArrayIterator<MonthDayNanoIntervalArray>;
|
| 169 |
+
|
| 170 |
+
explicit MonthDayNanoIntervalArray(const std::shared_ptr<ArrayData>& data);
|
| 171 |
+
|
| 172 |
+
MonthDayNanoIntervalArray(const std::shared_ptr<DataType>& type, int64_t length,
|
| 173 |
+
const std::shared_ptr<Buffer>& data,
|
| 174 |
+
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
|
| 175 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0);
|
| 176 |
+
|
| 177 |
+
MonthDayNanoIntervalArray(int64_t length, const std::shared_ptr<Buffer>& data,
|
| 178 |
+
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
|
| 179 |
+
int64_t null_count = kUnknownNullCount, int64_t offset = 0);
|
| 180 |
+
|
| 181 |
+
TypeClass::MonthDayNanos GetValue(int64_t i) const;
|
| 182 |
+
TypeClass::MonthDayNanos Value(int64_t i) const { return GetValue(i); }
|
| 183 |
+
|
| 184 |
+
// For compatibility with Take kernel.
|
| 185 |
+
TypeClass::MonthDayNanos GetView(int64_t i) const { return GetValue(i); }
|
| 186 |
+
|
| 187 |
+
IteratorType begin() const { return IteratorType(*this); }
|
| 188 |
+
|
| 189 |
+
IteratorType end() const { return IteratorType(*this, length()); }
|
| 190 |
+
|
| 191 |
+
std::optional<TypeClass::MonthDayNanos> operator[](int64_t i) const {
|
| 192 |
+
return *IteratorType(*this, i);
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
int32_t byte_width() const { return sizeof(TypeClass::MonthDayNanos); }
|
| 196 |
+
|
| 197 |
+
const uint8_t* raw_values() const { return raw_values_ + data_->offset * byte_width(); }
|
| 198 |
+
};
|
| 199 |
+
|
| 200 |
+
/// @}
|
| 201 |
+
|
| 202 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/array_run_end.h
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
// Array accessor classes run-end encoded arrays
|
| 19 |
+
|
| 20 |
+
#pragma once
|
| 21 |
+
|
| 22 |
+
#include <cstdint>
|
| 23 |
+
#include <memory>
|
| 24 |
+
#include <string>
|
| 25 |
+
#include <utility>
|
| 26 |
+
#include <vector>
|
| 27 |
+
|
| 28 |
+
#include "arrow/array/array_base.h"
|
| 29 |
+
#include "arrow/array/data.h"
|
| 30 |
+
#include "arrow/result.h"
|
| 31 |
+
#include "arrow/status.h"
|
| 32 |
+
#include "arrow/type.h"
|
| 33 |
+
#include "arrow/type_fwd.h"
|
| 34 |
+
#include "arrow/util/checked_cast.h"
|
| 35 |
+
#include "arrow/util/macros.h"
|
| 36 |
+
#include "arrow/util/visibility.h"
|
| 37 |
+
|
| 38 |
+
namespace arrow {
|
| 39 |
+
|
| 40 |
+
/// \addtogroup run-end-encoded-arrays
|
| 41 |
+
///
|
| 42 |
+
/// @{
|
| 43 |
+
|
| 44 |
+
// ----------------------------------------------------------------------
|
| 45 |
+
// RunEndEncoded
|
| 46 |
+
|
| 47 |
+
/// \brief Array type for run-end encoded data
|
| 48 |
+
class ARROW_EXPORT RunEndEncodedArray : public Array {
|
| 49 |
+
private:
|
| 50 |
+
std::shared_ptr<Array> run_ends_array_;
|
| 51 |
+
std::shared_ptr<Array> values_array_;
|
| 52 |
+
|
| 53 |
+
public:
|
| 54 |
+
using TypeClass = RunEndEncodedType;
|
| 55 |
+
|
| 56 |
+
explicit RunEndEncodedArray(const std::shared_ptr<ArrayData>& data);
|
| 57 |
+
|
| 58 |
+
/// \brief Construct a RunEndEncodedArray from all parameters
|
| 59 |
+
///
|
| 60 |
+
/// The length and offset parameters refer to the dimensions of the logical
|
| 61 |
+
/// array which is the array we would get after expanding all the runs into
|
| 62 |
+
/// repeated values. As such, length can be much greater than the length of
|
| 63 |
+
/// the child run_ends and values arrays.
|
| 64 |
+
RunEndEncodedArray(const std::shared_ptr<DataType>& type, int64_t length,
|
| 65 |
+
const std::shared_ptr<Array>& run_ends,
|
| 66 |
+
const std::shared_ptr<Array>& values, int64_t offset = 0);
|
| 67 |
+
|
| 68 |
+
/// \brief Construct a RunEndEncodedArray from all parameters
|
| 69 |
+
///
|
| 70 |
+
/// The length and offset parameters refer to the dimensions of the logical
|
| 71 |
+
/// array which is the array we would get after expanding all the runs into
|
| 72 |
+
/// repeated values. As such, length can be much greater than the length of
|
| 73 |
+
/// the child run_ends and values arrays.
|
| 74 |
+
static Result<std::shared_ptr<RunEndEncodedArray>> Make(
|
| 75 |
+
const std::shared_ptr<DataType>& type, int64_t logical_length,
|
| 76 |
+
const std::shared_ptr<Array>& run_ends, const std::shared_ptr<Array>& values,
|
| 77 |
+
int64_t logical_offset = 0);
|
| 78 |
+
|
| 79 |
+
/// \brief Construct a RunEndEncodedArray from values and run ends arrays
|
| 80 |
+
///
|
| 81 |
+
/// The data type is automatically inferred from the arguments.
|
| 82 |
+
/// The run_ends and values arrays must have the same length.
|
| 83 |
+
static Result<std::shared_ptr<RunEndEncodedArray>> Make(
|
| 84 |
+
int64_t logical_length, const std::shared_ptr<Array>& run_ends,
|
| 85 |
+
const std::shared_ptr<Array>& values, int64_t logical_offset = 0);
|
| 86 |
+
|
| 87 |
+
protected:
|
| 88 |
+
void SetData(const std::shared_ptr<ArrayData>& data);
|
| 89 |
+
|
| 90 |
+
public:
|
| 91 |
+
/// \brief Returns an array holding the logical indexes of each run-end
|
| 92 |
+
///
|
| 93 |
+
/// The physical offset to the array is applied.
|
| 94 |
+
const std::shared_ptr<Array>& run_ends() const { return run_ends_array_; }
|
| 95 |
+
|
| 96 |
+
/// \brief Returns an array holding the values of each run
|
| 97 |
+
///
|
| 98 |
+
/// The physical offset to the array is applied.
|
| 99 |
+
const std::shared_ptr<Array>& values() const { return values_array_; }
|
| 100 |
+
|
| 101 |
+
/// \brief Returns an array holding the logical indexes of each run end
|
| 102 |
+
///
|
| 103 |
+
/// If a non-zero logical offset is set, this function allocates a new
|
| 104 |
+
/// array and rewrites all the run end values to be relative to the logical
|
| 105 |
+
/// offset and cuts the end of the array to the logical length.
|
| 106 |
+
Result<std::shared_ptr<Array>> LogicalRunEnds(MemoryPool* pool) const;
|
| 107 |
+
|
| 108 |
+
/// \brief Returns an array holding the values of each run
|
| 109 |
+
///
|
| 110 |
+
/// If a non-zero logical offset is set, this function allocates a new
|
| 111 |
+
/// array containing only the values within the logical range.
|
| 112 |
+
std::shared_ptr<Array> LogicalValues() const;
|
| 113 |
+
|
| 114 |
+
/// \brief Find the physical offset of this REE array
|
| 115 |
+
///
|
| 116 |
+
/// This function uses binary-search, so it has a O(log N) cost.
|
| 117 |
+
int64_t FindPhysicalOffset() const;
|
| 118 |
+
|
| 119 |
+
/// \brief Find the physical length of this REE array
|
| 120 |
+
///
|
| 121 |
+
/// The physical length of an REE is the number of physical values (and
|
| 122 |
+
/// run-ends) necessary to represent the logical range of values from offset
|
| 123 |
+
/// to length.
|
| 124 |
+
///
|
| 125 |
+
/// Avoid calling this function if the physical length can be established in
|
| 126 |
+
/// some other way (e.g. when iterating over the runs sequentially until the
|
| 127 |
+
/// end). This function uses binary-search, so it has a O(log N) cost.
|
| 128 |
+
int64_t FindPhysicalLength() const;
|
| 129 |
+
};
|
| 130 |
+
|
| 131 |
+
/// @}
|
| 132 |
+
|
| 133 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/builder_adaptive.h
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <cstdint>
|
| 21 |
+
#include <cstring>
|
| 22 |
+
#include <memory>
|
| 23 |
+
#include <type_traits>
|
| 24 |
+
|
| 25 |
+
#include "arrow/array/builder_base.h"
|
| 26 |
+
#include "arrow/buffer.h"
|
| 27 |
+
#include "arrow/status.h"
|
| 28 |
+
#include "arrow/type.h"
|
| 29 |
+
#include "arrow/util/macros.h"
|
| 30 |
+
#include "arrow/util/visibility.h"
|
| 31 |
+
|
| 32 |
+
namespace arrow {
|
| 33 |
+
|
| 34 |
+
/// \addtogroup numeric-builders
|
| 35 |
+
///
|
| 36 |
+
/// @{
|
| 37 |
+
|
| 38 |
+
namespace internal {
|
| 39 |
+
|
| 40 |
+
class ARROW_EXPORT AdaptiveIntBuilderBase : public ArrayBuilder {
|
| 41 |
+
public:
|
| 42 |
+
AdaptiveIntBuilderBase(uint8_t start_int_size, MemoryPool* pool,
|
| 43 |
+
int64_t alignment = kDefaultBufferAlignment);
|
| 44 |
+
|
| 45 |
+
explicit AdaptiveIntBuilderBase(MemoryPool* pool,
|
| 46 |
+
int64_t alignment = kDefaultBufferAlignment)
|
| 47 |
+
: AdaptiveIntBuilderBase(sizeof(uint8_t), pool, alignment) {}
|
| 48 |
+
|
| 49 |
+
/// \brief Append multiple nulls
|
| 50 |
+
/// \param[in] length the number of nulls to append
|
| 51 |
+
Status AppendNulls(int64_t length) final {
|
| 52 |
+
ARROW_RETURN_NOT_OK(CommitPendingData());
|
| 53 |
+
if (ARROW_PREDICT_TRUE(length > 0)) {
|
| 54 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 55 |
+
memset(data_->mutable_data() + length_ * int_size_, 0, int_size_ * length);
|
| 56 |
+
UnsafeSetNull(length);
|
| 57 |
+
}
|
| 58 |
+
return Status::OK();
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
Status AppendNull() final {
|
| 62 |
+
pending_data_[pending_pos_] = 0;
|
| 63 |
+
pending_valid_[pending_pos_] = 0;
|
| 64 |
+
pending_has_nulls_ = true;
|
| 65 |
+
++pending_pos_;
|
| 66 |
+
++length_;
|
| 67 |
+
++null_count_;
|
| 68 |
+
|
| 69 |
+
if (ARROW_PREDICT_FALSE(pending_pos_ >= pending_size_)) {
|
| 70 |
+
return CommitPendingData();
|
| 71 |
+
}
|
| 72 |
+
return Status::OK();
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
Status AppendEmptyValues(int64_t length) final {
|
| 76 |
+
ARROW_RETURN_NOT_OK(CommitPendingData());
|
| 77 |
+
if (ARROW_PREDICT_TRUE(length > 0)) {
|
| 78 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 79 |
+
memset(data_->mutable_data() + length_ * int_size_, 0, int_size_ * length);
|
| 80 |
+
UnsafeSetNotNull(length);
|
| 81 |
+
}
|
| 82 |
+
return Status::OK();
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
Status AppendEmptyValue() final {
|
| 86 |
+
pending_data_[pending_pos_] = 0;
|
| 87 |
+
pending_valid_[pending_pos_] = 1;
|
| 88 |
+
++pending_pos_;
|
| 89 |
+
++length_;
|
| 90 |
+
|
| 91 |
+
if (ARROW_PREDICT_FALSE(pending_pos_ >= pending_size_)) {
|
| 92 |
+
return CommitPendingData();
|
| 93 |
+
}
|
| 94 |
+
return Status::OK();
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
void Reset() override;
|
| 98 |
+
Status Resize(int64_t capacity) override;
|
| 99 |
+
|
| 100 |
+
protected:
|
| 101 |
+
Status AppendInternal(const uint64_t val) {
|
| 102 |
+
pending_data_[pending_pos_] = val;
|
| 103 |
+
pending_valid_[pending_pos_] = 1;
|
| 104 |
+
++pending_pos_;
|
| 105 |
+
++length_;
|
| 106 |
+
|
| 107 |
+
if (ARROW_PREDICT_FALSE(pending_pos_ >= pending_size_)) {
|
| 108 |
+
return CommitPendingData();
|
| 109 |
+
}
|
| 110 |
+
return Status::OK();
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
virtual Status CommitPendingData() = 0;
|
| 114 |
+
|
| 115 |
+
template <typename new_type, typename old_type>
|
| 116 |
+
typename std::enable_if<sizeof(old_type) >= sizeof(new_type), Status>::type
|
| 117 |
+
ExpandIntSizeInternal();
|
| 118 |
+
template <typename new_type, typename old_type>
|
| 119 |
+
typename std::enable_if<(sizeof(old_type) < sizeof(new_type)), Status>::type
|
| 120 |
+
ExpandIntSizeInternal();
|
| 121 |
+
|
| 122 |
+
std::shared_ptr<ResizableBuffer> data_;
|
| 123 |
+
uint8_t* raw_data_ = NULLPTR;
|
| 124 |
+
|
| 125 |
+
const uint8_t start_int_size_;
|
| 126 |
+
uint8_t int_size_;
|
| 127 |
+
|
| 128 |
+
static constexpr int32_t pending_size_ = 1024;
|
| 129 |
+
uint8_t pending_valid_[pending_size_];
|
| 130 |
+
uint64_t pending_data_[pending_size_];
|
| 131 |
+
int32_t pending_pos_ = 0;
|
| 132 |
+
bool pending_has_nulls_ = false;
|
| 133 |
+
};
|
| 134 |
+
|
| 135 |
+
} // namespace internal
|
| 136 |
+
|
| 137 |
+
class ARROW_EXPORT AdaptiveUIntBuilder : public internal::AdaptiveIntBuilderBase {
|
| 138 |
+
public:
|
| 139 |
+
explicit AdaptiveUIntBuilder(uint8_t start_int_size,
|
| 140 |
+
MemoryPool* pool = default_memory_pool());
|
| 141 |
+
|
| 142 |
+
explicit AdaptiveUIntBuilder(MemoryPool* pool = default_memory_pool())
|
| 143 |
+
: AdaptiveUIntBuilder(sizeof(uint8_t), pool) {}
|
| 144 |
+
|
| 145 |
+
using internal::AdaptiveIntBuilderBase::Reset;
|
| 146 |
+
|
| 147 |
+
/// Scalar append
|
| 148 |
+
Status Append(const uint64_t val) { return AppendInternal(val); }
|
| 149 |
+
|
| 150 |
+
/// \brief Append a sequence of elements in one shot
|
| 151 |
+
/// \param[in] values a contiguous C array of values
|
| 152 |
+
/// \param[in] length the number of values to append
|
| 153 |
+
/// \param[in] valid_bytes an optional sequence of bytes where non-zero
|
| 154 |
+
/// indicates a valid (non-null) value
|
| 155 |
+
/// \return Status
|
| 156 |
+
Status AppendValues(const uint64_t* values, int64_t length,
|
| 157 |
+
const uint8_t* valid_bytes = NULLPTR);
|
| 158 |
+
|
| 159 |
+
Status FinishInternal(std::shared_ptr<ArrayData>* out) override;
|
| 160 |
+
|
| 161 |
+
std::shared_ptr<DataType> type() const override;
|
| 162 |
+
|
| 163 |
+
protected:
|
| 164 |
+
Status CommitPendingData() override;
|
| 165 |
+
Status ExpandIntSize(uint8_t new_int_size);
|
| 166 |
+
|
| 167 |
+
Status AppendValuesInternal(const uint64_t* values, int64_t length,
|
| 168 |
+
const uint8_t* valid_bytes);
|
| 169 |
+
|
| 170 |
+
template <typename new_type>
|
| 171 |
+
Status ExpandIntSizeN();
|
| 172 |
+
};
|
| 173 |
+
|
| 174 |
+
class ARROW_EXPORT AdaptiveIntBuilder : public internal::AdaptiveIntBuilderBase {
|
| 175 |
+
public:
|
| 176 |
+
explicit AdaptiveIntBuilder(uint8_t start_int_size,
|
| 177 |
+
MemoryPool* pool = default_memory_pool(),
|
| 178 |
+
int64_t alignment = kDefaultBufferAlignment);
|
| 179 |
+
|
| 180 |
+
explicit AdaptiveIntBuilder(MemoryPool* pool = default_memory_pool(),
|
| 181 |
+
int64_t alignment = kDefaultBufferAlignment)
|
| 182 |
+
: AdaptiveIntBuilder(sizeof(uint8_t), pool, alignment) {}
|
| 183 |
+
|
| 184 |
+
using internal::AdaptiveIntBuilderBase::Reset;
|
| 185 |
+
|
| 186 |
+
/// Scalar append
|
| 187 |
+
Status Append(const int64_t val) { return AppendInternal(static_cast<uint64_t>(val)); }
|
| 188 |
+
|
| 189 |
+
/// \brief Append a sequence of elements in one shot
|
| 190 |
+
/// \param[in] values a contiguous C array of values
|
| 191 |
+
/// \param[in] length the number of values to append
|
| 192 |
+
/// \param[in] valid_bytes an optional sequence of bytes where non-zero
|
| 193 |
+
/// indicates a valid (non-null) value
|
| 194 |
+
/// \return Status
|
| 195 |
+
Status AppendValues(const int64_t* values, int64_t length,
|
| 196 |
+
const uint8_t* valid_bytes = NULLPTR);
|
| 197 |
+
|
| 198 |
+
Status FinishInternal(std::shared_ptr<ArrayData>* out) override;
|
| 199 |
+
|
| 200 |
+
std::shared_ptr<DataType> type() const override;
|
| 201 |
+
|
| 202 |
+
protected:
|
| 203 |
+
Status CommitPendingData() override;
|
| 204 |
+
Status ExpandIntSize(uint8_t new_int_size);
|
| 205 |
+
|
| 206 |
+
Status AppendValuesInternal(const int64_t* values, int64_t length,
|
| 207 |
+
const uint8_t* valid_bytes);
|
| 208 |
+
|
| 209 |
+
template <typename new_type>
|
| 210 |
+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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <array>
|
| 21 |
+
#include <cstddef>
|
| 22 |
+
#include <cstdint>
|
| 23 |
+
#include <cstring>
|
| 24 |
+
#include <limits>
|
| 25 |
+
#include <memory>
|
| 26 |
+
#include <numeric>
|
| 27 |
+
#include <string>
|
| 28 |
+
#include <string_view>
|
| 29 |
+
#include <vector>
|
| 30 |
+
|
| 31 |
+
#include "arrow/array/array_base.h"
|
| 32 |
+
#include "arrow/array/array_binary.h"
|
| 33 |
+
#include "arrow/array/builder_base.h"
|
| 34 |
+
#include "arrow/array/data.h"
|
| 35 |
+
#include "arrow/buffer.h"
|
| 36 |
+
#include "arrow/buffer_builder.h"
|
| 37 |
+
#include "arrow/status.h"
|
| 38 |
+
#include "arrow/type.h"
|
| 39 |
+
#include "arrow/util/binary_view_util.h"
|
| 40 |
+
#include "arrow/util/macros.h"
|
| 41 |
+
#include "arrow/util/visibility.h"
|
| 42 |
+
|
| 43 |
+
namespace arrow {
|
| 44 |
+
|
| 45 |
+
/// \addtogroup binary-builders
|
| 46 |
+
///
|
| 47 |
+
/// @{
|
| 48 |
+
|
| 49 |
+
// ----------------------------------------------------------------------
|
| 50 |
+
// Binary and String
|
| 51 |
+
|
| 52 |
+
template <typename TYPE>
|
| 53 |
+
class BaseBinaryBuilder
|
| 54 |
+
: public ArrayBuilder,
|
| 55 |
+
public internal::ArrayBuilderExtraOps<BaseBinaryBuilder<TYPE>, std::string_view> {
|
| 56 |
+
public:
|
| 57 |
+
using TypeClass = TYPE;
|
| 58 |
+
using offset_type = typename TypeClass::offset_type;
|
| 59 |
+
|
| 60 |
+
explicit BaseBinaryBuilder(MemoryPool* pool = default_memory_pool(),
|
| 61 |
+
int64_t alignment = kDefaultBufferAlignment)
|
| 62 |
+
: ArrayBuilder(pool, alignment),
|
| 63 |
+
offsets_builder_(pool, alignment),
|
| 64 |
+
value_data_builder_(pool, alignment) {}
|
| 65 |
+
|
| 66 |
+
BaseBinaryBuilder(const std::shared_ptr<DataType>& type, MemoryPool* pool)
|
| 67 |
+
: BaseBinaryBuilder(pool) {}
|
| 68 |
+
|
| 69 |
+
Status Append(const uint8_t* value, offset_type length) {
|
| 70 |
+
ARROW_RETURN_NOT_OK(Reserve(1));
|
| 71 |
+
UnsafeAppendNextOffset();
|
| 72 |
+
// Safety check for UBSAN.
|
| 73 |
+
if (ARROW_PREDICT_TRUE(length > 0)) {
|
| 74 |
+
ARROW_RETURN_NOT_OK(ValidateOverflow(length));
|
| 75 |
+
ARROW_RETURN_NOT_OK(value_data_builder_.Append(value, length));
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
UnsafeAppendToBitmap(true);
|
| 79 |
+
return Status::OK();
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
Status Append(const char* value, offset_type length) {
|
| 83 |
+
return Append(reinterpret_cast<const uint8_t*>(value), length);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
Status Append(std::string_view value) {
|
| 87 |
+
return Append(value.data(), static_cast<offset_type>(value.size()));
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/// Extend the last appended value by appending more data at the end
|
| 91 |
+
///
|
| 92 |
+
/// Unlike Append, this does not create a new offset.
|
| 93 |
+
Status ExtendCurrent(const uint8_t* value, offset_type length) {
|
| 94 |
+
// Safety check for UBSAN.
|
| 95 |
+
if (ARROW_PREDICT_TRUE(length > 0)) {
|
| 96 |
+
ARROW_RETURN_NOT_OK(ValidateOverflow(length));
|
| 97 |
+
ARROW_RETURN_NOT_OK(value_data_builder_.Append(value, length));
|
| 98 |
+
}
|
| 99 |
+
return Status::OK();
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
Status ExtendCurrent(std::string_view value) {
|
| 103 |
+
return ExtendCurrent(reinterpret_cast<const uint8_t*>(value.data()),
|
| 104 |
+
static_cast<offset_type>(value.size()));
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
Status AppendNulls(int64_t length) final {
|
| 108 |
+
const int64_t num_bytes = value_data_builder_.length();
|
| 109 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 110 |
+
for (int64_t i = 0; i < length; ++i) {
|
| 111 |
+
offsets_builder_.UnsafeAppend(static_cast<offset_type>(num_bytes));
|
| 112 |
+
}
|
| 113 |
+
UnsafeAppendToBitmap(length, false);
|
| 114 |
+
return Status::OK();
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
Status AppendNull() final {
|
| 118 |
+
ARROW_RETURN_NOT_OK(Reserve(1));
|
| 119 |
+
UnsafeAppendNextOffset();
|
| 120 |
+
UnsafeAppendToBitmap(false);
|
| 121 |
+
return Status::OK();
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
Status AppendEmptyValue() final {
|
| 125 |
+
ARROW_RETURN_NOT_OK(Reserve(1));
|
| 126 |
+
UnsafeAppendNextOffset();
|
| 127 |
+
UnsafeAppendToBitmap(true);
|
| 128 |
+
return Status::OK();
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
Status AppendEmptyValues(int64_t length) final {
|
| 132 |
+
const int64_t num_bytes = value_data_builder_.length();
|
| 133 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 134 |
+
for (int64_t i = 0; i < length; ++i) {
|
| 135 |
+
offsets_builder_.UnsafeAppend(static_cast<offset_type>(num_bytes));
|
| 136 |
+
}
|
| 137 |
+
UnsafeAppendToBitmap(length, true);
|
| 138 |
+
return Status::OK();
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
/// \brief Append without checking capacity
|
| 142 |
+
///
|
| 143 |
+
/// Offsets and data should have been presized using Reserve() and
|
| 144 |
+
/// ReserveData(), respectively.
|
| 145 |
+
void UnsafeAppend(const uint8_t* value, offset_type length) {
|
| 146 |
+
UnsafeAppendNextOffset();
|
| 147 |
+
value_data_builder_.UnsafeAppend(value, length);
|
| 148 |
+
UnsafeAppendToBitmap(true);
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
void UnsafeAppend(const char* value, offset_type length) {
|
| 152 |
+
UnsafeAppend(reinterpret_cast<const uint8_t*>(value), length);
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
void UnsafeAppend(const std::string& value) {
|
| 156 |
+
UnsafeAppend(value.c_str(), static_cast<offset_type>(value.size()));
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
void UnsafeAppend(std::string_view value) {
|
| 160 |
+
UnsafeAppend(value.data(), static_cast<offset_type>(value.size()));
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
/// Like ExtendCurrent, but do not check capacity
|
| 164 |
+
void UnsafeExtendCurrent(const uint8_t* value, offset_type length) {
|
| 165 |
+
value_data_builder_.UnsafeAppend(value, length);
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
void UnsafeExtendCurrent(std::string_view value) {
|
| 169 |
+
UnsafeExtendCurrent(reinterpret_cast<const uint8_t*>(value.data()),
|
| 170 |
+
static_cast<offset_type>(value.size()));
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
void UnsafeAppendNull() {
|
| 174 |
+
const int64_t num_bytes = value_data_builder_.length();
|
| 175 |
+
offsets_builder_.UnsafeAppend(static_cast<offset_type>(num_bytes));
|
| 176 |
+
UnsafeAppendToBitmap(false);
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
void UnsafeAppendEmptyValue() {
|
| 180 |
+
const int64_t num_bytes = value_data_builder_.length();
|
| 181 |
+
offsets_builder_.UnsafeAppend(static_cast<offset_type>(num_bytes));
|
| 182 |
+
UnsafeAppendToBitmap(true);
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
/// \brief Append a sequence of strings in one shot.
|
| 186 |
+
///
|
| 187 |
+
/// \param[in] values a vector of strings
|
| 188 |
+
/// \param[in] valid_bytes an optional sequence of bytes where non-zero
|
| 189 |
+
/// indicates a valid (non-null) value
|
| 190 |
+
/// \return Status
|
| 191 |
+
Status AppendValues(const std::vector<std::string>& values,
|
| 192 |
+
const uint8_t* valid_bytes = NULLPTR) {
|
| 193 |
+
std::size_t total_length = std::accumulate(
|
| 194 |
+
values.begin(), values.end(), 0ULL,
|
| 195 |
+
[](uint64_t sum, const std::string& str) { return sum + str.size(); });
|
| 196 |
+
ARROW_RETURN_NOT_OK(Reserve(values.size()));
|
| 197 |
+
ARROW_RETURN_NOT_OK(ReserveData(total_length));
|
| 198 |
+
|
| 199 |
+
if (valid_bytes != NULLPTR) {
|
| 200 |
+
for (std::size_t i = 0; i < values.size(); ++i) {
|
| 201 |
+
UnsafeAppendNextOffset();
|
| 202 |
+
if (valid_bytes[i]) {
|
| 203 |
+
value_data_builder_.UnsafeAppend(
|
| 204 |
+
reinterpret_cast<const uint8_t*>(values[i].data()), values[i].size());
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
} else {
|
| 208 |
+
for (const auto& value : values) {
|
| 209 |
+
UnsafeAppendNextOffset();
|
| 210 |
+
value_data_builder_.UnsafeAppend(reinterpret_cast<const uint8_t*>(value.data()),
|
| 211 |
+
value.size());
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
UnsafeAppendToBitmap(valid_bytes, values.size());
|
| 216 |
+
return Status::OK();
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/// \brief Append a sequence of nul-terminated strings in one shot.
|
| 220 |
+
/// If one of the values is NULL, it is processed as a null
|
| 221 |
+
/// value even if the corresponding valid_bytes entry is 1.
|
| 222 |
+
///
|
| 223 |
+
/// \param[in] values a contiguous C array of nul-terminated char *
|
| 224 |
+
/// \param[in] length the number of values to append
|
| 225 |
+
/// \param[in] valid_bytes an optional sequence of bytes where non-zero
|
| 226 |
+
/// indicates a valid (non-null) value
|
| 227 |
+
/// \return Status
|
| 228 |
+
Status AppendValues(const char** values, int64_t length,
|
| 229 |
+
const uint8_t* valid_bytes = NULLPTR) {
|
| 230 |
+
std::size_t total_length = 0;
|
| 231 |
+
std::vector<std::size_t> value_lengths(length);
|
| 232 |
+
bool have_null_value = false;
|
| 233 |
+
for (int64_t i = 0; i < length; ++i) {
|
| 234 |
+
if (values[i] != NULLPTR) {
|
| 235 |
+
auto value_length = strlen(values[i]);
|
| 236 |
+
value_lengths[i] = value_length;
|
| 237 |
+
total_length += value_length;
|
| 238 |
+
} else {
|
| 239 |
+
have_null_value = true;
|
| 240 |
+
}
|
| 241 |
+
}
|
| 242 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 243 |
+
ARROW_RETURN_NOT_OK(ReserveData(total_length));
|
| 244 |
+
|
| 245 |
+
if (valid_bytes) {
|
| 246 |
+
int64_t valid_bytes_offset = 0;
|
| 247 |
+
for (int64_t i = 0; i < length; ++i) {
|
| 248 |
+
UnsafeAppendNextOffset();
|
| 249 |
+
if (valid_bytes[i]) {
|
| 250 |
+
if (values[i]) {
|
| 251 |
+
value_data_builder_.UnsafeAppend(reinterpret_cast<const uint8_t*>(values[i]),
|
| 252 |
+
value_lengths[i]);
|
| 253 |
+
} else {
|
| 254 |
+
UnsafeAppendToBitmap(valid_bytes + valid_bytes_offset,
|
| 255 |
+
i - valid_bytes_offset);
|
| 256 |
+
UnsafeAppendToBitmap(false);
|
| 257 |
+
valid_bytes_offset = i + 1;
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
}
|
| 261 |
+
UnsafeAppendToBitmap(valid_bytes + valid_bytes_offset, length - valid_bytes_offset);
|
| 262 |
+
} else {
|
| 263 |
+
if (have_null_value) {
|
| 264 |
+
std::vector<uint8_t> valid_vector(length, 0);
|
| 265 |
+
for (int64_t i = 0; i < length; ++i) {
|
| 266 |
+
UnsafeAppendNextOffset();
|
| 267 |
+
if (values[i]) {
|
| 268 |
+
value_data_builder_.UnsafeAppend(reinterpret_cast<const uint8_t*>(values[i]),
|
| 269 |
+
value_lengths[i]);
|
| 270 |
+
valid_vector[i] = 1;
|
| 271 |
+
}
|
| 272 |
+
}
|
| 273 |
+
UnsafeAppendToBitmap(valid_vector.data(), length);
|
| 274 |
+
} else {
|
| 275 |
+
for (int64_t i = 0; i < length; ++i) {
|
| 276 |
+
UnsafeAppendNextOffset();
|
| 277 |
+
value_data_builder_.UnsafeAppend(reinterpret_cast<const uint8_t*>(values[i]),
|
| 278 |
+
value_lengths[i]);
|
| 279 |
+
}
|
| 280 |
+
UnsafeAppendToBitmap(NULLPTR, length);
|
| 281 |
+
}
|
| 282 |
+
}
|
| 283 |
+
return Status::OK();
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
Status AppendArraySlice(const ArraySpan& array, int64_t offset,
|
| 287 |
+
int64_t length) override {
|
| 288 |
+
auto bitmap = array.GetValues<uint8_t>(0, 0);
|
| 289 |
+
auto offsets = array.GetValues<offset_type>(1);
|
| 290 |
+
auto data = array.GetValues<uint8_t>(2, 0);
|
| 291 |
+
auto total_length = offsets[offset + length] - offsets[offset];
|
| 292 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 293 |
+
ARROW_RETURN_NOT_OK(ReserveData(total_length));
|
| 294 |
+
for (int64_t i = 0; i < length; i++) {
|
| 295 |
+
if (!bitmap || bit_util::GetBit(bitmap, array.offset + offset + i)) {
|
| 296 |
+
const offset_type start = offsets[offset + i];
|
| 297 |
+
const offset_type end = offsets[offset + i + 1];
|
| 298 |
+
UnsafeAppend(data + start, end - start);
|
| 299 |
+
} else {
|
| 300 |
+
UnsafeAppendNull();
|
| 301 |
+
}
|
| 302 |
+
}
|
| 303 |
+
return Status::OK();
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
void Reset() override {
|
| 307 |
+
ArrayBuilder::Reset();
|
| 308 |
+
offsets_builder_.Reset();
|
| 309 |
+
value_data_builder_.Reset();
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
Status ValidateOverflow(int64_t new_bytes) {
|
| 313 |
+
auto new_size = value_data_builder_.length() + new_bytes;
|
| 314 |
+
if (ARROW_PREDICT_FALSE(new_size > memory_limit())) {
|
| 315 |
+
return Status::CapacityError("array cannot contain more than ", memory_limit(),
|
| 316 |
+
" bytes, have ", new_size);
|
| 317 |
+
} else {
|
| 318 |
+
return Status::OK();
|
| 319 |
+
}
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
Status Resize(int64_t capacity) override {
|
| 323 |
+
ARROW_RETURN_NOT_OK(CheckCapacity(capacity));
|
| 324 |
+
// One more than requested for offsets
|
| 325 |
+
ARROW_RETURN_NOT_OK(offsets_builder_.Resize(capacity + 1));
|
| 326 |
+
return ArrayBuilder::Resize(capacity);
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
/// \brief Ensures there is enough allocated capacity to append the indicated
|
| 330 |
+
/// number of bytes to the value data buffer without additional allocations
|
| 331 |
+
Status ReserveData(int64_t elements) {
|
| 332 |
+
ARROW_RETURN_NOT_OK(ValidateOverflow(elements));
|
| 333 |
+
return value_data_builder_.Reserve(elements);
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
Status FinishInternal(std::shared_ptr<ArrayData>* out) override {
|
| 337 |
+
// Write final offset (values length)
|
| 338 |
+
ARROW_RETURN_NOT_OK(AppendNextOffset());
|
| 339 |
+
|
| 340 |
+
// These buffers' padding zeroed by BufferBuilder
|
| 341 |
+
std::shared_ptr<Buffer> offsets, value_data, null_bitmap;
|
| 342 |
+
ARROW_RETURN_NOT_OK(offsets_builder_.Finish(&offsets));
|
| 343 |
+
ARROW_RETURN_NOT_OK(value_data_builder_.Finish(&value_data));
|
| 344 |
+
ARROW_RETURN_NOT_OK(null_bitmap_builder_.Finish(&null_bitmap));
|
| 345 |
+
|
| 346 |
+
*out = ArrayData::Make(type(), length_, {null_bitmap, offsets, value_data},
|
| 347 |
+
null_count_, 0);
|
| 348 |
+
Reset();
|
| 349 |
+
return Status::OK();
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
/// \return data pointer of the value date builder
|
| 353 |
+
const uint8_t* value_data() const { return value_data_builder_.data(); }
|
| 354 |
+
/// \return size of values buffer so far
|
| 355 |
+
int64_t value_data_length() const { return value_data_builder_.length(); }
|
| 356 |
+
/// \return capacity of values buffer
|
| 357 |
+
int64_t value_data_capacity() const { return value_data_builder_.capacity(); }
|
| 358 |
+
|
| 359 |
+
/// \return data pointer of the value date builder
|
| 360 |
+
const offset_type* offsets_data() const { return offsets_builder_.data(); }
|
| 361 |
+
|
| 362 |
+
/// Temporary access to a value.
|
| 363 |
+
///
|
| 364 |
+
/// This pointer becomes invalid on the next modifying operation.
|
| 365 |
+
const uint8_t* GetValue(int64_t i, offset_type* out_length) const {
|
| 366 |
+
const offset_type* offsets = offsets_builder_.data();
|
| 367 |
+
const auto offset = offsets[i];
|
| 368 |
+
if (i == (length_ - 1)) {
|
| 369 |
+
*out_length = static_cast<offset_type>(value_data_builder_.length()) - offset;
|
| 370 |
+
} else {
|
| 371 |
+
*out_length = offsets[i + 1] - offset;
|
| 372 |
+
}
|
| 373 |
+
return value_data_builder_.data() + offset;
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
offset_type offset(int64_t i) const { return offsets_data()[i]; }
|
| 377 |
+
|
| 378 |
+
/// Temporary access to a value.
|
| 379 |
+
///
|
| 380 |
+
/// This view becomes invalid on the next modifying operation.
|
| 381 |
+
std::string_view GetView(int64_t i) const {
|
| 382 |
+
offset_type value_length;
|
| 383 |
+
const uint8_t* value_data = GetValue(i, &value_length);
|
| 384 |
+
return std::string_view(reinterpret_cast<const char*>(value_data), value_length);
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
// Cannot make this a static attribute because of linking issues
|
| 388 |
+
static constexpr int64_t memory_limit() {
|
| 389 |
+
return std::numeric_limits<offset_type>::max() - 1;
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
protected:
|
| 393 |
+
TypedBufferBuilder<offset_type> offsets_builder_;
|
| 394 |
+
TypedBufferBuilder<uint8_t> value_data_builder_;
|
| 395 |
+
|
| 396 |
+
Status AppendNextOffset() {
|
| 397 |
+
const int64_t num_bytes = value_data_builder_.length();
|
| 398 |
+
return offsets_builder_.Append(static_cast<offset_type>(num_bytes));
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
void UnsafeAppendNextOffset() {
|
| 402 |
+
const int64_t num_bytes = value_data_builder_.length();
|
| 403 |
+
offsets_builder_.UnsafeAppend(static_cast<offset_type>(num_bytes));
|
| 404 |
+
}
|
| 405 |
+
};
|
| 406 |
+
|
| 407 |
+
/// \class BinaryBuilder
|
| 408 |
+
/// \brief Builder class for variable-length binary data
|
| 409 |
+
class ARROW_EXPORT BinaryBuilder : public BaseBinaryBuilder<BinaryType> {
|
| 410 |
+
public:
|
| 411 |
+
using BaseBinaryBuilder::BaseBinaryBuilder;
|
| 412 |
+
|
| 413 |
+
/// \cond FALSE
|
| 414 |
+
using ArrayBuilder::Finish;
|
| 415 |
+
/// \endcond
|
| 416 |
+
|
| 417 |
+
Status Finish(std::shared_ptr<BinaryArray>* out) { return FinishTyped(out); }
|
| 418 |
+
|
| 419 |
+
std::shared_ptr<DataType> type() const override { return binary(); }
|
| 420 |
+
};
|
| 421 |
+
|
| 422 |
+
/// \class StringBuilder
|
| 423 |
+
/// \brief Builder class for UTF8 strings
|
| 424 |
+
class ARROW_EXPORT StringBuilder : public BinaryBuilder {
|
| 425 |
+
public:
|
| 426 |
+
using BinaryBuilder::BinaryBuilder;
|
| 427 |
+
|
| 428 |
+
/// \cond FALSE
|
| 429 |
+
using ArrayBuilder::Finish;
|
| 430 |
+
/// \endcond
|
| 431 |
+
|
| 432 |
+
Status Finish(std::shared_ptr<StringArray>* out) { return FinishTyped(out); }
|
| 433 |
+
|
| 434 |
+
std::shared_ptr<DataType> type() const override { return utf8(); }
|
| 435 |
+
};
|
| 436 |
+
|
| 437 |
+
/// \class LargeBinaryBuilder
|
| 438 |
+
/// \brief Builder class for large variable-length binary data
|
| 439 |
+
class ARROW_EXPORT LargeBinaryBuilder : public BaseBinaryBuilder<LargeBinaryType> {
|
| 440 |
+
public:
|
| 441 |
+
using BaseBinaryBuilder::BaseBinaryBuilder;
|
| 442 |
+
|
| 443 |
+
/// \cond FALSE
|
| 444 |
+
using ArrayBuilder::Finish;
|
| 445 |
+
/// \endcond
|
| 446 |
+
|
| 447 |
+
Status Finish(std::shared_ptr<LargeBinaryArray>* out) { return FinishTyped(out); }
|
| 448 |
+
|
| 449 |
+
std::shared_ptr<DataType> type() const override { return large_binary(); }
|
| 450 |
+
};
|
| 451 |
+
|
| 452 |
+
/// \class LargeStringBuilder
|
| 453 |
+
/// \brief Builder class for large UTF8 strings
|
| 454 |
+
class ARROW_EXPORT LargeStringBuilder : public LargeBinaryBuilder {
|
| 455 |
+
public:
|
| 456 |
+
using LargeBinaryBuilder::LargeBinaryBuilder;
|
| 457 |
+
|
| 458 |
+
/// \cond FALSE
|
| 459 |
+
using ArrayBuilder::Finish;
|
| 460 |
+
/// \endcond
|
| 461 |
+
|
| 462 |
+
Status Finish(std::shared_ptr<LargeStringArray>* out) { return FinishTyped(out); }
|
| 463 |
+
|
| 464 |
+
std::shared_ptr<DataType> type() const override { return large_utf8(); }
|
| 465 |
+
};
|
| 466 |
+
|
| 467 |
+
// ----------------------------------------------------------------------
|
| 468 |
+
// BinaryViewBuilder, StringViewBuilder
|
| 469 |
+
//
|
| 470 |
+
// These builders do not support building raw pointer view arrays.
|
| 471 |
+
|
| 472 |
+
namespace internal {
|
| 473 |
+
|
| 474 |
+
// We allocate medium-sized memory chunks and accumulate data in those, which
|
| 475 |
+
// may result in some waste if there are many large-ish strings. If a string
|
| 476 |
+
// comes along that does not fit into a block, we allocate a new block and
|
| 477 |
+
// write into that.
|
| 478 |
+
//
|
| 479 |
+
// Later we can implement optimizations to continuing filling underfull blocks
|
| 480 |
+
// after encountering a large string that required allocating a new block.
|
| 481 |
+
class ARROW_EXPORT StringHeapBuilder {
|
| 482 |
+
public:
|
| 483 |
+
static constexpr int64_t kDefaultBlocksize = 32 << 10; // 32KB
|
| 484 |
+
|
| 485 |
+
StringHeapBuilder(MemoryPool* pool, int64_t alignment)
|
| 486 |
+
: pool_(pool), alignment_(alignment) {}
|
| 487 |
+
|
| 488 |
+
void SetBlockSize(int64_t blocksize) { blocksize_ = blocksize; }
|
| 489 |
+
|
| 490 |
+
using c_type = BinaryViewType::c_type;
|
| 491 |
+
|
| 492 |
+
template <bool Safe>
|
| 493 |
+
std::conditional_t<Safe, Result<c_type>, c_type> Append(const uint8_t* value,
|
| 494 |
+
int64_t length) {
|
| 495 |
+
if (length <= BinaryViewType::kInlineSize) {
|
| 496 |
+
return util::ToInlineBinaryView(value, static_cast<int32_t>(length));
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
if constexpr (Safe) {
|
| 500 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
auto v =
|
| 504 |
+
util::ToBinaryView(value, static_cast<int32_t>(length),
|
| 505 |
+
static_cast<int32_t>(blocks_.size() - 1), current_offset_);
|
| 506 |
+
|
| 507 |
+
memcpy(current_out_buffer_, value, static_cast<size_t>(length));
|
| 508 |
+
current_out_buffer_ += length;
|
| 509 |
+
current_remaining_bytes_ -= length;
|
| 510 |
+
current_offset_ += static_cast<int32_t>(length);
|
| 511 |
+
return v;
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
static constexpr int64_t ValueSizeLimit() {
|
| 515 |
+
return std::numeric_limits<int32_t>::max();
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
/// \brief Ensure that the indicated number of bytes can be appended via
|
| 519 |
+
/// UnsafeAppend operations without the need to allocate more memory
|
| 520 |
+
Status Reserve(int64_t num_bytes) {
|
| 521 |
+
if (ARROW_PREDICT_FALSE(num_bytes > ValueSizeLimit())) {
|
| 522 |
+
return Status::CapacityError(
|
| 523 |
+
"BinaryView or StringView elements cannot reference "
|
| 524 |
+
"strings larger than 2GB");
|
| 525 |
+
}
|
| 526 |
+
if (num_bytes > current_remaining_bytes_) {
|
| 527 |
+
ARROW_RETURN_NOT_OK(FinishLastBlock());
|
| 528 |
+
current_remaining_bytes_ = num_bytes > blocksize_ ? num_bytes : blocksize_;
|
| 529 |
+
ARROW_ASSIGN_OR_RAISE(
|
| 530 |
+
std::shared_ptr<ResizableBuffer> new_block,
|
| 531 |
+
AllocateResizableBuffer(current_remaining_bytes_, alignment_, pool_));
|
| 532 |
+
current_offset_ = 0;
|
| 533 |
+
current_out_buffer_ = new_block->mutable_data();
|
| 534 |
+
blocks_.emplace_back(std::move(new_block));
|
| 535 |
+
}
|
| 536 |
+
return Status::OK();
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
void Reset() {
|
| 540 |
+
current_offset_ = 0;
|
| 541 |
+
current_out_buffer_ = NULLPTR;
|
| 542 |
+
current_remaining_bytes_ = 0;
|
| 543 |
+
blocks_.clear();
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
int64_t current_remaining_bytes() const { return current_remaining_bytes_; }
|
| 547 |
+
|
| 548 |
+
Result<std::vector<std::shared_ptr<ResizableBuffer>>> Finish() {
|
| 549 |
+
if (!blocks_.empty()) {
|
| 550 |
+
ARROW_RETURN_NOT_OK(FinishLastBlock());
|
| 551 |
+
}
|
| 552 |
+
current_offset_ = 0;
|
| 553 |
+
current_out_buffer_ = NULLPTR;
|
| 554 |
+
current_remaining_bytes_ = 0;
|
| 555 |
+
return std::move(blocks_);
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
private:
|
| 559 |
+
Status FinishLastBlock() {
|
| 560 |
+
if (current_remaining_bytes_ > 0) {
|
| 561 |
+
// Avoid leaking uninitialized bytes from the allocator
|
| 562 |
+
ARROW_RETURN_NOT_OK(
|
| 563 |
+
blocks_.back()->Resize(blocks_.back()->size() - current_remaining_bytes_,
|
| 564 |
+
/*shrink_to_fit=*/true));
|
| 565 |
+
blocks_.back()->ZeroPadding();
|
| 566 |
+
}
|
| 567 |
+
return Status::OK();
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
MemoryPool* pool_;
|
| 571 |
+
int64_t alignment_;
|
| 572 |
+
int64_t blocksize_ = kDefaultBlocksize;
|
| 573 |
+
std::vector<std::shared_ptr<ResizableBuffer>> blocks_;
|
| 574 |
+
|
| 575 |
+
int32_t current_offset_ = 0;
|
| 576 |
+
uint8_t* current_out_buffer_ = NULLPTR;
|
| 577 |
+
int64_t current_remaining_bytes_ = 0;
|
| 578 |
+
};
|
| 579 |
+
|
| 580 |
+
} // namespace internal
|
| 581 |
+
|
| 582 |
+
class ARROW_EXPORT BinaryViewBuilder : public ArrayBuilder {
|
| 583 |
+
public:
|
| 584 |
+
using TypeClass = BinaryViewType;
|
| 585 |
+
|
| 586 |
+
// this constructor provided for MakeBuilder compatibility
|
| 587 |
+
BinaryViewBuilder(const std::shared_ptr<DataType>&, MemoryPool* pool);
|
| 588 |
+
|
| 589 |
+
explicit BinaryViewBuilder(MemoryPool* pool = default_memory_pool(),
|
| 590 |
+
int64_t alignment = kDefaultBufferAlignment)
|
| 591 |
+
: ArrayBuilder(pool, alignment),
|
| 592 |
+
data_builder_(pool, alignment),
|
| 593 |
+
data_heap_builder_(pool, alignment) {}
|
| 594 |
+
|
| 595 |
+
/// Set the size for future preallocated data buffers.
|
| 596 |
+
///
|
| 597 |
+
/// The default size is 32KB, so after each 32KB of string data appended to the builder
|
| 598 |
+
/// a new data buffer will be allocated. Adjust this to a larger value to decrease the
|
| 599 |
+
/// frequency of allocation, or to a smaller value to lower the overhead of each
|
| 600 |
+
/// allocation.
|
| 601 |
+
void SetBlockSize(int64_t blocksize) { data_heap_builder_.SetBlockSize(blocksize); }
|
| 602 |
+
|
| 603 |
+
/// The number of bytes which can be appended to this builder without allocating another
|
| 604 |
+
/// data buffer.
|
| 605 |
+
int64_t current_block_bytes_remaining() const {
|
| 606 |
+
return data_heap_builder_.current_remaining_bytes();
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
Status Append(const uint8_t* value, int64_t length) {
|
| 610 |
+
ARROW_RETURN_NOT_OK(Reserve(1));
|
| 611 |
+
UnsafeAppendToBitmap(true);
|
| 612 |
+
ARROW_ASSIGN_OR_RAISE(auto v,
|
| 613 |
+
data_heap_builder_.Append</*Safe=*/true>(value, length));
|
| 614 |
+
data_builder_.UnsafeAppend(v);
|
| 615 |
+
return Status::OK();
|
| 616 |
+
}
|
| 617 |
+
|
| 618 |
+
Status Append(const char* value, int64_t length) {
|
| 619 |
+
return Append(reinterpret_cast<const uint8_t*>(value), length);
|
| 620 |
+
}
|
| 621 |
+
|
| 622 |
+
Status Append(std::string_view value) {
|
| 623 |
+
return Append(value.data(), static_cast<int64_t>(value.size()));
|
| 624 |
+
}
|
| 625 |
+
|
| 626 |
+
/// \brief Append without checking capacity
|
| 627 |
+
///
|
| 628 |
+
/// Builder should have been presized using Reserve() and ReserveData(),
|
| 629 |
+
/// respectively, and the value must not be larger than 2GB
|
| 630 |
+
void UnsafeAppend(const uint8_t* value, int64_t length) {
|
| 631 |
+
UnsafeAppendToBitmap(true);
|
| 632 |
+
auto v = data_heap_builder_.Append</*Safe=*/false>(value, length);
|
| 633 |
+
data_builder_.UnsafeAppend(v);
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
void UnsafeAppend(const char* value, int64_t length) {
|
| 637 |
+
UnsafeAppend(reinterpret_cast<const uint8_t*>(value), length);
|
| 638 |
+
}
|
| 639 |
+
|
| 640 |
+
void UnsafeAppend(const std::string& value) {
|
| 641 |
+
UnsafeAppend(value.c_str(), static_cast<int64_t>(value.size()));
|
| 642 |
+
}
|
| 643 |
+
|
| 644 |
+
void UnsafeAppend(std::string_view value) {
|
| 645 |
+
UnsafeAppend(value.data(), static_cast<int64_t>(value.size()));
|
| 646 |
+
}
|
| 647 |
+
|
| 648 |
+
/// \brief Ensures there is enough allocated available capacity in the
|
| 649 |
+
/// out-of-line data heap to append the indicated number of bytes without
|
| 650 |
+
/// additional allocations
|
| 651 |
+
Status ReserveData(int64_t length);
|
| 652 |
+
|
| 653 |
+
Status AppendNulls(int64_t length) final {
|
| 654 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 655 |
+
data_builder_.UnsafeAppend(length, BinaryViewType::c_type{});
|
| 656 |
+
UnsafeSetNull(length);
|
| 657 |
+
return Status::OK();
|
| 658 |
+
}
|
| 659 |
+
|
| 660 |
+
/// \brief Append a single null element
|
| 661 |
+
Status AppendNull() final {
|
| 662 |
+
ARROW_RETURN_NOT_OK(Reserve(1));
|
| 663 |
+
data_builder_.UnsafeAppend(BinaryViewType::c_type{});
|
| 664 |
+
UnsafeAppendToBitmap(false);
|
| 665 |
+
return Status::OK();
|
| 666 |
+
}
|
| 667 |
+
|
| 668 |
+
/// \brief Append a empty element (length-0 inline string)
|
| 669 |
+
Status AppendEmptyValue() final {
|
| 670 |
+
ARROW_RETURN_NOT_OK(Reserve(1));
|
| 671 |
+
data_builder_.UnsafeAppend(BinaryViewType::c_type{});
|
| 672 |
+
UnsafeAppendToBitmap(true);
|
| 673 |
+
return Status::OK();
|
| 674 |
+
}
|
| 675 |
+
|
| 676 |
+
/// \brief Append several empty elements
|
| 677 |
+
Status AppendEmptyValues(int64_t length) final {
|
| 678 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 679 |
+
data_builder_.UnsafeAppend(length, BinaryViewType::c_type{});
|
| 680 |
+
UnsafeSetNotNull(length);
|
| 681 |
+
return Status::OK();
|
| 682 |
+
}
|
| 683 |
+
|
| 684 |
+
void UnsafeAppendNull() {
|
| 685 |
+
data_builder_.UnsafeAppend(BinaryViewType::c_type{});
|
| 686 |
+
UnsafeAppendToBitmap(false);
|
| 687 |
+
}
|
| 688 |
+
|
| 689 |
+
void UnsafeAppendEmptyValue() {
|
| 690 |
+
data_builder_.UnsafeAppend(BinaryViewType::c_type{});
|
| 691 |
+
UnsafeAppendToBitmap(true);
|
| 692 |
+
}
|
| 693 |
+
|
| 694 |
+
/// \brief Append a slice of a BinaryViewArray passed as an ArraySpan. Copies
|
| 695 |
+
/// the underlying out-of-line string memory to avoid memory lifetime issues
|
| 696 |
+
Status AppendArraySlice(const ArraySpan& array, int64_t offset,
|
| 697 |
+
int64_t length) override;
|
| 698 |
+
|
| 699 |
+
void Reset() override;
|
| 700 |
+
|
| 701 |
+
Status Resize(int64_t capacity) override {
|
| 702 |
+
ARROW_RETURN_NOT_OK(CheckCapacity(capacity));
|
| 703 |
+
capacity = std::max(capacity, kMinBuilderCapacity);
|
| 704 |
+
ARROW_RETURN_NOT_OK(data_builder_.Resize(capacity));
|
| 705 |
+
return ArrayBuilder::Resize(capacity);
|
| 706 |
+
}
|
| 707 |
+
|
| 708 |
+
Status FinishInternal(std::shared_ptr<ArrayData>* out) override;
|
| 709 |
+
|
| 710 |
+
std::shared_ptr<DataType> type() const override { return binary_view(); }
|
| 711 |
+
|
| 712 |
+
protected:
|
| 713 |
+
TypedBufferBuilder<BinaryViewType::c_type> data_builder_;
|
| 714 |
+
|
| 715 |
+
// Accumulates out-of-line data in fixed-size chunks which are then attached
|
| 716 |
+
// to the resulting ArrayData
|
| 717 |
+
internal::StringHeapBuilder data_heap_builder_;
|
| 718 |
+
};
|
| 719 |
+
|
| 720 |
+
class ARROW_EXPORT StringViewBuilder : public BinaryViewBuilder {
|
| 721 |
+
public:
|
| 722 |
+
using BinaryViewBuilder::BinaryViewBuilder;
|
| 723 |
+
std::shared_ptr<DataType> type() const override { return utf8_view(); }
|
| 724 |
+
};
|
| 725 |
+
|
| 726 |
+
// ----------------------------------------------------------------------
|
| 727 |
+
// FixedSizeBinaryBuilder
|
| 728 |
+
|
| 729 |
+
class ARROW_EXPORT FixedSizeBinaryBuilder : public ArrayBuilder {
|
| 730 |
+
public:
|
| 731 |
+
using TypeClass = FixedSizeBinaryType;
|
| 732 |
+
|
| 733 |
+
explicit FixedSizeBinaryBuilder(const std::shared_ptr<DataType>& type,
|
| 734 |
+
MemoryPool* pool = default_memory_pool(),
|
| 735 |
+
int64_t alignment = kDefaultBufferAlignment);
|
| 736 |
+
|
| 737 |
+
Status Append(const uint8_t* value) {
|
| 738 |
+
ARROW_RETURN_NOT_OK(Reserve(1));
|
| 739 |
+
UnsafeAppend(value);
|
| 740 |
+
return Status::OK();
|
| 741 |
+
}
|
| 742 |
+
|
| 743 |
+
Status Append(const char* value) {
|
| 744 |
+
return Append(reinterpret_cast<const uint8_t*>(value));
|
| 745 |
+
}
|
| 746 |
+
|
| 747 |
+
Status Append(std::string_view view) {
|
| 748 |
+
ARROW_RETURN_NOT_OK(Reserve(1));
|
| 749 |
+
UnsafeAppend(view);
|
| 750 |
+
return Status::OK();
|
| 751 |
+
}
|
| 752 |
+
|
| 753 |
+
Status Append(const std::string& s) {
|
| 754 |
+
ARROW_RETURN_NOT_OK(Reserve(1));
|
| 755 |
+
UnsafeAppend(s);
|
| 756 |
+
return Status::OK();
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
Status Append(const Buffer& s) {
|
| 760 |
+
ARROW_RETURN_NOT_OK(Reserve(1));
|
| 761 |
+
UnsafeAppend(s);
|
| 762 |
+
return Status::OK();
|
| 763 |
+
}
|
| 764 |
+
|
| 765 |
+
Status Append(const std::shared_ptr<Buffer>& s) { return Append(*s); }
|
| 766 |
+
|
| 767 |
+
template <size_t NBYTES>
|
| 768 |
+
Status Append(const std::array<uint8_t, NBYTES>& value) {
|
| 769 |
+
ARROW_RETURN_NOT_OK(Reserve(1));
|
| 770 |
+
UnsafeAppend(
|
| 771 |
+
std::string_view(reinterpret_cast<const char*>(value.data()), value.size()));
|
| 772 |
+
return Status::OK();
|
| 773 |
+
}
|
| 774 |
+
|
| 775 |
+
Status AppendValues(const uint8_t* data, int64_t length,
|
| 776 |
+
const uint8_t* valid_bytes = NULLPTR);
|
| 777 |
+
|
| 778 |
+
Status AppendValues(const uint8_t* data, int64_t length, const uint8_t* validity,
|
| 779 |
+
int64_t bitmap_offset);
|
| 780 |
+
|
| 781 |
+
Status AppendNull() final;
|
| 782 |
+
Status AppendNulls(int64_t length) final;
|
| 783 |
+
|
| 784 |
+
Status AppendEmptyValue() final;
|
| 785 |
+
Status AppendEmptyValues(int64_t length) final;
|
| 786 |
+
|
| 787 |
+
Status AppendArraySlice(const ArraySpan& array, int64_t offset,
|
| 788 |
+
int64_t length) override {
|
| 789 |
+
return AppendValues(
|
| 790 |
+
array.GetValues<uint8_t>(1, 0) + ((array.offset + offset) * byte_width_), length,
|
| 791 |
+
array.GetValues<uint8_t>(0, 0), array.offset + offset);
|
| 792 |
+
}
|
| 793 |
+
|
| 794 |
+
void UnsafeAppend(const uint8_t* value) {
|
| 795 |
+
UnsafeAppendToBitmap(true);
|
| 796 |
+
if (ARROW_PREDICT_TRUE(byte_width_ > 0)) {
|
| 797 |
+
byte_builder_.UnsafeAppend(value, byte_width_);
|
| 798 |
+
}
|
| 799 |
+
}
|
| 800 |
+
|
| 801 |
+
void UnsafeAppend(const char* value) {
|
| 802 |
+
UnsafeAppend(reinterpret_cast<const uint8_t*>(value));
|
| 803 |
+
}
|
| 804 |
+
|
| 805 |
+
void UnsafeAppend(std::string_view value) {
|
| 806 |
+
#ifndef NDEBUG
|
| 807 |
+
CheckValueSize(static_cast<size_t>(value.size()));
|
| 808 |
+
#endif
|
| 809 |
+
UnsafeAppend(reinterpret_cast<const uint8_t*>(value.data()));
|
| 810 |
+
}
|
| 811 |
+
|
| 812 |
+
void UnsafeAppend(const Buffer& s) { UnsafeAppend(std::string_view{s}); }
|
| 813 |
+
|
| 814 |
+
void UnsafeAppend(const std::shared_ptr<Buffer>& s) { UnsafeAppend(*s); }
|
| 815 |
+
|
| 816 |
+
void UnsafeAppendNull() {
|
| 817 |
+
UnsafeAppendToBitmap(false);
|
| 818 |
+
byte_builder_.UnsafeAppend(/*num_copies=*/byte_width_, 0);
|
| 819 |
+
}
|
| 820 |
+
|
| 821 |
+
Status ValidateOverflow(int64_t new_bytes) const {
|
| 822 |
+
auto new_size = byte_builder_.length() + new_bytes;
|
| 823 |
+
if (ARROW_PREDICT_FALSE(new_size > memory_limit())) {
|
| 824 |
+
return Status::CapacityError("array cannot contain more than ", memory_limit(),
|
| 825 |
+
" bytes, have ", new_size);
|
| 826 |
+
} else {
|
| 827 |
+
return Status::OK();
|
| 828 |
+
}
|
| 829 |
+
}
|
| 830 |
+
|
| 831 |
+
/// \brief Ensures there is enough allocated capacity to append the indicated
|
| 832 |
+
/// number of bytes to the value data buffer without additional allocations
|
| 833 |
+
Status ReserveData(int64_t elements) {
|
| 834 |
+
ARROW_RETURN_NOT_OK(ValidateOverflow(elements));
|
| 835 |
+
return byte_builder_.Reserve(elements);
|
| 836 |
+
}
|
| 837 |
+
|
| 838 |
+
void Reset() override;
|
| 839 |
+
Status Resize(int64_t capacity) override;
|
| 840 |
+
Status FinishInternal(std::shared_ptr<ArrayData>* out) override;
|
| 841 |
+
|
| 842 |
+
/// \cond FALSE
|
| 843 |
+
using ArrayBuilder::Finish;
|
| 844 |
+
/// \endcond
|
| 845 |
+
|
| 846 |
+
Status Finish(std::shared_ptr<FixedSizeBinaryArray>* out) { return FinishTyped(out); }
|
| 847 |
+
|
| 848 |
+
/// \return size of values buffer so far
|
| 849 |
+
int64_t value_data_length() const { return byte_builder_.length(); }
|
| 850 |
+
|
| 851 |
+
int32_t byte_width() const { return byte_width_; }
|
| 852 |
+
|
| 853 |
+
/// Temporary access to a value.
|
| 854 |
+
///
|
| 855 |
+
/// This pointer becomes invalid on the next modifying operation.
|
| 856 |
+
const uint8_t* GetValue(int64_t i) const;
|
| 857 |
+
|
| 858 |
+
/// Temporary access to a value.
|
| 859 |
+
///
|
| 860 |
+
/// This view becomes invalid on the next modifying operation.
|
| 861 |
+
std::string_view GetView(int64_t i) const;
|
| 862 |
+
|
| 863 |
+
static constexpr int64_t memory_limit() {
|
| 864 |
+
return std::numeric_limits<int64_t>::max() - 1;
|
| 865 |
+
}
|
| 866 |
+
|
| 867 |
+
std::shared_ptr<DataType> type() const override {
|
| 868 |
+
return fixed_size_binary(byte_width_);
|
| 869 |
+
}
|
| 870 |
+
|
| 871 |
+
protected:
|
| 872 |
+
int32_t byte_width_;
|
| 873 |
+
BufferBuilder byte_builder_;
|
| 874 |
+
|
| 875 |
+
/// Temporary access to a value.
|
| 876 |
+
///
|
| 877 |
+
/// This pointer becomes invalid on the next modifying operation.
|
| 878 |
+
uint8_t* GetMutableValue(int64_t i) {
|
| 879 |
+
uint8_t* data_ptr = byte_builder_.mutable_data();
|
| 880 |
+
return data_ptr + i * byte_width_;
|
| 881 |
+
}
|
| 882 |
+
|
| 883 |
+
void CheckValueSize(int64_t size);
|
| 884 |
+
};
|
| 885 |
+
|
| 886 |
+
/// @}
|
| 887 |
+
|
| 888 |
+
// ----------------------------------------------------------------------
|
| 889 |
+
// Chunked builders: build a sequence of BinaryArray or StringArray that are
|
| 890 |
+
// limited to a particular size (to the upper limit of 2GB)
|
| 891 |
+
|
| 892 |
+
namespace internal {
|
| 893 |
+
|
| 894 |
+
class ARROW_EXPORT ChunkedBinaryBuilder {
|
| 895 |
+
public:
|
| 896 |
+
explicit ChunkedBinaryBuilder(int32_t max_chunk_value_length,
|
| 897 |
+
MemoryPool* pool = default_memory_pool());
|
| 898 |
+
|
| 899 |
+
ChunkedBinaryBuilder(int32_t max_chunk_value_length, int32_t max_chunk_length,
|
| 900 |
+
MemoryPool* pool = default_memory_pool());
|
| 901 |
+
|
| 902 |
+
virtual ~ChunkedBinaryBuilder() = default;
|
| 903 |
+
|
| 904 |
+
Status Append(const uint8_t* value, int32_t length) {
|
| 905 |
+
if (ARROW_PREDICT_FALSE(length + builder_->value_data_length() >
|
| 906 |
+
max_chunk_value_length_)) {
|
| 907 |
+
if (builder_->value_data_length() == 0) {
|
| 908 |
+
// The current item is larger than max_chunk_size_;
|
| 909 |
+
// this chunk will be oversize and hold *only* this item
|
| 910 |
+
ARROW_RETURN_NOT_OK(builder_->Append(value, length));
|
| 911 |
+
return NextChunk();
|
| 912 |
+
}
|
| 913 |
+
// The current item would cause builder_->value_data_length() to exceed
|
| 914 |
+
// max_chunk_size_, so finish this chunk and append the current item to the next
|
| 915 |
+
// chunk
|
| 916 |
+
ARROW_RETURN_NOT_OK(NextChunk());
|
| 917 |
+
return Append(value, length);
|
| 918 |
+
}
|
| 919 |
+
|
| 920 |
+
if (ARROW_PREDICT_FALSE(builder_->length() == max_chunk_length_)) {
|
| 921 |
+
// The current item would cause builder_->length() to exceed max_chunk_length_, so
|
| 922 |
+
// finish this chunk and append the current item to the next chunk
|
| 923 |
+
ARROW_RETURN_NOT_OK(NextChunk());
|
| 924 |
+
}
|
| 925 |
+
|
| 926 |
+
return builder_->Append(value, length);
|
| 927 |
+
}
|
| 928 |
+
|
| 929 |
+
Status Append(std::string_view value) {
|
| 930 |
+
return Append(reinterpret_cast<const uint8_t*>(value.data()),
|
| 931 |
+
static_cast<int32_t>(value.size()));
|
| 932 |
+
}
|
| 933 |
+
|
| 934 |
+
Status AppendNull() {
|
| 935 |
+
if (ARROW_PREDICT_FALSE(builder_->length() == max_chunk_length_)) {
|
| 936 |
+
ARROW_RETURN_NOT_OK(NextChunk());
|
| 937 |
+
}
|
| 938 |
+
return builder_->AppendNull();
|
| 939 |
+
}
|
| 940 |
+
|
| 941 |
+
Status Reserve(int64_t values);
|
| 942 |
+
|
| 943 |
+
virtual Status Finish(ArrayVector* out);
|
| 944 |
+
|
| 945 |
+
protected:
|
| 946 |
+
Status NextChunk();
|
| 947 |
+
|
| 948 |
+
// maximum total character data size per chunk
|
| 949 |
+
int64_t max_chunk_value_length_;
|
| 950 |
+
|
| 951 |
+
// maximum elements allowed per chunk
|
| 952 |
+
int64_t max_chunk_length_ = kListMaximumElements;
|
| 953 |
+
|
| 954 |
+
// when Reserve() would cause builder_ to exceed its max_chunk_length_,
|
| 955 |
+
// add to extra_capacity_ instead and wait to reserve until the next chunk
|
| 956 |
+
int64_t extra_capacity_ = 0;
|
| 957 |
+
|
| 958 |
+
std::unique_ptr<BinaryBuilder> builder_;
|
| 959 |
+
std::vector<std::shared_ptr<Array>> chunks_;
|
| 960 |
+
};
|
| 961 |
+
|
| 962 |
+
class ARROW_EXPORT ChunkedStringBuilder : public ChunkedBinaryBuilder {
|
| 963 |
+
public:
|
| 964 |
+
using ChunkedBinaryBuilder::ChunkedBinaryBuilder;
|
| 965 |
+
|
| 966 |
+
Status Finish(ArrayVector* out) override;
|
| 967 |
+
};
|
| 968 |
+
|
| 969 |
+
} // namespace internal
|
| 970 |
+
|
| 971 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/builder_decimal.h
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <memory>
|
| 21 |
+
|
| 22 |
+
#include "arrow/array/array_decimal.h"
|
| 23 |
+
#include "arrow/array/builder_base.h"
|
| 24 |
+
#include "arrow/array/builder_binary.h"
|
| 25 |
+
#include "arrow/array/data.h"
|
| 26 |
+
#include "arrow/status.h"
|
| 27 |
+
#include "arrow/type.h"
|
| 28 |
+
#include "arrow/util/visibility.h"
|
| 29 |
+
|
| 30 |
+
namespace arrow {
|
| 31 |
+
|
| 32 |
+
/// \addtogroup numeric-builders
|
| 33 |
+
///
|
| 34 |
+
/// @{
|
| 35 |
+
|
| 36 |
+
class ARROW_EXPORT Decimal128Builder : public FixedSizeBinaryBuilder {
|
| 37 |
+
public:
|
| 38 |
+
using TypeClass = Decimal128Type;
|
| 39 |
+
using ValueType = Decimal128;
|
| 40 |
+
|
| 41 |
+
explicit Decimal128Builder(const std::shared_ptr<DataType>& type,
|
| 42 |
+
MemoryPool* pool = default_memory_pool(),
|
| 43 |
+
int64_t alignment = kDefaultBufferAlignment);
|
| 44 |
+
|
| 45 |
+
using FixedSizeBinaryBuilder::Append;
|
| 46 |
+
using FixedSizeBinaryBuilder::AppendValues;
|
| 47 |
+
using FixedSizeBinaryBuilder::Reset;
|
| 48 |
+
|
| 49 |
+
Status Append(Decimal128 val);
|
| 50 |
+
void UnsafeAppend(Decimal128 val);
|
| 51 |
+
void UnsafeAppend(std::string_view val);
|
| 52 |
+
|
| 53 |
+
Status FinishInternal(std::shared_ptr<ArrayData>* out) override;
|
| 54 |
+
|
| 55 |
+
/// \cond FALSE
|
| 56 |
+
using ArrayBuilder::Finish;
|
| 57 |
+
/// \endcond
|
| 58 |
+
|
| 59 |
+
Status Finish(std::shared_ptr<Decimal128Array>* out) { return FinishTyped(out); }
|
| 60 |
+
|
| 61 |
+
std::shared_ptr<DataType> type() const override { return decimal_type_; }
|
| 62 |
+
|
| 63 |
+
protected:
|
| 64 |
+
std::shared_ptr<Decimal128Type> decimal_type_;
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
class ARROW_EXPORT Decimal256Builder : public FixedSizeBinaryBuilder {
|
| 68 |
+
public:
|
| 69 |
+
using TypeClass = Decimal256Type;
|
| 70 |
+
using ValueType = Decimal256;
|
| 71 |
+
|
| 72 |
+
explicit Decimal256Builder(const std::shared_ptr<DataType>& type,
|
| 73 |
+
MemoryPool* pool = default_memory_pool(),
|
| 74 |
+
int64_t alignment = kDefaultBufferAlignment);
|
| 75 |
+
|
| 76 |
+
using FixedSizeBinaryBuilder::Append;
|
| 77 |
+
using FixedSizeBinaryBuilder::AppendValues;
|
| 78 |
+
using FixedSizeBinaryBuilder::Reset;
|
| 79 |
+
|
| 80 |
+
Status Append(const Decimal256& val);
|
| 81 |
+
void UnsafeAppend(const Decimal256& val);
|
| 82 |
+
void UnsafeAppend(std::string_view val);
|
| 83 |
+
|
| 84 |
+
Status FinishInternal(std::shared_ptr<ArrayData>* out) override;
|
| 85 |
+
|
| 86 |
+
/// \cond FALSE
|
| 87 |
+
using ArrayBuilder::Finish;
|
| 88 |
+
/// \endcond
|
| 89 |
+
|
| 90 |
+
Status Finish(std::shared_ptr<Decimal256Array>* out) { return FinishTyped(out); }
|
| 91 |
+
|
| 92 |
+
std::shared_ptr<DataType> type() const override { return decimal_type_; }
|
| 93 |
+
|
| 94 |
+
protected:
|
| 95 |
+
std::shared_ptr<Decimal256Type> decimal_type_;
|
| 96 |
+
};
|
| 97 |
+
|
| 98 |
+
using DecimalBuilder = Decimal128Builder;
|
| 99 |
+
|
| 100 |
+
/// @}
|
| 101 |
+
|
| 102 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/builder_primitive.h
ADDED
|
@@ -0,0 +1,556 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <algorithm>
|
| 21 |
+
#include <memory>
|
| 22 |
+
#include <vector>
|
| 23 |
+
|
| 24 |
+
#include "arrow/array/builder_base.h"
|
| 25 |
+
#include "arrow/array/data.h"
|
| 26 |
+
#include "arrow/result.h"
|
| 27 |
+
#include "arrow/type.h"
|
| 28 |
+
#include "arrow/type_traits.h"
|
| 29 |
+
|
| 30 |
+
namespace arrow {
|
| 31 |
+
|
| 32 |
+
class ARROW_EXPORT NullBuilder : public ArrayBuilder {
|
| 33 |
+
public:
|
| 34 |
+
explicit NullBuilder(MemoryPool* pool = default_memory_pool(),
|
| 35 |
+
int64_t ARROW_ARG_UNUSED(alignment) = kDefaultBufferAlignment)
|
| 36 |
+
: ArrayBuilder(pool) {}
|
| 37 |
+
|
| 38 |
+
explicit NullBuilder(const std::shared_ptr<DataType>& ARROW_ARG_UNUSED(type),
|
| 39 |
+
MemoryPool* pool = default_memory_pool(),
|
| 40 |
+
int64_t alignment = kDefaultBufferAlignment)
|
| 41 |
+
: NullBuilder(pool, alignment) {}
|
| 42 |
+
|
| 43 |
+
/// \brief Append the specified number of null elements
|
| 44 |
+
Status AppendNulls(int64_t length) final {
|
| 45 |
+
if (length < 0) return Status::Invalid("length must be positive");
|
| 46 |
+
null_count_ += length;
|
| 47 |
+
length_ += length;
|
| 48 |
+
return Status::OK();
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/// \brief Append a single null element
|
| 52 |
+
Status AppendNull() final { return AppendNulls(1); }
|
| 53 |
+
|
| 54 |
+
Status AppendEmptyValues(int64_t length) final { return AppendNulls(length); }
|
| 55 |
+
|
| 56 |
+
Status AppendEmptyValue() final { return AppendEmptyValues(1); }
|
| 57 |
+
|
| 58 |
+
Status Append(std::nullptr_t) { return AppendNull(); }
|
| 59 |
+
|
| 60 |
+
Status AppendArraySlice(const ArraySpan&, int64_t, int64_t length) override {
|
| 61 |
+
return AppendNulls(length);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
Status FinishInternal(std::shared_ptr<ArrayData>* out) override;
|
| 65 |
+
|
| 66 |
+
/// \cond FALSE
|
| 67 |
+
using ArrayBuilder::Finish;
|
| 68 |
+
/// \endcond
|
| 69 |
+
|
| 70 |
+
std::shared_ptr<DataType> type() const override { return null(); }
|
| 71 |
+
|
| 72 |
+
Status Finish(std::shared_ptr<NullArray>* out) { return FinishTyped(out); }
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
/// \addtogroup numeric-builders
|
| 76 |
+
///
|
| 77 |
+
/// @{
|
| 78 |
+
|
| 79 |
+
/// Base class for all Builders that emit an Array of a scalar numerical type.
|
| 80 |
+
template <typename T>
|
| 81 |
+
class NumericBuilder
|
| 82 |
+
: public ArrayBuilder,
|
| 83 |
+
public internal::ArrayBuilderExtraOps<NumericBuilder<T>, typename T::c_type> {
|
| 84 |
+
public:
|
| 85 |
+
using TypeClass = T;
|
| 86 |
+
using value_type = typename T::c_type;
|
| 87 |
+
using ArrayType = typename TypeTraits<T>::ArrayType;
|
| 88 |
+
|
| 89 |
+
template <typename T1 = T>
|
| 90 |
+
explicit NumericBuilder(
|
| 91 |
+
enable_if_parameter_free<T1, MemoryPool*> pool = default_memory_pool(),
|
| 92 |
+
int64_t alignment = kDefaultBufferAlignment)
|
| 93 |
+
: ArrayBuilder(pool, alignment),
|
| 94 |
+
type_(TypeTraits<T>::type_singleton()),
|
| 95 |
+
data_builder_(pool, alignment) {}
|
| 96 |
+
|
| 97 |
+
NumericBuilder(const std::shared_ptr<DataType>& type, MemoryPool* pool,
|
| 98 |
+
int64_t alignment = kDefaultBufferAlignment)
|
| 99 |
+
: ArrayBuilder(pool, alignment), type_(type), data_builder_(pool, alignment) {}
|
| 100 |
+
|
| 101 |
+
/// Append a single scalar and increase the size if necessary.
|
| 102 |
+
Status Append(const value_type val) {
|
| 103 |
+
ARROW_RETURN_NOT_OK(ArrayBuilder::Reserve(1));
|
| 104 |
+
UnsafeAppend(val);
|
| 105 |
+
return Status::OK();
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/// Write nulls as uint8_t* (0 value indicates null) into pre-allocated memory
|
| 109 |
+
/// The memory at the corresponding data slot is set to 0 to prevent
|
| 110 |
+
/// uninitialized memory access
|
| 111 |
+
Status AppendNulls(int64_t length) final {
|
| 112 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 113 |
+
data_builder_.UnsafeAppend(length, value_type{}); // zero
|
| 114 |
+
UnsafeSetNull(length);
|
| 115 |
+
return Status::OK();
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
/// \brief Append a single null element
|
| 119 |
+
Status AppendNull() final {
|
| 120 |
+
ARROW_RETURN_NOT_OK(Reserve(1));
|
| 121 |
+
data_builder_.UnsafeAppend(value_type{}); // zero
|
| 122 |
+
UnsafeAppendToBitmap(false);
|
| 123 |
+
return Status::OK();
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
/// \brief Append a empty element
|
| 127 |
+
Status AppendEmptyValue() final {
|
| 128 |
+
ARROW_RETURN_NOT_OK(Reserve(1));
|
| 129 |
+
data_builder_.UnsafeAppend(value_type{}); // zero
|
| 130 |
+
UnsafeAppendToBitmap(true);
|
| 131 |
+
return Status::OK();
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/// \brief Append several empty elements
|
| 135 |
+
Status AppendEmptyValues(int64_t length) final {
|
| 136 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 137 |
+
data_builder_.UnsafeAppend(length, value_type{}); // zero
|
| 138 |
+
UnsafeSetNotNull(length);
|
| 139 |
+
return Status::OK();
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
value_type GetValue(int64_t index) const { return data_builder_.data()[index]; }
|
| 143 |
+
|
| 144 |
+
void Reset() override {
|
| 145 |
+
data_builder_.Reset();
|
| 146 |
+
ArrayBuilder::Reset();
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
Status Resize(int64_t capacity) override {
|
| 150 |
+
ARROW_RETURN_NOT_OK(CheckCapacity(capacity));
|
| 151 |
+
capacity = std::max(capacity, kMinBuilderCapacity);
|
| 152 |
+
ARROW_RETURN_NOT_OK(data_builder_.Resize(capacity));
|
| 153 |
+
return ArrayBuilder::Resize(capacity);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
value_type operator[](int64_t index) const { return GetValue(index); }
|
| 157 |
+
|
| 158 |
+
value_type& operator[](int64_t index) {
|
| 159 |
+
return reinterpret_cast<value_type*>(data_builder_.mutable_data())[index];
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
/// \brief Append a sequence of elements in one shot
|
| 163 |
+
/// \param[in] values a contiguous C array of values
|
| 164 |
+
/// \param[in] length the number of values to append
|
| 165 |
+
/// \param[in] valid_bytes an optional sequence of bytes where non-zero
|
| 166 |
+
/// indicates a valid (non-null) value
|
| 167 |
+
/// \return Status
|
| 168 |
+
Status AppendValues(const value_type* values, int64_t length,
|
| 169 |
+
const uint8_t* valid_bytes = NULLPTR) {
|
| 170 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 171 |
+
data_builder_.UnsafeAppend(values, length);
|
| 172 |
+
// length_ is update by these
|
| 173 |
+
ArrayBuilder::UnsafeAppendToBitmap(valid_bytes, length);
|
| 174 |
+
return Status::OK();
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
/// \brief Append a sequence of elements in one shot
|
| 178 |
+
/// \param[in] values a contiguous C array of values
|
| 179 |
+
/// \param[in] length the number of values to append
|
| 180 |
+
/// \param[in] bitmap a validity bitmap to copy (may be null)
|
| 181 |
+
/// \param[in] bitmap_offset an offset into the validity bitmap
|
| 182 |
+
/// \return Status
|
| 183 |
+
Status AppendValues(const value_type* values, int64_t length, const uint8_t* bitmap,
|
| 184 |
+
int64_t bitmap_offset) {
|
| 185 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 186 |
+
data_builder_.UnsafeAppend(values, length);
|
| 187 |
+
// length_ is update by these
|
| 188 |
+
ArrayBuilder::UnsafeAppendToBitmap(bitmap, bitmap_offset, length);
|
| 189 |
+
return Status::OK();
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
/// \brief Append a sequence of elements in one shot
|
| 193 |
+
/// \param[in] values a contiguous C array of values
|
| 194 |
+
/// \param[in] length the number of values to append
|
| 195 |
+
/// \param[in] is_valid an std::vector<bool> indicating valid (1) or null
|
| 196 |
+
/// (0). Equal in length to values
|
| 197 |
+
/// \return Status
|
| 198 |
+
Status AppendValues(const value_type* values, int64_t length,
|
| 199 |
+
const std::vector<bool>& is_valid) {
|
| 200 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 201 |
+
data_builder_.UnsafeAppend(values, length);
|
| 202 |
+
// length_ is update by these
|
| 203 |
+
ArrayBuilder::UnsafeAppendToBitmap(is_valid);
|
| 204 |
+
return Status::OK();
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
/// \brief Append a sequence of elements in one shot
|
| 208 |
+
/// \param[in] values a std::vector of values
|
| 209 |
+
/// \param[in] is_valid an std::vector<bool> indicating valid (1) or null
|
| 210 |
+
/// (0). Equal in length to values
|
| 211 |
+
/// \return Status
|
| 212 |
+
Status AppendValues(const std::vector<value_type>& values,
|
| 213 |
+
const std::vector<bool>& is_valid) {
|
| 214 |
+
return AppendValues(values.data(), static_cast<int64_t>(values.size()), is_valid);
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
/// \brief Append a sequence of elements in one shot
|
| 218 |
+
/// \param[in] values a std::vector of values
|
| 219 |
+
/// \return Status
|
| 220 |
+
Status AppendValues(const std::vector<value_type>& values) {
|
| 221 |
+
return AppendValues(values.data(), static_cast<int64_t>(values.size()));
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
Status FinishInternal(std::shared_ptr<ArrayData>* out) override {
|
| 225 |
+
ARROW_ASSIGN_OR_RAISE(auto null_bitmap,
|
| 226 |
+
null_bitmap_builder_.FinishWithLength(length_));
|
| 227 |
+
ARROW_ASSIGN_OR_RAISE(auto data, data_builder_.FinishWithLength(length_));
|
| 228 |
+
*out = ArrayData::Make(type(), length_, {null_bitmap, data}, null_count_);
|
| 229 |
+
capacity_ = length_ = null_count_ = 0;
|
| 230 |
+
return Status::OK();
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
/// \cond FALSE
|
| 234 |
+
using ArrayBuilder::Finish;
|
| 235 |
+
/// \endcond
|
| 236 |
+
|
| 237 |
+
Status Finish(std::shared_ptr<ArrayType>* out) { return FinishTyped(out); }
|
| 238 |
+
|
| 239 |
+
/// \brief Append a sequence of elements in one shot
|
| 240 |
+
/// \param[in] values_begin InputIterator to the beginning of the values
|
| 241 |
+
/// \param[in] values_end InputIterator pointing to the end of the values
|
| 242 |
+
/// \return Status
|
| 243 |
+
template <typename ValuesIter>
|
| 244 |
+
Status AppendValues(ValuesIter values_begin, ValuesIter values_end) {
|
| 245 |
+
int64_t length = static_cast<int64_t>(std::distance(values_begin, values_end));
|
| 246 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 247 |
+
data_builder_.UnsafeAppend(values_begin, values_end);
|
| 248 |
+
// this updates the length_
|
| 249 |
+
UnsafeSetNotNull(length);
|
| 250 |
+
return Status::OK();
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
/// \brief Append a sequence of elements in one shot, with a specified nullmap
|
| 254 |
+
/// \param[in] values_begin InputIterator to the beginning of the values
|
| 255 |
+
/// \param[in] values_end InputIterator pointing to the end of the values
|
| 256 |
+
/// \param[in] valid_begin InputIterator with elements indication valid(1)
|
| 257 |
+
/// or null(0) values.
|
| 258 |
+
/// \return Status
|
| 259 |
+
template <typename ValuesIter, typename ValidIter>
|
| 260 |
+
enable_if_t<!std::is_pointer<ValidIter>::value, Status> AppendValues(
|
| 261 |
+
ValuesIter values_begin, ValuesIter values_end, ValidIter valid_begin) {
|
| 262 |
+
static_assert(!internal::is_null_pointer<ValidIter>::value,
|
| 263 |
+
"Don't pass a NULLPTR directly as valid_begin, use the 2-argument "
|
| 264 |
+
"version instead");
|
| 265 |
+
int64_t length = static_cast<int64_t>(std::distance(values_begin, values_end));
|
| 266 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 267 |
+
data_builder_.UnsafeAppend(values_begin, values_end);
|
| 268 |
+
null_bitmap_builder_.UnsafeAppend<true>(
|
| 269 |
+
length, [&valid_begin]() -> bool { return *valid_begin++; });
|
| 270 |
+
length_ = null_bitmap_builder_.length();
|
| 271 |
+
null_count_ = null_bitmap_builder_.false_count();
|
| 272 |
+
return Status::OK();
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
// Same as above, with a pointer type ValidIter
|
| 276 |
+
template <typename ValuesIter, typename ValidIter>
|
| 277 |
+
enable_if_t<std::is_pointer<ValidIter>::value, Status> AppendValues(
|
| 278 |
+
ValuesIter values_begin, ValuesIter values_end, ValidIter valid_begin) {
|
| 279 |
+
int64_t length = static_cast<int64_t>(std::distance(values_begin, values_end));
|
| 280 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 281 |
+
data_builder_.UnsafeAppend(values_begin, values_end);
|
| 282 |
+
// this updates the length_
|
| 283 |
+
if (valid_begin == NULLPTR) {
|
| 284 |
+
UnsafeSetNotNull(length);
|
| 285 |
+
} else {
|
| 286 |
+
null_bitmap_builder_.UnsafeAppend<true>(
|
| 287 |
+
length, [&valid_begin]() -> bool { return *valid_begin++; });
|
| 288 |
+
length_ = null_bitmap_builder_.length();
|
| 289 |
+
null_count_ = null_bitmap_builder_.false_count();
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
return Status::OK();
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
Status AppendArraySlice(const ArraySpan& array, int64_t offset,
|
| 296 |
+
int64_t length) override {
|
| 297 |
+
return AppendValues(array.GetValues<value_type>(1) + offset, length,
|
| 298 |
+
array.GetValues<uint8_t>(0, 0), array.offset + offset);
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
/// Append a single scalar under the assumption that the underlying Buffer is
|
| 302 |
+
/// large enough.
|
| 303 |
+
///
|
| 304 |
+
/// This method does not capacity-check; make sure to call Reserve
|
| 305 |
+
/// beforehand.
|
| 306 |
+
void UnsafeAppend(const value_type val) {
|
| 307 |
+
ArrayBuilder::UnsafeAppendToBitmap(true);
|
| 308 |
+
data_builder_.UnsafeAppend(val);
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
void UnsafeAppendNull() {
|
| 312 |
+
ArrayBuilder::UnsafeAppendToBitmap(false);
|
| 313 |
+
data_builder_.UnsafeAppend(value_type{}); // zero
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
std::shared_ptr<DataType> type() const override { return type_; }
|
| 317 |
+
|
| 318 |
+
protected:
|
| 319 |
+
std::shared_ptr<DataType> type_;
|
| 320 |
+
TypedBufferBuilder<value_type> data_builder_;
|
| 321 |
+
};
|
| 322 |
+
|
| 323 |
+
// Builders
|
| 324 |
+
|
| 325 |
+
using UInt8Builder = NumericBuilder<UInt8Type>;
|
| 326 |
+
using UInt16Builder = NumericBuilder<UInt16Type>;
|
| 327 |
+
using UInt32Builder = NumericBuilder<UInt32Type>;
|
| 328 |
+
using UInt64Builder = NumericBuilder<UInt64Type>;
|
| 329 |
+
|
| 330 |
+
using Int8Builder = NumericBuilder<Int8Type>;
|
| 331 |
+
using Int16Builder = NumericBuilder<Int16Type>;
|
| 332 |
+
using Int32Builder = NumericBuilder<Int32Type>;
|
| 333 |
+
using Int64Builder = NumericBuilder<Int64Type>;
|
| 334 |
+
|
| 335 |
+
using HalfFloatBuilder = NumericBuilder<HalfFloatType>;
|
| 336 |
+
using FloatBuilder = NumericBuilder<FloatType>;
|
| 337 |
+
using DoubleBuilder = NumericBuilder<DoubleType>;
|
| 338 |
+
|
| 339 |
+
/// @}
|
| 340 |
+
|
| 341 |
+
/// \addtogroup temporal-builders
|
| 342 |
+
///
|
| 343 |
+
/// @{
|
| 344 |
+
|
| 345 |
+
using Date32Builder = NumericBuilder<Date32Type>;
|
| 346 |
+
using Date64Builder = NumericBuilder<Date64Type>;
|
| 347 |
+
using Time32Builder = NumericBuilder<Time32Type>;
|
| 348 |
+
using Time64Builder = NumericBuilder<Time64Type>;
|
| 349 |
+
using TimestampBuilder = NumericBuilder<TimestampType>;
|
| 350 |
+
using MonthIntervalBuilder = NumericBuilder<MonthIntervalType>;
|
| 351 |
+
using DurationBuilder = NumericBuilder<DurationType>;
|
| 352 |
+
|
| 353 |
+
/// @}
|
| 354 |
+
|
| 355 |
+
class ARROW_EXPORT BooleanBuilder
|
| 356 |
+
: public ArrayBuilder,
|
| 357 |
+
public internal::ArrayBuilderExtraOps<BooleanBuilder, bool> {
|
| 358 |
+
public:
|
| 359 |
+
using TypeClass = BooleanType;
|
| 360 |
+
using value_type = bool;
|
| 361 |
+
|
| 362 |
+
explicit BooleanBuilder(MemoryPool* pool = default_memory_pool(),
|
| 363 |
+
int64_t alignment = kDefaultBufferAlignment);
|
| 364 |
+
|
| 365 |
+
BooleanBuilder(const std::shared_ptr<DataType>& type,
|
| 366 |
+
MemoryPool* pool = default_memory_pool(),
|
| 367 |
+
int64_t alignment = kDefaultBufferAlignment);
|
| 368 |
+
|
| 369 |
+
/// Write nulls as uint8_t* (0 value indicates null) into pre-allocated memory
|
| 370 |
+
Status AppendNulls(int64_t length) final {
|
| 371 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 372 |
+
data_builder_.UnsafeAppend(length, false);
|
| 373 |
+
UnsafeSetNull(length);
|
| 374 |
+
return Status::OK();
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
Status AppendNull() final {
|
| 378 |
+
ARROW_RETURN_NOT_OK(Reserve(1));
|
| 379 |
+
UnsafeAppendNull();
|
| 380 |
+
return Status::OK();
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
Status AppendEmptyValue() final {
|
| 384 |
+
ARROW_RETURN_NOT_OK(Reserve(1));
|
| 385 |
+
data_builder_.UnsafeAppend(false);
|
| 386 |
+
UnsafeSetNotNull(1);
|
| 387 |
+
return Status::OK();
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
Status AppendEmptyValues(int64_t length) final {
|
| 391 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 392 |
+
data_builder_.UnsafeAppend(length, false);
|
| 393 |
+
UnsafeSetNotNull(length);
|
| 394 |
+
return Status::OK();
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
/// Scalar append
|
| 398 |
+
Status Append(const bool val) {
|
| 399 |
+
ARROW_RETURN_NOT_OK(Reserve(1));
|
| 400 |
+
UnsafeAppend(val);
|
| 401 |
+
return Status::OK();
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
Status Append(const uint8_t val) { return Append(val != 0); }
|
| 405 |
+
|
| 406 |
+
/// Scalar append, without checking for capacity
|
| 407 |
+
void UnsafeAppend(const bool val) {
|
| 408 |
+
data_builder_.UnsafeAppend(val);
|
| 409 |
+
UnsafeAppendToBitmap(true);
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
void UnsafeAppendNull() {
|
| 413 |
+
data_builder_.UnsafeAppend(false);
|
| 414 |
+
UnsafeAppendToBitmap(false);
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
void UnsafeAppend(const uint8_t val) { UnsafeAppend(val != 0); }
|
| 418 |
+
|
| 419 |
+
/// \brief Append a sequence of elements in one shot
|
| 420 |
+
/// \param[in] values a contiguous array of bytes (non-zero is 1)
|
| 421 |
+
/// \param[in] length the number of values to append
|
| 422 |
+
/// \param[in] valid_bytes an optional sequence of bytes where non-zero
|
| 423 |
+
/// indicates a valid (non-null) value
|
| 424 |
+
/// \return Status
|
| 425 |
+
Status AppendValues(const uint8_t* values, int64_t length,
|
| 426 |
+
const uint8_t* valid_bytes = NULLPTR);
|
| 427 |
+
|
| 428 |
+
/// \brief Append a sequence of elements in one shot
|
| 429 |
+
/// \param[in] values a bitmap of values
|
| 430 |
+
/// \param[in] length the number of values to append
|
| 431 |
+
/// \param[in] validity a validity bitmap to copy (may be null)
|
| 432 |
+
/// \param[in] offset an offset into the values and validity bitmaps
|
| 433 |
+
/// \return Status
|
| 434 |
+
Status AppendValues(const uint8_t* values, int64_t length, const uint8_t* validity,
|
| 435 |
+
int64_t offset);
|
| 436 |
+
|
| 437 |
+
/// \brief Append a sequence of elements in one shot
|
| 438 |
+
/// \param[in] values a contiguous C array of values
|
| 439 |
+
/// \param[in] length the number of values to append
|
| 440 |
+
/// \param[in] is_valid an std::vector<bool> indicating valid (1) or null
|
| 441 |
+
/// (0). Equal in length to values
|
| 442 |
+
/// \return Status
|
| 443 |
+
Status AppendValues(const uint8_t* values, int64_t length,
|
| 444 |
+
const std::vector<bool>& is_valid);
|
| 445 |
+
|
| 446 |
+
/// \brief Append a sequence of elements in one shot
|
| 447 |
+
/// \param[in] values a std::vector of bytes
|
| 448 |
+
/// \param[in] is_valid an std::vector<bool> indicating valid (1) or null
|
| 449 |
+
/// (0). Equal in length to values
|
| 450 |
+
/// \return Status
|
| 451 |
+
Status AppendValues(const std::vector<uint8_t>& values,
|
| 452 |
+
const std::vector<bool>& is_valid);
|
| 453 |
+
|
| 454 |
+
/// \brief Append a sequence of elements in one shot
|
| 455 |
+
/// \param[in] values a std::vector of bytes
|
| 456 |
+
/// \return Status
|
| 457 |
+
Status AppendValues(const std::vector<uint8_t>& values);
|
| 458 |
+
|
| 459 |
+
/// \brief Append a sequence of elements in one shot
|
| 460 |
+
/// \param[in] values an std::vector<bool> indicating true (1) or false
|
| 461 |
+
/// \param[in] is_valid an std::vector<bool> indicating valid (1) or null
|
| 462 |
+
/// (0). Equal in length to values
|
| 463 |
+
/// \return Status
|
| 464 |
+
Status AppendValues(const std::vector<bool>& values, const std::vector<bool>& is_valid);
|
| 465 |
+
|
| 466 |
+
/// \brief Append a sequence of elements in one shot
|
| 467 |
+
/// \param[in] values an std::vector<bool> indicating true (1) or false
|
| 468 |
+
/// \return Status
|
| 469 |
+
Status AppendValues(const std::vector<bool>& values);
|
| 470 |
+
|
| 471 |
+
/// \brief Append a sequence of elements in one shot
|
| 472 |
+
/// \param[in] values_begin InputIterator to the beginning of the values
|
| 473 |
+
/// \param[in] values_end InputIterator pointing to the end of the values
|
| 474 |
+
/// or null(0) values
|
| 475 |
+
/// \return Status
|
| 476 |
+
template <typename ValuesIter>
|
| 477 |
+
Status AppendValues(ValuesIter values_begin, ValuesIter values_end) {
|
| 478 |
+
int64_t length = static_cast<int64_t>(std::distance(values_begin, values_end));
|
| 479 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 480 |
+
data_builder_.UnsafeAppend<false>(
|
| 481 |
+
length, [&values_begin]() -> bool { return *values_begin++; });
|
| 482 |
+
// this updates length_
|
| 483 |
+
UnsafeSetNotNull(length);
|
| 484 |
+
return Status::OK();
|
| 485 |
+
}
|
| 486 |
+
|
| 487 |
+
/// \brief Append a sequence of elements in one shot, with a specified nullmap
|
| 488 |
+
/// \param[in] values_begin InputIterator to the beginning of the values
|
| 489 |
+
/// \param[in] values_end InputIterator pointing to the end of the values
|
| 490 |
+
/// \param[in] valid_begin InputIterator with elements indication valid(1)
|
| 491 |
+
/// or null(0) values
|
| 492 |
+
/// \return Status
|
| 493 |
+
template <typename ValuesIter, typename ValidIter>
|
| 494 |
+
enable_if_t<!std::is_pointer<ValidIter>::value, Status> AppendValues(
|
| 495 |
+
ValuesIter values_begin, ValuesIter values_end, ValidIter valid_begin) {
|
| 496 |
+
static_assert(!internal::is_null_pointer<ValidIter>::value,
|
| 497 |
+
"Don't pass a NULLPTR directly as valid_begin, use the 2-argument "
|
| 498 |
+
"version instead");
|
| 499 |
+
int64_t length = static_cast<int64_t>(std::distance(values_begin, values_end));
|
| 500 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 501 |
+
|
| 502 |
+
data_builder_.UnsafeAppend<false>(
|
| 503 |
+
length, [&values_begin]() -> bool { return *values_begin++; });
|
| 504 |
+
null_bitmap_builder_.UnsafeAppend<true>(
|
| 505 |
+
length, [&valid_begin]() -> bool { return *valid_begin++; });
|
| 506 |
+
length_ = null_bitmap_builder_.length();
|
| 507 |
+
null_count_ = null_bitmap_builder_.false_count();
|
| 508 |
+
return Status::OK();
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
// Same as above, for a pointer type ValidIter
|
| 512 |
+
template <typename ValuesIter, typename ValidIter>
|
| 513 |
+
enable_if_t<std::is_pointer<ValidIter>::value, Status> AppendValues(
|
| 514 |
+
ValuesIter values_begin, ValuesIter values_end, ValidIter valid_begin) {
|
| 515 |
+
int64_t length = static_cast<int64_t>(std::distance(values_begin, values_end));
|
| 516 |
+
ARROW_RETURN_NOT_OK(Reserve(length));
|
| 517 |
+
data_builder_.UnsafeAppend<false>(
|
| 518 |
+
length, [&values_begin]() -> bool { return *values_begin++; });
|
| 519 |
+
|
| 520 |
+
if (valid_begin == NULLPTR) {
|
| 521 |
+
UnsafeSetNotNull(length);
|
| 522 |
+
} else {
|
| 523 |
+
null_bitmap_builder_.UnsafeAppend<true>(
|
| 524 |
+
length, [&valid_begin]() -> bool { return *valid_begin++; });
|
| 525 |
+
}
|
| 526 |
+
length_ = null_bitmap_builder_.length();
|
| 527 |
+
null_count_ = null_bitmap_builder_.false_count();
|
| 528 |
+
return Status::OK();
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
Status AppendValues(int64_t length, bool value);
|
| 532 |
+
|
| 533 |
+
Status AppendArraySlice(const ArraySpan& array, int64_t offset,
|
| 534 |
+
int64_t length) override {
|
| 535 |
+
return AppendValues(array.GetValues<uint8_t>(1, 0), length,
|
| 536 |
+
array.GetValues<uint8_t>(0, 0), array.offset + offset);
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
Status FinishInternal(std::shared_ptr<ArrayData>* out) override;
|
| 540 |
+
|
| 541 |
+
/// \cond FALSE
|
| 542 |
+
using ArrayBuilder::Finish;
|
| 543 |
+
/// \endcond
|
| 544 |
+
|
| 545 |
+
Status Finish(std::shared_ptr<BooleanArray>* out) { return FinishTyped(out); }
|
| 546 |
+
|
| 547 |
+
void Reset() override;
|
| 548 |
+
Status Resize(int64_t capacity) override;
|
| 549 |
+
|
| 550 |
+
std::shared_ptr<DataType> type() const override { return boolean(); }
|
| 551 |
+
|
| 552 |
+
protected:
|
| 553 |
+
TypedBufferBuilder<bool> data_builder_;
|
| 554 |
+
};
|
| 555 |
+
|
| 556 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/builder_time.h
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
// Contains declarations of time related Arrow builder types.
|
| 19 |
+
|
| 20 |
+
#pragma once
|
| 21 |
+
|
| 22 |
+
#include <memory>
|
| 23 |
+
|
| 24 |
+
#include "arrow/array/builder_base.h"
|
| 25 |
+
#include "arrow/array/builder_primitive.h"
|
| 26 |
+
|
| 27 |
+
namespace arrow {
|
| 28 |
+
|
| 29 |
+
/// \addtogroup temporal-builders
|
| 30 |
+
///
|
| 31 |
+
/// @{
|
| 32 |
+
|
| 33 |
+
// TODO(ARROW-7938): this class is untested
|
| 34 |
+
|
| 35 |
+
class ARROW_EXPORT DayTimeIntervalBuilder : public NumericBuilder<DayTimeIntervalType> {
|
| 36 |
+
public:
|
| 37 |
+
using DayMilliseconds = DayTimeIntervalType::DayMilliseconds;
|
| 38 |
+
|
| 39 |
+
explicit DayTimeIntervalBuilder(MemoryPool* pool = default_memory_pool(),
|
| 40 |
+
int64_t alignment = kDefaultBufferAlignment)
|
| 41 |
+
: DayTimeIntervalBuilder(day_time_interval(), pool, alignment) {}
|
| 42 |
+
|
| 43 |
+
explicit DayTimeIntervalBuilder(std::shared_ptr<DataType> type,
|
| 44 |
+
MemoryPool* pool = default_memory_pool(),
|
| 45 |
+
int64_t alignment = kDefaultBufferAlignment)
|
| 46 |
+
: NumericBuilder<DayTimeIntervalType>(type, pool, alignment) {}
|
| 47 |
+
};
|
| 48 |
+
|
| 49 |
+
class ARROW_EXPORT MonthDayNanoIntervalBuilder
|
| 50 |
+
: public NumericBuilder<MonthDayNanoIntervalType> {
|
| 51 |
+
public:
|
| 52 |
+
using MonthDayNanos = MonthDayNanoIntervalType::MonthDayNanos;
|
| 53 |
+
|
| 54 |
+
explicit MonthDayNanoIntervalBuilder(MemoryPool* pool = default_memory_pool(),
|
| 55 |
+
int64_t alignment = kDefaultBufferAlignment)
|
| 56 |
+
: MonthDayNanoIntervalBuilder(month_day_nano_interval(), pool, alignment) {}
|
| 57 |
+
|
| 58 |
+
explicit MonthDayNanoIntervalBuilder(std::shared_ptr<DataType> type,
|
| 59 |
+
MemoryPool* pool = default_memory_pool(),
|
| 60 |
+
int64_t alignment = kDefaultBufferAlignment)
|
| 61 |
+
: NumericBuilder<MonthDayNanoIntervalType>(type, pool, alignment) {}
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
/// @}
|
| 65 |
+
|
| 66 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/diff.h
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <cstdint>
|
| 21 |
+
#include <functional>
|
| 22 |
+
#include <iosfwd>
|
| 23 |
+
#include <memory>
|
| 24 |
+
|
| 25 |
+
#include "arrow/array/array_base.h"
|
| 26 |
+
#include "arrow/array/array_nested.h"
|
| 27 |
+
#include "arrow/result.h"
|
| 28 |
+
#include "arrow/status.h"
|
| 29 |
+
#include "arrow/type.h"
|
| 30 |
+
#include "arrow/util/visibility.h"
|
| 31 |
+
|
| 32 |
+
namespace arrow {
|
| 33 |
+
|
| 34 |
+
/// \brief Compare two arrays, returning an edit script which expresses the difference
|
| 35 |
+
/// between them
|
| 36 |
+
///
|
| 37 |
+
/// An edit script is an array of struct(insert: bool, run_length: int64_t).
|
| 38 |
+
/// Each element of "insert" determines whether an element was inserted into (true)
|
| 39 |
+
/// or deleted from (false) base. Each insertion or deletion is followed by a run of
|
| 40 |
+
/// elements which are unchanged from base to target; the length of this run is stored
|
| 41 |
+
/// in "run_length". (Note that the edit script begins and ends with a run of shared
|
| 42 |
+
/// elements but both fields of the struct must have the same length. To accommodate this
|
| 43 |
+
/// the first element of "insert" should be ignored.)
|
| 44 |
+
///
|
| 45 |
+
/// For example for base "hlloo" and target "hello", the edit script would be
|
| 46 |
+
/// [
|
| 47 |
+
/// {"insert": false, "run_length": 1}, // leading run of length 1 ("h")
|
| 48 |
+
/// {"insert": true, "run_length": 3}, // insert("e") then a run of length 3 ("llo")
|
| 49 |
+
/// {"insert": false, "run_length": 0} // delete("o") then an empty run
|
| 50 |
+
/// ]
|
| 51 |
+
///
|
| 52 |
+
/// Diffing arrays containing nulls is not currently supported.
|
| 53 |
+
///
|
| 54 |
+
/// \param[in] base baseline for comparison
|
| 55 |
+
/// \param[in] target an array of identical type to base whose elements differ from base's
|
| 56 |
+
/// \param[in] pool memory to store the result will be allocated from this memory pool
|
| 57 |
+
/// \return an edit script array which can be applied to base to produce target
|
| 58 |
+
ARROW_EXPORT
|
| 59 |
+
Result<std::shared_ptr<StructArray>> Diff(const Array& base, const Array& target,
|
| 60 |
+
MemoryPool* pool = default_memory_pool());
|
| 61 |
+
|
| 62 |
+
/// \brief visitor interface for easy traversal of an edit script
|
| 63 |
+
///
|
| 64 |
+
/// visitor will be called for each hunk of insertions and deletions.
|
| 65 |
+
ARROW_EXPORT Status VisitEditScript(
|
| 66 |
+
const Array& edits,
|
| 67 |
+
const std::function<Status(int64_t delete_begin, int64_t delete_end,
|
| 68 |
+
int64_t insert_begin, int64_t insert_end)>& visitor);
|
| 69 |
+
|
| 70 |
+
/// \brief return a function which will format an edit script in unified
|
| 71 |
+
/// diff format to os, given base and target arrays of type
|
| 72 |
+
ARROW_EXPORT Result<
|
| 73 |
+
std::function<Status(const Array& edits, const Array& base, const Array& target)>>
|
| 74 |
+
MakeUnifiedDiffFormatter(const DataType& type, std::ostream* os);
|
| 75 |
+
|
| 76 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/array/util.h
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <cstdint>
|
| 21 |
+
#include <memory>
|
| 22 |
+
#include <vector>
|
| 23 |
+
|
| 24 |
+
#include "arrow/array/data.h"
|
| 25 |
+
#include "arrow/compare.h"
|
| 26 |
+
#include "arrow/result.h"
|
| 27 |
+
#include "arrow/status.h"
|
| 28 |
+
#include "arrow/type.h"
|
| 29 |
+
#include "arrow/util/macros.h"
|
| 30 |
+
#include "arrow/util/visibility.h"
|
| 31 |
+
|
| 32 |
+
namespace arrow {
|
| 33 |
+
|
| 34 |
+
/// \defgroup array-factories Array factory functions
|
| 35 |
+
///
|
| 36 |
+
/// @{
|
| 37 |
+
|
| 38 |
+
/// \brief Create a strongly-typed Array instance from generic ArrayData
|
| 39 |
+
/// \param[in] data the array contents
|
| 40 |
+
/// \return the resulting Array instance
|
| 41 |
+
ARROW_EXPORT
|
| 42 |
+
std::shared_ptr<Array> MakeArray(const std::shared_ptr<ArrayData>& data);
|
| 43 |
+
|
| 44 |
+
/// \brief Create a strongly-typed Array instance with all elements null
|
| 45 |
+
/// \param[in] type the array type
|
| 46 |
+
/// \param[in] length the array length
|
| 47 |
+
/// \param[in] pool the memory pool to allocate memory from
|
| 48 |
+
ARROW_EXPORT
|
| 49 |
+
Result<std::shared_ptr<Array>> MakeArrayOfNull(const std::shared_ptr<DataType>& type,
|
| 50 |
+
int64_t length,
|
| 51 |
+
MemoryPool* pool = default_memory_pool());
|
| 52 |
+
|
| 53 |
+
/// \brief Create an Array instance whose slots are the given scalar
|
| 54 |
+
/// \param[in] scalar the value with which to fill the array
|
| 55 |
+
/// \param[in] length the array length
|
| 56 |
+
/// \param[in] pool the memory pool to allocate memory from
|
| 57 |
+
ARROW_EXPORT
|
| 58 |
+
Result<std::shared_ptr<Array>> MakeArrayFromScalar(
|
| 59 |
+
const Scalar& scalar, int64_t length, MemoryPool* pool = default_memory_pool());
|
| 60 |
+
|
| 61 |
+
/// \brief Create an empty Array of a given type
|
| 62 |
+
///
|
| 63 |
+
/// The output Array will be of the given type.
|
| 64 |
+
///
|
| 65 |
+
/// \param[in] type the data type of the empty Array
|
| 66 |
+
/// \param[in] pool the memory pool to allocate memory from
|
| 67 |
+
/// \return the resulting Array
|
| 68 |
+
ARROW_EXPORT
|
| 69 |
+
Result<std::shared_ptr<Array>> MakeEmptyArray(std::shared_ptr<DataType> type,
|
| 70 |
+
MemoryPool* pool = default_memory_pool());
|
| 71 |
+
|
| 72 |
+
/// @}
|
| 73 |
+
|
| 74 |
+
namespace internal {
|
| 75 |
+
|
| 76 |
+
/// \brief Swap endian of each element in a generic ArrayData
|
| 77 |
+
///
|
| 78 |
+
/// As dictionaries are often shared between different arrays, dictionaries
|
| 79 |
+
/// are not swapped by this function and should be handled separately.
|
| 80 |
+
///
|
| 81 |
+
/// \param[in] data the array contents
|
| 82 |
+
/// \param[in] pool the memory pool to allocate memory from
|
| 83 |
+
/// \return the resulting ArrayData whose elements were swapped
|
| 84 |
+
ARROW_EXPORT
|
| 85 |
+
Result<std::shared_ptr<ArrayData>> SwapEndianArrayData(
|
| 86 |
+
const std::shared_ptr<ArrayData>& data, MemoryPool* pool = default_memory_pool());
|
| 87 |
+
|
| 88 |
+
/// Given a number of ArrayVectors, treat each ArrayVector as the
|
| 89 |
+
/// chunks of a chunked array. Then rechunk each ArrayVector such that
|
| 90 |
+
/// all ArrayVectors are chunked identically. It is mandatory that
|
| 91 |
+
/// all ArrayVectors contain the same total number of elements.
|
| 92 |
+
ARROW_EXPORT
|
| 93 |
+
std::vector<ArrayVector> RechunkArraysConsistently(const std::vector<ArrayVector>&);
|
| 94 |
+
|
| 95 |
+
} // namespace internal
|
| 96 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/api.h
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include "arrow/ipc/dictionary.h"
|
| 21 |
+
#include "arrow/ipc/feather.h"
|
| 22 |
+
#include "arrow/ipc/json_simple.h"
|
| 23 |
+
#include "arrow/ipc/message.h"
|
| 24 |
+
#include "arrow/ipc/reader.h"
|
| 25 |
+
#include "arrow/ipc/writer.h"
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/dictionary.h
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
// Tools for dictionaries in IPC context
|
| 19 |
+
|
| 20 |
+
#pragma once
|
| 21 |
+
|
| 22 |
+
#include <cstdint>
|
| 23 |
+
#include <memory>
|
| 24 |
+
#include <utility>
|
| 25 |
+
#include <vector>
|
| 26 |
+
|
| 27 |
+
#include "arrow/result.h"
|
| 28 |
+
#include "arrow/status.h"
|
| 29 |
+
#include "arrow/type_fwd.h"
|
| 30 |
+
#include "arrow/util/macros.h"
|
| 31 |
+
#include "arrow/util/visibility.h"
|
| 32 |
+
|
| 33 |
+
namespace arrow {
|
| 34 |
+
namespace ipc {
|
| 35 |
+
|
| 36 |
+
namespace internal {
|
| 37 |
+
|
| 38 |
+
class FieldPosition {
|
| 39 |
+
public:
|
| 40 |
+
FieldPosition() : parent_(NULLPTR), index_(-1), depth_(0) {}
|
| 41 |
+
|
| 42 |
+
FieldPosition child(int index) const { return {this, index}; }
|
| 43 |
+
|
| 44 |
+
std::vector<int> path() const {
|
| 45 |
+
std::vector<int> path(depth_);
|
| 46 |
+
const FieldPosition* cur = this;
|
| 47 |
+
for (int i = depth_ - 1; i >= 0; --i) {
|
| 48 |
+
path[i] = cur->index_;
|
| 49 |
+
cur = cur->parent_;
|
| 50 |
+
}
|
| 51 |
+
return path;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
protected:
|
| 55 |
+
FieldPosition(const FieldPosition* parent, int index)
|
| 56 |
+
: parent_(parent), index_(index), depth_(parent->depth_ + 1) {}
|
| 57 |
+
|
| 58 |
+
const FieldPosition* parent_;
|
| 59 |
+
int index_;
|
| 60 |
+
int depth_;
|
| 61 |
+
};
|
| 62 |
+
|
| 63 |
+
} // namespace internal
|
| 64 |
+
|
| 65 |
+
/// \brief Map fields in a schema to dictionary ids
|
| 66 |
+
///
|
| 67 |
+
/// The mapping is structural, i.e. the field path (as a vector of indices)
|
| 68 |
+
/// is associated to the dictionary id. A dictionary id may be associated
|
| 69 |
+
/// to multiple fields.
|
| 70 |
+
class ARROW_EXPORT DictionaryFieldMapper {
|
| 71 |
+
public:
|
| 72 |
+
DictionaryFieldMapper();
|
| 73 |
+
explicit DictionaryFieldMapper(const Schema& schema);
|
| 74 |
+
~DictionaryFieldMapper();
|
| 75 |
+
|
| 76 |
+
Status AddSchemaFields(const Schema& schema);
|
| 77 |
+
Status AddField(int64_t id, std::vector<int> field_path);
|
| 78 |
+
|
| 79 |
+
Result<int64_t> GetFieldId(std::vector<int> field_path) const;
|
| 80 |
+
|
| 81 |
+
int num_fields() const;
|
| 82 |
+
|
| 83 |
+
/// \brief Returns number of unique dictionaries, taking into
|
| 84 |
+
/// account that different fields can share the same dictionary.
|
| 85 |
+
int num_dicts() const;
|
| 86 |
+
|
| 87 |
+
private:
|
| 88 |
+
struct Impl;
|
| 89 |
+
std::unique_ptr<Impl> impl_;
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
using DictionaryVector = std::vector<std::pair<int64_t, std::shared_ptr<Array>>>;
|
| 93 |
+
|
| 94 |
+
/// \brief Memoization data structure for reading dictionaries from IPC streams
|
| 95 |
+
///
|
| 96 |
+
/// This structure tracks the following associations:
|
| 97 |
+
/// - field position (structural) -> dictionary id
|
| 98 |
+
/// - dictionary id -> value type
|
| 99 |
+
/// - dictionary id -> dictionary (value) data
|
| 100 |
+
///
|
| 101 |
+
/// Together, they allow resolving dictionary data when reading an IPC stream,
|
| 102 |
+
/// using metadata recorded in the schema message and data recorded in the
|
| 103 |
+
/// dictionary batch messages (see ResolveDictionaries).
|
| 104 |
+
///
|
| 105 |
+
/// This structure isn't useful for writing an IPC stream, where only
|
| 106 |
+
/// DictionaryFieldMapper is necessary.
|
| 107 |
+
class ARROW_EXPORT DictionaryMemo {
|
| 108 |
+
public:
|
| 109 |
+
DictionaryMemo();
|
| 110 |
+
~DictionaryMemo();
|
| 111 |
+
|
| 112 |
+
DictionaryFieldMapper& fields();
|
| 113 |
+
const DictionaryFieldMapper& fields() const;
|
| 114 |
+
|
| 115 |
+
/// \brief Return current dictionary corresponding to a particular
|
| 116 |
+
/// id. Returns KeyError if id not found
|
| 117 |
+
Result<std::shared_ptr<ArrayData>> GetDictionary(int64_t id, MemoryPool* pool) const;
|
| 118 |
+
|
| 119 |
+
/// \brief Return dictionary value type corresponding to a
|
| 120 |
+
/// particular dictionary id.
|
| 121 |
+
Result<std::shared_ptr<DataType>> GetDictionaryType(int64_t id) const;
|
| 122 |
+
|
| 123 |
+
/// \brief Return true if we have a dictionary for the input id
|
| 124 |
+
bool HasDictionary(int64_t id) const;
|
| 125 |
+
|
| 126 |
+
/// \brief Add a dictionary value type to the memo with a particular id.
|
| 127 |
+
/// Returns KeyError if a different type is already registered with the same id.
|
| 128 |
+
Status AddDictionaryType(int64_t id, const std::shared_ptr<DataType>& type);
|
| 129 |
+
|
| 130 |
+
/// \brief Add a dictionary to the memo with a particular id. Returns
|
| 131 |
+
/// KeyError if that dictionary already exists
|
| 132 |
+
Status AddDictionary(int64_t id, const std::shared_ptr<ArrayData>& dictionary);
|
| 133 |
+
|
| 134 |
+
/// \brief Append a dictionary delta to the memo with a particular id. Returns
|
| 135 |
+
/// KeyError if that dictionary does not exists
|
| 136 |
+
Status AddDictionaryDelta(int64_t id, const std::shared_ptr<ArrayData>& dictionary);
|
| 137 |
+
|
| 138 |
+
/// \brief Add a dictionary to the memo if it does not have one with the id,
|
| 139 |
+
/// otherwise, replace the dictionary with the new one.
|
| 140 |
+
///
|
| 141 |
+
/// Return true if the dictionary was added, false if replaced.
|
| 142 |
+
Result<bool> AddOrReplaceDictionary(int64_t id,
|
| 143 |
+
const std::shared_ptr<ArrayData>& dictionary);
|
| 144 |
+
|
| 145 |
+
private:
|
| 146 |
+
struct Impl;
|
| 147 |
+
std::unique_ptr<Impl> impl_;
|
| 148 |
+
};
|
| 149 |
+
|
| 150 |
+
// For writing: collect dictionary entries to write to the IPC stream, in order
|
| 151 |
+
// (i.e. inner dictionaries before dependent outer dictionaries).
|
| 152 |
+
ARROW_EXPORT
|
| 153 |
+
Result<DictionaryVector> CollectDictionaries(const RecordBatch& batch,
|
| 154 |
+
const DictionaryFieldMapper& mapper);
|
| 155 |
+
|
| 156 |
+
// For reading: resolve all dictionaries in columns, according to the field
|
| 157 |
+
// mapping and dictionary arrays stored in memo.
|
| 158 |
+
// Columns may be sparse, i.e. some entries may be left null
|
| 159 |
+
// (e.g. if an inclusion mask was used).
|
| 160 |
+
ARROW_EXPORT
|
| 161 |
+
Status ResolveDictionaries(const ArrayDataVector& columns, const DictionaryMemo& memo,
|
| 162 |
+
MemoryPool* pool);
|
| 163 |
+
|
| 164 |
+
namespace internal {
|
| 165 |
+
|
| 166 |
+
// Like CollectDictionaries above, but uses the memo's DictionaryFieldMapper
|
| 167 |
+
// and all collected dictionaries are added to the memo using AddDictionary.
|
| 168 |
+
//
|
| 169 |
+
// This is used as a shortcut in some roundtripping tests (to avoid emitting
|
| 170 |
+
// any actual dictionary batches).
|
| 171 |
+
ARROW_EXPORT
|
| 172 |
+
Status CollectDictionaries(const RecordBatch& batch, DictionaryMemo* memo);
|
| 173 |
+
|
| 174 |
+
} // namespace internal
|
| 175 |
+
|
| 176 |
+
} // namespace ipc
|
| 177 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/feather.h
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
// Public API for the "Feather" file format, originally created at
|
| 19 |
+
// http://github.com/wesm/feather
|
| 20 |
+
|
| 21 |
+
#pragma once
|
| 22 |
+
|
| 23 |
+
#include <cstdint>
|
| 24 |
+
#include <memory>
|
| 25 |
+
#include <string>
|
| 26 |
+
#include <vector>
|
| 27 |
+
|
| 28 |
+
#include "arrow/ipc/options.h"
|
| 29 |
+
#include "arrow/type_fwd.h"
|
| 30 |
+
#include "arrow/util/compression.h"
|
| 31 |
+
#include "arrow/util/visibility.h"
|
| 32 |
+
|
| 33 |
+
namespace arrow {
|
| 34 |
+
|
| 35 |
+
class Schema;
|
| 36 |
+
class Status;
|
| 37 |
+
class Table;
|
| 38 |
+
|
| 39 |
+
namespace io {
|
| 40 |
+
|
| 41 |
+
class OutputStream;
|
| 42 |
+
class RandomAccessFile;
|
| 43 |
+
|
| 44 |
+
} // namespace io
|
| 45 |
+
|
| 46 |
+
namespace ipc {
|
| 47 |
+
namespace feather {
|
| 48 |
+
|
| 49 |
+
static constexpr const int kFeatherV1Version = 2;
|
| 50 |
+
static constexpr const int kFeatherV2Version = 3;
|
| 51 |
+
|
| 52 |
+
// ----------------------------------------------------------------------
|
| 53 |
+
// Metadata accessor classes
|
| 54 |
+
|
| 55 |
+
/// \class Reader
|
| 56 |
+
/// \brief An interface for reading columns from Feather files
|
| 57 |
+
class ARROW_EXPORT Reader {
|
| 58 |
+
public:
|
| 59 |
+
virtual ~Reader() = default;
|
| 60 |
+
|
| 61 |
+
/// \brief Open a Feather file from a RandomAccessFile interface
|
| 62 |
+
///
|
| 63 |
+
/// \param[in] source a RandomAccessFile instance
|
| 64 |
+
/// \return the table reader
|
| 65 |
+
static Result<std::shared_ptr<Reader>> Open(
|
| 66 |
+
const std::shared_ptr<io::RandomAccessFile>& source);
|
| 67 |
+
|
| 68 |
+
/// \brief Open a Feather file from a RandomAccessFile interface
|
| 69 |
+
/// with IPC Read options
|
| 70 |
+
///
|
| 71 |
+
/// \param[in] source a RandomAccessFile instance
|
| 72 |
+
/// \param[in] options IPC Read options
|
| 73 |
+
/// \return the table reader
|
| 74 |
+
static Result<std::shared_ptr<Reader>> Open(
|
| 75 |
+
const std::shared_ptr<io::RandomAccessFile>& source, const IpcReadOptions& options);
|
| 76 |
+
|
| 77 |
+
/// \brief Return the version number of the Feather file
|
| 78 |
+
virtual int version() const = 0;
|
| 79 |
+
|
| 80 |
+
virtual std::shared_ptr<Schema> schema() const = 0;
|
| 81 |
+
|
| 82 |
+
/// \brief Read all columns from the file as an arrow::Table.
|
| 83 |
+
///
|
| 84 |
+
/// \param[out] out the returned table
|
| 85 |
+
/// \return Status
|
| 86 |
+
///
|
| 87 |
+
/// This function is zero-copy if the file source supports zero-copy reads
|
| 88 |
+
virtual Status Read(std::shared_ptr<Table>* out) = 0;
|
| 89 |
+
|
| 90 |
+
/// \brief Read only the specified columns from the file as an arrow::Table.
|
| 91 |
+
///
|
| 92 |
+
/// \param[in] indices the column indices to read
|
| 93 |
+
/// \param[out] out the returned table
|
| 94 |
+
/// \return Status
|
| 95 |
+
///
|
| 96 |
+
/// This function is zero-copy if the file source supports zero-copy reads
|
| 97 |
+
virtual Status Read(const std::vector<int>& indices, std::shared_ptr<Table>* out) = 0;
|
| 98 |
+
|
| 99 |
+
/// \brief Read only the specified columns from the file as an arrow::Table.
|
| 100 |
+
///
|
| 101 |
+
/// \param[in] names the column names to read
|
| 102 |
+
/// \param[out] out the returned table
|
| 103 |
+
/// \return Status
|
| 104 |
+
///
|
| 105 |
+
/// This function is zero-copy if the file source supports zero-copy reads
|
| 106 |
+
virtual Status Read(const std::vector<std::string>& names,
|
| 107 |
+
std::shared_ptr<Table>* out) = 0;
|
| 108 |
+
};
|
| 109 |
+
|
| 110 |
+
struct ARROW_EXPORT WriteProperties {
|
| 111 |
+
static WriteProperties Defaults();
|
| 112 |
+
|
| 113 |
+
static WriteProperties DefaultsV1() {
|
| 114 |
+
WriteProperties props = Defaults();
|
| 115 |
+
props.version = kFeatherV1Version;
|
| 116 |
+
return props;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/// Feather file version number
|
| 120 |
+
///
|
| 121 |
+
/// version 2: "Feather V1" Apache Arrow <= 0.16.0
|
| 122 |
+
/// version 3: "Feather V2" Apache Arrow > 0.16.0
|
| 123 |
+
int version = kFeatherV2Version;
|
| 124 |
+
|
| 125 |
+
// Parameters for Feather V2 only
|
| 126 |
+
|
| 127 |
+
/// Number of rows per intra-file chunk. Use smaller chunksize when you need
|
| 128 |
+
/// faster random row access
|
| 129 |
+
int64_t chunksize = 1LL << 16;
|
| 130 |
+
|
| 131 |
+
/// Compression type to use. Only UNCOMPRESSED, LZ4_FRAME, and ZSTD are
|
| 132 |
+
/// supported. The default compression returned by Defaults() is LZ4 if the
|
| 133 |
+
/// project is built with support for it, otherwise
|
| 134 |
+
/// UNCOMPRESSED. UNCOMPRESSED is set as the object default here so that if
|
| 135 |
+
/// WriteProperties::Defaults() is not used, the default constructor for
|
| 136 |
+
/// WriteProperties will work regardless of the options used to build the C++
|
| 137 |
+
/// project.
|
| 138 |
+
Compression::type compression = Compression::UNCOMPRESSED;
|
| 139 |
+
|
| 140 |
+
/// Compressor-specific compression level
|
| 141 |
+
int compression_level = ::arrow::util::kUseDefaultCompressionLevel;
|
| 142 |
+
};
|
| 143 |
+
|
| 144 |
+
ARROW_EXPORT
|
| 145 |
+
Status WriteTable(const Table& table, io::OutputStream* dst,
|
| 146 |
+
const WriteProperties& properties = WriteProperties::Defaults());
|
| 147 |
+
|
| 148 |
+
} // namespace feather
|
| 149 |
+
} // namespace ipc
|
| 150 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/json_simple.h
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
// Implement a simple JSON representation format for arrays
|
| 19 |
+
|
| 20 |
+
#pragma once
|
| 21 |
+
|
| 22 |
+
#include <memory>
|
| 23 |
+
#include <string>
|
| 24 |
+
#include <string_view>
|
| 25 |
+
|
| 26 |
+
#include "arrow/status.h"
|
| 27 |
+
#include "arrow/type_fwd.h"
|
| 28 |
+
#include "arrow/util/visibility.h"
|
| 29 |
+
|
| 30 |
+
namespace arrow {
|
| 31 |
+
|
| 32 |
+
class Array;
|
| 33 |
+
class DataType;
|
| 34 |
+
|
| 35 |
+
namespace ipc {
|
| 36 |
+
namespace internal {
|
| 37 |
+
namespace json {
|
| 38 |
+
|
| 39 |
+
ARROW_EXPORT
|
| 40 |
+
Result<std::shared_ptr<Array>> ArrayFromJSON(const std::shared_ptr<DataType>&,
|
| 41 |
+
const std::string& json);
|
| 42 |
+
|
| 43 |
+
ARROW_EXPORT
|
| 44 |
+
Result<std::shared_ptr<Array>> ArrayFromJSON(const std::shared_ptr<DataType>&,
|
| 45 |
+
std::string_view json);
|
| 46 |
+
|
| 47 |
+
ARROW_EXPORT
|
| 48 |
+
Result<std::shared_ptr<Array>> ArrayFromJSON(const std::shared_ptr<DataType>&,
|
| 49 |
+
const char* json);
|
| 50 |
+
|
| 51 |
+
ARROW_EXPORT
|
| 52 |
+
Status ChunkedArrayFromJSON(const std::shared_ptr<DataType>& type,
|
| 53 |
+
const std::vector<std::string>& json_strings,
|
| 54 |
+
std::shared_ptr<ChunkedArray>* out);
|
| 55 |
+
|
| 56 |
+
ARROW_EXPORT
|
| 57 |
+
Status DictArrayFromJSON(const std::shared_ptr<DataType>&, std::string_view indices_json,
|
| 58 |
+
std::string_view dictionary_json, std::shared_ptr<Array>* out);
|
| 59 |
+
|
| 60 |
+
ARROW_EXPORT
|
| 61 |
+
Status ScalarFromJSON(const std::shared_ptr<DataType>&, std::string_view json,
|
| 62 |
+
std::shared_ptr<Scalar>* out);
|
| 63 |
+
|
| 64 |
+
ARROW_EXPORT
|
| 65 |
+
Status DictScalarFromJSON(const std::shared_ptr<DataType>&, std::string_view index_json,
|
| 66 |
+
std::string_view dictionary_json, std::shared_ptr<Scalar>* out);
|
| 67 |
+
|
| 68 |
+
} // namespace json
|
| 69 |
+
} // namespace internal
|
| 70 |
+
} // namespace ipc
|
| 71 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/message.h
ADDED
|
@@ -0,0 +1,565 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
// C++ object model and user API for interprocess schema messaging
|
| 19 |
+
|
| 20 |
+
#pragma once
|
| 21 |
+
|
| 22 |
+
#include <cstdint>
|
| 23 |
+
#include <functional>
|
| 24 |
+
#include <memory>
|
| 25 |
+
#include <string>
|
| 26 |
+
#include <utility>
|
| 27 |
+
|
| 28 |
+
#include "arrow/io/type_fwd.h"
|
| 29 |
+
#include "arrow/ipc/type_fwd.h"
|
| 30 |
+
#include "arrow/result.h"
|
| 31 |
+
#include "arrow/status.h"
|
| 32 |
+
#include "arrow/type_fwd.h"
|
| 33 |
+
#include "arrow/util/macros.h"
|
| 34 |
+
#include "arrow/util/visibility.h"
|
| 35 |
+
|
| 36 |
+
namespace arrow {
|
| 37 |
+
namespace ipc {
|
| 38 |
+
|
| 39 |
+
struct IpcWriteOptions;
|
| 40 |
+
|
| 41 |
+
// Read interface classes. We do not fully deserialize the flatbuffers so that
|
| 42 |
+
// individual fields metadata can be retrieved from very large schema without
|
| 43 |
+
//
|
| 44 |
+
|
| 45 |
+
/// \class Message
|
| 46 |
+
/// \brief An IPC message including metadata and body
|
| 47 |
+
class ARROW_EXPORT Message {
|
| 48 |
+
public:
|
| 49 |
+
/// \brief Construct message, but do not validate
|
| 50 |
+
///
|
| 51 |
+
/// Use at your own risk; Message::Open has more metadata validation
|
| 52 |
+
Message(std::shared_ptr<Buffer> metadata, std::shared_ptr<Buffer> body);
|
| 53 |
+
|
| 54 |
+
~Message();
|
| 55 |
+
|
| 56 |
+
/// \brief Create and validate a Message instance from two buffers
|
| 57 |
+
///
|
| 58 |
+
/// \param[in] metadata a buffer containing the Flatbuffer metadata
|
| 59 |
+
/// \param[in] body a buffer containing the message body, which may be null
|
| 60 |
+
/// \return the created message
|
| 61 |
+
static Result<std::unique_ptr<Message>> Open(std::shared_ptr<Buffer> metadata,
|
| 62 |
+
std::shared_ptr<Buffer> body);
|
| 63 |
+
|
| 64 |
+
/// \brief Read message body and create Message given Flatbuffer metadata
|
| 65 |
+
/// \param[in] metadata containing a serialized Message flatbuffer
|
| 66 |
+
/// \param[in] stream an InputStream
|
| 67 |
+
/// \return the created Message
|
| 68 |
+
///
|
| 69 |
+
/// \note If stream supports zero-copy, this is zero-copy
|
| 70 |
+
static Result<std::unique_ptr<Message>> ReadFrom(std::shared_ptr<Buffer> metadata,
|
| 71 |
+
io::InputStream* stream);
|
| 72 |
+
|
| 73 |
+
/// \brief Read message body from position in file, and create Message given
|
| 74 |
+
/// the Flatbuffer metadata
|
| 75 |
+
/// \param[in] offset the position in the file where the message body starts.
|
| 76 |
+
/// \param[in] metadata containing a serialized Message flatbuffer
|
| 77 |
+
/// \param[in] file the seekable file interface to read from
|
| 78 |
+
/// \return the created Message
|
| 79 |
+
///
|
| 80 |
+
/// \note If file supports zero-copy, this is zero-copy
|
| 81 |
+
static Result<std::unique_ptr<Message>> ReadFrom(const int64_t offset,
|
| 82 |
+
std::shared_ptr<Buffer> metadata,
|
| 83 |
+
io::RandomAccessFile* file);
|
| 84 |
+
|
| 85 |
+
/// \brief Return true if message type and contents are equal
|
| 86 |
+
///
|
| 87 |
+
/// \param other another message
|
| 88 |
+
/// \return true if contents equal
|
| 89 |
+
bool Equals(const Message& other) const;
|
| 90 |
+
|
| 91 |
+
/// \brief the Message metadata
|
| 92 |
+
///
|
| 93 |
+
/// \return buffer
|
| 94 |
+
std::shared_ptr<Buffer> metadata() const;
|
| 95 |
+
|
| 96 |
+
/// \brief Custom metadata serialized in metadata Flatbuffer. Returns nullptr
|
| 97 |
+
/// when none set
|
| 98 |
+
const std::shared_ptr<const KeyValueMetadata>& custom_metadata() const;
|
| 99 |
+
|
| 100 |
+
/// \brief the Message body, if any
|
| 101 |
+
///
|
| 102 |
+
/// \return buffer is null if no body
|
| 103 |
+
std::shared_ptr<Buffer> body() const;
|
| 104 |
+
|
| 105 |
+
/// \brief The expected body length according to the metadata, for
|
| 106 |
+
/// verification purposes
|
| 107 |
+
int64_t body_length() const;
|
| 108 |
+
|
| 109 |
+
/// \brief The Message type
|
| 110 |
+
MessageType type() const;
|
| 111 |
+
|
| 112 |
+
/// \brief The Message metadata version
|
| 113 |
+
MetadataVersion metadata_version() const;
|
| 114 |
+
|
| 115 |
+
const void* header() const;
|
| 116 |
+
|
| 117 |
+
/// \brief Write length-prefixed metadata and body to output stream
|
| 118 |
+
///
|
| 119 |
+
/// \param[in] file output stream to write to
|
| 120 |
+
/// \param[in] options IPC writing options including alignment
|
| 121 |
+
/// \param[out] output_length the number of bytes written
|
| 122 |
+
/// \return Status
|
| 123 |
+
Status SerializeTo(io::OutputStream* file, const IpcWriteOptions& options,
|
| 124 |
+
int64_t* output_length) const;
|
| 125 |
+
|
| 126 |
+
/// \brief Return true if the Message metadata passes Flatbuffer validation
|
| 127 |
+
bool Verify() const;
|
| 128 |
+
|
| 129 |
+
/// \brief Whether a given message type needs a body.
|
| 130 |
+
static bool HasBody(MessageType type) {
|
| 131 |
+
return type != MessageType::NONE && type != MessageType::SCHEMA;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
private:
|
| 135 |
+
// Hide serialization details from user API
|
| 136 |
+
class MessageImpl;
|
| 137 |
+
std::unique_ptr<MessageImpl> impl_;
|
| 138 |
+
|
| 139 |
+
ARROW_DISALLOW_COPY_AND_ASSIGN(Message);
|
| 140 |
+
};
|
| 141 |
+
|
| 142 |
+
ARROW_EXPORT std::string FormatMessageType(MessageType type);
|
| 143 |
+
|
| 144 |
+
/// \class MessageDecoderListener
|
| 145 |
+
/// \brief An abstract class to listen events from MessageDecoder.
|
| 146 |
+
///
|
| 147 |
+
/// This API is EXPERIMENTAL.
|
| 148 |
+
///
|
| 149 |
+
/// \since 0.17.0
|
| 150 |
+
class ARROW_EXPORT MessageDecoderListener {
|
| 151 |
+
public:
|
| 152 |
+
virtual ~MessageDecoderListener() = default;
|
| 153 |
+
|
| 154 |
+
/// \brief Called when a message is decoded.
|
| 155 |
+
///
|
| 156 |
+
/// MessageDecoder calls this method when it decodes a message. This
|
| 157 |
+
/// method is called multiple times when the target stream has
|
| 158 |
+
/// multiple messages.
|
| 159 |
+
///
|
| 160 |
+
/// \param[in] message a decoded message
|
| 161 |
+
/// \return Status
|
| 162 |
+
virtual Status OnMessageDecoded(std::unique_ptr<Message> message) = 0;
|
| 163 |
+
|
| 164 |
+
/// \brief Called when the decoder state is changed to
|
| 165 |
+
/// MessageDecoder::State::INITIAL.
|
| 166 |
+
///
|
| 167 |
+
/// The default implementation just returns arrow::Status::OK().
|
| 168 |
+
///
|
| 169 |
+
/// \return Status
|
| 170 |
+
virtual Status OnInitial();
|
| 171 |
+
|
| 172 |
+
/// \brief Called when the decoder state is changed to
|
| 173 |
+
/// MessageDecoder::State::METADATA_LENGTH.
|
| 174 |
+
///
|
| 175 |
+
/// The default implementation just returns arrow::Status::OK().
|
| 176 |
+
///
|
| 177 |
+
/// \return Status
|
| 178 |
+
virtual Status OnMetadataLength();
|
| 179 |
+
|
| 180 |
+
/// \brief Called when the decoder state is changed to
|
| 181 |
+
/// MessageDecoder::State::METADATA.
|
| 182 |
+
///
|
| 183 |
+
/// The default implementation just returns arrow::Status::OK().
|
| 184 |
+
///
|
| 185 |
+
/// \return Status
|
| 186 |
+
virtual Status OnMetadata();
|
| 187 |
+
|
| 188 |
+
/// \brief Called when the decoder state is changed to
|
| 189 |
+
/// MessageDecoder::State::BODY.
|
| 190 |
+
///
|
| 191 |
+
/// The default implementation just returns arrow::Status::OK().
|
| 192 |
+
///
|
| 193 |
+
/// \return Status
|
| 194 |
+
virtual Status OnBody();
|
| 195 |
+
|
| 196 |
+
/// \brief Called when the decoder state is changed to
|
| 197 |
+
/// MessageDecoder::State::EOS.
|
| 198 |
+
///
|
| 199 |
+
/// The default implementation just returns arrow::Status::OK().
|
| 200 |
+
///
|
| 201 |
+
/// \return Status
|
| 202 |
+
virtual Status OnEOS();
|
| 203 |
+
};
|
| 204 |
+
|
| 205 |
+
/// \class AssignMessageDecoderListener
|
| 206 |
+
/// \brief Assign a message decoded by MessageDecoder.
|
| 207 |
+
///
|
| 208 |
+
/// This API is EXPERIMENTAL.
|
| 209 |
+
///
|
| 210 |
+
/// \since 0.17.0
|
| 211 |
+
class ARROW_EXPORT AssignMessageDecoderListener : public MessageDecoderListener {
|
| 212 |
+
public:
|
| 213 |
+
/// \brief Construct a listener that assigns a decoded message to the
|
| 214 |
+
/// specified location.
|
| 215 |
+
///
|
| 216 |
+
/// \param[in] message a location to store the received message
|
| 217 |
+
explicit AssignMessageDecoderListener(std::unique_ptr<Message>* message)
|
| 218 |
+
: message_(message) {}
|
| 219 |
+
|
| 220 |
+
virtual ~AssignMessageDecoderListener() = default;
|
| 221 |
+
|
| 222 |
+
Status OnMessageDecoded(std::unique_ptr<Message> message) override {
|
| 223 |
+
*message_ = std::move(message);
|
| 224 |
+
return Status::OK();
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
private:
|
| 228 |
+
std::unique_ptr<Message>* message_;
|
| 229 |
+
|
| 230 |
+
ARROW_DISALLOW_COPY_AND_ASSIGN(AssignMessageDecoderListener);
|
| 231 |
+
};
|
| 232 |
+
|
| 233 |
+
/// \class MessageDecoder
|
| 234 |
+
/// \brief Push style message decoder that receives data from user.
|
| 235 |
+
///
|
| 236 |
+
/// This API is EXPERIMENTAL.
|
| 237 |
+
///
|
| 238 |
+
/// \since 0.17.0
|
| 239 |
+
class ARROW_EXPORT MessageDecoder {
|
| 240 |
+
public:
|
| 241 |
+
/// \brief State for reading a message
|
| 242 |
+
enum State {
|
| 243 |
+
/// The initial state. It requires one of the followings as the next data:
|
| 244 |
+
///
|
| 245 |
+
/// * int32_t continuation token
|
| 246 |
+
/// * int32_t end-of-stream mark (== 0)
|
| 247 |
+
/// * int32_t metadata length (backward compatibility for
|
| 248 |
+
/// reading old IPC messages produced prior to version 0.15.0
|
| 249 |
+
INITIAL,
|
| 250 |
+
|
| 251 |
+
/// It requires int32_t metadata length.
|
| 252 |
+
METADATA_LENGTH,
|
| 253 |
+
|
| 254 |
+
/// It requires metadata.
|
| 255 |
+
METADATA,
|
| 256 |
+
|
| 257 |
+
/// It requires message body.
|
| 258 |
+
BODY,
|
| 259 |
+
|
| 260 |
+
/// The end-of-stream state. No more data is processed.
|
| 261 |
+
EOS,
|
| 262 |
+
};
|
| 263 |
+
|
| 264 |
+
/// \brief Construct a message decoder.
|
| 265 |
+
///
|
| 266 |
+
/// \param[in] listener a MessageDecoderListener that responds events from
|
| 267 |
+
/// the decoder
|
| 268 |
+
/// \param[in] pool an optional MemoryPool to copy metadata on the
|
| 269 |
+
/// \param[in] skip_body if true the body will be skipped even if the message has a body
|
| 270 |
+
/// CPU, if required
|
| 271 |
+
explicit MessageDecoder(std::shared_ptr<MessageDecoderListener> listener,
|
| 272 |
+
MemoryPool* pool = default_memory_pool(),
|
| 273 |
+
bool skip_body = false);
|
| 274 |
+
|
| 275 |
+
/// \brief Construct a message decoder with the specified state.
|
| 276 |
+
///
|
| 277 |
+
/// This is a construct for advanced users that know how to decode
|
| 278 |
+
/// Message.
|
| 279 |
+
///
|
| 280 |
+
/// \param[in] listener a MessageDecoderListener that responds events from
|
| 281 |
+
/// the decoder
|
| 282 |
+
/// \param[in] initial_state an initial state of the decode
|
| 283 |
+
/// \param[in] initial_next_required_size the number of bytes needed
|
| 284 |
+
/// to run the next action
|
| 285 |
+
/// \param[in] pool an optional MemoryPool to copy metadata on the
|
| 286 |
+
/// CPU, if required
|
| 287 |
+
/// \param[in] skip_body if true the body will be skipped even if the message has a body
|
| 288 |
+
MessageDecoder(std::shared_ptr<MessageDecoderListener> listener, State initial_state,
|
| 289 |
+
int64_t initial_next_required_size,
|
| 290 |
+
MemoryPool* pool = default_memory_pool(), bool skip_body = false);
|
| 291 |
+
|
| 292 |
+
virtual ~MessageDecoder();
|
| 293 |
+
|
| 294 |
+
/// \brief Feed data to the decoder as a raw data.
|
| 295 |
+
///
|
| 296 |
+
/// If the decoder can decode one or more messages by the data, the
|
| 297 |
+
/// decoder calls listener->OnMessageDecoded() with a decoded
|
| 298 |
+
/// message multiple times.
|
| 299 |
+
///
|
| 300 |
+
/// If the state of the decoder is changed, corresponding callbacks
|
| 301 |
+
/// on listener is called:
|
| 302 |
+
///
|
| 303 |
+
/// * MessageDecoder::State::INITIAL: listener->OnInitial()
|
| 304 |
+
/// * MessageDecoder::State::METADATA_LENGTH: listener->OnMetadataLength()
|
| 305 |
+
/// * MessageDecoder::State::METADATA: listener->OnMetadata()
|
| 306 |
+
/// * MessageDecoder::State::BODY: listener->OnBody()
|
| 307 |
+
/// * MessageDecoder::State::EOS: listener->OnEOS()
|
| 308 |
+
///
|
| 309 |
+
/// \param[in] data a raw data to be processed. This data isn't
|
| 310 |
+
/// copied. The passed memory must be kept alive through message
|
| 311 |
+
/// processing.
|
| 312 |
+
/// \param[in] size raw data size.
|
| 313 |
+
/// \return Status
|
| 314 |
+
Status Consume(const uint8_t* data, int64_t size);
|
| 315 |
+
|
| 316 |
+
/// \brief Feed data to the decoder as a Buffer.
|
| 317 |
+
///
|
| 318 |
+
/// If the decoder can decode one or more messages by the Buffer,
|
| 319 |
+
/// the decoder calls listener->OnMessageDecoded() with a decoded
|
| 320 |
+
/// message multiple times.
|
| 321 |
+
///
|
| 322 |
+
/// \param[in] buffer a Buffer to be processed.
|
| 323 |
+
/// \return Status
|
| 324 |
+
Status Consume(std::shared_ptr<Buffer> buffer);
|
| 325 |
+
|
| 326 |
+
/// \brief Return the number of bytes needed to advance the state of
|
| 327 |
+
/// the decoder.
|
| 328 |
+
///
|
| 329 |
+
/// This method is provided for users who want to optimize performance.
|
| 330 |
+
/// Normal users don't need to use this method.
|
| 331 |
+
///
|
| 332 |
+
/// Here is an example usage for normal users:
|
| 333 |
+
///
|
| 334 |
+
/// ~~~{.cpp}
|
| 335 |
+
/// decoder.Consume(buffer1);
|
| 336 |
+
/// decoder.Consume(buffer2);
|
| 337 |
+
/// decoder.Consume(buffer3);
|
| 338 |
+
/// ~~~
|
| 339 |
+
///
|
| 340 |
+
/// Decoder has internal buffer. If consumed data isn't enough to
|
| 341 |
+
/// advance the state of the decoder, consumed data is buffered to
|
| 342 |
+
/// the internal buffer. It causes performance overhead.
|
| 343 |
+
///
|
| 344 |
+
/// If you pass next_required_size() size data to each Consume()
|
| 345 |
+
/// call, the decoder doesn't use its internal buffer. It improves
|
| 346 |
+
/// performance.
|
| 347 |
+
///
|
| 348 |
+
/// Here is an example usage to avoid using internal buffer:
|
| 349 |
+
///
|
| 350 |
+
/// ~~~{.cpp}
|
| 351 |
+
/// buffer1 = get_data(decoder.next_required_size());
|
| 352 |
+
/// decoder.Consume(buffer1);
|
| 353 |
+
/// buffer2 = get_data(decoder.next_required_size());
|
| 354 |
+
/// decoder.Consume(buffer2);
|
| 355 |
+
/// ~~~
|
| 356 |
+
///
|
| 357 |
+
/// Users can use this method to avoid creating small
|
| 358 |
+
/// chunks. Message body must be contiguous data. If users pass
|
| 359 |
+
/// small chunks to the decoder, the decoder needs concatenate small
|
| 360 |
+
/// chunks internally. It causes performance overhead.
|
| 361 |
+
///
|
| 362 |
+
/// Here is an example usage to reduce small chunks:
|
| 363 |
+
///
|
| 364 |
+
/// ~~~{.cpp}
|
| 365 |
+
/// buffer = AllocateResizableBuffer();
|
| 366 |
+
/// while ((small_chunk = get_data(&small_chunk_size))) {
|
| 367 |
+
/// auto current_buffer_size = buffer->size();
|
| 368 |
+
/// buffer->Resize(current_buffer_size + small_chunk_size);
|
| 369 |
+
/// memcpy(buffer->mutable_data() + current_buffer_size,
|
| 370 |
+
/// small_chunk,
|
| 371 |
+
/// small_chunk_size);
|
| 372 |
+
/// if (buffer->size() < decoder.next_required_size()) {
|
| 373 |
+
/// continue;
|
| 374 |
+
/// }
|
| 375 |
+
/// std::shared_ptr<arrow::Buffer> chunk(buffer.release());
|
| 376 |
+
/// decoder.Consume(chunk);
|
| 377 |
+
/// buffer = AllocateResizableBuffer();
|
| 378 |
+
/// }
|
| 379 |
+
/// if (buffer->size() > 0) {
|
| 380 |
+
/// std::shared_ptr<arrow::Buffer> chunk(buffer.release());
|
| 381 |
+
/// decoder.Consume(chunk);
|
| 382 |
+
/// }
|
| 383 |
+
/// ~~~
|
| 384 |
+
///
|
| 385 |
+
/// \return the number of bytes needed to advance the state of the
|
| 386 |
+
/// decoder
|
| 387 |
+
int64_t next_required_size() const;
|
| 388 |
+
|
| 389 |
+
/// \brief Return the current state of the decoder.
|
| 390 |
+
///
|
| 391 |
+
/// This method is provided for users who want to optimize performance.
|
| 392 |
+
/// Normal users don't need to use this method.
|
| 393 |
+
///
|
| 394 |
+
/// Decoder doesn't need Buffer to process data on the
|
| 395 |
+
/// MessageDecoder::State::INITIAL state and the
|
| 396 |
+
/// MessageDecoder::State::METADATA_LENGTH. Creating Buffer has
|
| 397 |
+
/// performance overhead. Advanced users can avoid creating Buffer
|
| 398 |
+
/// by checking the current state of the decoder:
|
| 399 |
+
///
|
| 400 |
+
/// ~~~{.cpp}
|
| 401 |
+
/// switch (decoder.state()) {
|
| 402 |
+
/// MessageDecoder::State::INITIAL:
|
| 403 |
+
/// MessageDecoder::State::METADATA_LENGTH:
|
| 404 |
+
/// {
|
| 405 |
+
/// uint8_t data[sizeof(int32_t)];
|
| 406 |
+
/// auto data_size = input->Read(decoder.next_required_size(), data);
|
| 407 |
+
/// decoder.Consume(data, data_size);
|
| 408 |
+
/// }
|
| 409 |
+
/// break;
|
| 410 |
+
/// default:
|
| 411 |
+
/// {
|
| 412 |
+
/// auto buffer = input->Read(decoder.next_required_size());
|
| 413 |
+
/// decoder.Consume(buffer);
|
| 414 |
+
/// }
|
| 415 |
+
/// break;
|
| 416 |
+
/// }
|
| 417 |
+
/// ~~~
|
| 418 |
+
///
|
| 419 |
+
/// \return the current state
|
| 420 |
+
State state() const;
|
| 421 |
+
|
| 422 |
+
private:
|
| 423 |
+
class MessageDecoderImpl;
|
| 424 |
+
std::unique_ptr<MessageDecoderImpl> impl_;
|
| 425 |
+
|
| 426 |
+
ARROW_DISALLOW_COPY_AND_ASSIGN(MessageDecoder);
|
| 427 |
+
};
|
| 428 |
+
|
| 429 |
+
/// \brief Abstract interface for a sequence of messages
|
| 430 |
+
/// \since 0.5.0
|
| 431 |
+
class ARROW_EXPORT MessageReader {
|
| 432 |
+
public:
|
| 433 |
+
virtual ~MessageReader() = default;
|
| 434 |
+
|
| 435 |
+
/// \brief Create MessageReader that reads from InputStream
|
| 436 |
+
static std::unique_ptr<MessageReader> Open(io::InputStream* stream);
|
| 437 |
+
|
| 438 |
+
/// \brief Create MessageReader that reads from owned InputStream
|
| 439 |
+
static std::unique_ptr<MessageReader> Open(
|
| 440 |
+
const std::shared_ptr<io::InputStream>& owned_stream);
|
| 441 |
+
|
| 442 |
+
/// \brief Read next Message from the interface
|
| 443 |
+
///
|
| 444 |
+
/// \return an arrow::ipc::Message instance
|
| 445 |
+
virtual Result<std::unique_ptr<Message>> ReadNextMessage() = 0;
|
| 446 |
+
};
|
| 447 |
+
|
| 448 |
+
// the first parameter of the function should be a pointer to metadata (aka.
|
| 449 |
+
// org::apache::arrow::flatbuf::RecordBatch*)
|
| 450 |
+
using FieldsLoaderFunction = std::function<Status(const void*, io::RandomAccessFile*)>;
|
| 451 |
+
|
| 452 |
+
/// \brief Read encapsulated RPC message from position in file
|
| 453 |
+
///
|
| 454 |
+
/// Read a length-prefixed message flatbuffer starting at the indicated file
|
| 455 |
+
/// offset. If the message has a body with non-zero length, it will also be
|
| 456 |
+
/// read
|
| 457 |
+
///
|
| 458 |
+
/// The metadata_length includes at least the length prefix and the flatbuffer
|
| 459 |
+
///
|
| 460 |
+
/// \param[in] offset the position in the file where the message starts. The
|
| 461 |
+
/// first 4 bytes after the offset are the message length
|
| 462 |
+
/// \param[in] metadata_length the total number of bytes to read from file
|
| 463 |
+
/// \param[in] file the seekable file interface to read from
|
| 464 |
+
/// \param[in] fields_loader the function for loading subset of fields from the given file
|
| 465 |
+
/// \return the message read
|
| 466 |
+
|
| 467 |
+
ARROW_EXPORT
|
| 468 |
+
Result<std::unique_ptr<Message>> ReadMessage(
|
| 469 |
+
const int64_t offset, const int32_t metadata_length, io::RandomAccessFile* file,
|
| 470 |
+
const FieldsLoaderFunction& fields_loader = {});
|
| 471 |
+
|
| 472 |
+
/// \brief Read encapsulated RPC message from cached buffers
|
| 473 |
+
///
|
| 474 |
+
/// The buffers should contain an entire message. Partial reads are not handled.
|
| 475 |
+
///
|
| 476 |
+
/// This method can be used to read just the metadata by passing in a nullptr for the
|
| 477 |
+
/// body. The body will then be skipped and the body size will not be validated.
|
| 478 |
+
///
|
| 479 |
+
/// If the body buffer is provided then it must be the complete body buffer
|
| 480 |
+
///
|
| 481 |
+
/// This is similar to Message::Open but performs slightly more validation (e.g. checks
|
| 482 |
+
/// to see that the metadata length is correct and that the body is the size the metadata
|
| 483 |
+
/// expected)
|
| 484 |
+
///
|
| 485 |
+
/// \param metadata The bytes for the metadata
|
| 486 |
+
/// \param body The bytes for the body
|
| 487 |
+
/// \return The message represented by the buffers
|
| 488 |
+
ARROW_EXPORT Result<std::unique_ptr<Message>> ReadMessage(
|
| 489 |
+
std::shared_ptr<Buffer> metadata, std::shared_ptr<Buffer> body);
|
| 490 |
+
|
| 491 |
+
ARROW_EXPORT
|
| 492 |
+
Future<std::shared_ptr<Message>> ReadMessageAsync(
|
| 493 |
+
const int64_t offset, const int32_t metadata_length, const int64_t body_length,
|
| 494 |
+
io::RandomAccessFile* file, const io::IOContext& context = io::default_io_context());
|
| 495 |
+
|
| 496 |
+
/// \brief Advance stream to an 8-byte offset if its position is not a multiple
|
| 497 |
+
/// of 8 already
|
| 498 |
+
/// \param[in] stream an input stream
|
| 499 |
+
/// \param[in] alignment the byte multiple for the metadata prefix, usually 8
|
| 500 |
+
/// or 64, to ensure the body starts on a multiple of that alignment
|
| 501 |
+
/// \return Status
|
| 502 |
+
ARROW_EXPORT
|
| 503 |
+
Status AlignStream(io::InputStream* stream, int32_t alignment = 8);
|
| 504 |
+
|
| 505 |
+
/// \brief Advance stream to an 8-byte offset if its position is not a multiple
|
| 506 |
+
/// of 8 already
|
| 507 |
+
/// \param[in] stream an output stream
|
| 508 |
+
/// \param[in] alignment the byte multiple for the metadata prefix, usually 8
|
| 509 |
+
/// or 64, to ensure the body starts on a multiple of that alignment
|
| 510 |
+
/// \return Status
|
| 511 |
+
ARROW_EXPORT
|
| 512 |
+
Status AlignStream(io::OutputStream* stream, int32_t alignment = 8);
|
| 513 |
+
|
| 514 |
+
/// \brief Return error Status if file position is not a multiple of the
|
| 515 |
+
/// indicated alignment
|
| 516 |
+
ARROW_EXPORT
|
| 517 |
+
Status CheckAligned(io::FileInterface* stream, int32_t alignment = 8);
|
| 518 |
+
|
| 519 |
+
/// \brief Read encapsulated IPC message (metadata and body) from InputStream
|
| 520 |
+
///
|
| 521 |
+
/// Returns null if there are not enough bytes available or the
|
| 522 |
+
/// message length is 0 (e.g. EOS in a stream)
|
| 523 |
+
///
|
| 524 |
+
/// \param[in] stream an input stream
|
| 525 |
+
/// \param[in] pool an optional MemoryPool to copy metadata on the CPU, if required
|
| 526 |
+
/// \return Message
|
| 527 |
+
ARROW_EXPORT
|
| 528 |
+
Result<std::unique_ptr<Message>> ReadMessage(io::InputStream* stream,
|
| 529 |
+
MemoryPool* pool = default_memory_pool());
|
| 530 |
+
|
| 531 |
+
/// \brief Feed data from InputStream to MessageDecoder to decode an
|
| 532 |
+
/// encapsulated IPC message (metadata and body)
|
| 533 |
+
///
|
| 534 |
+
/// This API is EXPERIMENTAL.
|
| 535 |
+
///
|
| 536 |
+
/// \param[in] decoder a decoder
|
| 537 |
+
/// \param[in] stream an input stream
|
| 538 |
+
/// \return Status
|
| 539 |
+
///
|
| 540 |
+
/// \since 0.17.0
|
| 541 |
+
ARROW_EXPORT
|
| 542 |
+
Status DecodeMessage(MessageDecoder* decoder, io::InputStream* stream);
|
| 543 |
+
|
| 544 |
+
/// Write encapsulated IPC message Does not make assumptions about
|
| 545 |
+
/// whether the stream is aligned already. Can write legacy (pre
|
| 546 |
+
/// version 0.15.0) IPC message if option set
|
| 547 |
+
///
|
| 548 |
+
/// continuation: 0xFFFFFFFF
|
| 549 |
+
/// message_size: int32
|
| 550 |
+
/// message: const void*
|
| 551 |
+
/// padding
|
| 552 |
+
///
|
| 553 |
+
///
|
| 554 |
+
/// \param[in] message a buffer containing the metadata to write
|
| 555 |
+
/// \param[in] options IPC writing options, including alignment and
|
| 556 |
+
/// legacy message support
|
| 557 |
+
/// \param[in,out] file the OutputStream to write to
|
| 558 |
+
/// \param[out] message_length the total size of the payload written including
|
| 559 |
+
/// padding
|
| 560 |
+
/// \return Status
|
| 561 |
+
Status WriteMessage(const Buffer& message, const IpcWriteOptions& options,
|
| 562 |
+
io::OutputStream* file, int32_t* message_length);
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <cstdint>
|
| 21 |
+
#include <optional>
|
| 22 |
+
#include <vector>
|
| 23 |
+
|
| 24 |
+
#include "arrow/io/caching.h"
|
| 25 |
+
#include "arrow/ipc/type_fwd.h"
|
| 26 |
+
#include "arrow/status.h"
|
| 27 |
+
#include "arrow/type_fwd.h"
|
| 28 |
+
#include "arrow/util/compression.h"
|
| 29 |
+
#include "arrow/util/visibility.h"
|
| 30 |
+
|
| 31 |
+
namespace arrow {
|
| 32 |
+
|
| 33 |
+
class MemoryPool;
|
| 34 |
+
|
| 35 |
+
namespace ipc {
|
| 36 |
+
|
| 37 |
+
// ARROW-109: We set this number arbitrarily to help catch user mistakes. For
|
| 38 |
+
// deeply nested schemas, it is expected the user will indicate explicitly the
|
| 39 |
+
// maximum allowed recursion depth
|
| 40 |
+
constexpr int kMaxNestingDepth = 64;
|
| 41 |
+
|
| 42 |
+
/// \brief Options for writing Arrow IPC messages
|
| 43 |
+
struct ARROW_EXPORT IpcWriteOptions {
|
| 44 |
+
/// \brief If true, allow field lengths that don't fit in a signed 32-bit int.
|
| 45 |
+
///
|
| 46 |
+
/// Some implementations may not be able to parse streams created with this option.
|
| 47 |
+
bool allow_64bit = false;
|
| 48 |
+
|
| 49 |
+
/// \brief The maximum permitted schema nesting depth.
|
| 50 |
+
int max_recursion_depth = kMaxNestingDepth;
|
| 51 |
+
|
| 52 |
+
/// \brief Write padding after memory buffers up to this multiple of bytes.
|
| 53 |
+
int32_t alignment = 8;
|
| 54 |
+
|
| 55 |
+
/// \brief Write the pre-0.15.0 IPC message format
|
| 56 |
+
///
|
| 57 |
+
/// This legacy format consists of a 4-byte prefix instead of 8-byte.
|
| 58 |
+
bool write_legacy_ipc_format = false;
|
| 59 |
+
|
| 60 |
+
/// \brief The memory pool to use for allocations made during IPC writing
|
| 61 |
+
///
|
| 62 |
+
/// While Arrow IPC is predominantly zero-copy, it may have to allocate
|
| 63 |
+
/// memory in some cases (for example if compression is enabled).
|
| 64 |
+
MemoryPool* memory_pool = default_memory_pool();
|
| 65 |
+
|
| 66 |
+
/// \brief Compression codec to use for record batch body buffers
|
| 67 |
+
///
|
| 68 |
+
/// May only be UNCOMPRESSED, LZ4_FRAME and ZSTD.
|
| 69 |
+
std::shared_ptr<util::Codec> codec;
|
| 70 |
+
|
| 71 |
+
/// \brief Minimum space savings percentage required for compression to be applied
|
| 72 |
+
///
|
| 73 |
+
/// Space savings is calculated as (1.0 - compressed_size / uncompressed_size).
|
| 74 |
+
///
|
| 75 |
+
/// For example, if min_space_savings = 0.1, a 100-byte body buffer won't undergo
|
| 76 |
+
/// compression if its expected compressed size exceeds 90 bytes. If this option is
|
| 77 |
+
/// unset, compression will be used indiscriminately. If no codec was supplied, this
|
| 78 |
+
/// option is ignored.
|
| 79 |
+
///
|
| 80 |
+
/// Values outside of the range [0,1] are handled as errors.
|
| 81 |
+
///
|
| 82 |
+
/// Note that enabling this option may result in unreadable data for Arrow C++ versions
|
| 83 |
+
/// prior to 12.0.0.
|
| 84 |
+
std::optional<double> min_space_savings;
|
| 85 |
+
|
| 86 |
+
/// \brief Use global CPU thread pool to parallelize any computational tasks
|
| 87 |
+
/// like compression
|
| 88 |
+
bool use_threads = true;
|
| 89 |
+
|
| 90 |
+
/// \brief Whether to emit dictionary deltas
|
| 91 |
+
///
|
| 92 |
+
/// If false, a changed dictionary for a given field will emit a full
|
| 93 |
+
/// dictionary replacement.
|
| 94 |
+
/// If true, a changed dictionary will be compared against the previous
|
| 95 |
+
/// version. If possible, a dictionary delta will be emitted, otherwise
|
| 96 |
+
/// a full dictionary replacement.
|
| 97 |
+
///
|
| 98 |
+
/// Default is false to maximize stream compatibility.
|
| 99 |
+
///
|
| 100 |
+
/// Also, note that if a changed dictionary is a nested dictionary,
|
| 101 |
+
/// then a delta is never emitted, for compatibility with the read path.
|
| 102 |
+
bool emit_dictionary_deltas = false;
|
| 103 |
+
|
| 104 |
+
/// \brief Whether to unify dictionaries for the IPC file format
|
| 105 |
+
///
|
| 106 |
+
/// The IPC file format doesn't support dictionary replacements.
|
| 107 |
+
/// Therefore, chunks of a column with a dictionary type must have the same
|
| 108 |
+
/// dictionary in each record batch (or an extended dictionary + delta).
|
| 109 |
+
///
|
| 110 |
+
/// If this option is true, RecordBatchWriter::WriteTable will attempt
|
| 111 |
+
/// to unify dictionaries across each table column. If this option is
|
| 112 |
+
/// false, incompatible dictionaries across a table column will simply
|
| 113 |
+
/// raise an error.
|
| 114 |
+
///
|
| 115 |
+
/// Note that enabling this option has a runtime cost. Also, not all types
|
| 116 |
+
/// currently support dictionary unification.
|
| 117 |
+
///
|
| 118 |
+
/// This option is ignored for IPC streams, which support dictionary replacement
|
| 119 |
+
/// and deltas.
|
| 120 |
+
bool unify_dictionaries = false;
|
| 121 |
+
|
| 122 |
+
/// \brief Format version to use for IPC messages and their metadata.
|
| 123 |
+
///
|
| 124 |
+
/// Presently using V5 version (readable by 1.0.0 and later).
|
| 125 |
+
/// V4 is also available (readable by 0.8.0 and later).
|
| 126 |
+
MetadataVersion metadata_version = MetadataVersion::V5;
|
| 127 |
+
|
| 128 |
+
static IpcWriteOptions Defaults();
|
| 129 |
+
};
|
| 130 |
+
|
| 131 |
+
/// \brief Options for reading Arrow IPC messages
|
| 132 |
+
struct ARROW_EXPORT IpcReadOptions {
|
| 133 |
+
/// \brief The maximum permitted schema nesting depth.
|
| 134 |
+
int max_recursion_depth = kMaxNestingDepth;
|
| 135 |
+
|
| 136 |
+
/// \brief The memory pool to use for allocations made during IPC reading
|
| 137 |
+
///
|
| 138 |
+
/// While Arrow IPC is predominantly zero-copy, it may have to allocate
|
| 139 |
+
/// memory in some cases (for example if compression is enabled).
|
| 140 |
+
MemoryPool* memory_pool = default_memory_pool();
|
| 141 |
+
|
| 142 |
+
/// \brief Top-level schema fields to include when deserializing RecordBatch.
|
| 143 |
+
///
|
| 144 |
+
/// If empty (the default), return all deserialized fields.
|
| 145 |
+
/// If non-empty, the values are the indices of fields in the top-level schema.
|
| 146 |
+
std::vector<int> included_fields;
|
| 147 |
+
|
| 148 |
+
/// \brief Use global CPU thread pool to parallelize any computational tasks
|
| 149 |
+
/// like decompression
|
| 150 |
+
bool use_threads = true;
|
| 151 |
+
|
| 152 |
+
/// \brief Whether to convert incoming data to platform-native endianness
|
| 153 |
+
///
|
| 154 |
+
/// If the endianness of the received schema is not equal to platform-native
|
| 155 |
+
/// endianness, then all buffers with endian-sensitive data will be byte-swapped.
|
| 156 |
+
/// This includes the value buffers of numeric types, temporal types, decimal
|
| 157 |
+
/// types, as well as the offset buffers of variable-sized binary and list-like
|
| 158 |
+
/// types.
|
| 159 |
+
///
|
| 160 |
+
/// Endianness conversion is achieved by the RecordBatchFileReader,
|
| 161 |
+
/// RecordBatchStreamReader and StreamDecoder classes.
|
| 162 |
+
bool ensure_native_endian = true;
|
| 163 |
+
|
| 164 |
+
/// \brief Options to control caching behavior when pre-buffering is requested
|
| 165 |
+
///
|
| 166 |
+
/// The lazy property will always be reset to true to deliver the expected behavior
|
| 167 |
+
io::CacheOptions pre_buffer_cache_options = io::CacheOptions::LazyDefaults();
|
| 168 |
+
|
| 169 |
+
static IpcReadOptions Defaults();
|
| 170 |
+
};
|
| 171 |
+
|
| 172 |
+
namespace internal {
|
| 173 |
+
|
| 174 |
+
Status CheckCompressionSupported(Compression::type codec);
|
| 175 |
+
|
| 176 |
+
} // namespace internal
|
| 177 |
+
} // namespace ipc
|
| 178 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/reader.h
ADDED
|
@@ -0,0 +1,638 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
// Read Arrow files and streams
|
| 19 |
+
|
| 20 |
+
#pragma once
|
| 21 |
+
|
| 22 |
+
#include <cstddef>
|
| 23 |
+
#include <cstdint>
|
| 24 |
+
#include <memory>
|
| 25 |
+
#include <utility>
|
| 26 |
+
#include <vector>
|
| 27 |
+
|
| 28 |
+
#include "arrow/io/caching.h"
|
| 29 |
+
#include "arrow/io/type_fwd.h"
|
| 30 |
+
#include "arrow/ipc/message.h"
|
| 31 |
+
#include "arrow/ipc/options.h"
|
| 32 |
+
#include "arrow/record_batch.h"
|
| 33 |
+
#include "arrow/result.h"
|
| 34 |
+
#include "arrow/type_fwd.h"
|
| 35 |
+
#include "arrow/util/async_generator.h"
|
| 36 |
+
#include "arrow/util/macros.h"
|
| 37 |
+
#include "arrow/util/visibility.h"
|
| 38 |
+
|
| 39 |
+
namespace arrow {
|
| 40 |
+
namespace ipc {
|
| 41 |
+
|
| 42 |
+
class DictionaryMemo;
|
| 43 |
+
struct IpcPayload;
|
| 44 |
+
|
| 45 |
+
using RecordBatchReader = ::arrow::RecordBatchReader;
|
| 46 |
+
|
| 47 |
+
struct ReadStats {
|
| 48 |
+
/// Number of IPC messages read.
|
| 49 |
+
int64_t num_messages = 0;
|
| 50 |
+
/// Number of record batches read.
|
| 51 |
+
int64_t num_record_batches = 0;
|
| 52 |
+
/// Number of dictionary batches read.
|
| 53 |
+
///
|
| 54 |
+
/// Note: num_dictionary_batches >= num_dictionary_deltas + num_replaced_dictionaries
|
| 55 |
+
int64_t num_dictionary_batches = 0;
|
| 56 |
+
|
| 57 |
+
/// Number of dictionary deltas read.
|
| 58 |
+
int64_t num_dictionary_deltas = 0;
|
| 59 |
+
/// Number of replaced dictionaries (i.e. where a dictionary batch replaces
|
| 60 |
+
/// an existing dictionary with an unrelated new dictionary).
|
| 61 |
+
int64_t num_replaced_dictionaries = 0;
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
/// \brief Synchronous batch stream reader that reads from io::InputStream
|
| 65 |
+
///
|
| 66 |
+
/// This class reads the schema (plus any dictionaries) as the first messages
|
| 67 |
+
/// in the stream, followed by record batches. For more granular zero-copy
|
| 68 |
+
/// reads see the ReadRecordBatch functions
|
| 69 |
+
class ARROW_EXPORT RecordBatchStreamReader : public RecordBatchReader {
|
| 70 |
+
public:
|
| 71 |
+
/// Create batch reader from generic MessageReader.
|
| 72 |
+
/// This will take ownership of the given MessageReader.
|
| 73 |
+
///
|
| 74 |
+
/// \param[in] message_reader a MessageReader implementation
|
| 75 |
+
/// \param[in] options any IPC reading options (optional)
|
| 76 |
+
/// \return the created batch reader
|
| 77 |
+
static Result<std::shared_ptr<RecordBatchStreamReader>> Open(
|
| 78 |
+
std::unique_ptr<MessageReader> message_reader,
|
| 79 |
+
const IpcReadOptions& options = IpcReadOptions::Defaults());
|
| 80 |
+
|
| 81 |
+
/// \brief Record batch stream reader from InputStream
|
| 82 |
+
///
|
| 83 |
+
/// \param[in] stream an input stream instance. Must stay alive throughout
|
| 84 |
+
/// lifetime of stream reader
|
| 85 |
+
/// \param[in] options any IPC reading options (optional)
|
| 86 |
+
/// \return the created batch reader
|
| 87 |
+
static Result<std::shared_ptr<RecordBatchStreamReader>> Open(
|
| 88 |
+
io::InputStream* stream,
|
| 89 |
+
const IpcReadOptions& options = IpcReadOptions::Defaults());
|
| 90 |
+
|
| 91 |
+
/// \brief Open stream and retain ownership of stream object
|
| 92 |
+
/// \param[in] stream the input stream
|
| 93 |
+
/// \param[in] options any IPC reading options (optional)
|
| 94 |
+
/// \return the created batch reader
|
| 95 |
+
static Result<std::shared_ptr<RecordBatchStreamReader>> Open(
|
| 96 |
+
const std::shared_ptr<io::InputStream>& stream,
|
| 97 |
+
const IpcReadOptions& options = IpcReadOptions::Defaults());
|
| 98 |
+
|
| 99 |
+
/// \brief Return current read statistics
|
| 100 |
+
virtual ReadStats stats() const = 0;
|
| 101 |
+
};
|
| 102 |
+
|
| 103 |
+
/// \brief Reads the record batch file format
|
| 104 |
+
class ARROW_EXPORT RecordBatchFileReader
|
| 105 |
+
: public std::enable_shared_from_this<RecordBatchFileReader> {
|
| 106 |
+
public:
|
| 107 |
+
virtual ~RecordBatchFileReader() = default;
|
| 108 |
+
|
| 109 |
+
/// \brief Open a RecordBatchFileReader
|
| 110 |
+
///
|
| 111 |
+
/// Open a file-like object that is assumed to be self-contained; i.e., the
|
| 112 |
+
/// end of the file interface is the end of the Arrow file. Note that there
|
| 113 |
+
/// can be any amount of data preceding the Arrow-formatted data, because we
|
| 114 |
+
/// need only locate the end of the Arrow file stream to discover the metadata
|
| 115 |
+
/// and then proceed to read the data into memory.
|
| 116 |
+
static Result<std::shared_ptr<RecordBatchFileReader>> Open(
|
| 117 |
+
io::RandomAccessFile* file,
|
| 118 |
+
const IpcReadOptions& options = IpcReadOptions::Defaults());
|
| 119 |
+
|
| 120 |
+
/// \brief Open a RecordBatchFileReader
|
| 121 |
+
/// If the file is embedded within some larger file or memory region, you can
|
| 122 |
+
/// pass the absolute memory offset to the end of the file (which contains the
|
| 123 |
+
/// metadata footer). The metadata must have been written with memory offsets
|
| 124 |
+
/// relative to the start of the containing file
|
| 125 |
+
///
|
| 126 |
+
/// \param[in] file the data source
|
| 127 |
+
/// \param[in] footer_offset the position of the end of the Arrow file
|
| 128 |
+
/// \param[in] options options for IPC reading
|
| 129 |
+
/// \return the returned reader
|
| 130 |
+
static Result<std::shared_ptr<RecordBatchFileReader>> Open(
|
| 131 |
+
io::RandomAccessFile* file, int64_t footer_offset,
|
| 132 |
+
const IpcReadOptions& options = IpcReadOptions::Defaults());
|
| 133 |
+
|
| 134 |
+
/// \brief Version of Open that retains ownership of file
|
| 135 |
+
///
|
| 136 |
+
/// \param[in] file the data source
|
| 137 |
+
/// \param[in] options options for IPC reading
|
| 138 |
+
/// \return the returned reader
|
| 139 |
+
static Result<std::shared_ptr<RecordBatchFileReader>> Open(
|
| 140 |
+
const std::shared_ptr<io::RandomAccessFile>& file,
|
| 141 |
+
const IpcReadOptions& options = IpcReadOptions::Defaults());
|
| 142 |
+
|
| 143 |
+
/// \brief Version of Open that retains ownership of file
|
| 144 |
+
///
|
| 145 |
+
/// \param[in] file the data source
|
| 146 |
+
/// \param[in] footer_offset the position of the end of the Arrow file
|
| 147 |
+
/// \param[in] options options for IPC reading
|
| 148 |
+
/// \return the returned reader
|
| 149 |
+
static Result<std::shared_ptr<RecordBatchFileReader>> Open(
|
| 150 |
+
const std::shared_ptr<io::RandomAccessFile>& file, int64_t footer_offset,
|
| 151 |
+
const IpcReadOptions& options = IpcReadOptions::Defaults());
|
| 152 |
+
|
| 153 |
+
/// \brief Open a file asynchronously (owns the file).
|
| 154 |
+
static Future<std::shared_ptr<RecordBatchFileReader>> OpenAsync(
|
| 155 |
+
const std::shared_ptr<io::RandomAccessFile>& file,
|
| 156 |
+
const IpcReadOptions& options = IpcReadOptions::Defaults());
|
| 157 |
+
|
| 158 |
+
/// \brief Open a file asynchronously (borrows the file).
|
| 159 |
+
static Future<std::shared_ptr<RecordBatchFileReader>> OpenAsync(
|
| 160 |
+
io::RandomAccessFile* file,
|
| 161 |
+
const IpcReadOptions& options = IpcReadOptions::Defaults());
|
| 162 |
+
|
| 163 |
+
/// \brief Open a file asynchronously (owns the file).
|
| 164 |
+
static Future<std::shared_ptr<RecordBatchFileReader>> OpenAsync(
|
| 165 |
+
const std::shared_ptr<io::RandomAccessFile>& file, int64_t footer_offset,
|
| 166 |
+
const IpcReadOptions& options = IpcReadOptions::Defaults());
|
| 167 |
+
|
| 168 |
+
/// \brief Open a file asynchronously (borrows the file).
|
| 169 |
+
static Future<std::shared_ptr<RecordBatchFileReader>> OpenAsync(
|
| 170 |
+
io::RandomAccessFile* file, int64_t footer_offset,
|
| 171 |
+
const IpcReadOptions& options = IpcReadOptions::Defaults());
|
| 172 |
+
|
| 173 |
+
/// \brief The schema read from the file
|
| 174 |
+
virtual std::shared_ptr<Schema> schema() const = 0;
|
| 175 |
+
|
| 176 |
+
/// \brief Returns the number of record batches in the file
|
| 177 |
+
virtual int num_record_batches() const = 0;
|
| 178 |
+
|
| 179 |
+
/// \brief Return the metadata version from the file metadata
|
| 180 |
+
virtual MetadataVersion version() const = 0;
|
| 181 |
+
|
| 182 |
+
/// \brief Return the contents of the custom_metadata field from the file's
|
| 183 |
+
/// Footer
|
| 184 |
+
virtual std::shared_ptr<const KeyValueMetadata> metadata() const = 0;
|
| 185 |
+
|
| 186 |
+
/// \brief Read a particular record batch from the file. Does not copy memory
|
| 187 |
+
/// if the input source supports zero-copy.
|
| 188 |
+
///
|
| 189 |
+
/// \param[in] i the index of the record batch to return
|
| 190 |
+
/// \return the read batch
|
| 191 |
+
virtual Result<std::shared_ptr<RecordBatch>> ReadRecordBatch(int i) = 0;
|
| 192 |
+
|
| 193 |
+
/// \brief Read a particular record batch along with its custom metadata from the file.
|
| 194 |
+
/// Does not copy memory if the input source supports zero-copy.
|
| 195 |
+
///
|
| 196 |
+
/// \param[in] i the index of the record batch to return
|
| 197 |
+
/// \return a struct containing the read batch and its custom metadata
|
| 198 |
+
virtual Result<RecordBatchWithMetadata> ReadRecordBatchWithCustomMetadata(int i) = 0;
|
| 199 |
+
|
| 200 |
+
/// \brief Return current read statistics
|
| 201 |
+
virtual ReadStats stats() const = 0;
|
| 202 |
+
|
| 203 |
+
/// \brief Computes the total number of rows in the file.
|
| 204 |
+
virtual Result<int64_t> CountRows() = 0;
|
| 205 |
+
|
| 206 |
+
/// \brief Begin loading metadata for the desired batches into memory.
|
| 207 |
+
///
|
| 208 |
+
/// This method will also begin loading all dictionaries messages into memory.
|
| 209 |
+
///
|
| 210 |
+
/// For a regular file this will immediately begin disk I/O in the background on a
|
| 211 |
+
/// thread on the IOContext's thread pool. If the file is memory mapped this will
|
| 212 |
+
/// ensure the memory needed for the metadata is paged from disk into memory
|
| 213 |
+
///
|
| 214 |
+
/// \param indices Indices of the batches to prefetch
|
| 215 |
+
/// If empty then all batches will be prefetched.
|
| 216 |
+
virtual Status PreBufferMetadata(const std::vector<int>& indices) = 0;
|
| 217 |
+
|
| 218 |
+
/// \brief Get a reentrant generator of record batches.
|
| 219 |
+
///
|
| 220 |
+
/// \param[in] coalesce If true, enable I/O coalescing.
|
| 221 |
+
/// \param[in] io_context The IOContext to use (controls which thread pool
|
| 222 |
+
/// is used for I/O).
|
| 223 |
+
/// \param[in] cache_options Options for coalescing (if enabled).
|
| 224 |
+
/// \param[in] executor Optionally, an executor to use for decoding record
|
| 225 |
+
/// batches. This is generally only a benefit for very wide and/or
|
| 226 |
+
/// compressed batches.
|
| 227 |
+
virtual Result<AsyncGenerator<std::shared_ptr<RecordBatch>>> GetRecordBatchGenerator(
|
| 228 |
+
const bool coalesce = false,
|
| 229 |
+
const io::IOContext& io_context = io::default_io_context(),
|
| 230 |
+
const io::CacheOptions cache_options = io::CacheOptions::LazyDefaults(),
|
| 231 |
+
arrow::internal::Executor* executor = NULLPTR) = 0;
|
| 232 |
+
|
| 233 |
+
/// \brief Collect all batches as a vector of record batches
|
| 234 |
+
Result<RecordBatchVector> ToRecordBatches();
|
| 235 |
+
|
| 236 |
+
/// \brief Collect all batches and concatenate as arrow::Table
|
| 237 |
+
Result<std::shared_ptr<Table>> ToTable();
|
| 238 |
+
};
|
| 239 |
+
|
| 240 |
+
/// \brief A general listener class to receive events.
|
| 241 |
+
///
|
| 242 |
+
/// You must implement callback methods for interested events.
|
| 243 |
+
///
|
| 244 |
+
/// This API is EXPERIMENTAL.
|
| 245 |
+
///
|
| 246 |
+
/// \since 0.17.0
|
| 247 |
+
class ARROW_EXPORT Listener {
|
| 248 |
+
public:
|
| 249 |
+
virtual ~Listener() = default;
|
| 250 |
+
|
| 251 |
+
/// \brief Called when end-of-stream is received.
|
| 252 |
+
///
|
| 253 |
+
/// The default implementation just returns arrow::Status::OK().
|
| 254 |
+
///
|
| 255 |
+
/// \return Status
|
| 256 |
+
///
|
| 257 |
+
/// \see StreamDecoder
|
| 258 |
+
virtual Status OnEOS();
|
| 259 |
+
|
| 260 |
+
/// \brief Called when a record batch is decoded and
|
| 261 |
+
/// OnRecordBatchWithMetadataDecoded() isn't overridden.
|
| 262 |
+
///
|
| 263 |
+
/// The default implementation just returns
|
| 264 |
+
/// arrow::Status::NotImplemented().
|
| 265 |
+
///
|
| 266 |
+
/// \param[in] record_batch a record batch decoded
|
| 267 |
+
/// \return Status
|
| 268 |
+
///
|
| 269 |
+
/// \see StreamDecoder
|
| 270 |
+
virtual Status OnRecordBatchDecoded(std::shared_ptr<RecordBatch> record_batch);
|
| 271 |
+
|
| 272 |
+
/// \brief Called when a record batch with custom metadata is decoded.
|
| 273 |
+
///
|
| 274 |
+
/// The default implementation just calls OnRecordBatchDecoded()
|
| 275 |
+
/// without custom metadata.
|
| 276 |
+
///
|
| 277 |
+
/// \param[in] record_batch_with_metadata a record batch with custom
|
| 278 |
+
/// metadata decoded
|
| 279 |
+
/// \return Status
|
| 280 |
+
///
|
| 281 |
+
/// \see StreamDecoder
|
| 282 |
+
///
|
| 283 |
+
/// \since 13.0.0
|
| 284 |
+
virtual Status OnRecordBatchWithMetadataDecoded(
|
| 285 |
+
RecordBatchWithMetadata record_batch_with_metadata);
|
| 286 |
+
|
| 287 |
+
/// \brief Called when a schema is decoded.
|
| 288 |
+
///
|
| 289 |
+
/// The default implementation just returns arrow::Status::OK().
|
| 290 |
+
///
|
| 291 |
+
/// \param[in] schema a schema decoded
|
| 292 |
+
/// \return Status
|
| 293 |
+
///
|
| 294 |
+
/// \see StreamDecoder
|
| 295 |
+
virtual Status OnSchemaDecoded(std::shared_ptr<Schema> schema);
|
| 296 |
+
|
| 297 |
+
/// \brief Called when a schema is decoded.
|
| 298 |
+
///
|
| 299 |
+
/// The default implementation just calls OnSchemaDecoded(schema)
|
| 300 |
+
/// (without filtered_schema) to keep backward compatibility.
|
| 301 |
+
///
|
| 302 |
+
/// \param[in] schema a schema decoded
|
| 303 |
+
/// \param[in] filtered_schema a filtered schema that only has read fields
|
| 304 |
+
/// \return Status
|
| 305 |
+
///
|
| 306 |
+
/// \see StreamDecoder
|
| 307 |
+
///
|
| 308 |
+
/// \since 13.0.0
|
| 309 |
+
virtual Status OnSchemaDecoded(std::shared_ptr<Schema> schema,
|
| 310 |
+
std::shared_ptr<Schema> filtered_schema);
|
| 311 |
+
};
|
| 312 |
+
|
| 313 |
+
/// \brief Collect schema and record batches decoded by StreamDecoder.
|
| 314 |
+
///
|
| 315 |
+
/// This API is EXPERIMENTAL.
|
| 316 |
+
///
|
| 317 |
+
/// \since 0.17.0
|
| 318 |
+
class ARROW_EXPORT CollectListener : public Listener {
|
| 319 |
+
public:
|
| 320 |
+
CollectListener() : schema_(), filtered_schema_(), record_batches_(), metadatas_() {}
|
| 321 |
+
virtual ~CollectListener() = default;
|
| 322 |
+
|
| 323 |
+
Status OnSchemaDecoded(std::shared_ptr<Schema> schema,
|
| 324 |
+
std::shared_ptr<Schema> filtered_schema) override {
|
| 325 |
+
schema_ = std::move(schema);
|
| 326 |
+
filtered_schema_ = std::move(filtered_schema);
|
| 327 |
+
return Status::OK();
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
Status OnRecordBatchWithMetadataDecoded(
|
| 331 |
+
RecordBatchWithMetadata record_batch_with_metadata) override {
|
| 332 |
+
record_batches_.push_back(std::move(record_batch_with_metadata.batch));
|
| 333 |
+
metadatas_.push_back(std::move(record_batch_with_metadata.custom_metadata));
|
| 334 |
+
return Status::OK();
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
/// \return the decoded schema
|
| 338 |
+
std::shared_ptr<Schema> schema() const { return schema_; }
|
| 339 |
+
|
| 340 |
+
/// \return the filtered schema
|
| 341 |
+
std::shared_ptr<Schema> filtered_schema() const { return filtered_schema_; }
|
| 342 |
+
|
| 343 |
+
/// \return the all decoded record batches
|
| 344 |
+
const std::vector<std::shared_ptr<RecordBatch>>& record_batches() const {
|
| 345 |
+
return record_batches_;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
/// \return the all decoded metadatas
|
| 349 |
+
const std::vector<std::shared_ptr<KeyValueMetadata>>& metadatas() const {
|
| 350 |
+
return metadatas_;
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
/// \return the number of collected record batches
|
| 354 |
+
int64_t num_record_batches() const { return record_batches_.size(); }
|
| 355 |
+
|
| 356 |
+
/// \return the last decoded record batch and remove it from
|
| 357 |
+
/// record_batches
|
| 358 |
+
std::shared_ptr<RecordBatch> PopRecordBatch() {
|
| 359 |
+
auto record_batch_with_metadata = PopRecordBatchWithMetadata();
|
| 360 |
+
return std::move(record_batch_with_metadata.batch);
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
/// \return the last decoded record batch with custom metadata and
|
| 364 |
+
/// remove it from record_batches
|
| 365 |
+
RecordBatchWithMetadata PopRecordBatchWithMetadata() {
|
| 366 |
+
RecordBatchWithMetadata record_batch_with_metadata;
|
| 367 |
+
if (record_batches_.empty()) {
|
| 368 |
+
return record_batch_with_metadata;
|
| 369 |
+
}
|
| 370 |
+
record_batch_with_metadata.batch = std::move(record_batches_.back());
|
| 371 |
+
record_batch_with_metadata.custom_metadata = std::move(metadatas_.back());
|
| 372 |
+
record_batches_.pop_back();
|
| 373 |
+
metadatas_.pop_back();
|
| 374 |
+
return record_batch_with_metadata;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
private:
|
| 378 |
+
std::shared_ptr<Schema> schema_;
|
| 379 |
+
std::shared_ptr<Schema> filtered_schema_;
|
| 380 |
+
std::vector<std::shared_ptr<RecordBatch>> record_batches_;
|
| 381 |
+
std::vector<std::shared_ptr<KeyValueMetadata>> metadatas_;
|
| 382 |
+
};
|
| 383 |
+
|
| 384 |
+
/// \brief Push style stream decoder that receives data from user.
|
| 385 |
+
///
|
| 386 |
+
/// This class decodes the Apache Arrow IPC streaming format data.
|
| 387 |
+
///
|
| 388 |
+
/// This API is EXPERIMENTAL.
|
| 389 |
+
///
|
| 390 |
+
/// \see https://arrow.apache.org/docs/format/Columnar.html#ipc-streaming-format
|
| 391 |
+
///
|
| 392 |
+
/// \since 0.17.0
|
| 393 |
+
class ARROW_EXPORT StreamDecoder {
|
| 394 |
+
public:
|
| 395 |
+
/// \brief Construct a stream decoder.
|
| 396 |
+
///
|
| 397 |
+
/// \param[in] listener a Listener that must implement
|
| 398 |
+
/// Listener::OnRecordBatchDecoded() to receive decoded record batches
|
| 399 |
+
/// \param[in] options any IPC reading options (optional)
|
| 400 |
+
StreamDecoder(std::shared_ptr<Listener> listener,
|
| 401 |
+
IpcReadOptions options = IpcReadOptions::Defaults());
|
| 402 |
+
|
| 403 |
+
virtual ~StreamDecoder();
|
| 404 |
+
|
| 405 |
+
/// \brief Feed data to the decoder as a raw data.
|
| 406 |
+
///
|
| 407 |
+
/// If the decoder can read one or more record batches by the data,
|
| 408 |
+
/// the decoder calls listener->OnRecordBatchDecoded() with a
|
| 409 |
+
/// decoded record batch multiple times.
|
| 410 |
+
///
|
| 411 |
+
/// \param[in] data a raw data to be processed. This data isn't
|
| 412 |
+
/// copied. The passed memory must be kept alive through record
|
| 413 |
+
/// batch processing.
|
| 414 |
+
/// \param[in] size raw data size.
|
| 415 |
+
/// \return Status
|
| 416 |
+
Status Consume(const uint8_t* data, int64_t size);
|
| 417 |
+
|
| 418 |
+
/// \brief Feed data to the decoder as a Buffer.
|
| 419 |
+
///
|
| 420 |
+
/// If the decoder can read one or more record batches by the
|
| 421 |
+
/// Buffer, the decoder calls listener->RecordBatchReceived() with a
|
| 422 |
+
/// decoded record batch multiple times.
|
| 423 |
+
///
|
| 424 |
+
/// \param[in] buffer a Buffer to be processed.
|
| 425 |
+
/// \return Status
|
| 426 |
+
Status Consume(std::shared_ptr<Buffer> buffer);
|
| 427 |
+
|
| 428 |
+
/// \brief Reset the internal status.
|
| 429 |
+
///
|
| 430 |
+
/// You can reuse this decoder for new stream after calling
|
| 431 |
+
/// this.
|
| 432 |
+
///
|
| 433 |
+
/// \return Status
|
| 434 |
+
Status Reset();
|
| 435 |
+
|
| 436 |
+
/// \return the shared schema of the record batches in the stream
|
| 437 |
+
std::shared_ptr<Schema> schema() const;
|
| 438 |
+
|
| 439 |
+
/// \brief Return the number of bytes needed to advance the state of
|
| 440 |
+
/// the decoder.
|
| 441 |
+
///
|
| 442 |
+
/// This method is provided for users who want to optimize performance.
|
| 443 |
+
/// Normal users don't need to use this method.
|
| 444 |
+
///
|
| 445 |
+
/// Here is an example usage for normal users:
|
| 446 |
+
///
|
| 447 |
+
/// ~~~{.cpp}
|
| 448 |
+
/// decoder.Consume(buffer1);
|
| 449 |
+
/// decoder.Consume(buffer2);
|
| 450 |
+
/// decoder.Consume(buffer3);
|
| 451 |
+
/// ~~~
|
| 452 |
+
///
|
| 453 |
+
/// Decoder has internal buffer. If consumed data isn't enough to
|
| 454 |
+
/// advance the state of the decoder, consumed data is buffered to
|
| 455 |
+
/// the internal buffer. It causes performance overhead.
|
| 456 |
+
///
|
| 457 |
+
/// If you pass next_required_size() size data to each Consume()
|
| 458 |
+
/// call, the decoder doesn't use its internal buffer. It improves
|
| 459 |
+
/// performance.
|
| 460 |
+
///
|
| 461 |
+
/// Here is an example usage to avoid using internal buffer:
|
| 462 |
+
///
|
| 463 |
+
/// ~~~{.cpp}
|
| 464 |
+
/// buffer1 = get_data(decoder.next_required_size());
|
| 465 |
+
/// decoder.Consume(buffer1);
|
| 466 |
+
/// buffer2 = get_data(decoder.next_required_size());
|
| 467 |
+
/// decoder.Consume(buffer2);
|
| 468 |
+
/// ~~~
|
| 469 |
+
///
|
| 470 |
+
/// Users can use this method to avoid creating small chunks. Record
|
| 471 |
+
/// batch data must be contiguous data. If users pass small chunks
|
| 472 |
+
/// to the decoder, the decoder needs concatenate small chunks
|
| 473 |
+
/// internally. It causes performance overhead.
|
| 474 |
+
///
|
| 475 |
+
/// Here is an example usage to reduce small chunks:
|
| 476 |
+
///
|
| 477 |
+
/// ~~~{.cpp}
|
| 478 |
+
/// buffer = AllocateResizableBuffer();
|
| 479 |
+
/// while ((small_chunk = get_data(&small_chunk_size))) {
|
| 480 |
+
/// auto current_buffer_size = buffer->size();
|
| 481 |
+
/// buffer->Resize(current_buffer_size + small_chunk_size);
|
| 482 |
+
/// memcpy(buffer->mutable_data() + current_buffer_size,
|
| 483 |
+
/// small_chunk,
|
| 484 |
+
/// small_chunk_size);
|
| 485 |
+
/// if (buffer->size() < decoder.next_required_size()) {
|
| 486 |
+
/// continue;
|
| 487 |
+
/// }
|
| 488 |
+
/// std::shared_ptr<arrow::Buffer> chunk(buffer.release());
|
| 489 |
+
/// decoder.Consume(chunk);
|
| 490 |
+
/// buffer = AllocateResizableBuffer();
|
| 491 |
+
/// }
|
| 492 |
+
/// if (buffer->size() > 0) {
|
| 493 |
+
/// std::shared_ptr<arrow::Buffer> chunk(buffer.release());
|
| 494 |
+
/// decoder.Consume(chunk);
|
| 495 |
+
/// }
|
| 496 |
+
/// ~~~
|
| 497 |
+
///
|
| 498 |
+
/// \return the number of bytes needed to advance the state of the
|
| 499 |
+
/// decoder
|
| 500 |
+
int64_t next_required_size() const;
|
| 501 |
+
|
| 502 |
+
/// \brief Return current read statistics
|
| 503 |
+
ReadStats stats() const;
|
| 504 |
+
|
| 505 |
+
private:
|
| 506 |
+
class StreamDecoderImpl;
|
| 507 |
+
std::unique_ptr<StreamDecoderImpl> impl_;
|
| 508 |
+
|
| 509 |
+
ARROW_DISALLOW_COPY_AND_ASSIGN(StreamDecoder);
|
| 510 |
+
};
|
| 511 |
+
|
| 512 |
+
// Generic read functions; does not copy data if the input supports zero copy reads
|
| 513 |
+
|
| 514 |
+
/// \brief Read Schema from stream serialized as a single IPC message
|
| 515 |
+
/// and populate any dictionary-encoded fields into a DictionaryMemo
|
| 516 |
+
///
|
| 517 |
+
/// \param[in] stream an InputStream
|
| 518 |
+
/// \param[in] dictionary_memo for recording dictionary-encoded fields
|
| 519 |
+
/// \return the output Schema
|
| 520 |
+
///
|
| 521 |
+
/// If record batches follow the schema, it is better to use
|
| 522 |
+
/// RecordBatchStreamReader
|
| 523 |
+
ARROW_EXPORT
|
| 524 |
+
Result<std::shared_ptr<Schema>> ReadSchema(io::InputStream* stream,
|
| 525 |
+
DictionaryMemo* dictionary_memo);
|
| 526 |
+
|
| 527 |
+
/// \brief Read Schema from encapsulated Message
|
| 528 |
+
///
|
| 529 |
+
/// \param[in] message the message containing the Schema IPC metadata
|
| 530 |
+
/// \param[in] dictionary_memo DictionaryMemo for recording dictionary-encoded
|
| 531 |
+
/// fields. Can be nullptr if you are sure there are no
|
| 532 |
+
/// dictionary-encoded fields
|
| 533 |
+
/// \return the resulting Schema
|
| 534 |
+
ARROW_EXPORT
|
| 535 |
+
Result<std::shared_ptr<Schema>> ReadSchema(const Message& message,
|
| 536 |
+
DictionaryMemo* dictionary_memo);
|
| 537 |
+
|
| 538 |
+
/// Read record batch as encapsulated IPC message with metadata size prefix and
|
| 539 |
+
/// header
|
| 540 |
+
///
|
| 541 |
+
/// \param[in] schema the record batch schema
|
| 542 |
+
/// \param[in] dictionary_memo DictionaryMemo which has any
|
| 543 |
+
/// dictionaries. Can be nullptr if you are sure there are no
|
| 544 |
+
/// dictionary-encoded fields
|
| 545 |
+
/// \param[in] options IPC options for reading
|
| 546 |
+
/// \param[in] stream the file where the batch is located
|
| 547 |
+
/// \return the read record batch
|
| 548 |
+
ARROW_EXPORT
|
| 549 |
+
Result<std::shared_ptr<RecordBatch>> ReadRecordBatch(
|
| 550 |
+
const std::shared_ptr<Schema>& schema, const DictionaryMemo* dictionary_memo,
|
| 551 |
+
const IpcReadOptions& options, io::InputStream* stream);
|
| 552 |
+
|
| 553 |
+
/// \brief Read record batch from message
|
| 554 |
+
///
|
| 555 |
+
/// \param[in] message a Message containing the record batch metadata
|
| 556 |
+
/// \param[in] schema the record batch schema
|
| 557 |
+
/// \param[in] dictionary_memo DictionaryMemo which has any
|
| 558 |
+
/// dictionaries. Can be nullptr if you are sure there are no
|
| 559 |
+
/// dictionary-encoded fields
|
| 560 |
+
/// \param[in] options IPC options for reading
|
| 561 |
+
/// \return the read record batch
|
| 562 |
+
ARROW_EXPORT
|
| 563 |
+
Result<std::shared_ptr<RecordBatch>> ReadRecordBatch(
|
| 564 |
+
const Message& message, const std::shared_ptr<Schema>& schema,
|
| 565 |
+
const DictionaryMemo* dictionary_memo, const IpcReadOptions& options);
|
| 566 |
+
|
| 567 |
+
/// Read record batch from file given metadata and schema
|
| 568 |
+
///
|
| 569 |
+
/// \param[in] metadata a Message containing the record batch metadata
|
| 570 |
+
/// \param[in] schema the record batch schema
|
| 571 |
+
/// \param[in] dictionary_memo DictionaryMemo which has any
|
| 572 |
+
/// dictionaries. Can be nullptr if you are sure there are no
|
| 573 |
+
/// dictionary-encoded fields
|
| 574 |
+
/// \param[in] file a random access file
|
| 575 |
+
/// \param[in] options options for deserialization
|
| 576 |
+
/// \return the read record batch
|
| 577 |
+
ARROW_EXPORT
|
| 578 |
+
Result<std::shared_ptr<RecordBatch>> ReadRecordBatch(
|
| 579 |
+
const Buffer& metadata, const std::shared_ptr<Schema>& schema,
|
| 580 |
+
const DictionaryMemo* dictionary_memo, const IpcReadOptions& options,
|
| 581 |
+
io::RandomAccessFile* file);
|
| 582 |
+
|
| 583 |
+
/// \brief Read arrow::Tensor as encapsulated IPC message in file
|
| 584 |
+
///
|
| 585 |
+
/// \param[in] file an InputStream pointed at the start of the message
|
| 586 |
+
/// \return the read tensor
|
| 587 |
+
ARROW_EXPORT
|
| 588 |
+
Result<std::shared_ptr<Tensor>> ReadTensor(io::InputStream* file);
|
| 589 |
+
|
| 590 |
+
/// \brief EXPERIMENTAL: Read arrow::Tensor from IPC message
|
| 591 |
+
///
|
| 592 |
+
/// \param[in] message a Message containing the tensor metadata and body
|
| 593 |
+
/// \return the read tensor
|
| 594 |
+
ARROW_EXPORT
|
| 595 |
+
Result<std::shared_ptr<Tensor>> ReadTensor(const Message& message);
|
| 596 |
+
|
| 597 |
+
/// \brief EXPERIMENTAL: Read arrow::SparseTensor as encapsulated IPC message in file
|
| 598 |
+
///
|
| 599 |
+
/// \param[in] file an InputStream pointed at the start of the message
|
| 600 |
+
/// \return the read sparse tensor
|
| 601 |
+
ARROW_EXPORT
|
| 602 |
+
Result<std::shared_ptr<SparseTensor>> ReadSparseTensor(io::InputStream* file);
|
| 603 |
+
|
| 604 |
+
/// \brief EXPERIMENTAL: Read arrow::SparseTensor from IPC message
|
| 605 |
+
///
|
| 606 |
+
/// \param[in] message a Message containing the tensor metadata and body
|
| 607 |
+
/// \return the read sparse tensor
|
| 608 |
+
ARROW_EXPORT
|
| 609 |
+
Result<std::shared_ptr<SparseTensor>> ReadSparseTensor(const Message& message);
|
| 610 |
+
|
| 611 |
+
namespace internal {
|
| 612 |
+
|
| 613 |
+
// These internal APIs may change without warning or deprecation
|
| 614 |
+
|
| 615 |
+
/// \brief EXPERIMENTAL: Read arrow::SparseTensorFormat::type from a metadata
|
| 616 |
+
/// \param[in] metadata a Buffer containing the sparse tensor metadata
|
| 617 |
+
/// \return the count of the body buffers
|
| 618 |
+
ARROW_EXPORT
|
| 619 |
+
Result<size_t> ReadSparseTensorBodyBufferCount(const Buffer& metadata);
|
| 620 |
+
|
| 621 |
+
/// \brief EXPERIMENTAL: Read arrow::SparseTensor from an IpcPayload
|
| 622 |
+
/// \param[in] payload a IpcPayload contains a serialized SparseTensor
|
| 623 |
+
/// \return the read sparse tensor
|
| 624 |
+
ARROW_EXPORT
|
| 625 |
+
Result<std::shared_ptr<SparseTensor>> ReadSparseTensorPayload(const IpcPayload& payload);
|
| 626 |
+
|
| 627 |
+
// For fuzzing targets
|
| 628 |
+
ARROW_EXPORT
|
| 629 |
+
Status FuzzIpcStream(const uint8_t* data, int64_t size);
|
| 630 |
+
ARROW_EXPORT
|
| 631 |
+
Status FuzzIpcTensorStream(const uint8_t* data, int64_t size);
|
| 632 |
+
ARROW_EXPORT
|
| 633 |
+
Status FuzzIpcFile(const uint8_t* data, int64_t size);
|
| 634 |
+
|
| 635 |
+
} // namespace internal
|
| 636 |
+
|
| 637 |
+
} // namespace ipc
|
| 638 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/test_common.h
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <cstdint>
|
| 21 |
+
#include <memory>
|
| 22 |
+
#include <vector>
|
| 23 |
+
|
| 24 |
+
#include "arrow/array.h"
|
| 25 |
+
#include "arrow/record_batch.h"
|
| 26 |
+
#include "arrow/status.h"
|
| 27 |
+
#include "arrow/testing/visibility.h"
|
| 28 |
+
#include "arrow/type.h"
|
| 29 |
+
|
| 30 |
+
namespace arrow {
|
| 31 |
+
namespace ipc {
|
| 32 |
+
namespace test {
|
| 33 |
+
|
| 34 |
+
// A typedef used for test parameterization
|
| 35 |
+
typedef Status MakeRecordBatch(std::shared_ptr<RecordBatch>* out);
|
| 36 |
+
|
| 37 |
+
ARROW_TESTING_EXPORT
|
| 38 |
+
void CompareArraysDetailed(int index, const Array& result, const Array& expected);
|
| 39 |
+
|
| 40 |
+
ARROW_TESTING_EXPORT
|
| 41 |
+
void CompareBatchColumnsDetailed(const RecordBatch& result, const RecordBatch& expected);
|
| 42 |
+
|
| 43 |
+
ARROW_TESTING_EXPORT
|
| 44 |
+
Status MakeRandomInt32Array(int64_t length, bool include_nulls, MemoryPool* pool,
|
| 45 |
+
std::shared_ptr<Array>* out, uint32_t seed = 0,
|
| 46 |
+
int32_t min = 0, int32_t max = 1000);
|
| 47 |
+
|
| 48 |
+
ARROW_TESTING_EXPORT
|
| 49 |
+
Status MakeRandomInt64Array(int64_t length, bool include_nulls, MemoryPool* pool,
|
| 50 |
+
std::shared_ptr<Array>* out, uint32_t seed = 0);
|
| 51 |
+
|
| 52 |
+
ARROW_TESTING_EXPORT
|
| 53 |
+
Status MakeRandomListArray(const std::shared_ptr<Array>& child_array, int num_lists,
|
| 54 |
+
bool include_nulls, MemoryPool* pool,
|
| 55 |
+
std::shared_ptr<Array>* out);
|
| 56 |
+
|
| 57 |
+
ARROW_TESTING_EXPORT
|
| 58 |
+
Status MakeRandomLargeListArray(const std::shared_ptr<Array>& child_array, int num_lists,
|
| 59 |
+
bool include_nulls, MemoryPool* pool,
|
| 60 |
+
std::shared_ptr<Array>* out);
|
| 61 |
+
|
| 62 |
+
ARROW_TESTING_EXPORT
|
| 63 |
+
Status MakeRandomBooleanArray(const int length, bool include_nulls,
|
| 64 |
+
std::shared_ptr<Array>* out);
|
| 65 |
+
|
| 66 |
+
ARROW_TESTING_EXPORT
|
| 67 |
+
Status MakeBooleanBatchSized(const int length, std::shared_ptr<RecordBatch>* out);
|
| 68 |
+
|
| 69 |
+
ARROW_TESTING_EXPORT
|
| 70 |
+
Status MakeBooleanBatch(std::shared_ptr<RecordBatch>* out);
|
| 71 |
+
|
| 72 |
+
ARROW_TESTING_EXPORT
|
| 73 |
+
Status MakeIntBatchSized(int length, std::shared_ptr<RecordBatch>* out,
|
| 74 |
+
uint32_t seed = 0);
|
| 75 |
+
|
| 76 |
+
ARROW_TESTING_EXPORT
|
| 77 |
+
Status MakeIntRecordBatch(std::shared_ptr<RecordBatch>* out);
|
| 78 |
+
|
| 79 |
+
ARROW_TESTING_EXPORT
|
| 80 |
+
Status MakeFloat3264BatchSized(int length, std::shared_ptr<RecordBatch>* out,
|
| 81 |
+
uint32_t seed = 0);
|
| 82 |
+
|
| 83 |
+
ARROW_TESTING_EXPORT
|
| 84 |
+
Status MakeFloat3264Batch(std::shared_ptr<RecordBatch>* out);
|
| 85 |
+
|
| 86 |
+
ARROW_TESTING_EXPORT
|
| 87 |
+
Status MakeFloatBatchSized(int length, std::shared_ptr<RecordBatch>* out,
|
| 88 |
+
uint32_t seed = 0);
|
| 89 |
+
|
| 90 |
+
ARROW_TESTING_EXPORT
|
| 91 |
+
Status MakeFloatBatch(std::shared_ptr<RecordBatch>* out);
|
| 92 |
+
|
| 93 |
+
ARROW_TESTING_EXPORT
|
| 94 |
+
Status MakeRandomStringArray(int64_t length, bool include_nulls, MemoryPool* pool,
|
| 95 |
+
std::shared_ptr<Array>* out);
|
| 96 |
+
|
| 97 |
+
ARROW_TESTING_EXPORT
|
| 98 |
+
Status MakeStringTypesRecordBatch(std::shared_ptr<RecordBatch>* out,
|
| 99 |
+
bool with_nulls = true, bool with_view_types = true);
|
| 100 |
+
|
| 101 |
+
ARROW_TESTING_EXPORT
|
| 102 |
+
Status MakeStringTypesRecordBatchWithNulls(std::shared_ptr<RecordBatch>* out);
|
| 103 |
+
|
| 104 |
+
ARROW_TESTING_EXPORT
|
| 105 |
+
Status MakeNullRecordBatch(std::shared_ptr<RecordBatch>* out);
|
| 106 |
+
|
| 107 |
+
ARROW_TESTING_EXPORT
|
| 108 |
+
Status MakeListRecordBatch(std::shared_ptr<RecordBatch>* out);
|
| 109 |
+
|
| 110 |
+
ARROW_TESTING_EXPORT
|
| 111 |
+
Status MakeListViewRecordBatch(std::shared_ptr<RecordBatch>* out);
|
| 112 |
+
|
| 113 |
+
ARROW_TESTING_EXPORT
|
| 114 |
+
Status MakeFixedSizeListRecordBatch(std::shared_ptr<RecordBatch>* out);
|
| 115 |
+
|
| 116 |
+
ARROW_TESTING_EXPORT
|
| 117 |
+
Status MakeZeroLengthRecordBatch(std::shared_ptr<RecordBatch>* out);
|
| 118 |
+
|
| 119 |
+
ARROW_TESTING_EXPORT
|
| 120 |
+
Status MakeNonNullRecordBatch(std::shared_ptr<RecordBatch>* out);
|
| 121 |
+
|
| 122 |
+
ARROW_TESTING_EXPORT
|
| 123 |
+
Status MakeDeeplyNestedList(std::shared_ptr<RecordBatch>* out);
|
| 124 |
+
|
| 125 |
+
ARROW_TESTING_EXPORT
|
| 126 |
+
Status MakeDeeplyNestedListView(std::shared_ptr<RecordBatch>* out);
|
| 127 |
+
|
| 128 |
+
ARROW_TESTING_EXPORT
|
| 129 |
+
Status MakeStruct(std::shared_ptr<RecordBatch>* out);
|
| 130 |
+
|
| 131 |
+
ARROW_TESTING_EXPORT
|
| 132 |
+
Status MakeRunEndEncoded(std::shared_ptr<RecordBatch>* out);
|
| 133 |
+
|
| 134 |
+
ARROW_TESTING_EXPORT
|
| 135 |
+
Status MakeUnion(std::shared_ptr<RecordBatch>* out);
|
| 136 |
+
|
| 137 |
+
ARROW_TESTING_EXPORT
|
| 138 |
+
Status MakeDictionary(std::shared_ptr<RecordBatch>* out);
|
| 139 |
+
|
| 140 |
+
ARROW_TESTING_EXPORT
|
| 141 |
+
Status MakeDictionaryFlat(std::shared_ptr<RecordBatch>* out);
|
| 142 |
+
|
| 143 |
+
ARROW_TESTING_EXPORT
|
| 144 |
+
Status MakeNestedDictionary(std::shared_ptr<RecordBatch>* out);
|
| 145 |
+
|
| 146 |
+
ARROW_TESTING_EXPORT
|
| 147 |
+
Status MakeMap(std::shared_ptr<RecordBatch>* out);
|
| 148 |
+
|
| 149 |
+
ARROW_TESTING_EXPORT
|
| 150 |
+
Status MakeMapOfDictionary(std::shared_ptr<RecordBatch>* out);
|
| 151 |
+
|
| 152 |
+
ARROW_TESTING_EXPORT
|
| 153 |
+
Status MakeDates(std::shared_ptr<RecordBatch>* out);
|
| 154 |
+
|
| 155 |
+
ARROW_TESTING_EXPORT
|
| 156 |
+
Status MakeTimestamps(std::shared_ptr<RecordBatch>* out);
|
| 157 |
+
|
| 158 |
+
ARROW_TESTING_EXPORT
|
| 159 |
+
Status MakeIntervals(std::shared_ptr<RecordBatch>* out);
|
| 160 |
+
|
| 161 |
+
ARROW_TESTING_EXPORT
|
| 162 |
+
Status MakeTimes(std::shared_ptr<RecordBatch>* out);
|
| 163 |
+
|
| 164 |
+
ARROW_TESTING_EXPORT
|
| 165 |
+
Status MakeFWBinary(std::shared_ptr<RecordBatch>* out);
|
| 166 |
+
|
| 167 |
+
ARROW_TESTING_EXPORT
|
| 168 |
+
Status MakeDecimal(std::shared_ptr<RecordBatch>* out);
|
| 169 |
+
|
| 170 |
+
ARROW_TESTING_EXPORT
|
| 171 |
+
Status MakeNull(std::shared_ptr<RecordBatch>* out);
|
| 172 |
+
|
| 173 |
+
ARROW_TESTING_EXPORT
|
| 174 |
+
Status MakeUuid(std::shared_ptr<RecordBatch>* out);
|
| 175 |
+
|
| 176 |
+
ARROW_TESTING_EXPORT
|
| 177 |
+
Status MakeComplex128(std::shared_ptr<RecordBatch>* out);
|
| 178 |
+
|
| 179 |
+
ARROW_TESTING_EXPORT
|
| 180 |
+
Status MakeDictExtension(std::shared_ptr<RecordBatch>* out);
|
| 181 |
+
|
| 182 |
+
ARROW_TESTING_EXPORT
|
| 183 |
+
Status MakeRandomTensor(const std::shared_ptr<DataType>& type,
|
| 184 |
+
const std::vector<int64_t>& shape, bool row_major_p,
|
| 185 |
+
std::shared_ptr<Tensor>* out, uint32_t seed = 0);
|
| 186 |
+
|
| 187 |
+
} // namespace test
|
| 188 |
+
} // namespace ipc
|
| 189 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/type_fwd.h
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
namespace arrow {
|
| 21 |
+
namespace ipc {
|
| 22 |
+
|
| 23 |
+
enum class MetadataVersion : char {
|
| 24 |
+
/// 0.1.0
|
| 25 |
+
V1,
|
| 26 |
+
|
| 27 |
+
/// 0.2.0
|
| 28 |
+
V2,
|
| 29 |
+
|
| 30 |
+
/// 0.3.0 to 0.7.1
|
| 31 |
+
V3,
|
| 32 |
+
|
| 33 |
+
/// 0.8.0 to 0.17.0
|
| 34 |
+
V4,
|
| 35 |
+
|
| 36 |
+
/// >= 1.0.0
|
| 37 |
+
V5
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
class Message;
|
| 41 |
+
enum class MessageType {
|
| 42 |
+
NONE,
|
| 43 |
+
SCHEMA,
|
| 44 |
+
DICTIONARY_BATCH,
|
| 45 |
+
RECORD_BATCH,
|
| 46 |
+
TENSOR,
|
| 47 |
+
SPARSE_TENSOR
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
struct IpcReadOptions;
|
| 51 |
+
struct IpcWriteOptions;
|
| 52 |
+
|
| 53 |
+
class MessageReader;
|
| 54 |
+
|
| 55 |
+
class RecordBatchStreamReader;
|
| 56 |
+
class RecordBatchFileReader;
|
| 57 |
+
class RecordBatchWriter;
|
| 58 |
+
|
| 59 |
+
class DictionaryFieldMapper;
|
| 60 |
+
class DictionaryMemo;
|
| 61 |
+
|
| 62 |
+
namespace feather {
|
| 63 |
+
|
| 64 |
+
class Reader;
|
| 65 |
+
|
| 66 |
+
} // namespace feather
|
| 67 |
+
} // namespace ipc
|
| 68 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/ipc/writer.h
ADDED
|
@@ -0,0 +1,475 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
// Implement Arrow streaming binary format
|
| 19 |
+
|
| 20 |
+
#pragma once
|
| 21 |
+
|
| 22 |
+
#include <cstdint>
|
| 23 |
+
#include <memory>
|
| 24 |
+
#include <vector>
|
| 25 |
+
|
| 26 |
+
#include "arrow/ipc/dictionary.h" // IWYU pragma: export
|
| 27 |
+
#include "arrow/ipc/message.h"
|
| 28 |
+
#include "arrow/ipc/options.h"
|
| 29 |
+
#include "arrow/result.h"
|
| 30 |
+
#include "arrow/util/macros.h"
|
| 31 |
+
#include "arrow/util/visibility.h"
|
| 32 |
+
|
| 33 |
+
namespace arrow {
|
| 34 |
+
|
| 35 |
+
class Array;
|
| 36 |
+
class Buffer;
|
| 37 |
+
class MemoryManager;
|
| 38 |
+
class MemoryPool;
|
| 39 |
+
class RecordBatch;
|
| 40 |
+
class Schema;
|
| 41 |
+
class Status;
|
| 42 |
+
class Table;
|
| 43 |
+
class Tensor;
|
| 44 |
+
class SparseTensor;
|
| 45 |
+
|
| 46 |
+
namespace io {
|
| 47 |
+
|
| 48 |
+
class OutputStream;
|
| 49 |
+
|
| 50 |
+
} // namespace io
|
| 51 |
+
|
| 52 |
+
namespace ipc {
|
| 53 |
+
|
| 54 |
+
/// \brief Intermediate data structure with metadata header, and zero
|
| 55 |
+
/// or more buffers for the message body.
|
| 56 |
+
struct IpcPayload {
|
| 57 |
+
MessageType type = MessageType::NONE;
|
| 58 |
+
std::shared_ptr<Buffer> metadata;
|
| 59 |
+
std::vector<std::shared_ptr<Buffer>> body_buffers;
|
| 60 |
+
std::vector<int64_t> variadic_buffer_counts;
|
| 61 |
+
int64_t body_length = 0; // serialized body length (padded, maybe compressed)
|
| 62 |
+
int64_t raw_body_length = 0; // initial uncompressed body length
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
struct WriteStats {
|
| 66 |
+
/// Number of IPC messages written.
|
| 67 |
+
int64_t num_messages = 0;
|
| 68 |
+
/// Number of record batches written.
|
| 69 |
+
int64_t num_record_batches = 0;
|
| 70 |
+
/// Number of dictionary batches written.
|
| 71 |
+
///
|
| 72 |
+
/// Note: num_dictionary_batches >= num_dictionary_deltas + num_replaced_dictionaries
|
| 73 |
+
int64_t num_dictionary_batches = 0;
|
| 74 |
+
|
| 75 |
+
/// Number of dictionary deltas written.
|
| 76 |
+
int64_t num_dictionary_deltas = 0;
|
| 77 |
+
/// Number of replaced dictionaries (i.e. where a dictionary batch replaces
|
| 78 |
+
/// an existing dictionary with an unrelated new dictionary).
|
| 79 |
+
int64_t num_replaced_dictionaries = 0;
|
| 80 |
+
|
| 81 |
+
/// Total size in bytes of record batches emitted.
|
| 82 |
+
/// The "raw" size counts the original buffer sizes, while the "serialized" size
|
| 83 |
+
/// includes padding and (optionally) compression.
|
| 84 |
+
int64_t total_raw_body_size = 0;
|
| 85 |
+
int64_t total_serialized_body_size = 0;
|
| 86 |
+
};
|
| 87 |
+
|
| 88 |
+
/// \class RecordBatchWriter
|
| 89 |
+
/// \brief Abstract interface for writing a stream of record batches
|
| 90 |
+
class ARROW_EXPORT RecordBatchWriter {
|
| 91 |
+
public:
|
| 92 |
+
virtual ~RecordBatchWriter();
|
| 93 |
+
|
| 94 |
+
/// \brief Write a record batch to the stream
|
| 95 |
+
///
|
| 96 |
+
/// \param[in] batch the record batch to write to the stream
|
| 97 |
+
/// \return Status
|
| 98 |
+
virtual Status WriteRecordBatch(const RecordBatch& batch) = 0;
|
| 99 |
+
|
| 100 |
+
/// \brief Write a record batch with custom metadata to the stream
|
| 101 |
+
///
|
| 102 |
+
/// \param[in] batch the record batch to write to the stream
|
| 103 |
+
/// \param[in] custom_metadata the record batch's custom metadata to write to the stream
|
| 104 |
+
/// \return Status
|
| 105 |
+
virtual Status WriteRecordBatch(
|
| 106 |
+
const RecordBatch& batch,
|
| 107 |
+
const std::shared_ptr<const KeyValueMetadata>& custom_metadata);
|
| 108 |
+
|
| 109 |
+
/// \brief Write possibly-chunked table by creating sequence of record batches
|
| 110 |
+
/// \param[in] table table to write
|
| 111 |
+
/// \return Status
|
| 112 |
+
Status WriteTable(const Table& table);
|
| 113 |
+
|
| 114 |
+
/// \brief Write Table with a particular chunksize
|
| 115 |
+
/// \param[in] table table to write
|
| 116 |
+
/// \param[in] max_chunksize maximum number of rows for table chunks. To
|
| 117 |
+
/// indicate that no maximum should be enforced, pass -1.
|
| 118 |
+
/// \return Status
|
| 119 |
+
virtual Status WriteTable(const Table& table, int64_t max_chunksize);
|
| 120 |
+
|
| 121 |
+
/// \brief Perform any logic necessary to finish the stream
|
| 122 |
+
///
|
| 123 |
+
/// \return Status
|
| 124 |
+
virtual Status Close() = 0;
|
| 125 |
+
|
| 126 |
+
/// \brief Return current write statistics
|
| 127 |
+
virtual WriteStats stats() const = 0;
|
| 128 |
+
};
|
| 129 |
+
|
| 130 |
+
/// \defgroup record-batch-writer-factories Functions for creating RecordBatchWriter
|
| 131 |
+
/// instances
|
| 132 |
+
///
|
| 133 |
+
/// @{
|
| 134 |
+
|
| 135 |
+
/// Create a new IPC stream writer from stream sink and schema. User is
|
| 136 |
+
/// responsible for closing the actual OutputStream.
|
| 137 |
+
///
|
| 138 |
+
/// \param[in] sink output stream to write to
|
| 139 |
+
/// \param[in] schema the schema of the record batches to be written
|
| 140 |
+
/// \param[in] options options for serialization
|
| 141 |
+
/// \return Result<std::shared_ptr<RecordBatchWriter>>
|
| 142 |
+
ARROW_EXPORT
|
| 143 |
+
Result<std::shared_ptr<RecordBatchWriter>> MakeStreamWriter(
|
| 144 |
+
io::OutputStream* sink, const std::shared_ptr<Schema>& schema,
|
| 145 |
+
const IpcWriteOptions& options = IpcWriteOptions::Defaults());
|
| 146 |
+
|
| 147 |
+
/// Create a new IPC stream writer from stream sink and schema. User is
|
| 148 |
+
/// responsible for closing the actual OutputStream.
|
| 149 |
+
///
|
| 150 |
+
/// \param[in] sink output stream to write to
|
| 151 |
+
/// \param[in] schema the schema of the record batches to be written
|
| 152 |
+
/// \param[in] options options for serialization
|
| 153 |
+
/// \return Result<std::shared_ptr<RecordBatchWriter>>
|
| 154 |
+
ARROW_EXPORT
|
| 155 |
+
Result<std::shared_ptr<RecordBatchWriter>> MakeStreamWriter(
|
| 156 |
+
std::shared_ptr<io::OutputStream> sink, const std::shared_ptr<Schema>& schema,
|
| 157 |
+
const IpcWriteOptions& options = IpcWriteOptions::Defaults());
|
| 158 |
+
|
| 159 |
+
/// Create a new IPC file writer from stream sink and schema
|
| 160 |
+
///
|
| 161 |
+
/// \param[in] sink output stream to write to
|
| 162 |
+
/// \param[in] schema the schema of the record batches to be written
|
| 163 |
+
/// \param[in] options options for serialization, optional
|
| 164 |
+
/// \param[in] metadata custom metadata for File Footer, optional
|
| 165 |
+
/// \return Result<std::shared_ptr<RecordBatchWriter>>
|
| 166 |
+
ARROW_EXPORT
|
| 167 |
+
Result<std::shared_ptr<RecordBatchWriter>> MakeFileWriter(
|
| 168 |
+
io::OutputStream* sink, const std::shared_ptr<Schema>& schema,
|
| 169 |
+
const IpcWriteOptions& options = IpcWriteOptions::Defaults(),
|
| 170 |
+
const std::shared_ptr<const KeyValueMetadata>& metadata = NULLPTR);
|
| 171 |
+
|
| 172 |
+
/// Create a new IPC file writer from stream sink and schema
|
| 173 |
+
///
|
| 174 |
+
/// \param[in] sink output stream to write to
|
| 175 |
+
/// \param[in] schema the schema of the record batches to be written
|
| 176 |
+
/// \param[in] options options for serialization, optional
|
| 177 |
+
/// \param[in] metadata custom metadata for File Footer, optional
|
| 178 |
+
/// \return Result<std::shared_ptr<RecordBatchWriter>>
|
| 179 |
+
ARROW_EXPORT
|
| 180 |
+
Result<std::shared_ptr<RecordBatchWriter>> MakeFileWriter(
|
| 181 |
+
std::shared_ptr<io::OutputStream> sink, const std::shared_ptr<Schema>& schema,
|
| 182 |
+
const IpcWriteOptions& options = IpcWriteOptions::Defaults(),
|
| 183 |
+
const std::shared_ptr<const KeyValueMetadata>& metadata = NULLPTR);
|
| 184 |
+
|
| 185 |
+
/// @}
|
| 186 |
+
|
| 187 |
+
/// \brief Low-level API for writing a record batch (without schema)
|
| 188 |
+
/// to an OutputStream as encapsulated IPC message. See Arrow format
|
| 189 |
+
/// documentation for more detail.
|
| 190 |
+
///
|
| 191 |
+
/// \param[in] batch the record batch to write
|
| 192 |
+
/// \param[in] buffer_start_offset the start offset to use in the buffer metadata,
|
| 193 |
+
/// generally should be 0
|
| 194 |
+
/// \param[in] dst an OutputStream
|
| 195 |
+
/// \param[out] metadata_length the size of the length-prefixed flatbuffer
|
| 196 |
+
/// including padding to a 64-byte boundary
|
| 197 |
+
/// \param[out] body_length the size of the contiguous buffer block plus
|
| 198 |
+
/// \param[in] options options for serialization
|
| 199 |
+
/// \return Status
|
| 200 |
+
ARROW_EXPORT
|
| 201 |
+
Status WriteRecordBatch(const RecordBatch& batch, int64_t buffer_start_offset,
|
| 202 |
+
io::OutputStream* dst, int32_t* metadata_length,
|
| 203 |
+
int64_t* body_length, const IpcWriteOptions& options);
|
| 204 |
+
|
| 205 |
+
/// \brief Serialize record batch as encapsulated IPC message in a new buffer
|
| 206 |
+
///
|
| 207 |
+
/// \param[in] batch the record batch
|
| 208 |
+
/// \param[in] options the IpcWriteOptions to use for serialization
|
| 209 |
+
/// \return the serialized message
|
| 210 |
+
ARROW_EXPORT
|
| 211 |
+
Result<std::shared_ptr<Buffer>> SerializeRecordBatch(const RecordBatch& batch,
|
| 212 |
+
const IpcWriteOptions& options);
|
| 213 |
+
|
| 214 |
+
/// \brief Serialize record batch as encapsulated IPC message in a new buffer
|
| 215 |
+
///
|
| 216 |
+
/// \param[in] batch the record batch
|
| 217 |
+
/// \param[in] mm a MemoryManager to allocate memory from
|
| 218 |
+
/// \return the serialized message
|
| 219 |
+
ARROW_EXPORT
|
| 220 |
+
Result<std::shared_ptr<Buffer>> SerializeRecordBatch(const RecordBatch& batch,
|
| 221 |
+
std::shared_ptr<MemoryManager> mm);
|
| 222 |
+
|
| 223 |
+
/// \brief Write record batch to OutputStream
|
| 224 |
+
///
|
| 225 |
+
/// \param[in] batch the record batch to write
|
| 226 |
+
/// \param[in] options the IpcWriteOptions to use for serialization
|
| 227 |
+
/// \param[in] out the OutputStream to write the output to
|
| 228 |
+
/// \return Status
|
| 229 |
+
///
|
| 230 |
+
/// If writing to pre-allocated memory, you can use
|
| 231 |
+
/// arrow::ipc::GetRecordBatchSize to compute how much space is required
|
| 232 |
+
ARROW_EXPORT
|
| 233 |
+
Status SerializeRecordBatch(const RecordBatch& batch, const IpcWriteOptions& options,
|
| 234 |
+
io::OutputStream* out);
|
| 235 |
+
|
| 236 |
+
/// \brief Serialize schema as encapsulated IPC message
|
| 237 |
+
///
|
| 238 |
+
/// \param[in] schema the schema to write
|
| 239 |
+
/// \param[in] pool a MemoryPool to allocate memory from
|
| 240 |
+
/// \return the serialized schema
|
| 241 |
+
ARROW_EXPORT
|
| 242 |
+
Result<std::shared_ptr<Buffer>> SerializeSchema(const Schema& schema,
|
| 243 |
+
MemoryPool* pool = default_memory_pool());
|
| 244 |
+
|
| 245 |
+
/// \brief Write multiple record batches to OutputStream, including schema
|
| 246 |
+
/// \param[in] batches a vector of batches. Must all have same schema
|
| 247 |
+
/// \param[in] options options for serialization
|
| 248 |
+
/// \param[out] dst an OutputStream
|
| 249 |
+
/// \return Status
|
| 250 |
+
ARROW_EXPORT
|
| 251 |
+
Status WriteRecordBatchStream(const std::vector<std::shared_ptr<RecordBatch>>& batches,
|
| 252 |
+
const IpcWriteOptions& options, io::OutputStream* dst);
|
| 253 |
+
|
| 254 |
+
/// \brief Compute the number of bytes needed to write an IPC payload
|
| 255 |
+
/// including metadata
|
| 256 |
+
///
|
| 257 |
+
/// \param[in] payload the IPC payload to write
|
| 258 |
+
/// \param[in] options write options
|
| 259 |
+
/// \return the size of the complete encapsulated message
|
| 260 |
+
ARROW_EXPORT
|
| 261 |
+
int64_t GetPayloadSize(const IpcPayload& payload,
|
| 262 |
+
const IpcWriteOptions& options = IpcWriteOptions::Defaults());
|
| 263 |
+
|
| 264 |
+
/// \brief Compute the number of bytes needed to write a record batch including metadata
|
| 265 |
+
///
|
| 266 |
+
/// \param[in] batch the record batch to write
|
| 267 |
+
/// \param[out] size the size of the complete encapsulated message
|
| 268 |
+
/// \return Status
|
| 269 |
+
ARROW_EXPORT
|
| 270 |
+
Status GetRecordBatchSize(const RecordBatch& batch, int64_t* size);
|
| 271 |
+
|
| 272 |
+
/// \brief Compute the number of bytes needed to write a record batch including metadata
|
| 273 |
+
///
|
| 274 |
+
/// \param[in] batch the record batch to write
|
| 275 |
+
/// \param[in] options options for serialization
|
| 276 |
+
/// \param[out] size the size of the complete encapsulated message
|
| 277 |
+
/// \return Status
|
| 278 |
+
ARROW_EXPORT
|
| 279 |
+
Status GetRecordBatchSize(const RecordBatch& batch, const IpcWriteOptions& options,
|
| 280 |
+
int64_t* size);
|
| 281 |
+
|
| 282 |
+
/// \brief Compute the number of bytes needed to write a tensor including metadata
|
| 283 |
+
///
|
| 284 |
+
/// \param[in] tensor the tensor to write
|
| 285 |
+
/// \param[out] size the size of the complete encapsulated message
|
| 286 |
+
/// \return Status
|
| 287 |
+
ARROW_EXPORT
|
| 288 |
+
Status GetTensorSize(const Tensor& tensor, int64_t* size);
|
| 289 |
+
|
| 290 |
+
/// \brief EXPERIMENTAL: Convert arrow::Tensor to a Message with minimal memory
|
| 291 |
+
/// allocation
|
| 292 |
+
///
|
| 293 |
+
/// \param[in] tensor the Tensor to write
|
| 294 |
+
/// \param[in] pool MemoryPool to allocate space for metadata
|
| 295 |
+
/// \return the resulting Message
|
| 296 |
+
ARROW_EXPORT
|
| 297 |
+
Result<std::unique_ptr<Message>> GetTensorMessage(const Tensor& tensor, MemoryPool* pool);
|
| 298 |
+
|
| 299 |
+
/// \brief Write arrow::Tensor as a contiguous message.
|
| 300 |
+
///
|
| 301 |
+
/// The metadata and body are written assuming 64-byte alignment. It is the
|
| 302 |
+
/// user's responsibility to ensure that the OutputStream has been aligned
|
| 303 |
+
/// to a 64-byte multiple before writing the message.
|
| 304 |
+
///
|
| 305 |
+
/// The message is written out as followed:
|
| 306 |
+
/// \code
|
| 307 |
+
/// <metadata size> <metadata> <tensor data>
|
| 308 |
+
/// \endcode
|
| 309 |
+
///
|
| 310 |
+
/// \param[in] tensor the Tensor to write
|
| 311 |
+
/// \param[in] dst the OutputStream to write to
|
| 312 |
+
/// \param[out] metadata_length the actual metadata length, including padding
|
| 313 |
+
/// \param[out] body_length the actual message body length
|
| 314 |
+
/// \return Status
|
| 315 |
+
ARROW_EXPORT
|
| 316 |
+
Status WriteTensor(const Tensor& tensor, io::OutputStream* dst, int32_t* metadata_length,
|
| 317 |
+
int64_t* body_length);
|
| 318 |
+
|
| 319 |
+
/// \brief EXPERIMENTAL: Convert arrow::SparseTensor to a Message with minimal memory
|
| 320 |
+
/// allocation
|
| 321 |
+
///
|
| 322 |
+
/// The message is written out as followed:
|
| 323 |
+
/// \code
|
| 324 |
+
/// <metadata size> <metadata> <sparse index> <sparse tensor body>
|
| 325 |
+
/// \endcode
|
| 326 |
+
///
|
| 327 |
+
/// \param[in] sparse_tensor the SparseTensor to write
|
| 328 |
+
/// \param[in] pool MemoryPool to allocate space for metadata
|
| 329 |
+
/// \return the resulting Message
|
| 330 |
+
ARROW_EXPORT
|
| 331 |
+
Result<std::unique_ptr<Message>> GetSparseTensorMessage(const SparseTensor& sparse_tensor,
|
| 332 |
+
MemoryPool* pool);
|
| 333 |
+
|
| 334 |
+
/// \brief EXPERIMENTAL: Write arrow::SparseTensor as a contiguous message. The metadata,
|
| 335 |
+
/// sparse index, and body are written assuming 64-byte alignment. It is the
|
| 336 |
+
/// user's responsibility to ensure that the OutputStream has been aligned
|
| 337 |
+
/// to a 64-byte multiple before writing the message.
|
| 338 |
+
///
|
| 339 |
+
/// \param[in] sparse_tensor the SparseTensor to write
|
| 340 |
+
/// \param[in] dst the OutputStream to write to
|
| 341 |
+
/// \param[out] metadata_length the actual metadata length, including padding
|
| 342 |
+
/// \param[out] body_length the actual message body length
|
| 343 |
+
/// \return Status
|
| 344 |
+
ARROW_EXPORT
|
| 345 |
+
Status WriteSparseTensor(const SparseTensor& sparse_tensor, io::OutputStream* dst,
|
| 346 |
+
int32_t* metadata_length, int64_t* body_length);
|
| 347 |
+
|
| 348 |
+
/// \brief Compute IpcPayload for the given schema
|
| 349 |
+
/// \param[in] schema the Schema that is being serialized
|
| 350 |
+
/// \param[in] options options for serialization
|
| 351 |
+
/// \param[in] mapper object mapping dictionary fields to dictionary ids
|
| 352 |
+
/// \param[out] out the returned vector of IpcPayloads
|
| 353 |
+
/// \return Status
|
| 354 |
+
ARROW_EXPORT
|
| 355 |
+
Status GetSchemaPayload(const Schema& schema, const IpcWriteOptions& options,
|
| 356 |
+
const DictionaryFieldMapper& mapper, IpcPayload* out);
|
| 357 |
+
|
| 358 |
+
/// \brief Compute IpcPayload for a dictionary
|
| 359 |
+
/// \param[in] id the dictionary id
|
| 360 |
+
/// \param[in] dictionary the dictionary values
|
| 361 |
+
/// \param[in] options options for serialization
|
| 362 |
+
/// \param[out] payload the output IpcPayload
|
| 363 |
+
/// \return Status
|
| 364 |
+
ARROW_EXPORT
|
| 365 |
+
Status GetDictionaryPayload(int64_t id, const std::shared_ptr<Array>& dictionary,
|
| 366 |
+
const IpcWriteOptions& options, IpcPayload* payload);
|
| 367 |
+
|
| 368 |
+
/// \brief Compute IpcPayload for a dictionary
|
| 369 |
+
/// \param[in] id the dictionary id
|
| 370 |
+
/// \param[in] is_delta whether the dictionary is a delta dictionary
|
| 371 |
+
/// \param[in] dictionary the dictionary values
|
| 372 |
+
/// \param[in] options options for serialization
|
| 373 |
+
/// \param[out] payload the output IpcPayload
|
| 374 |
+
/// \return Status
|
| 375 |
+
ARROW_EXPORT
|
| 376 |
+
Status GetDictionaryPayload(int64_t id, bool is_delta,
|
| 377 |
+
const std::shared_ptr<Array>& dictionary,
|
| 378 |
+
const IpcWriteOptions& options, IpcPayload* payload);
|
| 379 |
+
|
| 380 |
+
/// \brief Compute IpcPayload for the given record batch
|
| 381 |
+
/// \param[in] batch the RecordBatch that is being serialized
|
| 382 |
+
/// \param[in] options options for serialization
|
| 383 |
+
/// \param[out] out the returned IpcPayload
|
| 384 |
+
/// \return Status
|
| 385 |
+
ARROW_EXPORT
|
| 386 |
+
Status GetRecordBatchPayload(const RecordBatch& batch, const IpcWriteOptions& options,
|
| 387 |
+
IpcPayload* out);
|
| 388 |
+
|
| 389 |
+
/// \brief Compute IpcPayload for the given record batch and custom metadata
|
| 390 |
+
/// \param[in] batch the RecordBatch that is being serialized
|
| 391 |
+
/// \param[in] custom_metadata the custom metadata to be serialized with the record batch
|
| 392 |
+
/// \param[in] options options for serialization
|
| 393 |
+
/// \param[out] out the returned IpcPayload
|
| 394 |
+
/// \return Status
|
| 395 |
+
ARROW_EXPORT
|
| 396 |
+
Status GetRecordBatchPayload(
|
| 397 |
+
const RecordBatch& batch,
|
| 398 |
+
const std::shared_ptr<const KeyValueMetadata>& custom_metadata,
|
| 399 |
+
const IpcWriteOptions& options, IpcPayload* out);
|
| 400 |
+
|
| 401 |
+
/// \brief Write an IPC payload to the given stream.
|
| 402 |
+
/// \param[in] payload the payload to write
|
| 403 |
+
/// \param[in] options options for serialization
|
| 404 |
+
/// \param[in] dst The stream to write the payload to.
|
| 405 |
+
/// \param[out] metadata_length the length of the serialized metadata
|
| 406 |
+
/// \return Status
|
| 407 |
+
ARROW_EXPORT
|
| 408 |
+
Status WriteIpcPayload(const IpcPayload& payload, const IpcWriteOptions& options,
|
| 409 |
+
io::OutputStream* dst, int32_t* metadata_length);
|
| 410 |
+
|
| 411 |
+
/// \brief Compute IpcPayload for the given sparse tensor
|
| 412 |
+
/// \param[in] sparse_tensor the SparseTensor that is being serialized
|
| 413 |
+
/// \param[in,out] pool for any required temporary memory allocations
|
| 414 |
+
/// \param[out] out the returned IpcPayload
|
| 415 |
+
/// \return Status
|
| 416 |
+
ARROW_EXPORT
|
| 417 |
+
Status GetSparseTensorPayload(const SparseTensor& sparse_tensor, MemoryPool* pool,
|
| 418 |
+
IpcPayload* out);
|
| 419 |
+
|
| 420 |
+
namespace internal {
|
| 421 |
+
|
| 422 |
+
// These internal APIs may change without warning or deprecation
|
| 423 |
+
|
| 424 |
+
class ARROW_EXPORT IpcPayloadWriter {
|
| 425 |
+
public:
|
| 426 |
+
virtual ~IpcPayloadWriter();
|
| 427 |
+
|
| 428 |
+
// Default implementation is a no-op
|
| 429 |
+
virtual Status Start();
|
| 430 |
+
|
| 431 |
+
virtual Status WritePayload(const IpcPayload& payload) = 0;
|
| 432 |
+
|
| 433 |
+
virtual Status Close() = 0;
|
| 434 |
+
};
|
| 435 |
+
|
| 436 |
+
/// Create a new IPC payload stream writer from stream sink. User is
|
| 437 |
+
/// responsible for closing the actual OutputStream.
|
| 438 |
+
///
|
| 439 |
+
/// \param[in] sink output stream to write to
|
| 440 |
+
/// \param[in] options options for serialization
|
| 441 |
+
/// \return Result<std::shared_ptr<IpcPayloadWriter>>
|
| 442 |
+
ARROW_EXPORT
|
| 443 |
+
Result<std::unique_ptr<IpcPayloadWriter>> MakePayloadStreamWriter(
|
| 444 |
+
io::OutputStream* sink, const IpcWriteOptions& options = IpcWriteOptions::Defaults());
|
| 445 |
+
|
| 446 |
+
/// Create a new IPC payload file writer from stream sink.
|
| 447 |
+
///
|
| 448 |
+
/// \param[in] sink output stream to write to
|
| 449 |
+
/// \param[in] schema the schema of the record batches to be written
|
| 450 |
+
/// \param[in] options options for serialization, optional
|
| 451 |
+
/// \param[in] metadata custom metadata for File Footer, optional
|
| 452 |
+
/// \return Status
|
| 453 |
+
ARROW_EXPORT
|
| 454 |
+
Result<std::unique_ptr<IpcPayloadWriter>> MakePayloadFileWriter(
|
| 455 |
+
io::OutputStream* sink, const std::shared_ptr<Schema>& schema,
|
| 456 |
+
const IpcWriteOptions& options = IpcWriteOptions::Defaults(),
|
| 457 |
+
const std::shared_ptr<const KeyValueMetadata>& metadata = NULLPTR);
|
| 458 |
+
|
| 459 |
+
/// Create a new RecordBatchWriter from IpcPayloadWriter and schema.
|
| 460 |
+
///
|
| 461 |
+
/// The format is implicitly the IPC stream format (allowing dictionary
|
| 462 |
+
/// replacement and deltas).
|
| 463 |
+
///
|
| 464 |
+
/// \param[in] sink the IpcPayloadWriter to write to
|
| 465 |
+
/// \param[in] schema the schema of the record batches to be written
|
| 466 |
+
/// \param[in] options options for serialization
|
| 467 |
+
/// \return Result<std::unique_ptr<RecordBatchWriter>>
|
| 468 |
+
ARROW_EXPORT
|
| 469 |
+
Result<std::unique_ptr<RecordBatchWriter>> OpenRecordBatchWriter(
|
| 470 |
+
std::unique_ptr<IpcPayloadWriter> sink, const std::shared_ptr<Schema>& schema,
|
| 471 |
+
const IpcWriteOptions& options = IpcWriteOptions::Defaults());
|
| 472 |
+
|
| 473 |
+
} // namespace internal
|
| 474 |
+
} // namespace ipc
|
| 475 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/arrow_to_pandas.h
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
// Functions for converting between pandas's NumPy-based data representation
|
| 19 |
+
// and Arrow data structures
|
| 20 |
+
|
| 21 |
+
#pragma once
|
| 22 |
+
|
| 23 |
+
#include "arrow/python/platform.h"
|
| 24 |
+
|
| 25 |
+
#include <memory>
|
| 26 |
+
#include <string>
|
| 27 |
+
#include <unordered_set>
|
| 28 |
+
|
| 29 |
+
#include "arrow/memory_pool.h"
|
| 30 |
+
#include "arrow/python/visibility.h"
|
| 31 |
+
|
| 32 |
+
namespace arrow {
|
| 33 |
+
|
| 34 |
+
class Array;
|
| 35 |
+
class ChunkedArray;
|
| 36 |
+
class Column;
|
| 37 |
+
class DataType;
|
| 38 |
+
class MemoryPool;
|
| 39 |
+
class Status;
|
| 40 |
+
class Table;
|
| 41 |
+
|
| 42 |
+
namespace py {
|
| 43 |
+
|
| 44 |
+
enum class MapConversionType {
|
| 45 |
+
DEFAULT, // convert arrow maps to assoc lists (list of kev-value tuples) in Pandas
|
| 46 |
+
LOSSY, // report warnings when lossiness is encountered due to duplicate keys
|
| 47 |
+
STRICT_, // raise a Python exception when lossiness is encountered due to duplicate
|
| 48 |
+
// keys
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
struct PandasOptions {
|
| 52 |
+
/// arrow::MemoryPool to use for memory allocations
|
| 53 |
+
MemoryPool* pool = default_memory_pool();
|
| 54 |
+
|
| 55 |
+
/// If true, we will convert all string columns to categoricals
|
| 56 |
+
bool strings_to_categorical = false;
|
| 57 |
+
bool zero_copy_only = false;
|
| 58 |
+
bool integer_object_nulls = false;
|
| 59 |
+
bool date_as_object = false;
|
| 60 |
+
bool timestamp_as_object = false;
|
| 61 |
+
bool use_threads = false;
|
| 62 |
+
|
| 63 |
+
/// Coerce all date and timestamp to datetime64[ns]
|
| 64 |
+
bool coerce_temporal_nanoseconds = false;
|
| 65 |
+
|
| 66 |
+
/// Used to maintain backwards compatibility for
|
| 67 |
+
/// timezone bugs (see ARROW-9528). Should be removed
|
| 68 |
+
/// after Arrow 2.0 release.
|
| 69 |
+
bool ignore_timezone = false;
|
| 70 |
+
|
| 71 |
+
/// \brief If true, do not create duplicate PyObject versions of equal
|
| 72 |
+
/// objects. This only applies to immutable objects like strings or datetime
|
| 73 |
+
/// objects
|
| 74 |
+
bool deduplicate_objects = false;
|
| 75 |
+
|
| 76 |
+
/// \brief For certain data types, a cast is needed in order to store the
|
| 77 |
+
/// data in a pandas DataFrame or Series (e.g. timestamps are always stored
|
| 78 |
+
/// as nanoseconds in pandas). This option controls whether it is a safe
|
| 79 |
+
/// cast or not.
|
| 80 |
+
bool safe_cast = true;
|
| 81 |
+
|
| 82 |
+
/// \brief If true, create one block per column rather than consolidated
|
| 83 |
+
/// blocks (1 per data type). Do zero-copy wrapping when there are no
|
| 84 |
+
/// nulls. pandas currently will consolidate the blocks on its own, causing
|
| 85 |
+
/// increased memory use, so keep this in mind if you are working on a
|
| 86 |
+
/// memory-constrained situation.
|
| 87 |
+
bool split_blocks = false;
|
| 88 |
+
|
| 89 |
+
/// \brief If true, allow non-writable zero-copy views to be created for
|
| 90 |
+
/// single column blocks. This option is also used to provide zero copy for
|
| 91 |
+
/// Series data
|
| 92 |
+
bool allow_zero_copy_blocks = false;
|
| 93 |
+
|
| 94 |
+
/// \brief If true, attempt to deallocate buffers in passed Arrow object if
|
| 95 |
+
/// it is the only remaining shared_ptr copy of it. See ARROW-3789 for
|
| 96 |
+
/// original context for this feature. Only currently implemented for Table
|
| 97 |
+
/// conversions
|
| 98 |
+
bool self_destruct = false;
|
| 99 |
+
|
| 100 |
+
/// \brief The default behavior (DEFAULT), is to convert Arrow Map arrays to
|
| 101 |
+
/// Python association lists (list-of-tuples) in the same order as the Arrow
|
| 102 |
+
/// Map, as in [(key1, value1), (key2, value2), ...]
|
| 103 |
+
/// If LOSSY or STRICT, convert Arrow Map arrays to native Python dicts.
|
| 104 |
+
/// This can change the ordering of (key, value) pairs, and will deduplicate
|
| 105 |
+
/// multiple keys, resulting in a possible loss of data.
|
| 106 |
+
/// If 'lossy', this key deduplication results in a warning printed
|
| 107 |
+
/// when detected. If 'strict', this instead results in an exception
|
| 108 |
+
/// being raised when detected.
|
| 109 |
+
MapConversionType maps_as_pydicts = MapConversionType::DEFAULT;
|
| 110 |
+
|
| 111 |
+
// Used internally for nested arrays.
|
| 112 |
+
bool decode_dictionaries = false;
|
| 113 |
+
|
| 114 |
+
// Columns that should be casted to categorical
|
| 115 |
+
std::unordered_set<std::string> categorical_columns;
|
| 116 |
+
|
| 117 |
+
// Columns that should be passed through to be converted to
|
| 118 |
+
// ExtensionArray/Block
|
| 119 |
+
std::unordered_set<std::string> extension_columns;
|
| 120 |
+
|
| 121 |
+
// Used internally to decipher between to_numpy() and to_pandas() when
|
| 122 |
+
// the expected output differs
|
| 123 |
+
bool to_numpy = false;
|
| 124 |
+
};
|
| 125 |
+
|
| 126 |
+
ARROW_PYTHON_EXPORT
|
| 127 |
+
Status ConvertArrayToPandas(const PandasOptions& options, std::shared_ptr<Array> arr,
|
| 128 |
+
PyObject* py_ref, PyObject** out);
|
| 129 |
+
|
| 130 |
+
ARROW_PYTHON_EXPORT
|
| 131 |
+
Status ConvertChunkedArrayToPandas(const PandasOptions& options,
|
| 132 |
+
std::shared_ptr<ChunkedArray> col, PyObject* py_ref,
|
| 133 |
+
PyObject** out);
|
| 134 |
+
|
| 135 |
+
// Convert a whole table as efficiently as possible to a pandas.DataFrame.
|
| 136 |
+
//
|
| 137 |
+
// The returned Python object is a list of tuples consisting of the exact 2D
|
| 138 |
+
// BlockManager structure of the pandas.DataFrame used as of pandas 0.19.x.
|
| 139 |
+
//
|
| 140 |
+
// tuple item: (indices: ndarray[int32], block: ndarray[TYPE, ndim=2])
|
| 141 |
+
ARROW_PYTHON_EXPORT
|
| 142 |
+
Status ConvertTableToPandas(const PandasOptions& options, std::shared_ptr<Table> table,
|
| 143 |
+
PyObject** out);
|
| 144 |
+
|
| 145 |
+
} // namespace py
|
| 146 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/async.h
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <utility>
|
| 21 |
+
|
| 22 |
+
#include "arrow/python/common.h"
|
| 23 |
+
#include "arrow/status.h"
|
| 24 |
+
#include "arrow/util/future.h"
|
| 25 |
+
|
| 26 |
+
namespace arrow::py {
|
| 27 |
+
|
| 28 |
+
/// \brief Bind a Python callback to an arrow::Future.
|
| 29 |
+
///
|
| 30 |
+
/// If the Future finishes successfully, py_wrapper is called with its
|
| 31 |
+
/// result value and should return a PyObject*. If py_wrapper is successful,
|
| 32 |
+
/// py_cb is called with its return value.
|
| 33 |
+
///
|
| 34 |
+
/// If either the Future or py_wrapper fails, py_cb is called with the
|
| 35 |
+
/// associated Python exception.
|
| 36 |
+
///
|
| 37 |
+
/// \param future The future to bind to.
|
| 38 |
+
/// \param py_cb The Python callback function. Will be passed the result of
|
| 39 |
+
/// py_wrapper, or a Python exception if the future failed or one was
|
| 40 |
+
/// raised by py_wrapper.
|
| 41 |
+
/// \param py_wrapper A function (likely defined in Cython) to convert the C++
|
| 42 |
+
/// result of the future to a Python object.
|
| 43 |
+
template <typename T, typename PyWrapper = PyObject* (*)(T)>
|
| 44 |
+
void BindFuture(Future<T> future, PyObject* py_cb, PyWrapper py_wrapper) {
|
| 45 |
+
Py_INCREF(py_cb);
|
| 46 |
+
OwnedRefNoGIL cb_ref(py_cb);
|
| 47 |
+
|
| 48 |
+
auto future_cb = [cb_ref = std::move(cb_ref),
|
| 49 |
+
py_wrapper = std::move(py_wrapper)](Result<T> result) {
|
| 50 |
+
SafeCallIntoPythonVoid([&]() {
|
| 51 |
+
OwnedRef py_value_or_exc{WrapResult(std::move(result), std::move(py_wrapper))};
|
| 52 |
+
Py_XDECREF(
|
| 53 |
+
PyObject_CallFunctionObjArgs(cb_ref.obj(), py_value_or_exc.obj(), NULLPTR));
|
| 54 |
+
ARROW_WARN_NOT_OK(CheckPyError(), "Internal error in async call");
|
| 55 |
+
});
|
| 56 |
+
};
|
| 57 |
+
future.AddCallback(std::move(future_cb));
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
} // namespace arrow::py
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/csv.h
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <functional>
|
| 21 |
+
#include <memory>
|
| 22 |
+
#include <string>
|
| 23 |
+
#include <vector>
|
| 24 |
+
|
| 25 |
+
#include "arrow/csv/options.h"
|
| 26 |
+
#include "arrow/python/common.h"
|
| 27 |
+
#include "arrow/util/macros.h"
|
| 28 |
+
|
| 29 |
+
namespace arrow {
|
| 30 |
+
namespace py {
|
| 31 |
+
namespace csv {
|
| 32 |
+
|
| 33 |
+
using PyInvalidRowCallback = std::function<::arrow::csv::InvalidRowResult(
|
| 34 |
+
PyObject*, const ::arrow::csv::InvalidRow&)>;
|
| 35 |
+
|
| 36 |
+
ARROW_PYTHON_EXPORT
|
| 37 |
+
::arrow::csv::InvalidRowHandler MakeInvalidRowHandler(PyInvalidRowCallback,
|
| 38 |
+
PyObject* handler);
|
| 39 |
+
|
| 40 |
+
} // namespace csv
|
| 41 |
+
} // namespace py
|
| 42 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/gdb.h
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include "arrow/python/visibility.h"
|
| 21 |
+
|
| 22 |
+
namespace arrow {
|
| 23 |
+
namespace gdb {
|
| 24 |
+
|
| 25 |
+
ARROW_PYTHON_EXPORT
|
| 26 |
+
void TestSession();
|
| 27 |
+
|
| 28 |
+
} // namespace gdb
|
| 29 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/helpers.h
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include "arrow/python/platform.h"
|
| 21 |
+
|
| 22 |
+
#include <limits>
|
| 23 |
+
#include <memory>
|
| 24 |
+
#include <string>
|
| 25 |
+
#include <utility>
|
| 26 |
+
|
| 27 |
+
#include "arrow/python/numpy_interop.h"
|
| 28 |
+
|
| 29 |
+
#include <numpy/halffloat.h>
|
| 30 |
+
|
| 31 |
+
#include "arrow/python/visibility.h"
|
| 32 |
+
#include "arrow/type.h"
|
| 33 |
+
#include "arrow/util/macros.h"
|
| 34 |
+
|
| 35 |
+
namespace arrow {
|
| 36 |
+
|
| 37 |
+
namespace py {
|
| 38 |
+
|
| 39 |
+
class OwnedRef;
|
| 40 |
+
|
| 41 |
+
// \brief Get an arrow DataType instance from Arrow's Type::type enum
|
| 42 |
+
// \param[in] type One of the values of Arrow's Type::type enum
|
| 43 |
+
// \return A shared pointer to DataType
|
| 44 |
+
ARROW_PYTHON_EXPORT std::shared_ptr<DataType> GetPrimitiveType(Type::type type);
|
| 45 |
+
|
| 46 |
+
// \brief Construct a np.float16 object from a npy_half value.
|
| 47 |
+
ARROW_PYTHON_EXPORT PyObject* PyHalf_FromHalf(npy_half value);
|
| 48 |
+
|
| 49 |
+
// \brief Convert a Python object to a npy_half value.
|
| 50 |
+
ARROW_PYTHON_EXPORT Status PyFloat_AsHalf(PyObject* obj, npy_half* out);
|
| 51 |
+
|
| 52 |
+
namespace internal {
|
| 53 |
+
|
| 54 |
+
// \brief Check that a Python module has been already imported
|
| 55 |
+
// \param[in] module_name The name of the module
|
| 56 |
+
Result<bool> IsModuleImported(const std::string& module_name);
|
| 57 |
+
|
| 58 |
+
// \brief Import a Python module
|
| 59 |
+
// \param[in] module_name The name of the module
|
| 60 |
+
// \param[out] ref The OwnedRef containing the module PyObject*
|
| 61 |
+
ARROW_PYTHON_EXPORT
|
| 62 |
+
Status ImportModule(const std::string& module_name, OwnedRef* ref);
|
| 63 |
+
|
| 64 |
+
// \brief Import an object from a Python module
|
| 65 |
+
// \param[in] module A Python module
|
| 66 |
+
// \param[in] name The name of the object to import
|
| 67 |
+
// \param[out] ref The OwnedRef containing the \c name attribute of the Python module \c
|
| 68 |
+
// module
|
| 69 |
+
ARROW_PYTHON_EXPORT
|
| 70 |
+
Status ImportFromModule(PyObject* module, const std::string& name, OwnedRef* ref);
|
| 71 |
+
|
| 72 |
+
// \brief Check whether obj is an integer, independent of Python versions.
|
| 73 |
+
inline bool IsPyInteger(PyObject* obj) { return PyLong_Check(obj); }
|
| 74 |
+
|
| 75 |
+
// \brief Import symbols from pandas that we need for various type-checking,
|
| 76 |
+
// like pandas.NaT or pandas.NA
|
| 77 |
+
void InitPandasStaticData();
|
| 78 |
+
|
| 79 |
+
// \brief Use pandas missing value semantics to check if a value is null
|
| 80 |
+
ARROW_PYTHON_EXPORT
|
| 81 |
+
bool PandasObjectIsNull(PyObject* obj);
|
| 82 |
+
|
| 83 |
+
// \brief Check that obj is a pandas.Timedelta instance
|
| 84 |
+
ARROW_PYTHON_EXPORT
|
| 85 |
+
bool IsPandasTimedelta(PyObject* obj);
|
| 86 |
+
|
| 87 |
+
// \brief Check that obj is a pandas.Timestamp instance
|
| 88 |
+
bool IsPandasTimestamp(PyObject* obj);
|
| 89 |
+
|
| 90 |
+
// \brief Returned a borrowed reference to the pandas.tseries.offsets.DateOffset
|
| 91 |
+
PyObject* BorrowPandasDataOffsetType();
|
| 92 |
+
|
| 93 |
+
// \brief Check whether obj is a floating-point NaN
|
| 94 |
+
ARROW_PYTHON_EXPORT
|
| 95 |
+
bool PyFloat_IsNaN(PyObject* obj);
|
| 96 |
+
|
| 97 |
+
inline bool IsPyBinary(PyObject* obj) {
|
| 98 |
+
return PyBytes_Check(obj) || PyByteArray_Check(obj) || PyMemoryView_Check(obj);
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
// \brief Convert a Python integer into a C integer
|
| 102 |
+
// \param[in] obj A Python integer
|
| 103 |
+
// \param[out] out A pointer to a C integer to hold the result of the conversion
|
| 104 |
+
// \return The status of the operation
|
| 105 |
+
template <typename Int>
|
| 106 |
+
Status CIntFromPython(PyObject* obj, Int* out, const std::string& overflow_message = "");
|
| 107 |
+
|
| 108 |
+
// \brief Convert a Python unicode string to a std::string
|
| 109 |
+
ARROW_PYTHON_EXPORT
|
| 110 |
+
Status PyUnicode_AsStdString(PyObject* obj, std::string* out);
|
| 111 |
+
|
| 112 |
+
// \brief Convert a Python bytes object to a std::string
|
| 113 |
+
ARROW_PYTHON_EXPORT
|
| 114 |
+
std::string PyBytes_AsStdString(PyObject* obj);
|
| 115 |
+
|
| 116 |
+
// \brief Call str() on the given object and return the result as a std::string
|
| 117 |
+
ARROW_PYTHON_EXPORT
|
| 118 |
+
Status PyObject_StdStringStr(PyObject* obj, std::string* out);
|
| 119 |
+
|
| 120 |
+
// \brief Return the repr() of the given object (always succeeds)
|
| 121 |
+
ARROW_PYTHON_EXPORT
|
| 122 |
+
std::string PyObject_StdStringRepr(PyObject* obj);
|
| 123 |
+
|
| 124 |
+
// \brief Cast the given size to int32_t, with error checking
|
| 125 |
+
inline Status CastSize(Py_ssize_t size, int32_t* out,
|
| 126 |
+
const char* error_msg = "Maximum size exceeded (2GB)") {
|
| 127 |
+
// size is assumed to be positive
|
| 128 |
+
if (size > std::numeric_limits<int32_t>::max()) {
|
| 129 |
+
return Status::Invalid(error_msg);
|
| 130 |
+
}
|
| 131 |
+
*out = static_cast<int32_t>(size);
|
| 132 |
+
return Status::OK();
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
inline Status CastSize(Py_ssize_t size, int64_t* out, const char* error_msg = NULLPTR) {
|
| 136 |
+
// size is assumed to be positive
|
| 137 |
+
*out = static_cast<int64_t>(size);
|
| 138 |
+
return Status::OK();
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
// \brief Print the Python object's __str__ form along with the passed error
|
| 142 |
+
// message
|
| 143 |
+
ARROW_PYTHON_EXPORT
|
| 144 |
+
Status InvalidValue(PyObject* obj, const std::string& why);
|
| 145 |
+
|
| 146 |
+
ARROW_PYTHON_EXPORT
|
| 147 |
+
Status InvalidType(PyObject* obj, const std::string& why);
|
| 148 |
+
|
| 149 |
+
ARROW_PYTHON_EXPORT
|
| 150 |
+
Status IntegerScalarToDoubleSafe(PyObject* obj, double* result);
|
| 151 |
+
ARROW_PYTHON_EXPORT
|
| 152 |
+
Status IntegerScalarToFloat32Safe(PyObject* obj, float* result);
|
| 153 |
+
|
| 154 |
+
// \brief Print Python object __repr__
|
| 155 |
+
void DebugPrint(PyObject* obj);
|
| 156 |
+
|
| 157 |
+
ARROW_PYTHON_EXPORT
|
| 158 |
+
bool IsThreadingEnabled();
|
| 159 |
+
|
| 160 |
+
} // namespace internal
|
| 161 |
+
} // namespace py
|
| 162 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/inference.h
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
// Functions for converting between CPython built-in data structures and Arrow
|
| 19 |
+
// data structures
|
| 20 |
+
|
| 21 |
+
#pragma once
|
| 22 |
+
|
| 23 |
+
#include "arrow/python/platform.h"
|
| 24 |
+
|
| 25 |
+
#include <memory>
|
| 26 |
+
|
| 27 |
+
#include "arrow/python/visibility.h"
|
| 28 |
+
#include "arrow/type.h"
|
| 29 |
+
#include "arrow/util/macros.h"
|
| 30 |
+
|
| 31 |
+
#include "common.h"
|
| 32 |
+
|
| 33 |
+
namespace arrow {
|
| 34 |
+
|
| 35 |
+
class Array;
|
| 36 |
+
class Status;
|
| 37 |
+
|
| 38 |
+
namespace py {
|
| 39 |
+
|
| 40 |
+
// These functions take a sequence input, not arbitrary iterables
|
| 41 |
+
|
| 42 |
+
/// \brief Infer Arrow type from a Python sequence
|
| 43 |
+
/// \param[in] obj the sequence of values
|
| 44 |
+
/// \param[in] mask an optional mask where True values are null. May
|
| 45 |
+
/// be nullptr
|
| 46 |
+
/// \param[in] pandas_null_sentinels use pandas's null value markers
|
| 47 |
+
ARROW_PYTHON_EXPORT
|
| 48 |
+
Result<std::shared_ptr<arrow::DataType>> InferArrowType(PyObject* obj, PyObject* mask,
|
| 49 |
+
bool pandas_null_sentinels);
|
| 50 |
+
|
| 51 |
+
/// Checks whether the passed Python object is a boolean scalar
|
| 52 |
+
ARROW_PYTHON_EXPORT
|
| 53 |
+
bool IsPyBool(PyObject* obj);
|
| 54 |
+
|
| 55 |
+
/// Checks whether the passed Python object is an integer scalar
|
| 56 |
+
ARROW_PYTHON_EXPORT
|
| 57 |
+
bool IsPyInt(PyObject* obj);
|
| 58 |
+
|
| 59 |
+
/// Checks whether the passed Python object is a float scalar
|
| 60 |
+
ARROW_PYTHON_EXPORT
|
| 61 |
+
bool IsPyFloat(PyObject* obj);
|
| 62 |
+
|
| 63 |
+
} // namespace py
|
| 64 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/init.h
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include "arrow/python/platform.h"
|
| 21 |
+
#include "arrow/python/visibility.h"
|
| 22 |
+
|
| 23 |
+
extern "C" {
|
| 24 |
+
ARROW_PYTHON_EXPORT
|
| 25 |
+
int arrow_init_numpy();
|
| 26 |
+
}
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/io.h
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <memory>
|
| 21 |
+
|
| 22 |
+
#include "arrow/io/interfaces.h"
|
| 23 |
+
#include "arrow/io/transform.h"
|
| 24 |
+
|
| 25 |
+
#include "arrow/python/common.h"
|
| 26 |
+
#include "arrow/python/visibility.h"
|
| 27 |
+
|
| 28 |
+
namespace arrow {
|
| 29 |
+
namespace py {
|
| 30 |
+
|
| 31 |
+
class ARROW_NO_EXPORT PythonFile;
|
| 32 |
+
|
| 33 |
+
class ARROW_PYTHON_EXPORT PyReadableFile : public io::RandomAccessFile {
|
| 34 |
+
public:
|
| 35 |
+
explicit PyReadableFile(PyObject* file);
|
| 36 |
+
~PyReadableFile() override;
|
| 37 |
+
|
| 38 |
+
Status Close() override;
|
| 39 |
+
Status Abort() override;
|
| 40 |
+
bool closed() const override;
|
| 41 |
+
|
| 42 |
+
Result<int64_t> Read(int64_t nbytes, void* out) override;
|
| 43 |
+
Result<std::shared_ptr<Buffer>> Read(int64_t nbytes) override;
|
| 44 |
+
|
| 45 |
+
// Thread-safe version
|
| 46 |
+
Result<int64_t> ReadAt(int64_t position, int64_t nbytes, void* out) override;
|
| 47 |
+
|
| 48 |
+
// Thread-safe version
|
| 49 |
+
Result<std::shared_ptr<Buffer>> ReadAt(int64_t position, int64_t nbytes) override;
|
| 50 |
+
|
| 51 |
+
Result<int64_t> GetSize() override;
|
| 52 |
+
|
| 53 |
+
Status Seek(int64_t position) override;
|
| 54 |
+
|
| 55 |
+
Result<int64_t> Tell() const override;
|
| 56 |
+
|
| 57 |
+
private:
|
| 58 |
+
std::unique_ptr<PythonFile> file_;
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
class ARROW_PYTHON_EXPORT PyOutputStream : public io::OutputStream {
|
| 62 |
+
public:
|
| 63 |
+
explicit PyOutputStream(PyObject* file);
|
| 64 |
+
~PyOutputStream() override;
|
| 65 |
+
|
| 66 |
+
Status Close() override;
|
| 67 |
+
Status Abort() override;
|
| 68 |
+
bool closed() const override;
|
| 69 |
+
Result<int64_t> Tell() const override;
|
| 70 |
+
Status Write(const void* data, int64_t nbytes) override;
|
| 71 |
+
Status Write(const std::shared_ptr<Buffer>& buffer) override;
|
| 72 |
+
|
| 73 |
+
private:
|
| 74 |
+
std::unique_ptr<PythonFile> file_;
|
| 75 |
+
int64_t position_;
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
// TODO(wesm): seekable output files
|
| 79 |
+
|
| 80 |
+
// A Buffer subclass that keeps a PyObject reference throughout its
|
| 81 |
+
// lifetime, such that the Python object is kept alive as long as the
|
| 82 |
+
// C++ buffer is still needed.
|
| 83 |
+
// Keeping the reference in a Python wrapper would be incorrect as
|
| 84 |
+
// the Python wrapper can get destroyed even though the wrapped C++
|
| 85 |
+
// buffer is still alive (ARROW-2270).
|
| 86 |
+
class ARROW_PYTHON_EXPORT PyForeignBuffer : public Buffer {
|
| 87 |
+
public:
|
| 88 |
+
static Status Make(const uint8_t* data, int64_t size, PyObject* base,
|
| 89 |
+
std::shared_ptr<Buffer>* out);
|
| 90 |
+
|
| 91 |
+
private:
|
| 92 |
+
PyForeignBuffer(const uint8_t* data, int64_t size, PyObject* base)
|
| 93 |
+
: Buffer(data, size) {
|
| 94 |
+
Py_INCREF(base);
|
| 95 |
+
base_.reset(base);
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
OwnedRefNoGIL base_;
|
| 99 |
+
};
|
| 100 |
+
|
| 101 |
+
// All this rigamarole because Cython is really poor with std::function<>
|
| 102 |
+
|
| 103 |
+
using TransformCallback = std::function<void(
|
| 104 |
+
PyObject*, const std::shared_ptr<Buffer>& src, std::shared_ptr<Buffer>* out)>;
|
| 105 |
+
|
| 106 |
+
struct TransformInputStreamVTable {
|
| 107 |
+
TransformCallback transform;
|
| 108 |
+
};
|
| 109 |
+
|
| 110 |
+
ARROW_PYTHON_EXPORT
|
| 111 |
+
std::shared_ptr<::arrow::io::InputStream> MakeTransformInputStream(
|
| 112 |
+
std::shared_ptr<::arrow::io::InputStream> wrapped, TransformInputStreamVTable vtable,
|
| 113 |
+
PyObject* arg);
|
| 114 |
+
|
| 115 |
+
using StreamWrapFunc = std::function<Result<std::shared_ptr<io::InputStream>>(
|
| 116 |
+
std::shared_ptr<io::InputStream>)>;
|
| 117 |
+
ARROW_PYTHON_EXPORT
|
| 118 |
+
std::shared_ptr<StreamWrapFunc> MakeStreamTransformFunc(TransformInputStreamVTable vtable,
|
| 119 |
+
PyObject* handler);
|
| 120 |
+
} // namespace py
|
| 121 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/numpy_convert.h
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
// Functions for converting between pandas's NumPy-based data representation
|
| 19 |
+
// and Arrow data structures
|
| 20 |
+
|
| 21 |
+
#pragma once
|
| 22 |
+
|
| 23 |
+
#include "arrow/python/platform.h"
|
| 24 |
+
|
| 25 |
+
#include <memory>
|
| 26 |
+
#include <string>
|
| 27 |
+
#include <vector>
|
| 28 |
+
|
| 29 |
+
#include "arrow/buffer.h"
|
| 30 |
+
#include "arrow/python/visibility.h"
|
| 31 |
+
#include "arrow/sparse_tensor.h"
|
| 32 |
+
|
| 33 |
+
namespace arrow {
|
| 34 |
+
|
| 35 |
+
class DataType;
|
| 36 |
+
class MemoryPool;
|
| 37 |
+
class Status;
|
| 38 |
+
class Tensor;
|
| 39 |
+
|
| 40 |
+
namespace py {
|
| 41 |
+
|
| 42 |
+
class ARROW_PYTHON_EXPORT NumPyBuffer : public Buffer {
|
| 43 |
+
public:
|
| 44 |
+
explicit NumPyBuffer(PyObject* arr);
|
| 45 |
+
virtual ~NumPyBuffer();
|
| 46 |
+
|
| 47 |
+
private:
|
| 48 |
+
PyObject* arr_;
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
ARROW_PYTHON_EXPORT
|
| 52 |
+
Result<std::shared_ptr<DataType>> NumPyDtypeToArrow(PyObject* dtype);
|
| 53 |
+
ARROW_PYTHON_EXPORT
|
| 54 |
+
Result<std::shared_ptr<DataType>> NumPyDtypeToArrow(PyArray_Descr* descr);
|
| 55 |
+
ARROW_PYTHON_EXPORT
|
| 56 |
+
Result<std::shared_ptr<DataType>> NumPyScalarToArrowDataType(PyObject* scalar);
|
| 57 |
+
|
| 58 |
+
ARROW_PYTHON_EXPORT Status NdarrayToTensor(MemoryPool* pool, PyObject* ao,
|
| 59 |
+
const std::vector<std::string>& dim_names,
|
| 60 |
+
std::shared_ptr<Tensor>* out);
|
| 61 |
+
|
| 62 |
+
ARROW_PYTHON_EXPORT Status TensorToNdarray(const std::shared_ptr<Tensor>& tensor,
|
| 63 |
+
PyObject* base, PyObject** out);
|
| 64 |
+
|
| 65 |
+
ARROW_PYTHON_EXPORT Status
|
| 66 |
+
SparseCOOTensorToNdarray(const std::shared_ptr<SparseCOOTensor>& sparse_tensor,
|
| 67 |
+
PyObject* base, PyObject** out_data, PyObject** out_coords);
|
| 68 |
+
|
| 69 |
+
Status SparseCSXMatrixToNdarray(const std::shared_ptr<SparseTensor>& sparse_tensor,
|
| 70 |
+
PyObject* base, PyObject** out_data,
|
| 71 |
+
PyObject** out_indptr, PyObject** out_indices);
|
| 72 |
+
|
| 73 |
+
ARROW_PYTHON_EXPORT Status SparseCSRMatrixToNdarray(
|
| 74 |
+
const std::shared_ptr<SparseCSRMatrix>& sparse_tensor, PyObject* base,
|
| 75 |
+
PyObject** out_data, PyObject** out_indptr, PyObject** out_indices);
|
| 76 |
+
|
| 77 |
+
ARROW_PYTHON_EXPORT Status SparseCSCMatrixToNdarray(
|
| 78 |
+
const std::shared_ptr<SparseCSCMatrix>& sparse_tensor, PyObject* base,
|
| 79 |
+
PyObject** out_data, PyObject** out_indptr, PyObject** out_indices);
|
| 80 |
+
|
| 81 |
+
ARROW_PYTHON_EXPORT Status SparseCSFTensorToNdarray(
|
| 82 |
+
const std::shared_ptr<SparseCSFTensor>& sparse_tensor, PyObject* base,
|
| 83 |
+
PyObject** out_data, PyObject** out_indptr, PyObject** out_indices);
|
| 84 |
+
|
| 85 |
+
ARROW_PYTHON_EXPORT Status NdarraysToSparseCOOTensor(
|
| 86 |
+
MemoryPool* pool, PyObject* data_ao, PyObject* coords_ao,
|
| 87 |
+
const std::vector<int64_t>& shape, const std::vector<std::string>& dim_names,
|
| 88 |
+
std::shared_ptr<SparseCOOTensor>* out);
|
| 89 |
+
|
| 90 |
+
ARROW_PYTHON_EXPORT Status NdarraysToSparseCSRMatrix(
|
| 91 |
+
MemoryPool* pool, PyObject* data_ao, PyObject* indptr_ao, PyObject* indices_ao,
|
| 92 |
+
const std::vector<int64_t>& shape, const std::vector<std::string>& dim_names,
|
| 93 |
+
std::shared_ptr<SparseCSRMatrix>* out);
|
| 94 |
+
|
| 95 |
+
ARROW_PYTHON_EXPORT Status NdarraysToSparseCSCMatrix(
|
| 96 |
+
MemoryPool* pool, PyObject* data_ao, PyObject* indptr_ao, PyObject* indices_ao,
|
| 97 |
+
const std::vector<int64_t>& shape, const std::vector<std::string>& dim_names,
|
| 98 |
+
std::shared_ptr<SparseCSCMatrix>* out);
|
| 99 |
+
|
| 100 |
+
ARROW_PYTHON_EXPORT Status NdarraysToSparseCSFTensor(
|
| 101 |
+
MemoryPool* pool, PyObject* data_ao, PyObject* indptr_ao, PyObject* indices_ao,
|
| 102 |
+
const std::vector<int64_t>& shape, const std::vector<int64_t>& axis_order,
|
| 103 |
+
const std::vector<std::string>& dim_names, std::shared_ptr<SparseCSFTensor>* out);
|
| 104 |
+
|
| 105 |
+
ARROW_PYTHON_EXPORT Status
|
| 106 |
+
TensorToSparseCOOTensor(const std::shared_ptr<Tensor>& tensor,
|
| 107 |
+
std::shared_ptr<SparseCOOTensor>* csparse_tensor);
|
| 108 |
+
|
| 109 |
+
ARROW_PYTHON_EXPORT Status
|
| 110 |
+
TensorToSparseCSRMatrix(const std::shared_ptr<Tensor>& tensor,
|
| 111 |
+
std::shared_ptr<SparseCSRMatrix>* csparse_tensor);
|
| 112 |
+
|
| 113 |
+
ARROW_PYTHON_EXPORT Status
|
| 114 |
+
TensorToSparseCSCMatrix(const std::shared_ptr<Tensor>& tensor,
|
| 115 |
+
std::shared_ptr<SparseCSCMatrix>* csparse_tensor);
|
| 116 |
+
|
| 117 |
+
ARROW_PYTHON_EXPORT Status
|
| 118 |
+
TensorToSparseCSFTensor(const std::shared_ptr<Tensor>& tensor,
|
| 119 |
+
std::shared_ptr<SparseCSFTensor>* csparse_tensor);
|
| 120 |
+
|
| 121 |
+
} // namespace py
|
| 122 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/numpy_to_arrow.h
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
// Converting from pandas memory representation to Arrow data structures
|
| 19 |
+
|
| 20 |
+
#pragma once
|
| 21 |
+
|
| 22 |
+
#include "arrow/python/platform.h"
|
| 23 |
+
|
| 24 |
+
#include <memory>
|
| 25 |
+
|
| 26 |
+
#include "arrow/compute/api.h"
|
| 27 |
+
#include "arrow/python/visibility.h"
|
| 28 |
+
|
| 29 |
+
namespace arrow {
|
| 30 |
+
|
| 31 |
+
class Array;
|
| 32 |
+
class ChunkedArray;
|
| 33 |
+
class DataType;
|
| 34 |
+
class MemoryPool;
|
| 35 |
+
class Status;
|
| 36 |
+
|
| 37 |
+
namespace py {
|
| 38 |
+
|
| 39 |
+
/// Convert NumPy arrays to Arrow. If target data type is not known, pass a
|
| 40 |
+
/// type with null
|
| 41 |
+
///
|
| 42 |
+
/// \param[in] pool Memory pool for any memory allocations
|
| 43 |
+
/// \param[in] ao an ndarray with the array data
|
| 44 |
+
/// \param[in] mo an ndarray with a null mask (True is null), optional
|
| 45 |
+
/// \param[in] from_pandas If true, use pandas's null sentinels to determine
|
| 46 |
+
/// whether values are null
|
| 47 |
+
/// \param[in] type a specific type to cast to, may be null
|
| 48 |
+
/// \param[in] cast_options casting options
|
| 49 |
+
/// \param[out] out a ChunkedArray, to accommodate chunked output
|
| 50 |
+
ARROW_PYTHON_EXPORT
|
| 51 |
+
Status NdarrayToArrow(MemoryPool* pool, PyObject* ao, PyObject* mo, bool from_pandas,
|
| 52 |
+
const std::shared_ptr<DataType>& type,
|
| 53 |
+
const compute::CastOptions& cast_options,
|
| 54 |
+
std::shared_ptr<ChunkedArray>* out);
|
| 55 |
+
|
| 56 |
+
/// Safely convert NumPy arrays to Arrow. If target data type is not known,
|
| 57 |
+
/// pass a type with null.
|
| 58 |
+
///
|
| 59 |
+
/// \param[in] pool Memory pool for any memory allocations
|
| 60 |
+
/// \param[in] ao an ndarray with the array data
|
| 61 |
+
/// \param[in] mo an ndarray with a null mask (True is null), optional
|
| 62 |
+
/// \param[in] from_pandas If true, use pandas's null sentinels to determine
|
| 63 |
+
/// whether values are null
|
| 64 |
+
/// \param[in] type a specific type to cast to, may be null
|
| 65 |
+
/// \param[out] out a ChunkedArray, to accommodate chunked output
|
| 66 |
+
ARROW_PYTHON_EXPORT
|
| 67 |
+
Status NdarrayToArrow(MemoryPool* pool, PyObject* ao, PyObject* mo, bool from_pandas,
|
| 68 |
+
const std::shared_ptr<DataType>& type,
|
| 69 |
+
std::shared_ptr<ChunkedArray>* out);
|
| 70 |
+
|
| 71 |
+
} // namespace py
|
| 72 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/parquet_encryption.h
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <string>
|
| 21 |
+
|
| 22 |
+
#include "arrow/python/common.h"
|
| 23 |
+
#include "arrow/python/visibility.h"
|
| 24 |
+
#include "arrow/util/macros.h"
|
| 25 |
+
#include "parquet/encryption/crypto_factory.h"
|
| 26 |
+
#include "parquet/encryption/kms_client.h"
|
| 27 |
+
#include "parquet/encryption/kms_client_factory.h"
|
| 28 |
+
|
| 29 |
+
#if defined(_WIN32) || defined(__CYGWIN__) // Windows
|
| 30 |
+
#if defined(_MSC_VER)
|
| 31 |
+
#pragma warning(disable : 4251)
|
| 32 |
+
#else
|
| 33 |
+
#pragma GCC diagnostic ignored "-Wattributes"
|
| 34 |
+
#endif
|
| 35 |
+
|
| 36 |
+
#ifdef ARROW_PYTHON_STATIC
|
| 37 |
+
#define ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT
|
| 38 |
+
#elif defined(ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORTING)
|
| 39 |
+
#define ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT __declspec(dllexport)
|
| 40 |
+
#else
|
| 41 |
+
#define ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT __declspec(dllimport)
|
| 42 |
+
#endif
|
| 43 |
+
|
| 44 |
+
#else // Not Windows
|
| 45 |
+
#ifndef ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT
|
| 46 |
+
#define ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT __attribute__((visibility("default")))
|
| 47 |
+
#endif
|
| 48 |
+
#endif // Non-Windows
|
| 49 |
+
|
| 50 |
+
namespace arrow {
|
| 51 |
+
namespace py {
|
| 52 |
+
namespace parquet {
|
| 53 |
+
namespace encryption {
|
| 54 |
+
|
| 55 |
+
/// \brief A table of function pointers for calling from C++ into
|
| 56 |
+
/// Python.
|
| 57 |
+
class ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT PyKmsClientVtable {
|
| 58 |
+
public:
|
| 59 |
+
std::function<void(PyObject*, const std::string& key_bytes,
|
| 60 |
+
const std::string& master_key_identifier, std::string* out)>
|
| 61 |
+
wrap_key;
|
| 62 |
+
std::function<void(PyObject*, const std::string& wrapped_key,
|
| 63 |
+
const std::string& master_key_identifier, std::string* out)>
|
| 64 |
+
unwrap_key;
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
/// \brief A helper for KmsClient implementation in Python.
|
| 68 |
+
class ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT PyKmsClient
|
| 69 |
+
: public ::parquet::encryption::KmsClient {
|
| 70 |
+
public:
|
| 71 |
+
PyKmsClient(PyObject* handler, PyKmsClientVtable vtable);
|
| 72 |
+
~PyKmsClient() override;
|
| 73 |
+
|
| 74 |
+
std::string WrapKey(const std::string& key_bytes,
|
| 75 |
+
const std::string& master_key_identifier) override;
|
| 76 |
+
|
| 77 |
+
std::string UnwrapKey(const std::string& wrapped_key,
|
| 78 |
+
const std::string& master_key_identifier) override;
|
| 79 |
+
|
| 80 |
+
private:
|
| 81 |
+
OwnedRefNoGIL handler_;
|
| 82 |
+
PyKmsClientVtable vtable_;
|
| 83 |
+
};
|
| 84 |
+
|
| 85 |
+
/// \brief A table of function pointers for calling from C++ into
|
| 86 |
+
/// Python.
|
| 87 |
+
class ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT PyKmsClientFactoryVtable {
|
| 88 |
+
public:
|
| 89 |
+
std::function<void(
|
| 90 |
+
PyObject*, const ::parquet::encryption::KmsConnectionConfig& kms_connection_config,
|
| 91 |
+
std::shared_ptr<::parquet::encryption::KmsClient>* out)>
|
| 92 |
+
create_kms_client;
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
/// \brief A helper for KmsClientFactory implementation in Python.
|
| 96 |
+
class ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT PyKmsClientFactory
|
| 97 |
+
: public ::parquet::encryption::KmsClientFactory {
|
| 98 |
+
public:
|
| 99 |
+
PyKmsClientFactory(PyObject* handler, PyKmsClientFactoryVtable vtable);
|
| 100 |
+
~PyKmsClientFactory() override;
|
| 101 |
+
|
| 102 |
+
std::shared_ptr<::parquet::encryption::KmsClient> CreateKmsClient(
|
| 103 |
+
const ::parquet::encryption::KmsConnectionConfig& kms_connection_config) override;
|
| 104 |
+
|
| 105 |
+
private:
|
| 106 |
+
OwnedRefNoGIL handler_;
|
| 107 |
+
PyKmsClientFactoryVtable vtable_;
|
| 108 |
+
};
|
| 109 |
+
|
| 110 |
+
/// \brief A CryptoFactory that returns Results instead of throwing exceptions.
|
| 111 |
+
class ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT PyCryptoFactory
|
| 112 |
+
: public ::parquet::encryption::CryptoFactory {
|
| 113 |
+
public:
|
| 114 |
+
arrow::Result<std::shared_ptr<::parquet::FileEncryptionProperties>>
|
| 115 |
+
SafeGetFileEncryptionProperties(
|
| 116 |
+
const ::parquet::encryption::KmsConnectionConfig& kms_connection_config,
|
| 117 |
+
const ::parquet::encryption::EncryptionConfiguration& encryption_config);
|
| 118 |
+
|
| 119 |
+
/// The returned FileDecryptionProperties object will use the cache inside this
|
| 120 |
+
/// CryptoFactory object, so please keep this
|
| 121 |
+
/// CryptoFactory object alive along with the returned
|
| 122 |
+
/// FileDecryptionProperties object.
|
| 123 |
+
arrow::Result<std::shared_ptr<::parquet::FileDecryptionProperties>>
|
| 124 |
+
SafeGetFileDecryptionProperties(
|
| 125 |
+
const ::parquet::encryption::KmsConnectionConfig& kms_connection_config,
|
| 126 |
+
const ::parquet::encryption::DecryptionConfiguration& decryption_config);
|
| 127 |
+
};
|
| 128 |
+
|
| 129 |
+
} // namespace encryption
|
| 130 |
+
} // namespace parquet
|
| 131 |
+
} // namespace py
|
| 132 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/platform.h
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
// Functions for converting between pandas's NumPy-based data representation
|
| 19 |
+
// and Arrow data structures
|
| 20 |
+
|
| 21 |
+
#pragma once
|
| 22 |
+
|
| 23 |
+
// If PY_SSIZE_T_CLEAN is defined, argument parsing functions treat #-specifier
|
| 24 |
+
// to mean Py_ssize_t (defining this to suppress deprecation warning)
|
| 25 |
+
#define PY_SSIZE_T_CLEAN
|
| 26 |
+
|
| 27 |
+
#include <Python.h> // IWYU pragma: export
|
| 28 |
+
#include <datetime.h>
|
| 29 |
+
|
| 30 |
+
// Work around C2528 error
|
| 31 |
+
#ifdef _MSC_VER
|
| 32 |
+
#if _MSC_VER >= 1900
|
| 33 |
+
#undef timezone
|
| 34 |
+
#endif
|
| 35 |
+
|
| 36 |
+
// https://bugs.python.org/issue36020
|
| 37 |
+
// TODO(wjones127): Can remove once we drop support for CPython 3.9
|
| 38 |
+
#ifdef snprintf
|
| 39 |
+
#undef snprintf
|
| 40 |
+
#endif
|
| 41 |
+
#endif
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/pyarrow.h
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include "arrow/python/platform.h"
|
| 21 |
+
|
| 22 |
+
#include <memory>
|
| 23 |
+
|
| 24 |
+
#include "arrow/python/visibility.h"
|
| 25 |
+
|
| 26 |
+
#include "arrow/sparse_tensor.h"
|
| 27 |
+
|
| 28 |
+
// Work around ARROW-2317 (C linkage warning from Cython)
|
| 29 |
+
extern "C++" {
|
| 30 |
+
|
| 31 |
+
namespace arrow {
|
| 32 |
+
|
| 33 |
+
class Array;
|
| 34 |
+
class Buffer;
|
| 35 |
+
class DataType;
|
| 36 |
+
class Field;
|
| 37 |
+
class RecordBatch;
|
| 38 |
+
class Schema;
|
| 39 |
+
class Status;
|
| 40 |
+
class Table;
|
| 41 |
+
class Tensor;
|
| 42 |
+
|
| 43 |
+
namespace py {
|
| 44 |
+
|
| 45 |
+
// Returns 0 on success, -1 on error.
|
| 46 |
+
ARROW_PYTHON_EXPORT int import_pyarrow();
|
| 47 |
+
|
| 48 |
+
#define DECLARE_WRAP_FUNCTIONS(FUNC_SUFFIX, TYPE_NAME) \
|
| 49 |
+
ARROW_PYTHON_EXPORT bool is_##FUNC_SUFFIX(PyObject*); \
|
| 50 |
+
ARROW_PYTHON_EXPORT Result<std::shared_ptr<TYPE_NAME>> unwrap_##FUNC_SUFFIX( \
|
| 51 |
+
PyObject*); \
|
| 52 |
+
ARROW_PYTHON_EXPORT PyObject* wrap_##FUNC_SUFFIX(const std::shared_ptr<TYPE_NAME>&);
|
| 53 |
+
|
| 54 |
+
DECLARE_WRAP_FUNCTIONS(buffer, Buffer)
|
| 55 |
+
|
| 56 |
+
DECLARE_WRAP_FUNCTIONS(data_type, DataType)
|
| 57 |
+
DECLARE_WRAP_FUNCTIONS(field, Field)
|
| 58 |
+
DECLARE_WRAP_FUNCTIONS(schema, Schema)
|
| 59 |
+
|
| 60 |
+
DECLARE_WRAP_FUNCTIONS(scalar, Scalar)
|
| 61 |
+
|
| 62 |
+
DECLARE_WRAP_FUNCTIONS(array, Array)
|
| 63 |
+
DECLARE_WRAP_FUNCTIONS(chunked_array, ChunkedArray)
|
| 64 |
+
|
| 65 |
+
DECLARE_WRAP_FUNCTIONS(sparse_coo_tensor, SparseCOOTensor)
|
| 66 |
+
DECLARE_WRAP_FUNCTIONS(sparse_csc_matrix, SparseCSCMatrix)
|
| 67 |
+
DECLARE_WRAP_FUNCTIONS(sparse_csf_tensor, SparseCSFTensor)
|
| 68 |
+
DECLARE_WRAP_FUNCTIONS(sparse_csr_matrix, SparseCSRMatrix)
|
| 69 |
+
DECLARE_WRAP_FUNCTIONS(tensor, Tensor)
|
| 70 |
+
|
| 71 |
+
DECLARE_WRAP_FUNCTIONS(batch, RecordBatch)
|
| 72 |
+
DECLARE_WRAP_FUNCTIONS(table, Table)
|
| 73 |
+
|
| 74 |
+
#undef DECLARE_WRAP_FUNCTIONS
|
| 75 |
+
|
| 76 |
+
namespace internal {
|
| 77 |
+
|
| 78 |
+
// If status is ok, return 0.
|
| 79 |
+
// If status is not ok, set Python error indicator and return -1.
|
| 80 |
+
ARROW_PYTHON_EXPORT int check_status(const Status& status);
|
| 81 |
+
|
| 82 |
+
// Convert status to a Python exception object. Status must not be ok.
|
| 83 |
+
ARROW_PYTHON_EXPORT PyObject* convert_status(const Status& status);
|
| 84 |
+
|
| 85 |
+
} // namespace internal
|
| 86 |
+
} // namespace py
|
| 87 |
+
} // namespace arrow
|
| 88 |
+
|
| 89 |
+
} // extern "C++"
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/python_test.h
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <functional>
|
| 21 |
+
#include <string>
|
| 22 |
+
#include <vector>
|
| 23 |
+
|
| 24 |
+
#include "arrow/status.h"
|
| 25 |
+
|
| 26 |
+
#include "arrow/python/visibility.h"
|
| 27 |
+
|
| 28 |
+
namespace arrow {
|
| 29 |
+
namespace py {
|
| 30 |
+
namespace testing {
|
| 31 |
+
|
| 32 |
+
struct TestCase {
|
| 33 |
+
std::string name;
|
| 34 |
+
std::function<Status()> func;
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
ARROW_PYTHON_EXPORT
|
| 38 |
+
std::vector<TestCase> GetCppTestCases();
|
| 39 |
+
|
| 40 |
+
} // namespace testing
|
| 41 |
+
} // namespace py
|
| 42 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/python/udf.h
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include "arrow/compute/exec.h"
|
| 21 |
+
#include "arrow/compute/function.h"
|
| 22 |
+
#include "arrow/compute/registry.h"
|
| 23 |
+
#include "arrow/python/platform.h"
|
| 24 |
+
#include "arrow/record_batch.h"
|
| 25 |
+
#include "arrow/util/iterator.h"
|
| 26 |
+
|
| 27 |
+
#include "arrow/python/common.h"
|
| 28 |
+
#include "arrow/python/pyarrow.h"
|
| 29 |
+
#include "arrow/python/visibility.h"
|
| 30 |
+
|
| 31 |
+
namespace arrow {
|
| 32 |
+
|
| 33 |
+
namespace py {
|
| 34 |
+
|
| 35 |
+
// TODO: TODO(ARROW-16041): UDF Options are not exposed to the Python
|
| 36 |
+
// users. This feature will be included when extending to provide advanced
|
| 37 |
+
// options for the users.
|
| 38 |
+
struct ARROW_PYTHON_EXPORT UdfOptions {
|
| 39 |
+
std::string func_name;
|
| 40 |
+
compute::Arity arity;
|
| 41 |
+
compute::FunctionDoc func_doc;
|
| 42 |
+
std::vector<std::shared_ptr<DataType>> input_types;
|
| 43 |
+
std::shared_ptr<DataType> output_type;
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
/// \brief A context passed as the first argument of UDF functions.
|
| 47 |
+
struct ARROW_PYTHON_EXPORT UdfContext {
|
| 48 |
+
MemoryPool* pool;
|
| 49 |
+
int64_t batch_length;
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
using UdfWrapperCallback = std::function<PyObject*(
|
| 53 |
+
PyObject* user_function, const UdfContext& context, PyObject* inputs)>;
|
| 54 |
+
|
| 55 |
+
/// \brief register a Scalar user-defined-function from Python
|
| 56 |
+
Status ARROW_PYTHON_EXPORT RegisterScalarFunction(
|
| 57 |
+
PyObject* user_function, UdfWrapperCallback wrapper, const UdfOptions& options,
|
| 58 |
+
compute::FunctionRegistry* registry = NULLPTR);
|
| 59 |
+
|
| 60 |
+
/// \brief register a Table user-defined-function from Python
|
| 61 |
+
Status ARROW_PYTHON_EXPORT RegisterTabularFunction(
|
| 62 |
+
PyObject* user_function, UdfWrapperCallback wrapper, const UdfOptions& options,
|
| 63 |
+
compute::FunctionRegistry* registry = NULLPTR);
|
| 64 |
+
|
| 65 |
+
/// \brief register a Aggregate user-defined-function from Python
|
| 66 |
+
Status ARROW_PYTHON_EXPORT RegisterAggregateFunction(
|
| 67 |
+
PyObject* user_function, UdfWrapperCallback wrapper, const UdfOptions& options,
|
| 68 |
+
compute::FunctionRegistry* registry = NULLPTR);
|
| 69 |
+
|
| 70 |
+
/// \brief register a Vector user-defined-function from Python
|
| 71 |
+
Status ARROW_PYTHON_EXPORT RegisterVectorFunction(
|
| 72 |
+
PyObject* user_function, UdfWrapperCallback wrapper, const UdfOptions& options,
|
| 73 |
+
compute::FunctionRegistry* registry = NULLPTR);
|
| 74 |
+
|
| 75 |
+
Result<std::shared_ptr<RecordBatchReader>> ARROW_PYTHON_EXPORT
|
| 76 |
+
CallTabularFunction(const std::string& func_name, const std::vector<Datum>& args,
|
| 77 |
+
compute::FunctionRegistry* registry = NULLPTR);
|
| 78 |
+
|
| 79 |
+
} // namespace py
|
| 80 |
+
|
| 81 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/tensor/converter.h
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include "arrow/sparse_tensor.h" // IWYU pragma: export
|
| 21 |
+
|
| 22 |
+
#include <memory>
|
| 23 |
+
|
| 24 |
+
namespace arrow {
|
| 25 |
+
namespace internal {
|
| 26 |
+
|
| 27 |
+
struct SparseTensorConverterMixin {
|
| 28 |
+
static bool IsNonZero(const uint8_t val) { return val != 0; }
|
| 29 |
+
|
| 30 |
+
static void AssignIndex(uint8_t* indices, int64_t val, const int elsize);
|
| 31 |
+
|
| 32 |
+
static int64_t GetIndexValue(const uint8_t* value_ptr, const int elsize);
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
Status MakeSparseCOOTensorFromTensor(const Tensor& tensor,
|
| 36 |
+
const std::shared_ptr<DataType>& index_value_type,
|
| 37 |
+
MemoryPool* pool,
|
| 38 |
+
std::shared_ptr<SparseIndex>* out_sparse_index,
|
| 39 |
+
std::shared_ptr<Buffer>* out_data);
|
| 40 |
+
|
| 41 |
+
Status MakeSparseCSXMatrixFromTensor(SparseMatrixCompressedAxis axis,
|
| 42 |
+
const Tensor& tensor,
|
| 43 |
+
const std::shared_ptr<DataType>& index_value_type,
|
| 44 |
+
MemoryPool* pool,
|
| 45 |
+
std::shared_ptr<SparseIndex>* out_sparse_index,
|
| 46 |
+
std::shared_ptr<Buffer>* out_data);
|
| 47 |
+
|
| 48 |
+
Status MakeSparseCSFTensorFromTensor(const Tensor& tensor,
|
| 49 |
+
const std::shared_ptr<DataType>& index_value_type,
|
| 50 |
+
MemoryPool* pool,
|
| 51 |
+
std::shared_ptr<SparseIndex>* out_sparse_index,
|
| 52 |
+
std::shared_ptr<Buffer>* out_data);
|
| 53 |
+
|
| 54 |
+
Result<std::shared_ptr<Tensor>> MakeTensorFromSparseCOOTensor(
|
| 55 |
+
MemoryPool* pool, const SparseCOOTensor* sparse_tensor);
|
| 56 |
+
|
| 57 |
+
Result<std::shared_ptr<Tensor>> MakeTensorFromSparseCSRMatrix(
|
| 58 |
+
MemoryPool* pool, const SparseCSRMatrix* sparse_tensor);
|
| 59 |
+
|
| 60 |
+
Result<std::shared_ptr<Tensor>> MakeTensorFromSparseCSCMatrix(
|
| 61 |
+
MemoryPool* pool, const SparseCSCMatrix* sparse_tensor);
|
| 62 |
+
|
| 63 |
+
Result<std::shared_ptr<Tensor>> MakeTensorFromSparseCSFTensor(
|
| 64 |
+
MemoryPool* pool, const SparseCSFTensor* sparse_tensor);
|
| 65 |
+
|
| 66 |
+
} // namespace internal
|
| 67 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/async_util.h
ADDED
|
@@ -0,0 +1,460 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <atomic>
|
| 21 |
+
#include <functional>
|
| 22 |
+
#include <list>
|
| 23 |
+
#include <memory>
|
| 24 |
+
|
| 25 |
+
#include "arrow/result.h"
|
| 26 |
+
#include "arrow/status.h"
|
| 27 |
+
#include "arrow/util/cancel.h"
|
| 28 |
+
#include "arrow/util/functional.h"
|
| 29 |
+
#include "arrow/util/future.h"
|
| 30 |
+
#include "arrow/util/iterator.h"
|
| 31 |
+
#include "arrow/util/mutex.h"
|
| 32 |
+
#include "arrow/util/thread_pool.h"
|
| 33 |
+
#include "arrow/util/tracing.h"
|
| 34 |
+
|
| 35 |
+
namespace arrow {
|
| 36 |
+
|
| 37 |
+
using internal::FnOnce;
|
| 38 |
+
|
| 39 |
+
namespace util {
|
| 40 |
+
|
| 41 |
+
/// A utility which keeps tracks of, and schedules, asynchronous tasks
|
| 42 |
+
///
|
| 43 |
+
/// An asynchronous task has a synchronous component and an asynchronous component.
|
| 44 |
+
/// The synchronous component typically schedules some kind of work on an external
|
| 45 |
+
/// resource (e.g. the I/O thread pool or some kind of kernel-based asynchronous
|
| 46 |
+
/// resource like io_uring). The asynchronous part represents the work
|
| 47 |
+
/// done on that external resource. Executing the synchronous part will be referred
|
| 48 |
+
/// to as "submitting the task" since this usually includes submitting the asynchronous
|
| 49 |
+
/// portion to the external thread pool.
|
| 50 |
+
///
|
| 51 |
+
/// By default the scheduler will submit the task (execute the synchronous part) as
|
| 52 |
+
/// soon as it is added, assuming the underlying thread pool hasn't terminated or the
|
| 53 |
+
/// scheduler hasn't aborted. In this mode, the scheduler is simply acting as
|
| 54 |
+
/// a simple task group.
|
| 55 |
+
///
|
| 56 |
+
/// A task scheduler starts with an initial task. That task, and all subsequent tasks
|
| 57 |
+
/// are free to add subtasks. Once all submitted tasks finish the scheduler will
|
| 58 |
+
/// finish. Note, it is not an error to add additional tasks after a scheduler has
|
| 59 |
+
/// aborted. These tasks will be ignored and never submitted. The scheduler returns a
|
| 60 |
+
/// future which will complete when all submitted tasks have finished executing. Once all
|
| 61 |
+
/// tasks have been finished the scheduler is invalid and should no longer be used.
|
| 62 |
+
///
|
| 63 |
+
/// Task failure (either the synchronous portion or the asynchronous portion) will cause
|
| 64 |
+
/// the scheduler to enter an aborted state. The first such failure will be reported in
|
| 65 |
+
/// the final task future.
|
| 66 |
+
class ARROW_EXPORT AsyncTaskScheduler {
|
| 67 |
+
public:
|
| 68 |
+
/// Destructor for AsyncTaskScheduler
|
| 69 |
+
///
|
| 70 |
+
/// The lifetime of the task scheduled is managed automatically. The scheduler
|
| 71 |
+
/// will remain valid while any tasks are running (and can always be safely accessed)
|
| 72 |
+
/// within tasks) and will be destroyed as soon as all tasks have finished.
|
| 73 |
+
virtual ~AsyncTaskScheduler() = default;
|
| 74 |
+
/// An interface for a task
|
| 75 |
+
///
|
| 76 |
+
/// Users may want to override this, for example, to add priority
|
| 77 |
+
/// information for use by a queue.
|
| 78 |
+
class Task {
|
| 79 |
+
public:
|
| 80 |
+
virtual ~Task() = default;
|
| 81 |
+
/// Submit the task
|
| 82 |
+
///
|
| 83 |
+
/// This will be called by the scheduler at most once when there
|
| 84 |
+
/// is space to run the task. This is expected to be a fairly quick
|
| 85 |
+
/// function that simply submits the actual task work to an external
|
| 86 |
+
/// resource (e.g. I/O thread pool).
|
| 87 |
+
///
|
| 88 |
+
/// If this call fails then the scheduler will enter an aborted state.
|
| 89 |
+
virtual Result<Future<>> operator()() = 0;
|
| 90 |
+
/// The cost of the task
|
| 91 |
+
///
|
| 92 |
+
/// A ThrottledAsyncTaskScheduler can be used to limit the number of concurrent tasks.
|
| 93 |
+
/// A custom cost may be used, for example, if you would like to limit the number of
|
| 94 |
+
/// tasks based on the total expected RAM usage of the tasks (this is done in the
|
| 95 |
+
/// scanner)
|
| 96 |
+
virtual int cost() const { return 1; }
|
| 97 |
+
/// The name of the task
|
| 98 |
+
///
|
| 99 |
+
/// This is used for debugging and traceability. The returned view must remain
|
| 100 |
+
/// valid for the lifetime of the task.
|
| 101 |
+
virtual std::string_view name() const = 0;
|
| 102 |
+
|
| 103 |
+
/// a span tied to the lifetime of the task, for internal use only
|
| 104 |
+
tracing::Span span;
|
| 105 |
+
};
|
| 106 |
+
|
| 107 |
+
/// Add a task to the scheduler
|
| 108 |
+
///
|
| 109 |
+
/// If the scheduler is in an aborted state this call will return false and the task
|
| 110 |
+
/// will never be run. This is harmless and does not need to be guarded against.
|
| 111 |
+
///
|
| 112 |
+
/// The return value for this call can usually be ignored. There is little harm in
|
| 113 |
+
/// attempting to add tasks to an aborted scheduler. It is only included for callers
|
| 114 |
+
/// that want to avoid future task generation to save effort.
|
| 115 |
+
///
|
| 116 |
+
/// \param task the task to submit
|
| 117 |
+
///
|
| 118 |
+
/// A task's name must remain valid for the duration of the task. It is used for
|
| 119 |
+
/// debugging (e.g. when debugging a deadlock to see which tasks still remain) and for
|
| 120 |
+
/// traceability (the name will be used for spans assigned to the task)
|
| 121 |
+
///
|
| 122 |
+
/// \return true if the task was submitted or queued, false if the task was ignored
|
| 123 |
+
virtual bool AddTask(std::unique_ptr<Task> task) = 0;
|
| 124 |
+
|
| 125 |
+
/// Adds an async generator to the scheduler
|
| 126 |
+
///
|
| 127 |
+
/// The async generator will be visited, one item at a time. Submitting a task
|
| 128 |
+
/// will consist of polling the generator for the next future. The generator's future
|
| 129 |
+
/// will then represent the task itself.
|
| 130 |
+
///
|
| 131 |
+
/// This visits the task serially without readahead. If readahead or parallelism
|
| 132 |
+
/// is desired then it should be added in the generator itself.
|
| 133 |
+
///
|
| 134 |
+
/// The generator itself will be kept alive until all tasks have been completed.
|
| 135 |
+
/// However, if the scheduler is aborted, the generator will be destroyed as soon as the
|
| 136 |
+
/// next item would be requested.
|
| 137 |
+
///
|
| 138 |
+
/// \param generator the generator to submit to the scheduler
|
| 139 |
+
/// \param visitor a function which visits each generator future as it completes
|
| 140 |
+
/// \param name a name which will be used for each submitted task
|
| 141 |
+
template <typename T>
|
| 142 |
+
bool AddAsyncGenerator(std::function<Future<T>()> generator,
|
| 143 |
+
std::function<Status(const T&)> visitor, std::string_view name);
|
| 144 |
+
|
| 145 |
+
template <typename Callable>
|
| 146 |
+
struct SimpleTask : public Task {
|
| 147 |
+
SimpleTask(Callable callable, std::string_view name)
|
| 148 |
+
: callable(std::move(callable)), name_(name) {}
|
| 149 |
+
SimpleTask(Callable callable, std::string name)
|
| 150 |
+
: callable(std::move(callable)), owned_name_(std::move(name)) {
|
| 151 |
+
name_ = *owned_name_;
|
| 152 |
+
}
|
| 153 |
+
Result<Future<>> operator()() override { return callable(); }
|
| 154 |
+
std::string_view name() const override { return name_; }
|
| 155 |
+
Callable callable;
|
| 156 |
+
std::string_view name_;
|
| 157 |
+
std::optional<std::string> owned_name_;
|
| 158 |
+
};
|
| 159 |
+
|
| 160 |
+
/// Add a task with cost 1 to the scheduler
|
| 161 |
+
///
|
| 162 |
+
/// \param callable a "submit" function that should return a future
|
| 163 |
+
/// \param name a name for the task
|
| 164 |
+
///
|
| 165 |
+
/// `name` must remain valid until the task has been submitted AND the returned
|
| 166 |
+
/// future completes. It is used for debugging and tracing.
|
| 167 |
+
///
|
| 168 |
+
/// \see AddTask for more details
|
| 169 |
+
template <typename Callable>
|
| 170 |
+
bool AddSimpleTask(Callable callable, std::string_view name) {
|
| 171 |
+
return AddTask(std::make_unique<SimpleTask<Callable>>(std::move(callable), name));
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
/// Add a task with cost 1 to the scheduler
|
| 175 |
+
///
|
| 176 |
+
/// This is an overload of \see AddSimpleTask that keeps `name` alive
|
| 177 |
+
/// in the task.
|
| 178 |
+
template <typename Callable>
|
| 179 |
+
bool AddSimpleTask(Callable callable, std::string name) {
|
| 180 |
+
return AddTask(
|
| 181 |
+
std::make_unique<SimpleTask<Callable>>(std::move(callable), std::move(name)));
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
/// Construct a scheduler
|
| 185 |
+
///
|
| 186 |
+
/// \param initial_task The initial task which is responsible for adding
|
| 187 |
+
/// the first subtasks to the scheduler.
|
| 188 |
+
/// \param abort_callback A callback that will be triggered immediately after a task
|
| 189 |
+
/// fails while other tasks may still be running. Nothing needs to be done here,
|
| 190 |
+
/// when a task fails the scheduler will stop accepting new tasks and eventually
|
| 191 |
+
/// return the error. However, this callback can be used to more quickly end
|
| 192 |
+
/// long running tasks that have already been submitted. Defaults to doing
|
| 193 |
+
/// nothing.
|
| 194 |
+
/// \param stop_token An optional stop token that will allow cancellation of the
|
| 195 |
+
/// scheduler. This will be checked before each task is submitted and, in the
|
| 196 |
+
/// event of a cancellation, the scheduler will enter an aborted state. This is
|
| 197 |
+
/// a graceful cancellation and submitted tasks will still complete.
|
| 198 |
+
/// \return A future that will be completed when the initial task and all subtasks have
|
| 199 |
+
/// finished.
|
| 200 |
+
static Future<> Make(
|
| 201 |
+
FnOnce<Status(AsyncTaskScheduler*)> initial_task,
|
| 202 |
+
FnOnce<void(const Status&)> abort_callback = [](const Status&) {},
|
| 203 |
+
StopToken stop_token = StopToken::Unstoppable());
|
| 204 |
+
|
| 205 |
+
/// A span tracking execution of the scheduler's tasks, for internal use only
|
| 206 |
+
virtual const tracing::Span& span() const = 0;
|
| 207 |
+
};
|
| 208 |
+
|
| 209 |
+
class ARROW_EXPORT ThrottledAsyncTaskScheduler : public AsyncTaskScheduler {
|
| 210 |
+
public:
|
| 211 |
+
/// An interface for a task queue
|
| 212 |
+
///
|
| 213 |
+
/// A queue's methods will not be called concurrently
|
| 214 |
+
class Queue {
|
| 215 |
+
public:
|
| 216 |
+
virtual ~Queue() = default;
|
| 217 |
+
/// Push a task to the queue
|
| 218 |
+
///
|
| 219 |
+
/// \param task the task to enqueue
|
| 220 |
+
virtual void Push(std::unique_ptr<Task> task) = 0;
|
| 221 |
+
/// Pop the next task from the queue
|
| 222 |
+
virtual std::unique_ptr<Task> Pop() = 0;
|
| 223 |
+
/// Peek the next task in the queue
|
| 224 |
+
virtual const Task& Peek() = 0;
|
| 225 |
+
/// Check if the queue is empty
|
| 226 |
+
virtual bool Empty() = 0;
|
| 227 |
+
/// Purge the queue of all items
|
| 228 |
+
virtual void Purge() = 0;
|
| 229 |
+
virtual std::size_t Size() const = 0;
|
| 230 |
+
};
|
| 231 |
+
|
| 232 |
+
class Throttle {
|
| 233 |
+
public:
|
| 234 |
+
virtual ~Throttle() = default;
|
| 235 |
+
/// Acquire amt permits
|
| 236 |
+
///
|
| 237 |
+
/// If nullopt is returned then the permits were immediately
|
| 238 |
+
/// acquired and the caller can proceed. If a future is returned then the caller
|
| 239 |
+
/// should wait for the future to complete first. When the returned future completes
|
| 240 |
+
/// the permits have NOT been acquired and the caller must call Acquire again
|
| 241 |
+
///
|
| 242 |
+
/// \param amt the number of permits to acquire
|
| 243 |
+
virtual std::optional<Future<>> TryAcquire(int amt) = 0;
|
| 244 |
+
/// Release amt permits
|
| 245 |
+
///
|
| 246 |
+
/// This will possibly complete waiting futures and should probably not be
|
| 247 |
+
/// called while holding locks.
|
| 248 |
+
///
|
| 249 |
+
/// \param amt the number of permits to release
|
| 250 |
+
virtual void Release(int amt) = 0;
|
| 251 |
+
|
| 252 |
+
/// The size of the largest task that can run
|
| 253 |
+
///
|
| 254 |
+
/// Incoming tasks will have their cost latched to this value to ensure
|
| 255 |
+
/// they can still run (although they will be the only thing allowed to
|
| 256 |
+
/// run at that time).
|
| 257 |
+
virtual int Capacity() = 0;
|
| 258 |
+
|
| 259 |
+
/// Pause the throttle
|
| 260 |
+
///
|
| 261 |
+
/// Any tasks that have been submitted already will continue. However, no new tasks
|
| 262 |
+
/// will be run until the throttle is resumed.
|
| 263 |
+
virtual void Pause() = 0;
|
| 264 |
+
/// Resume the throttle
|
| 265 |
+
///
|
| 266 |
+
/// Allows task to be submitted again. If there is a max_concurrent_cost limit then
|
| 267 |
+
/// it will still apply.
|
| 268 |
+
virtual void Resume() = 0;
|
| 269 |
+
};
|
| 270 |
+
|
| 271 |
+
/// Pause the throttle
|
| 272 |
+
///
|
| 273 |
+
/// Any tasks that have been submitted already will continue. However, no new tasks
|
| 274 |
+
/// will be run until the throttle is resumed.
|
| 275 |
+
virtual void Pause() = 0;
|
| 276 |
+
/// Resume the throttle
|
| 277 |
+
///
|
| 278 |
+
/// Allows task to be submitted again. If there is a max_concurrent_cost limit then
|
| 279 |
+
/// it will still apply.
|
| 280 |
+
virtual void Resume() = 0;
|
| 281 |
+
/// Return the number of tasks queued but not yet submitted
|
| 282 |
+
virtual std::size_t QueueSize() = 0;
|
| 283 |
+
|
| 284 |
+
/// Create a throttled view of a scheduler
|
| 285 |
+
///
|
| 286 |
+
/// Tasks added via this view will be subjected to the throttle and, if the tasks cannot
|
| 287 |
+
/// run immediately, will be placed into a queue.
|
| 288 |
+
///
|
| 289 |
+
/// Although a shared_ptr is returned it should generally be assumed that the caller
|
| 290 |
+
/// is being given exclusive ownership. The shared_ptr is used to share the view with
|
| 291 |
+
/// queued and submitted tasks and the lifetime of those is unpredictable. It is
|
| 292 |
+
/// important the caller keep the returned pointer alive for as long as they plan to add
|
| 293 |
+
/// tasks to the view.
|
| 294 |
+
///
|
| 295 |
+
/// \param scheduler a scheduler to submit tasks to after throttling
|
| 296 |
+
///
|
| 297 |
+
/// This can be the root scheduler, another throttled scheduler, or a task group. These
|
| 298 |
+
/// are all composable.
|
| 299 |
+
///
|
| 300 |
+
/// \param max_concurrent_cost the maximum amount of cost allowed to run at any one time
|
| 301 |
+
///
|
| 302 |
+
/// If a task is added that has a cost greater than max_concurrent_cost then its cost
|
| 303 |
+
/// will be reduced to max_concurrent_cost so that it is still possible for the task to
|
| 304 |
+
/// run.
|
| 305 |
+
///
|
| 306 |
+
/// \param queue the queue to use when tasks cannot be submitted
|
| 307 |
+
///
|
| 308 |
+
/// By default a FIFO queue will be used. However, a custom queue can be provided if
|
| 309 |
+
/// some tasks have higher priority than other tasks.
|
| 310 |
+
static std::shared_ptr<ThrottledAsyncTaskScheduler> Make(
|
| 311 |
+
AsyncTaskScheduler* scheduler, int max_concurrent_cost,
|
| 312 |
+
std::unique_ptr<Queue> queue = NULLPTR);
|
| 313 |
+
|
| 314 |
+
/// @brief Create a ThrottledAsyncTaskScheduler using a custom throttle
|
| 315 |
+
///
|
| 316 |
+
/// \see Make
|
| 317 |
+
static std::shared_ptr<ThrottledAsyncTaskScheduler> MakeWithCustomThrottle(
|
| 318 |
+
AsyncTaskScheduler* scheduler, std::unique_ptr<Throttle> throttle,
|
| 319 |
+
std::unique_ptr<Queue> queue = NULLPTR);
|
| 320 |
+
};
|
| 321 |
+
|
| 322 |
+
/// A utility to keep track of a collection of tasks
|
| 323 |
+
///
|
| 324 |
+
/// Often it is useful to keep track of some state that only needs to stay alive
|
| 325 |
+
/// for some small collection of tasks, or to perform some kind of final cleanup
|
| 326 |
+
/// when a collection of tasks is finished.
|
| 327 |
+
///
|
| 328 |
+
/// For example, when scanning, we need to keep the file reader alive while all scan
|
| 329 |
+
/// tasks run for a given file, and then we can gracefully close it when we finish the
|
| 330 |
+
/// file.
|
| 331 |
+
class ARROW_EXPORT AsyncTaskGroup : public AsyncTaskScheduler {
|
| 332 |
+
public:
|
| 333 |
+
/// Destructor for the task group
|
| 334 |
+
///
|
| 335 |
+
/// The destructor might trigger the finish callback. If the finish callback fails
|
| 336 |
+
/// then the error will be reported as a task on the scheduler.
|
| 337 |
+
///
|
| 338 |
+
/// Failure to destroy the async task group will not prevent the scheduler from
|
| 339 |
+
/// finishing. If the scheduler finishes before the async task group is done then
|
| 340 |
+
/// the finish callback will be run immediately when the async task group finishes.
|
| 341 |
+
///
|
| 342 |
+
/// If the scheduler has aborted then the finish callback will not run.
|
| 343 |
+
~AsyncTaskGroup() = default;
|
| 344 |
+
/// Create an async task group
|
| 345 |
+
///
|
| 346 |
+
/// The finish callback will not run until the task group is destroyed and all
|
| 347 |
+
/// tasks are finished so you will generally want to reset / destroy the returned
|
| 348 |
+
/// unique_ptr at some point.
|
| 349 |
+
///
|
| 350 |
+
/// \param scheduler The underlying scheduler to submit tasks to
|
| 351 |
+
/// \param finish_callback A callback that will be run only after the task group has
|
| 352 |
+
/// been destroyed and all tasks added by the group have
|
| 353 |
+
/// finished.
|
| 354 |
+
///
|
| 355 |
+
/// Note: in error scenarios the finish callback may not run. However, it will still,
|
| 356 |
+
/// of course, be destroyed.
|
| 357 |
+
static std::unique_ptr<AsyncTaskGroup> Make(AsyncTaskScheduler* scheduler,
|
| 358 |
+
FnOnce<Status()> finish_callback);
|
| 359 |
+
};
|
| 360 |
+
|
| 361 |
+
/// Create a task group that is also throttled
|
| 362 |
+
///
|
| 363 |
+
/// This is a utility factory that creates a throttled view of a scheduler and then
|
| 364 |
+
/// wraps that throttled view with a task group that destroys the throttle when finished.
|
| 365 |
+
///
|
| 366 |
+
/// \see ThrottledAsyncTaskScheduler
|
| 367 |
+
/// \see AsyncTaskGroup
|
| 368 |
+
/// \param target the underlying scheduler to submit tasks to
|
| 369 |
+
/// \param max_concurrent_cost the maximum amount of cost allowed to run at any one time
|
| 370 |
+
/// \param queue the queue to use when tasks cannot be submitted
|
| 371 |
+
/// \param finish_callback A callback that will be run only after the task group has
|
| 372 |
+
/// been destroyed and all tasks added by the group have finished
|
| 373 |
+
ARROW_EXPORT std::unique_ptr<ThrottledAsyncTaskScheduler> MakeThrottledAsyncTaskGroup(
|
| 374 |
+
AsyncTaskScheduler* target, int max_concurrent_cost,
|
| 375 |
+
std::unique_ptr<ThrottledAsyncTaskScheduler::Queue> queue,
|
| 376 |
+
FnOnce<Status()> finish_callback);
|
| 377 |
+
|
| 378 |
+
// Defined down here to avoid circular dependency between AsyncTaskScheduler and
|
| 379 |
+
// AsyncTaskGroup
|
| 380 |
+
template <typename T>
|
| 381 |
+
bool AsyncTaskScheduler::AddAsyncGenerator(std::function<Future<T>()> generator,
|
| 382 |
+
std::function<Status(const T&)> visitor,
|
| 383 |
+
std::string_view name) {
|
| 384 |
+
struct State {
|
| 385 |
+
State(std::function<Future<T>()> generator, std::function<Status(const T&)> visitor,
|
| 386 |
+
std::unique_ptr<AsyncTaskGroup> task_group, std::string_view name)
|
| 387 |
+
: generator(std::move(generator)),
|
| 388 |
+
visitor(std::move(visitor)),
|
| 389 |
+
task_group(std::move(task_group)),
|
| 390 |
+
name(name) {}
|
| 391 |
+
std::function<Future<T>()> generator;
|
| 392 |
+
std::function<Status(const T&)> visitor;
|
| 393 |
+
std::unique_ptr<AsyncTaskGroup> task_group;
|
| 394 |
+
std::string_view name;
|
| 395 |
+
};
|
| 396 |
+
struct SubmitTask : public Task {
|
| 397 |
+
explicit SubmitTask(std::unique_ptr<State> state_holder)
|
| 398 |
+
: state_holder(std::move(state_holder)) {}
|
| 399 |
+
|
| 400 |
+
struct SubmitTaskCallback {
|
| 401 |
+
SubmitTaskCallback(std::unique_ptr<State> state_holder, Future<> task_completion)
|
| 402 |
+
: state_holder(std::move(state_holder)),
|
| 403 |
+
task_completion(std::move(task_completion)) {}
|
| 404 |
+
void operator()(const Result<T>& maybe_item) {
|
| 405 |
+
if (!maybe_item.ok()) {
|
| 406 |
+
task_completion.MarkFinished(maybe_item.status());
|
| 407 |
+
return;
|
| 408 |
+
}
|
| 409 |
+
const auto& item = *maybe_item;
|
| 410 |
+
if (IsIterationEnd(item)) {
|
| 411 |
+
task_completion.MarkFinished();
|
| 412 |
+
return;
|
| 413 |
+
}
|
| 414 |
+
Status visit_st = state_holder->visitor(item);
|
| 415 |
+
if (!visit_st.ok()) {
|
| 416 |
+
task_completion.MarkFinished(std::move(visit_st));
|
| 417 |
+
return;
|
| 418 |
+
}
|
| 419 |
+
state_holder->task_group->AddTask(
|
| 420 |
+
std::make_unique<SubmitTask>(std::move(state_holder)));
|
| 421 |
+
task_completion.MarkFinished();
|
| 422 |
+
}
|
| 423 |
+
std::unique_ptr<State> state_holder;
|
| 424 |
+
Future<> task_completion;
|
| 425 |
+
};
|
| 426 |
+
|
| 427 |
+
Result<Future<>> operator()() {
|
| 428 |
+
Future<> task = Future<>::Make();
|
| 429 |
+
// Consume as many items as we can (those that are already finished)
|
| 430 |
+
// synchronously to avoid recursion / stack overflow.
|
| 431 |
+
while (true) {
|
| 432 |
+
Future<T> next = state_holder->generator();
|
| 433 |
+
if (next.TryAddCallback(
|
| 434 |
+
[&] { return SubmitTaskCallback(std::move(state_holder), task); })) {
|
| 435 |
+
return task;
|
| 436 |
+
}
|
| 437 |
+
ARROW_ASSIGN_OR_RAISE(T item, next.result());
|
| 438 |
+
if (IsIterationEnd(item)) {
|
| 439 |
+
task.MarkFinished();
|
| 440 |
+
return task;
|
| 441 |
+
}
|
| 442 |
+
ARROW_RETURN_NOT_OK(state_holder->visitor(item));
|
| 443 |
+
}
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
std::string_view name() const { return state_holder->name; }
|
| 447 |
+
|
| 448 |
+
std::unique_ptr<State> state_holder;
|
| 449 |
+
};
|
| 450 |
+
std::unique_ptr<AsyncTaskGroup> task_group =
|
| 451 |
+
AsyncTaskGroup::Make(this, [] { return Status::OK(); });
|
| 452 |
+
AsyncTaskGroup* task_group_view = task_group.get();
|
| 453 |
+
std::unique_ptr<State> state_holder = std::make_unique<State>(
|
| 454 |
+
std::move(generator), std::move(visitor), std::move(task_group), name);
|
| 455 |
+
task_group_view->AddTask(std::make_unique<SubmitTask>(std::move(state_holder)));
|
| 456 |
+
return true;
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
} // namespace util
|
| 460 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/basic_decimal.h
ADDED
|
@@ -0,0 +1,492 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <array>
|
| 21 |
+
#include <cstdint>
|
| 22 |
+
#include <cstring>
|
| 23 |
+
#include <limits>
|
| 24 |
+
#include <string>
|
| 25 |
+
#include <type_traits>
|
| 26 |
+
|
| 27 |
+
#include "arrow/util/endian.h"
|
| 28 |
+
#include "arrow/util/macros.h"
|
| 29 |
+
#include "arrow/util/type_traits.h"
|
| 30 |
+
#include "arrow/util/visibility.h"
|
| 31 |
+
|
| 32 |
+
namespace arrow {
|
| 33 |
+
|
| 34 |
+
enum class DecimalStatus {
|
| 35 |
+
kSuccess,
|
| 36 |
+
kDivideByZero,
|
| 37 |
+
kOverflow,
|
| 38 |
+
kRescaleDataLoss,
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
template <typename Derived, int BIT_WIDTH, int NWORDS = BIT_WIDTH / 64>
|
| 42 |
+
class ARROW_EXPORT GenericBasicDecimal {
|
| 43 |
+
protected:
|
| 44 |
+
struct LittleEndianArrayTag {};
|
| 45 |
+
|
| 46 |
+
#if ARROW_LITTLE_ENDIAN
|
| 47 |
+
static constexpr int kHighWordIndex = NWORDS - 1;
|
| 48 |
+
static constexpr int kLowWordIndex = 0;
|
| 49 |
+
#else
|
| 50 |
+
static constexpr int kHighWordIndex = 0;
|
| 51 |
+
static constexpr int kLowWordIndex = NWORDS - 1;
|
| 52 |
+
#endif
|
| 53 |
+
|
| 54 |
+
public:
|
| 55 |
+
static constexpr int kBitWidth = BIT_WIDTH;
|
| 56 |
+
static constexpr int kByteWidth = kBitWidth / 8;
|
| 57 |
+
static constexpr int kNumWords = NWORDS;
|
| 58 |
+
|
| 59 |
+
// A constructor tag to introduce a little-endian encoded array
|
| 60 |
+
static constexpr LittleEndianArrayTag LittleEndianArray{};
|
| 61 |
+
|
| 62 |
+
using WordArray = std::array<uint64_t, NWORDS>;
|
| 63 |
+
|
| 64 |
+
/// \brief Empty constructor creates a decimal with a value of 0.
|
| 65 |
+
constexpr GenericBasicDecimal() noexcept : array_({0}) {}
|
| 66 |
+
|
| 67 |
+
/// \brief Create a decimal from the two's complement representation.
|
| 68 |
+
///
|
| 69 |
+
/// Input array is assumed to be in native endianness.
|
| 70 |
+
explicit constexpr GenericBasicDecimal(const WordArray& array) noexcept
|
| 71 |
+
: array_(array) {}
|
| 72 |
+
|
| 73 |
+
/// \brief Create a decimal from the two's complement representation.
|
| 74 |
+
///
|
| 75 |
+
/// Input array is assumed to be in little endianness, with native endian elements.
|
| 76 |
+
GenericBasicDecimal(LittleEndianArrayTag, const WordArray& array) noexcept
|
| 77 |
+
: GenericBasicDecimal(bit_util::little_endian::ToNative(array)) {}
|
| 78 |
+
|
| 79 |
+
/// \brief Create a decimal from any integer not wider than 64 bits.
|
| 80 |
+
template <typename T,
|
| 81 |
+
typename = typename std::enable_if<
|
| 82 |
+
std::is_integral<T>::value && (sizeof(T) <= sizeof(uint64_t)), T>::type>
|
| 83 |
+
constexpr GenericBasicDecimal(T value) noexcept // NOLINT(runtime/explicit)
|
| 84 |
+
: array_(WordsFromLowBits(value)) {}
|
| 85 |
+
|
| 86 |
+
/// \brief Create a decimal from an array of bytes.
|
| 87 |
+
///
|
| 88 |
+
/// Bytes are assumed to be in native-endian byte order.
|
| 89 |
+
explicit GenericBasicDecimal(const uint8_t* bytes) {
|
| 90 |
+
memcpy(array_.data(), bytes, sizeof(array_));
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/// \brief Get the bits of the two's complement representation of the number.
|
| 94 |
+
///
|
| 95 |
+
/// The elements are in native endian order. The bits within each uint64_t element
|
| 96 |
+
/// are in native endian order. For example, on a little endian machine,
|
| 97 |
+
/// BasicDecimal128(123).native_endian_array() = {123, 0};
|
| 98 |
+
/// but on a big endian machine,
|
| 99 |
+
/// BasicDecimal128(123).native_endian_array() = {0, 123};
|
| 100 |
+
constexpr const WordArray& native_endian_array() const { return array_; }
|
| 101 |
+
|
| 102 |
+
/// \brief Get the bits of the two's complement representation of the number.
|
| 103 |
+
///
|
| 104 |
+
/// The elements are in little endian order. However, the bits within each
|
| 105 |
+
/// uint64_t element are in native endian order.
|
| 106 |
+
/// For example, BasicDecimal128(123).little_endian_array() = {123, 0};
|
| 107 |
+
WordArray little_endian_array() const {
|
| 108 |
+
return bit_util::little_endian::FromNative(array_);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
const uint8_t* native_endian_bytes() const {
|
| 112 |
+
return reinterpret_cast<const uint8_t*>(array_.data());
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
uint8_t* mutable_native_endian_bytes() {
|
| 116 |
+
return reinterpret_cast<uint8_t*>(array_.data());
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/// \brief Return the raw bytes of the value in native-endian byte order.
|
| 120 |
+
std::array<uint8_t, kByteWidth> ToBytes() const {
|
| 121 |
+
std::array<uint8_t, kByteWidth> out{{0}};
|
| 122 |
+
memcpy(out.data(), array_.data(), kByteWidth);
|
| 123 |
+
return out;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
/// \brief Copy the raw bytes of the value in native-endian byte order.
|
| 127 |
+
void ToBytes(uint8_t* out) const { memcpy(out, array_.data(), kByteWidth); }
|
| 128 |
+
|
| 129 |
+
/// Return 1 if positive or zero, -1 if strictly negative.
|
| 130 |
+
int64_t Sign() const {
|
| 131 |
+
return 1 | (static_cast<int64_t>(array_[kHighWordIndex]) >> 63);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
bool IsNegative() const { return static_cast<int64_t>(array_[kHighWordIndex]) < 0; }
|
| 135 |
+
|
| 136 |
+
explicit operator bool() const { return array_ != WordArray{}; }
|
| 137 |
+
|
| 138 |
+
friend bool operator==(const GenericBasicDecimal& left,
|
| 139 |
+
const GenericBasicDecimal& right) {
|
| 140 |
+
return left.array_ == right.array_;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
friend bool operator!=(const GenericBasicDecimal& left,
|
| 144 |
+
const GenericBasicDecimal& right) {
|
| 145 |
+
return left.array_ != right.array_;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
protected:
|
| 149 |
+
WordArray array_;
|
| 150 |
+
|
| 151 |
+
template <typename T>
|
| 152 |
+
static constexpr uint64_t SignExtend(T low_bits) noexcept {
|
| 153 |
+
return low_bits >= T{} ? uint64_t{0} : ~uint64_t{0};
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
template <typename T>
|
| 157 |
+
static constexpr WordArray WordsFromLowBits(T low_bits) {
|
| 158 |
+
WordArray words{};
|
| 159 |
+
if (low_bits < T{}) {
|
| 160 |
+
for (auto& word : words) {
|
| 161 |
+
word = ~uint64_t{0};
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
words[kLowWordIndex] = static_cast<uint64_t>(low_bits);
|
| 165 |
+
return words;
|
| 166 |
+
}
|
| 167 |
+
};
|
| 168 |
+
|
| 169 |
+
/// Represents a signed 128-bit integer in two's complement.
|
| 170 |
+
///
|
| 171 |
+
/// This class is also compiled into LLVM IR - so, it should not have cpp references like
|
| 172 |
+
/// streams and boost.
|
| 173 |
+
class ARROW_EXPORT BasicDecimal128 : public GenericBasicDecimal<BasicDecimal128, 128> {
|
| 174 |
+
public:
|
| 175 |
+
static constexpr int kMaxPrecision = 38;
|
| 176 |
+
static constexpr int kMaxScale = 38;
|
| 177 |
+
|
| 178 |
+
using GenericBasicDecimal::GenericBasicDecimal;
|
| 179 |
+
|
| 180 |
+
constexpr BasicDecimal128() noexcept : GenericBasicDecimal() {}
|
| 181 |
+
|
| 182 |
+
/// \brief Create a BasicDecimal128 from the two's complement representation.
|
| 183 |
+
#if ARROW_LITTLE_ENDIAN
|
| 184 |
+
constexpr BasicDecimal128(int64_t high, uint64_t low) noexcept
|
| 185 |
+
: BasicDecimal128(WordArray{low, static_cast<uint64_t>(high)}) {}
|
| 186 |
+
#else
|
| 187 |
+
constexpr BasicDecimal128(int64_t high, uint64_t low) noexcept
|
| 188 |
+
: BasicDecimal128(WordArray{static_cast<uint64_t>(high), low}) {}
|
| 189 |
+
#endif
|
| 190 |
+
|
| 191 |
+
/// \brief Negate the current value (in-place)
|
| 192 |
+
BasicDecimal128& Negate();
|
| 193 |
+
|
| 194 |
+
/// \brief Absolute value (in-place)
|
| 195 |
+
BasicDecimal128& Abs();
|
| 196 |
+
|
| 197 |
+
/// \brief Absolute value
|
| 198 |
+
static BasicDecimal128 Abs(const BasicDecimal128& left);
|
| 199 |
+
|
| 200 |
+
/// \brief Add a number to this one. The result is truncated to 128 bits.
|
| 201 |
+
BasicDecimal128& operator+=(const BasicDecimal128& right);
|
| 202 |
+
|
| 203 |
+
/// \brief Subtract a number from this one. The result is truncated to 128 bits.
|
| 204 |
+
BasicDecimal128& operator-=(const BasicDecimal128& right);
|
| 205 |
+
|
| 206 |
+
/// \brief Multiply this number by another number. The result is truncated to 128 bits.
|
| 207 |
+
BasicDecimal128& operator*=(const BasicDecimal128& right);
|
| 208 |
+
|
| 209 |
+
/// Divide this number by right and return the result.
|
| 210 |
+
///
|
| 211 |
+
/// This operation is not destructive.
|
| 212 |
+
/// The answer rounds to zero. Signs work like:
|
| 213 |
+
/// 21 / 5 -> 4, 1
|
| 214 |
+
/// -21 / 5 -> -4, -1
|
| 215 |
+
/// 21 / -5 -> -4, 1
|
| 216 |
+
/// -21 / -5 -> 4, -1
|
| 217 |
+
/// \param[in] divisor the number to divide by
|
| 218 |
+
/// \param[out] result the quotient
|
| 219 |
+
/// \param[out] remainder the remainder after the division
|
| 220 |
+
DecimalStatus Divide(const BasicDecimal128& divisor, BasicDecimal128* result,
|
| 221 |
+
BasicDecimal128* remainder) const;
|
| 222 |
+
|
| 223 |
+
/// \brief In-place division.
|
| 224 |
+
BasicDecimal128& operator/=(const BasicDecimal128& right);
|
| 225 |
+
|
| 226 |
+
/// \brief Bitwise "or" between two BasicDecimal128.
|
| 227 |
+
BasicDecimal128& operator|=(const BasicDecimal128& right);
|
| 228 |
+
|
| 229 |
+
/// \brief Bitwise "and" between two BasicDecimal128.
|
| 230 |
+
BasicDecimal128& operator&=(const BasicDecimal128& right);
|
| 231 |
+
|
| 232 |
+
/// \brief Shift left by the given number of bits.
|
| 233 |
+
BasicDecimal128& operator<<=(uint32_t bits);
|
| 234 |
+
|
| 235 |
+
BasicDecimal128 operator<<(uint32_t bits) const {
|
| 236 |
+
auto res = *this;
|
| 237 |
+
res <<= bits;
|
| 238 |
+
return res;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
/// \brief Shift right by the given number of bits.
|
| 242 |
+
///
|
| 243 |
+
/// Negative values will sign-extend.
|
| 244 |
+
BasicDecimal128& operator>>=(uint32_t bits);
|
| 245 |
+
|
| 246 |
+
BasicDecimal128 operator>>(uint32_t bits) const {
|
| 247 |
+
auto res = *this;
|
| 248 |
+
res >>= bits;
|
| 249 |
+
return res;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
/// \brief Get the high bits of the two's complement representation of the number.
|
| 253 |
+
constexpr int64_t high_bits() const {
|
| 254 |
+
#if ARROW_LITTLE_ENDIAN
|
| 255 |
+
return static_cast<int64_t>(array_[1]);
|
| 256 |
+
#else
|
| 257 |
+
return static_cast<int64_t>(array_[0]);
|
| 258 |
+
#endif
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
/// \brief Get the low bits of the two's complement representation of the number.
|
| 262 |
+
constexpr uint64_t low_bits() const {
|
| 263 |
+
#if ARROW_LITTLE_ENDIAN
|
| 264 |
+
return array_[0];
|
| 265 |
+
#else
|
| 266 |
+
return array_[1];
|
| 267 |
+
#endif
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
/// \brief separate the integer and fractional parts for the given scale.
|
| 271 |
+
void GetWholeAndFraction(int32_t scale, BasicDecimal128* whole,
|
| 272 |
+
BasicDecimal128* fraction) const;
|
| 273 |
+
|
| 274 |
+
/// \brief Scale multiplier for given scale value.
|
| 275 |
+
static const BasicDecimal128& GetScaleMultiplier(int32_t scale);
|
| 276 |
+
/// \brief Half-scale multiplier for given scale value.
|
| 277 |
+
static const BasicDecimal128& GetHalfScaleMultiplier(int32_t scale);
|
| 278 |
+
|
| 279 |
+
/// \brief Convert BasicDecimal128 from one scale to another
|
| 280 |
+
DecimalStatus Rescale(int32_t original_scale, int32_t new_scale,
|
| 281 |
+
BasicDecimal128* out) const;
|
| 282 |
+
|
| 283 |
+
/// \brief Scale up.
|
| 284 |
+
BasicDecimal128 IncreaseScaleBy(int32_t increase_by) const;
|
| 285 |
+
|
| 286 |
+
/// \brief Scale down.
|
| 287 |
+
/// - If 'round' is true, the right-most digits are dropped and the result value is
|
| 288 |
+
/// rounded up (+1 for +ve, -1 for -ve) based on the value of the dropped digits
|
| 289 |
+
/// (>= 10^reduce_by / 2).
|
| 290 |
+
/// - If 'round' is false, the right-most digits are simply dropped.
|
| 291 |
+
BasicDecimal128 ReduceScaleBy(int32_t reduce_by, bool round = true) const;
|
| 292 |
+
|
| 293 |
+
/// \brief Whether this number fits in the given precision
|
| 294 |
+
///
|
| 295 |
+
/// Return true if the number of significant digits is less or equal to `precision`.
|
| 296 |
+
bool FitsInPrecision(int32_t precision) const;
|
| 297 |
+
|
| 298 |
+
/// \brief count the number of leading binary zeroes.
|
| 299 |
+
int32_t CountLeadingBinaryZeros() const;
|
| 300 |
+
|
| 301 |
+
/// \brief Get the maximum valid unscaled decimal value.
|
| 302 |
+
static const BasicDecimal128& GetMaxValue();
|
| 303 |
+
|
| 304 |
+
/// \brief Get the maximum valid unscaled decimal value for the given precision.
|
| 305 |
+
static BasicDecimal128 GetMaxValue(int32_t precision);
|
| 306 |
+
|
| 307 |
+
/// \brief Get the maximum decimal value (is not a valid value).
|
| 308 |
+
static constexpr BasicDecimal128 GetMaxSentinel() {
|
| 309 |
+
return BasicDecimal128(/*high=*/std::numeric_limits<int64_t>::max(),
|
| 310 |
+
/*low=*/std::numeric_limits<uint64_t>::max());
|
| 311 |
+
}
|
| 312 |
+
/// \brief Get the minimum decimal value (is not a valid value).
|
| 313 |
+
static constexpr BasicDecimal128 GetMinSentinel() {
|
| 314 |
+
return BasicDecimal128(/*high=*/std::numeric_limits<int64_t>::min(),
|
| 315 |
+
/*low=*/std::numeric_limits<uint64_t>::min());
|
| 316 |
+
}
|
| 317 |
+
};
|
| 318 |
+
|
| 319 |
+
ARROW_EXPORT bool operator<(const BasicDecimal128& left, const BasicDecimal128& right);
|
| 320 |
+
ARROW_EXPORT bool operator<=(const BasicDecimal128& left, const BasicDecimal128& right);
|
| 321 |
+
ARROW_EXPORT bool operator>(const BasicDecimal128& left, const BasicDecimal128& right);
|
| 322 |
+
ARROW_EXPORT bool operator>=(const BasicDecimal128& left, const BasicDecimal128& right);
|
| 323 |
+
|
| 324 |
+
ARROW_EXPORT BasicDecimal128 operator-(const BasicDecimal128& operand);
|
| 325 |
+
ARROW_EXPORT BasicDecimal128 operator~(const BasicDecimal128& operand);
|
| 326 |
+
ARROW_EXPORT BasicDecimal128 operator+(const BasicDecimal128& left,
|
| 327 |
+
const BasicDecimal128& right);
|
| 328 |
+
ARROW_EXPORT BasicDecimal128 operator-(const BasicDecimal128& left,
|
| 329 |
+
const BasicDecimal128& right);
|
| 330 |
+
ARROW_EXPORT BasicDecimal128 operator*(const BasicDecimal128& left,
|
| 331 |
+
const BasicDecimal128& right);
|
| 332 |
+
ARROW_EXPORT BasicDecimal128 operator/(const BasicDecimal128& left,
|
| 333 |
+
const BasicDecimal128& right);
|
| 334 |
+
ARROW_EXPORT BasicDecimal128 operator%(const BasicDecimal128& left,
|
| 335 |
+
const BasicDecimal128& right);
|
| 336 |
+
|
| 337 |
+
class ARROW_EXPORT BasicDecimal256 : public GenericBasicDecimal<BasicDecimal256, 256> {
|
| 338 |
+
public:
|
| 339 |
+
using GenericBasicDecimal::GenericBasicDecimal;
|
| 340 |
+
|
| 341 |
+
static constexpr int kMaxPrecision = 76;
|
| 342 |
+
static constexpr int kMaxScale = 76;
|
| 343 |
+
|
| 344 |
+
constexpr BasicDecimal256() noexcept : GenericBasicDecimal() {}
|
| 345 |
+
|
| 346 |
+
explicit BasicDecimal256(const BasicDecimal128& value) noexcept
|
| 347 |
+
: BasicDecimal256(bit_util::little_endian::ToNative<uint64_t, 4>(
|
| 348 |
+
{value.low_bits(), static_cast<uint64_t>(value.high_bits()),
|
| 349 |
+
SignExtend(value.high_bits()), SignExtend(value.high_bits())})) {}
|
| 350 |
+
|
| 351 |
+
/// \brief Negate the current value (in-place)
|
| 352 |
+
BasicDecimal256& Negate();
|
| 353 |
+
|
| 354 |
+
/// \brief Absolute value (in-place)
|
| 355 |
+
BasicDecimal256& Abs();
|
| 356 |
+
|
| 357 |
+
/// \brief Absolute value
|
| 358 |
+
static BasicDecimal256 Abs(const BasicDecimal256& left);
|
| 359 |
+
|
| 360 |
+
/// \brief Add a number to this one. The result is truncated to 256 bits.
|
| 361 |
+
BasicDecimal256& operator+=(const BasicDecimal256& right);
|
| 362 |
+
|
| 363 |
+
/// \brief Subtract a number from this one. The result is truncated to 256 bits.
|
| 364 |
+
BasicDecimal256& operator-=(const BasicDecimal256& right);
|
| 365 |
+
|
| 366 |
+
/// \brief Get the lowest bits of the two's complement representation of the number.
|
| 367 |
+
uint64_t low_bits() const { return bit_util::little_endian::Make(array_)[0]; }
|
| 368 |
+
|
| 369 |
+
/// \brief separate the integer and fractional parts for the given scale.
|
| 370 |
+
void GetWholeAndFraction(int32_t scale, BasicDecimal256* whole,
|
| 371 |
+
BasicDecimal256* fraction) const;
|
| 372 |
+
|
| 373 |
+
/// \brief Scale multiplier for given scale value.
|
| 374 |
+
static const BasicDecimal256& GetScaleMultiplier(int32_t scale);
|
| 375 |
+
/// \brief Half-scale multiplier for given scale value.
|
| 376 |
+
static const BasicDecimal256& GetHalfScaleMultiplier(int32_t scale);
|
| 377 |
+
|
| 378 |
+
/// \brief Convert BasicDecimal256 from one scale to another
|
| 379 |
+
DecimalStatus Rescale(int32_t original_scale, int32_t new_scale,
|
| 380 |
+
BasicDecimal256* out) const;
|
| 381 |
+
|
| 382 |
+
/// \brief Scale up.
|
| 383 |
+
BasicDecimal256 IncreaseScaleBy(int32_t increase_by) const;
|
| 384 |
+
|
| 385 |
+
/// \brief Scale down.
|
| 386 |
+
/// - If 'round' is true, the right-most digits are dropped and the result value is
|
| 387 |
+
/// rounded up (+1 for positive, -1 for negative) based on the value of the
|
| 388 |
+
/// dropped digits (>= 10^reduce_by / 2).
|
| 389 |
+
/// - If 'round' is false, the right-most digits are simply dropped.
|
| 390 |
+
BasicDecimal256 ReduceScaleBy(int32_t reduce_by, bool round = true) const;
|
| 391 |
+
|
| 392 |
+
/// \brief Whether this number fits in the given precision
|
| 393 |
+
///
|
| 394 |
+
/// Return true if the number of significant digits is less or equal to `precision`.
|
| 395 |
+
bool FitsInPrecision(int32_t precision) const;
|
| 396 |
+
|
| 397 |
+
/// \brief Multiply this number by another number. The result is truncated to 256 bits.
|
| 398 |
+
BasicDecimal256& operator*=(const BasicDecimal256& right);
|
| 399 |
+
|
| 400 |
+
/// Divide this number by right and return the result.
|
| 401 |
+
///
|
| 402 |
+
/// This operation is not destructive.
|
| 403 |
+
/// The answer rounds to zero. Signs work like:
|
| 404 |
+
/// 21 / 5 -> 4, 1
|
| 405 |
+
/// -21 / 5 -> -4, -1
|
| 406 |
+
/// 21 / -5 -> -4, 1
|
| 407 |
+
/// -21 / -5 -> 4, -1
|
| 408 |
+
/// \param[in] divisor the number to divide by
|
| 409 |
+
/// \param[out] result the quotient
|
| 410 |
+
/// \param[out] remainder the remainder after the division
|
| 411 |
+
DecimalStatus Divide(const BasicDecimal256& divisor, BasicDecimal256* result,
|
| 412 |
+
BasicDecimal256* remainder) const;
|
| 413 |
+
|
| 414 |
+
/// \brief Shift left by the given number of bits.
|
| 415 |
+
BasicDecimal256& operator<<=(uint32_t bits);
|
| 416 |
+
|
| 417 |
+
BasicDecimal256 operator<<(uint32_t bits) const {
|
| 418 |
+
auto res = *this;
|
| 419 |
+
res <<= bits;
|
| 420 |
+
return res;
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
/// \brief Shift right by the given number of bits.
|
| 424 |
+
///
|
| 425 |
+
/// Negative values will sign-extend.
|
| 426 |
+
BasicDecimal256& operator>>=(uint32_t bits);
|
| 427 |
+
|
| 428 |
+
BasicDecimal256 operator>>(uint32_t bits) const {
|
| 429 |
+
auto res = *this;
|
| 430 |
+
res >>= bits;
|
| 431 |
+
return res;
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
/// \brief In-place division.
|
| 435 |
+
BasicDecimal256& operator/=(const BasicDecimal256& right);
|
| 436 |
+
|
| 437 |
+
/// \brief Get the maximum valid unscaled decimal value for the given precision.
|
| 438 |
+
static BasicDecimal256 GetMaxValue(int32_t precision);
|
| 439 |
+
|
| 440 |
+
/// \brief Get the maximum decimal value (is not a valid value).
|
| 441 |
+
static constexpr BasicDecimal256 GetMaxSentinel() {
|
| 442 |
+
#if ARROW_LITTLE_ENDIAN
|
| 443 |
+
return BasicDecimal256({std::numeric_limits<uint64_t>::max(),
|
| 444 |
+
std::numeric_limits<uint64_t>::max(),
|
| 445 |
+
std::numeric_limits<uint64_t>::max(),
|
| 446 |
+
static_cast<uint64_t>(std::numeric_limits<int64_t>::max())});
|
| 447 |
+
#else
|
| 448 |
+
return BasicDecimal256({static_cast<uint64_t>(std::numeric_limits<int64_t>::max()),
|
| 449 |
+
std::numeric_limits<uint64_t>::max(),
|
| 450 |
+
std::numeric_limits<uint64_t>::max(),
|
| 451 |
+
std::numeric_limits<uint64_t>::max()});
|
| 452 |
+
#endif
|
| 453 |
+
}
|
| 454 |
+
/// \brief Get the minimum decimal value (is not a valid value).
|
| 455 |
+
static constexpr BasicDecimal256 GetMinSentinel() {
|
| 456 |
+
#if ARROW_LITTLE_ENDIAN
|
| 457 |
+
return BasicDecimal256(
|
| 458 |
+
{0, 0, 0, static_cast<uint64_t>(std::numeric_limits<int64_t>::min())});
|
| 459 |
+
#else
|
| 460 |
+
return BasicDecimal256(
|
| 461 |
+
{static_cast<uint64_t>(std::numeric_limits<int64_t>::min()), 0, 0, 0});
|
| 462 |
+
#endif
|
| 463 |
+
}
|
| 464 |
+
};
|
| 465 |
+
|
| 466 |
+
ARROW_EXPORT bool operator<(const BasicDecimal256& left, const BasicDecimal256& right);
|
| 467 |
+
|
| 468 |
+
ARROW_EXPORT inline bool operator<=(const BasicDecimal256& left,
|
| 469 |
+
const BasicDecimal256& right) {
|
| 470 |
+
return !operator<(right, left);
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
ARROW_EXPORT inline bool operator>(const BasicDecimal256& left,
|
| 474 |
+
const BasicDecimal256& right) {
|
| 475 |
+
return operator<(right, left);
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
ARROW_EXPORT inline bool operator>=(const BasicDecimal256& left,
|
| 479 |
+
const BasicDecimal256& right) {
|
| 480 |
+
return !operator<(left, right);
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
ARROW_EXPORT BasicDecimal256 operator-(const BasicDecimal256& operand);
|
| 484 |
+
ARROW_EXPORT BasicDecimal256 operator~(const BasicDecimal256& operand);
|
| 485 |
+
ARROW_EXPORT BasicDecimal256 operator+(const BasicDecimal256& left,
|
| 486 |
+
const BasicDecimal256& right);
|
| 487 |
+
ARROW_EXPORT BasicDecimal256 operator*(const BasicDecimal256& left,
|
| 488 |
+
const BasicDecimal256& right);
|
| 489 |
+
ARROW_EXPORT BasicDecimal256 operator/(const BasicDecimal256& left,
|
| 490 |
+
const BasicDecimal256& right);
|
| 491 |
+
|
| 492 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/benchmark_util.h
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#include <algorithm>
|
| 19 |
+
#include <cstdint>
|
| 20 |
+
#include <string>
|
| 21 |
+
|
| 22 |
+
#include "benchmark/benchmark.h"
|
| 23 |
+
|
| 24 |
+
#include "arrow/memory_pool.h"
|
| 25 |
+
#include "arrow/type_fwd.h"
|
| 26 |
+
#include "arrow/util/cpu_info.h"
|
| 27 |
+
#include "arrow/util/logging.h" // IWYU pragma: keep
|
| 28 |
+
|
| 29 |
+
namespace arrow {
|
| 30 |
+
|
| 31 |
+
// Benchmark changed its parameter type between releases from
|
| 32 |
+
// int to int64_t. As it doesn't have version macros, we need
|
| 33 |
+
// to apply C++ template magic.
|
| 34 |
+
|
| 35 |
+
template <typename Func>
|
| 36 |
+
struct BenchmarkArgsType;
|
| 37 |
+
|
| 38 |
+
// Pattern matching that extracts the vector element type of Benchmark::Args()
|
| 39 |
+
template <typename Values>
|
| 40 |
+
struct BenchmarkArgsType<benchmark::internal::Benchmark* (
|
| 41 |
+
benchmark::internal::Benchmark::*)(const std::vector<Values>&)> {
|
| 42 |
+
using type = Values;
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
using ArgsType =
|
| 46 |
+
typename BenchmarkArgsType<decltype(&benchmark::internal::Benchmark::Args)>::type;
|
| 47 |
+
|
| 48 |
+
using internal::CpuInfo;
|
| 49 |
+
|
| 50 |
+
static const CpuInfo* cpu_info = CpuInfo::GetInstance();
|
| 51 |
+
|
| 52 |
+
static const int64_t kL1Size = cpu_info->CacheSize(CpuInfo::CacheLevel::L1);
|
| 53 |
+
static const int64_t kL2Size = cpu_info->CacheSize(CpuInfo::CacheLevel::L2);
|
| 54 |
+
static const int64_t kL3Size = cpu_info->CacheSize(CpuInfo::CacheLevel::L3);
|
| 55 |
+
static const int64_t kCantFitInL3Size = kL3Size * 4;
|
| 56 |
+
static const std::vector<int64_t> kMemorySizes = {kL1Size, kL2Size, kL3Size,
|
| 57 |
+
kCantFitInL3Size};
|
| 58 |
+
// 0 is treated as "no nulls"
|
| 59 |
+
static const std::vector<ArgsType> kInverseNullProportions = {10000, 100, 10, 2, 1, 0};
|
| 60 |
+
|
| 61 |
+
struct GenericItemsArgs {
|
| 62 |
+
// number of items processed per iteration
|
| 63 |
+
const int64_t size;
|
| 64 |
+
|
| 65 |
+
// proportion of nulls in generated arrays
|
| 66 |
+
double null_proportion;
|
| 67 |
+
|
| 68 |
+
explicit GenericItemsArgs(benchmark::State& state)
|
| 69 |
+
: size(state.range(0)), state_(state) {
|
| 70 |
+
if (state.range(1) == 0) {
|
| 71 |
+
this->null_proportion = 0.0;
|
| 72 |
+
} else {
|
| 73 |
+
this->null_proportion = std::min(1., 1. / static_cast<double>(state.range(1)));
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
~GenericItemsArgs() {
|
| 78 |
+
state_.counters["size"] = static_cast<double>(size);
|
| 79 |
+
state_.counters["null_percent"] = null_proportion * 100;
|
| 80 |
+
state_.SetItemsProcessed(state_.iterations() * size);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
private:
|
| 84 |
+
benchmark::State& state_;
|
| 85 |
+
};
|
| 86 |
+
|
| 87 |
+
void BenchmarkSetArgsWithSizes(benchmark::internal::Benchmark* bench,
|
| 88 |
+
const std::vector<int64_t>& sizes = kMemorySizes) {
|
| 89 |
+
bench->Unit(benchmark::kMicrosecond);
|
| 90 |
+
|
| 91 |
+
for (const auto size : sizes) {
|
| 92 |
+
for (const auto inverse_null_proportion : kInverseNullProportions) {
|
| 93 |
+
bench->Args({static_cast<ArgsType>(size), inverse_null_proportion});
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
void BenchmarkSetArgs(benchmark::internal::Benchmark* bench) {
|
| 99 |
+
BenchmarkSetArgsWithSizes(bench, kMemorySizes);
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
void RegressionSetArgs(benchmark::internal::Benchmark* bench) {
|
| 103 |
+
// Regression do not need to account for cache hierarchy, thus optimize for
|
| 104 |
+
// the best case.
|
| 105 |
+
BenchmarkSetArgsWithSizes(bench, {kL1Size});
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
// RAII struct to handle some of the boilerplate in regression benchmarks
|
| 109 |
+
struct RegressionArgs {
|
| 110 |
+
// size of memory tested (per iteration) in bytes
|
| 111 |
+
int64_t size;
|
| 112 |
+
|
| 113 |
+
// proportion of nulls in generated arrays
|
| 114 |
+
double null_proportion;
|
| 115 |
+
|
| 116 |
+
// If size_is_bytes is true, then it's a number of bytes, otherwise it's the
|
| 117 |
+
// number of items processed (for reporting)
|
| 118 |
+
explicit RegressionArgs(benchmark::State& state, bool size_is_bytes = true)
|
| 119 |
+
: size(state.range(0)), state_(state), size_is_bytes_(size_is_bytes) {
|
| 120 |
+
if (state.range(1) == 0) {
|
| 121 |
+
this->null_proportion = 0.0;
|
| 122 |
+
} else {
|
| 123 |
+
this->null_proportion = std::min(1., 1. / static_cast<double>(state.range(1)));
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
~RegressionArgs() {
|
| 128 |
+
state_.counters["size"] = static_cast<double>(size);
|
| 129 |
+
state_.counters["null_percent"] = null_proportion * 100;
|
| 130 |
+
if (size_is_bytes_) {
|
| 131 |
+
state_.SetBytesProcessed(state_.iterations() * size);
|
| 132 |
+
} else {
|
| 133 |
+
state_.SetItemsProcessed(state_.iterations() * size);
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
private:
|
| 138 |
+
benchmark::State& state_;
|
| 139 |
+
bool size_is_bytes_;
|
| 140 |
+
};
|
| 141 |
+
|
| 142 |
+
class MemoryPoolMemoryManager : public benchmark::MemoryManager {
|
| 143 |
+
void Start() override {
|
| 144 |
+
memory_pool = std::make_shared<ProxyMemoryPool>(default_memory_pool());
|
| 145 |
+
|
| 146 |
+
MemoryPool* default_pool = default_memory_pool();
|
| 147 |
+
global_allocations_start = default_pool->num_allocations();
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
// BENCHMARK_DONT_OPTIMIZE is used here to detect Google Benchmark
|
| 151 |
+
// 1.8.0. We can remove this Stop(Result*) when we require Google
|
| 152 |
+
// Benchmark 1.8.0 or later.
|
| 153 |
+
#ifndef BENCHMARK_DONT_OPTIMIZE
|
| 154 |
+
void Stop(Result* result) override { Stop(*result); }
|
| 155 |
+
#endif
|
| 156 |
+
|
| 157 |
+
void Stop(benchmark::MemoryManager::Result& result) override {
|
| 158 |
+
// If num_allocations is still zero, we assume that the memory pool wasn't passed down
|
| 159 |
+
// so we should record them.
|
| 160 |
+
MemoryPool* default_pool = default_memory_pool();
|
| 161 |
+
int64_t new_default_allocations =
|
| 162 |
+
default_pool->num_allocations() - global_allocations_start;
|
| 163 |
+
|
| 164 |
+
// Only record metrics if (1) there were allocations and (2) we
|
| 165 |
+
// recorded at least one.
|
| 166 |
+
if (new_default_allocations > 0 && memory_pool->num_allocations() > 0) {
|
| 167 |
+
if (new_default_allocations > memory_pool->num_allocations()) {
|
| 168 |
+
// If we missed some, let's report that.
|
| 169 |
+
int64_t missed_allocations =
|
| 170 |
+
new_default_allocations - memory_pool->num_allocations();
|
| 171 |
+
ARROW_LOG(WARNING) << "BenchmarkMemoryTracker recorded some allocations "
|
| 172 |
+
<< "for a benchmark, but missed " << missed_allocations
|
| 173 |
+
<< " allocations.\n";
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
result.max_bytes_used = memory_pool->max_memory();
|
| 177 |
+
result.total_allocated_bytes = memory_pool->total_bytes_allocated();
|
| 178 |
+
result.num_allocs = memory_pool->num_allocations();
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
public:
|
| 183 |
+
std::shared_ptr<::arrow::ProxyMemoryPool> memory_pool;
|
| 184 |
+
|
| 185 |
+
protected:
|
| 186 |
+
int64_t global_allocations_start;
|
| 187 |
+
};
|
| 188 |
+
|
| 189 |
+
/// \brief Track memory pool allocations in benchmarks.
|
| 190 |
+
///
|
| 191 |
+
/// Instantiate as a global variable to register the hooks into Google Benchmark
|
| 192 |
+
/// to collect memory metrics. Before each benchmark, a new ProxyMemoryPool is
|
| 193 |
+
/// created. It can then be accessed with memory_pool(). Once the benchmark is
|
| 194 |
+
/// complete, the hook will record the maximum memory used, the total bytes
|
| 195 |
+
/// allocated, and the total number of allocations. If no allocations were seen,
|
| 196 |
+
/// (for example, if you forgot to pass down the memory pool), then these metrics
|
| 197 |
+
/// will not be saved.
|
| 198 |
+
///
|
| 199 |
+
/// Since this is used as one global variable, this will not work if multiple
|
| 200 |
+
/// benchmarks are run concurrently or for multi-threaded benchmarks (ones
|
| 201 |
+
/// that use `->ThreadRange(...)`).
|
| 202 |
+
class BenchmarkMemoryTracker {
|
| 203 |
+
public:
|
| 204 |
+
BenchmarkMemoryTracker() : manager_() { ::benchmark::RegisterMemoryManager(&manager_); }
|
| 205 |
+
::arrow::MemoryPool* memory_pool() const { return manager_.memory_pool.get(); }
|
| 206 |
+
|
| 207 |
+
protected:
|
| 208 |
+
::arrow::MemoryPoolMemoryManager manager_;
|
| 209 |
+
};
|
| 210 |
+
|
| 211 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/bit_block_counter.h
ADDED
|
@@ -0,0 +1,570 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <algorithm>
|
| 21 |
+
#include <cstdint>
|
| 22 |
+
#include <limits>
|
| 23 |
+
#include <memory>
|
| 24 |
+
|
| 25 |
+
#include "arrow/buffer.h"
|
| 26 |
+
#include "arrow/status.h"
|
| 27 |
+
#include "arrow/util/bit_util.h"
|
| 28 |
+
#include "arrow/util/endian.h"
|
| 29 |
+
#include "arrow/util/macros.h"
|
| 30 |
+
#include "arrow/util/ubsan.h"
|
| 31 |
+
#include "arrow/util/visibility.h"
|
| 32 |
+
|
| 33 |
+
namespace arrow {
|
| 34 |
+
namespace internal {
|
| 35 |
+
namespace detail {
|
| 36 |
+
|
| 37 |
+
inline uint64_t LoadWord(const uint8_t* bytes) {
|
| 38 |
+
return bit_util::ToLittleEndian(util::SafeLoadAs<uint64_t>(bytes));
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
inline uint64_t ShiftWord(uint64_t current, uint64_t next, int64_t shift) {
|
| 42 |
+
if (shift == 0) {
|
| 43 |
+
return current;
|
| 44 |
+
}
|
| 45 |
+
return (current >> shift) | (next << (64 - shift));
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
// These templates are here to help with unit tests
|
| 49 |
+
|
| 50 |
+
template <typename T>
|
| 51 |
+
constexpr T BitNot(T x) {
|
| 52 |
+
return ~x;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
template <>
|
| 56 |
+
constexpr bool BitNot(bool x) {
|
| 57 |
+
return !x;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
struct BitBlockAnd {
|
| 61 |
+
template <typename T>
|
| 62 |
+
static constexpr T Call(T left, T right) {
|
| 63 |
+
return left & right;
|
| 64 |
+
}
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
struct BitBlockAndNot {
|
| 68 |
+
template <typename T>
|
| 69 |
+
static constexpr T Call(T left, T right) {
|
| 70 |
+
return left & BitNot(right);
|
| 71 |
+
}
|
| 72 |
+
};
|
| 73 |
+
|
| 74 |
+
struct BitBlockOr {
|
| 75 |
+
template <typename T>
|
| 76 |
+
static constexpr T Call(T left, T right) {
|
| 77 |
+
return left | right;
|
| 78 |
+
}
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
struct BitBlockOrNot {
|
| 82 |
+
template <typename T>
|
| 83 |
+
static constexpr T Call(T left, T right) {
|
| 84 |
+
return left | BitNot(right);
|
| 85 |
+
}
|
| 86 |
+
};
|
| 87 |
+
|
| 88 |
+
} // namespace detail
|
| 89 |
+
|
| 90 |
+
/// \brief Return value from bit block counters: the total number of bits and
|
| 91 |
+
/// the number of set bits.
|
| 92 |
+
struct BitBlockCount {
|
| 93 |
+
int16_t length;
|
| 94 |
+
int16_t popcount;
|
| 95 |
+
|
| 96 |
+
bool NoneSet() const { return this->popcount == 0; }
|
| 97 |
+
bool AllSet() const { return this->length == this->popcount; }
|
| 98 |
+
};
|
| 99 |
+
|
| 100 |
+
/// \brief A class that scans through a true/false bitmap to compute popcounts
|
| 101 |
+
/// 64 or 256 bits at a time. This is used to accelerate processing of
|
| 102 |
+
/// mostly-not-null array data.
|
| 103 |
+
class ARROW_EXPORT BitBlockCounter {
|
| 104 |
+
public:
|
| 105 |
+
BitBlockCounter(const uint8_t* bitmap, int64_t start_offset, int64_t length)
|
| 106 |
+
: bitmap_(util::MakeNonNull(bitmap) + start_offset / 8),
|
| 107 |
+
bits_remaining_(length),
|
| 108 |
+
offset_(start_offset % 8) {}
|
| 109 |
+
|
| 110 |
+
/// \brief The bit size of each word run
|
| 111 |
+
static constexpr int64_t kWordBits = 64;
|
| 112 |
+
|
| 113 |
+
/// \brief The bit size of four words run
|
| 114 |
+
static constexpr int64_t kFourWordsBits = kWordBits * 4;
|
| 115 |
+
|
| 116 |
+
/// \brief Return the next run of available bits, usually 256. The returned
|
| 117 |
+
/// pair contains the size of run and the number of true values. The last
|
| 118 |
+
/// block will have a length less than 256 if the bitmap length is not a
|
| 119 |
+
/// multiple of 256, and will return 0-length blocks in subsequent
|
| 120 |
+
/// invocations.
|
| 121 |
+
BitBlockCount NextFourWords() {
|
| 122 |
+
using detail::LoadWord;
|
| 123 |
+
using detail::ShiftWord;
|
| 124 |
+
|
| 125 |
+
if (!bits_remaining_) {
|
| 126 |
+
return {0, 0};
|
| 127 |
+
}
|
| 128 |
+
int64_t total_popcount = 0;
|
| 129 |
+
if (offset_ == 0) {
|
| 130 |
+
if (bits_remaining_ < kFourWordsBits) {
|
| 131 |
+
return GetBlockSlow(kFourWordsBits);
|
| 132 |
+
}
|
| 133 |
+
total_popcount += bit_util::PopCount(LoadWord(bitmap_));
|
| 134 |
+
total_popcount += bit_util::PopCount(LoadWord(bitmap_ + 8));
|
| 135 |
+
total_popcount += bit_util::PopCount(LoadWord(bitmap_ + 16));
|
| 136 |
+
total_popcount += bit_util::PopCount(LoadWord(bitmap_ + 24));
|
| 137 |
+
} else {
|
| 138 |
+
// When the offset is > 0, we need there to be a word beyond the last
|
| 139 |
+
// aligned word in the bitmap for the bit shifting logic.
|
| 140 |
+
if (bits_remaining_ < 5 * kFourWordsBits - offset_) {
|
| 141 |
+
return GetBlockSlow(kFourWordsBits);
|
| 142 |
+
}
|
| 143 |
+
auto current = LoadWord(bitmap_);
|
| 144 |
+
auto next = LoadWord(bitmap_ + 8);
|
| 145 |
+
total_popcount += bit_util::PopCount(ShiftWord(current, next, offset_));
|
| 146 |
+
current = next;
|
| 147 |
+
next = LoadWord(bitmap_ + 16);
|
| 148 |
+
total_popcount += bit_util::PopCount(ShiftWord(current, next, offset_));
|
| 149 |
+
current = next;
|
| 150 |
+
next = LoadWord(bitmap_ + 24);
|
| 151 |
+
total_popcount += bit_util::PopCount(ShiftWord(current, next, offset_));
|
| 152 |
+
current = next;
|
| 153 |
+
next = LoadWord(bitmap_ + 32);
|
| 154 |
+
total_popcount += bit_util::PopCount(ShiftWord(current, next, offset_));
|
| 155 |
+
}
|
| 156 |
+
bitmap_ += bit_util::BytesForBits(kFourWordsBits);
|
| 157 |
+
bits_remaining_ -= kFourWordsBits;
|
| 158 |
+
return {256, static_cast<int16_t>(total_popcount)};
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
/// \brief Return the next run of available bits, usually 64. The returned
|
| 162 |
+
/// pair contains the size of run and the number of true values. The last
|
| 163 |
+
/// block will have a length less than 64 if the bitmap length is not a
|
| 164 |
+
/// multiple of 64, and will return 0-length blocks in subsequent
|
| 165 |
+
/// invocations.
|
| 166 |
+
BitBlockCount NextWord() {
|
| 167 |
+
using detail::LoadWord;
|
| 168 |
+
using detail::ShiftWord;
|
| 169 |
+
|
| 170 |
+
if (!bits_remaining_) {
|
| 171 |
+
return {0, 0};
|
| 172 |
+
}
|
| 173 |
+
int64_t popcount = 0;
|
| 174 |
+
if (offset_ == 0) {
|
| 175 |
+
if (bits_remaining_ < kWordBits) {
|
| 176 |
+
return GetBlockSlow(kWordBits);
|
| 177 |
+
}
|
| 178 |
+
popcount = bit_util::PopCount(LoadWord(bitmap_));
|
| 179 |
+
} else {
|
| 180 |
+
// When the offset is > 0, we need there to be a word beyond the last
|
| 181 |
+
// aligned word in the bitmap for the bit shifting logic.
|
| 182 |
+
if (bits_remaining_ < 2 * kWordBits - offset_) {
|
| 183 |
+
return GetBlockSlow(kWordBits);
|
| 184 |
+
}
|
| 185 |
+
popcount = bit_util::PopCount(
|
| 186 |
+
ShiftWord(LoadWord(bitmap_), LoadWord(bitmap_ + 8), offset_));
|
| 187 |
+
}
|
| 188 |
+
bitmap_ += kWordBits / 8;
|
| 189 |
+
bits_remaining_ -= kWordBits;
|
| 190 |
+
return {64, static_cast<int16_t>(popcount)};
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
private:
|
| 194 |
+
/// \brief Return block with the requested size when doing word-wise
|
| 195 |
+
/// computation is not possible due to inadequate bits remaining.
|
| 196 |
+
BitBlockCount GetBlockSlow(int64_t block_size) noexcept;
|
| 197 |
+
|
| 198 |
+
const uint8_t* bitmap_;
|
| 199 |
+
int64_t bits_remaining_;
|
| 200 |
+
int64_t offset_;
|
| 201 |
+
};
|
| 202 |
+
|
| 203 |
+
/// \brief A tool to iterate through a possibly nonexistent validity bitmap,
|
| 204 |
+
/// to allow us to write one code path for both the with-nulls and no-nulls
|
| 205 |
+
/// cases without giving up a lot of performance.
|
| 206 |
+
class ARROW_EXPORT OptionalBitBlockCounter {
|
| 207 |
+
public:
|
| 208 |
+
// validity_bitmap may be NULLPTR
|
| 209 |
+
OptionalBitBlockCounter(const uint8_t* validity_bitmap, int64_t offset, int64_t length);
|
| 210 |
+
|
| 211 |
+
// validity_bitmap may be null
|
| 212 |
+
OptionalBitBlockCounter(const std::shared_ptr<Buffer>& validity_bitmap, int64_t offset,
|
| 213 |
+
int64_t length);
|
| 214 |
+
|
| 215 |
+
/// Return block count for next word when the bitmap is available otherwise
|
| 216 |
+
/// return a block with length up to INT16_MAX when there is no validity
|
| 217 |
+
/// bitmap (so all the referenced values are not null).
|
| 218 |
+
BitBlockCount NextBlock() {
|
| 219 |
+
static constexpr int64_t kMaxBlockSize = std::numeric_limits<int16_t>::max();
|
| 220 |
+
if (has_bitmap_) {
|
| 221 |
+
BitBlockCount block = counter_.NextWord();
|
| 222 |
+
position_ += block.length;
|
| 223 |
+
return block;
|
| 224 |
+
} else {
|
| 225 |
+
int16_t block_size =
|
| 226 |
+
static_cast<int16_t>(std::min(kMaxBlockSize, length_ - position_));
|
| 227 |
+
position_ += block_size;
|
| 228 |
+
// All values are non-null
|
| 229 |
+
return {block_size, block_size};
|
| 230 |
+
}
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
// Like NextBlock, but returns a word-sized block even when there is no
|
| 234 |
+
// validity bitmap
|
| 235 |
+
BitBlockCount NextWord() {
|
| 236 |
+
static constexpr int64_t kWordSize = 64;
|
| 237 |
+
if (has_bitmap_) {
|
| 238 |
+
BitBlockCount block = counter_.NextWord();
|
| 239 |
+
position_ += block.length;
|
| 240 |
+
return block;
|
| 241 |
+
} else {
|
| 242 |
+
int16_t block_size = static_cast<int16_t>(std::min(kWordSize, length_ - position_));
|
| 243 |
+
position_ += block_size;
|
| 244 |
+
// All values are non-null
|
| 245 |
+
return {block_size, block_size};
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
private:
|
| 250 |
+
const bool has_bitmap_;
|
| 251 |
+
int64_t position_;
|
| 252 |
+
int64_t length_;
|
| 253 |
+
BitBlockCounter counter_;
|
| 254 |
+
};
|
| 255 |
+
|
| 256 |
+
/// \brief A class that computes popcounts on the result of bitwise operations
|
| 257 |
+
/// between two bitmaps, 64 bits at a time. A 64-bit word is loaded from each
|
| 258 |
+
/// bitmap, then the popcount is computed on e.g. the bitwise-and of the two
|
| 259 |
+
/// words.
|
| 260 |
+
class ARROW_EXPORT BinaryBitBlockCounter {
|
| 261 |
+
public:
|
| 262 |
+
BinaryBitBlockCounter(const uint8_t* left_bitmap, int64_t left_offset,
|
| 263 |
+
const uint8_t* right_bitmap, int64_t right_offset, int64_t length)
|
| 264 |
+
: left_bitmap_(util::MakeNonNull(left_bitmap) + left_offset / 8),
|
| 265 |
+
left_offset_(left_offset % 8),
|
| 266 |
+
right_bitmap_(util::MakeNonNull(right_bitmap) + right_offset / 8),
|
| 267 |
+
right_offset_(right_offset % 8),
|
| 268 |
+
bits_remaining_(length) {}
|
| 269 |
+
|
| 270 |
+
/// \brief Return the popcount of the bitwise-and of the next run of
|
| 271 |
+
/// available bits, up to 64. The returned pair contains the size of run and
|
| 272 |
+
/// the number of true values. The last block will have a length less than 64
|
| 273 |
+
/// if the bitmap length is not a multiple of 64, and will return 0-length
|
| 274 |
+
/// blocks in subsequent invocations.
|
| 275 |
+
BitBlockCount NextAndWord() { return NextWord<detail::BitBlockAnd>(); }
|
| 276 |
+
|
| 277 |
+
/// \brief Computes "x & ~y" block for each available run of bits.
|
| 278 |
+
BitBlockCount NextAndNotWord() { return NextWord<detail::BitBlockAndNot>(); }
|
| 279 |
+
|
| 280 |
+
/// \brief Computes "x | y" block for each available run of bits.
|
| 281 |
+
BitBlockCount NextOrWord() { return NextWord<detail::BitBlockOr>(); }
|
| 282 |
+
|
| 283 |
+
/// \brief Computes "x | ~y" block for each available run of bits.
|
| 284 |
+
BitBlockCount NextOrNotWord() { return NextWord<detail::BitBlockOrNot>(); }
|
| 285 |
+
|
| 286 |
+
private:
|
| 287 |
+
template <class Op>
|
| 288 |
+
BitBlockCount NextWord() {
|
| 289 |
+
using detail::LoadWord;
|
| 290 |
+
using detail::ShiftWord;
|
| 291 |
+
|
| 292 |
+
if (!bits_remaining_) {
|
| 293 |
+
return {0, 0};
|
| 294 |
+
}
|
| 295 |
+
// When the offset is > 0, we need there to be a word beyond the last aligned
|
| 296 |
+
// word in the bitmap for the bit shifting logic.
|
| 297 |
+
constexpr int64_t kWordBits = BitBlockCounter::kWordBits;
|
| 298 |
+
const int64_t bits_required_to_use_words =
|
| 299 |
+
std::max(left_offset_ == 0 ? 64 : 64 + (64 - left_offset_),
|
| 300 |
+
right_offset_ == 0 ? 64 : 64 + (64 - right_offset_));
|
| 301 |
+
if (bits_remaining_ < bits_required_to_use_words) {
|
| 302 |
+
const int16_t run_length =
|
| 303 |
+
static_cast<int16_t>(std::min(bits_remaining_, kWordBits));
|
| 304 |
+
int16_t popcount = 0;
|
| 305 |
+
for (int64_t i = 0; i < run_length; ++i) {
|
| 306 |
+
if (Op::Call(bit_util::GetBit(left_bitmap_, left_offset_ + i),
|
| 307 |
+
bit_util::GetBit(right_bitmap_, right_offset_ + i))) {
|
| 308 |
+
++popcount;
|
| 309 |
+
}
|
| 310 |
+
}
|
| 311 |
+
// This code path should trigger _at most_ 2 times. In the "two times"
|
| 312 |
+
// case, the first time the run length will be a multiple of 8.
|
| 313 |
+
left_bitmap_ += run_length / 8;
|
| 314 |
+
right_bitmap_ += run_length / 8;
|
| 315 |
+
bits_remaining_ -= run_length;
|
| 316 |
+
return {run_length, popcount};
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
int64_t popcount = 0;
|
| 320 |
+
if (left_offset_ == 0 && right_offset_ == 0) {
|
| 321 |
+
popcount =
|
| 322 |
+
bit_util::PopCount(Op::Call(LoadWord(left_bitmap_), LoadWord(right_bitmap_)));
|
| 323 |
+
} else {
|
| 324 |
+
auto left_word =
|
| 325 |
+
ShiftWord(LoadWord(left_bitmap_), LoadWord(left_bitmap_ + 8), left_offset_);
|
| 326 |
+
auto right_word =
|
| 327 |
+
ShiftWord(LoadWord(right_bitmap_), LoadWord(right_bitmap_ + 8), right_offset_);
|
| 328 |
+
popcount = bit_util::PopCount(Op::Call(left_word, right_word));
|
| 329 |
+
}
|
| 330 |
+
left_bitmap_ += kWordBits / 8;
|
| 331 |
+
right_bitmap_ += kWordBits / 8;
|
| 332 |
+
bits_remaining_ -= kWordBits;
|
| 333 |
+
return {64, static_cast<int16_t>(popcount)};
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
const uint8_t* left_bitmap_;
|
| 337 |
+
int64_t left_offset_;
|
| 338 |
+
const uint8_t* right_bitmap_;
|
| 339 |
+
int64_t right_offset_;
|
| 340 |
+
int64_t bits_remaining_;
|
| 341 |
+
};
|
| 342 |
+
|
| 343 |
+
class ARROW_EXPORT OptionalBinaryBitBlockCounter {
|
| 344 |
+
public:
|
| 345 |
+
// Any bitmap may be NULLPTR
|
| 346 |
+
OptionalBinaryBitBlockCounter(const uint8_t* left_bitmap, int64_t left_offset,
|
| 347 |
+
const uint8_t* right_bitmap, int64_t right_offset,
|
| 348 |
+
int64_t length);
|
| 349 |
+
|
| 350 |
+
// Any bitmap may be null
|
| 351 |
+
OptionalBinaryBitBlockCounter(const std::shared_ptr<Buffer>& left_bitmap,
|
| 352 |
+
int64_t left_offset,
|
| 353 |
+
const std::shared_ptr<Buffer>& right_bitmap,
|
| 354 |
+
int64_t right_offset, int64_t length);
|
| 355 |
+
|
| 356 |
+
BitBlockCount NextAndBlock() {
|
| 357 |
+
static constexpr int64_t kMaxBlockSize = std::numeric_limits<int16_t>::max();
|
| 358 |
+
switch (has_bitmap_) {
|
| 359 |
+
case HasBitmap::BOTH: {
|
| 360 |
+
BitBlockCount block = binary_counter_.NextAndWord();
|
| 361 |
+
position_ += block.length;
|
| 362 |
+
return block;
|
| 363 |
+
}
|
| 364 |
+
case HasBitmap::ONE: {
|
| 365 |
+
BitBlockCount block = unary_counter_.NextWord();
|
| 366 |
+
position_ += block.length;
|
| 367 |
+
return block;
|
| 368 |
+
}
|
| 369 |
+
case HasBitmap::NONE:
|
| 370 |
+
default: {
|
| 371 |
+
const int16_t block_size =
|
| 372 |
+
static_cast<int16_t>(std::min(kMaxBlockSize, length_ - position_));
|
| 373 |
+
position_ += block_size;
|
| 374 |
+
// All values are non-null
|
| 375 |
+
return {block_size, block_size};
|
| 376 |
+
}
|
| 377 |
+
}
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
BitBlockCount NextOrNotBlock() {
|
| 381 |
+
static constexpr int64_t kMaxBlockSize = std::numeric_limits<int16_t>::max();
|
| 382 |
+
switch (has_bitmap_) {
|
| 383 |
+
case HasBitmap::BOTH: {
|
| 384 |
+
BitBlockCount block = binary_counter_.NextOrNotWord();
|
| 385 |
+
position_ += block.length;
|
| 386 |
+
return block;
|
| 387 |
+
}
|
| 388 |
+
case HasBitmap::ONE: {
|
| 389 |
+
BitBlockCount block = unary_counter_.NextWord();
|
| 390 |
+
position_ += block.length;
|
| 391 |
+
return block;
|
| 392 |
+
}
|
| 393 |
+
case HasBitmap::NONE:
|
| 394 |
+
default: {
|
| 395 |
+
const int16_t block_size =
|
| 396 |
+
static_cast<int16_t>(std::min(kMaxBlockSize, length_ - position_));
|
| 397 |
+
position_ += block_size;
|
| 398 |
+
// All values are non-null
|
| 399 |
+
return {block_size, block_size};
|
| 400 |
+
}
|
| 401 |
+
}
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
private:
|
| 405 |
+
enum class HasBitmap : int { BOTH, ONE, NONE };
|
| 406 |
+
|
| 407 |
+
const HasBitmap has_bitmap_;
|
| 408 |
+
int64_t position_;
|
| 409 |
+
int64_t length_;
|
| 410 |
+
BitBlockCounter unary_counter_;
|
| 411 |
+
BinaryBitBlockCounter binary_counter_;
|
| 412 |
+
|
| 413 |
+
static HasBitmap HasBitmapFromBitmaps(bool has_left, bool has_right) {
|
| 414 |
+
switch (static_cast<int>(has_left) + static_cast<int>(has_right)) {
|
| 415 |
+
case 0:
|
| 416 |
+
return HasBitmap::NONE;
|
| 417 |
+
case 1:
|
| 418 |
+
return HasBitmap::ONE;
|
| 419 |
+
default: // 2
|
| 420 |
+
return HasBitmap::BOTH;
|
| 421 |
+
}
|
| 422 |
+
}
|
| 423 |
+
};
|
| 424 |
+
|
| 425 |
+
// Functional-style bit block visitors.
|
| 426 |
+
|
| 427 |
+
template <typename VisitNotNull, typename VisitNull>
|
| 428 |
+
static Status VisitBitBlocks(const uint8_t* bitmap, int64_t offset, int64_t length,
|
| 429 |
+
VisitNotNull&& visit_not_null, VisitNull&& visit_null) {
|
| 430 |
+
internal::OptionalBitBlockCounter bit_counter(bitmap, offset, length);
|
| 431 |
+
int64_t position = 0;
|
| 432 |
+
while (position < length) {
|
| 433 |
+
internal::BitBlockCount block = bit_counter.NextBlock();
|
| 434 |
+
if (block.AllSet()) {
|
| 435 |
+
for (int64_t i = 0; i < block.length; ++i, ++position) {
|
| 436 |
+
ARROW_RETURN_NOT_OK(visit_not_null(position));
|
| 437 |
+
}
|
| 438 |
+
} else if (block.NoneSet()) {
|
| 439 |
+
for (int64_t i = 0; i < block.length; ++i, ++position) {
|
| 440 |
+
ARROW_RETURN_NOT_OK(visit_null());
|
| 441 |
+
}
|
| 442 |
+
} else {
|
| 443 |
+
for (int64_t i = 0; i < block.length; ++i, ++position) {
|
| 444 |
+
if (bit_util::GetBit(bitmap, offset + position)) {
|
| 445 |
+
ARROW_RETURN_NOT_OK(visit_not_null(position));
|
| 446 |
+
} else {
|
| 447 |
+
ARROW_RETURN_NOT_OK(visit_null());
|
| 448 |
+
}
|
| 449 |
+
}
|
| 450 |
+
}
|
| 451 |
+
}
|
| 452 |
+
return Status::OK();
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
template <typename VisitNotNull, typename VisitNull>
|
| 456 |
+
static void VisitBitBlocksVoid(const uint8_t* bitmap, int64_t offset, int64_t length,
|
| 457 |
+
VisitNotNull&& visit_not_null, VisitNull&& visit_null) {
|
| 458 |
+
internal::OptionalBitBlockCounter bit_counter(bitmap, offset, length);
|
| 459 |
+
int64_t position = 0;
|
| 460 |
+
while (position < length) {
|
| 461 |
+
internal::BitBlockCount block = bit_counter.NextBlock();
|
| 462 |
+
if (block.AllSet()) {
|
| 463 |
+
for (int64_t i = 0; i < block.length; ++i, ++position) {
|
| 464 |
+
visit_not_null(position);
|
| 465 |
+
}
|
| 466 |
+
} else if (block.NoneSet()) {
|
| 467 |
+
for (int64_t i = 0; i < block.length; ++i, ++position) {
|
| 468 |
+
visit_null();
|
| 469 |
+
}
|
| 470 |
+
} else {
|
| 471 |
+
for (int64_t i = 0; i < block.length; ++i, ++position) {
|
| 472 |
+
if (bit_util::GetBit(bitmap, offset + position)) {
|
| 473 |
+
visit_not_null(position);
|
| 474 |
+
} else {
|
| 475 |
+
visit_null();
|
| 476 |
+
}
|
| 477 |
+
}
|
| 478 |
+
}
|
| 479 |
+
}
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
template <typename VisitNotNull, typename VisitNull>
|
| 483 |
+
static Status VisitTwoBitBlocks(const uint8_t* left_bitmap, int64_t left_offset,
|
| 484 |
+
const uint8_t* right_bitmap, int64_t right_offset,
|
| 485 |
+
int64_t length, VisitNotNull&& visit_not_null,
|
| 486 |
+
VisitNull&& visit_null) {
|
| 487 |
+
if (left_bitmap == NULLPTR || right_bitmap == NULLPTR) {
|
| 488 |
+
// At most one bitmap is present
|
| 489 |
+
if (left_bitmap == NULLPTR) {
|
| 490 |
+
return VisitBitBlocks(right_bitmap, right_offset, length,
|
| 491 |
+
std::forward<VisitNotNull>(visit_not_null),
|
| 492 |
+
std::forward<VisitNull>(visit_null));
|
| 493 |
+
} else {
|
| 494 |
+
return VisitBitBlocks(left_bitmap, left_offset, length,
|
| 495 |
+
std::forward<VisitNotNull>(visit_not_null),
|
| 496 |
+
std::forward<VisitNull>(visit_null));
|
| 497 |
+
}
|
| 498 |
+
}
|
| 499 |
+
BinaryBitBlockCounter bit_counter(left_bitmap, left_offset, right_bitmap, right_offset,
|
| 500 |
+
length);
|
| 501 |
+
int64_t position = 0;
|
| 502 |
+
while (position < length) {
|
| 503 |
+
BitBlockCount block = bit_counter.NextAndWord();
|
| 504 |
+
if (block.AllSet()) {
|
| 505 |
+
for (int64_t i = 0; i < block.length; ++i, ++position) {
|
| 506 |
+
ARROW_RETURN_NOT_OK(visit_not_null(position));
|
| 507 |
+
}
|
| 508 |
+
} else if (block.NoneSet()) {
|
| 509 |
+
for (int64_t i = 0; i < block.length; ++i, ++position) {
|
| 510 |
+
ARROW_RETURN_NOT_OK(visit_null());
|
| 511 |
+
}
|
| 512 |
+
} else {
|
| 513 |
+
for (int64_t i = 0; i < block.length; ++i, ++position) {
|
| 514 |
+
if (bit_util::GetBit(left_bitmap, left_offset + position) &&
|
| 515 |
+
bit_util::GetBit(right_bitmap, right_offset + position)) {
|
| 516 |
+
ARROW_RETURN_NOT_OK(visit_not_null(position));
|
| 517 |
+
} else {
|
| 518 |
+
ARROW_RETURN_NOT_OK(visit_null());
|
| 519 |
+
}
|
| 520 |
+
}
|
| 521 |
+
}
|
| 522 |
+
}
|
| 523 |
+
return Status::OK();
|
| 524 |
+
}
|
| 525 |
+
|
| 526 |
+
template <typename VisitNotNull, typename VisitNull>
|
| 527 |
+
static void VisitTwoBitBlocksVoid(const uint8_t* left_bitmap, int64_t left_offset,
|
| 528 |
+
const uint8_t* right_bitmap, int64_t right_offset,
|
| 529 |
+
int64_t length, VisitNotNull&& visit_not_null,
|
| 530 |
+
VisitNull&& visit_null) {
|
| 531 |
+
if (left_bitmap == NULLPTR || right_bitmap == NULLPTR) {
|
| 532 |
+
// At most one bitmap is present
|
| 533 |
+
if (left_bitmap == NULLPTR) {
|
| 534 |
+
return VisitBitBlocksVoid(right_bitmap, right_offset, length,
|
| 535 |
+
std::forward<VisitNotNull>(visit_not_null),
|
| 536 |
+
std::forward<VisitNull>(visit_null));
|
| 537 |
+
} else {
|
| 538 |
+
return VisitBitBlocksVoid(left_bitmap, left_offset, length,
|
| 539 |
+
std::forward<VisitNotNull>(visit_not_null),
|
| 540 |
+
std::forward<VisitNull>(visit_null));
|
| 541 |
+
}
|
| 542 |
+
}
|
| 543 |
+
BinaryBitBlockCounter bit_counter(left_bitmap, left_offset, right_bitmap, right_offset,
|
| 544 |
+
length);
|
| 545 |
+
int64_t position = 0;
|
| 546 |
+
while (position < length) {
|
| 547 |
+
BitBlockCount block = bit_counter.NextAndWord();
|
| 548 |
+
if (block.AllSet()) {
|
| 549 |
+
for (int64_t i = 0; i < block.length; ++i, ++position) {
|
| 550 |
+
visit_not_null(position);
|
| 551 |
+
}
|
| 552 |
+
} else if (block.NoneSet()) {
|
| 553 |
+
for (int64_t i = 0; i < block.length; ++i, ++position) {
|
| 554 |
+
visit_null();
|
| 555 |
+
}
|
| 556 |
+
} else {
|
| 557 |
+
for (int64_t i = 0; i < block.length; ++i, ++position) {
|
| 558 |
+
if (bit_util::GetBit(left_bitmap, left_offset + position) &&
|
| 559 |
+
bit_util::GetBit(right_bitmap, right_offset + position)) {
|
| 560 |
+
visit_not_null(position);
|
| 561 |
+
} else {
|
| 562 |
+
visit_null();
|
| 563 |
+
}
|
| 564 |
+
}
|
| 565 |
+
}
|
| 566 |
+
}
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
} // namespace internal
|
| 570 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/bitmap_ops.h
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <cstdint>
|
| 21 |
+
#include <memory>
|
| 22 |
+
|
| 23 |
+
#include "arrow/result.h"
|
| 24 |
+
#include "arrow/util/visibility.h"
|
| 25 |
+
|
| 26 |
+
namespace arrow {
|
| 27 |
+
|
| 28 |
+
class Buffer;
|
| 29 |
+
class MemoryPool;
|
| 30 |
+
|
| 31 |
+
namespace internal {
|
| 32 |
+
|
| 33 |
+
// ----------------------------------------------------------------------
|
| 34 |
+
// Bitmap utilities
|
| 35 |
+
|
| 36 |
+
/// Copy a bit range of an existing bitmap
|
| 37 |
+
///
|
| 38 |
+
/// \param[in] pool memory pool to allocate memory from
|
| 39 |
+
/// \param[in] bitmap source data
|
| 40 |
+
/// \param[in] offset bit offset into the source data
|
| 41 |
+
/// \param[in] length number of bits to copy
|
| 42 |
+
///
|
| 43 |
+
/// \return Status message
|
| 44 |
+
ARROW_EXPORT
|
| 45 |
+
Result<std::shared_ptr<Buffer>> CopyBitmap(MemoryPool* pool, const uint8_t* bitmap,
|
| 46 |
+
int64_t offset, int64_t length);
|
| 47 |
+
|
| 48 |
+
/// Copy a bit range of an existing bitmap into an existing bitmap
|
| 49 |
+
///
|
| 50 |
+
/// \param[in] bitmap source data
|
| 51 |
+
/// \param[in] offset bit offset into the source data
|
| 52 |
+
/// \param[in] length number of bits to copy
|
| 53 |
+
/// \param[in] dest_offset bit offset into the destination
|
| 54 |
+
/// \param[out] dest the destination buffer, must have at least space for
|
| 55 |
+
/// (offset + length) bits
|
| 56 |
+
ARROW_EXPORT
|
| 57 |
+
void CopyBitmap(const uint8_t* bitmap, int64_t offset, int64_t length, uint8_t* dest,
|
| 58 |
+
int64_t dest_offset);
|
| 59 |
+
|
| 60 |
+
/// Invert a bit range of an existing bitmap into an existing bitmap
|
| 61 |
+
///
|
| 62 |
+
/// \param[in] bitmap source data
|
| 63 |
+
/// \param[in] offset bit offset into the source data
|
| 64 |
+
/// \param[in] length number of bits to copy
|
| 65 |
+
/// \param[in] dest_offset bit offset into the destination
|
| 66 |
+
/// \param[out] dest the destination buffer, must have at least space for
|
| 67 |
+
/// (offset + length) bits
|
| 68 |
+
ARROW_EXPORT
|
| 69 |
+
void InvertBitmap(const uint8_t* bitmap, int64_t offset, int64_t length, uint8_t* dest,
|
| 70 |
+
int64_t dest_offset);
|
| 71 |
+
|
| 72 |
+
/// Invert a bit range of an existing bitmap
|
| 73 |
+
///
|
| 74 |
+
/// \param[in] pool memory pool to allocate memory from
|
| 75 |
+
/// \param[in] bitmap source data
|
| 76 |
+
/// \param[in] offset bit offset into the source data
|
| 77 |
+
/// \param[in] length number of bits to copy
|
| 78 |
+
///
|
| 79 |
+
/// \return Status message
|
| 80 |
+
ARROW_EXPORT
|
| 81 |
+
Result<std::shared_ptr<Buffer>> InvertBitmap(MemoryPool* pool, const uint8_t* bitmap,
|
| 82 |
+
int64_t offset, int64_t length);
|
| 83 |
+
|
| 84 |
+
/// Reverse a bit range of an existing bitmap into an existing bitmap
|
| 85 |
+
///
|
| 86 |
+
/// \param[in] bitmap source data
|
| 87 |
+
/// \param[in] offset bit offset into the source data
|
| 88 |
+
/// \param[in] length number of bits to reverse
|
| 89 |
+
/// \param[in] dest_offset bit offset into the destination
|
| 90 |
+
/// \param[out] dest the destination buffer, must have at least space for
|
| 91 |
+
/// (offset + length) bits
|
| 92 |
+
ARROW_EXPORT
|
| 93 |
+
void ReverseBitmap(const uint8_t* bitmap, int64_t offset, int64_t length, uint8_t* dest,
|
| 94 |
+
int64_t dest_offset);
|
| 95 |
+
|
| 96 |
+
/// Reverse a bit range of an existing bitmap
|
| 97 |
+
///
|
| 98 |
+
/// \param[in] pool memory pool to allocate memory from
|
| 99 |
+
/// \param[in] bitmap source data
|
| 100 |
+
/// \param[in] offset bit offset into the source data
|
| 101 |
+
/// \param[in] length number of bits to reverse
|
| 102 |
+
///
|
| 103 |
+
/// \return Status message
|
| 104 |
+
ARROW_EXPORT
|
| 105 |
+
Result<std::shared_ptr<Buffer>> ReverseBitmap(MemoryPool* pool, const uint8_t* bitmap,
|
| 106 |
+
int64_t offset, int64_t length);
|
| 107 |
+
|
| 108 |
+
/// Compute the number of 1's in the given data array
|
| 109 |
+
///
|
| 110 |
+
/// \param[in] data a packed LSB-ordered bitmap as a byte array
|
| 111 |
+
/// \param[in] bit_offset a bitwise offset into the bitmap
|
| 112 |
+
/// \param[in] length the number of bits to inspect in the bitmap relative to
|
| 113 |
+
/// the offset
|
| 114 |
+
///
|
| 115 |
+
/// \return The number of set (1) bits in the range
|
| 116 |
+
ARROW_EXPORT
|
| 117 |
+
int64_t CountSetBits(const uint8_t* data, int64_t bit_offset, int64_t length);
|
| 118 |
+
|
| 119 |
+
/// Compute the number of 1's in the result of an "and" (&) of two bitmaps
|
| 120 |
+
///
|
| 121 |
+
/// \param[in] left_bitmap a packed LSB-ordered bitmap as a byte array
|
| 122 |
+
/// \param[in] left_offset a bitwise offset into the left bitmap
|
| 123 |
+
/// \param[in] right_bitmap a packed LSB-ordered bitmap as a byte array
|
| 124 |
+
/// \param[in] right_offset a bitwise offset into the right bitmap
|
| 125 |
+
/// \param[in] length the length of the bitmaps (must be the same)
|
| 126 |
+
///
|
| 127 |
+
/// \return The number of set (1) bits in the "and" of the two bitmaps
|
| 128 |
+
ARROW_EXPORT
|
| 129 |
+
int64_t CountAndSetBits(const uint8_t* left_bitmap, int64_t left_offset,
|
| 130 |
+
const uint8_t* right_bitmap, int64_t right_offset,
|
| 131 |
+
int64_t length);
|
| 132 |
+
|
| 133 |
+
ARROW_EXPORT
|
| 134 |
+
bool BitmapEquals(const uint8_t* left, int64_t left_offset, const uint8_t* right,
|
| 135 |
+
int64_t right_offset, int64_t length);
|
| 136 |
+
|
| 137 |
+
// Same as BitmapEquals, but considers a NULL bitmap pointer the same as an
|
| 138 |
+
// all-ones bitmap.
|
| 139 |
+
ARROW_EXPORT
|
| 140 |
+
bool OptionalBitmapEquals(const uint8_t* left, int64_t left_offset, const uint8_t* right,
|
| 141 |
+
int64_t right_offset, int64_t length);
|
| 142 |
+
|
| 143 |
+
ARROW_EXPORT
|
| 144 |
+
bool OptionalBitmapEquals(const std::shared_ptr<Buffer>& left, int64_t left_offset,
|
| 145 |
+
const std::shared_ptr<Buffer>& right, int64_t right_offset,
|
| 146 |
+
int64_t length);
|
| 147 |
+
|
| 148 |
+
/// \brief Do a "bitmap and" on right and left buffers starting at
|
| 149 |
+
/// their respective bit-offsets for the given bit-length and put
|
| 150 |
+
/// the results in out_buffer starting at the given bit-offset.
|
| 151 |
+
///
|
| 152 |
+
/// out_buffer will be allocated and initialized to zeros using pool before
|
| 153 |
+
/// the operation.
|
| 154 |
+
ARROW_EXPORT
|
| 155 |
+
Result<std::shared_ptr<Buffer>> BitmapAnd(MemoryPool* pool, const uint8_t* left,
|
| 156 |
+
int64_t left_offset, const uint8_t* right,
|
| 157 |
+
int64_t right_offset, int64_t length,
|
| 158 |
+
int64_t out_offset);
|
| 159 |
+
|
| 160 |
+
/// \brief Do a "bitmap and" on right and left buffers starting at
|
| 161 |
+
/// their respective bit-offsets for the given bit-length and put
|
| 162 |
+
/// the results in out starting at the given bit-offset.
|
| 163 |
+
ARROW_EXPORT
|
| 164 |
+
void BitmapAnd(const uint8_t* left, int64_t left_offset, const uint8_t* right,
|
| 165 |
+
int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out);
|
| 166 |
+
|
| 167 |
+
/// \brief Do a "bitmap or" for the given bit length on right and left buffers
|
| 168 |
+
/// starting at their respective bit-offsets and put the results in out_buffer
|
| 169 |
+
/// starting at the given bit-offset.
|
| 170 |
+
///
|
| 171 |
+
/// out_buffer will be allocated and initialized to zeros using pool before
|
| 172 |
+
/// the operation.
|
| 173 |
+
ARROW_EXPORT
|
| 174 |
+
Result<std::shared_ptr<Buffer>> BitmapOr(MemoryPool* pool, const uint8_t* left,
|
| 175 |
+
int64_t left_offset, const uint8_t* right,
|
| 176 |
+
int64_t right_offset, int64_t length,
|
| 177 |
+
int64_t out_offset);
|
| 178 |
+
|
| 179 |
+
/// \brief Do a "bitmap or" for the given bit length on right and left buffers
|
| 180 |
+
/// starting at their respective bit-offsets and put the results in out
|
| 181 |
+
/// starting at the given bit-offset.
|
| 182 |
+
ARROW_EXPORT
|
| 183 |
+
void BitmapOr(const uint8_t* left, int64_t left_offset, const uint8_t* right,
|
| 184 |
+
int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out);
|
| 185 |
+
|
| 186 |
+
/// \brief Do a "bitmap xor" for the given bit-length on right and left
|
| 187 |
+
/// buffers starting at their respective bit-offsets and put the results in
|
| 188 |
+
/// out_buffer starting at the given bit offset.
|
| 189 |
+
///
|
| 190 |
+
/// out_buffer will be allocated and initialized to zeros using pool before
|
| 191 |
+
/// the operation.
|
| 192 |
+
ARROW_EXPORT
|
| 193 |
+
Result<std::shared_ptr<Buffer>> BitmapXor(MemoryPool* pool, const uint8_t* left,
|
| 194 |
+
int64_t left_offset, const uint8_t* right,
|
| 195 |
+
int64_t right_offset, int64_t length,
|
| 196 |
+
int64_t out_offset);
|
| 197 |
+
|
| 198 |
+
/// \brief Do a "bitmap xor" for the given bit-length on right and left
|
| 199 |
+
/// buffers starting at their respective bit-offsets and put the results in
|
| 200 |
+
/// out starting at the given bit offset.
|
| 201 |
+
ARROW_EXPORT
|
| 202 |
+
void BitmapXor(const uint8_t* left, int64_t left_offset, const uint8_t* right,
|
| 203 |
+
int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out);
|
| 204 |
+
|
| 205 |
+
/// \brief Do a "bitmap and not" on right and left buffers starting at
|
| 206 |
+
/// their respective bit-offsets for the given bit-length and put
|
| 207 |
+
/// the results in out_buffer starting at the given bit-offset.
|
| 208 |
+
///
|
| 209 |
+
/// out_buffer will be allocated and initialized to zeros using pool before
|
| 210 |
+
/// the operation.
|
| 211 |
+
ARROW_EXPORT
|
| 212 |
+
Result<std::shared_ptr<Buffer>> BitmapAndNot(MemoryPool* pool, const uint8_t* left,
|
| 213 |
+
int64_t left_offset, const uint8_t* right,
|
| 214 |
+
int64_t right_offset, int64_t length,
|
| 215 |
+
int64_t out_offset);
|
| 216 |
+
|
| 217 |
+
/// \brief Do a "bitmap and not" on right and left buffers starting at
|
| 218 |
+
/// their respective bit-offsets for the given bit-length and put
|
| 219 |
+
/// the results in out starting at the given bit-offset.
|
| 220 |
+
ARROW_EXPORT
|
| 221 |
+
void BitmapAndNot(const uint8_t* left, int64_t left_offset, const uint8_t* right,
|
| 222 |
+
int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out);
|
| 223 |
+
|
| 224 |
+
/// \brief Do a "bitmap or not" on right and left buffers starting at
|
| 225 |
+
/// their respective bit-offsets for the given bit-length and put
|
| 226 |
+
/// the results in out_buffer starting at the given bit-offset.
|
| 227 |
+
///
|
| 228 |
+
/// out_buffer will be allocated and initialized to zeros using pool before
|
| 229 |
+
/// the operation.
|
| 230 |
+
ARROW_EXPORT
|
| 231 |
+
Result<std::shared_ptr<Buffer>> BitmapOrNot(MemoryPool* pool, const uint8_t* left,
|
| 232 |
+
int64_t left_offset, const uint8_t* right,
|
| 233 |
+
int64_t right_offset, int64_t length,
|
| 234 |
+
int64_t out_offset);
|
| 235 |
+
|
| 236 |
+
/// \brief Do a "bitmap or not" on right and left buffers starting at
|
| 237 |
+
/// their respective bit-offsets for the given bit-length and put
|
| 238 |
+
/// the results in out starting at the given bit-offset.
|
| 239 |
+
ARROW_EXPORT
|
| 240 |
+
void BitmapOrNot(const uint8_t* left, int64_t left_offset, const uint8_t* right,
|
| 241 |
+
int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out);
|
| 242 |
+
|
| 243 |
+
} // namespace internal
|
| 244 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/bitmap_reader.h
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <cassert>
|
| 21 |
+
#include <cstdint>
|
| 22 |
+
#include <cstring>
|
| 23 |
+
|
| 24 |
+
#include "arrow/buffer.h"
|
| 25 |
+
#include "arrow/util/bit_util.h"
|
| 26 |
+
#include "arrow/util/endian.h"
|
| 27 |
+
#include "arrow/util/macros.h"
|
| 28 |
+
|
| 29 |
+
namespace arrow {
|
| 30 |
+
namespace internal {
|
| 31 |
+
|
| 32 |
+
class BitmapReader {
|
| 33 |
+
public:
|
| 34 |
+
BitmapReader(const uint8_t* bitmap, int64_t start_offset, int64_t length)
|
| 35 |
+
: bitmap_(bitmap), position_(0), length_(length) {
|
| 36 |
+
current_byte_ = 0;
|
| 37 |
+
byte_offset_ = start_offset / 8;
|
| 38 |
+
bit_offset_ = start_offset % 8;
|
| 39 |
+
if (length > 0) {
|
| 40 |
+
current_byte_ = bitmap[byte_offset_];
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
bool IsSet() const { return (current_byte_ & (1 << bit_offset_)) != 0; }
|
| 45 |
+
|
| 46 |
+
bool IsNotSet() const { return (current_byte_ & (1 << bit_offset_)) == 0; }
|
| 47 |
+
|
| 48 |
+
void Next() {
|
| 49 |
+
++bit_offset_;
|
| 50 |
+
++position_;
|
| 51 |
+
if (ARROW_PREDICT_FALSE(bit_offset_ == 8)) {
|
| 52 |
+
bit_offset_ = 0;
|
| 53 |
+
++byte_offset_;
|
| 54 |
+
if (ARROW_PREDICT_TRUE(position_ < length_)) {
|
| 55 |
+
current_byte_ = bitmap_[byte_offset_];
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
int64_t position() const { return position_; }
|
| 61 |
+
|
| 62 |
+
int64_t length() const { return length_; }
|
| 63 |
+
|
| 64 |
+
private:
|
| 65 |
+
const uint8_t* bitmap_;
|
| 66 |
+
int64_t position_;
|
| 67 |
+
int64_t length_;
|
| 68 |
+
|
| 69 |
+
uint8_t current_byte_;
|
| 70 |
+
int64_t byte_offset_;
|
| 71 |
+
int64_t bit_offset_;
|
| 72 |
+
};
|
| 73 |
+
|
| 74 |
+
// XXX Cannot name it BitmapWordReader because the name is already used
|
| 75 |
+
// in bitmap_ops.cc
|
| 76 |
+
|
| 77 |
+
class BitmapUInt64Reader {
|
| 78 |
+
public:
|
| 79 |
+
BitmapUInt64Reader(const uint8_t* bitmap, int64_t start_offset, int64_t length)
|
| 80 |
+
: bitmap_(util::MakeNonNull(bitmap) + start_offset / 8),
|
| 81 |
+
num_carry_bits_(8 - start_offset % 8),
|
| 82 |
+
length_(length),
|
| 83 |
+
remaining_length_(length_),
|
| 84 |
+
carry_bits_(0) {
|
| 85 |
+
if (length_ > 0) {
|
| 86 |
+
// Load carry bits from the first byte's MSBs
|
| 87 |
+
if (length_ >= num_carry_bits_) {
|
| 88 |
+
carry_bits_ =
|
| 89 |
+
LoadPartialWord(static_cast<int8_t>(8 - num_carry_bits_), num_carry_bits_);
|
| 90 |
+
} else {
|
| 91 |
+
carry_bits_ = LoadPartialWord(static_cast<int8_t>(8 - num_carry_bits_), length_);
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
uint64_t NextWord() {
|
| 97 |
+
if (ARROW_PREDICT_TRUE(remaining_length_ >= 64 + num_carry_bits_)) {
|
| 98 |
+
// We can load a full word
|
| 99 |
+
uint64_t next_word = LoadFullWord();
|
| 100 |
+
// Carry bits come first, then the (64 - num_carry_bits_) LSBs from next_word
|
| 101 |
+
uint64_t word = carry_bits_ | (next_word << num_carry_bits_);
|
| 102 |
+
carry_bits_ = next_word >> (64 - num_carry_bits_);
|
| 103 |
+
remaining_length_ -= 64;
|
| 104 |
+
return word;
|
| 105 |
+
} else if (remaining_length_ > num_carry_bits_) {
|
| 106 |
+
// We can load a partial word
|
| 107 |
+
uint64_t next_word =
|
| 108 |
+
LoadPartialWord(/*bit_offset=*/0, remaining_length_ - num_carry_bits_);
|
| 109 |
+
uint64_t word = carry_bits_ | (next_word << num_carry_bits_);
|
| 110 |
+
carry_bits_ = next_word >> (64 - num_carry_bits_);
|
| 111 |
+
remaining_length_ = std::max<int64_t>(remaining_length_ - 64, 0);
|
| 112 |
+
return word;
|
| 113 |
+
} else {
|
| 114 |
+
remaining_length_ = 0;
|
| 115 |
+
return carry_bits_;
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
int64_t position() const { return length_ - remaining_length_; }
|
| 120 |
+
|
| 121 |
+
int64_t length() const { return length_; }
|
| 122 |
+
|
| 123 |
+
private:
|
| 124 |
+
uint64_t LoadFullWord() {
|
| 125 |
+
uint64_t word;
|
| 126 |
+
memcpy(&word, bitmap_, 8);
|
| 127 |
+
bitmap_ += 8;
|
| 128 |
+
return bit_util::ToLittleEndian(word);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
uint64_t LoadPartialWord(int8_t bit_offset, int64_t num_bits) {
|
| 132 |
+
uint64_t word = 0;
|
| 133 |
+
const int64_t num_bytes = bit_util::BytesForBits(num_bits);
|
| 134 |
+
memcpy(&word, bitmap_, num_bytes);
|
| 135 |
+
bitmap_ += num_bytes;
|
| 136 |
+
return (bit_util::ToLittleEndian(word) >> bit_offset) &
|
| 137 |
+
bit_util::LeastSignificantBitMask(num_bits);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
const uint8_t* bitmap_;
|
| 141 |
+
const int64_t num_carry_bits_; // in [1, 8]
|
| 142 |
+
const int64_t length_;
|
| 143 |
+
int64_t remaining_length_;
|
| 144 |
+
uint64_t carry_bits_;
|
| 145 |
+
};
|
| 146 |
+
|
| 147 |
+
// BitmapWordReader here is faster than BitmapUInt64Reader (in bitmap_reader.h)
|
| 148 |
+
// on sufficiently large inputs. However, it has a larger prolog / epilog overhead
|
| 149 |
+
// and should probably not be used for small bitmaps.
|
| 150 |
+
|
| 151 |
+
template <typename Word, bool may_have_byte_offset = true>
|
| 152 |
+
class BitmapWordReader {
|
| 153 |
+
public:
|
| 154 |
+
BitmapWordReader() = default;
|
| 155 |
+
BitmapWordReader(const uint8_t* bitmap, int64_t offset, int64_t length)
|
| 156 |
+
: offset_(static_cast<int64_t>(may_have_byte_offset) * (offset % 8)),
|
| 157 |
+
bitmap_(bitmap + offset / 8),
|
| 158 |
+
bitmap_end_(bitmap_ + bit_util::BytesForBits(offset_ + length)) {
|
| 159 |
+
// decrement word count by one as we may touch two adjacent words in one iteration
|
| 160 |
+
nwords_ = length / (sizeof(Word) * 8) - 1;
|
| 161 |
+
if (nwords_ < 0) {
|
| 162 |
+
nwords_ = 0;
|
| 163 |
+
}
|
| 164 |
+
trailing_bits_ = static_cast<int>(length - nwords_ * sizeof(Word) * 8);
|
| 165 |
+
trailing_bytes_ = static_cast<int>(bit_util::BytesForBits(trailing_bits_));
|
| 166 |
+
|
| 167 |
+
if (nwords_ > 0) {
|
| 168 |
+
current_data.word_ = load<Word>(bitmap_);
|
| 169 |
+
} else if (length > 0) {
|
| 170 |
+
current_data.epi.byte_ = load<uint8_t>(bitmap_);
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
Word NextWord() {
|
| 175 |
+
bitmap_ += sizeof(Word);
|
| 176 |
+
const Word next_word = load<Word>(bitmap_);
|
| 177 |
+
Word word = current_data.word_;
|
| 178 |
+
if (may_have_byte_offset && offset_) {
|
| 179 |
+
// combine two adjacent words into one word
|
| 180 |
+
// |<------ next ----->|<---- current ---->|
|
| 181 |
+
// +-------------+-----+-------------+-----+
|
| 182 |
+
// | --- | A | B | --- |
|
| 183 |
+
// +-------------+-----+-------------+-----+
|
| 184 |
+
// | | offset
|
| 185 |
+
// v v
|
| 186 |
+
// +-----+-------------+
|
| 187 |
+
// | A | B |
|
| 188 |
+
// +-----+-------------+
|
| 189 |
+
// |<------ word ----->|
|
| 190 |
+
word >>= offset_;
|
| 191 |
+
word |= next_word << (sizeof(Word) * 8 - offset_);
|
| 192 |
+
}
|
| 193 |
+
current_data.word_ = next_word;
|
| 194 |
+
return word;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
uint8_t NextTrailingByte(int& valid_bits) {
|
| 198 |
+
uint8_t byte;
|
| 199 |
+
assert(trailing_bits_ > 0);
|
| 200 |
+
|
| 201 |
+
if (trailing_bits_ <= 8) {
|
| 202 |
+
// last byte
|
| 203 |
+
valid_bits = trailing_bits_;
|
| 204 |
+
trailing_bits_ = 0;
|
| 205 |
+
byte = 0;
|
| 206 |
+
internal::BitmapReader reader(bitmap_, offset_, valid_bits);
|
| 207 |
+
for (int i = 0; i < valid_bits; ++i) {
|
| 208 |
+
byte >>= 1;
|
| 209 |
+
if (reader.IsSet()) {
|
| 210 |
+
byte |= 0x80;
|
| 211 |
+
}
|
| 212 |
+
reader.Next();
|
| 213 |
+
}
|
| 214 |
+
byte >>= (8 - valid_bits);
|
| 215 |
+
} else {
|
| 216 |
+
++bitmap_;
|
| 217 |
+
const uint8_t next_byte = load<uint8_t>(bitmap_);
|
| 218 |
+
byte = current_data.epi.byte_;
|
| 219 |
+
if (may_have_byte_offset && offset_) {
|
| 220 |
+
byte >>= offset_;
|
| 221 |
+
byte |= next_byte << (8 - offset_);
|
| 222 |
+
}
|
| 223 |
+
current_data.epi.byte_ = next_byte;
|
| 224 |
+
trailing_bits_ -= 8;
|
| 225 |
+
trailing_bytes_--;
|
| 226 |
+
valid_bits = 8;
|
| 227 |
+
}
|
| 228 |
+
return byte;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
int64_t words() const { return nwords_; }
|
| 232 |
+
int trailing_bytes() const { return trailing_bytes_; }
|
| 233 |
+
|
| 234 |
+
private:
|
| 235 |
+
int64_t offset_;
|
| 236 |
+
const uint8_t* bitmap_;
|
| 237 |
+
|
| 238 |
+
const uint8_t* bitmap_end_;
|
| 239 |
+
int64_t nwords_;
|
| 240 |
+
int trailing_bits_;
|
| 241 |
+
int trailing_bytes_;
|
| 242 |
+
union {
|
| 243 |
+
Word word_;
|
| 244 |
+
struct {
|
| 245 |
+
#if ARROW_LITTLE_ENDIAN == 0
|
| 246 |
+
uint8_t padding_bytes_[sizeof(Word) - 1];
|
| 247 |
+
#endif
|
| 248 |
+
uint8_t byte_;
|
| 249 |
+
} epi;
|
| 250 |
+
} current_data;
|
| 251 |
+
|
| 252 |
+
template <typename DType>
|
| 253 |
+
DType load(const uint8_t* bitmap) {
|
| 254 |
+
assert(bitmap + sizeof(DType) <= bitmap_end_);
|
| 255 |
+
return bit_util::ToLittleEndian(util::SafeLoadAs<DType>(bitmap));
|
| 256 |
+
}
|
| 257 |
+
};
|
| 258 |
+
|
| 259 |
+
/// \brief Index into a possibly nonexistent bitmap
|
| 260 |
+
struct OptionalBitIndexer {
|
| 261 |
+
const uint8_t* bitmap;
|
| 262 |
+
const int64_t offset;
|
| 263 |
+
|
| 264 |
+
explicit OptionalBitIndexer(const uint8_t* buffer = NULLPTR, int64_t offset = 0)
|
| 265 |
+
: bitmap(buffer), offset(offset) {}
|
| 266 |
+
|
| 267 |
+
bool operator[](int64_t i) const {
|
| 268 |
+
return bitmap == NULLPTR || bit_util::GetBit(bitmap, offset + i);
|
| 269 |
+
}
|
| 270 |
+
};
|
| 271 |
+
|
| 272 |
+
} // namespace internal
|
| 273 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/bpacking64_default.h
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/bpacking_avx2.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#pragma once
|
| 19 |
+
|
| 20 |
+
#include <stdint.h>
|
| 21 |
+
|
| 22 |
+
namespace arrow {
|
| 23 |
+
namespace internal {
|
| 24 |
+
|
| 25 |
+
int unpack32_avx2(const uint32_t* in, uint32_t* out, int batch_size, int num_bits);
|
| 26 |
+
|
| 27 |
+
} // namespace internal
|
| 28 |
+
} // namespace arrow
|
parrot/lib/python3.10/site-packages/pyarrow/include/arrow/util/bpacking_default.h
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|