-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
[SPARK-8305] [SPARK-8190] [SQL] improve codegen #6755
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,16 +250,11 @@ abstract class BinaryComparison extends BinaryExpression with Predicate { | |
} | ||
|
||
override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = { | ||
left.dataType match { | ||
case dt: NumericType if ctx.isNativeType(dt) => defineCodeGen (ctx, ev, { | ||
(c1, c3) => s"$c1 $symbol $c3" | ||
}) | ||
case DateType | TimestampType => defineCodeGen (ctx, ev, { | ||
(c1, c3) => s"$c1 $symbol $c3" | ||
}) | ||
case other => defineCodeGen (ctx, ev, { | ||
(c1, c2) => s"$c1.compare($c2) $symbol 0" | ||
}) | ||
if (ctx.isPrimitiveType(left.dataType)) { | ||
// faster version | ||
defineCodeGen(ctx, ev, (c1, c2) => s"$c1 $symbol $c2") | ||
} else { | ||
defineCodeGen(ctx, ev, (c1, c2) => s"${ctx.genComp(left.dataType, c1, c2)} $symbol 0") | ||
} | ||
} | ||
|
||
|
@@ -280,8 +275,9 @@ case class EqualTo(left: Expression, right: Expression) extends BinaryComparison | |
if (left.dataType != BinaryType) l == r | ||
else java.util.Arrays.equals(l.asInstanceOf[Array[Byte]], r.asInstanceOf[Array[Byte]]) | ||
} | ||
|
||
override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a blank line here |
||
defineCodeGen(ctx, ev, ctx.equalFunc(left.dataType)) | ||
defineCodeGen(ctx, ev, (c1, c2) => ctx.genEqual(left.dataType, c1, c2)) | ||
} | ||
} | ||
|
||
|
@@ -307,7 +303,7 @@ case class EqualNullSafe(left: Expression, right: Expression) extends BinaryComp | |
override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = { | ||
val eval1 = left.gen(ctx) | ||
val eval2 = right.gen(ctx) | ||
val equalCode = ctx.equalFunc(left.dataType)(eval1.primitive, eval2.primitive) | ||
val equalCode = ctx.genEqual(left.dataType, eval1.primitive, eval2.primitive) | ||
ev.isNull = "false" | ||
eval1.code + eval2.code + s""" | ||
boolean ${ev.primitive} = (${eval1.isNull} && ${eval2.isNull}) || | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,4 +53,12 @@ object TypeUtils { | |
|
||
def getOrdering(t: DataType): Ordering[Any] = | ||
t.asInstanceOf[AtomicType].ordering.asInstanceOf[Ordering[Any]] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove one extra line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
def compareBinary(x: Array[Byte], y: Array[Byte]): Int = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems super slow ... after this PR we should create a ByteArrayUtils in unsafe.types |
||
for (i <- 0 until x.length; if i < y.length) { | ||
val res = x(i).compareTo(y(i)) | ||
if (res != 0) return res | ||
} | ||
x.length - y.length | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(1.2 - 1.1).asInstanceOf[Int]
=> 0There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first case will handle float and double, using java.lang.Math.signum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add inline comment explaining why we have special case for float/double?