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 ka...@apache.org on 2014/05/15 10:34:40 UTC
svn commit: r1594816 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/sql/compile/
testing/org/apache/derbyTesting/functionTests/tests/lang/
Author: kahatlen
Date: Thu May 15 08:34:39 2014
New Revision: 1594816
URL: http://svn.apache.org/r1594816
Log:
DERBY-6577: Quantified comparison returns wrong result in CASE, COALESCE, IN and BETWEEN
ValueNodeList.preprocess() should update the list with the rewritten expressions.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InbetweenTest.java
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?rev=1594816&r1=1594815&r2=1594816&view=diff
==============================================================================
--- 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 Thu May 15 08:34:39 2014
@@ -546,14 +546,13 @@ class ValueNodeList extends QueryTreeNod
throws StandardException
{
int size = size();
- ValueNode valueNode;
for (int index = 0; index < size; index++)
{
- valueNode = elementAt(index);
- valueNode.preprocess(numTables,
+ ValueNode vn = elementAt(index).preprocess(numTables,
outerFromList, outerSubqueryList,
outerPredicateList);
+ setElementAt(vn, index);
}
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java?rev=1594816&r1=1594815&r2=1594816&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java Thu May 15 08:34:39 2014
@@ -547,4 +547,13 @@ public class CaseExpressionTest extends
assertCompileError("42X89",
"values case when 1<>1 then 'abc' else cast(null as smallint) end");
}
+
+ /** Regression test case for DERBY-6577. */
+ public void testQuantifiedComparison() throws SQLException {
+ // This query used to return wrong results.
+ JDBC.assertUnorderedResultSet(createStatement().executeQuery(
+ "select c, case when c = all (values 'Y') then true end "
+ + "from (values 'Y', 'N') v(c)"),
+ new String[][] { { "N", null }, { "Y", "true" }});
+ }
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java?rev=1594816&r1=1594815&r2=1594816&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java Thu May 15 08:34:39 2014
@@ -1085,6 +1085,15 @@ public class CoalesceTest extends BaseJD
vetThreeArgCoalesce("values coalesce(?, ?, cast(? as char(1)))");
}
+ /** Regression test case for DERBY-6577. */
+ public void testQuantifiedComparison() throws SQLException {
+ // This query used to return wrong results.
+ JDBC.assertUnorderedResultSet(createStatement().executeQuery(
+ "select c, coalesce((c = all (values 'Y')), false) "
+ + "from (values 'Y', 'N') v(c)"),
+ new String[][] { { "N", "false" }, { "Y", "true" }});
+ }
+
private void vetThreeArgCoalesce(String sql) throws SQLException {
// First three values in each row are arguments to COALESCE. The
// last value is the expected return value.
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InbetweenTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InbetweenTest.java?rev=1594816&r1=1594815&r2=1594816&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InbetweenTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InbetweenTest.java Thu May 15 08:34:39 2014
@@ -4467,4 +4467,25 @@ public final class InbetweenTest extends
"on a=b where b not between 1 and 5"),
new String[][]{{"0", "0"}});
}
+
+ /** Regression test case for DERBY-6577. */
+ public void testInBetweenQuantifiedComparison() throws SQLException {
+ Statement s = createStatement();
+ String[][] expectedRows = {
+ { "Y", "true" },
+ { "N", "false" },
+ };
+
+ // This query used to return wrong results.
+ JDBC.assertUnorderedResultSet(s.executeQuery(
+ "select c, true in ((c = all (values 'Y'))) "
+ + "from (values 'Y', 'N') v(c)"),
+ expectedRows);
+
+ // This query used to return wrong results.
+ JDBC.assertUnorderedResultSet(s.executeQuery(
+ "select c, true between false and (c = all (values 'Y')) "
+ + "from (values 'Y', 'N') v(c)"),
+ expectedRows);
+ }
}