Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use libcudf mixed joins for conditional hash semi and anti joins #4531

Merged
merged 4 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 3 additions & 40 deletions integration_tests/src/main/python/join_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,29 +504,14 @@ def do_join(spark):
# After 3.1.0 is the min spark version we can drop this
@ignore_order(local=True)
@pytest.mark.parametrize('data_gen', join_ast_gen, ids=idfn)
@pytest.mark.parametrize('join_type', ['Left', 'Right', 'FullOuter', 'Inner', 'Cross'], ids=idfn)
@pytest.mark.parametrize('join_type', all_join_types, ids=idfn)
def test_broadcast_join_with_conditionals(data_gen, join_type):
def do_join(spark):
left, right = create_df(spark, data_gen, 500, 250)
return left.join(broadcast(right),
(left.a == right.r_a) & (left.b >= right.r_b), join_type)
assert_gpu_and_cpu_are_equal_collect(do_join, conf=allow_negative_scale_of_decimal_conf)

# local sort because of https://github.com/NVIDIA/spark-rapids/issues/84
# After 3.1.0 is the min spark version we can drop this
@allow_non_gpu('BroadcastExchangeExec', 'BroadcastHashJoinExec', 'Cast', 'GreaterThan')
@ignore_order(local=True)
@pytest.mark.parametrize('data_gen', [long_gen], ids=idfn)
@pytest.mark.parametrize('join_type', ['LeftSemi', 'LeftAnti'], ids=idfn)
def test_broadcast_join_with_condition_join_type_fallback(data_gen, join_type):
def do_join(spark):
left, right = create_df(spark, data_gen, 50, 25)
# AST does not support cast or logarithm yet
return left.join(broadcast(right),
(left.a == right.r_a) & (left.b > right.r_b), join_type)
conf = allow_negative_scale_of_decimal_conf
assert_gpu_fallback_collect(do_join, 'BroadcastHashJoinExec', conf=conf)

# local sort because of https://github.com/NVIDIA/spark-rapids/issues/84
# After 3.1.0 is the min spark version we can drop this
@allow_non_gpu('BroadcastExchangeExec', 'BroadcastHashJoinExec', 'Cast', 'GreaterThan', 'Log', 'SortMergeJoinExec')
Expand Down Expand Up @@ -571,45 +556,23 @@ def do_join(spark):
(left.a == right.r_a) & (left.b > right.r_b), join_type)
assert_gpu_and_cpu_are_equal_collect(do_join, conf=allow_negative_scale_of_decimal_conf)

# local sort because of https://github.com/NVIDIA/spark-rapids/issues/84
# After 3.1.0 is the min spark version we can drop this
@ignore_order(local=True)
@pytest.mark.parametrize('data_gen', all_gen, ids=idfn)
def test_sortmerge_join_with_conditionals(data_gen):
def do_join(spark):
left, right = create_df(spark, data_gen, 500, 250)
return left.join(right, (left.a == right.r_a) & (left.b >= right.r_b), 'Inner')
assert_gpu_and_cpu_are_equal_collect(do_join, conf=_sortmerge_join_conf)

# local sort because of https://github.com/NVIDIA/spark-rapids/issues/84
# After 3.1.0 is the min spark version we can drop this
@ignore_order(local=True)
@pytest.mark.parametrize('data_gen', join_ast_gen, ids=idfn)
@pytest.mark.parametrize('join_type', ['Left', 'Right', 'FullOuter'], ids=idfn)
@pytest.mark.parametrize('join_type', ['Left', 'Right', 'Inner', 'FullOuter', 'LeftSemi', 'LeftAnti'], ids=idfn)
def test_sortmerge_join_with_condition_ast(data_gen, join_type):
def do_join(spark):
left, right = create_df(spark, data_gen, 500, 250)
return left.join(right, (left.a == right.r_a) & (left.b >= right.r_b), join_type)
assert_gpu_and_cpu_are_equal_collect(do_join, conf=_sortmerge_join_conf)

# local sort because of https://github.com/NVIDIA/spark-rapids/issues/84
# After 3.1.0 is the min spark version we can drop this
@allow_non_gpu('GreaterThan', 'ShuffleExchangeExec', 'SortMergeJoinExec')
@ignore_order(local=True)
@pytest.mark.parametrize('data_gen', [long_gen], ids=idfn)
@pytest.mark.parametrize('join_type', ['LeftSemi', 'LeftAnti'], ids=idfn)
def test_sortmerge_join_with_condition_join_type_fallback(data_gen, join_type):
def do_join(spark):
left, right = create_df(spark, data_gen, 500, 250)
return left.join(right, (left.a == right.r_a) & (left.b >= right.r_b), join_type)
assert_gpu_fallback_collect(do_join, 'SortMergeJoinExec', conf=_sortmerge_join_conf)

# local sort because of https://github.com/NVIDIA/spark-rapids/issues/84
# After 3.1.0 is the min spark version we can drop this
@allow_non_gpu('GreaterThan', 'Log', 'ShuffleExchangeExec', 'SortMergeJoinExec')
@ignore_order(local=True)
@pytest.mark.parametrize('data_gen', [long_gen], ids=idfn)
@pytest.mark.parametrize('join_type', ['Left', 'Right', 'FullOuter'], ids=idfn)
@pytest.mark.parametrize('join_type', ['Left', 'Right', 'FullOuter', 'LeftSemi', 'LeftAnti'], ids=idfn)
def test_sortmerge_join_with_condition_ast_op_fallback(data_gen, join_type):
def do_join(spark):
left, right = create_df(spark, data_gen, 500, 250)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,25 +104,19 @@ object GpuHashJoin extends Arm {
conditionMeta: Option[BaseExprMeta[_]]): Unit = {
val keyDataTypes = (leftKeys ++ rightKeys).map(_.dataType)

def unSupportNonEqualCondition(): Unit = if (conditionMeta.isDefined) {
meta.willNotWorkOnGpu(s"$joinType joins currently do not support conditions")
}
def unSupportStructKeys(): Unit = if (keyDataTypes.exists(_.isInstanceOf[StructType])) {
meta.willNotWorkOnGpu(s"$joinType joins currently do not support with struct keys")
}
JoinTypeChecks.tagForGpu(joinType, meta)
joinType match {
case _: InnerLike =>
case RightOuter | LeftOuter =>
case RightOuter | LeftOuter | LeftSemi | LeftAnti =>
conditionMeta.foreach(meta.requireAstForGpuOn)
case LeftSemi | LeftAnti =>
unSupportNonEqualCondition()
case FullOuter =>
conditionMeta.foreach(meta.requireAstForGpuOn)
// FullOuter join cannot support with struct keys as two issues below
// * https://github.com/NVIDIA/spark-rapids/issues/2126
// * https://github.com/rapidsai/cudf/issues/7947
unSupportStructKeys()
if (keyDataTypes.exists(_.isInstanceOf[StructType])) {
meta.willNotWorkOnGpu(s"$joinType joins currently do not support with struct keys")
}
case _ =>
meta.willNotWorkOnGpu(s"$joinType currently is not supported")
}
Expand Down Expand Up @@ -475,17 +469,26 @@ class ConditionalHashJoinIterator(
withResource(GpuColumnVector.from(leftData.getBatch)) { leftTable =>
withResource(GpuColumnVector.from(rightData.getBatch)) { rightTable =>
val maps = joinType match {
case _: InnerLike => Table.mixedInnerJoinGatherMaps(
leftKeys, rightKeys, leftTable, rightTable, compiledCondition, nullEquality)
case LeftOuter => Table.mixedLeftJoinGatherMaps(
leftKeys, rightKeys, leftTable, rightTable, compiledCondition, nullEquality)
case _: InnerLike =>
Table.mixedInnerJoinGatherMaps(leftKeys, rightKeys, leftTable, rightTable,
compiledCondition, nullEquality)
case LeftOuter =>
Table.mixedLeftJoinGatherMaps(leftKeys, rightKeys, leftTable, rightTable,
compiledCondition, nullEquality)
case RightOuter =>
// Reverse the output of the join, because we expect the right gather map to
// always be on the right
Table.mixedLeftJoinGatherMaps(rightKeys, leftKeys, rightTable, leftTable,
compiledCondition, nullEquality).reverse
case FullOuter => Table.mixedFullJoinGatherMaps(
leftKeys, rightKeys, leftTable, rightTable, compiledCondition, nullEquality)
case FullOuter =>
Table.mixedFullJoinGatherMaps(leftKeys, rightKeys, leftTable, rightTable,
compiledCondition, nullEquality)
case LeftSemi =>
Array(Table.mixedLeftSemiJoinGatherMap(leftKeys, rightKeys, leftTable, rightTable,
compiledCondition, nullEquality))
case LeftAnti =>
Array(Table.mixedLeftAntiJoinGatherMap(leftKeys, rightKeys, leftTable, rightTable,
compiledCondition, nullEquality))
case _ =>
throw new NotImplementedError(s"Joint Type ${joinType.getClass} is not currently" +
s" supported")
Expand Down