{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/11809","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/11809/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/11809/comments","events_url":"https://api.github.com/repos/apache/spark/issues/11809/events","html_url":"https://github.com/apache/spark/pull/11809","id":141760302,"number":11809,"title":"[SPARK-13995][SQL] Extract correct IsNotNull constraints for Expression","user":{"login":"viirya","id":68855,"avatar_url":"https://avatars.githubusercontent.com/u/68855?v=3","gravatar_id":"","url":"https://api.github.com/users/viirya","html_url":"https://github.com/viirya","followers_url":"https://api.github.com/users/viirya/followers","following_url":"https://api.github.com/users/viirya/following{/other_user}","gists_url":"https://api.github.com/users/viirya/gists{/gist_id}","starred_url":"https://api.github.com/users/viirya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viirya/subscriptions","organizations_url":"https://api.github.com/users/viirya/orgs","repos_url":"https://api.github.com/users/viirya/repos","events_url":"https://api.github.com/users/viirya/events{/privacy}","received_events_url":"https://api.github.com/users/viirya/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":31,"created_at":"2016-03-18T02:57:16Z","updated_at":"2016-03-24T23:32:54Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/11809","html_url":"https://github.com/apache/spark/pull/11809","diff_url":"https://github.com/apache/spark/pull/11809.diff","patch_url":"https://github.com/apache/spark/pull/11809.patch"},"body":"## What changes were proposed in this pull request?\r\n\r\nJIRA: https://issues.apache.org/jira/browse/SPARK-13995\r\n\r\nWe infer relative `IsNotNull` constraints from logical plan's expressions in `constructIsNotNullConstraints` now. However, we don't consider the case of (nested) `Cast`.\r\n\r\nFor example:\r\n\r\n    val tr = LocalRelation('a.int, 'b.long)\r\n    val plan = tr.where('a.attr === 'b.attr).analyze\r\n\r\nThen, the plan's constraints will have `IsNotNull(Cast(resolveColumn(tr, \"a\"), LongType))`, instead of `IsNotNull(resolveColumn(tr, \"a\"))`. This PR fixes it.\r\n\r\nBesides, as `IsNotNull` constraints are most useful for `Attribute`, we should do recursing through any `Expression` that is null intolerant and construct `IsNotNull` constraints for all `Attribute`s under these Expressions.\r\n\r\nFor example, consider the following constraints:\r\n\r\n    val df = Seq((1,2,3)).toDF(\"a\", \"b\", \"c\")\r\n    df.where(\"a + b = c\").queryExecution.analyzed.constraints\r\n\r\nThe inferred isnotnull constraints should be isnotnull(a), isnotnull(b), isnotnull(c), instead of isnotnull(a + c) and isnotnull(c).\r\n\r\n## How was this patch tested?\r\n\r\nTest is added into `ConstraintPropagationSuite`.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/201073538","html_url":"https://github.com/apache/spark/pull/11809#issuecomment-201073538","issue_url":"https://api.github.com/repos/apache/spark/issues/11809","id":201073538,"user":{"login":"viirya","id":68855,"avatar_url":"https://avatars.githubusercontent.com/u/68855?v=3","gravatar_id":"","url":"https://api.github.com/users/viirya","html_url":"https://github.com/viirya","followers_url":"https://api.github.com/users/viirya/followers","following_url":"https://api.github.com/users/viirya/following{/other_user}","gists_url":"https://api.github.com/users/viirya/gists{/gist_id}","starred_url":"https://api.github.com/users/viirya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viirya/subscriptions","organizations_url":"https://api.github.com/users/viirya/orgs","repos_url":"https://api.github.com/users/viirya/repos","events_url":"https://api.github.com/users/viirya/events{/privacy}","received_events_url":"https://api.github.com/users/viirya/received_events","type":"User","site_admin":false},"created_at":"2016-03-24T23:32:54Z","updated_at":"2016-03-24T23:32:54Z","body":"@marmbrus @sameeragarwal @gatorsmile This is ready for review now. Thanks!"}}