Repository: phoenix Updated Branches: refs/heads/4.4-HBase-1.1 2fba75c65 -> 4db7aaf38
PHOENIX-2065 Throw TableNotFoundException when select all columns of one column family from the table with schema (Jun Ng) Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/4db7aaf3 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/4db7aaf3 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/4db7aaf3 Branch: refs/heads/4.4-HBase-1.1 Commit: 4db7aaf38522a655027bcaf7e6bec10374629c63 Parents: 2fba75c Author: Thomas D'Silva <tdsi...@salesforce.com> Authored: Thu Jul 2 21:37:10 2015 -0700 Committer: Thomas D'Silva <tdsi...@salesforce.com> Committed: Thu Jul 2 21:43:22 2015 -0700 ---------------------------------------------------------------------- .../apache/phoenix/compile/FromCompiler.java | 7 +++- .../phoenix/compile/QueryCompilerTest.java | 41 ++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/4db7aaf3/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java index 5fe0e6f..bc753c9 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java @@ -710,7 +710,12 @@ public class FromCompiler { if (theColumnFamilyRef != null) { return theColumnFamilyRef; } throw new TableNotFoundException(cfName); } else { - TableRef tableRef = resolveTable(null, tableName); + TableRef tableRef = null; + try { + tableRef = resolveTable(null, tableName); + } catch (TableNotFoundException e) { + return resolveColumnFamily(null, cfName); + } PColumnFamily columnFamily = tableRef.getTable().getColumnFamily(cfName); return new ColumnFamilyRef(tableRef, columnFamily); } http://git-wip-us.apache.org/repos/asf/phoenix/blob/4db7aaf3/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 7be8eae..cbbfb90 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 @@ -1793,4 +1793,45 @@ public class QueryCompilerTest extends BaseConnectionlessQueryTest { assertFalse("Expected plan to not use round robin iterator " + query, plan.useRoundRobinIterator()); } } + + @Test + public void testSelectColumnsInOneFamily() throws Exception { + Connection conn = DriverManager.getConnection(getUrl()); + Statement statement = conn.createStatement(); + try { + // create table with specified column family. + String create = "CREATE TABLE t (k integer not null primary key, f1.v1 varchar, f1.v2 varchar, f2.v3 varchar, v4 varchar)"; + statement.execute(create); + // select columns in one family. + String query = "SELECT f1.*, v4 FROM t"; + ResultSetMetaData rsMeta = statement.executeQuery(query).getMetaData(); + assertEquals("V1", rsMeta.getColumnName(1)); + assertEquals("V2", rsMeta.getColumnName(2)); + assertEquals("V4", rsMeta.getColumnName(3)); + } finally { + statement.execute("DROP TABLE IF EXISTS t"); + conn.close(); + } + } + + @Test + public void testSelectColumnsInOneFamilyWithSchema() throws Exception { + Connection conn = DriverManager.getConnection(getUrl()); + Statement statement = conn.createStatement(); + try { + // create table with specified column family. + String create = "CREATE TABLE s.t (k integer not null primary key, f1.v1 varchar, f1.v2 varchar, f2.v3 varchar, v4 varchar)"; + statement.execute(create); + // select columns in one family. + String query = "SELECT f1.*, v4 FROM s.t"; + ResultSetMetaData rsMeta = statement.executeQuery(query).getMetaData(); + assertEquals("V1", rsMeta.getColumnName(1)); + assertEquals("V2", rsMeta.getColumnName(2)); + assertEquals("V4", rsMeta.getColumnName(3)); + } finally { + statement.execute("DROP TABLE IF EXISTS s.t"); + conn.close(); + } + } + }