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


##########
cpp/src/arrow/compute/exec/asof_join_node.cc:
##########
@@ -184,27 +290,77 @@ class InputState {
     return queue_.UnsyncFront();
   }
 
-  KeyType GetLatestKey() const {
-    return queue_.UnsyncFront()
-        ->column_data(key_col_index_)
-        ->GetValues<KeyType>(1)[latest_ref_row_];
+#define LATEST_VAL_CASE(id, val)                            \
+  case Type::id: {                                          \
+    using T = typename TypeIdTraits<Type::id>::Type;        \
+    using CType = typename TypeTraits<T>::CType;            \
+    return val(data->GetValues<CType>(1)[latest_ref_row_]); \
+  }
+
+  ByType GetLatestKey() const {
+    const RecordBatch* batch = queue_.UnsyncFront().get();
+    if (must_hash_) {
+      return key_hasher_->HashesFor(batch)[latest_ref_row_];
+    }
+    auto data = batch->column_data(key_col_index_[0]);
+    switch (key_type_id_[0]) {
+      LATEST_VAL_CASE(INT8, key_value)
+      LATEST_VAL_CASE(INT16, key_value)
+      LATEST_VAL_CASE(INT32, key_value)
+      LATEST_VAL_CASE(INT64, key_value)
+      LATEST_VAL_CASE(UINT8, key_value)
+      LATEST_VAL_CASE(UINT16, key_value)
+      LATEST_VAL_CASE(UINT32, key_value)
+      LATEST_VAL_CASE(UINT64, key_value)
+      LATEST_VAL_CASE(DATE32, key_value)
+      LATEST_VAL_CASE(DATE64, key_value)
+      LATEST_VAL_CASE(TIME32, key_value)
+      LATEST_VAL_CASE(TIME64, key_value)
+      LATEST_VAL_CASE(TIMESTAMP, key_value)
+      default:
+        DCHECK(false);
+        return 0;  // cannot happen
+    }
   }
 
-  int64_t GetLatestTime() const {
-    return queue_.UnsyncFront()
-        ->column_data(time_col_index_)
-        ->GetValues<int64_t>(1)[latest_ref_row_];
+  OnType GetLatestTime() const {
+    auto data = queue_.UnsyncFront()->column_data(time_col_index_);
+    switch (time_type_id_) {

Review Comment:
   I tried this before and didn't like the macro-within-macro result I got. If 
we can come up with a good way to code the switch-statement using templates 
then I expect the result to look better.



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