db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r551183 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile: BinaryListOperatorNode.java SimpleStringOperatorNode.java UnaryArithmeticOperatorNode.java UnaryOperatorNode.java ValueNode.java ValueNodeList.java
Date Wed, 27 Jun 2007 14:50:47 GMT
Author: djd
Date: Wed Jun 27 07:50:44 2007
New Revision: 551183

URL: http://svn.apache.org/viewvc?view=rev&rev=551183
Log:
DERBY-2809 (partial) Cleanup the handling of nodes under UnaryOperatorNode to ensure
parameters (nodes requiring type to be set from the context) are handled consistently.
This includes moving logic to the node (UnaryArithmeticOperatorNode) that "owns" it rather
than having it in the
parent class (UnaryOperatorNode).

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryArithmeticOperatorNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java?view=diff&rev=551183&r1=551182&r2=551183
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java
Wed Jun 27 07:50:44 2007
@@ -146,8 +146,6 @@
 		/* Is there a ? parameter on the left? */
 		if (leftOperand.requiresTypeFromContext())
 		{
-			ValueNode rightOperand = (ValueNode) rightOperandList.elementAt(0);
-
 			/*
 			** It's an error if both operands are all ? parameters.
 			*/

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java?view=diff&rev=551183&r1=551182&r2=551183
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
Wed Jun 27 07:50:44 2007
@@ -163,14 +163,4 @@
 	public String getReceiverInterfaceName() {
 	    return ClassName.StringDataValue;
 	}
-
-	/**
-	 * @see ValueNode#requiresTypeFromContext
-	 */
-	public boolean requiresTypeFromContext()
-	{
-	    //should return false because lower(?)/upper(?) are bound to varchar and hence don't
-	    //require their type to be set from the context. 
-	    return false;
-	}
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryArithmeticOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryArithmeticOperatorNode.java?view=diff&rev=551183&r1=551182&r2=551183
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryArithmeticOperatorNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryArithmeticOperatorNode.java
Wed Jun 27 07:50:44 2007
@@ -52,23 +52,6 @@
 	private final static String[] UNARY_METHODS = {"plus","minus","sqrt", "absolute"};
 
 	private int operatorType;
-
-	//when the bindExpression method is called during the normal binding phase,
-	//unary minus and unary plus dynamic parameters are not ready for
-	//binding because the type of these dynamic parameters is not yet set.
-	//For eg, consider sql select * from t1 where c1 = -?
-	//bindExpression on -? gets called from BinaryComparisonOperatorNode's
-	//bindExpression but the parameter type has not been set yet for -?
-	//Later on, in BinaryComparisonOperatorNode's bindExpression, the type
-	//of the -? gets set to the type of c1 by the setType call. 
-	//Now, at this point, we are ready to finish binding phase for -? 
-	//(This class's setType method calls the bindExpression to finish binding)
-	//In order to accomplish binding later on, we need to save the following 
-	//3 objects during first call to bindExpression and then later this 
-	//gets used in setType method when it calls the bindExpression method.
-	FromList localCopyFromList;
-	SubqueryList localCopySubqueryList;
-	Vector localAggregateVector;
   
 	/**
 	 * Initializer for a UnaryArithmeticOperatorNode
@@ -101,13 +84,26 @@
 		init(operand, UNARY_OPERATORS[this.operatorType], 
 				UNARY_METHODS[this.operatorType]);
 	}
+    
+    /**
+     * Unary + and - require their type to be set if
+     * they wrap another node (e.g. a parameter) that
+     * requires type from its context.
+     * @see ValueNode#requiresTypeFromContext
+     */
+    public boolean requiresTypeFromContext()
+    {
+        if (operatorType == UNARY_PLUS || operatorType == UNARY_MINUS)
+            return operand.requiresTypeFromContext(); 
+        return false;
+    }
 
 	/**
-	 * By default unary operators don't accept ? parameters as operands.
-	 * This can be over-ridden for particular unary operators.
-	 *
-	 *	We throw an exception if the parameter doesn't have a datatype
-	 *	assigned to it yet.
+     * For SQRT and ABS the parameter becomes a DOUBLE.
+     * For unary + and - no change is made to the
+     * underlying node. Once this node's type is set
+     * using setType, then the underlying node will have
+     * its type set.
 	 *
 	 * @exception StandardException		Thrown if ?  parameter doesn't
 	 *									have a type bound to it yet.
@@ -120,15 +116,19 @@
 		{
 			operand.setType(
 				new DataTypeDescriptor(TypeId.getBuiltInTypeId(Types.DOUBLE), true));
+            return;
 		}
+        
 		//Derby-582 add support for dynamic parameter for unary plus and minus
-		else if (operatorType == UNARY_MINUS || operatorType == UNARY_PLUS) 
+		if (operatorType == UNARY_MINUS || operatorType == UNARY_PLUS) 
 			return;
-		else if (operand.getTypeServices() == null)
-		{
-			throw StandardException.newException(SQLState.LANG_UNARY_OPERAND_PARM, operator);
-		}
+        
+        // Not expected to get here since only the above types are supported
+        // but the super-class method will throw an exception
+        super.bindParameter();
+        
 	}
+    
 	/**
 	 * Bind this operator
 	 *
@@ -146,9 +146,6 @@
 		Vector	aggregateVector)
 			throws StandardException
 	{
-		localCopyFromList = fromList;
-		localCopySubqueryList = subqueryList;
-		localAggregateVector = aggregateVector;
 		//Return with no binding, if the type of unary minus/plus parameter is not set yet.
 		if (operand.requiresTypeFromContext() && ((operatorType == UNARY_PLUS || operatorType
== UNARY_MINUS))
 				&& operand.getTypeServices() == null)
@@ -163,15 +160,7 @@
 		}
 		else if (operatorType == UNARY_PLUS || operatorType == UNARY_MINUS)
 		{
-			TypeId operandType = operand.getTypeId();
-
-			if ( ! operandType.isNumericTypeId())
-			{
-			
-				throw StandardException.newException(SQLState.LANG_UNARY_ARITHMETIC_BAD_TYPE, 
-					(operatorType == UNARY_PLUS) ? "+" : "-", 
-					operandType.getSQLTypeName());
-			}
+            checkOperandIsNumeric(operand.getTypeId());
 		}
 		/*
 		** The result type of a +, -, SQRT, ABS is the same as its operand.
@@ -179,6 +168,22 @@
 		super.setType(operand.getTypeServices());
 		return this;
 	}
+    
+    /**
+     * Only called for Unary +/-.
+     *
+     */
+	private void checkOperandIsNumeric(TypeId operandType) throws StandardException
+	{
+	    if (!operandType.isNumericTypeId())
+	    {
+	        throw StandardException.newException(
+                    SQLState.LANG_UNARY_ARITHMETIC_BAD_TYPE, 
+	                (operatorType == UNARY_PLUS) ? "+" : "-", 
+	                        operandType.getSQLTypeName());
+	    }
+	    
+	}
 
 	/**
 	 * Do code generation for this unary plus operator
@@ -245,18 +250,17 @@
 		}
 	}
 
-	/** @see ValueNode#setType */
-	/* We are overwriting this method here because for -?/+?, we now know
+	/** We are overwriting this method here because for -?/+?, we now know
 	the type of these dynamic parameters and hence we can do the parameter
 	binding. The setType method will call the binding code after setting
 	the type of the parameter*/
 	public void setType(DataTypeDescriptor descriptor) throws StandardException
 	{
-		operand.setType(descriptor);
+        if (operand.requiresTypeFromContext() && operand.getTypeServices() == null)
+        {
+            checkOperandIsNumeric(descriptor.getTypeId());
+		    operand.setType(descriptor);
+        }
 		super.setType(descriptor);
-		//Derby-582 add support for dynamic parameters for unary plus and minus
-		//Now that we know the type of this parameter node, we can do the
-		//binding.
-		bindExpression(localCopyFromList, localCopySubqueryList, localAggregateVector);
 	}
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java?view=diff&rev=551183&r1=551182&r2=551183
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java
Wed Jun 27 07:50:44 2007
@@ -76,11 +76,6 @@
 	 */
 	ValueNode	operand;
 
-	public final static int UNARY_PLUS	= 1;
-	public final static int UNARY_MINUS	= 2;
-	public final static int NOT		= 3;
-	public final static int IS_NULL		= 4;
-
 	// At the time of adding XML support, it was decided that
 	// we should avoid creating new OperatorNodes where possible.
 	// So for the XML-related unary operators we just add the
@@ -334,16 +329,18 @@
 					Vector	aggregateVector)
 				throws StandardException
 	{
-
-		//Return with no binding, if the type of unary minus/plus parameter is not set yet.
-		if (operand.requiresTypeFromContext() && ((operator.equals("-") || operator.equals("+")))
&& operand.getTypeServices() == null)
-			return;
-
 		operand = operand.bindExpression(fromList, subqueryList,
 								aggregateVector);
 
-		if (operand.requiresTypeFromContext())
+		if (operand.requiresTypeFromContext()) {
 			bindParameter();
+            // If not bound yet then just return.
+            // The node type will be set by either
+            // this class' bindExpression() or a by
+            // a node that contains this expression.
+            if (operand.getTypeServices() == null)
+                return;
+        }
 
 		/* If the operand is not a built-in type, then generate a bound conversion
 		 * tree to a built-in type.
@@ -362,7 +359,7 @@
      *
      * @exception StandardException Thrown on error
      */
-    public void bindXMLParse() throws StandardException
+    private void bindXMLParse() throws StandardException
     {
         // Check the type of the operand - this function is allowed only on
         // string value (char) types.
@@ -402,7 +399,7 @@
      *
      * @exception StandardException Thrown on error
      */
-    public void bindXMLSerialize() throws StandardException
+    private void bindXMLSerialize() throws StandardException
     {
         TypeId operandType;
 
@@ -554,18 +551,6 @@
 					true :
 					operand.constantExpression(whereClause);
 	}
-
-	/**
-	 * @see ValueNode#requiresTypeFromContext
-	 */
-	public boolean requiresTypeFromContext()
-	{
-		if (operand == null)
-			return false;
-		else
-			return (operand.requiresTypeFromContext()); 
-	}
-
 
 	/**
 	 * Returns true if this UnaryOperatorNode is for -?/+?.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java?view=diff&rev=551183&r1=551182&r2=551183
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java Wed Jun
27 07:50:44 2007
@@ -1324,7 +1324,9 @@
 
 	/**
 	 * Returns TRUE if the type of this node will be determined from the
-	 * context in which it is getting used.
+	 * context in which it is getting used. If true is returned then
+     * after bindExpression() is called on the node, its type
+     * must be set (from the relevant context) using setType().
 	 *
 	 * @return Whether this node's type will be determined from the context
 	 */

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java?view=diff&rev=551183&r1=551182&r2=551183
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java Wed
Jun 27 07:50:44 2007
@@ -283,24 +283,20 @@
 	 */
 	public DataTypeDescriptor getTypeServices() throws StandardException
 	{
-		DataTypeDescriptor	firstDTS = null;
 		int size = size();
 
 		for (int index = 0; index < size; index++)
 		{
-			ValueNode			valueNode;
-
-			valueNode = (ValueNode) elementAt(index);
+			ValueNode valueNode = (ValueNode) elementAt(index);
 			DataTypeDescriptor valueNodeDTS = valueNode.getTypeServices();
 
-			if ((firstDTS == null) && (valueNodeDTS != null))
+			if (valueNodeDTS != null)
 			{
-				firstDTS = valueNodeDTS;
-				break;
+				return valueNodeDTS;
 			}
 		}
 
-		return firstDTS;
+		return null;
 	}
 
 	/**
@@ -574,11 +570,10 @@
 						throws StandardException
 	{
 		int size = size();
-		ValueNode	valueNode;
 
 		for (int index = 0; index < size; index++)
 		{
-			valueNode = (ValueNode) elementAt(index);
+			ValueNode valueNode = (ValueNode) elementAt(index);
 			if (valueNode.requiresTypeFromContext())
 			{
 				valueNode.setType(descriptor);



Mime
View raw message