iChauster commented on code in PR #13426:
URL: https://github.com/apache/arrow/pull/13426#discussion_r923500215
##########
cpp/src/arrow/compute/exec/test_util.cc:
##########
@@ -459,5 +460,44 @@ void PrintTo(const Declaration& decl, std::ostream* os) {
*os << "}";
}
+std::shared_ptr<Table> MakeRandomTable(TableGenerationProperties properties) {
+ int total_columns = properties.num_columns + 2;
+ std::vector<std::shared_ptr<Array>> columns;
+ columns.reserve(total_columns);
+ arrow::FieldVector field_vector = arrow::FieldVector();
+ field_vector.reserve(total_columns);
+
+ field_vector.push_back(std::make_shared<Field>("time", int64()));
+ field_vector.push_back(std::make_shared<Field>("id", int32()));
+
+ int num_rows = 0;
+ std::vector<int64_t> time_column;
+ std::vector<int32_t> id_column;
+ for (int time = properties.start; time <= properties.end;
+ time += properties.time_frequency) {
+ for (int id = 0; id < properties.num_ids; id++) {
+ time_column.push_back(time);
+ id_column.push_back(id);
+ num_rows += 1;
+ }
+ }
+ std::shared_ptr<Array> time_array;
+ ArrayFromVector<Int64Type, int64_t>(int64(), time_column, &time_array);
+ columns.push_back(time_array);
+ std::shared_ptr<Array> id_array;
+ ArrayFromVector<Int32Type, int32_t>(int32(), id_column, &id_array);
+ columns.push_back(id_array);
+
+ for (int i = 0; i < properties.num_columns; i++) {
+ std::ostringstream string_stream;
+ string_stream << properties.column_prefix << i;
+ field_vector.push_back(std::make_shared<Field>(string_stream.str(),
float64()));
+ random::RandomArrayGenerator rand =
random::RandomArrayGenerator(properties.seed + i);
+ columns.push_back(rand.Float64(num_rows, -1e5, 1e5));
+ }
+ std::shared_ptr<arrow::Schema> schema =
std::make_shared<arrow::Schema>(field_vector);
Review Comment:
A bit of a cpp clarification question, why does `field_vector` need to be
moved here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]