You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "zanmato1984 (via GitHub)" <gi...@apache.org> on 2024/04/24 17:48:25 UTC

Re: [I] [C++][Acero] Support join matching missing value [arrow]

zanmato1984 commented on issue #41358:
URL: https://github.com/apache/arrow/issues/41358#issuecomment-2075508642

   Acero does support this kind of join, which is enabled by `JoinKeyCmp::IS`:
   https://github.com/apache/arrow/blob/fd75cbdb38836b66dbae81094cf06821e5d25cb1/cpp/src/arrow/acero/options.h#L558
   
   So in C++, you are well able to do this as shown in the following quick demo:
   ```
   TEST(HashJoin, JoinKeyCmp) {
     std::vector<TypeHolder> left_types = {utf8()};
     auto left_batch = ExecBatchFromJSON(left_types, R"([["a"], [null], ["b"]])");
     std::vector<TypeHolder> right_types = {utf8(), int32()};
     auto right_batch = ExecBatchFromJSON(right_types, R"([["a", 1], [null, 2], ["b", 3]])");
   
     Declaration left{
         "exec_batch_source",
         ExecBatchSourceNodeOptions(schema({field("l_key", utf8())}), {left_batch})};
     Declaration right{
         "exec_batch_source",
         ExecBatchSourceNodeOptions(
             schema({field("r_key", utf8()), field("r_value", int32())}), {right_batch})};
   
     {
       std::cout << "Joining using JoinKeyCmp::EQ" << std::endl;
       HashJoinNodeOptions join_opts(JoinType::LEFT_OUTER, /*left_keys=*/{"l_key"},
                                     /*right_keys*/ {"r_key"}, /*left_output=*/{"l_key"},
                                     /*right_output=*/{"r_key", "r_value"},
                                     /*NOTE: key_cmp=*/{JoinKeyCmp::EQ});
       Declaration join{"hashjoin", {left, right}, join_opts};
       ASSERT_OK_AND_ASSIGN(auto result, DeclarationToTable(std::move(join)));
       std::cout << result->ToString() << std::endl;
     }
   
     {
       std::cout << "Joining using JoinKeyCmp::IS" << std::endl;
       HashJoinNodeOptions join_opts(JoinType::LEFT_OUTER, /*left_keys=*/{"l_key"},
                                     /*right_keys*/ {"r_key"}, /*left_output=*/{"l_key"},
                                     /*right_output=*/{"r_key", "r_value"},
                                     /*NOTE: key_cmp=*/{JoinKeyCmp::IS});
       Declaration join{"hashjoin", {left, right}, join_opts};
       ASSERT_OK_AND_ASSIGN(auto result, DeclarationToTable(std::move(join)));
       std::cout << result->ToString() << std::endl;
     }
   }
   ```
   
   Output:
   ```
   Joining using JoinKeyCmp::EQ
   ----
   l_key:
     [
       [
         "a",
         "b",
         null
       ]
     ]
   r_key:
     [
       [
         "a",
         "b",
         null
       ]
     ]
   r_value:
     [
       [
         1,
         3,
         null
       ]
     ]
   
   Joining using JoinKeyCmp::IS
   ----
   l_key:
     [
       [
         "a",
         null,
         "b"
       ]
     ]
   r_key:
     [
       [
         "a",
         null,
         "b"
       ]
     ]
   r_value:
     [
       [
         1,
         2,
         3
       ]
     ]
   ```
   
   But I'm not familiar with R binding so I can't really tell if this is available in R.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org