Package: cassandra-joinlib
Cassandra-Join-LibraryCassandra Join Operation Extension for Python. Client-sided and runs on single machine.Latest Version : 0.3.1Requirements :Python >= 3.7Supporting Only Cassandra 4.0Installation GuideTo install the package you will needpip, then runpip install cassandra-joinlib.
Pip install will automatically install all dependencies and you are ready to go. 🍻Usage GuideIt is actually pretty simple to use this library, this is the general steps for you to follow:This library works as an executor for join operation, so it focuses onJoinExecutorclass which has 2 types that you can utilize based on your needs:If you need an equi join, it is better to useHashJoinExecutor.HashJoinExecutoris importable fromcassandra_joinlib.hash_joinFor non equi-join, you may useNestedJoinExecutor(Hash join doesn't support non equi-join). ImportNestedJoinExecutorfromcassandra_joinlib.nested_join.BothHashJoinExecutorandNestedJoinExecutorrequires two parameters to be initialized, your connection with cassandrasessionand the name of the keyspacekeyspace_name.Example:HashJoinExecutor(session, keyspace_name).Once you have initialized the executor, you may add join operation/operations using these functions:join(TableInfo left_table_info, TableInfo, right_table_info, str operator)for inner joinrightJoin(TableInfo left_table_info, TableInfo right_table_info, str operator)for right outer joinleftJoin(TableInfo, left_table_info, TableInfo right_table_info, str operator)for left outer joinfullOuterJoin(TableInfo left_table_info, TableInfo right_table_info, str operator)for full outer joinWe needTableInfoobject for our join function. To initialize it, we need 2 params which are name of the table and name of the join column for that table.TableInfocan be imported fromcassandra_joinlib.commands.Example: Let's say we want to (inner) join tableuserand tablepayment_receivedbased on join columnemailusingHashJoinExecutor.left_table_info = TableInfo('user', 'email')
right_table_info = TableInfo('payment_received', 'email')
HashJoinExecutor(session, keyspace_name).join(left_table_info, right_table_info)Each of the join function returns join executor itself, so you may add a chained join operation like this:NestedJoinExecutor(session, keyspace_name) \
.join(left_table_info, right_table_info, "<") \
.fullOuterJoin(left_table_info_2, right_table_info2, "=")After you add join operation/operations to the executor, it actually queue the join command(s). You may execute the join operation when you think you are ready by using.execute()from the join executor and do not forget to save the join result with.save_result(filename).Example:HashJoinExecutor(session, keyspace_name) \
.join(left_tbl_info, right_tbl_info) \
.execute() \
.save_result("my_first_join")Note that the result will be saved in.txtfile in JSON FormatRun the python script and wait until it finishes execution.You may also print the join result by usingprintJoinResult(filename, max_buffer_size)which can be imported fromcassandra_joinlib.utils. Parammax_buffer_sizeis the number of rows that will be printed pertabulateand has10000as a default value. Print function should be called after.execute()function.That's it, you're done 🥳 🥳 🥳Hey... you can also get join execution time with.get_time_elapsed()called on the join executor after.execute()function.Important things you need to knowThis library executes any chained-join with left deep join method. It means that result of first join operation would be the left table of the second join operation, the result of second join operation would be the left table of the third join operation, and so on...For NON-first join, make sure you use the result from the previous join as left table.Example:tableinfo1_L = TableInfo("user", "email")
tableinfo1_R = TableInfo("payment_received", "email")

tableinfo2_L = TableInfo("user", "userid")
tableinfo2_R = TableInfo("user_item_like", "userid")

HashJoinExecutor(session, keyspace_name) \
.fullOuterJoin(tableinfo1_L, tableinfo1_R) \
.join(tableinfo2_L, tableinfo2_R) \
.execute() \
.save_result("chained_hash_join")Notice that on left table info for second join operationtableinfo2_L, we can useusertable sinceuserandpayment_receivedare in the result of the previous join operation.Cautions and Notescassandra-joinlibwill save some/all the incoming data from Cassandra due to the big size that cannot be fit into memory entirely.
BothHashJoinExecutorandNestedJoinExecutorhave partitioning mechanism and save the partitioned data inside a temporary folder calledtmpfolder.
The result of the join operation will be saved inside theresultfolder.Note that bothtmpfolderandresultwill be created inside your current working directory, please make sure you have enough space available for them.Author : Rafi AdyatmaInitially developed for my final project at Bandung Institute of Technology