db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1396589 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/loc/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Wed, 10 Oct 2012 13:31:42 GMT
Author: rhillegas
Date: Wed Oct 10 13:31:41 2012
New Revision: 1396589

URL: http://svn.apache.org/viewvc?rev=1396589&view=rev
Log:
DERBY-672: Add tests of user-defined aggregates on all builtin Derby types except for XML.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LobMode.java
  (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UserAggregateDefinition.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GenericMode.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ModeAggregate.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UserDefinedAggregatesTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java?rev=1396589&r1=1396588&r2=1396589&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
Wed Oct 10 13:31:41 2012
@@ -30,6 +30,7 @@ import org.apache.derby.catalog.types.Ro
 import org.apache.derby.catalog.types.SynonymAliasInfo;
 import org.apache.derby.catalog.types.UDTAliasInfo;
 import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.reference.JDBC40Translation;
 import org.apache.derby.iapi.reference.Limits;
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.services.sanity.SanityManager;
@@ -150,6 +151,15 @@ public class CreateAliasNode extends DDL
                 TypeDescriptor  aggForType = bindUserCatalogType( (TypeDescriptor) aggElements[
AGG_FOR_TYPE ] );
                 TypeDescriptor  aggReturnType = bindUserCatalogType( (TypeDescriptor) aggElements[
AGG_RETURN_TYPE ] );
 
+                // XML not allowed because SQLXML support has not been implemented
+                if (
+                    (aggForType.getJDBCTypeId() == JDBC40Translation.SQLXML) ||
+                    (aggReturnType.getJDBCTypeId() == JDBC40Translation.SQLXML)
+                   )
+                {
+                    throw StandardException.newException( SQLState.LANG_XML_NOT_ALLOWED_DJRS
);
+                }
+
 				aliasInfo = new AggregateAliasInfo( aggForType, aggReturnType );
 				implicitCreateSchema = true;
                 break;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UserAggregateDefinition.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UserAggregateDefinition.java?rev=1396589&r1=1396588&r2=1396589&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UserAggregateDefinition.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UserAggregateDefinition.java
Wed Oct 10 13:31:41 2012
@@ -59,6 +59,8 @@ public class UserAggregateDefinition imp
     private static  final   int AGGREGATOR_TYPE = RETURN_TYPE + 1;
     private static  final   int AGGREGATOR_PARAM_COUNT = AGGREGATOR_TYPE + 1;
 
+    private static  final   String  DERBY_BYTE_ARRAY_NAME = "byte[]";
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // STATE
@@ -133,8 +135,8 @@ public class UserAggregateDefinition imp
             AggregateAliasInfo  aai = (AggregateAliasInfo) _alias.getAliasInfo();
             DataTypeDescriptor  expectedInputType = DataTypeDescriptor.getType( aai.getForType()
);
             DataTypeDescriptor  expectedReturnType = DataTypeDescriptor.getType( aai.getReturnType()
);
-            Class       expectedInputClass = getJavaClass( expectedInputType );
-            Class       expectedReturnClass = getJavaClass( expectedReturnType );
+            Class       expectedInputClass = getJavaClass( classFactory, expectedInputType
);
+            Class       expectedReturnClass = getJavaClass( classFactory, expectedReturnType
);
 
             // the input operand must be the expected input type of the aggregate
             if ( !inputType.getTypeId().equals( expectedInputType.getTypeId() ) ) { return
null; }
@@ -193,13 +195,20 @@ public class UserAggregateDefinition imp
     /**
      * Get the Java class corresponding to a Derby datatype.
      */
-    private Class   getJavaClass( DataTypeDescriptor dtd )
+    private Class   getJavaClass( ClassFactory classFactory, DataTypeDescriptor dtd )
         throws StandardException, ClassNotFoundException
     {
         JSQLType    jsqlType = new JSQLType( dtd );
         String  javaClassName = MethodCallNode.getObjectTypeName( jsqlType, null );
 
-        return Class.forName( javaClassName );
+        //
+        // The real class name of byte[] is [B. Class.forName( "byte[]" ) will throw a
+        // ClassNotFoundException.
+        //
+        if ( DERBY_BYTE_ARRAY_NAME.equals( javaClassName ) )
+        { javaClassName = byte[].class.getName(); }
+        
+        return classFactory.loadApplicationClass( javaClassName );
     }
 
     /**

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=1396589&r1=1396588&r2=1396589&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 Wed Oct 10 13:31:41
2012
@@ -2926,7 +2926,7 @@ Guide.
 
             <msg>
                 <name>42ZB3</name>
-                <text>XML is not allowed as the datatype of a column returned by a
table function.</text>
+                <text>XML is not allowed as the datatype of a user-defined aggregate
or of a column returned by a table function.</text>
             </msg>
 
             <msg>

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GenericMode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GenericMode.java?rev=1396589&r1=1396588&r2=1396589&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GenericMode.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GenericMode.java
Wed Oct 10 13:31:41 2012
@@ -20,11 +20,18 @@
  */
 package org.apache.derbyTesting.functionTests.tests.lang;
 
+import java.math.BigDecimal;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 
 import org.apache.derby.agg.Aggregator;
 
+/**
+ * <p>
+ * This is a generic mode aggregator for testing with many types.
+ * </p>
+ */
 public  class   GenericMode<V extends Comparable<V>>    implements  Aggregator<V,V,GenericMode<V>>
 {
     ///////////////////////////////////////////////////////////////////////////////////
@@ -33,7 +40,13 @@ public  class   GenericMode<V extends Co
     //
     ///////////////////////////////////////////////////////////////////////////////////
 
+    public  static  final   class   BigDecimalMode extends GenericMode<BigDecimal>
{}
+    public  static  final   class   BooleanMode extends GenericMode<Boolean> {}
+    public  static  final   class   ShortMode extends GenericMode<Short> {}
     public  static  final   class   IntMode extends GenericMode<Integer> {}
+    public  static  final   class   BigintMode extends GenericMode<Long> {}
+    public  static  final   class   DoubleMode extends GenericMode<Double> {}
+    public  static  final   class   RealMode extends GenericMode<Float> {}
     public  static  final   class   StringMode extends GenericMode<String> {}
     public  static  final   class   FullNameMode extends GenericMode<FullName> {}
     
@@ -71,20 +84,9 @@ public  class   GenericMode<V extends Co
         }
     }
 
-    // Generic arrays can't be created, so we have to cast the value on the way out.
-    // Suppress the resulting compiler warning.
-    @SuppressWarnings("unchecked")
     public  V terminate()
     {
-        int     numAccumulators = _accumulators.size();
-        if ( numAccumulators == 0 ) { return null; }
-        
-        Accumulator[]   accumulators = new Accumulator[ numAccumulators ];
-
-        accumulators = _accumulators.values().toArray( accumulators );
-        Arrays.sort( accumulators );
-        
-        return (V) accumulators[ numAccumulators - 1 ].getValue();
+        return _accumulators.isEmpty() ? null : Collections.max( _accumulators.values() ).getValue();
     }
 
     private Accumulator<V>   getAccumulator( V value )
@@ -124,8 +126,6 @@ public  class   GenericMode<V extends Co
         // Comparable behavior
         public  int compareTo( Accumulator<V> that )
         {
-            if ( that == null ) { return 1; }
-
             int retval = this._count - that._count;
 
             if ( retval != 0 ) { return retval; }

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LobMode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LobMode.java?rev=1396589&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LobMode.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LobMode.java
Wed Oct 10 13:31:41 2012
@@ -0,0 +1,183 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.lang.LobMode
+
+   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.derbyTesting.functionTests.tests.lang;
+
+import java.sql.Clob;
+import java.sql.Blob;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+
+import org.apache.derby.agg.Aggregator;
+
+/**
+ * <p>
+ * This is a version of GenericMode for use with types which are not Comparable.
+ * The class started out for use with Blob and Clob but was pressed into service
+ * for other types also.
+ * </p>
+ *
+ * <p>
+ * In particular, this is a mode aggregator for use with the
+ * JDBC date/time classes too. You can't use GenericMode with those types
+ * because they do not satisfy its type bounds. That is because they inherit the
+ * Comparable implementation of java.util.Date rather than implementing
+ * their own more specific version of Comparable. That is,
+ * java.sql.Date implements Comparable<java.util.Date> rather than
+ * Comparable<java.sql.Date>.
+ * </p>
+ */
+public  class   LobMode<V>    implements  Aggregator<V,V,LobMode<V>>
+{
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // NESTED CLASSES
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    public  static  final   class   ClobMode extends LobMode<Clob> {}
+    public  static  final   class   BlobMode extends LobMode<Blob> {}
+    public  static  final   class   BinaryMode extends LobMode<byte[]> {}
+    public  static  final   class   DateMode extends LobMode<Date> {}
+    public  static  final   class   TimeMode extends LobMode<Time> {}
+    public  static  final   class   TimestampMode extends LobMode<Timestamp> {}
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // STATE
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    private HashMap<String,Accumulator<V>>  _accumulators;
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTRUCTOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    public  LobMode() {}
+    
+    public  void    init()
+    {
+        _accumulators = new HashMap<String,Accumulator<V>>();
+    }
+    public  void    accumulate( V value )
+    {
+        getAccumulator( value ).add( 1 );
+    }
+    public  void    merge( LobMode<V> otherAggregator )
+    {
+        HashMap<String,Accumulator<V>>  otherAccumulators = otherAggregator._accumulators;
+        
+        for ( Accumulator<V> accumulator : otherAccumulators.values() )
+        {
+            V   value = accumulator.getValue();
+            getAccumulator( value ).add( accumulator.getCount() );
+        }
+    }
+
+    public  V terminate()
+    {
+        return _accumulators.isEmpty() ? null : Collections.max( _accumulators.values() ).getValue();
+    }
+
+    private Accumulator<V>   getAccumulator( V value )
+    {
+        String      key = toString( value );
+        
+        Accumulator<V>   retval = _accumulators.get( key );
+        if ( retval == null )
+        {
+            retval = new Accumulator<V>( value );
+            _accumulators.put( key, retval );
+        }
+
+        return retval;
+    }
+
+    static  String  toString( Object raw )
+    {
+        try {
+            if ( raw instanceof Clob )
+            {
+                Clob    clob = (Clob) raw;
+
+                return clob.getSubString( 1L, (int) clob.length() );
+            }
+            else if ( raw instanceof Blob )
+            {
+                Blob    blob = (Blob) raw;
+                byte[]  bytes = blob.getBytes( 1L, (int) blob.length() );
+
+                return new String( bytes, "UTF-8" );
+            }
+            else if ( raw instanceof Date ) { return raw.toString(); }
+            else if ( raw instanceof Time ) { return raw.toString(); }
+            else if ( raw instanceof Timestamp ) { return raw.toString(); }
+            else if ( raw instanceof byte[] )
+            {
+                byte[]  bytes = (byte[]) raw;
+
+                return new String( bytes, "UTF-8" );
+            }
+        } catch (Exception e) { throw new IllegalArgumentException( e ); }
+
+        throw new IllegalArgumentException( "Unsupported object type: " + raw.getClass().getName()
);
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // NESTED CLASSES
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    public  static  final   class   Accumulator<V> implements  Comparable<Accumulator<V>>
+    {
+        private V       _value;
+        private int         _count;
+
+        public  Accumulator( V value )
+        {
+            _value = value;
+            _count = 0;
+        }
+
+        public  void    add( int increment ) { _count += increment; }
+
+        public  V getValue() { return _value; }
+        public  int     getCount() { return _count; }
+
+        // Comparable behavior
+        public  int compareTo( Accumulator<V> that )
+        {
+            int retval = this._count - that._count;
+
+            if ( retval != 0 ) { return retval; }
+            else { return LobMode.toString( this._value ).compareTo( LobMode.toString( that._value
) ); }
+        }
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LobMode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ModeAggregate.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ModeAggregate.java?rev=1396589&r1=1396588&r2=1396589&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ModeAggregate.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ModeAggregate.java
Wed Oct 10 13:31:41 2012
@@ -22,10 +22,16 @@
 package org.apache.derbyTesting.functionTests.tests.lang;
 
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 
 import org.apache.derby.agg.Aggregator;
 
+/**
+ * <p>
+ * This is a mode aggregator for ints.
+ * </p>
+ */
 public  class   ModeAggregate    implements  Aggregator<Integer,Integer,ModeAggregate>
 {
     ///////////////////////////////////////////////////////////////////////////////////
@@ -64,15 +70,7 @@ public  class   ModeAggregate    impleme
 
     public  Integer terminate()
     {
-        int     numAccumulators = _accumulators.size();
-        if ( numAccumulators == 0 ) { return null; }
-        
-        Accumulator[]   accumulators = new Accumulator[ numAccumulators ];
-
-        accumulators = _accumulators.values().toArray( accumulators );
-        Arrays.sort( accumulators );
-        
-        return accumulators[ numAccumulators - 1 ].getValue();
+        return _accumulators.isEmpty() ? null : Collections.max( _accumulators.values() ).getValue();
     }
 
     private Accumulator   getAccumulator( Integer value )
@@ -112,8 +110,6 @@ public  class   ModeAggregate    impleme
         // Comparable behavior
         public  int compareTo( Accumulator that )
         {
-            if ( that == null ) { return 1; }
-
             int retval = this._count - that._count;
 
             if ( retval != 0 ) { return retval; }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UserDefinedAggregatesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UserDefinedAggregatesTest.java?rev=1396589&r1=1396588&r2=1396589&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UserDefinedAggregatesTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UserDefinedAggregatesTest.java
Wed Oct 10 13:31:41 2012
@@ -28,12 +28,17 @@ import java.sql.ParameterMetaData;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
+import java.sql.Blob;
+import java.sql.Clob;
 import java.util.HashMap;
 
 import junit.framework.Test;
 import org.apache.derbyTesting.junit.TestConfiguration;
 import org.apache.derbyTesting.junit.JDBC;
 
+import org.apache.derby.iapi.types.HarmonySerialBlob;
+import org.apache.derby.iapi.types.HarmonySerialClob;
+
 /**
  * <p>
  * Test user defined aggregates. See DERBY-672.
@@ -55,6 +60,10 @@ public class UserDefinedAggregatesTest  
     public static final String BAD_AGGREGATE_USAGE = "42903";
     public static final String BAD_ORDER_BY = "42Y35";
     public static final String INPUT_MISMATCH = "42Y22";
+    public static final String BAD_GEN_COL = "42XA1";
+    public static final String INPUT_OUTSIDE_BOUNDS = "42ZC6";
+    public static final String RETURN_OUTSIDE_BOUNDS = "42ZC7";
+    public static final String XML_TYPE = "42ZB3";
 
     ///////////////////////////////////////////////////////////////////////////////////
     //
@@ -1016,6 +1025,749 @@ public class UserDefinedAggregatesTest  
              );
         expectCompilationError( INPUT_MISMATCH, "select intMode_10( b ) from intMode_10_inputs"
);
 
+        // aggregates not allowed in generated columns
+        expectCompilationError( BAD_GEN_COL, "create table t_shouldFail( a int, b int generated
always as ( intMode_10( a ) ) )" );
+
+        //
+        // Input type not within bounds of aggregator class.
+        //
+        goodStatement
+            (
+             conn,
+             "create type Price_10 external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java"
+             );
+        goodStatement
+            (
+             conn,
+             "create table t_price_10( a int, b Price_10 )"
+             );
+        goodStatement
+            (
+             conn,
+             "create derby aggregate priceMode_10 for Price_10\n" +
+             "external name 'org.apache.derbyTesting.functionTests.tests.lang.GenericMode'\n"
+             );
+        expectCompilationError( INPUT_OUTSIDE_BOUNDS, "select priceMode_10( b ) from t_price_10"
);
+        expectCompilationError( INPUT_OUTSIDE_BOUNDS, "select a, priceMode_10( b ) from t_price_10
group by a" );
+
+        //
+        // Return type not within bounds of aggregator class.
+        //
+        goodStatement
+            (
+             conn,
+             "create table t_price_10_1( a int, b int )"
+             );
+        goodStatement
+            (
+             conn,
+             "create derby aggregate priceMode_10_1 for int returns Price_10\n" +
+             "external name 'org.apache.derbyTesting.functionTests.tests.lang.GenericMode'"
+             );
+        expectCompilationError( RETURN_OUTSIDE_BOUNDS, "select priceMode_10_1( b ) from t_price_10_1"
);
+        expectCompilationError( RETURN_OUTSIDE_BOUNDS, "select a, priceMode_10_1( b ) from
t_price_10_1 group by a" );
+    }
+
+    /**
+     * <p>
+     * Test datatype coverage. Verify that you can declare user-defined aggregates on all
+     * Derby data types except for XML.
+     * </p>
+     */
+    public void test_11_datatypes() throws Exception
+    {
+        Connection conn = getConnection();
+
+        // if this fails, then we need to add a new data type to this test
+        vetDatatypeCount( conn, 22 );
+        
+        vetParameterizedAggregate
+            (
+             conn,
+             "booleanMode_11",
+             "boolean",
+             "org.apache.derbyTesting.functionTests.tests.lang.GenericMode$BooleanMode",
+             "( 1, false ), ( 1, true ), (1, false ), ( 2, true ), ( 2, true ), ( 3, false
), ( 3, true ), ( 3, true )",
+             new String[][]
+             {
+                 { "true" },
+             },
+             new String[][]
+             {
+                 { "1", "false" },
+                 { "2", "true" },
+                 { "3", "true" },
+             },
+             new String[][]
+             {
+                 { "true" },
+             },
+             new String[][]
+             {
+                 { "1", "true" },
+                 { "2", "true" },
+                 { "3", "true" },
+             }
+             );
+
+        vetParameterizedAggregate
+            (
+             conn,
+             "bigintMode_11",
+             "bigint",
+             "org.apache.derbyTesting.functionTests.tests.lang.GenericMode$BigintMode",
+             "( 1, 1 ), ( 1, 2 ), (1, 2 ), ( 2, 2 ), ( 2, 3 ), ( 3, 3 ), ( 3, 4 ), ( 3, 5
)",
+             new String[][]
+             {
+                 { "2" },
+             },
+             new String[][]
+             {
+                 { "1", "2" },
+                 { "2", "3" },
+                 { "3", "5" },
+             },
+             new String[][]
+             {
+                 { "5" },
+             },
+             new String[][]
+             {
+                 { "1", "2" },
+                 { "2", "3" },
+                 { "3", "5" },
+             }
+             );
+
+        vetParameterizedAggregate
+            (
+             conn,
+             "smallintMode_11",
+             "smallint",
+             "org.apache.derbyTesting.functionTests.tests.lang.GenericMode$IntMode",
+             "( 1, 1 ), ( 1, 2 ), (1, 2 ), ( 2, 2 ), ( 2, 3 ), ( 3, 3 ), ( 3, 4 ), ( 3, 5
)",
+             new String[][]
+             {
+                 { "2" },
+             },
+             new String[][]
+             {
+                 { "1", "2" },
+                 { "2", "3" },
+                 { "3", "5" },
+             },
+             new String[][]
+             {
+                 { "5" },
+             },
+             new String[][]
+             {
+                 { "1", "2" },
+                 { "2", "3" },
+                 { "3", "5" },
+             }
+             );
+
+        vetParameterizedAggregate
+            (
+             conn,
+             "intMode_11",
+             "int",
+             "org.apache.derbyTesting.functionTests.tests.lang.GenericMode$IntMode",
+             "( 1, 1 ), ( 1, 2 ), (1, 2 ), ( 2, 2 ), ( 2, 3 ), ( 3, 3 ), ( 3, 4 ), ( 3, 5
)",
+             new String[][]
+             {
+                 { "2" },
+             },
+             new String[][]
+             {
+                 { "1", "2" },
+                 { "2", "3" },
+                 { "3", "5" },
+             },
+             new String[][]
+             {
+                 { "5" },
+             },
+             new String[][]
+             {
+                 { "1", "2" },
+                 { "2", "3" },
+                 { "3", "5" },
+             }
+             );
+
+        vetParameterizedAggregate
+            (
+             conn,
+             "decimalMode_11",
+             "decimal( 5, 2 )",
+             "org.apache.derbyTesting.functionTests.tests.lang.GenericMode$BigDecimalMode",
+             "( 1, 1.11 ), ( 1, 2.22 ), (1, 2.22 ), ( 2, 2.22 ), ( 2, 3.33 ), ( 3, 3.33 ),
( 3, 4.44 ), ( 3, 5.55 )",
+             new String[][]
+             {
+                 { "2.22" },
+             },
+             new String[][]
+             {
+                 { "1", "2.22" },
+                 { "2", "3.33" },
+                 { "3", "5.55" },
+             },
+             new String[][]
+             {
+                 { "5.55" },
+             },
+             new String[][]
+             {
+                 { "1", "2.22" },
+                 { "2", "3.33" },
+                 { "3", "5.55" },
+             }
+             );
+
+        vetParameterizedAggregate
+            (
+             conn,
+             "numericMode_11",
+             "numeric( 5, 2 )",
+             "org.apache.derbyTesting.functionTests.tests.lang.GenericMode$BigDecimalMode",
+             "( 1, 1.11 ), ( 1, 2.22 ), (1, 2.22 ), ( 2, 2.22 ), ( 2, 3.33 ), ( 3, 3.33 ),
( 3, 4.44 ), ( 3, 5.55 )",
+             new String[][]
+             {
+                 { "2.22" },
+             },
+             new String[][]
+             {
+                 { "1", "2.22" },
+                 { "2", "3.33" },
+                 { "3", "5.55" },
+             },
+             new String[][]
+             {
+                 { "5.55" },
+             },
+             new String[][]
+             {
+                 { "1", "2.22" },
+                 { "2", "3.33" },
+                 { "3", "5.55" },
+             }
+             );
+
+        vetParameterizedAggregate
+            (
+             conn,
+             "doubleMode_11",
+             "double",
+             "org.apache.derbyTesting.functionTests.tests.lang.GenericMode$DoubleMode",
+             "( 1, 1.11 ), ( 1, 2.22 ), (1, 2.22 ), ( 2, 2.22 ), ( 2, 3.33 ), ( 3, 3.33 ),
( 3, 4.44 ), ( 3, 5.55 )",
+             new String[][]
+             {
+                 { "2.22" },
+             },
+             new String[][]
+             {
+                 { "1", "2.22" },
+                 { "2", "3.33" },
+                 { "3", "5.55" },
+             },
+             new String[][]
+             {
+                 { "5.55" },
+             },
+             new String[][]
+             {
+                 { "1", "2.22" },
+                 { "2", "3.33" },
+                 { "3", "5.55" },
+             }
+             );
+
+        vetParameterizedAggregate
+            (
+             conn,
+             "floatMode_11",
+             "float",
+             "org.apache.derbyTesting.functionTests.tests.lang.GenericMode$DoubleMode",
+             "( 1, 1.11 ), ( 1, 2.22 ), (1, 2.22 ), ( 2, 2.22 ), ( 2, 3.33 ), ( 3, 3.33 ),
( 3, 4.44 ), ( 3, 5.55 )",
+             new String[][]
+             {
+                 { "2.22" },
+             },
+             new String[][]
+             {
+                 { "1", "2.22" },
+                 { "2", "3.33" },
+                 { "3", "5.55" },
+             },
+             new String[][]
+             {
+                 { "5.55" },
+             },
+             new String[][]
+             {
+                 { "1", "2.22" },
+                 { "2", "3.33" },
+                 { "3", "5.55" },
+             }
+             );
+
+        vetParameterizedAggregate
+            (
+             conn,
+             "realMode_11",
+             "real",
+             "org.apache.derbyTesting.functionTests.tests.lang.GenericMode$RealMode",
+             "( 1, 1.11 ), ( 1, 2.22 ), (1, 2.22 ), ( 2, 2.22 ), ( 2, 3.33 ), ( 3, 3.33 ),
( 3, 4.44 ), ( 3, 5.55 )",
+             new String[][]
+             {
+                 { "2.22" },
+             },
+             new String[][]
+             {
+                 { "1", "2.22" },
+                 { "2", "3.33" },
+                 { "3", "5.55" },
+             },
+             new String[][]
+             {
+                 { "5.55" },
+             },
+             new String[][]
+             {
+                 { "1", "2.22" },
+                 { "2", "3.33" },
+                 { "3", "5.55" },
+             }
+             );
+
+        vetParameterizedAggregate
+            (
+             conn,
+             "charMode_11",
+             "char( 4 )",
+             "org.apache.derbyTesting.functionTests.tests.lang.GenericMode$StringMode",
+             "( 1, 'aaaa' ), ( 1, 'abaa' ), ( 1, 'aaaa' ), ( 2, 'abaa' ), ( 2, 'abaa' ),
( 2, 'abca' ), ( 3, 'abaa' ), ( 3, 'abaa' ), ( 3, 'abcd' )",
+             new String[][]
+             {
+                 { "abaa" },
+             },
+             new String[][]
+             {
+                 { "1", "aaaa" },
+                 { "2", "abaa" },
+                 { "3", "abaa" },
+             },
+             new String[][]
+             {
+                 { "abcd" },
+             },
+             new String[][]
+             {
+                 { "1", "abaa" },
+                 { "2", "abca" },
+                 { "3", "abcd" },
+             }
+             );
+
+        vetParameterizedAggregate
+            (
+             conn,
+             "varcharMode_11",
+             "varchar( 4 )",
+             "org.apache.derbyTesting.functionTests.tests.lang.GenericMode$StringMode",
+             "( 1, 'aaaa' ), ( 1, 'abaa' ), ( 1, 'aaaa' ), ( 2, 'abaa' ), ( 2, 'abaa' ),
( 2, 'abca' ), ( 3, 'abaa' ), ( 3, 'abaa' ), ( 3, 'abcd' )",
+             new String[][]
+             {
+                 { "abaa" },
+             },
+             new String[][]
+             {
+                 { "1", "aaaa" },
+                 { "2", "abaa" },
+                 { "3", "abaa" },
+             },
+             new String[][]
+             {
+                 { "abcd" },
+             },
+             new String[][]
+             {
+                 { "1", "abaa" },
+                 { "2", "abca" },
+                 { "3", "abcd" },
+             }
+             );
+
+        vetParameterizedAggregate
+            (
+             conn,
+             "longvarcharMode_11",
+             "long varchar",
+             "org.apache.derbyTesting.functionTests.tests.lang.GenericMode$StringMode",
+             "( 1, 'aaaa' ), ( 1, 'abaa' ), ( 1, 'aaaa' ), ( 2, 'abaa' ), ( 2, 'abaa' ),
( 2, 'abca' ), ( 3, 'abaa' ), ( 3, 'abaa' ), ( 3, 'abcd' )",
+             new String[][]
+             {
+                 { "abaa" },
+             },
+             new String[][]
+             {
+                 { "1", "aaaa" },
+                 { "2", "abaa" },
+                 { "3", "abaa" },
+             },
+             null,
+             null
+             );
+
+        goodStatement
+            (
+             conn,
+             "create function makeBlob_11( contents varchar( 32672 ) ) returns blob\n" +
+             "language java parameter style java no sql deterministic\n" +
+             "external name 'org.apache.derbyTesting.functionTests.tests.lang.UserDefinedAggregatesTest.makeBlob'\n"
+             );
+        vetParameterizedAggregate
+            (
+             conn,
+             "blobMode_11",
+             "blob",
+             "org.apache.derbyTesting.functionTests.tests.lang.LobMode$BlobMode",
+             "( 1, makeBlob_11( 'a' ) ),\n" +
+             "( 1, makeBlob_11( 'ab' ) ),\n" +
+             "( 1, makeBlob_11( 'ab' ) ),\n" +
+             "( 2, makeBlob_11( 'ab' ) ),\n" +
+             "( 2, makeBlob_11( 'abc' ) ),\n" +
+             "( 3, makeBlob_11( 'a' ) ),\n" +
+             "( 3, makeBlob_11( 'ab' ) ),\n" +
+             "( 3, makeBlob_11( 'abcd' ) )",
+             new String[][]
+             {
+                 { "6162" },
+             },
+             new String[][]
+             {
+                 { "1", "6162" },
+                 { "2", "616263" },
+                 { "3", "61626364" },
+             },
+             null,
+             null
+             );
+
+        goodStatement
+            (
+             conn,
+             "create function makeClob_11( contents varchar( 32672 ) ) returns clob\n" +
+             "language java parameter style java no sql deterministic\n" +
+             "external name 'org.apache.derbyTesting.functionTests.tests.lang.UserDefinedAggregatesTest.makeClob'\n"
+             );
+        vetParameterizedAggregate
+            (
+             conn,
+             "clobMode_11",
+             "clob",
+             "org.apache.derbyTesting.functionTests.tests.lang.LobMode$ClobMode",
+             "( 1, makeClob_11( 'a' ) ),\n" +
+             "( 1, makeClob_11( 'ab' ) ),\n" +
+             "( 1, makeClob_11( 'ab' ) ),\n" +
+             "( 2, makeClob_11( 'ab' ) ),\n" +
+             "( 2, makeClob_11( 'abc' ) ),\n" +
+             "( 3, makeClob_11( 'a' ) ),\n" +
+             "( 3, makeClob_11( 'ab' ) ),\n" +
+             "( 3, makeClob_11( 'abcd' ) )",
+             new String[][]
+             {
+                 { "ab" },
+             },
+             new String[][]
+             {
+                 { "1", "ab" },
+                 { "2", "abc" },
+                 { "3", "abcd" },
+             },
+             null,
+             null
+             );
+
+        goodStatement
+            (
+             conn,
+             "create function makeBinary_11( contents varchar( 32672 ) ) returns char( 4
) for bit data\n" +
+             "language java parameter style java no sql deterministic\n" +
+             "external name 'org.apache.derbyTesting.functionTests.tests.lang.UserDefinedAggregatesTest.makeBinary'\n"
+             );
+        vetParameterizedAggregate
+            (
+             conn,
+             "binaryMode_11",
+             "char( 4 ) for bit data",
+             "org.apache.derbyTesting.functionTests.tests.lang.LobMode$BinaryMode",
+             "( 1, makeBinary_11( 'abaa' ) ),\n" +
+             "( 1, makeBinary_11( 'abaa' ) ),\n" +
+             "( 1, makeBinary_11( 'abca' ) ),\n" +
+             "( 2, makeBinary_11( 'abaa' ) ),\n" +
+             "( 2, makeBinary_11( 'abca' ) ),\n" +
+             "( 2, makeBinary_11( 'abaa' ) ),\n" +
+             "( 3, makeBinary_11( 'aaaa' ) ),\n" +
+             "( 3, makeBinary_11( 'abcd' ) ),\n" +
+             "( 3, makeBinary_11( 'abcd' ) )\n",
+             new String[][]
+             {
+                 { "61626161" },
+             },
+             new String[][]
+             {
+                 { "1", "61626161" },
+                 { "2", "61626161" },
+                 { "3", "61626364" },
+             },
+             new String[][]
+             {
+                 { "61626364" },
+             },
+             new String[][]
+             {
+                 { "1", "61626361" },
+                 { "2", "61626361" },
+                 { "3", "61626364" },
+             }
+             );
+
+        goodStatement
+            (
+             conn,
+             "create function makeVarbinary_11( contents varchar( 32672 ) ) returns varchar(
4 ) for bit data\n" +
+             "language java parameter style java no sql deterministic\n" +
+             "external name 'org.apache.derbyTesting.functionTests.tests.lang.UserDefinedAggregatesTest.makeBinary'\n"
+             );
+        vetParameterizedAggregate
+            (
+             conn,
+             "varbinaryMode_11",
+             "varchar( 4 ) for bit data",
+             "org.apache.derbyTesting.functionTests.tests.lang.LobMode$BinaryMode",
+             "( 1, makeVarbinary_11( 'abaa' ) ),\n" +
+             "( 1, makeVarbinary_11( 'abaa' ) ),\n" +
+             "( 1, makeVarbinary_11( 'abca' ) ),\n" +
+             "( 2, makeVarbinary_11( 'abaa' ) ),\n" +
+             "( 2, makeVarbinary_11( 'abca' ) ),\n" +
+             "( 2, makeVarbinary_11( 'abaa' ) ),\n" +
+             "( 3, makeVarbinary_11( 'aaaa' ) ),\n" +
+             "( 3, makeVarbinary_11( 'abcd' ) ),\n" +
+             "( 3, makeVarbinary_11( 'abcd' ) )\n",
+             new String[][]
+             {
+                 { "61626161" },
+             },
+             new String[][]
+             {
+                 { "1", "61626161" },
+                 { "2", "61626161" },
+                 { "3", "61626364" },
+             },
+             new String[][]
+             {
+                 { "61626364" },
+             },
+             new String[][]
+             {
+                 { "1", "61626361" },
+                 { "2", "61626361" },
+                 { "3", "61626364" },
+             }
+             );
+
+        goodStatement
+            (
+             conn,
+             "create function makeLongvarbinary_11( contents varchar( 32672 ) ) returns long
varchar for bit data\n" +
+             "language java parameter style java no sql deterministic\n" +
+             "external name 'org.apache.derbyTesting.functionTests.tests.lang.UserDefinedAggregatesTest.makeBinary'\n"
+             );
+        vetParameterizedAggregate
+            (
+             conn,
+             "longvarbinaryMode_11",
+             "long varchar for bit data",
+             "org.apache.derbyTesting.functionTests.tests.lang.LobMode$BinaryMode",
+             "( 1, makeLongvarbinary_11( 'abaa' ) ),\n" +
+             "( 1, makeLongvarbinary_11( 'abaa' ) ),\n" +
+             "( 1, makeLongvarbinary_11( 'abca' ) ),\n" +
+             "( 2, makeLongvarbinary_11( 'abaa' ) ),\n" +
+             "( 2, makeLongvarbinary_11( 'abca' ) ),\n" +
+             "( 2, makeLongvarbinary_11( 'abaa' ) ),\n" +
+             "( 3, makeLongvarbinary_11( 'aaaa' ) ),\n" +
+             "( 3, makeLongvarbinary_11( 'abcd' ) ),\n" +
+             "( 3, makeLongvarbinary_11( 'abcd' ) )\n",
+             new String[][]
+             {
+                 { "61626161" },
+             },
+             new String[][]
+             {
+                 { "1", "61626161" },
+                 { "2", "61626161" },
+                 { "3", "61626364" },
+             },
+             null,
+             null
+             );
+
+        vetParameterizedAggregate
+            (
+             conn,
+             "dateMode_11",
+             "date",
+             "org.apache.derbyTesting.functionTests.tests.lang.LobMode$DateMode",
+             "( 1, date( '1994-02-23' ) ),\n" +
+             "( 1, date( '1994-02-23' ) ),\n" +
+             "( 1, date( '1995-02-23' ) ),\n" +
+             "( 2, date( '1995-02-23' ) ),\n" +
+             "( 2, date( '1995-02-23' ) ),\n" +
+             "( 2, date( '1996-02-23' ) ),\n" +
+             "( 3, date( '1993-02-23' ) ),\n" +
+             "( 3, date( '1993-02-23' ) ),\n" +
+             "( 3, date( '1995-02-23' ) )\n",
+             new String[][]
+             {
+                 { "1995-02-23" },
+             },
+             new String[][]
+             {
+                 { "1", "1994-02-23" },
+                 { "2", "1995-02-23" },
+                 { "3", "1993-02-23" },
+             },
+             new String[][]
+             {
+                 { "1996-02-23" },
+             },
+             new String[][]
+             {
+                 { "1", "1995-02-23" },
+                 { "2", "1996-02-23" },
+                 { "3", "1995-02-23" },
+             }
+             );
+
+        vetParameterizedAggregate
+            (
+             conn,
+             "timestampMode_11",
+             "timestamp",
+             "org.apache.derbyTesting.functionTests.tests.lang.LobMode$TimestampMode",
+             "( 1, timestamp( '1994-02-23 03:20:20' ) ),\n" +
+             "( 1, timestamp( '1994-02-23 03:20:20' ) ),\n" +
+             "( 1, timestamp( '1995-02-23 03:20:20' ) ),\n" +
+             "( 2, timestamp( '1995-02-23 03:20:20' ) ),\n" +
+             "( 2, timestamp( '1995-02-23 03:20:20' ) ),\n" +
+             "( 2, timestamp( '1996-02-23 03:20:20' ) ),\n" +
+             "( 3, timestamp( '1993-02-23 03:20:20' ) ),\n" +
+             "( 3, timestamp( '1993-02-23 03:20:20' ) ),\n" +
+             "( 3, timestamp( '1995-02-23 03:20:20' ) )\n",
+             new String[][]
+             {
+                 { "1995-02-23 03:20:20.0" },
+             },
+             new String[][]
+             {
+                 { "1", "1994-02-23 03:20:20.0" },
+                 { "2", "1995-02-23 03:20:20.0" },
+                 { "3", "1993-02-23 03:20:20.0" },
+             },
+             new String[][]
+             {
+                 { "1996-02-23 03:20:20.0" },
+             },
+             new String[][]
+             {
+                 { "1", "1995-02-23 03:20:20.0" },
+                 { "2", "1996-02-23 03:20:20.0" },
+                 { "3", "1995-02-23 03:20:20.0" },
+             }
+             );
+
+        vetParameterizedAggregate
+            (
+             conn,
+             "timeMode_11",
+             "time",
+             "org.apache.derbyTesting.functionTests.tests.lang.LobMode$TimeMode",
+             "( 1, time( '03:20:20' ) ),\n" +
+             "( 1, time( '03:20:20' ) ),\n" +
+             "( 1, time( '04:20:20' ) ),\n" +
+             "( 2, time( '04:20:20' ) ),\n" +
+             "( 2, time( '04:20:20' ) ),\n" +
+             "( 2, time( '05:20:20' ) ),\n" +
+             "( 3, time( '04:20:20' ) ),\n" +
+             "( 3, time( '04:20:20' ) ),\n" +
+             "( 3, time( '06:20:20' ) )\n",
+             new String[][]
+             {
+                 { "04:20:20" },
+             },
+             new String[][]
+             {
+                 { "1", "03:20:20" },
+                 { "2", "04:20:20" },
+                 { "3", "04:20:20" },
+             },
+             new String[][]
+             {
+                 { "06:20:20" },
+             },
+             new String[][]
+             {
+                 { "1", "04:20:20" },
+                 { "2", "05:20:20" },
+                 { "3", "06:20:20" },
+             }
+             );
+
+        // XML is not a valid data type for UDA inputs and return values
+        expectCompilationError
+            (
+             XML_TYPE,
+             "create derby aggregate xmlMode_11 for xml\n" +
+             "external name 'org.apache.derbyTesting.functionTests.tests.lang.LobMode'\n"
+             );
+    }
+
+   /** Blob-creating function */
+    public  static  Blob    makeBlob( String contents ) throws Exception
+    {
+        return new HarmonySerialBlob( makeBinary( contents ) );
+    }
+
+    private int vetDatatypeCount( Connection conn, int expectedTypeCount ) throws Exception
+    {
+        //
+        // If this fails, it means that we need to add another datatype to the
+        // calling test.
+        //
+        
+        ResultSet rs = conn.getMetaData().getTypeInfo();
+        int actualTypeCount = 0;
+        while ( rs.next() ) { actualTypeCount++; }
+        rs.close();
+
+        assertEquals( expectedTypeCount, actualTypeCount );
+
+        return actualTypeCount;
+    }
+    
+   /** Blob-creating function */
+    public  static  byte[]    makeBinary( String contents ) throws Exception
+    {
+        return contents.getBytes( "UTF-8" );
+    }
+
+   /** Clob-creating function */
+    public  static  Clob    makeClob( String contents ) throws Exception
+    {
+        return new HarmonySerialClob( contents );
     }
 
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml?rev=1396589&r1=1396588&r2=1396589&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml
Wed Oct 10 13:31:41 2012
@@ -88,6 +88,7 @@
       <exclude name="${this.dir}/FullName.java"/>
       <exclude name="${this.dir}/GenericMode.java"/>
       <exclude name="${this.dir}/ModeAggregate.java"/>
+      <exclude name="${this.dir}/LobMode.java"/>
       <exclude name="${this.dir}/declareGlobalTempTableJavaJDBC30.java"/>
       <exclude name="${this.dir}/UpdatableResultSetTest.java"/>
       <exclude name="${this.dir}/holdCursorJavaReflection.java"/>
@@ -168,6 +169,7 @@
       <include name="${this.dir}/FullName.java"/>
       <include name="${this.dir}/GenericMode.java"/>
       <include name="${this.dir}/ModeAggregate.java"/>
+      <include name="${this.dir}/LobMode.java"/>
     </javac>
   </target> 
 



Mime
View raw message