File indexing completed on 2025-08-28 08:27:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #pragma once
0019
0020 #include <algorithm>
0021 #include <cstdint>
0022 #include <cstdlib>
0023 #include <cstring>
0024 #include <limits>
0025 #include <memory>
0026 #include <optional>
0027 #include <string>
0028 #include <type_traits>
0029 #include <utility>
0030 #include <vector>
0031
0032 #include "arrow/buffer.h"
0033 #include "arrow/record_batch.h"
0034 #include "arrow/status.h"
0035 #include "arrow/testing/visibility.h"
0036 #include "arrow/type_fwd.h"
0037 #include "arrow/util/macros.h"
0038
0039 namespace arrow {
0040
0041 template <typename T>
0042 Status CopyBufferFromVector(const std::vector<T>& values, MemoryPool* pool,
0043 std::shared_ptr<Buffer>* result) {
0044 int64_t nbytes = static_cast<int>(values.size()) * sizeof(T);
0045
0046 ARROW_ASSIGN_OR_RAISE(auto buffer, AllocateBuffer(nbytes, pool));
0047 auto immutable_data = reinterpret_cast<const uint8_t*>(values.data());
0048 std::copy(immutable_data, immutable_data + nbytes, buffer->mutable_data());
0049 memset(buffer->mutable_data() + nbytes, 0,
0050 static_cast<size_t>(buffer->capacity() - nbytes));
0051
0052 *result = std::move(buffer);
0053 return Status::OK();
0054 }
0055
0056
0057
0058 ARROW_TESTING_EXPORT void random_null_bytes(int64_t n, double pct_null,
0059 uint8_t* null_bytes);
0060 ARROW_TESTING_EXPORT void random_is_valid(int64_t n, double pct_null,
0061 std::vector<bool>* is_valid,
0062 int random_seed = 0);
0063 ARROW_TESTING_EXPORT void random_bytes(int64_t n, uint32_t seed, uint8_t* out);
0064 ARROW_TESTING_EXPORT std::string random_string(int64_t n, uint32_t seed);
0065 ARROW_TESTING_EXPORT int32_t DecimalSize(int32_t precision);
0066 ARROW_TESTING_EXPORT void random_ascii(int64_t n, uint32_t seed, uint8_t* out);
0067 ARROW_TESTING_EXPORT int64_t CountNulls(const std::vector<uint8_t>& valid_bytes);
0068
0069 ARROW_TESTING_EXPORT Status MakeRandomByteBuffer(int64_t length, MemoryPool* pool,
0070 std::shared_ptr<ResizableBuffer>* out,
0071 uint32_t seed = 0);
0072
0073 ARROW_TESTING_EXPORT uint64_t random_seed();
0074
0075 #define DECL_T() typedef typename TestFixture::T T;
0076
0077 #define DECL_TYPE() typedef typename TestFixture::Type Type;
0078
0079
0080
0081
0082 class BatchIterator : public RecordBatchReader {
0083 public:
0084 BatchIterator(const std::shared_ptr<Schema>& schema,
0085 const std::vector<std::shared_ptr<RecordBatch>>& batches)
0086 : schema_(schema), batches_(batches), position_(0) {}
0087
0088 std::shared_ptr<Schema> schema() const override { return schema_; }
0089
0090 Status ReadNext(std::shared_ptr<RecordBatch>* out) override {
0091 if (position_ >= batches_.size()) {
0092 *out = nullptr;
0093 } else {
0094 *out = batches_[position_++];
0095 }
0096 return Status::OK();
0097 }
0098
0099 private:
0100 std::shared_ptr<Schema> schema_;
0101 std::vector<std::shared_ptr<RecordBatch>> batches_;
0102 size_t position_;
0103 };
0104
0105 static inline std::vector<std::shared_ptr<DataType> (*)(FieldVector, std::vector<int8_t>)>
0106 UnionTypeFactories() {
0107 return {sparse_union, dense_union};
0108 }
0109
0110
0111
0112 ARROW_TESTING_EXPORT Status GetTestResourceRoot(std::string*);
0113
0114
0115 ARROW_TESTING_EXPORT std::optional<std::string> GetTestTimezoneDatabaseRoot();
0116
0117
0118
0119 ARROW_TESTING_EXPORT Status InitTestTimezoneDatabase();
0120
0121
0122
0123
0124 ARROW_TESTING_EXPORT int GetListenPort();
0125
0126
0127
0128
0129 ARROW_TESTING_EXPORT std::string GetListenAddress();
0130
0131
0132
0133 ARROW_TESTING_EXPORT std::string GetListenAddress(const std::string& host);
0134
0135 ARROW_TESTING_EXPORT
0136 const std::vector<std::shared_ptr<DataType>>& all_dictionary_index_types();
0137
0138
0139
0140 ARROW_TESTING_EXPORT
0141 std::vector<int64_t> GetSupportedHardwareFlags(
0142 const std::vector<int64_t>& candidate_flags);
0143
0144 }