You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ma...@apache.org on 2015/04/03 23:17:09 UTC
phoenix git commit: Fixed select one column issue;
Added a distinct test
Repository: phoenix
Updated Branches:
refs/heads/calcite fbcefdbf3 -> f04eaf172
Fixed select one column issue; Added a distinct test
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/f04eaf17
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/f04eaf17
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/f04eaf17
Branch: refs/heads/calcite
Commit: f04eaf172b7ca3b100cc14cc191800cc98e508ee
Parents: fbcefdb
Author: maryannxue <we...@intel.com>
Authored: Fri Apr 3 17:16:44 2015 -0400
Committer: maryannxue <we...@intel.com>
Committed: Fri Apr 3 17:16:44 2015 -0400
----------------------------------------------------------------------
.../org/apache/phoenix/calcite/CalciteTest.java | 13 +++++++++
.../apache/phoenix/calcite/CalciteRuntime.java | 28 ++++++++++++--------
2 files changed, 30 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/f04eaf17/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
index a4017dc..8d2be0d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
@@ -335,6 +335,19 @@ public class CalciteTest extends BaseClientManagedTimeIT {
.close();
}
+ @Test public void testDistinct() {
+ start().sql("select distinct a_string from aTable")
+ .explainIs("PhoenixToEnumerableConverter\n" +
+ " PhoenixAggregate(group=[{0}])\n" +
+ " PhoenixProject(A_STRING=[$2])\n" +
+ " PhoenixTableScan(table=[[phoenix, ATABLE]])\n")
+ .resultIs(new Object[][]{
+ {"a"},
+ {"b"},
+ {"c"}})
+ .close();;
+ }
+
@Test public void testSubquery() {
start().sql("SELECT \"order_id\", quantity FROM " + JOIN_ORDER_TABLE_FULL_NAME + " o WHERE quantity = (SELECT max(quantity) FROM " + JOIN_ORDER_TABLE_FULL_NAME + " q WHERE o.\"item_id\" = q.\"item_id\")")
.explainIs("PhoenixToEnumerableConverter\n" +
http://git-wip-us.apache.org/repos/asf/phoenix/blob/f04eaf17/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteRuntime.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteRuntime.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteRuntime.java
index 0c7c495..d961630 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteRuntime.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteRuntime.java
@@ -16,16 +16,16 @@ import java.sql.SQLException;
* Methods used by code generated by Calcite.
*/
public class CalciteRuntime {
- public static Enumerable<Object[]> toEnumerable2(final ResultIterator iterator, final RowProjector rowProjector) {
- return new AbstractEnumerable<Object[]>() {
+ public static Enumerable<Object> toEnumerable2(final ResultIterator iterator, final RowProjector rowProjector) {
+ return new AbstractEnumerable<Object>() {
@Override
- public Enumerator<Object[]> enumerator() {
+ public Enumerator<Object> enumerator() {
return toEnumerator(iterator, rowProjector);
}
};
}
- public static Enumerable<Object[]> toEnumerable(final QueryPlan plan) {
+ public static Enumerable<Object> toEnumerable(final QueryPlan plan) {
try {
return toEnumerable2(plan.iterator(), plan.getProjector());
} catch (SQLException e) {
@@ -33,13 +33,14 @@ public class CalciteRuntime {
}
}
- public static Enumerator<Object[]> toEnumerator(final ResultIterator iterator, final RowProjector rowProjector) {
- return new Enumerator<Object[]>() {
- Object[] current;
+ public static Enumerator<Object> toEnumerator(final ResultIterator iterator, final RowProjector rowProjector) {
+ final int count = rowProjector.getColumnCount();
+ return new Enumerator<Object>() {
+ Object current;
private final ImmutableBytesWritable ptr = new ImmutableBytesWritable();
@Override
- public Object[] current() {
+ public Object current() {
return current;
}
@@ -51,12 +52,17 @@ public class CalciteRuntime {
current = null;
return false;
}
- int count = rowProjector.getColumnCount();
- current = new Object[count];
+ if (count == 1) {
+ ColumnProjector projector = rowProjector.getColumnProjector(0);
+ current = rowProjector.getColumnProjector(0).getValue(tuple, projector.getExpression().getDataType(), ptr);
+ return true;
+ }
+ Object[] array = new Object[count];
for (int i = 0; i < count; i++) {
ColumnProjector projector = rowProjector.getColumnProjector(i);
- current[i] = projector.getValue(tuple, projector.getExpression().getDataType(), ptr);
+ array[i] = projector.getValue(tuple, projector.getExpression().getDataType(), ptr);
}
+ current = array;
return true;
} catch (SQLException e) {
throw new RuntimeException(e);