[7/8] phoenix git commit: PHOENIX-1311 HBase namespaces surfaced in phoenix

2016-04-14 Thread ankit
http://git-wip-us.apache.org/repos/asf/phoenix/blob/de9a2c7b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
index 4246229..2d79f36 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
@@ -30,6 +30,8 @@ import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -72,19 +74,38 @@ import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.StringUtil;
 import org.apache.phoenix.util.TestUtil;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 
 import com.google.common.collect.Maps;
 
+@RunWith(Parameterized.class)
 public class LocalIndexIT extends BaseHBaseManagedTimeIT {
 
 private static CountDownLatch latch1 = new CountDownLatch(1);
 private static CountDownLatch latch2 = new CountDownLatch(1);
 private static final int WAIT_TIME_SECONDS = 60;
+private String schemaName="TEST";
+private boolean isNamespaceMapped;
+private String tableName = schemaName + ".T";
+private String indexTableName = schemaName + ".I";
+private String indexName = "I";
+private String indexPhysicalTableName;
+private TableName physicalTableName;
 
+public LocalIndexIT(boolean isNamespaceMapped) {
+this.isNamespaceMapped = isNamespaceMapped;
+this.physicalTableName = 
SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped);
+this.indexPhysicalTableName = Bytes
+
.toString(MetaDataUtil.getLocalIndexPhysicalName(physicalTableName.getName()));
+}
+
 @BeforeClass 
 @Shadower(classBeingShadowed = BaseHBaseManagedTimeIT.class)
 public static void doSetup() throws Exception {
@@ -96,7 +117,10 @@ public class LocalIndexIT extends BaseHBaseManagedTimeIT {
 }
 
 private void createBaseTable(String tableName, Integer saltBuckets, String 
splits) throws SQLException {
-Connection conn = DriverManager.getConnection(getUrl());
+Connection conn = getConnection();
+if (isNamespaceMapped) {
+conn.createStatement().execute("CREATE SCHEMA IF NOT EXISTS " + 
schemaName);
+}
 String ddl = "CREATE TABLE " + tableName + " (t_id VARCHAR NOT 
NULL,\n" +
 "k1 INTEGER NOT NULL,\n" +
 "k2 INTEGER NOT NULL,\n" +
@@ -108,79 +132,94 @@ public class LocalIndexIT extends BaseHBaseManagedTimeIT {
 conn.createStatement().execute(ddl);
 conn.close();
 }
-
+
+@Parameters(name = "isNamespaceMapped = {0}")
+public static Collection data() {
+return Arrays.asList(true, false);
+}
+
 @Test
 public void testLocalIndexRoundTrip() throws Exception {
-createBaseTable(TestUtil.DEFAULT_DATA_TABLE_NAME, null, null);
+createBaseTable(tableName, null, null);
 Connection conn1 = DriverManager.getConnection(getUrl());
-conn1.createStatement().execute("CREATE LOCAL INDEX " + 
TestUtil.DEFAULT_INDEX_TABLE_NAME + " ON " + TestUtil.DEFAULT_DATA_TABLE_NAME + 
"(v1)");
-conn1.createStatement().executeQuery("SELECT * FROM " + 
TestUtil.DEFAULT_DATA_TABLE_FULL_NAME).next();
-PTable localIndex = conn1.unwrap(PhoenixConnection.class).getTable(new 
PTableKey(null,TestUtil.DEFAULT_INDEX_TABLE_NAME));
+conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " 
ON " + tableName + "(v1)");
+conn1.createStatement().executeQuery("SELECT * FROM " + 
tableName).next();
+PTable localIndex = conn1.unwrap(PhoenixConnection.class).getTable(new 
PTableKey(null, indexTableName));
 assertEquals(IndexType.LOCAL, localIndex.getIndexType());
 assertNotNull(localIndex.getViewIndexId());
 }
-
+
 @Test
 public void testLocalIndexCreationWithSplitsShouldFail() throws Exception {
-createBaseTable(TestUtil.DEFAULT_DATA_TABLE_NAME, null, null);
-Connection conn1 = DriverManager.getConnection(getUrl());
-Connection conn2 = DriverManager.getConnection(getUrl());
+createBaseTable(tableName, null, null);
+Connection conn1 = getConnection();
+Connection conn2 = getConnection();
 try {
-

[7/8] phoenix git commit: PHOENIX-1311 HBase namespaces surfaced in phoenix

2016-04-14 Thread ankit
http://git-wip-us.apache.org/repos/asf/phoenix/blob/70f76539/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
index 4246229..2d79f36 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
@@ -30,6 +30,8 @@ import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -72,19 +74,38 @@ import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.StringUtil;
 import org.apache.phoenix.util.TestUtil;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 
 import com.google.common.collect.Maps;
 
+@RunWith(Parameterized.class)
 public class LocalIndexIT extends BaseHBaseManagedTimeIT {
 
 private static CountDownLatch latch1 = new CountDownLatch(1);
 private static CountDownLatch latch2 = new CountDownLatch(1);
 private static final int WAIT_TIME_SECONDS = 60;
+private String schemaName="TEST";
+private boolean isNamespaceMapped;
+private String tableName = schemaName + ".T";
+private String indexTableName = schemaName + ".I";
+private String indexName = "I";
+private String indexPhysicalTableName;
+private TableName physicalTableName;
 
+public LocalIndexIT(boolean isNamespaceMapped) {
+this.isNamespaceMapped = isNamespaceMapped;
+this.physicalTableName = 
SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped);
+this.indexPhysicalTableName = Bytes
+
.toString(MetaDataUtil.getLocalIndexPhysicalName(physicalTableName.getName()));
+}
+
 @BeforeClass 
 @Shadower(classBeingShadowed = BaseHBaseManagedTimeIT.class)
 public static void doSetup() throws Exception {
@@ -96,7 +117,10 @@ public class LocalIndexIT extends BaseHBaseManagedTimeIT {
 }
 
 private void createBaseTable(String tableName, Integer saltBuckets, String 
splits) throws SQLException {
-Connection conn = DriverManager.getConnection(getUrl());
+Connection conn = getConnection();
+if (isNamespaceMapped) {
+conn.createStatement().execute("CREATE SCHEMA IF NOT EXISTS " + 
schemaName);
+}
 String ddl = "CREATE TABLE " + tableName + " (t_id VARCHAR NOT 
NULL,\n" +
 "k1 INTEGER NOT NULL,\n" +
 "k2 INTEGER NOT NULL,\n" +
@@ -108,79 +132,94 @@ public class LocalIndexIT extends BaseHBaseManagedTimeIT {
 conn.createStatement().execute(ddl);
 conn.close();
 }
-
+
+@Parameters(name = "isNamespaceMapped = {0}")
+public static Collection data() {
+return Arrays.asList(true, false);
+}
+
 @Test
 public void testLocalIndexRoundTrip() throws Exception {
-createBaseTable(TestUtil.DEFAULT_DATA_TABLE_NAME, null, null);
+createBaseTable(tableName, null, null);
 Connection conn1 = DriverManager.getConnection(getUrl());
-conn1.createStatement().execute("CREATE LOCAL INDEX " + 
TestUtil.DEFAULT_INDEX_TABLE_NAME + " ON " + TestUtil.DEFAULT_DATA_TABLE_NAME + 
"(v1)");
-conn1.createStatement().executeQuery("SELECT * FROM " + 
TestUtil.DEFAULT_DATA_TABLE_FULL_NAME).next();
-PTable localIndex = conn1.unwrap(PhoenixConnection.class).getTable(new 
PTableKey(null,TestUtil.DEFAULT_INDEX_TABLE_NAME));
+conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " 
ON " + tableName + "(v1)");
+conn1.createStatement().executeQuery("SELECT * FROM " + 
tableName).next();
+PTable localIndex = conn1.unwrap(PhoenixConnection.class).getTable(new 
PTableKey(null, indexTableName));
 assertEquals(IndexType.LOCAL, localIndex.getIndexType());
 assertNotNull(localIndex.getViewIndexId());
 }
-
+
 @Test
 public void testLocalIndexCreationWithSplitsShouldFail() throws Exception {
-createBaseTable(TestUtil.DEFAULT_DATA_TABLE_NAME, null, null);
-Connection conn1 = DriverManager.getConnection(getUrl());
-Connection conn2 = DriverManager.getConnection(getUrl());
+createBaseTable(tableName, null, null);
+Connection conn1 = getConnection();
+Connection conn2 = getConnection();
 try {
-

[7/8] phoenix git commit: PHOENIX-1311 HBase namespaces surfaced in phoenix

2016-04-14 Thread ankit
http://git-wip-us.apache.org/repos/asf/phoenix/blob/7e432be7/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
index 8c804bb..68fcae3 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
@@ -30,6 +30,8 @@ import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -73,19 +75,38 @@ import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.StringUtil;
 import org.apache.phoenix.util.TestUtil;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 
 import com.google.common.collect.Maps;
 
+@RunWith(Parameterized.class)
 public class LocalIndexIT extends BaseHBaseManagedTimeIT {
 
 private static CountDownLatch latch1 = new CountDownLatch(1);
 private static CountDownLatch latch2 = new CountDownLatch(1);
 private static final int WAIT_TIME_SECONDS = 60;
+private String schemaName="TEST";
+private boolean isNamespaceMapped;
+private String tableName = schemaName + ".T";
+private String indexTableName = schemaName + ".I";
+private String indexName = "I";
+private String indexPhysicalTableName;
+private TableName physicalTableName;
 
+public LocalIndexIT(boolean isNamespaceMapped) {
+this.isNamespaceMapped = isNamespaceMapped;
+this.physicalTableName = 
SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped);
+this.indexPhysicalTableName = Bytes
+
.toString(MetaDataUtil.getLocalIndexPhysicalName(physicalTableName.getName()));
+}
+
 @BeforeClass 
 @Shadower(classBeingShadowed = BaseHBaseManagedTimeIT.class)
 public static void doSetup() throws Exception {
@@ -97,7 +118,10 @@ public class LocalIndexIT extends BaseHBaseManagedTimeIT {
 }
 
 private void createBaseTable(String tableName, Integer saltBuckets, String 
splits) throws SQLException {
-Connection conn = DriverManager.getConnection(getUrl());
+Connection conn = getConnection();
+if (isNamespaceMapped) {
+conn.createStatement().execute("CREATE SCHEMA IF NOT EXISTS " + 
schemaName);
+}
 String ddl = "CREATE TABLE " + tableName + " (t_id VARCHAR NOT 
NULL,\n" +
 "k1 INTEGER NOT NULL,\n" +
 "k2 INTEGER NOT NULL,\n" +
@@ -109,79 +133,94 @@ public class LocalIndexIT extends BaseHBaseManagedTimeIT {
 conn.createStatement().execute(ddl);
 conn.close();
 }
-
+
+@Parameters(name = "isNamespaceMapped = {0}")
+public static Collection data() {
+return Arrays.asList(true, false);
+}
+
 @Test
 public void testLocalIndexRoundTrip() throws Exception {
-createBaseTable(TestUtil.DEFAULT_DATA_TABLE_NAME, null, null);
+createBaseTable(tableName, null, null);
 Connection conn1 = DriverManager.getConnection(getUrl());
-conn1.createStatement().execute("CREATE LOCAL INDEX " + 
TestUtil.DEFAULT_INDEX_TABLE_NAME + " ON " + TestUtil.DEFAULT_DATA_TABLE_NAME + 
"(v1)");
-conn1.createStatement().executeQuery("SELECT * FROM " + 
TestUtil.DEFAULT_DATA_TABLE_FULL_NAME).next();
-PTable localIndex = conn1.unwrap(PhoenixConnection.class).getTable(new 
PTableKey(null,TestUtil.DEFAULT_INDEX_TABLE_NAME));
+conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " 
ON " + tableName + "(v1)");
+conn1.createStatement().executeQuery("SELECT * FROM " + 
tableName).next();
+PTable localIndex = conn1.unwrap(PhoenixConnection.class).getTable(new 
PTableKey(null, indexTableName));
 assertEquals(IndexType.LOCAL, localIndex.getIndexType());
 assertNotNull(localIndex.getViewIndexId());
 }
-
+
 @Test
 public void testLocalIndexCreationWithSplitsShouldFail() throws Exception {
-createBaseTable(TestUtil.DEFAULT_DATA_TABLE_NAME, null, null);
-Connection conn1 = DriverManager.getConnection(getUrl());
-Connection conn2 = DriverManager.getConnection(getUrl());
+createBaseTable(tableName, null, null);
+Connection conn1 = getConnection();
+Connection conn2 = getConnection();
 try {
-