db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r955983 - in /db/derby/code/trunk/java: engine/org/apache/derby/catalog/types/ engine/org/apache/derby/iapi/types/ engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Fri, 18 Jun 2010 12:44:36 GMT
Author: rhillegas
Date: Fri Jun 18 12:44:36 2010
New Revision: 955983

URL: http://svn.apache.org/viewvc?rev=955983&view=rev
Log:
DERBY-4703: Allow BOOLEAN-valued columns in table functions.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/TypeId.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java?rev=955983&r1=955982&r2=955983&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
Fri Jun 18 12:44:36 2010
@@ -297,6 +297,10 @@ public class TypeDescriptorImpl implemen
 				else
 					return 2 * maximumWidth;
 
+			// ODBC does not define a BOOLEAN data type.
+            // However, 1 seems to me like a reasonable byte length for a BOOLEAN.
+            case Types.BOOLEAN: return 1;
+                
 			case Types.ARRAY:
 			case Types.DISTINCT:
 			case Types.NULL:

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/TypeId.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/TypeId.java?rev=955983&r1=955982&r2=955983&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/TypeId.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/TypeId.java Fri Jun 18 12:44:36
2010
@@ -748,6 +748,7 @@ public final class TypeId
                                 break;
 
                         case StoredFormatIds.BOOLEAN_TYPE_ID:
+                                maxPrecision = TypeId.BOOLEAN_MAXWIDTH;
                                 typePrecedence = BOOLEAN_PRECEDENCE;
                                 javaTypeName = "java.lang.Boolean";
                                 maxMaxWidth = TypeId.BOOLEAN_MAXWIDTH;
@@ -940,6 +941,7 @@ public final class TypeId
                               break;
 
                 }
+
         }
         /**
          * JDBC has its own idea of type identifiers which is different from

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=955983&r1=955982&r2=955983&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Fri Jun
18 12:44:36 2010
@@ -10959,7 +10959,7 @@ throws StandardException :
 }
 {
 	name = identifier( Limits.MAX_IDENTIFIER_LENGTH, true )
-	typeDescriptor = dataTypeDDL( false )
+	typeDescriptor = dataTypeDDL( true )
 	{
 		names.add( name );
 		types.add( typeDescriptor.getCatalogType() );

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java?rev=955983&r1=955982&r2=955983&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java
Fri Jun 18 12:44:36 2010
@@ -85,6 +85,12 @@ public class TableFunctionTest extends B
         { "the", (String) null },
     };
     
+    private static  final   String[][]  BOOLEAN_ROWS =
+    {
+        { "tRuE", "true" },
+        { "fAlSe", "false" },
+    };
+    
     private static  final   String[][]  ALL_TYPES_ROWS =
     {
         {
@@ -109,6 +115,7 @@ public class TableFunctionTest extends B
             null,   // TIMESTAMP
             null,   // VARCHAR
             null,   // VARCHAR FOR BIT DATA
+            null,   // BOOLEAN
         },
     };
 
@@ -133,7 +140,8 @@ public class TableFunctionTest extends B
         "getTime " +            // TIME
         "getTimestamp " +       // TIMESTAMP
         "getString " +          // VARCHAR
-        "getBytes ";            // VARCHAR FOR BIT DATA
+        "getBytes " +           // VARCHAR FOR BIT DATA
+        "getBoolean ";            // BOOLEAN
 
     private static  final   String  EXPECTED_GET_XXX_CALLS_JSR169 =
         "getLong " +            // BIGINT
@@ -156,7 +164,8 @@ public class TableFunctionTest extends B
         "getTime " +            // TIME
         "getTimestamp " +       // TIMESTAMP
         "getString " +          // VARCHAR
-        "getBytes ";            // VARCHAR FOR BIT DATA
+        "getBytes " +           // VARCHAR FOR BIT DATA
+        "getBoolean ";            // BOOLEAN
 
     private static  final   String[]  STRING_TYPES =
     {
@@ -185,7 +194,7 @@ public class TableFunctionTest extends B
     };
 
     private static  final   String  SFT_RETURN_TYPE = "TABLE ( \"INTCOL\" INTEGER, \"VARCHARCOL\"
VARCHAR(10) )";
-    private static  final   String  RADT_RETURN_TYPE = "TABLE ( \"COLUMN0\" BIGINT, \"COLUMN1\"
BLOB(2147483647), \"COLUMN2\" CHAR(10), \"COLUMN3\" CHAR (10) FOR BIT DATA, \"COLUMN4\" CLOB(2147483647),
\"COLUMN5\" DATE, \"COLUMN6\" DECIMAL(5,0), \"COLUMN7\" DOUBLE, \"COLUMN8\" DOUBLE, \"COLUMN9\"
REAL, \"COLUMN10\" DOUBLE, \"COLUMN11\" INTEGER, \"COLUMN12\" LONG VARCHAR, \"COLUMN13\" LONG
VARCHAR FOR BIT DATA, \"COLUMN14\" NUMERIC(5,0), \"COLUMN15\" REAL, \"COLUMN16\" SMALLINT,
\"COLUMN17\" TIME, \"COLUMN18\" TIMESTAMP, \"COLUMN19\" VARCHAR(10), \"COLUMN20\" VARCHAR
(10) FOR BIT DATA )";
+    private static  final   String  RADT_RETURN_TYPE = "TABLE ( \"COLUMN0\" BIGINT, \"COLUMN1\"
BLOB(2147483647), \"COLUMN2\" CHAR(10), \"COLUMN3\" CHAR (10) FOR BIT DATA, \"COLUMN4\" CLOB(2147483647),
\"COLUMN5\" DATE, \"COLUMN6\" DECIMAL(5,0), \"COLUMN7\" DOUBLE, \"COLUMN8\" DOUBLE, \"COLUMN9\"
REAL, \"COLUMN10\" DOUBLE, \"COLUMN11\" INTEGER, \"COLUMN12\" LONG VARCHAR, \"COLUMN13\" LONG
VARCHAR FOR BIT DATA, \"COLUMN14\" NUMERIC(5,0), \"COLUMN15\" REAL, \"COLUMN16\" SMALLINT,
\"COLUMN17\" TIME, \"COLUMN18\" TIMESTAMP, \"COLUMN19\" VARCHAR(10), \"COLUMN20\" VARCHAR
(10) FOR BIT DATA, \"COLUMN21\" BOOLEAN )";
     
     private static  final   Integer FUNCTION_COLUMN_IN = new Integer( JDBC40Translation.FUNCTION_PARAMETER_IN
);
     private static  final   Integer FUNCTION_RETURN_VALUE = new Integer( JDBC40Translation.FUNCTION_RETURN
);
@@ -213,6 +222,7 @@ public class TableFunctionTest extends B
     private static  final   Integer JDBC_TYPE_LONGVARBINARY = new Integer( Types.LONGVARBINARY
);
     private static  final   Integer JDBC_TYPE_LONGVARCHAR = new Integer( Types.LONGVARCHAR
);
     private static  final   Integer JDBC_TYPE_VARBINARY = new Integer( Types.VARBINARY );
+    private static  final   Integer JDBC_TYPE_BOOLEAN = new Integer( Types.BOOLEAN );
 
     private static  final   Integer PRECISION_NONE = new Integer( 0 );
     private static  final   Integer PRECISION_INTEGER = new Integer( 10 );
@@ -794,6 +804,27 @@ public class TableFunctionTest extends B
             ARG_COUNT_2,
             new Integer( 22 )
         },
+        {
+            NO_CATALOG,
+            "APP",
+            "RETURNSALLLEGALDATATYPES",
+            "COLUMN21",
+            FUNCTION_RESULT_COLUMN,
+            JDBC_TYPE_BOOLEAN,
+            "BOOLEAN",
+            new Integer( 1 ),     // PRECISION
+            new Integer( 1 ),         // LENGTH
+            SCALE_UNDEFINED,       // SCALE
+            RADIX_UNDEFINED,    // RADIX
+            ALLOWS_NULLS,
+            EMPTY_REMARKS,
+            UNDEFINED_CHAR_OCTET_LENGTH,    // CHAR_OCTET_LENGTH
+            new Integer( 22 ),           // ORDINAL_POSITION
+            IS_NULLABLE,
+            GENERIC_NAME,
+            ARG_COUNT_2,
+            new Integer( 23 )
+        },
     };
 
     private static  final   String  ESTIMATED_ROW_COUNT = "optimizer estimated row count:";
@@ -1125,7 +1156,31 @@ public class TableFunctionTest extends B
          "    from TABLE( returnsACoupleRowsAsCHAR() ) s\n",
          CHAR_ROWS,
          new int[] { Types.CHAR, Types.CHAR }
-         );        
+         );
+
+        // boolean valued columns
+        goodStatement
+            (
+             "create function returnsBooleans()\n" +
+             "returns TABLE\n" +
+             "  (\n" +
+             "     column0 varchar( 10 ),\n" +
+             "     column1 boolean\n" +
+             "  )\n" +
+             "language java\n" +
+             "parameter style DERBY_JDBC_RESULT_SET\n" +
+             "no sql\n" +
+             "external name '" + getClass().getName() + ".returnsBooleans'\n"
+             );
+        assertResults
+        (
+         "select s.*\n" +
+         "    from TABLE( returnsBooleans() ) s\n",
+         BOOLEAN_ROWS,
+         new int[] { Types.VARCHAR, Types.BOOLEAN }
+         );
+
+
     }
     
     /**
@@ -1169,7 +1224,8 @@ public class TableFunctionTest extends B
              "column17 TIME,\n" +
              "column18 TIMESTAMP,\n" +
              "column19 VARCHAR( 10 ),\n" +
-             "column20 VARCHAR( 10 ) FOR BIT DATA\n" +
+             "column20 VARCHAR( 10 ) FOR BIT DATA,\n" +
+             "column21 BOOLEAN\n" +
              "  )\n" +
              "language java\n" +
              "parameter style DERBY_JDBC_RESULT_SET\n" +
@@ -1205,6 +1261,7 @@ public class TableFunctionTest extends B
                     Types.TIMESTAMP,
                     Types.VARCHAR,
                     Types.VARBINARY,
+                    Types.BOOLEAN,
                 }
              );
         
@@ -1262,6 +1319,7 @@ public class TableFunctionTest extends B
                     Types.TIMESTAMP,
                     Types.VARCHAR,
                     Types.VARBINARY,
+                    Types.BOOLEAN,
                 }
              );
 
@@ -1747,6 +1805,14 @@ public class TableFunctionTest extends B
     }
     
     /**
+     * A VTI which returns some boolean values
+     */
+    public  static  ResultSet returnsBooleans()
+    {
+        return makeVTI( BOOLEAN_ROWS );
+    }
+
+    /**
      * A VTI which returns a couple rows.
      */
     public  static  ResultSet returnsACoupleRows()



Mime
View raw message