[ https://issues.apache.org/jira/browse/HIVE-25653?focusedWorklogId=671879&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-671879 ]
ASF GitHub Bot logged work on HIVE-25653: ----------------------------------------- Author: ASF GitHub Bot Created on: 29/Oct/21 08:57 Start Date: 29/Oct/21 08:57 Worklog Time Spent: 10m Work Description: adesh-rao commented on a change in pull request #2760: URL: https://github.com/apache/hive/pull/2760#discussion_r739045967 ########## File path: ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFStd.java ########## @@ -90,7 +92,9 @@ public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) * use it, etc. */ public static double calculateStdResult(double variance, long count) { - return Math.sqrt(variance / count); + BigDecimal bvariance = new BigDecimal(variance); + BigDecimal result = bvariance.divide(new BigDecimal(count)); + return Math.sqrt(result.doubleValue()); Review comment: Add a ToDo to use BigDecimal.sqrt() once hive moves to java >= 9 version? ########## File path: ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFVariance.java ########## @@ -120,14 +126,15 @@ public static double calculateMerge( long partialCount, long mergeCount, double partialSum, double mergeSum, double partialVariance, double mergeVariance) { - final double doublePartialCount = (double) partialCount; - final double doubleMergeCount = (double) mergeCount; + final BigDecimal bPartialCount = new BigDecimal(partialCount); + final BigDecimal bMergeCount = new BigDecimal(mergeCount); + BigDecimal bmergeVariance = new BigDecimal(mergeVariance); - double t = (doublePartialCount / doubleMergeCount) * mergeSum - partialSum; - mergeVariance += - partialVariance + ((doubleMergeCount / doublePartialCount) / - (doubleMergeCount + doublePartialCount)) * t * t; - return mergeVariance; + BigDecimal t = + (bPartialCount.divide(bMergeCount).multiply(new BigDecimal(mergeSum).subtract(new BigDecimal(partialSum)))); Review comment: the preview expression was `(doublePartialCount/doubleMergeCount) * mergeSum - partialSum` The new expression seems to be like: `(bPartialCount/bMergeCount )* (mergeSum - partialSum)`. Both are not equivalent. Can you fix this? ########## File path: ql/src/test/queries/clientpositive/sdtdev.q ########## @@ -0,0 +1,12 @@ +create table test ( col1 decimal(10,3) ); +insert into test values (10230.72),(10230.72),(10230.72),(10230.72),(10230.72),(10230.72),(10230.72); +select STDDEV_SAMP(col1) AS STDDEV_6M , STDDEV(col1) as STDDEV ,STDDEV_POP(col1) as STDDEV_POP , variance(col1) as variance,var_pop(col1) as var_pop,var_samp(col1) as var_samp from test; + +create table testpoint ( col1 decimal(10,3)); +insert into testpoint values (0.12345678),(0.25362123),(0.62437485),(0.65133746),(0.98765432),(0.12435647),(0.7654321445); +select STDDEV_SAMP(col1) AS STDDEV_6M , STDDEV(col1) as STDDEV ,STDDEV_POP(col1) as STDDEV_POP , variance(col1) as variance,var_pop(col1) as var_pop,var_samp(col1) as var_samp from testpoint; + +create table testint(col1 int); +insert into testint values (85),(86),(100),(76),(81),(93),(84),(99),(71),(69),(93),(85),(81),(87),(89); +select STDDEV_SAMP(col1) AS STDDEV_6M , STDDEV(col1) as STDDEV ,STDDEV_POP(col1) as STDDEV_POP, variance(col1) as variance,var_pop(col1) as var_pop,var_samp(col1) as var_samp from testint; + Review comment: nit: add drop table statements? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 671879) Time Spent: 20m (was: 10m) > Precision problem in STD, STDDDEV_SAMP,STDDEV_POP > ------------------------------------------------- > > Key: HIVE-25653 > URL: https://issues.apache.org/jira/browse/HIVE-25653 > Project: Hive > Issue Type: Improvement > Reporter: Ashish Sharma > Assignee: Ashish Sharma > Priority: Major > Labels: pull-request-available > Time Spent: 20m > Remaining Estimate: 0h > > Description > *Script*- > create table test ( col1 int ); > insert into values > ('10230.72'),('10230.72'),('10230.72'),('10230.72'),('10230.72'),('10230.72'),('10230.72'); > select STDDEV_SAMP(col1) AS STDDEV_6M , STDDEV(col1) as STDDEV > ,STDDEV_POP(col1) as STDDEV_POP from test; > *Result*- > STDDDEV_SAMP STDDEV > STDDEV_POP > 5.940794514955821E-13 5.42317860890711E-13 5.42317860890711E-13 > *Expected*- > STDDDEV_SAMP STDDEV > STDDEV_POP > 0 0 > 0 -- This message was sent by Atlassian Jira (v8.3.4#803005)