You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by td...@apache.org on 2015/07/03 06:38:34 UTC

phoenix git commit: PHOENIX-2065 Throw TableNotFoundException when select all columns of one column family from the table with schema (Jun Ng)

Repository: phoenix
Updated Branches:
  refs/heads/master b2fb04b0c -> ba5faf143


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/ba5faf14
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/ba5faf14
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/ba5faf14

Branch: refs/heads/master
Commit: ba5faf1435756cf42d2e39e65e1a82cdf00530c3
Parents: b2fb04b
Author: Thomas D'Silva <td...@salesforce.com>
Authored: Thu Jul 2 21:37:10 2015 -0700
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Jul 2 21:38:26 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/ba5faf14/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/ba5faf14/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 79721df..559ce10 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
@@ -1859,4 +1859,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();
+        }
+    }
+
 }