db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r640520 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile: InsertNode.java NormalizeResultSetNode.java ResultSetNode.java UnionNode.java UpdateNode.java
Date Mon, 24 Mar 2008 18:59:43 GMT
Author: kmarsden
Date: Mon Mar 24 11:59:37 2008
New Revision: 640520

URL: http://svn.apache.org/viewvc?rev=640520&view=rev
Log:
DERBY-3494 Move the setup of NormalizeResultSetNode into the NormalizeResultSetNode (partial)

Remove genNormalizeResultSetNode method and incorporate into NormalizeResultSetNode


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NormalizeResultSetNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnionNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java?rev=640520&r1=640519&r2=640520&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java Mon
Mar 24 11:59:37 2008
@@ -422,7 +422,12 @@
 		if (! resultColumnList.columnTypesAndLengthsMatch(
 												resultSet.getResultColumns()))
 		{
-			resultSet = resultSet.genNormalizeResultSetNode(false);
+            
+			resultSet = 
+			(NormalizeResultSetNode) getNodeFactory().getNode(
+			C_NodeTypes.NORMALIZE_RESULT_SET_NODE,
+			resultSet, null, Boolean.FALSE,
+			getContextManager());
 			resultColumnList.copyTypesAndLengthsToSource(resultSet.getResultColumns());
 		}
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NormalizeResultSetNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NormalizeResultSetNode.java?rev=640520&r1=640519&r2=640520&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NormalizeResultSetNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NormalizeResultSetNode.java
Mon Mar 24 11:59:37 2008
@@ -70,23 +70,68 @@
 
 	/**
 	 * Initializer for a NormalizeResultSetNode.
+	 ** ColumnReferences must continue to point to the same ResultColumn, so
+	 * that ResultColumn must percolate up to the new PRN.  However,
+	 * that ResultColumn will point to a new expression, a VirtualColumnNode, 
+	 * which points to the FromTable and the ResultColumn that is the source for
+	 * the ColumnReference.  
+	 * (The new NRSN will have the original of the ResultColumnList and
+	 * the ResultColumns from that list.  The FromTable will get shallow copies
+	 * of the ResultColumnList and its ResultColumns.  ResultColumn.expression
+	 * will remain at the FromTable, with the PRN getting a new 
+	 * VirtualColumnNode for each ResultColumn.expression.)
+	 *
+	 * This is useful for UNIONs, where we want to generate a DistinctNode above
+	 * the UnionNode to eliminate the duplicates, because the type going into the
+	 * sort has to agree with what the sort expects.
+	 * (insert into t1 (smallintcol) values 1 union all values 2;
 	 *
 	 * @param childResult	The child ResultSetNode
-	 * @param rcl			The RCL for the node
 	 * @param tableProperties	Properties list associated with the table
 	 * @param forUpdate 	tells us if the normalize operation is being
 	 * performed on behalf of an update statement. 
+	 * @throws StandardException 
 	 */
 
 	public void init(
 							Object childResult,
-							Object rcl,
 							Object tableProperties,
-							Object forUpdate)
+							Object forUpdate) throws StandardException
 	{
 		super.init(childResult, tableProperties);
-		resultColumns = (ResultColumnList) rcl;
 		this.forUpdate = ((Boolean)forUpdate).booleanValue();
+
+		ResultSetNode rsn  = (ResultSetNode) childResult;
+		ResultColumnList rcl = rsn.getResultColumns();
+
+		/* We get a shallow copy of the ResultColumnList and its 
+		 * ResultColumns.  (Copy maintains ResultColumn.expression for now.)
+		 * 
+		 * Setting this.resultColumns to the modified child result column list,
+		 * and making a new copy for the child result set node
+		 * ensures that the ProjectRestrictNode restrictions still points to 
+		 * the same list.  See d3494_npe_writeup-4.html in DERBY-3494 for a
+		 * detailed explanation of how this works.
+		 */
+		ResultColumnList prRCList = rcl;
+		rsn.setResultColumns(rcl.copyListAndObjects());
+		// Remove any columns that were generated.
+		prRCList.removeGeneratedGroupingColumns();
+
+		/* Replace ResultColumn.expression with new VirtualColumnNodes
+		 * in the NormalizeResultSetNode's ResultColumnList.  (VirtualColumnNodes include
+		 * pointers to source ResultSetNode, rsn, and source ResultColumn.)
+		 */
+		prRCList.genVirtualColumnNodes(rsn, rsn.getResultColumns());
+        
+		this.resultColumns = prRCList;
+		// Propagate the referenced table map if it's already been created
+		if (rsn.getReferencedTableMap() != null)
+		    {
+			setReferencedTableMap((JBitSet) getReferencedTableMap().clone());
+		    }
+        
+        
 	}
 
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java?rev=640520&r1=640519&r2=640520&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java Mon
Mar 24 11:59:37 2008
@@ -1396,70 +1396,9 @@
 		return genProjectRestrict();
 	}
 
-	/** 
-	 * Put a NormalizeResultSetNode on top of this ResultSetNode.
-	 * ColumnReferences must continue to point to the same ResultColumn, so
-	 * that ResultColumn must percolate up to the new PRN.  However,
-	 * that ResultColumn will point to a new expression, a VirtualColumnNode, 
-	 * which points to the FromTable and the ResultColumn that is the source for
-	 * the ColumnReference.  
-	 * (The new NRSN will have the original of the ResultColumnList and
-	 * the ResultColumns from that list.  The FromTable will get shallow copies
-	 * of the ResultColumnList and its ResultColumns.  ResultColumn.expression
-	 * will remain at the FromTable, with the PRN getting a new 
-	 * VirtualColumnNode for each ResultColumn.expression.)
-	 *
-	 * This is useful for UNIONs, where we want to generate a DistinctNode above
-	 * the UnionNode to eliminate the duplicates, because the type going into the
-	 * sort has to agree with what the sort expects.
-	 * (insert into t1 (smallintcol) values 1 union all values 2;
-	 *
-	 * @param forUpdate			If the normalize result set is being used as a
-	 * child for an update statement, then this is true. 
-	 *
-	 * @return The generated NormalizeResultSetNode atop the original UnionNode.
-	 *
-	 * @exception StandardException		Thrown on error
-	 * @see NormalizeResultSetNode#init
-	 */
-
-	NormalizeResultSetNode 
-		genNormalizeResultSetNode(boolean forUpdate)
-				throws StandardException
-	{
-		/* We get a shallow copy of the ResultColumnList and its 
-		 * ResultColumns.  (Copy maintains ResultColumn.expression for now.)
-		 */
-        ResultColumnList prRCList = resultColumns;
-		resultColumns = resultColumns.copyListAndObjects();
-
-		// Remove any columns that were generated.
-		prRCList.removeGeneratedGroupingColumns();
-
-		/* Replace ResultColumn.expression with new VirtualColumnNodes
-		 * in the NormalizeResultSetNode's ResultColumnList.  (VirtualColumnNodes include
-		 * pointers to source ResultSetNode, this, and source ResultColumn.)
-		 */
-		prRCList.genVirtualColumnNodes(this, resultColumns);
-
-		
-		/* Finally, we create the new NormalizeResultSetNode */
-        NormalizeResultSetNode nrsn =
-            (NormalizeResultSetNode) getNodeFactory().getNode(
-								C_NodeTypes.NORMALIZE_RESULT_SET_NODE,
-								this,
-								prRCList,
-								null, new Boolean(forUpdate),
-								getContextManager());
-		// Propagate the referenced table map if it's already been created
-		if (getReferencedTableMap() != null)
-		{
-			nrsn.setReferencedTableMap((JBitSet) getReferencedTableMap().clone());
-		}
-		return nrsn;
-	}
-
-	/**
+	
+    
+    /**
 	 * Generate the code for a NormalizeResultSet.
 	   The call must push two items before calling this method
 	   <OL>

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnionNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnionNode.java?rev=640520&r1=640519&r2=640520&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnionNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnionNode.java Mon Mar
24 11:59:37 2008
@@ -410,7 +410,11 @@
 			 */
 			if (! columnTypesAndLengthsMatch())
 			{
-				treeTop = genNormalizeResultSetNode(false);	
+			    treeTop = 
+				(NormalizeResultSetNode) getNodeFactory().getNode(
+				C_NodeTypes.NORMALIZE_RESULT_SET_NODE,
+				treeTop, null, Boolean.FALSE,
+				getContextManager());	
 			}
 
 			treeTop = (ResultSetNode) getNodeFactory().getNode(

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java?rev=640520&r1=640519&r2=640520&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java Mon
Mar 24 11:59:37 2008
@@ -548,7 +548,10 @@
 		 */
 		if (! resultColumnList.columnTypesAndLengthsMatch())
  		{
-			resultSet = resultSet.genNormalizeResultSetNode(true);
+			resultSet = (NormalizeResultSetNode) getNodeFactory().getNode(
+			    C_NodeTypes.NORMALIZE_RESULT_SET_NODE,
+			    resultSet, null, Boolean.TRUE,
+			    getContextManager());
 			resultColumnList.copyTypesAndLengthsToSource(resultSet.getResultColumns());
 								
  			if (hasCheckConstraints(dataDictionary, targetTableDescriptor))



Mime
View raw message