Repository: phoenix
Updated Branches:
  refs/heads/4.0 7701ae2ce -> e9094d0a4


PHOENIX-1305 create index throws NPE when dataTable has specified default 
column family (daniel meng)


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

Branch: refs/heads/4.0
Commit: e9094d0a4cee18161197cffa57d2c9868c23b0a4
Parents: 7701ae2
Author: Jesse Yates <jya...@apache.org>
Authored: Mon Oct 6 11:42:13 2014 -0700
Committer: Jesse Yates <jya...@apache.org>
Committed: Mon Oct 6 11:42:13 2014 -0700

----------------------------------------------------------------------
 .../phoenix/end2end/index/MutableIndexIT.java   | 50 ++++++++++++++++++++
 .../phoenix/parse/CreateIndexStatement.java     |  3 +-
 2 files changed, 52 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/e9094d0a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
index b093acb..8c9256d 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
@@ -34,10 +34,16 @@ import java.util.Map;
 import java.util.Properties;
 
 import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.phoenix.compile.ColumnResolver;
+import org.apache.phoenix.compile.FromCompiler;
 import org.apache.phoenix.end2end.BaseHBaseManagedTimeIT;
 import org.apache.phoenix.end2end.HBaseManagedTimeTest;
 import org.apache.phoenix.end2end.Shadower;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.parse.NamedTableNode;
+import org.apache.phoenix.parse.TableName;
 import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
@@ -63,6 +69,50 @@ public class MutableIndexIT extends BaseMutableIndexIT {
         props.put(QueryServices.DROP_METADATA_ATTRIB, Boolean.toString(true));
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
+    
+    @Test
+    public void testIndexCreateWithoutOptions()  throws Exception {
+        createIndexOnTableWithSpecifiedDefaultCF(false);
+    }
+    
+    @Test
+    public void testIndexCreateWithOptions()  throws Exception {
+        createIndexOnTableWithSpecifiedDefaultCF(true);
+    }
+    
+    private void createIndexOnTableWithSpecifiedDefaultCF(boolean hasOptions) 
throws Exception {
+        String query;
+        ResultSet rs;
+
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        conn.createStatement().execute(
+                "CREATE TABLE " + DATA_TABLE_FULL_NAME + " (k VARCHAR NOT NULL 
PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) DEFAULT_COLUMN_FAMILY='A'");
+        query = "SELECT * FROM " + DATA_TABLE_FULL_NAME;
+        rs = conn.createStatement().executeQuery(query);
+        assertFalse(rs.next());
+
+        String options = hasOptions ? "SALT_BUCKETS=10, MULTI_TENANT=true, 
IMMUTABLE_ROWS=true, DISABLE_WAL=true" : "";
+        conn.createStatement().execute(
+                "CREATE INDEX " + INDEX_TABLE_NAME + " ON " + 
DATA_TABLE_FULL_NAME + " (v1) INCLUDE (v2) " + options);
+        query = "SELECT * FROM " + INDEX_TABLE_FULL_NAME;
+        rs = conn.createStatement().executeQuery(query);
+        assertFalse(rs.next());
+        
+        //check options set correctly on index
+        TableName indexName = TableName.create(SCHEMA_NAME, INDEX_TABLE_NAME);
+        NamedTableNode indexNode = NamedTableNode.create(null, indexName, 
null);
+        ColumnResolver resolver = FromCompiler.getResolver(indexNode, 
conn.unwrap(PhoenixConnection.class));
+        PTable indexTable = resolver.getTables().get(0).getTable();
+        // Can't set IMMUTABLE_ROWS, MULTI_TENANT or 
DEFAULT_COLUMN_FAMILY_NAME on an index
+        assertNull(indexTable.getDefaultFamilyName());
+        assertFalse(indexTable.isMultiTenant());
+        assertFalse(indexTable.isImmutableRows());
+        if(hasOptions) {
+            assertEquals(10, indexTable.getBucketNum().intValue());
+            assertTrue(indexTable.isWALDisabled());
+        }
+    }
 
     @Test
     public void testIndexWithNullableFixedWithCols() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e9094d0a/phoenix-core/src/main/java/org/apache/phoenix/parse/CreateIndexStatement.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/parse/CreateIndexStatement.java 
b/phoenix-core/src/main/java/org/apache/phoenix/parse/CreateIndexStatement.java
index f688ceb..669dc3f 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/parse/CreateIndexStatement.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/parse/CreateIndexStatement.java
@@ -23,6 +23,7 @@ import java.util.List;
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.phoenix.schema.PTable.IndexType;
 
+import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.ListMultimap;
 
 
@@ -43,7 +44,7 @@ public class CreateIndexStatement extends 
SingleTableStatement {
         this.indexConstraint = indexConstraint == null ? 
PrimaryKeyConstraint.EMPTY : indexConstraint;
         this.includeColumns = includeColumns == null ? 
Collections.<ColumnName>emptyList() : includeColumns;
         this.splitNodes = splits == null ? Collections.<ParseNode>emptyList() 
: splits;
-        this.props = props;
+        this.props = props == null ? 
ArrayListMultimap.<String,Pair<String,Object>>create() : props;
         this.ifNotExists = ifNotExists;
         this.indexType = indexType;
     }

Reply via email to