Skip to content
Closed
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ case class Like(left: Expression, right: Expression, escapeChar: Char = '\\')
""")
}
} else {
val pattern = ctx.freshName("pattern")
val rightStr = ctx.freshName("rightStr")
// We need double escape to avoid org.codehaus.commons.compiler.CompileException.
// '\\' will cause exception 'Single quote must be backslash-escaped in character literal'.
// '\"' will cause exception 'Line break in literal not allowed'.
Expand All @@ -162,10 +160,17 @@ case class Like(left: Expression, right: Expression, escapeChar: Char = '\\')
} else {
escapeChar
}
val rightStr = ctx.freshName("rightStr")
val pattern = ctx.addMutableState(patternClass, "pattern")
val lastRightStr = ctx.addMutableState(classOf[String].getName, "lastRightStr")

nullSafeCodeGen(ctx, ev, (eval1, eval2) => {
s"""
String $rightStr = $eval2.toString();
$patternClass $pattern = $patternClass.compile($escapeFunc($rightStr, '$newEscapeChar'));
if ($lastRightStr != $rightStr) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this optimization is a corner case and highly depends on input data.... cc: @dongjoon-hyun

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, and here I have an another idea.
Now BroadcastNestedLoopJoinExec always loop streamed firstly then nest loop broadcast and the pattern is always at broadcast side.
In inner like join, we can add another optimization that loop broadcast first and then nest loop streamed. So we can use the feature of this pr.

$pattern = $patternClass.compile($escapeFunc($rightStr, '$newEscapeChar'));
$lastRightStr = $rightStr;
}
${ev.value} = $pattern.matcher($eval1.toString()).matches();
"""
})
Expand Down Expand Up @@ -240,11 +245,16 @@ case class RLike(left: Expression, right: Expression) extends StringRegexExpress
}
} else {
val rightStr = ctx.freshName("rightStr")
val pattern = ctx.freshName("pattern")
val pattern = ctx.addMutableState(patternClass, "pattern")
val lastRightStr = ctx.addMutableState(classOf[String].getName, "lastRightStr")

nullSafeCodeGen(ctx, ev, (eval1, eval2) => {
s"""
String $rightStr = $eval2.toString();
$patternClass $pattern = $patternClass.compile($rightStr);
if ($rightStr != $lastRightStr) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you mean to use equals()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, forget this is not scala code.

$pattern = $patternClass.compile($rightStr);
$lastRightStr = $rightStr;
}
${ev.value} = $pattern.matcher($eval1.toString()).find(0);
"""
})
Expand Down