You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2014/02/08 04:15:43 UTC

git commit: PHOENIX-30 NPE on PTable.getColumn(String) if column with same name used in the PK and non PK (JamesTaylor)

Updated Branches:
  refs/heads/master a977a7529 -> 5d1fd559b


PHOENIX-30 NPE on PTable.getColumn(String) if column with same name used in the PK and non PK (JamesTaylor)


Project: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/commit/5d1fd559
Tree: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/tree/5d1fd559
Diff: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/diff/5d1fd559

Branch: refs/heads/master
Commit: 5d1fd559b27ea04d677b5a77fb26ab1d685053ee
Parents: a977a75
Author: James Taylor <ja...@apache.org>
Authored: Fri Feb 7 19:15:26 2014 -0800
Committer: James Taylor <ja...@apache.org>
Committed: Fri Feb 7 19:15:26 2014 -0800

----------------------------------------------------------------------
 .../java/org/apache/phoenix/schema/PTableImpl.java |  6 ++++--
 .../apache/phoenix/compile/QueryCompileTest.java   | 17 ++++++++++++++++-
 2 files changed, 20 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/5d1fd559/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
index 466c26b..f2a3e76 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
@@ -468,8 +468,10 @@ public class PTableImpl implements PTable {
         }
         if (size > 1) {
             for (PColumn column : columns) {
-                if (QueryConstants.DEFAULT_COLUMN_FAMILY.equals(column.getFamilyName().getString())) {
-                    // Allow ambiguity with default column, since a user would not know how to prefix it.
+                if (column.getFamilyName() == null || QueryConstants.DEFAULT_COLUMN_FAMILY.equals(column.getFamilyName().getString())) {
+                    // Allow ambiguity with PK column or column in the default column family,
+                    // since a PK column cannot be prefixed and a user would not know how to
+                    // prefix a column in the default column family.
                     return column;
                 }
             }

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/5d1fd559/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompileTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompileTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompileTest.java
index d7579f9..e9c34e0 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompileTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompileTest.java
@@ -23,10 +23,10 @@ import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.apache.phoenix.util.TestUtil.assertDegenerate;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.fail;
 
 import java.sql.Connection;
@@ -45,12 +45,14 @@ import org.apache.phoenix.expression.aggregator.Aggregator;
 import org.apache.phoenix.expression.aggregator.CountAggregator;
 import org.apache.phoenix.expression.aggregator.ServerAggregators;
 import org.apache.phoenix.expression.function.TimeUnit;
+import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixPreparedStatement;
 import org.apache.phoenix.query.BaseConnectionlessQueryTest;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.schema.AmbiguousColumnException;
 import org.apache.phoenix.schema.ColumnAlreadyExistsException;
 import org.apache.phoenix.schema.ColumnNotFoundException;
+import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.SchemaUtil;
@@ -139,6 +141,19 @@ public class QueryCompileTest extends BaseConnectionlessQueryTest {
     }
 
     @Test
+    public void testSameColumnNameInPKAndNonPK() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        try {
+            String query = "CREATE TABLE t1 (k integer not null primary key, a.k decimal, b.k decimal)";
+            conn.createStatement().execute(query);
+            PColumn c = conn.unwrap(PhoenixConnection.class).getPMetaData().getTable("T1").getColumn("K");
+            assertTrue(SchemaUtil.isPKColumn(c));
+        } finally {
+            conn.close();
+        }
+    }
+
+    @Test
     public void testVarBinaryInMultipartPK() throws Exception {
         Connection conn = DriverManager.getConnection(getUrl());
         // When the VARBINARY key is the last column, it is allowed.