Repository: phoenix Updated Branches: refs/heads/master 8d41ab0b4 -> 507c7270c
PHOENIX-2425 Invalid sql syntax produces NPE instead of meaningful error message Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/21c12b11 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/21c12b11 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/21c12b11 Branch: refs/heads/master Commit: 21c12b11b1bc1b18ac667666dd715ed91d48ed4f Parents: 27a152e Author: maryannxue <wei....@intel.com> Authored: Thu Nov 19 13:43:35 2015 -0500 Committer: maryannxue <wei....@intel.com> Committed: Thu Nov 19 13:43:35 2015 -0500 ---------------------------------------------------------------------- .../phoenix/compile/ProjectionCompiler.java | 6 +++++ .../phoenix/exception/SQLExceptionCode.java | 1 + .../phoenix/compile/QueryCompilerTest.java | 24 +++++++++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/21c12b11/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java index 86b89b8..e477009 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java @@ -364,6 +364,9 @@ public class ProjectionCompiler { if (statement.isAggregate()) { ExpressionCompiler.throwNonAggExpressionInAggException(node.toString()); } + if (tableRef == TableRef.EMPTY_TABLE_REF) { + throw new SQLExceptionInfo.Builder(SQLExceptionCode.NO_TABLE_SPECIFIED_FOR_WILDCARD_SELECT).build().buildException(); + } isWildcard = true; if (tableRef.getTable().getType() == PTableType.INDEX && ((WildcardParseNode)node).isRewrite()) { projectAllIndexColumns(context, tableRef, resolveColumn, projectedExpressions, projectedColumns, targetColumns); @@ -382,6 +385,9 @@ public class ProjectionCompiler { projectAllTableColumns(context, tRef, true, projectedExpressions, projectedColumns, targetColumns); } } else if (node instanceof FamilyWildcardParseNode){ + if (tableRef == TableRef.EMPTY_TABLE_REF) { + throw new SQLExceptionInfo.Builder(SQLExceptionCode.NO_TABLE_SPECIFIED_FOR_WILDCARD_SELECT).build().buildException(); + } // Project everything for SELECT cf.* String cfName = ((FamilyWildcardParseNode) node).getName(); // Delay projecting to scan, as when any other column in the column family gets http://git-wip-us.apache.org/repos/asf/phoenix/blob/21c12b11/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java index cc0d0ed..bb76ccb 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java @@ -226,6 +226,7 @@ public enum SQLExceptionCode { AGGREGATE_WITH_NOT_GROUP_BY_COLUMN(1018, "42Y27", "Aggregate may not contain columns not in GROUP BY."), ONLY_AGGREGATE_IN_HAVING_CLAUSE(1019, "42Y26", "Only aggregate maybe used in the HAVING clause."), UPSERT_COLUMN_NUMBERS_MISMATCH(1020, "42Y60", "Number of columns upserting must match number of values."), + NO_TABLE_SPECIFIED_FOR_WILDCARD_SELECT(1057, "42Y10", "No table specified for wildcard select."), // Table properties exception. INVALID_BUCKET_NUM(1021, "42Y80", "Salt bucket numbers should be with 1 and 256."), NO_SPLITS_ON_SALTED_TABLE(1022, "42Y81", "Should not specify split points on salted table with default row key order."), http://git-wip-us.apache.org/repos/asf/phoenix/blob/21c12b11/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 dd7b181..23eb147 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 @@ -1985,9 +1985,27 @@ public class QueryCompilerTest extends BaseConnectionlessQueryTest { public void testFailNoFromClauseSelect() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); try { - conn.createStatement().executeQuery("SELECT foo, bar"); - fail("Should have got ColumnNotFoundException"); - } catch (ColumnNotFoundException e) { + try { + conn.createStatement().executeQuery("SELECT foo, bar"); + fail("Should have got ColumnNotFoundException"); + } catch (ColumnNotFoundException e) { + } + + try { + conn.createStatement().executeQuery("SELECT *"); + fail("Should have got SQLException"); + } catch (SQLException e) { + assertEquals(SQLExceptionCode.NO_TABLE_SPECIFIED_FOR_WILDCARD_SELECT.getErrorCode(), e.getErrorCode()); + } + + try { + conn.createStatement().executeQuery("SELECT A.*"); + fail("Should have got SQLException"); + } catch (SQLException e) { + assertEquals(SQLExceptionCode.NO_TABLE_SPECIFIED_FOR_WILDCARD_SELECT.getErrorCode(), e.getErrorCode()); + } + } finally { + conn.close(); } }