rtpsw commented on code in PR #13880:
URL: https://github.com/apache/arrow/pull/13880#discussion_r954690186


##########
cpp/src/arrow/compute/exec/asof_join_node_test.cc:
##########
@@ -32,23 +35,172 @@
 #include "arrow/testing/random.h"
 #include "arrow/util/checked_cast.h"
 #include "arrow/util/make_unique.h"
+#include "arrow/util/string_view.h"
 #include "arrow/util/thread_pool.h"
 
+#define TRACED_TEST(t_class, t_name)          \
+  static void _##t_class##_##t_name();        \
+  TEST(t_class, t_name) {                     \
+    ARROW_SCOPED_TRACE(#t_class "_" #t_name); \
+    _##t_class##_##t_name();                  \
+  }                                           \
+  static void _##t_class##_##t_name()
+
 using testing::UnorderedElementsAreArray;
 
 namespace arrow {
 namespace compute {
 
+bool is_temporal_primitive(Type::type type_id) {
+  switch (type_id) {
+    case Type::TIME32:
+    case Type::TIME64:
+    case Type::DATE32:
+    case Type::DATE64:
+    case Type::TIMESTAMP:
+      return true;
+    default:
+      return false;
+  }
+}
+
+BatchesWithSchema MakeBatchesFromNumString(
+    const std::shared_ptr<Schema>& schema,
+    const std::vector<util::string_view>& json_strings, int multiplicity = 1) {
+  FieldVector num_fields;
+  for (auto field : schema->fields()) {
+    num_fields.push_back(
+        is_base_binary_like(field->type()->id()) ? field->WithType(int64()) : 
field);
+  }
+  auto num_schema =
+      std::make_shared<Schema>(num_fields, schema->endianness(), 
schema->metadata());
+  BatchesWithSchema num_batches =
+      MakeBatchesFromString(num_schema, json_strings, multiplicity);
+  BatchesWithSchema batches;
+  batches.schema = schema;
+  int n_fields = schema->num_fields();
+  for (auto num_batch : num_batches.batches) {
+    std::vector<Datum> values;
+    for (int i = 0; i < n_fields; i++) {
+      auto type = schema->field(i)->type();
+      if (is_base_binary_like(type->id())) {
+        // casting to string first enables casting to binary
+        Datum as_string = Cast(num_batch.values[i], utf8()).ValueOrDie();
+        values.push_back(Cast(as_string, type).ValueOrDie());
+      } else {
+        values.push_back(num_batch.values[i]);
+      }
+    }
+    ExecBatch batch(values, num_batch.length);
+    batches.batches.push_back(batch);
+  }
+  return batches;
+}
+
+void BuildNullArray(std::shared_ptr<Array>& empty, const 
std::shared_ptr<DataType>& type,
+                    int64_t length) {
+  ASSERT_OK_AND_ASSIGN(auto builder, MakeBuilder(type, default_memory_pool()));
+  ASSERT_OK(builder->Reserve(length));
+  ASSERT_OK(builder->AppendNulls(length));
+  ASSERT_OK(builder->Finish(&empty));
+}
+
+void BuildZeroPrimitiveArray(std::shared_ptr<Array>& empty,
+                             const std::shared_ptr<DataType>& type, int64_t 
length) {
+  ASSERT_OK_AND_ASSIGN(auto builder, MakeBuilder(type, default_memory_pool()));
+  ASSERT_OK(builder->Reserve(length));
+  ASSERT_OK_AND_ASSIGN(auto scalar, MakeScalar(type, 0));
+  ASSERT_OK(builder->AppendScalar(*scalar, length));
+  ASSERT_OK(builder->Finish(&empty));
+}
+
+template <typename Builder>
+void BuildZeroBaseBinaryArray(std::shared_ptr<Array>& empty, int64_t length) {
+  Builder builder(default_memory_pool());
+  ASSERT_OK(builder.Reserve(length));
+  for (int64_t i = 0; i < length; i++) {
+    ASSERT_OK(builder.Append("0", /*length=*/1));
+  }
+  ASSERT_OK(builder.Finish(&empty));
+}
+
+// mutates by copying from_key into to_key and changing from_key to zero
+BatchesWithSchema MutateByKey(BatchesWithSchema& batches, std::string from_key,
+                              std::string to_key, bool replace_key = false,
+                              bool null_key = false) {
+  int from_index = batches.schema->GetFieldIndex(from_key);
+  int n_fields = batches.schema->num_fields();
+  auto fields = batches.schema->fields();
+  BatchesWithSchema new_batches;
+  auto new_field = batches.schema->field(from_index)->WithName(to_key);
+  new_batches.schema = (replace_key ? batches.schema->SetField(from_index, 
new_field)
+                                    : batches.schema->AddField(from_index, 
new_field))
+                           .ValueOrDie();

Review Comment:
   Will do.



-- 
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]

Reply via email to