db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1694392 - in /db/derby/code/trunk: java/build/org/apache/derbyBuild/lastgoodjarcontents/ java/engine/org/apache/derby/impl/sql/execute/ tools/jar/
Date Thu, 06 Aug 2015 03:27:01 GMT
Author: rhillegas
Date: Thu Aug  6 03:27:00 2015
New Revision: 1694392

URL: http://svn.apache.org/r1694392
Log:
DERBY-5466: Check in Scott Lewis' aggregator classes for var_pop(), var_samp(), stddev_pop()
and stddev_samp(); tests passed cleanly for me on derby-5466-01-aa-aggregatorClasses.diff.

Added:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StdDevPAggregator.java
  (with props)
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StdDevSAggregator.java
  (with props)
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VarPAggregator.java
  (with props)
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VarSAggregator.java
  (with props)
Modified:
    db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derby.jar.lastcontents
    db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derby.jar.lastcontents
    db/derby/code/trunk/tools/jar/extraDBMSclasses.properties

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derby.jar.lastcontents
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derby.jar.lastcontents?rev=1694392&r1=1694391&r2=1694392&view=diff
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derby.jar.lastcontents
(original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derby.jar.lastcontents
Thu Aug  6 03:27:00 2015
@@ -1098,6 +1098,8 @@ org.apache.derby.impl.sql.execute.SetTra
 org.apache.derby.impl.sql.execute.SetTransactionResultSet.class
 org.apache.derby.impl.sql.execute.SortResultSet.class
 org.apache.derby.impl.sql.execute.StatementTriggerExecutor.class
+org.apache.derby.impl.sql.execute.StdDevPAggregator.class
+org.apache.derby.impl.sql.execute.StdDevSAggregator.class
 org.apache.derby.impl.sql.execute.SumAggregator.class
 org.apache.derby.impl.sql.execute.SystemAggregator.class
 org.apache.derby.impl.sql.execute.TablePrivilegeInfo.class
@@ -1119,6 +1121,8 @@ org.apache.derby.impl.sql.execute.UserDe
 org.apache.derby.impl.sql.execute.VTIResultSet.class
 org.apache.derby.impl.sql.execute.ValidateCheckConstraintResultSet.class
 org.apache.derby.impl.sql.execute.ValueRow.class
+org.apache.derby.impl.sql.execute.VarPAggregator.class
+org.apache.derby.impl.sql.execute.VarSAggregator.class
 org.apache.derby.impl.sql.execute.WindowResultSet.class
 org.apache.derby.impl.sql.execute.WriteCursorConstantAction.class
 org.apache.derby.impl.sql.execute.rts.RealAnyResultSetStatistics.class

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derby.jar.lastcontents
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derby.jar.lastcontents?rev=1694392&r1=1694391&r2=1694392&view=diff
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derby.jar.lastcontents
(original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derby.jar.lastcontents
Thu Aug  6 03:27:00 2015
@@ -1101,6 +1101,8 @@ org.apache.derby.impl.sql.execute.SetTra
 org.apache.derby.impl.sql.execute.SetTransactionResultSet.class
 org.apache.derby.impl.sql.execute.SortResultSet.class
 org.apache.derby.impl.sql.execute.StatementTriggerExecutor.class
+org.apache.derby.impl.sql.execute.StdDevPAggregator.class
+org.apache.derby.impl.sql.execute.StdDevSAggregator.class
 org.apache.derby.impl.sql.execute.SumAggregator.class
 org.apache.derby.impl.sql.execute.SystemAggregator.class
 org.apache.derby.impl.sql.execute.TablePrivilegeInfo.class
@@ -1122,6 +1124,8 @@ org.apache.derby.impl.sql.execute.UserDe
 org.apache.derby.impl.sql.execute.VTIResultSet.class
 org.apache.derby.impl.sql.execute.ValidateCheckConstraintResultSet.class
 org.apache.derby.impl.sql.execute.ValueRow.class
+org.apache.derby.impl.sql.execute.VarPAggregator.class
+org.apache.derby.impl.sql.execute.VarSAggregator.class
 org.apache.derby.impl.sql.execute.WindowResultSet.class
 org.apache.derby.impl.sql.execute.WriteCursorConstantAction.class
 org.apache.derby.impl.sql.execute.rts.RealAnyResultSetStatistics.class

Added: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StdDevPAggregator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StdDevPAggregator.java?rev=1694392&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StdDevPAggregator.java
(added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StdDevPAggregator.java
Thu Aug  6 03:27:00 2015
@@ -0,0 +1,44 @@
+/*
+
+   Derby - Class org.apache.derby.impl.sql.execute.StdDevPAggregator
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.derby.impl.sql.execute;
+
+/**
+ * <p>
+ * This class implements the SQL Standard STDDEV_POP() aggregator,
+ * computing a population's standard deviation. It relies on VarPAggregator
+ * to compute the population variance and then applies the textbook definition
+ * of standard deviation:
+ * </p>
+ *
+ * <blockquote><pre><b>
+ * &radic;<span style="text-decoration:overline">var_pop()</span>
+ * </b></pre></blockquote>
+ */
+public class StdDevPAggregator<V extends Number> extends VarPAggregator<V> {
+
+	private static final long serialVersionUID = -265838381117407283L;
+
+	@Override
+	public Double terminate() {
+		Double var = computeVar();
+		return var == null?null:Math.sqrt(var);
+	}
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StdDevPAggregator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StdDevSAggregator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StdDevSAggregator.java?rev=1694392&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StdDevSAggregator.java
(added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StdDevSAggregator.java
Thu Aug  6 03:27:00 2015
@@ -0,0 +1,44 @@
+/*
+
+   Derby - Class org.apache.derby.impl.sql.execute.StdDevSAggregator
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.derby.impl.sql.execute;
+
+/**
+ * <p>
+ * This class implements the SQL Standard STDDEV_SAMP() aggregator,
+ * computing a sample's standard deviation. It relies on VarSAggregator
+ * to compute the sample's variance and then applies the textbook
+ * definition of standard deviation:
+ * </p>
+ *
+ * <blockquote><pre><b>
+ * &radic;<span style="text-decoration:overline">var_samp()</span>
+ * </b></pre></blockquote>
+ */
+public class StdDevSAggregator<V extends Number> extends VarSAggregator<V> {
+
+	private static final long serialVersionUID = -265838381117407283L;
+
+	@Override
+	public Double terminate() {
+		Double var = computeVar();
+		return var == null?null:Math.sqrt(var);
+	}
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StdDevSAggregator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VarPAggregator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VarPAggregator.java?rev=1694392&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VarPAggregator.java
(added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VarPAggregator.java
Thu Aug  6 03:27:00 2015
@@ -0,0 +1,114 @@
+/*
+
+   Derby - Class org.apache.derby.impl.sql.execute.VarPAggregator
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derby.impl.sql.execute;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import org.apache.derby.agg.Aggregator;
+
+/**
+ * <p>
+ * This class implements the SQL Standard VAR_POP() aggregator,
+ * computing a population's variance.  It uses the IBM formula described
+ * <a href="http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/db2/rbafzcolvar.htm">here</a>:
+ * </p>
+ *
+ * <blockquote><pre><b>
+ * sum(x<sub>i</sub><sup>2</sup>)/n - m<sup>2</sup>
+ * 
+ * where
+ * 
+ * n is the number of items in the population
+ * m is the population average
+ * x<sub>1</sub> ... x<sub>n</sub> are the items in the population
+ * </b></pre></blockquote>
+ *
+ * <p>
+ * The IBM formula can be computed without buffering up an arbitrarily
+ * long list of items. The IBM formula is algebraically equivalent
+ * to the textbook formula for population variance:
+ * </p>
+ *
+ * <blockquote><pre><b>
+ * sum( (x<sub>i</sub> - m)<sup>2</sup> )/n
+ * </b></pre></blockquote>
+ */
+public class VarPAggregator<V extends Number> implements Aggregator<V, Double, VarPAggregator<V>>,
Externalizable {
+
+	private static final long serialVersionUID = 239794626052067761L;
+
+	public static class Sums {
+		double x = 0;
+		double x2 = 0;		
+	}
+	
+	protected Sums sums;
+	protected int count;
+	
+	@Override
+	public void init() {
+		this.sums = new Sums();
+		this.count = 0;
+	}
+
+	@Override
+	public void accumulate(V value) {
+		double itemd = value.doubleValue();
+		sums.x += itemd;
+		sums.x2 += Math.pow(itemd,2);
+        count++;
+	}
+
+	@Override
+	public void merge(VarPAggregator<V> otherAggregator) {
+		this.sums.x += otherAggregator.sums.x;
+		this.sums.x2 += otherAggregator.sums.x2;
+		this.count += otherAggregator.count;
+	}
+
+	protected Double computeVar() {
+		if (count == 0) return null;
+		// See IBM formula: http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/db2/rbafzcolvar.htm
+		return (sums.x2 / count) - Math.pow(sums.x / count, 2.0); 
+	}
+
+	@Override
+	public Double terminate() {
+		return computeVar();
+	}
+
+	@Override
+	public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+		this.count = in.readInt();
+		this.sums = (Sums) in.readObject();
+	}
+
+	@Override
+	public void writeExternal(ObjectOutput out) throws IOException {
+		out.writeInt(this.count);
+		out.writeObject(this.sums);
+	}
+
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VarPAggregator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VarSAggregator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VarSAggregator.java?rev=1694392&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VarSAggregator.java
(added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VarSAggregator.java
Thu Aug  6 03:27:00 2015
@@ -0,0 +1,50 @@
+/*
+
+   Derby - Class org.apache.derby.impl.sql.execute.VarSAggregator
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derby.impl.sql.execute;
+
+/**
+ * <p>
+ * This class implements the SQL Standard VAR_SAMP() aggregator,
+ * computing the variance over a sample.  It uses the IBM formula described
+ * <a href="http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/db2/rbafzcolvarsamp.htm">here</a>:
+ * </p>
+ *
+ * <blockquote><pre><b>
+ * [ sum(x<sub>i</sub><sup>2</sup>) - sum(x<sub>i</sub>)<sup>2</sup>/n
]/(n-1)
+ * 
+ * where
+ * 
+ * n is the number of items in the population
+ * x<sub>1</sub> ... x<sub>n</sub> are the items in the population
+ * </b></pre></blockquote>
+ */
+public class VarSAggregator<V extends Number> extends VarPAggregator<V> {
+
+	private static final long serialVersionUID = -741087542836440595L;
+
+	@Override
+	protected Double computeVar() {
+		if (count <= 1) return null;
+		// See IBM Forumula:  http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/db2/rbafzcolvarsamp.htm
+		return (sums.x2 - (Math.pow(sums.x, 2) / count)) / (count - 1);
+	}
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VarSAggregator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/tools/jar/extraDBMSclasses.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/tools/jar/extraDBMSclasses.properties?rev=1694392&r1=1694391&r2=1694392&view=diff
==============================================================================
--- db/derby/code/trunk/tools/jar/extraDBMSclasses.properties (original)
+++ db/derby/code/trunk/tools/jar/extraDBMSclasses.properties Thu Aug  6 03:27:00 2015
@@ -25,7 +25,11 @@ derby.module.database.PropInfo=org.apach
 derby.module.database.Factory=org.apache.derby.iapi.db.Factory
 derby.module.aggs.MaxMinAggDef=org.apache.derby.impl.sql.compile.MaxMinAggregateDefinition
 derby.module.aggs.SumAvgAggDef=org.apache.derby.impl.sql.compile.SumAvgAggregateDefinition
-derby.module.aggs.SumAvgAggDef=org.apache.derby.impl.sql.execute.UserDefinedAggregator
+derby.module.aggs.UserDefinedAggDef=org.apache.derby.impl.sql.execute.UserDefinedAggregator
+derby.module.aggs.VarPopDef=org.apache.derby.impl.sql.execute.VarPAggregator
+derby.module.aggs.VarSampDef=org.apache.derby.impl.sql.execute.VarSAggregator
+derby.module.aggs.StdDevPopDef=org.apache.derby.impl.sql.execute.StdDevPAggregator
+derby.module.aggs.StdDevSampDef=org.apache.derby.impl.sql.execute.StdDevSAggregator
 derby.module.jndi.basicSchemaBase=org.apache.derby.impl.jdbc.authentication.JNDIAuthenticationSchemeBase
 derby.module.jndi.basicService=org.apache.derby.impl.jdbc.authentication.JNDIAuthenticationService
 derby.module.jndi.LDAPSchemeImpl=org.apache.derby.impl.jdbc.authentication.LDAPAuthenticationSchemeImpl



Mime
View raw message