db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r694166 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl: jdbc/EmbedDatabaseMetaData.java sql/catalog/DataDictionaryImpl.java sql/compile/sqlgrammar.jj
Date Thu, 11 Sep 2008 08:00:13 GMT
Author: kristwaa
Date: Thu Sep 11 01:00:13 2008
New Revision: 694166

URL: http://svn.apache.org/viewvc?rev=694166&view=rev
Log:
DERBY-3063: Extend the system function mechanism to support functions with multiple arguments.
Added support for system functions with several arguments.
Added numberic function ATAN2 (used the one in StrictMath).
Patch file: derby-3063-2a.diff

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java?rev=694166&r1=694165&r2=694166&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
Thu Sep 11 01:00:13 2008
@@ -455,7 +455,7 @@
      * @return the list
      */
 	public String getNumericFunctions() {
-		return "ABS,ACOS,ASIN,ATAN,CEILING,COS,COT,DEGREES,EXP,FLOOR,LOG,LOG10,MOD,PI,RADIANS,RAND,SIGN,SIN,SQRT,TAN";
+		return "ABS,ACOS,ASIN,ATAN,ATAN2,CEILING,COS,COT,DEGREES,EXP,FLOOR,LOG,LOG10,MOD,PI,RADIANS,RAND,SIGN,SIN,SQRT,TAN";
 	}
 
     /**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=694166&r1=694165&r2=694166&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
Thu Sep 11 01:00:13 2008
@@ -205,24 +205,25 @@
 	* returns a CHAR(10).
 	* 
 	* 
-	* This simple table assumes zero or a single parameter
+    * This simple table can handle an arbitrary number of arguments
 	* and RETURNS NULL ON NULL INPUT. The scheme could be expanded
 	* to handle other function options such as other parameters if needed.
-	*[0] = FUNCTION name
-	*[1] = RETURNS type
-	*[2] = Java class
-	*[3] = method name and signature
-	*[4] = parameter type (single parameter) or null for no parameters.
+    *[0]    = FUNCTION name
+    *[1]    = RETURNS type
+    *[2]    = Java class
+    *[3]    = method name and signature
+    *[4..N] = arguments (optional, if not present zero arguments is assumed)
 	*
 	*/
 	private static final String[][] SYSFUN_FUNCTIONS = {
 			{"ACOS", "DOUBLE", "java.lang.StrictMath", "acos(double)", "DOUBLE"},
 			{"ASIN", "DOUBLE", "java.lang.StrictMath", "asin(double)", "DOUBLE"},
 			{"ATAN", "DOUBLE", "java.lang.StrictMath", "atan(double)", "DOUBLE"},
+            {"ATAN2", "DOUBLE", "java.lang.StrictMath", "atan2(double,double)", "DOUBLE",
"DOUBLE"},
 			{"COS", "DOUBLE", "java.lang.StrictMath", "cos(double)", "DOUBLE"},
 			{"SIN", "DOUBLE", "java.lang.StrictMath", "sin(double)", "DOUBLE"},
 			{"TAN", "DOUBLE", "java.lang.StrictMath", "tan(double)", "DOUBLE"},
-			{"PI", "DOUBLE", "org.apache.derby.catalog.SystemProcedures", "PI()", null},
+            {"PI", "DOUBLE", "org.apache.derby.catalog.SystemProcedures", "PI()"},
 			{"DEGREES", "DOUBLE", "java.lang.StrictMath", "toDegrees(double)", "DOUBLE"},
 			{"RADIANS", "DOUBLE", "java.lang.StrictMath", "toRadians(double)", "DOUBLE"},
 			{"LN", "DOUBLE", "java.lang.StrictMath", "log(double)", "DOUBLE"},
@@ -233,7 +234,7 @@
 			{"CEILING", "DOUBLE", "java.lang.StrictMath", "ceil(double)", "DOUBLE"}, // Same as CEIL
 			{"FLOOR", "DOUBLE", "java.lang.StrictMath", "floor(double)", "DOUBLE"},
 			{"SIGN", "INTEGER", "org.apache.derby.catalog.SystemProcedures", "SIGN(double)", "DOUBLE"},
-			{"RANDOM", "DOUBLE", "java.lang.StrictMath", "random()", null},
+            {"RANDOM", "DOUBLE", "java.lang.StrictMath", "random()"},
 			{"RAND", "DOUBLE", "org.apache.derby.catalog.SystemProcedures", "RAND(int)", "INTEGER"},
// Escape function spec.
 			{"COT", "DOUBLE", "org.apache.derby.catalog.SystemProcedures", "COT(double)", "DOUBLE"},
 			{"COSH", "DOUBLE", "org.apache.derby.catalog.SystemProcedures", "COSH(double)", "DOUBLE"},
@@ -241,22 +242,19 @@
 			{"TANH", "DOUBLE", "org.apache.derby.catalog.SystemProcedures", "TANH(double)", "DOUBLE"}
 	};
 	
+
+    /**
+     * The index of the first parameter in entries in the SYSFUN_FUNCTIONS
+     * table. Used to determine the parameter count (zero to many).
+     */
+    private static final int SYSFUN_FIRST_PARAMETER_INDEX =  4;
+
 	/**
 	 * Runtime definition of the functions from SYSFUN_FUNCTIONS.
 	 * Populated dynamically as functions are called.
 	 */
 	private static final AliasDescriptor[] SYSFUN_AD =
 		new AliasDescriptor[SYSFUN_FUNCTIONS.length];
-	
-	/**
-	 * Dummy parameter name for functions from SYSFUN_FUNCTIONS.
-	 */
-	private static final String[] SYSFUN_PNAME = {"P1"};
-	
-	/**
-	 * Parameter mode (IN as required) for functions from SYSFUN_FUNCTIONS.
-	 */	
-	private static final int[] SYSFUN_PMODE = {JDBC30Translation.PARAMETER_MODE_IN};
 
 	// the structure that holds all the core table info
 	private TabInfoImpl[] coreInfo;
@@ -6790,30 +6788,19 @@
 					TypeDescriptor rt =
 						DataTypeDescriptor.getBuiltInDataTypeDescriptor(details[1]).getCatalogType();
 
-					// details[4] - zero or single argument type
-					String paramType = details[4];
-					TypeDescriptor[] pt;
-					String[] paramNames;
-					int[] paramModes;
-					int paramCount;
-					if (paramType != null)
-					{			
-						paramNames = DataDictionaryImpl.SYSFUN_PNAME;
-						paramCount = 1;
-						paramModes = DataDictionaryImpl.SYSFUN_PMODE;
-						pt = new TypeDescriptor[1];
-						pt[0] =
-							DataTypeDescriptor.getBuiltInDataTypeDescriptor(paramType).getCatalogType();
-					}
-					else
-					{
-						// no parameters
-						paramNames = null;
-						pt = null;
-						paramCount = 0;
-						paramModes = null;
-					}
-					
+                    // Determine the number of arguments (could be zero).
+                    int paramCount = details.length - SYSFUN_FIRST_PARAMETER_INDEX;
+					TypeDescriptor[] pt = new TypeDescriptor[paramCount];
+					String[] paramNames = new String[paramCount];
+					int[] paramModes = new int[paramCount];
+                    for (int i = 0; i < paramCount; i++) {
+                        pt[i] = DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                                    details[SYSFUN_FIRST_PARAMETER_INDEX +i]).getCatalogType();
+                        paramNames[i] = "P" + (i +1); // Dummy names
+                        // All parameters must be IN.
+                        paramModes[i] = JDBC30Translation.PARAMETER_MODE_IN;
+                    }
+
 					// details[3] = java method
 					RoutineAliasInfo ai = new RoutineAliasInfo(details[3],
 							paramCount, paramNames,

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=694166&r1=694165&r2=694166&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 Thu Sep
11 01:00:13 2008
@@ -936,7 +936,7 @@
        a function in the SYSFUN schema.
     */
 	private static final String[] ESCAPED_SYSFUN_FUNCTIONS =
-        {"ACOS", "ASIN", "ATAN", "COS", "SIN", "TAN", "PI",
+        {"ACOS", "ASIN", "ATAN", "ATAN2", "COS", "SIN", "TAN", "PI",
          "DEGREES", "RADIANS", "EXP", "LOG", "LOG10", "CEILING", "FLOOR",
          "SIGN", "RAND", "COT" };
        



Mime
View raw message