db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1695154 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Mon, 10 Aug 2015 19:40:42 GMT
Author: rhillegas
Date: Mon Aug 10 19:40:42 2015
New Revision: 1695154

URL: http://svn.apache.org/r1695154
Log:
DERBY-5466: Raise a useful error when someone attempts to use DISTINCT with the statistics
aggregates. Commit derby-5466-03-aa-distinctError.diff.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AggregateNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDAPermsTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AggregateNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AggregateNode.java?rev=1695154&r1=1695153&r2=1695154&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AggregateNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AggregateNode.java Mon
Aug 10 19:40:42 2015
@@ -349,8 +349,10 @@ class AggregateNode extends UnaryOperato
 		cf = getClassFactory();
 		classInspector = cf.getClassInspector();
 
+        boolean noSchema = true;
         if ( userAggregateName != null )
         {
+            noSchema = (userAggregateName.getSchemaName() == null );
             userAggregateName.bind();
         }
 
@@ -359,7 +361,6 @@ class AggregateNode extends UnaryOperato
         if (userAggregateName != null && uad == null)
         {
             String  schemaName = userAggregateName.getSchemaName();
-            boolean noSchema = schemaName == null;
             AliasDescriptor ad = resolveAggregate
                 (
                  dd,
@@ -388,6 +389,13 @@ class AggregateNode extends UnaryOperato
         if ( isUserDefinedAggregate() )
         {
             AliasDescriptor ad = ((UserAggregateDefinition) uad).getAliasDescriptor();
+            boolean         isModernBuiltinAggregate =
+                SchemaDescriptor.STD_SYSTEM_SCHEMA_NAME.equals( ad.getSchemaName() );
+
+            if ( distinct && isModernBuiltinAggregate )
+            {
+                throw StandardException.newException( SQLState.LANG_BAD_DISTINCT_AGG );
+            }
 
             // set up dependency on the user-defined aggregate and compile a check for USAGE
             // priv if needed
@@ -400,7 +408,7 @@ class AggregateNode extends UnaryOperato
                 // aggregates. They are tricky. They masquerade as user-defined
                 // aggregates because they implement org.apache.derby.agg.Aggregator
                 //
-                if ( !SchemaDescriptor.STD_SYSTEM_SCHEMA_NAME.equals( ad.getSchemaName()
) )
+                if ( !isModernBuiltinAggregate )
                 {
                     getCompilerContext().addRequiredUsagePriv( ad );
                 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=1695154&r1=1695153&r2=1695154&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Mon Aug 10 19:40:42
2015
@@ -2348,6 +2348,11 @@ Guide.
             </msg>
 
 	        <msg>
+                <name>42XAS</name>
+                <text>DISTINCT and ALL are not allowed with the VAR_POP, VAR_SAMP,
STDDEV_POP, and STDDEV_SAMP aggregates.</text>
+            </msg>
+
+	        <msg>
                 <name>42XBA</name>
                 <text>The schema, table or column does not exist or the column is not
a string type.</text>
             </msg>

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=1695154&r1=1695153&r2=1695154&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Mon Aug 10 19:40:42 2015
@@ -962,6 +962,7 @@ public interface SQLState {
     String LANG_NO_SYNONYMS_IN_MERGE                            = "42XAP";
     String LANG_NO_DCL_IN_MERGE                                         = "42XAQ";
     String LANG_SYSTEM_SEQUENCE                                         = "42XAR";
+    String LANG_BAD_DISTINCT_AGG                                         = "42XAS";
     String LANG_INVALID_USER_AGGREGATE_DEFINITION2                     = "42Y00";
 	String LANG_INVALID_CHECK_CONSTRAINT                               = "42Y01";
     // String LANG_NO_ALTER_TABLE_COMPRESS_ON_TARGET_TABLE             = "42Y02";

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDAPermsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDAPermsTest.java?rev=1695154&r1=1695153&r2=1695154&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDAPermsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDAPermsTest.java
Mon Aug 10 19:40:42 2015
@@ -1,6 +1,6 @@
 /*
 
-   Derby - Class org.apache.derbyTesting.functionTests.tests.lang.UDAPermsTest
+   Derby - Class org.apache.derbyTesting.functionTests.tests.lang.UDAPermsTestz
 
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -50,6 +50,8 @@ public class UDAPermsTest extends Genera
 
     private static  final   String      MISSING_ROUTINE = "42Y03";
     private static  final   String      IMPLICIT_CAST_ERROR = "42Y22";
+    private static  final   String      PARSE_ERROR = "42X01";
+    private static  final   String      BAD_DISTINCT = "42XAS";
 
     ///////////////////////////////////////////////////////////////////////////////////
     //
@@ -541,6 +543,12 @@ public class UDAPermsTest extends Genera
         // cannot schema-qualify a builtin aggregate name
         expectCompilationError( conn, MISSING_ROUTINE,
                                 "select sys." + aggName + "( a ) from ruth.doubles" );
+
+        // cannot use ALL or DISTINCT with a builtin aggregate
+        expectCompilationError( conn, PARSE_ERROR,
+                                "select " + aggName + "( all a ) from ruth.doubles" );
+        expectCompilationError( conn, BAD_DISTINCT,
+                                "select " + aggName + "( distinct a ) from ruth.doubles"
);
     }
     private void createSchema_005( Connection ruthConnection )
         throws Exception



Mime
View raw message