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/02/12 05:14:46 UTC
[2/2] phoenix git commit: PHOENIX-2658 When using QueryRunner API
UNION ALL queries fail with NPE (Alicia Ying Shu)
PHOENIX-2658 When using QueryRunner API UNION ALL queries fail with NPE (Alicia Ying Shu)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/0c21539c
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/0c21539c
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/0c21539c
Branch: refs/heads/master
Commit: 0c21539cc331b8d6ca144604cf899068ad74fb25
Parents: 18f7a69
Author: James Taylor <jt...@salesforce.com>
Authored: Thu Feb 11 20:10:23 2016 -0800
Committer: James Taylor <jt...@salesforce.com>
Committed: Thu Feb 11 20:14:32 2016 -0800
----------------------------------------------------------------------
.../org/apache/phoenix/end2end/UnionAllIT.java | 49 +++++++++++++++++++-
.../apache/phoenix/compile/QueryCompiler.java | 3 +-
2 files changed, 50 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0c21539c/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java
index 6531129..b391dcc 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java
@@ -40,7 +40,6 @@ import org.apache.phoenix.util.ReadOnlyProps;
import org.junit.BeforeClass;
import org.junit.Test;
-
public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
@BeforeClass
@@ -679,4 +678,52 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
conn.close();
}
}
+
+ @Test
+ public void testParameterMetaDataNotNull() throws Exception {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+
+ String ddl = "CREATE TABLE test_table " +
+ " (a_string varchar not null, col1 integer" +
+ " CONSTRAINT pk PRIMARY KEY (a_string))\n";
+ createTestTable(getUrl(), ddl);
+ String dml = "UPSERT INTO test_table VALUES(?, ?)";
+ PreparedStatement stmt = conn.prepareStatement(dml);
+ stmt.setString(1, "a");
+ stmt.setInt(2, 10);
+ stmt.execute();
+ conn.commit();
+
+ ddl = "CREATE TABLE b_table " +
+ " (a_string varchar not null, col1 integer" +
+ " CONSTRAINT pk PRIMARY KEY (a_string))\n";
+ createTestTable(getUrl(), ddl);
+ dml = "UPSERT INTO b_table VALUES(?, ?)";
+ stmt = conn.prepareStatement(dml);
+ stmt.setString(1, "b");
+ stmt.setInt(2, 20);
+ stmt.execute();
+ conn.commit();
+
+ String query = "select * from test_table union all select * from b_table";
+
+ try{
+ PreparedStatement pstmt = conn.prepareStatement(query);
+ assertTrue(pstmt.getParameterMetaData() != null);
+ ResultSet rs = pstmt.executeQuery();
+ assertTrue(rs.next());
+ assertEquals("a",rs.getString(1));
+ assertEquals(10,rs.getInt(2));
+ assertTrue(rs.next());
+ assertEquals("b",rs.getString(1));
+ assertEquals(20,rs.getInt(2));
+ assertFalse(rs.next());
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ } finally {
+ conn.close();
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0c21539c/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java
index 70bb815..9e756c8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java
@@ -182,7 +182,8 @@ public class QueryCompiler {
StatementContext context = new StatementContext(statement, resolver, scan, sequenceManager);
QueryPlan plan = compileSingleFlatQuery(context, select, statement.getParameters(), false, false, null, null, false);
- plan = new UnionPlan(context, select, tableRef, plan.getProjector(), plan.getLimit(), plan.getOrderBy(), GroupBy.EMPTY_GROUP_BY, plans, null);
+ plan = new UnionPlan(context, select, tableRef, plan.getProjector(), plan.getLimit(), plan.getOrderBy(), GroupBy.EMPTY_GROUP_BY,
+ plans, context.getBindManager().getParameterMetaData());
return plan;
}