GitHub user windpiger opened a pull request: https://github.com/apache/spark/pull/15668
[SPARK-18137][SQL]Fix RewriteDistinctAggregates UnresolvedException w⦠## What changes were proposed in this pull request? In RewriteDistinctAggregates rewrite funtion,after the UDAF's childs are mapped to AttributeRefference, If the UDAF(such as ApproximatePercentile) has a foldable TypeCheck for the input, It will failed because the AttributeRefference is not foldable,then the UDAF is not resolved, and then nullify on the unresolved object will throw a Exception. In this PR, only map Unfoldable child to AttributeRefference, this can avoid the UDAF's foldable TypeCheck. and then only Expand Unfoldable child, there is no need to Expand a static value(foldable value). **Before sql result** >select percentile_approxy(key,0.99999),count(distinct key),sume(distinc key) from src limit 1 org.apache.spark.sql.catalyst.analysis.UnresolvedException: Invalid call to dataType on unresolved object, tree: 'percentile_approx(CAST(src.`key` AS DOUBLE), CAST(0.99999BD AS DOUBLE), 10000) at org.apache.spark.sql.catalyst.analysis.UnresolvedAttribute.dataType(unresolved.scala:92) at org.apache.spark.sql.catalyst.optimizer.RewriteDistinctAggregates$.org$apache$spark$sql$catalyst$optimizer$RewriteDistinctAggregates$$nullify(RewriteDistinctAggregates.scala:261) **After sql result** >select percentile_approxy(key,0.99999),count(distinct key),sume(distinc key) from src limit 1 [498.0,309,79136] ## How was this patch tested? Add a test case in HiveUDFSuit. You can merge this pull request into a Git repository by running: $ git pull https://github.com/windpiger/spark RewriteDistinctUDAFUnresolveExcep Alternatively you can review and apply these changes as the patch at: https://github.com/apache/spark/pull/15668.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #15668 ---- commit 7029e891ba25a026a8daf2664180166ee387bba5 Author: root <root@izbp1gsnrlfzjxh82cz80vz.(none)> Date: 2016-10-28T03:07:25Z [SPARK-18137][SQL]Fix RewriteDistinctAggregates UnresolvedException when the UDAF has a foldable TypeCheck ---- --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org