MCPcopy Create free account
hub / github.com/apache/arrow / Step

Function Step

cpp/src/arrow/testing/generator.h:321–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

319/// Note: overflow is not prevented standard unsigned integer overflow applies
320template <typename T = uint32_t>
321std::shared_ptr<ArrayGenerator> Step(T start = 0, T step = 1) {
322 class StepGenerator : public ArrayGenerator {
323 public:
324 // Use [[maybe_unused]] to avoid a compiler warning in Clang versions before 15 that
325 // incorrectly reports 'unused type alias'.
326 using ArrowType [[maybe_unused]] = typename CTypeTraits<T>::ArrowType;
327 static_assert(is_number_type<ArrowType>::value,
328 "Step generator only supports numeric types");
329
330 StepGenerator(T start, T step) : start_(start), step_(step) {}
331
332 Result<std::shared_ptr<Array>> Generate(int64_t num_rows) override {
333 TypedBufferBuilder<T> builder;
334 ARROW_RETURN_NOT_OK(builder.Reserve(num_rows));
335 T val = start_;
336 for (int64_t i = 0; i < num_rows; i++) {
337 builder.UnsafeAppend(val);
338 val += step_;
339 }
340 start_ = val;
341 ARROW_ASSIGN_OR_RAISE(auto buf, builder.Finish());
342 return MakeArray(ArrayData::Make(TypeTraits<ArrowType>::type_singleton(), num_rows,
343 {NULLPTR, std::move(buf)}, /*null_count=*/0));
344 }
345
346 std::shared_ptr<DataType> type() const override {
347 return TypeTraits<ArrowType>::type_singleton();
348 }
349
350 private:
351 T start_;
352 T step_;
353 };
354
355 return std::make_shared<StepGenerator>(start, step);
356}
357
358/// make a generator that returns a random value
359ARROW_TESTING_EXPORT std::shared_ptr<ArrayGenerator> Random(

Callers 9

ScanBatchesAsyncMethod · 0.85
TEST_FFunction · 0.85
TESTFunction · 0.85
CheckErrorFunction · 0.85
TestTableFunction · 0.85
TESTFunction · 0.85
TestTableFunction · 0.85
TestTableFunction · 0.85
TESTFunction · 0.85

Calls

no outgoing calls

Tested by 9

ScanBatchesAsyncMethod · 0.68
TEST_FFunction · 0.68
TESTFunction · 0.68
CheckErrorFunction · 0.68
TestTableFunction · 0.68
TESTFunction · 0.68
TestTableFunction · 0.68
TestTableFunction · 0.68
TESTFunction · 0.68