-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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-8371][SQL] improve unit test for MaxOf and MinOf and fix bugs #6825
Conversation
checkEvaluation(MaxOf(true, false), true) | ||
checkEvaluation(MaxOf("abc", "bcd"), "bcd") | ||
// checkEvaluation(MaxOf(Array(1.toByte, 2.toByte), Array(1.toByte, 3.toByte)), | ||
// Array(1.toByte, 3.toByte)) |
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.
This test will fail at checkEvaluationWithGeneratedProjection
for hash code not equal. I'm not sure why we want to compare the hash code, and I looked into the hashCode
implementation of GenericRow
and Row
, they are different. I'm trying to figure it out.
} | ||
""" | ||
} else { | ||
super.genCode(ctx, ev) | ||
ctx.defaultCodeGen(ev, this) |
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.
The origin code is not right as super
here refers to BinaryArithmetic
, not Expression
that we wanted.
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.
yes,i think you are right. because their symbol is empty.
Test build #34923 has finished for PR 6825 at commit
|
Test build #34933 has finished for PR 6825 at commit
|
val eval1 = left.gen(ctx) | ||
val eval2 = right.gen(ctx) | ||
val result = if (dataType == BooleanType) { | ||
s"${ev.primitive} = ${eval1.primitive} || ${eval2.primitive};" |
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.
i think at first it needs to check whether eval1 or eval2 isNull. and then calculate primitive.
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.
the code result
is inserted after null check.
retest it please. |
@cloud-fan There are some changes related to Max/Min in #6726 , is it useful for you? It will be good if you could merge them here. |
Test build #34987 has finished for PR 6825 at commit
|
checkEvaluation(MaxOf("abc", "bcd"), "bcd") | ||
// checkEvaluation(MaxOf(Array(1.toByte, 2.toByte), Array(1.toByte, 3.toByte)), | ||
// Array(1.toByte, 3.toByte)) | ||
checkEvaluation(MaxOf(java.sql.Date.valueOf("2012-11-12"), java.sql.Date.valueOf("2012-12-22")), |
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.
All expressions only work with InternalRow, which only contain internal types (int, long, UTF8String), no Date or Timestamp. so we don't need to test Date/Timestamp, or use DateUtils.fromDate() to do the conversion before calling expression on them.
checkEvaluation(MaxOf(true, false), true) | ||
checkEvaluation(MaxOf("abc", "bcd"), UTF8String.fromString("bcd")) | ||
// checkEvaluation(MaxOf(Array(1.toByte, 2.toByte), Array(1.toByte, 3.toByte)), | ||
// Array(1.toByte, 3.toByte)) |
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.
This test will fail at checkEvaluationWithGeneratedProjection
for hash code not equal. I'm not sure why we want to compare the hash code, and I looked into the hashCode implementation of GenericRow
and Row
, they are different. Does anyone know why we want to compare the hash code there?
Test build #35044 has finished for PR 6825 at commit
|
@@ -109,7 +109,7 @@ trait ExpressionEvalHelper { | |||
} | |||
|
|||
val actual = plan(inputRow) | |||
val expectedRow = new GenericRow(Array[Any](CatalystTypeConverters.convertToCatalyst(expected))) | |||
val expectedRow = InternalRow.fromSeq(Array(CatalystTypeConverters.convertToCatalyst(expected))) |
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.
@davies , we need the conversion here, as we use String
instead of UTF8String
at many tests...
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.
Sound reasonable, it's anonying to have so many UTF8String.fromString
in test cases.
Test build #35045 has finished for PR 6825 at commit
|
@cloud-fan Now #6876 is merged, could you update this PR? |
Test build #35636 has finished for PR 6825 at commit
|
@@ -175,8 +175,10 @@ class CodeGenContext { | |||
* Generate code for compare expression in Java | |||
*/ | |||
def genComp(dataType: DataType, c1: String, c2: String): String = dataType match { | |||
// java boolean doesn't support > or < operator | |||
case BooleanType => s"($c1 == $c2 ? 0 : ($c1 ? 1 : -1))" |
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.
Good catch!
LGTM, the failed PySpark test is not related, merging this into master, thanks! |
Test build #955 has finished for PR 6825 at commit
|
a follow up of #6813