You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2013/01/14 19:46:22 UTC
svn commit: r1433031 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/sql/compile/FromVTI.java
engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java
Author: rhillegas
Date: Mon Jan 14 18:46:22 2013
New Revision: 1433031
URL: http://svn.apache.org/viewvc?rev=1433031&view=rev
Log:
DERBY-6040: Fix sort order bug when selecting a partial column list from a table function.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java?rev=1433031&r1=1433030&r2=1433031&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java Mon Jan 14 18:46:22 2013
@@ -34,6 +34,7 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Vector;
import org.apache.derby.catalog.TypeDescriptor;
+import org.apache.derby.catalog.DefaultInfo;
import org.apache.derby.catalog.UUID;
import org.apache.derby.catalog.types.RoutineAliasInfo;
import org.apache.derby.iapi.error.StandardException;
@@ -62,6 +63,7 @@ import org.apache.derby.iapi.sql.diction
import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
import org.apache.derby.iapi.sql.execute.ExecutionContext;
import org.apache.derby.iapi.types.DataTypeDescriptor;
+import org.apache.derby.iapi.types.DataValueDescriptor;
import org.apache.derby.iapi.util.JBitSet;
import org.apache.derby.vti.DeferModification;
import org.apache.derby.vti.RestrictedVTI;
@@ -1981,10 +1983,27 @@ public class FromVTI extends FromTable i
TypeDescriptor[] types = td.getRowTypes();
for ( int i = 0; i < columnNames.length; i++ )
{
- resultColumns.addColumn( exposedName, columnNames[ i ],
- DataTypeDescriptor.getType(types[i]));
- }
+ String columnName = columnNames[ i ];
+ DataTypeDescriptor dtd = DataTypeDescriptor.getType(types[i]);
+ ResultColumn rc = resultColumns.addColumn
+ ( exposedName, columnName, dtd );
+ //
+ // Stuff a column descriptor into the ResultColumn. We do this so that
+ // getColumnPosition() will return the column position within the
+ // table function's shape. Later on, projection may remove columns
+ // from the ResultColumnList. We don't want getColumnPosition() to say
+ // that the column position is the index into the abbreviated ResultColumnList.
+ // See DERBY-6040.
+ //
+ ColumnDescriptor coldesc = new ColumnDescriptor
+ (
+ columnName, i+1, dtd,
+ (DataValueDescriptor) null, (DefaultInfo) null, (UUID) null, (UUID) null,
+ 0L, 0L, 0L
+ );
+ rc.setColumnDescriptor( null, coldesc );
+ }
}
/**
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java?rev=1433031&r1=1433030&r2=1433031&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java Mon Jan 14 18:46:22 2013
@@ -3466,9 +3466,10 @@ public class ResultColumnList extends Qu
/**
* Add a column to the list given a tablename, columnname, and datatype.
+ * Return the just-added column.
*
*/
- public void addColumn( TableName tableName, String columnName, DataTypeDescriptor dts )
+ public ResultColumn addColumn( TableName tableName, String columnName, DataTypeDescriptor dts )
throws StandardException
{
ValueNode bcn = (ValueNode) getNodeFactory().getNode(
@@ -3484,6 +3485,8 @@ public class ResultColumnList extends Qu
getContextManager());
rc.setType(dts);
addResultColumn(rc);
+
+ return rc;
}
/**
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=1433031&r1=1433030&r2=1433031&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 Mon Jan 14 18:46:22 2013
@@ -1933,6 +1933,7 @@ public class TableFunctionTest extends B
{
derby_4092();
derby_5779();
+ derby_6040();
}
/**
@@ -2325,6 +2326,82 @@ public class TableFunctionTest extends B
/**
* <p>
+ * Make sure that ORDER BY columns are not mistakenly pruned
+ * when projection eliminates a column and one of the columns is
+ * compared to a constant.
+ * </p>
+ */
+ private void derby_6040()
+ throws Exception
+ {
+ goodStatement
+ (
+ "create function leftTable\n" +
+ "(\n" +
+ " columnNames varchar( 32672 ),\n" +
+ " rowContents varchar( 32672 ) ...\n" +
+ ")\n" +
+ "returns table\n" +
+ "(\n" +
+ " a0 varchar( 5 ),\n" +
+ " a1 varchar( 5 ),\n" +
+ " a2 varchar( 5 ),\n" +
+ " a3 varchar( 5 )\n" +
+ ")\n" +
+ "language java parameter style derby_jdbc_result_set no sql\n" +
+ "external name 'org.apache.derbyTesting.functionTests.tests.lang.VarargsRoutines.stringArrayTable'\n"
+ );
+ goodStatement
+ (
+ "create function rightTable\n" +
+ "(\n" +
+ " columnNames varchar( 32672 ),\n" +
+ " rowContents varchar( 32672 ) ...\n" +
+ ")\n" +
+ "returns table\n" +
+ "(\n" +
+ " b1 varchar( 5 ),\n" +
+ " b2 varchar( 5 ),\n" +
+ " b3 varchar( 5 )\n" +
+ ")\n" +
+ "language java parameter style derby_jdbc_result_set no sql\n" +
+ "external name 'org.apache.derbyTesting.functionTests.tests.lang.VarargsRoutines.stringArrayTable'\n"
+ );
+ assertResults
+ (
+ "select l.a2 column0, r.b3 column1\n" +
+ "from\n" +
+ " table( leftTable\n" +
+ " (\n" +
+ " 'A0 A1 A2 A3',\n" +
+ " 'X APP T Z',\n" +
+ " 'X APP S Z'\n" +
+ " ) ) l,\n" +
+ " table( rightTable\n" +
+ " (\n" +
+ " 'B1 B2 B3',\n" +
+ " 'APP T A',\n" +
+ " 'APP T B',\n" +
+ " 'APP S A',\n" +
+ " 'APP S B'\n" +
+ " ) ) r\n" +
+ "where r.b2 = l.a2\n" +
+ "and l.a3 = 'Z'\n" +
+ "and r.b1 = l.a1\n" +
+ "order by column0, column1\n",
+ new String[][]
+ {
+ { "S", "A" },
+ { "S", "B" },
+ { "T", "A" },
+ { "T", "B" },
+ },
+ new int[] { Types.VARCHAR, Types.VARCHAR }
+ );
+ }
+
+ /**
+ * <p>
* Make the input rows for the coercion function.
* </p>
*/