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
Prev Previous commit
Next Next commit
Fix equality check with string.
  • Loading branch information
viirya committed Dec 21, 2017
commit 81c9b6e73ee64adcd8fc931d51f3faa98b892e0b
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ abstract class Expression extends TreeNode[Expression] {
private def reduceCodeSize(ctx: CodegenContext, eval: ExprCode): Unit = {
// TODO: support whole stage codegen too
if (eval.code.trim.length > 1024 && ctx.INPUT_ROW != null && ctx.currentVars == null) {
val setIsNull = if ("false" != eval.isNull && "true" != eval.isNull) {
val setIsNull = if ("false" != s"${eval.isNull}" && "true" != s"${eval.isNull}") {
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be simplified to !eval.isNull.instanceOf[LiteralValue]

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, yea.

val globalIsNull = ctx.addMutableState(ctx.JAVA_BOOLEAN, "globalIsNull")
val localIsNull = eval.isNull
eval.isNull = GlobalValue(globalIsNull)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ case class IsNull(child: Expression) extends UnaryExpression with Predicate {

override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
val eval = child.genCode(ctx)
val value = if ("true" == eval.isNull || "false" == eval.isNull) {
val value = if ("true" == s"${eval.isNull}" || "false" == s"${eval.isNull}") {
Copy link
Member

Choose a reason for hiding this comment

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

if ("true" == eval.isNull || "false" == eval.isNull) {?

Copy link
Contributor

Choose a reason for hiding this comment

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

or eval.isNull == Literal("true")? Or even better we can create a LiteralTrue = Literal("true") and equivalent for false and use them?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can do eval.isNull.instanceOf[LiteralValue] as suggested by @cloud-fan below.

LiteralValue(eval.isNull)
} else {
VariableValue(eval.isNull)
Expand Down Expand Up @@ -353,9 +353,9 @@ case class IsNotNull(child: Expression) extends UnaryExpression with Predicate {

override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
val eval = child.genCode(ctx)
val value = if ("true" == eval.isNull) {
val value = if ("true" == s"${eval.isNull}") {
Copy link
Member

Choose a reason for hiding this comment

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

ditto

LiteralValue("false")
} else if ("false" == eval.isNull) {
} else if ("false" == s"${eval.isNull}") {
LiteralValue("true")
} else {
StatementValue(s"(!(${eval.isNull}))")
Expand Down