applied-ai-018 commited on
Commit
6501646
·
verified ·
1 Parent(s): 52a5478

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +4 -0
  2. llmeval-env/lib/python3.10/site-packages/pyarrow/_flight.cpython-310-x86_64-linux-gnu.so +3 -0
  3. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/csv/api.h +22 -0
  4. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/csv/column_builder.h +78 -0
  5. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/csv/column_decoder.h +64 -0
  6. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/csv/parser.h +228 -0
  7. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/csv/type_fwd.h +28 -0
  8. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/api.h +22 -0
  9. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/pch.h +23 -0
  10. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/api.h +26 -0
  11. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/extension_set.h +481 -0
  12. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/extension_types.h +90 -0
  13. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/options.h +135 -0
  14. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/relation.h +71 -0
  15. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/serde.h +331 -0
  16. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/test_plan_builder.h +76 -0
  17. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/test_util.h +45 -0
  18. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/type_fwd.h +32 -0
  19. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/util.h +83 -0
  20. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/visibility.h +52 -0
  21. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/extension/fixed_shape_tensor.h +128 -0
  22. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/api.h +25 -0
  23. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/buffered.h +167 -0
  24. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/caching.h +157 -0
  25. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/compressed.h +124 -0
  26. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/concurrency.h +263 -0
  27. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/file.h +221 -0
  28. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/hdfs.h +284 -0
  29. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/interfaces.h +362 -0
  30. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/memory.h +213 -0
  31. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/mman.h +169 -0
  32. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/slow.h +118 -0
  33. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/stdio.h +82 -0
  34. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/test_common.h +67 -0
  35. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/transform.h +60 -0
  36. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/type_fwd.h +77 -0
  37. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/api.h +30 -0
  38. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/arrow_to_pandas.h +146 -0
  39. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/async.h +60 -0
  40. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/benchmark.h +36 -0
  41. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/csv.h +42 -0
  42. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/decimal.h +128 -0
  43. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/deserialize.h +106 -0
  44. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/extension_type.h +85 -0
  45. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/filesystem.h +130 -0
  46. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/flight.h +350 -0
  47. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/gdb.h +29 -0
  48. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/inference.h +64 -0
  49. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/init.h +26 -0
  50. llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/ipc.h +72 -0
.gitattributes CHANGED
@@ -72,3 +72,7 @@ llmeval-env/lib/python3.10/site-packages/triton/third_party/cuda/bin/nvdisasm fi
72
  llmeval-env/lib/python3.10/site-packages/pyarrow/libarrow_acero.so.1600 filter=lfs diff=lfs merge=lfs -text
73
  llmeval-env/lib/python3.10/site-packages/pyarrow/_compute.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
74
  llmeval-env/lib/python3.10/site-packages/pyarrow/_dataset.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
72
  llmeval-env/lib/python3.10/site-packages/pyarrow/libarrow_acero.so.1600 filter=lfs diff=lfs merge=lfs -text
73
  llmeval-env/lib/python3.10/site-packages/pyarrow/_compute.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
74
  llmeval-env/lib/python3.10/site-packages/pyarrow/_dataset.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
75
+ llmeval-env/lib/python3.10/site-packages/pyarrow/libarrow_python.so filter=lfs diff=lfs merge=lfs -text
76
+ llmeval-env/lib/python3.10/site-packages/pyarrow/_flight.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
77
+ llmeval-env/lib/python3.10/site-packages/pyarrow/libparquet.so.1600 filter=lfs diff=lfs merge=lfs -text
78
+ llmeval-env/lib/python3.10/site-packages/pyarrow/libarrow_dataset.so.1600 filter=lfs diff=lfs merge=lfs -text
llmeval-env/lib/python3.10/site-packages/pyarrow/_flight.cpython-310-x86_64-linux-gnu.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d69b13bb38af740d932b3333f923b1c11be3a42727fe327902cd8384dc6b3874
3
+ size 1291200
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/csv/api.h ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/csv/options.h"
21
+ #include "arrow/csv/reader.h"
22
+ #include "arrow/csv/writer.h"
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/csv/column_builder.h ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 <utility>
23
+
24
+ #include "arrow/result.h"
25
+ #include "arrow/type_fwd.h"
26
+ #include "arrow/util/type_fwd.h"
27
+ #include "arrow/util/visibility.h"
28
+
29
+ namespace arrow {
30
+ namespace csv {
31
+
32
+ class BlockParser;
33
+ struct ConvertOptions;
34
+
35
+ class ARROW_EXPORT ColumnBuilder {
36
+ public:
37
+ virtual ~ColumnBuilder() = default;
38
+
39
+ /// Spawn a task that will try to convert and append the given CSV block.
40
+ /// All calls to Append() should happen on the same thread, otherwise
41
+ /// call Insert() instead.
42
+ virtual void Append(const std::shared_ptr<BlockParser>& parser) = 0;
43
+
44
+ /// Spawn a task that will try to convert and insert the given CSV block
45
+ virtual void Insert(int64_t block_index,
46
+ const std::shared_ptr<BlockParser>& parser) = 0;
47
+
48
+ /// Return the final chunked array. The TaskGroup _must_ have finished!
49
+ virtual Result<std::shared_ptr<ChunkedArray>> Finish() = 0;
50
+
51
+ std::shared_ptr<arrow::internal::TaskGroup> task_group() { return task_group_; }
52
+
53
+ /// Construct a strictly-typed ColumnBuilder.
54
+ static Result<std::shared_ptr<ColumnBuilder>> Make(
55
+ MemoryPool* pool, const std::shared_ptr<DataType>& type, int32_t col_index,
56
+ const ConvertOptions& options,
57
+ const std::shared_ptr<arrow::internal::TaskGroup>& task_group);
58
+
59
+ /// Construct a type-inferring ColumnBuilder.
60
+ static Result<std::shared_ptr<ColumnBuilder>> Make(
61
+ MemoryPool* pool, int32_t col_index, const ConvertOptions& options,
62
+ const std::shared_ptr<arrow::internal::TaskGroup>& task_group);
63
+
64
+ /// Construct a ColumnBuilder for a column of nulls
65
+ /// (i.e. not present in the CSV file).
66
+ static Result<std::shared_ptr<ColumnBuilder>> MakeNull(
67
+ MemoryPool* pool, const std::shared_ptr<DataType>& type,
68
+ const std::shared_ptr<arrow::internal::TaskGroup>& task_group);
69
+
70
+ protected:
71
+ explicit ColumnBuilder(std::shared_ptr<arrow::internal::TaskGroup> task_group)
72
+ : task_group_(std::move(task_group)) {}
73
+
74
+ std::shared_ptr<arrow::internal::TaskGroup> task_group_;
75
+ };
76
+
77
+ } // namespace csv
78
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/csv/column_decoder.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
+ #pragma once
19
+
20
+ #include <cstdint>
21
+ #include <memory>
22
+ #include <utility>
23
+
24
+ #include "arrow/result.h"
25
+ #include "arrow/type_fwd.h"
26
+ #include "arrow/util/type_fwd.h"
27
+ #include "arrow/util/visibility.h"
28
+
29
+ namespace arrow {
30
+ namespace csv {
31
+
32
+ class BlockParser;
33
+ struct ConvertOptions;
34
+
35
+ class ARROW_EXPORT ColumnDecoder {
36
+ public:
37
+ virtual ~ColumnDecoder() = default;
38
+
39
+ /// Spawn a task that will try to convert and insert the given CSV block
40
+ virtual Future<std::shared_ptr<Array>> Decode(
41
+ const std::shared_ptr<BlockParser>& parser) = 0;
42
+
43
+ /// Construct a strictly-typed ColumnDecoder.
44
+ static Result<std::shared_ptr<ColumnDecoder>> Make(MemoryPool* pool,
45
+ std::shared_ptr<DataType> type,
46
+ int32_t col_index,
47
+ const ConvertOptions& options);
48
+
49
+ /// Construct a type-inferring ColumnDecoder.
50
+ /// Inference will run only on the first block, the type will be frozen afterwards.
51
+ static Result<std::shared_ptr<ColumnDecoder>> Make(MemoryPool* pool, int32_t col_index,
52
+ const ConvertOptions& options);
53
+
54
+ /// Construct a ColumnDecoder for a column of nulls
55
+ /// (i.e. not present in the CSV file).
56
+ static Result<std::shared_ptr<ColumnDecoder>> MakeNull(MemoryPool* pool,
57
+ std::shared_ptr<DataType> type);
58
+
59
+ protected:
60
+ ColumnDecoder() = default;
61
+ };
62
+
63
+ } // namespace csv
64
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/csv/parser.h ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 <cstddef>
22
+ #include <cstdint>
23
+ #include <memory>
24
+ #include <string_view>
25
+ #include <vector>
26
+
27
+ #include "arrow/buffer.h"
28
+ #include "arrow/csv/options.h"
29
+ #include "arrow/csv/type_fwd.h"
30
+ #include "arrow/status.h"
31
+ #include "arrow/util/macros.h"
32
+ #include "arrow/util/visibility.h"
33
+
34
+ namespace arrow {
35
+
36
+ class MemoryPool;
37
+
38
+ namespace csv {
39
+
40
+ /// Skip at most num_rows from the given input. The input pointer is updated
41
+ /// and the number of actually skipped rows is returns (may be less than
42
+ /// requested if the input is too short).
43
+ ARROW_EXPORT
44
+ int32_t SkipRows(const uint8_t* data, uint32_t size, int32_t num_rows,
45
+ const uint8_t** out_data);
46
+
47
+ class BlockParserImpl;
48
+
49
+ namespace detail {
50
+
51
+ struct ParsedValueDesc {
52
+ uint32_t offset : 31;
53
+ bool quoted : 1;
54
+ };
55
+
56
+ class ARROW_EXPORT DataBatch {
57
+ public:
58
+ explicit DataBatch(int32_t num_cols) : num_cols_(num_cols) {}
59
+
60
+ /// \brief Return the number of parsed rows (not skipped)
61
+ int32_t num_rows() const { return num_rows_; }
62
+ /// \brief Return the number of parsed columns
63
+ int32_t num_cols() const { return num_cols_; }
64
+ /// \brief Return the total size in bytes of parsed data
65
+ uint32_t num_bytes() const { return parsed_size_; }
66
+ /// \brief Return the number of skipped rows
67
+ int32_t num_skipped_rows() const { return static_cast<int32_t>(skipped_rows_.size()); }
68
+
69
+ template <typename Visitor>
70
+ Status VisitColumn(int32_t col_index, int64_t first_row, Visitor&& visit) const {
71
+ using detail::ParsedValueDesc;
72
+
73
+ int32_t batch_row = 0;
74
+ for (size_t buf_index = 0; buf_index < values_buffers_.size(); ++buf_index) {
75
+ const auto& values_buffer = values_buffers_[buf_index];
76
+ const auto values = reinterpret_cast<const ParsedValueDesc*>(values_buffer->data());
77
+ const auto max_pos =
78
+ static_cast<int32_t>(values_buffer->size() / sizeof(ParsedValueDesc)) - 1;
79
+ for (int32_t pos = col_index; pos < max_pos; pos += num_cols_, ++batch_row) {
80
+ auto start = values[pos].offset;
81
+ auto stop = values[pos + 1].offset;
82
+ auto quoted = values[pos + 1].quoted;
83
+ Status status = visit(parsed_ + start, stop - start, quoted);
84
+ if (ARROW_PREDICT_FALSE(!status.ok())) {
85
+ return DecorateWithRowNumber(std::move(status), first_row, batch_row);
86
+ }
87
+ }
88
+ }
89
+ return Status::OK();
90
+ }
91
+
92
+ template <typename Visitor>
93
+ Status VisitLastRow(Visitor&& visit) const {
94
+ using detail::ParsedValueDesc;
95
+
96
+ const auto& values_buffer = values_buffers_.back();
97
+ const auto values = reinterpret_cast<const ParsedValueDesc*>(values_buffer->data());
98
+ const auto start_pos =
99
+ static_cast<int32_t>(values_buffer->size() / sizeof(ParsedValueDesc)) -
100
+ num_cols_ - 1;
101
+ for (int32_t col_index = 0; col_index < num_cols_; ++col_index) {
102
+ auto start = values[start_pos + col_index].offset;
103
+ auto stop = values[start_pos + col_index + 1].offset;
104
+ auto quoted = values[start_pos + col_index + 1].quoted;
105
+ ARROW_RETURN_NOT_OK(visit(parsed_ + start, stop - start, quoted));
106
+ }
107
+ return Status::OK();
108
+ }
109
+
110
+ protected:
111
+ Status DecorateWithRowNumber(Status&& status, int64_t first_row,
112
+ int32_t batch_row) const {
113
+ if (first_row >= 0) {
114
+ // `skipped_rows_` is in ascending order by construction, so use bisection
115
+ // to find out how many rows were skipped before `batch_row`.
116
+ const auto skips_before =
117
+ std::upper_bound(skipped_rows_.begin(), skipped_rows_.end(), batch_row) -
118
+ skipped_rows_.begin();
119
+ status = status.WithMessage("Row #", batch_row + skips_before + first_row, ": ",
120
+ status.message());
121
+ }
122
+ // Use return_if so that when extra context is enabled it will be added
123
+ ARROW_RETURN_IF_(true, std::move(status), ARROW_STRINGIFY(status));
124
+ return std::move(status);
125
+ }
126
+
127
+ // The number of rows in this batch (not including any skipped ones)
128
+ int32_t num_rows_ = 0;
129
+ // The number of columns
130
+ int32_t num_cols_ = 0;
131
+
132
+ // XXX should we ensure the parsed buffer is padded with 8 or 16 excess zero bytes?
133
+ // It may help with null parsing...
134
+ std::vector<std::shared_ptr<Buffer>> values_buffers_;
135
+ std::shared_ptr<Buffer> parsed_buffer_;
136
+ const uint8_t* parsed_ = NULLPTR;
137
+ int32_t parsed_size_ = 0;
138
+
139
+ // Record the current num_rows_ each time a row is skipped
140
+ std::vector<int32_t> skipped_rows_;
141
+
142
+ friend class ::arrow::csv::BlockParserImpl;
143
+ };
144
+
145
+ } // namespace detail
146
+
147
+ constexpr int32_t kMaxParserNumRows = 100000;
148
+
149
+ /// \class BlockParser
150
+ /// \brief A reusable block-based parser for CSV data
151
+ ///
152
+ /// The parser takes a block of CSV data and delimits rows and fields,
153
+ /// unquoting and unescaping them on the fly. Parsed data is own by the
154
+ /// parser, so the original buffer can be discarded after Parse() returns.
155
+ ///
156
+ /// If the block is truncated (i.e. not all data can be parsed), it is up
157
+ /// to the caller to arrange the next block to start with the trailing data.
158
+ /// Also, if the previous block ends with CR (0x0d) and a new block starts
159
+ /// with LF (0x0a), the parser will consider the leading newline as an empty
160
+ /// line; the caller should therefore strip it.
161
+ class ARROW_EXPORT BlockParser {
162
+ public:
163
+ explicit BlockParser(ParseOptions options, int32_t num_cols = -1,
164
+ int64_t first_row = -1, int32_t max_num_rows = kMaxParserNumRows);
165
+ explicit BlockParser(MemoryPool* pool, ParseOptions options, int32_t num_cols = -1,
166
+ int64_t first_row = -1, int32_t max_num_rows = kMaxParserNumRows);
167
+ ~BlockParser();
168
+
169
+ /// \brief Parse a block of data
170
+ ///
171
+ /// Parse a block of CSV data, ingesting up to max_num_rows rows.
172
+ /// The number of bytes actually parsed is returned in out_size.
173
+ Status Parse(std::string_view data, uint32_t* out_size);
174
+
175
+ /// \brief Parse sequential blocks of data
176
+ ///
177
+ /// Only the last block is allowed to be truncated.
178
+ Status Parse(const std::vector<std::string_view>& data, uint32_t* out_size);
179
+
180
+ /// \brief Parse the final block of data
181
+ ///
182
+ /// Like Parse(), but called with the final block in a file.
183
+ /// The last row may lack a trailing line separator.
184
+ Status ParseFinal(std::string_view data, uint32_t* out_size);
185
+
186
+ /// \brief Parse the final sequential blocks of data
187
+ ///
188
+ /// Only the last block is allowed to be truncated.
189
+ Status ParseFinal(const std::vector<std::string_view>& data, uint32_t* out_size);
190
+
191
+ /// \brief Return the number of parsed rows
192
+ int32_t num_rows() const { return parsed_batch().num_rows(); }
193
+ /// \brief Return the number of parsed columns
194
+ int32_t num_cols() const { return parsed_batch().num_cols(); }
195
+ /// \brief Return the total size in bytes of parsed data
196
+ uint32_t num_bytes() const { return parsed_batch().num_bytes(); }
197
+
198
+ /// \brief Return the total number of rows including rows which were skipped
199
+ int32_t total_num_rows() const {
200
+ return parsed_batch().num_rows() + parsed_batch().num_skipped_rows();
201
+ }
202
+
203
+ /// \brief Return the row number of the first row in the block or -1 if unsupported
204
+ int64_t first_row_num() const;
205
+
206
+ /// \brief Visit parsed values in a column
207
+ ///
208
+ /// The signature of the visitor is
209
+ /// Status(const uint8_t* data, uint32_t size, bool quoted)
210
+ template <typename Visitor>
211
+ Status VisitColumn(int32_t col_index, Visitor&& visit) const {
212
+ return parsed_batch().VisitColumn(col_index, first_row_num(),
213
+ std::forward<Visitor>(visit));
214
+ }
215
+
216
+ template <typename Visitor>
217
+ Status VisitLastRow(Visitor&& visit) const {
218
+ return parsed_batch().VisitLastRow(std::forward<Visitor>(visit));
219
+ }
220
+
221
+ protected:
222
+ std::unique_ptr<BlockParserImpl> impl_;
223
+
224
+ const detail::DataBatch& parsed_batch() const;
225
+ };
226
+
227
+ } // namespace csv
228
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/csv/type_fwd.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
+ namespace arrow {
19
+ namespace csv {
20
+
21
+ class TableReader;
22
+ struct ConvertOptions;
23
+ struct ReadOptions;
24
+ struct ParseOptions;
25
+ struct WriteOptions;
26
+
27
+ } // namespace csv
28
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/api.h ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // This API is EXPERIMENTAL.
19
+
20
+ #pragma once
21
+
22
+ #include "arrow/engine/substrait/api.h"
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/pch.h ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // Often-used headers, for precompiling.
19
+ // If updating this header, please make sure you check compilation speed
20
+ // before checking in. Adding headers which are not used extremely often
21
+ // may incur a slowdown, since it makes the precompiled header heavier to load.
22
+
23
+ #include "arrow/pch.h"
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/api.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
+ // This API is EXPERIMENTAL.
19
+
20
+ #pragma once
21
+
22
+ #include "arrow/engine/substrait/extension_set.h"
23
+ #include "arrow/engine/substrait/extension_types.h"
24
+ #include "arrow/engine/substrait/options.h"
25
+ #include "arrow/engine/substrait/relation.h"
26
+ #include "arrow/engine/substrait/serde.h"
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/extension_set.h ADDED
@@ -0,0 +1,481 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // This API is EXPERIMENTAL.
19
+
20
+ #pragma once
21
+
22
+ #include <cstddef>
23
+ #include <cstdint>
24
+ #include <functional>
25
+ #include <memory>
26
+ #include <optional>
27
+ #include <string>
28
+ #include <string_view>
29
+ #include <unordered_map>
30
+ #include <utility>
31
+ #include <vector>
32
+
33
+ #include "arrow/compute/api_aggregate.h"
34
+ #include "arrow/compute/expression.h"
35
+ #include "arrow/engine/substrait/type_fwd.h"
36
+ #include "arrow/engine/substrait/visibility.h"
37
+ #include "arrow/result.h"
38
+ #include "arrow/status.h"
39
+ #include "arrow/type_fwd.h"
40
+ #include "arrow/util/macros.h"
41
+
42
+ namespace arrow {
43
+ namespace engine {
44
+
45
+ constexpr const char* kSubstraitArithmeticFunctionsUri =
46
+ "https://github.com/substrait-io/substrait/blob/main/extensions/"
47
+ "functions_arithmetic.yaml";
48
+ constexpr const char* kSubstraitBooleanFunctionsUri =
49
+ "https://github.com/substrait-io/substrait/blob/main/extensions/"
50
+ "functions_boolean.yaml";
51
+ constexpr const char* kSubstraitComparisonFunctionsUri =
52
+ "https://github.com/substrait-io/substrait/blob/main/extensions/"
53
+ "functions_comparison.yaml";
54
+ constexpr const char* kSubstraitDatetimeFunctionsUri =
55
+ "https://github.com/substrait-io/substrait/blob/main/extensions/"
56
+ "functions_datetime.yaml";
57
+ constexpr const char* kSubstraitLogarithmicFunctionsUri =
58
+ "https://github.com/substrait-io/substrait/blob/main/extensions/"
59
+ "functions_logarithmic.yaml";
60
+ constexpr const char* kSubstraitRoundingFunctionsUri =
61
+ "https://github.com/substrait-io/substrait/blob/main/extensions/"
62
+ "functions_rounding.yaml";
63
+ constexpr const char* kSubstraitStringFunctionsUri =
64
+ "https://github.com/substrait-io/substrait/blob/main/extensions/"
65
+ "functions_string.yaml";
66
+ constexpr const char* kSubstraitAggregateGenericFunctionsUri =
67
+ "https://github.com/substrait-io/substrait/blob/main/extensions/"
68
+ "functions_aggregate_generic.yaml";
69
+
70
+ /// If a function call contains this URI then the function is looked up
71
+ /// in the registry directly, all arguments are mapped as value arguments,
72
+ /// and any options are ignored.
73
+ constexpr const char* kArrowSimpleExtensionFunctionsUri =
74
+ "urn:arrow:substrait_simple_extension_function";
75
+
76
+ struct ARROW_ENGINE_EXPORT Id {
77
+ std::string_view uri, name;
78
+ bool empty() const { return uri.empty() && name.empty(); }
79
+ std::string ToString() const;
80
+ };
81
+ struct ARROW_ENGINE_EXPORT IdHashEq {
82
+ size_t operator()(Id id) const;
83
+ bool operator()(Id l, Id r) const;
84
+ };
85
+
86
+ /// \brief Owning storage for ids
87
+ ///
88
+ /// Substrait plans may reuse URIs and names in many places. For convenience
89
+ /// and performance Substrait ids are typically passed around as views. As we
90
+ /// convert a plan from Substrait to Arrow we need to copy these strings out of
91
+ /// the Substrait buffer and into owned storage. This class serves as that owned
92
+ /// storage.
93
+ class ARROW_ENGINE_EXPORT IdStorage {
94
+ public:
95
+ virtual ~IdStorage() = default;
96
+ /// \brief Get an equivalent id pointing into this storage
97
+ ///
98
+ /// This operation will copy the ids into storage if they do not already exist
99
+ virtual Id Emplace(Id id) = 0;
100
+ /// \brief Get an equivalent view pointing into this storage for a URI
101
+ ///
102
+ /// If no URI is found then the uri will be copied into storage
103
+ virtual std::string_view EmplaceUri(std::string_view uri) = 0;
104
+ /// \brief Get an equivalent id pointing into this storage
105
+ ///
106
+ /// If no id is found then nullopt will be returned
107
+ virtual std::optional<Id> Find(Id id) const = 0;
108
+ /// \brief Get an equivalent view pointing into this storage for a URI
109
+ ///
110
+ /// If no URI is found then nullopt will be returned
111
+ virtual std::optional<std::string_view> FindUri(std::string_view uri) const = 0;
112
+
113
+ static std::unique_ptr<IdStorage> Make();
114
+ };
115
+
116
+ /// \brief Describes a Substrait call
117
+ ///
118
+ /// Substrait call expressions contain a list of arguments which can either
119
+ /// be enum arguments (which are serialized as strings), value arguments (which)
120
+ /// are Arrow expressions, or type arguments (not yet implemented)
121
+ class ARROW_ENGINE_EXPORT SubstraitCall {
122
+ public:
123
+ SubstraitCall(Id id, std::shared_ptr<DataType> output_type, bool output_nullable,
124
+ bool is_hash = false)
125
+ : id_(id),
126
+ output_type_(std::move(output_type)),
127
+ output_nullable_(output_nullable),
128
+ is_hash_(is_hash) {}
129
+
130
+ const Id& id() const { return id_; }
131
+ const std::shared_ptr<DataType>& output_type() const { return output_type_; }
132
+ bool output_nullable() const { return output_nullable_; }
133
+ bool is_hash() const { return is_hash_; }
134
+ const std::unordered_map<std::string, std::vector<std::string>>& options() const {
135
+ return options_;
136
+ }
137
+
138
+ bool HasEnumArg(int index) const;
139
+ Result<std::string_view> GetEnumArg(int index) const;
140
+ void SetEnumArg(int index, std::string enum_arg);
141
+ Result<compute::Expression> GetValueArg(int index) const;
142
+ bool HasValueArg(int index) const;
143
+ void SetValueArg(int index, compute::Expression value_arg);
144
+ std::optional<std::vector<std::string> const*> GetOption(
145
+ std::string_view option_name) const;
146
+ void SetOption(std::string_view option_name,
147
+ const std::vector<std::string_view>& option_preferences);
148
+ bool HasOptions() const;
149
+ int size() const { return size_; }
150
+
151
+ private:
152
+ Id id_;
153
+ std::shared_ptr<DataType> output_type_;
154
+ bool output_nullable_;
155
+ // Only needed when converting from Substrait -> Arrow aggregates. The
156
+ // Arrow function name depends on whether or not there are any groups
157
+ bool is_hash_;
158
+ std::unordered_map<int, std::string> enum_args_;
159
+ std::unordered_map<int, compute::Expression> value_args_;
160
+ std::unordered_map<std::string, std::vector<std::string>> options_;
161
+ int size_ = 0;
162
+ };
163
+
164
+ /// Substrait identifies functions and custom data types using a (uri, name) pair.
165
+ ///
166
+ /// This registry is a bidirectional mapping between Substrait IDs and their
167
+ /// corresponding Arrow counterparts (arrow::DataType and function names in a function
168
+ /// registry)
169
+ ///
170
+ /// Substrait extension types and variations must be registered with their
171
+ /// corresponding arrow::DataType before they can be used!
172
+ ///
173
+ /// Conceptually this can be thought of as two pairs of `unordered_map`s. One pair to
174
+ /// go back and forth between Substrait ID and arrow::DataType and another pair to go
175
+ /// back and forth between Substrait ID and Arrow function names.
176
+ ///
177
+ /// Unlike an ExtensionSet this registry is not created automatically when consuming
178
+ /// Substrait plans and must be configured ahead of time (although there is a default
179
+ /// instance).
180
+ class ARROW_ENGINE_EXPORT ExtensionIdRegistry {
181
+ public:
182
+ using ArrowToSubstraitCall =
183
+ std::function<Result<SubstraitCall>(const arrow::compute::Expression::Call&)>;
184
+ using SubstraitCallToArrow =
185
+ std::function<Result<arrow::compute::Expression>(const SubstraitCall&)>;
186
+ using ArrowToSubstraitAggregate =
187
+ std::function<Result<SubstraitCall>(const arrow::compute::Aggregate&)>;
188
+ using SubstraitAggregateToArrow =
189
+ std::function<Result<arrow::compute::Aggregate>(const SubstraitCall&)>;
190
+
191
+ /// \brief A mapping between a Substrait ID and an arrow::DataType
192
+ struct TypeRecord {
193
+ Id id;
194
+ const std::shared_ptr<DataType>& type;
195
+ };
196
+
197
+ /// \brief Return a uri view owned by this registry
198
+ ///
199
+ /// If the URI has never been emplaced it will return nullopt
200
+ virtual std::optional<std::string_view> FindUri(std::string_view uri) const = 0;
201
+ /// \brief Return a id view owned by this registry
202
+ ///
203
+ /// If the id has never been emplaced it will return nullopt
204
+ virtual std::optional<Id> FindId(Id id) const = 0;
205
+ virtual std::optional<TypeRecord> GetType(const DataType&) const = 0;
206
+ virtual std::optional<TypeRecord> GetType(Id) const = 0;
207
+ virtual Status CanRegisterType(Id, const std::shared_ptr<DataType>& type) const = 0;
208
+ virtual Status RegisterType(Id, std::shared_ptr<DataType>) = 0;
209
+ /// \brief Register a converter that converts an Arrow call to a Substrait call
210
+ ///
211
+ /// Note that there may not be 1:1 parity between ArrowToSubstraitCall and
212
+ /// SubstraitCallToArrow because some standard functions (e.g. add) may map to
213
+ /// multiple Arrow functions (e.g. add, add_checked)
214
+ virtual Status AddArrowToSubstraitCall(std::string arrow_function_name,
215
+ ArrowToSubstraitCall conversion_func) = 0;
216
+ /// \brief Check to see if a converter can be registered
217
+ ///
218
+ /// \return Status::OK if there are no conflicts, otherwise an error is returned
219
+ virtual Status CanAddArrowToSubstraitCall(
220
+ const std::string& arrow_function_name) const = 0;
221
+
222
+ /// \brief Register a converter that converts an Arrow aggregate to a Substrait
223
+ /// aggregate
224
+ virtual Status AddArrowToSubstraitAggregate(
225
+ std::string arrow_function_name, ArrowToSubstraitAggregate conversion_func) = 0;
226
+ /// \brief Check to see if a converter can be registered
227
+ ///
228
+ /// \return Status::OK if there are no conflicts, otherwise an error is returned
229
+ virtual Status CanAddArrowToSubstraitAggregate(
230
+ const std::string& arrow_function_name) const = 0;
231
+
232
+ /// \brief Register a converter that converts a Substrait call to an Arrow call
233
+ virtual Status AddSubstraitCallToArrow(Id substrait_function_id,
234
+ SubstraitCallToArrow conversion_func) = 0;
235
+ /// \brief Check to see if a converter can be registered
236
+ ///
237
+ /// \return Status::OK if there are no conflicts, otherwise an error is returned
238
+ virtual Status CanAddSubstraitCallToArrow(Id substrait_function_id) const = 0;
239
+ /// \brief Register a simple mapping function
240
+ ///
241
+ /// All calls to the function must pass only value arguments. The arguments
242
+ /// will be converted to expressions and passed to the Arrow function
243
+ virtual Status AddSubstraitCallToArrow(Id substrait_function_id,
244
+ std::string arrow_function_name) = 0;
245
+
246
+ /// \brief Register a converter that converts a Substrait aggregate to an Arrow
247
+ /// aggregate
248
+ virtual Status AddSubstraitAggregateToArrow(
249
+ Id substrait_function_id, SubstraitAggregateToArrow conversion_func) = 0;
250
+ /// \brief Check to see if a converter can be registered
251
+ ///
252
+ /// \return Status::OK if there are no conflicts, otherwise an error is returned
253
+ virtual Status CanAddSubstraitAggregateToArrow(Id substrait_function_id) const = 0;
254
+
255
+ /// \brief Return a list of Substrait functions that have a converter
256
+ ///
257
+ /// The function ids are encoded as strings using the pattern {uri}#{name}
258
+ virtual std::vector<std::string> GetSupportedSubstraitFunctions() const = 0;
259
+
260
+ /// \brief Find a converter to map Arrow calls to Substrait calls
261
+ /// \return A converter function or an invalid status if no converter is registered
262
+ virtual Result<ArrowToSubstraitCall> GetArrowToSubstraitCall(
263
+ const std::string& arrow_function_name) const = 0;
264
+
265
+ /// \brief Find a converter to map Arrow aggregates to Substrait aggregates
266
+ /// \return A converter function or an invalid status if no converter is registered
267
+ virtual Result<ArrowToSubstraitAggregate> GetArrowToSubstraitAggregate(
268
+ const std::string& arrow_function_name) const = 0;
269
+
270
+ /// \brief Find a converter to map a Substrait aggregate to an Arrow aggregate
271
+ /// \return A converter function or an invalid status if no converter is registered
272
+ virtual Result<SubstraitAggregateToArrow> GetSubstraitAggregateToArrow(
273
+ Id substrait_function_id) const = 0;
274
+
275
+ /// \brief Find a converter to map a Substrait call to an Arrow call
276
+ /// \return A converter function or an invalid status if no converter is registered
277
+ virtual Result<SubstraitCallToArrow> GetSubstraitCallToArrow(
278
+ Id substrait_function_id) const = 0;
279
+
280
+ /// \brief Similar to \see GetSubstraitCallToArrow but only uses the name
281
+ ///
282
+ /// There may be multiple functions with the same name and this will return
283
+ /// the first. This is slower than GetSubstraitCallToArrow and should only
284
+ /// be used when the plan does not include a URI (or the URI is "/")
285
+ virtual Result<SubstraitCallToArrow> GetSubstraitCallToArrowFallback(
286
+ std::string_view function_name) const = 0;
287
+
288
+ /// \brief Similar to \see GetSubstraitAggregateToArrow but only uses the name
289
+ ///
290
+ /// \see GetSubstraitCallToArrowFallback for details on the fallback behavior
291
+ virtual Result<SubstraitAggregateToArrow> GetSubstraitAggregateToArrowFallback(
292
+ std::string_view function_name) const = 0;
293
+ };
294
+
295
+ constexpr std::string_view kArrowExtTypesUri =
296
+ "https://github.com/apache/arrow/blob/main/format/substrait/"
297
+ "extension_types.yaml";
298
+ // Extension types that don't match 1:1 with a data type (or the data type is
299
+ // parameterized)
300
+ constexpr std::string_view kTimeNanosTypeName = "time_nanos";
301
+ constexpr Id kTimeNanosId = {kArrowExtTypesUri, kTimeNanosTypeName};
302
+
303
+ /// A default registry with all supported functions and data types registered
304
+ ///
305
+ /// Note: Function support is currently very minimal, see ARROW-15538
306
+ ARROW_ENGINE_EXPORT ExtensionIdRegistry* default_extension_id_registry();
307
+
308
+ /// \brief Make a nested registry with a given parent.
309
+ ///
310
+ /// A nested registry supports registering types and functions other and on top of those
311
+ /// already registered in its parent registry. No conflicts in IDs and names used for
312
+ /// lookup are allowed. Normally, the given parent is the default registry.
313
+ ///
314
+ /// One use case for a nested registry is for dynamic registration of functions defined
315
+ /// within a Substrait plan while keeping these registrations specific to the plan. When
316
+ /// the Substrait plan is disposed of, normally after its execution, the nested registry
317
+ /// can be disposed of as well.
318
+ ARROW_ENGINE_EXPORT std::shared_ptr<ExtensionIdRegistry> nested_extension_id_registry(
319
+ const ExtensionIdRegistry* parent);
320
+
321
+ /// \brief A set of extensions used within a plan
322
+ ///
323
+ /// Each time an extension is used within a Substrait plan the extension
324
+ /// must be included in an extension set that is defined at the root of the
325
+ /// plan.
326
+ ///
327
+ /// The plan refers to a specific extension using an "anchor" which is an
328
+ /// arbitrary integer invented by the producer that has no meaning beyond a
329
+ /// plan but which should be consistent within a plan.
330
+ ///
331
+ /// To support serialization and deserialization this type serves as a
332
+ /// bidirectional map between Substrait ID and "anchor"s.
333
+ ///
334
+ /// When deserializing a Substrait plan the extension set should be extracted
335
+ /// after the plan has been converted from Protobuf and before the plan
336
+ /// is converted to an execution plan.
337
+ ///
338
+ /// The extension set can be kept and reused during serialization if a perfect
339
+ /// round trip is required. If serialization is not needed or round tripping
340
+ /// is not required then the extension set can be safely discarded after the
341
+ /// plan has been converted into an execution plan.
342
+ ///
343
+ /// When converting an execution plan into a Substrait plan an extension set
344
+ /// can be automatically generated or a previously generated extension set can
345
+ /// be used.
346
+ ///
347
+ /// ExtensionSet does not own strings; it only refers to strings in an
348
+ /// ExtensionIdRegistry.
349
+ class ARROW_ENGINE_EXPORT ExtensionSet {
350
+ public:
351
+ struct FunctionRecord {
352
+ Id id;
353
+ std::string_view name;
354
+ };
355
+
356
+ struct TypeRecord {
357
+ Id id;
358
+ std::shared_ptr<DataType> type;
359
+ };
360
+
361
+ /// Construct an empty ExtensionSet to be populated during serialization.
362
+ explicit ExtensionSet(const ExtensionIdRegistry* = default_extension_id_registry());
363
+ ARROW_DEFAULT_MOVE_AND_ASSIGN(ExtensionSet);
364
+
365
+ /// Construct an ExtensionSet with explicit extension ids for efficient referencing
366
+ /// during deserialization. Note that input vectors need not be densely packed; an empty
367
+ /// (default constructed) Id may be used as a placeholder to indicate an unused
368
+ /// _anchor/_reference. This factory will be used to wrap the extensions declared in a
369
+ /// substrait::Plan before deserializing the plan's relations.
370
+ ///
371
+ /// Views will be replaced with equivalent views pointing to memory owned by the
372
+ /// registry.
373
+ ///
374
+ /// Note: This is an advanced operation. The order of the ids, types, and functions
375
+ /// must match the anchor numbers chosen for a plan.
376
+ ///
377
+ /// An extension set should instead be created using
378
+ /// arrow::engine::GetExtensionSetFromPlan
379
+ static Result<ExtensionSet> Make(
380
+ std::unordered_map<uint32_t, std::string_view> uris,
381
+ std::unordered_map<uint32_t, Id> type_ids,
382
+ std::unordered_map<uint32_t, Id> function_ids,
383
+ const ConversionOptions& conversion_options,
384
+ const ExtensionIdRegistry* = default_extension_id_registry());
385
+
386
+ const std::unordered_map<uint32_t, std::string_view>& uris() const { return uris_; }
387
+
388
+ /// \brief Returns a data type given an anchor
389
+ ///
390
+ /// This is used when converting a Substrait plan to an Arrow execution plan.
391
+ ///
392
+ /// If the anchor does not exist in this extension set an error will be returned.
393
+ Result<TypeRecord> DecodeType(uint32_t anchor) const;
394
+
395
+ /// \brief Returns the number of custom type records in this extension set
396
+ ///
397
+ /// Note: the types are currently stored as a sparse vector, so this may return a value
398
+ /// larger than the actual number of types. This behavior may change in the future; see
399
+ /// ARROW-15583.
400
+ std::size_t num_types() const { return types_.size(); }
401
+
402
+ /// \brief Lookup the anchor for a given type
403
+ ///
404
+ /// This operation is used when converting an Arrow execution plan to a Substrait plan.
405
+ /// If the type has been previously encoded then the same anchor value will returned.
406
+ ///
407
+ /// If the type has not been previously encoded then a new anchor value will be created.
408
+ ///
409
+ /// If the type does not exist in the extension id registry then an error will be
410
+ /// returned.
411
+ ///
412
+ /// \return An anchor that can be used to refer to the type within a plan
413
+ Result<uint32_t> EncodeType(const DataType& type);
414
+
415
+ /// \brief Return a function id given an anchor
416
+ ///
417
+ /// This is used when converting a Substrait plan to an Arrow execution plan.
418
+ ///
419
+ /// If the anchor does not exist in this extension set an error will be returned.
420
+ Result<Id> DecodeFunction(uint32_t anchor) const;
421
+
422
+ /// \brief Lookup the anchor for a given function
423
+ ///
424
+ /// This operation is used when converting an Arrow execution plan to a Substrait plan.
425
+ /// If the function has been previously encoded then the same anchor value will be
426
+ /// returned.
427
+ ///
428
+ /// If the function has not been previously encoded then a new anchor value will be
429
+ /// created.
430
+ ///
431
+ /// If the function name is not in the extension id registry then an error will be
432
+ /// returned.
433
+ ///
434
+ /// \return An anchor that can be used to refer to the function within a plan
435
+ Result<uint32_t> EncodeFunction(Id function_id);
436
+
437
+ /// \brief Stores a plan-specific id that is not known to the registry
438
+ ///
439
+ /// This is used when converting an Arrow execution plan to a Substrait plan.
440
+ ///
441
+ /// If the function is a UDF, something that wasn't known to the registry,
442
+ /// then we need long term storage of the function name (the ids are just
443
+ /// views)
444
+ Id RegisterPlanSpecificId(Id id);
445
+
446
+ /// \brief Return the number of custom functions in this extension set
447
+ std::size_t num_functions() const { return functions_.size(); }
448
+
449
+ const ExtensionIdRegistry* registry() const { return registry_; }
450
+
451
+ private:
452
+ const ExtensionIdRegistry* registry_;
453
+ // If the registry is not aware of an id then we probably can't do anything
454
+ // with it. However, in some cases, these may represent extensions or features
455
+ // that we can safely ignore. For example, we can usually safely ignore
456
+ // extension type variations if we assume the plan is valid. These ignorable
457
+ // ids are stored here.
458
+ std::unique_ptr<IdStorage> plan_specific_ids_ = IdStorage::Make();
459
+
460
+ // Map from anchor values to URI values referenced by this extension set
461
+ std::unordered_map<uint32_t, std::string_view> uris_;
462
+ // Map from anchor values to type definitions, used during Substrait->Arrow
463
+ // and populated from the Substrait extension set
464
+ std::unordered_map<uint32_t, TypeRecord> types_;
465
+ // Map from anchor values to function ids, used during Substrait->Arrow
466
+ // and populated from the Substrait extension set
467
+ std::unordered_map<uint32_t, Id> functions_;
468
+ // Map from type names to anchor values. Used during Arrow->Substrait
469
+ // and built as the plan is created.
470
+ std::unordered_map<Id, uint32_t, IdHashEq, IdHashEq> types_map_;
471
+ // Map from function names to anchor values. Used during Arrow->Substrait
472
+ // and built as the plan is created.
473
+ std::unordered_map<Id, uint32_t, IdHashEq, IdHashEq> functions_map_;
474
+
475
+ Status CheckHasUri(std::string_view uri);
476
+ void AddUri(std::pair<uint32_t, std::string_view> uri);
477
+ Status AddUri(Id id);
478
+ };
479
+
480
+ } // namespace engine
481
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/extension_types.h ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // This API is EXPERIMENTAL.
19
+
20
+ #pragma once
21
+
22
+ #include <cstdint>
23
+ #include <memory>
24
+ #include <optional>
25
+
26
+ #include "arrow/engine/substrait/visibility.h"
27
+ #include "arrow/type_fwd.h"
28
+
29
+ namespace arrow {
30
+ namespace engine {
31
+
32
+ // arrow::ExtensionTypes are provided to wrap uuid, fixed_char, varchar, interval_year,
33
+ // and interval_day which are first-class types in substrait but do not appear in
34
+ // the arrow type system.
35
+ //
36
+ // Note that these are not automatically registered with arrow::RegisterExtensionType(),
37
+ // which means among other things that serialization of these types to IPC would fail.
38
+
39
+ /// fixed_size_binary(16) for storing Universally Unique IDentifiers
40
+ ARROW_ENGINE_EXPORT
41
+ std::shared_ptr<DataType> uuid();
42
+
43
+ /// fixed_size_binary(length) constrained to contain only valid UTF-8
44
+ ARROW_ENGINE_EXPORT
45
+ std::shared_ptr<DataType> fixed_char(int32_t length);
46
+
47
+ /// utf8() constrained to be shorter than `length`
48
+ ARROW_ENGINE_EXPORT
49
+ std::shared_ptr<DataType> varchar(int32_t length);
50
+
51
+ /// fixed_size_list(int32(), 2) storing a number of [years, months]
52
+ ARROW_ENGINE_EXPORT
53
+ std::shared_ptr<DataType> interval_year();
54
+
55
+ /// fixed_size_list(int32(), 2) storing a number of [days, seconds]
56
+ ARROW_ENGINE_EXPORT
57
+ std::shared_ptr<DataType> interval_day();
58
+
59
+ /// constructs the appropriate timestamp type given the precision
60
+ /// no time zone
61
+ ARROW_ENGINE_EXPORT
62
+ Result<std::shared_ptr<DataType>> precision_timestamp(int precision);
63
+
64
+ /// constructs the appropriate timestamp type given the precision
65
+ /// and the UTC time zone
66
+ ARROW_ENGINE_EXPORT
67
+ Result<std::shared_ptr<DataType>> precision_timestamp_tz(int precision);
68
+
69
+ /// Return true if t is Uuid, otherwise false
70
+ ARROW_ENGINE_EXPORT
71
+ bool UnwrapUuid(const DataType&);
72
+
73
+ /// Return FixedChar length if t is FixedChar, otherwise nullopt
74
+ ARROW_ENGINE_EXPORT
75
+ std::optional<int32_t> UnwrapFixedChar(const DataType&);
76
+
77
+ /// Return Varchar (max) length if t is VarChar, otherwise nullopt
78
+ ARROW_ENGINE_EXPORT
79
+ std::optional<int32_t> UnwrapVarChar(const DataType& t);
80
+
81
+ /// Return true if t is IntervalYear, otherwise false
82
+ ARROW_ENGINE_EXPORT
83
+ bool UnwrapIntervalYear(const DataType&);
84
+
85
+ /// Return true if t is IntervalDay, otherwise false
86
+ ARROW_ENGINE_EXPORT
87
+ bool UnwrapIntervalDay(const DataType&);
88
+
89
+ } // namespace engine
90
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/options.h ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // This API is EXPERIMENTAL.
19
+
20
+ #pragma once
21
+
22
+ #include <functional>
23
+ #include <string>
24
+ #include <vector>
25
+
26
+ #include "arrow/acero/exec_plan.h"
27
+ #include "arrow/acero/options.h"
28
+ #include "arrow/compute/type_fwd.h"
29
+ #include "arrow/engine/substrait/type_fwd.h"
30
+ #include "arrow/engine/substrait/visibility.h"
31
+ #include "arrow/type_fwd.h"
32
+
33
+ namespace arrow {
34
+ namespace engine {
35
+
36
+ /// How strictly to adhere to the input structure when converting between Substrait and
37
+ /// Acero representations of a plan. This allows the user to trade conversion accuracy
38
+ /// for performance and lenience.
39
+ enum class ARROW_ENGINE_EXPORT ConversionStrictness {
40
+ /// When a primitive is used at the input that doesn't have an exact match at the
41
+ /// output, reject the conversion. This effectively asserts that there is no (known)
42
+ /// information loss in the conversion, and that plans should either round-trip back and
43
+ /// forth exactly or not at all. This option is primarily intended for testing and
44
+ /// debugging.
45
+ EXACT_ROUNDTRIP,
46
+
47
+ /// When a primitive is used at the input that doesn't have an exact match at the
48
+ /// output, attempt to model it with some collection of primitives at the output. This
49
+ /// means that even if the incoming plan is completely optimal by some metric, the
50
+ /// returned plan is fairly likely to not be optimal anymore, and round-trips back and
51
+ /// forth may make the plan increasingly suboptimal. However, every primitive at the
52
+ /// output can be (manually) traced back to exactly one primitive at the input, which
53
+ /// may be useful when debugging.
54
+ PRESERVE_STRUCTURE,
55
+
56
+ /// Behaves like PRESERVE_STRUCTURE, but prefers performance over structural accuracy.
57
+ /// Basic optimizations *may* be applied, in order to attempt to not regress in terms of
58
+ /// plan performance: if the incoming plan was already aggressively optimized, the goal
59
+ /// is for the output plan to not be less performant. In practical use cases, this is
60
+ /// probably the option you want.
61
+ ///
62
+ /// Note that no guarantees are made on top of PRESERVE_STRUCTURE. Past and future
63
+ /// versions of Arrow may even ignore this option entirely and treat it exactly like
64
+ /// PRESERVE_STRUCTURE.
65
+ BEST_EFFORT,
66
+ };
67
+
68
+ using NamedTableProvider = std::function<Result<acero::Declaration>(
69
+ const std::vector<std::string>&, const Schema&)>;
70
+ static NamedTableProvider kDefaultNamedTableProvider;
71
+
72
+ using NamedTapProvider = std::function<Result<acero::Declaration>(
73
+ const std::string&, std::vector<acero::Declaration::Input>, const std::string&,
74
+ std::shared_ptr<Schema>)>;
75
+
76
+ class ARROW_ENGINE_EXPORT ExtensionDetails {
77
+ public:
78
+ virtual ~ExtensionDetails() = default;
79
+ };
80
+
81
+ class ARROW_ENGINE_EXPORT ExtensionProvider {
82
+ public:
83
+ virtual ~ExtensionProvider() = default;
84
+ virtual Result<DeclarationInfo> MakeRel(const ConversionOptions& conv_opts,
85
+ const std::vector<DeclarationInfo>& inputs,
86
+ const ExtensionDetails& ext_details,
87
+ const ExtensionSet& ext_set) = 0;
88
+ };
89
+
90
+ /// \brief Get the default extension provider
91
+ ARROW_ENGINE_EXPORT std::shared_ptr<ExtensionProvider> default_extension_provider();
92
+ /// \brief Set the default extension provider
93
+ ///
94
+ /// \param[in] provider the new provider to be set as default
95
+ ARROW_ENGINE_EXPORT void set_default_extension_provider(
96
+ const std::shared_ptr<ExtensionProvider>& provider);
97
+
98
+ ARROW_ENGINE_EXPORT NamedTapProvider default_named_tap_provider();
99
+
100
+ ARROW_ENGINE_EXPORT void set_default_named_tap_provider(NamedTapProvider provider);
101
+
102
+ /// Options that control the conversion between Substrait and Acero representations of a
103
+ /// plan.
104
+ struct ARROW_ENGINE_EXPORT ConversionOptions {
105
+ ConversionOptions()
106
+ : strictness(ConversionStrictness::BEST_EFFORT),
107
+ named_table_provider(kDefaultNamedTableProvider),
108
+ named_tap_provider(default_named_tap_provider()),
109
+ extension_provider(default_extension_provider()),
110
+ allow_arrow_extensions(false) {}
111
+
112
+ /// \brief How strictly the converter should adhere to the structure of the input.
113
+ ConversionStrictness strictness;
114
+ /// \brief A custom strategy to be used for providing named tables
115
+ ///
116
+ /// The default behavior will return an invalid status if the plan has any
117
+ /// named table relations.
118
+ NamedTableProvider named_table_provider;
119
+ /// \brief A custom strategy to be used for obtaining a tap declaration
120
+ ///
121
+ /// The default provider returns an error
122
+ NamedTapProvider named_tap_provider;
123
+ /// \brief A custom strategy to be used for providing relation infos.
124
+ ///
125
+ /// The default behavior will provide for relations known to Arrow.
126
+ std::shared_ptr<ExtensionProvider> extension_provider;
127
+ /// \brief If true then Arrow-specific types and functions will be allowed
128
+ ///
129
+ /// Set to false to create plans that are more likely to be compatible with non-Arrow
130
+ /// engines
131
+ bool allow_arrow_extensions;
132
+ };
133
+
134
+ } // namespace engine
135
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/relation.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
+ #pragma once
19
+
20
+ #include <memory>
21
+
22
+ #include "arrow/acero/exec_plan.h"
23
+ #include "arrow/compute/api_aggregate.h"
24
+ #include "arrow/engine/substrait/visibility.h"
25
+ #include "arrow/type_fwd.h"
26
+
27
+ namespace arrow {
28
+ namespace engine {
29
+
30
+ /// Execution information resulting from converting a Substrait relation.
31
+ struct ARROW_ENGINE_EXPORT DeclarationInfo {
32
+ /// The compute declaration produced thus far.
33
+ acero::Declaration declaration;
34
+
35
+ std::shared_ptr<Schema> output_schema;
36
+ };
37
+
38
+ /// Information resulting from converting a Substrait plan
39
+ struct ARROW_ENGINE_EXPORT PlanInfo {
40
+ /// The root declaration.
41
+ ///
42
+ /// Only plans containing a single top-level relation are supported and so this will
43
+ /// represent that relation.
44
+ ///
45
+ /// This should technically be a RelRoot but some producers use a simple Rel here and so
46
+ /// Acero currently supports that case.
47
+ DeclarationInfo root;
48
+ /// The names of the output fields
49
+ ///
50
+ /// If `root` was created from a simple Rel then this will be empty
51
+ std::vector<std::string> names;
52
+ };
53
+
54
+ /// An expression whose output has a name
55
+ struct ARROW_ENGINE_EXPORT NamedExpression {
56
+ /// An expression
57
+ compute::Expression expression;
58
+ // An optional name to assign to the output, may be the empty string
59
+ std::string name;
60
+ };
61
+
62
+ /// A collection of expressions bound to a common schema
63
+ struct ARROW_ENGINE_EXPORT BoundExpressions {
64
+ /// The expressions
65
+ std::vector<NamedExpression> named_expressions;
66
+ /// The schema that all the expressions are bound to
67
+ std::shared_ptr<Schema> schema;
68
+ };
69
+
70
+ } // namespace engine
71
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/serde.h ADDED
@@ -0,0 +1,331 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // This API is EXPERIMENTAL.
19
+
20
+ #pragma once
21
+
22
+ #include <functional>
23
+ #include <memory>
24
+ #include <string>
25
+ #include <string_view>
26
+ #include <vector>
27
+
28
+ #include "arrow/compute/type_fwd.h"
29
+ #include "arrow/dataset/type_fwd.h"
30
+ #include "arrow/engine/substrait/options.h"
31
+ #include "arrow/engine/substrait/relation.h"
32
+ #include "arrow/engine/substrait/type_fwd.h"
33
+ #include "arrow/engine/substrait/visibility.h"
34
+ #include "arrow/result.h"
35
+ #include "arrow/status.h"
36
+ #include "arrow/type_fwd.h"
37
+ #include "arrow/util/macros.h"
38
+
39
+ namespace arrow {
40
+ namespace engine {
41
+
42
+ /// \brief Serialize an Acero Plan to a binary protobuf Substrait message
43
+ ///
44
+ /// \param[in] declaration the Acero declaration to serialize.
45
+ /// This declaration is the sink relation of the Acero plan.
46
+ /// \param[in,out] ext_set the extension mapping to use; may be updated to add
47
+ /// \param[in] conversion_options options to control how the conversion is done
48
+ ///
49
+ /// \return a buffer containing the protobuf serialization of the Acero relation
50
+ ARROW_ENGINE_EXPORT
51
+ Result<std::shared_ptr<Buffer>> SerializePlan(
52
+ const acero::Declaration& declaration, ExtensionSet* ext_set,
53
+ const ConversionOptions& conversion_options = {});
54
+
55
+ /// \brief Serialize expressions to a Substrait message
56
+ ///
57
+ /// \param[in] bound_expressions the expressions to serialize.
58
+ /// \param[in] conversion_options options to control how the conversion is done
59
+ /// \param[in,out] ext_set the extension mapping to use, optional, only needed
60
+ /// if you want to control the value of function anchors
61
+ /// to mirror a previous serialization / deserialization.
62
+ /// Will be updated if new functions are encountered
63
+ ARROW_ENGINE_EXPORT
64
+ Result<std::shared_ptr<Buffer>> SerializeExpressions(
65
+ const BoundExpressions& bound_expressions,
66
+ const ConversionOptions& conversion_options = {}, ExtensionSet* ext_set = NULLPTR);
67
+
68
+ /// Factory function type for generating the node that consumes the batches produced by
69
+ /// each toplevel Substrait relation when deserializing a Substrait Plan.
70
+ using ConsumerFactory = std::function<std::shared_ptr<acero::SinkNodeConsumer>()>;
71
+
72
+ /// \brief Deserializes a Substrait Plan message to a list of ExecNode declarations
73
+ ///
74
+ /// The output of each top-level Substrait relation will be sent to a caller supplied
75
+ /// consumer function provided by consumer_factory
76
+ ///
77
+ /// \param[in] buf a buffer containing the protobuf serialization of a Substrait Plan
78
+ /// message
79
+ /// \param[in] consumer_factory factory function for generating the node that consumes
80
+ /// the batches produced by each toplevel Substrait relation
81
+ /// \param[in] registry an extension-id-registry to use, or null for the default one.
82
+ /// \param[out] ext_set_out if non-null, the extension mapping used by the Substrait
83
+ /// Plan is returned here.
84
+ /// \param[in] conversion_options options to control how the conversion is to be done.
85
+ /// \return a vector of ExecNode declarations, one for each toplevel relation in the
86
+ /// Substrait Plan
87
+ ARROW_ENGINE_EXPORT Result<std::vector<acero::Declaration>> DeserializePlans(
88
+ const Buffer& buf, const ConsumerFactory& consumer_factory,
89
+ const ExtensionIdRegistry* registry = NULLPTR, ExtensionSet* ext_set_out = NULLPTR,
90
+ const ConversionOptions& conversion_options = {});
91
+
92
+ /// \brief Deserializes a single-relation Substrait Plan message to an execution plan
93
+ ///
94
+ /// The output of each top-level Substrait relation will be sent to a caller supplied
95
+ /// consumer function provided by consumer_factory
96
+ ///
97
+ /// \param[in] buf a buffer containing the protobuf serialization of a Substrait Plan
98
+ /// message
99
+ /// \param[in] consumer node that consumes the batches produced by each toplevel Substrait
100
+ /// relation
101
+ /// \param[in] registry an extension-id-registry to use, or null for the default one.
102
+ /// \param[out] ext_set_out if non-null, the extension mapping used by the Substrait
103
+ /// \param[in] conversion_options options to control how the conversion is to be done.
104
+ /// Plan is returned here.
105
+ /// \return an ExecPlan for the Substrait Plan
106
+ ARROW_ENGINE_EXPORT Result<std::shared_ptr<acero::ExecPlan>> DeserializePlan(
107
+ const Buffer& buf, const std::shared_ptr<acero::SinkNodeConsumer>& consumer,
108
+ const ExtensionIdRegistry* registry = NULLPTR, ExtensionSet* ext_set_out = NULLPTR,
109
+ const ConversionOptions& conversion_options = {});
110
+
111
+ /// Factory function type for generating the write options of a node consuming the batches
112
+ /// produced by each toplevel Substrait relation when deserializing a Substrait Plan.
113
+ using WriteOptionsFactory = std::function<std::shared_ptr<dataset::WriteNodeOptions>()>;
114
+
115
+ /// \brief Deserializes a Substrait Plan message to a list of ExecNode declarations
116
+ ///
117
+ /// The output of each top-level Substrait relation will be written to a filesystem.
118
+ /// `write_options_factory` can be used to control write behavior.
119
+ ///
120
+ /// \param[in] buf a buffer containing the protobuf serialization of a Substrait Plan
121
+ /// message
122
+ /// \param[in] write_options_factory factory function for generating the write options of
123
+ /// a node consuming the batches produced by each toplevel Substrait relation
124
+ /// \param[in] registry an extension-id-registry to use, or null for the default one.
125
+ /// \param[out] ext_set_out if non-null, the extension mapping used by the Substrait
126
+ /// Plan is returned here.
127
+ /// \param[in] conversion_options options to control how the conversion is to be done.
128
+ /// \return a vector of ExecNode declarations, one for each toplevel relation in the
129
+ /// Substrait Plan
130
+ ARROW_ENGINE_EXPORT Result<std::vector<acero::Declaration>> DeserializePlans(
131
+ const Buffer& buf, const WriteOptionsFactory& write_options_factory,
132
+ const ExtensionIdRegistry* registry = NULLPTR, ExtensionSet* ext_set_out = NULLPTR,
133
+ const ConversionOptions& conversion_options = {});
134
+
135
+ /// \brief Deserializes a single-relation Substrait Plan message to an execution plan
136
+ ///
137
+ /// The output of the single Substrait relation will be written to a filesystem.
138
+ /// `write_options_factory` can be used to control write behavior.
139
+ ///
140
+ /// \param[in] buf a buffer containing the protobuf serialization of a Substrait Plan
141
+ /// message
142
+ /// \param[in] write_options write options of a node consuming the batches produced by
143
+ /// each toplevel Substrait relation
144
+ /// \param[in] registry an extension-id-registry to use, or null for the default one.
145
+ /// \param[out] ext_set_out if non-null, the extension mapping used by the Substrait
146
+ /// Plan is returned here.
147
+ /// \param[in] conversion_options options to control how the conversion is to be done.
148
+ /// \return an ExecPlan for the Substrait Plan
149
+ ARROW_ENGINE_EXPORT Result<std::shared_ptr<acero::ExecPlan>> DeserializePlan(
150
+ const Buffer& buf, const std::shared_ptr<dataset::WriteNodeOptions>& write_options,
151
+ const ExtensionIdRegistry* registry = NULLPTR, ExtensionSet* ext_set_out = NULLPTR,
152
+ const ConversionOptions& conversion_options = {});
153
+
154
+ /// \brief Deserializes a Substrait Plan message to a Declaration
155
+ ///
156
+ /// The plan will not contain any sink nodes and will be suitable for use in any
157
+ /// of the arrow::compute::DeclarationToXyz methods.
158
+ ///
159
+ /// \param[in] buf a buffer containing the protobuf serialization of a Substrait Plan
160
+ /// message
161
+ /// \param[in] registry an extension-id-registry to use, or null for the default one.
162
+ /// \param[out] ext_set_out if non-null, the extension mapping used by the Substrait
163
+ /// Plan is returned here.
164
+ /// \param[in] conversion_options options to control how the conversion is to be done.
165
+ /// \return A declaration representing the Substrait plan
166
+ ARROW_ENGINE_EXPORT Result<PlanInfo> DeserializePlan(
167
+ const Buffer& buf, const ExtensionIdRegistry* registry = NULLPTR,
168
+ ExtensionSet* ext_set_out = NULLPTR,
169
+ const ConversionOptions& conversion_options = {});
170
+
171
+ /// \brief Deserialize a Substrait ExtendedExpression message to the corresponding Arrow
172
+ /// type
173
+ ///
174
+ /// \param[in] buf a buffer containing the protobuf serialization of a collection of bound
175
+ /// expressions
176
+ /// \param[in] registry an extension-id-registry to use, or null for the default one
177
+ /// \param[in] conversion_options options to control how the conversion is done
178
+ /// \param[out] ext_set_out if non-null, the extension mapping used by the Substrait
179
+ /// message is returned here.
180
+ /// \return A collection of expressions and a common input schema they are bound to
181
+ ARROW_ENGINE_EXPORT Result<BoundExpressions> DeserializeExpressions(
182
+ const Buffer& buf, const ExtensionIdRegistry* registry = NULLPTR,
183
+ const ConversionOptions& conversion_options = {},
184
+ ExtensionSet* ext_set_out = NULLPTR);
185
+
186
+ /// \brief Deserializes a Substrait Type message to the corresponding Arrow type
187
+ ///
188
+ /// \param[in] buf a buffer containing the protobuf serialization of a Substrait Type
189
+ /// message
190
+ /// \param[in] ext_set the extension mapping to use, normally provided by the
191
+ /// surrounding Plan message
192
+ /// \param[in] conversion_options options to control how the conversion is to be done.
193
+ /// \return the corresponding Arrow data type
194
+ ARROW_ENGINE_EXPORT
195
+ Result<std::shared_ptr<DataType>> DeserializeType(
196
+ const Buffer& buf, const ExtensionSet& ext_set,
197
+ const ConversionOptions& conversion_options = {});
198
+
199
+ /// \brief Serializes an Arrow type to a Substrait Type message
200
+ ///
201
+ /// \param[in] type the Arrow data type to serialize
202
+ /// \param[in,out] ext_set the extension mapping to use; may be updated to add a
203
+ /// mapping for the given type
204
+ /// \param[in] conversion_options options to control how the conversion is to be done.
205
+ /// \return a buffer containing the protobuf serialization of the corresponding Substrait
206
+ /// Type message
207
+ ARROW_ENGINE_EXPORT
208
+ Result<std::shared_ptr<Buffer>> SerializeType(
209
+ const DataType& type, ExtensionSet* ext_set,
210
+ const ConversionOptions& conversion_options = {});
211
+
212
+ /// \brief Deserializes a Substrait NamedStruct message to an Arrow schema
213
+ ///
214
+ /// \param[in] buf a buffer containing the protobuf serialization of a Substrait
215
+ /// NamedStruct message
216
+ /// \param[in] ext_set the extension mapping to use, normally provided by the
217
+ /// surrounding Plan message
218
+ /// \param[in] conversion_options options to control how the conversion is to be done.
219
+ /// \return the corresponding Arrow schema
220
+ ARROW_ENGINE_EXPORT
221
+ Result<std::shared_ptr<Schema>> DeserializeSchema(
222
+ const Buffer& buf, const ExtensionSet& ext_set,
223
+ const ConversionOptions& conversion_options = {});
224
+
225
+ /// \brief Serializes an Arrow schema to a Substrait NamedStruct message
226
+ ///
227
+ /// \param[in] schema the Arrow schema to serialize
228
+ /// \param[in,out] ext_set the extension mapping to use; may be updated to add
229
+ /// mappings for the types used in the schema
230
+ /// \param[in] conversion_options options to control how the conversion is to be done.
231
+ /// \return a buffer containing the protobuf serialization of the corresponding Substrait
232
+ /// NamedStruct message
233
+ ARROW_ENGINE_EXPORT
234
+ Result<std::shared_ptr<Buffer>> SerializeSchema(
235
+ const Schema& schema, ExtensionSet* ext_set,
236
+ const ConversionOptions& conversion_options = {});
237
+
238
+ /// \brief Deserializes a Substrait Expression message to a compute expression
239
+ ///
240
+ /// \param[in] buf a buffer containing the protobuf serialization of a Substrait
241
+ /// Expression message
242
+ /// \param[in] ext_set the extension mapping to use, normally provided by the
243
+ /// surrounding Plan message
244
+ /// \param[in] conversion_options options to control how the conversion is to be done.
245
+ /// \return the corresponding Arrow compute expression
246
+ ARROW_ENGINE_EXPORT
247
+ Result<compute::Expression> DeserializeExpression(
248
+ const Buffer& buf, const ExtensionSet& ext_set,
249
+ const ConversionOptions& conversion_options = {});
250
+
251
+ /// \brief Serializes an Arrow compute expression to a Substrait Expression message
252
+ ///
253
+ /// \param[in] expr the Arrow compute expression to serialize
254
+ /// \param[in,out] ext_set the extension mapping to use; may be updated to add
255
+ /// mappings for the types used in the expression
256
+ /// \param[in] conversion_options options to control how the conversion is to be done.
257
+ /// \return a buffer containing the protobuf serialization of the corresponding Substrait
258
+ /// Expression message
259
+ ARROW_ENGINE_EXPORT
260
+ Result<std::shared_ptr<Buffer>> SerializeExpression(
261
+ const compute::Expression& expr, ExtensionSet* ext_set,
262
+ const ConversionOptions& conversion_options = {});
263
+
264
+ /// \brief Serialize an Acero Declaration to a binary protobuf Substrait message
265
+ ///
266
+ /// \param[in] declaration the Acero declaration to serialize
267
+ /// \param[in,out] ext_set the extension mapping to use; may be updated to add
268
+ /// \param[in] conversion_options options to control how the conversion is done
269
+ ///
270
+ /// \return a buffer containing the protobuf serialization of the Acero relation
271
+ ARROW_ENGINE_EXPORT Result<std::shared_ptr<Buffer>> SerializeRelation(
272
+ const acero::Declaration& declaration, ExtensionSet* ext_set,
273
+ const ConversionOptions& conversion_options = {});
274
+
275
+ /// \brief Deserializes a Substrait Rel (relation) message to an ExecNode declaration
276
+ ///
277
+ /// \param[in] buf a buffer containing the protobuf serialization of a Substrait
278
+ /// Rel message
279
+ /// \param[in] ext_set the extension mapping to use, normally provided by the
280
+ /// surrounding Plan message
281
+ /// \param[in] conversion_options options to control how the conversion is to be done.
282
+ /// \return the corresponding ExecNode declaration
283
+ ARROW_ENGINE_EXPORT Result<acero::Declaration> DeserializeRelation(
284
+ const Buffer& buf, const ExtensionSet& ext_set,
285
+ const ConversionOptions& conversion_options = {});
286
+
287
+ namespace internal {
288
+
289
+ /// \brief Checks whether two protobuf serializations of a particular Substrait message
290
+ /// type are equivalent
291
+ ///
292
+ /// Note that a binary comparison of the two buffers is insufficient. One reason for this
293
+ /// is that the fields of a message can be specified in any order in the serialization.
294
+ ///
295
+ /// \param[in] message_name the name of the Substrait message type to check
296
+ /// \param[in] l_buf buffer containing the first protobuf serialization to compare
297
+ /// \param[in] r_buf buffer containing the second protobuf serialization to compare
298
+ /// \return success if equivalent, failure if not
299
+ ARROW_ENGINE_EXPORT
300
+ Status CheckMessagesEquivalent(std::string_view message_name, const Buffer& l_buf,
301
+ const Buffer& r_buf);
302
+
303
+ /// \brief Utility function to convert a JSON serialization of a Substrait message to
304
+ /// its binary serialization
305
+ ///
306
+ /// \param[in] type_name the name of the Substrait message type to convert
307
+ /// \param[in] json the JSON string to convert
308
+ /// \param[in] ignore_unknown_fields if true then unknown fields will be ignored and
309
+ /// will not cause an error
310
+ ///
311
+ /// This should generally be true to allow consumption of plans from newer
312
+ /// producers but setting to false can be useful if you are testing
313
+ /// conformance to a specific Substrait version
314
+ /// \return a buffer filled with the binary protobuf serialization of message
315
+ ARROW_ENGINE_EXPORT
316
+ Result<std::shared_ptr<Buffer>> SubstraitFromJSON(std::string_view type_name,
317
+ std::string_view json,
318
+ bool ignore_unknown_fields = true);
319
+
320
+ /// \brief Utility function to convert a binary protobuf serialization of a Substrait
321
+ /// message to JSON
322
+ ///
323
+ /// \param[in] type_name the name of the Substrait message type to convert
324
+ /// \param[in] buf the buffer containing the binary protobuf serialization of the message
325
+ /// \return a JSON string representing the message
326
+ ARROW_ENGINE_EXPORT
327
+ Result<std::string> SubstraitToJSON(std::string_view type_name, const Buffer& buf);
328
+
329
+ } // namespace internal
330
+ } // namespace engine
331
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/test_plan_builder.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
+ // These utilities are for internal / unit test use only.
19
+ // They allow for the construction of simple Substrait plans
20
+ // programmatically without first requiring the construction
21
+ // of an ExecPlan
22
+
23
+ // These utilities have to be here, and not in a test_util.cc
24
+ // file (or in a unit test) because only one .so is allowed
25
+ // to include each .pb.h file or else protobuf will encounter
26
+ // global namespace conflicts.
27
+
28
+ #include <memory>
29
+ #include <string>
30
+ #include <unordered_map>
31
+ #include <vector>
32
+
33
+ #include "arrow/engine/substrait/visibility.h"
34
+ #include "arrow/result.h"
35
+ #include "arrow/type_fwd.h"
36
+
37
+ namespace arrow {
38
+ namespace engine {
39
+
40
+ struct Id;
41
+
42
+ namespace internal {
43
+
44
+ /// \brief Create a scan->project->sink plan for tests
45
+ ///
46
+ /// The plan will project one additional column using the function
47
+ /// defined by `function_id`, `arguments`, and data_types. `arguments`
48
+ /// and `data_types` should have the same length but only one of each
49
+ /// should be defined at each index.
50
+ ///
51
+ /// If `data_types` is defined at an index then the plan will create a
52
+ /// direct reference (starting at index 0 and increasing by 1 for each
53
+ /// argument of this type).
54
+ ///
55
+ /// If `arguments` is defined at an index then the plan will create an
56
+ /// enum argument with that value.
57
+ ARROW_ENGINE_EXPORT Result<std::shared_ptr<Buffer>> CreateScanProjectSubstrait(
58
+ Id function_id, const std::shared_ptr<Table>& input_table,
59
+ const std::vector<std::string>& arguments,
60
+ const std::unordered_map<std::string, std::vector<std::string>>& options,
61
+ const std::vector<std::shared_ptr<DataType>>& data_types,
62
+ const DataType& output_type);
63
+
64
+ /// \brief Create a scan->aggregate->sink plan for tests
65
+ ///
66
+ /// The plan will create an aggregate with one grouping set (defined by
67
+ /// key_idxs) and one measure. The measure will be a function
68
+ /// defined by `function_id` and direct references to `arg_idxs`.
69
+ ARROW_ENGINE_EXPORT Result<std::shared_ptr<Buffer>> CreateScanAggSubstrait(
70
+ Id function_id, const std::shared_ptr<Table>& input_table,
71
+ const std::vector<int>& key_idxs, const std::vector<int>& arg_idxs,
72
+ const DataType& output_type);
73
+
74
+ } // namespace internal
75
+ } // namespace engine
76
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/test_util.h ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/testing/gtest_util.h"
21
+ #include "arrow/util/vector.h"
22
+
23
+ #include <functional>
24
+ #include <random>
25
+ #include <string>
26
+ #include <string_view>
27
+ #include <vector>
28
+
29
+ #include "arrow/acero/exec_plan.h"
30
+ #include "arrow/compute/exec.h"
31
+ #include "arrow/compute/kernel.h"
32
+ #include "arrow/testing/visibility.h"
33
+ #include "arrow/util/async_generator.h"
34
+ #include "arrow/util/pcg_random.h"
35
+
36
+ namespace arrow {
37
+ namespace engine {
38
+
39
+ Result<std::shared_ptr<Table>> SortTableOnAllFields(const std::shared_ptr<Table>& tab);
40
+
41
+ void AssertTablesEqualIgnoringOrder(const std::shared_ptr<Table>& exp,
42
+ const std::shared_ptr<Table>& act);
43
+
44
+ } // namespace engine
45
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/type_fwd.h ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // This API is EXPERIMENTAL.
19
+
20
+ #pragma once
21
+
22
+ namespace arrow {
23
+ namespace engine {
24
+
25
+ class ExtensionIdRegistry;
26
+ class ExtensionSet;
27
+
28
+ struct ConversionOptions;
29
+ struct DeclarationInfo;
30
+
31
+ } // namespace engine
32
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/util.h ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/compute/type_fwd.h"
26
+ #include "arrow/engine/substrait/options.h"
27
+ #include "arrow/engine/substrait/type_fwd.h"
28
+ #include "arrow/engine/substrait/visibility.h"
29
+ #include "arrow/result.h"
30
+ #include "arrow/type_fwd.h"
31
+ #include "arrow/util/iterator.h"
32
+ #include "arrow/util/macros.h"
33
+
34
+ namespace arrow {
35
+
36
+ namespace engine {
37
+
38
+ using PythonTableProvider =
39
+ std::function<Result<std::shared_ptr<Table>>(const std::vector<std::string>&)>;
40
+
41
+ /// \brief Utility method to run a Substrait plan
42
+ /// \param substrait_buffer The plan to run, must be in binary protobuf format
43
+ /// \param registry A registry of extension functions to make available to the plan
44
+ /// If null then the default registry will be used.
45
+ /// \param memory_pool The memory pool the plan should use to make allocations.
46
+ /// \param func_registry A registry of functions used for execution expressions.
47
+ /// `registry` maps from Substrait function IDs to "names". These
48
+ /// names will be provided to `func_registry` to get the actual
49
+ /// kernel.
50
+ /// \param conversion_options Options to control plan deserialization
51
+ /// \param use_threads If True then the CPU thread pool will be used for CPU work. If
52
+ /// False then all work will be done on the calling thread.
53
+ /// \return A record batch reader that will read out the results
54
+ ARROW_ENGINE_EXPORT Result<std::shared_ptr<RecordBatchReader>> ExecuteSerializedPlan(
55
+ const Buffer& substrait_buffer, const ExtensionIdRegistry* registry = NULLPTR,
56
+ compute::FunctionRegistry* func_registry = NULLPTR,
57
+ const ConversionOptions& conversion_options = {}, bool use_threads = true,
58
+ MemoryPool* memory_pool = default_memory_pool());
59
+
60
+ /// \brief Get a Serialized Plan from a Substrait JSON plan.
61
+ /// This is a helper method for Python tests.
62
+ ARROW_ENGINE_EXPORT Result<std::shared_ptr<Buffer>> SerializeJsonPlan(
63
+ const std::string& substrait_json);
64
+
65
+ /// \brief Make a nested registry with the default registry as parent.
66
+ /// See arrow::engine::nested_extension_id_registry for details.
67
+ ARROW_ENGINE_EXPORT std::shared_ptr<ExtensionIdRegistry> MakeExtensionIdRegistry();
68
+
69
+ ARROW_ENGINE_EXPORT const std::string& default_extension_types_uri();
70
+
71
+ // TODO(ARROW-18145) Populate these from cmake files
72
+ constexpr uint32_t kSubstraitMajorVersion = 0;
73
+ constexpr uint32_t kSubstraitMinorVersion = 44;
74
+ constexpr uint32_t kSubstraitPatchVersion = 0;
75
+
76
+ constexpr uint32_t kSubstraitMinimumMajorVersion = 0;
77
+ constexpr uint32_t kSubstraitMinimumMinorVersion = 20;
78
+
79
+ Status CheckVersion(uint32_t major_version, uint32_t minor_version);
80
+
81
+ } // namespace engine
82
+
83
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/engine/substrait/visibility.h ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // TODO(westonpace): Once we have a proper engine module this file
19
+ // should be renamed arrow/engine/visibility.h
20
+ // This API is EXPERIMENTAL.
21
+
22
+ #pragma once
23
+
24
+ #if defined(_WIN32) || defined(__CYGWIN__)
25
+ #if defined(_MSC_VER)
26
+ #pragma warning(push)
27
+ #pragma warning(disable : 4251)
28
+ #else
29
+ #pragma GCC diagnostic ignored "-Wattributes"
30
+ #endif
31
+
32
+ #ifdef ARROW_ENGINE_STATIC
33
+ #define ARROW_ENGINE_EXPORT
34
+ #elif defined(ARROW_ENGINE_EXPORTING)
35
+ #define ARROW_ENGINE_EXPORT __declspec(dllexport)
36
+ #else
37
+ #define ARROW_ENGINE_EXPORT __declspec(dllimport)
38
+ #endif
39
+
40
+ #define ARROW_ENGINE_NO_EXPORT
41
+ #else // Not Windows
42
+ #ifndef ARROW_ENGINE_EXPORT
43
+ #define ARROW_ENGINE_EXPORT __attribute__((visibility("default")))
44
+ #endif
45
+ #ifndef ARROW_ENGINE_NO_EXPORT
46
+ #define ARROW_ENGINE_NO_EXPORT __attribute__((visibility("hidden")))
47
+ #endif
48
+ #endif // Non-Windows
49
+
50
+ #if defined(_MSC_VER)
51
+ #pragma warning(pop)
52
+ #endif
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/extension/fixed_shape_tensor.h ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 "arrow/extension_type.h"
19
+
20
+ namespace arrow {
21
+ namespace extension {
22
+
23
+ class ARROW_EXPORT FixedShapeTensorArray : public ExtensionArray {
24
+ public:
25
+ using ExtensionArray::ExtensionArray;
26
+
27
+ /// \brief Create a FixedShapeTensorArray from a Tensor
28
+ ///
29
+ /// This method will create a FixedShapeTensorArray from a Tensor, taking its first
30
+ /// dimension as the number of elements in the resulting array and the remaining
31
+ /// dimensions as the shape of the individual tensors. If Tensor provides strides,
32
+ /// they will be used to determine dimension permutation. Otherwise, row-major layout
33
+ /// (i.e. no permutation) will be assumed.
34
+ ///
35
+ /// \param[in] tensor The Tensor to convert to a FixedShapeTensorArray
36
+ static Result<std::shared_ptr<FixedShapeTensorArray>> FromTensor(
37
+ const std::shared_ptr<Tensor>& tensor);
38
+
39
+ /// \brief Create a Tensor from FixedShapeTensorArray
40
+ ///
41
+ /// This method will create a Tensor from a FixedShapeTensorArray, setting its first
42
+ /// dimension as length equal to the FixedShapeTensorArray's length and the remaining
43
+ /// dimensions as the FixedShapeTensorType's shape. Shape and dim_names will be
44
+ /// permuted according to permutation stored in the FixedShapeTensorType metadata.
45
+ const Result<std::shared_ptr<Tensor>> ToTensor() const;
46
+ };
47
+
48
+ /// \brief Concrete type class for constant-size Tensor data.
49
+ /// This is a canonical arrow extension type.
50
+ /// See: https://arrow.apache.org/docs/format/CanonicalExtensions.html
51
+ class ARROW_EXPORT FixedShapeTensorType : public ExtensionType {
52
+ public:
53
+ FixedShapeTensorType(const std::shared_ptr<DataType>& value_type, const int32_t& size,
54
+ const std::vector<int64_t>& shape,
55
+ const std::vector<int64_t>& permutation = {},
56
+ const std::vector<std::string>& dim_names = {})
57
+ : ExtensionType(fixed_size_list(value_type, size)),
58
+ value_type_(value_type),
59
+ shape_(shape),
60
+ permutation_(permutation),
61
+ dim_names_(dim_names) {}
62
+
63
+ std::string extension_name() const override { return "arrow.fixed_shape_tensor"; }
64
+ std::string ToString(bool show_metadata = false) const override;
65
+
66
+ /// Number of dimensions of tensor elements
67
+ size_t ndim() const { return shape_.size(); }
68
+
69
+ /// Shape of tensor elements
70
+ const std::vector<int64_t> shape() const { return shape_; }
71
+
72
+ /// Value type of tensor elements
73
+ const std::shared_ptr<DataType> value_type() const { return value_type_; }
74
+
75
+ /// Strides of tensor elements. Strides state offset in bytes between adjacent
76
+ /// elements along each dimension. In case permutation is non-empty strides are
77
+ /// computed from permuted tensor element's shape.
78
+ const std::vector<int64_t>& strides();
79
+
80
+ /// Permutation mapping from logical to physical memory layout of tensor elements
81
+ const std::vector<int64_t>& permutation() const { return permutation_; }
82
+
83
+ /// Dimension names of tensor elements. Dimensions are ordered physically.
84
+ const std::vector<std::string>& dim_names() const { return dim_names_; }
85
+
86
+ bool ExtensionEquals(const ExtensionType& other) const override;
87
+
88
+ std::string Serialize() const override;
89
+
90
+ Result<std::shared_ptr<DataType>> Deserialize(
91
+ std::shared_ptr<DataType> storage_type,
92
+ const std::string& serialized_data) const override;
93
+
94
+ /// Create a FixedShapeTensorArray from ArrayData
95
+ std::shared_ptr<Array> MakeArray(std::shared_ptr<ArrayData> data) const override;
96
+
97
+ /// \brief Create a Tensor from an ExtensionScalar from a FixedShapeTensorArray
98
+ ///
99
+ /// This method will return a Tensor from ExtensionScalar with strides
100
+ /// derived from shape and permutation of FixedShapeTensorType. Shape and
101
+ /// dim_names will be permuted according to permutation stored in the
102
+ /// FixedShapeTensorType metadata.
103
+ static Result<std::shared_ptr<Tensor>> MakeTensor(
104
+ const std::shared_ptr<ExtensionScalar>& scalar);
105
+
106
+ /// \brief Create a FixedShapeTensorType instance
107
+ static Result<std::shared_ptr<DataType>> Make(
108
+ const std::shared_ptr<DataType>& value_type, const std::vector<int64_t>& shape,
109
+ const std::vector<int64_t>& permutation = {},
110
+ const std::vector<std::string>& dim_names = {});
111
+
112
+ private:
113
+ std::shared_ptr<DataType> storage_type_;
114
+ std::shared_ptr<DataType> value_type_;
115
+ std::vector<int64_t> shape_;
116
+ std::vector<int64_t> strides_;
117
+ std::vector<int64_t> permutation_;
118
+ std::vector<std::string> dim_names_;
119
+ };
120
+
121
+ /// \brief Return a FixedShapeTensorType instance.
122
+ ARROW_EXPORT std::shared_ptr<DataType> fixed_shape_tensor(
123
+ const std::shared_ptr<DataType>& storage_type, const std::vector<int64_t>& shape,
124
+ const std::vector<int64_t>& permutation = {},
125
+ const std::vector<std::string>& dim_names = {});
126
+
127
+ } // namespace extension
128
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/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/io/buffered.h"
21
+ #include "arrow/io/compressed.h"
22
+ #include "arrow/io/file.h"
23
+ #include "arrow/io/hdfs.h"
24
+ #include "arrow/io/interfaces.h"
25
+ #include "arrow/io/memory.h"
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/buffered.h ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // Buffered stream implementations
19
+
20
+ #pragma once
21
+
22
+ #include <cstdint>
23
+ #include <memory>
24
+ #include <string_view>
25
+
26
+ #include "arrow/io/concurrency.h"
27
+ #include "arrow/io/interfaces.h"
28
+ #include "arrow/util/visibility.h"
29
+
30
+ namespace arrow {
31
+
32
+ class Buffer;
33
+ class MemoryPool;
34
+ class Status;
35
+
36
+ namespace io {
37
+
38
+ class ARROW_EXPORT BufferedOutputStream : public OutputStream {
39
+ public:
40
+ ~BufferedOutputStream() override;
41
+
42
+ /// \brief Create a buffered output stream wrapping the given output stream.
43
+ /// \param[in] buffer_size the size of the temporary write buffer
44
+ /// \param[in] pool a MemoryPool to use for allocations
45
+ /// \param[in] raw another OutputStream
46
+ /// \return the created BufferedOutputStream
47
+ static Result<std::shared_ptr<BufferedOutputStream>> Create(
48
+ int64_t buffer_size, MemoryPool* pool, std::shared_ptr<OutputStream> raw);
49
+
50
+ /// \brief Resize internal buffer
51
+ /// \param[in] new_buffer_size the new buffer size
52
+ /// \return Status
53
+ Status SetBufferSize(int64_t new_buffer_size);
54
+
55
+ /// \brief Return the current size of the internal buffer
56
+ int64_t buffer_size() const;
57
+
58
+ /// \brief Return the number of remaining bytes that have not been flushed to
59
+ /// the raw OutputStream
60
+ int64_t bytes_buffered() const;
61
+
62
+ /// \brief Flush any buffered writes and release the raw
63
+ /// OutputStream. Further operations on this object are invalid
64
+ /// \return the underlying OutputStream
65
+ Result<std::shared_ptr<OutputStream>> Detach();
66
+
67
+ // OutputStream interface
68
+
69
+ /// \brief Close the buffered output stream. This implicitly closes the
70
+ /// underlying raw output stream.
71
+ Status Close() override;
72
+ Status Abort() override;
73
+ bool closed() const override;
74
+
75
+ Result<int64_t> Tell() const override;
76
+ // Write bytes to the stream. Thread-safe
77
+ Status Write(const void* data, int64_t nbytes) override;
78
+ Status Write(const std::shared_ptr<Buffer>& data) override;
79
+
80
+ Status Flush() override;
81
+
82
+ /// \brief Return the underlying raw output stream.
83
+ std::shared_ptr<OutputStream> raw() const;
84
+
85
+ private:
86
+ explicit BufferedOutputStream(std::shared_ptr<OutputStream> raw, MemoryPool* pool);
87
+
88
+ class ARROW_NO_EXPORT Impl;
89
+ std::unique_ptr<Impl> impl_;
90
+ };
91
+
92
+ /// \class BufferedInputStream
93
+ /// \brief An InputStream that performs buffered reads from an unbuffered
94
+ /// InputStream, which can mitigate the overhead of many small reads in some
95
+ /// cases
96
+ class ARROW_EXPORT BufferedInputStream
97
+ : public internal::InputStreamConcurrencyWrapper<BufferedInputStream> {
98
+ public:
99
+ ~BufferedInputStream() override;
100
+
101
+ /// \brief Create a BufferedInputStream from a raw InputStream
102
+ /// \param[in] buffer_size the size of the temporary read buffer
103
+ /// \param[in] pool a MemoryPool to use for allocations
104
+ /// \param[in] raw a raw InputStream
105
+ /// \param[in] raw_read_bound a bound on the maximum number of bytes
106
+ /// to read from the raw input stream. The default -1 indicates that
107
+ /// it is unbounded
108
+ /// \return the created BufferedInputStream
109
+ static Result<std::shared_ptr<BufferedInputStream>> Create(
110
+ int64_t buffer_size, MemoryPool* pool, std::shared_ptr<InputStream> raw,
111
+ int64_t raw_read_bound = -1);
112
+
113
+ /// \brief Resize internal read buffer; calls to Read(...) will read at least
114
+ /// \param[in] new_buffer_size the new read buffer size
115
+ /// \return Status
116
+ Status SetBufferSize(int64_t new_buffer_size);
117
+
118
+ /// \brief Return the number of remaining bytes in the read buffer
119
+ int64_t bytes_buffered() const;
120
+
121
+ /// \brief Return the current size of the internal buffer
122
+ int64_t buffer_size() const;
123
+
124
+ /// \brief Release the raw InputStream. Any data buffered will be
125
+ /// discarded. Further operations on this object are invalid
126
+ /// \return raw the underlying InputStream
127
+ std::shared_ptr<InputStream> Detach();
128
+
129
+ /// \brief Return the unbuffered InputStream
130
+ std::shared_ptr<InputStream> raw() const;
131
+
132
+ // InputStream APIs
133
+
134
+ bool closed() const override;
135
+ Result<std::shared_ptr<const KeyValueMetadata>> ReadMetadata() override;
136
+ Future<std::shared_ptr<const KeyValueMetadata>> ReadMetadataAsync(
137
+ const IOContext& io_context) override;
138
+
139
+ private:
140
+ friend InputStreamConcurrencyWrapper<BufferedInputStream>;
141
+
142
+ explicit BufferedInputStream(std::shared_ptr<InputStream> raw, MemoryPool* pool,
143
+ int64_t raw_total_bytes_bound);
144
+
145
+ Status DoClose();
146
+ Status DoAbort() override;
147
+
148
+ /// \brief Returns the position of the buffered stream, though the position
149
+ /// of the unbuffered stream may be further advanced.
150
+ Result<int64_t> DoTell() const;
151
+
152
+ Result<int64_t> DoRead(int64_t nbytes, void* out);
153
+
154
+ /// \brief Read into buffer.
155
+ Result<std::shared_ptr<Buffer>> DoRead(int64_t nbytes);
156
+
157
+ /// \brief Return a zero-copy string view referencing buffered data,
158
+ /// but do not advance the position of the stream. Buffers data and
159
+ /// expands the buffer size if necessary
160
+ Result<std::string_view> DoPeek(int64_t nbytes) override;
161
+
162
+ class ARROW_NO_EXPORT Impl;
163
+ std::unique_ptr<Impl> impl_;
164
+ };
165
+
166
+ } // namespace io
167
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/caching.h ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 <string>
23
+ #include <utility>
24
+ #include <vector>
25
+
26
+ #include "arrow/io/interfaces.h"
27
+ #include "arrow/util/type_fwd.h"
28
+ #include "arrow/util/visibility.h"
29
+
30
+ namespace arrow {
31
+ namespace io {
32
+
33
+ struct ARROW_EXPORT CacheOptions {
34
+ static constexpr double kDefaultIdealBandwidthUtilizationFrac = 0.9;
35
+ static constexpr int64_t kDefaultMaxIdealRequestSizeMib = 64;
36
+
37
+ /// \brief The maximum distance in bytes between two consecutive
38
+ /// ranges; beyond this value, ranges are not combined
39
+ int64_t hole_size_limit;
40
+ /// \brief The maximum size in bytes of a combined range; if
41
+ /// combining two consecutive ranges would produce a range of a
42
+ /// size greater than this, they are not combined
43
+ int64_t range_size_limit;
44
+ /// \brief A lazy cache does not perform any I/O until requested.
45
+ /// lazy = false: request all byte ranges when PreBuffer or WillNeed is called.
46
+ /// lazy = True, prefetch_limit = 0: request merged byte ranges only after the reader
47
+ /// needs them.
48
+ /// lazy = True, prefetch_limit = k: prefetch up to k merged byte ranges ahead of the
49
+ /// range that is currently being read.
50
+ bool lazy;
51
+ /// \brief The maximum number of ranges to be prefetched. This is only used
52
+ /// for lazy cache to asynchronously read some ranges after reading the target range.
53
+ int64_t prefetch_limit = 0;
54
+
55
+ bool operator==(const CacheOptions& other) const {
56
+ return hole_size_limit == other.hole_size_limit &&
57
+ range_size_limit == other.range_size_limit && lazy == other.lazy &&
58
+ prefetch_limit == other.prefetch_limit;
59
+ }
60
+
61
+ /// \brief Construct CacheOptions from network storage metrics (e.g. S3).
62
+ ///
63
+ /// \param[in] time_to_first_byte_millis Seek-time or Time-To-First-Byte (TTFB) in
64
+ /// milliseconds, also called call setup latency of a new read request.
65
+ /// The value is a positive integer.
66
+ /// \param[in] transfer_bandwidth_mib_per_sec Data transfer Bandwidth (BW) in MiB/sec
67
+ /// (per connection).
68
+ /// The value is a positive integer.
69
+ /// \param[in] ideal_bandwidth_utilization_frac Transfer bandwidth utilization fraction
70
+ /// (per connection) to maximize the net data load.
71
+ /// The value is a positive double precision number less than 1.
72
+ /// \param[in] max_ideal_request_size_mib The maximum single data request size (in MiB)
73
+ /// to maximize the net data load.
74
+ /// The value is a positive integer.
75
+ /// \return A new instance of CacheOptions.
76
+ static CacheOptions MakeFromNetworkMetrics(
77
+ int64_t time_to_first_byte_millis, int64_t transfer_bandwidth_mib_per_sec,
78
+ double ideal_bandwidth_utilization_frac = kDefaultIdealBandwidthUtilizationFrac,
79
+ int64_t max_ideal_request_size_mib = kDefaultMaxIdealRequestSizeMib);
80
+
81
+ static CacheOptions Defaults();
82
+ static CacheOptions LazyDefaults();
83
+ };
84
+
85
+ namespace internal {
86
+
87
+ /// \brief A read cache designed to hide IO latencies when reading.
88
+ ///
89
+ /// This class takes multiple byte ranges that an application expects to read, and
90
+ /// coalesces them into fewer, larger read requests, which benefits performance on some
91
+ /// filesystems, particularly remote ones like Amazon S3. By default, it also issues
92
+ /// these read requests in parallel up front.
93
+ ///
94
+ /// To use:
95
+ /// 1. Cache() the ranges you expect to read in the future. Ideally, these ranges have
96
+ /// the exact offset and length that will later be read. The cache will combine those
97
+ /// ranges according to parameters (see constructor).
98
+ ///
99
+ /// By default, the cache will also start fetching the combined ranges in parallel in
100
+ /// the background, unless CacheOptions.lazy is set.
101
+ ///
102
+ /// 2. Call WaitFor() to be notified when the given ranges have been read. If
103
+ /// CacheOptions.lazy is set, I/O will be triggered in the background here instead.
104
+ /// This can be done in parallel (e.g. if parsing a file, call WaitFor() for each
105
+ /// chunk of the file that can be parsed in parallel).
106
+ ///
107
+ /// 3. Call Read() to retrieve the actual data for the given ranges.
108
+ /// A synchronous application may skip WaitFor() and just call Read() - it will still
109
+ /// benefit from coalescing and parallel fetching.
110
+ class ARROW_EXPORT ReadRangeCache {
111
+ public:
112
+ static constexpr int64_t kDefaultHoleSizeLimit = 8192;
113
+ static constexpr int64_t kDefaultRangeSizeLimit = 32 * 1024 * 1024;
114
+
115
+ /// Construct a read cache with default
116
+ explicit ReadRangeCache(std::shared_ptr<RandomAccessFile> file, IOContext ctx)
117
+ : ReadRangeCache(file, file.get(), std::move(ctx), CacheOptions::Defaults()) {}
118
+
119
+ /// Construct a read cache with given options
120
+ explicit ReadRangeCache(std::shared_ptr<RandomAccessFile> file, IOContext ctx,
121
+ CacheOptions options)
122
+ : ReadRangeCache(file, file.get(), std::move(ctx), options) {}
123
+
124
+ /// Construct a read cache with an unowned file
125
+ ReadRangeCache(RandomAccessFile* file, IOContext ctx, CacheOptions options)
126
+ : ReadRangeCache(NULLPTR, file, std::move(ctx), options) {}
127
+
128
+ ~ReadRangeCache();
129
+
130
+ /// \brief Cache the given ranges in the background.
131
+ ///
132
+ /// The caller must ensure that the ranges do not overlap with each other,
133
+ /// nor with previously cached ranges. Otherwise, behaviour will be undefined.
134
+ Status Cache(std::vector<ReadRange> ranges);
135
+
136
+ /// \brief Read a range previously given to Cache().
137
+ Result<std::shared_ptr<Buffer>> Read(ReadRange range);
138
+
139
+ /// \brief Wait until all ranges added so far have been cached.
140
+ Future<> Wait();
141
+
142
+ /// \brief Wait until all given ranges have been cached.
143
+ Future<> WaitFor(std::vector<ReadRange> ranges);
144
+
145
+ protected:
146
+ struct Impl;
147
+ struct LazyImpl;
148
+
149
+ ReadRangeCache(std::shared_ptr<RandomAccessFile> owned_file, RandomAccessFile* file,
150
+ IOContext ctx, CacheOptions options);
151
+
152
+ std::unique_ptr<Impl> impl_;
153
+ };
154
+
155
+ } // namespace internal
156
+ } // namespace io
157
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/compressed.h ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // Compressed stream implementations
19
+
20
+ #pragma once
21
+
22
+ #include <memory>
23
+ #include <string>
24
+
25
+ #include "arrow/io/concurrency.h"
26
+ #include "arrow/io/interfaces.h"
27
+ #include "arrow/util/visibility.h"
28
+
29
+ namespace arrow {
30
+
31
+ class MemoryPool;
32
+ class Status;
33
+
34
+ namespace util {
35
+
36
+ class Codec;
37
+
38
+ } // namespace util
39
+
40
+ namespace io {
41
+
42
+ class ARROW_EXPORT CompressedOutputStream : public OutputStream {
43
+ public:
44
+ ~CompressedOutputStream() override;
45
+
46
+ /// \brief Create a compressed output stream wrapping the given output stream.
47
+ ///
48
+ /// The codec must be capable of streaming compression. Some codecs,
49
+ /// like Snappy, are not able to do so.
50
+ static Result<std::shared_ptr<CompressedOutputStream>> Make(
51
+ util::Codec* codec, const std::shared_ptr<OutputStream>& raw,
52
+ MemoryPool* pool = default_memory_pool());
53
+
54
+ // OutputStream interface
55
+
56
+ /// \brief Close the compressed output stream. This implicitly closes the
57
+ /// underlying raw output stream.
58
+ Status Close() override;
59
+ Status Abort() override;
60
+ bool closed() const override;
61
+
62
+ Result<int64_t> Tell() const override;
63
+
64
+ Status Write(const void* data, int64_t nbytes) override;
65
+ /// \cond FALSE
66
+ using Writable::Write;
67
+ /// \endcond
68
+ Status Flush() override;
69
+
70
+ /// \brief Return the underlying raw output stream.
71
+ std::shared_ptr<OutputStream> raw() const;
72
+
73
+ private:
74
+ ARROW_DISALLOW_COPY_AND_ASSIGN(CompressedOutputStream);
75
+
76
+ CompressedOutputStream() = default;
77
+
78
+ class ARROW_NO_EXPORT Impl;
79
+ std::unique_ptr<Impl> impl_;
80
+ };
81
+
82
+ class ARROW_EXPORT CompressedInputStream
83
+ : public internal::InputStreamConcurrencyWrapper<CompressedInputStream> {
84
+ public:
85
+ ~CompressedInputStream() override;
86
+
87
+ /// \brief Create a compressed input stream wrapping the given input stream.
88
+ ///
89
+ /// The codec must be capable of streaming decompression. Some codecs,
90
+ /// like Snappy, are not able to do so.
91
+ static Result<std::shared_ptr<CompressedInputStream>> Make(
92
+ util::Codec* codec, const std::shared_ptr<InputStream>& raw,
93
+ MemoryPool* pool = default_memory_pool());
94
+
95
+ // InputStream interface
96
+
97
+ bool closed() const override;
98
+ Result<std::shared_ptr<const KeyValueMetadata>> ReadMetadata() override;
99
+ Future<std::shared_ptr<const KeyValueMetadata>> ReadMetadataAsync(
100
+ const IOContext& io_context) override;
101
+
102
+ /// \brief Return the underlying raw input stream.
103
+ std::shared_ptr<InputStream> raw() const;
104
+
105
+ private:
106
+ friend InputStreamConcurrencyWrapper<CompressedInputStream>;
107
+ ARROW_DISALLOW_COPY_AND_ASSIGN(CompressedInputStream);
108
+
109
+ CompressedInputStream() = default;
110
+
111
+ /// \brief Close the compressed input stream. This implicitly closes the
112
+ /// underlying raw input stream.
113
+ Status DoClose();
114
+ Status DoAbort() override;
115
+ Result<int64_t> DoTell() const;
116
+ Result<int64_t> DoRead(int64_t nbytes, void* out);
117
+ Result<std::shared_ptr<Buffer>> DoRead(int64_t nbytes);
118
+
119
+ class ARROW_NO_EXPORT Impl;
120
+ std::unique_ptr<Impl> impl_;
121
+ };
122
+
123
+ } // namespace io
124
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/concurrency.h ADDED
@@ -0,0 +1,263 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/result.h"
24
+ #include "arrow/status.h"
25
+ #include "arrow/util/checked_cast.h"
26
+ #include "arrow/util/macros.h"
27
+ #include "arrow/util/visibility.h"
28
+
29
+ namespace arrow {
30
+ namespace io {
31
+ namespace internal {
32
+
33
+ template <class LockType>
34
+ class SharedLockGuard {
35
+ public:
36
+ explicit SharedLockGuard(LockType* lock) : lock_(lock) { lock_->LockShared(); }
37
+
38
+ ~SharedLockGuard() { lock_->UnlockShared(); }
39
+
40
+ protected:
41
+ LockType* lock_;
42
+ };
43
+
44
+ template <class LockType>
45
+ class ExclusiveLockGuard {
46
+ public:
47
+ explicit ExclusiveLockGuard(LockType* lock) : lock_(lock) { lock_->LockExclusive(); }
48
+
49
+ ~ExclusiveLockGuard() { lock_->UnlockExclusive(); }
50
+
51
+ protected:
52
+ LockType* lock_;
53
+ };
54
+
55
+ // Debug concurrency checker that marks "shared" and "exclusive" code sections,
56
+ // aborting if the concurrency rules get violated. Does nothing in release mode.
57
+ // Note that we intentionally use the same class declaration in debug and
58
+ // release builds in order to avoid runtime failures when e.g. loading a
59
+ // release-built DLL with a debug-built application, or the reverse.
60
+
61
+ class ARROW_EXPORT SharedExclusiveChecker {
62
+ public:
63
+ SharedExclusiveChecker();
64
+ void LockShared();
65
+ void UnlockShared();
66
+ void LockExclusive();
67
+ void UnlockExclusive();
68
+
69
+ SharedLockGuard<SharedExclusiveChecker> shared_guard() {
70
+ return SharedLockGuard<SharedExclusiveChecker>(this);
71
+ }
72
+
73
+ ExclusiveLockGuard<SharedExclusiveChecker> exclusive_guard() {
74
+ return ExclusiveLockGuard<SharedExclusiveChecker>(this);
75
+ }
76
+
77
+ protected:
78
+ struct Impl;
79
+ std::shared_ptr<Impl> impl_;
80
+ };
81
+
82
+ // Concurrency wrappers for IO classes that check the correctness of
83
+ // concurrent calls to various methods. It is not necessary to wrap all
84
+ // IO classes with these, only a few core classes that get used in tests.
85
+ //
86
+ // We're not using virtual inheritance here as virtual bases have poorly
87
+ // understood semantic overhead which we'd be passing on to implementers
88
+ // and users of these interfaces. Instead, we just duplicate the method
89
+ // wrappers between those two classes.
90
+
91
+ template <class Derived>
92
+ class ARROW_EXPORT InputStreamConcurrencyWrapper : public InputStream {
93
+ public:
94
+ Status Close() final {
95
+ auto guard = lock_.exclusive_guard();
96
+ return derived()->DoClose();
97
+ }
98
+
99
+ Status Abort() final {
100
+ auto guard = lock_.exclusive_guard();
101
+ return derived()->DoAbort();
102
+ }
103
+
104
+ Result<int64_t> Tell() const final {
105
+ auto guard = lock_.exclusive_guard();
106
+ return derived()->DoTell();
107
+ }
108
+
109
+ Result<int64_t> Read(int64_t nbytes, void* out) final {
110
+ auto guard = lock_.exclusive_guard();
111
+ return derived()->DoRead(nbytes, out);
112
+ }
113
+
114
+ Result<std::shared_ptr<Buffer>> Read(int64_t nbytes) final {
115
+ auto guard = lock_.exclusive_guard();
116
+ return derived()->DoRead(nbytes);
117
+ }
118
+
119
+ Result<std::string_view> Peek(int64_t nbytes) final {
120
+ auto guard = lock_.exclusive_guard();
121
+ return derived()->DoPeek(nbytes);
122
+ }
123
+
124
+ /*
125
+ Methods to implement in derived class:
126
+
127
+ Status DoClose();
128
+ Result<int64_t> DoTell() const;
129
+ Result<int64_t> DoRead(int64_t nbytes, void* out);
130
+ Result<std::shared_ptr<Buffer>> DoRead(int64_t nbytes);
131
+
132
+ And optionally:
133
+
134
+ Status DoAbort() override;
135
+ Result<std::string_view> DoPeek(int64_t nbytes) override;
136
+
137
+ These methods should be protected in the derived class and
138
+ InputStreamConcurrencyWrapper declared as a friend with
139
+
140
+ friend InputStreamConcurrencyWrapper<derived>;
141
+ */
142
+
143
+ protected:
144
+ // Default implementations. They are virtual because the derived class may
145
+ // have derived classes itself.
146
+ virtual Status DoAbort() { return derived()->DoClose(); }
147
+
148
+ virtual Result<std::string_view> DoPeek(int64_t ARROW_ARG_UNUSED(nbytes)) {
149
+ return Status::NotImplemented("Peek not implemented");
150
+ }
151
+
152
+ Derived* derived() { return ::arrow::internal::checked_cast<Derived*>(this); }
153
+
154
+ const Derived* derived() const {
155
+ return ::arrow::internal::checked_cast<const Derived*>(this);
156
+ }
157
+
158
+ mutable SharedExclusiveChecker lock_;
159
+ };
160
+
161
+ template <class Derived>
162
+ class ARROW_EXPORT RandomAccessFileConcurrencyWrapper : public RandomAccessFile {
163
+ public:
164
+ Status Close() final {
165
+ auto guard = lock_.exclusive_guard();
166
+ return derived()->DoClose();
167
+ }
168
+
169
+ Status Abort() final {
170
+ auto guard = lock_.exclusive_guard();
171
+ return derived()->DoAbort();
172
+ }
173
+
174
+ Result<int64_t> Tell() const final {
175
+ auto guard = lock_.exclusive_guard();
176
+ return derived()->DoTell();
177
+ }
178
+
179
+ Result<int64_t> Read(int64_t nbytes, void* out) final {
180
+ auto guard = lock_.exclusive_guard();
181
+ return derived()->DoRead(nbytes, out);
182
+ }
183
+
184
+ Result<std::shared_ptr<Buffer>> Read(int64_t nbytes) final {
185
+ auto guard = lock_.exclusive_guard();
186
+ return derived()->DoRead(nbytes);
187
+ }
188
+
189
+ Result<std::string_view> Peek(int64_t nbytes) final {
190
+ auto guard = lock_.exclusive_guard();
191
+ return derived()->DoPeek(nbytes);
192
+ }
193
+
194
+ Status Seek(int64_t position) final {
195
+ auto guard = lock_.exclusive_guard();
196
+ return derived()->DoSeek(position);
197
+ }
198
+
199
+ Result<int64_t> GetSize() final {
200
+ auto guard = lock_.shared_guard();
201
+ return derived()->DoGetSize();
202
+ }
203
+
204
+ // NOTE: ReadAt doesn't use stream pointer, but it is allowed to update it
205
+ // (it's the case on Windows when using ReadFileEx).
206
+ // So any method that relies on the current position (even if it doesn't
207
+ // update it, such as Peek) cannot run in parallel with ReadAt and has
208
+ // to use the exclusive_guard.
209
+
210
+ Result<int64_t> ReadAt(int64_t position, int64_t nbytes, void* out) final {
211
+ auto guard = lock_.shared_guard();
212
+ return derived()->DoReadAt(position, nbytes, out);
213
+ }
214
+
215
+ Result<std::shared_ptr<Buffer>> ReadAt(int64_t position, int64_t nbytes) final {
216
+ auto guard = lock_.shared_guard();
217
+ return derived()->DoReadAt(position, nbytes);
218
+ }
219
+
220
+ /*
221
+ Methods to implement in derived class:
222
+
223
+ Status DoClose();
224
+ Result<int64_t> DoTell() const;
225
+ Result<int64_t> DoRead(int64_t nbytes, void* out);
226
+ Result<std::shared_ptr<Buffer>> DoRead(int64_t nbytes);
227
+ Status DoSeek(int64_t position);
228
+ Result<int64_t> DoGetSize()
229
+ Result<int64_t> DoReadAt(int64_t position, int64_t nbytes, void* out);
230
+ Result<std::shared_ptr<Buffer>> DoReadAt(int64_t position, int64_t nbytes);
231
+
232
+ And optionally:
233
+
234
+ Status DoAbort() override;
235
+ Result<std::string_view> DoPeek(int64_t nbytes) override;
236
+
237
+ These methods should be protected in the derived class and
238
+ RandomAccessFileConcurrencyWrapper declared as a friend with
239
+
240
+ friend RandomAccessFileConcurrencyWrapper<derived>;
241
+ */
242
+
243
+ protected:
244
+ // Default implementations. They are virtual because the derived class may
245
+ // have derived classes itself.
246
+ virtual Status DoAbort() { return derived()->DoClose(); }
247
+
248
+ virtual Result<std::string_view> DoPeek(int64_t ARROW_ARG_UNUSED(nbytes)) {
249
+ return Status::NotImplemented("Peek not implemented");
250
+ }
251
+
252
+ Derived* derived() { return ::arrow::internal::checked_cast<Derived*>(this); }
253
+
254
+ const Derived* derived() const {
255
+ return ::arrow::internal::checked_cast<const Derived*>(this);
256
+ }
257
+
258
+ mutable SharedExclusiveChecker lock_;
259
+ };
260
+
261
+ } // namespace internal
262
+ } // namespace io
263
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/file.h ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // IO interface implementations for OS files
19
+
20
+ #pragma once
21
+
22
+ #include <cstdint>
23
+ #include <memory>
24
+ #include <string>
25
+ #include <vector>
26
+
27
+ #include "arrow/io/concurrency.h"
28
+ #include "arrow/io/interfaces.h"
29
+ #include "arrow/util/visibility.h"
30
+
31
+ namespace arrow {
32
+
33
+ class Buffer;
34
+ class MemoryPool;
35
+ class Status;
36
+
37
+ namespace io {
38
+
39
+ /// \brief An operating system file open in write-only mode.
40
+ class ARROW_EXPORT FileOutputStream : public OutputStream {
41
+ public:
42
+ ~FileOutputStream() override;
43
+
44
+ /// \brief Open a local file for writing, truncating any existing file
45
+ /// \param[in] path with UTF8 encoding
46
+ /// \param[in] append append to existing file, otherwise truncate to 0 bytes
47
+ /// \return an open FileOutputStream
48
+ ///
49
+ /// When opening a new file, any existing file with the indicated path is
50
+ /// truncated to 0 bytes, deleting any existing data
51
+ static Result<std::shared_ptr<FileOutputStream>> Open(const std::string& path,
52
+ bool append = false);
53
+
54
+ /// \brief Open a file descriptor for writing. The underlying file isn't
55
+ /// truncated.
56
+ /// \param[in] fd file descriptor
57
+ /// \return an open FileOutputStream
58
+ ///
59
+ /// The file descriptor becomes owned by the OutputStream, and will be closed
60
+ /// on Close() or destruction.
61
+ static Result<std::shared_ptr<FileOutputStream>> Open(int fd);
62
+
63
+ // OutputStream interface
64
+ Status Close() override;
65
+ bool closed() const override;
66
+ Result<int64_t> Tell() const override;
67
+
68
+ // Write bytes to the stream. Thread-safe
69
+ Status Write(const void* data, int64_t nbytes) override;
70
+ /// \cond FALSE
71
+ using Writable::Write;
72
+ /// \endcond
73
+
74
+ int file_descriptor() const;
75
+
76
+ private:
77
+ FileOutputStream();
78
+
79
+ class ARROW_NO_EXPORT FileOutputStreamImpl;
80
+ std::unique_ptr<FileOutputStreamImpl> impl_;
81
+ };
82
+
83
+ /// \brief An operating system file open in read-only mode.
84
+ ///
85
+ /// Reads through this implementation are unbuffered. If many small reads
86
+ /// need to be issued, it is recommended to use a buffering layer for good
87
+ /// performance.
88
+ class ARROW_EXPORT ReadableFile
89
+ : public internal::RandomAccessFileConcurrencyWrapper<ReadableFile> {
90
+ public:
91
+ ~ReadableFile() override;
92
+
93
+ /// \brief Open a local file for reading
94
+ /// \param[in] path with UTF8 encoding
95
+ /// \param[in] pool a MemoryPool for memory allocations
96
+ /// \return ReadableFile instance
97
+ static Result<std::shared_ptr<ReadableFile>> Open(
98
+ const std::string& path, MemoryPool* pool = default_memory_pool());
99
+
100
+ /// \brief Open a local file for reading
101
+ /// \param[in] fd file descriptor
102
+ /// \param[in] pool a MemoryPool for memory allocations
103
+ /// \return ReadableFile instance
104
+ ///
105
+ /// The file descriptor becomes owned by the ReadableFile, and will be closed
106
+ /// on Close() or destruction.
107
+ static Result<std::shared_ptr<ReadableFile>> Open(
108
+ int fd, MemoryPool* pool = default_memory_pool());
109
+
110
+ bool closed() const override;
111
+
112
+ int file_descriptor() const;
113
+
114
+ Status WillNeed(const std::vector<ReadRange>& ranges) override;
115
+
116
+ private:
117
+ friend RandomAccessFileConcurrencyWrapper<ReadableFile>;
118
+
119
+ explicit ReadableFile(MemoryPool* pool);
120
+
121
+ Status DoClose();
122
+ Result<int64_t> DoTell() const;
123
+ Result<int64_t> DoRead(int64_t nbytes, void* buffer);
124
+ Result<std::shared_ptr<Buffer>> DoRead(int64_t nbytes);
125
+
126
+ /// \brief Thread-safe implementation of ReadAt
127
+ Result<int64_t> DoReadAt(int64_t position, int64_t nbytes, void* out);
128
+
129
+ /// \brief Thread-safe implementation of ReadAt
130
+ Result<std::shared_ptr<Buffer>> DoReadAt(int64_t position, int64_t nbytes);
131
+
132
+ Result<int64_t> DoGetSize();
133
+ Status DoSeek(int64_t position);
134
+
135
+ class ARROW_NO_EXPORT ReadableFileImpl;
136
+ std::unique_ptr<ReadableFileImpl> impl_;
137
+ };
138
+
139
+ /// \brief A file interface that uses memory-mapped files for memory interactions
140
+ ///
141
+ /// This implementation supports zero-copy reads. The same class is used
142
+ /// for both reading and writing.
143
+ ///
144
+ /// If opening a file in a writable mode, it is not truncated first as with
145
+ /// FileOutputStream.
146
+ class ARROW_EXPORT MemoryMappedFile : public ReadWriteFileInterface {
147
+ public:
148
+ ~MemoryMappedFile() override;
149
+
150
+ /// Create new file with indicated size, return in read/write mode
151
+ static Result<std::shared_ptr<MemoryMappedFile>> Create(const std::string& path,
152
+ int64_t size);
153
+
154
+ // mmap() with whole file
155
+ static Result<std::shared_ptr<MemoryMappedFile>> Open(const std::string& path,
156
+ FileMode::type mode);
157
+
158
+ // mmap() with a region of file, the offset must be a multiple of the page size
159
+ static Result<std::shared_ptr<MemoryMappedFile>> Open(const std::string& path,
160
+ FileMode::type mode,
161
+ const int64_t offset,
162
+ const int64_t length);
163
+
164
+ Status Close() override;
165
+
166
+ bool closed() const override;
167
+
168
+ Result<int64_t> Tell() const override;
169
+
170
+ Status Seek(int64_t position) override;
171
+
172
+ // Required by RandomAccessFile, copies memory into out. Not thread-safe
173
+ Result<int64_t> Read(int64_t nbytes, void* out) override;
174
+
175
+ // Zero copy read, moves position pointer. Not thread-safe
176
+ Result<std::shared_ptr<Buffer>> Read(int64_t nbytes) override;
177
+
178
+ // Zero-copy read, leaves position unchanged. Acquires a reader lock
179
+ // for the duration of slice creation (typically very short). Is thread-safe.
180
+ Result<std::shared_ptr<Buffer>> ReadAt(int64_t position, int64_t nbytes) override;
181
+
182
+ // Raw copy of the memory at specified position. Thread-safe, but
183
+ // locks out other readers for the duration of memcpy. Prefer the
184
+ // zero copy method
185
+ Result<int64_t> ReadAt(int64_t position, int64_t nbytes, void* out) override;
186
+
187
+ // Synchronous ReadAsync override
188
+ Future<std::shared_ptr<Buffer>> ReadAsync(const IOContext&, int64_t position,
189
+ int64_t nbytes) override;
190
+
191
+ Status WillNeed(const std::vector<ReadRange>& ranges) override;
192
+
193
+ bool supports_zero_copy() const override;
194
+
195
+ /// Write data at the current position in the file. Thread-safe
196
+ Status Write(const void* data, int64_t nbytes) override;
197
+ /// \cond FALSE
198
+ using Writable::Write;
199
+ /// \endcond
200
+
201
+ /// Set the size of the map to new_size.
202
+ Status Resize(int64_t new_size);
203
+
204
+ /// Write data at a particular position in the file. Thread-safe
205
+ Status WriteAt(int64_t position, const void* data, int64_t nbytes) override;
206
+
207
+ Result<int64_t> GetSize() override;
208
+
209
+ int file_descriptor() const;
210
+
211
+ private:
212
+ MemoryMappedFile();
213
+
214
+ Status WriteInternal(const void* data, int64_t nbytes);
215
+
216
+ class ARROW_NO_EXPORT MemoryMap;
217
+ std::shared_ptr<MemoryMap> memory_map_;
218
+ };
219
+
220
+ } // namespace io
221
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/hdfs.h ADDED
@@ -0,0 +1,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 <string>
23
+ #include <unordered_map>
24
+ #include <vector>
25
+
26
+ #include "arrow/io/interfaces.h"
27
+ #include "arrow/util/macros.h"
28
+ #include "arrow/util/visibility.h"
29
+
30
+ namespace arrow {
31
+
32
+ class Buffer;
33
+ class MemoryPool;
34
+ class Status;
35
+
36
+ namespace io {
37
+
38
+ class HdfsReadableFile;
39
+ class HdfsOutputStream;
40
+
41
+ /// DEPRECATED. Use the FileSystem API in arrow::fs instead.
42
+ struct ObjectType {
43
+ enum type { FILE, DIRECTORY };
44
+ };
45
+
46
+ /// DEPRECATED. Use the FileSystem API in arrow::fs instead.
47
+ struct ARROW_EXPORT FileStatistics {
48
+ /// Size of file, -1 if finding length is unsupported
49
+ int64_t size;
50
+ ObjectType::type kind;
51
+ };
52
+
53
+ class ARROW_EXPORT FileSystem {
54
+ public:
55
+ virtual ~FileSystem() = default;
56
+
57
+ virtual Status MakeDirectory(const std::string& path) = 0;
58
+
59
+ virtual Status DeleteDirectory(const std::string& path) = 0;
60
+
61
+ virtual Status GetChildren(const std::string& path,
62
+ std::vector<std::string>* listing) = 0;
63
+
64
+ virtual Status Rename(const std::string& src, const std::string& dst) = 0;
65
+
66
+ virtual Status Stat(const std::string& path, FileStatistics* stat) = 0;
67
+ };
68
+
69
+ struct HdfsPathInfo {
70
+ ObjectType::type kind;
71
+
72
+ std::string name;
73
+ std::string owner;
74
+ std::string group;
75
+
76
+ // Access times in UNIX timestamps (seconds)
77
+ int64_t size;
78
+ int64_t block_size;
79
+
80
+ int32_t last_modified_time;
81
+ int32_t last_access_time;
82
+
83
+ int16_t replication;
84
+ int16_t permissions;
85
+ };
86
+
87
+ struct HdfsConnectionConfig {
88
+ std::string host;
89
+ int port;
90
+ std::string user;
91
+ std::string kerb_ticket;
92
+ std::unordered_map<std::string, std::string> extra_conf;
93
+ };
94
+
95
+ class ARROW_EXPORT HadoopFileSystem : public FileSystem {
96
+ public:
97
+ ~HadoopFileSystem() override;
98
+
99
+ // Connect to an HDFS cluster given a configuration
100
+ //
101
+ // @param config (in): configuration for connecting
102
+ // @param fs (out): the created client
103
+ // @returns Status
104
+ static Status Connect(const HdfsConnectionConfig* config,
105
+ std::shared_ptr<HadoopFileSystem>* fs);
106
+
107
+ // Create directory and all parents
108
+ //
109
+ // @param path (in): absolute HDFS path
110
+ // @returns Status
111
+ Status MakeDirectory(const std::string& path) override;
112
+
113
+ // Delete file or directory
114
+ // @param path absolute path to data
115
+ // @param recursive if path is a directory, delete contents as well
116
+ // @returns error status on failure
117
+ Status Delete(const std::string& path, bool recursive = false);
118
+
119
+ Status DeleteDirectory(const std::string& path) override;
120
+
121
+ // Disconnect from cluster
122
+ //
123
+ // @returns Status
124
+ Status Disconnect();
125
+
126
+ // @param path (in): absolute HDFS path
127
+ // @returns bool, true if the path exists, false if not (or on error)
128
+ bool Exists(const std::string& path);
129
+
130
+ // @param path (in): absolute HDFS path
131
+ // @param info (out)
132
+ // @returns Status
133
+ Status GetPathInfo(const std::string& path, HdfsPathInfo* info);
134
+
135
+ // @param nbytes (out): total capacity of the filesystem
136
+ // @returns Status
137
+ Status GetCapacity(int64_t* nbytes);
138
+
139
+ // @param nbytes (out): total bytes used of the filesystem
140
+ // @returns Status
141
+ Status GetUsed(int64_t* nbytes);
142
+
143
+ Status GetChildren(const std::string& path, std::vector<std::string>* listing) override;
144
+
145
+ /// List directory contents
146
+ ///
147
+ /// If path is a relative path, returned values will be absolute paths or URIs
148
+ /// starting from the current working directory.
149
+ Status ListDirectory(const std::string& path, std::vector<HdfsPathInfo>* listing);
150
+
151
+ /// Return the filesystem's current working directory.
152
+ ///
153
+ /// The working directory is the base path for all relative paths given to
154
+ /// other APIs.
155
+ /// NOTE: this actually returns a URI.
156
+ Status GetWorkingDirectory(std::string* out);
157
+
158
+ /// Change
159
+ ///
160
+ /// @param path file path to change
161
+ /// @param owner pass null for no change
162
+ /// @param group pass null for no change
163
+ Status Chown(const std::string& path, const char* owner, const char* group);
164
+
165
+ /// Change path permissions
166
+ ///
167
+ /// \param path Absolute path in file system
168
+ /// \param mode Mode bitset
169
+ /// \return Status
170
+ Status Chmod(const std::string& path, int mode);
171
+
172
+ // Move file or directory from source path to destination path within the
173
+ // current filesystem
174
+ Status Rename(const std::string& src, const std::string& dst) override;
175
+
176
+ Status Copy(const std::string& src, const std::string& dst);
177
+
178
+ Status Move(const std::string& src, const std::string& dst);
179
+
180
+ Status Stat(const std::string& path, FileStatistics* stat) override;
181
+
182
+ // TODO(wesm): GetWorkingDirectory, SetWorkingDirectory
183
+
184
+ // Open an HDFS file in READ mode. Returns error
185
+ // status if the file is not found.
186
+ //
187
+ // @param path complete file path
188
+ Status OpenReadable(const std::string& path, int32_t buffer_size,
189
+ std::shared_ptr<HdfsReadableFile>* file);
190
+
191
+ Status OpenReadable(const std::string& path, int32_t buffer_size,
192
+ const io::IOContext& io_context,
193
+ std::shared_ptr<HdfsReadableFile>* file);
194
+
195
+ Status OpenReadable(const std::string& path, std::shared_ptr<HdfsReadableFile>* file);
196
+
197
+ Status OpenReadable(const std::string& path, const io::IOContext& io_context,
198
+ std::shared_ptr<HdfsReadableFile>* file);
199
+
200
+ // FileMode::WRITE options
201
+ // @param path complete file path
202
+ // @param buffer_size 0 by default
203
+ // @param replication 0 by default
204
+ // @param default_block_size 0 by default
205
+ Status OpenWritable(const std::string& path, bool append, int32_t buffer_size,
206
+ int16_t replication, int64_t default_block_size,
207
+ std::shared_ptr<HdfsOutputStream>* file);
208
+
209
+ Status OpenWritable(const std::string& path, bool append,
210
+ std::shared_ptr<HdfsOutputStream>* file);
211
+
212
+ private:
213
+ friend class HdfsReadableFile;
214
+ friend class HdfsOutputStream;
215
+
216
+ class ARROW_NO_EXPORT HadoopFileSystemImpl;
217
+ std::unique_ptr<HadoopFileSystemImpl> impl_;
218
+
219
+ HadoopFileSystem();
220
+ ARROW_DISALLOW_COPY_AND_ASSIGN(HadoopFileSystem);
221
+ };
222
+
223
+ class ARROW_EXPORT HdfsReadableFile : public RandomAccessFile {
224
+ public:
225
+ ~HdfsReadableFile() override;
226
+
227
+ Status Close() override;
228
+
229
+ bool closed() const override;
230
+
231
+ // NOTE: If you wish to read a particular range of a file in a multithreaded
232
+ // context, you may prefer to use ReadAt to avoid locking issues
233
+ Result<int64_t> Read(int64_t nbytes, void* out) override;
234
+ Result<std::shared_ptr<Buffer>> Read(int64_t nbytes) override;
235
+ Result<int64_t> ReadAt(int64_t position, int64_t nbytes, void* out) override;
236
+ Result<std::shared_ptr<Buffer>> ReadAt(int64_t position, int64_t nbytes) override;
237
+
238
+ Status Seek(int64_t position) override;
239
+ Result<int64_t> Tell() const override;
240
+ Result<int64_t> GetSize() override;
241
+
242
+ private:
243
+ explicit HdfsReadableFile(const io::IOContext&);
244
+
245
+ class ARROW_NO_EXPORT HdfsReadableFileImpl;
246
+ std::unique_ptr<HdfsReadableFileImpl> impl_;
247
+
248
+ friend class HadoopFileSystem::HadoopFileSystemImpl;
249
+
250
+ ARROW_DISALLOW_COPY_AND_ASSIGN(HdfsReadableFile);
251
+ };
252
+
253
+ // Naming this file OutputStream because it does not support seeking (like the
254
+ // WritableFile interface)
255
+ class ARROW_EXPORT HdfsOutputStream : public OutputStream {
256
+ public:
257
+ ~HdfsOutputStream() override;
258
+
259
+ Status Close() override;
260
+
261
+ bool closed() const override;
262
+
263
+ using OutputStream::Write;
264
+ Status Write(const void* buffer, int64_t nbytes) override;
265
+
266
+ Status Flush() override;
267
+
268
+ Result<int64_t> Tell() const override;
269
+
270
+ private:
271
+ class ARROW_NO_EXPORT HdfsOutputStreamImpl;
272
+ std::unique_ptr<HdfsOutputStreamImpl> impl_;
273
+
274
+ friend class HadoopFileSystem::HadoopFileSystemImpl;
275
+
276
+ HdfsOutputStream();
277
+
278
+ ARROW_DISALLOW_COPY_AND_ASSIGN(HdfsOutputStream);
279
+ };
280
+
281
+ ARROW_EXPORT Status HaveLibHdfs();
282
+
283
+ } // namespace io
284
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/interfaces.h ADDED
@@ -0,0 +1,362 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 <string>
23
+ #include <string_view>
24
+ #include <vector>
25
+
26
+ #include "arrow/io/type_fwd.h"
27
+ #include "arrow/type_fwd.h"
28
+ #include "arrow/util/cancel.h"
29
+ #include "arrow/util/macros.h"
30
+ #include "arrow/util/type_fwd.h"
31
+ #include "arrow/util/visibility.h"
32
+
33
+ namespace arrow {
34
+ namespace io {
35
+
36
+ struct ReadRange {
37
+ int64_t offset;
38
+ int64_t length;
39
+
40
+ friend bool operator==(const ReadRange& left, const ReadRange& right) {
41
+ return (left.offset == right.offset && left.length == right.length);
42
+ }
43
+ friend bool operator!=(const ReadRange& left, const ReadRange& right) {
44
+ return !(left == right);
45
+ }
46
+
47
+ bool Contains(const ReadRange& other) const {
48
+ return (offset <= other.offset && offset + length >= other.offset + other.length);
49
+ }
50
+ };
51
+
52
+ /// EXPERIMENTAL: options provider for IO tasks
53
+ ///
54
+ /// Includes an Executor (which will be used to execute asynchronous reads),
55
+ /// a MemoryPool (which will be used to allocate buffers when zero copy reads
56
+ /// are not possible), and an external id (in case the executor receives tasks from
57
+ /// multiple sources and must distinguish tasks associated with this IOContext).
58
+ struct ARROW_EXPORT IOContext {
59
+ // No specified executor: will use a global IO thread pool
60
+ IOContext() : IOContext(default_memory_pool(), StopToken::Unstoppable()) {}
61
+
62
+ explicit IOContext(StopToken stop_token)
63
+ : IOContext(default_memory_pool(), std::move(stop_token)) {}
64
+
65
+ explicit IOContext(MemoryPool* pool, StopToken stop_token = StopToken::Unstoppable());
66
+
67
+ explicit IOContext(MemoryPool* pool, ::arrow::internal::Executor* executor,
68
+ StopToken stop_token = StopToken::Unstoppable(),
69
+ int64_t external_id = -1)
70
+ : pool_(pool),
71
+ executor_(executor),
72
+ external_id_(external_id),
73
+ stop_token_(std::move(stop_token)) {}
74
+
75
+ explicit IOContext(::arrow::internal::Executor* executor,
76
+ StopToken stop_token = StopToken::Unstoppable(),
77
+ int64_t external_id = -1)
78
+ : pool_(default_memory_pool()),
79
+ executor_(executor),
80
+ external_id_(external_id),
81
+ stop_token_(std::move(stop_token)) {}
82
+
83
+ MemoryPool* pool() const { return pool_; }
84
+
85
+ ::arrow::internal::Executor* executor() const { return executor_; }
86
+
87
+ // An application-specific ID, forwarded to executor task submissions
88
+ int64_t external_id() const { return external_id_; }
89
+
90
+ StopToken stop_token() const { return stop_token_; }
91
+
92
+ private:
93
+ MemoryPool* pool_;
94
+ ::arrow::internal::Executor* executor_;
95
+ int64_t external_id_;
96
+ StopToken stop_token_;
97
+ };
98
+
99
+ class ARROW_EXPORT FileInterface : public std::enable_shared_from_this<FileInterface> {
100
+ public:
101
+ virtual ~FileInterface() = 0;
102
+
103
+ /// \brief Close the stream cleanly
104
+ ///
105
+ /// For writable streams, this will attempt to flush any pending data
106
+ /// before releasing the underlying resource.
107
+ ///
108
+ /// After Close() is called, closed() returns true and the stream is not
109
+ /// available for further operations.
110
+ virtual Status Close() = 0;
111
+
112
+ /// \brief Close the stream asynchronously
113
+ ///
114
+ /// By default, this will just submit the synchronous Close() to the
115
+ /// default I/O thread pool. Subclasses may implement this in a more
116
+ /// efficient manner.
117
+ virtual Future<> CloseAsync();
118
+
119
+ /// \brief Close the stream abruptly
120
+ ///
121
+ /// This method does not guarantee that any pending data is flushed.
122
+ /// It merely releases any underlying resource used by the stream for
123
+ /// its operation.
124
+ ///
125
+ /// After Abort() is called, closed() returns true and the stream is not
126
+ /// available for further operations.
127
+ virtual Status Abort();
128
+
129
+ /// \brief Return the position in this stream
130
+ virtual Result<int64_t> Tell() const = 0;
131
+
132
+ /// \brief Return whether the stream is closed
133
+ virtual bool closed() const = 0;
134
+
135
+ FileMode::type mode() const { return mode_; }
136
+
137
+ protected:
138
+ FileInterface() : mode_(FileMode::READ) {}
139
+ FileMode::type mode_;
140
+ void set_mode(FileMode::type mode) { mode_ = mode; }
141
+
142
+ private:
143
+ ARROW_DISALLOW_COPY_AND_ASSIGN(FileInterface);
144
+ };
145
+
146
+ class ARROW_EXPORT Seekable {
147
+ public:
148
+ virtual ~Seekable() = default;
149
+ virtual Status Seek(int64_t position) = 0;
150
+ };
151
+
152
+ class ARROW_EXPORT Writable {
153
+ public:
154
+ virtual ~Writable() = default;
155
+
156
+ /// \brief Write the given data to the stream
157
+ ///
158
+ /// This method always processes the bytes in full. Depending on the
159
+ /// semantics of the stream, the data may be written out immediately,
160
+ /// held in a buffer, or written asynchronously. In the case where
161
+ /// the stream buffers the data, it will be copied. To avoid potentially
162
+ /// large copies, use the Write variant that takes an owned Buffer.
163
+ virtual Status Write(const void* data, int64_t nbytes) = 0;
164
+
165
+ /// \brief Write the given data to the stream
166
+ ///
167
+ /// Since the Buffer owns its memory, this method can avoid a copy if
168
+ /// buffering is required. See Write(const void*, int64_t) for details.
169
+ virtual Status Write(const std::shared_ptr<Buffer>& data);
170
+
171
+ /// \brief Flush buffered bytes, if any
172
+ virtual Status Flush();
173
+
174
+ Status Write(std::string_view data);
175
+ };
176
+
177
+ class ARROW_EXPORT Readable {
178
+ public:
179
+ virtual ~Readable() = default;
180
+
181
+ /// \brief Read data from current file position.
182
+ ///
183
+ /// Read at most `nbytes` from the current file position into `out`.
184
+ /// The number of bytes read is returned.
185
+ virtual Result<int64_t> Read(int64_t nbytes, void* out) = 0;
186
+
187
+ /// \brief Read data from current file position.
188
+ ///
189
+ /// Read at most `nbytes` from the current file position. Less bytes may
190
+ /// be read if EOF is reached. This method updates the current file position.
191
+ ///
192
+ /// In some cases (e.g. a memory-mapped file), this method may avoid a
193
+ /// memory copy.
194
+ virtual Result<std::shared_ptr<Buffer>> Read(int64_t nbytes) = 0;
195
+
196
+ /// EXPERIMENTAL: The IOContext associated with this file.
197
+ ///
198
+ /// By default, this is the same as default_io_context(), but it may be
199
+ /// overridden by subclasses.
200
+ virtual const IOContext& io_context() const;
201
+ };
202
+
203
+ class ARROW_EXPORT OutputStream : virtual public FileInterface, public Writable {
204
+ protected:
205
+ OutputStream() = default;
206
+ };
207
+
208
+ class ARROW_EXPORT InputStream : virtual public FileInterface, virtual public Readable {
209
+ public:
210
+ /// \brief Advance or skip stream indicated number of bytes
211
+ /// \param[in] nbytes the number to move forward
212
+ /// \return Status
213
+ Status Advance(int64_t nbytes);
214
+
215
+ /// \brief Return zero-copy string_view to upcoming bytes.
216
+ ///
217
+ /// Do not modify the stream position. The view becomes invalid after
218
+ /// any operation on the stream. May trigger buffering if the requested
219
+ /// size is larger than the number of buffered bytes.
220
+ ///
221
+ /// May return NotImplemented on streams that don't support it.
222
+ ///
223
+ /// \param[in] nbytes the maximum number of bytes to see
224
+ virtual Result<std::string_view> Peek(int64_t nbytes);
225
+
226
+ /// \brief Return true if InputStream is capable of zero copy Buffer reads
227
+ ///
228
+ /// Zero copy reads imply the use of Buffer-returning Read() overloads.
229
+ virtual bool supports_zero_copy() const;
230
+
231
+ /// \brief Read and return stream metadata
232
+ ///
233
+ /// If the stream implementation doesn't support metadata, empty metadata
234
+ /// is returned. Note that it is allowed to return a null pointer rather
235
+ /// than an allocated empty metadata.
236
+ virtual Result<std::shared_ptr<const KeyValueMetadata>> ReadMetadata();
237
+
238
+ /// \brief Read stream metadata asynchronously
239
+ virtual Future<std::shared_ptr<const KeyValueMetadata>> ReadMetadataAsync(
240
+ const IOContext& io_context);
241
+ Future<std::shared_ptr<const KeyValueMetadata>> ReadMetadataAsync();
242
+
243
+ protected:
244
+ InputStream() = default;
245
+ };
246
+
247
+ class ARROW_EXPORT RandomAccessFile : public InputStream, public Seekable {
248
+ public:
249
+ /// Necessary because we hold a std::unique_ptr
250
+ ~RandomAccessFile() override;
251
+
252
+ /// \brief Create an isolated InputStream that reads a segment of a
253
+ /// RandomAccessFile. Multiple such stream can be created and used
254
+ /// independently without interference
255
+ /// \param[in] file a file instance
256
+ /// \param[in] file_offset the starting position in the file
257
+ /// \param[in] nbytes the extent of bytes to read. The file should have
258
+ /// sufficient bytes available
259
+ static Result<std::shared_ptr<InputStream>> GetStream(
260
+ std::shared_ptr<RandomAccessFile> file, int64_t file_offset, int64_t nbytes);
261
+
262
+ /// \brief Return the total file size in bytes.
263
+ ///
264
+ /// This method does not read or move the current file position, so is safe
265
+ /// to call concurrently with e.g. ReadAt().
266
+ virtual Result<int64_t> GetSize() = 0;
267
+
268
+ /// \brief Read data from given file position.
269
+ ///
270
+ /// At most `nbytes` bytes are read. The number of bytes read is returned
271
+ /// (it can be less than `nbytes` if EOF is reached).
272
+ ///
273
+ /// This method can be safely called from multiple threads concurrently.
274
+ /// It is unspecified whether this method updates the file position or not.
275
+ ///
276
+ /// The default RandomAccessFile-provided implementation uses Seek() and Read(),
277
+ /// but subclasses may override it with a more efficient implementation
278
+ /// that doesn't depend on implicit file positioning.
279
+ ///
280
+ /// \param[in] position Where to read bytes from
281
+ /// \param[in] nbytes The number of bytes to read
282
+ /// \param[out] out The buffer to read bytes into
283
+ /// \return The number of bytes read, or an error
284
+ virtual Result<int64_t> ReadAt(int64_t position, int64_t nbytes, void* out);
285
+
286
+ /// \brief Read data from given file position.
287
+ ///
288
+ /// At most `nbytes` bytes are read, but it can be less if EOF is reached.
289
+ ///
290
+ /// \param[in] position Where to read bytes from
291
+ /// \param[in] nbytes The number of bytes to read
292
+ /// \return A buffer containing the bytes read, or an error
293
+ virtual Result<std::shared_ptr<Buffer>> ReadAt(int64_t position, int64_t nbytes);
294
+
295
+ /// EXPERIMENTAL: Read data asynchronously.
296
+ virtual Future<std::shared_ptr<Buffer>> ReadAsync(const IOContext&, int64_t position,
297
+ int64_t nbytes);
298
+
299
+ /// EXPERIMENTAL: Read data asynchronously, using the file's IOContext.
300
+ Future<std::shared_ptr<Buffer>> ReadAsync(int64_t position, int64_t nbytes);
301
+
302
+ /// EXPERIMENTAL: Explicit multi-read.
303
+ /// \brief Request multiple reads at once
304
+ ///
305
+ /// The underlying filesystem may optimize these reads by coalescing small reads into
306
+ /// large reads or by breaking up large reads into multiple parallel smaller reads. The
307
+ /// reads should be issued in parallel if it makes sense for the filesystem.
308
+ ///
309
+ /// One future will be returned for each input read range. Multiple returned futures
310
+ /// may correspond to a single read. Or, a single returned future may be a combined
311
+ /// result of several individual reads.
312
+ ///
313
+ /// \param[in] ranges The ranges to read
314
+ /// \return A future that will complete with the data from the requested range is
315
+ /// available
316
+ virtual std::vector<Future<std::shared_ptr<Buffer>>> ReadManyAsync(
317
+ const IOContext&, const std::vector<ReadRange>& ranges);
318
+
319
+ /// EXPERIMENTAL: Explicit multi-read, using the file's IOContext.
320
+ std::vector<Future<std::shared_ptr<Buffer>>> ReadManyAsync(
321
+ const std::vector<ReadRange>& ranges);
322
+
323
+ /// EXPERIMENTAL: Inform that the given ranges may be read soon.
324
+ ///
325
+ /// Some implementations might arrange to prefetch some of the data.
326
+ /// However, no guarantee is made and the default implementation does nothing.
327
+ /// For robust prefetching, use ReadAt() or ReadAsync().
328
+ virtual Status WillNeed(const std::vector<ReadRange>& ranges);
329
+
330
+ protected:
331
+ RandomAccessFile();
332
+
333
+ private:
334
+ struct ARROW_NO_EXPORT Impl;
335
+ std::unique_ptr<Impl> interface_impl_;
336
+ };
337
+
338
+ class ARROW_EXPORT WritableFile : public OutputStream, public Seekable {
339
+ public:
340
+ virtual Status WriteAt(int64_t position, const void* data, int64_t nbytes) = 0;
341
+
342
+ protected:
343
+ WritableFile() = default;
344
+ };
345
+
346
+ class ARROW_EXPORT ReadWriteFileInterface : public RandomAccessFile, public WritableFile {
347
+ protected:
348
+ ReadWriteFileInterface() { RandomAccessFile::set_mode(FileMode::READWRITE); }
349
+ };
350
+
351
+ /// \brief Return an iterator on an input stream
352
+ ///
353
+ /// The iterator yields a fixed-size block on each Next() call, except the
354
+ /// last block in the stream which may be smaller.
355
+ /// Once the end of stream is reached, Next() returns nullptr
356
+ /// (unlike InputStream::Read() which returns an empty buffer).
357
+ ARROW_EXPORT
358
+ Result<Iterator<std::shared_ptr<Buffer>>> MakeInputStreamIterator(
359
+ std::shared_ptr<InputStream> stream, int64_t block_size);
360
+
361
+ } // namespace io
362
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/memory.h ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 different memory sharing / IO mechanisms
19
+
20
+ #pragma once
21
+
22
+ #include <cstdint>
23
+ #include <memory>
24
+ #include <string_view>
25
+ #include <vector>
26
+
27
+ #include "arrow/io/concurrency.h"
28
+ #include "arrow/io/interfaces.h"
29
+ #include "arrow/type_fwd.h"
30
+ #include "arrow/util/visibility.h"
31
+
32
+ namespace arrow {
33
+
34
+ class Status;
35
+
36
+ namespace io {
37
+
38
+ /// \brief An output stream that writes to a resizable buffer
39
+ class ARROW_EXPORT BufferOutputStream : public OutputStream {
40
+ public:
41
+ explicit BufferOutputStream(const std::shared_ptr<ResizableBuffer>& buffer);
42
+
43
+ /// \brief Create in-memory output stream with indicated capacity using a
44
+ /// memory pool
45
+ /// \param[in] initial_capacity the initial allocated internal capacity of
46
+ /// the OutputStream
47
+ /// \param[in,out] pool a MemoryPool to use for allocations
48
+ /// \return the created stream
49
+ static Result<std::shared_ptr<BufferOutputStream>> Create(
50
+ int64_t initial_capacity = 4096, MemoryPool* pool = default_memory_pool());
51
+
52
+ ~BufferOutputStream() override;
53
+
54
+ // Implement the OutputStream interface
55
+
56
+ /// Close the stream, preserving the buffer (retrieve it with Finish()).
57
+ Status Close() override;
58
+ bool closed() const override;
59
+ Result<int64_t> Tell() const override;
60
+ Status Write(const void* data, int64_t nbytes) override;
61
+
62
+ /// \cond FALSE
63
+ using OutputStream::Write;
64
+ /// \endcond
65
+
66
+ /// Close the stream and return the buffer
67
+ Result<std::shared_ptr<Buffer>> Finish();
68
+
69
+ /// \brief Initialize state of OutputStream with newly allocated memory and
70
+ /// set position to 0
71
+ /// \param[in] initial_capacity the starting allocated capacity
72
+ /// \param[in,out] pool the memory pool to use for allocations
73
+ /// \return Status
74
+ Status Reset(int64_t initial_capacity = 1024, MemoryPool* pool = default_memory_pool());
75
+
76
+ int64_t capacity() const { return capacity_; }
77
+
78
+ private:
79
+ BufferOutputStream();
80
+
81
+ // Ensures there is sufficient space available to write nbytes
82
+ Status Reserve(int64_t nbytes);
83
+
84
+ std::shared_ptr<ResizableBuffer> buffer_;
85
+ bool is_open_;
86
+ int64_t capacity_;
87
+ int64_t position_;
88
+ uint8_t* mutable_data_;
89
+ };
90
+
91
+ /// \brief A helper class to track the size of allocations
92
+ ///
93
+ /// Writes to this stream do not copy or retain any data, they just bump
94
+ /// a size counter that can be later used to know exactly which data size
95
+ /// needs to be allocated for actual writing.
96
+ class ARROW_EXPORT MockOutputStream : public OutputStream {
97
+ public:
98
+ MockOutputStream() : extent_bytes_written_(0), is_open_(true) {}
99
+
100
+ // Implement the OutputStream interface
101
+ Status Close() override;
102
+ bool closed() const override;
103
+ Result<int64_t> Tell() const override;
104
+ Status Write(const void* data, int64_t nbytes) override;
105
+ /// \cond FALSE
106
+ using Writable::Write;
107
+ /// \endcond
108
+
109
+ int64_t GetExtentBytesWritten() const { return extent_bytes_written_; }
110
+
111
+ private:
112
+ int64_t extent_bytes_written_;
113
+ bool is_open_;
114
+ };
115
+
116
+ /// \brief An output stream that writes into a fixed-size mutable buffer
117
+ class ARROW_EXPORT FixedSizeBufferWriter : public WritableFile {
118
+ public:
119
+ /// Input buffer must be mutable, will abort if not
120
+ explicit FixedSizeBufferWriter(const std::shared_ptr<Buffer>& buffer);
121
+ ~FixedSizeBufferWriter() override;
122
+
123
+ Status Close() override;
124
+ bool closed() const override;
125
+ Status Seek(int64_t position) override;
126
+ Result<int64_t> Tell() const override;
127
+ Status Write(const void* data, int64_t nbytes) override;
128
+ /// \cond FALSE
129
+ using Writable::Write;
130
+ /// \endcond
131
+
132
+ Status WriteAt(int64_t position, const void* data, int64_t nbytes) override;
133
+
134
+ void set_memcopy_threads(int num_threads);
135
+ void set_memcopy_blocksize(int64_t blocksize);
136
+ void set_memcopy_threshold(int64_t threshold);
137
+
138
+ protected:
139
+ class FixedSizeBufferWriterImpl;
140
+ std::unique_ptr<FixedSizeBufferWriterImpl> impl_;
141
+ };
142
+
143
+ /// \class BufferReader
144
+ /// \brief Random access zero-copy reads on an arrow::Buffer
145
+ class ARROW_EXPORT BufferReader
146
+ : public internal::RandomAccessFileConcurrencyWrapper<BufferReader> {
147
+ public:
148
+ /// \brief Instantiate from std::shared_ptr<Buffer>.
149
+ ///
150
+ /// This is a zero-copy constructor.
151
+ explicit BufferReader(std::shared_ptr<Buffer> buffer);
152
+ ARROW_DEPRECATED(
153
+ "Deprecated in 14.0.0. Use FromString or BufferReader(std::shared_ptr<Buffer> "
154
+ "buffer) instead.")
155
+ explicit BufferReader(const Buffer& buffer);
156
+ ARROW_DEPRECATED(
157
+ "Deprecated in 14.0.0. Use FromString or BufferReader(std::shared_ptr<Buffer> "
158
+ "buffer) instead.")
159
+ BufferReader(const uint8_t* data, int64_t size);
160
+
161
+ /// \brief Instantiate from std::string_view. Does not own data
162
+ /// \deprecated Deprecated in 14.0.0. Use FromString or
163
+ /// BufferReader(std::shared_ptr<Buffer> buffer) instead.
164
+ ARROW_DEPRECATED(
165
+ "Deprecated in 14.0.0. Use FromString or BufferReader(std::shared_ptr<Buffer> "
166
+ "buffer) instead.")
167
+ explicit BufferReader(std::string_view data);
168
+
169
+ /// \brief Instantiate from std::string. Owns data.
170
+ static std::unique_ptr<BufferReader> FromString(std::string data);
171
+
172
+ bool closed() const override;
173
+
174
+ bool supports_zero_copy() const override;
175
+
176
+ std::shared_ptr<Buffer> buffer() const { return buffer_; }
177
+
178
+ // Synchronous ReadAsync override
179
+ Future<std::shared_ptr<Buffer>> ReadAsync(const IOContext&, int64_t position,
180
+ int64_t nbytes) override;
181
+ Status WillNeed(const std::vector<ReadRange>& ranges) override;
182
+
183
+ protected:
184
+ friend RandomAccessFileConcurrencyWrapper<BufferReader>;
185
+
186
+ Status DoClose();
187
+
188
+ Result<int64_t> DoRead(int64_t nbytes, void* buffer);
189
+ Result<std::shared_ptr<Buffer>> DoRead(int64_t nbytes);
190
+ Result<int64_t> DoReadAt(int64_t position, int64_t nbytes, void* out);
191
+ Result<std::shared_ptr<Buffer>> DoReadAt(int64_t position, int64_t nbytes);
192
+ Result<std::string_view> DoPeek(int64_t nbytes) override;
193
+
194
+ Result<int64_t> DoTell() const;
195
+ Status DoSeek(int64_t position);
196
+ Result<int64_t> DoGetSize();
197
+
198
+ Status CheckClosed() const {
199
+ if (!is_open_) {
200
+ return Status::Invalid("Operation forbidden on closed BufferReader");
201
+ }
202
+ return Status::OK();
203
+ }
204
+
205
+ std::shared_ptr<Buffer> buffer_;
206
+ const uint8_t* data_;
207
+ int64_t size_;
208
+ int64_t position_;
209
+ bool is_open_;
210
+ };
211
+
212
+ } // namespace io
213
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/mman.h ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright https://code.google.com/p/mman-win32/
2
+ //
3
+ // Licensed under the MIT License;
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // https://opensource.org/licenses/MIT
7
+
8
+ #pragma once
9
+
10
+ #include "arrow/util/windows_compatibility.h"
11
+
12
+ #include <errno.h>
13
+ #include <io.h>
14
+ #include <sys/types.h>
15
+
16
+ #include <cstdint>
17
+
18
+ #define PROT_NONE 0
19
+ #define PROT_READ 1
20
+ #define PROT_WRITE 2
21
+ #define PROT_EXEC 4
22
+
23
+ #define MAP_FILE 0
24
+ #define MAP_SHARED 1
25
+ #define MAP_PRIVATE 2
26
+ #define MAP_TYPE 0xf
27
+ #define MAP_FIXED 0x10
28
+ #define MAP_ANONYMOUS 0x20
29
+ #define MAP_ANON MAP_ANONYMOUS
30
+
31
+ #define MAP_FAILED ((void*)-1)
32
+
33
+ /* Flags for msync. */
34
+ #define MS_ASYNC 1
35
+ #define MS_SYNC 2
36
+ #define MS_INVALIDATE 4
37
+
38
+ #ifndef FILE_MAP_EXECUTE
39
+ #define FILE_MAP_EXECUTE 0x0020
40
+ #endif
41
+
42
+ static inline int __map_mman_error(const DWORD err, const int deferr) {
43
+ if (err == 0) return 0;
44
+ // TODO: implement
45
+ return err;
46
+ }
47
+
48
+ static inline DWORD __map_mmap_prot_page(const int prot) {
49
+ DWORD protect = 0;
50
+
51
+ if (prot == PROT_NONE) return protect;
52
+
53
+ if ((prot & PROT_EXEC) != 0) {
54
+ protect = ((prot & PROT_WRITE) != 0) ? PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ;
55
+ } else {
56
+ protect = ((prot & PROT_WRITE) != 0) ? PAGE_READWRITE : PAGE_READONLY;
57
+ }
58
+
59
+ return protect;
60
+ }
61
+
62
+ static inline DWORD __map_mmap_prot_file(const int prot) {
63
+ DWORD desiredAccess = 0;
64
+
65
+ if (prot == PROT_NONE) return desiredAccess;
66
+
67
+ if ((prot & PROT_READ) != 0) desiredAccess |= FILE_MAP_READ;
68
+ if ((prot & PROT_WRITE) != 0) desiredAccess |= FILE_MAP_WRITE;
69
+ if ((prot & PROT_EXEC) != 0) desiredAccess |= FILE_MAP_EXECUTE;
70
+
71
+ return desiredAccess;
72
+ }
73
+
74
+ static inline void* mmap(void* addr, size_t len, int prot, int flags, int fildes,
75
+ off_t off) {
76
+ HANDLE fm, h;
77
+
78
+ void* map = MAP_FAILED;
79
+ const uint64_t off64 = static_cast<uint64_t>(off);
80
+ const uint64_t maxSize = off64 + len;
81
+
82
+ const DWORD dwFileOffsetLow = static_cast<DWORD>(off64 & 0xFFFFFFFFUL);
83
+ const DWORD dwFileOffsetHigh = static_cast<DWORD>((off64 >> 32) & 0xFFFFFFFFUL);
84
+ const DWORD dwMaxSizeLow = static_cast<DWORD>(maxSize & 0xFFFFFFFFUL);
85
+ const DWORD dwMaxSizeHigh = static_cast<DWORD>((maxSize >> 32) & 0xFFFFFFFFUL);
86
+
87
+ const DWORD protect = __map_mmap_prot_page(prot);
88
+ const DWORD desiredAccess = __map_mmap_prot_file(prot);
89
+
90
+ errno = 0;
91
+
92
+ if (len == 0
93
+ /* Unsupported flag combinations */
94
+ || (flags & MAP_FIXED) != 0
95
+ /* Unsupported protection combinations */
96
+ || prot == PROT_EXEC) {
97
+ errno = EINVAL;
98
+ return MAP_FAILED;
99
+ }
100
+
101
+ h = ((flags & MAP_ANONYMOUS) == 0) ? (HANDLE)_get_osfhandle(fildes)
102
+ : INVALID_HANDLE_VALUE;
103
+
104
+ if ((flags & MAP_ANONYMOUS) == 0 && h == INVALID_HANDLE_VALUE) {
105
+ errno = EBADF;
106
+ return MAP_FAILED;
107
+ }
108
+
109
+ fm = CreateFileMapping(h, NULL, protect, dwMaxSizeHigh, dwMaxSizeLow, NULL);
110
+
111
+ if (fm == NULL) {
112
+ errno = __map_mman_error(GetLastError(), EPERM);
113
+ return MAP_FAILED;
114
+ }
115
+
116
+ map = MapViewOfFile(fm, desiredAccess, dwFileOffsetHigh, dwFileOffsetLow, len);
117
+
118
+ CloseHandle(fm);
119
+
120
+ if (map == NULL) {
121
+ errno = __map_mman_error(GetLastError(), EPERM);
122
+ return MAP_FAILED;
123
+ }
124
+
125
+ return map;
126
+ }
127
+
128
+ static inline int munmap(void* addr, size_t len) {
129
+ if (UnmapViewOfFile(addr)) return 0;
130
+
131
+ errno = __map_mman_error(GetLastError(), EPERM);
132
+
133
+ return -1;
134
+ }
135
+
136
+ static inline int mprotect(void* addr, size_t len, int prot) {
137
+ DWORD newProtect = __map_mmap_prot_page(prot);
138
+ DWORD oldProtect = 0;
139
+
140
+ if (VirtualProtect(addr, len, newProtect, &oldProtect)) return 0;
141
+
142
+ errno = __map_mman_error(GetLastError(), EPERM);
143
+
144
+ return -1;
145
+ }
146
+
147
+ static inline int msync(void* addr, size_t len, int flags) {
148
+ if (FlushViewOfFile(addr, len)) return 0;
149
+
150
+ errno = __map_mman_error(GetLastError(), EPERM);
151
+
152
+ return -1;
153
+ }
154
+
155
+ static inline int mlock(const void* addr, size_t len) {
156
+ if (VirtualLock((LPVOID)addr, len)) return 0;
157
+
158
+ errno = __map_mman_error(GetLastError(), EPERM);
159
+
160
+ return -1;
161
+ }
162
+
163
+ static inline int munlock(const void* addr, size_t len) {
164
+ if (VirtualUnlock((LPVOID)addr, len)) return 0;
165
+
166
+ errno = __map_mman_error(GetLastError(), EPERM);
167
+
168
+ return -1;
169
+ }
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/slow.h ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // Slow stream implementations, mainly for testing and benchmarking
19
+
20
+ #pragma once
21
+
22
+ #include <cstdint>
23
+ #include <memory>
24
+ #include <utility>
25
+
26
+ #include "arrow/io/interfaces.h"
27
+ #include "arrow/util/visibility.h"
28
+
29
+ namespace arrow {
30
+
31
+ class Buffer;
32
+ class Status;
33
+
34
+ namespace io {
35
+
36
+ class ARROW_EXPORT LatencyGenerator {
37
+ public:
38
+ virtual ~LatencyGenerator();
39
+
40
+ void Sleep();
41
+
42
+ virtual double NextLatency() = 0;
43
+
44
+ static std::shared_ptr<LatencyGenerator> Make(double average_latency);
45
+ static std::shared_ptr<LatencyGenerator> Make(double average_latency, int32_t seed);
46
+ };
47
+
48
+ // XXX use ConcurrencyWrapper? It could increase chances of finding a race.
49
+
50
+ template <class StreamType>
51
+ class SlowInputStreamBase : public StreamType {
52
+ public:
53
+ SlowInputStreamBase(std::shared_ptr<StreamType> stream,
54
+ std::shared_ptr<LatencyGenerator> latencies)
55
+ : stream_(std::move(stream)), latencies_(std::move(latencies)) {}
56
+
57
+ SlowInputStreamBase(std::shared_ptr<StreamType> stream, double average_latency)
58
+ : stream_(std::move(stream)), latencies_(LatencyGenerator::Make(average_latency)) {}
59
+
60
+ SlowInputStreamBase(std::shared_ptr<StreamType> stream, double average_latency,
61
+ int32_t seed)
62
+ : stream_(std::move(stream)),
63
+ latencies_(LatencyGenerator::Make(average_latency, seed)) {}
64
+
65
+ protected:
66
+ std::shared_ptr<StreamType> stream_;
67
+ std::shared_ptr<LatencyGenerator> latencies_;
68
+ };
69
+
70
+ /// \brief An InputStream wrapper that makes reads slower.
71
+ ///
72
+ /// Read() calls are made slower by an average latency (in seconds).
73
+ /// Actual latencies form a normal distribution closely centered
74
+ /// on the average latency.
75
+ /// Other calls are forwarded directly.
76
+ class ARROW_EXPORT SlowInputStream : public SlowInputStreamBase<InputStream> {
77
+ public:
78
+ ~SlowInputStream() override;
79
+
80
+ using SlowInputStreamBase<InputStream>::SlowInputStreamBase;
81
+
82
+ Status Close() override;
83
+ Status Abort() override;
84
+ bool closed() const override;
85
+
86
+ Result<int64_t> Read(int64_t nbytes, void* out) override;
87
+ Result<std::shared_ptr<Buffer>> Read(int64_t nbytes) override;
88
+ Result<std::string_view> Peek(int64_t nbytes) override;
89
+
90
+ Result<int64_t> Tell() const override;
91
+ };
92
+
93
+ /// \brief A RandomAccessFile wrapper that makes reads slower.
94
+ ///
95
+ /// Similar to SlowInputStream, but allows random access and seeking.
96
+ class ARROW_EXPORT SlowRandomAccessFile : public SlowInputStreamBase<RandomAccessFile> {
97
+ public:
98
+ ~SlowRandomAccessFile() override;
99
+
100
+ using SlowInputStreamBase<RandomAccessFile>::SlowInputStreamBase;
101
+
102
+ Status Close() override;
103
+ Status Abort() override;
104
+ bool closed() const override;
105
+
106
+ Result<int64_t> Read(int64_t nbytes, void* out) override;
107
+ Result<std::shared_ptr<Buffer>> Read(int64_t nbytes) override;
108
+ Result<int64_t> ReadAt(int64_t position, int64_t nbytes, void* out) override;
109
+ Result<std::shared_ptr<Buffer>> ReadAt(int64_t position, int64_t nbytes) override;
110
+ Result<std::string_view> Peek(int64_t nbytes) override;
111
+
112
+ Result<int64_t> GetSize() override;
113
+ Status Seek(int64_t position) override;
114
+ Result<int64_t> Tell() const override;
115
+ };
116
+
117
+ } // namespace io
118
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/stdio.h ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
22
+ #include "arrow/io/interfaces.h"
23
+ #include "arrow/util/visibility.h"
24
+
25
+ namespace arrow {
26
+ namespace io {
27
+
28
+ // Output stream that just writes to stdout.
29
+ class ARROW_EXPORT StdoutStream : public OutputStream {
30
+ public:
31
+ StdoutStream();
32
+ ~StdoutStream() override {}
33
+
34
+ Status Close() override;
35
+ bool closed() const override;
36
+
37
+ Result<int64_t> Tell() const override;
38
+
39
+ Status Write(const void* data, int64_t nbytes) override;
40
+
41
+ private:
42
+ int64_t pos_;
43
+ };
44
+
45
+ // Output stream that just writes to stderr.
46
+ class ARROW_EXPORT StderrStream : public OutputStream {
47
+ public:
48
+ StderrStream();
49
+ ~StderrStream() override {}
50
+
51
+ Status Close() override;
52
+ bool closed() const override;
53
+
54
+ Result<int64_t> Tell() const override;
55
+
56
+ Status Write(const void* data, int64_t nbytes) override;
57
+
58
+ private:
59
+ int64_t pos_;
60
+ };
61
+
62
+ // Input stream that just reads from stdin.
63
+ class ARROW_EXPORT StdinStream : public InputStream {
64
+ public:
65
+ StdinStream();
66
+ ~StdinStream() override {}
67
+
68
+ Status Close() override;
69
+ bool closed() const override;
70
+
71
+ Result<int64_t> Tell() const override;
72
+
73
+ Result<int64_t> Read(int64_t nbytes, void* out) override;
74
+
75
+ Result<std::shared_ptr<Buffer>> Read(int64_t nbytes) override;
76
+
77
+ private:
78
+ int64_t pos_;
79
+ };
80
+
81
+ } // namespace io
82
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/test_common.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 <memory>
21
+ #include <string>
22
+ #include <vector>
23
+
24
+ #include "arrow/io/interfaces.h"
25
+ #include "arrow/testing/visibility.h"
26
+ #include "arrow/type_fwd.h"
27
+
28
+ namespace arrow {
29
+ namespace io {
30
+
31
+ class MemoryMappedFile;
32
+
33
+ ARROW_TESTING_EXPORT
34
+ void AssertFileContents(const std::string& path, const std::string& contents);
35
+
36
+ ARROW_TESTING_EXPORT bool FileExists(const std::string& path);
37
+
38
+ ARROW_TESTING_EXPORT Status PurgeLocalFileFromOsCache(const std::string& path);
39
+
40
+ ARROW_TESTING_EXPORT
41
+ Status ZeroMemoryMap(MemoryMappedFile* file);
42
+
43
+ class ARROW_TESTING_EXPORT MemoryMapFixture {
44
+ public:
45
+ void TearDown();
46
+
47
+ void CreateFile(const std::string& path, int64_t size);
48
+
49
+ Result<std::shared_ptr<MemoryMappedFile>> InitMemoryMap(int64_t size,
50
+ const std::string& path);
51
+
52
+ void AppendFile(const std::string& path);
53
+
54
+ private:
55
+ std::vector<std::string> tmp_files_;
56
+ };
57
+
58
+ class ARROW_TESTING_EXPORT TrackedRandomAccessFile : public io::RandomAccessFile {
59
+ public:
60
+ virtual int64_t num_reads() const = 0;
61
+ virtual int64_t bytes_read() const = 0;
62
+ virtual const std::vector<io::ReadRange>& get_read_ranges() const = 0;
63
+ static std::unique_ptr<TrackedRandomAccessFile> Make(io::RandomAccessFile* target);
64
+ };
65
+
66
+ } // namespace io
67
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/transform.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
+ // Transform stream implementations
19
+
20
+ #pragma once
21
+
22
+ #include <cstdint>
23
+ #include <functional>
24
+ #include <memory>
25
+ #include <utility>
26
+
27
+ #include "arrow/io/interfaces.h"
28
+ #include "arrow/util/visibility.h"
29
+
30
+ namespace arrow {
31
+ namespace io {
32
+
33
+ class ARROW_EXPORT TransformInputStream : public InputStream {
34
+ public:
35
+ using TransformFunc =
36
+ std::function<Result<std::shared_ptr<Buffer>>(const std::shared_ptr<Buffer>&)>;
37
+
38
+ TransformInputStream(std::shared_ptr<InputStream> wrapped, TransformFunc transform);
39
+ ~TransformInputStream() override;
40
+
41
+ Status Close() override;
42
+ Status Abort() override;
43
+ bool closed() const override;
44
+
45
+ Result<int64_t> Read(int64_t nbytes, void* out) override;
46
+ Result<std::shared_ptr<Buffer>> Read(int64_t nbytes) override;
47
+
48
+ Result<std::shared_ptr<const KeyValueMetadata>> ReadMetadata() override;
49
+ Future<std::shared_ptr<const KeyValueMetadata>> ReadMetadataAsync(
50
+ const IOContext& io_context) override;
51
+
52
+ Result<int64_t> Tell() const override;
53
+
54
+ protected:
55
+ struct Impl;
56
+ std::unique_ptr<Impl> impl_;
57
+ };
58
+
59
+ } // namespace io
60
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/io/type_fwd.h ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/type_fwd.h"
21
+ #include "arrow/util/visibility.h"
22
+
23
+ namespace arrow {
24
+ namespace io {
25
+
26
+ struct FileMode {
27
+ enum type { READ, WRITE, READWRITE };
28
+ };
29
+
30
+ struct IOContext;
31
+ struct CacheOptions;
32
+
33
+ /// EXPERIMENTAL: convenience global singleton for default IOContext settings
34
+ ARROW_EXPORT
35
+ const IOContext& default_io_context();
36
+
37
+ /// \brief Get the capacity of the global I/O thread pool
38
+ ///
39
+ /// Return the number of worker threads in the thread pool to which
40
+ /// Arrow dispatches various I/O-bound tasks. This is an ideal number,
41
+ /// not necessarily the exact number of threads at a given point in time.
42
+ ///
43
+ /// You can change this number using SetIOThreadPoolCapacity().
44
+ ARROW_EXPORT int GetIOThreadPoolCapacity();
45
+
46
+ /// \brief Set the capacity of the global I/O thread pool
47
+ ///
48
+ /// Set the number of worker threads in the thread pool to which
49
+ /// Arrow dispatches various I/O-bound tasks.
50
+ ///
51
+ /// The current number is returned by GetIOThreadPoolCapacity().
52
+ ARROW_EXPORT Status SetIOThreadPoolCapacity(int threads);
53
+
54
+ class FileInterface;
55
+ class Seekable;
56
+ class Writable;
57
+ class Readable;
58
+ class OutputStream;
59
+ class FileOutputStream;
60
+ class InputStream;
61
+ class ReadableFile;
62
+ class RandomAccessFile;
63
+ class MemoryMappedFile;
64
+ class WritableFile;
65
+ class ReadWriteFileInterface;
66
+
67
+ class LatencyGenerator;
68
+
69
+ class BufferOutputStream;
70
+ class BufferReader;
71
+ class CompressedInputStream;
72
+ class CompressedOutputStream;
73
+ class BufferedInputStream;
74
+ class BufferedOutputStream;
75
+
76
+ } // namespace io
77
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/api.h ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/arrow_to_pandas.h"
21
+ #include "arrow/python/common.h"
22
+ #include "arrow/python/datetime.h"
23
+ #include "arrow/python/deserialize.h"
24
+ #include "arrow/python/helpers.h"
25
+ #include "arrow/python/inference.h"
26
+ #include "arrow/python/io.h"
27
+ #include "arrow/python/numpy_convert.h"
28
+ #include "arrow/python/numpy_to_arrow.h"
29
+ #include "arrow/python/python_to_arrow.h"
30
+ #include "arrow/python/serialize.h"
llmeval-env/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
llmeval-env/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
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/benchmark.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 "arrow/python/visibility.h"
23
+
24
+ namespace arrow {
25
+ namespace py {
26
+ namespace benchmark {
27
+
28
+ // Micro-benchmark routines for use from ASV
29
+
30
+ // Run PandasObjectIsNull() once over every object in *list*
31
+ ARROW_PYTHON_EXPORT
32
+ void Benchmark_PandasObjectIsNull(PyObject* list);
33
+
34
+ } // namespace benchmark
35
+ } // namespace py
36
+ } // namespace arrow
llmeval-env/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
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/decimal.h ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/visibility.h"
23
+ #include "arrow/type.h"
24
+
25
+ namespace arrow {
26
+
27
+ class Decimal128;
28
+ class Decimal256;
29
+
30
+ namespace py {
31
+
32
+ class OwnedRef;
33
+
34
+ //
35
+ // Python Decimal support
36
+ //
37
+
38
+ namespace internal {
39
+
40
+ // \brief Import the Python Decimal type
41
+ ARROW_PYTHON_EXPORT
42
+ Status ImportDecimalType(OwnedRef* decimal_type);
43
+
44
+ // \brief Convert a Python Decimal object to a C++ string
45
+ // \param[in] python_decimal A Python decimal.Decimal instance
46
+ // \param[out] The string representation of the Python Decimal instance
47
+ // \return The status of the operation
48
+ ARROW_PYTHON_EXPORT
49
+ Status PythonDecimalToString(PyObject* python_decimal, std::string* out);
50
+
51
+ // \brief Convert a C++ std::string to a Python Decimal instance
52
+ // \param[in] decimal_constructor The decimal type object
53
+ // \param[in] decimal_string A decimal string
54
+ // \return An instance of decimal.Decimal
55
+ ARROW_PYTHON_EXPORT
56
+ PyObject* DecimalFromString(PyObject* decimal_constructor,
57
+ const std::string& decimal_string);
58
+
59
+ // \brief Convert a Python decimal to an Arrow Decimal128 object
60
+ // \param[in] python_decimal A Python decimal.Decimal instance
61
+ // \param[in] arrow_type An instance of arrow::DecimalType
62
+ // \param[out] out A pointer to a Decimal128
63
+ // \return The status of the operation
64
+ ARROW_PYTHON_EXPORT
65
+ Status DecimalFromPythonDecimal(PyObject* python_decimal, const DecimalType& arrow_type,
66
+ Decimal128* out);
67
+
68
+ // \brief Convert a Python object to an Arrow Decimal128 object
69
+ // \param[in] python_decimal A Python int or decimal.Decimal instance
70
+ // \param[in] arrow_type An instance of arrow::DecimalType
71
+ // \param[out] out A pointer to a Decimal128
72
+ // \return The status of the operation
73
+ ARROW_PYTHON_EXPORT
74
+ Status DecimalFromPyObject(PyObject* obj, const DecimalType& arrow_type, Decimal128* out);
75
+
76
+ // \brief Convert a Python decimal to an Arrow Decimal256 object
77
+ // \param[in] python_decimal A Python decimal.Decimal instance
78
+ // \param[in] arrow_type An instance of arrow::DecimalType
79
+ // \param[out] out A pointer to a Decimal256
80
+ // \return The status of the operation
81
+ ARROW_PYTHON_EXPORT
82
+ Status DecimalFromPythonDecimal(PyObject* python_decimal, const DecimalType& arrow_type,
83
+ Decimal256* out);
84
+
85
+ // \brief Convert a Python object to an Arrow Decimal256 object
86
+ // \param[in] python_decimal A Python int or decimal.Decimal instance
87
+ // \param[in] arrow_type An instance of arrow::DecimalType
88
+ // \param[out] out A pointer to a Decimal256
89
+ // \return The status of the operation
90
+ ARROW_PYTHON_EXPORT
91
+ Status DecimalFromPyObject(PyObject* obj, const DecimalType& arrow_type, Decimal256* out);
92
+
93
+ // \brief Check whether obj is an instance of Decimal
94
+ ARROW_PYTHON_EXPORT
95
+ bool PyDecimal_Check(PyObject* obj);
96
+
97
+ // \brief Check whether obj is nan. This function will abort the program if the argument
98
+ // is not a Decimal instance
99
+ ARROW_PYTHON_EXPORT
100
+ bool PyDecimal_ISNAN(PyObject* obj);
101
+
102
+ // \brief Helper class to track and update the precision and scale of a decimal
103
+ class ARROW_PYTHON_EXPORT DecimalMetadata {
104
+ public:
105
+ DecimalMetadata();
106
+ DecimalMetadata(int32_t precision, int32_t scale);
107
+
108
+ // \brief Adjust the precision and scale of a decimal type given a new precision and a
109
+ // new scale \param[in] suggested_precision A candidate precision \param[in]
110
+ // suggested_scale A candidate scale \return The status of the operation
111
+ Status Update(int32_t suggested_precision, int32_t suggested_scale);
112
+
113
+ // \brief A convenient interface for updating the precision and scale based on a Python
114
+ // Decimal object \param object A Python Decimal object \return The status of the
115
+ // operation
116
+ Status Update(PyObject* object);
117
+
118
+ int32_t precision() const { return precision_; }
119
+ int32_t scale() const { return scale_; }
120
+
121
+ private:
122
+ int32_t precision_;
123
+ int32_t scale_;
124
+ };
125
+
126
+ } // namespace internal
127
+ } // namespace py
128
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/deserialize.h ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/python/serialize.h"
25
+ #include "arrow/python/visibility.h"
26
+ #include "arrow/status.h"
27
+
28
+ namespace arrow {
29
+
30
+ class RecordBatch;
31
+ class Tensor;
32
+
33
+ namespace io {
34
+
35
+ class RandomAccessFile;
36
+
37
+ } // namespace io
38
+
39
+ namespace py {
40
+
41
+ struct ARROW_PYTHON_EXPORT SparseTensorCounts {
42
+ int coo;
43
+ int csr;
44
+ int csc;
45
+ int csf;
46
+ int ndim_csf;
47
+
48
+ int num_total_tensors() const { return coo + csr + csc + csf; }
49
+ int num_total_buffers() const {
50
+ return coo * 3 + csr * 4 + csc * 4 + 2 * ndim_csf + csf;
51
+ }
52
+ };
53
+
54
+ /// \brief Read serialized Python sequence from file interface using Arrow IPC
55
+ /// \param[in] src a RandomAccessFile
56
+ /// \param[out] out the reconstructed data
57
+ /// \return Status
58
+ ARROW_PYTHON_EXPORT
59
+ Status ReadSerializedObject(io::RandomAccessFile* src, SerializedPyObject* out);
60
+
61
+ /// \brief Reconstruct SerializedPyObject from representation produced by
62
+ /// SerializedPyObject::GetComponents.
63
+ ///
64
+ /// \param[in] num_tensors number of tensors in the object
65
+ /// \param[in] num_sparse_tensors number of sparse tensors in the object
66
+ /// \param[in] num_ndarrays number of numpy Ndarrays in the object
67
+ /// \param[in] num_buffers number of buffers in the object
68
+ /// \param[in] data a list containing pyarrow.Buffer instances. It must be 1 +
69
+ /// num_tensors * 2 + num_coo_tensors * 3 + num_csr_tensors * 4 + num_csc_tensors * 4 +
70
+ /// num_csf_tensors * (2 * ndim_csf + 3) + num_buffers in length
71
+ /// \param[out] out the reconstructed object
72
+ /// \return Status
73
+ ARROW_PYTHON_EXPORT
74
+ Status GetSerializedFromComponents(int num_tensors,
75
+ const SparseTensorCounts& num_sparse_tensors,
76
+ int num_ndarrays, int num_buffers, PyObject* data,
77
+ SerializedPyObject* out);
78
+
79
+ /// \brief Reconstruct Python object from Arrow-serialized representation
80
+ /// \param[in] context Serialization context which contains custom serialization
81
+ /// and deserialization callbacks. Can be any Python object with a
82
+ /// _serialize_callback method for serialization and a _deserialize_callback
83
+ /// method for deserialization. If context is None, no custom serialization
84
+ /// will be attempted.
85
+ /// \param[in] object Object to deserialize
86
+ /// \param[in] base a Python object holding the underlying data that any NumPy
87
+ /// arrays will reference, to avoid premature deallocation
88
+ /// \param[out] out The returned object
89
+ /// \return Status
90
+ /// This acquires the GIL
91
+ ARROW_PYTHON_EXPORT
92
+ Status DeserializeObject(PyObject* context, const SerializedPyObject& object,
93
+ PyObject* base, PyObject** out);
94
+
95
+ /// \brief Reconstruct Ndarray from Arrow-serialized representation
96
+ /// \param[in] object Object to deserialize
97
+ /// \param[out] out The deserialized tensor
98
+ /// \return Status
99
+ ARROW_PYTHON_EXPORT
100
+ Status DeserializeNdarray(const SerializedPyObject& object, std::shared_ptr<Tensor>* out);
101
+
102
+ ARROW_PYTHON_EXPORT
103
+ Status NdarrayFromBuffer(std::shared_ptr<Buffer> src, std::shared_ptr<Tensor>* out);
104
+
105
+ } // namespace py
106
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/extension_type.h ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #include <string>
22
+
23
+ #include "arrow/extension_type.h"
24
+ #include "arrow/python/common.h"
25
+ #include "arrow/python/visibility.h"
26
+ #include "arrow/util/macros.h"
27
+
28
+ namespace arrow {
29
+ namespace py {
30
+
31
+ class ARROW_PYTHON_EXPORT PyExtensionType : public ExtensionType {
32
+ public:
33
+ // Implement extensionType API
34
+ std::string extension_name() const override { return extension_name_; }
35
+
36
+ std::string ToString(bool show_metadata = false) const override;
37
+
38
+ bool ExtensionEquals(const ExtensionType& other) const override;
39
+
40
+ std::shared_ptr<Array> MakeArray(std::shared_ptr<ArrayData> data) const override;
41
+
42
+ Result<std::shared_ptr<DataType>> Deserialize(
43
+ std::shared_ptr<DataType> storage_type,
44
+ const std::string& serialized) const override;
45
+
46
+ std::string Serialize() const override;
47
+
48
+ // For use from Cython
49
+ // Assumes that `typ` is borrowed
50
+ static Status FromClass(const std::shared_ptr<DataType> storage_type,
51
+ const std::string extension_name, PyObject* typ,
52
+ std::shared_ptr<ExtensionType>* out);
53
+
54
+ // Return new ref
55
+ PyObject* GetInstance() const;
56
+ Status SetInstance(PyObject*) const;
57
+
58
+ protected:
59
+ PyExtensionType(std::shared_ptr<DataType> storage_type, PyObject* typ,
60
+ PyObject* inst = NULLPTR);
61
+ PyExtensionType(std::shared_ptr<DataType> storage_type, std::string extension_name,
62
+ PyObject* typ, PyObject* inst = NULLPTR);
63
+
64
+ std::string extension_name_;
65
+
66
+ // These fields are mutable because of two-step initialization.
67
+ mutable OwnedRefNoGIL type_class_;
68
+ // A weakref or null. Storing a strong reference to the Python extension type
69
+ // instance would create an unreclaimable reference cycle between Python and C++
70
+ // (the Python instance has to keep a strong reference to the C++ ExtensionType
71
+ // in other direction). Instead, we store a weakref to the instance.
72
+ // If the weakref is dead, we reconstruct the instance from its serialized form.
73
+ mutable OwnedRefNoGIL type_instance_;
74
+ // Empty if type_instance_ is null
75
+ mutable std::string serialized_;
76
+ };
77
+
78
+ ARROW_PYTHON_EXPORT std::string PyExtensionName();
79
+
80
+ ARROW_PYTHON_EXPORT Status RegisterPyExtensionType(const std::shared_ptr<DataType>&);
81
+
82
+ ARROW_PYTHON_EXPORT Status UnregisterPyExtensionType(const std::string& type_name);
83
+
84
+ } // namespace py
85
+ } // namespace arrow
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/filesystem.h ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #include <string>
22
+ #include <vector>
23
+
24
+ #include "arrow/filesystem/filesystem.h"
25
+ #include "arrow/python/common.h"
26
+ #include "arrow/python/visibility.h"
27
+ #include "arrow/util/macros.h"
28
+
29
+ namespace arrow::py::fs {
30
+
31
+ class ARROW_PYTHON_EXPORT PyFileSystemVtable {
32
+ public:
33
+ std::function<void(PyObject*, std::string* out)> get_type_name;
34
+ std::function<bool(PyObject*, const arrow::fs::FileSystem& other)> equals;
35
+
36
+ std::function<void(PyObject*, const std::string& path, arrow::fs::FileInfo* out)>
37
+ get_file_info;
38
+ std::function<void(PyObject*, const std::vector<std::string>& paths,
39
+ std::vector<arrow::fs::FileInfo>* out)>
40
+ get_file_info_vector;
41
+ std::function<void(PyObject*, const arrow::fs::FileSelector&,
42
+ std::vector<arrow::fs::FileInfo>* out)>
43
+ get_file_info_selector;
44
+
45
+ std::function<void(PyObject*, const std::string& path, bool)> create_dir;
46
+ std::function<void(PyObject*, const std::string& path)> delete_dir;
47
+ std::function<void(PyObject*, const std::string& path, bool)> delete_dir_contents;
48
+ std::function<void(PyObject*)> delete_root_dir_contents;
49
+ std::function<void(PyObject*, const std::string& path)> delete_file;
50
+ std::function<void(PyObject*, const std::string& src, const std::string& dest)> move;
51
+ std::function<void(PyObject*, const std::string& src, const std::string& dest)>
52
+ copy_file;
53
+
54
+ std::function<void(PyObject*, const std::string& path,
55
+ std::shared_ptr<io::InputStream>* out)>
56
+ open_input_stream;
57
+ std::function<void(PyObject*, const std::string& path,
58
+ std::shared_ptr<io::RandomAccessFile>* out)>
59
+ open_input_file;
60
+ std::function<void(PyObject*, const std::string& path,
61
+ const std::shared_ptr<const KeyValueMetadata>&,
62
+ std::shared_ptr<io::OutputStream>* out)>
63
+ open_output_stream;
64
+ std::function<void(PyObject*, const std::string& path,
65
+ const std::shared_ptr<const KeyValueMetadata>&,
66
+ std::shared_ptr<io::OutputStream>* out)>
67
+ open_append_stream;
68
+
69
+ std::function<void(PyObject*, const std::string& path, std::string* out)>
70
+ normalize_path;
71
+ };
72
+
73
+ class ARROW_PYTHON_EXPORT PyFileSystem : public arrow::fs::FileSystem {
74
+ public:
75
+ PyFileSystem(PyObject* handler, PyFileSystemVtable vtable);
76
+ ~PyFileSystem() override;
77
+
78
+ static std::shared_ptr<PyFileSystem> Make(PyObject* handler, PyFileSystemVtable vtable);
79
+
80
+ std::string type_name() const override;
81
+
82
+ bool Equals(const FileSystem& other) const override;
83
+
84
+ /// \cond FALSE
85
+ using FileSystem::CreateDir;
86
+ using FileSystem::DeleteDirContents;
87
+ using FileSystem::GetFileInfo;
88
+ using FileSystem::OpenAppendStream;
89
+ using FileSystem::OpenOutputStream;
90
+ /// \endcond
91
+
92
+ Result<arrow::fs::FileInfo> GetFileInfo(const std::string& path) override;
93
+ Result<std::vector<arrow::fs::FileInfo>> GetFileInfo(
94
+ const std::vector<std::string>& paths) override;
95
+ Result<std::vector<arrow::fs::FileInfo>> GetFileInfo(
96
+ const arrow::fs::FileSelector& select) override;
97
+
98
+ Status CreateDir(const std::string& path, bool recursive) override;
99
+
100
+ Status DeleteDir(const std::string& path) override;
101
+ Status DeleteDirContents(const std::string& path, bool missing_dir_ok) override;
102
+ Status DeleteRootDirContents() override;
103
+
104
+ Status DeleteFile(const std::string& path) override;
105
+
106
+ Status Move(const std::string& src, const std::string& dest) override;
107
+
108
+ Status CopyFile(const std::string& src, const std::string& dest) override;
109
+
110
+ Result<std::shared_ptr<io::InputStream>> OpenInputStream(
111
+ const std::string& path) override;
112
+ Result<std::shared_ptr<io::RandomAccessFile>> OpenInputFile(
113
+ const std::string& path) override;
114
+ Result<std::shared_ptr<io::OutputStream>> OpenOutputStream(
115
+ const std::string& path,
116
+ const std::shared_ptr<const KeyValueMetadata>& metadata) override;
117
+ Result<std::shared_ptr<io::OutputStream>> OpenAppendStream(
118
+ const std::string& path,
119
+ const std::shared_ptr<const KeyValueMetadata>& metadata) override;
120
+
121
+ Result<std::string> NormalizePath(std::string path) override;
122
+
123
+ PyObject* handler() const { return handler_.obj(); }
124
+
125
+ private:
126
+ OwnedRefNoGIL handler_;
127
+ PyFileSystemVtable vtable_;
128
+ };
129
+
130
+ } // namespace arrow::py::fs
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/flight.h ADDED
@@ -0,0 +1,350 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #include <string>
22
+ #include <vector>
23
+
24
+ #include "arrow/flight/api.h"
25
+ #include "arrow/ipc/dictionary.h"
26
+ #include "arrow/python/common.h"
27
+
28
+ #if defined(_WIN32) || defined(__CYGWIN__) // Windows
29
+ #if defined(_MSC_VER)
30
+ #pragma warning(disable : 4251)
31
+ #else
32
+ #pragma GCC diagnostic ignored "-Wattributes"
33
+ #endif
34
+
35
+ #ifdef ARROW_PYTHON_STATIC
36
+ #define ARROW_PYFLIGHT_EXPORT
37
+ #elif defined(ARROW_PYFLIGHT_EXPORTING)
38
+ #define ARROW_PYFLIGHT_EXPORT __declspec(dllexport)
39
+ #else
40
+ #define ARROW_PYFLIGHT_EXPORT __declspec(dllimport)
41
+ #endif
42
+
43
+ #else // Not Windows
44
+ #ifndef ARROW_PYFLIGHT_EXPORT
45
+ #define ARROW_PYFLIGHT_EXPORT __attribute__((visibility("default")))
46
+ #endif
47
+ #endif // Non-Windows
48
+
49
+ namespace arrow {
50
+
51
+ namespace py {
52
+
53
+ namespace flight {
54
+
55
+ ARROW_PYFLIGHT_EXPORT
56
+ extern const char* kPyServerMiddlewareName;
57
+
58
+ /// \brief A table of function pointers for calling from C++ into
59
+ /// Python.
60
+ class ARROW_PYFLIGHT_EXPORT PyFlightServerVtable {
61
+ public:
62
+ std::function<Status(PyObject*, const arrow::flight::ServerCallContext&,
63
+ const arrow::flight::Criteria*,
64
+ std::unique_ptr<arrow::flight::FlightListing>*)>
65
+ list_flights;
66
+ std::function<Status(PyObject*, const arrow::flight::ServerCallContext&,
67
+ const arrow::flight::FlightDescriptor&,
68
+ std::unique_ptr<arrow::flight::FlightInfo>*)>
69
+ get_flight_info;
70
+ std::function<Status(PyObject*, const arrow::flight::ServerCallContext&,
71
+ const arrow::flight::FlightDescriptor&,
72
+ std::unique_ptr<arrow::flight::SchemaResult>*)>
73
+ get_schema;
74
+ std::function<Status(PyObject*, const arrow::flight::ServerCallContext&,
75
+ const arrow::flight::Ticket&,
76
+ std::unique_ptr<arrow::flight::FlightDataStream>*)>
77
+ do_get;
78
+ std::function<Status(PyObject*, const arrow::flight::ServerCallContext&,
79
+ std::unique_ptr<arrow::flight::FlightMessageReader>,
80
+ std::unique_ptr<arrow::flight::FlightMetadataWriter>)>
81
+ do_put;
82
+ std::function<Status(PyObject*, const arrow::flight::ServerCallContext&,
83
+ std::unique_ptr<arrow::flight::FlightMessageReader>,
84
+ std::unique_ptr<arrow::flight::FlightMessageWriter>)>
85
+ do_exchange;
86
+ std::function<Status(PyObject*, const arrow::flight::ServerCallContext&,
87
+ const arrow::flight::Action&,
88
+ std::unique_ptr<arrow::flight::ResultStream>*)>
89
+ do_action;
90
+ std::function<Status(PyObject*, const arrow::flight::ServerCallContext&,
91
+ std::vector<arrow::flight::ActionType>*)>
92
+ list_actions;
93
+ };
94
+
95
+ class ARROW_PYFLIGHT_EXPORT PyServerAuthHandlerVtable {
96
+ public:
97
+ std::function<Status(PyObject*, arrow::flight::ServerAuthSender*,
98
+ arrow::flight::ServerAuthReader*)>
99
+ authenticate;
100
+ std::function<Status(PyObject*, const std::string&, std::string*)> is_valid;
101
+ };
102
+
103
+ class ARROW_PYFLIGHT_EXPORT PyClientAuthHandlerVtable {
104
+ public:
105
+ std::function<Status(PyObject*, arrow::flight::ClientAuthSender*,
106
+ arrow::flight::ClientAuthReader*)>
107
+ authenticate;
108
+ std::function<Status(PyObject*, std::string*)> get_token;
109
+ };
110
+
111
+ /// \brief A helper to implement an auth mechanism in Python.
112
+ class ARROW_PYFLIGHT_EXPORT PyServerAuthHandler
113
+ : public arrow::flight::ServerAuthHandler {
114
+ public:
115
+ explicit PyServerAuthHandler(PyObject* handler,
116
+ const PyServerAuthHandlerVtable& vtable);
117
+ Status Authenticate(arrow::flight::ServerAuthSender* outgoing,
118
+ arrow::flight::ServerAuthReader* incoming) override;
119
+ Status IsValid(const std::string& token, std::string* peer_identity) override;
120
+
121
+ private:
122
+ OwnedRefNoGIL handler_;
123
+ PyServerAuthHandlerVtable vtable_;
124
+ };
125
+
126
+ /// \brief A helper to implement an auth mechanism in Python.
127
+ class ARROW_PYFLIGHT_EXPORT PyClientAuthHandler
128
+ : public arrow::flight::ClientAuthHandler {
129
+ public:
130
+ explicit PyClientAuthHandler(PyObject* handler,
131
+ const PyClientAuthHandlerVtable& vtable);
132
+ Status Authenticate(arrow::flight::ClientAuthSender* outgoing,
133
+ arrow::flight::ClientAuthReader* incoming) override;
134
+ Status GetToken(std::string* token) override;
135
+
136
+ private:
137
+ OwnedRefNoGIL handler_;
138
+ PyClientAuthHandlerVtable vtable_;
139
+ };
140
+
141
+ class ARROW_PYFLIGHT_EXPORT PyFlightServer : public arrow::flight::FlightServerBase {
142
+ public:
143
+ explicit PyFlightServer(PyObject* server, const PyFlightServerVtable& vtable);
144
+
145
+ // Like Serve(), but set up signals and invoke Python signal handlers
146
+ // if necessary. This function may return with a Python exception set.
147
+ Status ServeWithSignals();
148
+
149
+ Status ListFlights(const arrow::flight::ServerCallContext& context,
150
+ const arrow::flight::Criteria* criteria,
151
+ std::unique_ptr<arrow::flight::FlightListing>* listings) override;
152
+ Status GetFlightInfo(const arrow::flight::ServerCallContext& context,
153
+ const arrow::flight::FlightDescriptor& request,
154
+ std::unique_ptr<arrow::flight::FlightInfo>* info) override;
155
+ Status GetSchema(const arrow::flight::ServerCallContext& context,
156
+ const arrow::flight::FlightDescriptor& request,
157
+ std::unique_ptr<arrow::flight::SchemaResult>* result) override;
158
+ Status DoGet(const arrow::flight::ServerCallContext& context,
159
+ const arrow::flight::Ticket& request,
160
+ std::unique_ptr<arrow::flight::FlightDataStream>* stream) override;
161
+ Status DoPut(const arrow::flight::ServerCallContext& context,
162
+ std::unique_ptr<arrow::flight::FlightMessageReader> reader,
163
+ std::unique_ptr<arrow::flight::FlightMetadataWriter> writer) override;
164
+ Status DoExchange(const arrow::flight::ServerCallContext& context,
165
+ std::unique_ptr<arrow::flight::FlightMessageReader> reader,
166
+ std::unique_ptr<arrow::flight::FlightMessageWriter> writer) override;
167
+ Status DoAction(const arrow::flight::ServerCallContext& context,
168
+ const arrow::flight::Action& action,
169
+ std::unique_ptr<arrow::flight::ResultStream>* result) override;
170
+ Status ListActions(const arrow::flight::ServerCallContext& context,
171
+ std::vector<arrow::flight::ActionType>* actions) override;
172
+
173
+ private:
174
+ OwnedRefNoGIL server_;
175
+ PyFlightServerVtable vtable_;
176
+ };
177
+
178
+ /// \brief A callback that obtains the next result from a Flight action.
179
+ typedef std::function<Status(PyObject*, std::unique_ptr<arrow::flight::Result>*)>
180
+ PyFlightResultStreamCallback;
181
+
182
+ /// \brief A ResultStream built around a Python callback.
183
+ class ARROW_PYFLIGHT_EXPORT PyFlightResultStream : public arrow::flight::ResultStream {
184
+ public:
185
+ /// \brief Construct a FlightResultStream from a Python object and callback.
186
+ /// Must only be called while holding the GIL.
187
+ explicit PyFlightResultStream(PyObject* generator,
188
+ PyFlightResultStreamCallback callback);
189
+ arrow::Result<std::unique_ptr<arrow::flight::Result>> Next() override;
190
+
191
+ private:
192
+ OwnedRefNoGIL generator_;
193
+ PyFlightResultStreamCallback callback_;
194
+ };
195
+
196
+ /// \brief A wrapper around a FlightDataStream that keeps alive a
197
+ /// Python object backing it.
198
+ class ARROW_PYFLIGHT_EXPORT PyFlightDataStream : public arrow::flight::FlightDataStream {
199
+ public:
200
+ /// \brief Construct a FlightDataStream from a Python object and underlying stream.
201
+ /// Must only be called while holding the GIL.
202
+ explicit PyFlightDataStream(PyObject* data_source,
203
+ std::unique_ptr<arrow::flight::FlightDataStream> stream);
204
+
205
+ std::shared_ptr<Schema> schema() override;
206
+ arrow::Result<arrow::flight::FlightPayload> GetSchemaPayload() override;
207
+ arrow::Result<arrow::flight::FlightPayload> Next() override;
208
+
209
+ private:
210
+ OwnedRefNoGIL data_source_;
211
+ std::unique_ptr<arrow::flight::FlightDataStream> stream_;
212
+ };
213
+
214
+ class ARROW_PYFLIGHT_EXPORT PyServerMiddlewareFactory
215
+ : public arrow::flight::ServerMiddlewareFactory {
216
+ public:
217
+ /// \brief A callback to create the middleware instance in Python
218
+ typedef std::function<Status(
219
+ PyObject*, const arrow::flight::CallInfo& info,
220
+ const arrow::flight::CallHeaders& incoming_headers,
221
+ std::shared_ptr<arrow::flight::ServerMiddleware>* middleware)>
222
+ StartCallCallback;
223
+
224
+ /// \brief Must only be called while holding the GIL.
225
+ explicit PyServerMiddlewareFactory(PyObject* factory, StartCallCallback start_call);
226
+
227
+ Status StartCall(const arrow::flight::CallInfo& info,
228
+ const arrow::flight::CallHeaders& incoming_headers,
229
+ std::shared_ptr<arrow::flight::ServerMiddleware>* middleware) override;
230
+
231
+ private:
232
+ OwnedRefNoGIL factory_;
233
+ StartCallCallback start_call_;
234
+ };
235
+
236
+ class ARROW_PYFLIGHT_EXPORT PyServerMiddleware : public arrow::flight::ServerMiddleware {
237
+ public:
238
+ typedef std::function<Status(PyObject*,
239
+ arrow::flight::AddCallHeaders* outgoing_headers)>
240
+ SendingHeadersCallback;
241
+ typedef std::function<Status(PyObject*, const Status& status)> CallCompletedCallback;
242
+
243
+ struct Vtable {
244
+ SendingHeadersCallback sending_headers;
245
+ CallCompletedCallback call_completed;
246
+ };
247
+
248
+ /// \brief Must only be called while holding the GIL.
249
+ explicit PyServerMiddleware(PyObject* middleware, Vtable vtable);
250
+
251
+ void SendingHeaders(arrow::flight::AddCallHeaders* outgoing_headers) override;
252
+ void CallCompleted(const Status& status) override;
253
+ std::string name() const override;
254
+ /// \brief Get the underlying Python object.
255
+ PyObject* py_object() const;
256
+
257
+ private:
258
+ OwnedRefNoGIL middleware_;
259
+ Vtable vtable_;
260
+ };
261
+
262
+ class ARROW_PYFLIGHT_EXPORT PyClientMiddlewareFactory
263
+ : public arrow::flight::ClientMiddlewareFactory {
264
+ public:
265
+ /// \brief A callback to create the middleware instance in Python
266
+ typedef std::function<Status(
267
+ PyObject*, const arrow::flight::CallInfo& info,
268
+ std::unique_ptr<arrow::flight::ClientMiddleware>* middleware)>
269
+ StartCallCallback;
270
+
271
+ /// \brief Must only be called while holding the GIL.
272
+ explicit PyClientMiddlewareFactory(PyObject* factory, StartCallCallback start_call);
273
+
274
+ void StartCall(const arrow::flight::CallInfo& info,
275
+ std::unique_ptr<arrow::flight::ClientMiddleware>* middleware) override;
276
+
277
+ private:
278
+ OwnedRefNoGIL factory_;
279
+ StartCallCallback start_call_;
280
+ };
281
+
282
+ class ARROW_PYFLIGHT_EXPORT PyClientMiddleware : public arrow::flight::ClientMiddleware {
283
+ public:
284
+ typedef std::function<Status(PyObject*,
285
+ arrow::flight::AddCallHeaders* outgoing_headers)>
286
+ SendingHeadersCallback;
287
+ typedef std::function<Status(PyObject*,
288
+ const arrow::flight::CallHeaders& incoming_headers)>
289
+ ReceivedHeadersCallback;
290
+ typedef std::function<Status(PyObject*, const Status& status)> CallCompletedCallback;
291
+
292
+ struct Vtable {
293
+ SendingHeadersCallback sending_headers;
294
+ ReceivedHeadersCallback received_headers;
295
+ CallCompletedCallback call_completed;
296
+ };
297
+
298
+ /// \brief Must only be called while holding the GIL.
299
+ explicit PyClientMiddleware(PyObject* factory, Vtable vtable);
300
+
301
+ void SendingHeaders(arrow::flight::AddCallHeaders* outgoing_headers) override;
302
+ void ReceivedHeaders(const arrow::flight::CallHeaders& incoming_headers) override;
303
+ void CallCompleted(const Status& status) override;
304
+
305
+ private:
306
+ OwnedRefNoGIL middleware_;
307
+ Vtable vtable_;
308
+ };
309
+
310
+ /// \brief A callback that obtains the next payload from a Flight result stream.
311
+ typedef std::function<Status(PyObject*, arrow::flight::FlightPayload*)>
312
+ PyGeneratorFlightDataStreamCallback;
313
+
314
+ /// \brief A FlightDataStream built around a Python callback.
315
+ class ARROW_PYFLIGHT_EXPORT PyGeneratorFlightDataStream
316
+ : public arrow::flight::FlightDataStream {
317
+ public:
318
+ /// \brief Construct a FlightDataStream from a Python object and underlying stream.
319
+ /// Must only be called while holding the GIL.
320
+ explicit PyGeneratorFlightDataStream(PyObject* generator,
321
+ std::shared_ptr<arrow::Schema> schema,
322
+ PyGeneratorFlightDataStreamCallback callback,
323
+ const ipc::IpcWriteOptions& options);
324
+ std::shared_ptr<Schema> schema() override;
325
+ arrow::Result<arrow::flight::FlightPayload> GetSchemaPayload() override;
326
+ arrow::Result<arrow::flight::FlightPayload> Next() override;
327
+
328
+ private:
329
+ OwnedRefNoGIL generator_;
330
+ std::shared_ptr<arrow::Schema> schema_;
331
+ ipc::DictionaryFieldMapper mapper_;
332
+ ipc::IpcWriteOptions options_;
333
+ PyGeneratorFlightDataStreamCallback callback_;
334
+ };
335
+
336
+ ARROW_PYFLIGHT_EXPORT
337
+ Status CreateFlightInfo(const std::shared_ptr<arrow::Schema>& schema,
338
+ const arrow::flight::FlightDescriptor& descriptor,
339
+ const std::vector<arrow::flight::FlightEndpoint>& endpoints,
340
+ int64_t total_records, int64_t total_bytes,
341
+ std::unique_ptr<arrow::flight::FlightInfo>* out);
342
+
343
+ /// \brief Create a SchemaResult from schema.
344
+ ARROW_PYFLIGHT_EXPORT
345
+ Status CreateSchemaResult(const std::shared_ptr<arrow::Schema>& schema,
346
+ std::unique_ptr<arrow::flight::SchemaResult>* out);
347
+
348
+ } // namespace flight
349
+ } // namespace py
350
+ } // namespace arrow
llmeval-env/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
llmeval-env/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
llmeval-env/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
+ }
llmeval-env/lib/python3.10/site-packages/pyarrow/include/arrow/python/ipc.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
+ #pragma once
19
+
20
+ #include <memory>
21
+
22
+ #include "arrow/python/common.h"
23
+ #include "arrow/python/visibility.h"
24
+ #include "arrow/record_batch.h"
25
+ #include "arrow/result.h"
26
+ #include "arrow/util/macros.h"
27
+
28
+ namespace arrow {
29
+ namespace py {
30
+
31
+ class ARROW_PYTHON_EXPORT PyRecordBatchReader : public RecordBatchReader {
32
+ public:
33
+ std::shared_ptr<Schema> schema() const override;
34
+
35
+ Status ReadNext(std::shared_ptr<RecordBatch>* batch) override;
36
+
37
+ // For use from Cython
38
+ // Assumes that `iterable` is borrowed
39
+ static Result<std::shared_ptr<RecordBatchReader>> Make(std::shared_ptr<Schema>,
40
+ PyObject* iterable);
41
+
42
+ protected:
43
+ PyRecordBatchReader();
44
+
45
+ Status Init(std::shared_ptr<Schema>, PyObject* iterable);
46
+
47
+ std::shared_ptr<Schema> schema_;
48
+ OwnedRefNoGIL iterator_;
49
+ };
50
+
51
+ class ARROW_PYTHON_EXPORT CastingRecordBatchReader : public RecordBatchReader {
52
+ public:
53
+ std::shared_ptr<Schema> schema() const override;
54
+
55
+ Status ReadNext(std::shared_ptr<RecordBatch>* batch) override;
56
+
57
+ static Result<std::shared_ptr<RecordBatchReader>> Make(
58
+ std::shared_ptr<RecordBatchReader> parent, std::shared_ptr<Schema> schema);
59
+
60
+ Status Close() override;
61
+
62
+ protected:
63
+ CastingRecordBatchReader();
64
+
65
+ Status Init(std::shared_ptr<RecordBatchReader> parent, std::shared_ptr<Schema> schema);
66
+
67
+ std::shared_ptr<RecordBatchReader> parent_;
68
+ std::shared_ptr<Schema> schema_;
69
+ };
70
+
71
+ } // namespace py
72
+ } // namespace arrow