Skip to content

Conversation

@AngersZhuuuu
Copy link
Contributor

@AngersZhuuuu AngersZhuuuu commented Sep 21, 2019

What changes were proposed in this pull request?

Rewrite

NOT isnull(x)     -> isnotnull(x)
NOT isnotnull(x)  -> isnull(x)

Why are the changes needed?

Make LogicalPlan more readable and useful for query canonicalization. Make same condition equal when judge query canonicalization equal

Does this PR introduce any user-facing change?

NO

How was this patch tested?

Newly added UTs.

@AngersZhuuuu
Copy link
Contributor Author

gentle ping @juliuszsompolski
I agree a lot that we should simplify these expression. It's really useful for judge query canonicalization equal. Meet this problem when I am doing some cache framework .

Literal.create(null, e.dataType)

case n@Not(expr: IsNull) => IsNotNull(expr.child)
case n@Not(expr: IsNotNull) => IsNull(expr.child)
Copy link
Member

Choose a reason for hiding this comment

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

Why do you handle this in NullPropagation?

Copy link
Member

Choose a reason for hiding this comment

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

Also, plz check the code style carefully?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, plz check the code style carefully?

Sorry, forget to check this place...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why do you handle this in NullPropagation?

Don't found other better place, and it's also NULL expression problem.
Or add a new class?

Copy link
Member

Choose a reason for hiding this comment

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

Yea, the @viirya suggestion looks nice to me.

@HyukjinKwon
Copy link
Member

ok to test

@SparkQA
Copy link

SparkQA commented Sep 21, 2019

Test build #111122 has finished for PR 25878 at commit 9bf2d7c.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

}

case n @ Not(expr: IsNull) => IsNotNull(expr.child)
case n @ Not(expr: IsNotNull) => IsNull(expr.child)
Copy link
Member

Choose a reason for hiding this comment

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

you don't need n.

}

private def assertFilter(originalExpr: Expression,
expectedExpr: Expression): Unit = {
Copy link
Member

Choose a reason for hiding this comment

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

indent is wrong.

e.copy(branches = branches.take(i).map(branch => (branch._1, elseValue)))
}

case n @ Not(expr: IsNull) => IsNotNull(expr.child)
Copy link
Member

Choose a reason for hiding this comment

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

IsNull and IsNotNull are conditional expressions? Seems BooleanSimplification is more suitable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

conditional

Reasonable, I focus too much on isnull/isnotnull expression。

}
}

test("SPARK-29152: Simplify NOT(IsNull(x)) and NOT(IsNotNull(x))") {
Copy link
Member

Choose a reason for hiding this comment

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

nit: I personally think the SimplifyConditionalSuite test is enough for this fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nit: I personally think the SimplifyConditionalSuite test is enough for this fix.

Yeah, seems end-to-end test in SQLQuerySuit is redundant

}

test("simplify NOT(IsNull(x)) and NOT(IsNotNull(x))") {
assertFilter(Not(IsNotNull(UnresolvedAttribute("b"))), IsNull(UnresolvedAttribute("b")))
Copy link
Member

Choose a reason for hiding this comment

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

We cannot use assertEquivalent here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We cannot use assertEquivalent here?

assertEquivalent use OneRowRelation, no column, so I add a testRelation.
I will remove it to BooleanSimplificationSuit .

Copy link
Member

@maropu maropu left a comment

Choose a reason for hiding this comment

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

@dongjoon-hyun dongjoon-hyun changed the title [SPARK-29162][SQL]Simplify NOT(IsNull(x)) and NOT(IsNotNull(x)) [SPARK-29162][SQL] Simplify NOT(IsNull(x)) and NOT(IsNotNull(x)) Sep 22, 2019
case Not(Not(e)) => e

case Not(expr: IsNull) => IsNotNull(expr.child)
case Not(expr: IsNotNull) => IsNull(expr.child)
Copy link
Member

Choose a reason for hiding this comment

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

nit. expr -> e.

case Not(e: IsNull) => IsNotNull(e.child)
case Not(e: IsNotNull) => IsNull(e.child)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nit. expr -> e.

How about

      case Not(IsNull(e)) => IsNotNull(e)
      case Not(IsNotNull(e)) => IsNull(e)

Copy link
Member

Choose a reason for hiding this comment

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

Better!

test("simplify NOT(IsNull(x)) and NOT(IsNotNull(x))") {
checkCondition(Not(IsNotNull(UnresolvedAttribute("b"))), IsNull(UnresolvedAttribute("b")))
checkCondition(Not(IsNull(UnresolvedAttribute("b"))), IsNotNull(UnresolvedAttribute("b")))
}
Copy link
Member

Choose a reason for hiding this comment

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

@AngersZhuuuu . Since you are active contribution, I'd like to recommend to use DSL as possible as you can. (Please refer the other tests.)

  test("simplify NOT(IsNull(x)) and NOT(IsNotNull(x))") {
    checkCondition(Not(IsNotNull('e)), IsNull('e))
    checkCondition(Not(IsNull('e)), IsNotNull('e))
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AngersZhuuuu . Since you are active contribution, I'd like to recommend to use DSL as possible as you can. (Please refer the other tests.)

First time use DSL, I will get to know DSL more

@dongjoon-hyun
Copy link
Member

@AngersZhuuuu . Thank you for your contributions. I left two minor comments. Please address them.

@AngersZhuuuu
Copy link
Contributor Author

@AngersZhuuuu . Thank you for your contributions. I left two minor comments. Please address them.

Thank you for your advise. All for better job.

@SparkQA
Copy link

SparkQA commented Sep 22, 2019

Test build #111131 has finished for PR 25878 at commit a75c2ef.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Sep 22, 2019

Test build #111133 has finished for PR 25878 at commit cb9cef2.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Sep 22, 2019

Test build #111142 has finished for PR 25878 at commit f71698d.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@AngersZhuuuu
Copy link
Contributor Author

@AngersZhuuuu . Thank you for your contributions. I left two minor comments. Please address them.

Can you trigger restart test. Thanks .

@maropu
Copy link
Member

maropu commented Sep 22, 2019

retest this please

@SparkQA
Copy link

SparkQA commented Sep 22, 2019

Test build #111156 has finished for PR 25878 at commit f71698d.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

+1, LGTM. Merged to master. Thank you all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants