Repository: phoenix Updated Branches: refs/heads/4.x-HBase-1.0 98f3f12be -> 421ad309b
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/421ad309 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/421ad309 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/421ad309 Branch: refs/heads/4.x-HBase-1.0 Commit: 421ad309bfba84d7d6c0bc6c1ebafe7c7a583e33 Parents: 6967543 Author: James Taylor <jtay...@salesforce.com> Authored: Thu Feb 11 20:10:23 2016 -0800 Committer: James Taylor <jtay...@salesforce.com> Committed: Thu Feb 11 20:22:18 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/421ad309/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/421ad309/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; }