from deephaven import new_table
from deephaven.column import string_col, int_col
from deephaven.constants import NULL_INT
from deephaven.table import NaturalJoinType
source_left = new_table(
[
string_col("LastName", ["Rafferty", "Jones", "Steiner", "Robins", "Smith"]),
int_col("DeptID", [31, 33, 33, 34, 34]),
string_col(
"Telephone",
[
"(303) 555-0162",
"(303) 555-0149",
"(303) 555-0184",
"(303) 555-0125",
"",
],
),
]
)
source_right = new_table(
[
int_col("DeptID", [31, 33, 34, 35]),
string_col("DeptName", ["Sales", "Engineering", "Clerical", "Marketing"]),
string_col(
"DeptTelephone",
["(303) 555-0136", "(303) 555-0162", "(303) 555-0175", "(303) 555-0171"],
),
]
)
result_error_on_duplicates = source_left.natural_join(table=source_right, on=["DeptID"], type=NaturalJoinType.ERROR_ON_DUPLICATE)
result_first_match = source_left.natural_join(table=source_right, on=["DeptID"], type=NaturalJoinType.FIRST_MATCH)
result_last_match = source_left.natural_join(table=source_right, on=["DeptID"], type=NaturalJoinType.LAST_MATCH)
result_exact_match = source_left.natural_join(table=source_right, on=["DeptID"], type=NaturalJoinType.EXACTLY_ONE_MATCH)