You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ss...@apache.org on 2017/05/22 19:16:48 UTC
[4/4] phoenix git commit: PHOENIX-3843 Improve logging for UNION ALL
errors
PHOENIX-3843 Improve logging for UNION ALL errors
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/e746c225
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/e746c225
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/e746c225
Branch: refs/heads/4.x-HBase-1.2
Commit: e746c225eddd59936d1f21ba2f5814c2d683a5d1
Parents: 1089db9
Author: Sergey Soldatov <ss...@apache.org>
Authored: Wed May 10 00:44:17 2017 -0700
Committer: Sergey Soldatov <ss...@apache.org>
Committed: Mon May 22 11:00:06 2017 -0700
----------------------------------------------------------------------
.../apache/phoenix/compile/UnionCompiler.java | 7 ++-
.../phoenix/compile/QueryCompilerTest.java | 47 ++++++++++++++++++++
2 files changed, 52 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e746c225/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
index e5e18e3..c7f798c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
@@ -58,7 +58,8 @@ public class UnionCompiler {
for (QueryPlan plan : selectPlans) {
if (columnCount !=plan.getProjector().getColumnCount()) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode
- .SELECT_COLUMN_NUM_IN_UNIONALL_DIFFS).setMessage(".")
+ .SELECT_COLUMN_NUM_IN_UNIONALL_DIFFS).setMessage("1st query has " + columnCount + " columns whereas 2nd " +
+ "query has " + plan.getProjector().getColumnCount())
.build().buildException();
}
ColumnProjector colproj = plan.getProjector().getColumnProjector(i);
@@ -116,7 +117,9 @@ public class UnionCompiler {
targetTypes.get(i).setType(type);
} else {
throw new SQLExceptionInfo.Builder(SQLExceptionCode
- .SELECT_COLUMN_TYPE_IN_UNIONALL_DIFFS).setMessage(".")
+ .SELECT_COLUMN_TYPE_IN_UNIONALL_DIFFS).setMessage("Column # " + i + " is "
+ + targetTypes.get(i).getType().getSqlTypeName() + " in 1st query where as it is "
+ + type.getSqlTypeName() + " in 2nd query")
.build().buildException();
}
Integer len = expression.getMaxLength();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e746c225/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
index 4bc7d2b..9d0e3d2 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
@@ -4134,4 +4134,51 @@ public class QueryCompilerTest extends BaseConnectionlessQueryTest {
}
}
}
+
+ @Test
+ public void testUnionDifferentColumnNumber() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ Statement statement = conn.createStatement();
+ try {
+ String create = "CREATE TABLE s.t1 (k integer not null primary key, f1.v1 varchar, f1.v2 varchar, " +
+ "f2.v3 varchar, v4 varchar)";
+ statement.execute(create);
+ create = "CREATE TABLE s.t2 (k integer not null primary key, f1.v1 varchar, f1.v2 varchar, f2.v3 varchar)";
+ statement.execute(create);
+ String query = "SELECT * FROM s.t1 UNION ALL select * FROM s.t2";
+ statement.executeQuery(query);
+ fail("Should fail with different column numbers ");
+ } catch (SQLException e) {
+ assertEquals(e.getMessage(), "ERROR 525 (42902): SELECT column number differs in a Union All query " +
+ "is not allowed. 1st query has 5 columns whereas 2nd query has 4");
+ } finally {
+ statement.execute("DROP TABLE IF EXISTS s.t1");
+ statement.execute("DROP TABLE IF EXISTS s.t2");
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testUnionDifferentColumnType() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ Statement statement = conn.createStatement();
+ try {
+ String create = "CREATE TABLE s.t1 (k integer not null primary key, f1.v1 varchar, f1.v2 varchar, " +
+ "f2.v3 varchar, v4 varchar)";
+ statement.execute(create);
+ create = "CREATE TABLE s.t2 (k integer not null primary key, f1.v1 varchar, f1.v2 integer, " +
+ "f2.v3 varchar, f2.v4 varchar)";
+ statement.execute(create);
+ String query = "SELECT * FROM s.t1 UNION ALL select * FROM s.t2";
+ statement.executeQuery(query);
+ fail("Should fail with different column types ");
+ } catch (SQLException e) {
+ assertEquals(e.getMessage(), "ERROR 526 (42903): SELECT column types differ in a Union All query " +
+ "is not allowed. Column # 2 is VARCHAR in 1st query where as it is INTEGER in 2nd query");
+ } finally {
+ statement.execute("DROP TABLE IF EXISTS s.t1");
+ statement.execute("DROP TABLE IF EXISTS s.t2");
+ conn.close();
+ }
+ }
}