Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ object WindowJoinUtil {
windowEndEqualityRightKeys) =
excludeWindowStartEqualityAndEndEqualityFromJoinInfoPairs(join)

val joinInfo = join.analyzeCondition()
val joinSpec = JoinUtil.createJoinSpec(join)
val (remainLeftKeys, remainRightKeys, remainCondition) = if (
windowStartEqualityLeftKeys.nonEmpty || windowEndEqualityLeftKeys.nonEmpty) {
val leftChildFieldsType = join.getLeft.getRowType.getFieldList
Expand All @@ -98,31 +98,37 @@ object WindowJoinUtil {
val remainRightKeysArray = mutable.ArrayBuffer[Int]()
// convert remain pairs to RexInputRef tuple for building SqlStdOperatorTable.EQUALS calls
// or SqlStdOperatorTable.IS_NOT_DISTINCT_FROM
joinInfo.pairs().foreach { p =>
if (!windowStartEqualityLeftKeys.contains(p.source) &&
!windowEndEqualityLeftKeys.contains(p.source)) {
val leftFieldType = leftChildFieldsType.get(p.source).getType
val leftInputRef = new RexInputRef(p.source, leftFieldType)
val rightFieldType = rightChildFieldsType.get(p.target).getType
val rightIndex = leftFieldCnt + p.target
joinSpec.getLeftKeys.zip(joinSpec.getRightKeys).
zip(joinSpec.getFilterNulls).foreach { case ((source, target), filterNull) =>
if (!windowStartEqualityLeftKeys.contains(source) &&
!windowEndEqualityLeftKeys.contains(source)) {
val leftFieldType = leftChildFieldsType.get(source).getType
val leftInputRef = new RexInputRef(source, leftFieldType)
val rightFieldType = rightChildFieldsType.get(target).getType
val rightIndex = leftFieldCnt + target
val rightInputRef = new RexInputRef(rightIndex, rightFieldType)
val remainEqual = rexBuilder.makeCall(
SqlStdOperatorTable.EQUALS,
leftInputRef,
rightInputRef)
remainEquals.add(remainEqual)
remainLeftKeysArray.add(p.source)
remainRightKeysArray.add(p.target)
val op = if (filterNull) {
SqlStdOperatorTable.EQUALS
} else {
SqlStdOperatorTable.IS_NOT_DISTINCT_FROM
}
val remainEqual = rexBuilder.makeCall(op, leftInputRef, rightInputRef)
remainEquals += remainEqual
remainLeftKeysArray += source
remainRightKeysArray += target
}
}
val remainAnds = remainEquals ++ joinInfo.nonEquiConditions
val notEquiCondition = joinSpec.getNonEquiCondition
if (notEquiCondition.isPresent) {
remainEquals += notEquiCondition.get()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better we can rename this field to remainingConditions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
(
remainLeftKeysArray.toArray,
remainRightKeysArray.toArray,
// build a new condition
RexUtil.composeConjunction(rexBuilder, remainAnds.toList))
RexUtil.composeConjunction(rexBuilder, remainEquals.toList))
} else {
(joinInfo.leftKeys.toIntArray, joinInfo.rightKeys.toIntArray, join.getCondition)
(joinSpec.getLeftKeys, joinSpec.getRightKeys, join.getCondition)
}

(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ LogicalProject(a=[$0], window_start=[$1], window_end=[$2], window_time=[$3], cnt
</Resource>
<Resource name="optimized rel plan">
<![CDATA[
WindowJoin(leftWindow=[TUMBLE(win_start=[window_start], win_end=[window_end], size=[15 min])], rightWindow=[TUMBLE(win_start=[window_start], win_end=[window_end], size=[15 min])], joinType=[InnerJoin], where=[=(a, a0)], select=[a, window_start, window_end, window_time, cnt, uv, a0, window_start0, window_end0, window_time0, cnt0, uv0])
WindowJoin(leftWindow=[TUMBLE(win_start=[window_start], win_end=[window_end], size=[15 min])], rightWindow=[TUMBLE(win_start=[window_start], win_end=[window_end], size=[15 min])], joinType=[InnerJoin], where=[IS NOT DISTINCT FROM(a, a0)], select=[a, window_start, window_end, window_time, cnt, uv, a0, window_start0, window_end0, window_time0, cnt0, uv0])
:- Exchange(distribution=[hash[a]])
: +- Calc(select=[a, window_start, window_end, window_time, cnt, uv])
: +- GlobalWindowAggregate(groupBy=[a], window=[TUMBLE(slice_end=[$slice_end], size=[15 min])], select=[a, COUNT(count1$0) AS cnt, COUNT(distinct$0 count$1) AS uv, start('w$) AS window_start, end('w$) AS window_end, rowtime('w$) AS window_time])
Expand Down