phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject [1/4] phoenix git commit: PHOENIX-2942 Order by incorrect for RVC
Date Thu, 09 Jun 2016 18:27:53 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 82295b5d2 -> 5cc781e0d


PHOENIX-2942 Order by incorrect for RVC


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/5cc781e0
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/5cc781e0
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/5cc781e0

Branch: refs/heads/4.x-HBase-0.98
Commit: 5cc781e0d601670ea8ceee97a5a2392c15e5c7e5
Parents: ad7f18e
Author: James Taylor <jamestaylor@apache.org>
Authored: Thu Jun 9 11:18:48 2016 -0700
Committer: James Taylor <jamestaylor@apache.org>
Committed: Thu Jun 9 11:29:15 2016 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/OrderByIT.java   | 29 +++++++++++++++++++
 .../RowValueConstructorExpression.java          | 30 +++++++++++---------
 2 files changed, 45 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/5cc781e0/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
index 1d31eee..2c880e7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
@@ -507,4 +507,33 @@ public class OrderByIT extends BaseHBaseManagedTimeIT {
             conn.close();
         }
     }
+    
+    @Test
+    public void testOrderByRVC() throws Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        String ddl = "create table test1 (testpk varchar not null primary key, l_quantity
decimal(15,2), l_discount decimal(15,2))";
+        conn.createStatement().execute(ddl);
+
+        PreparedStatement stmt = conn.prepareStatement("upsert into test1 values ('a',0.1,0.9)");
+        stmt.execute();
+        stmt = conn.prepareStatement(" upsert into test1 values ('b',0.5,0.5)");
+        stmt.execute();
+        stmt = conn.prepareStatement(" upsert into test1 values ('c',0.9,0.1)");
+        stmt.execute();
+        conn.commit();
+
+        ResultSet rs;
+        stmt = conn.prepareStatement("select l_discount,testpk from test1 order by (l_discount,l_quantity)");
+        rs = stmt.executeQuery();
+        assertTrue(rs.next());
+        assertEquals(0.1, rs.getDouble(1), 0.01);
+        assertEquals("c", rs.getString(2));
+        assertTrue(rs.next());
+        assertEquals(0.5, rs.getDouble(1), 0.01);
+        assertEquals("b", rs.getString(2));
+        assertTrue(rs.next());
+        assertEquals(0.9, rs.getDouble(1), 0.01);
+        assertEquals("a", rs.getString(2));
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5cc781e0/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
index 481368c..15f6e3e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
@@ -44,7 +44,7 @@ public class RowValueConstructorExpression extends BaseCompoundExpression
{
     
     private ImmutableBytesWritable ptrs[];
     private ImmutableBytesWritable literalExprPtr;
-    private int counter;
+    private int partialEvalIndex = -1;
     private int estimatedByteSize;
 
     public RowValueConstructorExpression() {
@@ -52,7 +52,6 @@ public class RowValueConstructorExpression extends BaseCompoundExpression
{
     
     public RowValueConstructorExpression(List<Expression> children, boolean isConstant)
{
         super(children);
-        counter = 0;
         estimatedByteSize = 0;
         init(isConstant);
     }
@@ -108,9 +107,10 @@ public class RowValueConstructorExpression extends BaseCompoundExpression
{
     
     @Override
     public void reset() {
-        counter = 0;
+        partialEvalIndex = 0;
         estimatedByteSize = 0;
         Arrays.fill(ptrs, null);
+        super.reset();
     }
     
     private static int getExpressionByteCount(Expression e) {
@@ -132,30 +132,32 @@ public class RowValueConstructorExpression extends BaseCompoundExpression
{
             return true;
         }
         try {
-            int j;
-            int expressionCount = counter;
-            for(j = counter; j < ptrs.length; j++) {
-                final Expression expression = children.get(j);
+            boolean isPartialEval = this.partialEvalIndex >= 0;
+            int evalIndex = isPartialEval ? this.partialEvalIndex : 0;
+            int expressionCount = evalIndex;
+            for(; evalIndex < ptrs.length; evalIndex++) {
+                final Expression expression = children.get(evalIndex);
                 // TODO: handle overflow and underflow
                 if (expression.evaluate(tuple, ptr)) {
                     if (ptr.getLength() == 0) {
                         estimatedByteSize += getExpressionByteCount(expression);
                     } else {
-                        expressionCount = j+1;
-                        ptrs[j] = new ImmutableBytesWritable();
-                        ptrs[j].set(ptr.get(), ptr.getOffset(), ptr.getLength());
+                        expressionCount = evalIndex+1;
+                        ptrs[evalIndex] = new ImmutableBytesWritable();
+                        ptrs[evalIndex].set(ptr.get(), ptr.getOffset(), ptr.getLength());
                         estimatedByteSize += ptr.getLength() + (expression.getDataType().isFixedWidth()
? 0 : 1); // 1 extra for the separator byte.
                     }
-                    counter++;
                 } else if (tuple == null || tuple.isImmutable()) {
                     estimatedByteSize += getExpressionByteCount(expression);
-                    counter++;
-                } else {
+                } else { // Cannot yet be evaluated
                     return false;
                 }
             }
+            if (isPartialEval) {
+                this.partialEvalIndex = evalIndex; // Move counter forward
+            }
             
-            if (j == ptrs.length) {
+            if (evalIndex == ptrs.length) {
                 if (expressionCount == 0) {
                     ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
                     return true;


Mime
View raw message