You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2016/06/09 18:15:32 UTC
[4/4] phoenix git commit: PHOENIX-2942 Order by incorrect for RVC
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/ec02daf3
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/ec02daf3
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/ec02daf3
Branch: refs/heads/master
Commit: ec02daf34f46163b8d089eb50257fe43f134dc24
Parents: 94c4b2a
Author: James Taylor <ja...@apache.org>
Authored: Thu Jun 9 11:18:48 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Thu Jun 9 11:18:48 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/ec02daf3/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/ec02daf3/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;