Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpp/src/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ set(ARROW_SRCS
type_traits.cc
visitor.cc
c/bridge.cc
c/dlpack.cc)
c/dlpack.cc
testing/random.cc)

arrow_add_object_library(ARROW_ARRAY
array/array_base.cc
Expand Down Expand Up @@ -737,7 +738,6 @@ set(ARROW_TESTING_SRCS
testing/gtest_util.cc
testing/math.cc
testing/process.cc
testing/random.cc
testing/util.cc)

#
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ arrow_components = {
'visitor.cc',
'c/bridge.cc',
'c/dlpack.cc',
'testing/random.cc',
],
},
}
Expand Down Expand Up @@ -311,7 +312,6 @@ arrow_testing_srcs = [
'testing/gtest_util.cc',
'testing/math.cc',
'testing/process.cc',
'testing/random.cc',
'testing/util.cc',
]

Expand Down
51 changes: 24 additions & 27 deletions cpp/src/arrow/testing/random.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

#include "arrow/testing/random.h"

#include <gtest/gtest.h>

#include <algorithm>
#include <array>
#include <cmath>
Expand All @@ -35,7 +33,6 @@
#include "arrow/buffer.h"
#include "arrow/extension_type.h"
#include "arrow/record_batch.h"
#include "arrow/testing/gtest_util.h"
#include "arrow/type.h"
#include "arrow/type_fwd.h"
#include "arrow/type_traits.h"
Expand Down Expand Up @@ -364,7 +361,7 @@ struct DecimalGenerator {
// Second compute decimal values from the individual components,
// building up a decimal array.
DecimalBuilderType builder(type_, memory_pool, alignment);
ABORT_NOT_OK(builder.Reserve(size));
ARROW_CHECK_OK(builder.Reserve(size));

const DecimalValue kDigitsMultiplier =
DecimalValue::GetScaleMultiplier(kMaxDigitsInInteger);
Expand All @@ -386,7 +383,7 @@ struct DecimalGenerator {
}
}
std::shared_ptr<Array> array;
ABORT_NOT_OK(builder.Finish(&array));
ARROW_CHECK_OK(builder.Finish(&array));
return array;
}
};
Expand Down Expand Up @@ -473,7 +470,7 @@ static std::shared_ptr<Array> GenerateBinaryArray(
using OffsetArrayType = typename TypeTraits<OffsetArrowType>::ArrayType;

if (null_probability < 0 || null_probability > 1) {
ABORT_NOT_OK(Status::Invalid("null_probability must be between 0 and 1"));
ARROW_CHECK_OK(Status::Invalid("null_probability must be between 0 and 1"));
}

auto lengths = std::dynamic_pointer_cast<OffsetArrayType>(gen->Numeric<OffsetArrowType>(
Expand All @@ -495,14 +492,14 @@ static std::shared_ptr<Array> GenerateBinaryArray(
for (int64_t i = 0; i < size; ++i) {
if (lengths->IsValid(i)) {
options.GenerateData(str_buffer.data(), lengths->Value(i));
ABORT_NOT_OK(builder.Append(str_buffer.data(), lengths->Value(i)));
ARROW_CHECK_OK(builder.Append(str_buffer.data(), lengths->Value(i)));
} else {
ABORT_NOT_OK(builder.AppendNull());
ARROW_CHECK_OK(builder.AppendNull());
}
}

std::shared_ptr<Array> result;
ABORT_NOT_OK(builder.Finish(&result));
ARROW_CHECK_OK(builder.Finish(&result));
return result;
}

Expand Down Expand Up @@ -562,22 +559,22 @@ std::shared_ptr<Array> RandomArrayGenerator::StringWithRepeats(
if (indices->IsValid(i)) {
const auto index = indices->Value(i);
const auto value = dictionary->GetView(index);
ABORT_NOT_OK(builder.Append(value));
ARROW_CHECK_OK(builder.Append(value));
} else {
ABORT_NOT_OK(builder.AppendNull());
ARROW_CHECK_OK(builder.AppendNull());
}
}

std::shared_ptr<Array> result;
ABORT_NOT_OK(builder.Finish(&result));
ARROW_CHECK_OK(builder.Finish(&result));
return result;
}

std::shared_ptr<Array> RandomArrayGenerator::FixedSizeBinary(
int64_t size, int32_t byte_width, double null_probability, uint8_t min_byte,
uint8_t max_byte, int64_t alignment, MemoryPool* memory_pool) {
if (null_probability < 0 || null_probability > 1) {
ABORT_NOT_OK(Status::Invalid("null_probability must be between 0 and 1"));
ARROW_CHECK_OK(Status::Invalid("null_probability must be between 0 and 1"));
}

// Visual Studio does not implement uniform_int_distribution for char types.
Expand Down Expand Up @@ -719,8 +716,8 @@ enable_if_parameter_free<ArrowType, T> GetMetadata(const KeyValueMetadata* metad
const auto& value = metadata->value(index);
T output{};
if (!internal::ParseValue<ArrowType>(value.data(), value.length(), &output)) {
ABORT_NOT_OK(Status::Invalid("Could not parse ", key, " = ", value, " as ",
ArrowType::type_name()));
ARROW_CHECK_OK(Status::Invalid("Could not parse ", key, " = ", value, " as ",
ArrowType::type_name()));
}
return output;
}
Expand Down Expand Up @@ -1034,14 +1031,14 @@ std::shared_ptr<Array> RandomArrayGenerator::DenseUnion(const ArrayVector& field
// Generate array of offsets
const auto& concrete_ids = checked_cast<const Int8Array&>(*type_ids);
Int32Builder offsets_builder(memory_pool, alignment);
ABORT_NOT_OK(offsets_builder.Reserve(size));
ARROW_CHECK_OK(offsets_builder.Reserve(size));
std::vector<int32_t> last_offsets(fields.size(), 0);
for (int64_t i = 0; i < size; ++i) {
const auto field_id = concrete_ids.Value(i);
offsets_builder.UnsafeAppend(last_offsets[field_id]++);
}
std::shared_ptr<Array> offsets;
ABORT_NOT_OK(offsets_builder.Finish(&offsets));
ARROW_CHECK_OK(offsets_builder.Finish(&offsets));

return *DenseUnionArray::Make(*type_ids, *offsets, fields, type_codes);
}
Expand All @@ -1059,15 +1056,15 @@ std::shared_ptr<Array> RandomArrayGenerator::ArrayOf(std::shared_ptr<DataType> t
std::shared_ptr<Array> RandomArrayGenerator::ArrayOf(const Field& field, int64_t length,
int64_t alignment,
MemoryPool* memory_pool) {
#define VALIDATE_RANGE(PARAM, MIN, MAX) \
if (PARAM < MIN || PARAM > MAX) { \
ABORT_NOT_OK(Status::Invalid(field.ToString(), ": ", ARROW_STRINGIFY(PARAM), \
" must be in [", MIN, ", ", MAX, " ] but got ", \
PARAM)); \
#define VALIDATE_RANGE(PARAM, MIN, MAX) \
if (PARAM < MIN || PARAM > MAX) { \
ARROW_CHECK_OK(Status::Invalid(field.ToString(), ": ", ARROW_STRINGIFY(PARAM), \
" must be in [", MIN, ", ", MAX, " ] but got ", \
PARAM)); \
}
#define VALIDATE_MIN_MAX(MIN, MAX) \
if (MIN > MAX) { \
ABORT_NOT_OK( \
ARROW_CHECK_OK( \
Status::Invalid(field.ToString(), ": min ", MIN, " must be <= max ", MAX)); \
}
#define GENERATE_INTEGRAL_CASE_VIEW(BASE_TYPE, VIEW_TYPE) \
Expand Down Expand Up @@ -1343,9 +1340,9 @@ std::shared_ptr<Array> RandomArrayGenerator::ArrayOf(const Field& field, int64_t
values_length, alignment, memory_pool);
auto merged = field.metadata() ? field.metadata() : key_value_metadata({}, {});
if (merged->Contains("min"))
ABORT_NOT_OK(Status::Invalid(field.ToString(), ": cannot specify min"));
ARROW_CHECK_OK(Status::Invalid(field.ToString(), ": cannot specify min"));
if (merged->Contains("max"))
ABORT_NOT_OK(Status::Invalid(field.ToString(), ": cannot specify max"));
ARROW_CHECK_OK(Status::Invalid(field.ToString(), ": cannot specify max"));
merged = merged->Merge(
*key_value_metadata({{"min", "0"}, {"max", ToChars(values_length - 1)}}));
auto indices = ArrayOf(
Expand Down Expand Up @@ -1401,7 +1398,7 @@ std::shared_ptr<Array> RandomArrayGenerator::ArrayOf(const Field& field, int64_t
const auto unique_values =
GetMetadata<int32_t>(field.metadata().get(), "unique", -1);
if (unique_values > 0) {
ABORT_NOT_OK(
ARROW_CHECK_OK(
Status::NotImplemented("Generating random array with repeated values for "
"large string/large binary types"));
}
Expand All @@ -1424,7 +1421,7 @@ std::shared_ptr<Array> RandomArrayGenerator::ArrayOf(const Field& field, int64_t
#undef VALIDATE_RANGE
#undef VALIDATE_MIN_MAX

ABORT_NOT_OK(
ARROW_CHECK_OK(
Status::NotImplemented("Generating random array for field ", field.ToString()));
return nullptr;
}
Expand Down
14 changes: 7 additions & 7 deletions cpp/src/arrow/testing/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
#include <vector>

#include "arrow/testing/uniform_real.h"
#include "arrow/testing/visibility.h"
#include "arrow/type.h"
#include "arrow/util/float16.h"
#include "arrow/util/visibility.h"

namespace arrow {

Expand All @@ -39,7 +39,7 @@ namespace random {
using SeedType = int32_t;
constexpr SeedType kSeedMax = std::numeric_limits<SeedType>::max();

class ARROW_TESTING_EXPORT RandomArrayGenerator {
class ARROW_EXPORT RandomArrayGenerator {
public:
explicit RandomArrayGenerator(SeedType seed)
: seed_distribution_(static_cast<SeedType>(1), kSeedMax), seed_rng_(seed) {}
Expand Down Expand Up @@ -696,14 +696,14 @@ class ARROW_TESTING_EXPORT RandomArrayGenerator {
};

/// Generate a batch with random data. See RandomArrayGenerator::BatchOf.
ARROW_TESTING_EXPORT
ARROW_EXPORT
std::shared_ptr<arrow::RecordBatch> GenerateBatch(
const FieldVector& fields, int64_t size, SeedType seed,
int64_t alignment = kDefaultBufferAlignment,
MemoryPool* memory_pool = default_memory_pool());

/// Generate an array with random data. See RandomArrayGenerator::BatchOf.
ARROW_TESTING_EXPORT
ARROW_EXPORT
std::shared_ptr<arrow::Array> GenerateArray(
const Field& field, int64_t size, SeedType seed,
int64_t alignment = kDefaultBufferAlignment,
Expand All @@ -715,9 +715,9 @@ std::shared_ptr<arrow::Array> GenerateArray(
// Assorted functions
//

ARROW_TESTING_EXPORT
ARROW_EXPORT
void rand_day_millis(int64_t N, std::vector<DayTimeIntervalType::DayMilliseconds>* out);
ARROW_TESTING_EXPORT
ARROW_EXPORT
void rand_month_day_nanos(int64_t N,
std::vector<MonthDayNanoIntervalType::MonthDayNanos>* out);

Expand All @@ -733,7 +733,7 @@ void rand_month_day_nanos(int64_t N,
/// \param[in] seed Random seed for reproducibility
/// \param[in] num_chars Number of Unicode code points to generate
/// \return a generated UTF-8 encoded string
ARROW_TESTING_EXPORT
ARROW_EXPORT
std::string RandomUtf8String(random::SeedType seed, int num_chars);

template <typename T, typename U>
Expand Down
3 changes: 2 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,8 @@ set(CYTHON_EXTENSIONS
_feather
_fs
_json
_pyarrow_cpp_tests)
_pyarrow_cpp_tests
_testing)
set_source_files_properties(pyarrow/lib.pyx PROPERTIES CYTHON_API TRUE)

set(LINK_LIBS arrow_python)
Expand Down
Loading
Loading