You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ma...@apache.org on 2016/09/20 18:05:24 UTC

[01/47] phoenix git commit: PHOENIX-2474 Cannot round to a negative precision (to the left of the decimal) (Kevin Liew)

Repository: phoenix
Updated Branches:
  refs/heads/calcite b8c8a4f50 -> b612f1696


PHOENIX-2474 Cannot round to a negative precision (to the left of the decimal) (Kevin Liew)


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

Branch: refs/heads/calcite
Commit: b7d45ca66729ae57c0896449e36b80f4fdcafb46
Parents: 1ce9845
Author: Samarth <sa...@salesforce.com>
Authored: Thu Sep 1 09:49:22 2016 -0700
Committer: Samarth <sa...@salesforce.com>
Committed: Thu Sep 1 09:49:22 2016 -0700

----------------------------------------------------------------------
 .../expression/function/RoundDecimalExpression.java   |  2 +-
 .../expression/RoundFloorCeilExpressionsTest.java     | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b7d45ca6/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java
index 65ffacb..055535e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java
@@ -100,7 +100,7 @@ public class RoundDecimalExpression extends ScalarFunction {
         if(scaleValue != null) {
             if (scaleType.isCoercibleTo(PInteger.INSTANCE, scaleValue)) {
                 int scale = (Integer) PInteger.INSTANCE.toObject(scaleValue, scaleType);
-                if (scale >=0 && scale <= PDataType.MAX_PRECISION) {
+                if (scale <= PDataType.MAX_PRECISION) {
                     this.scale = scale;
                     return;
                 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b7d45ca6/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java b/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
index 5022e71..89058ba 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
@@ -79,6 +79,20 @@ public class RoundFloorCeilExpressionsTest {
     }
 
     @Test
+    public void testRoundNegativePrecisionDecimalExpression() throws Exception {
+        LiteralExpression decimalLiteral = LiteralExpression.newConstant(444.44, PDecimal.INSTANCE);
+        Expression roundDecimalExpression = RoundDecimalExpression.create(decimalLiteral, -2);
+
+        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+        roundDecimalExpression.evaluate(null, ptr);
+        Object result = roundDecimalExpression.getDataType().toObject(ptr);
+
+        assertTrue(result instanceof BigDecimal);
+        BigDecimal resultDecimal = (BigDecimal)result;
+        assertEquals(0, BigDecimal.valueOf(400).compareTo(resultDecimal));
+    }
+
+    @Test
     public void testRoundDecimalExpressionNoop() throws Exception {
         LiteralExpression decimalLiteral = LiteralExpression.newConstant(5, PInteger.INSTANCE);
         Expression roundDecimalExpression = RoundDecimalExpression.create(decimalLiteral, 3);


[12/47] phoenix git commit: PHOENIX-3081 Consult RegionServer stopped/stopping state before logging error in StatisticsScanner

Posted by ma...@apache.org.
PHOENIX-3081 Consult RegionServer stopped/stopping state before logging error in StatisticsScanner


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

Branch: refs/heads/calcite
Commit: 36d500cb83209cd10ae87c5cce6648aab2866925
Parents: fd6da35
Author: Josh Elser <el...@apache.org>
Authored: Mon Jul 18 16:24:22 2016 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Thu Sep 8 17:27:07 2016 -0400

----------------------------------------------------------------------
 .../phoenix/schema/stats/StatisticsScanner.java |  72 ++++++++--
 .../schema/stats/StatisticsScannerTest.java     | 144 +++++++++++++++++++
 2 files changed, 202 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/36d500cb/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsScanner.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsScanner.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsScanner.java
index 082e833..736efc6 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsScanner.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsScanner.java
@@ -35,6 +35,7 @@ import org.apache.hadoop.hbase.client.Mutation;
 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
 import org.apache.hadoop.hbase.regionserver.InternalScanner;
 import org.apache.hadoop.hbase.regionserver.Region;
+import org.apache.hadoop.hbase.regionserver.RegionServerServices;
 import org.apache.hadoop.hbase.regionserver.ScannerContext;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
 
@@ -49,12 +50,14 @@ public class StatisticsScanner implements InternalScanner {
     private StatisticsCollector tracker;
     private ImmutableBytesPtr family;
     private final Configuration config;
+    private final RegionServerServices regionServerServices;
 
     public StatisticsScanner(StatisticsCollector tracker, StatisticsWriter stats, RegionCoprocessorEnvironment env,
             InternalScanner delegate, ImmutableBytesPtr family) {
         this.tracker = tracker;
         this.statsWriter = stats;
         this.delegate = delegate;
+        this.regionServerServices = env.getRegionServerServices();
         this.region = env.getRegion();
         this.family = family;
         this.config = env.getConfiguration();
@@ -89,9 +92,13 @@ public class StatisticsScanner implements InternalScanner {
 
     @Override
     public void close() throws IOException {
-        boolean async = config.getBoolean(COMMIT_STATS_ASYNC, DEFAULT_COMMIT_STATS_ASYNC);
-        StatisticsCollectionRunTracker collectionTracker = StatisticsCollectionRunTracker.getInstance(config);
-        StatisticsScannerCallable callable = new StatisticsScannerCallable();
+        boolean async = getConfig().getBoolean(COMMIT_STATS_ASYNC, DEFAULT_COMMIT_STATS_ASYNC);
+        StatisticsCollectionRunTracker collectionTracker = getStatsCollectionRunTracker(config);
+        StatisticsScannerCallable callable = createCallable();
+        if (getRegionServerServices().isStopping() || getRegionServerServices().isStopped()) {
+            LOG.debug("Not updating table statistics because the server is stopping/stopped");
+            return;
+        }
         if (!async) {
             callable.call();
         } else {
@@ -99,12 +106,45 @@ public class StatisticsScanner implements InternalScanner {
         }
     }
 
-    private class StatisticsScannerCallable implements Callable<Void> {
+    // VisibleForTesting
+    StatisticsCollectionRunTracker getStatsCollectionRunTracker(Configuration c) {
+        return StatisticsCollectionRunTracker.getInstance(c);
+    }
+
+    Configuration getConfig() {
+        return config;
+    }
+
+    StatisticsWriter getStatisticsWriter() {
+        return statsWriter;
+    }
+
+    RegionServerServices getRegionServerServices() {
+        return regionServerServices;
+    }
+
+    Region getRegion() {
+        return region;
+    }
+
+    StatisticsScannerCallable createCallable() {
+        return new StatisticsScannerCallable();
+    }
+
+    StatisticsCollector getTracker() {
+        return tracker;
+    }
+
+    InternalScanner getDelegate() {
+        return delegate;
+    }
+
+    class StatisticsScannerCallable implements Callable<Void> {
         @Override
         public Void call() throws IOException {
             IOException toThrow = null;
-            StatisticsCollectionRunTracker collectionTracker = StatisticsCollectionRunTracker.getInstance(config);
-            final HRegionInfo regionInfo = region.getRegionInfo();
+            StatisticsCollectionRunTracker collectionTracker = getStatsCollectionRunTracker(config);
+            final HRegionInfo regionInfo = getRegion().getRegionInfo();
             try {
                 // update the statistics table
                 // Just verify if this if fine
@@ -114,32 +154,36 @@ public class StatisticsScanner implements InternalScanner {
                     LOG.debug("Deleting the stats for the region " + regionInfo.getRegionNameAsString()
                             + " as part of major compaction");
                 }
-                statsWriter.deleteStats(region, tracker, family, mutations);
+                getStatisticsWriter().deleteStats(region, tracker, family, mutations);
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("Adding new stats for the region " + regionInfo.getRegionNameAsString()
                             + " as part of major compaction");
                 }
-                statsWriter.addStats(tracker, family, mutations);
+                getStatisticsWriter().addStats(tracker, family, mutations);
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("Committing new stats for the region " + regionInfo.getRegionNameAsString()
                             + " as part of major compaction");
                 }
-                statsWriter.commitStats(mutations, tracker);
+                getStatisticsWriter().commitStats(mutations, tracker);
             } catch (IOException e) {
-                LOG.error("Failed to update statistics table!", e);
-                toThrow = e;
+                if (getRegionServerServices().isStopping() || getRegionServerServices().isStopped()) {
+                    LOG.debug("Ignoring error updating statistics because region is closing/closed");
+                } else {
+                    LOG.error("Failed to update statistics table!", e);
+                    toThrow = e;
+                }
             } finally {
                 try {
                     collectionTracker.removeCompactingRegion(regionInfo);
-                    statsWriter.close();// close the writer
-                    tracker.close();// close the tracker
+                    getStatisticsWriter().close();// close the writer
+                    getTracker().close();// close the tracker
                 } catch (IOException e) {
                     if (toThrow == null) toThrow = e;
                     LOG.error("Error while closing the stats table", e);
                 } finally {
                     // close the delegate scanner
                     try {
-                        delegate.close();
+                        getDelegate().close();
                     } catch (IOException e) {
                         if (toThrow == null) toThrow = e;
                         LOG.error("Error while closing the scanner", e);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/36d500cb/phoenix-core/src/test/java/org/apache/phoenix/schema/stats/StatisticsScannerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/schema/stats/StatisticsScannerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/schema/stats/StatisticsScannerTest.java
new file mode 100644
index 0000000..888f09a
--- /dev/null
+++ b/phoenix-core/src/test/java/org/apache/phoenix/schema/stats/StatisticsScannerTest.java
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.schema.stats;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.regionserver.InternalScanner;
+import org.apache.hadoop.hbase.regionserver.Region;
+import org.apache.hadoop.hbase.regionserver.RegionServerServices;
+import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+import org.apache.phoenix.schema.stats.StatisticsScanner.StatisticsScannerCallable;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test to verify that we don't try to update stats when a RS is stopping.
+ */
+public class StatisticsScannerTest {
+
+    private Region region;
+    private RegionServerServices rsServices;
+    private StatisticsWriter statsWriter;
+    private StatisticsScannerCallable callable;
+    private StatisticsCollectionRunTracker runTracker;
+    private StatisticsScanner mockScanner;
+    private StatisticsCollector tracker;
+    private InternalScanner delegate;
+    private HRegionInfo regionInfo;
+
+    private Configuration config;
+
+    @Before
+    public void setupMocks() throws Exception {
+        this.config = new Configuration(false);
+
+        // Create all of the mocks
+        this.region = mock(Region.class);
+        this.rsServices = mock(RegionServerServices.class);
+        this.statsWriter = mock(StatisticsWriter.class);
+        this.callable = mock(StatisticsScannerCallable.class);
+        this.runTracker = mock(StatisticsCollectionRunTracker.class);
+        this.mockScanner = mock(StatisticsScanner.class);
+        this.tracker = mock(StatisticsCollector.class);
+        this.delegate = mock(InternalScanner.class);
+        this.regionInfo = mock(HRegionInfo.class);
+
+        // Wire up the mocks to the mock StatisticsScanner
+        when(mockScanner.getStatisticsWriter()).thenReturn(statsWriter);
+        when(mockScanner.getRegionServerServices()).thenReturn(rsServices);
+        when(mockScanner.createCallable()).thenReturn(callable);
+        when(mockScanner.getStatsCollectionRunTracker(any(Configuration.class))).thenReturn(runTracker);
+        when(mockScanner.getRegion()).thenReturn(region);
+        when(mockScanner.getConfig()).thenReturn(config);
+        when(mockScanner.getTracker()).thenReturn(tracker);
+        when(mockScanner.getDelegate()).thenReturn(delegate);
+
+        // Wire up the HRegionInfo mock to the Region mock
+        when(region.getRegionInfo()).thenReturn(regionInfo);
+
+        // Always call close() on the mock StatisticsScanner
+        doCallRealMethod().when(mockScanner).close();
+    }
+
+    @Test
+    public void testCheckRegionServerStoppingOnClose() throws Exception {
+        when(rsServices.isStopping()).thenReturn(true);
+        when(rsServices.isStopped()).thenReturn(false);
+
+        mockScanner.close();
+
+        verify(rsServices).isStopping();
+        verify(callable, never()).call();
+        verify(runTracker, never()).runTask(callable);
+    }
+
+    @Test
+    public void testCheckRegionServerStoppedOnClose() throws Exception {
+        when(rsServices.isStopping()).thenReturn(false);
+        when(rsServices.isStopped()).thenReturn(true);
+
+        mockScanner.close();
+
+        verify(rsServices).isStopping();
+        verify(rsServices).isStopped();
+        verify(callable, never()).call();
+        verify(runTracker, never()).runTask(callable);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testCheckRegionServerStoppingOnException() throws Exception {
+        StatisticsScannerCallable realCallable = mockScanner.new StatisticsScannerCallable();
+        doThrow(new IOException()).when(statsWriter).deleteStats(any(Region.class), any(StatisticsCollector.class),
+                any(ImmutableBytesPtr.class), any(List.class));
+        when(rsServices.isStopping()).thenReturn(true);
+        when(rsServices.isStopped()).thenReturn(false);
+
+        // Should not throw an exception
+        realCallable.call();
+
+        verify(rsServices).isStopping();
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testCheckRegionServerStoppedOnException() throws Exception {
+        StatisticsScannerCallable realCallable = mockScanner.new StatisticsScannerCallable();
+        doThrow(new IOException()).when(statsWriter).deleteStats(any(Region.class), any(StatisticsCollector.class),
+                any(ImmutableBytesPtr.class), any(List.class));
+        when(rsServices.isStopping()).thenReturn(false);
+        when(rsServices.isStopped()).thenReturn(true);
+
+        // Should not throw an exception
+        realCallable.call();
+
+        verify(rsServices).isStopping();
+        verify(rsServices).isStopped();
+    }
+}


[45/47] phoenix git commit: PHOENIX-3302 Use unique names for views and indexes in GlobalIndexOptimizationIT

Posted by ma...@apache.org.
PHOENIX-3302 Use unique names for views and indexes in GlobalIndexOptimizationIT


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

Branch: refs/heads/calcite
Commit: 0a05d67f1785bba2ca333f281b4d7650a05c6ee0
Parents: e90feaa
Author: Samarth <sa...@salesforce.com>
Authored: Mon Sep 19 19:49:15 2016 -0700
Committer: Samarth <sa...@salesforce.com>
Committed: Mon Sep 19 19:49:15 2016 -0700

----------------------------------------------------------------------
 .../end2end/index/GlobalIndexOptimizationIT.java     | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/0a05d67f/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java
index b84cf5d..af2ddaa 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java
@@ -333,21 +333,24 @@ public class GlobalIndexOptimizationIT extends ParallelStatsDisabledIT {
         String dataTableName = generateRandomString();
         createBaseTable(dataTableName, null, "('e','i','o')", false);
         Connection conn1 = DriverManager.getConnection(getUrl());
+        String viewName = generateRandomString();
+        String indexOnDataTable = generateRandomString();
         try{
-            conn1.createStatement().execute("CREATE INDEX i1 ON " + dataTableName + "(k2,k1) INCLUDE (v1)");
-            conn1.createStatement().execute("CREATE VIEW v AS SELECT * FROM " + dataTableName + " WHERE v1 = 'a'");
+            conn1.createStatement().execute("CREATE INDEX " + indexOnDataTable + " ON " + dataTableName + "(k2,k1) INCLUDE (v1)");
+            conn1.createStatement().execute("CREATE VIEW " + viewName  + " AS SELECT * FROM " + dataTableName + " WHERE v1 = 'a'");
             conn1.createStatement().execute("UPSERT INTO " + dataTableName + " values('b',1,2,4,'z')");
             conn1.createStatement().execute("UPSERT INTO " + dataTableName + " values('f',1,2,3,'a')");
             conn1.createStatement().execute("UPSERT INTO " + dataTableName + " values('j',2,4,2,'a')");
             conn1.createStatement().execute("UPSERT INTO " + dataTableName + " values('q',3,1,1,'c')");
             conn1.commit();
-            ResultSet rs = conn1.createStatement().executeQuery("SELECT COUNT(*) FROM v");
+            ResultSet rs = conn1.createStatement().executeQuery("SELECT COUNT(*) FROM " + viewName);
             assertTrue(rs.next());
             assertEquals(2, rs.getInt(1));
             assertFalse(rs.next());
-            conn1.createStatement().execute("CREATE INDEX vi1 ON v(k1)");
+            String viewIndex = generateRandomString();
+            conn1.createStatement().execute("CREATE INDEX " + viewIndex + " ON " + viewName + " (k1)");
             
-            String query = "SELECT /*+ INDEX(v vi1)*/ t_id,k1,k2,k3,v1 FROM v where k1 IN (1,2) and k2 IN (3,4)";
+            String query = "SELECT /*+ INDEX(" + viewName + " " + viewIndex + ")*/ t_id,k1,k2,k3,v1 FROM " + viewName + " where k1 IN (1,2) and k2 IN (3,4)";
             rs = conn1.createStatement().executeQuery("EXPLAIN "+ query);
             
             String actual = QueryUtil.getExplainPlan(rs);
@@ -357,7 +360,7 @@ public class GlobalIndexOptimizationIT extends ParallelStatsDisabledIT {
                     "    SKIP-SCAN-JOIN TABLE 0\n" +
                     "        CLIENT PARALLEL 1-WAY SKIP SCAN ON 2 KEYS OVER _IDX_" + dataTableName + " \\[-32768,1\\] - \\[-32768,2\\]\n" +
                     "            SERVER FILTER BY FIRST KEY ONLY AND \"K2\" IN \\(3,4\\)\n" +
-                    "    DYNAMIC SERVER FILTER BY \\(\"V.T_ID\", \"V.K1\", \"V.K2\"\\) IN \\(\\(\\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+\\)\\)";
+                    "    DYNAMIC SERVER FILTER BY \\(\"" + viewName + ".T_ID\", \"" + viewName + ".K1\", \"" + viewName + ".K2\"\\) IN \\(\\(\\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+\\)\\)";
             assertTrue("Expected:\n" + expected + "\ndid not match\n" + actual, Pattern.matches(expected,actual));
             
             rs = conn1.createStatement().executeQuery(query);


[07/47] phoenix git commit: PHOENIX-2785 Do not store NULLs for immutable tables.

Posted by ma...@apache.org.
PHOENIX-2785 Do not store NULLs for immutable tables.


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

Branch: refs/heads/calcite
Commit: 3a8724eee05aaf477bf6085415e781856990e1c0
Parents: b65e385
Author: Lars Hofhansl <la...@apache.org>
Authored: Wed Sep 7 14:03:56 2016 -0700
Committer: Lars Hofhansl <la...@apache.org>
Committed: Wed Sep 7 14:11:03 2016 -0700

----------------------------------------------------------------------
 .../apache/phoenix/end2end/StoreNullsIT.java    | 40 +++++++++++++++++++-
 .../org/apache/phoenix/schema/PTableImpl.java   | 13 ++++---
 2 files changed, 47 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/3a8724ee/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
index cbce02e..836418c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
@@ -34,7 +34,6 @@ import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.SchemaUtil;
 import org.junit.After;
-import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -63,6 +62,8 @@ public class StoreNullsIT extends BaseHBaseManagedTimeTableReuseIT {
     private static final Log LOG = LogFactory.getLog(StoreNullsIT.class);
     private static final String WITH_NULLS = generateRandomString();
     private static final String WITHOUT_NULLS = generateRandomString();
+    private static final String IMMUTABLE_WITH_NULLS = generateRandomString();
+    private static final String IMMUTABLE_WITHOUT_NULLS = generateRandomString();
 
     private static Connection conn;
     private static Statement stmt;
@@ -81,6 +82,12 @@ public class StoreNullsIT extends BaseHBaseManagedTimeTableReuseIT {
                         "id SMALLINT NOT NULL PRIMARY KEY, " +
                         "name VARCHAR) " +
                 "VERSIONS = 1000, KEEP_DELETED_CELLS = false");
+        stmt.execute("CREATE TABLE " + IMMUTABLE_WITH_NULLS + " ("
+                + "id SMALLINT NOT NULL PRIMARY KEY, name VARCHAR) "
+                + "STORE_NULLS = true, VERSIONS = 1, KEEP_DELETED_CELLS = false, IMMUTABLE_ROWS=true");
+        stmt.execute("CREATE TABLE " + IMMUTABLE_WITHOUT_NULLS + " ("
+                + "id SMALLINT NOT NULL PRIMARY KEY, name VARCHAR) "
+                + "VERSIONS = 1, KEEP_DELETED_CELLS = false, IMMUTABLE_ROWS=true");
     }
 
     @After
@@ -90,6 +97,37 @@ public class StoreNullsIT extends BaseHBaseManagedTimeTableReuseIT {
     }
 
     @Test
+    public void testStoringNulls() throws SQLException, InterruptedException, IOException {
+        stmt.executeUpdate("UPSERT INTO " + IMMUTABLE_WITH_NULLS + " VALUES (1, 'v1')");
+        stmt.executeUpdate("UPSERT INTO " + IMMUTABLE_WITHOUT_NULLS + " VALUES (1, 'v1')");
+        stmt.executeUpdate("UPSERT INTO " + IMMUTABLE_WITH_NULLS + " VALUES (2, null)");
+        stmt.executeUpdate("UPSERT INTO " + IMMUTABLE_WITHOUT_NULLS + " VALUES (2, null)");
+
+        ensureNullsNotStored(IMMUTABLE_WITH_NULLS);
+        ensureNullsNotStored(IMMUTABLE_WITHOUT_NULLS);
+    }
+
+    private void ensureNullsNotStored(String tableName) throws IOException {
+        tableName = SchemaUtil.normalizeIdentifier(tableName);
+        HTable htable = new HTable(getUtility().getConfiguration(), tableName);
+        Scan s = new Scan();
+        s.setRaw(true);
+        ResultScanner scanner = htable.getScanner(s);
+        // first row has a value for name
+        Result rs = scanner.next();
+        assertTrue(rs.containsColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, Bytes.toBytes("NAME")));
+        assertTrue(rs.size() == 2);
+        // 2nd row has not
+        rs = scanner.next();
+        assertFalse(rs.containsColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, Bytes.toBytes("NAME")));
+        // and no delete marker either
+        assertTrue(rs.size() == 1);
+        assertNull(scanner.next());
+        scanner.close();
+        htable.close();
+    }
+
+    @Test
     public void testQueryingHistory() throws SQLException, InterruptedException, IOException {
         stmt.executeUpdate("UPSERT INTO " + WITH_NULLS + " VALUES (1, 'v1')");
         stmt.executeUpdate("UPSERT INTO " + WITHOUT_NULLS + " VALUES (1, 'v1')");

http://git-wip-us.apache.org/repos/asf/phoenix/blob/3a8724ee/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 c485a30..b9cec02 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
@@ -782,6 +782,7 @@ public class PTableImpl implements PTable {
                     if (Bytes.compareTo(kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength(),
                           qualifier, 0, qualifier.length) == 0) {
                         iterator.remove();
+                        break;
                     }
                 }
             }
@@ -798,13 +799,15 @@ public class PTableImpl implements PTable {
             deleteRow = null;
             byte[] family = column.getFamilyName().getBytes();
             byte[] qualifier = column.getName().getBytes();
-            PDataType type = column.getDataType();
+            PDataType<?> type = column.getDataType();
             // Check null, since some types have no byte representation for null
             boolean isNull = type.isNull(byteValue);
-            if (isNull && !getStoreNulls()) {
-                if (!column.isNullable()) {
-                    throw new ConstraintViolationException(name.getString() + "." + column.getName().getString() + " may not be null");
-                }
+            if (isNull && !column.isNullable()) {
+                throw new ConstraintViolationException(name.getString() + "." + column.getName().getString() + " may not be null");
+            } else if (isNull && PTableImpl.this.isImmutableRows()) {
+                removeIfPresent(setValues, family, qualifier);
+                removeIfPresent(unsetValues, family, qualifier);
+            } else if (isNull && !getStoreNulls()) {
                 removeIfPresent(setValues, family, qualifier);
                 deleteQuietly(unsetValues, kvBuilder, kvBuilder.buildDeleteColumns(keyPtr, column
                             .getFamilyName().getBytesPtr(), column.getName().getBytesPtr(), ts));


[46/47] phoenix git commit: PHOENIX-3279 QueryPlan.iterator(ParallelScanGrouper scanGrouper) should pass null ('unknown') as scan parameter when calling this.iterator(ParallelScanGrouper scanGrouper, Scan scan)

Posted by ma...@apache.org.
PHOENIX-3279 QueryPlan.iterator(ParallelScanGrouper scanGrouper) should pass null ('unknown') as scan parameter when calling this.iterator(ParallelScanGrouper scanGrouper, Scan scan)


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

Branch: refs/heads/calcite
Commit: 7601d5942fdeb55c114295292e2100aafb84e861
Parents: 0a05d67
Author: maryannxue <ma...@gmail.com>
Authored: Tue Sep 20 09:19:06 2016 -0700
Committer: maryannxue <ma...@gmail.com>
Committed: Tue Sep 20 09:19:06 2016 -0700

----------------------------------------------------------------------
 .../apache/phoenix/end2end/DerivedTableIT.java  | 11 ++++++++++
 .../apache/phoenix/execute/BaseQueryPlan.java   | 16 +++++++++------
 .../phoenix/execute/ClientAggregatePlan.java    |  7 +------
 .../phoenix/execute/ClientProcessingPlan.java   |  9 ---------
 .../apache/phoenix/execute/ClientScanPlan.java  |  4 ----
 .../apache/phoenix/execute/CorrelatePlan.java   | 15 ++------------
 .../phoenix/execute/DelegateQueryPlan.java      | 13 ++++++++++++
 .../apache/phoenix/execute/HashJoinPlan.java    | 15 ++++----------
 .../phoenix/execute/TupleProjectionPlan.java    | 11 ----------
 .../org/apache/phoenix/execute/UnionPlan.java   | 21 ++++++++------------
 .../apache/phoenix/execute/UnnestArrayPlan.java | 11 ----------
 .../phoenix/iterate/UnionResultIterators.java   |  4 +---
 12 files changed, 50 insertions(+), 87 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/7601d594/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
index 862416b..67be132 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
@@ -225,6 +225,17 @@ public class DerivedTableIT extends BaseClientManagedTimeIT {
             assertEquals(ROW2,rs.getString(1));
 
             assertFalse(rs.next());
+            
+            // ((where limit) where limit) limit
+            query = "SELECT u.eid FROM (SELECT t.eid FROM (SELECT entity_id eid, b_string b FROM aTable WHERE a_string = '" + B_VALUE + "' LIMIT 5) AS t WHERE t.b = '" + C_VALUE + "' LIMIT 4) AS u WHERE u.eid >= '" + ROW1 + "' LIMIT 3";
+            statement = conn.prepareStatement(query);
+            rs = statement.executeQuery();
+            assertTrue (rs.next());
+            assertEquals(ROW5,rs.getString(1));
+            assertTrue (rs.next());
+            assertEquals(ROW8,rs.getString(1));
+
+            assertFalse(rs.next());
 
             // (count) where
             query = "SELECT t.c FROM (SELECT count(*) c FROM aTable) AS t WHERE t.c > 0";

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7601d594/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
index 1e09079..76dec2f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
@@ -200,10 +200,15 @@ public abstract class BaseQueryPlan implements QueryPlan {
 //        byte[] producer = Bytes.toBytes(UUID.randomUUID().toString());
 //        scan.setAttribute(HBaseServer.CALL_QUEUE_PRODUCER_ATTRIB_NAME, producer);
 //    }
+
+    @Override
+    public final ResultIterator iterator() throws SQLException {
+        return iterator(Collections.<SQLCloseable>emptyList(), DefaultParallelScanGrouper.getInstance(), null);
+    }
     
     @Override
     public final ResultIterator iterator(ParallelScanGrouper scanGrouper) throws SQLException {
-        return iterator(Collections.<SQLCloseable>emptyList(), scanGrouper, this.context.getScan());
+        return iterator(Collections.<SQLCloseable>emptyList(), scanGrouper, null);
     }
 
     @Override
@@ -211,12 +216,11 @@ public abstract class BaseQueryPlan implements QueryPlan {
         return iterator(Collections.<SQLCloseable>emptyList(), scanGrouper, scan);
     }
 
-    @Override
-    public final ResultIterator iterator() throws SQLException {
-        return iterator(Collections.<SQLCloseable>emptyList(), DefaultParallelScanGrouper.getInstance(), this.context.getScan());
-    }
-
     public final ResultIterator iterator(final List<? extends SQLCloseable> dependencies, ParallelScanGrouper scanGrouper, Scan scan) throws SQLException {
+         if (scan == null) {
+             scan = context.getScan();
+         }
+         
 		/*
 		 * For aggregate queries, we still need to let the AggregationPlan to
 		 * proceed so that we can give proper aggregates even if there are no

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7601d594/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
index eb048f4..9251724 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
@@ -83,13 +83,8 @@ public class ClientAggregatePlan extends ClientProcessingPlan {
     }
 
     @Override
-    public ResultIterator iterator(ParallelScanGrouper scanGrouper) throws SQLException {
-        return iterator(scanGrouper, null);
-    }
-
-    @Override
     public ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan) throws SQLException {
-        ResultIterator iterator = delegate.iterator(scanGrouper);
+        ResultIterator iterator = delegate.iterator(scanGrouper, scan);
         if (where != null) {
             iterator = new FilterResultIterator(iterator, where);
         }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7601d594/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
index 2cd5237..ac43919 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
@@ -17,15 +17,11 @@
  */
 package org.apache.phoenix.execute;
 
-import java.sql.SQLException;
-
 import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.compile.RowProjector;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.compile.OrderByCompiler.OrderBy;
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.iterate.DefaultParallelScanGrouper;
-import org.apache.phoenix.iterate.ResultIterator;
 import org.apache.phoenix.parse.FilterableStatement;
 import org.apache.phoenix.schema.TableRef;
 
@@ -89,9 +85,4 @@ public abstract class ClientProcessingPlan extends DelegateQueryPlan {
     public FilterableStatement getStatement() {
         return statement;
     }
-    
-    @Override
-    public ResultIterator iterator() throws SQLException {
-        return iterator(DefaultParallelScanGrouper.getInstance());
-    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7601d594/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java
index 4e43225..6bbc545 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java
@@ -50,10 +50,6 @@ public class ClientScanPlan extends ClientProcessingPlan {
     }
 
     @Override
-    public ResultIterator iterator(ParallelScanGrouper scanGrouper) throws SQLException {
-        return iterator(scanGrouper, delegate.getContext().getScan());
-    }
-    @Override
     public ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan) throws SQLException {
         ResultIterator iterator = delegate.iterator(scanGrouper, scan);
         if (where != null) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7601d594/phoenix-core/src/main/java/org/apache/phoenix/execute/CorrelatePlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/CorrelatePlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/CorrelatePlan.java
index fc5a04d..b1d00ab 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/CorrelatePlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/CorrelatePlan.java
@@ -28,7 +28,6 @@ import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.execute.TupleProjector.ProjectedValueTuple;
-import org.apache.phoenix.iterate.DefaultParallelScanGrouper;
 import org.apache.phoenix.iterate.ParallelScanGrouper;
 import org.apache.phoenix.iterate.ResultIterator;
 import org.apache.phoenix.parse.JoinTableNode.JoinType;
@@ -99,17 +98,7 @@ public class CorrelatePlan extends DelegateQueryPlan {
     }
 
     @Override
-    public ResultIterator iterator() throws SQLException {
-        return iterator(DefaultParallelScanGrouper.getInstance());
-    }
-
-    @Override
-    public ResultIterator iterator(ParallelScanGrouper scanGrouper) 
-                throws SQLException {
-        return iterator(scanGrouper, null);
-    }
-    @Override
-    public ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan)
+    public ResultIterator iterator(final ParallelScanGrouper scanGrouper, final Scan scan)
             throws SQLException {
         return new ResultIterator() {
             private final ValueBitSet destBitSet = ValueBitSet.newInstance(joinedSchema);
@@ -118,7 +107,7 @@ public class CorrelatePlan extends DelegateQueryPlan {
                     (joinType == JoinType.Semi || joinType == JoinType.Anti) ?
                             ValueBitSet.EMPTY_VALUE_BITSET 
                           : ValueBitSet.newInstance(rhsSchema);
-            private final ResultIterator iter = delegate.iterator();
+            private final ResultIterator iter = delegate.iterator(scanGrouper, scan);
             private ResultIterator rhsIter = null;
             private Tuple current = null;
             private boolean closed = false;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7601d594/phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateQueryPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateQueryPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateQueryPlan.java
index 8f0d224..46eec91 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateQueryPlan.java
@@ -25,6 +25,9 @@ import java.util.Set;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.phoenix.compile.GroupByCompiler.GroupBy;
 import org.apache.phoenix.compile.OrderByCompiler.OrderBy;
+import org.apache.phoenix.iterate.DefaultParallelScanGrouper;
+import org.apache.phoenix.iterate.ParallelScanGrouper;
+import org.apache.phoenix.iterate.ResultIterator;
 import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.compile.RowProjector;
 import org.apache.phoenix.compile.StatementContext;
@@ -124,4 +127,14 @@ public abstract class DelegateQueryPlan implements QueryPlan {
     public Integer getOffset() {
         return delegate.getOffset();
     }
+     
+     @Override
+     public ResultIterator iterator() throws SQLException {
+         return iterator(DefaultParallelScanGrouper.getInstance());
+     }
+ 
+     @Override
+     public ResultIterator iterator(ParallelScanGrouper scanGrouper) throws SQLException {
+         return iterator(scanGrouper, null);
+     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7601d594/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java
index d332f68..dce797d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java
@@ -50,7 +50,6 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.InListExpression;
 import org.apache.phoenix.expression.LiteralExpression;
 import org.apache.phoenix.expression.RowValueConstructorExpression;
-import org.apache.phoenix.iterate.DefaultParallelScanGrouper;
 import org.apache.phoenix.iterate.FilterResultIterator;
 import org.apache.phoenix.iterate.ParallelScanGrouper;
 import org.apache.phoenix.iterate.ResultIterator;
@@ -132,19 +131,13 @@ public class HashJoinPlan extends DelegateQueryPlan {
     public Set<TableRef> getSourceRefs() {
         return tableRefs;
     }
-    
-    @Override
-    public ResultIterator iterator() throws SQLException {
-    	return iterator(DefaultParallelScanGrouper.getInstance());
-    }
-
-    @Override
-    public ResultIterator iterator(ParallelScanGrouper scanGrouper) throws SQLException {
-        return iterator(scanGrouper, this.delegate.getContext().getScan());
-    }
         
     @Override
     public ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan) throws SQLException {
+        if (scan == null) {
+            scan = delegate.getContext().getScan();
+        }
+        
         int count = subPlans.length;
         PhoenixConnection connection = getContext().getConnection();
         ConnectionQueryServices services = connection.getQueryServices();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7601d594/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjectionPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjectionPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjectionPlan.java
index 0ba0cc1..f42af56 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjectionPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjectionPlan.java
@@ -24,7 +24,6 @@ import org.apache.hadoop.hbase.client.Scan;
 import org.apache.phoenix.compile.ExplainPlan;
 import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.iterate.DefaultParallelScanGrouper;
 import org.apache.phoenix.iterate.DelegateResultIterator;
 import org.apache.phoenix.iterate.FilterResultIterator;
 import org.apache.phoenix.iterate.ParallelScanGrouper;
@@ -53,16 +52,6 @@ public class TupleProjectionPlan extends DelegateQueryPlan {
 
         return new ExplainPlan(planSteps);
     }
-    
-    @Override
-    public ResultIterator iterator() throws SQLException {
-    	return iterator(DefaultParallelScanGrouper.getInstance());
-    }
-
-    @Override
-    public ResultIterator iterator(ParallelScanGrouper scanGrouper) throws SQLException {
-        return iterator(scanGrouper, delegate.getContext().getScan());
-    }
 
     @Override
     public ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan) throws SQLException {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7601d594/phoenix-core/src/main/java/org/apache/phoenix/execute/UnionPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/UnionPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/UnionPlan.java
index cf95b5b..e2c18b1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/UnionPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/UnionPlan.java
@@ -20,7 +20,6 @@ package org.apache.phoenix.execute;
 import java.sql.ParameterMetaData;
 import java.sql.SQLException;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
@@ -33,6 +32,7 @@ import org.apache.phoenix.compile.RowProjector;
 import org.apache.phoenix.compile.ScanRanges;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.iterate.ConcatResultIterator;
+import org.apache.phoenix.iterate.DefaultParallelScanGrouper;
 import org.apache.phoenix.iterate.LimitingResultIterator;
 import org.apache.phoenix.iterate.MergeSortTopNResultIterator;
 import org.apache.phoenix.iterate.OffsetResultIterator;
@@ -43,8 +43,6 @@ import org.apache.phoenix.jdbc.PhoenixStatement.Operation;
 import org.apache.phoenix.parse.FilterableStatement;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.schema.TableRef;
-import org.apache.phoenix.util.SQLCloseable;
-
 import com.google.common.collect.Sets;
 
 
@@ -134,22 +132,19 @@ public class UnionPlan implements QueryPlan {
     public RowProjector getProjector() {
         return projector;
     }
-
+    
     @Override
-    public final ResultIterator iterator(ParallelScanGrouper scanGrouper) throws SQLException {
-        return iterator(Collections.<SQLCloseable>emptyList());
+    public ResultIterator iterator() throws SQLException {
+        return iterator(DefaultParallelScanGrouper.getInstance());
     }
 
     @Override
-    public final ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan) throws SQLException {
-        return iterator(Collections.<SQLCloseable>emptyList());
-    }
-    @Override
-    public final ResultIterator iterator() throws SQLException {
-        return iterator(Collections.<SQLCloseable>emptyList());
+    public ResultIterator iterator(ParallelScanGrouper scanGrouper) throws SQLException {
+        return iterator(scanGrouper, null);
     }
 
-    public final ResultIterator iterator(final List<? extends SQLCloseable> dependencies) throws SQLException {
+    @Override
+    public final ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan) throws SQLException {
         this.iterators = new UnionResultIterators(plans, parentContext);
         ResultIterator scanner;      
         boolean isOrdered = !orderBy.getOrderByExpressions().isEmpty();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7601d594/phoenix-core/src/main/java/org/apache/phoenix/execute/UnnestArrayPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/UnnestArrayPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/UnnestArrayPlan.java
index 94c59df..bda1b96 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/UnnestArrayPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/UnnestArrayPlan.java
@@ -28,7 +28,6 @@ import org.apache.phoenix.expression.BaseSingleExpression;
 import org.apache.phoenix.expression.BaseTerminalExpression;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
-import org.apache.phoenix.iterate.DefaultParallelScanGrouper;
 import org.apache.phoenix.iterate.DelegateResultIterator;
 import org.apache.phoenix.iterate.ParallelScanGrouper;
 import org.apache.phoenix.iterate.ResultIterator;
@@ -48,16 +47,6 @@ public class UnnestArrayPlan extends DelegateQueryPlan {
     }
 
     @Override
-    public ResultIterator iterator() throws SQLException {
-        return iterator(DefaultParallelScanGrouper.getInstance());
-    }
-
-    @Override
-    public ResultIterator iterator(ParallelScanGrouper scanGrouper) throws SQLException {
-        return new UnnestArrayResultIterator(delegate.iterator(scanGrouper, delegate.getContext().getScan()));
-    }
-
-    @Override
     public ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan) throws SQLException {
         return new UnnestArrayResultIterator(delegate.iterator(scanGrouper, scan));
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7601d594/phoenix-core/src/main/java/org/apache/phoenix/iterate/UnionResultIterators.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/UnionResultIterators.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/UnionResultIterators.java
index 5018dad..910a514 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/UnionResultIterators.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/UnionResultIterators.java
@@ -42,21 +42,19 @@ public class UnionResultIterators implements ResultIterators {
     private final List<KeyRange> splits;
     private final List<List<Scan>> scans;
     private final List<PeekingResultIterator> iterators;
-    private final List<QueryPlan> plans;
     private final List<ReadMetricQueue> readMetricsList;
     private final List<OverAllQueryMetrics> overAllQueryMetricsList;
     private boolean closed;
     private final StatementContext parentStmtCtx;
     public UnionResultIterators(List<QueryPlan> plans, StatementContext parentStmtCtx) throws SQLException {
         this.parentStmtCtx = parentStmtCtx;
-        this.plans = plans;
         int nPlans = plans.size();
         iterators = Lists.newArrayListWithExpectedSize(nPlans);
         splits = Lists.newArrayListWithExpectedSize(nPlans * 30); 
         scans = Lists.newArrayListWithExpectedSize(nPlans * 10); 
         readMetricsList = Lists.newArrayListWithCapacity(nPlans);
         overAllQueryMetricsList = Lists.newArrayListWithCapacity(nPlans);
-        for (QueryPlan plan : this.plans) {
+        for (QueryPlan plan : plans) {
             readMetricsList.add(plan.getContext().getReadMetricsQueue());
             overAllQueryMetricsList.add(plan.getContext().getOverallQueryMetrics());
             iterators.add(LookAheadResultIterator.wrap(plan.iterator()));


[05/47] phoenix git commit: PHOENIX-2641 Implicit wildcard in LIKE predicate search pattern

Posted by ma...@apache.org.
PHOENIX-2641 Implicit wildcard in LIKE predicate search pattern

This closes #200


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

Branch: refs/heads/calcite
Commit: c02d6cb5971f7b17bcd5e308952fa081e32adf19
Parents: 7827178
Author: kliewkliew <kl...@users.noreply.github.com>
Authored: Wed Aug 24 06:40:35 2016 -0700
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Tue Sep 6 11:11:38 2016 -0700

----------------------------------------------------------------------
 .../phoenix/end2end/LikeExpressionIT.java       | 23 ++++++++++++++++++++
 .../phoenix/compile/ExpressionCompiler.java     | 10 +++++++--
 .../phoenix/expression/LikeExpressionTest.java  |  6 +++++
 3 files changed, 37 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/c02d6cb5/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java
index 6bfa358..f97e1d7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java
@@ -182,4 +182,27 @@ public class LikeExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
                 "SELECT * FROM " + t + " WHERE k like 'AA_'");
         assertFalse(rs.next());
     }
+
+    @Test
+    public void testOneChar() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String t = generateRandomString();
+        String ddl = "CREATE TABLE " + t + " (k VARCHAR NOT NULL PRIMARY KEY)";
+        conn.createStatement().execute(ddl);
+        conn.createStatement().execute("UPSERT INTO " + t + " VALUES('A')");
+        conn.createStatement().execute("UPSERT INTO " + t + " VALUES('AA')");
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery(
+                "SELECT * FROM " + t + " WHERE k like '_'");
+        assertTrue(rs.next());
+        assertEquals("A", rs.getString(1));
+        assertFalse(rs.next());
+
+        rs = conn.createStatement().executeQuery(
+                "SELECT * FROM " + t + " WHERE k like '_A'");
+        assertTrue(rs.next());
+        assertEquals("AA", rs.getString(1));
+        assertFalse(rs.next());
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/c02d6cb5/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
index 0fd1876..aaab763 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
@@ -136,6 +136,7 @@ import org.apache.phoenix.schema.types.PhoenixArray;
 import org.apache.phoenix.util.ExpressionUtil;
 import org.apache.phoenix.util.IndexUtil;
 import org.apache.phoenix.util.SchemaUtil;
+import org.apache.phoenix.util.StringUtil;
 
 
 public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expression> {
@@ -517,8 +518,13 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
                       return new ComparisonExpression(Arrays.asList(lhs,rhs), op);
                   }
                 }
-            } else if (index == 0 && pattern.length() == 1) {
-                return IsNullExpression.create(lhs, true, context.getTempPtr());
+            } else {
+                byte[] nullExpressionString = new byte[pattern.length()];
+                byte[] wildcard = {StringUtil.MULTI_CHAR_LIKE};
+                StringUtil.fill(nullExpressionString, 0, pattern.length(), wildcard, 0, 1, false);
+                if (pattern.equals(new String (nullExpressionString))) {
+                    return IsNullExpression.create(lhs, true, context.getTempPtr());
+                }
             }
         }
         QueryServices services = context.getConnection().getQueryServices();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/c02d6cb5/phoenix-core/src/test/java/org/apache/phoenix/expression/LikeExpressionTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/expression/LikeExpressionTest.java b/phoenix-core/src/test/java/org/apache/phoenix/expression/LikeExpressionTest.java
index 580ac8e..2e33e7b 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/expression/LikeExpressionTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/expression/LikeExpressionTest.java
@@ -77,6 +77,12 @@ public class LikeExpressionTest {
     }
 
     @Test
+    public void testOneChar() throws Exception {
+        assertEquals(Boolean.TRUE, testExpression ("A", "_"));
+        assertEquals(Boolean.FALSE, testExpression ("AA", "_"));
+    }
+
+    @Test
     public void testEmptySourceStr() throws Exception {
         assertEquals(Boolean.TRUE, testExpression ("", "%"));
         assertEquals(Boolean.FALSE, testExpression ("", "_"));


[02/47] phoenix git commit: PHOENIX-2793 Test case for date-time functions on null dates return no data (Kevin Liew)

Posted by ma...@apache.org.
PHOENIX-2793 Test case for date-time functions on null dates return no data (Kevin Liew)


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

Branch: refs/heads/calcite
Commit: 06d37e534d1e07e8206eaefb82dd7bf3f50455b0
Parents: b7d45ca
Author: Samarth <sa...@salesforce.com>
Authored: Thu Sep 1 10:28:49 2016 -0700
Committer: Samarth <sa...@salesforce.com>
Committed: Thu Sep 1 10:28:49 2016 -0700

----------------------------------------------------------------------
 .../it/java/org/apache/phoenix/end2end/DateTimeIT.java   | 11 +++++++++++
 1 file changed, 11 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/06d37e53/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
index abdcf3b..227374a 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
@@ -794,4 +794,15 @@ public class DateTimeIT extends BaseHBaseManagedTimeTableReuseIT {
         assertEquals(false, rs.getBoolean(1));
         assertFalse(rs.next());
     }
+    
+    @Test
+    public void testFunctionOnNullDate() throws Exception {
+        ResultSet rs = conn.createStatement().executeQuery("SELECT YEAR(a_date), entity_id from " + this.tableName + " WHERE entity_id = '" + ROW10 + "'");
+        assertNotNull(rs);
+        assertTrue(rs.next());
+        assertEquals(ROW10, rs.getString(2));
+        assertNull(rs.getDate(1));
+        assertNull(rs.getDate(1, GregorianCalendar.getInstance()));
+        assertFalse(rs.next());
+    }
 }


[32/47] phoenix git commit: PHOENIX-3249 Make changes in LocalIndexIT for method level parallelization in BaseHBaseManagedTimeTableReuseIT

Posted by ma...@apache.org.
PHOENIX-3249 Make changes in LocalIndexIT for method level parallelization in BaseHBaseManagedTimeTableReuseIT


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

Branch: refs/heads/calcite
Commit: b0f900488dec92d0eaac8e2576991281e78984f5
Parents: 1a3bd43
Author: James Taylor <ja...@apache.org>
Authored: Thu Sep 15 17:01:27 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Thu Sep 15 17:01:27 2016 -0700

----------------------------------------------------------------------
 .../end2end/index/AsyncImmutableIndexIT.java    | 114 ----------
 .../end2end/index/IndexOnOwnClusterIT.java      | 114 ++++++++++
 .../phoenix/end2end/index/LocalIndexIT.java     | 215 ++-----------------
 3 files changed, 129 insertions(+), 314 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b0f90048/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/AsyncImmutableIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/AsyncImmutableIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/AsyncImmutableIndexIT.java
deleted file mode 100644
index 8c90b6e..0000000
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/AsyncImmutableIndexIT.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.phoenix.end2end.index;
-
-import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.phoenix.end2end.BaseOwnClusterHBaseManagedTimeIT;
-import org.apache.phoenix.end2end.IndexToolIT;
-import org.apache.phoenix.mapreduce.index.IndexTool;
-import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.query.QueryServicesOptions;
-import org.apache.phoenix.util.PropertiesUtil;
-import org.apache.phoenix.util.QueryUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.google.common.collect.Maps;
-
-public class AsyncImmutableIndexIT extends BaseOwnClusterHBaseManagedTimeIT {
-    
-    @BeforeClass
-    public static void doSetup() throws Exception {
-        Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(1);
-        serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB,
-            QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
-        setUpRealDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
-            ReadOnlyProps.EMPTY_PROPS);
-    }
-    
-    @Test
-    public void testDeleteFromImmutable() throws Exception {
-        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-            conn.createStatement().execute("CREATE TABLE TEST_TABLE (\n" + 
-                    "        pk1 VARCHAR NOT NULL,\n" + 
-                    "        pk2 VARCHAR NOT NULL,\n" + 
-                    "        pk3 VARCHAR\n" + 
-                    "        CONSTRAINT PK PRIMARY KEY \n" + 
-                    "        (\n" + 
-                    "        pk1,\n" + 
-                    "        pk2,\n" + 
-                    "        pk3\n" + 
-                    "        )\n" + 
-                    "        ) IMMUTABLE_ROWS=true");
-            conn.createStatement().execute("upsert into TEST_TABLE (pk1, pk2, pk3) values ('a', '1', '1')");
-            conn.createStatement().execute("upsert into TEST_TABLE (pk1, pk2, pk3) values ('b', '2', '2')");
-            conn.commit();
-            conn.createStatement().execute("CREATE INDEX TEST_INDEX ON TEST_TABLE (pk3, pk2) ASYNC");
-            
-            // this delete will be issued at a timestamp later than the above timestamp of the index table
-            conn.createStatement().execute("delete from TEST_TABLE where pk1 = 'a'");
-            conn.commit();
-
-            // run the index MR job
-            final IndexTool indexingTool = new IndexTool();
-            indexingTool.setConf(new Configuration(getUtility().getConfiguration()));
-            final String[] cmdArgs =
-                    IndexToolIT.getArgValues(null, "TEST_TABLE", "TEST_INDEX", true);
-            int status = indexingTool.run(cmdArgs);
-            assertEquals(0, status);
-
-            // upsert two more rows
-            conn.createStatement().execute(
-                "upsert into TEST_TABLE (pk1, pk2, pk3) values ('a', '3', '3')");
-            conn.createStatement().execute(
-                "upsert into TEST_TABLE (pk1, pk2, pk3) values ('b', '4', '4')");
-            conn.commit();
-
-            // validate that delete markers were issued correctly and only ('a', '1', 'value1') was
-            // deleted
-            String query = "SELECT pk3 from TEST_TABLE ORDER BY pk3";
-            ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + query);
-            String expectedPlan =
-                    "CLIENT 1-CHUNK PARALLEL 1-WAY FULL SCAN OVER TEST_INDEX\n"
-                            + "    SERVER FILTER BY FIRST KEY ONLY";
-            assertEquals("Wrong plan ", expectedPlan, QueryUtil.getExplainPlan(rs));
-            rs = conn.createStatement().executeQuery(query);
-            assertTrue(rs.next());
-            assertEquals("2", rs.getString(1));
-            assertTrue(rs.next());
-            assertEquals("3", rs.getString(1));
-            assertTrue(rs.next());
-            assertEquals("4", rs.getString(1));
-            assertFalse(rs.next());
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b0f90048/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java
new file mode 100644
index 0000000..8c90b6e
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end.index;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.phoenix.end2end.BaseOwnClusterHBaseManagedTimeIT;
+import org.apache.phoenix.end2end.IndexToolIT;
+import org.apache.phoenix.mapreduce.index.IndexTool;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.QueryUtil;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+
+public class AsyncImmutableIndexIT extends BaseOwnClusterHBaseManagedTimeIT {
+    
+    @BeforeClass
+    public static void doSetup() throws Exception {
+        Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(1);
+        serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB,
+            QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
+        setUpRealDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
+            ReadOnlyProps.EMPTY_PROPS);
+    }
+    
+    @Test
+    public void testDeleteFromImmutable() throws Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.createStatement().execute("CREATE TABLE TEST_TABLE (\n" + 
+                    "        pk1 VARCHAR NOT NULL,\n" + 
+                    "        pk2 VARCHAR NOT NULL,\n" + 
+                    "        pk3 VARCHAR\n" + 
+                    "        CONSTRAINT PK PRIMARY KEY \n" + 
+                    "        (\n" + 
+                    "        pk1,\n" + 
+                    "        pk2,\n" + 
+                    "        pk3\n" + 
+                    "        )\n" + 
+                    "        ) IMMUTABLE_ROWS=true");
+            conn.createStatement().execute("upsert into TEST_TABLE (pk1, pk2, pk3) values ('a', '1', '1')");
+            conn.createStatement().execute("upsert into TEST_TABLE (pk1, pk2, pk3) values ('b', '2', '2')");
+            conn.commit();
+            conn.createStatement().execute("CREATE INDEX TEST_INDEX ON TEST_TABLE (pk3, pk2) ASYNC");
+            
+            // this delete will be issued at a timestamp later than the above timestamp of the index table
+            conn.createStatement().execute("delete from TEST_TABLE where pk1 = 'a'");
+            conn.commit();
+
+            // run the index MR job
+            final IndexTool indexingTool = new IndexTool();
+            indexingTool.setConf(new Configuration(getUtility().getConfiguration()));
+            final String[] cmdArgs =
+                    IndexToolIT.getArgValues(null, "TEST_TABLE", "TEST_INDEX", true);
+            int status = indexingTool.run(cmdArgs);
+            assertEquals(0, status);
+
+            // upsert two more rows
+            conn.createStatement().execute(
+                "upsert into TEST_TABLE (pk1, pk2, pk3) values ('a', '3', '3')");
+            conn.createStatement().execute(
+                "upsert into TEST_TABLE (pk1, pk2, pk3) values ('b', '4', '4')");
+            conn.commit();
+
+            // validate that delete markers were issued correctly and only ('a', '1', 'value1') was
+            // deleted
+            String query = "SELECT pk3 from TEST_TABLE ORDER BY pk3";
+            ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + query);
+            String expectedPlan =
+                    "CLIENT 1-CHUNK PARALLEL 1-WAY FULL SCAN OVER TEST_INDEX\n"
+                            + "    SERVER FILTER BY FIRST KEY ONLY";
+            assertEquals("Wrong plan ", expectedPlan, QueryUtil.getExplainPlan(rs));
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals("2", rs.getString(1));
+            assertTrue(rs.next());
+            assertEquals("3", rs.getString(1));
+            assertTrue(rs.next());
+            assertEquals("4", rs.getString(1));
+            assertFalse(rs.next());
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b0f90048/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 f254c49..d3d775b 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
@@ -33,14 +33,10 @@ 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;
 
 import org.apache.hadoop.hbase.HColumnDescriptor;
-import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.MetaTableAccessor;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.client.HTable;
@@ -52,47 +48,41 @@ import org.apache.hadoop.hbase.util.Pair;
 import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
 import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
-import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.hbase.index.IndexRegionSplitPolicy;
 import org.apache.phoenix.jdbc.PhoenixConnection;
-import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.jdbc.PhoenixStatement;
+import org.apache.phoenix.query.BaseTest;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.schema.*;
+import org.apache.phoenix.schema.PNameFactory;
+import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTable.IndexType;
-import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.schema.PTableKey;
+import org.apache.phoenix.schema.TableNotFoundException;
+import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.TestUtil;
-import org.junit.BeforeClass;
+import org.junit.Before;
 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 BaseHBaseManagedTimeTableReuseIT {
     private boolean isNamespaceMapped;
-    String schemaName="TEST";
+    private String schemaName;
 
     public LocalIndexIT(boolean isNamespaceMapped) {
         this.isNamespaceMapped = isNamespaceMapped;
     }
     
-    @BeforeClass 
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
-    public static void doSetup() throws Exception {
-        Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
-        // Drop the HBase table metadata for this test
-        props.put(QueryServices.DROP_METADATA_ATTRIB, Boolean.toString(true));
-        // Must update config before starting server
-        setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+    @Before
+    public void setup() {
+        schemaName = BaseTest.generateRandomString();
     }
-
+    
     private void createBaseTable(String tableName, Integer saltBuckets, String splits) throws SQLException {
         Connection conn = getConnection();
         if (isNamespaceMapped) {
@@ -110,7 +100,7 @@ public class LocalIndexIT extends BaseHBaseManagedTimeTableReuseIT {
         conn.close();
     }
 
-    @Parameters(name = "isNamespaceMapped = {0}")
+    @Parameters(name = "LocalIndexIT_isNamespaceMapped={0}") // name is used by failsafe as file name in reports
     public static Collection<Boolean> data() {
         return Arrays.asList(true, false);
     }
@@ -202,14 +192,12 @@ public class LocalIndexIT extends BaseHBaseManagedTimeTableReuseIT {
         }
     }
     
-    public Connection getConnection() throws SQLException{
-        Properties props = new Properties();
-        props.put(QueryServices.DROP_METADATA_ATTRIB, Boolean.toString(true));
+    private Connection getConnection() throws SQLException{
+        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
         props.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(isNamespaceMapped));
         return DriverManager.getConnection(getUrl(),props);
     }
 
-
     @Test
     public void testDropLocalIndexTable() throws Exception {
         String tableName = schemaName + "." + generateRandomString();
@@ -805,103 +793,6 @@ public class LocalIndexIT extends BaseHBaseManagedTimeTableReuseIT {
     }
 
     @Test
-    public void testLocalIndexScanAfterRegionSplit() throws Exception {
-        String tableName = schemaName + "." + generateRandomString();
-        String indexName = "IDX_" + generateRandomString();
-        TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped);
-        String indexPhysicalTableName = physicalTableName.getNameAsString();
-
-        if (isNamespaceMapped) { return; }
-        createBaseTable(tableName, null, "('e','j','o')");
-        Connection conn1 = getConnection();
-        try{
-            String[] strings = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
-            for (int i = 0; i < 26; i++) {
-                conn1.createStatement().execute(
-                    "UPSERT INTO " + tableName + " values('"+strings[i]+"'," + i + ","
-                            + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')");
-            }
-            conn1.commit();
-            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)");
-            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + "_2 ON " + tableName + "(k3)");
-
-            ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + tableName);
-            assertTrue(rs.next());
-            
-            HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
-            for (int i = 1; i < 5; i++) {
-                admin.split(physicalTableName, ByteUtil.concat(Bytes.toBytes(strings[3*i])));
-                List<HRegionInfo> regionsOfUserTable =
-                        MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
-                                physicalTableName, false);
-
-                while (regionsOfUserTable.size() != (4+i)) {
-                    Thread.sleep(100);
-                    regionsOfUserTable = MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(),
-                            admin.getConnection(), physicalTableName, false);
-                }
-                assertEquals(4+i, regionsOfUserTable.size());
-                String[] tIdColumnValues = new String[26]; 
-                String[] v1ColumnValues = new String[26];
-                int[] k1ColumnValue = new int[26];
-                String query = "SELECT t_id,k1,v1 FROM " + tableName;
-                rs = conn1.createStatement().executeQuery(query);
-                Thread.sleep(1000);
-                for (int j = 0; j < 26; j++) {
-                    assertTrue(rs.next());
-                    tIdColumnValues[j] = rs.getString("t_id");
-                    k1ColumnValue[j] = rs.getInt("k1");
-                    v1ColumnValues[j] = rs.getString("V1");
-                }
-                Arrays.sort(tIdColumnValues);
-                Arrays.sort(v1ColumnValues);
-                Arrays.sort(k1ColumnValue);
-                assertTrue(Arrays.equals(strings, tIdColumnValues));
-                assertTrue(Arrays.equals(strings, v1ColumnValues));
-                for(int m=0;m<26;m++) {
-                    assertEquals(m, k1ColumnValue[m]);
-                }
-
-                rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
-                assertEquals(
-                        "CLIENT PARALLEL " + (4 + i) + "-WAY RANGE SCAN OVER "
-                                + indexPhysicalTableName + " [1]\n"
-                                        + "    SERVER FILTER BY FIRST KEY ONLY\n"
-                                + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
-                
-                query = "SELECT t_id,k1,k3 FROM " + tableName;
-                rs = conn1.createStatement().executeQuery("EXPLAIN "+query);
-                assertEquals(
-                    "CLIENT PARALLEL "
-                            + ((strings[3 * i].compareTo("j") < 0) ? (4 + i) : (4 + i - 1))
-                            + "-WAY RANGE SCAN OVER "
-                            + indexPhysicalTableName + " [2]\n"
-                                    + "    SERVER FILTER BY FIRST KEY ONLY\n"
-                            + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
-                rs = conn1.createStatement().executeQuery(query);
-                Thread.sleep(1000);
-                int[] k3ColumnValue = new int[26];
-                for (int j = 0; j < 26; j++) {
-                    assertTrue(rs.next());
-                    tIdColumnValues[j] = rs.getString("t_id");
-                    k1ColumnValue[j] = rs.getInt("k1");
-                    k3ColumnValue[j] = rs.getInt("k3");
-                }
-                Arrays.sort(tIdColumnValues);
-                Arrays.sort(k1ColumnValue);
-                Arrays.sort(k3ColumnValue);
-                assertTrue(Arrays.equals(strings, tIdColumnValues));
-                for(int m=0;m<26;m++) {
-                    assertEquals(m, k1ColumnValue[m]);
-                    assertEquals(m+2, k3ColumnValue[m]);
-                }
-            }
-       } finally {
-            conn1.close();
-        }
-    }
-
-    @Test
     public void testLocalIndexScanWithSmallChunks() throws Exception {
         String tableName = schemaName + "." + generateRandomString();
         String indexName = "IDX_" + generateRandomString();
@@ -946,80 +837,4 @@ public class LocalIndexIT extends BaseHBaseManagedTimeTableReuseIT {
             conn1.close();
         }
     }
-
-    @Test
-    public void testLocalIndexScanAfterRegionsMerge() throws Exception {
-        String tableName = schemaName + "." + generateRandomString();
-        String indexName = "IDX_" + generateRandomString();
-        TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped);
-        String indexPhysicalTableName = physicalTableName.getNameAsString();
-
-        if (isNamespaceMapped) { return; }
-        createBaseTable(tableName, null, "('e','j','o')");
-        Connection conn1 = getConnection();
-        try{
-            String[] strings = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
-            for (int i = 0; i < 26; i++) {
-                conn1.createStatement().execute(
-                    "UPSERT INTO " + tableName + " values('"+strings[i]+"'," + i + ","
-                            + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')");
-            }
-            conn1.commit();
-            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)");
-            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + "_2 ON " + tableName + "(k3)");
-
-            ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + tableName);
-            assertTrue(rs.next());
-
-            HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
-            List<HRegionInfo> regionsOfUserTable =
-                    MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
-                        physicalTableName, false);
-            admin.mergeRegions(regionsOfUserTable.get(0).getEncodedNameAsBytes(),
-                regionsOfUserTable.get(1).getEncodedNameAsBytes(), false);
-            regionsOfUserTable =
-                    MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
-                            physicalTableName, false);
-
-            while (regionsOfUserTable.size() != 3) {
-                Thread.sleep(100);
-                regionsOfUserTable = MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(),
-                        admin.getConnection(), physicalTableName, false);
-            }
-            String query = "SELECT t_id,k1,v1 FROM " + tableName;
-            rs = conn1.createStatement().executeQuery(query);
-            Thread.sleep(1000);
-            for (int j = 0; j < 26; j++) {
-                assertTrue(rs.next());
-                assertEquals(strings[25 - j], rs.getString("t_id"));
-                assertEquals(25 - j, rs.getInt("k1"));
-                assertEquals(strings[j], rs.getString("V1"));
-            }
-            rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
-            assertEquals(
-                "CLIENT PARALLEL " + 3 + "-WAY RANGE SCAN OVER "
-                        + indexPhysicalTableName
-                        + " [1]\n" + "    SERVER FILTER BY FIRST KEY ONLY\n"
-                        + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
-
-            query = "SELECT t_id,k1,k3 FROM " + tableName;
-            rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
-            assertEquals(
-                "CLIENT PARALLEL " + 3 + "-WAY RANGE SCAN OVER "
-                        + indexPhysicalTableName
-                        + " [2]\n" + "    SERVER FILTER BY FIRST KEY ONLY\n"
-                        + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
-
-            rs = conn1.createStatement().executeQuery(query);
-            Thread.sleep(1000);
-            for (int j = 0; j < 26; j++) {
-                assertTrue(rs.next());
-                assertEquals(strings[j], rs.getString("t_id"));
-                assertEquals(j, rs.getInt("k1"));
-                assertEquals(j + 2, rs.getInt("k3"));
-            }
-       } finally {
-            conn1.close();
-        }
-    }
 }


[43/47] phoenix git commit: PHOENIX-3174 Make minor upgrade a manual step

Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index 1aa9b88..dfe7ee8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -63,6 +63,7 @@ import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.annotation.concurrent.GuardedBy;
 
@@ -131,6 +132,8 @@ import org.apache.phoenix.coprocessor.generated.MetaDataProtos.UpdateIndexStateR
 import org.apache.phoenix.exception.PhoenixIOException;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
+import org.apache.phoenix.exception.UpgradeInProgressException;
+import org.apache.phoenix.exception.UpgradeNotRequiredException;
 import org.apache.phoenix.execute.MutationState;
 import org.apache.phoenix.hbase.index.IndexRegionSplitPolicy;
 import org.apache.phoenix.hbase.index.Indexer;
@@ -266,6 +269,8 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
     private final List<LinkedBlockingQueue<WeakReference<PhoenixConnection>>> connectionQueues;
     private ScheduledExecutorService renewLeaseExecutor;
     private final boolean renewLeaseEnabled;
+    private final boolean isAutoUpgradeEnabled;
+    private final AtomicBoolean upgradeRequired = new AtomicBoolean(false);
 
     private static interface FeatureSupported {
         boolean isSupported(ConnectionQueryServices services);
@@ -342,6 +347,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         connectionQueues = ImmutableList.copyOf(list);
         // A little bit of a smell to leak `this` here, but should not be a problem
         this.tableStatsCache = new TableStatsCache(this, config);
+        this.isAutoUpgradeEnabled = config.getBoolean(AUTO_UPGRADE_ENABLED, QueryServicesOptions.DEFAULT_AUTO_UPGRADE_ENABLED);
     }
 
     @Override
@@ -2310,29 +2316,16 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                             return null;
                         }
                         checkClosed();
-                        PhoenixConnection metaConnection = null;
-                        boolean success = false;
-                        String snapshotName = null;
-                        String sysCatalogTableName = null;
                         try {
                             openConnection();
-                            String noUpgradeProp = props.getProperty(PhoenixRuntime.NO_UPGRADE_ATTRIB);
-                            boolean upgradeSystemTables = !Boolean.TRUE.equals(Boolean.valueOf(noUpgradeProp));
-                            Properties scnProps = PropertiesUtil.deepCopy(props);
-                            scnProps.setProperty(
-                                    PhoenixRuntime.CURRENT_SCN_ATTRIB,
-                                    Long.toString(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP));
-                            scnProps.remove(PhoenixRuntime.TENANT_ID_ATTRIB);
-                            String globalUrl = JDBCUtil.removeProperty(url, PhoenixRuntime.TENANT_ID_ATTRIB);
-                            metaConnection = new PhoenixConnection(
-                                    ConnectionQueryServicesImpl.this, globalUrl, scnProps, newEmptyMetaData());
+                            boolean isDoNotUpgradePropSet = UpgradeUtil.isNoUpgradeSet(props);
                             try (HBaseAdmin admin = getAdmin()) {
                                 boolean mappedSystemCatalogExists = admin
                                         .tableExists(SchemaUtil.getPhysicalTableName(SYSTEM_CATALOG_NAME_BYTES, true));
                                 if (SchemaUtil.isNamespaceMappingEnabled(PTableType.SYSTEM,
                                         ConnectionQueryServicesImpl.this.getProps())) {
                                     if (admin.tableExists(SYSTEM_CATALOG_NAME_BYTES)) {
-                                        //check if the server is already updated and have namespace config properly set.
+                                        //check if the server is already updated and have namespace config properly set. 
                                         checkClientServerCompatibility(SYSTEM_CATALOG_NAME_BYTES);
                                     }
                                     ensureSystemTablesUpgraded(ConnectionQueryServicesImpl.this.getProps());
@@ -2345,232 +2338,32 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                                                 + IS_NAMESPACE_MAPPING_ENABLED + " enabled")
                                                 .build().buildException(); }
                             }
-                            try {
-                                metaConnection.createStatement().executeUpdate(QueryConstants.CREATE_TABLE_METADATA);
-                            } catch (NewerTableAlreadyExistsException ignore) {
-                                // Ignore, as this will happen if the SYSTEM.CATALOG already exists at this fixed timestamp.
-                                // A TableAlreadyExistsException is not thrown, since the table only exists *after* this fixed timestamp.
-                            } catch (TableAlreadyExistsException e) {
-                                if (upgradeSystemTables) {
-                                    long currentServerSideTableTimeStamp = e.getTable().getTimeStamp();
-                                    sysCatalogTableName = e.getTable().getPhysicalName().getString();
-                                    if (currentServerSideTableTimeStamp < MIN_SYSTEM_TABLE_TIMESTAMP && acquireUpgradeMutex(currentServerSideTableTimeStamp, e.getTable().getPhysicalName().getBytes())) {
-                                        snapshotName = getUpgradeSnapshotName(sysCatalogTableName, currentServerSideTableTimeStamp);
-                                        createSnapshot(snapshotName, sysCatalogTableName);
-                                    }
-                                    String columnsToAdd = "";
-                                    // This will occur if we have an older SYSTEM.CATALOG and we need to update it to include
-                                    // any new columns we've added.
-                                    if(currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_3_0) {
-                                        // We know that we always need to add the STORE_NULLS column for 4.3 release
-                                        columnsToAdd = addColumn(columnsToAdd, PhoenixDatabaseMetaData.STORE_NULLS + " " + PBoolean.INSTANCE.getSqlTypeName());
-                                        try (HBaseAdmin admin = getAdmin()) {
-                                            HTableDescriptor[] localIndexTables = admin.listTables(MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX+".*");
-                                            for (HTableDescriptor table : localIndexTables) {
-                                                if (table.getValue(MetaDataUtil.PARENT_TABLE_KEY) == null
-                                                        && table.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_NAME) != null) {
-                                                    table.setValue(MetaDataUtil.PARENT_TABLE_KEY,
-                                                            MetaDataUtil.getUserTableName(table
-                                                                    .getNameAsString()));
-                                                    // Explicitly disable, modify and enable the table to ensure co-location of data
-                                                    // and index regions. If we just modify the table descriptor when online schema
-                                                    // change enabled may reopen the region in same region server instead of following data region.
-                                                    admin.disableTable(table.getTableName());
-                                                    admin.modifyTable(table.getTableName(), table);
-                                                    admin.enableTable(table.getTableName());
-                                                }
-                                            }
-                                        }
-                                    }
-
-                                    // If the server side schema is before MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0 then
-                                    // we need to add INDEX_TYPE and INDEX_DISABLE_TIMESTAMP columns too.
-                                    // TODO: Once https://issues.apache.org/jira/browse/PHOENIX-1614 is fixed,
-                                    // we should just have a ALTER TABLE ADD IF NOT EXISTS statement with all
-                                    // the column names that have been added to SYSTEM.CATALOG since 4.0.
-                                    if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0) {
-                                        columnsToAdd = addColumn(columnsToAdd, PhoenixDatabaseMetaData.INDEX_TYPE + " " + PUnsignedTinyint.INSTANCE.getSqlTypeName()
-                                                + ", " + PhoenixDatabaseMetaData.INDEX_DISABLE_TIMESTAMP + " " + PLong.INSTANCE.getSqlTypeName());
-                                    }
-
-                                    // If we have some new columns from 4.1-4.3 to add, add them now.
-                                    if (!columnsToAdd.isEmpty()) {
-                                        // Ugh..need to assign to another local variable to keep eclipse happy.
-                                        PhoenixConnection newMetaConnection = addColumnsIfNotExists(metaConnection,
-                                                PhoenixDatabaseMetaData.SYSTEM_CATALOG,
-                                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_3_0, columnsToAdd);
-                                        metaConnection = newMetaConnection;
-                                    }
-
-                                    if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_5_0) {
-                                        columnsToAdd = PhoenixDatabaseMetaData.BASE_COLUMN_COUNT + " "
-                                                + PInteger.INSTANCE.getSqlTypeName();
-                                        try {
-                                            metaConnection = addColumn(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG,
-                                                    MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_5_0, columnsToAdd, false);
-                                            upgradeTo4_5_0(metaConnection);
-                                        } catch (ColumnAlreadyExistsException ignored) {
-                                            /*
-                                             * Upgrade to 4.5 is a slightly special case. We use the fact that the column
-                                             * BASE_COLUMN_COUNT is already part of the meta-data schema as the signal that
-                                             * the server side upgrade has finished or is in progress.
-                                             */
-                                            logger.debug("No need to run 4.5 upgrade");
-                                        }
-                                        Properties props = PropertiesUtil.deepCopy(metaConnection.getClientInfo());
-                                        props.remove(PhoenixRuntime.CURRENT_SCN_ATTRIB);
-                                        props.remove(PhoenixRuntime.TENANT_ID_ATTRIB);
-                                        PhoenixConnection conn = new PhoenixConnection(ConnectionQueryServicesImpl.this, metaConnection.getURL(), props, metaConnection.getMetaDataCache());
-                                        try {
-                                            List<String> tablesNeedingUpgrade = UpgradeUtil.getPhysicalTablesWithDescRowKey(conn);
-                                            if (!tablesNeedingUpgrade.isEmpty()) {
-                                                logger.warn("The following tables require upgrade due to a bug causing the row key to be incorrect for descending columns and ascending BINARY columns (PHOENIX-2067 and PHOENIX-2120):\n" + Joiner.on(' ').join(tablesNeedingUpgrade) + "\nTo upgrade issue the \"bin/psql.py -u\" command.");
-                                            }
-                                            List<String> unsupportedTables = UpgradeUtil.getPhysicalTablesWithDescVarbinaryRowKey(conn);
-                                            if (!unsupportedTables.isEmpty()) {
-                                                logger.warn("The following tables use an unsupported VARBINARY DESC construct and need to be changed:\n" + Joiner.on(' ').join(unsupportedTables));
-                                            }
-                                        } catch (Exception ex) {
-                                            logger.error("Unable to determine tables requiring upgrade due to PHOENIX-2067", ex);
-                                        } finally {
-                                            conn.close();
-                                        }
-                                    }
-                                    // Add these columns one at a time, each with different timestamps so that if folks have
-                                    // run the upgrade code already for a snapshot, we'll still enter this block (and do the
-                                    // parts we haven't yet done).
-                                    if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_6_0) {
-                                        columnsToAdd = PhoenixDatabaseMetaData.IS_ROW_TIMESTAMP + " " + PBoolean.INSTANCE.getSqlTypeName();
-                                        metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG,
-                                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_6_0, columnsToAdd);
-                                    }
-                                    if(currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0) {
-                                        // Drop old stats table so that new stats table is created
-                                        metaConnection = dropStatsTable(metaConnection,
-                                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 4);
-                                        metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG,
-                                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 3,
-                                                PhoenixDatabaseMetaData.TRANSACTIONAL + " " + PBoolean.INSTANCE.getSqlTypeName());
-                                        metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG,
-                                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 2,
-                                                PhoenixDatabaseMetaData.UPDATE_CACHE_FREQUENCY + " " + PLong.INSTANCE.getSqlTypeName());
-                                        metaConnection = setImmutableTableIndexesImmutable(metaConnection,
-                                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 1);
-                                        metaConnection = updateSystemCatalogTimestamp(metaConnection,
-                                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0);
-                                        ConnectionQueryServicesImpl.this.removeTable(null, PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME, null, MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0);
-                                        clearCache();
-                                    }
-
-                                    if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0) {
-                                        metaConnection = addColumnsIfNotExists(metaConnection,
-                                                PhoenixDatabaseMetaData.SYSTEM_CATALOG,
-                                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0 - 2,
-                                                PhoenixDatabaseMetaData.IS_NAMESPACE_MAPPED + " "
-                                                        + PBoolean.INSTANCE.getSqlTypeName());
-                                        metaConnection = addColumnsIfNotExists(metaConnection,
-                                                PhoenixDatabaseMetaData.SYSTEM_CATALOG,
-                                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0 - 1,
-                                                PhoenixDatabaseMetaData.AUTO_PARTITION_SEQ + " "
-                                                        + PVarchar.INSTANCE.getSqlTypeName());
-                                        metaConnection = addColumnsIfNotExists(metaConnection,
-                                                PhoenixDatabaseMetaData.SYSTEM_CATALOG,
-                                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0,
-                                                PhoenixDatabaseMetaData.APPEND_ONLY_SCHEMA + " "
-                                                        + PBoolean.INSTANCE.getSqlTypeName());
-                                        metaConnection = UpgradeUtil.disableViewIndexes(metaConnection);
-                                        if(getProps().getBoolean(QueryServices.LOCAL_INDEX_CLIENT_UPGRADE_ATTRIB,
-                                                QueryServicesOptions.DEFAULT_LOCAL_INDEX_CLIENT_UPGRADE)) {
-                                            metaConnection = UpgradeUtil.upgradeLocalIndexes(metaConnection);
-                                        }
-                                        ConnectionQueryServicesImpl.this.removeTable(null,
-                                                PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME, null,
-                                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0);
-                                        clearCache();
-                                    }
-
-                                }
-                            }
-
-                            int nSaltBuckets = ConnectionQueryServicesImpl.this.props.getInt(QueryServices.SEQUENCE_SALT_BUCKETS_ATTRIB,
-                                    QueryServicesOptions.DEFAULT_SEQUENCE_TABLE_SALT_BUCKETS);
-                            try {
-                                String createSequenceTable = Sequence.getCreateTableStatement(nSaltBuckets);
-                                metaConnection.createStatement().executeUpdate(createSequenceTable);
-                                nSequenceSaltBuckets = nSaltBuckets;
-                            } catch (NewerTableAlreadyExistsException e) {
-                                // Ignore, as this will happen if the SYSTEM.SEQUENCE already exists at this fixed timestamp.
-                                // A TableAlreadyExistsException is not thrown, since the table only exists *after* this fixed timestamp.
-                                nSequenceSaltBuckets = getSaltBuckets(e);
-                            } catch (TableAlreadyExistsException e) {
-                                if (upgradeSystemTables) {
-                                    // This will occur if we have an older SYSTEM.SEQUENCE and we need to update it to include
-                                    // any new columns we've added.
+                            Properties scnProps = PropertiesUtil.deepCopy(props);
+                            scnProps.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
+                                    Long.toString(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP));
+                            scnProps.remove(PhoenixRuntime.TENANT_ID_ATTRIB);
+                            String globalUrl = JDBCUtil.removeProperty(url, PhoenixRuntime.TENANT_ID_ATTRIB);
+                            try (PhoenixConnection metaConnection = new PhoenixConnection(ConnectionQueryServicesImpl.this, globalUrl,
+                                    scnProps, newEmptyMetaData())) {
+                                try {
+                                    metaConnection.createStatement().executeUpdate(QueryConstants.CREATE_TABLE_METADATA);
+                                } catch (NewerTableAlreadyExistsException ignore) {
+                                    // Ignore, as this will happen if the SYSTEM.CATALOG already exists at this fixed
+                                    // timestamp. A TableAlreadyExistsException is not thrown, since the table only exists
+                                    // *after* this fixed timestamp.
+                                } catch (TableAlreadyExistsException e) {
                                     long currentServerSideTableTimeStamp = e.getTable().getTimeStamp();
-                                    if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0) {
-                                        // If the table time stamp is before 4.1.0 then we need to add below columns
-                                        // to the SYSTEM.SEQUENCE table.
-                                        String columnsToAdd = PhoenixDatabaseMetaData.MIN_VALUE + " " + PLong.INSTANCE.getSqlTypeName()
-                                                + ", " + PhoenixDatabaseMetaData.MAX_VALUE + " " + PLong.INSTANCE.getSqlTypeName()
-                                                + ", " + PhoenixDatabaseMetaData.CYCLE_FLAG + " " + PBoolean.INSTANCE.getSqlTypeName()
-                                                + ", " + PhoenixDatabaseMetaData.LIMIT_REACHED_FLAG + " " + PBoolean.INSTANCE.getSqlTypeName();
-                                        addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG,
-                                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP, columnsToAdd);
-                                    }
-                                    // If the table timestamp is before 4.2.1 then run the upgrade script
-                                    if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_2_1) {
-                                        if (UpgradeUtil.upgradeSequenceTable(metaConnection, nSaltBuckets, e.getTable())) {
-                                            metaConnection.removeTable(null,
-                                                   PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_SCHEMA,
-                                                   PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_TABLE,
-                                                   MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP);
-                                            clearTableFromCache(ByteUtil.EMPTY_BYTE_ARRAY,
-                                                   PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_SCHEMA_BYTES,
-                                                   PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_TABLE_BYTES,
-                                                   MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP);
-                                            clearTableRegionCache(PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_NAME_BYTES);
-                                        }
-                                        nSequenceSaltBuckets = nSaltBuckets;
-                                    } else {
-                                        nSequenceSaltBuckets = getSaltBuckets(e);
+                                    if (currentServerSideTableTimeStamp < MIN_SYSTEM_TABLE_TIMESTAMP) {
+                                        ConnectionQueryServicesImpl.this.upgradeRequired.set(true);
                                     }
                                 }
-                            }
-                            try {
-                                metaConnection.createStatement().executeUpdate(
-                                        QueryConstants.CREATE_STATS_TABLE_METADATA);
-                            } catch (NewerTableAlreadyExistsException ignore) {
-                            } catch(TableAlreadyExistsException e) {
-                                if (upgradeSystemTables) {
-                                    long currentServerSideTableTimeStamp = e.getTable().getTimeStamp();
-                                    if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_3_0) {
-                                        metaConnection = addColumnsIfNotExists(
-                                               metaConnection,
-                                               SYSTEM_STATS_NAME,
-                                               MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP,
-                                               PhoenixDatabaseMetaData.GUIDE_POSTS_ROW_COUNT + " "
-                                                       + PLong.INSTANCE.getSqlTypeName());
-                                    }
+                                if (!ConnectionQueryServicesImpl.this.upgradeRequired.get()) {
+                                    createOtherSystemTables(metaConnection);
+                                } else if (isAutoUpgradeEnabled && !isDoNotUpgradePropSet) {
+                                    upgradeSystemTables(url, props);
                                 }
                             }
-                            try {
-                                metaConnection.createStatement().executeUpdate(
-                                        QueryConstants.CREATE_FUNCTION_METADATA);
-                            } catch (NewerTableAlreadyExistsException e) {
-                            } catch (TableAlreadyExistsException e) {
-                            }
-                            if (SchemaUtil.isNamespaceMappingEnabled(PTableType.SYSTEM,
-                                    ConnectionQueryServicesImpl.this.getProps())) {
-                                try {
-                                    metaConnection.createStatement().executeUpdate("CREATE SCHEMA IF NOT EXISTS "
-                                            + PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA);
-                                } catch (NewerSchemaAlreadyExistsException e) {}
-                            }
-                            success = true;
                             scheduleRenewLeaseTasks();
-                        } catch (UpgradeInProgressException e) {
-                            // don't set it as initializationException because otherwise client won't be able to retry
-                            throw e;
                         } catch (Exception e) {
                             if (e instanceof SQLException) {
                                 initializationException = (SQLException)e;
@@ -2579,222 +2372,517 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                                 initializationException = new SQLException(e);
                             }
                         } finally {
-                            try {
-                                if (metaConnection != null) metaConnection.close();
-                            } catch (SQLException e) {
-                                if (initializationException != null) {
-                                    initializationException.setNextException(e);
-                                } else {
-                                    initializationException = e;
-                                }
-                            } finally {
-                                try {
-                                    restoreFromSnapshot(sysCatalogTableName, snapshotName, success);
-                                } catch (SQLException e) {
-                                    if (initializationException != null) {
-                                        initializationException.setNextException(e);
-                                    } else {
-                                        initializationException = e;
-                                    }
-                                }
-                                try {
-                                    if (initializationException != null) {
-                                        throw initializationException;
-                                    }
-                                } finally {
-                                    initialized = true;
-                                }
-                            }
+                            initialized = true;
                         }
-                    }
+                    } 
                     return null;
                 }
-
-                private void createSnapshot(String snapshotName, String tableName)
-                        throws SQLException {
-                    HBaseAdmin admin = null;
-                    SQLException sqlE = null;
-                    try {
-                        admin = getAdmin();
-                        admin.snapshot(snapshotName, tableName);
-                        logger.info("Successfully created snapshot " + snapshotName + " for "
-                                + tableName);
-                    } catch (Exception e) {
-                        sqlE = new SQLException(e);
-                    } finally {
-                        try {
-                            if (admin != null) {
-                                admin.close();
-                            }
-                        } catch (Exception e) {
-                            SQLException adminCloseEx = new SQLException(e);
-                            if (sqlE == null) {
-                                sqlE = adminCloseEx;
-                            } else {
-                                sqlE.setNextException(adminCloseEx);
-                            }
-                        } finally {
-                            if (sqlE != null) {
-                                throw sqlE;
+            });
+        } catch (Exception e) {
+            Throwables.propagateIfInstanceOf(e, SQLException.class);
+            Throwables.propagate(e);
+        }
+    }
+    
+    private void createOtherSystemTables(PhoenixConnection metaConnection) throws SQLException {
+        try {
+            metaConnection.createStatement().execute(QueryConstants.CREATE_SEQUENCE_METADATA);
+        } catch (TableAlreadyExistsException ignore) {}
+        try {
+            metaConnection.createStatement().execute(QueryConstants.CREATE_STATS_TABLE_METADATA);
+        } catch (TableAlreadyExistsException ignore) {}
+        try {
+            metaConnection.createStatement().execute(QueryConstants.CREATE_FUNCTION_METADATA);
+        } catch (TableAlreadyExistsException ignore) {}
+    }
+    
+    /**
+     * There is no other locking needed here since only one connection (on the same or different JVM) will be able to
+     * acquire the upgrade mutex via {@link #acquireUpgradeMutex(long, byte[])}.
+     */
+    @Override
+    public void upgradeSystemTables(final String url, final Properties props) throws SQLException {
+        PhoenixConnection metaConnection = null;
+        boolean success = false;
+        String snapshotName = null;
+        String sysCatalogTableName = null;
+        SQLException toThrow = null;
+        try {
+            if (!ConnectionQueryServicesImpl.this.upgradeRequired.get()) {
+                throw new UpgradeNotRequiredException();
+            }
+            Properties scnProps = PropertiesUtil.deepCopy(props);
+            scnProps.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
+                    Long.toString(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP));
+            scnProps.remove(PhoenixRuntime.TENANT_ID_ATTRIB);
+            String globalUrl = JDBCUtil.removeProperty(url, PhoenixRuntime.TENANT_ID_ATTRIB);
+            metaConnection = new PhoenixConnection(ConnectionQueryServicesImpl.this, globalUrl,
+                    scnProps, newEmptyMetaData());
+            metaConnection.setRunningUpgrade(true);
+            try {
+                metaConnection.createStatement().executeUpdate(QueryConstants.CREATE_TABLE_METADATA);
+            } catch (NewerTableAlreadyExistsException ignore) {
+                // Ignore, as this will happen if the SYSTEM.CATALOG already exists at this fixed
+                // timestamp. A TableAlreadyExistsException is not thrown, since the table only exists
+                // *after* this fixed timestamp.
+            } catch (TableAlreadyExistsException e) {
+                long currentServerSideTableTimeStamp = e.getTable().getTimeStamp();
+                sysCatalogTableName = e.getTable().getPhysicalName().getString();
+                if (currentServerSideTableTimeStamp < MIN_SYSTEM_TABLE_TIMESTAMP
+                        && acquireUpgradeMutex(currentServerSideTableTimeStamp, e.getTable()
+                                .getPhysicalName().getBytes())) {
+                    snapshotName = getUpgradeSnapshotName(sysCatalogTableName,
+                            currentServerSideTableTimeStamp);
+                    createSnapshot(snapshotName, sysCatalogTableName);
+                }
+                String columnsToAdd = "";
+                // This will occur if we have an older SYSTEM.CATALOG and we need to update it to
+                // include any new columns we've added.
+                if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_3_0) {
+                    // We know that we always need to add the STORE_NULLS column for 4.3 release
+                    columnsToAdd = addColumn(columnsToAdd, PhoenixDatabaseMetaData.STORE_NULLS
+                            + " " + PBoolean.INSTANCE.getSqlTypeName());
+                    try (HBaseAdmin admin = getAdmin()) {
+                        HTableDescriptor[] localIndexTables = admin
+                                .listTables(MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX + ".*");
+                        for (HTableDescriptor table : localIndexTables) {
+                            if (table.getValue(MetaDataUtil.PARENT_TABLE_KEY) == null
+                                    && table.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_NAME) != null) {
+                                table.setValue(MetaDataUtil.PARENT_TABLE_KEY,
+                                        MetaDataUtil.getUserTableName(table.getNameAsString()));
+                                // Explicitly disable, modify and enable the table to ensure
+                                // co-location of data and index regions. If we just modify the
+                                // table descriptor when online schema change enabled may reopen 
+                                // the region in same region server instead of following data region.
+                                admin.disableTable(table.getTableName());
+                                admin.modifyTable(table.getTableName(), table);
+                                admin.enableTable(table.getTableName());
                             }
                         }
                     }
                 }
 
-                private void restoreFromSnapshot(String tableName, String snapshotName,
-                        boolean success) throws SQLException {
-                    boolean snapshotRestored = false;
-                    boolean tableDisabled = false;
-                    if (!success && snapshotName != null) {
-                        SQLException sqlE = null;
-                        HBaseAdmin admin = null;
-                        try {
-                            logger.warn("Starting restore of " + tableName + " using snapshot "
-                                    + snapshotName + " because upgrade failed");
-                            admin = getAdmin();
-                            admin.disableTable(tableName);
-                            tableDisabled = true;
-                            admin.restoreSnapshot(snapshotName);
-                            snapshotRestored = true;
-                            logger.warn("Successfully restored " + tableName + " using snapshot "
-                                    + snapshotName);
-                        } catch (Exception e) {
-                            sqlE = new SQLException(e);
-                        } finally {
-                            if (admin != null && tableDisabled) {
-                                try {
-                                    admin.enableTable(tableName);
-                                    if (snapshotRestored) {
-                                        logger.warn("Successfully restored and enabled " + tableName + " using snapshot "
-                                                + snapshotName);
-                                    } else {
-                                        logger.warn("Successfully enabled " + tableName + " after restoring using snapshot "
-                                                + snapshotName + " failed. ");
-                                    }
-                                } catch (Exception e1) {
-                                    SQLException enableTableEx = new SQLException(e1);
-                                    if (sqlE == null) {
-                                        sqlE = enableTableEx;
-                                    } else {
-                                        sqlE.setNextException(enableTableEx);
-                                    }
-                                    logger.error("Failure in enabling "
-                                            + tableName
-                                            + (snapshotRestored ? " after successfully restoring using snapshot"
-                                                    + snapshotName
-                                                    : " after restoring using snapshot "
-                                                    + snapshotName + " failed. "));
-                                } finally {
-                                    try {
-                                        admin.close();
-                                    } catch (Exception e2) {
-                                        SQLException adminCloseEx = new SQLException(e2);
-                                        if (sqlE == null) {
-                                            sqlE = adminCloseEx;
-                                        } else {
-                                            sqlE.setNextException(adminCloseEx);
-                                        }
-                                    } finally {
-                                        if (sqlE != null) {
-                                            throw sqlE;
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    }
+                // If the server side schema is before MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0 then
+                // we need to add INDEX_TYPE and INDEX_DISABLE_TIMESTAMP columns too.
+                // TODO: Once https://issues.apache.org/jira/browse/PHOENIX-1614 is fixed,
+                // we should just have a ALTER TABLE ADD IF NOT EXISTS statement with all
+                // the column names that have been added to SYSTEM.CATALOG since 4.0.
+                if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0) {
+                    columnsToAdd = addColumn(columnsToAdd, PhoenixDatabaseMetaData.INDEX_TYPE + " "
+                            + PUnsignedTinyint.INSTANCE.getSqlTypeName() + ", "
+                            + PhoenixDatabaseMetaData.INDEX_DISABLE_TIMESTAMP + " "
+                            + PLong.INSTANCE.getSqlTypeName());
                 }
 
-                private void ensureSystemTablesUpgraded(ReadOnlyProps props)
-                        throws SQLException, IOException, IllegalArgumentException, InterruptedException {
-                    if (!SchemaUtil.isNamespaceMappingEnabled(PTableType.SYSTEM, props)) { return; }
-                    HTableInterface metatable = null;
-                    try (HBaseAdmin admin = getAdmin()) {
-                        ensureNamespaceCreated(QueryConstants.SYSTEM_SCHEMA_NAME);
-                        List<HTableDescriptor> tables = Arrays
-                                .asList(admin.listTables(QueryConstants.SYSTEM_SCHEMA_NAME + "\\..*", false));
-                        List<String> tableNames = getTableNames(tables);
-                        if (tableNames.size() == 0) { return; }
-                        if (tableNames.size() > 4) { throw new IllegalArgumentException(
-                                "Expected 4 system table only but found " + tableNames.size() + ":" + tableNames); }
-                        byte[] mappedSystemTable = SchemaUtil
-                                .getPhysicalName(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES, props).getName();
-                        metatable = getTable(mappedSystemTable);
-                        if (tableNames.contains(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME)) {
-                            if (!admin.tableExists(mappedSystemTable)) {
-                                UpgradeUtil.mapTableToNamespace(admin, metatable,
-                                        PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME, props, null, PTableType.SYSTEM,
-                                        null);
-                                ConnectionQueryServicesImpl.this.removeTable(null,
-                                        PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME, null,
-                                        MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0);
-                            }
-                            tableNames.remove(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME);
-                        }
-                        for (String table : tableNames) {
-                            UpgradeUtil.mapTableToNamespace(admin, metatable, table, props, null, PTableType.SYSTEM,
-                                    null);
-                            ConnectionQueryServicesImpl.this.removeTable(null, table, null,
-                                    MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0);
+                // If we have some new columns from 4.1-4.3 to add, add them now.
+                if (!columnsToAdd.isEmpty()) {
+                    // Ugh..need to assign to another local variable to keep eclipse happy.
+                    PhoenixConnection newMetaConnection = addColumnsIfNotExists(metaConnection,
+                            PhoenixDatabaseMetaData.SYSTEM_CATALOG,
+                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_3_0, columnsToAdd);
+                    metaConnection = newMetaConnection;
+                }
+
+                if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_5_0) {
+                    columnsToAdd = PhoenixDatabaseMetaData.BASE_COLUMN_COUNT + " "
+                            + PInteger.INSTANCE.getSqlTypeName();
+                    try {
+                        metaConnection = addColumn(metaConnection,
+                                PhoenixDatabaseMetaData.SYSTEM_CATALOG,
+                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_5_0, columnsToAdd,
+                                false);
+                        upgradeTo4_5_0(metaConnection);
+                    } catch (ColumnAlreadyExistsException ignored) {
+                        /*
+                         * Upgrade to 4.5 is a slightly special case. We use the fact that the
+                         * column BASE_COLUMN_COUNT is already part of the meta-data schema as the
+                         * signal that the server side upgrade has finished or is in progress.
+                         */
+                        logger.debug("No need to run 4.5 upgrade");
+                    }
+                    Properties p = PropertiesUtil.deepCopy(metaConnection.getClientInfo());
+                    p.remove(PhoenixRuntime.CURRENT_SCN_ATTRIB);
+                    p.remove(PhoenixRuntime.TENANT_ID_ATTRIB);
+                    PhoenixConnection conn = new PhoenixConnection(
+                            ConnectionQueryServicesImpl.this, metaConnection.getURL(), p,
+                            metaConnection.getMetaDataCache());
+                    try {
+                        List<String> tablesNeedingUpgrade = UpgradeUtil
+                                .getPhysicalTablesWithDescRowKey(conn);
+                        if (!tablesNeedingUpgrade.isEmpty()) {
+                            logger.warn("The following tables require upgrade due to a bug causing the row key to be incorrect for descending columns and ascending BINARY columns (PHOENIX-2067 and PHOENIX-2120):\n"
+                                    + Joiner.on(' ').join(tablesNeedingUpgrade)
+                                    + "\nTo upgrade issue the \"bin/psql.py -u\" command.");
                         }
-                        if (!tableNames.isEmpty()) {
-                            clearCache();
+                        List<String> unsupportedTables = UpgradeUtil
+                                .getPhysicalTablesWithDescVarbinaryRowKey(conn);
+                        if (!unsupportedTables.isEmpty()) {
+                            logger.warn("The following tables use an unsupported VARBINARY DESC construct and need to be changed:\n"
+                                    + Joiner.on(' ').join(unsupportedTables));
                         }
+                    } catch (Exception ex) {
+                        logger.error(
+                                "Unable to determine tables requiring upgrade due to PHOENIX-2067",
+                                ex);
                     } finally {
-                        if (metatable != null) {
-                            metatable.close();
-                        }
+                        conn.close();
+                    }
+                }
+                // Add these columns one at a time, each with different timestamps so that if folks
+                // have
+                // run the upgrade code already for a snapshot, we'll still enter this block (and do
+                // the
+                // parts we haven't yet done).
+                if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_6_0) {
+                    columnsToAdd = PhoenixDatabaseMetaData.IS_ROW_TIMESTAMP + " "
+                            + PBoolean.INSTANCE.getSqlTypeName();
+                    metaConnection = addColumnsIfNotExists(metaConnection,
+                            PhoenixDatabaseMetaData.SYSTEM_CATALOG,
+                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_6_0, columnsToAdd);
+                }
+                if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0) {
+                    // Drop old stats table so that new stats table is created
+                    metaConnection = dropStatsTable(metaConnection,
+                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 4);
+                    metaConnection = addColumnsIfNotExists(
+                            metaConnection,
+                            PhoenixDatabaseMetaData.SYSTEM_CATALOG,
+                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 3,
+                            PhoenixDatabaseMetaData.TRANSACTIONAL + " "
+                                    + PBoolean.INSTANCE.getSqlTypeName());
+                    metaConnection = addColumnsIfNotExists(
+                            metaConnection,
+                            PhoenixDatabaseMetaData.SYSTEM_CATALOG,
+                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 2,
+                            PhoenixDatabaseMetaData.UPDATE_CACHE_FREQUENCY + " "
+                                    + PLong.INSTANCE.getSqlTypeName());
+                    metaConnection = setImmutableTableIndexesImmutable(metaConnection,
+                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 1);
+                    metaConnection = updateSystemCatalogTimestamp(metaConnection,
+                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0);
+                    ConnectionQueryServicesImpl.this.removeTable(null,
+                            PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME, null,
+                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0);
+                    clearCache();
+                }
+
+                if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0) {
+                    metaConnection = addColumnsIfNotExists(
+                            metaConnection,
+                            PhoenixDatabaseMetaData.SYSTEM_CATALOG,
+                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0 - 2,
+                            PhoenixDatabaseMetaData.IS_NAMESPACE_MAPPED + " "
+                                    + PBoolean.INSTANCE.getSqlTypeName());
+                    metaConnection = addColumnsIfNotExists(
+                            metaConnection,
+                            PhoenixDatabaseMetaData.SYSTEM_CATALOG,
+                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0 - 1,
+                            PhoenixDatabaseMetaData.AUTO_PARTITION_SEQ + " "
+                                    + PVarchar.INSTANCE.getSqlTypeName());
+                    metaConnection = addColumnsIfNotExists(
+                            metaConnection,
+                            PhoenixDatabaseMetaData.SYSTEM_CATALOG,
+                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0,
+                            PhoenixDatabaseMetaData.APPEND_ONLY_SCHEMA + " "
+                                    + PBoolean.INSTANCE.getSqlTypeName());
+                    metaConnection = UpgradeUtil.disableViewIndexes(metaConnection);
+                    if (getProps().getBoolean(QueryServices.LOCAL_INDEX_CLIENT_UPGRADE_ATTRIB,
+                            QueryServicesOptions.DEFAULT_LOCAL_INDEX_CLIENT_UPGRADE)) {
+                        metaConnection = UpgradeUtil.upgradeLocalIndexes(metaConnection);
                     }
+                    ConnectionQueryServicesImpl.this.removeTable(null,
+                            PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME, null,
+                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0);
+                    clearCache();
                 }
+            }
+
 
-                /**
-                 * Acquire distributed mutex of sorts to make sure only one JVM is able to run the upgrade code by
-                 * making use of HBase's checkAndPut api.
-                 * <p>
-                 * This method was added as part of 4.8.1 release. For clients upgrading to 4.8.1, the old value in the
-                 * version cell will be null i.e. the {@value QueryConstants#UPGRADE_MUTEX} column will be non-existent. For client's
-                 * upgrading to a release newer than 4.8.1 the existing version cell will be non-null. The client which
-                 * wins the race will end up setting the version cell to the {@value MetaDataProtocol#MIN_SYSTEM_TABLE_TIMESTAMP}
-                 * for the release.
-                 * </p>
-                 *
-                 * @return true if client won the race, false otherwise
-                 * @throws IOException
-                 * @throws SQLException
-                 */
-                private boolean acquireUpgradeMutex(long currentServerSideTableTimestamp, byte[] sysCatalogTableName) throws IOException,
-                SQLException {
-                    Preconditions.checkArgument(currentServerSideTableTimestamp < MIN_SYSTEM_TABLE_TIMESTAMP);
-                    try (HTableInterface sysCatalogTable = getTable(sysCatalogTableName)) {
-                        byte[] row = SchemaUtil.getTableKey(null, PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA,
-                                PhoenixDatabaseMetaData.SYSTEM_CATALOG_TABLE);
-                        byte[] family = PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES;
-                        byte[] qualifier = QueryConstants.UPGRADE_MUTEX;
-                        byte[] oldValue = currentServerSideTableTimestamp < MIN_SYSTEM_TABLE_TIMESTAMP_4_8_1 ? null
-                                : PLong.INSTANCE.toBytes(currentServerSideTableTimestamp);
-                        byte[] newValue = PLong.INSTANCE.toBytes(MIN_SYSTEM_TABLE_TIMESTAMP);
-                        // Note that the timestamp for this put doesn't really matter since UPGRADE_MUTEX column isn't used
-                        // to calculate SYSTEM.CATALOG's server side timestamp.
-                        Put put = new Put(row);
-                        put.add(family, qualifier, newValue);
-                        boolean acquired = sysCatalogTable.checkAndPut(row, family, qualifier, oldValue, put);
-                        if (!acquired) { throw new UpgradeInProgressException(
-                                getVersion(currentServerSideTableTimestamp), getVersion(MIN_SYSTEM_TABLE_TIMESTAMP)); }
-                        return true;
+            int nSaltBuckets = ConnectionQueryServicesImpl.this.props.getInt(
+                    QueryServices.SEQUENCE_SALT_BUCKETS_ATTRIB,
+                    QueryServicesOptions.DEFAULT_SEQUENCE_TABLE_SALT_BUCKETS);
+            try {
+                String createSequenceTable = Sequence.getCreateTableStatement(nSaltBuckets);
+                metaConnection.createStatement().executeUpdate(createSequenceTable);
+                nSequenceSaltBuckets = nSaltBuckets;
+            } catch (NewerTableAlreadyExistsException e) {
+                // Ignore, as this will happen if the SYSTEM.SEQUENCE already exists at this fixed
+                // timestamp.
+                // A TableAlreadyExistsException is not thrown, since the table only exists *after* this
+                // fixed timestamp.
+                nSequenceSaltBuckets = getSaltBuckets(e);
+            } catch (TableAlreadyExistsException e) {
+                // This will occur if we have an older SYSTEM.SEQUENCE and we need to update it to
+                // include
+                // any new columns we've added.
+                long currentServerSideTableTimeStamp = e.getTable().getTimeStamp();
+                if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0) {
+                    // If the table time stamp is before 4.1.0 then we need to add below columns
+                    // to the SYSTEM.SEQUENCE table.
+                    String columnsToAdd = PhoenixDatabaseMetaData.MIN_VALUE + " "
+                            + PLong.INSTANCE.getSqlTypeName() + ", "
+                            + PhoenixDatabaseMetaData.MAX_VALUE + " "
+                            + PLong.INSTANCE.getSqlTypeName() + ", "
+                            + PhoenixDatabaseMetaData.CYCLE_FLAG + " "
+                            + PBoolean.INSTANCE.getSqlTypeName() + ", "
+                            + PhoenixDatabaseMetaData.LIMIT_REACHED_FLAG + " "
+                            + PBoolean.INSTANCE.getSqlTypeName();
+                    addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG,
+                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP, columnsToAdd);
+                }
+                // If the table timestamp is before 4.2.1 then run the upgrade script
+                if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_2_1) {
+                    if (UpgradeUtil.upgradeSequenceTable(metaConnection, nSaltBuckets, e.getTable())) {
+                        metaConnection.removeTable(null,
+                                PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_SCHEMA,
+                                PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_TABLE,
+                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP);
+                        clearTableFromCache(ByteUtil.EMPTY_BYTE_ARRAY,
+                                PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_SCHEMA_BYTES,
+                                PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_TABLE_BYTES,
+                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP);
+                        clearTableRegionCache(PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_NAME_BYTES);
                     }
+                    nSequenceSaltBuckets = nSaltBuckets;
+                } else {
+                    nSequenceSaltBuckets = getSaltBuckets(e);
                 }
-            });
+            }
+            try {
+                metaConnection.createStatement().executeUpdate(
+                        QueryConstants.CREATE_STATS_TABLE_METADATA);
+            } catch (NewerTableAlreadyExistsException ignore) {} catch (TableAlreadyExistsException e) {
+                long currentServerSideTableTimeStamp = e.getTable().getTimeStamp();
+                if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_3_0) {
+                    metaConnection = addColumnsIfNotExists(
+                            metaConnection,
+                            SYSTEM_STATS_NAME,
+                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP,
+                            PhoenixDatabaseMetaData.GUIDE_POSTS_ROW_COUNT + " "
+                                    + PLong.INSTANCE.getSqlTypeName());
+                }
+            }
+            try {
+                metaConnection.createStatement().executeUpdate(QueryConstants.CREATE_FUNCTION_METADATA);
+            } catch (NewerTableAlreadyExistsException e) {} catch (TableAlreadyExistsException e) {}
+            if (SchemaUtil.isNamespaceMappingEnabled(PTableType.SYSTEM,
+                    ConnectionQueryServicesImpl.this.getProps())) {
+                try {
+                    metaConnection.createStatement().executeUpdate(
+                            "CREATE SCHEMA IF NOT EXISTS "
+                                    + PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA);
+                } catch (NewerSchemaAlreadyExistsException e) {}
+            }
+            ConnectionQueryServicesImpl.this.upgradeRequired.set(false);
+            success = true;
+        } catch (UpgradeInProgressException | UpgradeNotRequiredException e) {
+            // don't set it as initializationException because otherwise client won't be able to retry
+            throw e;
         } catch (Exception e) {
-            Throwables.propagateIfInstanceOf(e, SQLException.class);
-            Throwables.propagate(e);
+            if (e instanceof SQLException) {
+                toThrow = (SQLException)e;
+            } else {
+                // wrap every other exception into a SQLException
+                toThrow = new SQLException(e);
+            }
+        } finally {
+            try {
+                if (metaConnection != null) {
+                    metaConnection.close();
+                }
+            } catch (SQLException e) {
+                if (toThrow != null) {
+                    toThrow.setNextException(e);
+                } else {
+                    toThrow = e;
+                }
+            } finally {
+                try {
+                    restoreFromSnapshot(sysCatalogTableName, snapshotName, success);
+                } catch (SQLException e) {
+                    if (toThrow != null) {
+                        toThrow.setNextException(e);
+                    } else {
+                        toThrow = e;
+                    }
+                }
+                if (toThrow != null) { throw toThrow; }
+            }
+        }
+    }
+
+    private void createSnapshot(String snapshotName, String tableName)
+            throws SQLException {
+        HBaseAdmin admin = null;
+        SQLException sqlE = null;
+        try {
+            admin = getAdmin();
+            admin.snapshot(snapshotName, tableName);
+            logger.info("Successfully created snapshot " + snapshotName + " for "
+                    + tableName);
+        } catch (Exception e) {
+            sqlE = new SQLException(e);
+        } finally {
+            try {
+                if (admin != null) {
+                    admin.close();
+                }
+            } catch (Exception e) {
+                SQLException adminCloseEx = new SQLException(e);
+                if (sqlE == null) {
+                    sqlE = adminCloseEx;
+                } else {
+                    sqlE.setNextException(adminCloseEx);
+                }
+            } finally {
+                if (sqlE != null) {
+                    throw sqlE;
+                }
+            }
         }
     }
 
-    private static class UpgradeInProgressException extends SQLException {
-        public UpgradeInProgressException(String upgradeFrom, String upgradeTo) {
-            super("Cluster is being concurrently upgraded from " + upgradeFrom + " to " + upgradeTo
-                    + ". Please retry establishing connection.", SQLExceptionCode.CONCURRENT_UPGRADE_IN_PROGRESS
-                    .getSQLState(), SQLExceptionCode.CONCURRENT_UPGRADE_IN_PROGRESS.getErrorCode());
+    private void restoreFromSnapshot(String tableName, String snapshotName,
+            boolean success) throws SQLException {
+        boolean snapshotRestored = false;
+        boolean tableDisabled = false;
+        if (!success && snapshotName != null) {
+            SQLException sqlE = null;
+            HBaseAdmin admin = null;
+            try {
+                logger.warn("Starting restore of " + tableName + " using snapshot "
+                        + snapshotName + " because upgrade failed");
+                admin = getAdmin();
+                admin.disableTable(tableName);
+                tableDisabled = true;
+                admin.restoreSnapshot(snapshotName);
+                snapshotRestored = true;
+                logger.warn("Successfully restored " + tableName + " using snapshot "
+                        + snapshotName);
+            } catch (Exception e) {
+                sqlE = new SQLException(e);
+            } finally {
+                if (admin != null && tableDisabled) {
+                    try {
+                        admin.enableTable(tableName);
+                        if (snapshotRestored) {
+                            logger.warn("Successfully restored and enabled " + tableName + " using snapshot "
+                                    + snapshotName);
+                        } else {
+                            logger.warn("Successfully enabled " + tableName + " after restoring using snapshot "
+                                    + snapshotName + " failed. ");
+                        }
+                    } catch (Exception e1) {
+                        SQLException enableTableEx = new SQLException(e1);
+                        if (sqlE == null) {
+                            sqlE = enableTableEx;
+                        } else {
+                            sqlE.setNextException(enableTableEx);
+                        }
+                        logger.error("Failure in enabling "
+                                + tableName
+                                + (snapshotRestored ? " after successfully restoring using snapshot"
+                                        + snapshotName
+                                        : " after restoring using snapshot "
+                                                + snapshotName + " failed. "));
+                    } finally {
+                        try {
+                            admin.close();
+                        } catch (Exception e2) {
+                            SQLException adminCloseEx = new SQLException(e2);
+                            if (sqlE == null) {
+                                sqlE = adminCloseEx;
+                            } else {
+                                sqlE.setNextException(adminCloseEx);
+                            }
+                        } finally {
+                            if (sqlE != null) {
+                                throw sqlE;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+    
+    private void ensureSystemTablesUpgraded(ReadOnlyProps props)
+            throws SQLException, IOException, IllegalArgumentException, InterruptedException {
+        if (!SchemaUtil.isNamespaceMappingEnabled(PTableType.SYSTEM, props)) { return; }
+        HTableInterface metatable = null;
+        try (HBaseAdmin admin = getAdmin()) {
+            ensureNamespaceCreated(QueryConstants.SYSTEM_SCHEMA_NAME);
+            List<HTableDescriptor> tables = Arrays
+                    .asList(admin.listTables(QueryConstants.SYSTEM_SCHEMA_NAME + "\\..*"));
+            List<String> tableNames = getTableNames(tables);
+            if (tableNames.size() == 0) { return; }
+            if (tableNames.size() > 4) { throw new IllegalArgumentException(
+                    "Expected 4 system table only but found " + tableNames.size() + ":" + tableNames); }
+            byte[] mappedSystemTable = SchemaUtil
+                    .getPhysicalName(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES, props).getName();
+            metatable = getTable(mappedSystemTable);
+            if (tableNames.contains(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME)) {
+                if (!admin.tableExists(mappedSystemTable)) {
+                    UpgradeUtil.mapTableToNamespace(admin, metatable,
+                            PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME, props, null, PTableType.SYSTEM,
+                            null);
+                    ConnectionQueryServicesImpl.this.removeTable(null,
+                            PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME, null,
+                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0);
+                }
+                tableNames.remove(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME);
+            }
+            for (String table : tableNames) {
+                UpgradeUtil.mapTableToNamespace(admin, metatable, table, props, null, PTableType.SYSTEM,
+                        null);
+                ConnectionQueryServicesImpl.this.removeTable(null, table, null,
+                        MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0);
+            }
+            if (!tableNames.isEmpty()) {
+                clearCache();
+            }
+        } finally {
+            if (metatable != null) {
+                metatable.close();
+            }
+        }
+    }
+    
+    /**
+     * Acquire distributed mutex of sorts to make sure only one JVM is able to run the upgrade code by
+     * making use of HBase's checkAndPut api.
+     * <p>
+     * This method was added as part of 4.8.1 release. For clients upgrading to 4.8.1, the old value in the
+     * cell will be null i.e. the {@value QueryConstants#UPGRADE_MUTEX} column will be non-existent. For client's
+     * upgrading to a release newer than 4.8.1 the existing cell value will be non-null. The client which
+     * wins the race will end up setting the cell value to the {@value MetaDataProtocol#MIN_SYSTEM_TABLE_TIMESTAMP}
+     * for the release.
+     * </p>
+     * 
+     * @return true if client won the race, false otherwise
+     * @throws IOException
+     * @throws SQLException
+     */
+    @VisibleForTesting
+    public boolean acquireUpgradeMutex(long currentServerSideTableTimestamp, byte[] sysCatalogTableName) throws IOException,
+            SQLException {
+        Preconditions.checkArgument(currentServerSideTableTimestamp < MIN_SYSTEM_TABLE_TIMESTAMP);
+        try (HTableInterface sysCatalogTable = getTable(sysCatalogTableName)) {
+            byte[] row = SchemaUtil.getTableKey(null, PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA,
+                    PhoenixDatabaseMetaData.SYSTEM_CATALOG_TABLE);
+            byte[] family = PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES;
+            byte[] qualifier = QueryConstants.UPGRADE_MUTEX;
+            byte[] oldValue = currentServerSideTableTimestamp < MIN_SYSTEM_TABLE_TIMESTAMP_4_8_1 ? null
+                    : PLong.INSTANCE.toBytes(currentServerSideTableTimestamp);
+            byte[] newValue = PLong.INSTANCE.toBytes(MIN_SYSTEM_TABLE_TIMESTAMP);
+            // Note that the timestamp for this put doesn't really matter since UPGRADE_MUTEX column isn't used
+            // to calculate SYSTEM.CATALOG's server side timestamp.
+            Put put = new Put(row);
+            put.addColumn(family, qualifier, newValue);
+            boolean acquired = sysCatalogTable.checkAndPut(row, family, qualifier, oldValue, put);
+            if (!acquired) { throw new UpgradeInProgressException(
+                    getVersion(currentServerSideTableTimestamp), getVersion(MIN_SYSTEM_TABLE_TIMESTAMP)); }
+            return true;
         }
     }
 
@@ -3879,4 +3967,9 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
     public void invalidateStats(ImmutableBytesPtr tableName) {
         this.tableStatsCache.invalidate(Objects.requireNonNull(tableName));
     }
+
+    @Override
+    public boolean isUpgradeRequired() {
+        return upgradeRequired.get();
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
index 560b5d9..337e43c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
@@ -650,4 +650,12 @@ public class ConnectionlessQueryServicesImpl extends DelegateQueryServices imple
     public void invalidateStats(ImmutableBytesPtr tableName) {
         this.tableStatsCache.invalidate(Objects.requireNonNull(tableName));
     }
+
+    @Override
+    public void upgradeSystemTables(String url, Properties props) throws SQLException {}
+
+    @Override
+    public boolean isUpgradeRequired() {
+        return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java b/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
index 99ad59c..81517e3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
@@ -345,4 +345,14 @@ public class DelegateConnectionQueryServices extends DelegateQueryServices imple
     public void invalidateStats(ImmutableBytesPtr tableName) {
         getDelegate().invalidateStats(tableName);
     }
+
+    @Override
+    public void upgradeSystemTables(String url, Properties props) throws SQLException {
+        getDelegate().upgradeSystemTables(url, props);
+    }
+
+    @Override
+    public boolean isUpgradeRequired() {
+        return getDelegate().isUpgradeRequired();
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
index 8cd009a..51a18d4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
@@ -224,6 +224,7 @@ public interface QueryServices extends SQLCloseable {
     public static final String INDEX_ASYNC_BUILD_ENABLED = "phoenix.index.async.build.enabled";
     
     public static final String CLIENT_CACHE_ENCODING = "phoenix.table.client.cache.encoding";
+    public static final String AUTO_UPGRADE_ENABLED = "phoenix.autoupgrade.enabled";
     /**
      * Get executor service used for parallel scans
      */

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
index 669bcd2..9b87361 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
@@ -20,6 +20,7 @@ package org.apache.phoenix.query;
 import static org.apache.hadoop.hbase.HConstants.DEFAULT_HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD;
 import static org.apache.phoenix.query.QueryServices.ALLOW_ONLINE_TABLE_SCHEMA_UPDATE;
 import static org.apache.phoenix.query.QueryServices.ALLOW_VIEWS_ADD_NEW_CF_BASE_TABLE;
+import static org.apache.phoenix.query.QueryServices.AUTO_UPGRADE_ENABLED;
 import static org.apache.phoenix.query.QueryServices.CALL_QUEUE_PRODUCER_ATTRIB_NAME;
 import static org.apache.phoenix.query.QueryServices.CALL_QUEUE_ROUND_ROBIN_ATTRIB;
 import static org.apache.phoenix.query.QueryServices.COLLECT_REQUEST_LEVEL_METRICS;
@@ -257,6 +258,7 @@ public class QueryServicesOptions {
     public static final boolean DEFAULT_INDEX_ASYNC_BUILD_ENABLED = true;
     
     public static final String DEFAULT_CLIENT_CACHE_ENCODING = PTableRefFactory.Encoding.OBJECT.toString();
+    public static final boolean DEFAULT_AUTO_UPGRADE_ENABLED = true;
 
     @SuppressWarnings("serial")
     public static final Set<String> DEFAULT_QUERY_SERVER_SKIP_WORDS = new HashSet<String>() {
@@ -334,7 +336,8 @@ public class QueryServicesOptions {
             .setIfUnset(RENEW_LEASE_THREAD_POOL_SIZE, DEFAULT_RENEW_LEASE_THREAD_POOL_SIZE)
             .setIfUnset(IS_NAMESPACE_MAPPING_ENABLED, DEFAULT_IS_NAMESPACE_MAPPING_ENABLED)
             .setIfUnset(IS_SYSTEM_TABLE_MAPPED_TO_NAMESPACE, DEFAULT_IS_SYSTEM_TABLE_MAPPED_TO_NAMESPACE)
-            .setIfUnset(LOCAL_INDEX_CLIENT_UPGRADE_ATTRIB, DEFAULT_LOCAL_INDEX_CLIENT_UPGRADE);
+            .setIfUnset(LOCAL_INDEX_CLIENT_UPGRADE_ATTRIB, DEFAULT_LOCAL_INDEX_CLIENT_UPGRADE)
+            .setIfUnset(AUTO_UPGRADE_ENABLED, DEFAULT_AUTO_UPGRADE_ENABLED);
         // HBase sets this to 1, so we reset it to something more appropriate.
         // Hopefully HBase will change this, because we can't know if a user set
         // it to 1, so we'll change it.

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index 28ed11d..73f1501 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -3406,7 +3406,7 @@ public class MetaDataClient {
                                 String indexTenantId = entry.getKey();
                                 Properties props = new Properties(connection.getClientInfo());
                                 props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, indexTenantId);
-                                try (PhoenixConnection tenantConn = DriverManager.getConnection(connection.getURL(), props).unwrap(PhoenixConnection.class)) {
+                                try (PhoenixConnection tenantConn = new PhoenixConnection(connection, connection.getQueryServices(), props)) {
                                     PostDDLCompiler dropCompiler = new PostDDLCompiler(tenantConn);
                                     tenantConn.getQueryServices().updateData(dropCompiler.compile(entry.getValue(), null, null, Collections.<PColumn>emptyList(), ts));
                                 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/trace/PhoenixMetricsSink.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/trace/PhoenixMetricsSink.java b/phoenix-core/src/main/java/org/apache/phoenix/trace/PhoenixMetricsSink.java
index a8e80ab..fea6d61 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/trace/PhoenixMetricsSink.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/trace/PhoenixMetricsSink.java
@@ -38,16 +38,23 @@ import org.apache.commons.configuration.SubsetConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.TableNotDisabledException;
 import org.apache.hadoop.metrics2.AbstractMetric;
 import org.apache.hadoop.metrics2.MetricsRecord;
 import org.apache.hadoop.metrics2.MetricsSink;
 import org.apache.hadoop.metrics2.MetricsTag;
+import org.apache.phoenix.compile.MutationPlan;
+import org.apache.phoenix.execute.MutationState;
+import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.jdbc.PhoenixPreparedStatement;
 import org.apache.phoenix.metrics.MetricInfo;
 import org.apache.phoenix.metrics.Metrics;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.trace.util.Tracing;
+import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.QueryUtil;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -93,7 +100,7 @@ public class PhoenixMetricsSink implements MetricsSink {
     private Connection conn;
 
     private String table;
-
+    
     public PhoenixMetricsSink() {
         LOG.info("Writing tracing metrics to phoenix table");
 
@@ -133,14 +140,25 @@ public class PhoenixMetricsSink implements MetricsSink {
             }
         }
     }
-
+    
     private void initializeInternal(Connection conn, String tableName) throws SQLException {
         this.conn = conn;
-
         // ensure that the target table already exists
-        createTable(conn, tableName);
+        if (!traceTableExists(conn, tableName)) {
+            createTable(conn, tableName);
+        }
+        this.table = tableName;
     }
-
+    
+    private boolean traceTableExists(Connection conn, String traceTableName) throws SQLException {
+        try {
+            PhoenixRuntime.getTable(conn, traceTableName);
+            return true;
+        } catch (TableNotFoundException e) {
+            return false;
+        }
+    }
+    
     /**
      * Used for <b>TESTING ONLY</b>
      * Initialize the connection and setup the table to use the
@@ -183,10 +201,8 @@ public class PhoenixMetricsSink implements MetricsSink {
                         // tables created as transactional tables, make these table non
                         // transactional
                         PhoenixDatabaseMetaData.TRANSACTIONAL + "=" + Boolean.FALSE;
-;
         PreparedStatement stmt = conn.prepareStatement(ddl);
         stmt.execute();
-        this.table = table;
     }
 
     @Override
@@ -281,7 +297,12 @@ public class PhoenixMetricsSink implements MetricsSink {
             for (String tag : variableValues) {
                 ps.setString(index++, tag);
             }
-            ps.execute();
+            // Not going through the standard route of using statement.execute() as that code path
+            // is blocked if the metadata hasn't been been upgraded to the new minor release. 
+            MutationPlan plan = ps.unwrap(PhoenixPreparedStatement.class).compileMutation(stmt);
+            MutationState state = conn.unwrap(PhoenixConnection.class).getMutationState();
+            MutationState newState = plan.execute();
+            state.join(newState);
         } catch (SQLException e) {
             LOG.error("Could not write metric: \n" + record + " to prepared statement:\n" + stmt,
                     e);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
index a690dd8..764d135 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
@@ -172,7 +172,6 @@ public class PhoenixRuntime {
             AUTO_COMMIT_ATTRIB,
             CONSISTENCY_ATTRIB,
             REQUEST_METRIC_ATTRIB,
-            NO_UPGRADE_ATTRIB
             };
 
     /**
@@ -215,6 +214,7 @@ public class PhoenixRuntime {
                 props.setProperty(QueryServices.LOCAL_INDEX_CLIENT_UPGRADE_ATTRIB, "false");
             }
             conn = DriverManager.getConnection(jdbcUrl, props).unwrap(PhoenixConnection.class);
+            conn.setRunningUpgrade(true);
             if (execCmd.isMapNamespace()) {
                 String srcTable = execCmd.getSrcTable();
                 System.out.println("Starting upgrading table:" + srcTable + "... please don't kill it in between!!");

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java
index 6d8e00d..bab52a4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java
@@ -310,7 +310,7 @@ public final class QueryUtil {
     }
 
     /**
-     * @return {@link PhoenixConnection} with NO_UPGRADE_ATTRIB set so that we don't initiate server upgrade
+     * @return {@link PhoenixConnection} with {@value UpgradeUtil#RUN_UPGRADE} set so that we don't initiate server upgrade
      */
     public static Connection getConnectionOnServer(Configuration conf) throws ClassNotFoundException,
             SQLException {
@@ -318,12 +318,12 @@ public final class QueryUtil {
     }
 
     /**
-     * @return {@link PhoenixConnection} with NO_UPGRADE_ATTRIB set so that we don't initiate server upgrade
+     * @return {@link PhoenixConnection} with {@value UpgradeUtil#DO_NOT_UPGRADE} set so that we don't initiate metadata upgrade.
      */
     public static Connection getConnectionOnServer(Properties props, Configuration conf)
             throws ClassNotFoundException,
             SQLException {
-        props.setProperty(PhoenixRuntime.NO_UPGRADE_ATTRIB, Boolean.TRUE.toString());
+        UpgradeUtil.doNotUpgradeOnFirstConnection(props);
         return getConnection(props, conf);
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
index 8bc3e63..cddebb7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
@@ -132,7 +132,12 @@ public class UpgradeUtil {
     private static final Logger logger = LoggerFactory.getLogger(UpgradeUtil.class);
     private static final byte[] SEQ_PREFIX_BYTES = ByteUtil.concat(QueryConstants.SEPARATOR_BYTE_ARRAY, Bytes.toBytes("_SEQ_"));
     public static final byte[] UPGRADE_TO_4_7_COLUMN_NAME = Bytes.toBytes("UPGRADE_TO_4_7");
-    
+    /**
+     * Attribute for Phoenix's internal purposes only. When this attribute is set on a phoenix connection, then
+     * the upgrade code for upgrading the cluster to the new minor release is not triggered. Note that presence 
+     * of this attribute overrides a true value for {@value QueryServices#AUTO_UPGRADE_ENABLED}.     
+     */
+    private static final String DO_NOT_UPGRADE = "DoNotUpgrade";
     public static String UPSERT_BASE_COLUMN_COUNT_IN_HEADER_ROW = "UPSERT "
             + "INTO SYSTEM.CATALOG "
             + "(TENANT_ID, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, COLUMN_FAMILY, BASE_COLUMN_COUNT) "
@@ -174,7 +179,7 @@ public class UpgradeUtil {
             + " FROM " + SYSTEM_CATALOG_SCHEMA + "." + SYSTEM_CATALOG_TABLE + " WHERE " + COLUMN_FAMILY + " = ? AND "
             + LINK_TYPE + " = " + LinkType.PHYSICAL_TABLE.getSerializedValue() + " AND ( " + TABLE_TYPE + "=" + "'"
             + PTableType.VIEW.getSerializedValue() + "' OR " + TABLE_TYPE + " IS NULL) ORDER BY "+TENANT_ID;
-
+    
     private UpgradeUtil() {
     }
 
@@ -1498,7 +1503,7 @@ public class UpgradeUtil {
             }
             throw new SQLException(buf.toString());
         }
-        PhoenixConnection upgradeConn = new PhoenixConnection(conn, true);
+        PhoenixConnection upgradeConn = new PhoenixConnection(conn, true, true);
         try {
             upgradeConn.setAutoCommit(true);
             for (PTable table : tablesNeedingUpgrading) {
@@ -1898,4 +1903,12 @@ public class UpgradeUtil {
         String upgradingFrom = getVersion(currentSystemTableTimestamp);
         return "SNAPSHOT_" + tableString + "_" + upgradingFrom + "_TO_" + CURRENT_CLIENT_VERSION + "_" + date;
     }
+    
+    public static boolean isNoUpgradeSet(Properties props) {
+        return Boolean.compare(true, Boolean.valueOf(props.getProperty(DO_NOT_UPGRADE))) == 0;
+    }
+    
+    public static void doNotUpgradeOnFirstConnection(Properties props) {
+        props.setProperty(DO_NOT_UPGRADE, String.valueOf(true));
+    }
 }
\ No newline at end of file


[38/47] phoenix git commit: PHOENIX-3290 Move and/or combine as many NeedsOwnCluster tests to bring down test run time

Posted by ma...@apache.org.
PHOENIX-3290 Move and/or combine as many NeedsOwnCluster tests to bring down test run time


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

Branch: refs/heads/calcite
Commit: 14d16c8534f8807680b345bcb1b47fa4d03e522c
Parents: 553a587
Author: James Taylor <ja...@apache.org>
Authored: Sat Sep 17 00:05:06 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Sat Sep 17 00:07:28 2016 -0700

----------------------------------------------------------------------
 .../apache/phoenix/end2end/AlterTableIT.java    | 705 ++++++++++---------
 .../org/apache/phoenix/end2end/BaseViewIT.java  |   1 -
 .../phoenix/end2end/CsvBulkLoadToolIT.java      |   6 +-
 .../apache/phoenix/end2end/IndexExtendedIT.java | 578 +++++++++++++++
 .../org/apache/phoenix/end2end/IndexToolIT.java | 257 -------
 .../org/apache/phoenix/end2end/KeyOnlyIT.java   |   5 +-
 .../phoenix/end2end/MultiCfQueryExecIT.java     |   1 -
 .../phoenix/end2end/MutableIndexToolIT.java     | 129 ----
 .../phoenix/end2end/RoundFloorCeilFuncIT.java   | 683 ++++++++++++++++++
 .../RoundFloorCeilFunctionsEnd2EndIT.java       | 686 ------------------
 .../phoenix/end2end/TransactionalViewIT.java    |   5 +-
 .../org/apache/phoenix/end2end/UnionAllIT.java  | 288 ++++----
 .../index/ImmutableIndexWithStatsIT.java        |   5 +-
 .../end2end/index/IndexOnOwnClusterIT.java      | 324 ---------
 .../org/apache/phoenix/tx/TransactionIT.java    |   8 +-
 .../java/org/apache/phoenix/query/BaseTest.java |  30 -
 16 files changed, 1802 insertions(+), 1909 deletions(-)
----------------------------------------------------------------------



[13/47] phoenix git commit: PHOENIX-3230 Upgrade code running concurrently on different JVMs could make clients unusuable

Posted by ma...@apache.org.
PHOENIX-3230 Upgrade code running concurrently on different JVMs could make clients unusuable


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

Branch: refs/heads/calcite
Commit: df0d61179a97881b8b72595af198dbb346adfb9f
Parents: 36d500c
Author: Samarth <sa...@salesforce.com>
Authored: Thu Sep 8 20:20:59 2016 -0700
Committer: Samarth <sa...@salesforce.com>
Committed: Thu Sep 8 20:20:59 2016 -0700

----------------------------------------------------------------------
 .../phoenix/coprocessor/MetaDataProtocol.java   |  20 +-
 .../phoenix/exception/SQLExceptionCode.java     |   1 +
 .../query/ConnectionQueryServicesImpl.java      | 244 +++++++++++--------
 .../apache/phoenix/query/QueryConstants.java    |   1 +
 .../org/apache/phoenix/util/UpgradeUtil.java    |   5 +-
 5 files changed, 164 insertions(+), 107 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/df0d6117/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java
index dce89bd..20922e5 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java
@@ -19,9 +19,9 @@ package org.apache.phoenix.coprocessor;
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
+import java.util.NavigableMap;
+import java.util.TreeMap;
 
 import org.apache.hadoop.hbase.util.ByteStringer;
 import org.apache.phoenix.coprocessor.generated.MetaDataProtos;
@@ -29,7 +29,6 @@ import org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataResponse;
 import org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataService;
 import org.apache.phoenix.coprocessor.generated.PFunctionProtos;
 import org.apache.phoenix.hbase.index.util.VersionUtil;
-import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.parse.PFunction;
 import org.apache.phoenix.parse.PSchema;
 import org.apache.phoenix.schema.PColumn;
@@ -64,7 +63,7 @@ import com.google.protobuf.ByteString;
 public abstract class MetaDataProtocol extends MetaDataService {
     public static final int PHOENIX_MAJOR_VERSION = 4;
     public static final int PHOENIX_MINOR_VERSION = 8;
-    public static final int PHOENIX_PATCH_NUMBER = 0;
+    public static final int PHOENIX_PATCH_NUMBER = 1;
     public static final int PHOENIX_VERSION =
             VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER);
 
@@ -89,7 +88,7 @@ public abstract class MetaDataProtocol extends MetaDataService {
     
     // ALWAYS update this map whenever rolling out a new release (major, minor or patch release). 
     // Key is the SYSTEM.CATALOG timestamp for the version and value is the version string.
-    public static final Map<Long, String> TIMESTAMP_VERSION_MAP = new HashMap<>(10);
+    private static final NavigableMap<Long, String> TIMESTAMP_VERSION_MAP = new TreeMap<>();
     static {
         TIMESTAMP_VERSION_MAP.put(MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0, "4.1.x");
         TIMESTAMP_VERSION_MAP.put(MIN_SYSTEM_TABLE_TIMESTAMP_4_2_0, "4.2.0");
@@ -100,6 +99,7 @@ public abstract class MetaDataProtocol extends MetaDataService {
         TIMESTAMP_VERSION_MAP.put(MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0, "4.7.x");
         TIMESTAMP_VERSION_MAP.put(MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0, "4.8.x");
     }
+    
     public static final String CURRENT_CLIENT_VERSION = PHOENIX_MAJOR_VERSION + "." + PHOENIX_MINOR_VERSION + "." + PHOENIX_PATCH_NUMBER; 
     
     // TODO: pare this down to minimum, as we don't need duplicates for both table and column errors, nor should we need
@@ -401,4 +401,14 @@ public abstract class MetaDataProtocol extends MetaDataService {
             return schema;
         }
     }
+  
+    public static String getVersion(long serverTimestamp) {
+        /*
+         * It is possible that when clients are trying to run upgrades concurrently, we could be at an intermediate
+         * server timestamp. Using floorKey provides us a range based lookup where the timestamp range for a release is
+         * [timeStampForRelease, timestampForNextRelease).
+         */
+        String version = TIMESTAMP_VERSION_MAP.get(TIMESTAMP_VERSION_MAP.floorKey(serverTimestamp));
+        return version;
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/df0d6117/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
index 5a8fffa..0ccecae 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
@@ -370,6 +370,7 @@ public enum SQLExceptionCode {
     OUTDATED_JARS(2007, "INT09", "Outdated jars."),
     INDEX_METADATA_NOT_FOUND(2008, "INT10", "Unable to find cached index metadata. "),
     UNKNOWN_ERROR_CODE(2009, "INT11", "Unknown error code."),
+    CONCURRENT_UPGRADE_IN_PROGRESS(2010, "INT12", ""),
     OPERATION_TIMED_OUT(6000, "TIM01", "Operation timed out.", new Factory() {
         @Override
         public SQLException newException(SQLExceptionInfo info) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/df0d6117/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index 86217e7..c5d53c3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -19,13 +19,12 @@ package org.apache.phoenix.query;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static org.apache.hadoop.hbase.HColumnDescriptor.TTL;
 import static org.apache.phoenix.coprocessor.MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP;
+import static org.apache.phoenix.coprocessor.MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0;
 import static org.apache.phoenix.coprocessor.MetaDataProtocol.PHOENIX_MAJOR_VERSION;
 import static org.apache.phoenix.coprocessor.MetaDataProtocol.PHOENIX_MINOR_VERSION;
 import static org.apache.phoenix.coprocessor.MetaDataProtocol.PHOENIX_PATCH_NUMBER;
-import static org.apache.phoenix.util.UpgradeUtil.getUpgradeSnapshotName;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME;
+import static org.apache.phoenix.coprocessor.MetaDataProtocol.getVersion;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_SEQUENCE;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_STATS_NAME;
 import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_DROP_METADATA;
 import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_RENEW_LEASE_ENABLED;
@@ -80,6 +79,7 @@ import org.apache.hadoop.hbase.client.HConnection;
 import org.apache.hadoop.hbase.client.HTableInterface;
 import org.apache.hadoop.hbase.client.Increment;
 import org.apache.hadoop.hbase.client.Mutation;
+import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.coprocessor.Batch;
 import org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint;
@@ -88,9 +88,6 @@ import org.apache.hadoop.hbase.ipc.BlockingRpcCallback;
 import org.apache.hadoop.hbase.ipc.ServerRpcController;
 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto;
 import org.apache.hadoop.hbase.regionserver.IndexHalfStoreFileReaderGenerator;
-import org.apache.hadoop.hbase.security.User;
-import org.apache.hadoop.hbase.snapshot.RestoreSnapshotException;
-import org.apache.hadoop.hbase.snapshot.SnapshotCreationException;
 import org.apache.hadoop.hbase.util.ByteStringer;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
@@ -210,6 +207,7 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
 import com.google.common.base.Throwables;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.ImmutableList;
@@ -2331,140 +2329,141 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                                 if (upgradeSystemTables) {
                                     long currentServerSideTableTimeStamp = e.getTable().getTimeStamp();
                                     sysCatalogTableName = e.getTable().getPhysicalName().getString();
-                                    if (currentServerSideTableTimeStamp < MIN_SYSTEM_TABLE_TIMESTAMP) {
+                                    if (currentServerSideTableTimeStamp < MIN_SYSTEM_TABLE_TIMESTAMP && acquireUpgradeMutex(currentServerSideTableTimeStamp)) {
                                         snapshotName = getUpgradeSnapshotName(sysCatalogTableName, currentServerSideTableTimeStamp);
                                         createSnapshot(snapshotName, sysCatalogTableName);
                                     }
-                                        String columnsToAdd = "";
-                                        // This will occur if we have an older SYSTEM.CATALOG and we need to update it to include
-                                        // any new columns we've added.
-                                        if(currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_3_0) {
-                                            // We know that we always need to add the STORE_NULLS column for 4.3 release
-                                            columnsToAdd = addColumn(columnsToAdd, PhoenixDatabaseMetaData.STORE_NULLS + " " + PBoolean.INSTANCE.getSqlTypeName());
-                                            try (HBaseAdmin admin = getAdmin()) {
-                                                HTableDescriptor[] localIndexTables = admin.listTables(MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX+".*");
-                                                for (HTableDescriptor table : localIndexTables) {
-                                                    if (table.getValue(MetaDataUtil.PARENT_TABLE_KEY) == null
-                                                            && table.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_NAME) != null) {
-                                                        table.setValue(MetaDataUtil.PARENT_TABLE_KEY,
+                                    String columnsToAdd = "";
+                                    // This will occur if we have an older SYSTEM.CATALOG and we need to update it to include
+                                    // any new columns we've added.
+                                    if(currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_3_0) {
+                                        // We know that we always need to add the STORE_NULLS column for 4.3 release
+                                        columnsToAdd = addColumn(columnsToAdd, PhoenixDatabaseMetaData.STORE_NULLS + " " + PBoolean.INSTANCE.getSqlTypeName());
+                                        try (HBaseAdmin admin = getAdmin()) {
+                                            HTableDescriptor[] localIndexTables = admin.listTables(MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX+".*");
+                                            for (HTableDescriptor table : localIndexTables) {
+                                                if (table.getValue(MetaDataUtil.PARENT_TABLE_KEY) == null
+                                                        && table.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_NAME) != null) {
+                                                    table.setValue(MetaDataUtil.PARENT_TABLE_KEY,
                                                             MetaDataUtil.getUserTableName(table
-                                                                .getNameAsString()));
-                                                        // Explicitly disable, modify and enable the table to ensure co-location of data
-                                                        // and index regions. If we just modify the table descriptor when online schema
-                                                        // change enabled may reopen the region in same region server instead of following data region.
-                                                        admin.disableTable(table.getTableName());
-                                                        admin.modifyTable(table.getTableName(), table);
-                                                        admin.enableTable(table.getTableName());
-                                                    }
+                                                                    .getNameAsString()));
+                                                    // Explicitly disable, modify and enable the table to ensure co-location of data
+                                                    // and index regions. If we just modify the table descriptor when online schema
+                                                    // change enabled may reopen the region in same region server instead of following data region.
+                                                    admin.disableTable(table.getTableName());
+                                                    admin.modifyTable(table.getTableName(), table);
+                                                    admin.enableTable(table.getTableName());
                                                 }
                                             }
                                         }
+                                    }
 
-                                        // If the server side schema is before MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0 then
-                                        // we need to add INDEX_TYPE and INDEX_DISABLE_TIMESTAMP columns too. 
-                                        // TODO: Once https://issues.apache.org/jira/browse/PHOENIX-1614 is fixed, 
-                                        // we should just have a ALTER TABLE ADD IF NOT EXISTS statement with all 
-                                        // the column names that have been added to SYSTEM.CATALOG since 4.0. 
-                                        if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0) {
-                                            columnsToAdd = addColumn(columnsToAdd, PhoenixDatabaseMetaData.INDEX_TYPE + " " + PUnsignedTinyint.INSTANCE.getSqlTypeName()
+                                    // If the server side schema is before MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0 then
+                                    // we need to add INDEX_TYPE and INDEX_DISABLE_TIMESTAMP columns too. 
+                                    // TODO: Once https://issues.apache.org/jira/browse/PHOENIX-1614 is fixed, 
+                                    // we should just have a ALTER TABLE ADD IF NOT EXISTS statement with all 
+                                    // the column names that have been added to SYSTEM.CATALOG since 4.0. 
+                                    if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0) {
+                                        columnsToAdd = addColumn(columnsToAdd, PhoenixDatabaseMetaData.INDEX_TYPE + " " + PUnsignedTinyint.INSTANCE.getSqlTypeName()
                                                 + ", " + PhoenixDatabaseMetaData.INDEX_DISABLE_TIMESTAMP + " " + PLong.INSTANCE.getSqlTypeName());
-                                        }
+                                    }
 
-                                        // If we have some new columns from 4.1-4.3 to add, add them now.
-                                        if (!columnsToAdd.isEmpty()) {
-                                            // Ugh..need to assign to another local variable to keep eclipse happy.
-                                            PhoenixConnection newMetaConnection = addColumnsIfNotExists(metaConnection,
+                                    // If we have some new columns from 4.1-4.3 to add, add them now.
+                                    if (!columnsToAdd.isEmpty()) {
+                                        // Ugh..need to assign to another local variable to keep eclipse happy.
+                                        PhoenixConnection newMetaConnection = addColumnsIfNotExists(metaConnection,
                                                 PhoenixDatabaseMetaData.SYSTEM_CATALOG,
                                                 MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_3_0, columnsToAdd);
-                                            metaConnection = newMetaConnection;
-                                        }
+                                        metaConnection = newMetaConnection;
+                                    }
 
-                                        if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_5_0) {
-                                            columnsToAdd = PhoenixDatabaseMetaData.BASE_COLUMN_COUNT + " "
-                                                    + PInteger.INSTANCE.getSqlTypeName();
-                                            try {
-                                                metaConnection = addColumn(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG,
+                                    if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_5_0) {
+                                        columnsToAdd = PhoenixDatabaseMetaData.BASE_COLUMN_COUNT + " "
+                                                + PInteger.INSTANCE.getSqlTypeName();
+                                        try {
+                                            metaConnection = addColumn(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG,
                                                     MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_5_0, columnsToAdd, false);
-                                                upgradeTo4_5_0(metaConnection);
-                                            } catch (ColumnAlreadyExistsException ignored) {
-                                                /* 
-                                                 * Upgrade to 4.5 is a slightly special case. We use the fact that the column
-                                                 * BASE_COLUMN_COUNT is already part of the meta-data schema as the signal that
-                                                 * the server side upgrade has finished or is in progress.
-                                                 */
-                                                logger.debug("No need to run 4.5 upgrade");
+                                            upgradeTo4_5_0(metaConnection);
+                                        } catch (ColumnAlreadyExistsException ignored) {
+                                            /* 
+                                             * Upgrade to 4.5 is a slightly special case. We use the fact that the column
+                                             * BASE_COLUMN_COUNT is already part of the meta-data schema as the signal that
+                                             * the server side upgrade has finished or is in progress.
+                                             */
+                                            logger.debug("No need to run 4.5 upgrade");
+                                        }
+                                        Properties props = PropertiesUtil.deepCopy(metaConnection.getClientInfo());
+                                        props.remove(PhoenixRuntime.CURRENT_SCN_ATTRIB);
+                                        props.remove(PhoenixRuntime.TENANT_ID_ATTRIB);
+                                        PhoenixConnection conn = new PhoenixConnection(ConnectionQueryServicesImpl.this, metaConnection.getURL(), props, metaConnection.getMetaDataCache());
+                                        try {
+                                            List<String> tablesNeedingUpgrade = UpgradeUtil.getPhysicalTablesWithDescRowKey(conn);
+                                            if (!tablesNeedingUpgrade.isEmpty()) {
+                                                logger.warn("The following tables require upgrade due to a bug causing the row key to be incorrect for descending columns and ascending BINARY columns (PHOENIX-2067 and PHOENIX-2120):\n" + Joiner.on(' ').join(tablesNeedingUpgrade) + "\nTo upgrade issue the \"bin/psql.py -u\" command.");
                                             }
-                                            Properties props = PropertiesUtil.deepCopy(metaConnection.getClientInfo());
-                                            props.remove(PhoenixRuntime.CURRENT_SCN_ATTRIB);
-                                            props.remove(PhoenixRuntime.TENANT_ID_ATTRIB);
-                                            PhoenixConnection conn = new PhoenixConnection(ConnectionQueryServicesImpl.this, metaConnection.getURL(), props, metaConnection.getMetaDataCache());
-                                            try {
-                                                List<String> tablesNeedingUpgrade = UpgradeUtil.getPhysicalTablesWithDescRowKey(conn);
-                                                if (!tablesNeedingUpgrade.isEmpty()) {
-                                                    logger.warn("The following tables require upgrade due to a bug causing the row key to be incorrect for descending columns and ascending BINARY columns (PHOENIX-2067 and PHOENIX-2120):\n" + Joiner.on(' ').join(tablesNeedingUpgrade) + "\nTo upgrade issue the \"bin/psql.py -u\" command.");
-                                                }
-                                                List<String> unsupportedTables = UpgradeUtil.getPhysicalTablesWithDescVarbinaryRowKey(conn);
-                                                if (!unsupportedTables.isEmpty()) {
-                                                    logger.warn("The following tables use an unsupported VARBINARY DESC construct and need to be changed:\n" + Joiner.on(' ').join(unsupportedTables));
-                                                }
-                                            } catch (Exception ex) {
-                                                logger.error("Unable to determine tables requiring upgrade due to PHOENIX-2067", ex);
-                                            } finally {
-                                                conn.close();
+                                            List<String> unsupportedTables = UpgradeUtil.getPhysicalTablesWithDescVarbinaryRowKey(conn);
+                                            if (!unsupportedTables.isEmpty()) {
+                                                logger.warn("The following tables use an unsupported VARBINARY DESC construct and need to be changed:\n" + Joiner.on(' ').join(unsupportedTables));
                                             }
+                                        } catch (Exception ex) {
+                                            logger.error("Unable to determine tables requiring upgrade due to PHOENIX-2067", ex);
+                                        } finally {
+                                            conn.close();
                                         }
-                                        // Add these columns one at a time, each with different timestamps so that if folks have
-                                        // run the upgrade code already for a snapshot, we'll still enter this block (and do the
-                                        // parts we haven't yet done).
-                                        if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_6_0) {
-                                            columnsToAdd = PhoenixDatabaseMetaData.IS_ROW_TIMESTAMP + " " + PBoolean.INSTANCE.getSqlTypeName();
-                                            metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG,
+                                    }
+                                    // Add these columns one at a time, each with different timestamps so that if folks have
+                                    // run the upgrade code already for a snapshot, we'll still enter this block (and do the
+                                    // parts we haven't yet done).
+                                    if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_6_0) {
+                                        columnsToAdd = PhoenixDatabaseMetaData.IS_ROW_TIMESTAMP + " " + PBoolean.INSTANCE.getSqlTypeName();
+                                        metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG,
                                                 MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_6_0, columnsToAdd);
-                                        }
-                                        if(currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0) {
-                                            // Drop old stats table so that new stats table is created
-                                            metaConnection = dropStatsTable(metaConnection, 
+                                    }
+                                    if(currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0) {
+                                        // Drop old stats table so that new stats table is created
+                                        metaConnection = dropStatsTable(metaConnection, 
                                                 MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 4);
-                                            metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG, 
+                                        metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG, 
                                                 MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 3,
                                                 PhoenixDatabaseMetaData.TRANSACTIONAL + " " + PBoolean.INSTANCE.getSqlTypeName());
-                                            metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG, 
+                                        metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG, 
                                                 MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 2,
                                                 PhoenixDatabaseMetaData.UPDATE_CACHE_FREQUENCY + " " + PLong.INSTANCE.getSqlTypeName());
-                                            metaConnection = setImmutableTableIndexesImmutable(metaConnection, 
+                                        metaConnection = setImmutableTableIndexesImmutable(metaConnection, 
                                                 MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 1);
-                                            metaConnection = updateSystemCatalogTimestamp(metaConnection, 
+                                        metaConnection = updateSystemCatalogTimestamp(metaConnection, 
                                                 MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0);
-                                            ConnectionQueryServicesImpl.this.removeTable(null, PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME, null, MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0);
-                                            clearCache();
-                                        }
+                                        ConnectionQueryServicesImpl.this.removeTable(null, PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME, null, MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0);
+                                        clearCache();
+                                    }
 
-                                        if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0) {
-                                            metaConnection = addColumnsIfNotExists(metaConnection,
+                                    if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0) {
+                                        metaConnection = addColumnsIfNotExists(metaConnection,
                                                 PhoenixDatabaseMetaData.SYSTEM_CATALOG,
                                                 MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0 - 2,
                                                 PhoenixDatabaseMetaData.IS_NAMESPACE_MAPPED + " "
                                                         + PBoolean.INSTANCE.getSqlTypeName());
-                                            metaConnection = addColumnsIfNotExists(metaConnection,
+                                        metaConnection = addColumnsIfNotExists(metaConnection,
                                                 PhoenixDatabaseMetaData.SYSTEM_CATALOG,
                                                 MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0 - 1,
                                                 PhoenixDatabaseMetaData.AUTO_PARTITION_SEQ + " "
                                                         + PVarchar.INSTANCE.getSqlTypeName());
-                                            metaConnection = addColumnsIfNotExists(metaConnection,
+                                        metaConnection = addColumnsIfNotExists(metaConnection,
                                                 PhoenixDatabaseMetaData.SYSTEM_CATALOG,
                                                 MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0,
                                                 PhoenixDatabaseMetaData.APPEND_ONLY_SCHEMA + " "
                                                         + PBoolean.INSTANCE.getSqlTypeName());
-                                            metaConnection = UpgradeUtil.disableViewIndexes(metaConnection);
-                                            if(getProps().getBoolean(QueryServices.LOCAL_INDEX_CLIENT_UPGRADE_ATTRIB,
+                                        metaConnection = UpgradeUtil.disableViewIndexes(metaConnection);
+                                        if(getProps().getBoolean(QueryServices.LOCAL_INDEX_CLIENT_UPGRADE_ATTRIB,
                                                 QueryServicesOptions.DEFAULT_LOCAL_INDEX_CLIENT_UPGRADE)) {
-                                                metaConnection = UpgradeUtil.upgradeLocalIndexes(metaConnection);
-                                            }
-                                            ConnectionQueryServicesImpl.this.removeTable(null,
+                                            metaConnection = UpgradeUtil.upgradeLocalIndexes(metaConnection);
+                                        }
+                                        ConnectionQueryServicesImpl.this.removeTable(null,
                                                 PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME, null,
                                                 MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0);
-                                            clearCache();
-                                        }
+                                        clearCache();
+                                    }
+
                                 }
                             }
 
@@ -2544,6 +2543,9 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                             }
                             success = true;
                             scheduleRenewLeaseTasks();
+                        } catch (UpgradeInProgressException e) {
+                            // don't set it as initializationException because otherwise client won't be able to retry
+                            throw e;
                         } catch (Exception e) {
                             if (e instanceof SQLException) {
                                 initializationException = (SQLException)e;
@@ -2719,12 +2721,56 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                         }
                     }
                 }
+                
+                /**
+                 * Acquire distributed mutex of sorts to make sure only one JVM is able to run the upgrade code by
+                 * making use of HBase's checkAndPut api.
+                 * <p>
+                 * This method was added as part of 4.8.1 release. For clients upgrading to 4.8.1, the old value in the
+                 * version cell will be null i.e. the QueryConstants#VERSION column will be non-existent. For client's
+                 * upgrading to a release newer than 4.8.1 the existing version cell will be non-null. The client which
+                 * wins the race will end up setting the version cell to the MetadataProtocol#MIN_SYSTEM_TABLE_TIMESTAMP
+                 * for the release.
+                 * </p>
+                 * 
+                 * @return true if client won the race, false otherwise
+                 * @throws IOException
+                 * @throws SQLException
+                 */
+                private boolean acquireUpgradeMutex(long currentServerSideTableTimestamp) throws IOException,
+                        SQLException {
+                    Preconditions.checkArgument(currentServerSideTableTimestamp < MIN_SYSTEM_TABLE_TIMESTAMP);
+                    try (HTableInterface sysCatalogTable = getTable(SYSTEM_CATALOG_NAME_BYTES)) {
+                        byte[] row = SchemaUtil.getTableKey(null, PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA,
+                                PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME);
+                        byte[] family = PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES;
+                        byte[] qualifier = QueryConstants.VERSION;
+                        byte[] oldValue = currentServerSideTableTimestamp < MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0 ? null
+                                : Bytes.toBytes(currentServerSideTableTimestamp);
+                        byte[] newValue = Bytes.toBytes(MIN_SYSTEM_TABLE_TIMESTAMP);
+                        long ts = MIN_SYSTEM_TABLE_TIMESTAMP;
+                        Put put = new Put(row, ts);
+                        put.add(family, qualifier, newValue);
+                        boolean acquired = sysCatalogTable.checkAndPut(row, family, qualifier, oldValue, put);
+                        if (!acquired) { throw new UpgradeInProgressException(
+                                getVersion(currentServerSideTableTimestamp), getVersion(MIN_SYSTEM_TABLE_TIMESTAMP)); }
+                        return true;
+                    }
+                }
             });
         } catch (Exception e) {
             Throwables.propagateIfInstanceOf(e, SQLException.class);
             throw Throwables.propagate(e);
         }
     }
+    
+    private static class UpgradeInProgressException extends SQLException {
+        public UpgradeInProgressException(String upgradeFrom, String upgradeTo) {
+            super("Cluster is being concurrently upgraded from " + upgradeFrom + " to " + upgradeTo
+                    + ". Please retry establishing connection.", SQLExceptionCode.CONCURRENT_UPGRADE_IN_PROGRESS
+                    .getSQLState(), SQLExceptionCode.CONCURRENT_UPGRADE_IN_PROGRESS.getErrorCode());
+        }
+    }
 
     private List<String> getTableNames(List<HTableDescriptor> tables) {
         List<String> tableNames = new ArrayList<String>(4);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/df0d6117/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
index 9f8f58c..3077943 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
@@ -356,5 +356,6 @@ public interface QueryConstants {
     public static final byte[] OFFSET_FAMILY = "f_offset".getBytes();
     public static final byte[] OFFSET_COLUMN = "c_offset".getBytes();
     public static final String LAST_SCAN = "LAST_SCAN";
+    public static final byte[] VERSION = "VERSION".getBytes();
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/df0d6117/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
index 7c34f4a..8bc3e63 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
@@ -19,7 +19,7 @@ package org.apache.phoenix.util;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.apache.phoenix.coprocessor.MetaDataProtocol.CURRENT_CLIENT_VERSION;
-import static org.apache.phoenix.coprocessor.MetaDataProtocol.TIMESTAMP_VERSION_MAP;
+import static org.apache.phoenix.coprocessor.MetaDataProtocol.getVersion;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ARRAY_SIZE;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.CACHE_SIZE;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_FAMILY;
@@ -31,7 +31,6 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DATA_TABLE_NAME;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DATA_TYPE;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DECIMAL_DIGITS;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.INCREMENT_BY;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.INDEX_TYPE;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.LIMIT_REACHED_FLAG;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.LINK_TYPE;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.MAX_VALUE;
@@ -1896,7 +1895,7 @@ public class UpgradeUtil {
     public static final String getUpgradeSnapshotName(String tableString, long currentSystemTableTimestamp) {
         Format formatter = new SimpleDateFormat("yyyyMMddHHmmssZ");
         String date = formatter.format(new Date(System.currentTimeMillis()));
-        String upgradingFrom = TIMESTAMP_VERSION_MAP.get(currentSystemTableTimestamp);
+        String upgradingFrom = getVersion(currentSystemTableTimestamp);
         return "SNAPSHOT_" + tableString + "_" + upgradingFrom + "_TO_" + CURRENT_CLIENT_VERSION + "_" + date;
     }
 }
\ No newline at end of file


[20/47] phoenix git commit: PHOENIX-3275 Reduce logging level of mutable secondary index logging

Posted by ma...@apache.org.
PHOENIX-3275 Reduce logging level of mutable secondary index logging


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

Branch: refs/heads/calcite
Commit: 27722998c35cbc14f8a6c1c1be1c0cc6b0f7769a
Parents: c0f72b5
Author: James Taylor <ja...@apache.org>
Authored: Tue Sep 13 22:52:42 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Tue Sep 13 22:52:42 2016 -0700

----------------------------------------------------------------------
 .../phoenix/hbase/index/covered/NonTxIndexBuilder.java    |  4 ++--
 .../phoenix/hbase/index/covered/data/IndexMemStore.java   | 10 +++++-----
 .../hbase/index/covered/update/IndexUpdateManager.java    |  4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/27722998/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/NonTxIndexBuilder.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/NonTxIndexBuilder.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/NonTxIndexBuilder.java
index 10d164b..eb9dc96 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/NonTxIndexBuilder.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/NonTxIndexBuilder.java
@@ -70,8 +70,8 @@ public class NonTxIndexBuilder extends BaseIndexBuilder {
 
         batchMutationAndAddUpdates(manager, state, mutation, indexMetaData);
 
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Found index updates for Mutation: " + mutation + "\n" + manager);
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Found index updates for Mutation: " + mutation + "\n" + manager);
         }
 
         return manager.toMap();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/27722998/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/data/IndexMemStore.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/data/IndexMemStore.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/data/IndexMemStore.java
index 5b68fa2..0fc9e14 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/data/IndexMemStore.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/data/IndexMemStore.java
@@ -113,8 +113,8 @@ public class IndexMemStore implements KeyValueStore {
 
   @Override
   public void add(KeyValue kv, boolean overwrite) {
-    if (LOG.isDebugEnabled()) {
-      LOG.info("Inserting: " + toString(kv));
+    if (LOG.isTraceEnabled()) {
+      LOG.trace("Inserting: " + toString(kv));
     }
     // if overwriting, we will always update
     if (!overwrite) {
@@ -139,13 +139,13 @@ public class IndexMemStore implements KeyValueStore {
 
   private String toString(KeyValue kv) {
     return kv.toString() + "/value=" + 
-        Bytes.toString(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength());
+        Bytes.toStringBinary(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength());
   }
 
   @Override
   public void rollback(KeyValue kv) {
-    if (LOG.isDebugEnabled()) {
-      LOG.debug("Rolling back: " + toString(kv));
+    if (LOG.isTraceEnabled()) {
+      LOG.trace("Rolling back: " + toString(kv));
     }
     // If the key is in the store, delete it
     this.kvset.remove(kv);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/27722998/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/IndexUpdateManager.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/IndexUpdateManager.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/IndexUpdateManager.java
index 26f620f..a183186 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/IndexUpdateManager.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/IndexUpdateManager.java
@@ -209,7 +209,7 @@ public class IndexUpdateManager {
   public String toString() {
     StringBuffer sb = new StringBuffer("Pending Index Updates:\n");
     for (Entry<ImmutableBytesPtr, Collection<Mutation>> entry : map.entrySet()) {
-      String tableName = Bytes.toString(entry.getKey().get());
+      String tableName = Bytes.toStringBinary(entry.getKey().get());
       sb.append("   Table: '" + tableName + "'\n");
       for (Mutation m : entry.getValue()) {
         sb.append("\t");
@@ -218,7 +218,7 @@ public class IndexUpdateManager {
         }
         sb.append(m.getClass().getSimpleName() + ":"
             + ((m instanceof Put) ? m.getTimeStamp() + " " : ""));
-        sb.append(" row=" + Bytes.toString(m.getRow()));
+        sb.append(" row=" + Bytes.toStringBinary(m.getRow()));
         sb.append("\n");
         if (m.getFamilyCellMap().isEmpty()) {
           sb.append("\t\t=== EMPTY ===\n");


[22/47] phoenix git commit: PHOENIX-3237 Automatic rebuild of disabled index will fail if indexes of two tables are disabled at the same time

Posted by ma...@apache.org.
PHOENIX-3237 Automatic rebuild of disabled index will fail if indexes of two tables are disabled at the same time


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

Branch: refs/heads/calcite
Commit: b640b39ce8cbd36fab33c79ea81ed500dd882f99
Parents: 850b02c
Author: Ankit Singhal <an...@gmail.com>
Authored: Wed Sep 14 13:40:49 2016 +0530
Committer: Ankit Singhal <an...@gmail.com>
Committed: Wed Sep 14 13:40:49 2016 +0530

----------------------------------------------------------------------
 .../end2end/index/MutableIndexFailureIT.java    | 239 +++++++++++--------
 .../coprocessor/MetaDataRegionObserver.java     |   6 +-
 2 files changed, 143 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b640b39c/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
index 5d0230b..0a85216 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
@@ -49,7 +49,6 @@ import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.PIndexState;
 import org.apache.phoenix.schema.PTableType;
-import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
@@ -128,6 +127,9 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
     }
 
     public void helpTestWriteFailureDisablesIndex() throws Exception {
+        String secondTableName = fullTableName + "_2";
+        String secondIndexName = indexName + "_2";
+        String secondFullIndexName = fullIndexName + "_2";
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         props.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, String.valueOf(isNamespaceMapped));
         try (Connection conn = driver.connect(url, props)) {
@@ -139,6 +141,8 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
             }
             conn.createStatement().execute("CREATE TABLE " + fullTableName
                     + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) " + tableDDLOptions);
+            conn.createStatement().execute("CREATE TABLE " + secondTableName
+                    + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) " + tableDDLOptions);
             query = "SELECT * FROM " + fullTableName;
             rs = conn.createStatement().executeQuery(query);
             assertFalse(rs.next());
@@ -146,34 +150,26 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
             FAIL_WRITE = false;
             conn.createStatement().execute(
                     "CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + indexName + " ON " + fullTableName + " (v1) INCLUDE (v2)");
+            conn.createStatement().execute(
+                    "CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + secondIndexName + " ON " + secondTableName + " (v1) INCLUDE (v2)");
 
             query = "SELECT * FROM " + fullIndexName;
             rs = conn.createStatement().executeQuery(query);
             assertFalse(rs.next());
 
             // Verify the metadata for index is correct.
-            rs = conn.getMetaData().getTables(null, StringUtil.escapeLike(schema), indexName,
+            rs = conn.getMetaData().getTables(null, StringUtil.escapeLike(schema), indexName+"%",
                     new String[] { PTableType.INDEX.toString() });
             assertTrue(rs.next());
             assertEquals(indexName, rs.getString(3));
             assertEquals(PIndexState.ACTIVE.toString(), rs.getString("INDEX_STATE"));
+            assertTrue(rs.next());
+            assertEquals(secondIndexName, rs.getString(3));
+            assertEquals(PIndexState.ACTIVE.toString(), rs.getString("INDEX_STATE"));
             assertFalse(rs.next());
-
-            PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + fullTableName + " VALUES(?,?,?)");
-            stmt.setString(1, "a");
-            stmt.setString(2, "x");
-            stmt.setString(3, "1");
-            stmt.execute();
-            stmt.setString(1, "b");
-            stmt.setString(2, "y");
-            stmt.setString(3, "2");
-            stmt.execute();
-            stmt.setString(1, "c");
-            stmt.setString(2, "z");
-            stmt.setString(3, "3");
-            stmt.execute();
-            conn.commit();
-
+            initializeTable(conn, fullTableName);
+            initializeTable(conn, secondTableName);
+            
             query = "SELECT /*+ NO_INDEX */ k,v1 FROM " + fullTableName;
             rs = conn.createStatement().executeQuery("EXPLAIN " + query);
             String expectedPlan = "CLIENT PARALLEL 1-WAY FULL SCAN OVER "
@@ -192,31 +188,8 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
             assertFalse(rs.next());
 
             FAIL_WRITE = true;
-
-            stmt = conn.prepareStatement("UPSERT INTO " + fullTableName + " VALUES(?,?,?)");
-            // Insert new row
-            stmt.setString(1, "d");
-            stmt.setString(2, "d");
-            stmt.setString(3, "4");
-            stmt.execute();
-            // Update existing row
-            stmt.setString(1, "a");
-            stmt.setString(2, "x2");
-            stmt.setString(3, "2");
-            stmt.execute();
-            // Delete existing row
-            stmt = conn.prepareStatement("DELETE FROM " + fullTableName + " WHERE k=?");
-            stmt.setString(1, "b");
-            stmt.execute();
-            try {
-                conn.commit();
-                fail();
-            } catch (SQLException e) {
-                System.out.println();
-            }  catch(Exception e) {
-                System.out.println();
-            }
-
+            updateTable(conn, fullTableName);
+            updateTable(conn, secondTableName);
             // Verify the metadata for index is correct.
             rs = conn.getMetaData().getTables(null, StringUtil.escapeLike(schema), indexName,
                     new String[] { PTableType.INDEX.toString() });
@@ -236,13 +209,18 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
             // would have succeeded while the index writes would have failed.
             if (!transactional) {
                 // Verify UPSERT on data table still work after index is disabled
-                stmt = conn.prepareStatement("UPSERT INTO " + fullTableName + " VALUES(?,?,?)");
+                PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + fullTableName + " VALUES(?,?,?)");
+                stmt.setString(1, "a3");
+                stmt.setString(2, "x3");
+                stmt.setString(3, "3");
+                stmt.execute();
+                conn.commit();
+                stmt = conn.prepareStatement("UPSERT INTO " + secondTableName + " VALUES(?,?,?)");
                 stmt.setString(1, "a3");
                 stmt.setString(2, "x3");
                 stmt.setString(3, "3");
                 stmt.execute();
                 conn.commit();
-
                 // Verify previous writes succeeded to data table
                 query = "SELECT /*+ NO_INDEX */ k,v1 FROM " + fullTableName;
                 rs = conn.createStatement().executeQuery("EXPLAIN " + query);
@@ -267,25 +245,18 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
 
             // re-enable index table
             FAIL_WRITE = false;
-            
-            boolean isActive = false;
-            if (!transactional) {
-                int maxTries = 3, nTries = 0;
-                do {
-                    Thread.sleep(15 * 1000); // sleep 15 secs
-                    rs = conn.getMetaData().getTables(null, StringUtil.escapeLike(schema), indexName,
-                            new String[] { PTableType.INDEX.toString() });
-                    assertTrue(rs.next());
-                    if(PIndexState.ACTIVE.toString().equals(rs.getString("INDEX_STATE"))){
-                        isActive = true;
-                        break;
-                    }
-                } while(++nTries < maxTries);
-                assertTrue(isActive);
-            }
+            waitForIndexToBeActive(conn,indexName);
+            waitForIndexToBeActive(conn,secondIndexName);
 
             // Verify UPSERT on data table still work after index table is recreated
-            stmt = conn.prepareStatement("UPSERT INTO " + fullTableName + " VALUES(?,?,?)");
+            PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + fullTableName + " VALUES(?,?,?)");
+            stmt.setString(1, "a3");
+            stmt.setString(2, "x4");
+            stmt.setString(3, "4");
+            stmt.execute();
+            conn.commit();
+            
+            stmt = conn.prepareStatement("UPSERT INTO " + secondTableName + " VALUES(?,?,?)");
             stmt.setString(1, "a3");
             stmt.setString(2, "x4");
             stmt.setString(3, "4");
@@ -293,48 +264,116 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
             conn.commit();
 
             // verify index table has correct data
-            query = "SELECT /*+ INDEX(" + indexName + ") */ k,v1 FROM " + fullTableName;
-            rs = conn.createStatement().executeQuery("EXPLAIN " + query);
-            expectedPlan = " OVER "
-                    + (localIndex
-                            ? Bytes.toString(SchemaUtil
-                                    .getPhysicalTableName(fullTableName.getBytes(), isNamespaceMapped).getName())
-                            : SchemaUtil.getPhysicalTableName(fullIndexName.getBytes(), isNamespaceMapped).getNameAsString());
-            String explainPlan = QueryUtil.getExplainPlan(rs);
-            assertTrue(explainPlan.contains(expectedPlan));
-            rs = conn.createStatement().executeQuery(query);
-            if (transactional) { // failed commit does not get retried
-                assertTrue(rs.next());
-                assertEquals("a", rs.getString(1));
-                assertEquals("x", rs.getString(2));
-                assertTrue(rs.next());
-                assertEquals("a3", rs.getString(1));
-                assertEquals("x4", rs.getString(2));
-                assertTrue(rs.next());
-                assertEquals("b", rs.getString(1));
-                assertEquals("y", rs.getString(2));
-                assertTrue(rs.next());
-                assertEquals("c", rs.getString(1));
-                assertEquals("z", rs.getString(2));
-                assertFalse(rs.next());
-            } else { // failed commit eventually succeeds
-                assertTrue(rs.next());
-                assertEquals("d", rs.getString(1));
-                assertEquals("d", rs.getString(2));
-                assertTrue(rs.next());
-                assertEquals("a", rs.getString(1));
-                assertEquals("x2", rs.getString(2));
-                assertTrue(rs.next());
-                assertEquals("a3", rs.getString(1));
-                assertEquals("x4", rs.getString(2));
+            validateDataWithIndex(conn, fullTableName, fullIndexName);
+            validateDataWithIndex(conn, secondTableName, secondFullIndexName);
+        }
+    }
+
+    private void waitForIndexToBeActive(Connection conn, String index) throws InterruptedException, SQLException {
+        boolean isActive = false;
+        if (!transactional) {
+            int maxTries = 4, nTries = 0;
+            do {
+                Thread.sleep(15 * 1000); // sleep 15 secs
+                ResultSet rs = conn.getMetaData().getTables(null, StringUtil.escapeLike(schema), index,
+                        new String[] { PTableType.INDEX.toString() });
                 assertTrue(rs.next());
-                assertEquals("c", rs.getString(1));
-                assertEquals("z", rs.getString(2));
-                assertFalse(rs.next());
-            }
+                if (PIndexState.ACTIVE.toString().equals(rs.getString("INDEX_STATE"))) {
+                    isActive = true;
+                    break;
+                }
+            } while (++nTries < maxTries);
+            assertTrue(isActive);
+        }
+    }
+
+    private void initializeTable(Connection conn, String tableName) throws SQLException {
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES(?,?,?)");
+        stmt.setString(1, "a");
+        stmt.setString(2, "x");
+        stmt.setString(3, "1");
+        stmt.execute();
+        stmt.setString(1, "b");
+        stmt.setString(2, "y");
+        stmt.setString(3, "2");
+        stmt.execute();
+        stmt.setString(1, "c");
+        stmt.setString(2, "z");
+        stmt.setString(3, "3");
+        stmt.execute();
+        conn.commit();
+
+    }
+
+    private void validateDataWithIndex(Connection conn, String tableName, String indexName) throws SQLException {
+        String query = "SELECT /*+ INDEX(" + indexName + ") */ k,v1 FROM " + tableName;
+        ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + query);
+        String expectedPlan = " OVER "
+                + (localIndex
+                        ? Bytes.toString(
+                                SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped).getName())
+                        : SchemaUtil.getPhysicalTableName(indexName.getBytes(), isNamespaceMapped).getNameAsString());
+        String explainPlan = QueryUtil.getExplainPlan(rs);
+        assertTrue(explainPlan.contains(expectedPlan));
+        rs = conn.createStatement().executeQuery(query);
+        if (transactional) { // failed commit does not get retried
+            assertTrue(rs.next());
+            assertEquals("a", rs.getString(1));
+            assertEquals("x", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("a3", rs.getString(1));
+            assertEquals("x4", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("b", rs.getString(1));
+            assertEquals("y", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("c", rs.getString(1));
+            assertEquals("z", rs.getString(2));
+            assertFalse(rs.next());
+        } else { // failed commit eventually succeeds
+            assertTrue(rs.next());
+            assertEquals("d", rs.getString(1));
+            assertEquals("d", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("a", rs.getString(1));
+            assertEquals("x2", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("a3", rs.getString(1));
+            assertEquals("x4", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("c", rs.getString(1));
+            assertEquals("z", rs.getString(2));
+            assertFalse(rs.next());
         }
     }
     
+    private void updateTable(Connection conn, String tableName) throws SQLException {
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES(?,?,?)");
+        // Insert new row
+        stmt.setString(1, "d");
+        stmt.setString(2, "d");
+        stmt.setString(3, "4");
+        stmt.execute();
+        // Update existing row
+        stmt.setString(1, "a");
+        stmt.setString(2, "x2");
+        stmt.setString(3, "2");
+        stmt.execute();
+        // Delete existing row
+        stmt = conn.prepareStatement("DELETE FROM " + tableName + " WHERE k=?");
+        stmt.setString(1, "b");
+        stmt.execute();
+        try {
+            conn.commit();
+            fail();
+        } catch (SQLException e) {
+            System.out.println();
+        } catch (Exception e) {
+            System.out.println();
+        }
+
+    }
+
     public static class FailingRegionObserver extends SimpleRegionObserver {
         @Override
         public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws HBaseIOException {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b640b39c/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
index 5beba49..f1dc982 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
@@ -257,9 +257,11 @@ public class MetaDataRegionObserver extends BaseRegionObserver {
                         PhoenixDatabaseMetaData.DATA_TABLE_NAME_BYTES);
                     byte[] indexStat = r.getValue(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,
                         PhoenixDatabaseMetaData.INDEX_STATE_BYTES);
-                    if ((dataTable == null || dataTable.length == 0)
-                            || (indexStat == null || indexStat.length == 0)) {
+                    if ((dataTable == null || dataTable.length == 0) || (indexStat == null || indexStat.length == 0)
+                            || (dataPTable != null
+                                    && Bytes.compareTo(dataPTable.getName().getBytes(), dataTable) != 0)) {
                         // data table name can't be empty
+                        // we need to build indexes of same data table. so skip other indexes for this task.
                         continue;
                     }
 


[39/47] phoenix git commit: PHOENIX-3291 Do not throw return value of Throwables#propagate call

Posted by ma...@apache.org.
PHOENIX-3291 Do not throw return value of Throwables#propagate call


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

Branch: refs/heads/calcite
Commit: 553a5871e3c8e2277cebd9f2561b1f2899d1e6d5
Parents: 4c8bda1
Author: James Taylor <ja...@apache.org>
Authored: Fri Sep 16 21:25:00 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Sat Sep 17 00:07:28 2016 -0700

----------------------------------------------------------------------
 .../main/java/org/apache/phoenix/jdbc/PhoenixStatement.java    | 6 ++++--
 .../apache/phoenix/mapreduce/FormatToBytesWritableMapper.java  | 3 ++-
 .../org/apache/phoenix/query/ConnectionQueryServicesImpl.java  | 2 +-
 .../main/java/org/apache/phoenix/util/CSVCommonsLoader.java    | 2 +-
 .../java/org/apache/phoenix/util/PhoenixContextExecutor.java   | 6 +++---
 5 files changed, 11 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/553a5871/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
index 0c154e2..0fbc81a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
@@ -314,7 +314,8 @@ public class PhoenixStatement implements Statement, SQLCloseable {
                 }, PhoenixContextExecutor.inContext());
         } catch (Exception e) {
             Throwables.propagateIfInstanceOf(e, SQLException.class);
-            throw Throwables.propagate(e);
+            Throwables.propagate(e);
+            throw new IllegalStateException(); // Can't happen as Throwables.propagate() always throws
         }
     }
     
@@ -367,7 +368,8 @@ public class PhoenixStatement implements Statement, SQLCloseable {
                         Tracing.withTracing(connection, this.toString()));
         } catch (Exception e) {
             Throwables.propagateIfInstanceOf(e, SQLException.class);
-            throw Throwables.propagate(e);
+            Throwables.propagate(e);
+            throw new IllegalStateException(); // Can't happen as Throwables.propagate() always throws
         }
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/553a5871/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
index cacbce7..b12326a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
@@ -28,6 +28,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.TreeMap;
+
 import javax.annotation.Nullable;
 
 import org.apache.hadoop.conf.Configuration;
@@ -379,7 +380,7 @@ public abstract class FormatToBytesWritableMapper<RECORD> extends Mapper<LongWri
             LOG.error("Error on record " + record, throwable);
             context.getCounter(COUNTER_GROUP_NAME, "Errors on records").increment(1L);
             if (!ignoreRecordErrors) {
-                throw Throwables.propagate(throwable);
+                Throwables.propagate(throwable);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/553a5871/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index 767a600..1aa9b88 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -2786,7 +2786,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             });
         } catch (Exception e) {
             Throwables.propagateIfInstanceOf(e, SQLException.class);
-            throw Throwables.propagate(e);
+            Throwables.propagate(e);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/553a5871/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java b/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java
index cdd9d7b..23f123e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java
@@ -292,7 +292,7 @@ public class CSVCommonsLoader {
         public void errorOnRecord(CSVRecord csvRecord, Throwable throwable) {
             LOG.error("Error upserting record " + csvRecord, throwable.getMessage());
             if (strict) {
-                throw Throwables.propagate(throwable);
+                Throwables.propagate(throwable);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/553a5871/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixContextExecutor.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixContextExecutor.java b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixContextExecutor.java
index 2da3249..cd12261 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixContextExecutor.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixContextExecutor.java
@@ -21,8 +21,6 @@ import java.util.concurrent.Callable;
 
 import org.apache.phoenix.call.CallWrapper;
 
-import com.google.common.base.Throwables;
-
 /**
  * Executes {@code Callable}s using a context classloader that is set up to load classes from
  * Phoenix.
@@ -91,8 +89,10 @@ public class PhoenixContextExecutor {
     public static <T> T callWithoutPropagation(Callable<T> target) {
         try {
             return call(target);
+        } catch (RuntimeException e) {
+            throw e;
         } catch (Exception e) {
-            throw Throwables.propagate(e);
+            throw new RuntimeException(e);
         }
     }
 


[17/47] phoenix git commit: PHOENIX-3176 Remove unnecessary PQS proxy user authorization

Posted by ma...@apache.org.
PHOENIX-3176 Remove unnecessary PQS proxy user authorization


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

Branch: refs/heads/calcite
Commit: c3cdb2afbe60a4959237a6ac264f42322a049d1d
Parents: 5a6496e
Author: Josh Elser <el...@apache.org>
Authored: Sat Sep 10 16:05:15 2016 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Sun Sep 11 15:03:43 2016 -0400

----------------------------------------------------------------------
 .../main/java/org/apache/phoenix/queryserver/server/Main.java    | 4 ----
 1 file changed, 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/c3cdb2af/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/Main.java
----------------------------------------------------------------------
diff --git a/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/Main.java b/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/Main.java
index 4b3ca7e..0ed3b7b 100644
--- a/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/Main.java
+++ b/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/Main.java
@@ -286,10 +286,6 @@ public final class Main extends Configured implements Tool, Runnable {
       // LoadingCache will create a new instance for us if one isn't cached.
       UserGroupInformation proxyUser = createProxyUser(remoteUserName);
 
-      // Check if this user is allowed to be impersonated.
-      // Will throw AuthorizationException if the impersonation as this user is not allowed
-      ProxyUsers.authorize(proxyUser, remoteAddress);
-
       // Execute the actual call as this proxy user
       return proxyUser.doAs(new PrivilegedExceptionAction<T>() {
         @Override


[30/47] phoenix git commit: PHOENIX-3286 Use regular queue depth instead of overriding it to zero for tests

Posted by ma...@apache.org.
PHOENIX-3286 Use regular queue depth instead of overriding it to zero for tests


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

Branch: refs/heads/calcite
Commit: a4ebcfdd262dcc311f96a80c3dd47290bce2c236
Parents: 2a223ad
Author: James Taylor <ja...@apache.org>
Authored: Thu Sep 15 15:52:06 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Thu Sep 15 15:52:06 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/phoenix/query/QueryServicesTestImpl.java     | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/a4ebcfdd/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
index 6ae655c..f2b1519 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
@@ -33,8 +33,7 @@ import org.apache.phoenix.util.ReadOnlyProps;
  */
 public final class QueryServicesTestImpl extends BaseQueryServicesImpl {
 
-    private static final int DEFAULT_THREAD_POOL_SIZE = 20;
-    private static final int DEFAULT_QUEUE_SIZE = 0;
+    private static final int DEFAULT_THREAD_POOL_SIZE = 10;
     // TODO: setting this down to 5mb causes insufficient memory exceptions. Need to investigate why
     private static final int DEFAULT_MAX_MEMORY_PERC = 30; // 30% of heap
     private static final int DEFAULT_THREAD_TIMEOUT_MS = 60000*5; //5min
@@ -85,7 +84,6 @@ public final class QueryServicesTestImpl extends BaseQueryServicesImpl {
     	        .setSequenceSaltBuckets(DEFAULT_SEQUENCE_TABLE_SALT_BUCKETS)
                 .setMinStatsUpdateFrequencyMs(DEFAULT_MIN_STATS_UPDATE_FREQ_MS)
                 .setThreadPoolSize(DEFAULT_THREAD_POOL_SIZE)
-                .setQueueSize(DEFAULT_QUEUE_SIZE)
                 .setMaxMemoryPerc(DEFAULT_MAX_MEMORY_PERC)
                 .setThreadTimeoutMs(DEFAULT_THREAD_TIMEOUT_MS)
                 .setSpoolThresholdBytes(DEFAULT_SPOOL_THRESHOLD_BYTES)


[35/47] phoenix git commit: PHOENIX-3290 Move and/or combine as many NeedsOwnCluster tests to bring down test run time

Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFunctionsEnd2EndIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFunctionsEnd2EndIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFunctionsEnd2EndIT.java
deleted file mode 100644
index c365934..0000000
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFunctionsEnd2EndIT.java
+++ /dev/null
@@ -1,686 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.phoenix.end2end;
-
-import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.apache.phoenix.util.TestUtil.closeStmtAndConn;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.math.BigDecimal;
-import java.sql.Connection;
-import java.sql.Date;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.util.Properties;
-
-import org.apache.phoenix.expression.function.CeilFunction;
-import org.apache.phoenix.expression.function.FloorFunction;
-import org.apache.phoenix.expression.function.RoundFunction;
-import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.util.DateUtil;
-import org.apache.phoenix.util.PhoenixRuntime;
-import org.apache.phoenix.util.PropertiesUtil;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.common.primitives.Doubles;
-import com.google.common.primitives.Floats;
-
-/**
- * 
- * End to end tests for {@link RoundFunction}, {@link FloorFunction}, {@link CeilFunction} 
- *
- * 
- * @since 3.0.0
- */
-
-
-public class RoundFloorCeilFunctionsEnd2EndIT extends BaseHBaseManagedTimeTableReuseIT {
-
-  private static final String TABLE_NAME = generateRandomString();
-  private static long millisPart = 660;
-    private static int nanosPart = 500100;
-    private static BigDecimal decimalUpserted = BigDecimal.valueOf(1.264);
-    private static double doubleUpserted = 1.264d;
-    private static double unsignedDoubleUpserted = 1.264d;
-    private static float floatUpserted = 1.264f;
-    private static float unsignedFloatUpserted = 1.264f;
-    
-    @Before
-    public void initTable() throws Exception {
-        String testString = "abc";
-        Connection conn = null;
-        PreparedStatement stmt = null;
-        try {
-            conn = DriverManager.getConnection(getUrl());
-            String ddl = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME
-                + " (s VARCHAR NOT NULL PRIMARY KEY, dt DATE, t TIME, ts TIMESTAMP, dec DECIMAL, doub DOUBLE, undoub UNSIGNED_DOUBLE, fl FLOAT, unfl UNSIGNED_FLOAT)";
-            conn.createStatement().execute(ddl);
-            
-            Date dateUpserted = DateUtil.parseDate("2012-01-01 14:25:28");
-            dateUpserted = new Date(dateUpserted.getTime() + millisPart); // this makes the dateUpserted equivalent to 2012-01-01 14:25:28.660 
-            long millis = dateUpserted.getTime();
-
-            Time timeUpserted = new Time(millis);
-            Timestamp tsUpserted = DateUtil.getTimestamp(millis, nanosPart);
-            
-            stmt =  conn.prepareStatement(
-                "UPSERT INTO " + TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
-            stmt.setString(1, testString);
-            stmt.setDate(2, dateUpserted);
-            stmt.setTime(3, timeUpserted);
-            stmt.setTimestamp(4, tsUpserted);
-            stmt.setBigDecimal(5, decimalUpserted);
-            stmt.setDouble(6, doubleUpserted);
-            stmt.setDouble(7, unsignedDoubleUpserted);
-            stmt.setFloat(8, floatUpserted);
-            stmt.setFloat(9, unsignedFloatUpserted);
-            stmt.executeUpdate();
-            conn.commit();
-        } finally {
-            closeStmtAndConn(stmt, conn);
-        }
-    }
-
-    @Test
-    public void testRoundingUpDate() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery("SELECT ROUND(dt, 'day'), ROUND(dt, 'hour', 1), ROUND(dt, 'minute', 1), ROUND(dt, 'second', 1), "
-                + " ROUND(dt,'week'), ROUND(dt,'month') , ROUND(dt,'year') FROM " + TABLE_NAME);
-        assertTrue(rs.next());
-        Date expectedDate = DateUtil.parseDate("2012-01-02 00:00:00");
-        assertEquals(expectedDate, rs.getDate(1));
-        expectedDate = DateUtil.parseDate("2012-01-01 14:00:00");
-        assertEquals(expectedDate, rs.getDate(2));
-        expectedDate = DateUtil.parseDate("2012-01-01 14:25:00");
-        assertEquals(expectedDate, rs.getDate(3));
-        expectedDate = DateUtil.parseDate("2012-01-01 14:25:29"); 
-        assertEquals(expectedDate, rs.getDate(4));
-        expectedDate = DateUtil.parseDate("2012-01-02 00:00:00"); 
-        assertEquals(expectedDate, rs.getDate(5));
-        expectedDate = DateUtil.parseDate("2012-01-01 00:00:00"); 
-        assertEquals(expectedDate, rs.getDate(6));
-        expectedDate = DateUtil.parseDate("2012-01-01 00:00:00"); 
-        assertEquals(expectedDate, rs.getDate(7));
-    }
-    
-    @Test
-    public void testRoundingUpDateInWhere() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + TABLE_NAME
-            + " WHERE ROUND(dt, 'day') = to_date('2012-01-02 00:00:00')");
-        assertTrue(rs.next());
-    }
-    
-    @Test
-    public void testFloorDate() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery("SELECT FLOOR(dt, 'day', 1), FLOOR(dt, 'hour', 1), FLOOR(dt, 'minute', 1), FLOOR(dt, 'second', 1),"
-                + " FLOOR(dt,'week'), FLOOR(dt,'month'), FLOOR(dt,'year') FROM " + TABLE_NAME);
-        assertTrue(rs.next());
-        Date expectedDate = DateUtil.parseDate("2012-01-01 00:00:00");
-        assertEquals(expectedDate, rs.getDate(1));
-        expectedDate = DateUtil.parseDate("2012-01-01 14:00:00");
-        assertEquals(expectedDate, rs.getDate(2));
-        expectedDate = DateUtil.parseDate("2012-01-01 14:25:00");
-        assertEquals(expectedDate, rs.getDate(3));
-        expectedDate = DateUtil.parseDate("2012-01-01 14:25:28");
-        assertEquals(expectedDate, rs.getDate(4));
-        expectedDate = DateUtil.parseDate("2011-12-26 00:00:00");
-        assertEquals(expectedDate, rs.getDate(5));
-        expectedDate = DateUtil.parseDate("2012-01-01 00:00:00");
-        assertEquals(expectedDate, rs.getDate(6));
-        expectedDate = DateUtil.parseDate("2012-01-01 00:00:00");
-        assertEquals(expectedDate, rs.getDate(7));
-    }
-    
-    @Test
-    public void testFloorDateInWhere() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + TABLE_NAME
-            + " WHERE FLOOR(dt, 'hour') = to_date('2012-01-01 14:00:00')");
-        assertTrue(rs.next());
-    }
-    
-    @Test
-    public void testCeilDate() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery("SELECT CEIL(dt, 'day', 1), CEIL(dt, 'hour', 1), CEIL(dt, 'minute', 1), CEIL(dt, 'second', 1), "
-                + " CEIL(dt,'week') , CEIL(dt,'month') , CEIL(dt,'year')  FROM " + TABLE_NAME);
-        assertTrue(rs.next());
-        //Date upserted is 2012-01-01 14:25:28.660. So we will end up bumping up in every case.
-        Date expectedDate = DateUtil.parseDate("2012-01-02 00:00:00");
-        assertEquals(expectedDate, rs.getDate(1));
-        expectedDate = DateUtil.parseDate("2012-01-01 15:00:00");
-        assertEquals(expectedDate, rs.getDate(2));
-        expectedDate = DateUtil.parseDate("2012-01-01 14:26:00");
-        assertEquals(expectedDate, rs.getDate(3));
-        expectedDate = DateUtil.parseDate("2012-01-01 14:25:29");
-        assertEquals(expectedDate, rs.getDate(4));
-        expectedDate = DateUtil.parseDate("2012-01-02 00:00:00");
-        System.out.println(String.format(" the expected time is [%s] and the actual time is [%s]",expectedDate.getTime(),rs.getDate(5).getTime()));
-        assertEquals(expectedDate, rs.getDate(5));
-        expectedDate = DateUtil.parseDate("2012-02-01 00:00:00");
-        assertEquals(expectedDate, rs.getDate(6));
-        expectedDate = DateUtil.parseDate("2013-01-01 00:00:00");
-        assertEquals(expectedDate, rs.getDate(7));
-    }
-    
-    @Test
-    public void testCeilDateInWhere() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + TABLE_NAME
-            + " WHERE CEIL(dt, 'second') = to_date('2012-01-01 14:25:29')");
-        assertTrue(rs.next());
-    }
-    
-    @Test
-    public void testRoundingUpTimestamp() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT ROUND(ts, 'day'), ROUND(ts, 'hour', 1), ROUND(ts, 'minute', 1), ROUND(ts, 'second', 1), ROUND(ts, 'millisecond', 1) FROM "
-                + TABLE_NAME);
-        assertTrue(rs.next());
-        Timestamp expectedTimestamp;
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(1));
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:00:00").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(2));
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:00").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(3));
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:29").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(4));
-        
-        // Rounding of "2012-01-01 14:25:28.660" + nanosPart will end up bumping up the millisecond part of date. 
-        // That is, it should be  evaluated as "2012-01-01 14:25:28.661". 
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:28").getTime() + millisPart + 1);
-        assertEquals(expectedTimestamp, rs.getTimestamp(5));
-    }
-    
-    @Test
-    public void testRoundingUpTimestampInWhere() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + TABLE_NAME
-            + " WHERE ROUND(ts, 'second') = to_date('2012-01-01 14:25:29')");
-        assertTrue(rs.next());
-    }
-    
-    @Test
-    public void testFloorTimestamp() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery("SELECT FLOOR(ts, 'day'), FLOOR(ts, 'hour', 1), FLOOR(ts, 'minute', 1), FLOOR(ts, 'second', 1), "
-                + " FLOOR(ts, 'millisecond', 1) , FLOOR(ts,'week') , FLOOR(ts,'month') FROM "
-            + TABLE_NAME);
-        assertTrue(rs.next());
-        Timestamp expectedTimestamp;
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(1));
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:00:00").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(2));
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:00").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(3));
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:28").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(4));
-        
-        // FLOOR of "2012-01-01 14:25:28.660" + nanosPart will end up removing the nanos part. 
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:28").getTime() + millisPart);
-        assertEquals(expectedTimestamp, rs.getTimestamp(5));
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2011-12-26 00:00:00").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(6));
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(7));
-    }
-    
-    @Test
-    public void testFloorTimestampInWhere() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + TABLE_NAME
-            + " WHERE FLOOR(ts, 'second') = to_date('2012-01-01 14:25:28')");
-        assertTrue(rs.next());
-    }
-    
-    @Test
-    public void testWeekFloorTimestampInWhere() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + TABLE_NAME
-            + " WHERE FLOOR(ts, 'week') = to_date('2011-12-26 00:00:00')");
-        assertTrue(rs.next());
-    }
-    
-    @Test
-    public void testCeilTimestamp() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery("SELECT CEIL(ts, 'day'), CEIL(ts, 'hour', 1), CEIL(ts, 'minute', 1), CEIL(ts, 'second', 1), CEIL(ts, 'millisecond', 1),"
-                + " CEIL(ts,'week'), CEIL(ts,'month') , CEIL(ts,'year') FROM " + TABLE_NAME);
-        assertTrue(rs.next());
-        Timestamp expectedTimestamp;
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(1));
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 15:00:00").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(2));
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:26:00").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(3));
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:29").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(4));
-        
-        // CEIL of "2012-01-01 14:25:28.660" + nanosPart will end up bumping up the millisecond part of date. 
-        // That is, it should be  evaluated as "2012-01-01 14:25:28.661". 
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:28").getTime() + millisPart + 1);
-        assertEquals(expectedTimestamp, rs.getTimestamp(5));
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(6));
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-02-01 00:00:00").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(7));
-        expectedTimestamp = new Timestamp(DateUtil.parseDate("2013-01-01 00:00:00").getTime());
-        assertEquals(expectedTimestamp, rs.getTimestamp(8));
-    }
-    
-    @Test
-    public void testCeilTimestampInWhere() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + TABLE_NAME
-            + " WHERE CEIL(ts, 'second') = to_date('2012-01-01 14:25:29')");
-        assertTrue(rs.next());
-    }
-    
-    @Test
-    public void testRoundingUpTime() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery("SELECT ROUND(t, 'day', 1), ROUND(t, 'hour', 1), ROUND(t, 'minute', 1), ROUND(t, 'second', 1),"
-                + " ROUND(t,'week') , ROUND(t,'month') , ROUND(t,'year') FROM " + TABLE_NAME);
-        assertTrue(rs.next());
-        Time expectedTime = new Time(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
-        assertEquals(expectedTime, rs.getTime(1));
-        expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:00:00").getTime());
-        assertEquals(expectedTime, rs.getTime(2));
-        expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:00").getTime());
-        assertEquals(expectedTime, rs.getTime(3));
-        expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:29").getTime());
-        assertEquals(expectedTime, rs.getTime(4));
-        expectedTime = new Time(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
-        assertEquals(expectedTime, rs.getTime(5));
-        expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
-        assertEquals(expectedTime, rs.getTime(6));
-        expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
-        assertEquals(expectedTime, rs.getTime(7));
-    }
-    
-    @Test
-    public void testFloorTime() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery("SELECT FLOOR(t, 'day', 1), FLOOR(t, 'hour', 1), FLOOR(t, 'minute', 1), FLOOR(t, 'second', 1), "
-                + " FLOOR(t, 'week'),  FLOOR(t, 'month'), FLOOR(t, 'year') FROM " + TABLE_NAME);
-        assertTrue(rs.next());
-        Time expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
-        assertEquals(expectedTime, rs.getTime(1));
-        expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:00:00").getTime());
-        assertEquals(expectedTime, rs.getTime(2));
-        expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:00").getTime());
-        assertEquals(expectedTime, rs.getTime(3));
-        expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:28").getTime());
-        assertEquals(expectedTime, rs.getTime(4));
-        expectedTime = new Time(DateUtil.parseDate("2011-12-26 00:00:00").getTime());
-        assertEquals(expectedTime, rs.getTime(5));
-        expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
-        assertEquals(expectedTime, rs.getTime(6));
-        expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
-        assertEquals(expectedTime, rs.getTime(7));
-    }
-    
-    @Test
-    public void testCeilTime() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery("SELECT CEIL(t, 'day', 1), CEIL(t, 'hour', 1), CEIL(t, 'minute', 1), CEIL(t, 'second', 1),"
-                + " CEIL(t,'week') , CEIL(t,'month') , CEIL(t,'year') FROM " + TABLE_NAME);
-        assertTrue(rs.next());
-        Time expectedTime = new Time(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
-        assertEquals(expectedTime, rs.getTime(1));
-        expectedTime = new Time(DateUtil.parseDate("2012-01-01 15:00:00").getTime());
-        assertEquals(expectedTime, rs.getTime(2));
-        expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:26:00").getTime());
-        assertEquals(expectedTime, rs.getTime(3));
-        expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:29").getTime());
-        assertEquals(expectedTime, rs.getTime(4));
-        expectedTime = new Time(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
-        assertEquals(expectedTime, rs.getTime(5));
-        expectedTime = new Time(DateUtil.parseDate("2012-02-01 00:00:00").getTime());
-        assertEquals(expectedTime, rs.getTime(6));
-        expectedTime = new Time(DateUtil.parseDate("2013-01-01 00:00:00").getTime());
-        assertEquals(expectedTime, rs.getTime(7));
-    }
-
-    @Test
-    public void testRoundingUpDecimal() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT ROUND(dec), ROUND(dec, 1), ROUND(dec, 2), ROUND(dec, 3) FROM " + TABLE_NAME);
-        assertTrue(rs.next());
-        BigDecimal expectedBd = BigDecimal.valueOf(1);
-        assertEquals(expectedBd, rs.getBigDecimal(1));
-        expectedBd = BigDecimal.valueOf(1.3);
-        assertEquals(expectedBd, rs.getBigDecimal(2));
-        expectedBd = BigDecimal.valueOf(1.26);
-        assertEquals(expectedBd, rs.getBigDecimal(3));
-        expectedBd = BigDecimal.valueOf(1.264);
-        assertEquals(expectedBd, rs.getBigDecimal(4));
-    }
-    
-    @Test
-    public void testRoundingUpDecimalInWhere() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT * FROM " + TABLE_NAME + " WHERE ROUND(dec, 2) = 1.26");
-        assertTrue(rs.next());
-    }
-    
-    @Test
-    public void testFloorDecimal() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT FLOOR(dec), FLOOR(dec, 1), FLOOR(dec, 2), FLOOR(dec, 3) FROM " + TABLE_NAME);
-        assertTrue(rs.next());
-        BigDecimal expectedBd = BigDecimal.valueOf(1);
-        assertEquals(expectedBd, rs.getBigDecimal(1));
-        expectedBd = BigDecimal.valueOf(1.2);
-        assertEquals(expectedBd, rs.getBigDecimal(2));
-        expectedBd = BigDecimal.valueOf(1.26);
-        assertEquals(expectedBd, rs.getBigDecimal(3));
-        expectedBd = BigDecimal.valueOf(1.264);
-        assertEquals(expectedBd, rs.getBigDecimal(4));
-    }
-    
-    @Test
-    public void testFloorDecimalInWhere() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT * FROM " + TABLE_NAME + " WHERE FLOOR(dec, 2) = 1.26");
-        assertTrue(rs.next());
-    }
-    
-    @Test
-    public void testCeilDecimal() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT CEIL(dec), CEIL(dec, 1), CEIL(dec, 2), CEIL(dec, 3) FROM " + TABLE_NAME);
-        assertTrue(rs.next());
-        BigDecimal expectedBd = BigDecimal.valueOf(2);
-        assertEquals(expectedBd, rs.getBigDecimal(1));
-        expectedBd = BigDecimal.valueOf(1.3);
-        assertEquals(expectedBd, rs.getBigDecimal(2));
-        expectedBd = BigDecimal.valueOf(1.27);
-        assertEquals(expectedBd, rs.getBigDecimal(3));
-        expectedBd = BigDecimal.valueOf(1.264);
-        assertEquals(expectedBd, rs.getBigDecimal(4));
-    }
-    
-    @Test
-    public void testCeilDecimalInWhere() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT * FROM " + TABLE_NAME + " WHERE CEIL(dec, 2) = 1.27");
-        assertTrue(rs.next());
-    }
-    @Test
-	public void testRoundingUpDouble() throws Exception {
-		Connection conn = DriverManager.getConnection(getUrl());
-		ResultSet rs = conn.createStatement().executeQuery(
-        "SELECT ROUND(doub), ROUND(doub, 1), ROUND(doub, 2), ROUND(doub, 3) FROM " + TABLE_NAME);
-		assertTrue(rs.next());
-		assertEquals(0, Doubles.compare(1, rs.getDouble(1)));
-		assertEquals(0, Doubles.compare(1.3, rs.getDouble(2)));
-		assertEquals(0, Doubles.compare(1.26, rs.getDouble(3)));
-		assertEquals(0, Doubles.compare(1.264, rs.getDouble(4)));
-	}
-
-	@Test
-	public void testRoundingUpDoubleInWhere() throws Exception {
-		Connection conn = DriverManager.getConnection(getUrl());
-		ResultSet rs = conn.createStatement().executeQuery(
-        "SELECT * FROM " + TABLE_NAME + " WHERE ROUND(dec, 2) = 1.26");
-		assertTrue(rs.next());
-	}
-
-	@Test
-	public void testCeilDouble() throws Exception {
-		Connection conn = DriverManager.getConnection(getUrl());
-		ResultSet rs = conn.createStatement().executeQuery(
-        "SELECT CEIL(doub), CEIL(doub, 1), CEIL(doub, 2), CEIL(doub, 3) FROM " + TABLE_NAME);
-		assertTrue(rs.next());
-		assertEquals(0, Doubles.compare(2, rs.getDouble(1)));
-		assertEquals(0, Doubles.compare(1.3, rs.getDouble(2)));
-		assertEquals(0, Doubles.compare(1.27, rs.getDouble(3)));
-		assertEquals(0, Doubles.compare(1.264, rs.getDouble(4)));
-	}
-
-	@Test
-	public void testCeilDoubleInWhere() throws Exception {
-		Connection conn = DriverManager.getConnection(getUrl());
-		ResultSet rs = conn.createStatement().executeQuery(
-        "SELECT * FROM " + TABLE_NAME + " WHERE CEIL(doub, 2) = 1.27");
-		assertTrue(rs.next());
-	}
-
-	@Test
-	public void testFloorDouble() throws Exception {
-		Connection conn = DriverManager.getConnection(getUrl());
-		ResultSet rs = conn.createStatement().executeQuery(
-        "SELECT FLOOR(doub), FLOOR(doub, 1), FLOOR(doub, 2), FLOOR(doub, 3) FROM " + TABLE_NAME);
-		assertTrue(rs.next());
-		assertEquals(0, Doubles.compare(1, rs.getDouble(1)));
-		assertEquals(0, Doubles.compare(1.2, rs.getDouble(2)));
-		assertEquals(0, Doubles.compare(1.26, rs.getDouble(3)));
-		assertEquals(0, Doubles.compare(1.264, rs.getDouble(4)));
-	}
-
-	@Test
-	public void testFloorDoubleInWhere() throws Exception {
-		Connection conn = DriverManager.getConnection(getUrl());
-		ResultSet rs = conn.createStatement().executeQuery(
-        "SELECT * FROM " + TABLE_NAME + " WHERE FLOOR(doub, 2) = 1.26");
-		assertTrue(rs.next());
-	}
-	
-	@Test
-	public void testRoundFloat() throws Exception {
-		Connection conn = DriverManager.getConnection(getUrl());
-		ResultSet rs = conn.createStatement().executeQuery(
-        "SELECT ROUND(fl), ROUND(fl, 1), ROUND(fl, 2), ROUND(fl, 3) FROM " + TABLE_NAME);
-		assertTrue(rs.next());
-		assertEquals(0, Floats.compare(1, rs.getFloat(1)));
-		assertEquals(0, Floats.compare(1.3f, rs.getFloat(2)));
-		assertEquals(0, Floats.compare(1.26f, rs.getFloat(3)));
-		assertEquals(0, Floats.compare(1.264f, rs.getFloat(4)));
-	}
-	
-	@Test
-	public void testRoundUnsignedFloat() throws Exception {
-		Connection conn = DriverManager.getConnection(getUrl());
-		ResultSet rs = conn.createStatement().executeQuery(
-        "SELECT ROUND(unfl), ROUND(unfl, 1), ROUND(unfl, 2), ROUND(unfl, 3) FROM " + TABLE_NAME);
-		assertTrue(rs.next());
-		assertEquals(0, Floats.compare(1, rs.getFloat(1)));
-		assertEquals(0, Floats.compare(1.3f, rs.getFloat(2)));
-		assertEquals(0, Floats.compare(1.26f, rs.getFloat(3)));
-		assertEquals(0, Floats.compare(1.264f, rs.getFloat(4)));
-	}
-	
-	@Test
-	public void testRoundUnsignedDouble() throws Exception {
-		Connection conn = DriverManager.getConnection(getUrl());
-		ResultSet rs = conn.createStatement().executeQuery(
-        "SELECT ROUND(undoub), ROUND(undoub, 1), ROUND(undoub, 2), ROUND(undoub, 3) FROM "
-            + TABLE_NAME);
-		assertTrue(rs.next());
-		assertEquals(0, Floats.compare(1, rs.getFloat(1)));
-		assertEquals(0, Floats.compare(1.3f, rs.getFloat(2)));
-		assertEquals(0, Floats.compare(1.26f, rs.getFloat(3)));
-		assertEquals(0, Floats.compare(1.264f, rs.getFloat(4)));
-	}	
-	
-	@Test
-	public void testTimestampAggregateFunctions() throws Exception {
-		String dateString = "2015-03-08 09:09:11.665";
-		Properties props = new Properties();
-		props.setProperty(QueryServices.DATE_FORMAT_TIMEZONE_ATTRIB, "GMT+1");
-		Connection conn = DriverManager.getConnection(getUrl(), props);
-		try {
-			conn.prepareStatement(
-					"create table TIME_AGG_TABLE("
-							+ "ID unsigned_int NOT NULL, "
-							+ "THE_DATE TIMESTAMP, "
-							+ "constraint PK primary key (ID))").execute();
-			PreparedStatement stmt = conn.prepareStatement("upsert into "
-					+ "TIME_AGG_TABLE(" + "    ID, " + "    THE_DATE)"
-					+ "VALUES (?, ?)");
-			stmt.setInt(1, 1);
-			stmt.setTimestamp(2, DateUtil.parseTimestamp(dateString));
-			stmt.execute();
-			conn.commit();
-
-			ResultSet rs = conn.prepareStatement(
-					"SELECT THE_DATE ,TRUNC(THE_DATE,'DAY') AS day_from_dt "
-							+ ",TRUNC(THE_DATE,'HOUR') AS hour_from_dt "
-							+ ",TRUNC(THE_DATE,'MINUTE') AS min_from_dt "
-							+ ",TRUNC(THE_DATE,'SECOND') AS sec_from_dt "
-							+ ",TRUNC(THE_DATE,'MILLISECOND') AS mil_from_dt "
-							+ "FROM TIME_AGG_TABLE").executeQuery();
-			assertTrue(rs.next());
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
-					rs.getTimestamp("THE_DATE"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 00:00:00.0"),
-					rs.getTimestamp("day_from_dt"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:00:00.0"),
-					rs.getTimestamp("hour_from_dt"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:00.0"),
-					rs.getTimestamp("min_from_dt"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.0"),
-					rs.getTimestamp("sec_from_dt"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
-					rs.getTimestamp("mil_from_dt"));
-			rs.close();
-
-			rs = conn.prepareStatement(
-					"SELECT THE_DATE ,ROUND(THE_DATE,'DAY') AS day_from_dt "
-							+ ",ROUND(THE_DATE,'HOUR') AS hour_from_dt "
-							+ ",ROUND(THE_DATE,'MINUTE') AS min_from_dt "
-							+ ",ROUND(THE_DATE,'SECOND') AS sec_from_dt "
-							+ ",ROUND(THE_DATE,'MILLISECOND') AS mil_from_dt "
-							+ "FROM TIME_AGG_TABLE").executeQuery();
-			assertTrue(rs.next());
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
-					rs.getTimestamp("THE_DATE"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 00:00:00.0"),
-					rs.getTimestamp("day_from_dt"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:00:00.0"),
-					rs.getTimestamp("hour_from_dt"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:00.0"),
-					rs.getTimestamp("min_from_dt"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:12.0"),
-					rs.getTimestamp("sec_from_dt"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
-					rs.getTimestamp("mil_from_dt"));
-			rs.close();
-
-			rs = conn.prepareStatement(
-					"SELECT THE_DATE ,FLOOR(THE_DATE,'DAY') AS day_from_dt "
-							+ ",FLOOR(THE_DATE,'HOUR') AS hour_from_dt "
-							+ ",FLOOR(THE_DATE,'MINUTE') AS min_from_dt "
-							+ ",FLOOR(THE_DATE,'SECOND') AS sec_from_dt "
-							+ ",FLOOR(THE_DATE,'MILLISECOND') AS mil_from_dt "
-							+ "FROM TIME_AGG_TABLE").executeQuery();
-			assertTrue(rs.next());
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
-					rs.getTimestamp("THE_DATE"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 00:00:00.0"),
-					rs.getTimestamp("day_from_dt"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:00:00.0"),
-					rs.getTimestamp("hour_from_dt"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:00.0"),
-					rs.getTimestamp("min_from_dt"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.0"),
-					rs.getTimestamp("sec_from_dt"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
-					rs.getTimestamp("mil_from_dt"));
-			rs.close();
-
-			rs = conn.prepareStatement(
-					"SELECT THE_DATE ,CEIL(THE_DATE,'DAY') AS day_from_dt "
-							+ ",CEIL(THE_DATE,'HOUR') AS hour_from_dt "
-							+ ",CEIL(THE_DATE,'MINUTE') AS min_from_dt "
-							+ ",CEIL(THE_DATE,'SECOND') AS sec_from_dt "
-							+ ",CEIL(THE_DATE,'MILLISECOND') AS mil_from_dt "
-							+ "FROM TIME_AGG_TABLE").executeQuery();
-			assertTrue(rs.next());
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
-					rs.getTimestamp("THE_DATE"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-09 00:00:00.0"),
-					rs.getTimestamp("day_from_dt"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 10:00:00.0"),
-					rs.getTimestamp("hour_from_dt"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:10:00.0"),
-					rs.getTimestamp("min_from_dt"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:12.0"),
-					rs.getTimestamp("sec_from_dt"));
-			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
-					rs.getTimestamp("mil_from_dt"));
-			rs.close();
-		} finally {
-			conn.close();
-		}
-	}
-
-  @Test
-  public void testRoundOffFunction() throws SQLException {
-    long ts = nextTimestamp();
-    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-    props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
-    Connection conn = DriverManager.getConnection(getUrl(), props);
-    String ddl = "create table round_test(k bigint primary key)";
-    conn.createStatement().execute(ddl);
-    conn.close();
-    
-    props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
-    conn = DriverManager.getConnection(getUrl(), props);
-    PreparedStatement stmt = conn.prepareStatement("upsert into round_test values(1380603308885)");
-    stmt.execute();
-    conn.commit();
-    conn.close();
-    
-
-    props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
-    conn = DriverManager.getConnection(getUrl(), props);
-    ResultSet rs;
-    stmt = conn.prepareStatement("select round(k/1000000,0) from round_test");
-    rs = stmt.executeQuery();
-    assertTrue(rs.next());
-    assertEquals(1380603, rs.getLong(1));
-    
-    props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
-    conn = DriverManager.getConnection(getUrl(), props);
-    stmt = conn.prepareStatement("select round(k/1000000,0) x from round_test group by x");
-    rs = stmt.executeQuery();
-    assertTrue(rs.next());
-    assertEquals(1380603, rs.getLong(1));
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/TransactionalViewIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TransactionalViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TransactionalViewIT.java
index aa6fa06..e5cd578 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TransactionalViewIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TransactionalViewIT.java
@@ -41,7 +41,6 @@ public class TransactionalViewIT extends BaseOwnClusterHBaseManagedTimeIT {
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
         props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Integer.toString(20));
-        props.put(QueryServices.QUEUE_SIZE_ATTRIB, Integer.toString(1024));
         props.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.toString(true));
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
@@ -107,8 +106,8 @@ public class TransactionalViewIT extends BaseOwnClusterHBaseManagedTimeIT {
             }
             assertEquals(4, count);
             
-            Thread.sleep(DEFAULT_TXN_TIMEOUT_SECONDS*1000+20000);
-            assertEquals("There should be one invalid transaction", 1, txManager.getInvalidSize());
+            // Thread.sleep(DEFAULT_TXN_TIMEOUT_SECONDS*1000+20000);
+            // assertEquals("There should be one invalid transaction", 1, txManager.getInvalidSize());
             
             // verify stats can see the rows from the invalid transaction
             analyzeTable(conn2, "v", true);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java
index 57ba858..c6a7bf0 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java
@@ -30,49 +30,41 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Collections;
-import java.util.Map;
 import java.util.Properties;
 
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
-public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
-
-    @BeforeClass
-    public static void doSetup() throws Exception {
-        Map<String, String> props = Collections.emptyMap();
-        setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
-    }
+public class UnionAllIT extends BaseHBaseManagedTimeTableReuseIT {
 
     @Test
     public void testUnionAllSelects() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE test_table " +
+            String ddl = "CREATE TABLE " + tableName1 + " " +
                     "  (a_string varchar(10) not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
 
-            String dml = "UPSERT INTO test_table VALUES(?, ?)";
+            String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
             PreparedStatement stmt = conn.prepareStatement(dml);
             stmt.setString(1, "a");
             stmt.setInt(2, 10);
             stmt.execute();
             conn.commit();
 
-            ddl = "CREATE TABLE b_table " +
+            ddl = "CREATE TABLE " + tableName2 + " " +
                     "  (a_string char(20) not null, col1 bigint" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
-            dml = "UPSERT INTO b_table VALUES(?, ?)";
+            dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
             stmt = conn.prepareStatement(dml);
             stmt.setString(1, "b");
             stmt.setInt(2, 20);
@@ -82,7 +74,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             stmt.execute();
             conn.commit();
 
-            ddl = "select * from test_table union all select * from b_table union all select * from test_table";
+            ddl = "select * from " + tableName1 + " union all select * from " + tableName2 + " union all select * from " + tableName1;
             ResultSet rs = conn.createStatement().executeQuery(ddl);
             assertTrue(rs.next());
             assertEquals("a",rs.getString(1));
@@ -104,17 +96,19 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
 
     @Test
     public void testAggregate() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE test_table " +
+            String ddl = "CREATE TABLE " + tableName1 + " " +
                     "  (a_string char(5) not null, col1 tinyint" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
 
-            String dml = "UPSERT INTO test_table VALUES(?, ?)";
+            String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
             PreparedStatement stmt = conn.prepareStatement(dml);
             stmt.setString(1, "a");
             stmt.setInt(2, 10);
@@ -127,11 +121,11 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             stmt.execute();
             conn.commit();
 
-            ddl = "CREATE TABLE b_table " +
+            ddl = "CREATE TABLE " + tableName2 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
-            dml = "UPSERT INTO b_table VALUES(?, ?)";
+            dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
             stmt = conn.prepareStatement(dml);
             stmt.setString(1, "b");
             stmt.setInt(2, 20);
@@ -141,7 +135,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             stmt.execute();
             conn.commit();
 
-            String aggregate = "select count(*) from test_table union all select count(*) from b_table union all select count(*) from test_table";
+            String aggregate = "select count(*) from " + tableName1 + " union all select count(*) from " + tableName2 + " union all select count(*) from " + tableName1;
             ResultSet rs = conn.createStatement().executeQuery(aggregate);
             assertTrue(rs.next());
             assertEquals(3,rs.getInt(1));
@@ -157,28 +151,30 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
 
     @Test
     public void testGroupBy() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE test_table " +
+            String ddl = "CREATE TABLE " + tableName1 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
 
-            String dml = "UPSERT INTO test_table VALUES(?, ?)";
+            String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
             PreparedStatement stmt = conn.prepareStatement(dml);
             stmt.setString(1, "a");
             stmt.setInt(2, 10);
             stmt.execute();
             conn.commit();
 
-            ddl = "CREATE TABLE b_table " +
+            ddl = "CREATE TABLE " + tableName2 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
-            dml = "UPSERT INTO b_table VALUES(?, ?)";
+            dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
             stmt = conn.prepareStatement(dml);
             stmt.setString(1, "b");
             stmt.setInt(2, 20);
@@ -188,7 +184,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             stmt.execute();
             conn.commit();
 
-            String aggregate = "select count(*), col1 from test_table group by col1 union all select count(*), col1 from b_table group by col1";
+            String aggregate = "select count(*), col1 from " + tableName1 + " group by col1 union all select count(*), col1 from " + tableName2 + " group by col1";
             ResultSet rs = conn.createStatement().executeQuery(aggregate);
             assertTrue(rs.next());
             assertEquals(1,rs.getInt(1));
@@ -204,17 +200,19 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
 
     @Test
     public void testOrderByLimit() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE test_table1 " +
+            String ddl = "CREATE TABLE " + tableName1 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
 
-            String dml = "UPSERT INTO test_table1 VALUES(?, ?)";
+            String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
             PreparedStatement stmt = conn.prepareStatement(dml);
             stmt.setString(1, "a");
             stmt.setInt(2, 10);
@@ -224,11 +222,11 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             stmt.execute();
             conn.commit();
 
-            ddl = "CREATE TABLE b_table1 " +
+            ddl = "CREATE TABLE " + tableName2 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
-            dml = "UPSERT INTO b_table1 VALUES(?, ?)";
+            dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
             stmt = conn.prepareStatement(dml);
             stmt.setString(1, "b");
             stmt.setInt(2, 20);
@@ -244,7 +242,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             stmt.execute();
             conn.commit();
 
-            String aggregate = "select count(*), col1 from b_table1 group by col1 union all select count(*), col1 from test_table1 group by col1 order by col1";
+            String aggregate = "select count(*), col1 from " + tableName2 + " group by col1 union all select count(*), col1 from " + tableName1 + " group by col1 order by col1";
             ResultSet rs = conn.createStatement().executeQuery(aggregate);
             assertTrue(rs.next());
             assertEquals(2,rs.getInt(1));
@@ -254,7 +252,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             assertEquals(3,rs.getInt(1));  
             assertFalse(rs.next());  
 
-            String limit = "select count(*), col1 x from test_table1 group by col1 union all select count(*), col1 x from b_table1 group by col1 order by x limit 2";
+            String limit = "select count(*), col1 x from " + tableName1 + " group by col1 union all select count(*), col1 x from " + tableName2 + " group by col1 order by x limit 2";
             rs = conn.createStatement().executeQuery(limit);
             assertTrue(rs.next());
             assertEquals(2,rs.getInt(1));
@@ -262,7 +260,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             assertEquals(1,rs.getInt(1));
             assertFalse(rs.next());  
 
-            String limitOnly = "select * from test_table1 union all select * from b_table1 limit 2";
+            String limitOnly = "select * from " + tableName1 + " union all select * from " + tableName2 + " limit 2";
             rs = conn.createStatement().executeQuery(limitOnly);
             assertTrue(rs.next());
             assertEquals("a",rs.getString(1));
@@ -278,22 +276,24 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
 
     @Test
     public void testSelectDiff() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE test_table " +
+            String ddl = "CREATE TABLE " + tableName1 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
 
-            ddl = "CREATE TABLE b_table " +
+            ddl = "CREATE TABLE " + tableName2 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
 
-            ddl = "select a_string, col1, col1 from test_table union all select * from b_table union all select a_string, col1 from test_table";
+            ddl = "select a_string, col1, col1 from " + tableName1 + " union all select * from " + tableName2 + " union all select a_string, col1 from " + tableName1;
             conn.createStatement().executeQuery(ddl);
             fail();
         }  catch (SQLException e) {
@@ -305,38 +305,40 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
 
     @Test
     public void testJoinInUnionAll() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE test_table " +
+            String ddl = "CREATE TABLE " + tableName1 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
 
-            String dml = "UPSERT INTO test_table VALUES(?, ?)";
+            String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
             PreparedStatement stmt = conn.prepareStatement(dml);
             stmt.setString(1, "a");
             stmt.setInt(2, 10);
             stmt.execute();
             conn.commit();
 
-            ddl = "CREATE TABLE b_table " +
+            ddl = "CREATE TABLE " + tableName2 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
 
 
-            dml = "UPSERT INTO b_table VALUES(?, ?)";
+            dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
             stmt = conn.prepareStatement(dml);
             stmt.setString(1, "a");
             stmt.setInt(2, 20);
             stmt.execute();
             conn.commit();
 
-            ddl = "select x.a_string, y.col1  from test_table x, b_table y where x.a_string=y.a_string union all " +
-                    "select t.a_string, s.col1 from test_table s, b_table t where s.a_string=t.a_string"; 
+            ddl = "select x.a_string, y.col1  from " + tableName1 + " x, " + tableName2 + " y where x.a_string=y.a_string union all " +
+                    "select t.a_string, s.col1 from " + tableName1 + " s, " + tableName2 + " t where s.a_string=t.a_string"; 
             ResultSet rs = conn.createStatement().executeQuery(ddl);
             assertTrue(rs.next());
             assertEquals("a",rs.getString(1));
@@ -346,8 +348,8 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             assertEquals(10,rs.getInt(2));
             assertFalse(rs.next()); 
 
-            ddl = "select x.a_string, y.col1  from test_table x join b_table y on x.a_string=y.a_string union all " +
-                    "select t.a_string, s.col1 from test_table s inner join b_table t on s.a_string=t.a_string"; 
+            ddl = "select x.a_string, y.col1  from " + tableName1 + " x join " + tableName2 + " y on x.a_string=y.a_string union all " +
+                    "select t.a_string, s.col1 from " + tableName1 + " s inner join " + tableName2 + " t on s.a_string=t.a_string"; 
             rs = conn.createStatement().executeQuery(ddl);
             assertTrue(rs.next());
             assertEquals("a",rs.getString(1));
@@ -357,9 +359,9 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             assertEquals(10,rs.getInt(2));
             assertFalse(rs.next()); 
 
-            ddl = "select x.a_string, y.col1  from test_table x left join b_table y on x.a_string=y.a_string union all " +
-                    "select t.a_string, s.col1 from test_table s inner join b_table t on s.a_string=t.a_string union all " +
-                    "select y.a_string, x.col1 from b_table x right join test_table y on x.a_string=y.a_string";
+            ddl = "select x.a_string, y.col1  from " + tableName1 + " x left join " + tableName2 + " y on x.a_string=y.a_string union all " +
+                    "select t.a_string, s.col1 from " + tableName1 + " s inner join " + tableName2 + " t on s.a_string=t.a_string union all " +
+                    "select y.a_string, x.col1 from " + tableName2 + " x right join " + tableName1 + " y on x.a_string=y.a_string";
             rs = conn.createStatement().executeQuery(ddl);
             assertTrue(rs.next());
             assertEquals("a",rs.getString(1));
@@ -378,37 +380,39 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
 
     @Test
     public void testDerivedTable() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE test_table " +
+            String ddl = "CREATE TABLE " + tableName1 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
 
-            String dml = "UPSERT INTO test_table VALUES(?, ?)";
+            String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
             PreparedStatement stmt = conn.prepareStatement(dml);
             stmt.setString(1, "a");
             stmt.setInt(2, 10);
             stmt.execute();
             conn.commit();
 
-            ddl = "CREATE TABLE b_table " +
+            ddl = "CREATE TABLE " + tableName2 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
 
-            dml = "UPSERT INTO b_table VALUES(?, ?)";
+            dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
             stmt = conn.prepareStatement(dml);
             stmt.setString(1, "a");
             stmt.setInt(2, 20);
             stmt.execute();
             conn.commit();
 
-            ddl = "select * from (select x.a_string, y.col1  from test_table x, b_table y where x.a_string=y.a_string) union all " +
-                    "select * from (select t.a_string, s.col1 from test_table s, b_table t where s.a_string=t.a_string)"; 
+            ddl = "select * from (select x.a_string, y.col1  from " + tableName1 + " x, " + tableName2 + " y where x.a_string=y.a_string) union all " +
+                    "select * from (select t.a_string, s.col1 from " + tableName1 + " s, " + tableName2 + " t where s.a_string=t.a_string)"; 
             ResultSet rs = conn.createStatement().executeQuery(ddl);
             assertTrue(rs.next());
             assertEquals("a",rs.getString(1));
@@ -424,17 +428,19 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
 
     @Test
     public void testUnionAllInDerivedTable() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE test_table " +
+            String ddl = "CREATE TABLE " + tableName1 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
 
-            String dml = "UPSERT INTO test_table VALUES(?, ?)";
+            String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
             PreparedStatement stmt = conn.prepareStatement(dml);
             stmt.setString(1, "a");
             stmt.setInt(2, 10);
@@ -444,12 +450,12 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             stmt.execute();
             conn.commit();
 
-            ddl = "CREATE TABLE b_table " +
+            ddl = "CREATE TABLE " + tableName2 + " " +
                     "  (a_string varchar not null, col2 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
 
-            dml = "UPSERT INTO b_table VALUES(?, ?)";
+            dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
             stmt = conn.prepareStatement(dml);
             stmt.setString(1, "a");
             stmt.setInt(2, 30);
@@ -460,7 +466,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             conn.commit();
 
             String query = "select a_string from " +
-                    "(select a_string, col1 from test_table union all select a_string, col2 from b_table order by a_string)";
+                    "(select a_string, col1 from " + tableName1 + " union all select a_string, col2 from " + tableName2 + " order by a_string)";
             ResultSet rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals("a", rs.getString(1));
@@ -473,7 +479,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             assertFalse(rs.next());
             
             query = "select c from " +
-                    "(select a_string, col1 c from test_table union all select a_string, col2 c from b_table order by c)";
+                    "(select a_string, col1 c from " + tableName1 + " union all select a_string, col2 c from " + tableName2 + " order by c)";
             rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals(10, rs.getInt(1));
@@ -491,17 +497,19 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
 
     @Test
     public void testUnionAllInSubquery() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE test_table " +
+            String ddl = "CREATE TABLE " + tableName1 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
 
-            String dml = "UPSERT INTO test_table VALUES(?, ?)";
+            String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
             PreparedStatement stmt = conn.prepareStatement(dml);
             stmt.setString(1, "a");
             stmt.setInt(2, 10);
@@ -511,12 +519,12 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             stmt.execute();
             conn.commit();
 
-            ddl = "CREATE TABLE b_table " +
+            ddl = "CREATE TABLE " + tableName2 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
 
-            dml = "UPSERT INTO b_table VALUES(?, ?)";
+            dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
             stmt = conn.prepareStatement(dml);
             stmt.setString(1, "a");
             stmt.setInt(2, 30);
@@ -527,10 +535,10 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             conn.commit();
 
             String[] queries = new String[2];
-            queries[0] = "select a_string, col1 from test_table where a_string in " +
-                    "(select a_string aa from b_table where a_string != 'a' union all select a_string bb from b_table)";
-            queries[1] = "select a_string, col1 from test_table where a_string in (select a_string from  " +
-                    "(select a_string from b_table where a_string != 'a' union all select a_string from b_table))";
+            queries[0] = "select a_string, col1 from " + tableName1 + " where a_string in " +
+                    "(select a_string aa from " + tableName2 + " where a_string != 'a' union all select a_string bb from " + tableName2 + ")";
+            queries[1] = "select a_string, col1 from " + tableName1 + " where a_string in (select a_string from  " +
+                    "(select a_string from " + tableName2 + " where a_string != 'a' union all select a_string from " + tableName2 + "))";
             for (String query : queries) {
                 ResultSet rs = conn.createStatement().executeQuery(query);
                 assertTrue(rs.next());
@@ -545,34 +553,36 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
 
     @Test
     public void testUnionAllWithBindParam() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE test_table " +
+            String ddl = "CREATE TABLE " + tableName1 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
-            String dml = "UPSERT INTO test_table VALUES(?, ?)";
+            String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
             PreparedStatement stmt = conn.prepareStatement(dml);
             stmt.setString(1, "a");
             stmt.setInt(2, 10);
             stmt.execute();
             conn.commit();
 
-            ddl = "CREATE TABLE b_table " +
+            ddl = "CREATE TABLE " + tableName2 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
-            dml = "UPSERT INTO b_table VALUES(?, ?)";
+            dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
             stmt = conn.prepareStatement(dml);
             stmt.setString(1, "b");
             stmt.setInt(2, 20);
             stmt.execute();
             conn.commit();
 
-            ddl = "select a_string, col1 from b_table where col1=? union all select a_string, col1 from test_table where col1=? ";
+            ddl = "select a_string, col1 from " + tableName2 + " where col1=? union all select a_string, col1 from " + tableName1 + " where col1=? ";
             stmt = conn.prepareStatement(ddl);
             stmt.setInt(1, 20);
             stmt.setInt(2, 10);
@@ -591,43 +601,45 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
 
     @Test
     public void testExplainUnionAll() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE test_table " +
+            String ddl = "CREATE TABLE " + tableName1 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
 
-            ddl = "CREATE TABLE b_table " +
+            ddl = "CREATE TABLE " + tableName2 + " " +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
 
-            ddl = "explain select a_string, col1 from test_table union all select a_string, col1 from b_table order by col1 limit 1";
+            ddl = "explain select a_string, col1 from " + tableName1 + " union all select a_string, col1 from " + tableName2 + " order by col1 limit 1";
             ResultSet rs = conn.createStatement().executeQuery(ddl);
             assertEquals(
                     "UNION ALL OVER 2 QUERIES\n" +
-                    "    CLIENT PARALLEL 1-WAY FULL SCAN OVER TEST_TABLE\n" + 
+                    "    CLIENT PARALLEL 1-WAY FULL SCAN OVER " + tableName1 + "\n" + 
                     "        SERVER TOP 1 ROW SORTED BY [COL1]\n" + 
                     "    CLIENT MERGE SORT\n" + 
-                    "    CLIENT PARALLEL 1-WAY FULL SCAN OVER B_TABLE\n" + 
+                    "    CLIENT PARALLEL 1-WAY FULL SCAN OVER " + tableName2 + "\n" + 
                     "        SERVER TOP 1 ROW SORTED BY [COL1]\n" + 
                     "    CLIENT MERGE SORT\n" + 
                     "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs)); 
             
             String limitPlan = 
                     "UNION ALL OVER 2 QUERIES\n" + 
-                    "    CLIENT SERIAL 1-WAY FULL SCAN OVER TEST_TABLE\n" + 
+                    "    CLIENT SERIAL 1-WAY FULL SCAN OVER " + tableName1 + "\n" + 
                     "        SERVER 2 ROW LIMIT\n" + 
                     "    CLIENT 2 ROW LIMIT\n" + 
-                    "    CLIENT SERIAL 1-WAY FULL SCAN OVER B_TABLE\n" + 
+                    "    CLIENT SERIAL 1-WAY FULL SCAN OVER " + tableName2 + "\n" + 
                     "        SERVER 2 ROW LIMIT\n" + 
                     "    CLIENT 2 ROW LIMIT\n" + 
                     "CLIENT 2 ROW LIMIT";
-            ddl = "explain select a_string, col1 from test_table union all select a_string, col1 from b_table";
+            ddl = "explain select a_string, col1 from " + tableName1 + " union all select a_string, col1 from " + tableName2;
             rs = conn.createStatement().executeQuery(ddl + " limit 2");
             assertEquals(limitPlan, QueryUtil.getExplainPlan(rs));
             Statement stmt = conn.createStatement();
@@ -635,12 +647,12 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             rs = stmt.executeQuery(ddl);
             assertEquals(limitPlan, QueryUtil.getExplainPlan(rs));
             
-            ddl = "explain select a_string, col1 from test_table union all select a_string, col1 from b_table";
+            ddl = "explain select a_string, col1 from " + tableName1 + " union all select a_string, col1 from " + tableName2;
             rs = conn.createStatement().executeQuery(ddl);
             assertEquals(
                     "UNION ALL OVER 2 QUERIES\n" + 
-                    "    CLIENT PARALLEL 1-WAY FULL SCAN OVER TEST_TABLE\n" + 
-                    "    CLIENT PARALLEL 1-WAY FULL SCAN OVER B_TABLE", QueryUtil.getExplainPlan(rs)); 
+                    "    CLIENT PARALLEL 1-WAY FULL SCAN OVER " + tableName1 + "\n" + 
+                    "    CLIENT PARALLEL 1-WAY FULL SCAN OVER " + tableName2, QueryUtil.getExplainPlan(rs)); 
         } finally {
             conn.close();
         }
@@ -648,66 +660,68 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
 
     @Test
     public void testBug2295() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
+        String itableName1 = generateRandomString();
+        String itableName2 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE table1(" +
+            String ddl = "CREATE TABLE " + tableName1 + "(" +
                     "id BIGINT, col1 VARCHAR, col2 integer, CONSTRAINT pk PRIMARY KEY (id)) IMMUTABLE_ROWS=true";
             createTestTable(getUrl(), ddl);
 
-            ddl = "CREATE TABLE table2(" +
+            ddl = "CREATE TABLE " + tableName2 + "(" +
                     "id BIGINT, col1 VARCHAR, col2 integer, CONSTRAINT pk PRIMARY KEY (id)) IMMUTABLE_ROWS=true";
             createTestTable(getUrl(), ddl);
 
-            ddl = "CREATE index idx_table1_col1 on table1(col1)";
+            ddl = "CREATE index " + itableName1 + " on " + tableName1 + "(col1)";
             createTestTable(getUrl(), ddl);
 
-            ddl = "CREATE index idx_table2_col1 on table2(col1)";
+            ddl = "CREATE index " + itableName2 + " on " + tableName2 + "(col1)";
             createTestTable(getUrl(), ddl);
 
-            ddl = "Explain SELECT /*+ INDEX(table1 idx_table1_col1) */ col1, col2 from table1 where col1='123' " +
-                    "union all SELECT /*+ INDEX(table2 idx_table2_col1) */ col1, col2 from table2 where col1='123'"; 
+            ddl = "Explain SELECT /*+ INDEX(" + tableName1 + " " + itableName1 + ") */ col1, col2 from " + tableName1 + " where col1='123' " +
+                    "union all SELECT /*+ INDEX(" + tableName2 + " " + itableName2 + ") */ col1, col2 from " + tableName2 + " where col1='123'"; 
             ResultSet rs = conn.createStatement().executeQuery(ddl);
             assertTrue(rs.next());
         } finally {
-            String ddl = "drop table table1";
-            conn.createStatement().execute(ddl);
-            ddl = "drop table table2";
-            conn.createStatement().execute(ddl);
             conn.close();
         }
     }
 
     @Test
     public void testParameterMetaDataNotNull() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
     
-        String ddl = "CREATE TABLE test_table " +
+        String ddl = "CREATE TABLE " + tableName1 + " " +
                 "  (a_string varchar not null, col1 integer" +
                 "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
         createTestTable(getUrl(), ddl);
-        String dml = "UPSERT INTO test_table VALUES(?, ?)";
+        String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
         PreparedStatement stmt = conn.prepareStatement(dml);
         stmt.setString(1, "a");
         stmt.setInt(2, 10);
         stmt.execute();
         conn.commit();
 
-        ddl = "CREATE TABLE b_table " +
+        ddl = "CREATE TABLE " + tableName2 + " " +
                 "  (a_string varchar not null, col1 integer" +
                 "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
         createTestTable(getUrl(), ddl);
-        dml = "UPSERT INTO b_table VALUES(?, ?)";
+        dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
         stmt = conn.prepareStatement(dml);
         stmt.setString(1, "b");
         stmt.setInt(2, 20);
         stmt.execute();
         conn.commit();
 
-        String query = "select * from test_table union all select * from b_table";
+        String query = "select * from " + tableName1 + " union all select * from " + tableName2;
 
         try{
             PreparedStatement pstmt = conn.prepareStatement(query);
@@ -727,13 +741,17 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
 
     @Test
     public void testDiffDataTypes() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
+        String tableName3 = generateRandomString();
+        String tableName4 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
 
-        String ddl = "create table person ( id bigint not null primary key, " +
+        String ddl = "create table " + tableName1 + " ( id bigint not null primary key, " +
                 "firstname varchar(10), lastname varchar(10) )";
         createTestTable(getUrl(), ddl);
-        String dml = "upsert into person values (?, ?, ?)";
+        String dml = "upsert into " + tableName1 + " values (?, ?, ?)";
         PreparedStatement stmt = conn.prepareStatement(dml);
         stmt.setInt(1, 1);
         stmt.setString(2, "john");
@@ -745,10 +763,10 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
         stmt.execute();
         conn.commit();
 
-        ddl = "create table user ( id integer not null primary key, firstname char(12)," +
+        ddl = "create table " + tableName2 + " ( id integer not null primary key, firstname char(12)," +
                 " lastname varchar(12) )";
         createTestTable(getUrl(), ddl);
-        dml = "upsert into user values (?, ?, ?)";
+        dml = "upsert into " + tableName2 + " values (?, ?, ?)";
         stmt = conn.prepareStatement(dml);
         stmt.setInt(1, 1);
         stmt.setString(2, "sam");
@@ -760,20 +778,20 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
         stmt.execute();
         conn.commit();
 
-        ddl = "create table t1 ( id varchar(20) not null primary key)";
+        ddl = "create table " + tableName3 + " ( id varchar(20) not null primary key)";
         createTestTable(getUrl(), ddl);
-        dml = "upsert into t1 values ('abcd')";
+        dml = "upsert into " + tableName3 + " values ('abcd')";
         stmt = conn.prepareStatement(dml);
         stmt.execute();
         conn.commit();
-        ddl = "create table t2 ( id char(50) not null primary key)";
+        ddl = "create table " + tableName4 + " ( id char(50) not null primary key)";
         createTestTable(getUrl(), ddl);
-        dml = "upsert into t2 values ('xyz')";
+        dml = "upsert into " + tableName4 + " values ('xyz')";
         stmt = conn.prepareStatement(dml);
         stmt.execute();
         conn.commit();
-        String query = "select id, 'foo' firstname, lastname from person union all" +
-                " select * from user";
+        String query = "select id, 'foo' firstname, lastname from " + tableName1 + " union all" +
+                " select * from " + tableName2;
         try {
             PreparedStatement pstmt = conn.prepareStatement(query);
             ResultSet rs = pstmt.executeQuery();
@@ -795,7 +813,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             assertEquals("wiely", rs.getString(3));
             assertFalse(rs.next());
 
-            pstmt = conn.prepareStatement("select * from t1 union all select * from t2");
+            pstmt = conn.prepareStatement("select * from " + tableName3 + " union all select * from " + tableName4);
             rs = pstmt.executeQuery();
             assertTrue(rs.next());
             assertEquals("abcd", rs.getString(1));
@@ -809,13 +827,17 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
 
     @Test
     public void testDiffScaleSortOrder() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
+        String tableName3 = generateRandomString();
+        String tableName4 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
 
-        String ddl = "create table person ( id bigint not null primary key desc, " +
+        String ddl = "create table " + tableName1 + " ( id bigint not null primary key desc, " +
                 "firstname char(10), lastname varchar(10) )";
         createTestTable(getUrl(), ddl);
-        String dml = "upsert into person values (?, ?, ?)";
+        String dml = "upsert into " + tableName1 + " values (?, ?, ?)";
         PreparedStatement stmt = conn.prepareStatement(dml);
         stmt.setInt(1, 1);
         stmt.setString(2, "john");
@@ -827,10 +849,10 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
         stmt.execute();
         conn.commit();
 
-        ddl = "create table user ( id integer not null primary key asc, " +
+        ddl = "create table " + tableName2 + " ( id integer not null primary key asc, " +
                 "firstname varchar(12), lastname varchar(10) )";
         createTestTable(getUrl(), ddl);
-        dml = "upsert into user values (?, ?, ?)";
+        dml = "upsert into " + tableName2 + " values (?, ?, ?)";
         stmt = conn.prepareStatement(dml);
         stmt.setInt(1, 1);
         stmt.setString(2, "sam");
@@ -842,20 +864,20 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
         stmt.execute();
         conn.commit();
 
-        ddl = "create table t1 ( id varchar(20) not null primary key, col1 decimal)";
+        ddl = "create table " + tableName3 + " ( id varchar(20) not null primary key, col1 decimal)";
         createTestTable(getUrl(), ddl);
-        dml = "upsert into t1 values ('abcd', 234.23)";
+        dml = "upsert into " + tableName3 + " values ('abcd', 234.23)";
         stmt = conn.prepareStatement(dml);
         stmt.execute();
         conn.commit();
-        ddl = "create table t2 ( id char(50) not null primary key, col1 decimal(12,4))";
+        ddl = "create table " + tableName4 + " ( id char(50) not null primary key, col1 decimal(12,4))";
         createTestTable(getUrl(), ddl);
-        dml = "upsert into t2 values ('xyz', 1342.1234)";
+        dml = "upsert into " + tableName4 + " values ('xyz', 1342.1234)";
         stmt = conn.prepareStatement(dml);
         stmt.execute();
         conn.commit();
 
-        String query = "select * from user union all select * from person";
+        String query = "select * from " + tableName2 + " union all select * from " + tableName1;
         try {
             PreparedStatement pstmt = conn.prepareStatement(query);
             ResultSet rs = pstmt.executeQuery();
@@ -877,7 +899,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             assertEquals("doe", rs.getString(3));
             assertFalse(rs.next());
 
-            pstmt = conn.prepareStatement("select * from t1 union all select * from t2");
+            pstmt = conn.prepareStatement("select * from " + tableName3 + " union all select * from " + tableName4);
             rs = pstmt.executeQuery();
             assertTrue(rs.next());
             assertEquals("abcd", rs.getString(1));
@@ -893,13 +915,15 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
 
     @Test
     public void testVarcharChar() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
 
-        String ddl = "create table user ( id integer not null primary key asc, " +
+        String ddl = "create table " + tableName2 + " ( id integer not null primary key asc, " +
                 "firstname char(8), lastname varchar )";
         createTestTable(getUrl(), ddl);
-        String dml = "upsert into user values (?, ?, ?)";
+        String dml = "upsert into " + tableName2 + " values (?, ?, ?)";
         PreparedStatement  stmt = conn.prepareStatement(dml);
         stmt.setInt(1, 1);
         stmt.setString(2, "sam");
@@ -911,10 +935,10 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
         stmt.execute();
         conn.commit();
 
-        ddl = "create table person ( id bigint not null primary key desc, " +
+        ddl = "create table " + tableName1 + " ( id bigint not null primary key desc, " +
                 "firstname varchar(10), lastname char(10) )";
         createTestTable(getUrl(), ddl);
-        dml = "upsert into person values (?, ?, ?)";
+        dml = "upsert into " + tableName1 + " values (?, ?, ?)";
         stmt = conn.prepareStatement(dml);
         stmt.setInt(1, 1);
         stmt.setString(2, "john");
@@ -926,8 +950,8 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
         stmt.execute();
         conn.commit();
 
-        String query = "select id, 'baa' firstname, lastname from user " +
-                "union all select * from person";
+        String query = "select id, 'baa' firstname, lastname from " + tableName2 + " " +
+                "union all select * from " + tableName1;
         try {
             PreparedStatement pstmt = conn.prepareStatement(query);
             ResultSet rs = pstmt.executeQuery();
@@ -955,13 +979,15 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
 
     @Test
     public void testCoerceExpr() throws Exception {
+        String tableName1 = generateRandomString();
+        String tableName2 = generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
 
-        String ddl = "create table user ( id integer not null primary key desc, " +
+        String ddl = "create table " + tableName2 + " ( id integer not null primary key desc, " +
                 "firstname char(8), lastname varchar, sales double)";
         createTestTable(getUrl(), ddl);
-        String dml = "upsert into user values (?, ?, ?, ?)";
+        String dml = "upsert into " + tableName2 + " values (?, ?, ?, ?)";
         PreparedStatement  stmt = conn.prepareStatement(dml);
         stmt.setInt(1, 1);
         stmt.setString(2, "sam");
@@ -975,10 +1001,10 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
         stmt.execute();
         conn.commit();
 
-        ddl = "create table person (id bigint not null primary key, " +
+        ddl = "create table " + tableName1 + " (id bigint not null primary key, " +
                 "firstname char(10), lastname varchar(10), sales decimal)";
         createTestTable(getUrl(), ddl);
-        dml = "upsert into person values (?, ?, ?, ?)";
+        dml = "upsert into " + tableName1 + " values (?, ?, ?, ?)";
         stmt = conn.prepareStatement(dml);
         stmt.setInt(1, 1);
         stmt.setString(2, "john");
@@ -993,7 +1019,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
         conn.commit();
 
         String query = "select id, cast('foo' as char(10)) firstname, lastname, sales " +
-                "from person union all select * from user";
+                "from " + tableName1 + " union all select * from " + tableName2;
         try {
             PreparedStatement pstmt = conn.prepareStatement(query);
             ResultSet rs = pstmt.executeQuery();
@@ -1019,7 +1045,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
             assertEquals(BigDecimal.valueOf(100.6798), rs.getBigDecimal(4));
             assertFalse(rs.next());
 
-            query = "select id, cast('foo' as char(10)) firstname, lastname, sales from person";
+            query = "select id, cast('foo' as char(10)) firstname, lastname, sales from " + tableName1;
             pstmt = conn.prepareStatement(query);
             rs = pstmt.executeQuery();
             assertTrue(rs.next());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexWithStatsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexWithStatsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexWithStatsIT.java
index 867c0f7..32f272d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexWithStatsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexWithStatsIT.java
@@ -46,9 +46,6 @@ public class ImmutableIndexWithStatsIT extends BaseOwnClusterHBaseManagedTimeIT
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(5);
         props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Long.toString(1));
-        props.put(QueryServices.EXPLAIN_CHUNK_COUNT_ATTRIB, Boolean.TRUE.toString());
-        props.put(QueryServices.THREAD_POOL_SIZE_ATTRIB, Integer.toString(4));
-        props.put(QueryServices.QUEUE_SIZE_ATTRIB, Integer.toString(500));
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
    
@@ -77,7 +74,7 @@ public class ImmutableIndexWithStatsIT extends BaseOwnClusterHBaseManagedTimeIT
         conn.createStatement().execute("UPDATE STATISTICS " + tableName);
         query = "SELECT COUNT(*) FROM " + tableName;
         rs = conn.createStatement().executeQuery("EXPLAIN " + query);
-        assertTrue(QueryUtil.getExplainPlan(rs).startsWith("CLIENT 7-CHUNK PARALLEL 1-WAY FULL SCAN"));
+        assertTrue(QueryUtil.getExplainPlan(rs).startsWith("CLIENT PARALLEL 1-WAY FULL SCAN"));
 
         String indexName = TestUtil.DEFAULT_INDEX_TABLE_NAME;
         conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + " (v)");


[04/47] phoenix git commit: PHOENIX-3054 Counting zero null rows returns an empty result set

Posted by ma...@apache.org.
PHOENIX-3054 Counting zero null rows returns an empty result set


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

Branch: refs/heads/calcite
Commit: 7827178b7addbd336d5a5c3b12a4e1b764f0f74a
Parents: fce0f10
Author: Ankit Singhal <an...@gmail.com>
Authored: Tue Sep 6 10:58:33 2016 +0530
Committer: Ankit Singhal <an...@gmail.com>
Committed: Tue Sep 6 10:58:33 2016 +0530

----------------------------------------------------------------------
 .../phoenix/end2end/AggregateQueryIT.java       | 36 ++++++++++++++++++++
 .../phoenix/end2end/index/ViewIndexIT.java      | 25 +++++---------
 .../apache/phoenix/execute/BaseQueryPlan.java   |  7 +++-
 .../iterate/MergeSortResultIterator.java        |  2 +-
 4 files changed, 52 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/7827178b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AggregateQueryIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AggregateQueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AggregateQueryIT.java
index f23b5eb..01cc2c1 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AggregateQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AggregateQueryIT.java
@@ -191,6 +191,42 @@ public class AggregateQueryIT extends BaseQueryIT {
             conn.close();
         }
     }
+    
+    
+    @Test
+    public void testCountWithNoScanRanges() throws Exception {
+        String query = "SELECT count(1) FROM aTable WHERE organization_id = 'not_existing_organization_id'";
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
+		Connection conn = DriverManager.getConnection(getUrl(), props);
+		try {
+			PreparedStatement statement = conn.prepareStatement(query);
+			ResultSet rs = statement.executeQuery();
+			assertTrue(rs.next());
+			assertEquals(0, rs.getLong(1));
+			assertFalse(rs.next());
+			query = "SELECT count(1) FROM aTable WHERE organization_id = 'not_existing_organization_id' having count(*)>0";
+			rs = conn.prepareStatement(query).executeQuery();
+			assertFalse(rs.next());
+			query = "SELECT count(1) FROM aTable WHERE organization_id = 'not_existing_organization_id' limit 1 offset 1";
+			rs = conn.prepareStatement(query).executeQuery();
+			assertFalse(rs.next());
+			query = "SELECT count(1),123 FROM aTable WHERE organization_id = 'not_existing_organization_id'";
+			rs = conn.prepareStatement(query).executeQuery();
+			assertTrue(rs.next());
+			assertEquals(0, rs.getLong(1));
+			assertEquals("123", rs.getString(2));
+			assertFalse(rs.next());
+			query = "SELECT count(1),sum(x_decimal) FROM aTable WHERE organization_id = 'not_existing_organization_id'";
+			rs = conn.prepareStatement(query).executeQuery();
+			assertTrue(rs.next());
+			assertEquals(0, rs.getLong(1));
+			assertEquals(null, rs.getBigDecimal(2));
+			assertFalse(rs.next());
+		} finally {
+			conn.close();
+		}
+	}
 
     @Test
     public void testCountIsNotNull() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7827178b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
index d97a749..c985fc9 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
@@ -39,17 +39,14 @@ import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
 import org.apache.phoenix.end2end.Shadower;
-import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.PNameFactory;
-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.TestUtil;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -133,24 +130,20 @@ public class ViewIndexIT extends BaseHBaseManagedTimeTableReuseIT {
         conn1.createStatement().execute("CREATE VIEW " + viewName + " AS SELECT * FROM " + tableName);
         conn1.createStatement().execute("CREATE INDEX " + indexName + " ON " + viewName + " (v1)");
         conn2.createStatement().executeQuery("SELECT * FROM " + tableName).next();
-        String query = "SELECT sequence_schema, sequence_name, current_value, increment_by FROM SYSTEM.\"SEQUENCE\" WHERE sequence_schema like '%"
-                + schemaName + "%'";
-        ResultSet rs = conn1.prepareStatement(query).executeQuery();
-        assertTrue(rs.next());
-        assertEquals(MetaDataUtil.getViewIndexSequenceSchemaName(PNameFactory.newName(tableName), isNamespaceMapped),
-                rs.getString("sequence_schema"));
-        assertEquals(MetaDataUtil.getViewIndexSequenceName(PNameFactory.newName(tableName), null, isNamespaceMapped),
-                rs.getString("sequence_name"));
-        assertEquals(-32767, rs.getInt("current_value"));
-        assertEquals(1, rs.getInt("increment_by"));
-        assertFalse(rs.next());
+        String sequenceName = getViewIndexSequenceName(PNameFactory.newName(tableName), null, isNamespaceMapped);
+        String sequenceSchemaName = getViewIndexSequenceSchemaName(PNameFactory.newName(tableName), isNamespaceMapped);
+        String seqName = getViewIndexSequenceName(PNameFactory.newName(tableName), null, !isNamespaceMapped);
+        String seqSchemaName = getViewIndexSequenceSchemaName(PNameFactory.newName(tableName), !isNamespaceMapped);
+        verifySequence(null, sequenceName, sequenceSchemaName, true);
+        // Check other format of sequence is not there as Sequences format is different for views/indexes created on
+        // table which are namespace mapped and which are not.
+        verifySequence(null, seqName, seqSchemaName, false);
         HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin();
         conn1.createStatement().execute("DROP VIEW " + viewName);
         conn1.createStatement().execute("DROP TABLE "+ tableName);
         admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin();
         assertFalse("View index table should be deleted.", admin.tableExists(TableName.valueOf(viewIndexPhysicalTableName)));
-        String sequenceName = getViewIndexSequenceName(PNameFactory.newName(tableName), PNameFactory.newName("a"), isNamespaceMapped);
-        String sequenceSchemaName = getViewIndexSequenceSchemaName(PNameFactory.newName(tableName), isNamespaceMapped);
+        
         verifySequence(null, sequenceName, sequenceSchemaName, false);
 
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7827178b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
index b573f07..1e09079 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
@@ -217,7 +217,12 @@ public abstract class BaseQueryPlan implements QueryPlan {
     }
 
     public final ResultIterator iterator(final List<? extends SQLCloseable> dependencies, ParallelScanGrouper scanGrouper, Scan scan) throws SQLException {
-        if (context.getScanRanges() == ScanRanges.NOTHING) {
+		/*
+		 * For aggregate queries, we still need to let the AggregationPlan to
+		 * proceed so that we can give proper aggregates even if there are no
+		 * row to be scanned.
+		 */
+        if (context.getScanRanges() == ScanRanges.NOTHING && !getStatement().isAggregate()) {
             return ResultIterator.EMPTY_ITERATOR;
         }
         

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7827178b/phoenix-core/src/main/java/org/apache/phoenix/iterate/MergeSortResultIterator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/MergeSortResultIterator.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/MergeSortResultIterator.java
index 961e766..d094bec 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/MergeSortResultIterator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/MergeSortResultIterator.java
@@ -70,7 +70,7 @@ public abstract class MergeSortResultIterator implements PeekingResultIterator {
     private PriorityQueue<MaterializedComparableResultIterator> getMinHeap() throws SQLException {
         if (minHeap == null) {
             List<PeekingResultIterator> iterators = resultIterators.getIterators();
-            minHeap = new PriorityQueue<MaterializedComparableResultIterator>(iterators.size());
+            minHeap = new PriorityQueue<MaterializedComparableResultIterator>(Math.max(1, iterators.size()));
             for (PeekingResultIterator itr : iterators) {
                 if (itr.peek() == null) {
                     itr.close();


[27/47] phoenix git commit: PHOENIX-3072 Deadlock on region opening with secondary index recovery (Enis Soztutar)

Posted by ma...@apache.org.
PHOENIX-3072 Deadlock on region opening with secondary index recovery (Enis Soztutar)

Signed-off-by: Josh Elser <el...@apache.org>


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

Branch: refs/heads/calcite
Commit: 2c2b552cd7c611c63677b0be075065504d579469
Parents: 7af7088
Author: James Taylor <ja...@apache.org>
Authored: Tue Sep 13 22:37:18 2016 -0700
Committer: Josh Elser <el...@apache.org>
Committed: Wed Sep 14 14:44:04 2016 -0400

----------------------------------------------------------------------
 .../apache/phoenix/end2end/index/IndexIT.java   | 1136 +++++++++---------
 .../query/ConnectionQueryServicesImpl.java      | 1005 ++++++++--------
 .../apache/phoenix/query/QueryConstants.java    |    5 +
 .../apache/phoenix/schema/MetaDataClient.java   |  568 ++++-----
 4 files changed, 1398 insertions(+), 1316 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/2c2b552c/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
index 072e216..a5fefe2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
@@ -22,6 +22,7 @@ import static org.apache.phoenix.query.QueryConstants.MILLIS_IN_DAY;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 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.fail;
@@ -43,11 +44,14 @@ import java.util.Properties;
 import org.apache.hadoop.hbase.Cell;
 import org.apache.hadoop.hbase.CellScanner;
 import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.client.HTableInterface;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.ResultScanner;
 import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.ipc.PhoenixRpcSchedulerFactory;
 import org.apache.phoenix.compile.ColumnResolver;
 import org.apache.phoenix.compile.FromCompiler;
 import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
@@ -59,6 +63,7 @@ import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.parse.NamedTableNode;
 import org.apache.phoenix.parse.TableName;
 import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTableKey;
@@ -79,45 +84,45 @@ import com.google.common.collect.Maps;
 
 @RunWith(Parameterized.class)
 public class IndexIT extends BaseOwnClusterIT {
-	
-	private final boolean localIndex;
+
+    private final boolean localIndex;
     private final boolean transactional;
     private final boolean mutable;
-	private final String tableDDLOptions;
-
-	
-	public IndexIT(boolean localIndex, boolean mutable, boolean transactional) {
-		this.localIndex = localIndex;
-		this.transactional = transactional;
-		this.mutable = mutable;
-		StringBuilder optionBuilder = new StringBuilder();
-		if (!mutable) 
-			optionBuilder.append(" IMMUTABLE_ROWS=true ");
-		if (transactional) {
-			if (!(optionBuilder.length()==0))
-				optionBuilder.append(",");
-			optionBuilder.append(" TRANSACTIONAL=true ");
-		}
-		this.tableDDLOptions = optionBuilder.toString();
-	}
-	
-	@BeforeClass
+    private final String tableDDLOptions;
+
+
+    public IndexIT(boolean localIndex, boolean mutable, boolean transactional) {
+        this.localIndex = localIndex;
+        this.transactional = transactional;
+        this.mutable = mutable;
+        StringBuilder optionBuilder = new StringBuilder();
+        if (!mutable)
+            optionBuilder.append(" IMMUTABLE_ROWS=true ");
+        if (transactional) {
+            if (!(optionBuilder.length()==0))
+                optionBuilder.append(",");
+            optionBuilder.append(" TRANSACTIONAL=true ");
+        }
+        this.tableDDLOptions = optionBuilder.toString();
+    }
+
+    @BeforeClass
     @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(1);
         props.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.toString(true));
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
-	
-	@Parameters(name="localIndex = {0} , mutable = {1} , transactional = {2}")
+
+    @Parameters(name="localIndex = {0} , mutable = {1} , transactional = {2}")
     public static Collection<Boolean[]> data() {
-        return Arrays.asList(new Boolean[][] {     
-                 { false, false, false }, { false, false, true }, { false, true, false }, { false, true, true }, 
+        return Arrays.asList(new Boolean[][] {
+                 { false, false, false }, { false, false, true }, { false, true, false }, { false, true, true },
                  { true, false, false }, { true, false, true }, { true, true, false }, { true, true, true }
            });
     }
 
-	@Test
+    @Test
     public void testIndexWithNullableFixedWithCols() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         String tableName = "TBL_" + generateRandomString();
@@ -125,58 +130,58 @@ public class IndexIT extends BaseOwnClusterIT {
         String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
 
         try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-	        conn.setAutoCommit(false);
-	        String ddl ="CREATE TABLE " + fullTableName + BaseTest.TEST_TABLE_SCHEMA + tableDDLOptions;
-	        Statement stmt = conn.createStatement();
-	        stmt.execute(ddl);
-	        BaseTest.populateTestTable(fullTableName);
-	        ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullTableName 
-	                    + " (char_col1 ASC, int_col1 ASC)"
-	                    + " INCLUDE (long_col1, long_col2)";
-	        stmt.execute(ddl);
-	        
-	        String query = "SELECT d.char_col1, int_col1 from " + fullTableName + " as d";
-	        ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + query);
-	        if(localIndex) {
-	            assertEquals(
-	                "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + tableName + " [1]\n" + 
-	                "    SERVER FILTER BY FIRST KEY ONLY\n" +
-	                "CLIENT MERGE SORT",
-	                QueryUtil.getExplainPlan(rs));
-	        } else {
-	            assertEquals("CLIENT PARALLEL 1-WAY FULL SCAN OVER " + indexName + "\n"
-	                    + "    SERVER FILTER BY FIRST KEY ONLY", QueryUtil.getExplainPlan(rs));
-	        }
-	        
-	        rs = conn.createStatement().executeQuery(query);
-	        assertTrue(rs.next());
-	        assertEquals("chara", rs.getString(1));
-	        assertEquals("chara", rs.getString("char_col1"));
-	        assertEquals(2, rs.getInt(2));
-	        assertTrue(rs.next());
-	        assertEquals("chara", rs.getString(1));
-	        assertEquals(3, rs.getInt(2));
-	        assertTrue(rs.next());
-	        assertEquals("chara", rs.getString(1));
-	        assertEquals(4, rs.getInt(2));
-	        assertFalse(rs.next());
-	        
-	        conn.createStatement().execute("DROP INDEX " + indexName + " ON " + fullTableName);
-	        
-	        query = "SELECT char_col1, int_col1 from " + fullTableName;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertTrue(rs.next());
-	        
-	        query = "SELECT char_col1, int_col1 from "+indexName;
-	        try{
-	            rs = conn.createStatement().executeQuery(query);
-	            fail();
-	        } catch (SQLException e) {
-	            assertEquals(SQLExceptionCode.TABLE_UNDEFINED.getErrorCode(), e.getErrorCode());
-	        }
+            conn.setAutoCommit(false);
+            String ddl ="CREATE TABLE " + fullTableName + BaseTest.TEST_TABLE_SCHEMA + tableDDLOptions;
+            Statement stmt = conn.createStatement();
+            stmt.execute(ddl);
+            BaseTest.populateTestTable(fullTableName);
+            ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullTableName
+                    + " (char_col1 ASC, int_col1 ASC)"
+                    + " INCLUDE (long_col1, long_col2)";
+            stmt.execute(ddl);
+
+            String query = "SELECT d.char_col1, int_col1 from " + fullTableName + " as d";
+            ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + query);
+            if(localIndex) {
+                assertEquals(
+                        "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + tableName + " [1]\n" +
+                                "    SERVER FILTER BY FIRST KEY ONLY\n" +
+                                "CLIENT MERGE SORT",
+                                QueryUtil.getExplainPlan(rs));
+            } else {
+                assertEquals("CLIENT PARALLEL 1-WAY FULL SCAN OVER " + indexName + "\n"
+                        + "    SERVER FILTER BY FIRST KEY ONLY", QueryUtil.getExplainPlan(rs));
+            }
+
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals("chara", rs.getString(1));
+            assertEquals("chara", rs.getString("char_col1"));
+            assertEquals(2, rs.getInt(2));
+            assertTrue(rs.next());
+            assertEquals("chara", rs.getString(1));
+            assertEquals(3, rs.getInt(2));
+            assertTrue(rs.next());
+            assertEquals("chara", rs.getString(1));
+            assertEquals(4, rs.getInt(2));
+            assertFalse(rs.next());
+
+            conn.createStatement().execute("DROP INDEX " + indexName + " ON " + fullTableName);
+
+            query = "SELECT char_col1, int_col1 from " + fullTableName;
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+
+            query = "SELECT char_col1, int_col1 from "+indexName;
+            try{
+                rs = conn.createStatement().executeQuery(query);
+                fail();
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.TABLE_UNDEFINED.getErrorCode(), e.getErrorCode());
+            }
         }
     }
-    
+
     @Test
     public void testDeleteFromAllPKColumnIndex() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
@@ -185,57 +190,57 @@ public class IndexIT extends BaseOwnClusterIT {
         String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
         String fullIndexName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, indexName);
         try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-	        conn.setAutoCommit(false);
-	        String ddl ="CREATE TABLE " + fullTableName + BaseTest.TEST_TABLE_SCHEMA + tableDDLOptions;
-	        Statement stmt = conn.createStatement();
-	        stmt.execute(ddl);
-	        BaseTest.populateTestTable(fullTableName);
-	        ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullTableName
-	                    + " (long_pk, varchar_pk)"
-	                    + " INCLUDE (long_col1, long_col2)";
-	        stmt.execute(ddl);
-	        
-	        ResultSet rs;
-	        
-	        rs = conn.createStatement().executeQuery("SELECT COUNT(*) FROM " + fullTableName);
-	        assertTrue(rs.next());
-	        assertEquals(3,rs.getInt(1));
-	        rs = conn.createStatement().executeQuery("SELECT COUNT(*) FROM " + fullIndexName);
-	        assertTrue(rs.next());
-	        assertEquals(3,rs.getInt(1));
-	        
-	        String dml = "DELETE from " + fullTableName + " WHERE long_col2 = 4";
-	        assertEquals(1,conn.createStatement().executeUpdate(dml));
-	        conn.commit();
-	        
-	        String query = "SELECT /*+ NO_INDEX */ long_pk FROM " + fullTableName;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertTrue(rs.next());
-	        assertEquals(1L, rs.getLong(1));
-	        assertTrue(rs.next());
-	        assertEquals(3L, rs.getLong(1));
-	        assertFalse(rs.next());
-	        
-	        query = "SELECT long_pk FROM " + fullTableName;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertTrue(rs.next());
-	        assertEquals(1L, rs.getLong(1));
-	        assertTrue(rs.next());
-	        assertEquals(3L, rs.getLong(1));
-	        assertFalse(rs.next());
-	        
-	        query = "SELECT * FROM " + fullIndexName;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertTrue(rs.next());
-	        assertEquals(1L, rs.getLong(1));
-	        assertTrue(rs.next());
-	        assertEquals(3L, rs.getLong(1));
-	        assertFalse(rs.next());
-	        
-	        conn.createStatement().execute("DROP INDEX " + indexName + " ON " + fullTableName);
+            conn.setAutoCommit(false);
+            String ddl ="CREATE TABLE " + fullTableName + BaseTest.TEST_TABLE_SCHEMA + tableDDLOptions;
+            Statement stmt = conn.createStatement();
+            stmt.execute(ddl);
+            BaseTest.populateTestTable(fullTableName);
+            ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullTableName
+                        + " (long_pk, varchar_pk)"
+                        + " INCLUDE (long_col1, long_col2)";
+            stmt.execute(ddl);
+
+            ResultSet rs;
+
+            rs = conn.createStatement().executeQuery("SELECT COUNT(*) FROM " + fullTableName);
+            assertTrue(rs.next());
+            assertEquals(3,rs.getInt(1));
+            rs = conn.createStatement().executeQuery("SELECT COUNT(*) FROM " + fullIndexName);
+            assertTrue(rs.next());
+            assertEquals(3,rs.getInt(1));
+
+            String dml = "DELETE from " + fullTableName + " WHERE long_col2 = 4";
+            assertEquals(1,conn.createStatement().executeUpdate(dml));
+            conn.commit();
+
+            String query = "SELECT /*+ NO_INDEX */ long_pk FROM " + fullTableName;
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals(1L, rs.getLong(1));
+            assertTrue(rs.next());
+            assertEquals(3L, rs.getLong(1));
+            assertFalse(rs.next());
+
+            query = "SELECT long_pk FROM " + fullTableName;
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals(1L, rs.getLong(1));
+            assertTrue(rs.next());
+            assertEquals(3L, rs.getLong(1));
+            assertFalse(rs.next());
+
+            query = "SELECT * FROM " + fullIndexName;
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals(1L, rs.getLong(1));
+            assertTrue(rs.next());
+            assertEquals(3L, rs.getLong(1));
+            assertFalse(rs.next());
+
+            conn.createStatement().execute("DROP INDEX " + indexName + " ON " + fullTableName);
         }
     }
-    
+
     @Test
     public void testCreateIndexAfterUpsertStarted() throws Exception {
         String tableName = "TBL_" + generateRandomString();
@@ -258,13 +263,13 @@ public class IndexIT extends BaseOwnClusterIT {
             BaseTest.populateTestTable(fullTableName);
 
             ResultSet rs;
-            
+
             rs = conn1.createStatement().executeQuery("SELECT COUNT(*) FROM " + fullTableName);
             assertTrue(rs.next());
             assertEquals(3,rs.getInt(1));
 
             try (Connection conn2 = DriverManager.getConnection(getUrl(), props)) {
-                
+
                 String upsert = "UPSERT INTO " + fullTableName
                         + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                 PreparedStatement pstmt2 = conn2.prepareStatement(upsert);
@@ -288,39 +293,39 @@ public class IndexIT extends BaseOwnClusterIT {
                 pstmt2.setBigDecimal(17, new BigDecimal(3.0));
                 pstmt2.setDate(18, date);
                 pstmt2.executeUpdate();
-                
+
                 if (readOwnWrites) {
                     String query = "SELECT long_pk FROM " + fullTableName + " WHERE long_pk=4";
                     rs = conn2.createStatement().executeQuery(query);
                     assertTrue(rs.next());
                     assertFalse(rs.next());
                 }
-                
+
                 String indexName = SchemaUtil.getTableNameFromFullName(fullIndexName);
                 ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullTableName
                         + " (long_pk, varchar_pk)"
                         + " INCLUDE (long_col1, long_col2)";
                 stmt1.execute(ddl);
-                
+
                 /*
                  * Commit upsert after index created through different connection.
                  * This forces conn2 (which doesn't know about the index yet) to update the metadata
                  * at commit time, recognize the new index, and generate the correct metadata (or index
                  * rows for immutable indexes).
-                 * 
+                 *
                  * For transactional data, this is problematic because the index
                  * gets a timestamp *after* the commit timestamp of conn2 and thus won't be seen during
                  * the commit. Also, when the index is being built, the data hasn't yet been committed
                  * and thus won't be part of the initial index build (fixed by PHOENIX-2446).
                  */
                 conn2.commit();
-                
+
                 stmt1 = conn1.createStatement();
                 rs = stmt1.executeQuery("SELECT COUNT(*) FROM " + fullTableName);
                 assertTrue(rs.next());
                 assertEquals(4,rs.getInt(1));
                 assertEquals(fullIndexName, stmt1.unwrap(PhoenixStatement.class).getQueryPlan().getTableRef().getTable().getName().getString());
-                
+
                 String query = "SELECT /*+ NO_INDEX */ long_pk FROM " + fullTableName;
                 rs = conn1.createStatement().executeQuery(query);
                 assertTrue(rs.next());
@@ -335,7 +340,7 @@ public class IndexIT extends BaseOwnClusterIT {
             }
         }
     }
-    
+
     @Test
     public void testDeleteFromNonPKColumnIndex() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
@@ -346,85 +351,85 @@ public class IndexIT extends BaseOwnClusterIT {
 
         String ddl ="CREATE TABLE " + fullTableName + BaseTest.TEST_TABLE_SCHEMA + tableDDLOptions;
         try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-	        conn.setAutoCommit(false);
-	        Statement stmt = conn.createStatement();
-	        stmt.execute(ddl);
-	        BaseTest.populateTestTable(fullTableName);
-	        ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullTableName
-	                    + " (long_col1, long_col2)"
-	                    + " INCLUDE (decimal_col1, decimal_col2)";
-	        stmt.execute(ddl);
+            conn.setAutoCommit(false);
+            Statement stmt = conn.createStatement();
+            stmt.execute(ddl);
+            BaseTest.populateTestTable(fullTableName);
+            ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullTableName
+                        + " (long_col1, long_col2)"
+                        + " INCLUDE (decimal_col1, decimal_col2)";
+            stmt.execute(ddl);
         }
-        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {    
-	        ResultSet rs;
-	        
-	        rs = conn.createStatement().executeQuery("SELECT COUNT(*) FROM " + fullTableName);
-	        assertTrue(rs.next());
-	        assertEquals(3,rs.getInt(1));
-	        rs = conn.createStatement().executeQuery("SELECT COUNT(*) FROM " + fullIndexName);
-	        assertTrue(rs.next());
-	        assertEquals(3,rs.getInt(1));
-	        
-	        String dml = "DELETE from " + fullTableName + " WHERE long_col2 = 4";
-	        assertEquals(1,conn.createStatement().executeUpdate(dml));
-	        conn.commit();
-
-	        // query the data table
-	        String query = "SELECT /*+ NO_INDEX */ long_pk FROM " + fullTableName;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertTrue(rs.next());
-	        assertEquals(1L, rs.getLong(1));
-	        assertTrue(rs.next());
-	        assertEquals(3L, rs.getLong(1));
-	        assertFalse(rs.next());
-	        
-	        // query the index table
-	        query = "SELECT long_pk FROM " + fullTableName + " ORDER BY long_col1";
-	        rs = conn.createStatement().executeQuery(query);
-	        assertTrue(rs.next());
-	        assertEquals(1L, rs.getLong(1));
-	        assertTrue(rs.next());
-	        assertEquals(3L, rs.getLong(1));
-	        assertFalse(rs.next());
-	        
-	        conn.createStatement().execute("DROP INDEX " + indexName + " ON " + fullTableName);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            ResultSet rs;
+
+            rs = conn.createStatement().executeQuery("SELECT COUNT(*) FROM " + fullTableName);
+            assertTrue(rs.next());
+            assertEquals(3,rs.getInt(1));
+            rs = conn.createStatement().executeQuery("SELECT COUNT(*) FROM " + fullIndexName);
+            assertTrue(rs.next());
+            assertEquals(3,rs.getInt(1));
+
+            String dml = "DELETE from " + fullTableName + " WHERE long_col2 = 4";
+            assertEquals(1,conn.createStatement().executeUpdate(dml));
+            conn.commit();
+
+            // query the data table
+            String query = "SELECT /*+ NO_INDEX */ long_pk FROM " + fullTableName;
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals(1L, rs.getLong(1));
+            assertTrue(rs.next());
+            assertEquals(3L, rs.getLong(1));
+            assertFalse(rs.next());
+
+            // query the index table
+            query = "SELECT long_pk FROM " + fullTableName + " ORDER BY long_col1";
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals(1L, rs.getLong(1));
+            assertTrue(rs.next());
+            assertEquals(3L, rs.getLong(1));
+            assertFalse(rs.next());
+
+            conn.createStatement().execute("DROP INDEX " + indexName + " ON " + fullTableName);
         }
     }
-    
+
     @Test
     public void testGroupByCount() throws Exception {
-    	Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         String tableName = "TBL_" + generateRandomString();
         String indexName = "IND_" + generateRandomString();
         String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
-    	try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-	        conn.setAutoCommit(false);
-	        String ddl ="CREATE TABLE " + fullTableName + BaseTest.TEST_TABLE_SCHEMA + tableDDLOptions;
-	        Statement stmt = conn.createStatement();
-	        stmt.execute(ddl);
-	        BaseTest.populateTestTable(fullTableName);
-	        ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullTableName + " (int_col2)";
-	        stmt.execute(ddl);
-	        ResultSet rs;
-	        rs = conn.createStatement().executeQuery("SELECT int_col2, COUNT(*) FROM " + fullTableName + " GROUP BY int_col2");
-	        assertTrue(rs.next());
-	        assertEquals(1,rs.getInt(2));
-    	}
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.setAutoCommit(false);
+            String ddl ="CREATE TABLE " + fullTableName + BaseTest.TEST_TABLE_SCHEMA + tableDDLOptions;
+            Statement stmt = conn.createStatement();
+            stmt.execute(ddl);
+            BaseTest.populateTestTable(fullTableName);
+            ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullTableName + " (int_col2)";
+            stmt.execute(ddl);
+            ResultSet rs;
+            rs = conn.createStatement().executeQuery("SELECT int_col2, COUNT(*) FROM " + fullTableName + " GROUP BY int_col2");
+            assertTrue(rs.next());
+            assertEquals(1,rs.getInt(2));
+        }
     }
 
     @Test
     public void testSelectDistinctOnTableWithSecondaryImmutableIndex() throws Exception {
-    	Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         String tableName = "TBL_" + generateRandomString();
         String indexName = "IND_" + generateRandomString();
         String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
-    	try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-	        conn.setAutoCommit(false);
-	        String ddl ="CREATE TABLE " + fullTableName + BaseTest.TEST_TABLE_SCHEMA + tableDDLOptions;
-	        Statement stmt = conn.createStatement();
-	        stmt.execute(ddl);
-	        BaseTest.populateTestTable(fullTableName);
-	        ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullTableName + " (int_col2)";
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.setAutoCommit(false);
+            String ddl ="CREATE TABLE " + fullTableName + BaseTest.TEST_TABLE_SCHEMA + tableDDLOptions;
+            Statement stmt = conn.createStatement();
+            stmt.execute(ddl);
+            BaseTest.populateTestTable(fullTableName);
+            ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullTableName + " (int_col2)";
             PreparedStatement pstmt = conn.prepareStatement(ddl);
             pstmt.execute();
             ResultSet rs = conn.createStatement().executeQuery("SELECT distinct int_col2 FROM " + fullTableName + " where int_col2 > 0");
@@ -435,22 +440,22 @@ public class IndexIT extends BaseOwnClusterIT {
             assertTrue(rs.next());
             assertEquals(5, rs.getInt(1));
             assertFalse(rs.next());
-    	}
+        }
     }
 
     @Test
     public void testInClauseWithIndexOnColumnOfUsignedIntType() throws Exception {
-    	Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         String tableName = "TBL_" + generateRandomString();
         String indexName = "IND_" + generateRandomString();
         String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
-    	try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-	        conn.setAutoCommit(false);
-	        String ddl ="CREATE TABLE " + fullTableName + BaseTest.TEST_TABLE_SCHEMA + tableDDLOptions;
-	        Statement stmt = conn.createStatement();
-	        stmt.execute(ddl);
-	        BaseTest.populateTestTable(fullTableName);
-	        ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullTableName + " (int_col1)";
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.setAutoCommit(false);
+            String ddl ="CREATE TABLE " + fullTableName + BaseTest.TEST_TABLE_SCHEMA + tableDDLOptions;
+            Statement stmt = conn.createStatement();
+            stmt.execute(ddl);
+            BaseTest.populateTestTable(fullTableName);
+            ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullTableName + " (int_col1)";
             stmt.execute(ddl);
             ResultSet rs = conn.createStatement().executeQuery("SELECT int_col1 FROM " + fullTableName + " where int_col1 IN (1, 2, 3, 4)");
             assertTrue(rs.next());
@@ -460,9 +465,9 @@ public class IndexIT extends BaseOwnClusterIT {
             assertTrue(rs.next());
             assertEquals(4, rs.getInt(1));
             assertFalse(rs.next());
-    	}
+        }
     }
-    
+
     @Test
     public void createIndexOnTableWithSpecifiedDefaultCF() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
@@ -471,69 +476,69 @@ public class IndexIT extends BaseOwnClusterIT {
         String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
         String fullIndexName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, indexName);
         try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-	        conn.setAutoCommit(false);
-	        String query;
+            conn.setAutoCommit(false);
+            String query;
             ResultSet rs;
-	        String ddl ="CREATE TABLE " + fullTableName 
-	        		+ " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) DEFAULT_COLUMN_FAMILY='A'" + (!tableDDLOptions.isEmpty() ? "," + tableDDLOptions : "");
-	        Statement stmt = conn.createStatement();
-	        stmt.execute(ddl);
-
-	        query = "SELECT * FROM " + tableName;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertFalse(rs.next());
-
-	        String options = localIndex ? "SALT_BUCKETS=10, MULTI_TENANT=true, IMMUTABLE_ROWS=true, DISABLE_WAL=true" : "";
-	        conn.createStatement().execute(
-	                "CREATE INDEX " + indexName + " ON " + fullTableName + " (v1) INCLUDE (v2) " + options);
-	        query = "SELECT * FROM " + fullIndexName;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertFalse(rs.next());
-	        
-	        //check options set correctly on index
-	        TableName indexTableName = TableName.create(TestUtil.DEFAULT_SCHEMA_NAME, indexName);
-	        NamedTableNode indexNode = NamedTableNode.create(null, indexTableName, 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());
-	        assertEquals(mutable, !indexTable.isImmutableRows()); // Should match table
-	        if(localIndex) {
-	            assertEquals(10, indexTable.getBucketNum().intValue());
-	            assertTrue(indexTable.isWALDisabled());
-	        }
+            String ddl ="CREATE TABLE " + fullTableName
+                    + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) DEFAULT_COLUMN_FAMILY='A'" + (!tableDDLOptions.isEmpty() ? "," + tableDDLOptions : "");
+            Statement stmt = conn.createStatement();
+            stmt.execute(ddl);
+
+            query = "SELECT * FROM " + tableName;
+            rs = conn.createStatement().executeQuery(query);
+            assertFalse(rs.next());
+
+            String options = localIndex ? "SALT_BUCKETS=10, MULTI_TENANT=true, IMMUTABLE_ROWS=true, DISABLE_WAL=true" : "";
+            conn.createStatement().execute(
+                    "CREATE INDEX " + indexName + " ON " + fullTableName + " (v1) INCLUDE (v2) " + options);
+            query = "SELECT * FROM " + fullIndexName;
+            rs = conn.createStatement().executeQuery(query);
+            assertFalse(rs.next());
+
+            //check options set correctly on index
+            TableName indexTableName = TableName.create(TestUtil.DEFAULT_SCHEMA_NAME, indexName);
+            NamedTableNode indexNode = NamedTableNode.create(null, indexTableName, 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());
+            assertEquals(mutable, !indexTable.isImmutableRows()); // Should match table
+            if(localIndex) {
+                assertEquals(10, indexTable.getBucketNum().intValue());
+                assertTrue(indexTable.isWALDisabled());
+            }
         }
     }
-    
+
     @Test
     public void testIndexWithNullableDateCol() throws Exception {
         String tableName = "TBL_" + generateRandomString();
         String indexName = "IND_" + generateRandomString();
         String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
         String fullIndexName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, indexName);
-    	Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-	        conn.setAutoCommit(false);
+            conn.setAutoCommit(false);
             Date date = new Date(System.currentTimeMillis());
-            
+
             TestUtil.createMultiCFTestTable(conn, fullTableName, tableDDLOptions);
             populateMultiCFTestTable(fullTableName, date);
             String ddl = "CREATE " + (localIndex ? " LOCAL " : "") + " INDEX " + indexName + " ON " + fullTableName + " (date_col)";
             PreparedStatement stmt = conn.prepareStatement(ddl);
             stmt.execute();
-            
+
             String query = "SELECT int_pk from " + fullTableName ;
             ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + query);
             if (localIndex) {
                 assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + fullTableName +" [1]\n"
-                           + "    SERVER FILTER BY FIRST KEY ONLY\n"
-                           + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+                        + "    SERVER FILTER BY FIRST KEY ONLY\n"
+                        + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
             } else {
                 assertEquals("CLIENT PARALLEL 1-WAY FULL SCAN OVER " + fullIndexName + "\n"
                         + "    SERVER FILTER BY FIRST KEY ONLY", QueryUtil.getExplainPlan(rs));
             }
-            
+
             rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals(2, rs.getInt(1));
@@ -542,7 +547,7 @@ public class IndexIT extends BaseOwnClusterIT {
             assertTrue(rs.next());
             assertEquals(3, rs.getInt(1));
             assertFalse(rs.next());
-            
+
             query = "SELECT date_col from " + fullTableName + " order by date_col" ;
             rs = conn.createStatement().executeQuery("EXPLAIN " + query);
             if (localIndex) {
@@ -553,7 +558,7 @@ public class IndexIT extends BaseOwnClusterIT {
                 assertEquals("CLIENT PARALLEL 1-WAY FULL SCAN OVER " + fullIndexName + "\n"
                         + "    SERVER FILTER BY FIRST KEY ONLY", QueryUtil.getExplainPlan(rs));
             }
-            
+
             rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals(date, rs.getDate(1));
@@ -562,9 +567,9 @@ public class IndexIT extends BaseOwnClusterIT {
             assertTrue(rs.next());
             assertEquals(new Date(date.getTime() + 2 * MILLIS_IN_DAY), rs.getDate(1));
             assertFalse(rs.next());
-        } 
+        }
     }
-    
+
     @Test
     public void testSelectAllAndAliasWithIndex() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
@@ -573,205 +578,205 @@ public class IndexIT extends BaseOwnClusterIT {
         String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
         String fullIndexName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, indexName);
         try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-	        conn.setAutoCommit(false);
-	        String query;
-	        ResultSet rs;
-	        String ddl = "CREATE TABLE " + fullTableName + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) " + tableDDLOptions;
-			conn.createStatement().execute(ddl);
-	        query = "SELECT * FROM " + fullTableName;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertFalse(rs.next());
-	        
-	        ddl = "CREATE " + (localIndex ? " LOCAL " : "") + " INDEX " + indexName + " ON " + fullTableName + " (v2 DESC) INCLUDE (v1)";
-	        conn.createStatement().execute(ddl);
-	        query = "SELECT * FROM " + fullIndexName;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertFalse(rs.next());
-
-	        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + fullTableName + " VALUES(?,?,?)");
-	        stmt.setString(1,"a");
-	        stmt.setString(2, "x");
-	        stmt.setString(3, "1");
-	        stmt.execute();
-	        stmt.setString(1,"b");
-	        stmt.setString(2, "y");
-	        stmt.setString(3, "2");
-	        stmt.execute();
-	        conn.commit();
-	        
-	        query = "SELECT * FROM " + fullTableName;
-	        rs = conn.createStatement().executeQuery("EXPLAIN " + query);
-	        if(localIndex){
-	            assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + fullTableName+" [1]\nCLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
-	        } else {
-	            assertEquals("CLIENT PARALLEL 1-WAY FULL SCAN OVER " + fullIndexName, QueryUtil.getExplainPlan(rs));
-	        }
-
-	        rs = conn.createStatement().executeQuery(query);
-	        assertTrue(rs.next());
-	        assertEquals("b",rs.getString(1));
-	        assertEquals("y",rs.getString(2));
-	        assertEquals("2",rs.getString(3));
-	        assertEquals("b",rs.getString("k"));
-	        assertEquals("y",rs.getString("v1"));
-	        assertEquals("2",rs.getString("v2"));
-	        assertTrue(rs.next());
-	        assertEquals("a",rs.getString(1));
-	        assertEquals("x",rs.getString(2));
-	        assertEquals("1",rs.getString(3));
-	        assertEquals("a",rs.getString("k"));
-	        assertEquals("x",rs.getString("v1"));
-	        assertEquals("1",rs.getString("v2"));
-	        assertFalse(rs.next());
-	        
-	        query = "SELECT v1 as foo FROM " + fullTableName + " WHERE v2 = '1' ORDER BY foo";
-	        rs = conn.createStatement().executeQuery("EXPLAIN " + query);
-	        if(localIndex){
-	            assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " +fullTableName + " [1,~'1']\n" + 
-	                    "    SERVER SORTED BY [\"V1\"]\n" + 
-	                    "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
-	        } else {
-	            assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " +fullIndexName + " [~'1']\n" + 
-	                    "    SERVER SORTED BY [\"V1\"]\n" + 
-	                    "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
-	        }
-
-	        rs = conn.createStatement().executeQuery(query);
-	        assertTrue(rs.next());
-	        assertEquals("x",rs.getString(1));
-	        assertEquals("x",rs.getString("foo"));
-	        assertFalse(rs.next());
+            conn.setAutoCommit(false);
+            String query;
+            ResultSet rs;
+            String ddl = "CREATE TABLE " + fullTableName + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) " + tableDDLOptions;
+            conn.createStatement().execute(ddl);
+            query = "SELECT * FROM " + fullTableName;
+            rs = conn.createStatement().executeQuery(query);
+            assertFalse(rs.next());
+
+            ddl = "CREATE " + (localIndex ? " LOCAL " : "") + " INDEX " + indexName + " ON " + fullTableName + " (v2 DESC) INCLUDE (v1)";
+            conn.createStatement().execute(ddl);
+            query = "SELECT * FROM " + fullIndexName;
+            rs = conn.createStatement().executeQuery(query);
+            assertFalse(rs.next());
+
+            PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + fullTableName + " VALUES(?,?,?)");
+            stmt.setString(1,"a");
+            stmt.setString(2, "x");
+            stmt.setString(3, "1");
+            stmt.execute();
+            stmt.setString(1,"b");
+            stmt.setString(2, "y");
+            stmt.setString(3, "2");
+            stmt.execute();
+            conn.commit();
+
+            query = "SELECT * FROM " + fullTableName;
+            rs = conn.createStatement().executeQuery("EXPLAIN " + query);
+            if(localIndex){
+                assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + fullTableName+" [1]\nCLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+            } else {
+                assertEquals("CLIENT PARALLEL 1-WAY FULL SCAN OVER " + fullIndexName, QueryUtil.getExplainPlan(rs));
+            }
+
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals("b",rs.getString(1));
+            assertEquals("y",rs.getString(2));
+            assertEquals("2",rs.getString(3));
+            assertEquals("b",rs.getString("k"));
+            assertEquals("y",rs.getString("v1"));
+            assertEquals("2",rs.getString("v2"));
+            assertTrue(rs.next());
+            assertEquals("a",rs.getString(1));
+            assertEquals("x",rs.getString(2));
+            assertEquals("1",rs.getString(3));
+            assertEquals("a",rs.getString("k"));
+            assertEquals("x",rs.getString("v1"));
+            assertEquals("1",rs.getString("v2"));
+            assertFalse(rs.next());
+
+            query = "SELECT v1 as foo FROM " + fullTableName + " WHERE v2 = '1' ORDER BY foo";
+            rs = conn.createStatement().executeQuery("EXPLAIN " + query);
+            if(localIndex){
+                assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " +fullTableName + " [1,~'1']\n" +
+                        "    SERVER SORTED BY [\"V1\"]\n" +
+                        "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+            } else {
+                assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " +fullIndexName + " [~'1']\n" +
+                        "    SERVER SORTED BY [\"V1\"]\n" +
+                        "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+            }
+
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals("x",rs.getString(1));
+            assertEquals("x",rs.getString("foo"));
+            assertFalse(rs.next());
         }
     }
-    
+
     @Test
     public void testSelectCF() throws Exception {
-    	Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         String tableName = "TBL_" + generateRandomString();
         String indexName = "IND_" + generateRandomString();
         String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
         String fullIndexName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, indexName);
         try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-	        conn.setAutoCommit(false);
-	        String query;
-	        ResultSet rs;
-	        String ddl = "CREATE TABLE " + fullTableName + " (k VARCHAR NOT NULL PRIMARY KEY, a.v1 VARCHAR, a.v2 VARCHAR, b.v1 VARCHAR) " + tableDDLOptions;
-			conn.createStatement().execute(ddl);
-	        query = "SELECT * FROM " + fullTableName;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertFalse(rs.next());
-	        ddl = "CREATE " + (localIndex ? " LOCAL " : "") + " INDEX " + indexName + " ON " + fullTableName + " (v2 DESC) INCLUDE (a.v1)";
-	        conn.createStatement().execute(ddl);
-	        query = "SELECT * FROM " + fullIndexName;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertFalse(rs.next());
-	
-	        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + fullTableName + " VALUES(?,?,?,?)");
-	        stmt.setString(1,"a");
-	        stmt.setString(2, "x");
-	        stmt.setString(3, "1");
-	        stmt.setString(4, "A");
-	        stmt.execute();
-	        stmt.setString(1,"b");
-	        stmt.setString(2, "y");
-	        stmt.setString(3, "2");
-	        stmt.setString(4, "B");
-	        stmt.execute();
-	        conn.commit();
-	        
-	        query = "SELECT * FROM " + fullTableName;
-	        rs = conn.createStatement().executeQuery("EXPLAIN " + query);
-	        assertEquals("CLIENT PARALLEL 1-WAY FULL SCAN OVER " + fullTableName, QueryUtil.getExplainPlan(rs));
-	
-	        query = "SELECT a.* FROM " + fullTableName;
-	        rs = conn.createStatement().executeQuery("EXPLAIN " + query);
-	        if(localIndex) {
-	            assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + fullTableName+" [1]\nCLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
-	        } else {
-	            assertEquals("CLIENT PARALLEL 1-WAY FULL SCAN OVER " + fullIndexName, QueryUtil.getExplainPlan(rs));
-	        }
-	        rs = conn.createStatement().executeQuery(query);
-	        assertTrue(rs.next());
-	        assertEquals("y",rs.getString(1));
-	        assertEquals("2",rs.getString(2));
-	        assertEquals("y",rs.getString("v1"));
-	        assertEquals("2",rs.getString("v2"));
-	        assertTrue(rs.next());
-	        assertEquals("x",rs.getString(1));
-	        assertEquals("1",rs.getString(2));
-	        assertEquals("x",rs.getString("v1"));
-	        assertEquals("1",rs.getString("v2"));
-	        assertFalse(rs.next());
+            conn.setAutoCommit(false);
+            String query;
+            ResultSet rs;
+            String ddl = "CREATE TABLE " + fullTableName + " (k VARCHAR NOT NULL PRIMARY KEY, a.v1 VARCHAR, a.v2 VARCHAR, b.v1 VARCHAR) " + tableDDLOptions;
+            conn.createStatement().execute(ddl);
+            query = "SELECT * FROM " + fullTableName;
+            rs = conn.createStatement().executeQuery(query);
+            assertFalse(rs.next());
+            ddl = "CREATE " + (localIndex ? " LOCAL " : "") + " INDEX " + indexName + " ON " + fullTableName + " (v2 DESC) INCLUDE (a.v1)";
+            conn.createStatement().execute(ddl);
+            query = "SELECT * FROM " + fullIndexName;
+            rs = conn.createStatement().executeQuery(query);
+            assertFalse(rs.next());
+
+            PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + fullTableName + " VALUES(?,?,?,?)");
+            stmt.setString(1,"a");
+            stmt.setString(2, "x");
+            stmt.setString(3, "1");
+            stmt.setString(4, "A");
+            stmt.execute();
+            stmt.setString(1,"b");
+            stmt.setString(2, "y");
+            stmt.setString(3, "2");
+            stmt.setString(4, "B");
+            stmt.execute();
+            conn.commit();
+
+            query = "SELECT * FROM " + fullTableName;
+            rs = conn.createStatement().executeQuery("EXPLAIN " + query);
+            assertEquals("CLIENT PARALLEL 1-WAY FULL SCAN OVER " + fullTableName, QueryUtil.getExplainPlan(rs));
+
+            query = "SELECT a.* FROM " + fullTableName;
+            rs = conn.createStatement().executeQuery("EXPLAIN " + query);
+            if(localIndex) {
+                assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + fullTableName+" [1]\nCLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+            } else {
+                assertEquals("CLIENT PARALLEL 1-WAY FULL SCAN OVER " + fullIndexName, QueryUtil.getExplainPlan(rs));
+            }
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals("y",rs.getString(1));
+            assertEquals("2",rs.getString(2));
+            assertEquals("y",rs.getString("v1"));
+            assertEquals("2",rs.getString("v2"));
+            assertTrue(rs.next());
+            assertEquals("x",rs.getString(1));
+            assertEquals("1",rs.getString(2));
+            assertEquals("x",rs.getString("v1"));
+            assertEquals("1",rs.getString("v2"));
+            assertFalse(rs.next());
         }
     }
-    
+
     @Test
     public void testUpsertAfterIndexDrop() throws Exception {
-    	Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         String tableName = "TBL_" + generateRandomString();
         String indexName = "IND_" + generateRandomString();
         String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
         String fullIndexName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, indexName);
         try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-	        conn.setAutoCommit(false);
-	        String query;
-	        ResultSet rs;
-	        // make sure that the tables are empty, but reachable
-	        conn.createStatement().execute(
-	          "CREATE TABLE " + fullTableName
-	              + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)" + tableDDLOptions);
-	        query = "SELECT * FROM " + fullTableName;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertFalse(rs.next());
-	    
-	        conn.createStatement().execute(
-	          "CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + indexName + " ON " + fullTableName + " (v1, v2)");
-	        query = "SELECT * FROM " + fullIndexName;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertFalse(rs.next());
-	    
-	        // load some data into the table
-	        PreparedStatement stmt =
-	            conn.prepareStatement("UPSERT INTO " + fullTableName + " VALUES(?,?,?)");
-	        stmt.setString(1, "a");
-	        stmt.setString(2, "x");
-	        stmt.setString(3, "1");
-	        stmt.execute();
-	        conn.commit();
-	        
-	        // make sure the index is working as expected
-	        query = "SELECT * FROM " + fullIndexName;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertTrue(rs.next());
-	        assertEquals("x", rs.getString(1));
-	        assertEquals("1", rs.getString(2));
-	        assertEquals("a", rs.getString(3));
-	        assertFalse(rs.next());
-	
-	        String ddl = "DROP INDEX " + indexName + " ON " + fullTableName;
-	        stmt = conn.prepareStatement(ddl);
-	        stmt.execute();
-	        
-	        stmt = conn.prepareStatement("UPSERT INTO " + fullTableName + "(k, v1) VALUES(?,?)");
-	        stmt.setString(1, "a");
-	        stmt.setString(2, "y");
-	        stmt.execute();
-	        conn.commit();
-	    
-	        query = "SELECT * FROM " + fullTableName;
-	    
-	        // check that the data table matches as expected
-	        rs = conn.createStatement().executeQuery(query);
-	        assertTrue(rs.next());
-	        assertEquals("a", rs.getString(1));
-	        assertEquals("y", rs.getString(2));
-	        assertFalse(rs.next());
+            conn.setAutoCommit(false);
+            String query;
+            ResultSet rs;
+            // make sure that the tables are empty, but reachable
+            conn.createStatement().execute(
+                    "CREATE TABLE " + fullTableName
+                    + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)" + tableDDLOptions);
+            query = "SELECT * FROM " + fullTableName;
+            rs = conn.createStatement().executeQuery(query);
+            assertFalse(rs.next());
+
+            conn.createStatement().execute(
+                    "CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + indexName + " ON " + fullTableName + " (v1, v2)");
+            query = "SELECT * FROM " + fullIndexName;
+            rs = conn.createStatement().executeQuery(query);
+            assertFalse(rs.next());
+
+            // load some data into the table
+            PreparedStatement stmt =
+                    conn.prepareStatement("UPSERT INTO " + fullTableName + " VALUES(?,?,?)");
+            stmt.setString(1, "a");
+            stmt.setString(2, "x");
+            stmt.setString(3, "1");
+            stmt.execute();
+            conn.commit();
+
+            // make sure the index is working as expected
+            query = "SELECT * FROM " + fullIndexName;
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals("x", rs.getString(1));
+            assertEquals("1", rs.getString(2));
+            assertEquals("a", rs.getString(3));
+            assertFalse(rs.next());
+
+            String ddl = "DROP INDEX " + indexName + " ON " + fullTableName;
+            stmt = conn.prepareStatement(ddl);
+            stmt.execute();
+
+            stmt = conn.prepareStatement("UPSERT INTO " + fullTableName + "(k, v1) VALUES(?,?)");
+            stmt.setString(1, "a");
+            stmt.setString(2, "y");
+            stmt.execute();
+            conn.commit();
+
+            query = "SELECT * FROM " + fullTableName;
+
+            // check that the data table matches as expected
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals("a", rs.getString(1));
+            assertEquals("y", rs.getString(2));
+            assertFalse(rs.next());
         }
     }
-    
+
     @Test
     public void testMultipleUpdatesAcrossRegions() throws Exception {
-    	Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         String tableName = "TBL_" + generateRandomString();
         String indexName = "IND_" + generateRandomString();
         String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
@@ -779,107 +784,107 @@ public class IndexIT extends BaseOwnClusterIT {
 
         String testTable = fullTableName+"_MULTIPLE_UPDATES";
         try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-	        conn.setAutoCommit(false);
-	        String query;
-	        ResultSet rs;
-	        // make sure that the tables are empty, but reachable
-	        conn.createStatement().execute(
-	          "CREATE TABLE " + testTable
-	              + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) "
-	              + (!tableDDLOptions.isEmpty() ? tableDDLOptions : "") + "SPLIT ON ('b')");
-	        query = "SELECT * FROM " + testTable;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertFalse(rs.next());
-	
-	        conn.createStatement().execute(
-	  	          "CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + indexName + " ON " + testTable + " (v1, v2)");
-	        query = "SELECT * FROM " + fullIndexName;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertFalse(rs.next());
-	    
-	        // load some data into the table
-	        PreparedStatement stmt =
-	            conn.prepareStatement("UPSERT INTO " + testTable + " VALUES(?,?,?)");
-	        stmt.setString(1, "a");
-	        stmt.setString(2, "x");
-	        stmt.setString(3, "1");
-	        stmt.execute();
-	        stmt.setString(1, "b");
-	        stmt.setString(2, "y");
-	        stmt.setString(3, "2");
-	        stmt.execute();
-	        stmt.setString(1, "c");
-	        stmt.setString(2, "z");
-	        stmt.setString(3, "3");
-	        stmt.execute();
-	        conn.commit();
-	        
-	        // make sure the index is working as expected
-	        query = "SELECT * FROM " + fullIndexName;
-	        rs = conn.createStatement().executeQuery(query);
-	        assertTrue(rs.next());
-	        assertEquals("x", rs.getString(1));
-	        assertEquals("1", rs.getString(2));
-	        assertEquals("a", rs.getString(3));
-	        assertTrue(rs.next());
-	        assertEquals("y", rs.getString(1));
-	        assertEquals("2", rs.getString(2));
-	        assertEquals("b", rs.getString(3));
-	        assertTrue(rs.next());
-	        assertEquals("z", rs.getString(1));
-	        assertEquals("3", rs.getString(2));
-	        assertEquals("c", rs.getString(3));
-	        assertFalse(rs.next());
-	
-	        query = "SELECT * FROM " + testTable;
-	        rs = conn.createStatement().executeQuery("EXPLAIN " + query);
-	        if (localIndex) {
-	            assertEquals("CLIENT PARALLEL 2-WAY RANGE SCAN OVER " + testTable+" [1]\n"
-	                       + "    SERVER FILTER BY FIRST KEY ONLY\n"
-	                       + "CLIENT MERGE SORT",
-	                QueryUtil.getExplainPlan(rs));
-	        } else {
-	            assertEquals("CLIENT PARALLEL 1-WAY FULL SCAN OVER " + fullIndexName + "\n"
-	                    + "    SERVER FILTER BY FIRST KEY ONLY",
-	                QueryUtil.getExplainPlan(rs));
-	        }
-	    
-	        // check that the data table matches as expected
-	        rs = conn.createStatement().executeQuery(query);
-	        assertTrue(rs.next());
-	        assertEquals("a", rs.getString(1));
-	        assertEquals("x", rs.getString(2));
-	        assertEquals("1", rs.getString(3));
-	        assertTrue(rs.next());
-	        assertEquals("b", rs.getString(1));
-	        assertEquals("y", rs.getString(2));
-	        assertEquals("2", rs.getString(3));
-	        assertTrue(rs.next());
-	        assertEquals("c", rs.getString(1));
-	        assertEquals("z", rs.getString(2));
-	        assertEquals("3", rs.getString(3));
-	        assertFalse(rs.next());
+            conn.setAutoCommit(false);
+            String query;
+            ResultSet rs;
+            // make sure that the tables are empty, but reachable
+            conn.createStatement().execute(
+                    "CREATE TABLE " + testTable
+                    + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) "
+                    + (!tableDDLOptions.isEmpty() ? tableDDLOptions : "") + "SPLIT ON ('b')");
+            query = "SELECT * FROM " + testTable;
+            rs = conn.createStatement().executeQuery(query);
+            assertFalse(rs.next());
+
+            conn.createStatement().execute(
+                    "CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + indexName + " ON " + testTable + " (v1, v2)");
+            query = "SELECT * FROM " + fullIndexName;
+            rs = conn.createStatement().executeQuery(query);
+            assertFalse(rs.next());
+
+            // load some data into the table
+            PreparedStatement stmt =
+                    conn.prepareStatement("UPSERT INTO " + testTable + " VALUES(?,?,?)");
+            stmt.setString(1, "a");
+            stmt.setString(2, "x");
+            stmt.setString(3, "1");
+            stmt.execute();
+            stmt.setString(1, "b");
+            stmt.setString(2, "y");
+            stmt.setString(3, "2");
+            stmt.execute();
+            stmt.setString(1, "c");
+            stmt.setString(2, "z");
+            stmt.setString(3, "3");
+            stmt.execute();
+            conn.commit();
+
+            // make sure the index is working as expected
+            query = "SELECT * FROM " + fullIndexName;
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals("x", rs.getString(1));
+            assertEquals("1", rs.getString(2));
+            assertEquals("a", rs.getString(3));
+            assertTrue(rs.next());
+            assertEquals("y", rs.getString(1));
+            assertEquals("2", rs.getString(2));
+            assertEquals("b", rs.getString(3));
+            assertTrue(rs.next());
+            assertEquals("z", rs.getString(1));
+            assertEquals("3", rs.getString(2));
+            assertEquals("c", rs.getString(3));
+            assertFalse(rs.next());
+
+            query = "SELECT * FROM " + testTable;
+            rs = conn.createStatement().executeQuery("EXPLAIN " + query);
+            if (localIndex) {
+                assertEquals("CLIENT PARALLEL 2-WAY RANGE SCAN OVER " + testTable+" [1]\n"
+                        + "    SERVER FILTER BY FIRST KEY ONLY\n"
+                        + "CLIENT MERGE SORT",
+                        QueryUtil.getExplainPlan(rs));
+            } else {
+                assertEquals("CLIENT PARALLEL 1-WAY FULL SCAN OVER " + fullIndexName + "\n"
+                        + "    SERVER FILTER BY FIRST KEY ONLY",
+                        QueryUtil.getExplainPlan(rs));
+            }
+
+            // check that the data table matches as expected
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals("a", rs.getString(1));
+            assertEquals("x", rs.getString(2));
+            assertEquals("1", rs.getString(3));
+            assertTrue(rs.next());
+            assertEquals("b", rs.getString(1));
+            assertEquals("y", rs.getString(2));
+            assertEquals("2", rs.getString(3));
+            assertTrue(rs.next());
+            assertEquals("c", rs.getString(1));
+            assertEquals("z", rs.getString(2));
+            assertEquals("3", rs.getString(3));
+            assertFalse(rs.next());
         }
     }
-    
+
     @Test
     public void testIndexWithCaseSensitiveCols() throws Exception {
-    	Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         String tableName = "TBL_" + generateRandomString();
         String indexName = "IND_" + generateRandomString();
         String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
         String fullIndexName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, indexName);
         try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-	        conn.setAutoCommit(false);
-	        String query;
-	        ResultSet rs;
+            conn.setAutoCommit(false);
+            String query;
+            ResultSet rs;
             conn.createStatement().execute("CREATE TABLE " + fullTableName + " (k VARCHAR NOT NULL PRIMARY KEY, \"V1\" VARCHAR, \"v2\" VARCHAR)"+tableDDLOptions);
             query = "SELECT * FROM "+fullTableName;
             rs = conn.createStatement().executeQuery(query);
             long ts = conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null,fullTableName)).getTimeStamp();
             assertFalse(rs.next());
             conn.createStatement().execute(
-  	  	          "CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + indexName + " ON " + fullTableName + "(\"v2\") INCLUDE (\"V1\")");
+                    "CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + indexName + " ON " + fullTableName + "(\"v2\") INCLUDE (\"V1\")");
             query = "SELECT * FROM "+fullIndexName;
             rs = conn.createStatement().executeQuery(query);
             assertFalse(rs.next());
@@ -899,7 +904,7 @@ public class IndexIT extends BaseOwnClusterIT {
             rs = conn.createStatement().executeQuery("EXPLAIN " + query);
             if(localIndex){
                 assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + fullTableName + " [1,'1']\n"
-                           + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+                        + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
             } else {
                 assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + fullIndexName + " ['1']", QueryUtil.getExplainPlan(rs));
             }
@@ -918,7 +923,7 @@ public class IndexIT extends BaseOwnClusterIT {
             rs = conn.createStatement().executeQuery("EXPLAIN " + query);
             if(localIndex){
                 assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + fullTableName + " [1]\nCLIENT MERGE SORT",
-                    QueryUtil.getExplainPlan(rs));
+                        QueryUtil.getExplainPlan(rs));
             } else {
                 assertEquals("CLIENT PARALLEL 1-WAY FULL SCAN OVER "+fullIndexName, QueryUtil.getExplainPlan(rs));
             }
@@ -947,9 +952,9 @@ public class IndexIT extends BaseOwnClusterIT {
             assertEquals("2",rs.getString(5));
             assertEquals("2",rs.getString("v2"));
             assertFalse(rs.next());
-            
+
             assertNoIndexDeletes(conn, ts, fullIndexName);
-        } 
+        }
     }
 
     private void assertNoIndexDeletes(Connection conn, long minTimestamp, String fullIndexName) throws IOException, SQLException {
@@ -979,45 +984,45 @@ public class IndexIT extends BaseOwnClusterIT {
 
     @Test
     public void testInFilterOnIndexedTable() throws Exception {
-    	Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         String tableName = "TBL_" + generateRandomString();
         String indexName = "IND_" + generateRandomString();
         String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
         try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-	        conn.setAutoCommit(false);
-	        String query;
-	        ResultSet rs;
-	        String ddl = "CREATE TABLE " + fullTableName +"  (PK1 CHAR(2) NOT NULL PRIMARY KEY, CF1.COL1 BIGINT) " + tableDDLOptions;
-	        conn.createStatement().execute(ddl);
-	        ddl = "CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + indexName + " ON " + fullTableName + "(COL1)";
-	        conn.createStatement().execute(ddl);
-	
-	        query = "SELECT COUNT(COL1) FROM " + fullTableName +" WHERE COL1 IN (1,25,50,75,100)"; 
-	        rs = conn.createStatement().executeQuery(query);
-	        assertTrue(rs.next());
-        } 
+            conn.setAutoCommit(false);
+            String query;
+            ResultSet rs;
+            String ddl = "CREATE TABLE " + fullTableName +"  (PK1 CHAR(2) NOT NULL PRIMARY KEY, CF1.COL1 BIGINT) " + tableDDLOptions;
+            conn.createStatement().execute(ddl);
+            ddl = "CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + indexName + " ON " + fullTableName + "(COL1)";
+            conn.createStatement().execute(ddl);
+
+            query = "SELECT COUNT(COL1) FROM " + fullTableName +" WHERE COL1 IN (1,25,50,75,100)";
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+        }
     }
 
     @Test
     public void testIndexWithDecimalCol() throws Exception {
-    	Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         String tableName = "TBL_" + generateRandomString();
         String indexName = "IND_" + generateRandomString();
         String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
         String fullIndexName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, indexName);
         try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-	        conn.setAutoCommit(false);
-	        String query;
-	        ResultSet rs;
+            conn.setAutoCommit(false);
+            String query;
+            ResultSet rs;
             Date date = new Date(System.currentTimeMillis());
-            
+
             TestUtil.createMultiCFTestTable(conn, fullTableName, tableDDLOptions);
             populateMultiCFTestTable(fullTableName, date);
             String ddl = null;
             ddl = "CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + indexName + " ON " + fullTableName + " (decimal_pk) INCLUDE (decimal_col1, decimal_col2)";
             PreparedStatement stmt = conn.prepareStatement(ddl);
             stmt.execute();
-            
+
             query = "SELECT decimal_pk, decimal_col1, decimal_col2 from " + fullTableName ;
             rs = conn.createStatement().executeQuery("EXPLAIN " + query);
             if(localIndex) {
@@ -1025,7 +1030,7 @@ public class IndexIT extends BaseOwnClusterIT {
             } else {
                 assertEquals("CLIENT PARALLEL 1-WAY FULL SCAN OVER " + fullIndexName, QueryUtil.getExplainPlan(rs));
             }
-            
+
             rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals(new BigDecimal("1.1"), rs.getBigDecimal(1));
@@ -1040,7 +1045,54 @@ public class IndexIT extends BaseOwnClusterIT {
             assertEquals(new BigDecimal("4.3"), rs.getBigDecimal(2));
             assertEquals(new BigDecimal("5.3"), rs.getBigDecimal(3));
             assertFalse(rs.next());
-        } 
+        }
+    }
+
+    /**
+     * Ensure that HTD contains table priorities correctly.
+     */
+    @Test
+    public void testTableDescriptorPriority() throws SQLException, IOException {
+        String tableName = "TBL_" + generateRandomString();
+        String indexName = "IND_" + generateRandomString();
+        String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
+        // Check system tables priorities.
+        try (HBaseAdmin admin = driver.getConnectionQueryServices(null, null).getAdmin()) {
+            for (HTableDescriptor htd : admin.listTables()) {
+                if (htd.getTableName().getNameAsString().startsWith(QueryConstants.SYSTEM_SCHEMA_NAME)) {
+                    String val = htd.getValue("PRIORITY");
+                    assertNotNull("PRIORITY is not set for table:" + htd, val);
+                    assertTrue(Integer.parseInt(val)
+                            >= PhoenixRpcSchedulerFactory.getMetadataPriority(config));
+                }
+            }
+
+            Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+            String ddl ="CREATE TABLE " + fullTableName + BaseTest.TEST_TABLE_SCHEMA + tableDDLOptions;
+            try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+                conn.setAutoCommit(false);
+                Statement stmt = conn.createStatement();
+                stmt.execute(ddl);
+                BaseTest.populateTestTable(fullTableName);
+                ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName
+                        + " ON " + fullTableName + " (long_col1, long_col2)"
+                        + " INCLUDE (decimal_col1, decimal_col2)";
+                stmt.execute(ddl);
+            }
+
+            HTableDescriptor dataTable = admin.getTableDescriptor(
+                    org.apache.hadoop.hbase.TableName.valueOf(fullTableName));
+            String val = dataTable.getValue("PRIORITY");
+            assertTrue(val == null || Integer.parseInt(val) < HConstants.HIGH_QOS);
+
+            if (!localIndex && mutable) {
+                HTableDescriptor indexTable = admin.getTableDescriptor(
+                        org.apache.hadoop.hbase.TableName.valueOf(indexName));
+                val = indexTable.getValue("PRIORITY");
+                assertNotNull("PRIORITY is not set for table:" + indexTable, val);
+                assertTrue(Integer.parseInt(val) >= PhoenixRpcSchedulerFactory.getIndexPriority(config));
+            }
+        }
     }
-    
-}
\ No newline at end of file
+
+}


[11/47] phoenix git commit: PHOENIX-3228 Index tables should not be configured with a custom/smaller MAX_FILESIZE.

Posted by ma...@apache.org.
PHOENIX-3228 Index tables should not be configured with a custom/smaller MAX_FILESIZE.


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

Branch: refs/heads/calcite
Commit: fd6da35eee5b366530f73a435ae4bc4de0f0eb25
Parents: d94d571
Author: Lars Hofhansl <la...@apache.org>
Authored: Thu Sep 8 13:34:21 2016 -0700
Committer: Lars Hofhansl <la...@apache.org>
Committed: Thu Sep 8 13:35:16 2016 -0700

----------------------------------------------------------------------
 .../query/ConnectionQueryServicesImpl.java      | 10 ---------
 .../org/apache/phoenix/query/QueryServices.java |  1 -
 .../phoenix/query/QueryServicesOptions.java     |  1 -
 .../apache/phoenix/schema/MetaDataClient.java   | 22 --------------------
 4 files changed, 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd6da35e/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index 04c2c7b..86217e7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -1274,16 +1274,6 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         }
         byte[] physicalIndexName = MetaDataUtil.getViewIndexPhysicalName(physicalTableName);
 
-        int indexMaxFileSizePerc;
-        // Get percentage to use from table props first and then fallback to config
-        Integer indexMaxFileSizePercProp = (Integer)tableProps.remove(QueryServices.INDEX_MAX_FILESIZE_PERC_ATTRIB);
-        if (indexMaxFileSizePercProp == null) {
-            indexMaxFileSizePerc = this.props.getInt(QueryServices.INDEX_MAX_FILESIZE_PERC_ATTRIB, QueryServicesOptions.DEFAULT_INDEX_MAX_FILESIZE_PERC);
-        } else {
-            indexMaxFileSizePerc = indexMaxFileSizePercProp;
-        }
-        long indexMaxFileSize = maxFileSize * indexMaxFileSizePerc / 100;
-        tableProps.put(HTableDescriptor.MAX_FILESIZE, indexMaxFileSize);
         tableProps.put(MetaDataUtil.IS_VIEW_INDEX_TABLE_PROP_NAME, TRUE_BYTES_AS_STRING);
         HTableDescriptor desc = ensureTableCreated(physicalIndexName, PTableType.TABLE, tableProps, families, splits,
                 false, isNamespaceMapped);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd6da35e/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
index dbd0a99..8cd009a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
@@ -113,7 +113,6 @@ public interface QueryServices extends SQLCloseable {
     public static final String ZOOKEEPER_ROOT_NODE_ATTRIB = "zookeeper.znode.parent";
     public static final String DISTINCT_VALUE_COMPRESS_THRESHOLD_ATTRIB = "phoenix.distinct.value.compress.threshold";
     public static final String SEQUENCE_CACHE_SIZE_ATTRIB = "phoenix.sequence.cacheSize";
-    public static final String INDEX_MAX_FILESIZE_PERC_ATTRIB = "phoenix.index.maxDataFileSizePerc";
     public static final String MAX_SERVER_METADATA_CACHE_TIME_TO_LIVE_MS_ATTRIB = "phoenix.coprocessor.maxMetaDataCacheTimeToLiveMs";
     public static final String MAX_SERVER_METADATA_CACHE_SIZE_ATTRIB = "phoenix.coprocessor.maxMetaDataCacheSize";
     public static final String MAX_CLIENT_METADATA_CACHE_SIZE_ATTRIB = "phoenix.client.maxMetaDataCacheSize";

http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd6da35e/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
index 475c141..669bcd2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
@@ -152,7 +152,6 @@ public class QueryServicesOptions {
     public static final long DEFAULT_GROUPBY_MAX_CACHE_MAX = 1024L*1024L*100L;  // 100 Mb
 
     public static final long DEFAULT_SEQUENCE_CACHE_SIZE = 100;  // reserve 100 sequences at a time
-    public static final int DEFAULT_INDEX_MAX_FILESIZE_PERC = 50; // % of data table max file size for index table
     public static final long DEFAULT_MAX_SERVER_METADATA_CACHE_TIME_TO_LIVE_MS =  60000 * 30; // 30 mins
     public static final long DEFAULT_MAX_SERVER_METADATA_CACHE_SIZE =  1024L*1024L*20L; // 20 Mb
     public static final long DEFAULT_MAX_CLIENT_METADATA_CACHE_SIZE =  1024L*1024L*10L; // 10 Mb

http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd6da35e/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index efe60ac..fd6b48c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -2133,28 +2133,6 @@ public class MetaDataClient {
                                 PNameFactory.newName(defaultFamilyName), null,
                         Boolean.TRUE.equals(disableWAL), false, false, null, indexId, indexType, true, false, 0, 0L, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema);
                 connection.addTable(table, MetaDataProtocol.MIN_TABLE_TIMESTAMP);
-            } else if (tableType == PTableType.INDEX && indexId == null) {
-                if (tableProps.get(HTableDescriptor.MAX_FILESIZE) == null) {
-                    int nIndexRowKeyColumns = isPK ? 1 : pkColumnsNames.size();
-                    int nIndexKeyValueColumns = columns.size() - nIndexRowKeyColumns;
-                    int nBaseRowKeyColumns = parent.getPKColumns().size() - (parent.getBucketNum() == null ? 0 : 1);
-                    int nBaseKeyValueColumns = parent.getColumns().size() - parent.getPKColumns().size();
-                    /*
-                     * Approximate ratio between index table size and data table size:
-                     * More or less equal to the ratio between the number of key value columns in each. We add one to
-                     * the key value column count to take into account our empty key value. We add 1/4 for any key
-                     * value data table column that was moved into the index table row key.
-                     */
-                    double ratio = (1+nIndexKeyValueColumns + (nIndexRowKeyColumns - nBaseRowKeyColumns)/4d)/(1+nBaseKeyValueColumns);
-                    HTableDescriptor descriptor = connection.getQueryServices().getTableDescriptor(parent.getPhysicalName().getBytes());
-                    if (descriptor != null) { // Is null for connectionless
-                        long maxFileSize = descriptor.getMaxFileSize();
-                        if (maxFileSize == -1) { // If unset, use default
-                            maxFileSize = HConstants.DEFAULT_MAX_FILE_SIZE;
-                        }
-                        tableProps.put(HTableDescriptor.MAX_FILESIZE, (long)(maxFileSize * ratio));
-                    }
-                }
             }
 
             short nextKeySeq = 0;


[23/47] phoenix git commit: PHOENIX-3162 TableNotFoundException might be thrown when an index dropped while upserting.(Rajeshbabu)

Posted by ma...@apache.org.
PHOENIX-3162 TableNotFoundException might be thrown when an index dropped while upserting.(Rajeshbabu)


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

Branch: refs/heads/calcite
Commit: e4fd03952a15be60eee6ddc557a19ce917c606c2
Parents: b640b39
Author: Rajeshbabu Chintaguntla <ra...@apache.org>
Authored: Wed Sep 14 21:03:22 2016 +0530
Committer: Rajeshbabu Chintaguntla <ra...@apache.org>
Committed: Wed Sep 14 21:03:22 2016 +0530

----------------------------------------------------------------------
 .../end2end/index/MutableIndexFailureIT.java    | 34 +++++++++++++++++---
 .../index/PhoenixIndexFailurePolicy.java        |  5 +--
 2 files changed, 32 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/e4fd0395/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
index 0a85216..c68d897 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
@@ -45,6 +45,7 @@ import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.end2end.BaseOwnClusterHBaseManagedTimeIT;
 import org.apache.phoenix.end2end.NeedsOwnMiniClusterTest;
+import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.PIndexState;
@@ -79,7 +80,7 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
     
     private String tableName;
     private String indexName;
-    private String fullTableName;
+    public static volatile String fullTableName;
     private String fullIndexName;
 
     private final boolean transactional;
@@ -150,6 +151,11 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
             FAIL_WRITE = false;
             conn.createStatement().execute(
                     "CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + indexName + " ON " + fullTableName + " (v1) INCLUDE (v2)");
+            // Create other index which should be local/global if the other index is global/local to
+            // check the drop index.
+            conn.createStatement().execute(
+                "CREATE " + (!localIndex ? "LOCAL " : "") + "INDEX " + indexName + "_3" + " ON "
+                        + fullTableName + " (v2) INCLUDE (v1)");
             conn.createStatement().execute(
                     "CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + secondIndexName + " ON " + secondTableName + " (v1) INCLUDE (v2)");
 
@@ -166,7 +172,9 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
             assertTrue(rs.next());
             assertEquals(secondIndexName, rs.getString(3));
             assertEquals(PIndexState.ACTIVE.toString(), rs.getString("INDEX_STATE"));
-            assertFalse(rs.next());
+            assertTrue(rs.next());
+            assertEquals(indexName+"_3", rs.getString(3));
+            assertEquals(PIndexState.ACTIVE.toString(), rs.getString("INDEX_STATE"));
             initializeTable(conn, fullTableName);
             initializeTable(conn, secondTableName);
             
@@ -262,7 +270,9 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
             stmt.setString(3, "4");
             stmt.execute();
             conn.commit();
-
+            // To clear the index name from connection.
+            PhoenixConnection phoenixConn = conn.unwrap(PhoenixConnection.class);
+            phoenixConn.getMetaDataCache().removeTable(null, fullTableName, null, HConstants.LATEST_TIMESTAMP);
             // verify index table has correct data
             validateDataWithIndex(conn, fullTableName, fullIndexName);
             validateDataWithIndex(conn, secondTableName, secondFullIndexName);
@@ -306,7 +316,7 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
     }
 
     private void validateDataWithIndex(Connection conn, String tableName, String indexName) throws SQLException {
-        String query = "SELECT /*+ INDEX(" + indexName + ") */ k,v1 FROM " + tableName;
+        String query = "SELECT /*+ INDEX(" + indexName + ")  */ k,v1 FROM " + tableName;
         ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + query);
         String expectedPlan = " OVER "
                 + (localIndex
@@ -314,7 +324,7 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
                                 SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped).getName())
                         : SchemaUtil.getPhysicalTableName(indexName.getBytes(), isNamespaceMapped).getNameAsString());
         String explainPlan = QueryUtil.getExplainPlan(rs);
-        assertTrue(explainPlan.contains(expectedPlan));
+        assertTrue(explainPlan, explainPlan.contains(expectedPlan));
         rs = conn.createStatement().executeQuery(query);
         if (transactional) { // failed commit does not get retried
             assertTrue(rs.next());
@@ -378,16 +388,30 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
         @Override
         public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws HBaseIOException {
             if (c.getEnvironment().getRegionInfo().getTable().getNameAsString().contains(INDEX_NAME) && FAIL_WRITE) {
+                dropIndex(c);
                 throw new DoNotRetryIOException();
             }
             Mutation operation = miniBatchOp.getOperation(0);
             Set<byte[]> keySet = operation.getFamilyMap().keySet();
             for(byte[] family: keySet) {
                 if(Bytes.toString(family).startsWith(QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX) && FAIL_WRITE) {
+                    dropIndex(c);
                     throw new DoNotRetryIOException();
                 }
             }
         }
+
+         private void dropIndex(ObserverContext<RegionCoprocessorEnvironment> c) {
+             try {
+                 Connection connection =
+                         QueryUtil.getConnection(c.getEnvironment().getConfiguration());
+                 connection.createStatement().execute(
+                     "DROP INDEX IF EXISTS " + INDEX_NAME + "_3" + " ON "
+                             + fullTableName);
+             } catch (ClassNotFoundException e) {
+             } catch (SQLException e) {
+             }
+         }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e4fd0395/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
index 67242f6..c29d7b4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
@@ -137,8 +137,9 @@ public class PhoenixIndexFailurePolicy extends DelegateIndexFailurePolicy {
                 }
             }
 
-            // its a local index table, so we need to convert it to the index table names we should disable
-            if (MetaDataUtil.hasLocalIndexColumnFamily(env.getRegion().getTableDesc())) {
+            // If the data table has local index column families then get local indexes to disable.
+            if (ref.getTableName().equals(env.getRegion().getTableDesc().getNameAsString())
+                    && MetaDataUtil.hasLocalIndexColumnFamily(env.getRegion().getTableDesc())) {
                 for (String tableName : getLocalIndexNames(ref, mutations)) {
                     indexTableNames.put(tableName, minTimeStamp);
                 }


[08/47] phoenix git commit: PHOENIX-2946 Projected comparison between date and timestamp columns always returns true

Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedLong.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedLong.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedLong.java
index a21ccc3..1ee46fd 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedLong.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedLong.java
@@ -19,6 +19,7 @@ package org.apache.phoenix.schema.types;
 
 import java.math.BigDecimal;
 
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Order;
 import org.apache.phoenix.schema.SortOrder;
@@ -37,163 +38,175 @@ import com.google.common.primitives.Longs;
  */
 public class PUnsignedLong extends PWholeNumber<Long> {
 
-  public static final PUnsignedLong INSTANCE = new PUnsignedLong();
-
-  private PUnsignedLong() {
-    super("UNSIGNED_LONG", 10 /* no constant available in Types */, Long.class,
-        new UnsignedLongCodec(), 15);
-  }
-
-  @Override
-  public boolean isOrderPreserving() {
-    return true;
-  }
-
-  @Override
-  public Order getOrder() {
-    return Order.ASCENDING;
-  }
-
-  @Override
-  public boolean isSkippable() {
-    return true;
-  }
-
-  @Override
-  public Integer getScale(Object o) {
-    return ZERO;
-  }
-
-  @Override
-  public byte[] toBytes(Object object) {
-    byte[] b = new byte[Bytes.SIZEOF_LONG];
-    toBytes(object, b, 0);
-    return b;
-  }
-
-  @Override
-  public int toBytes(Object object, byte[] b, int o) {
-    if (object == null) {
-      throw newIllegalDataException(this + " may not be null");
-    }
-    return this.getCodec().encodeLong(((Number) object).longValue(), b, o);
-  }
-
-  @Override
-  public Object toObject(Object object, PDataType actualType) {
-    Long v = (Long) PLong.INSTANCE.toObject(object, actualType);
-    throwIfNonNegativeNumber(v);
-    return v;
-  }
-
-  @Override
-  public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
-      Integer maxLength, Integer scale) {
-    Long v = (Long) PLong.INSTANCE.toObject(b, o, l, actualType, sortOrder);
-    throwIfNonNegativeNumber(v);
-    return v;
-  }
-
-  @Override
+    public static final PUnsignedLong INSTANCE = new PUnsignedLong();
+
+    private PUnsignedLong() {
+        super("UNSIGNED_LONG", 10 /* no constant available in Types */, Long.class,
+                new UnsignedLongCodec(), 15);
+    }
+
+    @Override
+    public boolean isOrderPreserving() {
+        return true;
+    }
+
+    @Override
+    public Order getOrder() {
+        return Order.ASCENDING;
+    }
+
+    @Override
+    public boolean isSkippable() {
+        return true;
+    }
+
+    @Override
+    public Integer getScale(Object o) {
+        return ZERO;
+    }
+
+    @Override
+    public byte[] toBytes(Object object) {
+        byte[] b = new byte[Bytes.SIZEOF_LONG];
+        toBytes(object, b, 0);
+        return b;
+    }
+
+    @Override
+    public int toBytes(Object object, byte[] b, int o) {
+        if (object == null) {
+            throw newIllegalDataException(this + " may not be null");
+        }
+        return this.getCodec().encodeLong(((Number) object).longValue(), b, o);
+    }
+
+    @Override
+    public Object toObject(Object object, PDataType actualType) {
+        Long v = (Long) PLong.INSTANCE.toObject(object, actualType);
+        throwIfNonNegativeNumber(v);
+        return v;
+    }
+
+    @Override
+    public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
+            Integer maxLength, Integer scale) {
+        Long v = (Long) PLong.INSTANCE.toObject(b, o, l, actualType, sortOrder);
+        throwIfNonNegativeNumber(v);
+        return v;
+    }
+
+    @Override
     public boolean isCastableTo(PDataType targetType) {
-      return super.isCastableTo(targetType) || targetType.isCoercibleTo(PTimestamp.INSTANCE);
-    }
-
-  @Override
-  public boolean isCoercibleTo(PDataType targetType) {
-    return targetType == this || targetType == PUnsignedDouble.INSTANCE || PLong.INSTANCE
-        .isCoercibleTo(targetType);
-  }
-
-  @Override
-  public boolean isCoercibleTo(PDataType targetType, Object value) {
-    return super.isCoercibleTo(targetType, value) || PLong.INSTANCE.isCoercibleTo(targetType, value);
-  }
-
-  @Override
-  public boolean isFixedWidth() {
-    return true;
-  }
-
-  @Override
-  public Integer getByteSize() {
-    return Bytes.SIZEOF_LONG;
-  }
-
-  @Override
-  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-    if (rhsType == PDecimal.INSTANCE) {
-      return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).longValue()));
-    } else if (equalsAny(rhsType, PDouble.INSTANCE, PFloat.INSTANCE, PUnsignedDouble.INSTANCE,
-        PUnsignedFloat.INSTANCE)) {
-      return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue());
-    }
-    return Longs.compare(((Number) lhs).longValue(), ((Number) rhs).longValue());
-  }
-
-  @Override
-  public boolean isComparableTo(PDataType targetType) {
-    return PDecimal.INSTANCE.isComparableTo(targetType);
-  }
-
-  @Override
-  public Object toObject(String value) {
-    if (value == null || value.length() == 0) {
-      return null;
-    }
-    try {
-      Long l = Long.parseLong(value);
-      if (l.longValue() < 0) {
-        throw newIllegalDataException("Value may not be negative(" + l + ")");
-      }
-      return l;
-    } catch (NumberFormatException e) {
-      throw newIllegalDataException(e);
-    }
-  }
-
-  @Override
-  public int getResultSetSqlType() {
-    return PLong.INSTANCE.getResultSetSqlType();
-  }
-
-  @Override
-  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-    return Math.abs((Long) PLong.INSTANCE.getSampleValue(maxLength, arrayLength));
-  }
-
-  static class UnsignedLongCodec extends PLong.LongCodec {
-
-    @Override
-    public long decodeLong(byte[] b, int o, SortOrder sortOrder) {
-      Preconditions.checkNotNull(sortOrder);
-      checkForSufficientLength(b, o, Bytes.SIZEOF_LONG);
-      long v = 0;
-      if (sortOrder == SortOrder.ASC) {
-        for (int i = o; i < o + Bytes.SIZEOF_LONG; i++) {
-          v <<= 8;
-          v ^= b[i] & 0xFF;
+        return super.isCastableTo(targetType) || targetType.isCoercibleTo(PTimestamp.INSTANCE);
+    }
+
+    @Override
+    public boolean isCoercibleTo(PDataType targetType) {
+        return targetType == this || targetType == PUnsignedDouble.INSTANCE || PLong.INSTANCE
+                .isCoercibleTo(targetType);
+    }
+
+    @Override
+    public boolean isCoercibleTo(PDataType targetType, Object value) {
+        return super.isCoercibleTo(targetType, value) || PLong.INSTANCE.isCoercibleTo(targetType, value);
+    }
+
+    @Override
+    public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+            Integer maxLength, Integer scale, SortOrder actualModifier, Integer desiredMaxLength, Integer desiredScale,
+            SortOrder expectedModifier) {
+        // Decrease size of TIMESTAMP to size of LONG and continue coerce
+        if (ptr.getLength() > getByteSize()) {
+            ptr.set(ptr.get(), ptr.getOffset(), getByteSize());
         }
-      } else {
-        for (int i = o; i < o + Bytes.SIZEOF_LONG; i++) {
-          v <<= 8;
-          v ^= (b[i] & 0xFF) ^ 0xFF;
+        super.coerceBytes(ptr, object, actualType, maxLength, scale, actualModifier, desiredMaxLength,
+                desiredScale, expectedModifier);
+    }
+
+    @Override
+    public boolean isFixedWidth() {
+        return true;
+    }
+
+    @Override
+    public Integer getByteSize() {
+        return Bytes.SIZEOF_LONG;
+    }
+
+    @Override
+    public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+        if (rhsType == PDecimal.INSTANCE) {
+            return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).longValue()));
+        } else if (equalsAny(rhsType, PDouble.INSTANCE, PFloat.INSTANCE, PUnsignedDouble.INSTANCE,
+                PUnsignedFloat.INSTANCE)) {
+            return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue());
         }
-      }
-      if (v < 0) {
-        throw newIllegalDataException();
-      }
-      return v;
+        return Longs.compare(((Number) lhs).longValue(), ((Number) rhs).longValue());
     }
 
     @Override
-    public int encodeLong(long v, byte[] b, int o) {
-      checkForSufficientLength(b, o, Bytes.SIZEOF_LONG);
-      if (v < 0) {
-        throw newIllegalDataException();
-      }
-      Bytes.putLong(b, o, v);
-      return Bytes.SIZEOF_LONG;
+    public boolean isComparableTo(PDataType targetType) {
+        return PDecimal.INSTANCE.isComparableTo(targetType);
+    }
+
+    @Override
+    public Object toObject(String value) {
+        if (value == null || value.length() == 0) {
+            return null;
+        }
+        try {
+            Long l = Long.parseLong(value);
+            if (l.longValue() < 0) {
+                throw newIllegalDataException("Value may not be negative(" + l + ")");
+            }
+            return l;
+        } catch (NumberFormatException e) {
+            throw newIllegalDataException(e);
+        }
+    }
+
+    @Override
+    public int getResultSetSqlType() {
+        return PLong.INSTANCE.getResultSetSqlType();
+    }
+
+    @Override
+    public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+        return Math.abs((Long) PLong.INSTANCE.getSampleValue(maxLength, arrayLength));
+    }
+
+    static class UnsignedLongCodec extends PLong.LongCodec {
+
+        @Override
+        public long decodeLong(byte[] b, int o, SortOrder sortOrder) {
+            Preconditions.checkNotNull(sortOrder);
+            checkForSufficientLength(b, o, Bytes.SIZEOF_LONG);
+            long v = 0;
+            if (sortOrder == SortOrder.ASC) {
+                for (int i = o; i < o + Bytes.SIZEOF_LONG; i++) {
+                    v <<= 8;
+                    v ^= b[i] & 0xFF;
+                }
+            } else {
+                for (int i = o; i < o + Bytes.SIZEOF_LONG; i++) {
+                    v <<= 8;
+                    v ^= (b[i] & 0xFF) ^ 0xFF;
+                }
+            }
+            if (v < 0) {
+                throw newIllegalDataException();
+            }
+            return v;
+        }
+
+        @Override
+        public int encodeLong(long v, byte[] b, int o) {
+            checkForSufficientLength(b, o, Bytes.SIZEOF_LONG);
+            if (v < 0) {
+                throw newIllegalDataException();
+            }
+            Bytes.putLong(b, o, v);
+            return Bytes.SIZEOF_LONG;
+        }
     }
-  }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTime.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTime.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTime.java
index 4173be1..db0ba0c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTime.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTime.java
@@ -94,7 +94,7 @@ public class PUnsignedTime extends PDataType<Time> {
 
   @Override
   public boolean isBytesComparableWith(PDataType otherType) {
-    return super.isBytesComparableWith(otherType) || otherType == PUnsignedDate.INSTANCE;
+    return super.isBytesComparableWith(otherType) || otherType == PUnsignedDate.INSTANCE || otherType == PUnsignedTimestamp.INSTANCE;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimestamp.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimestamp.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimestamp.java
index 29154b0..08b28c0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimestamp.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimestamp.java
@@ -17,132 +17,60 @@
  */
 package org.apache.phoenix.schema.types;
 
-import java.sql.Timestamp;
-import java.sql.Types;
-import java.text.Format;
-
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.util.DateUtil;
-
-public class PUnsignedTimestamp extends PDataType<Timestamp> {
 
-  public static final PUnsignedTimestamp INSTANCE = new PUnsignedTimestamp();
+public class PUnsignedTimestamp extends PTimestamp {
 
-  private PUnsignedTimestamp() {
-    super("UNSIGNED_TIMESTAMP", 20, java.sql.Timestamp.class, new PUnsignedDate.UnsignedDateCodec(), 12);
-  }
+    public static final PUnsignedTimestamp INSTANCE = new PUnsignedTimestamp();
 
-  @Override
-  public byte[] toBytes(Object object) {
-    if (object == null) {
-      throw newIllegalDataException(this + " may not be null");
+    private PUnsignedTimestamp() {
+        super("UNSIGNED_TIMESTAMP", 20, 12);
     }
-    byte[] bytes = new byte[getByteSize()];
-    toBytes(object, bytes, 0);
-    return bytes;
-  }
 
-  @Override
-  public int toBytes(Object object, byte[] bytes, int offset) {
-    if (object == null) {
-      throw newIllegalDataException(this + " may not be null");
+    @Override
+    public boolean isBytesComparableWith(PDataType otherType) {
+        return equalsAny(this, otherType, PVarbinary.INSTANCE, PBinary.INSTANCE, PUnsignedTime.INSTANCE, PUnsignedDate.INSTANCE, PUnsignedLong.INSTANCE);
     }
-    java.sql.Timestamp value = (java.sql.Timestamp) object;
-    PUnsignedDate.INSTANCE.getCodec().encodeLong(value.getTime(), bytes, offset);
-
-            /*
-             * By not getting the stuff that got spilled over from the millis part,
-             * it leaves the timestamp's byte representation saner - 8 bytes of millis | 4 bytes of nanos.
-             * Also, it enables timestamp bytes to be directly compared with date/time bytes.
-             */
-    Bytes.putInt(bytes, offset + Bytes.SIZEOF_LONG, value.getNanos() % 1000000);
-    return getByteSize();
-  }
-
-  @Override
-  public Object toObject(Object object, PDataType actualType) {
-    java.sql.Timestamp ts = (java.sql.Timestamp) PTimestamp.INSTANCE.toObject(object, actualType);
-    throwIfNonNegativeDate(ts);
-    return ts;
-  }
-
-  @Override
-  public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
-      Integer maxLength, Integer scale) {
-    java.sql.Timestamp ts =
-        (java.sql.Timestamp) PTimestamp.INSTANCE.toObject(b, o, l, actualType, sortOrder);
-    throwIfNonNegativeDate(ts);
-    return ts;
-  }
-
-  @Override
-  public boolean isCastableTo(PDataType targetType) {
-    return PUnsignedDate.INSTANCE.isCastableTo(targetType);
-  }
-
-  @Override
-  public boolean isCoercibleTo(PDataType targetType) {
-    return targetType.equals(this) || PUnsignedDate.INSTANCE.isCoercibleTo(targetType);
-  }
-
-  @Override
-  public boolean isCoercibleTo(PDataType targetType, Object value) {
-    return super.isCoercibleTo(targetType, value) || PTimestamp.INSTANCE
-        .isCoercibleTo(targetType, value);
-  }
 
-  @Override
-  public boolean isFixedWidth() {
-    return true;
-  }
-
-  @Override
-  public Integer getByteSize() {
-    return PTimestamp.INSTANCE.getByteSize();
-  }
-
-  @Override
-  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-    return PTimestamp.INSTANCE.compareTo(lhs, rhs, rhsType);
-  }
+    @Override
+    public Object toObject(Object object, PDataType actualType) {
+        java.sql.Timestamp ts = (java.sql.Timestamp) super.toObject(object, actualType);
+        throwIfNonNegativeDate(ts);
+        return ts;
+    }
 
-  @Override
-  public Object toObject(String value) {
-    return PTimestamp.INSTANCE.toObject(value);
-  }
+    @Override
+    public boolean isCastableTo(PDataType targetType) {
+        return PUnsignedDate.INSTANCE.isCastableTo(targetType);
+    }
 
-  @Override
-  public String toStringLiteral(Object o, Format formatter) {
-    if (formatter == null) {
-      formatter = DateUtil.DEFAULT_TIMESTAMP_FORMATTER;
+    @Override
+    public boolean isCoercibleTo(PDataType targetType) {
+        return targetType.equals(this) || PUnsignedDate.INSTANCE.isCoercibleTo(targetType);
     }
-    return "'" + super.toStringLiteral(o, formatter) + "'";
-  }
 
-  @Override
-  public int getNanos(ImmutableBytesWritable ptr, SortOrder sortOrder) {
-    int nanos = PUnsignedInt.INSTANCE.getCodec()
-        .decodeInt(ptr.get(), ptr.getOffset() + PLong.INSTANCE.getByteSize(), sortOrder);
-    return nanos;
-  }
+    @Override
+    public boolean isCoercibleTo(PDataType targetType, Object value) {
+        return super.isCoercibleTo(targetType, value) || PTimestamp.INSTANCE
+                .isCoercibleTo(targetType, value);
+    }
 
-  @Override
-  public long getMillis(ImmutableBytesWritable ptr, SortOrder sortOrder) {
-    long millis =
-        PUnsignedLong.INSTANCE.getCodec().decodeLong(ptr.get(), ptr.getOffset(), sortOrder);
-    return millis;
-  }
+    @Override
+    public int getResultSetSqlType() {
+        return PTimestamp.INSTANCE.getResultSetSqlType();
+    }
 
-  @Override
-  public int getResultSetSqlType() {
-    return Types.TIMESTAMP;
-  }
+    @Override
+    public int getNanos(ImmutableBytesWritable ptr, SortOrder sortOrder) {
+        int nanos = PUnsignedInt.INSTANCE.getCodec()
+                .decodeInt(ptr.get(), ptr.getOffset() + PLong.INSTANCE.getByteSize(), sortOrder);
+        return nanos;
+    }
 
-  @Override
-  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-    return new java.sql.Timestamp(
-        (Long) PUnsignedLong.INSTANCE.getSampleValue(maxLength, arrayLength));
-  }
+    @Override
+    public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+        return new java.sql.Timestamp(
+                (Long) PUnsignedLong.INSTANCE.getSampleValue(maxLength, arrayLength));
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/util/DateUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/DateUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/DateUtil.java
index 557d8ed..7f62797 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/DateUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/DateUtil.java
@@ -32,9 +32,14 @@ import java.util.List;
 import java.util.TimeZone;
 
 import org.apache.commons.lang.time.FastDateFormat;
-import org.apache.hadoop.hbase.exceptions.IllegalArgumentIOException;
 import org.apache.phoenix.schema.IllegalDataException;
+import org.apache.phoenix.schema.TypeMismatchException;
 import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDataType.PDataCodec;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PUnsignedDate;
+import org.apache.phoenix.schema.types.PUnsignedTimestamp;
 import org.joda.time.DateTimeZone;
 import org.joda.time.chrono.ISOChronology;
 import org.joda.time.format.DateTimeFormatter;
@@ -42,6 +47,7 @@ import org.joda.time.format.DateTimeFormatterBuilder;
 import org.joda.time.format.ISODateTimeFormat;
 
 import com.google.common.collect.Lists;
+import com.sun.istack.NotNull;
 
 
 @SuppressWarnings({ "serial", "deprecation" })
@@ -74,6 +80,21 @@ public class DateUtil {
     private DateUtil() {
     }
 
+    @NotNull
+    public static PDataCodec getCodecFor(PDataType type) {
+        PDataCodec codec = type.getCodec();
+        if (codec != null) {
+            return codec;
+        }
+        if (type == PTimestamp.INSTANCE) {
+            return PDate.INSTANCE.getCodec();
+        } else if (type == PUnsignedTimestamp.INSTANCE) {
+            return PUnsignedDate.INSTANCE.getCodec();
+        } else {
+            throw new RuntimeException(TypeMismatchException.newException(PTimestamp.INSTANCE, type));
+        }
+    }
+    
     private static TimeZone getTimeZone(String timeZoneId) {
         TimeZone parserTimeZone;
         if (timeZoneId == null) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/util/csv/CsvUpsertExecutor.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/csv/CsvUpsertExecutor.java b/phoenix-core/src/main/java/org/apache/phoenix/util/csv/CsvUpsertExecutor.java
index cddafc6..0d3e17d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/csv/CsvUpsertExecutor.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/csv/CsvUpsertExecutor.java
@@ -23,6 +23,7 @@ import java.sql.SQLException;
 import java.sql.Types;
 import java.util.List;
 import java.util.Properties;
+
 import javax.annotation.Nullable;
 
 import org.apache.commons.csv.CSVRecord;
@@ -30,6 +31,7 @@ import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.schema.types.PBoolean;
 import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDataType.PDataCodec;
 import org.apache.phoenix.schema.types.PTimestamp;
 import org.apache.phoenix.util.ColumnInfo;
 import org.apache.phoenix.util.DateUtil;
@@ -112,6 +114,7 @@ public class CsvUpsertExecutor extends UpsertExecutor<CSVRecord, String> {
     static class SimpleDatatypeConversionFunction implements Function<String, Object> {
 
         private final PDataType dataType;
+        private final PDataCodec codec;
         private final DateUtil.DateTimeParser dateTimeParser;
 
         SimpleDatatypeConversionFunction(PDataType dataType, Connection conn) {
@@ -122,7 +125,9 @@ public class CsvUpsertExecutor extends UpsertExecutor<CSVRecord, String> {
                 throw new RuntimeException(e);
             }
             this.dataType = dataType;
+            PDataCodec codec = dataType.getCodec();
             if(dataType.isCoercibleTo(PTimestamp.INSTANCE)) {
+                codec = DateUtil.getCodecFor(dataType);
                 // TODO: move to DateUtil
                 String dateFormat;
                 int dateSqlType = dataType.getResultSetSqlType();
@@ -142,6 +147,7 @@ public class CsvUpsertExecutor extends UpsertExecutor<CSVRecord, String> {
             } else {
                 this.dateTimeParser = null;
             }
+            this.codec = codec;
         }
 
         @Nullable
@@ -153,7 +159,7 @@ public class CsvUpsertExecutor extends UpsertExecutor<CSVRecord, String> {
             if (dateTimeParser != null) {
                 long epochTime = dateTimeParser.parseDateTime(input);
                 byte[] byteValue = new byte[dataType.getByteSize()];
-                dataType.getCodec().encodeLong(epochTime, byteValue, 0);
+                codec.encodeLong(epochTime, byteValue, 0);
                 return dataType.toObject(byteValue);
             } else if (dataType == PBoolean.INSTANCE) {
                 switch (input.toLowerCase()) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java b/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java
index 085af44..ba48a8a 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java
@@ -1837,6 +1837,24 @@ public class PDataTypeTest {
     }
     
     @Test
+    public void testTimestampToDateComparison() {
+        long now = System.currentTimeMillis();
+        Timestamp ts1 = DateUtil.getTimestamp(now,  1111);    
+        final byte[] bytes1 = PTimestamp.INSTANCE.toBytes(ts1);
+        Date ts2 = new Date(now);
+        final byte[] bytes2 = PDate.INSTANCE.toBytes(ts2);
+        assertTrue(PTimestamp.INSTANCE.compareTo(bytes1, 0, bytes1.length, SortOrder.getDefault(), bytes2, 0, bytes2.length, SortOrder.getDefault(), PDate.INSTANCE) > 0);
+
+        Timestamp ts3 = DateUtil.getTimestamp(now,  0);    
+        final byte[] bytes3 = PTimestamp.INSTANCE.toBytes(ts3);
+        assertTrue(PTimestamp.INSTANCE.compareTo(bytes3, 0, bytes3.length, SortOrder.getDefault(), bytes2, 0, bytes2.length, SortOrder.getDefault(), PDate.INSTANCE) == 0);
+
+        Timestamp ts4 = DateUtil.getTimestamp(now,  0);    
+        final byte[] bytes4 = PUnsignedTimestamp.INSTANCE.toBytes(ts4);
+        assertTrue(PUnsignedTimestamp.INSTANCE.compareTo(bytes4, 0, bytes4.length, SortOrder.getDefault(), bytes2, 0, bytes2.length, SortOrder.getDefault(), PDate.INSTANCE) == 0);
+    }
+    
+    @Test
     public void testTimestamp() {
         long now = System.currentTimeMillis();
         Timestamp ts1 = DateUtil.getTimestamp(now,  1111);


[06/47] phoenix git commit: PHOENIX-3246 Treat U+2002 as whitespace in parser

Posted by ma...@apache.org.
PHOENIX-3246 Treat U+2002 as whitespace in parser


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

Branch: refs/heads/calcite
Commit: b65e385a828f89980ba4e5ae68f724d7cad50265
Parents: c02d6cb
Author: Josh Elser <el...@apache.org>
Authored: Sat Sep 3 19:21:43 2016 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Wed Sep 7 14:19:06 2016 -0400

----------------------------------------------------------------------
 phoenix-core/src/main/antlr3/PhoenixSQL.g                 |  5 +++--
 .../src/main/java/org/apache/phoenix/parse/SQLParser.java |  2 +-
 .../java/org/apache/phoenix/parse/QueryParserTest.java    | 10 ++++++++++
 3 files changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b65e385a/phoenix-core/src/main/antlr3/PhoenixSQL.g
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/antlr3/PhoenixSQL.g b/phoenix-core/src/main/antlr3/PhoenixSQL.g
index d8f28e5..bc48b19 100644
--- a/phoenix-core/src/main/antlr3/PhoenixSQL.g
+++ b/phoenix-core/src/main/antlr3/PhoenixSQL.g
@@ -1223,7 +1223,8 @@ FIELDCHAR
     :    LETTER
     |    DIGIT
     |    '_'
-    |    '\u0080'..'\ufffe'
+    |    '\u0080'..'\u2001'
+    |    '\u2003'..'\ufffe'
     ;
 
 // A Letter is a lower or upper case ascii character.
@@ -1283,7 +1284,7 @@ CHAR_ESC
 
 // whitespace (skip)
 WS
-    :   ( ' ' | '\t' ) { $channel=HIDDEN; }
+    :   ( ' ' | '\t' | '\u2002' ) { $channel=HIDDEN; }
     ;
     
 EOL

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b65e385a/phoenix-core/src/main/java/org/apache/phoenix/parse/SQLParser.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/SQLParser.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/SQLParser.java
index 36f756c..1a80991 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/SQLParser.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/SQLParser.java
@@ -192,4 +192,4 @@ public class SQLParser {
             return Character.toLowerCase(data[p + i - 1]);
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b65e385a/phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java b/phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java
index 70f590f..e7127b7 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java
@@ -34,6 +34,8 @@ import org.apache.phoenix.jdbc.PhoenixStatement.Operation;
 import org.apache.phoenix.schema.SortOrder;
 import org.junit.Test;
 
+import com.google.common.base.Joiner;
+
 
 public class QueryParserTest {
     private void parseQuery(String sql) throws IOException, SQLException {
@@ -772,4 +774,12 @@ public class QueryParserTest {
         String sql = "SELECT * FROM T WHERE A LIKE 'a\\(d'";
         parseQuery(sql);
     }
+
+    @Test
+    public void testUnicodeSpace() throws Exception {
+        // U+2002 (8194) is a "EN Space" which looks just like a normal space (0x20 in ascii) 
+        String unicodeEnSpace = String.valueOf(Character.toChars(8194));
+        String sql = Joiner.on(unicodeEnSpace).join(new String[] {"SELECT", "*", "FROM", "T"});
+        parseQuery(sql);
+    }
 }


[10/47] phoenix git commit: PHOENIX-3255 Increase test coverage for TIMESTAMP (Kevin Liew)

Posted by ma...@apache.org.
PHOENIX-3255 Increase test coverage for TIMESTAMP (Kevin Liew)


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

Branch: refs/heads/calcite
Commit: d94d57183501526cff6fc1c5d1475e487c9c4653
Parents: 210445d
Author: James Taylor <ja...@apache.org>
Authored: Thu Sep 8 09:39:31 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Thu Sep 8 11:13:47 2016 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/DateTimeIT.java  | 703 ++++++++++++++++++-
 1 file changed, 695 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d94d5718/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
index 05a8ec8..fe02c57 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
@@ -39,14 +39,7 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.math.BigDecimal;
-import java.sql.Connection;
-import java.sql.Date;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Types;
+import java.sql.*;
 import java.text.Format;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
@@ -850,4 +843,698 @@ public class DateTimeIT extends BaseHBaseManagedTimeTableReuseIT {
         assertNull(rs.getDate(1, GregorianCalendar.getInstance()));
         assertFalse(rs.next());
     }
+
+    @Test
+    public void testProjectedDateTimestampUnequal() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, dates DATE, timestamps TIMESTAMP)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_DATE('2004-02-04 00:10:10')," +
+                "TO_TIMESTAMP('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Differ by nanoseconds
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?)");
+        stmt.setInt(1, 3);
+        stmt.setDate(2, new Date(1000));
+        Timestamp ts = new Timestamp(1000);
+        ts.setNanos(100);
+        stmt.setTimestamp(3, ts);
+        stmt.execute();
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (4," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT dates = timestamps FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedTimeTimestampCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, times TIME, timestamps TIMESTAMP)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_TIME('2004-02-04 00:10:10')," +
+                "TO_TIMESTAMP('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_TIME('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Differ by nanoseconds
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?)");
+        stmt.setInt(1, 3);
+        stmt.setTime(2, new Time(1000));
+        Timestamp ts = new Timestamp(1000);
+        ts.setNanos(100);
+        stmt.setTimestamp(3, ts);
+        stmt.execute();
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (4," +
+                "TO_TIME('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT times = timestamps FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedDateTimeCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, dates DATE, times TIME)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_DATE('2004-02-04 00:10:10')," +
+                "TO_TIME('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_TIME('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (3," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_TIME('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT dates = times FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedDateUnsignedTimestampCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, dates DATE, timestamps UNSIGNED_TIMESTAMP)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_DATE('2004-02-04 00:10:10')," +
+                "TO_TIMESTAMP('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Differ by nanoseconds
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?)");
+        stmt.setInt(1, 3);
+        stmt.setDate(2, new Date(1000));
+        Timestamp ts = new Timestamp(1000);
+        ts.setNanos(100);
+        stmt.setTimestamp(3, ts);
+        stmt.execute();
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (4," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT dates = timestamps FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedTimeUnsignedTimestampCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, times TIME, timestamps UNSIGNED_TIMESTAMP)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_TIME('2004-02-04 00:10:10')," +
+                "TO_TIMESTAMP('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_TIME('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Differ by nanoseconds
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?)");
+        stmt.setInt(1, 3);
+        stmt.setTime(2, new Time(1000));
+        Timestamp ts = new Timestamp(1000);
+        ts.setNanos(100);
+        stmt.setTimestamp(3, ts);
+        stmt.execute();
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (4," +
+                "TO_TIME('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT times = timestamps FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedDateUnsignedTimeCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, dates DATE, times UNSIGNED_TIME)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_DATE('2004-02-04 00:10:10')," +
+                "TO_TIME('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_TIME('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (3," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_TIME('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT dates = times FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedUnsignedDateTimestampCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, dates UNSIGNED_DATE, timestamps TIMESTAMP)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_DATE('2004-02-04 00:10:10')," +
+                "TO_TIMESTAMP('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Differ by nanoseconds
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?)");
+        stmt.setInt(1, 3);
+        stmt.setDate(2, new Date(1000));
+        Timestamp ts = new Timestamp(1000);
+        ts.setNanos(100);
+        stmt.setTimestamp(3, ts);
+        stmt.execute();
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (4," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT dates = timestamps FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedUnsignedTimeTimestampCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, times UNSIGNED_TIME, timestamps TIMESTAMP)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_TIME('2004-02-04 00:10:10')," +
+                "TO_TIMESTAMP('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_TIME('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Differ by nanoseconds
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?)");
+        stmt.setInt(1, 3);
+        stmt.setTime(2, new Time(1000));
+        Timestamp ts = new Timestamp(1000);
+        ts.setNanos(100);
+        stmt.setTimestamp(3, ts);
+        stmt.execute();
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (4," +
+                "TO_TIME('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT times = timestamps FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedUnsignedDateTimeCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, dates UNSIGNED_DATE, times TIME)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_DATE('2004-02-04 00:10:10')," +
+                "TO_TIME('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_TIME('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (3," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_TIME('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT dates = times FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedUnsignedDateUnsignedTimestampCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, dates UNSIGNED_DATE, timestamps UNSIGNED_TIMESTAMP)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_DATE('2004-02-04 00:10:10')," +
+                "TO_TIMESTAMP('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Differ by nanoseconds
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?)");
+        stmt.setInt(1, 3);
+        stmt.setDate(2, new Date(1000));
+        Timestamp ts = new Timestamp(1000);
+        ts.setNanos(100);
+        stmt.setTimestamp(3, ts);
+        stmt.execute();
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (4," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT dates = timestamps FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedUnsignedTimeUnsignedTimestampCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, times UNSIGNED_TIME, timestamps UNSIGNED_TIMESTAMP)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_TIME('2004-02-04 00:10:10')," +
+                "TO_TIMESTAMP('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_TIME('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Differ by nanoseconds
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?)");
+        stmt.setInt(1, 3);
+        stmt.setTime(2, new Time(1000));
+        Timestamp ts = new Timestamp(1000);
+        ts.setNanos(100);
+        stmt.setTimestamp(3, ts);
+        stmt.execute();
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (4," +
+                "TO_TIME('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT times = timestamps FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedUnsignedDateUnsignedTimeCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, dates UNSIGNED_DATE, times UNSIGNED_TIME)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_DATE('2004-02-04 00:10:10')," +
+                "TO_TIME('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_TIME('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (3," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_TIME('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT dates = times FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedDateDateCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, date1 DATE, date2 DATE)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_DATE('2004-02-04 00:10:10')," +
+                "TO_DATE('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_DATE('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (3," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_DATE('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT date1 = date2 FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedUnsignedDateUnsignedDateCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, date1 UNSIGNED_DATE, date2 UNSIGNED_DATE)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_DATE('2004-02-04 00:10:10')," +
+                "TO_DATE('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_DATE('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (3," +
+                "TO_DATE('2004-02-04 00:10:10'), " +
+                "TO_DATE('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT date1 = date2 FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedTimeTimeCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, time1 TIME, time2 TIME)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_TIME('2004-02-04 00:10:10')," +
+                "TO_TIME('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_TIME('2004-02-04 00:10:10'), " +
+                "TO_TIME('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (3," +
+                "TO_TIME('2004-02-04 00:10:10'), " +
+                "TO_TIME('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT time1 = time2 FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedUnsignedTimeUnsignedTimeCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, time1 UNSIGNED_TIME, time2 UNSIGNED_TIME)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_TIME('2004-02-04 00:10:10')," +
+                "TO_TIME('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_TIME('2004-02-04 00:10:10'), " +
+                "TO_TIME('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (3," +
+                "TO_TIME('2004-02-04 00:10:10'), " +
+                "TO_TIME('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT time1 = time2 FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedTimeStampTimeStampCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, timestamp1 TIMESTAMP, timestamp2 TIMESTAMP)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_TIMESTAMP('2004-02-04 00:10:10')," +
+                "TO_TIMESTAMP('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_TIMESTAMP('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Differ by nanoseconds
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?)");
+        stmt.setInt(1, 3);
+        Timestamp ts = new Timestamp(1000);
+        stmt.setTimestamp(2, ts);
+        ts.setNanos(100);
+        stmt.setTimestamp(3, ts);
+        stmt.execute();
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (4," +
+                "TO_TIMESTAMP('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT timestamp1 = timestamp2 FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testProjectedUnsignedTimeStampUnsignedTimeStampCompare() throws Exception {
+        String tableName = generateRandomString();
+        String ddl =
+                "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, timestamp1 UNSIGNED_TIMESTAMP, timestamp2 UNSIGNED_TIMESTAMP)";
+        conn.createStatement().execute(ddl);
+        // Differ by date
+        String dml = "UPSERT INTO " + tableName + " VALUES (1," +
+                "TO_TIMESTAMP('2004-02-04 00:10:10')," +
+                "TO_TIMESTAMP('2006-04-12 00:10:10'))";
+        conn.createStatement().execute(dml);
+        // Differ by time
+        dml = "UPSERT INTO " + tableName + " VALUES (2," +
+                "TO_TIMESTAMP('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 15:10:20'))";
+        conn.createStatement().execute(dml);
+        // Differ by nanoseconds
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?)");
+        stmt.setInt(1, 3);
+        Timestamp ts = new Timestamp(1000);
+        stmt.setTimestamp(2, ts);
+        ts.setNanos(100);
+        stmt.setTimestamp(3, ts);
+        stmt.execute();
+        // Equality
+        dml = "UPSERT INTO " + tableName + " VALUES (4," +
+                "TO_TIMESTAMP('2004-02-04 00:10:10'), " +
+                "TO_TIMESTAMP('2004-02-04 00:10:10'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT timestamp1 = timestamp2 FROM " + tableName);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.next());
+    }
 }


[24/47] phoenix git commit: PHOENIX-3278 Remove usage of BaseTest.ensureTableCreated()

Posted by ma...@apache.org.
PHOENIX-3278 Remove usage of BaseTest.ensureTableCreated()


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

Branch: refs/heads/calcite
Commit: 7af708873c0b4457eb6598fb41fd279672fe0029
Parents: e4fd039
Author: James Taylor <ja...@apache.org>
Authored: Wed Sep 14 09:31:00 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Wed Sep 14 09:45:30 2016 -0700

----------------------------------------------------------------------
 .../BaseHBaseManagedTimeTableReuseIT.java       |  3 --
 .../ConnectionQueryServicesTestImpl.java        | 30 +++--------
 .../apache/phoenix/end2end/DynamicUpsertIT.java | 31 ++++++------
 .../apache/phoenix/end2end/GroupByCaseIT.java   | 27 +++++-----
 .../apache/phoenix/end2end/HashJoinMoreIT.java  | 14 ------
 .../apache/phoenix/end2end/PercentileIT.java    | 29 +++++------
 .../end2end/QueryDatabaseMetaDataIT.java        |  9 ++--
 .../org/apache/phoenix/end2end/QueryMoreIT.java |  6 +--
 .../end2end/RegexpReplaceFunctionIT.java        |  4 +-
 .../phoenix/end2end/RegexpSubstrFunctionIT.java |  4 +-
 .../apache/phoenix/end2end/SkipScanQueryIT.java |  2 +-
 .../org/apache/phoenix/end2end/SortOrderIT.java |  9 +++-
 .../phoenix/end2end/SpillableGroupByIT.java     | 21 +++++---
 .../end2end/index/IndexExpressionIT.java        | 47 ++++++++++-------
 .../apache/phoenix/end2end/index/IndexIT.java   |  4 +-
 .../phoenix/end2end/index/IndexMetadataIT.java  | 26 ++++++----
 .../phoenix/end2end/index/MutableIndexIT.java   |  2 +-
 .../org/apache/phoenix/rpc/UpdateCacheIT.java   |  9 ++--
 .../phoenix/rpc/UpdateCacheWithScnIT.java       | 12 ++++-
 .../org/apache/phoenix/tx/TransactionIT.java    | 53 +++++++++++---------
 .../apache/phoenix/jdbc/PhoenixTestDriver.java  |  2 +-
 .../java/org/apache/phoenix/query/BaseTest.java | 52 +++----------------
 .../java/org/apache/phoenix/util/TestUtil.java  | 29 +++++++++++
 23 files changed, 208 insertions(+), 217 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTableReuseIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTableReuseIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTableReuseIT.java
index c40ec59..b09984b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTableReuseIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTableReuseIT.java
@@ -18,8 +18,6 @@
 
 package org.apache.phoenix.end2end;
 
-import javax.annotation.concurrent.NotThreadSafe;
-
 import org.apache.hadoop.conf.Configuration;
 import org.apache.phoenix.query.BaseTest;
 import org.apache.phoenix.util.ReadOnlyProps;
@@ -45,7 +43,6 @@ import org.junit.experimental.categories.Category;
  *
  * @since 0.1
  */
-@NotThreadSafe
 @Category(HBaseManagedTimeTableReuseTest.class)
 public class BaseHBaseManagedTimeTableReuseIT extends BaseTest {
     protected static Configuration getTestClusterConfig() {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
index 2d0ed60..48f392b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
@@ -49,39 +49,23 @@ public class ConnectionQueryServicesTestImpl extends ConnectionQueryServicesImpl
     }
     
     @Override
-    public void addConnection(PhoenixConnection connection) throws SQLException {
+    public synchronized void addConnection(PhoenixConnection connection) throws SQLException {
         connections.add(connection);
     }
     
     @Override
-    public void removeConnection(PhoenixConnection connection) throws SQLException {
+    public synchronized void removeConnection(PhoenixConnection connection) throws SQLException {
         connections.remove(connection);
     }
 
     @Override
-    public void init(String url, Properties props) throws SQLException {
-        try {
-            super.init(url, props);
-            /**
-             * Clear the server-side meta data cache on initialization. Otherwise, if we
-             * query for meta data tables, we'll get nothing (since the server just came
-             * up). However, our server-side cache (which is a singleton) will claim
-             * that we do have tables and our create table calls will return the cached
-             * meta data instead of creating new metadata.
-             */
-            clearCache();
-        } catch (SQLException e) {
-            throw e;
-        } catch (Exception e) {
-            throw new SQLException(e);
-        }
-    }
-
-    @Override
     public void close() throws SQLException {
         try {
-            Set<PhoenixConnection> connections = this.connections;
-            this.connections = Sets.newHashSet();
+            Set<PhoenixConnection> connections;
+            synchronized(this) {
+                connections = this.connections;
+                this.connections = Sets.newHashSet();
+            }
             SQLCloseables.closeAll(connections);
             long unfreedBytes = clearCache();
             assertEquals("Found unfreed bytes in server-side cache", 0, unfreedBytes);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java
index 0852859..c0fd38a 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java
@@ -36,7 +36,6 @@ import org.apache.phoenix.schema.ColumnAlreadyExistsException;
 import org.apache.phoenix.schema.ColumnFamilyNotFoundException;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 /**
@@ -48,14 +47,14 @@ import org.junit.Test;
 
 
 public class DynamicUpsertIT extends BaseHBaseManagedTimeTableReuseIT {
-    private static String TABLE;
+    private String tableName;
 
-    @BeforeClass
-    public static void doBeforeTestSetup() throws Exception {
-    	TABLE = BaseTest.generateRandomString();
+    @Before
+    public void doBeforeTestSetup() throws Exception {
+    	tableName = BaseTest.generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
-        String ddl = "create table if not exists  " + TABLE + "   (entry varchar not null primary key,"
+        String ddl = "create table " + tableName + "   (entry varchar not null primary key,"
                 + "    a.dummy varchar," + "    b.dummy varchar)";
         conn.createStatement().execute(ddl);
         conn.close();
@@ -66,9 +65,9 @@ public class DynamicUpsertIT extends BaseHBaseManagedTimeTableReuseIT {
      */
     @Test
     public void testUpsert() throws Exception {
-        String upsertquery = "UPSERT INTO " + TABLE
+        String upsertquery = "UPSERT INTO " + tableName
                 + " (entry, a.DynCol VARCHAR,a.dummy) VALUES ('dynEntry','DynValue','DynColValue')";
-        String selectquery = "SELECT DynCol FROM " + TABLE + " (a.DynCol VARCHAR) where entry='dynEntry'";
+        String selectquery = "SELECT DynCol FROM " + tableName + " (a.DynCol VARCHAR) where entry='dynEntry'";
         // String selectquery = "SELECT * FROM "+TABLE;
 
         String url = getUrl() + ";";
@@ -96,9 +95,9 @@ public class DynamicUpsertIT extends BaseHBaseManagedTimeTableReuseIT {
      */
     @Test
     public void testMultiUpsert() throws Exception {
-        String upsertquery = "UPSERT INTO " + TABLE
+        String upsertquery = "UPSERT INTO " + tableName
                 + " (entry, a.DynColA VARCHAR,b.DynColB varchar) VALUES('dynEntry','DynColValuea','DynColValueb')";
-        String selectquery = "SELECT DynColA,entry,DynColB FROM " + TABLE
+        String selectquery = "SELECT DynColA,entry,DynColB FROM " + tableName
                 + " (a.DynColA VARCHAR,b.DynColB VARCHAR) where entry='dynEntry'";
 
         String url = getUrl() + ";";
@@ -129,9 +128,9 @@ public class DynamicUpsertIT extends BaseHBaseManagedTimeTableReuseIT {
     @Test
     public void testFullUpsert() throws Exception {
         String upsertquery = "UPSERT INTO "
-                + TABLE
+                + tableName
                 + " (a.DynColA VARCHAR,b.DynColB varchar) VALUES('dynEntry','aValue','bValue','DynColValuea','DynColValueb')";
-        String selectquery = "SELECT entry,DynColA,a.dummy,DynColB,b.dummy FROM " + TABLE
+        String selectquery = "SELECT entry,DynColA,a.dummy,DynColB,b.dummy FROM " + tableName
                 + " (a.DynColA VARCHAR,b.DynColB VARCHAR) where entry='dynEntry'";
 
         String url = getUrl() + ";";
@@ -163,7 +162,7 @@ public class DynamicUpsertIT extends BaseHBaseManagedTimeTableReuseIT {
      */
     @Test
     public void testFullUnbalancedUpsert() throws Exception {
-        String upsertquery = "UPSERT INTO " + TABLE
+        String upsertquery = "UPSERT INTO " + tableName
                 + " (a.DynCol VARCHAR,b.DynCol varchar) VALUES('dynEntry','aValue','bValue','dyncola')";
 
         String url = getUrl() + ";";
@@ -185,7 +184,7 @@ public class DynamicUpsertIT extends BaseHBaseManagedTimeTableReuseIT {
      */
     @Test(expected = ColumnAlreadyExistsException.class)
     public void testAmbiguousStaticUpsert() throws Exception {
-        String upsertquery = "UPSERT INTO " + TABLE + " (a.dummy INTEGER,b.dummy INTEGER) VALUES(1,2)";
+        String upsertquery = "UPSERT INTO " + tableName + " (a.dummy INTEGER,b.dummy INTEGER) VALUES(1,2)";
         String url = getUrl() + ";";
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(url, props);
@@ -202,7 +201,7 @@ public class DynamicUpsertIT extends BaseHBaseManagedTimeTableReuseIT {
      */
     @Test(expected = ColumnAlreadyExistsException.class)
     public void testAmbiguousDynamicUpsert() throws Exception {
-        String upsertquery = "UPSERT INTO " + TABLE + " (a.DynCol VARCHAR,a.DynCol INTEGER) VALUES('dynCol',1)";
+        String upsertquery = "UPSERT INTO " + tableName + " (a.DynCol VARCHAR,a.DynCol INTEGER) VALUES('dynCol',1)";
         String url = getUrl() + ";";
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(url, props);
@@ -219,7 +218,7 @@ public class DynamicUpsertIT extends BaseHBaseManagedTimeTableReuseIT {
      */
     @Test(expected = ColumnFamilyNotFoundException.class)
     public void testFakeCFDynamicUpsert() throws Exception {
-        String upsertquery = "UPSERT INTO " + TABLE + " (fakecf.DynCol VARCHAR) VALUES('dynCol')";
+        String upsertquery = "UPSERT INTO " + tableName + " (fakecf.DynCol VARCHAR) VALUES('dynCol')";
         String url = getUrl() + ";";
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(url, props);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java
index 86a1f64..7cbbcbe 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java
@@ -17,9 +17,7 @@
  */
 package org.apache.phoenix.end2end;
 
-import static org.apache.phoenix.util.TestUtil.GROUPBYTEST_NAME;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.apache.phoenix.util.TestUtil.getTableName;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -42,29 +40,28 @@ import org.junit.Test;
 
 
 public class GroupByCaseIT extends BaseHBaseManagedTimeTableReuseIT {
-    private static int id;
-
     private static void initData(Connection conn, String tableName) throws SQLException {
-        ensureTableCreated(getUrl(), tableName, GROUPBYTEST_NAME);
-        insertRow(conn, tableName, "Report1", 10);
-        insertRow(conn, tableName, "Report2", 10);
-        insertRow(conn, tableName, "Report3", 30);
-        insertRow(conn, tableName, "Report4", 30);
-        insertRow(conn, tableName, "SOQL1", 10);
-        insertRow(conn, tableName, "SOQL2", 10);
-        insertRow(conn, tableName, "SOQL3", 30);
-        insertRow(conn, tableName, "SOQL4", 30);
+        conn.createStatement().execute("create table " + tableName +
+                "   (id varchar not null primary key,\n" +
+                "    uri varchar, appcpu integer)");
+        insertRow(conn, tableName, "Report1", 10, 1);
+        insertRow(conn, tableName, "Report2", 10, 2);
+        insertRow(conn, tableName, "Report3", 30, 3);
+        insertRow(conn, tableName, "Report4", 30, 4);
+        insertRow(conn, tableName, "SOQL1", 10, 5);
+        insertRow(conn, tableName, "SOQL2", 10, 6);
+        insertRow(conn, tableName, "SOQL3", 30, 7);
+        insertRow(conn, tableName, "SOQL4", 30, 8);
         conn.commit();
         conn.close();
     }
 
-    private static void insertRow(Connection conn, String tableName, String uri, int appcpu) throws SQLException {
+    private static void insertRow(Connection conn, String tableName, String uri, int appcpu, int id) throws SQLException {
         PreparedStatement statement = conn.prepareStatement("UPSERT INTO " + tableName + "(id, uri, appcpu) values (?,?,?)");
         statement.setString(1, "id" + id);
         statement.setString(2, uri);
         statement.setInt(3, appcpu);
         statement.executeUpdate();
-        id++;
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java
index 943a376..715132f 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java
@@ -27,17 +27,14 @@ import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
-import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Map;
 import java.util.Properties;
 
-import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
-import org.junit.After;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -104,17 +101,6 @@ public class HashJoinMoreIT extends BaseHBaseManagedTimeTableReuseIT {
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
     
-    @After
-    public void assertNoUnfreedMemory() throws SQLException {
-        Connection conn = DriverManager.getConnection(getUrl());
-        try {
-            long unfreedBytes = conn.unwrap(PhoenixConnection.class).getQueryServices().clearCache();
-            assertEquals(0,unfreedBytes);
-        } finally {
-            conn.close();
-        }
-    }
-    
     @Test
     public void testJoinOverSaltedTables() throws Exception {
         String tempTableNoSalting = generateRandomString();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java
index f0b4b24..598785c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java
@@ -23,7 +23,6 @@ import static org.apache.phoenix.util.TestUtil.A_VALUE;
 import static org.apache.phoenix.util.TestUtil.B_VALUE;
 import static org.apache.phoenix.util.TestUtil.C_VALUE;
 import static org.apache.phoenix.util.TestUtil.INDEX_DATA_SCHEMA;
-import static org.apache.phoenix.util.TestUtil.INDEX_DATA_TABLE;
 import static org.apache.phoenix.util.TestUtil.ROW1;
 import static org.apache.phoenix.util.TestUtil.ROW2;
 import static org.apache.phoenix.util.TestUtil.ROW3;
@@ -408,14 +407,13 @@ public class PercentileIT extends BaseHBaseManagedTimeTableReuseIT {
     @Test
     public void testPercentileContOnDescPKColumn() throws Exception {
         String indexDataTableName = generateRandomString();
-        ensureTableCreated(getUrl(), indexDataTableName, INDEX_DATA_TABLE);
-        populateINDEX_DATA_TABLETable(indexDataTableName);
-
-        String query = "SELECT PERCENTILE_CONT(1) WITHIN GROUP (ORDER BY long_pk ASC) FROM " + INDEX_DATA_SCHEMA
-                + QueryConstants.NAME_SEPARATOR + indexDataTableName;
+        String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTableName;
+        String query = "SELECT PERCENTILE_CONT(1) WITHIN GROUP (ORDER BY long_pk ASC) FROM " + fullTableName;
 
         Connection conn = DriverManager.getConnection(getUrl());
         try {
+            conn.createStatement().execute("create table " + fullTableName + TEST_TABLE_SCHEMA + "IMMUTABLE_ROWS=true");
+            populateINDEX_DATA_TABLETable(indexDataTableName);
             PreparedStatement statement = conn.prepareStatement(query);
             ResultSet rs = statement.executeQuery();
             assertTrue(rs.next());
@@ -431,14 +429,12 @@ public class PercentileIT extends BaseHBaseManagedTimeTableReuseIT {
     @Test
     public void testPercentRankOnDescPKColumn() throws Exception {
         String indexDataTableName = generateRandomString();
-        ensureTableCreated(getUrl(), indexDataTableName, INDEX_DATA_TABLE);
-        populateINDEX_DATA_TABLETable(indexDataTableName);
-
-        String query = "SELECT PERCENT_RANK(2) WITHIN GROUP (ORDER BY long_pk ASC) FROM " + INDEX_DATA_SCHEMA
-                + QueryConstants.NAME_SEPARATOR + indexDataTableName;
-
         Connection conn = DriverManager.getConnection(getUrl());
         try {
+            String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTableName;
+            String query = "SELECT PERCENT_RANK(2) WITHIN GROUP (ORDER BY long_pk ASC) FROM " + fullTableName;
+            conn.createStatement().execute("create table " + fullTableName + TEST_TABLE_SCHEMA + "IMMUTABLE_ROWS=true");
+            populateINDEX_DATA_TABLETable(indexDataTableName);
             PreparedStatement statement = conn.prepareStatement(query);
             ResultSet rs = statement.executeQuery();
             assertTrue(rs.next());
@@ -454,14 +450,13 @@ public class PercentileIT extends BaseHBaseManagedTimeTableReuseIT {
     @Test
     public void testPercentileDiscOnDescPKColumn() throws Exception {
         String indexDataTableName = generateRandomString();
-        ensureTableCreated(getUrl(), indexDataTableName, INDEX_DATA_TABLE);
-        populateINDEX_DATA_TABLETable(indexDataTableName);
-
-        String query = "SELECT PERCENTILE_DISC(0.4) WITHIN GROUP (ORDER BY long_pk DESC) FROM " + INDEX_DATA_SCHEMA
-                + QueryConstants.NAME_SEPARATOR + indexDataTableName;
 
         Connection conn = DriverManager.getConnection(getUrl());
         try {
+            String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTableName;
+            String query = "SELECT PERCENTILE_DISC(0.4) WITHIN GROUP (ORDER BY long_pk DESC) FROM " + fullTableName;
+            conn.createStatement().execute("create table " + fullTableName + TEST_TABLE_SCHEMA + "IMMUTABLE_ROWS=true");
+            populateINDEX_DATA_TABLETable(indexDataTableName);
             PreparedStatement statement = conn.prepareStatement(query);
             ResultSet rs = statement.executeQuery();
             assertTrue(rs.next());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
index fbcc120..805691d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
@@ -34,6 +34,7 @@ import static org.apache.phoenix.util.TestUtil.PTSDB_NAME;
 import static org.apache.phoenix.util.TestUtil.STABLE_NAME;
 import static org.apache.phoenix.util.TestUtil.TABLE_WITH_SALTING;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.apache.phoenix.util.TestUtil.createGroupByTestTable;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
@@ -591,13 +592,15 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
     @Test
     public void testMultiTableColumnsMetadataScan() throws SQLException {
         long ts = nextTimestamp();
+        Properties props = new Properties();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        createGroupByTestTable(conn, GROUPBYTEST_NAME);
         ensureTableCreated(getUrl(), MDTEST_NAME, MDTEST_NAME, ts);
-        ensureTableCreated(getUrl(), GROUPBYTEST_NAME, GROUPBYTEST_NAME, ts);
         ensureTableCreated(getUrl(), PTSDB_NAME, PTSDB_NAME, ts);
         ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, CUSTOM_ENTITY_DATA_FULL_NAME, ts);
-        Properties props = new Properties();
         props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 5));
-        Connection conn = DriverManager.getConnection(getUrl(), props);
+        conn = DriverManager.getConnection(getUrl(), props);
         DatabaseMetaData dbmd = conn.getMetaData();
         ResultSet rs = dbmd.getColumns(null, "", "%TEST%", null);
         assertTrue(rs.next());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java
index c4e4665..6da9144 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java
@@ -72,21 +72,21 @@ public class QueryMoreIT extends BaseHBaseManagedTimeTableReuseIT {
     }
     
     private void testQueryMore(boolean queryAgainstTenantSpecificView, boolean dataTableSalted) throws Exception {
-        String[] tenantIds = new String[] {"00Dxxxxxtenant1", "00Dxxxxxtenant2", "00Dxxxxxtenant3"};
+        String[] tenantIds = new String[] {"T1_" + generateRandomString(), "T2_" + generateRandomString(), "T3_" + generateRandomString()};
         int numRowsPerTenant = 10;
         String cursorTableName = generateRandomString();
         String base_history_table = generateRandomString();
         this.dataTableName = base_history_table + (dataTableSalted ? "_SALTED" : "");
         String cursorTableDDL = "CREATE TABLE IF NOT EXISTS " + 
                 cursorTableName +  " (\n" +  
-                "TENANT_ID VARCHAR(15) NOT NULL\n," +  
+                "TENANT_ID VARCHAR NOT NULL\n," +  
                 "QUERY_ID VARCHAR(15) NOT NULL,\n" +
                 "CURSOR_ORDER BIGINT NOT NULL \n" + 
                 "CONSTRAINT CURSOR_TABLE_PK PRIMARY KEY (TENANT_ID, QUERY_ID, CURSOR_ORDER)) "+
                 "SALT_BUCKETS = 4, TTL=86400";
         String baseDataTableDDL = "CREATE TABLE IF NOT EXISTS " +
                 dataTableName + " (\n" + 
-                "TENANT_ID CHAR(15) NOT NULL,\n" +
+                "TENANT_ID VARCHAR NOT NULL,\n" +
                 "PARENT_ID CHAR(15) NOT NULL,\n" + 
                 "CREATED_DATE DATE NOT NULL,\n" + 
                 "ENTITY_HISTORY_ID CHAR(15) NOT NULL,\n" + 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpReplaceFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpReplaceFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpReplaceFunctionIT.java
index 7670481..5ce04eb 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpReplaceFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpReplaceFunctionIT.java
@@ -17,7 +17,7 @@
  */
 package org.apache.phoenix.end2end;
 
-import static org.apache.phoenix.util.TestUtil.GROUPBYTEST_NAME;
+import static org.apache.phoenix.util.TestUtil.createGroupByTestTable;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -41,8 +41,8 @@ public class RegexpReplaceFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     @Before
     public void doBeforeTestSetup() throws Exception {
         this.tableName = generateRandomString();
-        ensureTableCreated(getUrl(), this.tableName, GROUPBYTEST_NAME);
         Connection conn = DriverManager.getConnection(getUrl());
+        createGroupByTestTable(conn, tableName);
         insertRow(conn, "Report11", 10);
         insertRow(conn, "Report11", 10);
         insertRow(conn, "Report22", 30);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSubstrFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSubstrFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSubstrFunctionIT.java
index 6669017..777ccd1 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSubstrFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSubstrFunctionIT.java
@@ -17,7 +17,7 @@
  */
 package org.apache.phoenix.end2end;
 
-import static org.apache.phoenix.util.TestUtil.GROUPBYTEST_NAME;
+import static org.apache.phoenix.util.TestUtil.createGroupByTestTable;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -41,8 +41,8 @@ public class RegexpSubstrFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     @Before
     public void doBeforeTestSetup() throws Exception {
         tableName = generateRandomString();
-        ensureTableCreated(getUrl(), tableName, GROUPBYTEST_NAME);
         Connection conn = DriverManager.getConnection(getUrl());
+        createGroupByTestTable(conn, tableName);
         insertRow(conn, "Report1?1", 10);
         insertRow(conn, "Report1?2", 10);
         insertRow(conn, "Report2?1", 30);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
index 1021bdd..944acf7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
@@ -353,7 +353,7 @@ public class SkipScanQueryIT extends BaseHBaseManagedTimeTableReuseIT {
         String tableName = generateRandomString();
         String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
         try {
-            createMultiCFTestTable(fullTableName , null);
+            TestUtil.createMultiCFTestTable(conn , fullTableName, null);
             populateMultiCFTestTable(fullTableName);
             String upsert = "UPSERT INTO " + fullTableName
                     + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
index 4357272..87814fc 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
@@ -45,6 +45,7 @@ import org.apache.phoenix.schema.types.PDouble;
 import org.apache.phoenix.schema.types.PFloat;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
 import com.google.common.collect.Lists;
@@ -55,6 +56,12 @@ import com.google.common.collect.Lists;
 
 
 public class SortOrderIT extends BaseHBaseManagedTimeTableReuseIT {
+    private String baseTableName;
+    
+    @Before
+    public void generateTableName() {
+        baseTableName = generateRandomString();
+    }
     
     @Test
     public void noOrder() throws Exception {
@@ -530,7 +537,7 @@ public class SortOrderIT extends BaseHBaseManagedTimeTableReuseIT {
     }
 
     private void testCompareCompositeKey(Integer saltBuckets, PDataType dataType, SortOrder sortOrder, String whereClause, List<Integer> expectedResults, String orderBy) throws SQLException {
-        String tableName = "t_" + saltBuckets + "_" + dataType + "_" + sortOrder;
+        String tableName = "t_" + saltBuckets + "_" + dataType + "_" + sortOrder + "_" + baseTableName;
         String ddl = "create table if not exists " + tableName + " (k1 bigint not null, k2 " + dataType.getSqlTypeName() + (dataType.isFixedWidth() ? " not null" : "") + ", constraint pk primary key (k1,k2 " + sortOrder + "))" + (saltBuckets == null ? "" : (" SALT_BUCKETS= " + saltBuckets));
         Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));
         conn.createStatement().execute(ddl);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpillableGroupByIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpillableGroupByIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpillableGroupByIT.java
index 51dcd21..22bf8ce 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpillableGroupByIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpillableGroupByIT.java
@@ -19,6 +19,7 @@ package org.apache.phoenix.end2end;
 
 import static org.apache.phoenix.util.TestUtil.GROUPBYTEST_NAME;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.apache.phoenix.util.TestUtil.createGroupByTestTable;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -47,7 +48,7 @@ import com.google.common.collect.Maps;
  * cluster.
  */
 
-public class SpillableGroupByIT extends BaseOwnClusterHBaseManagedTimeIT {
+public class SpillableGroupByIT extends BaseOwnClusterClientManagedTimeIT {
 
     private static final int NUM_ROWS_INSERTED = 1000;
     
@@ -72,10 +73,8 @@ public class SpillableGroupByIT extends BaseOwnClusterHBaseManagedTimeIT {
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
 
-    private long createTable() throws Exception {
-        long ts = nextTimestamp();
-        ensureTableCreated(getUrl(), GROUPBYTEST_NAME, GROUPBYTEST_NAME, null, ts - 2);
-        return ts;
+    private void createTable(Connection conn, String tableName) throws Exception {
+        createGroupByTestTable(conn, tableName);
     }
 
     private void loadData(long ts) throws SQLException {
@@ -108,13 +107,19 @@ public class SpillableGroupByIT extends BaseOwnClusterHBaseManagedTimeIT {
     
     @Test
     public void testScanUri() throws Exception {
+        long ts = nextTimestamp();
         SpillableGroupByIT spGpByT = new SpillableGroupByIT();
-        long ts = spGpByT.createTable();
-        spGpByT.loadData(ts);
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
-                Long.toString(ts + 10));
+                Long.toString(ts));
         Connection conn = DriverManager.getConnection(getUrl(), props);
+        createTable(conn, GROUPBYTEST_NAME);
+        ts += 2;
+        spGpByT.loadData(ts);
+        props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
+                Long.toString(ts + 10));
+        conn = DriverManager.getConnection(getUrl(), props);
         try {
             Statement stmt = conn.createStatement();
             ResultSet rs = stmt.executeQuery(GROUPBY1);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
index 65f9bac..0dc2036 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
@@ -11,8 +11,6 @@ package org.apache.phoenix.end2end.index;
 
 import static org.apache.phoenix.query.QueryConstants.MILLIS_IN_DAY;
 import static org.apache.phoenix.util.TestUtil.INDEX_DATA_SCHEMA;
-import static org.apache.phoenix.util.TestUtil.INDEX_DATA_TABLE;
-import static org.apache.phoenix.util.TestUtil.MUTABLE_INDEX_DATA_TABLE;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -111,6 +109,11 @@ public class IndexExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
         assertEquals(i, rs.getLong(12));
     }
 
+    private void createDataTable(Connection conn, String dataTableName, String tableProps) throws SQLException {
+        String tableDDL = "create table " + dataTableName + TEST_TABLE_SCHEMA + tableProps;
+        conn.createStatement().execute(tableDDL);
+    }
+    
     protected void helpTestCreateAndUpdate(boolean mutable, boolean localIndex) throws Exception {
         String dataTableName = generateRandomString();
         String fullDataTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + dataTableName;
@@ -119,7 +122,8 @@ public class IndexExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
         Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             conn.setAutoCommit(false);
-            populateDataTable(conn, dataTableName, mutable ? MUTABLE_INDEX_DATA_TABLE : INDEX_DATA_TABLE);
+            createDataTable(conn, fullDataTableName, mutable ? "" : "IMMUTABLE_ROWS=true");
+            populateDataTable(conn, fullDataTableName);
 
             // create an expression index
             String ddl = "CREATE "
@@ -207,7 +211,7 @@ public class IndexExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
         String dataTableName = generateRandomString();
         String fullDataTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + dataTableName;
         String indexName = generateRandomString();
-    	helpTestUpdate(dataTableName, fullDataTableName, indexName, false);
+    	helpTestUpdate(fullDataTableName, indexName, false);
     }
 
     @Test
@@ -215,15 +219,16 @@ public class IndexExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
         String dataTableName = generateRandomString();
         String fullDataTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + dataTableName;
         String indexName = generateRandomString();
-        helpTestUpdate(dataTableName, fullDataTableName, indexName, true);
+        helpTestUpdate(fullDataTableName, indexName, true);
     }
     
-    protected void helpTestUpdate(String dataTableName, String fullDataTableName, String indexName, boolean localIndex) throws Exception {
+    protected void helpTestUpdate(String fullDataTableName, String indexName, boolean localIndex) throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             conn.setAutoCommit(false);
-            populateDataTable(conn, dataTableName, MUTABLE_INDEX_DATA_TABLE);
+            createDataTable(conn, fullDataTableName, "");
+            populateDataTable(conn, fullDataTableName);
 
             // create an expression index
             String ddl = "CREATE "
@@ -280,9 +285,8 @@ public class IndexExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
         }
     }
 
-    private void populateDataTable(Connection conn, String dataTable, String tableType) throws SQLException {
-        ensureTableCreated(getUrl(), dataTable, tableType);
-        String upsert = "UPSERT INTO " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + dataTable
+    private void populateDataTable(Connection conn, String dataTable) throws SQLException {
+        String upsert = "UPSERT INTO " + dataTable
                 + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
         PreparedStatement stmt1 = conn.prepareStatement(upsert);
         // insert two rows
@@ -320,8 +324,8 @@ public class IndexExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
         Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             conn.setAutoCommit(false);
-            ensureTableCreated(getUrl(), dataTableName, mutable ? MUTABLE_INDEX_DATA_TABLE : INDEX_DATA_TABLE);
-            populateDataTable(conn, dataTableName, mutable ? MUTABLE_INDEX_DATA_TABLE : INDEX_DATA_TABLE);
+            createDataTable(conn, fullDataTableName, mutable ? "" : "IMMUTABLE_ROWS=true");
+            populateDataTable(conn, fullDataTableName);
             String ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullDataTableName
                     + " (2*long_col2)";
             PreparedStatement stmt = conn.prepareStatement(ddl);
@@ -394,8 +398,8 @@ public class IndexExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
         Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             conn.setAutoCommit(false);
-            ensureTableCreated(getUrl(), dataTableName, mutable ? MUTABLE_INDEX_DATA_TABLE : INDEX_DATA_TABLE);
-            populateDataTable(conn, dataTableName, mutable ? MUTABLE_INDEX_DATA_TABLE : INDEX_DATA_TABLE);
+            createDataTable(conn, fullDataTableName, mutable ? "" : "IMMUTABLE_ROWS=true");
+            populateDataTable(conn, fullDataTableName);
             String ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullDataTableName
                     + " (long_pk, varchar_pk, 1+long_pk, UPPER(varchar_pk) )" + " INCLUDE (long_col1, long_col2)";
             PreparedStatement stmt = conn.prepareStatement(ddl);
@@ -475,7 +479,8 @@ public class IndexExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
         Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             conn.setAutoCommit(false);
-            populateDataTable(conn, dataTableName, mutable ? MUTABLE_INDEX_DATA_TABLE : INDEX_DATA_TABLE);
+            createDataTable(conn, fullDataTableName, mutable ? "" : "IMMUTABLE_ROWS=true");
+            populateDataTable(conn, fullDataTableName);
             String ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullDataTableName
                     + " (int_col1+int_col2)";
             PreparedStatement stmt = conn.prepareStatement(ddl);
@@ -530,7 +535,8 @@ public class IndexExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
         Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             conn.setAutoCommit(false);
-            populateDataTable(conn, dataTableName, mutable ? MUTABLE_INDEX_DATA_TABLE : INDEX_DATA_TABLE);
+            createDataTable(conn, fullDataTableName, mutable ? "" : "IMMUTABLE_ROWS=true");
+            populateDataTable(conn, fullDataTableName);
             String ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullDataTableName
                     + " (int_col1+1)";
             PreparedStatement stmt = conn.prepareStatement(ddl);
@@ -584,7 +590,8 @@ public class IndexExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
         Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             conn.setAutoCommit(false);
-            populateDataTable(conn, dataTableName, mutable ? MUTABLE_INDEX_DATA_TABLE : INDEX_DATA_TABLE);
+            createDataTable(conn, fullDataTableName, mutable ? "" : "IMMUTABLE_ROWS=true");
+            populateDataTable(conn, fullDataTableName);
             String ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullDataTableName
                     + " (int_col1+1)";
 
@@ -634,7 +641,8 @@ public class IndexExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
         Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             conn.setAutoCommit(false);
-            populateDataTable(conn, dataTableName, mutable ? MUTABLE_INDEX_DATA_TABLE : INDEX_DATA_TABLE);
+            createDataTable(conn, fullDataTableName, mutable ? "" : "IMMUTABLE_ROWS=true");
+            populateDataTable(conn, fullDataTableName);
             String ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullDataTableName
                     + " (int_col1+1)";
 
@@ -798,7 +806,8 @@ public class IndexExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
         Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             conn.setAutoCommit(false);
-            populateDataTable(conn, dataTableName, mutable ? MUTABLE_INDEX_DATA_TABLE : INDEX_DATA_TABLE);
+            createDataTable(conn, fullDataTableName, mutable ? "" : "IMMUTABLE_ROWS=true");
+            populateDataTable(conn, fullDataTableName);
             String ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + fullDataTableName
                     + " (int_col1+1)";
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
index 8283b28..072e216 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
@@ -517,7 +517,7 @@ public class IndexIT extends BaseOwnClusterIT {
 	        conn.setAutoCommit(false);
             Date date = new Date(System.currentTimeMillis());
             
-            createMultiCFTestTable(fullTableName, tableDDLOptions);
+            TestUtil.createMultiCFTestTable(conn, fullTableName, tableDDLOptions);
             populateMultiCFTestTable(fullTableName, date);
             String ddl = "CREATE " + (localIndex ? " LOCAL " : "") + " INDEX " + indexName + " ON " + fullTableName + " (date_col)";
             PreparedStatement stmt = conn.prepareStatement(ddl);
@@ -1011,7 +1011,7 @@ public class IndexIT extends BaseOwnClusterIT {
 	        ResultSet rs;
             Date date = new Date(System.currentTimeMillis());
             
-            createMultiCFTestTable(fullTableName, tableDDLOptions);
+            TestUtil.createMultiCFTestTable(conn, fullTableName, tableDDLOptions);
             populateMultiCFTestTable(fullTableName, date);
             String ddl = null;
             ddl = "CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + indexName + " ON " + fullTableName + " (decimal_pk) INCLUDE (decimal_col1, decimal_col2)";

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexMetadataIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexMetadataIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexMetadataIT.java
index 8cce14a..2e1fe1d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexMetadataIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexMetadataIT.java
@@ -17,7 +17,8 @@
  */
 package org.apache.phoenix.end2end.index;
 
-import static org.apache.phoenix.util.TestUtil.*;
+import static org.apache.phoenix.util.TestUtil.INDEX_DATA_SCHEMA;
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -33,7 +34,6 @@ import java.sql.SQLException;
 import java.sql.Types;
 import java.util.Properties;
 
-import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
 import org.apache.phoenix.exception.SQLExceptionCode;
@@ -50,7 +50,6 @@ import org.apache.phoenix.schema.types.PDate;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.StringUtil;
-import org.apache.phoenix.util.TestUtil;
 import org.junit.Test;
 
 
@@ -121,10 +120,12 @@ public class IndexMetadataIT extends BaseHBaseManagedTimeTableReuseIT {
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.setAutoCommit(false);
         String indexDataTable = generateRandomString();
+        String fullIndexDataTable = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable;
         String indexName = generateRandomString();
         try {
-            ensureTableCreated(getUrl(), indexDataTable, MUTABLE_INDEX_DATA_TABLE);
-            String ddl = "CREATE INDEX " + indexName + " ON " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable
+            String tableDDL = "create table " + fullIndexDataTable + TEST_TABLE_SCHEMA;
+            conn.createStatement().execute(tableDDL);
+            String ddl = "CREATE INDEX " + indexName + " ON " + fullIndexDataTable
                     + " (varchar_col1 ASC, varchar_col2 ASC, int_pk DESC)"
                     + " INCLUDE (int_col1, int_col2)";
             PreparedStatement stmt = conn.prepareStatement(ddl);
@@ -299,8 +300,9 @@ public class IndexMetadataIT extends BaseHBaseManagedTimeTableReuseIT {
         String indexName = generateRandomString();
         conn.setAutoCommit(false);
         try {
-            ensureTableCreated(getUrl(), indexDataTable, INDEX_DATA_TABLE);
-            String ddl = "CREATE INDEX " + indexName + " ON " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable
+            String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable;
+            conn.createStatement().execute("create table " + fullTableName + TEST_TABLE_SCHEMA + "IMMUTABLE_ROWS=true");
+            String ddl = "CREATE INDEX " + indexName + " ON " + fullTableName
                     + " (char_col1 ASC, int_col2 ASC, long_col2 DESC)"
                     + " INCLUDE (int_col1)";
             PreparedStatement stmt = conn.prepareStatement(ddl);
@@ -359,8 +361,9 @@ public class IndexMetadataIT extends BaseHBaseManagedTimeTableReuseIT {
         String indexName = "\"lowerCaseIndex\"";
         String indexDataTable = generateRandomString();
         try {
-            ensureTableCreated(getUrl(), indexDataTable, INDEX_DATA_TABLE);
-            String ddl = "CREATE INDEX " + indexName + " ON " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable
+            String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable;
+            conn.createStatement().execute("create table " + fullTableName + TEST_TABLE_SCHEMA + "IMMUTABLE_ROWS=true");
+            String ddl = "CREATE INDEX " + indexName + " ON " + fullTableName
                     + " (char_col1 ASC, int_col2 ASC, long_col2 DESC)"
                     + " INCLUDE (int_col1)";
             PreparedStatement stmt = conn.prepareStatement(ddl);
@@ -394,8 +397,9 @@ public class IndexMetadataIT extends BaseHBaseManagedTimeTableReuseIT {
         String indexDataTable = generateRandomString();
         String indexName = generateRandomString();
         try {
-            ensureTableCreated(getUrl(), indexDataTable, TestUtil.INDEX_DATA_TABLE);
-            String ddl = "CREATE INDEX " + indexName + " ON " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable
+            String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable;
+            conn.createStatement().execute("create table " + fullTableName + TEST_TABLE_SCHEMA + "IMMUTABLE_ROWS=true");
+            String ddl = "CREATE INDEX " + indexName + " ON " + fullTableName
             		+ " (a.int_col1, a.long_col1, b.int_col2, b.long_col2)"
             		+ " INCLUDE(int_col1, int_col2)";
             PreparedStatement stmt = conn.prepareStatement(ddl);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/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 0fde1c6..1646538 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
@@ -109,7 +109,7 @@ public class MutableIndexIT extends BaseHBaseManagedTimeTableReuseIT {
 			String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
 			String fullIndexName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, indexName);
 
-			createMultiCFTestTable(fullTableName, tableDDLOptions);
+			TestUtil.createMultiCFTestTable(conn, fullTableName, tableDDLOptions);
             populateMultiCFTestTable(fullTableName);
             PreparedStatement stmt = conn.prepareStatement("CREATE " + (localIndex ? " LOCAL " : "") + " INDEX " + indexName + " ON " + fullTableName 
             		+ " (char_col1 ASC, int_col1 ASC) INCLUDE (long_col1, long_col2)");

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java b/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java
index 00de6b0..f1eafc2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java
@@ -18,7 +18,6 @@
 package org.apache.phoenix.rpc;
 
 import static org.apache.phoenix.util.TestUtil.INDEX_DATA_SCHEMA;
-import static org.apache.phoenix.util.TestUtil.MUTABLE_INDEX_DATA_TABLE;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.apache.phoenix.util.TestUtil.TRANSACTIONAL_DATA_TABLE;
 import static org.junit.Assert.assertFalse;
@@ -84,7 +83,8 @@ public class UpdateCacheIT extends BaseHBaseManagedTimeTableReuseIT {
     @Test
     public void testUpdateCacheForTxnTable() throws Exception {
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + TRANSACTIONAL_DATA_TABLE;
-        ensureTableCreated(getUrl(), TRANSACTIONAL_DATA_TABLE, TRANSACTIONAL_DATA_TABLE);
+        Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));
+        conn.createStatement().execute("create table " + fullTableName + TEST_TABLE_SCHEMA + "TRANSACTIONAL=true");
         helpTestUpdateCache(fullTableName, null, new int[] {1, 1});
     }
     
@@ -92,7 +92,8 @@ public class UpdateCacheIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testUpdateCacheForNonTxnTable() throws Exception {
         String tableName = generateRandomString();
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + tableName;
-        ensureTableCreated(getUrl(), tableName, MUTABLE_INDEX_DATA_TABLE);
+        Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));
+        conn.createStatement().execute("create table " + fullTableName + TEST_TABLE_SCHEMA);
         helpTestUpdateCache(fullTableName, null, new int[] {1, 3});
     }
 	
@@ -107,9 +108,9 @@ public class UpdateCacheIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testUpdateCacheForNeverUpdatedTable() throws Exception {
         String tableName = generateRandomString();
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + tableName;
-        ensureTableCreated(getUrl(), tableName, MUTABLE_INDEX_DATA_TABLE);
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.createStatement().execute("create table " + fullTableName + TEST_TABLE_SCHEMA);
             conn.createStatement().execute(
             "alter table " + fullTableName + " SET UPDATE_CACHE_FREQUENCY=NEVER");
         }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheWithScnIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheWithScnIT.java b/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheWithScnIT.java
index 44e3115..75f67b3 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheWithScnIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheWithScnIT.java
@@ -19,9 +19,16 @@ package org.apache.phoenix.rpc;
 
 import static org.apache.phoenix.util.TestUtil.INDEX_DATA_SCHEMA;
 import static org.apache.phoenix.util.TestUtil.MUTABLE_INDEX_DATA_TABLE;
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.Properties;
 
 import org.apache.phoenix.end2end.BaseClientManagedTimeIT;
 import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
 
 public class UpdateCacheWithScnIT extends BaseClientManagedTimeIT {
@@ -30,7 +37,10 @@ public class UpdateCacheWithScnIT extends BaseClientManagedTimeIT {
 	public void testUpdateCacheWithScn() throws Exception {
         long ts = nextTimestamp();
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + MUTABLE_INDEX_DATA_TABLE;
-        ensureTableCreated(getUrl(), MUTABLE_INDEX_DATA_TABLE, MUTABLE_INDEX_DATA_TABLE, ts);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        conn.createStatement().execute("create table " + fullTableName + TEST_TABLE_SCHEMA);
         // FIXME: given that the scn is advancing in the test, why aren't there more RPCs?
 		UpdateCacheIT.helpTestUpdateCache(fullTableName, ts+2, new int[] {1, 1});
 	}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
index 0377a37..e55a63e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
@@ -19,7 +19,6 @@ package org.apache.phoenix.tx;
 
 import static org.apache.phoenix.util.TestUtil.INDEX_DATA_SCHEMA;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.apache.phoenix.util.TestUtil.TRANSACTIONAL_DATA_TABLE;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -52,6 +51,7 @@ import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.jdbc.PhoenixResultSet;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
@@ -62,15 +62,13 @@ import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
 import org.apache.phoenix.util.TestUtil;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
 import org.apache.tephra.TransactionContext;
 import org.apache.tephra.TransactionSystemClient;
 import org.apache.tephra.TxConstants;
 import org.apache.tephra.hbase.TransactionAwareHTable;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
@@ -85,14 +83,18 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
         props.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.toString(true));
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
-        
+
+    private static void createTable(Connection conn, String tableName) throws SQLException {
+        conn.createStatement().execute("create table " + tableName + TEST_TABLE_SCHEMA + "TRANSACTIONAL=true");
+    }
+    
     @Test
     public void testReadOwnWrites() throws Exception {
         String transTableName = generateRandomString();
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + transTableName;
-        ensureTableCreated(getUrl(), transTableName, TRANSACTIONAL_DATA_TABLE);
         String selectSql = "SELECT * FROM "+ fullTableName;
         try (Connection conn = DriverManager.getConnection(getUrl())) {
+            createTable(conn, fullTableName);
             conn.setAutoCommit(false);
             ResultSet rs = conn.createStatement().executeQuery(selectSql);
             assertFalse(rs.next());
@@ -125,9 +127,9 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testTxnClosedCorrecty() throws Exception {
         String transTableName = generateRandomString();
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + transTableName;
-        ensureTableCreated(getUrl(), transTableName, TRANSACTIONAL_DATA_TABLE);
         String selectSql = "SELECT * FROM "+fullTableName;
         try (Connection conn = DriverManager.getConnection(getUrl())) {
+            createTable(conn, fullTableName);
             conn.setAutoCommit(false);
             ResultSet rs = conn.createStatement().executeQuery(selectSql);
             assertFalse(rs.next());
@@ -144,12 +146,13 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
             rs = conn.createStatement().executeQuery(selectSql);
             TestUtil.validateRowKeyColumns(rs, 1);
             TestUtil.validateRowKeyColumns(rs, 2);
+            Long currentTx = rs.unwrap(PhoenixResultSet.class).getCurrentRow().getValue(0).getTimestamp();
             assertFalse(rs.next());
             
             conn.close();
-            // wait for any open txns to time out
-            Thread.sleep(DEFAULT_TXN_TIMEOUT_SECONDS*1000+10000);
-            assertTrue("There should be no invalid transactions", txManager.getInvalidSize()==0);
+            // start new connection
+            conn.createStatement().executeQuery(selectSql);
+            assertFalse("This transaction should not be on the invalid transactions", txManager.getCurrentState().getInvalid().contains(currentTx));
         }
     }
     
@@ -157,10 +160,11 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testDelete() throws Exception {
         String transTableName = generateRandomString();
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + transTableName;
-        ensureTableCreated(getUrl(), transTableName, TRANSACTIONAL_DATA_TABLE);
         String selectSQL = "SELECT * FROM " + fullTableName;
-        try (Connection conn1 = DriverManager.getConnection(getUrl()); 
+        try (Connection conn = DriverManager.getConnection(getUrl());
+                Connection conn1 = DriverManager.getConnection(getUrl()); 
                 Connection conn2 = DriverManager.getConnection(getUrl())) {
+            createTable(conn, fullTableName);
             conn1.setAutoCommit(false);
             ResultSet rs = conn1.createStatement().executeQuery(selectSQL);
             assertFalse(rs.next());
@@ -196,8 +200,8 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testAutoCommitQuerySingleTable() throws Exception {
         String transTableName = generateRandomString();
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + transTableName;
-        ensureTableCreated(getUrl(), transTableName, TRANSACTIONAL_DATA_TABLE);
         try (Connection conn = DriverManager.getConnection(getUrl())) {
+            createTable(conn, fullTableName);
             conn.setAutoCommit(true);
             // verify no rows returned
             ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + fullTableName);
@@ -209,8 +213,8 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testAutoCommitQueryMultiTables() throws Exception {
         String transTableName = generateRandomString();
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + transTableName;
-        ensureTableCreated(getUrl(), transTableName, TRANSACTIONAL_DATA_TABLE);
         try (Connection conn = DriverManager.getConnection(getUrl())) {
+            createTable(conn, fullTableName);
             conn.setAutoCommit(true);
             // verify no rows returned
             ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + fullTableName + " a JOIN " + fullTableName + " b ON (a.long_pk = b.int_pk)");
@@ -222,9 +226,9 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testColConflicts() throws Exception {
         String transTableName = generateRandomString();
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + transTableName;
-        ensureTableCreated(getUrl(), transTableName, TRANSACTIONAL_DATA_TABLE);
         try (Connection conn1 = DriverManager.getConnection(getUrl()); 
                 Connection conn2 = DriverManager.getConnection(getUrl())) {
+            createTable(conn1, fullTableName);
             conn1.setAutoCommit(false);
             conn2.setAutoCommit(false);
             String selectSql = "SELECT * FROM "+fullTableName;
@@ -295,7 +299,8 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testRowConflictDetected() throws Exception {
         String transTableName = generateRandomString();
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + transTableName;
-        ensureTableCreated(getUrl(), transTableName, TRANSACTIONAL_DATA_TABLE);
+        Connection conn = DriverManager.getConnection(getUrl());
+        createTable(conn, fullTableName);
         testRowConflicts(fullTableName);
     }
     
@@ -303,8 +308,8 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testNoConflictDetectionForImmutableRows() throws Exception {
         String transTableName = generateRandomString();
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + transTableName;
-        ensureTableCreated(getUrl(), transTableName, TRANSACTIONAL_DATA_TABLE);
         Connection conn = DriverManager.getConnection(getUrl());
+        createTable(conn, fullTableName);
         conn.createStatement().execute("ALTER TABLE " + fullTableName + " SET IMMUTABLE_ROWS=true");
         testRowConflicts(fullTableName);
     }
@@ -496,10 +501,6 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
     
     @Test
     public void testCreateTableToBeTransactional() throws Exception {
-
-        String transTableName = generateRandomString();
-        String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + transTableName;
-        ensureTableCreated(getUrl(), transTableName, TRANSACTIONAL_DATA_TABLE);
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         String ddl = "CREATE TABLE TEST_TRANSACTIONAL_TABLE (k varchar primary key) transactional=true";
@@ -542,11 +543,13 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
         assertTrue(htable.getTableDescriptor().getCoprocessors().contains(PhoenixTransactionalProcessor.class.getName()));
     }
 
+    @Test
     public void testCurrentDate() throws Exception {
         String transTableName = generateRandomString();
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + transTableName;
         String selectSql = "SELECT current_date() FROM "+fullTableName;
         try (Connection conn = DriverManager.getConnection(getUrl())) {
+            createTable(conn, fullTableName);
             conn.setAutoCommit(false);
             ResultSet rs = conn.createStatement().executeQuery(selectSql);
             assertFalse(rs.next());
@@ -782,10 +785,10 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testInflightUpdateNotSeen() throws Exception {
         String transTableName = generateRandomString();
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + transTableName;
-        ensureTableCreated(getUrl(), transTableName, TRANSACTIONAL_DATA_TABLE);
         String selectSQL = "SELECT * FROM " + fullTableName;
         try (Connection conn1 = DriverManager.getConnection(getUrl()); 
                 Connection conn2 = DriverManager.getConnection(getUrl())) {
+            createTable(conn1, fullTableName);
             conn1.setAutoCommit(false);
             conn2.setAutoCommit(true);
             ResultSet rs = conn1.createStatement().executeQuery(selectSQL);
@@ -836,10 +839,10 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testInflightDeleteNotSeen() throws Exception {
         String transTableName = generateRandomString();
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + transTableName;
-        ensureTableCreated(getUrl(), transTableName, TRANSACTIONAL_DATA_TABLE);
         String selectSQL = "SELECT * FROM " + fullTableName;
         try (Connection conn1 = DriverManager.getConnection(getUrl()); 
                 Connection conn2 = DriverManager.getConnection(getUrl())) {
+            createTable(conn1, fullTableName);
             conn1.setAutoCommit(false);
             conn2.setAutoCommit(true);
             ResultSet rs = conn1.createStatement().executeQuery(selectSQL);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixTestDriver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixTestDriver.java b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixTestDriver.java
index c8928cc..f9fa9f8 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixTestDriver.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixTestDriver.java
@@ -116,7 +116,7 @@ public class PhoenixTestDriver extends PhoenixEmbeddedDriver {
             try {
                 queryServices.close();
             } finally {
-                if (executor != null) executor.shutdown();
+                if (executor != null) executor.shutdownNow();
                 connectionQueryServices = null;
             }
         }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
index daef367..a28ef3b 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
@@ -42,11 +42,8 @@ import static org.apache.phoenix.util.TestUtil.ENTITY_HISTORY_SALTED_TABLE_NAME;
 import static org.apache.phoenix.util.TestUtil.ENTITY_HISTORY_TABLE_NAME;
 import static org.apache.phoenix.util.TestUtil.E_VALUE;
 import static org.apache.phoenix.util.TestUtil.FUNKY_NAME;
-import static org.apache.phoenix.util.TestUtil.GROUPBYTEST_NAME;
 import static org.apache.phoenix.util.TestUtil.HBASE_DYNAMIC_COLUMNS;
 import static org.apache.phoenix.util.TestUtil.HBASE_NATIVE;
-import static org.apache.phoenix.util.TestUtil.INDEX_DATA_SCHEMA;
-import static org.apache.phoenix.util.TestUtil.INDEX_DATA_TABLE;
 import static org.apache.phoenix.util.TestUtil.JOIN_COITEM_TABLE_FULL_NAME;
 import static org.apache.phoenix.util.TestUtil.JOIN_CUSTOMER_TABLE_FULL_NAME;
 import static org.apache.phoenix.util.TestUtil.JOIN_ITEM_TABLE_FULL_NAME;
@@ -55,7 +52,6 @@ import static org.apache.phoenix.util.TestUtil.JOIN_SUPPLIER_TABLE_FULL_NAME;
 import static org.apache.phoenix.util.TestUtil.KEYONLY_NAME;
 import static org.apache.phoenix.util.TestUtil.MDTEST_NAME;
 import static org.apache.phoenix.util.TestUtil.MULTI_CF_NAME;
-import static org.apache.phoenix.util.TestUtil.MUTABLE_INDEX_DATA_TABLE;
 import static org.apache.phoenix.util.TestUtil.PARENTID1;
 import static org.apache.phoenix.util.TestUtil.PARENTID2;
 import static org.apache.phoenix.util.TestUtil.PARENTID3;
@@ -79,15 +75,14 @@ import static org.apache.phoenix.util.TestUtil.ROW7;
 import static org.apache.phoenix.util.TestUtil.ROW8;
 import static org.apache.phoenix.util.TestUtil.ROW9;
 import static org.apache.phoenix.util.TestUtil.STABLE_NAME;
+import static org.apache.phoenix.util.TestUtil.SUM_DOUBLE_NAME;
 import static org.apache.phoenix.util.TestUtil.TABLE_WITH_ARRAY;
 import static org.apache.phoenix.util.TestUtil.TABLE_WITH_SALTING;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.apache.phoenix.util.TestUtil.TRANSACTIONAL_DATA_TABLE;
-import static org.apache.phoenix.util.TestUtil.SUM_DOUBLE_NAME;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
@@ -157,6 +152,11 @@ import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
 import org.apache.phoenix.util.SchemaUtil;
+import org.apache.tephra.TransactionManager;
+import org.apache.tephra.TxConstants;
+import org.apache.tephra.distributed.TransactionService;
+import org.apache.tephra.metrics.TxMetricsCollector;
+import org.apache.tephra.persist.InMemoryTransactionStateStorage;
 import org.apache.twill.discovery.DiscoveryService;
 import org.apache.twill.discovery.ZKDiscoveryService;
 import org.apache.twill.internal.utils.Networks;
@@ -175,12 +175,6 @@ import com.google.common.collect.Sets;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import com.google.inject.util.Providers;
 
-import org.apache.tephra.TransactionManager;
-import org.apache.tephra.TxConstants;
-import org.apache.tephra.distributed.TransactionService;
-import org.apache.tephra.metrics.TxMetricsCollector;
-import org.apache.tephra.persist.InMemoryTransactionStateStorage;
-
 /**
  * 
  * Base class that contains all the methods needed by
@@ -364,9 +358,6 @@ public abstract class BaseTest {
                 "    e.cpu_utilization decimal(31,10),\n" +
                 "    f.response_time bigint,\n" +
                 "    g.response_time bigint)");
-        builder.put(GROUPBYTEST_NAME,"create table " + GROUPBYTEST_NAME +
-                "   (id varchar not null primary key,\n" +
-                "    uri varchar, appcpu integer)");
         builder.put(HBASE_NATIVE,"create table " + HBASE_NATIVE +
                 "   (uint_key unsigned_int not null," +
                 "    ulong_key unsigned_long not null," +
@@ -442,9 +433,6 @@ public abstract class BaseTest {
         builder.put("KVBigIntValueTest", "create table KVBigIntValueTest" +
                 "   (pk integer not null primary key,\n" +
                 "    kv bigint)\n");
-        builder.put(INDEX_DATA_TABLE, "create table " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + INDEX_DATA_TABLE + TEST_TABLE_SCHEMA + "IMMUTABLE_ROWS=true");
-        builder.put(MUTABLE_INDEX_DATA_TABLE, "create table " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + MUTABLE_INDEX_DATA_TABLE + TEST_TABLE_SCHEMA);
-        builder.put(TRANSACTIONAL_DATA_TABLE, "create table " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + TRANSACTIONAL_DATA_TABLE + TEST_TABLE_SCHEMA + "TRANSACTIONAL=true");
         builder.put(SUM_DOUBLE_NAME,"create table SumDoubleTest" +
                 "   (id varchar not null primary key, d DOUBLE, f FLOAT, ud UNSIGNED_DOUBLE, uf UNSIGNED_FLOAT, i integer, de decimal)");
         builder.put(JOIN_ORDER_TABLE_FULL_NAME, "create table " + JOIN_ORDER_TABLE_FULL_NAME +
@@ -1988,32 +1976,6 @@ public abstract class BaseTest {
         }
     }
 
-    protected static void createMultiCFTestTable(String tableName, String options) throws SQLException {
-        String ddl = "create table if not exists " + tableName + "(" +
-                "   varchar_pk VARCHAR NOT NULL, " +
-                "   char_pk CHAR(5) NOT NULL, " +
-                "   int_pk INTEGER NOT NULL, "+ 
-                "   long_pk BIGINT NOT NULL, " +
-                "   decimal_pk DECIMAL(31, 10) NOT NULL, " +
-                "   a.varchar_col1 VARCHAR, " +
-                "   a.char_col1 CHAR(5), " +
-                "   a.int_col1 INTEGER, " +
-                "   a.long_col1 BIGINT, " +
-                "   a.decimal_col1 DECIMAL(31, 10), " +
-                "   b.varchar_col2 VARCHAR, " +
-                "   b.char_col2 CHAR(5), " +
-                "   b.int_col2 INTEGER, " +
-                "   b.long_col2 BIGINT, " +
-                "   b.decimal_col2 DECIMAL, " +
-                "   b.date_col DATE " + 
-                "   CONSTRAINT pk PRIMARY KEY (varchar_pk, char_pk, int_pk, long_pk DESC, decimal_pk)) "
-                + (options!=null? options : "");
-            Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-            Connection conn = DriverManager.getConnection(getUrl(), props);
-            conn.createStatement().execute(ddl);
-            conn.close();
-    }
-        
     // Populate the test table with data.
     protected static void populateMultiCFTestTable(String tableName) throws SQLException {
         populateMultiCFTestTable(tableName, null);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7af70887/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
index 68e7b9b..cddd762 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
@@ -472,6 +472,12 @@ public class TestUtil {
         conn.commit();
     }
 
+    public static void createGroupByTestTable(Connection conn, String tableName) throws SQLException {
+        conn.createStatement().execute("create table " + tableName +
+                "   (id varchar not null primary key,\n" +
+                "    uri varchar, appcpu integer)");
+    }
+    
     private static void createTable(Connection conn, String inputSqlType, String tableName, String sortOrder) throws SQLException {
         String dmlFormat =
             "CREATE TABLE " + tableName + "_%s (id INTEGER NOT NULL, pk %s NOT NULL, " + "kv %s "
@@ -697,5 +703,28 @@ public class TestUtil {
             return aggregators;
         }
     }
+
+    public static void createMultiCFTestTable(Connection conn, String tableName, String options) throws SQLException {
+        String ddl = "create table if not exists " + tableName + "(" +
+                "   varchar_pk VARCHAR NOT NULL, " +
+                "   char_pk CHAR(5) NOT NULL, " +
+                "   int_pk INTEGER NOT NULL, "+ 
+                "   long_pk BIGINT NOT NULL, " +
+                "   decimal_pk DECIMAL(31, 10) NOT NULL, " +
+                "   a.varchar_col1 VARCHAR, " +
+                "   a.char_col1 CHAR(5), " +
+                "   a.int_col1 INTEGER, " +
+                "   a.long_col1 BIGINT, " +
+                "   a.decimal_col1 DECIMAL(31, 10), " +
+                "   b.varchar_col2 VARCHAR, " +
+                "   b.char_col2 CHAR(5), " +
+                "   b.int_col2 INTEGER, " +
+                "   b.long_col2 BIGINT, " +
+                "   b.decimal_col2 DECIMAL, " +
+                "   b.date_col DATE " + 
+                "   CONSTRAINT pk PRIMARY KEY (varchar_pk, char_pk, int_pk, long_pk DESC, decimal_pk)) "
+                + (options!=null? options : "");
+            conn.createStatement().execute(ddl);
+    }
 }
 


[19/47] phoenix git commit: PHOENIX-3170 Remove the futuretask from the list if StaleRegionBoundaryCacheException is thrown while initializing the scanners(Rajeshbabu)

Posted by ma...@apache.org.
PHOENIX-3170 Remove the futuretask from the list if StaleRegionBoundaryCacheException is thrown while initializing the scanners(Rajeshbabu)


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

Branch: refs/heads/calcite
Commit: c0f72b536684bdbb6f3e597d5d93e767732bd007
Parents: 47a2b2c
Author: Rajeshbabu Chintaguntla <ra...@apache.org>
Authored: Tue Sep 13 16:33:46 2016 +0530
Committer: Rajeshbabu Chintaguntla <ra...@apache.org>
Committed: Tue Sep 13 16:33:46 2016 +0530

----------------------------------------------------------------------
 .../java/org/apache/phoenix/iterate/BaseResultIterators.java   | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/c0f72b53/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
index 8b9adfd..2685b93 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
@@ -31,6 +31,7 @@ import java.io.EOFException;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -751,7 +752,9 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
             boolean clearedCache = false;
             for (List<Pair<Scan,Future<PeekingResultIterator>>> future : reverseIfNecessary(futures,isReverse)) {
                 List<PeekingResultIterator> concatIterators = Lists.newArrayListWithExpectedSize(future.size());
-                for (Pair<Scan,Future<PeekingResultIterator>> scanPair : reverseIfNecessary(future,isReverse)) {
+                Iterator<Pair<Scan, Future<PeekingResultIterator>>> scanPairItr = reverseIfNecessary(future,isReverse).iterator();
+                while (scanPairItr.hasNext()) {
+                    Pair<Scan,Future<PeekingResultIterator>> scanPair = scanPairItr.next();
                     try {
                         long timeOutForScan = maxQueryEndTime - System.currentTimeMillis();
                         if (timeOutForScan < 0) {
@@ -773,6 +776,7 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
                         try { // Rethrow as SQLException
                             throw ServerUtil.parseServerException(e);
                         } catch (StaleRegionBoundaryCacheException e2) {
+                            scanPairItr.remove();
                             // Catch only to try to recover from region boundary cache being out of date
                             if (!clearedCache) { // Clear cache once so that we rejigger job based on new boundaries
                                 services.clearTableRegionCache(physicalTableName);


[14/47] phoenix git commit: PHOENIX-3260 MetadataRegionObserver.postOpen() can prevent region server from shutting down for a long duration

Posted by ma...@apache.org.
PHOENIX-3260 MetadataRegionObserver.postOpen() can prevent region server from shutting down for a long duration


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

Branch: refs/heads/calcite
Commit: d9eb45e14d36f92982c36b85a7132675d6272770
Parents: df0d611
Author: Samarth <sa...@salesforce.com>
Authored: Fri Sep 9 11:24:07 2016 -0700
Committer: Samarth <sa...@salesforce.com>
Committed: Fri Sep 9 11:24:07 2016 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/coprocessor/MetaDataRegionObserver.java   | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d9eb45e1/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
index 5243154..5beba49 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
@@ -156,7 +156,9 @@ public class MetaDataRegionObserver extends BaseRegionObserver {
                 }
             }
         };
-        (new Thread(r)).start();
+        Thread t = new Thread(r);
+        t.setDaemon(true);
+        t.start();
 
         if (!enableRebuildIndex && !blockWriteRebuildIndex) {
             LOG.info("Failure Index Rebuild is skipped by configuration.");


[34/47] phoenix git commit: PHOENIX-3290 Move and/or combine as many NeedsOwnCluster tests to bring down test run time

Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java
deleted file mode 100644
index 4f0da4d..0000000
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.phoenix.end2end.index;
-
-import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HRegionInfo;
-import org.apache.hadoop.hbase.MetaTableAccessor;
-import org.apache.hadoop.hbase.TableName;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.end2end.BaseOwnClusterHBaseManagedTimeIT;
-import org.apache.phoenix.end2end.IndexToolIT;
-import org.apache.phoenix.jdbc.PhoenixConnection;
-import org.apache.phoenix.mapreduce.index.IndexTool;
-import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.query.QueryServicesOptions;
-import org.apache.phoenix.util.ByteUtil;
-import org.apache.phoenix.util.PropertiesUtil;
-import org.apache.phoenix.util.QueryUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
-import org.apache.phoenix.util.SchemaUtil;
-import org.apache.phoenix.util.TestUtil;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.google.common.collect.Maps;
-
-public class IndexOnOwnClusterIT extends BaseOwnClusterHBaseManagedTimeIT {
-    
-    @BeforeClass
-    public static void doSetup() throws Exception {
-        Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(1);
-        serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB,
-            QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
-        setUpRealDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
-                ReadOnlyProps.EMPTY_PROPS);
-    }
-        
-    @Test
-    public void testDeleteFromImmutable() throws Exception {
-        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-            conn.createStatement().execute("CREATE TABLE TEST_TABLE (\n" + 
-                    "        pk1 VARCHAR NOT NULL,\n" + 
-                    "        pk2 VARCHAR NOT NULL,\n" + 
-                    "        pk3 VARCHAR\n" + 
-                    "        CONSTRAINT PK PRIMARY KEY \n" + 
-                    "        (\n" + 
-                    "        pk1,\n" + 
-                    "        pk2,\n" + 
-                    "        pk3\n" + 
-                    "        )\n" + 
-                    "        ) IMMUTABLE_ROWS=true");
-            conn.createStatement().execute("upsert into TEST_TABLE (pk1, pk2, pk3) values ('a', '1', '1')");
-            conn.createStatement().execute("upsert into TEST_TABLE (pk1, pk2, pk3) values ('b', '2', '2')");
-            conn.commit();
-            conn.createStatement().execute("CREATE INDEX TEST_INDEX ON TEST_TABLE (pk3, pk2) ASYNC");
-            
-            // this delete will be issued at a timestamp later than the above timestamp of the index table
-            conn.createStatement().execute("delete from TEST_TABLE where pk1 = 'a'");
-            conn.commit();
-
-            // run the index MR job
-            final IndexTool indexingTool = new IndexTool();
-            indexingTool.setConf(new Configuration(getUtility().getConfiguration()));
-            final String[] cmdArgs =
-                    IndexToolIT.getArgValues(null, "TEST_TABLE", "TEST_INDEX", true);
-            int status = indexingTool.run(cmdArgs);
-            assertEquals(0, status);
-
-            // upsert two more rows
-            conn.createStatement().execute(
-                "upsert into TEST_TABLE (pk1, pk2, pk3) values ('a', '3', '3')");
-            conn.createStatement().execute(
-                "upsert into TEST_TABLE (pk1, pk2, pk3) values ('b', '4', '4')");
-            conn.commit();
-
-            // validate that delete markers were issued correctly and only ('a', '1', 'value1') was
-            // deleted
-            String query = "SELECT pk3 from TEST_TABLE ORDER BY pk3";
-            ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + query);
-            String expectedPlan =
-                    "CLIENT PARALLEL 1-WAY FULL SCAN OVER TEST_INDEX\n"
-                            + "    SERVER FILTER BY FIRST KEY ONLY";
-            assertEquals("Wrong plan ", expectedPlan, QueryUtil.getExplainPlan(rs));
-            rs = conn.createStatement().executeQuery(query);
-            assertTrue(rs.next());
-            assertEquals("2", rs.getString(1));
-            assertTrue(rs.next());
-            assertEquals("3", rs.getString(1));
-            assertTrue(rs.next());
-            assertEquals("4", rs.getString(1));
-            assertFalse(rs.next());
-        }
-    }
-
-    private Connection getConnection() throws SQLException{
-        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
-        props.put(QueryServices.EXPLAIN_ROW_COUNT_ATTRIB,
-                Boolean.FALSE.toString());
-        props.put(QueryServices.EXPLAIN_CHUNK_COUNT_ATTRIB,
-                Boolean.FALSE.toString());
-        props.put(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB,
-                Boolean.TRUE.toString());
-        return DriverManager.getConnection(getUrl(),props);
-    }
-
-    private void createBaseTable(String tableName, String splits) throws SQLException {
-        Connection conn = getConnection();
-        String ddl = "CREATE TABLE " + tableName + " (t_id VARCHAR NOT NULL,\n" +
-                "k1 INTEGER NOT NULL,\n" +
-                "k2 INTEGER NOT NULL,\n" +
-                "k3 INTEGER,\n" +
-                "v1 VARCHAR,\n" +
-                "CONSTRAINT pk PRIMARY KEY (t_id, k1, k2))\n"
-                        + (splits != null ? (" split on " + splits) : "");
-        conn.createStatement().execute(ddl);
-        conn.close();
-    }
-
-    // Moved from LocalIndexIT because it was causing parallel runs to hang
-    @Test
-    public void testLocalIndexScanAfterRegionSplit() throws Exception {
-        String schemaName = generateRandomString();
-        String tableName = schemaName + "." + generateRandomString();
-        String indexName = "IDX_" + generateRandomString();
-        TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), false);
-        String indexPhysicalTableName = physicalTableName.getNameAsString();
-
-        createBaseTable(tableName, "('e','j','o')");
-        Connection conn1 = getConnection();
-        try{
-            String[] strings = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
-            for (int i = 0; i < 26; i++) {
-                conn1.createStatement().execute(
-                    "UPSERT INTO " + tableName + " values('"+strings[i]+"'," + i + ","
-                            + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')");
-            }
-            conn1.commit();
-            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)");
-            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + "_2 ON " + tableName + "(k3)");
-
-            ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + tableName);
-            assertTrue(rs.next());
-            
-            HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
-            for (int i = 1; i < 5; i++) {
-                admin.split(physicalTableName, ByteUtil.concat(Bytes.toBytes(strings[3*i])));
-                List<HRegionInfo> regionsOfUserTable =
-                        MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
-                                physicalTableName, false);
-
-                while (regionsOfUserTable.size() != (4+i)) {
-                    Thread.sleep(100);
-                    regionsOfUserTable = MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(),
-                            admin.getConnection(), physicalTableName, false);
-                }
-                assertEquals(4+i, regionsOfUserTable.size());
-                String[] tIdColumnValues = new String[26]; 
-                String[] v1ColumnValues = new String[26];
-                int[] k1ColumnValue = new int[26];
-                String query = "SELECT t_id,k1,v1 FROM " + tableName;
-                rs = conn1.createStatement().executeQuery(query);
-                Thread.sleep(1000);
-                for (int j = 0; j < 26; j++) {
-                    assertTrue(rs.next());
-                    tIdColumnValues[j] = rs.getString("t_id");
-                    k1ColumnValue[j] = rs.getInt("k1");
-                    v1ColumnValues[j] = rs.getString("V1");
-                }
-                Arrays.sort(tIdColumnValues);
-                Arrays.sort(v1ColumnValues);
-                Arrays.sort(k1ColumnValue);
-                assertTrue(Arrays.equals(strings, tIdColumnValues));
-                assertTrue(Arrays.equals(strings, v1ColumnValues));
-                for(int m=0;m<26;m++) {
-                    assertEquals(m, k1ColumnValue[m]);
-                }
-
-                rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
-                assertEquals(
-                        "CLIENT PARALLEL " + (4 + i) + "-WAY RANGE SCAN OVER "
-                                + indexPhysicalTableName + " [1]\n"
-                                        + "    SERVER FILTER BY FIRST KEY ONLY\n"
-                                + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
-                
-                query = "SELECT t_id,k1,k3 FROM " + tableName;
-                rs = conn1.createStatement().executeQuery("EXPLAIN "+query);
-                assertEquals(
-                    "CLIENT PARALLEL "
-                            + ((strings[3 * i].compareTo("j") < 0) ? (4 + i) : (4 + i - 1))
-                            + "-WAY RANGE SCAN OVER "
-                            + indexPhysicalTableName + " [2]\n"
-                                    + "    SERVER FILTER BY FIRST KEY ONLY\n"
-                            + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
-                rs = conn1.createStatement().executeQuery(query);
-                Thread.sleep(1000);
-                int[] k3ColumnValue = new int[26];
-                for (int j = 0; j < 26; j++) {
-                    assertTrue(rs.next());
-                    tIdColumnValues[j] = rs.getString("t_id");
-                    k1ColumnValue[j] = rs.getInt("k1");
-                    k3ColumnValue[j] = rs.getInt("k3");
-                }
-                Arrays.sort(tIdColumnValues);
-                Arrays.sort(k1ColumnValue);
-                Arrays.sort(k3ColumnValue);
-                assertTrue(Arrays.equals(strings, tIdColumnValues));
-                for(int m=0;m<26;m++) {
-                    assertEquals(m, k1ColumnValue[m]);
-                    assertEquals(m+2, k3ColumnValue[m]);
-                }
-            }
-       } finally {
-            conn1.close();
-        }
-    }
-
-    // Moved from LocalIndexIT because it was causing parallel runs to hang
-    @Test
-    public void testLocalIndexScanAfterRegionsMerge() throws Exception {
-        String schemaName = generateRandomString();
-        String tableName = schemaName + "." + generateRandomString();
-        String indexName = "IDX_" + generateRandomString();
-        TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), false);
-        String indexPhysicalTableName = physicalTableName.getNameAsString();
-
-        createBaseTable(tableName, "('e','j','o')");
-        Connection conn1 = getConnection();
-        try{
-            String[] strings = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
-            for (int i = 0; i < 26; i++) {
-                conn1.createStatement().execute(
-                    "UPSERT INTO " + tableName + " values('"+strings[i]+"'," + i + ","
-                            + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')");
-            }
-            conn1.commit();
-            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)");
-            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + "_2 ON " + tableName + "(k3)");
-
-            ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + tableName);
-            assertTrue(rs.next());
-
-            HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
-            List<HRegionInfo> regionsOfUserTable =
-                    MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
-                        physicalTableName, false);
-            admin.mergeRegions(regionsOfUserTable.get(0).getEncodedNameAsBytes(),
-                regionsOfUserTable.get(1).getEncodedNameAsBytes(), false);
-            regionsOfUserTable =
-                    MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
-                            physicalTableName, false);
-
-            while (regionsOfUserTable.size() != 3) {
-                Thread.sleep(100);
-                regionsOfUserTable = MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(),
-                        admin.getConnection(), physicalTableName, false);
-            }
-            String query = "SELECT t_id,k1,v1 FROM " + tableName;
-            rs = conn1.createStatement().executeQuery(query);
-            Thread.sleep(1000);
-            for (int j = 0; j < 26; j++) {
-                assertTrue(rs.next());
-                assertEquals(strings[25 - j], rs.getString("t_id"));
-                assertEquals(25 - j, rs.getInt("k1"));
-                assertEquals(strings[j], rs.getString("V1"));
-            }
-            rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
-            assertEquals(
-                "CLIENT PARALLEL " + 3 + "-WAY RANGE SCAN OVER "
-                        + indexPhysicalTableName
-                        + " [1]\n" + "    SERVER FILTER BY FIRST KEY ONLY\n"
-                        + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
-
-            query = "SELECT t_id,k1,k3 FROM " + tableName;
-            rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
-            assertEquals(
-                "CLIENT PARALLEL " + 3 + "-WAY RANGE SCAN OVER "
-                        + indexPhysicalTableName
-                        + " [2]\n" + "    SERVER FILTER BY FIRST KEY ONLY\n"
-                        + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
-
-            rs = conn1.createStatement().executeQuery(query);
-            Thread.sleep(1000);
-            for (int j = 0; j < 26; j++) {
-                assertTrue(rs.next());
-                assertEquals(strings[j], rs.getString("t_id"));
-                assertEquals(j, rs.getInt("k1"));
-                assertEquals(j + 2, rs.getInt("k3"));
-            }
-       } finally {
-            conn1.close();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
index cbd1472..e1eac48 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
@@ -51,7 +51,6 @@ import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
-import org.apache.phoenix.jdbc.PhoenixResultSet;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
@@ -146,13 +145,14 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
             rs = conn.createStatement().executeQuery(selectSql);
             TestUtil.validateRowKeyColumns(rs, 1);
             TestUtil.validateRowKeyColumns(rs, 2);
-            Long currentTx = rs.unwrap(PhoenixResultSet.class).getCurrentRow().getValue(0).getTimestamp();
+            // Long currentTx = rs.unwrap(PhoenixResultSet.class).getCurrentRow().getValue(0).getTimestamp();
             assertFalse(rs.next());
             
             conn.close();
             // start new connection
-            conn.createStatement().executeQuery(selectSql);
-            assertFalse("This transaction should not be on the invalid transactions", txManager.getCurrentState().getInvalid().contains(currentTx));
+            // conn.createStatement().executeQuery(selectSql);
+            // assertFalse("This transaction should not be on the invalid transactions",
+            // txManager.getCurrentState().getInvalid().contains(currentTx));
         }
     }
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
index a28ef3b..57df138 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
@@ -137,7 +137,6 @@ import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
-import org.apache.phoenix.jdbc.PhoenixDriver;
 import org.apache.phoenix.jdbc.PhoenixEmbeddedDriver;
 import org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo;
 import org.apache.phoenix.jdbc.PhoenixTestDriver;
@@ -491,7 +490,6 @@ public abstract class BaseTest {
     
     protected static String url;
     protected static PhoenixTestDriver driver;
-    protected static PhoenixDriver realDriver;
     protected static boolean clusterInitialized = false;
     private static HBaseTestingUtility utility;
     protected static final Configuration config = HBaseConfiguration.create(); 
@@ -574,13 +572,6 @@ public abstract class BaseTest {
                 driver = null;
             }
         }
-        if (realDriver != null) {
-            try {
-                assertTrue(destroyDriver(realDriver));
-            } finally {
-                realDriver = null;
-            }
-        }
         teardownTxManager();
     }
     
@@ -625,27 +616,6 @@ public abstract class BaseTest {
         }
     }
     
-    protected static void setUpRealDriver(ReadOnlyProps serverProps, ReadOnlyProps clientProps) throws Exception {
-        if (!clusterInitialized) {
-            setUpConfigForMiniCluster(config, serverProps);
-            utility = new HBaseTestingUtility(config);
-            try {
-                utility.startMiniCluster(NUM_SLAVES_BASE);
-                utility.startMiniMapReduceCluster();
-                url = QueryUtil.getConnectionUrl(new Properties(), utility.getConfiguration());
-            } catch (Throwable t) {
-                throw new RuntimeException(t);
-            }
-            clusterInitialized = true;
-        }
-        Class.forName(PhoenixDriver.class.getName());
-        realDriver = PhoenixDriver.INSTANCE;
-        DriverManager.registerDriver(realDriver);
-        if (clientProps.getBoolean(QueryServices.TRANSACTIONS_ENABLED, QueryServicesOptions.DEFAULT_TRANSACTIONS_ENABLED)) {
-            setupTxManager();
-        }
-    }
-
     private static boolean isDistributedClusterModeEnabled(Configuration conf) {
         boolean isDistributedCluster = false;
         //check if the distributed mode was specified as a system property.


[26/47] phoenix git commit: PHOENIX-3072 Deadlock on region opening with secondary index recovery (Enis Soztutar)

Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/2c2b552c/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index 607ad5e..767a600 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -39,6 +39,7 @@ import java.lang.ref.WeakReference;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -85,6 +86,7 @@ import org.apache.hadoop.hbase.client.coprocessor.Batch;
 import org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.hbase.ipc.BlockingRpcCallback;
+import org.apache.hadoop.hbase.ipc.PhoenixRpcSchedulerFactory;
 import org.apache.hadoop.hbase.ipc.ServerRpcController;
 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto;
 import org.apache.hadoop.hbase.regionserver.IndexHalfStoreFileReaderGenerator;
@@ -256,7 +258,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
     // setting this member variable guarded by "connectionCountLock"
     private volatile ConcurrentMap<SequenceKey,Sequence> sequenceMap = Maps.newConcurrentMap();
     private KeyValueBuilder kvBuilder;
-    
+
     private final int renewLeaseTaskFrequency;
     private final int renewLeasePoolSize;
     private final int renewLeaseThreshold;
@@ -268,7 +270,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
     private static interface FeatureSupported {
         boolean isSupported(ConnectionQueryServices services);
     }
-    
+
     private final Map<Feature, FeatureSupported> featureMap = ImmutableMap.<Feature, FeatureSupported>of(
             Feature.LOCAL_INDEX, new FeatureSupported() {
                 @Override
@@ -284,11 +286,11 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                     return hbaseVersion >= PhoenixDatabaseMetaData.MIN_RENEW_LEASE_VERSION;
                 }
             });
-    
+
     private PMetaData newEmptyMetaData() {
         return new PSynchronizedMetaData(new PMetaDataImpl(INITIAL_META_DATA_TABLE_CAPACITY, getProps()));
     }
-    
+
     /**
      * Construct a ConnectionQueryServicesImpl that represents a connection to an HBase
      * cluster.
@@ -346,7 +348,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
     public TransactionSystemClient getTransactionSystemClient() {
         return txServiceClient;
     }
-    
+
     private void initTxServiceClient() {
         String zkQuorumServersString = this.getProps().get(TxConstants.Service.CFG_DATA_TX_ZOOKEEPER_QUORUM);
         if (zkQuorumServersString==null) {
@@ -354,13 +356,13 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         }
 
         int timeOut = props.getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT);
-        // Create instance of the tephra zookeeper client 
+        // Create instance of the tephra zookeeper client
         ZKClientService tephraZKClientService = new TephraZKClientService(zkQuorumServersString, timeOut, null, ArrayListMultimap.<String, byte[]>create());
-        
+
         ZKClientService zkClientService = ZKClientServices.delegate(
-                  ZKClients.reWatchOnExpire(
-                         ZKClients.retryOnFailure(tephraZKClientService, RetryStrategies.exponentialDelay(500, 2000, TimeUnit.MILLISECONDS))
-                  )
+                ZKClients.reWatchOnExpire(
+                        ZKClients.retryOnFailure(tephraZKClientService, RetryStrategies.exponentialDelay(500, 2000, TimeUnit.MILLISECONDS))
+                        )
                 );
         zkClientService.startAndWait();
         ZKDiscoveryService zkDiscoveryService = new ZKDiscoveryService(zkClientService);
@@ -368,7 +370,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                 config, zkDiscoveryService);
         this.txServiceClient = new TransactionServiceClient(config,pooledClientProvider);
     }
-    
+
     private void openConnection() throws SQLException {
         try {
             boolean transactionsEnabled = props.getBoolean(
@@ -381,7 +383,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             this.connection = HBaseFactoryProvider.getHConnectionFactory().createConnection(this.config);
         } catch (IOException e) {
             throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_ESTABLISH_CONNECTION)
-                .setRootCause(e).build().buildException();
+            .setRootCause(e).build().buildException();
         }
         if (this.connection.isClosed()) { // TODO: why the heck doesn't this throw above?
             throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_ESTABLISH_CONNECTION).build().buildException();
@@ -395,7 +397,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         } catch (org.apache.hadoop.hbase.TableNotFoundException e) {
             throw new TableNotFoundException(SchemaUtil.getSchemaNameFromFullName(tableName), SchemaUtil.getTableNameFromFullName(tableName));
         } catch (IOException e) {
-        	throw new SQLException(e);
+            throw new SQLException(e);
         }
     }
 
@@ -405,11 +407,11 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         try {
             return htable.getTableDescriptor();
         } catch (IOException e) {
-            if(e instanceof org.apache.hadoop.hbase.TableNotFoundException ||
-                e.getCause() instanceof org.apache.hadoop.hbase.TableNotFoundException) {
-              byte[][] schemaAndTableName = new byte[2][];
-              SchemaUtil.getVarChars(tableName, schemaAndTableName);
-              throw new TableNotFoundException(Bytes.toString(schemaAndTableName[0]), Bytes.toString(schemaAndTableName[1]));
+            if(e instanceof org.apache.hadoop.hbase.TableNotFoundException
+                    || e.getCause() instanceof org.apache.hadoop.hbase.TableNotFoundException) {
+                byte[][] schemaAndTableName = new byte[2][];
+                SchemaUtil.getVarChars(tableName, schemaAndTableName);
+                throw new TableNotFoundException(Bytes.toString(schemaAndTableName[0]), Bytes.toString(schemaAndTableName[1]));
             }
             throw new RuntimeException(e);
         } finally {
@@ -522,10 +524,10 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                 List<HRegionLocation> locations = Lists.newArrayList();
                 byte[] currentKey = HConstants.EMPTY_START_ROW;
                 do {
-                  HRegionLocation regionLocation = connection.getRegionLocation(
-                      TableName.valueOf(tableName), currentKey, reload);
-                  locations.add(regionLocation);
-                  currentKey = regionLocation.getRegionInfo().getEndKey();
+                    HRegionLocation regionLocation = connection.getRegionLocation(
+                            TableName.valueOf(tableName), currentKey, reload);
+                    locations.add(regionLocation);
+                    currentKey = regionLocation.getRegionInfo().getEndKey();
                 } while (!Bytes.equals(currentKey, HConstants.EMPTY_END_ROW));
                 return locations;
             } catch (org.apache.hadoop.hbase.TableNotFoundException e) {
@@ -537,7 +539,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                     continue;
                 }
                 throw new SQLExceptionInfo.Builder(SQLExceptionCode.GET_TABLE_REGIONS_FAIL)
-                    .setRootCause(e).build().buildException();
+                .setRootCause(e).build().buildException();
             }
         }
     }
@@ -558,7 +560,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             latestMetaDataLock.notifyAll();
         }
     }
-    
+
     @Override
     public void updateResolvedTimestamp(PTable table, long resolvedTime) throws SQLException {
         synchronized (latestMetaDataLock) {
@@ -615,22 +617,22 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                     // restore the interrupt status
                     Thread.currentThread().interrupt();
                     throw new SQLExceptionInfo.Builder(SQLExceptionCode.INTERRUPTED_EXCEPTION)
-                        .setRootCause(e).build().buildException(); // FIXME
+                    .setRootCause(e).build().buildException(); // FIXME
                 }
             }
             latestMetaData = metaData;
             latestMetaDataLock.notifyAll();
             return metaData;
         }
-     }
+    }
 
-	@Override
+    @Override
     public void addColumn(final PName tenantId, final String tableName, final List<PColumn> columns,
             final long tableTimeStamp, final long tableSeqNum, final boolean isImmutableRows,
             final boolean isWalDisabled, final boolean isMultitenant, final boolean storeNulls,
             final boolean isTransactional, final long updateCacheFrequency, final boolean isNamespaceMapped,
             final long resolvedTime) throws SQLException {
-	    metaDataMutated(tenantId, tableName, tableSeqNum, new Mutator() {
+        metaDataMutated(tenantId, tableName, tableSeqNum, new Mutator() {
             @Override
             public void mutate(PMetaData metaData) throws SQLException {
                 try {
@@ -642,7 +644,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                 }
             }
         });
-     }
+    }
 
     @Override
     public void removeTable(PName tenantId, final String tableName, String parentTableName, long tableTimeStamp) throws SQLException {
@@ -683,7 +685,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         if (tableType != PTableType.VIEW) {
             if(props.get(QueryServices.DEFAULT_KEEP_DELETED_CELLS_ATTRIB) != null){
                 columnDesc.setKeepDeletedCells(props.getBoolean(
-                    QueryServices.DEFAULT_KEEP_DELETED_CELLS_ATTRIB, QueryServicesOptions.DEFAULT_KEEP_DELETED_CELLS));
+                        QueryServices.DEFAULT_KEEP_DELETED_CELLS_ATTRIB, QueryServicesOptions.DEFAULT_KEEP_DELETED_CELLS));
             }
             columnDesc.setDataBlockEncoding(SchemaUtil.DEFAULT_DATA_BLOCK_ENCODING);
             for (Entry<String,Object> entry : family.getSecond().entrySet()) {
@@ -694,7 +696,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         }
         return columnDesc;
     }
-    
+
     // Workaround HBASE-14737
     private static void setHColumnDescriptorValue(HColumnDescriptor columnDesc, String key, Object value) {
         if (HConstants.VERSIONS.equals(key)) {
@@ -717,7 +719,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         }
         return Integer.parseInt(stringValue);
     }
-    
+
     private void modifyColumnFamilyDescriptor(HColumnDescriptor hcd, Map<String,Object> props) throws SQLException {
         for (Entry<String, Object> entry : props.entrySet()) {
             String propName = entry.getKey();
@@ -725,14 +727,14 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             setHColumnDescriptorValue(hcd, propName, value);
         }
     }
-    
+
     private HTableDescriptor generateTableDescriptor(byte[] tableName, HTableDescriptor existingDesc,
             PTableType tableType, Map<String, Object> tableProps, List<Pair<byte[], Map<String, Object>>> families,
             byte[][] splits, boolean isNamespaceMapped) throws SQLException {
         String defaultFamilyName = (String)tableProps.remove(PhoenixDatabaseMetaData.DEFAULT_COLUMN_FAMILY_NAME);
         HTableDescriptor tableDescriptor = (existingDesc != null) ? new HTableDescriptor(existingDesc)
-                : new HTableDescriptor(
-                        SchemaUtil.getPhysicalHBaseTableName(tableName, isNamespaceMapped, tableType).getBytes());
+        : new HTableDescriptor(
+                SchemaUtil.getPhysicalHBaseTableName(tableName, isNamespaceMapped, tableType).getBytes());
         for (Entry<String,Object> entry : tableProps.entrySet()) {
             String key = entry.getKey();
             if (!TableProperty.isPhoenixTableProperty(key)) {
@@ -774,9 +776,31 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             }
         }
         addCoprocessors(tableName, tableDescriptor, tableType, tableProps);
+
+        // PHOENIX-3072: Set index priority if this is a system table or index table
+        if (tableType == PTableType.SYSTEM) {
+            tableDescriptor.setValue(QueryConstants.PRIORITY,
+                    String.valueOf(PhoenixRpcSchedulerFactory.getMetadataPriority(config)));
+        } else if (tableType == PTableType.INDEX // Global, mutable index
+                && !isLocalIndexTable(tableDescriptor.getFamiliesKeys())
+                && !Boolean.TRUE.equals(tableProps.get(PhoenixDatabaseMetaData.IMMUTABLE_ROWS))) {
+            tableDescriptor.setValue(QueryConstants.PRIORITY,
+                    String.valueOf(PhoenixRpcSchedulerFactory.getIndexPriority(config)));
+        }
         return tableDescriptor;
     }
 
+    private boolean isLocalIndexTable(Collection<byte[]> families) {
+        // no easier way to know local index table?
+        for (byte[] family: families) {
+            if (Bytes.toString(family).startsWith(QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    
     private void addCoprocessors(byte[] tableName, HTableDescriptor descriptor, PTableType tableType, Map<String,Object> tableProps) throws SQLException {
         // The phoenix jar must be available on HBase classpath
         int priority = props.getInt(QueryServices.COPROCESSOR_PRIORITY_ATTRIB, QueryServicesOptions.DEFAULT_COPROCESSOR_PRIORITY);
@@ -793,7 +817,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             if (!descriptor.hasCoprocessor(ServerCachingEndpointImpl.class.getName())) {
                 descriptor.addCoprocessor(ServerCachingEndpointImpl.class.getName(), null, priority, null);
             }
-            boolean isTransactional = 
+            boolean isTransactional =
                     Boolean.TRUE.equals(tableProps.get(TableProperty.TRANSACTIONAL.name())) ||
                     Boolean.TRUE.equals(tableProps.get(TxConstants.READ_NON_TX_DATA)); // For ALTER TABLE
             // TODO: better encapsulation for this
@@ -833,7 +857,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                 if(Bytes.toString(family).startsWith(QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX)) {
                     if (!descriptor.hasCoprocessor(IndexHalfStoreFileReaderGenerator.class.getName())) {
                         descriptor.addCoprocessor(IndexHalfStoreFileReaderGenerator.class.getName(),
-                            null, priority, null);
+                                null, priority, null);
                         break;
                     }
                 }
@@ -855,7 +879,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                     descriptor.addCoprocessor(SequenceRegionObserver.class.getName(), null, priority, null);
                 }
             }
-            
+
             if (isTransactional) {
                 if (!descriptor.hasCoprocessor(PhoenixTransactionalProcessor.class.getName())) {
                     descriptor.addCoprocessor(PhoenixTransactionalProcessor.class.getName(), null, priority - 10, null);
@@ -864,7 +888,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                 // If exception on alter table to transition back to non transactional
                 if (descriptor.hasCoprocessor(PhoenixTransactionalProcessor.class.getName())) {
                     descriptor.removeCoprocessor(PhoenixTransactionalProcessor.class.getName());
-                }                
+                }
             }
         } catch (IOException e) {
             throw ServerUtil.parseServerException(e);
@@ -982,7 +1006,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         SQLException sqlE = null;
         HTableDescriptor existingDesc = null;
         boolean isMetaTable = SchemaUtil.isMetaTable(tableName);
-        byte[] physicalTable = SchemaUtil.getPhysicalHBaseTableName(tableName, isNamespaceMapped, tableType).getBytes(); 
+        byte[] physicalTable = SchemaUtil.getPhysicalHBaseTableName(tableName, isNamespaceMapped, tableType).getBytes();
         boolean tableExist = true;
         try (HBaseAdmin admin = getAdmin()) {
             final String quorum = ZKConfig.getZKQuorumServersString(config);
@@ -1006,7 +1030,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
 
             if (!tableExist) {
                 if (newDesc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES) != null && Boolean.TRUE.equals(
-                    PBoolean.INSTANCE.toObject(newDesc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) {
+                        PBoolean.INSTANCE.toObject(newDesc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) {
                     newDesc.setValue(HTableDescriptor.SPLIT_POLICY, IndexRegionSplitPolicy.class.getName());
                 }
                 // Remove the splitPolicy attribute to prevent HBASE-12570
@@ -1048,12 +1072,12 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                 } else {
                     for(Pair<byte[],Map<String,Object>> family: families) {
                         if ((newDesc.getValue(HTableDescriptor.SPLIT_POLICY)==null || !newDesc.getValue(HTableDescriptor.SPLIT_POLICY).equals(
-                            IndexRegionSplitPolicy.class.getName()))
+                                IndexRegionSplitPolicy.class.getName()))
                                 && Bytes.toString(family.getFirst()).startsWith(
-                                    QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX)) {
-                                   newDesc.setValue(HTableDescriptor.SPLIT_POLICY, IndexRegionSplitPolicy.class.getName());
-                                   break;
-                           }
+                                        QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX)) {
+                            newDesc.setValue(HTableDescriptor.SPLIT_POLICY, IndexRegionSplitPolicy.class.getName());
+                            break;
+                        }
                     }
                 }
 
@@ -1103,17 +1127,17 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
     private void modifyTable(byte[] tableName, HTableDescriptor newDesc, boolean shouldPoll) throws IOException,
     InterruptedException, TimeoutException, SQLException {
         try (HBaseAdmin admin = getAdmin()) {
-    		if (!allowOnlineTableSchemaUpdate()) {
-    			admin.disableTable(tableName);
-    			admin.modifyTable(tableName, newDesc);
-    			admin.enableTable(tableName);
-    		} else {
-    			admin.modifyTable(tableName, newDesc);
-    			if (shouldPoll) {
-    			    pollForUpdatedTableDescriptor(admin, newDesc, tableName);
-    			}
-    		}
-    	}
+            if (!allowOnlineTableSchemaUpdate()) {
+                admin.disableTable(tableName);
+                admin.modifyTable(tableName, newDesc);
+                admin.enableTable(tableName);
+            } else {
+                admin.modifyTable(tableName, newDesc);
+                if (shouldPoll) {
+                    pollForUpdatedTableDescriptor(admin, newDesc, tableName);
+                }
+            }
+        }
     }
 
     private static boolean hasIndexWALCodec(Long serverVersion) {
@@ -1186,18 +1210,18 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             if (isTableNamespaceMappingEnabled != SchemaUtil.isNamespaceMappingEnabled(PTableType.TABLE,
                     getProps())) { throw new SQLExceptionInfo.Builder(
                             SQLExceptionCode.INCONSISTENET_NAMESPACE_MAPPING_PROPERTIES)
-                                    .setMessage(
-                                            "Ensure that config " + QueryServices.IS_NAMESPACE_MAPPING_ENABLED
-                                                    + " is consitent on client and server.")
-                                    .build().buildException(); }
+                    .setMessage(
+                            "Ensure that config " + QueryServices.IS_NAMESPACE_MAPPING_ENABLED
+                            + " is consitent on client and server.")
+                            .build().buildException(); }
             lowestClusterHBaseVersion = minHBaseVersion;
         } catch (SQLException e) {
             throw e;
         } catch (Throwable t) {
             // This is the case if the "phoenix.jar" is not on the classpath of HBase on the region server
             throw new SQLExceptionInfo.Builder(SQLExceptionCode.INCOMPATIBLE_CLIENT_SERVER_JAR).setRootCause(t)
-                .setMessage("Ensure that " + QueryConstants.DEFAULT_COPROCESS_PATH + " is put on the classpath of HBase in every region server: " + t.getMessage())
-                .build().buildException();
+            .setMessage("Ensure that " + QueryConstants.DEFAULT_COPROCESS_PATH + " is put on the classpath of HBase in every region server: " + t.getMessage())
+            .build().buildException();
         } finally {
             if (ht != null) {
                 try {
@@ -1221,12 +1245,13 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             Batch.Call<MetaDataService, MetaDataResponse> callable) throws SQLException {
         return metaDataCoprocessorExec(tableKey, callable, PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
     }
-        /**
-         * Invoke meta data coprocessor with one retry if the key was found to not be in the regions
-         * (due to a table split)
-         */
-        private MetaDataMutationResult metaDataCoprocessorExec(byte[] tableKey,
-                Batch.Call<MetaDataService, MetaDataResponse> callable, byte[] tableName) throws SQLException {
+
+    /**
+     * Invoke meta data coprocessor with one retry if the key was found to not be in the regions
+     * (due to a table split)
+     */
+    private MetaDataMutationResult metaDataCoprocessorExec(byte[] tableKey,
+            Batch.Call<MetaDataService, MetaDataResponse> callable, byte[] tableName) throws SQLException {
 
         try {
             boolean retried = false;
@@ -1266,10 +1291,6 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
     private void ensureViewIndexTableCreated(byte[] physicalTableName, Map<String, Object> tableProps,
             List<Pair<byte[], Map<String, Object>>> families, byte[][] splits, long timestamp,
             boolean isNamespaceMapped) throws SQLException {
-        Long maxFileSize = (Long)tableProps.get(HTableDescriptor.MAX_FILESIZE);
-        if (maxFileSize == null) {
-            maxFileSize = this.props.getLong(HConstants.HREGION_MAX_FILESIZE, HConstants.DEFAULT_MAX_FILE_SIZE);
-        }
         byte[] physicalIndexName = MetaDataUtil.getViewIndexPhysicalName(physicalTableName);
 
         tableProps.put(MetaDataUtil.IS_VIEW_INDEX_TABLE_PROP_NAME, TRUE_BYTES_AS_STRING);
@@ -1327,11 +1348,11 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                     for(HColumnDescriptor cf : desc.getColumnFamilies()) {
                         if(cf.getNameAsString().startsWith(QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX)) {
                             columnFamiles.add(cf.getNameAsString());
-                        }  
+                        }
                     }
                     for(String cf: columnFamiles) {
                         admin.deleteColumn(physicalTableName, cf);
-                    }  
+                    }
                     clearTableRegionCache(physicalTableName);
                     wasDeleted = true;
                 }
@@ -1359,10 +1380,10 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         byte[] tableName = physicalTableName != null ? physicalTableName : SchemaUtil.getTableNameAsBytes(schemaBytes, tableBytes);
         boolean localIndexTable = false;
         for(Pair<byte[], Map<String, Object>> family: families) {
-               if(Bytes.toString(family.getFirst()).startsWith(QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX)) {
-                       localIndexTable = true;
-                       break;
-               }
+            if(Bytes.toString(family.getFirst()).startsWith(QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX)) {
+                localIndexTable = true;
+                break;
+            }
         }
         if ((tableType == PTableType.VIEW && physicalTableName != null) || (tableType != PTableType.VIEW && (physicalTableName == null || localIndexTable))) {
             // For views this will ensure that metadata already exists
@@ -1401,30 +1422,30 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             ensureViewIndexTableCreated(
                     SchemaUtil.getPhysicalHBaseTableName(tableName, isNamespaceMapped, tableType).getBytes(),
                     tableProps, familiesPlusDefault, MetaDataUtil.isSalted(m, kvBuilder, ptr) ? splits : null,
-                    MetaDataUtil.getClientTimeStamp(m), isNamespaceMapped);
+                            MetaDataUtil.getClientTimeStamp(m), isNamespaceMapped);
         }
 
         byte[] tableKey = SchemaUtil.getTableKey(tenantIdBytes, schemaBytes, tableBytes);
         MetaDataMutationResult result = metaDataCoprocessorExec(tableKey,
-            new Batch.Call<MetaDataService, MetaDataResponse>() {
+                new Batch.Call<MetaDataService, MetaDataResponse>() {
             @Override
-                    public MetaDataResponse call(MetaDataService instance) throws IOException {
-                        ServerRpcController controller = new ServerRpcController();
-                        BlockingRpcCallback<MetaDataResponse> rpcCallback =
-                                new BlockingRpcCallback<MetaDataResponse>();
-                        CreateTableRequest.Builder builder = CreateTableRequest.newBuilder();
-                        for (Mutation m : tableMetaData) {
-                            MutationProto mp = ProtobufUtil.toProto(m);
-                            builder.addTableMetadataMutations(mp.toByteString());
-                        }
-                        builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
-                        CreateTableRequest build = builder.build();
-						instance.createTable(controller, build, rpcCallback);
-                        if(controller.getFailedOn() != null) {
-                            throw controller.getFailedOn();
-                        }
-                        return rpcCallback.get();
-                    }
+            public MetaDataResponse call(MetaDataService instance) throws IOException {
+                ServerRpcController controller = new ServerRpcController();
+                BlockingRpcCallback<MetaDataResponse> rpcCallback =
+                        new BlockingRpcCallback<MetaDataResponse>();
+                CreateTableRequest.Builder builder = CreateTableRequest.newBuilder();
+                for (Mutation m : tableMetaData) {
+                    MutationProto mp = ProtobufUtil.toProto(m);
+                    builder.addTableMetadataMutations(mp.toByteString());
+                }
+                builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
+                CreateTableRequest build = builder.build();
+                instance.createTable(controller, build, rpcCallback);
+                if(controller.getFailedOn() != null) {
+                    throw controller.getFailedOn();
+                }
+                return rpcCallback.get();
+            }
         });
         return result;
     }
@@ -1435,26 +1456,26 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         final byte[] tenantIdBytes = tenantId == null ? ByteUtil.EMPTY_BYTE_ARRAY : tenantId.getBytes();
         byte[] tableKey = SchemaUtil.getTableKey(tenantIdBytes, schemaBytes, tableBytes);
         return metaDataCoprocessorExec(tableKey,
-            new Batch.Call<MetaDataService, MetaDataResponse>() {
-                @Override
-                public MetaDataResponse call(MetaDataService instance) throws IOException {
-                    ServerRpcController controller = new ServerRpcController();
-                    BlockingRpcCallback<MetaDataResponse> rpcCallback =
-                            new BlockingRpcCallback<MetaDataResponse>();
-                    GetTableRequest.Builder builder = GetTableRequest.newBuilder();
-                    builder.setTenantId(ByteStringer.wrap(tenantIdBytes));
-                    builder.setSchemaName(ByteStringer.wrap(schemaBytes));
-                    builder.setTableName(ByteStringer.wrap(tableBytes));
-                    builder.setTableTimestamp(tableTimestamp);
-                    builder.setClientTimestamp(clientTimestamp);
-                    builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
-                    instance.getTable(controller, builder.build(), rpcCallback);
-                    if(controller.getFailedOn() != null) {
-                        throw controller.getFailedOn();
-                    }
-                    return rpcCallback.get();
+                new Batch.Call<MetaDataService, MetaDataResponse>() {
+            @Override
+            public MetaDataResponse call(MetaDataService instance) throws IOException {
+                ServerRpcController controller = new ServerRpcController();
+                BlockingRpcCallback<MetaDataResponse> rpcCallback =
+                        new BlockingRpcCallback<MetaDataResponse>();
+                GetTableRequest.Builder builder = GetTableRequest.newBuilder();
+                builder.setTenantId(ByteStringer.wrap(tenantIdBytes));
+                builder.setSchemaName(ByteStringer.wrap(schemaBytes));
+                builder.setTableName(ByteStringer.wrap(tableBytes));
+                builder.setTableTimestamp(tableTimestamp);
+                builder.setClientTimestamp(clientTimestamp);
+                builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
+                instance.getTable(controller, builder.build(), rpcCallback);
+                if(controller.getFailedOn() != null) {
+                    throw controller.getFailedOn();
                 }
-            });
+                return rpcCallback.get();
+            }
+        });
     }
 
     @Override
@@ -1468,26 +1489,26 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         byte[] tableKey = SchemaUtil.getTableKey(tenantIdBytes == null ? ByteUtil.EMPTY_BYTE_ARRAY : tenantIdBytes, schemaBytes, tableBytes);
         final MetaDataMutationResult result =  metaDataCoprocessorExec(tableKey,
                 new Batch.Call<MetaDataService, MetaDataResponse>() {
-                    @Override
-                    public MetaDataResponse call(MetaDataService instance) throws IOException {
-                        ServerRpcController controller = new ServerRpcController();
-                        BlockingRpcCallback<MetaDataResponse> rpcCallback =
-                                new BlockingRpcCallback<MetaDataResponse>();
-                        DropTableRequest.Builder builder = DropTableRequest.newBuilder();
-                        for (Mutation m : tableMetaData) {
-                            MutationProto mp = ProtobufUtil.toProto(m);
-                            builder.addTableMetadataMutations(mp.toByteString());
-                        }
-                        builder.setTableType(tableType.getSerializedValue());
-                        builder.setCascade(cascade);
-                        builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
-                        instance.dropTable(controller, builder.build(), rpcCallback);
-                        if(controller.getFailedOn() != null) {
-                            throw controller.getFailedOn();
-                        }
-                        return rpcCallback.get();
-                    }
-                });
+            @Override
+            public MetaDataResponse call(MetaDataService instance) throws IOException {
+                ServerRpcController controller = new ServerRpcController();
+                BlockingRpcCallback<MetaDataResponse> rpcCallback =
+                        new BlockingRpcCallback<MetaDataResponse>();
+                DropTableRequest.Builder builder = DropTableRequest.newBuilder();
+                for (Mutation m : tableMetaData) {
+                    MutationProto mp = ProtobufUtil.toProto(m);
+                    builder.addTableMetadataMutations(mp.toByteString());
+                }
+                builder.setTableType(tableType.getSerializedValue());
+                builder.setCascade(cascade);
+                builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
+                instance.dropTable(controller, builder.build(), rpcCallback);
+                if(controller.getFailedOn() != null) {
+                    throw controller.getFailedOn();
+                }
+                return rpcCallback.get();
+            }
+        });
 
         final MutationCode code = result.getMutationCode();
         switch(code) {
@@ -1511,7 +1532,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         default:
             break;
         }
-          return result;
+        return result;
     }
 
     /*
@@ -1541,28 +1562,28 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         byte[] tenantIdBytes = rowKeyMetadata[PhoenixDatabaseMetaData.TENANT_ID_INDEX];
         byte[] functionBytes = rowKeyMetadata[PhoenixDatabaseMetaData.FUNTION_NAME_INDEX];
         byte[] functionKey = SchemaUtil.getFunctionKey(tenantIdBytes, functionBytes);
-        
+
         final MetaDataMutationResult result =  metaDataCoprocessorExec(functionKey,
                 new Batch.Call<MetaDataService, MetaDataResponse>() {
-                    @Override
-                    public MetaDataResponse call(MetaDataService instance) throws IOException {
-                        ServerRpcController controller = new ServerRpcController();
-                        BlockingRpcCallback<MetaDataResponse> rpcCallback =
-                                new BlockingRpcCallback<MetaDataResponse>();
-                        DropFunctionRequest.Builder builder = DropFunctionRequest.newBuilder();
-                        for (Mutation m : functionData) {
-                            MutationProto mp = ProtobufUtil.toProto(m);
-                            builder.addTableMetadataMutations(mp.toByteString());
-                        }
-                        builder.setIfExists(ifExists);
-                        builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
-                        instance.dropFunction(controller, builder.build(), rpcCallback);
-                        if(controller.getFailedOn() != null) {
-                            throw controller.getFailedOn();
-                        }
-                        return rpcCallback.get();
-                    }
-                }, PhoenixDatabaseMetaData.SYSTEM_FUNCTION_NAME_BYTES);
+            @Override
+            public MetaDataResponse call(MetaDataService instance) throws IOException {
+                ServerRpcController controller = new ServerRpcController();
+                BlockingRpcCallback<MetaDataResponse> rpcCallback =
+                        new BlockingRpcCallback<MetaDataResponse>();
+                DropFunctionRequest.Builder builder = DropFunctionRequest.newBuilder();
+                for (Mutation m : functionData) {
+                    MutationProto mp = ProtobufUtil.toProto(m);
+                    builder.addTableMetadataMutations(mp.toByteString());
+                }
+                builder.setIfExists(ifExists);
+                builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
+                instance.dropFunction(controller, builder.build(), rpcCallback);
+                if(controller.getFailedOn() != null) {
+                    throw controller.getFailedOn();
+                }
+                return rpcCallback.get();
+            }
+        }, PhoenixDatabaseMetaData.SYSTEM_FUNCTION_NAME_BYTES);
         return result;
     }
 
@@ -1612,7 +1633,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         String name = Bytes
                 .toString(SchemaUtil.getParentTableNameFromIndexTable(physicalIndexTableName,
                         MetaDataUtil.VIEW_INDEX_TABLE_PREFIX))
-                .replace(QueryConstants.NAMESPACE_SEPARATOR, QueryConstants.NAME_SEPARATOR);
+                        .replace(QueryConstants.NAMESPACE_SEPARATOR, QueryConstants.NAME_SEPARATOR);
         PTable table = getTable(tenantId, name, timestamp);
         ensureViewIndexTableCreated(table, timestamp, isNamespaceMapped);
     }
@@ -1624,7 +1645,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             throwConnectionClosedIfNullMetaData();
             table = metadata.getTableRef(new PTableKey(tenantId, fullTableName)).getTable();
             if (table.getTimeStamp() >= timestamp) { // Table in cache is newer than client timestamp which shouldn't be
-                                                     // the case
+                // the case
                 throw new TableNotFoundException(table.getSchemaName().getString(), table.getTableName().getString());
             }
         } catch (TableNotFoundException e) {
@@ -1638,8 +1659,8 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         return table;
     }
 
-	private void ensureViewIndexTableCreated(PTable table, long timestamp, boolean isNamespaceMapped)
-			throws SQLException {
+    private void ensureViewIndexTableCreated(PTable table, long timestamp, boolean isNamespaceMapped)
+            throws SQLException {
         byte[] physicalTableName = table.getPhysicalName().getBytes();
         HTableDescriptor htableDesc = this.getTableDescriptor(physicalTableName);
         Map<String,Object> tableProps = createPropertiesMap(htableDesc.getValues());
@@ -1663,13 +1684,17 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             splits = SaltingUtil.getSalteByteSplitPoints(table.getBucketNum());
         }
 
+        // Transfer over table values into tableProps
+        // TODO: encapsulate better
+        tableProps.put(PhoenixDatabaseMetaData.TRANSACTIONAL, table.isTransactional());
+        tableProps.put(PhoenixDatabaseMetaData.IMMUTABLE_ROWS, table.isImmutableRows());
         ensureViewIndexTableCreated(physicalTableName, tableProps, families, splits, timestamp, isNamespaceMapped);
     }
-    
+
     @Override
     public MetaDataMutationResult addColumn(final List<Mutation> tableMetaData, PTable table, Map<String, List<Pair<String,Object>>> stmtProperties, Set<String> colFamiliesForPColumnsToBeAdded) throws SQLException {
-    	List<Pair<byte[], Map<String, Object>>> families = new ArrayList<>(stmtProperties.size());
-    	Map<String, Object> tableProps = new HashMap<String, Object>();
+        List<Pair<byte[], Map<String, Object>>> families = new ArrayList<>(stmtProperties.size());
+        Map<String, Object> tableProps = new HashMap<String, Object>();
         Set<HTableDescriptor> tableDescriptors = Collections.emptySet();
         Set<HTableDescriptor> origTableDescriptors = Collections.emptySet();
         boolean nonTxToTx = false;
@@ -1690,7 +1715,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                 updateDescriptorForTx(table, tableProps, tableDescriptor, Boolean.TRUE.toString(), tableDescriptors, origTableDescriptors);
             }
         }
-        
+
         boolean success = false;
         boolean metaDataUpdated = !tableDescriptors.isEmpty();
         boolean pollingNeeded = !(!tableProps.isEmpty() && families.isEmpty() && colFamiliesForPColumnsToBeAdded.isEmpty());
@@ -1700,13 +1725,13 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             if (table.getType() == PTableType.VIEW) {
                 boolean canViewsAddNewCF = props.getBoolean(QueryServices.ALLOW_VIEWS_ADD_NEW_CF_BASE_TABLE,
                         QueryServicesOptions.DEFAULT_ALLOW_VIEWS_ADD_NEW_CF_BASE_TABLE);
-                // When adding a column to a view, base physical table should only be modified when new column families are being added.  
+                // When adding a column to a view, base physical table should only be modified when new column families are being added.
                 modifyHTable = canViewsAddNewCF && !existingColumnFamiliesForBaseTable(table.getPhysicalName()).containsAll(colFamiliesForPColumnsToBeAdded);
             }
             if (modifyHTable) {
                 sendHBaseMetaData(tableDescriptors, pollingNeeded);
             }
-            
+
             // Special case for call during drop table to ensure that the empty column family exists.
             // In this, case we only include the table header row, as until we add schemaBytes and tableBytes
             // as args to this function, we have no way of getting them in this case.
@@ -1715,9 +1740,9 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             if ((tableMetaData.isEmpty()) || (tableMetaData.size() == 1 && tableMetaData.get(0).isEmpty())) {
                 return new MetaDataMutationResult(MutationCode.NO_OP, System.currentTimeMillis(), table);
             }
-             byte[][] rowKeyMetaData = new byte[3][];
-             PTableType tableType = table.getType();
-    
+            byte[][] rowKeyMetaData = new byte[3][];
+            PTableType tableType = table.getType();
+
             Mutation m = tableMetaData.get(0);
             byte[] rowKey = m.getRow();
             SchemaUtil.getVarChars(rowKey, rowKeyMetaData);
@@ -1725,37 +1750,37 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             byte[] schemaBytes = rowKeyMetaData[PhoenixDatabaseMetaData.SCHEMA_NAME_INDEX];
             byte[] tableBytes = rowKeyMetaData[PhoenixDatabaseMetaData.TABLE_NAME_INDEX];
             byte[] tableKey = SchemaUtil.getTableKey(tenantIdBytes, schemaBytes, tableBytes);
-            
+
             ImmutableBytesWritable ptr = new ImmutableBytesWritable();
             result =  metaDataCoprocessorExec(tableKey,
-                new Batch.Call<MetaDataService, MetaDataResponse>() {
-                    @Override
-                    public MetaDataResponse call(MetaDataService instance) throws IOException {
-                        ServerRpcController controller = new ServerRpcController();
-                        BlockingRpcCallback<MetaDataResponse> rpcCallback =
-                                new BlockingRpcCallback<MetaDataResponse>();
-                        AddColumnRequest.Builder builder = AddColumnRequest.newBuilder();
-                        for (Mutation m : tableMetaData) {
-                            MutationProto mp = ProtobufUtil.toProto(m);
-                            builder.addTableMetadataMutations(mp.toByteString());
-                        }
-                        builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
-                        instance.addColumn(controller, builder.build(), rpcCallback);
-                        if(controller.getFailedOn() != null) {
-                            throw controller.getFailedOn();
-                        }
-                        return rpcCallback.get();
+                    new Batch.Call<MetaDataService, MetaDataResponse>() {
+                @Override
+                public MetaDataResponse call(MetaDataService instance) throws IOException {
+                    ServerRpcController controller = new ServerRpcController();
+                    BlockingRpcCallback<MetaDataResponse> rpcCallback =
+                            new BlockingRpcCallback<MetaDataResponse>();
+                    AddColumnRequest.Builder builder = AddColumnRequest.newBuilder();
+                    for (Mutation m : tableMetaData) {
+                        MutationProto mp = ProtobufUtil.toProto(m);
+                        builder.addTableMetadataMutations(mp.toByteString());
                     }
-                });
-    
+                    builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
+                    instance.addColumn(controller, builder.build(), rpcCallback);
+                    if(controller.getFailedOn() != null) {
+                        throw controller.getFailedOn();
+                    }
+                    return rpcCallback.get();
+                }
+            });
+
             if (result.getMutationCode() == MutationCode.COLUMN_NOT_FOUND || result.getMutationCode() == MutationCode.TABLE_ALREADY_EXISTS) { // Success
                 success = true;
                 // Flush the table if transitioning DISABLE_WAL from TRUE to FALSE
                 if (  MetaDataUtil.getMutationValue(m,PhoenixDatabaseMetaData.DISABLE_WAL_BYTES, kvBuilder, ptr)
-                   && Boolean.FALSE.equals(PBoolean.INSTANCE.toObject(ptr))) {
+                        && Boolean.FALSE.equals(PBoolean.INSTANCE.toObject(ptr))) {
                     flushTable(table.getPhysicalName().getBytes());
                 }
-    
+
                 if (tableType == PTableType.TABLE) {
                     // If we're changing MULTI_TENANT to true or false, create or drop the view index table
                     if (MetaDataUtil.getMutationValue(m, PhoenixDatabaseMetaData.MULTI_TENANT_BYTES, kvBuilder, ptr)){
@@ -1861,7 +1886,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             }
         }
     }
-    
+
     private void sendHBaseMetaData(Set<HTableDescriptor> tableDescriptors, boolean pollingNeeded) throws SQLException {
         SQLException sqlE = null;
         for (HTableDescriptor descriptor : tableDescriptors) {
@@ -1890,7 +1915,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         }
         this.addCoprocessors(tableDescriptor.getName(), tableDescriptor, tableType, tableProps);
     }
-    
+
     private Pair<HTableDescriptor,HTableDescriptor> separateAndValidateProperties(PTable table, Map<String, List<Pair<String, Object>>> properties, Set<String> colFamiliesForPColumnsToBeAdded, List<Pair<byte[], Map<String, Object>>> families, Map<String, Object> tableProps) throws SQLException {
         Map<String, Map<String, Object>> stmtFamiliesPropsMap = new HashMap<>(properties.size());
         Map<String,Object> commonFamilyProps = new HashMap<>();
@@ -1919,7 +1944,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                         if (!family.equals(QueryConstants.ALL_FAMILY_PROPERTIES_KEY)) {
                             throw new SQLExceptionInfo.Builder(SQLExceptionCode.COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY)
                             .setMessage("Column Family: " + family + ", Property: " + propName).build()
-                            .buildException(); 
+                            .buildException();
                         }
                         tableProps.put(propName, propValue);
                     } else {
@@ -1943,7 +1968,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                                 }
                             } else {
                                 // invalid property - neither of HTableProp, HColumnProp or PhoenixTableProp
-                                // FIXME: This isn't getting triggered as currently a property gets evaluated 
+                                // FIXME: This isn't getting triggered as currently a property gets evaluated
                                 // as HTableProp if its neither HColumnProp or PhoenixTableProp.
                                 throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_ALTER_PROPERTY)
                                 .setMessage("Column Family: " + family + ", Property: " + propName).build()
@@ -1955,7 +1980,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                 if (!colFamilyPropsMap.isEmpty()) {
                     stmtFamiliesPropsMap.put(family, colFamilyPropsMap);
                 }
-  
+
             }
         }
         commonFamilyProps = Collections.unmodifiableMap(commonFamilyProps);
@@ -1977,13 +2002,13 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                         m.putAll(commonFamilyProps);
                         allFamiliesProps.put(colFamily, m);
                     } else if (isAddingPkColOnly) {
-                        // Setting HColumnProperty for a pk column is invalid 
+                        // Setting HColumnProperty for a pk column is invalid
                         // because it will be part of the row key and not a key value column family.
-                        // However, if both pk cols as well as key value columns are getting added 
+                        // However, if both pk cols as well as key value columns are getting added
                         // together, then its allowed. The above if block will make sure that we add properties
                         // only for the kv cols and not pk cols.
                         throw new SQLExceptionInfo.Builder(SQLExceptionCode.SET_UNSUPPORTED_PROP_ON_ALTER_TABLE)
-                                .build().buildException();
+                        .build().buildException();
                     }
                 }
             }
@@ -2014,8 +2039,8 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         }
 
         // case when there is a column family being added but there are no props
-        // For ex - in DROP COLUMN when a new empty CF needs to be added since all 
-        // the columns of the existing empty CF are getting dropped. Or the case 
+        // For ex - in DROP COLUMN when a new empty CF needs to be added since all
+        // the columns of the existing empty CF are getting dropped. Or the case
         // when one is just adding a column for a column family like this:
         // ALTER TABLE ADD CF.COL
         for (String cf : colFamiliesForPColumnsToBeAdded) {
@@ -2033,7 +2058,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             throw new SQLExceptionInfo.Builder(SQLExceptionCode.VIEW_WITH_PROPERTIES).build()
             .buildException();
         }
-        
+
         HTableDescriptor newTableDescriptor = null;
         HTableDescriptor origTableDescriptor = null;
         if (!allFamiliesProps.isEmpty() || !tableProps.isEmpty()) {
@@ -2047,7 +2072,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                 }
             }
             if (addingColumns) {
-                // Make sure that all the CFs of the table have the same TTL as the empty CF. 
+                // Make sure that all the CFs of the table have the same TTL as the empty CF.
                 setTTLForNewCFs(allFamiliesProps, table, newTableDescriptor, newTTL);
             }
             // Set TTL on all table column families, even if they're not referenced here
@@ -2071,7 +2096,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                     if (isTransactional) {
                         defaultTxMaxVersions = newTableDescriptor.getFamily(SchemaUtil.getEmptyColumnFamily(table)).getMaxVersions();
                     } else {
-                        defaultTxMaxVersions = 
+                        defaultTxMaxVersions =
                                 this.getProps().getInt(
                                         QueryServices.MAX_VERSIONS_TRANSACTIONAL_ATTRIB,
                                         QueryServicesOptions.DEFAULT_MAX_VERSIONS_TRANSACTIONAL);
@@ -2088,7 +2113,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                     }
                 }
             }
-            // Set Tephra's TTL property based on HBase property if we're 
+            // Set Tephra's TTL property based on HBase property if we're
             // transitioning to become transactional or setting TTL on
             // an already transactional table.
             if (isOrWillBeTransactional) {
@@ -2131,7 +2156,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         }
         return new Pair<>(origTableDescriptor, newTableDescriptor);
     }
-    
+
     private void checkTransactionalVersionsValue(HColumnDescriptor colDescriptor) throws SQLException {
         int maxVersions = colDescriptor.getMaxVersions();
         if (maxVersions <= 1) {
@@ -2146,7 +2171,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         PTable table = latestMetaData.getTableRef(new PTableKey(null, baseTableName.getString())).getTable();
         return existingColumnFamilies(table);
     }
-    
+
     private HashSet<String> existingColumnFamilies(PTable table) {
         List<PColumnFamily> cfs = table.getColumnFamilies();
         HashSet<String> cfNames = new HashSet<>(cfs.size());
@@ -2158,12 +2183,12 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
 
     private static int getTTL(PTable table, HTableDescriptor tableDesc, Integer newTTL) throws SQLException {
         // If we're setting TTL now, then use that value. Otherwise, use empty column family value
-        int ttl = newTTL != null ? newTTL 
+        int ttl = newTTL != null ? newTTL
                 : tableDesc.getFamily(SchemaUtil.getEmptyColumnFamily(table)).getTimeToLive();
         return ttl;
     }
-    
-    private static void setTTLForNewCFs(Map<String, Map<String, Object>> familyProps, PTable table, 
+
+    private static void setTTLForNewCFs(Map<String, Map<String, Object>> familyProps, PTable table,
             HTableDescriptor tableDesc, Integer newTTL) throws SQLException {
         if (!familyProps.isEmpty()) {
             int ttl = getTTL(table, tableDesc, newTTL);
@@ -2176,7 +2201,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             }
         }
     }
-    
+
     @Override
     public MetaDataMutationResult dropColumn(final List<Mutation> tableMetaData, PTableType tableType) throws SQLException {
         byte[][] rowKeyMetadata = new byte[3][];
@@ -2186,25 +2211,25 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         byte[] tableBytes = rowKeyMetadata[PhoenixDatabaseMetaData.TABLE_NAME_INDEX];
         byte[] tableKey = SchemaUtil.getTableKey(tenantIdBytes, schemaBytes, tableBytes);
         MetaDataMutationResult result = metaDataCoprocessorExec(tableKey,
-            new Batch.Call<MetaDataService, MetaDataResponse>() {
-                @Override
-                public MetaDataResponse call(MetaDataService instance) throws IOException {
-                    ServerRpcController controller = new ServerRpcController();
-                    BlockingRpcCallback<MetaDataResponse> rpcCallback =
-                            new BlockingRpcCallback<MetaDataResponse>();
-                    DropColumnRequest.Builder builder = DropColumnRequest.newBuilder();
-                    for (Mutation m : tableMetaData) {
-                        MutationProto mp = ProtobufUtil.toProto(m);
-                        builder.addTableMetadataMutations(mp.toByteString());
-                    }
-                    builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
-                    instance.dropColumn(controller, builder.build(), rpcCallback);
-                    if(controller.getFailedOn() != null) {
-                        throw controller.getFailedOn();
-                    }
-                    return rpcCallback.get();
+                new Batch.Call<MetaDataService, MetaDataResponse>() {
+            @Override
+            public MetaDataResponse call(MetaDataService instance) throws IOException {
+                ServerRpcController controller = new ServerRpcController();
+                BlockingRpcCallback<MetaDataResponse> rpcCallback =
+                        new BlockingRpcCallback<MetaDataResponse>();
+                DropColumnRequest.Builder builder = DropColumnRequest.newBuilder();
+                for (Mutation m : tableMetaData) {
+                    MutationProto mp = ProtobufUtil.toProto(m);
+                    builder.addTableMetadataMutations(mp.toByteString());
                 }
-            });
+                builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
+                instance.dropColumn(controller, builder.build(), rpcCallback);
+                if(controller.getFailedOn() != null) {
+                    throw controller.getFailedOn();
+                }
+                return rpcCallback.get();
+            }
+        });
         final MutationCode code = result.getMutationCode();
         switch(code) {
         case TABLE_ALREADY_EXISTS:
@@ -2221,7 +2246,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         return result;
 
     }
-    
+
     /**
      * This closes the passed connection.
      */
@@ -2254,15 +2279,15 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         }
         return metaConnection;
     }
-    
-    /** 
+
+    /**
      * Keeping this to use for further upgrades. This method closes the oldMetaConnection.
      */
     private PhoenixConnection addColumnsIfNotExists(PhoenixConnection oldMetaConnection,
             String tableName, long timestamp, String columns) throws SQLException {
         return addColumn(oldMetaConnection, tableName, timestamp, columns, true);
     }
-    
+
     @Override
     public void init(final String url, final Properties props) throws SQLException {
         try {
@@ -2292,34 +2317,34 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                         try {
                             openConnection();
                             String noUpgradeProp = props.getProperty(PhoenixRuntime.NO_UPGRADE_ATTRIB);
-                            boolean upgradeSystemTables = !Boolean.TRUE.equals(Boolean.valueOf(noUpgradeProp)); 
+                            boolean upgradeSystemTables = !Boolean.TRUE.equals(Boolean.valueOf(noUpgradeProp));
                             Properties scnProps = PropertiesUtil.deepCopy(props);
                             scnProps.setProperty(
-                                PhoenixRuntime.CURRENT_SCN_ATTRIB,
-                                Long.toString(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP));
+                                    PhoenixRuntime.CURRENT_SCN_ATTRIB,
+                                    Long.toString(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP));
                             scnProps.remove(PhoenixRuntime.TENANT_ID_ATTRIB);
                             String globalUrl = JDBCUtil.removeProperty(url, PhoenixRuntime.TENANT_ID_ATTRIB);
                             metaConnection = new PhoenixConnection(
-                                ConnectionQueryServicesImpl.this, globalUrl, scnProps, newEmptyMetaData());
+                                    ConnectionQueryServicesImpl.this, globalUrl, scnProps, newEmptyMetaData());
                             try (HBaseAdmin admin = getAdmin()) {
                                 boolean mappedSystemCatalogExists = admin
                                         .tableExists(SchemaUtil.getPhysicalTableName(SYSTEM_CATALOG_NAME_BYTES, true));
                                 if (SchemaUtil.isNamespaceMappingEnabled(PTableType.SYSTEM,
-                                    ConnectionQueryServicesImpl.this.getProps())) {
+                                        ConnectionQueryServicesImpl.this.getProps())) {
                                     if (admin.tableExists(SYSTEM_CATALOG_NAME_BYTES)) {
-                                        //check if the server is already updated and have namespace config properly set. 
+                                        //check if the server is already updated and have namespace config properly set.
                                         checkClientServerCompatibility(SYSTEM_CATALOG_NAME_BYTES);
                                     }
                                     ensureSystemTablesUpgraded(ConnectionQueryServicesImpl.this.getProps());
                                 } else if (mappedSystemCatalogExists) { throw new SQLExceptionInfo.Builder(
-                                    SQLExceptionCode.INCONSISTENET_NAMESPACE_MAPPING_PROPERTIES)
+                                        SQLExceptionCode.INCONSISTENET_NAMESPACE_MAPPING_PROPERTIES)
                                 .setMessage("Cannot initiate connection as "
                                         + SchemaUtil.getPhysicalTableName(
-                                            SYSTEM_CATALOG_NAME_BYTES, true)
-                                            + " is found but client does not have "
-                                            + IS_NAMESPACE_MAPPING_ENABLED + " enabled")
-                                            .build().buildException(); }
-                            }   
+                                                SYSTEM_CATALOG_NAME_BYTES, true)
+                                                + " is found but client does not have "
+                                                + IS_NAMESPACE_MAPPING_ENABLED + " enabled")
+                                                .build().buildException(); }
+                            }
                             try {
                                 metaConnection.createStatement().executeUpdate(QueryConstants.CREATE_TABLE_METADATA);
                             } catch (NewerTableAlreadyExistsException ignore) {
@@ -2359,10 +2384,10 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                                     }
 
                                     // If the server side schema is before MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0 then
-                                    // we need to add INDEX_TYPE and INDEX_DISABLE_TIMESTAMP columns too. 
-                                    // TODO: Once https://issues.apache.org/jira/browse/PHOENIX-1614 is fixed, 
-                                    // we should just have a ALTER TABLE ADD IF NOT EXISTS statement with all 
-                                    // the column names that have been added to SYSTEM.CATALOG since 4.0. 
+                                    // we need to add INDEX_TYPE and INDEX_DISABLE_TIMESTAMP columns too.
+                                    // TODO: Once https://issues.apache.org/jira/browse/PHOENIX-1614 is fixed,
+                                    // we should just have a ALTER TABLE ADD IF NOT EXISTS statement with all
+                                    // the column names that have been added to SYSTEM.CATALOG since 4.0.
                                     if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0) {
                                         columnsToAdd = addColumn(columnsToAdd, PhoenixDatabaseMetaData.INDEX_TYPE + " " + PUnsignedTinyint.INSTANCE.getSqlTypeName()
                                                 + ", " + PhoenixDatabaseMetaData.INDEX_DISABLE_TIMESTAMP + " " + PLong.INSTANCE.getSqlTypeName());
@@ -2385,7 +2410,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                                                     MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_5_0, columnsToAdd, false);
                                             upgradeTo4_5_0(metaConnection);
                                         } catch (ColumnAlreadyExistsException ignored) {
-                                            /* 
+                                            /*
                                              * Upgrade to 4.5 is a slightly special case. We use the fact that the column
                                              * BASE_COLUMN_COUNT is already part of the meta-data schema as the signal that
                                              * the server side upgrade has finished or is in progress.
@@ -2421,17 +2446,17 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                                     }
                                     if(currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0) {
                                         // Drop old stats table so that new stats table is created
-                                        metaConnection = dropStatsTable(metaConnection, 
+                                        metaConnection = dropStatsTable(metaConnection,
                                                 MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 4);
-                                        metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG, 
+                                        metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG,
                                                 MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 3,
                                                 PhoenixDatabaseMetaData.TRANSACTIONAL + " " + PBoolean.INSTANCE.getSqlTypeName());
-                                        metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG, 
+                                        metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG,
                                                 MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 2,
                                                 PhoenixDatabaseMetaData.UPDATE_CACHE_FREQUENCY + " " + PLong.INSTANCE.getSqlTypeName());
-                                        metaConnection = setImmutableTableIndexesImmutable(metaConnection, 
+                                        metaConnection = setImmutableTableIndexesImmutable(metaConnection,
                                                 MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 1);
-                                        metaConnection = updateSystemCatalogTimestamp(metaConnection, 
+                                        metaConnection = updateSystemCatalogTimestamp(metaConnection,
                                                 MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0);
                                         ConnectionQueryServicesImpl.this.removeTable(null, PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME, null, MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0);
                                         clearCache();
@@ -2468,7 +2493,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                             }
 
                             int nSaltBuckets = ConnectionQueryServicesImpl.this.props.getInt(QueryServices.SEQUENCE_SALT_BUCKETS_ATTRIB,
-                                QueryServicesOptions.DEFAULT_SEQUENCE_TABLE_SALT_BUCKETS);
+                                    QueryServicesOptions.DEFAULT_SEQUENCE_TABLE_SALT_BUCKETS);
                             try {
                                 String createSequenceTable = Sequence.getCreateTableStatement(nSaltBuckets);
                                 metaConnection.createStatement().executeUpdate(createSequenceTable);
@@ -2485,57 +2510,57 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                                     if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0) {
                                         // If the table time stamp is before 4.1.0 then we need to add below columns
                                         // to the SYSTEM.SEQUENCE table.
-                                        String columnsToAdd = PhoenixDatabaseMetaData.MIN_VALUE + " " + PLong.INSTANCE.getSqlTypeName() 
+                                        String columnsToAdd = PhoenixDatabaseMetaData.MIN_VALUE + " " + PLong.INSTANCE.getSqlTypeName()
                                                 + ", " + PhoenixDatabaseMetaData.MAX_VALUE + " " + PLong.INSTANCE.getSqlTypeName()
                                                 + ", " + PhoenixDatabaseMetaData.CYCLE_FLAG + " " + PBoolean.INSTANCE.getSqlTypeName()
                                                 + ", " + PhoenixDatabaseMetaData.LIMIT_REACHED_FLAG + " " + PBoolean.INSTANCE.getSqlTypeName();
                                         addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG,
-                                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP, columnsToAdd);
+                                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP, columnsToAdd);
                                     }
                                     // If the table timestamp is before 4.2.1 then run the upgrade script
                                     if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_2_1) {
                                         if (UpgradeUtil.upgradeSequenceTable(metaConnection, nSaltBuckets, e.getTable())) {
                                             metaConnection.removeTable(null,
-                                                PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_SCHEMA,
-                                                PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_TABLE,
-                                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP);
+                                                   PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_SCHEMA,
+                                                   PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_TABLE,
+                                                   MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP);
                                             clearTableFromCache(ByteUtil.EMPTY_BYTE_ARRAY,
-                                                PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_SCHEMA_BYTES,
-                                                PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_TABLE_BYTES,
-                                                MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP);
+                                                   PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_SCHEMA_BYTES,
+                                                   PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_TABLE_BYTES,
+                                                   MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP);
                                             clearTableRegionCache(PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_NAME_BYTES);
                                         }
                                         nSequenceSaltBuckets = nSaltBuckets;
-                                    } else { 
+                                    } else {
                                         nSequenceSaltBuckets = getSaltBuckets(e);
                                     }
                                 }
                             }
                             try {
                                 metaConnection.createStatement().executeUpdate(
-                                    QueryConstants.CREATE_STATS_TABLE_METADATA);
+                                        QueryConstants.CREATE_STATS_TABLE_METADATA);
                             } catch (NewerTableAlreadyExistsException ignore) {
                             } catch(TableAlreadyExistsException e) {
                                 if (upgradeSystemTables) {
                                     long currentServerSideTableTimeStamp = e.getTable().getTimeStamp();
                                     if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_3_0) {
                                         metaConnection = addColumnsIfNotExists(
-                                            metaConnection,
-                                            SYSTEM_STATS_NAME,
-                                            MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP,
-                                            PhoenixDatabaseMetaData.GUIDE_POSTS_ROW_COUNT + " "
-                                                    + PLong.INSTANCE.getSqlTypeName());
+                                               metaConnection,
+                                               SYSTEM_STATS_NAME,
+                                               MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP,
+                                               PhoenixDatabaseMetaData.GUIDE_POSTS_ROW_COUNT + " "
+                                                       + PLong.INSTANCE.getSqlTypeName());
                                     }
                                 }
                             }
                             try {
                                 metaConnection.createStatement().executeUpdate(
-                                    QueryConstants.CREATE_FUNCTION_METADATA);
+                                        QueryConstants.CREATE_FUNCTION_METADATA);
                             } catch (NewerTableAlreadyExistsException e) {
                             } catch (TableAlreadyExistsException e) {
                             }
                             if (SchemaUtil.isNamespaceMappingEnabled(PTableType.SYSTEM,
-                                ConnectionQueryServicesImpl.this.getProps())) {
+                                    ConnectionQueryServicesImpl.this.getProps())) {
                                 try {
                                     metaConnection.createStatement().executeUpdate("CREATE SCHEMA IF NOT EXISTS "
                                             + PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA);
@@ -2658,7 +2683,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                                             + (snapshotRestored ? " after successfully restoring using snapshot"
                                                     + snapshotName
                                                     : " after restoring using snapshot "
-                                                            + snapshotName + " failed. "));
+                                                    + snapshotName + " failed. "));
                                 } finally {
                                     try {
                                         admin.close();
@@ -2679,7 +2704,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                         }
                     }
                 }
-                
+
                 private void ensureSystemTablesUpgraded(ReadOnlyProps props)
                         throws SQLException, IOException, IllegalArgumentException, InterruptedException {
                     if (!SchemaUtil.isNamespaceMappingEnabled(PTableType.SYSTEM, props)) { return; }
@@ -2721,7 +2746,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                         }
                     }
                 }
-                
+
                 /**
                  * Acquire distributed mutex of sorts to make sure only one JVM is able to run the upgrade code by
                  * making use of HBase's checkAndPut api.
@@ -2732,13 +2757,13 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                  * wins the race will end up setting the version cell to the {@value MetaDataProtocol#MIN_SYSTEM_TABLE_TIMESTAMP}
                  * for the release.
                  * </p>
-                 * 
+                 *
                  * @return true if client won the race, false otherwise
                  * @throws IOException
                  * @throws SQLException
                  */
                 private boolean acquireUpgradeMutex(long currentServerSideTableTimestamp, byte[] sysCatalogTableName) throws IOException,
-                        SQLException {
+                SQLException {
                     Preconditions.checkArgument(currentServerSideTableTimestamp < MIN_SYSTEM_TABLE_TIMESTAMP);
                     try (HTableInterface sysCatalogTable = getTable(sysCatalogTableName)) {
                         byte[] row = SchemaUtil.getTableKey(null, PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA,
@@ -2764,7 +2789,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             throw Throwables.propagate(e);
         }
     }
-    
+
     private static class UpgradeInProgressException extends SQLException {
         public UpgradeInProgressException(String upgradeFrom, String upgradeTo) {
             super("Cluster is being concurrently upgraded from " + upgradeFrom + " to " + upgradeTo
@@ -2780,7 +2805,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         }
         return tableNames;
     }
-    
+
     private String addColumn(String columnsToAddSoFar, String columns) {
         if (columnsToAddSoFar == null || columnsToAddSoFar.isEmpty()) {
             return columns;
@@ -2803,18 +2828,18 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         try {
             metaConnection.setAutoCommit(true);
             metaConnection.createStatement().execute(
-                    "UPSERT INTO SYSTEM.CATALOG(TENANT_ID, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, COLUMN_FAMILY, IMMUTABLE_ROWS)\n" + 
-                    "SELECT A.TENANT_ID, A.TABLE_SCHEM,B.COLUMN_FAMILY,null,null,true\n" + 
-                    "FROM SYSTEM.CATALOG A JOIN SYSTEM.CATALOG B ON (\n" + 
-                    " A.TENANT_ID = B.TENANT_ID AND \n" + 
-                    " A.TABLE_SCHEM = B.TABLE_SCHEM AND\n" + 
-                    " A.TABLE_NAME = B.TABLE_NAME AND\n" + 
-                    " A.COLUMN_NAME = B.COLUMN_NAME AND\n" + 
-                    " B.LINK_TYPE = 1\n" + 
-                    ")\n" + 
-                    "WHERE A.COLUMN_FAMILY IS NULL AND\n" + 
-                    " B.COLUMN_FAMILY IS NOT NULL AND\n" + 
-                    " A.IMMUTABLE_ROWS = TRUE");
+                    "UPSERT INTO SYSTEM.CATALOG(TENANT_ID, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, COLUMN_FAMILY, IMMUTABLE_ROWS)\n" +
+                            "SELECT A.TENANT_ID, A.TABLE_SCHEM,B.COLUMN_FAMILY,null,null,true\n" +
+                            "FROM SYSTEM.CATALOG A JOIN SYSTEM.CATALOG B ON (\n" +
+                            " A.TENANT_ID = B.TENANT_ID AND \n" +
+                            " A.TABLE_SCHEM = B.TABLE_SCHEM AND\n" +
+                            " A.TABLE_NAME = B.TABLE_NAME AND\n" +
+                            " A.COLUMN_NAME = B.COLUMN_NAME AND\n" +
+                            " B.LINK_TYPE = 1\n" +
+                            ")\n" +
+                            "WHERE A.COLUMN_FAMILY IS NULL AND\n" +
+                            " B.COLUMN_FAMILY IS NOT NULL AND\n" +
+                            " A.IMMUTABLE_ROWS = TRUE");
         } catch (SQLException e) {
             logger.warn("exception during upgrading stats table:" + e);
             sqlE = e;
@@ -2854,8 +2879,8 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         try {
             metaConnection.setAutoCommit(true);
             metaConnection.createStatement().execute(
-                    "UPSERT INTO SYSTEM.CATALOG(TENANT_ID, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, COLUMN_FAMILY, DISABLE_WAL)\n" + 
-                    "VALUES (NULL, '" + QueryConstants.SYSTEM_SCHEMA_NAME + "','" + PhoenixDatabaseMetaData.SYSTEM_CATALOG_TABLE + "', NULL, NULL, FALSE)"); 
+                    "UPSERT INTO SYSTEM.CATALOG(TENANT_ID, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, COLUMN_FAMILY, DISABLE_WAL)\n" +
+                            "VALUES (NULL, '" + QueryConstants.SYSTEM_SCHEMA_NAME + "','" + PhoenixDatabaseMetaData.SYSTEM_CATALOG_TABLE + "', NULL, NULL, FALSE)");
         } catch (SQLException e) {
             logger.warn("exception during upgrading stats table:" + e);
             sqlE = e;
@@ -2878,50 +2903,50 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
     }
 
     private PhoenixConnection dropStatsTable(PhoenixConnection oldMetaConnection, long timestamp)
-			throws SQLException, IOException {
-		Properties props = PropertiesUtil.deepCopy(oldMetaConnection.getClientInfo());
-		props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(timestamp));
-		PhoenixConnection metaConnection = new PhoenixConnection(oldMetaConnection, this, props);
-		SQLException sqlE = null;
-		boolean wasCommit = metaConnection.getAutoCommit();
-		try {
-			metaConnection.setAutoCommit(true);
-			metaConnection.createStatement()
-					.executeUpdate("DELETE FROM " + PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME + " WHERE "
-							+ PhoenixDatabaseMetaData.TABLE_NAME + "='" + PhoenixDatabaseMetaData.SYSTEM_STATS_TABLE
-							+ "' AND " + PhoenixDatabaseMetaData.TABLE_SCHEM + "='"
-							+ PhoenixDatabaseMetaData.SYSTEM_SCHEMA_NAME + "'");
-		} catch (SQLException e) {
-			logger.warn("exception during upgrading stats table:" + e);
-			sqlE = e;
-		} finally {
-			try {
-				metaConnection.setAutoCommit(wasCommit);
-				oldMetaConnection.close();
-			} catch (SQLException e) {
-				if (sqlE != null) {
-					sqlE.setNextException(e);
-				} else {
-					sqlE = e;
-				}
-			}
-			if (sqlE != null) {
-				throw sqlE;
-			}
-		}
-		return metaConnection;
-	}
+            throws SQLException, IOException {
+        Properties props = PropertiesUtil.deepCopy(oldMetaConnection.getClientInfo());
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(timestamp));
+        PhoenixConnection metaConnection = new PhoenixConnection(oldMetaConnection, this, props);
+        SQLException sqlE = null;
+        boolean wasCommit = metaConnection.getAutoCommit();
+        try {
+            metaConnection.setAutoCommit(true);
+            metaConnection.createStatement()
+            .executeUpdate("DELETE FROM " + PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME + " WHERE "
+                    + PhoenixDatabaseMetaData.TABLE_NAME + "='" + PhoenixDatabaseMetaData.SYSTEM_STATS_TABLE
+                    + "' AND " + PhoenixDatabaseMetaData.TABLE_SCHEM + "='"
+                    + PhoenixDatabaseMetaData.SYSTEM_SCHEMA_NAME + "'");
+        } catch (SQLException e) {
+            logger.warn("exception during upgrading stats table:" + e);
+            sqlE = e;
+        } finally {
+            try {
+                metaConnection.setAutoCommit(wasCommit);
+                oldMetaConnection.close();
+            } catch (SQLException e) {
+                if (sqlE != null) {
+                    sqlE.setNextException(e);
+                } else {
+                    sqlE = e;
+                }
+            }
+            if (sqlE != null) {
+                throw sqlE;
+            }
+        }
+        return metaConnection;
+    }
 
     private void scheduleRenewLeaseTasks() {
         if (isRenewingLeasesEnabled()) {
             ThreadFactory threadFactory =
                     new ThreadFactoryBuilder().setDaemon(true)
-                            .setNameFormat("PHOENIX-SCANNER-RENEW-LEASE" + "-thread-%s").build();
+                    .setNameFormat("PHOENIX-SCANNER-RENEW-LEASE" + "-thread-%s").build();
             renewLeaseExecutor =
                     Executors.newScheduledThreadPool(renewLeasePoolSize, threadFactory);
             for (LinkedBlockingQueue<WeakReference<PhoenixConnection>> q : connectionQueues) {
                 renewLeaseExecutor.scheduleAtFixedRate(new RenewLeaseTask(q), 0,
-                    renewLeaseTaskFrequency, TimeUnit.MILLISECONDS);
+                        renewLeaseTaskFrequency, TimeUnit.MILLISECONDS);
             }
         }
     }
@@ -2931,7 +2956,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         Integer sequenceSaltBuckets = table == null ? null : table.getBucketNum();
         return sequenceSaltBuckets == null ? 0 : sequenceSaltBuckets;
     }
-    
+
     @Override
     public MutationState updateData(MutationPlan plan) throws SQLException {
         MutationState state = plan.execute();
@@ -2961,22 +2986,22 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                     .getPhysicalName(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES, this.getProps()).getName());
             try {
                 final Map<byte[], Long> results =
-                    htable.coprocessorService(MetaDataService.class, HConstants.EMPTY_START_ROW,
-                            HConstants.EMPTY_END_ROW, new Batch.Call<MetaDataService, Long>() {
-                        @Override
-                        public Long call(MetaDataService instance) throws IOException {
-                            ServerRpcController controller = new ServerRpcController();
-                            BlockingRpcCallback<ClearCacheResponse> rpcCallback =
-                                    new BlockingRpcCallback<ClearCacheResponse>();
-                            ClearCacheRequest.Builder builder = ClearCacheRequest.newBuilder();
-                            builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
-                            instance.clearCache(controller, builder.build(), rpcCallback);
-                            if(controller.getFailedOn() != null) {
-                                throw controller.getFailedOn();
+                        htable.coprocessorService(MetaDataService.class, HConstants.EMPTY_START_ROW,
+                                HConstants.EMPTY_END_ROW, new Batch.Call<MetaDataService, Long>() {
+                            @Override
+                            public Long call(MetaDataService instance) throws IOException {
+                                ServerRpcController controller = new ServerRpcController();
+                                BlockingRpcCallback<ClearCacheResponse> rpcCallback =
+                                        new BlockingRpcCallback<ClearCacheResponse>();
+                                ClearCacheRequest.Builder builder = ClearCacheRequest.newBuilder();
+                                bui

<TRUNCATED>

[42/47] phoenix git commit: PHOENIX-3268 Upgrade to Tephra 0.9.0

Posted by ma...@apache.org.
PHOENIX-3268 Upgrade to Tephra 0.9.0


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

Branch: refs/heads/calcite
Commit: e8ffc9c53513309c249aca740620ecc5df48a26a
Parents: 6b86839
Author: James Taylor <ja...@apache.org>
Authored: Mon Sep 19 07:49:29 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Mon Sep 19 07:49:29 2016 -0700

----------------------------------------------------------------------
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/e8ffc9c5/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 242c987..3c000e2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -98,7 +98,7 @@
     <joni.version>2.1.2</joni.version>
     <avatica.version>1.8.0</avatica.version>
     <jettyVersion>8.1.7.v20120910</jettyVersion>
-    <tephra.version>0.8.0-incubating</tephra.version>
+    <tephra.version>0.9.0-incubating</tephra.version>
     <spark.version>1.6.1</spark.version>
     <scala.version>2.10.4</scala.version>
     <scala.binary.version>2.10</scala.binary.version>


[18/47] phoenix git commit: PHOENIX-3046 NOT LIKE with wildcard unexpectedly returns results (Kevin Liew)

Posted by ma...@apache.org.
PHOENIX-3046 NOT LIKE with wildcard unexpectedly returns results (Kevin Liew)


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

Branch: refs/heads/calcite
Commit: 47a2b2c3ec1fb7a5ae3fc42c79a2199ab5108f44
Parents: c3cdb2a
Author: James Taylor <ja...@apache.org>
Authored: Mon Sep 12 09:54:10 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Mon Sep 12 11:46:58 2016 -0700

----------------------------------------------------------------------
 .../phoenix/end2end/LikeExpressionIT.java       | 100 ++++++++++++++++++-
 .../phoenix/compile/ExpressionCompiler.java     |  24 ++---
 2 files changed, 103 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/47a2b2c3/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java
index f97e1d7..2fcee45 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java
@@ -96,16 +96,16 @@ public class LikeExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
         Connection conn = DriverManager.getConnection(getUrl());
         String table = generateRandomString();
         String ddl = "CREATE TABLE " + table
-            + " (k1 VARCHAR, k2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2))";
+                + " (k1 VARCHAR, k2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2))";
         conn.createStatement().execute(ddl);
         conn.createStatement().execute("UPSERT INTO " + table + " VALUES('aa','bb')");
         conn.createStatement().execute("UPSERT INTO " + table + " VALUES('ab','bc')");
         conn.createStatement().execute("UPSERT INTO " + table + " VALUES(null,'cc')");
         conn.createStatement().execute("UPSERT INTO " + table + " VALUES('dd',null)");
         conn.commit();
-        
+
         ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT * FROM " + table + " WHERE k1 LIKE '%'");
+                "SELECT * FROM " + table + " WHERE k1 LIKE '%'");
         assertTrue(rs.next());
         assertEquals("aa", rs.getString(1));
         assertEquals("bb", rs.getString(2));
@@ -116,7 +116,7 @@ public class LikeExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
         assertEquals("dd", rs.getString(1));
         assertEquals(null, rs.getString(2));
         assertFalse(rs.next());
-        
+
         rs = conn.createStatement().executeQuery("SELECT * FROM " + table + " WHERE k2 LIKE '%'");
         assertTrue(rs.next());
         assertEquals(null, rs.getString(1));
@@ -128,7 +128,25 @@ public class LikeExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
         assertEquals("ab", rs.getString(1));
         assertEquals("bc", rs.getString(2));
         assertFalse(rs.next());
-        
+
+        rs = conn.createStatement().executeQuery("SELECT * FROM " + table + " WHERE k2 LIKE '%%'");
+        assertTrue(rs.next());
+        assertEquals(null, rs.getString(1));
+        assertEquals("cc", rs.getString(2));
+        assertTrue(rs.next());
+        assertEquals("aa", rs.getString(1));
+        assertEquals("bb", rs.getString(2));
+        assertTrue(rs.next());
+        assertEquals("ab", rs.getString(1));
+        assertEquals("bc", rs.getString(2));
+        assertFalse(rs.next());
+
+        rs = conn.createStatement().executeQuery("SELECT * FROM " + table + " WHERE k2 NOT LIKE '%'");
+        assertFalse(rs.next());
+
+        rs = conn.createStatement().executeQuery("SELECT * FROM " + table + " WHERE k2 NOT LIKE '%%'");
+        assertFalse(rs.next());
+
         conn.close();
     }
     
@@ -205,4 +223,76 @@ public class LikeExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
         assertEquals("AA", rs.getString(1));
         assertFalse(rs.next());
     }
+
+    @Test
+    public void testNull() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String table = generateRandomString();
+        String ddl = "CREATE TABLE " + table
+                + " (pk INTEGER PRIMARY KEY, str VARCHAR)";
+        conn.createStatement().execute(ddl);
+        conn.createStatement().execute("UPSERT INTO " + table + " VALUES(0,'aa')");
+        conn.createStatement().execute("UPSERT INTO " + table + " VALUES(1, null)");
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery(
+                "SELECT str LIKE '%' FROM " + table);
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.wasNull());
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.wasNull());
+        assertFalse(rs.next());
+
+        rs = conn.createStatement().executeQuery(
+                "SELECT str LIKE '%%' FROM " + table);
+        assertTrue(rs.next());
+        assertEquals(true, rs.getBoolean(1));
+        assertFalse(rs.wasNull());
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.wasNull());
+        assertFalse(rs.next());
+
+        rs = conn.createStatement().executeQuery(
+                "SELECT str NOT LIKE '%' FROM " + table);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertFalse(rs.wasNull());
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.wasNull());
+        assertFalse(rs.next());
+
+        rs = conn.createStatement().executeQuery(
+                "SELECT str NOT LIKE '%%' FROM " + table);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertFalse(rs.wasNull());
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.wasNull());
+        assertFalse(rs.next());
+
+        rs = conn.createStatement().executeQuery(
+                "SELECT NOT (str LIKE '%') FROM " + table);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertFalse(rs.wasNull());
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.wasNull());
+        assertFalse(rs.next());
+
+        rs = conn.createStatement().executeQuery(
+                "SELECT NOT(str LIKE '%%') FROM " + table);
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertFalse(rs.wasNull());
+        assertTrue(rs.next());
+        assertEquals(false, rs.getBoolean(1));
+        assertTrue(rs.wasNull());
+        assertFalse(rs.next());
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/47a2b2c3/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
index aaab763..c05918b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
@@ -105,6 +105,7 @@ import org.apache.phoenix.parse.SubqueryParseNode;
 import org.apache.phoenix.parse.SubtractParseNode;
 import org.apache.phoenix.parse.UDFParseNode;
 import org.apache.phoenix.parse.UnsupportedAllParseNodeVisitor;
+import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.schema.ColumnFamilyNotFoundException;
@@ -121,18 +122,7 @@ import org.apache.phoenix.schema.RowKeyValueAccessor;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.TableRef;
 import org.apache.phoenix.schema.TypeMismatchException;
-import org.apache.phoenix.schema.types.PArrayDataType;
-import org.apache.phoenix.schema.types.PBoolean;
-import org.apache.phoenix.schema.types.PChar;
-import org.apache.phoenix.schema.types.PDataType;
-import org.apache.phoenix.schema.types.PDate;
-import org.apache.phoenix.schema.types.PDecimal;
-import org.apache.phoenix.schema.types.PDouble;
-import org.apache.phoenix.schema.types.PLong;
-import org.apache.phoenix.schema.types.PTimestamp;
-import org.apache.phoenix.schema.types.PUnsignedTimestamp;
-import org.apache.phoenix.schema.types.PVarbinary;
-import org.apache.phoenix.schema.types.PhoenixArray;
+import org.apache.phoenix.schema.types.*;
 import org.apache.phoenix.util.ExpressionUtil;
 import org.apache.phoenix.util.IndexUtil;
 import org.apache.phoenix.util.SchemaUtil;
@@ -147,6 +137,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
     private int nodeCount;
     private int totalNodeCount;
     private final boolean resolveViewConstants;
+    private static final Expression NOT_NULL_STRING = LiteralExpression.newConstant(PVarchar.INSTANCE.toObject(KeyRange.IS_NOT_NULL_RANGE.getLowerRange()));
 
     public ExpressionCompiler(StatementContext context) {
         this(context,GroupBy.EMPTY_GROUP_BY, false);
@@ -519,11 +510,12 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
                   }
                 }
             } else {
-                byte[] nullExpressionString = new byte[pattern.length()];
+                byte[] wildcardString = new byte[pattern.length()];
                 byte[] wildcard = {StringUtil.MULTI_CHAR_LIKE};
-                StringUtil.fill(nullExpressionString, 0, pattern.length(), wildcard, 0, 1, false);
-                if (pattern.equals(new String (nullExpressionString))) {
-                    return IsNullExpression.create(lhs, true, context.getTempPtr());
+                StringUtil.fill(wildcardString, 0, pattern.length(), wildcard, 0, 1, false);
+                if (pattern.equals(new String (wildcardString))) {
+                    List<Expression> compareChildren = Arrays.asList(lhs, NOT_NULL_STRING);
+                    return new ComparisonExpression(compareChildren, node.isNegate() ? CompareOp.LESS : CompareOp.GREATER_OR_EQUAL);
                 }
             }
         }


[03/47] phoenix git commit: Implement DAYOFWEEK and DAYOFYEAR built-in functions (Prakul Agarwal)

Posted by ma...@apache.org.
Implement DAYOFWEEK and DAYOFYEAR built-in functions (Prakul Agarwal)


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

Branch: refs/heads/calcite
Commit: fce0f1033e252ecb55d168f63284be330a8fbda7
Parents: 06d37e5
Author: Samarth <sa...@salesforce.com>
Authored: Thu Sep 1 15:32:42 2016 -0700
Committer: Samarth <sa...@salesforce.com>
Committed: Thu Sep 1 15:32:42 2016 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/DateTimeIT.java  | 45 ++++++++++
 .../phoenix/expression/ExpressionType.java      |  9 +-
 .../expression/function/DayOfWeekFunction.java  | 86 ++++++++++++++++++++
 .../expression/function/DayOfYearFunction.java  | 77 ++++++++++++++++++
 4 files changed, 215 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/fce0f103/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
index 227374a..05a8ec8 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
@@ -688,6 +688,51 @@ public class DateTimeIT extends BaseHBaseManagedTimeTableReuseIT {
         assertFalse(rs.next());
     }
 
+    /*
+    Reference for dates used in the test
+    2013-04-09 - Tuesday (2)
+     2014-05-18 - Sunday (7)
+    2015-06-27 - Saturday (6)
+     */
+    @Test
+    public void testDayOfWeekFuncAgainstColumns() throws Exception {
+        String tableName = generateRandomString();
+        String ddl = "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER NOT NULL, dates DATE, timestamps TIMESTAMP, times TIME CONSTRAINT pk PRIMARY KEY (k1))";
+        conn.createStatement().execute(ddl);
+        String dml = "UPSERT INTO " + tableName + " VALUES (1, TO_DATE('2012-03-08 11:01:10'), TO_TIMESTAMP('2013-06-16 12:02:20'), TO_TIME('2014-09-23 13:03:30'))";
+        conn.createStatement().execute(dml);
+        dml = "UPSERT INTO " + tableName + " VALUES (2, TO_DATE('2013-04-09 11:02:10'), TO_TIMESTAMP('2014-05-18 12:03:20'), TO_TIME('2015-06-27 13:04:30'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT k1, DAYOFWEEK(dates), DAYOFWEEK(timestamps) FROM " + tableName + " where DAYOFWEEK(times)=6");
+        assertTrue(rs.next());
+        assertEquals(2, rs.getInt(1));
+        assertEquals(2, rs.getInt(2));
+        assertEquals(7, rs.getInt(3));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testDayOfYearFuncAgainstColumns() throws Exception {
+        String tableName = generateRandomString();
+        String ddl = "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER NOT NULL, dates DATE, timestamps TIMESTAMP, times TIME CONSTRAINT pk PRIMARY KEY (k1))";
+        conn.createStatement().execute(ddl);
+        String dml = "UPSERT INTO " + tableName + " VALUES (1, TO_DATE('2012-03-01 11:01:10'), TO_TIMESTAMP('2013-02-01 12:02:20'), TO_TIME('2014-01-15 13:03:30'))";
+        conn.createStatement().execute(dml);
+        dml = "UPSERT INTO " + tableName + " VALUES (2, TO_DATE('2013-04-09 11:02:10'), TO_TIMESTAMP('2014-05-18 12:03:20'), TO_TIME('2015-06-27 13:04:30'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT k1, DAYOFYEAR(dates), DAYOFYEAR(timestamps) FROM " + tableName + " where DAYOFYEAR(times)=15");
+
+        assertTrue(rs.next());
+        assertEquals(1, rs.getInt(1));
+        assertEquals(61, rs.getInt(2));
+        assertEquals(32, rs.getInt(3));
+        assertFalse(rs.next());
+    }
+
     @Test
     public void testNullDate() throws Exception {
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/fce0f103/phoenix-core/src/main/java/org/apache/phoenix/expression/ExpressionType.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ExpressionType.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ExpressionType.java
index f13e265..94120e9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ExpressionType.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ExpressionType.java
@@ -125,6 +125,8 @@ import org.apache.phoenix.expression.function.UDFExpression;
 import org.apache.phoenix.expression.function.UpperFunction;
 import org.apache.phoenix.expression.function.WeekFunction;
 import org.apache.phoenix.expression.function.YearFunction;
+import org.apache.phoenix.expression.function.DayOfWeekFunction;
+import org.apache.phoenix.expression.function.DayOfYearFunction;
 
 import com.google.common.collect.Maps;
 
@@ -281,8 +283,11 @@ public enum ExpressionType {
     FloorYearExpression(FloorYearExpression.class),
     CeilWeekExpression(CeilWeekExpression.class),
     CeilMonthExpression(CeilMonthExpression.class),
-    CeilYearExpression(CeilYearExpression.class);
-    ;
+    CeilYearExpression(CeilYearExpression.class),
+    DayOfWeekFunction(DayOfWeekFunction.class),
+    DayOfYearFunction(DayOfYearFunction.class);
+
+
 
     ExpressionType(Class<? extends Expression> clazz) {
         this.clazz = clazz;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/fce0f103/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfWeekFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfWeekFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfWeekFunction.java
new file mode 100644
index 0000000..0330b83
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfWeekFunction.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.expression.function;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.schema.tuple.Tuple;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.joda.time.DateTime;
+
+import java.util.List;
+
+/**
+ * Implementation of DayOfWeekFunction(Date/Timestamp)
+ *
+ * Returns an integer from 1 to 7. Each represents a day of the week as follows :
+ * MONDAY = 1;
+ * TUESDAY = 2;
+ * WEDNESDAY = 3;
+ * THURSDAY = 4;
+ * FRIDAY = 5;
+ * SATURDAY = 6;
+ * SUNDAY = 7;
+ *
+ */
+@BuiltInFunction(name=DayOfWeekFunction.NAME,
+        args={@Argument(allowedTypes={PTimestamp.class})})
+public class DayOfWeekFunction extends ScalarFunction {
+    public static final String NAME = "DAYOFWEEK";
+
+    public DayOfWeekFunction(){
+
+    }
+
+    public DayOfWeekFunction(List<Expression> children){
+        super(children);
+    }
+    @Override
+    public String getName() {
+        return NAME;
+    }
+
+    @Override
+    public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
+        Expression arg = getChildren().get(0);
+        if (!arg.evaluate(tuple,ptr)) {
+            return false;
+        }
+        if (ptr.getLength() == 0) {
+            return true;
+        }
+        long dateTime = arg.getDataType().getCodec().decodeLong(ptr, arg.getSortOrder());
+        DateTime jodaDT = new DateTime(dateTime);
+        int day = jodaDT.getDayOfWeek();
+        PDataType returnDataType = getDataType();
+        byte[] byteValue = new byte[returnDataType.getByteSize()];
+        returnDataType.getCodec().encodeInt(day, byteValue, 0);
+        ptr.set(byteValue);
+        return true;
+    }
+
+
+    @Override
+    public PDataType getDataType() {
+        return PInteger.INSTANCE;
+    }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/fce0f103/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfYearFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfYearFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfYearFunction.java
new file mode 100644
index 0000000..d4e92d6
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfYearFunction.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.expression.function;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.schema.tuple.Tuple;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.joda.time.DateTime;
+import java.util.List;
+
+/**
+ * Implementation of DayOfYearFunction(Date/Timestamp)
+ *
+ * Returns an integer from 1 to 365 (for each day of the week). Returns 366 in a leap year.
+ *
+ */
+@BuiltInFunction(name=DayOfYearFunction.NAME,
+        args={@Argument(allowedTypes={PTimestamp.class})})
+public class DayOfYearFunction extends ScalarFunction {
+    public static final String NAME = "DAYOFYEAR";
+
+    public DayOfYearFunction() {
+    }
+
+    public DayOfYearFunction(List<Expression> children) {
+        super(children);
+    }
+
+    @Override
+    public String getName() {
+        return NAME;
+    }
+
+    @Override
+    public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
+        Expression arg = getChildren().get(0);
+        if (!arg.evaluate(tuple,ptr)) {
+            return false;
+        }
+        if (ptr.getLength() == 0) {
+            return true;
+        }
+        long dateTime = arg.getDataType().getCodec().decodeLong(ptr, arg.getSortOrder());
+        DateTime jodaDT = new DateTime(dateTime);
+        int day = jodaDT.getDayOfYear();
+        PDataType returnDataType = getDataType();
+        byte[] byteValue = new byte[returnDataType.getByteSize()];
+        returnDataType.getCodec().encodeInt(day, byteValue, 0);
+        ptr.set(byteValue);
+        return true;
+    }
+
+    @Override
+    public PDataType getDataType() {
+        return PInteger.INSTANCE;
+    }
+}


[33/47] phoenix git commit: PHOENIX-3285 Add test name in Parameters name since failsafe uses that to form report file name

Posted by ma...@apache.org.
PHOENIX-3285 Add test name in Parameters name since failsafe uses that to form report file name


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

Branch: refs/heads/calcite
Commit: 4c8bda1510606148e6d3d5154ed9004098ff239d
Parents: b0f9004
Author: James Taylor <ja...@apache.org>
Authored: Thu Sep 15 17:07:13 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Thu Sep 15 17:07:13 2016 -0700

----------------------------------------------------------------------
 .../phoenix/end2end/AlterTableWithViewsIT.java  |   2 +-
 .../phoenix/end2end/AutoPartitionViewsIT.java   |   2 +-
 .../apache/phoenix/end2end/CaseStatementIT.java |   2 +-
 .../apache/phoenix/end2end/CastAndCoerceIT.java |   2 +-
 .../end2end/ClientTimeArithmeticQueryIT.java    |   2 +-
 .../apache/phoenix/end2end/DerivedTableIT.java  |   4 +-
 .../apache/phoenix/end2end/DropSchemaIT.java    |   2 +-
 .../org/apache/phoenix/end2end/GroupByIT.java   |   5 +-
 .../org/apache/phoenix/end2end/NotQueryIT.java  |   2 +-
 .../org/apache/phoenix/end2end/ScanQueryIT.java |   2 +-
 .../end2end/SequenceBulkAllocationIT.java       |   2 +-
 .../apache/phoenix/end2end/TenantIdTypeIT.java  |  12 +-
 .../phoenix/end2end/index/ImmutableIndexIT.java |   4 +-
 .../apache/phoenix/end2end/index/IndexIT.java   |   5 +-
 .../end2end/index/IndexOnOwnClusterIT.java      | 218 ++++++++++++++++++-
 .../end2end/index/MutableIndexFailureIT.java    |   2 +-
 .../phoenix/end2end/index/MutableIndexIT.java   |   4 +-
 .../end2end/index/ReadOnlyIndexFailureIT.java   |   2 +-
 .../phoenix/end2end/index/ViewIndexIT.java      |   2 +-
 .../end2end/index/txn/MutableRollbackIT.java    |   2 +-
 .../phoenix/end2end/index/txn/RollbackIT.java   |   2 +-
 .../end2end/index/txn/TxWriteFailureIT.java     |   2 +-
 .../apache/phoenix/execute/PartialCommitIT.java |   5 +-
 .../org/apache/phoenix/tx/TxCheckpointIT.java   |   5 +-
 24 files changed, 248 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
index ae3b977..177a5c7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
@@ -67,7 +67,7 @@ public class AlterTableWithViewsIT extends BaseHBaseManagedTimeTableReuseIT {
         this.isMultiTenant = isMultiTenant;
     }
     
-    @Parameters(name="multiTenant = {0}")
+    @Parameters(name="AlterTableWithViewsIT_multiTenant={0}") // name is used by failsafe as file name in reports
     public static Collection<Boolean> data() {
         return Arrays.asList(false, true);
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/AutoPartitionViewsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AutoPartitionViewsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AutoPartitionViewsIT.java
index 95ac2cb..f44c083 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AutoPartitionViewsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AutoPartitionViewsIT.java
@@ -56,7 +56,7 @@ public class AutoPartitionViewsIT extends BaseHBaseManagedTimeTableReuseIT {
     private final String TENANT_SPECIFIC_URL2 = getUrl() + ';' + PhoenixRuntime.TENANT_ID_ATTRIB
             + "=tenant2";
 
-    @Parameters(name = "salted = {0}, multi-tenant = {1}")
+    @Parameters(name = "AutoPartitionViewsIT_salted={0},multi-tenant={1}") // name is used by failsafe as file name in reports
     public static Collection<Boolean[]> data() {
         return Arrays.asList(new Boolean[][] { { false, false }, { false, true }, { true, false },
                 { true, true } });

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/CaseStatementIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CaseStatementIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CaseStatementIT.java
index bda1273..59b0f41 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CaseStatementIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CaseStatementIT.java
@@ -58,7 +58,7 @@ public class CaseStatementIT extends BaseQueryIT {
         super(indexDDL);
     }
     
-    @Parameters(name="{0}")
+    @Parameters(name="CaseStatementIT_{index}") // name is used by failsafe as file name in reports
     public static Collection<Object> data() {
         return QueryIT.data();
     }    

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/CastAndCoerceIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CastAndCoerceIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CastAndCoerceIT.java
index 8134aba..876c23a 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CastAndCoerceIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CastAndCoerceIT.java
@@ -47,7 +47,7 @@ public class CastAndCoerceIT extends BaseQueryIT {
         super(indexDDL);
     }
     
-    @Parameters(name="{0}")
+    @Parameters(name="CastAndCoerceIT_{index}") // name is used by failsafe as file name in reports
     public static Collection<Object> data() {
         return QueryIT.data();
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/ClientTimeArithmeticQueryIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ClientTimeArithmeticQueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ClientTimeArithmeticQueryIT.java
index 584f2ff..ea4f3ab 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ClientTimeArithmeticQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ClientTimeArithmeticQueryIT.java
@@ -64,7 +64,7 @@ public class ClientTimeArithmeticQueryIT extends BaseQueryIT {
         super(indexDDL);
     }
     
-    @Parameters(name="{0}")
+    @Parameters(name="ClientTimeArithmeticQueryIT_{index}") // name is used by failsafe as file name in reports
     public static Collection<Object> data() {
         return QueryIT.data();
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
index 16ad47f..862416b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
@@ -18,6 +18,7 @@
 
 package org.apache.phoenix.end2end;
 
+import static org.apache.phoenix.util.TestUtil.ATABLE_NAME;
 import static org.apache.phoenix.util.TestUtil.A_VALUE;
 import static org.apache.phoenix.util.TestUtil.B_VALUE;
 import static org.apache.phoenix.util.TestUtil.C_VALUE;
@@ -32,7 +33,6 @@ import static org.apache.phoenix.util.TestUtil.ROW7;
 import static org.apache.phoenix.util.TestUtil.ROW8;
 import static org.apache.phoenix.util.TestUtil.ROW9;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.apache.phoenix.util.TestUtil.ATABLE_NAME;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -85,7 +85,7 @@ public class DerivedTableIT extends BaseClientManagedTimeIT {
         }
     }
     
-    @Parameters(name="{0}")
+    @Parameters(name="DerivedTableIT_{index}") // name is used by failsafe as file name in reports
     public static Collection<Object> data() {
         List<Object> testCases = Lists.newArrayList();
         testCases.add(new String[][] {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/DropSchemaIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DropSchemaIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DropSchemaIT.java
index bfaf401..9d59ec7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DropSchemaIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DropSchemaIT.java
@@ -65,7 +65,7 @@ public class DropSchemaIT extends BaseClientManagedTimeIT {
         this.schema = schema;
     }
 
-    @Parameters(name = "schema = {0}")
+    @Parameters(name = "DropSchemaIT_schema={0}") // name is used by failsafe as file name in reports
     public static Collection<String> data() {
         return Arrays.asList("TEST_SCHEMA", "\"test_schema\"");
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByIT.java
index 1b5c275..f0c781f 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByIT.java
@@ -31,7 +31,6 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import java.sql.Connection;
-import java.sql.Date;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -45,8 +44,6 @@ import java.util.Properties;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
-import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -64,7 +61,7 @@ public class GroupByIT extends BaseQueryIT {
         super(indexDDL);
     }
     
-    @Parameters(name="{0}")
+    @Parameters(name="GroupByIT_{index}") // name is used by failsafe as file name in reports
     public static Collection<Object> data() {
         return QueryIT.data();
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/NotQueryIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NotQueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NotQueryIT.java
index 6cc0eed..76627be 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NotQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NotQueryIT.java
@@ -56,7 +56,7 @@ public class NotQueryIT extends BaseQueryIT {
         super(indexDDL);
     }
     
-    @Parameters(name="{0}")
+    @Parameters(name="NotQueryIT_{index}") // name is used by failsafe as file name in reports
     public static Collection<Object> data() {
         return QueryIT.data();
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/ScanQueryIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ScanQueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ScanQueryIT.java
index 063bdab..9b28bad 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ScanQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ScanQueryIT.java
@@ -61,7 +61,7 @@ import com.google.common.primitives.Floats;
 @RunWith(Parameterized.class)
 public class ScanQueryIT extends BaseQueryIT {
     
-    @Parameters(name="{0}")
+    @Parameters(name="ScanQueryIT_{index}") // name is used by failsafe as file name in reports
     public static Collection<Object> data() {
         return QueryIT.data();
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceBulkAllocationIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceBulkAllocationIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceBulkAllocationIT.java
index e7db1ec..7ea3477 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceBulkAllocationIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceBulkAllocationIT.java
@@ -96,7 +96,7 @@ public class SequenceBulkAllocationIT extends BaseClientManagedTimeIT {
         }
     }
     
-    @Parameters
+    @Parameters(name="SequenceBulkAllocationIT_tenantId={0}") // name is used by failsafe as file name in reports
     public static Object[] data() {
         return new Object[] {null, "tenant1"};
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantIdTypeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantIdTypeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantIdTypeIT.java
index c7b5716..a3ca355 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantIdTypeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantIdTypeIT.java
@@ -22,11 +22,13 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.sql.*;
-import java.util.Properties;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.util.Collection;
 import java.util.List;
-import com.google.common.collect.Lists;
+import java.util.Properties;
 
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.schema.SequenceNotFoundException;
@@ -37,6 +39,8 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
+import com.google.common.collect.Lists;
+
 @RunWith(Parameterized.class)
 public class TenantIdTypeIT extends BaseHBaseManagedTimeTableReuseIT {
 
@@ -86,7 +90,7 @@ public class TenantIdTypeIT extends BaseHBaseManagedTimeTableReuseIT {
                 + "MULTI_TENANT=true";
     }
 
-    @Parameters
+    @Parameters( name = "TenantIdTypeIT_datatype={0}" ) // name is used by failsafe as file name in reports
     public static Collection<Object[]> data() {
         List<Object[]> testCases = Lists.newArrayList();
         testCases.add(new Object[] { "INTEGER", "2147483647", "2147483646" });

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
index 0c7a356..ec5267d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
@@ -72,7 +72,6 @@ import com.google.common.collect.Maps;
 public class ImmutableIndexIT extends BaseHBaseManagedTimeTableReuseIT {
 
     private final boolean localIndex;
-    private final boolean transactional;
     private final String tableDDLOptions;
 
     private volatile boolean stopThreads = false;
@@ -83,7 +82,6 @@ public class ImmutableIndexIT extends BaseHBaseManagedTimeTableReuseIT {
 
     public ImmutableIndexIT(boolean localIndex, boolean transactional) {
         this.localIndex = localIndex;
-        this.transactional = transactional;
         StringBuilder optionBuilder = new StringBuilder("IMMUTABLE_ROWS=true");
         if (transactional) {
             optionBuilder.append(", TRANSACTIONAL=true");
@@ -103,7 +101,7 @@ public class ImmutableIndexIT extends BaseHBaseManagedTimeTableReuseIT {
         setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet().iterator()));
     }
 
-    @Parameters(name="localIndex = {0} , transactional = {1}")
+    @Parameters(name="ImmutableIndexIT_localIndex={0},transactional={1}") // name is used by failsafe as file name in reports
     public static Collection<Boolean[]> data() {
 		return Arrays.asList(new Boolean[][] { 
 				{ false, false }, { false, true },

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
index a5fefe2..f06ac82 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
@@ -55,7 +55,6 @@ import org.apache.hadoop.hbase.ipc.PhoenixRpcSchedulerFactory;
 import org.apache.phoenix.compile.ColumnResolver;
 import org.apache.phoenix.compile.FromCompiler;
 import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
-import org.apache.phoenix.end2end.BaseOwnClusterIT;
 import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixConnection;
@@ -83,7 +82,7 @@ import org.junit.runners.Parameterized.Parameters;
 import com.google.common.collect.Maps;
 
 @RunWith(Parameterized.class)
-public class IndexIT extends BaseOwnClusterIT {
+public class IndexIT extends BaseHBaseManagedTimeTableReuseIT {
 
     private final boolean localIndex;
     private final boolean transactional;
@@ -114,7 +113,7 @@ public class IndexIT extends BaseOwnClusterIT {
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
 
-    @Parameters(name="localIndex = {0} , mutable = {1} , transactional = {2}")
+    @Parameters(name="IndexIT_localIndex={0},mutable={1},transactional={2}") // name is used by failsafe as file name in reports
     public static Collection<Boolean[]> data() {
         return Arrays.asList(new Boolean[][] {
                  { false, false, false }, { false, false, true }, { false, true, false }, { false, true, true },

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java
index 8c90b6e..4f0da4d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java
@@ -25,24 +25,36 @@ import static org.junit.Assert.assertTrue;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.MetaTableAccessor;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.end2end.BaseOwnClusterHBaseManagedTimeIT;
 import org.apache.phoenix.end2end.IndexToolIT;
+import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.mapreduce.index.IndexTool;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
+import org.apache.phoenix.util.TestUtil;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.google.common.collect.Maps;
 
-public class AsyncImmutableIndexIT extends BaseOwnClusterHBaseManagedTimeIT {
+public class IndexOnOwnClusterIT extends BaseOwnClusterHBaseManagedTimeIT {
     
     @BeforeClass
     public static void doSetup() throws Exception {
@@ -50,9 +62,9 @@ public class AsyncImmutableIndexIT extends BaseOwnClusterHBaseManagedTimeIT {
         serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB,
             QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
         setUpRealDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
-            ReadOnlyProps.EMPTY_PROPS);
+                ReadOnlyProps.EMPTY_PROPS);
     }
-    
+        
     @Test
     public void testDeleteFromImmutable() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
@@ -97,7 +109,7 @@ public class AsyncImmutableIndexIT extends BaseOwnClusterHBaseManagedTimeIT {
             String query = "SELECT pk3 from TEST_TABLE ORDER BY pk3";
             ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + query);
             String expectedPlan =
-                    "CLIENT 1-CHUNK PARALLEL 1-WAY FULL SCAN OVER TEST_INDEX\n"
+                    "CLIENT PARALLEL 1-WAY FULL SCAN OVER TEST_INDEX\n"
                             + "    SERVER FILTER BY FIRST KEY ONLY";
             assertEquals("Wrong plan ", expectedPlan, QueryUtil.getExplainPlan(rs));
             rs = conn.createStatement().executeQuery(query);
@@ -111,4 +123,202 @@ public class AsyncImmutableIndexIT extends BaseOwnClusterHBaseManagedTimeIT {
         }
     }
 
+    private Connection getConnection() throws SQLException{
+        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+        props.put(QueryServices.EXPLAIN_ROW_COUNT_ATTRIB,
+                Boolean.FALSE.toString());
+        props.put(QueryServices.EXPLAIN_CHUNK_COUNT_ATTRIB,
+                Boolean.FALSE.toString());
+        props.put(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB,
+                Boolean.TRUE.toString());
+        return DriverManager.getConnection(getUrl(),props);
+    }
+
+    private void createBaseTable(String tableName, String splits) throws SQLException {
+        Connection conn = getConnection();
+        String ddl = "CREATE TABLE " + tableName + " (t_id VARCHAR NOT NULL,\n" +
+                "k1 INTEGER NOT NULL,\n" +
+                "k2 INTEGER NOT NULL,\n" +
+                "k3 INTEGER,\n" +
+                "v1 VARCHAR,\n" +
+                "CONSTRAINT pk PRIMARY KEY (t_id, k1, k2))\n"
+                        + (splits != null ? (" split on " + splits) : "");
+        conn.createStatement().execute(ddl);
+        conn.close();
+    }
+
+    // Moved from LocalIndexIT because it was causing parallel runs to hang
+    @Test
+    public void testLocalIndexScanAfterRegionSplit() throws Exception {
+        String schemaName = generateRandomString();
+        String tableName = schemaName + "." + generateRandomString();
+        String indexName = "IDX_" + generateRandomString();
+        TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), false);
+        String indexPhysicalTableName = physicalTableName.getNameAsString();
+
+        createBaseTable(tableName, "('e','j','o')");
+        Connection conn1 = getConnection();
+        try{
+            String[] strings = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
+            for (int i = 0; i < 26; i++) {
+                conn1.createStatement().execute(
+                    "UPSERT INTO " + tableName + " values('"+strings[i]+"'," + i + ","
+                            + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')");
+            }
+            conn1.commit();
+            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)");
+            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + "_2 ON " + tableName + "(k3)");
+
+            ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + tableName);
+            assertTrue(rs.next());
+            
+            HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
+            for (int i = 1; i < 5; i++) {
+                admin.split(physicalTableName, ByteUtil.concat(Bytes.toBytes(strings[3*i])));
+                List<HRegionInfo> regionsOfUserTable =
+                        MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
+                                physicalTableName, false);
+
+                while (regionsOfUserTable.size() != (4+i)) {
+                    Thread.sleep(100);
+                    regionsOfUserTable = MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(),
+                            admin.getConnection(), physicalTableName, false);
+                }
+                assertEquals(4+i, regionsOfUserTable.size());
+                String[] tIdColumnValues = new String[26]; 
+                String[] v1ColumnValues = new String[26];
+                int[] k1ColumnValue = new int[26];
+                String query = "SELECT t_id,k1,v1 FROM " + tableName;
+                rs = conn1.createStatement().executeQuery(query);
+                Thread.sleep(1000);
+                for (int j = 0; j < 26; j++) {
+                    assertTrue(rs.next());
+                    tIdColumnValues[j] = rs.getString("t_id");
+                    k1ColumnValue[j] = rs.getInt("k1");
+                    v1ColumnValues[j] = rs.getString("V1");
+                }
+                Arrays.sort(tIdColumnValues);
+                Arrays.sort(v1ColumnValues);
+                Arrays.sort(k1ColumnValue);
+                assertTrue(Arrays.equals(strings, tIdColumnValues));
+                assertTrue(Arrays.equals(strings, v1ColumnValues));
+                for(int m=0;m<26;m++) {
+                    assertEquals(m, k1ColumnValue[m]);
+                }
+
+                rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
+                assertEquals(
+                        "CLIENT PARALLEL " + (4 + i) + "-WAY RANGE SCAN OVER "
+                                + indexPhysicalTableName + " [1]\n"
+                                        + "    SERVER FILTER BY FIRST KEY ONLY\n"
+                                + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+                
+                query = "SELECT t_id,k1,k3 FROM " + tableName;
+                rs = conn1.createStatement().executeQuery("EXPLAIN "+query);
+                assertEquals(
+                    "CLIENT PARALLEL "
+                            + ((strings[3 * i].compareTo("j") < 0) ? (4 + i) : (4 + i - 1))
+                            + "-WAY RANGE SCAN OVER "
+                            + indexPhysicalTableName + " [2]\n"
+                                    + "    SERVER FILTER BY FIRST KEY ONLY\n"
+                            + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+                rs = conn1.createStatement().executeQuery(query);
+                Thread.sleep(1000);
+                int[] k3ColumnValue = new int[26];
+                for (int j = 0; j < 26; j++) {
+                    assertTrue(rs.next());
+                    tIdColumnValues[j] = rs.getString("t_id");
+                    k1ColumnValue[j] = rs.getInt("k1");
+                    k3ColumnValue[j] = rs.getInt("k3");
+                }
+                Arrays.sort(tIdColumnValues);
+                Arrays.sort(k1ColumnValue);
+                Arrays.sort(k3ColumnValue);
+                assertTrue(Arrays.equals(strings, tIdColumnValues));
+                for(int m=0;m<26;m++) {
+                    assertEquals(m, k1ColumnValue[m]);
+                    assertEquals(m+2, k3ColumnValue[m]);
+                }
+            }
+       } finally {
+            conn1.close();
+        }
+    }
+
+    // Moved from LocalIndexIT because it was causing parallel runs to hang
+    @Test
+    public void testLocalIndexScanAfterRegionsMerge() throws Exception {
+        String schemaName = generateRandomString();
+        String tableName = schemaName + "." + generateRandomString();
+        String indexName = "IDX_" + generateRandomString();
+        TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), false);
+        String indexPhysicalTableName = physicalTableName.getNameAsString();
+
+        createBaseTable(tableName, "('e','j','o')");
+        Connection conn1 = getConnection();
+        try{
+            String[] strings = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
+            for (int i = 0; i < 26; i++) {
+                conn1.createStatement().execute(
+                    "UPSERT INTO " + tableName + " values('"+strings[i]+"'," + i + ","
+                            + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')");
+            }
+            conn1.commit();
+            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)");
+            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + "_2 ON " + tableName + "(k3)");
+
+            ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + tableName);
+            assertTrue(rs.next());
+
+            HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
+            List<HRegionInfo> regionsOfUserTable =
+                    MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
+                        physicalTableName, false);
+            admin.mergeRegions(regionsOfUserTable.get(0).getEncodedNameAsBytes(),
+                regionsOfUserTable.get(1).getEncodedNameAsBytes(), false);
+            regionsOfUserTable =
+                    MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
+                            physicalTableName, false);
+
+            while (regionsOfUserTable.size() != 3) {
+                Thread.sleep(100);
+                regionsOfUserTable = MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(),
+                        admin.getConnection(), physicalTableName, false);
+            }
+            String query = "SELECT t_id,k1,v1 FROM " + tableName;
+            rs = conn1.createStatement().executeQuery(query);
+            Thread.sleep(1000);
+            for (int j = 0; j < 26; j++) {
+                assertTrue(rs.next());
+                assertEquals(strings[25 - j], rs.getString("t_id"));
+                assertEquals(25 - j, rs.getInt("k1"));
+                assertEquals(strings[j], rs.getString("V1"));
+            }
+            rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
+            assertEquals(
+                "CLIENT PARALLEL " + 3 + "-WAY RANGE SCAN OVER "
+                        + indexPhysicalTableName
+                        + " [1]\n" + "    SERVER FILTER BY FIRST KEY ONLY\n"
+                        + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+
+            query = "SELECT t_id,k1,k3 FROM " + tableName;
+            rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
+            assertEquals(
+                "CLIENT PARALLEL " + 3 + "-WAY RANGE SCAN OVER "
+                        + indexPhysicalTableName
+                        + " [2]\n" + "    SERVER FILTER BY FIRST KEY ONLY\n"
+                        + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+
+            rs = conn1.createStatement().executeQuery(query);
+            Thread.sleep(1000);
+            for (int j = 0; j < 26; j++) {
+                assertTrue(rs.next());
+                assertEquals(strings[j], rs.getString("t_id"));
+                assertEquals(j, rs.getInt("k1"));
+                assertEquals(j + 2, rs.getInt("k3"));
+            }
+       } finally {
+            conn1.close();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
index c68d897..ff74dc8 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
@@ -115,7 +115,7 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
         setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet().iterator()));
     }
 
-    @Parameters(name = "transactional = {0}, localIndex = {1}, isNamespaceMapped = {2}")
+    @Parameters(name = "MutableIndexFailureIT_transactional={0},localIndex={1},isNamespaceMapped={2}") // name is used by failsafe as file name in reports
     public static Collection<Boolean[]> data() {
         return Arrays.asList(new Boolean[][] { { false, false, true }, { false, false, false }, { false, true, true },
                 { false, true, false }, { true, false, true }, { true, true, true }, { true, false, false },

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/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 1646538..6dc4657 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
@@ -70,11 +70,9 @@ public class MutableIndexIT extends BaseHBaseManagedTimeTableReuseIT {
     
     protected final boolean localIndex;
     private final String tableDDLOptions;
-	private  final boolean transactional;
 	
     public MutableIndexIT(boolean localIndex, boolean transactional) {
 		this.localIndex = localIndex;
-		this.transactional = transactional;
 		StringBuilder optionBuilder = new StringBuilder();
 		if (transactional) {
 			optionBuilder.append("TRANSACTIONAL=true");
@@ -92,7 +90,7 @@ public class MutableIndexIT extends BaseHBaseManagedTimeTableReuseIT {
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
 	
-	@Parameters(name="localIndex = {0} , transactional = {1}")
+	@Parameters(name="MutableIndexIT_localIndex={0},transactional={1}") // name is used by failsafe as file name in reports
     public static Collection<Boolean[]> data() {
         return Arrays.asList(new Boolean[][] {
                 { false, false }, { false, true }, { true, false }, { true, true }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ReadOnlyIndexFailureIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ReadOnlyIndexFailureIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ReadOnlyIndexFailureIT.java
index a3ad418..1dae126 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ReadOnlyIndexFailureIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ReadOnlyIndexFailureIT.java
@@ -95,7 +95,7 @@ public class ReadOnlyIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
         this.fullIndexName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, indexName);
     }
 
-    @Parameters(name = "localIndex = {0}")
+    @Parameters(name = "ReadOnlyIndexFailureIT_localIndex={0}") // name is used by failsafe as file name in reports
     public static Collection<Boolean[]> data() {
         return Arrays.asList(new Boolean[][] { { false }, { true } });
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
index f70397a..a886bca 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
@@ -48,7 +48,7 @@ import org.junit.runners.Parameterized.Parameters;
 public class ViewIndexIT extends BaseHBaseManagedTimeTableReuseIT {
     private boolean isNamespaceMapped;
 
-    @Parameters(name = "isNamespaceMapped = {0}")
+    @Parameters(name = "ViewIndexIT_isNamespaceMapped={0}") // name is used by failsafe as file name in reports
     public static Collection<Boolean> data() {
         return Arrays.asList(true, false);
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
index 9d61247..8562c0a 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
@@ -69,7 +69,7 @@ public class MutableRollbackIT extends BaseHBaseManagedTimeTableReuseIT {
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
 	
-	@Parameters(name="localIndex = {0}")
+	@Parameters(name="MutableRollbackIT_localIndex={0}") // name is used by failsafe as file name in reports
     public static Collection<Boolean> data() {
         return Arrays.asList(new Boolean[] { false, true});
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java
index 963263f..92a69d0 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java
@@ -66,7 +66,7 @@ public class RollbackIT extends BaseHBaseManagedTimeTableReuseIT {
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
 	
-	@Parameters(name="localIndex = {0} , mutable = {1}")
+	@Parameters(name="RollbackIT_localIndex={0},mutable={1}") // name is used by failsafe as file name in reports
     public static Collection<Boolean[]> data() {
         return Arrays.asList(new Boolean[][] {     
                  { false, false }, { false, true },

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/TxWriteFailureIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/TxWriteFailureIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/TxWriteFailureIT.java
index c7364dd..0202128 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/TxWriteFailureIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/TxWriteFailureIT.java
@@ -86,7 +86,7 @@ public class TxWriteFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
         setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet().iterator()));
     }
 	
-	@Parameters(name="localIndex = {0} , mutable = {1}")
+	@Parameters(name="TxWriteFailureIT_localIndex={0},mutable={1}") // name is used by failsafe as file name in reports
     public static Collection<Boolean[]> data() {
         return Arrays.asList(new Boolean[][] {
                  { false, false }, { false, true }, { true, false }, { true, true }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/execute/PartialCommitIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/execute/PartialCommitIT.java b/phoenix-core/src/it/java/org/apache/phoenix/execute/PartialCommitIT.java
index 7ba6889..6758abc 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/execute/PartialCommitIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/execute/PartialCommitIT.java
@@ -67,8 +67,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
 
 @RunWith(Parameterized.class)
-// Needs to extend BaseOwnClusterIT (and not BaseOwnClusterHBaseManagedTimeIT since table data 
-// is created and populated once in the constructor 
+// Needs to extend BaseOwnClusterIT due to installation of FailingRegionObserver coprocessor
 public class PartialCommitIT extends BaseOwnClusterIT {
     
 	private final String A_SUCESS_TABLE;
@@ -93,7 +92,7 @@ public class PartialCommitIT extends BaseOwnClusterIT {
         createTablesWithABitOfData();
     }
     
-    @Parameters(name="transactional = {0}")
+    @Parameters(name="PartialCommitIT_transactional={0}") // name is used by failsafe as file name in reports
     public static Collection<Boolean> data() {
         return Arrays.asList(false, true);
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4c8bda15/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
index 9f47a1e..8f877ac 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
@@ -41,14 +41,13 @@ import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
 import org.apache.phoenix.util.SchemaUtil;
+import org.apache.tephra.Transaction.VisibilityLevel;
 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 org.apache.tephra.Transaction.VisibilityLevel;
-
 import com.google.common.collect.Maps;
 
 @RunWith(Parameterized.class)
@@ -72,7 +71,7 @@ public class TxCheckpointIT extends BaseHBaseManagedTimeTableReuseIT {
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
 	
-	@Parameters(name="localIndex = {0} , mutable = {1}")
+	@Parameters(name="TxCheckpointIT_localIndex={0},mutable={1}") // name is used by failsafe as file name in reports
     public static Collection<Boolean[]> data() {
         return Arrays.asList(new Boolean[][] {     
                  { false, false }, { false, true }, { true, false }, { true, true }  


[15/47] phoenix git commit: PHOENIX-3230 Addendum to use the physical name of system catalog and other tweaks/cleanup

Posted by ma...@apache.org.
PHOENIX-3230 Addendum to use the physical name of system catalog and other tweaks/cleanup


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

Branch: refs/heads/calcite
Commit: 8e082fb5bbace7a495c5b727b2f781bba3b67cd1
Parents: d9eb45e
Author: Samarth <sa...@salesforce.com>
Authored: Fri Sep 9 14:44:46 2016 -0700
Committer: Samarth <sa...@salesforce.com>
Committed: Fri Sep 9 14:44:46 2016 -0700

----------------------------------------------------------------------
 .../phoenix/coprocessor/MetaDataProtocol.java   |  3 ++-
 .../query/ConnectionQueryServicesImpl.java      | 27 ++++++++++----------
 .../apache/phoenix/query/QueryConstants.java    |  2 +-
 3 files changed, 17 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/8e082fb5/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java
index 20922e5..3b57981 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java
@@ -83,8 +83,9 @@ public abstract class MetaDataProtocol extends MetaDataService {
     public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_6_0 = MIN_TABLE_TIMESTAMP + 9;
     public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 = MIN_TABLE_TIMESTAMP + 15;
     public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0 = MIN_TABLE_TIMESTAMP + 18;
+    public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_8_1 = MIN_TABLE_TIMESTAMP + 18;
     // MIN_SYSTEM_TABLE_TIMESTAMP needs to be set to the max of all the MIN_SYSTEM_TABLE_TIMESTAMP_* constants
-    public static final long MIN_SYSTEM_TABLE_TIMESTAMP = MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0;
+    public static final long MIN_SYSTEM_TABLE_TIMESTAMP = MIN_SYSTEM_TABLE_TIMESTAMP_4_8_1;
     
     // ALWAYS update this map whenever rolling out a new release (major, minor or patch release). 
     // Key is the SYSTEM.CATALOG timestamp for the version and value is the version string.

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8e082fb5/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index c5d53c3..607ad5e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -19,7 +19,7 @@ package org.apache.phoenix.query;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static org.apache.hadoop.hbase.HColumnDescriptor.TTL;
 import static org.apache.phoenix.coprocessor.MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP;
-import static org.apache.phoenix.coprocessor.MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0;
+import static org.apache.phoenix.coprocessor.MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_1;
 import static org.apache.phoenix.coprocessor.MetaDataProtocol.PHOENIX_MAJOR_VERSION;
 import static org.apache.phoenix.coprocessor.MetaDataProtocol.PHOENIX_MINOR_VERSION;
 import static org.apache.phoenix.coprocessor.MetaDataProtocol.PHOENIX_PATCH_NUMBER;
@@ -2329,7 +2329,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                                 if (upgradeSystemTables) {
                                     long currentServerSideTableTimeStamp = e.getTable().getTimeStamp();
                                     sysCatalogTableName = e.getTable().getPhysicalName().getString();
-                                    if (currentServerSideTableTimeStamp < MIN_SYSTEM_TABLE_TIMESTAMP && acquireUpgradeMutex(currentServerSideTableTimeStamp)) {
+                                    if (currentServerSideTableTimeStamp < MIN_SYSTEM_TABLE_TIMESTAMP && acquireUpgradeMutex(currentServerSideTableTimeStamp, e.getTable().getPhysicalName().getBytes())) {
                                         snapshotName = getUpgradeSnapshotName(sysCatalogTableName, currentServerSideTableTimeStamp);
                                         createSnapshot(snapshotName, sysCatalogTableName);
                                     }
@@ -2727,9 +2727,9 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                  * making use of HBase's checkAndPut api.
                  * <p>
                  * This method was added as part of 4.8.1 release. For clients upgrading to 4.8.1, the old value in the
-                 * version cell will be null i.e. the QueryConstants#VERSION column will be non-existent. For client's
+                 * version cell will be null i.e. the {@value QueryConstants#UPGRADE_MUTEX} column will be non-existent. For client's
                  * upgrading to a release newer than 4.8.1 the existing version cell will be non-null. The client which
-                 * wins the race will end up setting the version cell to the MetadataProtocol#MIN_SYSTEM_TABLE_TIMESTAMP
+                 * wins the race will end up setting the version cell to the {@value MetaDataProtocol#MIN_SYSTEM_TABLE_TIMESTAMP}
                  * for the release.
                  * </p>
                  * 
@@ -2737,19 +2737,20 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                  * @throws IOException
                  * @throws SQLException
                  */
-                private boolean acquireUpgradeMutex(long currentServerSideTableTimestamp) throws IOException,
+                private boolean acquireUpgradeMutex(long currentServerSideTableTimestamp, byte[] sysCatalogTableName) throws IOException,
                         SQLException {
                     Preconditions.checkArgument(currentServerSideTableTimestamp < MIN_SYSTEM_TABLE_TIMESTAMP);
-                    try (HTableInterface sysCatalogTable = getTable(SYSTEM_CATALOG_NAME_BYTES)) {
+                    try (HTableInterface sysCatalogTable = getTable(sysCatalogTableName)) {
                         byte[] row = SchemaUtil.getTableKey(null, PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA,
-                                PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME);
+                                PhoenixDatabaseMetaData.SYSTEM_CATALOG_TABLE);
                         byte[] family = PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES;
-                        byte[] qualifier = QueryConstants.VERSION;
-                        byte[] oldValue = currentServerSideTableTimestamp < MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0 ? null
-                                : Bytes.toBytes(currentServerSideTableTimestamp);
-                        byte[] newValue = Bytes.toBytes(MIN_SYSTEM_TABLE_TIMESTAMP);
-                        long ts = MIN_SYSTEM_TABLE_TIMESTAMP;
-                        Put put = new Put(row, ts);
+                        byte[] qualifier = QueryConstants.UPGRADE_MUTEX;
+                        byte[] oldValue = currentServerSideTableTimestamp < MIN_SYSTEM_TABLE_TIMESTAMP_4_8_1 ? null
+                                : PLong.INSTANCE.toBytes(currentServerSideTableTimestamp);
+                        byte[] newValue = PLong.INSTANCE.toBytes(MIN_SYSTEM_TABLE_TIMESTAMP);
+                        // Note that the timestamp for this put doesn't really matter since UPGRADE_MUTEX column isn't used
+                        // to calculate SYSTEM.CATALOG's server side timestamp.
+                        Put put = new Put(row);
                         put.add(family, qualifier, newValue);
                         boolean acquired = sysCatalogTable.checkAndPut(row, family, qualifier, oldValue, put);
                         if (!acquired) { throw new UpgradeInProgressException(

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8e082fb5/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
index 3077943..7e5f7a2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
@@ -356,6 +356,6 @@ public interface QueryConstants {
     public static final byte[] OFFSET_FAMILY = "f_offset".getBytes();
     public static final byte[] OFFSET_COLUMN = "c_offset".getBytes();
     public static final String LAST_SCAN = "LAST_SCAN";
-    public static final byte[] VERSION = "VERSION".getBytes();
+    public static final byte[] UPGRADE_MUTEX = "UPGRADE_MUTEX".getBytes();
 
 }


[21/47] phoenix git commit: PHOENIX-3250 Remove static member variables to enable method-level parallelization

Posted by ma...@apache.org.
PHOENIX-3250 Remove static member variables to enable method-level parallelization


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

Branch: refs/heads/calcite
Commit: 850b02c6d7798a7ed466af3de4256da3aaa1616e
Parents: 2772299
Author: James Taylor <ja...@apache.org>
Authored: Tue Sep 13 23:48:34 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Tue Sep 13 23:48:34 2016 -0700

----------------------------------------------------------------------
 .../end2end/ArrayToStringFunctionIT.java        | 78 ++++++++++----------
 .../apache/phoenix/end2end/PrimitiveTypeIT.java | 60 ++++++++++-----
 .../phoenix/end2end/RegexpSplitFunctionIT.java  | 52 ++++++-------
 .../apache/phoenix/end2end/StoreNullsIT.java    | 56 +++++++-------
 .../phoenix/end2end/ToCharFunctionIT.java       | 11 +--
 5 files changed, 135 insertions(+), 122 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/850b02c6/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayToStringFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayToStringFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayToStringFunctionIT.java
index 0439033..86ff7b6 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayToStringFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayToStringFunctionIT.java
@@ -21,22 +21,26 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import java.sql.*;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
 
-import org.junit.BeforeClass;
+import org.junit.Before;
 import org.junit.Test;
 
 public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
-    private static final String REGIONS = generateRandomString();
-    private static Connection conn = null;
+    private String tableName;
+    private Connection conn;
 
-    @BeforeClass
-    public static void initTables() throws Exception {
+    @Before
+    public void initTables() throws Exception {
         conn = DriverManager.getConnection(getUrl());
-        String ddl = "CREATE TABLE " + REGIONS
+        tableName = generateRandomString();
+        String ddl = "CREATE TABLE " + tableName
             + " (region_name VARCHAR PRIMARY KEY,varchars VARCHAR[],integers INTEGER[],doubles DOUBLE[],bigints BIGINT[],chars CHAR(15)[],double1 DOUBLE,varchar1 VARCHAR,nullcheck INTEGER,chars2 CHAR(15)[])";
         conn.createStatement().execute(ddl);
-        String dml = "UPSERT INTO " + REGIONS
+        String dml = "UPSERT INTO " + tableName
             + "(region_name,varchars,integers,doubles,bigints,chars,double1,varchar1,nullcheck,chars2) VALUES('SF Bay Area',"
             +
                 "ARRAY['2345','46345','23234']," +
@@ -58,7 +62,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionVarchar1() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(varchars, ',','*') FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(varchars, ',','*') FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -72,7 +76,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionVarchar2() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(varchars, ',') FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(varchars, ',') FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -86,7 +90,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionVarchar3() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(ARRAY['hello', 'hello'], ',') FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(ARRAY['hello', 'hello'], ',') FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -100,7 +104,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionInt() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(integers, ',') FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(integers, ',') FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -114,7 +118,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionDouble1() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(doubles, ', ') FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(doubles, ', ') FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -128,7 +132,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionDouble2() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(ARRAY[2.3, 4.5], ', ') FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(ARRAY[2.3, 4.5], ', ') FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -142,7 +146,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionBigint() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(bigints, ', ') FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(bigints, ', ') FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -156,7 +160,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionChar1() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(chars, ', ') FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(chars, ', ') FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -170,7 +174,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionChar2() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(chars2, ', ') FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(chars2, ', ') FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -184,7 +188,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionChar3() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(chars2, varchar1) FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(chars2, varchar1) FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -198,7 +202,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionWithNestedFunctions1() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(ARRAY[integers[1],integers[1]], ', ') FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(ARRAY[integers[1],integers[1]], ', ') FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -213,7 +217,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
             "SELECT ARRAY_TO_STRING(ARRAY[ARRAY_ELEM(ARRAY[2,4],1),ARRAY_ELEM(ARRAY[2,4],2)], ', ') FROM "
-                + REGIONS + " WHERE region_name = 'SF Bay Area'");
+                + tableName + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
         String expected = "2, 4";
@@ -227,7 +231,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
             "SELECT ARRAY_TO_STRING(ARRAY[ARRAY_ELEM(doubles, 1), ARRAY_ELEM(doubles, 1)], ', ') FROM "
-                + REGIONS + " WHERE region_name = 'SF Bay Area'");
+                + tableName + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
         String expected = "23.45, 23.45";
@@ -241,7 +245,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
             "SELECT ARRAY_ELEM(ARRAY_APPEND(ARRAY['abc','bcd'], ARRAY_TO_STRING(ARRAY['a','b'], 'c')), 3) FROM "
-                + REGIONS + " WHERE region_name = 'SF Bay Area'");
+                + tableName + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
         String expected = "acb";
@@ -465,7 +469,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     @Test
     public void testArrayToStringFunctionInWhere1() throws Exception {
         ResultSet rs;
-        rs = conn.createStatement().executeQuery("SELECT region_name FROM " + REGIONS
+        rs = conn.createStatement().executeQuery("SELECT region_name FROM " + tableName
             + " WHERE '2345,46345,23234,456' = ARRAY_TO_STRING(integers,',')");
         assertTrue(rs.next());
 
@@ -476,7 +480,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     @Test
     public void testArrayToStringFunctionInWhere2() throws Exception {
         ResultSet rs;
-        rs = conn.createStatement().executeQuery("SELECT region_name FROM " + REGIONS
+        rs = conn.createStatement().executeQuery("SELECT region_name FROM " + tableName
             + " WHERE 'a,b,c' = ARRAY_TO_STRING(ARRAY['a', 'b', 'c'], ',')");
         assertTrue(rs.next());
 
@@ -487,7 +491,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     @Test
     public void testArrayToStringFunctionInWhere3() throws Exception {
         ResultSet rs;
-        rs = conn.createStatement().executeQuery("SELECT region_name FROM " + REGIONS
+        rs = conn.createStatement().executeQuery("SELECT region_name FROM " + tableName
             + " WHERE '1.1,2.2,3.3' = ARRAY_TO_STRING(ARRAY[1.1, 2.2, 3.3], ',')");
         assertTrue(rs.next());
 
@@ -498,7 +502,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     @Test
     public void testArrayToStringFunctionInWhere4() throws Exception {
         ResultSet rs;
-        rs = conn.createStatement().executeQuery("SELECT region_name FROM " + REGIONS
+        rs = conn.createStatement().executeQuery("SELECT region_name FROM " + tableName
             + " WHERE 'true,true,true' = ARRAY_TO_STRING(ARRAY[true, true, true], ',')");
         assertTrue(rs.next());
 
@@ -510,7 +514,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionInWhere5() throws Exception {
 
         ResultSet rs;
-        rs = conn.createStatement().executeQuery("SELECT region_name FROM " + REGIONS
+        rs = conn.createStatement().executeQuery("SELECT region_name FROM " + tableName
             + " WHERE 'a, bbbb, c, ddd, e' = ARRAY_TO_STRING(ARRAY['a', 'bbbb', 'c' , 'ddd', 'e'], ', ')");
         assertTrue(rs.next());
 
@@ -521,7 +525,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     @Test
     public void testArrayToStringFunctionInWhere6() throws Exception {
         ResultSet rs;
-        rs = conn.createStatement().executeQuery("SELECT region_name FROM " + REGIONS
+        rs = conn.createStatement().executeQuery("SELECT region_name FROM " + tableName
             + " WHERE ARRAY_TO_STRING(ARRAY[1,2,3], varchar1) = '1, 2, 3'");
         assertTrue(rs.next());
 
@@ -532,7 +536,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     @Test
     public void testArrayToStringFunctionInWhere7() throws Exception {
         ResultSet rs;
-        rs = conn.createStatement().executeQuery("SELECT region_name FROM " + REGIONS
+        rs = conn.createStatement().executeQuery("SELECT region_name FROM " + tableName
             + " WHERE ARRAY_TO_STRING(varchars, varchar1) = '2345, 46345, 23234'");
         assertTrue(rs.next());
 
@@ -544,7 +548,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionWithNulls1() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(ARRAY['a', NULL, 'b'], ', ','*') FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(ARRAY['a', NULL, 'b'], ', ','*') FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -558,7 +562,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionWithNulls2() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(ARRAY['a', NULL, 'b'], ', ') FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(ARRAY['a', NULL, 'b'], ', ') FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -572,7 +576,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionWithNulls3() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(ARRAY[NULL, 'a', 'b'], ', ', '*') FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(ARRAY[NULL, 'a', 'b'], ', ', '*') FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -586,7 +590,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionWithNulls4() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(ARRAY[NULL, 'a', 'b'], ', ') FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(ARRAY[NULL, 'a', 'b'], ', ') FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -600,7 +604,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionWithNulls5() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(ARRAY['a', 'b', NULL], ', ', '*') FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(ARRAY['a', 'b', NULL], ', ', '*') FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -614,7 +618,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testArrayToStringFunctionWithNulls6() throws Exception {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
-            "SELECT ARRAY_TO_STRING(ARRAY['a', 'b', NULL], ', ') FROM " + REGIONS
+            "SELECT ARRAY_TO_STRING(ARRAY['a', 'b', NULL], ', ') FROM " + tableName
                 + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
@@ -629,7 +633,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
             "SELECT ARRAY_TO_STRING(ARRAY[NULL, NULL, 'a', 'b', NULL, 'c', 'd', NULL, 'e', NULL, NULL], ', ', '*') FROM "
-                + REGIONS + " WHERE region_name = 'SF Bay Area'");
+                + tableName + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
         String expected = "*, *, a, b, *, c, d, *, e, *, *";
@@ -643,7 +647,7 @@ public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         ResultSet rs;
         rs = conn.createStatement().executeQuery(
             "SELECT ARRAY_TO_STRING(ARRAY[NULL, NULL, 'a', 'b', NULL, 'c', 'd', NULL, 'e', NULL, NULL], ', ') FROM "
-                + REGIONS + " WHERE region_name = 'SF Bay Area'");
+                + tableName + " WHERE region_name = 'SF Bay Area'");
         assertTrue(rs.next());
 
         String expected = "a, b, c, d, e";

http://git-wip-us.apache.org/repos/asf/phoenix/blob/850b02c6/phoenix-core/src/it/java/org/apache/phoenix/end2end/PrimitiveTypeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PrimitiveTypeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PrimitiveTypeIT.java
index b78d144..5891a62 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PrimitiveTypeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PrimitiveTypeIT.java
@@ -29,23 +29,18 @@ import java.util.Properties;
 
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.TestUtil;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 
 public class PrimitiveTypeIT extends BaseHBaseManagedTimeTableReuseIT {
 
-    private static final String TABLE_NAME = generateRandomString();
     private static final Properties PROPS = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
-    private static Connection conn;
 
-    @BeforeClass
-    public static void initTableValues() throws Exception {
-        conn = DriverManager.getConnection(getUrl(), PROPS);
+    public static void initTableValues(Connection conn, String tableName) throws Exception {
         conn.createStatement().execute(
-            "create table " + TABLE_NAME + " (l bigint not null primary key, b boolean)");
+            "create table " + tableName + " (l bigint not null primary key, b boolean)");
         PreparedStatement stmt = conn.prepareStatement(
-                "upsert into " + TABLE_NAME + " VALUES(?)");
+                "upsert into " + tableName + " VALUES(?)");
         stmt.setLong(1, 2);
         stmt.execute();
         conn.commit();
@@ -53,7 +48,10 @@ public class PrimitiveTypeIT extends BaseHBaseManagedTimeTableReuseIT {
 
     @Test
     public void testCompareLongGTDecimal() throws Exception {
-        String query = "SELECT l FROM " + TABLE_NAME + " where l > 1.5";
+        String tableName = generateRandomString();
+        Connection conn = DriverManager.getConnection(getUrl(), PROPS);
+        initTableValues(conn, tableName);
+        String query = "SELECT l FROM " + tableName + " where l > 1.5";
         try {
             PreparedStatement statement = conn.prepareStatement(query);
             ResultSet rs = statement.executeQuery();
@@ -67,7 +65,10 @@ public class PrimitiveTypeIT extends BaseHBaseManagedTimeTableReuseIT {
     
     @Test
     public void testCompareLongGTEDecimal() throws Exception {
-        String query = "SELECT l FROM " + TABLE_NAME + " where l >= 1.5";
+        String tableName = generateRandomString();
+        Connection conn = DriverManager.getConnection(getUrl(), PROPS);
+        initTableValues(conn, tableName);
+        String query = "SELECT l FROM " + tableName + " where l >= 1.5";
         try {
             PreparedStatement statement = conn.prepareStatement(query);
             ResultSet rs = statement.executeQuery();
@@ -88,7 +89,10 @@ public class PrimitiveTypeIT extends BaseHBaseManagedTimeTableReuseIT {
     
     @Test
     public void testCompareLongLTDecimal() throws Exception {
-        String query = "SELECT l FROM " + TABLE_NAME + " where l < 1.5";
+        String tableName = generateRandomString();
+        Connection conn = DriverManager.getConnection(getUrl(), PROPS);
+        initTableValues(conn, tableName);
+        String query = "SELECT l FROM " + tableName + " where l < 1.5";
         try {
             PreparedStatement statement = conn.prepareStatement(query);
             ResultSet rs = statement.executeQuery();
@@ -107,7 +111,10 @@ public class PrimitiveTypeIT extends BaseHBaseManagedTimeTableReuseIT {
 
     @Test
     public void testCompareLongLTEDecimal() throws Exception {
-        String query = "SELECT l FROM " + TABLE_NAME + " where l <= 1.5";
+        String tableName = generateRandomString();
+        Connection conn = DriverManager.getConnection(getUrl(), PROPS);
+        initTableValues(conn, tableName);
+        String query = "SELECT l FROM " + tableName + " where l <= 1.5";
         try {
             PreparedStatement statement = conn.prepareStatement(query);
             ResultSet rs = statement.executeQuery();
@@ -125,7 +132,10 @@ public class PrimitiveTypeIT extends BaseHBaseManagedTimeTableReuseIT {
     }
     @Test
     public void testCompareLongGTDecimal2() throws Exception {
-        String query = "SELECT l FROM " + TABLE_NAME + " where l > 2.5";
+        String tableName = generateRandomString();
+        Connection conn = DriverManager.getConnection(getUrl(), PROPS);
+        initTableValues(conn, tableName);
+        String query = "SELECT l FROM " + tableName + " where l > 2.5";
         try {
             PreparedStatement statement = conn.prepareStatement(query);
             ResultSet rs = statement.executeQuery();
@@ -144,7 +154,10 @@ public class PrimitiveTypeIT extends BaseHBaseManagedTimeTableReuseIT {
     
     @Test
     public void testCompareLongGTEDecimal2() throws Exception {
-        String query = "SELECT l FROM " + TABLE_NAME + " where l >= 2.5";
+        String tableName = generateRandomString();
+        Connection conn = DriverManager.getConnection(getUrl(), PROPS);
+        initTableValues(conn, tableName);
+        String query = "SELECT l FROM " + tableName + " where l >= 2.5";
         try {
             PreparedStatement statement = conn.prepareStatement(query);
             ResultSet rs = statement.executeQuery();
@@ -163,7 +176,10 @@ public class PrimitiveTypeIT extends BaseHBaseManagedTimeTableReuseIT {
     
     @Test
     public void testCompareLongLTDecimal2() throws Exception {
-        String query = "SELECT l FROM " + TABLE_NAME + " where l < 2.5";
+        String tableName = generateRandomString();
+        Connection conn = DriverManager.getConnection(getUrl(), PROPS);
+        initTableValues(conn, tableName);
+        String query = "SELECT l FROM " + tableName + " where l < 2.5";
         try {
             PreparedStatement statement = conn.prepareStatement(query);
             ResultSet rs = statement.executeQuery();
@@ -184,9 +200,10 @@ public class PrimitiveTypeIT extends BaseHBaseManagedTimeTableReuseIT {
 
     @Test
     public void testCompareLongLTEDecimal2() throws Exception {
-        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
-        Connection conn = DriverManager.getConnection(getUrl(), props);
-        String query = "SELECT l FROM " + TABLE_NAME + " where l <= 2.5";
+        String tableName = generateRandomString();
+        Connection conn = DriverManager.getConnection(getUrl(), PROPS);
+        initTableValues(conn, tableName);
+        String query = "SELECT l FROM " + tableName + " where l <= 2.5";
         try {
             PreparedStatement statement = conn.prepareStatement(query);
             ResultSet rs = statement.executeQuery();
@@ -207,13 +224,16 @@ public class PrimitiveTypeIT extends BaseHBaseManagedTimeTableReuseIT {
     
     @Test
     public void testBooleanAsObject() throws Exception {
-        String query = "upsert into " + TABLE_NAME + " values (2, ?)";
+        String tableName = generateRandomString();
+        Connection conn = DriverManager.getConnection(getUrl(), PROPS);
+        initTableValues(conn, tableName);
+        String query = "upsert into " + tableName + " values (2, ?)";
         try {
             PreparedStatement statement = conn.prepareStatement(query);
             statement.setObject(1, new Boolean("false"));
             statement.execute();
             conn.commit();
-            statement = conn.prepareStatement("SELECT l,b,? FROM " + TABLE_NAME);
+            statement = conn.prepareStatement("SELECT l,b,? FROM " + tableName);
             statement.setObject(1, new Boolean("false"));
             ResultSet rs = statement.executeQuery();
             assertTrue(rs.next());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/850b02c6/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSplitFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSplitFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSplitFunctionIT.java
index 6df4829..806d589 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSplitFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSplitFunctionIT.java
@@ -31,32 +31,26 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Types;
 
-import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 
 public class RegexpSplitFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
 
-    private static final String SPLIT_TEST = generateRandomString();
-
-    @BeforeClass
-    public static void setup() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        String ddl = "CREATE TABLE " + SPLIT_TEST + " (" +
-            "ID INTEGER NOT NULL PRIMARY KEY," +
-            "VAL VARCHAR," +
-            "SEP VARCHAR," +
-            "ARR VARCHAR ARRAY)";
-        conn.createStatement().execute(ddl);
-    }
+    private String tableName;
 
     private void initTable(Connection conn, String val) throws SQLException {
         initTable(conn, val, ",");
     }
 
     private void initTable(Connection conn, String val, String separator) throws SQLException {
-        String dml = "UPSERT INTO " + SPLIT_TEST + " (ID, SEP, VAL) VALUES (?, ?, ?)";
+        tableName = generateRandomString();
+        String ddl = "CREATE TABLE " + tableName + " (" +
+                "ID INTEGER NOT NULL PRIMARY KEY," +
+                "VAL VARCHAR," +
+                "SEP VARCHAR," +
+                "ARR VARCHAR ARRAY)";
+            conn.createStatement().execute(ddl);
+        String dml = "UPSERT INTO " + tableName + " (ID, SEP, VAL) VALUES (?, ?, ?)";
         PreparedStatement stmt = conn.prepareStatement(dml);
         stmt.setInt(1, 1);
         if (separator == null) {
@@ -79,7 +73,7 @@ public class RegexpSplitFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         initTable(conn, "ONE,TWO,THREE");
 
         ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT REGEXP_SPLIT(VAL, ',')[1] FROM " + SPLIT_TEST);
+            "SELECT REGEXP_SPLIT(VAL, ',')[1] FROM " + tableName);
         assertTrue(rs.next());
         assertEquals("ONE", rs.getString(1));
         assertFalse(rs.next());
@@ -96,7 +90,7 @@ public class RegexpSplitFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         initTable(conn, val);
 
         ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT array_length(REGEXP_SPLIT(VAL, ',')) FROM " + SPLIT_TEST);
+            "SELECT array_length(REGEXP_SPLIT(VAL, ',')) FROM " + tableName);
         assertTrue(rs.next());
         assertEquals(33267, rs.getInt(1));
         assertFalse(rs.next());
@@ -108,7 +102,7 @@ public class RegexpSplitFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         initTable(conn, "ONE,TWO,THREE");
 
         ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT ID FROM " + SPLIT_TEST + " WHERE (REGEXP_SPLIT(VAL, ','))[1] = 'ONE'");
+            "SELECT ID FROM " + tableName + " WHERE (REGEXP_SPLIT(VAL, ','))[1] = 'ONE'");
         assertTrue(rs.next());
         assertEquals(1, rs.getInt(1));
         assertFalse(rs.next());
@@ -120,11 +114,11 @@ public class RegexpSplitFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         initTable(conn, "ONE,TWO,THREE");
 
         conn.createStatement().executeUpdate(
-            "UPSERT INTO " + SPLIT_TEST + " (ID, ARR) SELECT ID, " + "REGEXP_SPLIT(VAL, ',') FROM "
-                + SPLIT_TEST);
+            "UPSERT INTO " + tableName + " (ID, ARR) SELECT ID, " + "REGEXP_SPLIT(VAL, ',') FROM "
+                + tableName);
         conn.commit();
 
-        ResultSet rs = conn.createStatement().executeQuery("SELECT ARR FROM " + SPLIT_TEST);
+        ResultSet rs = conn.createStatement().executeQuery("SELECT ARR FROM " + tableName);
         assertTrue(rs.next());
         Array array = rs.getArray(1);
         String[] values = (String[]) array.getArray();
@@ -137,7 +131,7 @@ public class RegexpSplitFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         initTable(conn, "ONE:TWO:THREE");
 
         ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT REGEXP_SPLIT(VAL, ':') FROM " + SPLIT_TEST);
+            "SELECT REGEXP_SPLIT(VAL, ':') FROM " + tableName);
         assertTrue(rs.next());
         Array array = rs.getArray(1);
         String[] values = (String[]) array.getArray();
@@ -150,7 +144,7 @@ public class RegexpSplitFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         initTable(conn, "ONE,TWO,THREE");
 
         ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT REGEXP_SPLIT(VAL, SEP) FROM " + SPLIT_TEST);
+            "SELECT REGEXP_SPLIT(VAL, SEP) FROM " + tableName);
         assertTrue(rs.next());
         Array array = rs.getArray(1);
         String[] values = (String[]) array.getArray();
@@ -163,7 +157,7 @@ public class RegexpSplitFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         initTable(conn, "CANNOT BE SPLIT");
 
         ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT REGEXP_SPLIT(VAL, ',') FROM " + SPLIT_TEST);
+            "SELECT REGEXP_SPLIT(VAL, ',') FROM " + tableName);
         assertTrue(rs.next());
         Array array = rs.getArray(1);
         String[] values = (String[]) array.getArray();
@@ -176,7 +170,7 @@ public class RegexpSplitFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         initTable(conn, "ONE!:TWO:::!THREE::!:FOUR");
 
         ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT REGEXP_SPLIT(VAL, '[:!]+') FROM " + SPLIT_TEST);
+            "SELECT REGEXP_SPLIT(VAL, '[:!]+') FROM " + tableName);
         assertTrue(rs.next());
         Array array = rs.getArray(1);
         String[] values = (String[]) array.getArray();
@@ -189,7 +183,7 @@ public class RegexpSplitFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         initTable(conn, "ONE|TWO|THREE");
 
         ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT REGEXP_SPLIT(VAL, '\\\\|') FROM " + SPLIT_TEST);
+            "SELECT REGEXP_SPLIT(VAL, '\\\\|') FROM " + tableName);
         assertTrue(rs.next());
         Array array = rs.getArray(1);
         String[] values = (String[]) array.getArray();
@@ -202,7 +196,7 @@ public class RegexpSplitFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         initTable(conn, null);
 
         ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT REGEXP_SPLIT(VAL, ',') FROM " + SPLIT_TEST);
+            "SELECT REGEXP_SPLIT(VAL, ',') FROM " + tableName);
         assertTrue(rs.next());
         assertNull(rs.getString(1));
         assertFalse(rs.next());
@@ -214,7 +208,7 @@ public class RegexpSplitFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         initTable(conn, "ONE,TWO,THREE");
 
         ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT REGEXP_SPLIT(VAL, NULL) FROM " + SPLIT_TEST);
+            "SELECT REGEXP_SPLIT(VAL, NULL) FROM " + tableName);
         assertTrue(rs.next());
         assertNull(rs.getString(1));
         assertFalse(rs.next());
@@ -226,7 +220,7 @@ public class RegexpSplitFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
         initTable(conn, "ONE,TWO,THREE", null);
 
         ResultSet rs = conn.createStatement().executeQuery(
-            "SELECT REGEXP_SPLIT(VAL, SEP) FROM " + SPLIT_TEST);
+            "SELECT REGEXP_SPLIT(VAL, SEP) FROM " + tableName);
         assertTrue(rs.next());
         assertNull(rs.getString(1));
         assertFalse(rs.next());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/850b02c6/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
index 836418c..363198c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
@@ -17,7 +17,20 @@
  */
 package org.apache.phoenix.end2end;
 
-import com.google.common.collect.Lists;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Properties;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hbase.HConstants;
@@ -34,22 +47,10 @@ import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.SchemaUtil;
 import org.junit.After;
-import org.junit.BeforeClass;
+import org.junit.Before;
 import org.junit.Test;
 
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.List;
-import java.util.Properties;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import com.google.common.collect.Lists;
 
 /**
  * Tests to demonstrate and verify the STORE_NULLS option on a table,
@@ -58,18 +59,21 @@ import static org.junit.Assert.assertTrue;
  * also allows permanently deleting a row.
  */
 public class StoreNullsIT extends BaseHBaseManagedTimeTableReuseIT {
-
     private static final Log LOG = LogFactory.getLog(StoreNullsIT.class);
-    private static final String WITH_NULLS = generateRandomString();
-    private static final String WITHOUT_NULLS = generateRandomString();
-    private static final String IMMUTABLE_WITH_NULLS = generateRandomString();
-    private static final String IMMUTABLE_WITHOUT_NULLS = generateRandomString();
-
-    private static Connection conn;
-    private static Statement stmt;
-
-    @BeforeClass
-    public static void setUp() throws SQLException {
+    
+    private String WITH_NULLS;
+    private String WITHOUT_NULLS;
+    private String IMMUTABLE_WITH_NULLS;
+    private String IMMUTABLE_WITHOUT_NULLS;
+    private Connection conn;
+    private Statement stmt;
+
+    @Before
+    public void setUp() throws SQLException {
+        WITH_NULLS = generateRandomString();
+        WITHOUT_NULLS = generateRandomString();
+        IMMUTABLE_WITH_NULLS = generateRandomString();
+        IMMUTABLE_WITHOUT_NULLS = generateRandomString();
         conn = DriverManager.getConnection(getUrl());
         conn.setAutoCommit(true);
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/850b02c6/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java
index e976517..27d593a 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java
@@ -49,7 +49,7 @@ import org.junit.Test;
 
 public class ToCharFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     
-    private static String TO_CHAR_TABLE_NAME;
+    private String TO_CHAR_TABLE_NAME;
     
     private Date row1Date;
     private Time row1Time;
@@ -62,15 +62,6 @@ public class ToCharFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     private Integer row2Integer;
     private BigDecimal row2Decimal;
     
-    public static final String TO_CHAR_TABLE_DDL = "create table " + TO_CHAR_TABLE_NAME +
-        "(pk integer not null, \n" + 
-        "col_date date, \n" +
-        "col_time date, \n" +
-        "col_timestamp timestamp, \n" +
-        "col_integer integer, \n" + 
-        "col_decimal decimal\n" + 
-        "CONSTRAINT my_pk PRIMARY KEY (pk))";
-
     @Before
     @edu.umd.cs.findbugs.annotations.SuppressWarnings(
             value="DMI_BIGDECIMAL_CONSTRUCTED_FROM_DOUBLE", 


[28/47] phoenix git commit: PHOENIX-3253 Make changes in various classes for method level parallelization in BaseHBaseManagedTimeTableReuseIT

Posted by ma...@apache.org.
PHOENIX-3253 Make changes in various classes for method level parallelization in BaseHBaseManagedTimeTableReuseIT


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

Branch: refs/heads/calcite
Commit: 27697b364511f8557a87d4007bff1a560e4b8490
Parents: 2c2b552
Author: James Taylor <ja...@apache.org>
Authored: Thu Sep 15 00:22:33 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Thu Sep 15 00:28:46 2016 -0700

----------------------------------------------------------------------
 .../ConnectionQueryServicesTestImpl.java        |  7 ++-
 .../org/apache/phoenix/end2end/DeleteIT.java    | 10 ++--
 .../phoenix/end2end/PhoenixRuntimeIT.java       | 48 +++++++++-----------
 .../phoenix/end2end/index/ViewIndexIT.java      | 41 +++--------------
 .../trace/PhoenixTableMetricsWriterIT.java      | 22 +++++----
 .../phoenix/trace/PhoenixTraceReaderIT.java     | 16 ++++---
 .../phoenix/trace/PhoenixTracingEndToEndIT.java | 23 +++++-----
 .../org/apache/phoenix/tx/TransactionIT.java    | 27 ++++++-----
 .../phoenix/trace/PhoenixMetricsSink.java       |  5 +-
 .../org/apache/phoenix/trace/TraceReader.java   | 12 ++---
 10 files changed, 91 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/27697b36/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
index 48f392b..b1e264b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
@@ -20,6 +20,8 @@ package org.apache.phoenix.end2end;
 import static org.junit.Assert.assertEquals;
 
 import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Properties;
 import java.util.Set;
 
@@ -61,9 +63,10 @@ public class ConnectionQueryServicesTestImpl extends ConnectionQueryServicesImpl
     @Override
     public void close() throws SQLException {
         try {
-            Set<PhoenixConnection> connections;
+            Collection<PhoenixConnection> connections;
             synchronized(this) {
-                connections = this.connections;
+                // Make copy to prevent ConcurrentModificationException (TODO: figure out why this is necessary)
+                connections = new ArrayList<>(this.connections);
                 this.connections = Sets.newHashSet();
             }
             SQLCloseables.closeAll(connections);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/27697b36/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
index 865b1fd..5234d10 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
@@ -34,7 +34,6 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.phoenix.util.QueryUtil;
-import org.junit.Assert;
 import org.junit.Test;
 
 
@@ -506,16 +505,17 @@ public class DeleteIT extends BaseHBaseManagedTimeTableReuseIT {
     
     @Test
     public void testDeleteForTableWithRowTimestampColServer() throws Exception {
-        testDeleteForTableWithRowTimestampCol(true);
+        String tableName = generateRandomString();
+        testDeleteForTableWithRowTimestampCol(true, tableName);
     }
     
     @Test
     public void testDeleteForTableWithRowTimestampColClient() throws Exception {
-        testDeleteForTableWithRowTimestampCol(false);
+        String tableName = generateRandomString();
+        testDeleteForTableWithRowTimestampCol(false, tableName);
     }
     
-    private void testDeleteForTableWithRowTimestampCol(boolean autoCommit) throws Exception {
-        String tableName = "testDeleteForTableWithRowTimestampCol".toUpperCase();
+    private void testDeleteForTableWithRowTimestampCol(boolean autoCommit, String tableName) throws Exception {
         try (Connection conn = DriverManager.getConnection(getUrl())) {
             conn.setAutoCommit(autoCommit);
             Statement stm = conn.createStatement();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/27697b36/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
index 579eb19..c84a76c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
@@ -18,18 +18,17 @@
 package org.apache.phoenix.end2end;
 
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES;
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
+import java.util.HashSet;
 import java.util.Properties;
+import java.util.Set;
 
-import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.client.HTableInterface;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.ResultScanner;
@@ -53,7 +52,7 @@ import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.TestUtil;
 import org.junit.Test;
 
-import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
 
 public class PhoenixRuntimeIT extends BaseHBaseManagedTimeTableReuseIT {
     private static void assertTenantIds(Expression e, HTableInterface htable, Filter filter, String[] tenantIds) throws IOException {
@@ -63,17 +62,15 @@ public class PhoenixRuntimeIT extends BaseHBaseManagedTimeTableReuseIT {
         ResultScanner scanner = htable.getScanner(scan);
         Result result = null;
         ResultTuple tuple = new ResultTuple();
-        List<String> actualTenantIds = Lists.newArrayListWithExpectedSize(tenantIds.length);
-        List<String> expectedTenantIds = Arrays.asList(tenantIds);
+        Set<String> actualTenantIds = Sets.newHashSetWithExpectedSize(tenantIds.length);
+        Set<String> expectedTenantIds = new HashSet<>(Arrays.asList(tenantIds));
         while ((result = scanner.next()) != null) {
             tuple.setResult(result);
             e.evaluate(tuple, ptr);
             String tenantId = (String)PVarchar.INSTANCE.toObject(ptr);
             actualTenantIds.add(tenantId == null ? "" : tenantId);
         }
-        // Need to sort because of salting
-        Collections.sort(actualTenantIds);
-        assertEquals(expectedTenantIds, actualTenantIds);
+        assertTrue(actualTenantIds.containsAll(expectedTenantIds));
     }
     
     @Test
@@ -96,35 +93,34 @@ public class PhoenixRuntimeIT extends BaseHBaseManagedTimeTableReuseIT {
     }
     
     private void testGetTenantIdExpression(boolean isSalted) throws Exception {
-        //Have to delete metaData tables because BaseHBaseManagedTimeTableReuseIT doesn't delete them after each test case , and tenant list will create issues between test cases
-        deletePriorMetaData(HConstants.LATEST_TIMESTAMP, getUrl());
-
         Connection conn = DriverManager.getConnection(getUrl());
         conn.setAutoCommit(true);
         String tableName = generateRandomString() ;
-        String sequenceName = generateRandomString() ;
+        String sequenceName = generateRandomString();
+        String t1 = generateRandomString();
+        String t2 = t1 + generateRandomString(); // ensure bigger
         conn.createStatement().execute("CREATE TABLE " + tableName + " (k1 VARCHAR NOT NULL, k2 VARCHAR, CONSTRAINT PK PRIMARY KEY(K1,K2)) MULTI_TENANT=true" + (isSalted ? ",SALT_BUCKETS=3" : ""));
         conn.createStatement().execute("CREATE SEQUENCE "  + sequenceName);
-        conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('t1','x')");
-        conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('t2','y')");
+        conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('" + t1 + "','x')");
+        conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('" + t2 + "','y')");
         
         Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
-        props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, "t1");
+        props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, t1);
         Connection tsconn = DriverManager.getConnection(getUrl(), props);
         tsconn.createStatement().execute("CREATE SEQUENCE " + sequenceName);
         Expression e1 = PhoenixRuntime.getTenantIdExpression(tsconn, PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_NAME);
         HTableInterface htable1 = tsconn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_NAME_BYTES);
-        assertTenantIds(e1, htable1, new FirstKeyOnlyFilter(), new String[] {"", "t1"} );
+        assertTenantIds(e1, htable1, new FirstKeyOnlyFilter(), new String[] {"", t1} );
 
         String viewName = generateRandomString();
         tsconn.createStatement().execute("CREATE VIEW " + viewName + "(V1 VARCHAR) AS SELECT * FROM " + tableName);
         Expression e2 = PhoenixRuntime.getTenantIdExpression(tsconn, PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME);
         HTableInterface htable2 = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
-        assertTenantIds(e2, htable2, getUserTableAndViewsFilter(), new String[] {"", "t1"} );
+        assertTenantIds(e2, htable2, getUserTableAndViewsFilter(), new String[] {"", t1} );
         
         Expression e3 = PhoenixRuntime.getTenantIdExpression(conn, tableName);
         HTableInterface htable3 = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(tableName));
-        assertTenantIds(e3, htable3, new FirstKeyOnlyFilter(), new String[] {"t1", "t2"} );
+        assertTenantIds(e3, htable3, new FirstKeyOnlyFilter(), new String[] {t1, t2} );
 
         String basTableName = generateRandomString();
         conn.createStatement().execute("CREATE TABLE " + basTableName + " (k1 VARCHAR PRIMARY KEY)");
@@ -135,23 +131,21 @@ public class PhoenixRuntimeIT extends BaseHBaseManagedTimeTableReuseIT {
         tsconn.createStatement().execute("CREATE INDEX " + indexName1 + " ON " + viewName + "(V1)");
         Expression e5 = PhoenixRuntime.getTenantIdExpression(tsconn, indexName1);
         HTableInterface htable5 = tsconn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(MetaDataUtil.VIEW_INDEX_TABLE_PREFIX + tableName));
-        assertTenantIds(e5, htable5, new FirstKeyOnlyFilter(), new String[] {"t1"} );
+        assertTenantIds(e5, htable5, new FirstKeyOnlyFilter(), new String[] {t1} );
 
         String indexName2 = generateRandomString();
         conn.createStatement().execute("CREATE INDEX " + indexName2 + " ON " + tableName + "(k2)");
         Expression e6 = PhoenixRuntime.getTenantIdExpression(conn, indexName2);
         HTableInterface htable6 = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(indexName2));
-        assertTenantIds(e6, htable6, new FirstKeyOnlyFilter(), new String[] {"t1", "t2"} );
+        assertTenantIds(e6, htable6, new FirstKeyOnlyFilter(), new String[] {t1, t2} );
         
         tableName = generateRandomString() + "BAR_" + (isSalted ? "SALTED" : "UNSALTED");
         conn.createStatement().execute("CREATE TABLE " + tableName + " (k1 VARCHAR NOT NULL, k2 VARCHAR, CONSTRAINT PK PRIMARY KEY(K1,K2)) " + (isSalted ? "SALT_BUCKETS=3" : ""));
-        conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('t1','x')");
-        conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('t2','y')");
+        conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('" + t1 + "','x')");
+        conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('" + t2 + "','y')");
         Expression e7 = PhoenixRuntime.getFirstPKColumnExpression(conn, tableName);
         HTableInterface htable7 = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(tableName));
-        assertTenantIds(e7, htable7, new FirstKeyOnlyFilter(), new String[] {"t1", "t2"} );
-
-
+        assertTenantIds(e7, htable7, new FirstKeyOnlyFilter(), new String[] {t1, t2} );
     }
     
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/27697b36/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
index c985fc9..f70397a 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
@@ -31,53 +31,29 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Map;
 import java.util.Properties;
 
-import org.apache.hadoop.hbase.TableName;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
-import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.PNameFactory;
 import org.apache.phoenix.util.QueryUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
-import org.apache.phoenix.util.SchemaUtil;
-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 ViewIndexIT extends BaseHBaseManagedTimeTableReuseIT {
-
-
-    private String schemaName="TEST";
     private boolean isNamespaceMapped;
 
-
-    @BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
-    public static void doSetup() throws Exception {
-        Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
-        // Drop the HBase table metadata for this test to confirm that view index table dropped
-        props.put(QueryServices.DROP_METADATA_ATTRIB, Boolean.toString(true));
-        // Must update config before starting server
-        setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
-    }
-
     @Parameters(name = "isNamespaceMapped = {0}")
     public static Collection<Boolean> data() {
         return Arrays.asList(true, false);
     }
 
-    private void createBaseTable(String tableName, boolean multiTenant, Integer saltBuckets, String splits)
+    private void createBaseTable(String schemaName, String tableName, boolean multiTenant, Integer saltBuckets, String splits)
             throws SQLException {
         Connection conn = getConnection();
         if (isNamespaceMapped) {
@@ -104,9 +80,8 @@ public class ViewIndexIT extends BaseHBaseManagedTimeTableReuseIT {
         conn.close();
     }
     
-    public Connection getConnection() throws SQLException{
+    private Connection getConnection() throws SQLException{
         Properties props = new Properties();
-        props.put(QueryServices.DROP_METADATA_ATTRIB, Boolean.toString(true));
         props.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(isNamespaceMapped));
         return DriverManager.getConnection(getUrl(),props);
     }
@@ -117,14 +92,13 @@ public class ViewIndexIT extends BaseHBaseManagedTimeTableReuseIT {
 
     @Test
     public void testDeleteViewIndexSequences() throws Exception {
+        String schemaName = generateRandomString();
         String tableName = schemaName + "." + generateRandomString();
         String indexName = "IND_" + generateRandomString();
         String VIEW_NAME = "VIEW_" + generateRandomString();
-        TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped);
-        String viewIndexPhysicalTableName = physicalTableName.getNameAsString();
         String viewName = schemaName + "." + VIEW_NAME;
 
-        createBaseTable(tableName, false, null, null);
+        createBaseTable(schemaName, tableName, false, null, null);
         Connection conn1 = getConnection();
         Connection conn2 = getConnection();
         conn1.createStatement().execute("CREATE VIEW " + viewName + " AS SELECT * FROM " + tableName);
@@ -138,22 +112,19 @@ public class ViewIndexIT extends BaseHBaseManagedTimeTableReuseIT {
         // Check other format of sequence is not there as Sequences format is different for views/indexes created on
         // table which are namespace mapped and which are not.
         verifySequence(null, seqName, seqSchemaName, false);
-        HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin();
         conn1.createStatement().execute("DROP VIEW " + viewName);
         conn1.createStatement().execute("DROP TABLE "+ tableName);
-        admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin();
-        assertFalse("View index table should be deleted.", admin.tableExists(TableName.valueOf(viewIndexPhysicalTableName)));
         
         verifySequence(null, sequenceName, sequenceSchemaName, false);
-
     }
     
     @Test
     public void testMultiTenantViewLocalIndex() throws Exception {
+        String schemaName = generateRandomString();
         String tableName =  generateRandomString();
         String indexName = "IND_" + generateRandomString();
         String VIEW_NAME = "VIEW_" + generateRandomString();
-        createBaseTable(tableName, true, null, null);
+        createBaseTable(schemaName, tableName, true, null, null);
         Connection conn = DriverManager.getConnection(getUrl());
         PreparedStatement stmt = conn.prepareStatement(
                 "UPSERT INTO " + tableName

http://git-wip-us.apache.org/repos/asf/phoenix/blob/27697b36/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTableMetricsWriterIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTableMetricsWriterIT.java b/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTableMetricsWriterIT.java
index 533b6f8..f0319c0 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTableMetricsWriterIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTableMetricsWriterIT.java
@@ -17,18 +17,18 @@
  */
 package org.apache.phoenix.trace;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.util.Collection;
+
 import org.apache.hadoop.metrics2.MetricsRecord;
 import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.trace.TraceReader.SpanInfo;
 import org.apache.phoenix.trace.TraceReader.TraceHolder;
 import org.junit.Test;
 
-import java.sql.Connection;
-import java.util.Collection;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
 /**
  * Test that the logging sink stores the expected metrics/stats
  */
@@ -43,7 +43,8 @@ public class PhoenixTableMetricsWriterIT extends BaseTracingTestIT {
     public void testCreatesTable() throws Exception {
         PhoenixMetricsSink sink = new PhoenixMetricsSink();
         Connection conn = getConnectionWithoutTracing();
-        sink.initForTesting(conn);
+        String tableName = generateRandomString();
+        sink.initForTesting(conn, tableName);
 
         // check for existence of the tracing table
         try {
@@ -57,7 +58,7 @@ public class PhoenixTableMetricsWriterIT extends BaseTracingTestIT {
 
         // initialize sink again, which should attempt to create the table, but not fail
         try {
-            sink.initForTesting(conn);
+            sink.initForTesting(conn, tableName);
         } catch (Exception e) {
             fail("Initialization shouldn't fail if table already exists!");
         }
@@ -73,7 +74,8 @@ public class PhoenixTableMetricsWriterIT extends BaseTracingTestIT {
         // hook up a phoenix sink
         PhoenixMetricsSink sink = new PhoenixMetricsSink();
         Connection conn = getConnectionWithoutTracing();
-        sink.initForTesting(conn);
+        String tableName = generateRandomString();
+        sink.initForTesting(conn, tableName);
 
         // create a simple metrics record
         long traceid = 987654;
@@ -94,7 +96,7 @@ public class PhoenixTableMetricsWriterIT extends BaseTracingTestIT {
 
         // make sure we only get expected stat entry (matcing the trace id), otherwise we could the
         // stats for the update as well
-        TraceReader reader = new TraceReader(conn);
+        TraceReader reader = new TraceReader(conn, tableName);
         Collection<TraceHolder> traces = reader.readAll(10);
         assertEquals("Wrong number of traces in the tracing table", 1, traces.size());
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/27697b36/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTraceReaderIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTraceReaderIT.java b/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTraceReaderIT.java
index 2315074..a7bd730 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTraceReaderIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTraceReaderIT.java
@@ -35,10 +35,10 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.metrics2.AbstractMetric;
 import org.apache.hadoop.metrics2.MetricsRecord;
 import org.apache.hadoop.metrics2.MetricsTag;
+import org.apache.htrace.Span;
 import org.apache.phoenix.metrics.MetricInfo;
 import org.apache.phoenix.trace.TraceReader.SpanInfo;
 import org.apache.phoenix.trace.TraceReader.TraceHolder;
-import org.apache.htrace.Span;
 import org.junit.Test;
 
 /**
@@ -55,7 +55,8 @@ public class PhoenixTraceReaderIT extends BaseTracingTestIT {
         PhoenixMetricsSink sink = new PhoenixMetricsSink();
         Properties props = new Properties(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
-        sink.initForTesting(conn);
+        String tableName = generateRandomString();
+        sink.initForTesting(conn, tableName);
 
         // create a simple metrics record
         long traceid = 987654;
@@ -64,7 +65,7 @@ public class PhoenixTraceReaderIT extends BaseTracingTestIT {
                     "host-name.value", "test annotation for a span");
 
         // start a reader
-        validateTraces(Collections.singletonList(record), conn, traceid);
+        validateTraces(Collections.singletonList(record), conn, traceid, tableName);
     }
 
     private MetricsRecord createAndFlush(PhoenixMetricsSink sink, long traceid,
@@ -87,7 +88,8 @@ public class PhoenixTraceReaderIT extends BaseTracingTestIT {
         // hook up a phoenix sink
         PhoenixMetricsSink sink = new PhoenixMetricsSink();
         Connection conn = getConnectionWithoutTracing();
-        sink.initForTesting(conn);
+        String tableName = generateRandomString();
+        sink.initForTesting(conn, tableName);
 
         // create a simple metrics record
         long traceid = 12345;
@@ -119,12 +121,12 @@ public class PhoenixTraceReaderIT extends BaseTracingTestIT {
         sink.flush();
 
         // start a reader
-        validateTraces(records, conn, traceid);
+        validateTraces(records, conn, traceid, tableName);
     }
 
-    private void validateTraces(List<MetricsRecord> records, Connection conn, long traceid)
+    private void validateTraces(List<MetricsRecord> records, Connection conn, long traceid, String tableName)
             throws Exception {
-        TraceReader reader = new TraceReader(conn);
+        TraceReader reader = new TraceReader(conn, tableName);
         Collection<TraceHolder> traces = reader.readAll(1);
         assertEquals("Got an unexpected number of traces!", 1, traces.size());
         // make sure the trace matches what we wrote

http://git-wip-us.apache.org/repos/asf/phoenix/blob/27697b36/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTracingEndToEndIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTracingEndToEndIT.java b/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTracingEndToEndIT.java
index 2cd795d..2e21846 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTracingEndToEndIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTracingEndToEndIT.java
@@ -48,7 +48,7 @@ import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.trace.TraceReader.SpanInfo;
 import org.apache.phoenix.trace.TraceReader.TraceHolder;
 import org.junit.After;
-import org.junit.BeforeClass;
+import org.junit.Before;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableMap;
@@ -64,13 +64,15 @@ public class PhoenixTracingEndToEndIT extends BaseTracingTestIT {
     private final String table = "ENABLED_FOR_LOGGING";
     private final String index = "ENABALED_FOR_LOGGING_INDEX";
 
-    private static DisableableMetricsWriter sink;
+    private DisableableMetricsWriter sink;
+    private String tableName;
 
-    @BeforeClass
-    public static void setupMetrics() throws Exception {
+    @Before
+    public void setupMetrics() throws Exception {
         PhoenixMetricsSink pWriter = new PhoenixMetricsSink();
         Connection conn = getConnectionWithoutTracing();
-        pWriter.initForTesting(conn);
+        tableName = generateRandomString();
+        pWriter.initForTesting(conn, tableName);
         sink = new DisableableMetricsWriter(pWriter);
 
         TracingTestUtil.registerSink(sink);
@@ -80,22 +82,19 @@ public class PhoenixTracingEndToEndIT extends BaseTracingTestIT {
     public void cleanup() {
         sink.disable();
         sink.clear();
-        sink.enable();
-
-        // LISTENABLE.clearListeners();
     }
 
-    private static void waitForCommit(CountDownLatch latch) throws SQLException {
+    private void waitForCommit(CountDownLatch latch) throws SQLException {
         Connection conn = new CountDownConnection(getConnectionWithoutTracing(), latch);
         replaceWriterConnection(conn);
     }
 
-    private static void replaceWriterConnection(Connection conn) throws SQLException {
+    private void replaceWriterConnection(Connection conn) throws SQLException {
         // disable the writer
         sink.disable();
 
         // swap the connection for one that listens
-        sink.getDelegate().initForTesting(conn);
+        sink.getDelegate().initForTesting(conn, tableName);
 
         // enable the writer
         sink.enable();
@@ -461,7 +460,7 @@ public class PhoenixTracingEndToEndIT extends BaseTracingTestIT {
     }
 
     private boolean checkStoredTraces(Connection conn, TraceChecker checker) throws Exception {
-        TraceReader reader = new TraceReader(conn);
+        TraceReader reader = new TraceReader(conn, tableName);
         int retries = 0;
         boolean found = false;
         outer: while (retries < MAX_RETRIES) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/27697b36/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
index e55a63e..3d94eba 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
@@ -503,16 +503,18 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
     public void testCreateTableToBeTransactional() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
-        String ddl = "CREATE TABLE TEST_TRANSACTIONAL_TABLE (k varchar primary key) transactional=true";
+        String t1 = generateRandomString();
+        String t2 = generateRandomString();
+        String ddl = "CREATE TABLE " + t1 + " (k varchar primary key) transactional=true";
         conn.createStatement().execute(ddl);
         PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
-        PTable table = pconn.getTable(new PTableKey(null, "TEST_TRANSACTIONAL_TABLE"));
-        HTableInterface htable = pconn.getQueryServices().getTable(Bytes.toBytes("TEST_TRANSACTIONAL_TABLE"));
+        PTable table = pconn.getTable(new PTableKey(null, t1));
+        HTableInterface htable = pconn.getQueryServices().getTable(Bytes.toBytes(t1));
         assertTrue(table.isTransactional());
         assertTrue(htable.getTableDescriptor().getCoprocessors().contains(PhoenixTransactionalProcessor.class.getName()));
         
         try {
-            ddl = "ALTER TABLE TEST_TRANSACTIONAL_TABLE SET transactional=false";
+            ddl = "ALTER TABLE " + t1 + " SET transactional=false";
             conn.createStatement().execute(ddl);
             fail();
         } catch (SQLException e) {
@@ -520,15 +522,15 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
         }
 
         HBaseAdmin admin = pconn.getQueryServices().getAdmin();
-        HTableDescriptor desc = new HTableDescriptor(TableName.valueOf("TXN_TEST_EXISTING"));
+        HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(t2));
         desc.addFamily(new HColumnDescriptor(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES));
         admin.createTable(desc);
-        ddl = "CREATE TABLE TXN_TEST_EXISTING (k varchar primary key) transactional=true";
+        ddl = "CREATE TABLE " + t2 + " (k varchar primary key) transactional=true";
         conn.createStatement().execute(ddl);
-        assertEquals(Boolean.TRUE.toString(), admin.getTableDescriptor(TableName.valueOf("TXN_TEST_EXISTING")).getValue(TxConstants.READ_NON_TX_DATA));
+        assertEquals(Boolean.TRUE.toString(), admin.getTableDescriptor(TableName.valueOf(t2)).getValue(TxConstants.READ_NON_TX_DATA));
         
         // Should be ok, as HBase metadata should match existing metadata.
-        ddl = "CREATE TABLE IF NOT EXISTS TEST_TRANSACTIONAL_TABLE (k varchar primary key)"; 
+        ddl = "CREATE TABLE IF NOT EXISTS " + t1 + " (k varchar primary key)"; 
         try {
             conn.createStatement().execute(ddl);
             fail();
@@ -537,8 +539,8 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
         }
         ddl += " transactional=true";
         conn.createStatement().execute(ddl);
-        table = pconn.getTable(new PTableKey(null, "TEST_TRANSACTIONAL_TABLE"));
-        htable = pconn.getQueryServices().getTable(Bytes.toBytes("TEST_TRANSACTIONAL_TABLE"));
+        table = pconn.getTable(new PTableKey(null, t1));
+        htable = pconn.getQueryServices().getTable(Bytes.toBytes(t1));
         assertTrue(table.isTransactional());
         assertTrue(htable.getTableDescriptor().getCoprocessors().contains(PhoenixTransactionalProcessor.class.getName()));
     }
@@ -840,9 +842,10 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
         String transTableName = generateRandomString();
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + transTableName;
         String selectSQL = "SELECT * FROM " + fullTableName;
-        try (Connection conn1 = DriverManager.getConnection(getUrl()); 
+        try (Connection conn = DriverManager.getConnection(getUrl());
+                Connection conn1 = DriverManager.getConnection(getUrl()); 
                 Connection conn2 = DriverManager.getConnection(getUrl())) {
-            createTable(conn1, fullTableName);
+            createTable(conn, fullTableName);
             conn1.setAutoCommit(false);
             conn2.setAutoCommit(true);
             ResultSet rs = conn1.createStatement().executeQuery(selectSQL);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/27697b36/phoenix-core/src/main/java/org/apache/phoenix/trace/PhoenixMetricsSink.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/trace/PhoenixMetricsSink.java b/phoenix-core/src/main/java/org/apache/phoenix/trace/PhoenixMetricsSink.java
index af0d6e7..a8e80ab 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/trace/PhoenixMetricsSink.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/trace/PhoenixMetricsSink.java
@@ -147,11 +147,12 @@ public class PhoenixMetricsSink implements MetricsSink {
      * {@link org.apache.phoenix.query.QueryServicesOptions#DEFAULT_TRACING_STATS_TABLE_NAME}
      *
      * @param conn to store for upserts and to create the table (if necessary)
+     * @param tableName TODO
      * @throws SQLException if any phoenix operation fails
      */
     @VisibleForTesting
-    public void initForTesting(Connection conn) throws SQLException {
-        initializeInternal(conn, QueryServicesOptions.DEFAULT_TRACING_STATS_TABLE_NAME);
+    public void initForTesting(Connection conn, String tableName) throws SQLException {
+        initializeInternal(conn, tableName);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/phoenix/blob/27697b36/phoenix-core/src/main/java/org/apache/phoenix/trace/TraceReader.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/trace/TraceReader.java b/phoenix-core/src/main/java/org/apache/phoenix/trace/TraceReader.java
index ccb9064..318453f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/trace/TraceReader.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/trace/TraceReader.java
@@ -29,12 +29,12 @@ import java.util.TreeSet;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.htrace.Span;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.metrics.MetricInfo;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.util.LogUtil;
-import org.apache.htrace.Span;
 
 import com.google.common.base.Joiner;
 import com.google.common.primitives.Longs;
@@ -62,17 +62,13 @@ public class TraceReader {
     private String table;
     private int pageSize;
 
-    public TraceReader(Connection conn, String statsTableName) throws SQLException {
+    public TraceReader(Connection conn, String tracingTableName) throws SQLException {
         this.conn = conn;
-        this.table = statsTableName;
+        this.table = tracingTableName;
         String ps = conn.getClientInfo(QueryServices.TRACING_PAGE_SIZE_ATTRIB);
         this.pageSize = ps == null ? QueryServicesOptions.DEFAULT_TRACING_PAGE_SIZE : Integer.parseInt(ps);
     }
 
-    public TraceReader(Connection conn) throws SQLException {
-        this(conn, QueryServicesOptions.DEFAULT_TRACING_STATS_TABLE_NAME);
-    }
-
     /**
      * Read all the currently stored traces.
      * <p>
@@ -87,7 +83,7 @@ public class TraceReader {
         // trace
         // goes together), and then by start time (so parent spans always appear before child spans)
         String query =
-                "SELECT " + knownColumns + " FROM " + QueryServicesOptions.DEFAULT_TRACING_STATS_TABLE_NAME
+                "SELECT " + knownColumns + " FROM " + table
                         + " ORDER BY " + MetricInfo.TRACE.columnName + " DESC, "
                         + MetricInfo.START.columnName + " ASC" + " LIMIT " + pageSize;
         int resultCount = 0;


[16/47] phoenix git commit: PHOENIX-1367 VIEW derived from another VIEW doesn't use parent VIEW indexes

Posted by ma...@apache.org.
PHOENIX-1367 VIEW derived from another VIEW doesn't use parent VIEW indexes


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

Branch: refs/heads/calcite
Commit: 5a6496e1dc51576f4882c3718495eb2e1d6bce0a
Parents: 8e082fb
Author: Cody Marcel <cm...@salesforce.com>
Authored: Mon Jul 18 17:58:32 2016 -0600
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Sun Sep 11 11:33:53 2016 -0700

----------------------------------------------------------------------
 .../index/ChildViewsUseParentViewIndexIT.java   | 254 +++++++++++++++++++
 .../coprocessor/MetaDataEndpointImpl.java       |  14 +-
 .../apache/phoenix/index/IndexMaintainer.java   |  16 +-
 .../apache/phoenix/query/QueryConstants.java    |   1 +
 .../apache/phoenix/schema/MetaDataClient.java   |  67 +++--
 .../apache/phoenix/schema/PMetaDataImpl.java    |   2 +-
 .../java/org/apache/phoenix/schema/PTable.java  |  20 +-
 .../org/apache/phoenix/schema/PTableImpl.java   |  41 ++-
 .../org/apache/phoenix/util/ExpressionUtil.java |  15 +-
 9 files changed, 360 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a6496e1/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ChildViewsUseParentViewIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ChildViewsUseParentViewIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ChildViewsUseParentViewIndexIT.java
new file mode 100644
index 0000000..60a428c
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ChildViewsUseParentViewIndexIT.java
@@ -0,0 +1,254 @@
+package org.apache.phoenix.end2end.index;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.Date;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.util.QueryUtil;
+import org.junit.Test;
+
+public class ChildViewsUseParentViewIndexIT extends BaseHBaseManagedTimeTableReuseIT {
+
+    @Test
+    public void testIndexOnParentViewWithTenantSpecificConnection() throws Exception {
+        final String baseTableName = generateRandomString();
+        final String globalViewName = generateRandomString();
+        final String globalViewIdxName = generateRandomString();
+        final String tenantViewName1 = generateRandomString();
+        final String tenantViewName2 = generateRandomString();
+
+        // Set up props with TenantId
+        Properties props  = new Properties();
+        props.setProperty("TenantId", "00Dxxxxxxxxxxx1");
+        
+        try (Connection conn = DriverManager.getConnection(getUrl());
+                Connection tenantConn = DriverManager.getConnection(getUrl(), props)) {
+            // Create Base table
+            createBaseTable(baseTableName, conn);
+            
+            // Create the Global View on the Base Table for a value of KP
+            createGlobalView(globalViewName, baseTableName, conn);
+    
+            // Create Global Index on View
+            createGlobalIndexOnView(globalViewName, globalViewIdxName, conn);
+    
+            // Create tenant specific view which is a child of global view
+            createTenantSpecificView(globalViewName, tenantViewName1, tenantConn);
+            
+            // Create tenant specific view which is a child of previous tenant view
+            createTenantSpecificView(tenantViewName1, tenantViewName2, tenantConn);
+    
+            int rowCount = 0;
+            insertRowIntoView(globalViewName, tenantConn, ++rowCount);
+            insertRowIntoView(globalViewName, tenantConn, ++rowCount);
+            insertRowIntoView(globalViewName, tenantConn, ++rowCount);
+            assertQueryIndex(globalViewName, baseTableName, tenantConn, 3);
+    
+            insertRowIntoView(tenantViewName1, tenantConn, ++rowCount);
+            insertRowIntoView(tenantViewName2, tenantConn, ++rowCount);
+    
+            // assert that we get 5 rows while querying via tenant specific views and that we use the index
+            assertQueryIndex(tenantViewName1, baseTableName, tenantConn, 5);
+            assertQueryIndex(tenantViewName2, baseTableName, tenantConn, 5);
+    
+            // assert that we get 5 rows while querying via global specific view and that we use the index
+            assertQueryIndex(globalViewName, baseTableName, tenantConn, 5);
+        }
+    }
+    
+    
+    @Test
+    public void testParentViewIndexWithSpecializedChildViews() throws Exception {
+        final String baseTableName = generateRandomString();
+        final String parentViewName = generateRandomString();
+        final String parentViewIdxName = generateRandomString();
+        final String childViewName1 = generateRandomString();
+        final String childViewName2 = generateRandomString();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            // create base table
+            String baseTableDdl = "CREATE TABLE " + baseTableName + " (" +
+                    "A0 CHAR(1) NOT NULL PRIMARY KEY," +
+                    "A1 CHAR(1)," +
+                    "A2 CHAR(1)," +
+                    "A3 CHAR(1)," +
+                    "A4 CHAR(1))";
+            conn.createStatement().execute(baseTableDdl);
+            
+            // create the parent view on the base table for a value of A
+            String globalViewDdl = "CREATE VIEW " + parentViewName + " AS SELECT * FROM " + baseTableName + " WHERE A1 = 'X'";
+            conn.createStatement().execute(globalViewDdl);
+    
+            // create index on parent view
+            conn.createStatement().execute("CREATE INDEX " + parentViewIdxName + " ON " + parentViewName + "(A4, A2)");
+    
+            // create child of parent view that should be able to use the parent's index
+            String childViewDdl = "CREATE VIEW " + childViewName1 + " AS SELECT * FROM " + parentViewName + " WHERE A2 = 'Y'";
+            conn.createStatement().execute(childViewDdl);
+            
+            // create child of parent view that should *not* be able to use the parent's index
+            String grandChildViewDdl1 = "CREATE VIEW " + childViewName2 + " AS SELECT * FROM " + childViewName1 + " WHERE A3 = 'Z'";
+            conn.createStatement().execute(grandChildViewDdl1);
+
+            // upsert row using parent view
+            PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + parentViewName + " (A0, A2, A3, A4) VALUES(?,?,?,?)");
+            stmt.setString(1, "1");
+            stmt.setString(2, "Y");
+            stmt.setString(3, "Z");
+            stmt.setString(4, "1");
+            stmt.execute();
+            conn.commit();
+            
+            // upsert row using first child view
+            stmt = conn.prepareStatement("UPSERT INTO " + childViewName1 + " (A0, A3, A4) VALUES(?,?,?)");
+            stmt.setString(1, "2");
+            stmt.setString(2, "Z");
+            stmt.setString(3, "2");
+            stmt.execute();
+            conn.commit();
+            
+            // upsert row using second child view
+            stmt = conn.prepareStatement("UPSERT INTO " + childViewName2 + " (A0, A4) VALUES(?,?)");
+            stmt.setString(1, "3");
+            stmt.setString(2, "3");
+            stmt.execute();
+            conn.commit();
+            
+            // assert that we get 2 rows while querying via parent views and that we use the index
+            assertQueryUsesIndex(baseTableName, parentViewName, conn, false);
+            
+            // assert that we get 2 rows while querying via the first child view and that we use the index
+            assertQueryUsesIndex(baseTableName, childViewName1, conn, true);
+            
+            // assert that we get 3 rows while querying via the second child view and that we use the base table
+            assertQueryUsesBaseTable(baseTableName, childViewName2, conn);
+        }
+    }
+
+    private void assertQueryUsesIndex(final String baseTableName, final String viewName, Connection conn, boolean isChildView) throws SQLException {
+        String sql = "SELECT A0, A1, A2, A4 FROM " + viewName +" WHERE A4 IN ('1', '2', '3') ORDER BY A4, A2";
+        ResultSet rs = conn.prepareStatement("EXPLAIN " + sql).executeQuery();
+        String childViewScanKey = isChildView ? ",'Y'" : "";
+        assertEquals(
+            "CLIENT PARALLEL 1-WAY SKIP SCAN ON 3 KEYS OVER _IDX_" + baseTableName + " [-32768,'1'" + childViewScanKey + "] - [-32768,'3'" + childViewScanKey + "]\n" +
+            "    SERVER FILTER BY FIRST KEY ONLY",
+            QueryUtil.getExplainPlan(rs));
+        
+        rs = conn.createStatement().executeQuery(sql);
+        assertTrue(rs.next());
+        assertEquals("1", rs.getString(1));
+        assertEquals("X", rs.getString(2));
+        assertEquals("Y", rs.getString(3));
+        assertEquals("1", rs.getString(4));
+        assertTrue(rs.next());
+        assertEquals("2", rs.getString(1));
+        assertEquals("X", rs.getString(2));
+        assertEquals("Y", rs.getString(3));
+        assertEquals("2", rs.getString(4));
+        assertFalse(rs.next());
+    }
+    
+    private void assertQueryUsesBaseTable(final String baseTableName, final String viewName, Connection conn) throws SQLException {
+        String sql = "SELECT A0, A1, A2, A4 FROM " + viewName +" WHERE A4 IN ('1', '2', '3') ";
+        ResultSet rs = conn.prepareStatement("EXPLAIN " + sql).executeQuery();
+        assertEquals(
+            "CLIENT PARALLEL 1-WAY FULL SCAN OVER " + baseTableName + "\n" +
+            "    SERVER FILTER BY (A4 IN ('1','2','3') AND ((A1 = 'X' AND A2 = 'Y') AND A3 = 'Z'))",
+            QueryUtil.getExplainPlan(rs));
+        
+        rs = conn.createStatement().executeQuery(sql);
+        assertTrue(rs.next());
+        assertEquals("1", rs.getString(1));
+        assertEquals("X", rs.getString(2));
+        assertEquals("Y", rs.getString(3));
+        assertEquals("1", rs.getString(4));
+        assertTrue(rs.next());
+        assertEquals("2", rs.getString(1));
+        assertEquals("X", rs.getString(2));
+        assertEquals("Y", rs.getString(3));
+        assertEquals("2", rs.getString(4));
+        assertTrue(rs.next());
+        assertEquals("3", rs.getString(1));
+        assertEquals("X", rs.getString(2));
+        assertEquals("Y", rs.getString(3));
+        assertEquals("3", rs.getString(4));
+        assertFalse(rs.next());
+    }
+
+    private void createBaseTable(String baseTableName, Connection conn) throws SQLException {
+        String baseTableDdl = "CREATE TABLE " + baseTableName + " (" +
+                "OID CHAR(15) NOT NULL,\n" +
+                "KP CHAR(3) NOT NULL\n," +
+                "CREATED_DATE DATE\n," +
+                "CREATED_BY CHAR(3)\n," +
+                "CONSTRAINT PK PRIMARY KEY (oid, kp))\n";
+        String ddlOptions = "MULTI_TENANT=true, IMMUTABLE_ROWS=TRUE, VERSIONS=1";
+        conn.createStatement().execute(baseTableDdl + ddlOptions);
+    }
+
+    private void createGlobalView(String globalViewName, String baseTableName, Connection conn) throws SQLException {
+        String globalViewDdl = "CREATE VIEW IF NOT EXISTS " + globalViewName + " (" +
+                "A_DATE DATE NOT NULL," +
+                "WO_ID CHAR(15) NOT NULL," +
+                "WA_ID CHAR(15) NOT NULL," +
+                "C_TYPE VARCHAR NOT NULL," +
+                "CA_TYPE VARCHAR NOT NULL," +
+                "V_ID CHAR(15)," +
+                "C_CTX VARCHAR," +
+                "CONSTRAINT PKVIEW PRIMARY KEY (A_DATE, WO_ID, WA_ID, C_TYPE, CA_TYPE))" +
+                "AS SELECT * FROM " + baseTableName + " WHERE KP = 'xyz'";
+        conn.createStatement().execute(globalViewDdl);
+    }
+
+    private void createGlobalIndexOnView(String globalViewName, String globalViewIdxName, Connection conn) throws SQLException {
+        String globalViewIdxDdl = "CREATE INDEX IF NOT EXISTS " + globalViewIdxName +
+                " ON " + globalViewName + "(WO_ID, A_DATE DESC)";
+        conn.createStatement().execute(globalViewIdxDdl);
+    }
+
+    private void createTenantSpecificView(String parentViewName, String tenantViewName, Connection conn) throws SQLException {
+        String tenantSpecificViewDdl = "CREATE VIEW IF NOT EXISTS " +
+                tenantViewName + " AS SELECT * FROM " + parentViewName;
+        conn.createStatement().
+                execute(tenantSpecificViewDdl);
+    }
+    
+    private void insertRowIntoView(String viewName, Connection conn, int rowCount) throws SQLException {
+        PreparedStatement stmt = conn.prepareStatement(
+                "UPSERT INTO " + viewName + " (A_DATE, WO_ID, WA_ID, C_TYPE, CA_TYPE, V_ID) VALUES(?,?,?,?,?,?)");
+        stmt.setDate(1, new Date(System.currentTimeMillis()));
+        stmt.setString(2, "003xxxxxxxxxxx" + rowCount);
+        stmt.setString(3, "701xxxxxxxxxxx" + rowCount);
+        stmt.setString(4, "ctype1");
+        stmt.setString(5, "catype1");
+        stmt.setString(6, "xyzxxxxxxxxxxx" + rowCount);
+        stmt.execute();
+        conn.commit();
+    }
+
+    private void assertQueryIndex(String viewName, String baseTableName, Connection conn, int expectedRows) throws SQLException {
+        String sql = "SELECT WO_ID FROM " + viewName +
+                " WHERE WO_ID IN ('003xxxxxxxxxxx1', '003xxxxxxxxxxx2', '003xxxxxxxxxxx3', '003xxxxxxxxxxx4', '003xxxxxxxxxxx5') " +
+                " AND (A_DATE > TO_DATE('2016-01-01 06:00:00.0')) " +
+                " ORDER BY WO_ID, A_DATE DESC";
+        ResultSet rs = conn.prepareStatement("EXPLAIN " + sql).executeQuery();
+        assertEquals(
+            "CLIENT PARALLEL 1-WAY SKIP SCAN ON 5 RANGES OVER _IDX_" + baseTableName + " [-32768,'00Dxxxxxxxxxxx1','003xxxxxxxxxxx1',*] - [-32768,'00Dxxxxxxxxxxx1','003xxxxxxxxxxx5',~'2016-01-01 06:00:00.000']\n" + 
+            "    SERVER FILTER BY FIRST KEY ONLY",
+            QueryUtil.getExplainPlan(rs));
+        
+        rs = conn.createStatement().executeQuery(sql);
+        for (int i=0; i<expectedRows; ++i)
+            assertTrue(rs.next());
+        assertFalse(rs.next());
+    }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a6496e1/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index 7d3468d..a5d77bc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -924,8 +924,10 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
         
         
         List<PColumn> columns = Lists.newArrayListWithExpectedSize(columnCount);
-        List<PTable> indexes = new ArrayList<PTable>();
-        List<PName> physicalTables = new ArrayList<PName>();
+        List<PTable> indexes = Lists.newArrayList();
+        List<PName> physicalTables = Lists.newArrayList();
+        PName parentTableName = tableType == INDEX ? dataTableName : null;
+        PName parentSchemaName = tableType == INDEX ? schemaName : null;
         while (true) {
           results.clear();
           scanner.next(results);
@@ -943,6 +945,9 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
                   addIndexToTable(tenantId, schemaName, famName, tableName, clientTimeStamp, indexes);
               } else if (linkType == LinkType.PHYSICAL_TABLE) {
                   physicalTables.add(famName);
+              } else if (linkType == LinkType.PARENT_TABLE) {
+                  parentTableName = PNameFactory.newName(SchemaUtil.getTableNameFromFullName(famName.getBytes()));
+                  parentSchemaName = PNameFactory.newName(SchemaUtil.getSchemaNameFromFullName(famName.getBytes()));
               }
           } else {
               addColumnToTable(results, colName, famName, colKeyValues, columns, saltBucketNum != null);
@@ -951,8 +956,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
         // Avoid querying the stats table because we're holding the rowLock here. Issuing an RPC to a remote
         // server while holding this lock is a bad idea and likely to cause contention.
         return PTableImpl.makePTable(tenantId, schemaName, tableName, tableType, indexState, timeStamp, tableSeqNum,
-                pkName, saltBucketNum, columns, tableType == INDEX ? schemaName : null,
-                tableType == INDEX ? dataTableName : null, indexes, isImmutableRows, physicalTables, defaultFamilyName,
+                pkName, saltBucketNum, columns, parentSchemaName, parentTableName, indexes, isImmutableRows, physicalTables, defaultFamilyName,
                 viewStatement, disableWAL, multiTenant, storeNulls, viewType, viewIndexId, indexType,
                 rowKeyOrderOptimizable, transactional, updateCacheFrequency, baseColumnCount,
                 indexDisableTimestamp, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema);
@@ -1718,7 +1722,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
             return new MetaDataMutationResult(MutationCode.TABLE_NOT_FOUND, EnvironmentEdgeManager.currentTimeMillis(), null);
         }
         // Make sure we're not deleting the "wrong" child
-        if (!Arrays.equals(parentTableName, table.getParentTableName() == null ? null : table.getParentTableName().getBytes())) {
+        if (parentTableName!=null && table.getParentTableName() != null && !Arrays.equals(parentTableName, table.getParentTableName().getBytes())) {
             return new MetaDataMutationResult(MutationCode.TABLE_NOT_FOUND, EnvironmentEdgeManager.currentTimeMillis(), null);
         }
         // Since we don't allow back in time DDL, we know if we have a table it's the one

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a6496e1/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
index ee67ca2..6595562 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
@@ -50,6 +50,7 @@ import org.apache.phoenix.compile.ColumnResolver;
 import org.apache.phoenix.compile.FromCompiler;
 import org.apache.phoenix.compile.IndexExpressionCompiler;
 import org.apache.phoenix.compile.StatementContext;
+import org.apache.phoenix.expression.CoerceExpression;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.ExpressionType;
 import org.apache.phoenix.expression.KeyValueColumnExpression;
@@ -85,10 +86,12 @@ import org.apache.phoenix.schema.tuple.ValueGetterTuple;
 import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.util.BitSet;
 import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.ExpressionUtil;
 import org.apache.phoenix.util.IndexUtil;
 import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.TrustedByteArrayOutputStream;
+import org.apache.tephra.TxConstants;
 
 import com.google.common.base.Predicate;
 import com.google.common.collect.Iterators;
@@ -96,8 +99,6 @@ import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 
-import org.apache.tephra.TxConstants;
-
 /**
  * 
  * Class that builds index row key from data row key and current state of
@@ -416,7 +417,16 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
 	                this.rowKeyMetaData.setIndexPkPosition(dataPkPos, indexPos);
 	            } else {
 	                indexColByteSize += column.getDataType().isFixedWidth() ? SchemaUtil.getFixedByteSize(column) : ValueSchema.ESTIMATED_VARIABLE_LENGTH_SIZE;
-	                this.indexedExpressions.add(expression);
+	                try {
+	                    // Surround constant with cast so that we can still know the original type. Otherwise, if we lose the type,
+	                    // (for example when VARCHAR becomes CHAR), it can lead to problems in the type translation we do between data tables and indexes.
+	                    if (column.isNullable() && ExpressionUtil.isConstant(expression)) {
+	                        expression = CoerceExpression.create(expression, indexColumn.getDataType());
+	                    }
+                        this.indexedExpressions.add(expression);
+                    } catch (SQLException e) {
+                        throw new RuntimeException(e); // Impossible
+                    }
 	            }
             }
             else {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a6496e1/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
index 7e5f7a2..155d1ba 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
@@ -131,6 +131,7 @@ import org.apache.phoenix.util.ByteUtil;
 public interface QueryConstants {
     public static final String NAME_SEPARATOR = ".";
     public static final String NAMESPACE_SEPARATOR = ":";
+    public static final String CHILD_VIEW_INDEX_NAME_SEPARATOR = "#";
     public static final byte[] NAMESPACE_SEPARATOR_BYTES = Bytes.toBytes(NAMESPACE_SEPARATOR);
     public static final byte NAMESPACE_SEPARATOR_BYTE = NAMESPACE_SEPARATOR_BYTES[0];
     public static final String NAME_SEPARATOR_REGEX = "\\" + NAME_SEPARATOR;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a6496e1/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index fd6b48c..7da7010 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -541,7 +541,7 @@ public class MetaDataClient {
                         // In this case, we update the parent table which may in turn pull
                         // in indexes to add to this table.
                         long resolvedTime = TransactionUtil.getResolvedTime(connection, result);
-                        if (addIndexesFromPhysicalTable(result, resolvedTimestamp)) {
+                        if (addIndexesFromParentTable(result, resolvedTimestamp)) {
                             connection.addTable(result.getTable(), resolvedTime);
                         }
                         else {
@@ -656,7 +656,7 @@ public class MetaDataClient {
     }
 
     /**
-     * Fault in the physical table to the cache and add any indexes it has to the indexes
+     * Fault in the parent table to the cache and add any indexes it has to the indexes
      * of the table for which we just updated.
      * TODO: combine this round trip with the one that updates the cache for the child table.
      * @param result the result from updating the cache for the current table.
@@ -664,29 +664,30 @@ public class MetaDataClient {
      * @return true if the PTable contained by result was modified and false otherwise
      * @throws SQLException if the physical table cannot be found
      */
-    private boolean addIndexesFromPhysicalTable(MetaDataMutationResult result, Long resolvedTimestamp) throws SQLException {
+    private boolean addIndexesFromParentTable(MetaDataMutationResult result, Long resolvedTimestamp) throws SQLException {
         PTable view = result.getTable();
         // If not a view or if a view directly over an HBase table, there's nothing to do
         if (view.getType() != PTableType.VIEW || view.getViewType() == ViewType.MAPPED) {
             return false;
         }
-        String physicalName = view.getPhysicalName().getString();
-        String schemaName = SchemaUtil.getSchemaNameFromFullName(physicalName);
-        String tableName = SchemaUtil.getTableNameFromFullName(physicalName);
-        MetaDataMutationResult parentResult = updateCache(null, schemaName, tableName, false, resolvedTimestamp);
-        PTable physicalTable = parentResult.getTable();
-        if (physicalTable == null) {
+        // a view on a table will not have a parent name but will have a physical table name (which is the parent)
+        String parentName = view.getParentName().getString();
+        String schemaName = SchemaUtil.getSchemaNameFromFullName(parentName);
+        String tableName = SchemaUtil.getTableNameFromFullName(parentName);
+        MetaDataMutationResult parentResult = updateCache(connection.getTenantId(), schemaName, tableName, false, resolvedTimestamp);
+        PTable parentTable = parentResult.getTable();
+        if (parentTable == null) {
             throw new TableNotFoundException(schemaName, tableName);
         }
         if (!result.wasUpdated() && !parentResult.wasUpdated()) {
             return false;
         }
-        List<PTable> physicalTableIndexes = physicalTable.getIndexes();
-        if (physicalTableIndexes.isEmpty()) {
+        List<PTable> parentTableIndexes = parentTable.getIndexes();
+        if (parentTableIndexes.isEmpty()) {
             return false;
         }
         // Filter out indexes if column doesn't exist in view
-        List<PTable> indexesToAdd = Lists.newArrayListWithExpectedSize(physicalTableIndexes.size() + view.getIndexes().size());
+        List<PTable> indexesToAdd = Lists.newArrayListWithExpectedSize(parentTableIndexes.size() + view.getIndexes().size());
         if (result.wasUpdated()) { // Table from server never contains inherited indexes
             indexesToAdd.addAll(view.getIndexes());
         } else { // Only add original ones, as inherited ones may have changed
@@ -697,11 +698,11 @@ public class MetaDataClient {
                 }
             }
         }
-        for (PTable index : physicalTableIndexes) {
+        for (PTable index : parentTableIndexes) {
             boolean containsAllReqdCols = true;
             // Ensure that all columns required to create index exist in the view too,
             // since view columns may be removed.
-            IndexMaintainer indexMaintainer = index.getIndexMaintainer(physicalTable, connection);
+            IndexMaintainer indexMaintainer = index.getIndexMaintainer(parentTable, connection);
             // Check that the columns required for the index pk are present in the view
             Set<ColumnReference> indexColRefs = indexMaintainer.getIndexedColumns();
             for (ColumnReference colRef : indexColRefs) {
@@ -720,7 +721,7 @@ public class MetaDataClient {
                 }
             }
             // Ensure that constant columns (i.e. columns matched in the view WHERE clause)
-            // all exist in the index on the physical table.
+            // all exist in the index on the parent table. 
             for (PColumn col : view.getColumns()) {
                 if (col.getViewConstant() != null) {
                     try {
@@ -729,17 +730,36 @@ public class MetaDataClient {
                         // would fail to compile.
                         String indexColumnName = IndexUtil.getIndexColumnName(col);
                         index.getColumn(indexColumnName);
-                    } catch (ColumnNotFoundException e) { // Ignore this index and continue with others
-                        containsAllReqdCols = false;
-                        break;
+                    } catch (ColumnNotFoundException e1) { 
+                        PColumn indexCol = null;
+                        try {
+                            String cf = col.getFamilyName()!=null ? col.getFamilyName().getString() : null;
+                            String cq = col.getName().getString();
+                            if (cf!=null) {
+                                indexCol = parentTable.getColumnFamily(cf).getColumn(cq);
+                            }
+                            else {
+                                indexCol = parentTable.getColumn(cq);
+                            }
+                        } catch (ColumnNotFoundException e2) { // Ignore this index and continue with others
+                            containsAllReqdCols = false;
+                            break;
+                        }
+                        if (indexCol.getViewConstant()==null || Bytes.compareTo(indexCol.getViewConstant(), col.getViewConstant())!=0) {
+                            containsAllReqdCols = false;
+                            break;
+                        }
                     }
                 }
             }
             if (containsAllReqdCols) {
                 // Tack on view statement to index to get proper filtering for view
-                String viewStatement = IndexUtil.rewriteViewStatement(connection, index, physicalTable, view.getViewStatement());
-                index = PTableImpl.makePTable(index, viewStatement);
-                indexesToAdd.add(index);
+                String viewStatement = IndexUtil.rewriteViewStatement(connection, index, parentTable, view.getViewStatement());
+                PName modifiedIndexName = PNameFactory.newName(index.getSchemaName().getString() + QueryConstants.CHILD_VIEW_INDEX_NAME_SEPARATOR 
+                    + index.getName().getString() + QueryConstants.CHILD_VIEW_INDEX_NAME_SEPARATOR + view.getName().getString());
+                // add the index table with a new name so that it does not conflict with the existing index table 
+                // also set update cache frequency to never since the renamed index is not present on the server 
+                indexesToAdd.add(PTableImpl.makePTable(index, modifiedIndexName, viewStatement, Long.MAX_VALUE, view.getTenantId()));
             }
         }
         PTable allIndexesTable = PTableImpl.makePTable(view, view.getTimeStamp(), indexesToAdd);
@@ -2190,7 +2210,6 @@ public class MetaDataClient {
             // add the columns in reverse order since we reverse the list later
             Collections.reverse(columnMetadata);
             tableMetaData.addAll(columnMetadata);
-
             String dataTableName = parent == null || tableType == PTableType.VIEW ? null : parent.getTableName().getString();
             PIndexState indexState = parent == null || tableType == PTableType.VIEW  ? null : PIndexState.BUILDING;
             PreparedStatement tableUpsert = connection.prepareStatement(CREATE_TABLE);
@@ -2341,7 +2360,7 @@ public class MetaDataClient {
                 PTable table =  PTableImpl.makePTable(
                         tenantId, newSchemaName, PNameFactory.newName(tableName), tableType, indexState, timestamp!=null ? timestamp : result.getMutationTime(),
                         PTable.INITIAL_SEQ_NUM, pkName == null ? null : PNameFactory.newName(pkName), saltBucketNum, columns.values(),
-                        dataTableName == null ? null : newSchemaName, dataTableName == null ? null : PNameFactory.newName(dataTableName), Collections.<PTable>emptyList(), isImmutableRows,
+                        parent == null ? null : parent.getSchemaName(), parent == null ? null : parent.getTableName(), Collections.<PTable>emptyList(), isImmutableRows,
                         physicalNames, defaultFamilyName == null ? null : PNameFactory.newName(defaultFamilyName), viewStatement, Boolean.TRUE.equals(disableWAL), multiTenant, storeNulls, viewType,
                         indexId, indexType, rowKeyOrderOptimizable, transactional, updateCacheFrequency, 0L, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema);
                 result = new MetaDataMutationResult(code, result.getMutationTime(), table, true);
@@ -3513,7 +3532,7 @@ public class MetaDataClient {
     }
 
     private PTable addTableToCache(MetaDataMutationResult result) throws SQLException {
-        addIndexesFromPhysicalTable(result, null);
+        addIndexesFromParentTable(result, null);
         PTable table = result.getTable();
         connection.addTable(table, TransactionUtil.getResolvedTime(connection, result));
         return table;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a6496e1/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
index 7a78006..8d7161e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
@@ -104,7 +104,7 @@ public class PMetaDataImpl implements PMetaData {
         PTable newParentTable = null;
         PTableRef newParentTableRef = null;
         long parentResolvedTimestamp = resolvedTime;
-        if (table.getParentName() != null) { // Upsert new index table into parent data table list
+        if (table.getType() == PTableType.INDEX) { // Upsert new index table into parent data table list
             String parentName = table.getParentName().getString();
             PTableRef oldParentRef = metaData.get(new PTableKey(table.getTenantId(), parentName));
             // If parentTable isn't cached, that's ok we can skip this

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a6496e1/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
index 344dc2c..b585323 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
@@ -24,8 +24,6 @@ import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.hbase.index.util.KeyValueBuilder;
 import org.apache.phoenix.index.IndexMaintainer;
 import org.apache.phoenix.jdbc.PhoenixConnection;
-import org.apache.phoenix.query.ConnectionQueryServices;
-import org.apache.phoenix.schema.stats.PTableStats;
 
 
 /**
@@ -281,21 +279,21 @@ public interface PTable extends PMetaDataEntity {
     PIndexState getIndexState();
 
     /**
-     * Gets the full name of the data table for an index table.
-     * @return the name of the data table that this index is on
-     *  or null if not an index.
+     * @return the full name of the parent view for a view or data table for an index table 
+     * or null if this is not a view or index table. Also returns null for a view of a data table 
+     * (use @getPhysicalName for this case) 
      */
     PName getParentName();
     /**
-     * Gets the table name of the data table for an index table.
-     * @return the table name of the data table that this index is
-     * on or null if not an index.
+     * @return the table name of the parent view for a view or data table for an index table 
+     * or null if this is not a view or index table. Also returns null for a view of a data table 
+     * (use @getPhysicalTableName for this case) 
      */
     PName getParentTableName();
     /**
-     * Gets the schema name of the data table for an index table.
-     * @return the schema name of the data table that this index is
-     * on or null if not an index.
+     * @return the schema name of the parent view for a view or data table for an index table 
+     * or null if this is not a view or index table. Also returns null for view of a data table 
+     * (use @getPhysicalSchemaName for this case) 
      */
     PName getParentSchemaName();
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a6496e1/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 b9cec02..293d422 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
@@ -206,12 +206,22 @@ public class PTableImpl implements PTable {
     }
 
     public static PTableImpl makePTable(PTable table, long timeStamp, List<PTable> indexes) throws SQLException {
-        return makePTable(table, timeStamp, indexes, table.getSchemaName(), table.getViewStatement());
+        return makePTable(table, timeStamp, indexes, table.getParentSchemaName(), table.getViewStatement());
     }
 
-    public static PTable makePTable(PTable table, String viewStatement) throws SQLException {
-        return Objects.equal(viewStatement, table.getViewStatement()) ? table : makePTable(table, table.getTimeStamp(), table.getIndexes(), table.getSchemaName(), viewStatement);
+    public static PTable makePTable(PTable index, PName indexName, String viewStatement, long updateCacheFrequency, PName tenantId) throws SQLException {
+        return Objects.equal(viewStatement, index.getViewStatement()) ? index : makePTable(index, indexName, index.getTimeStamp(), Lists.newArrayList(index.getPhysicalName()), index.getIndexes(), viewStatement, updateCacheFrequency, tenantId);
     }
+    
+    public static PTableImpl makePTable(PTable table, PName tableName, long timeStamp, List<PName> physicalNames, List<PTable> indexes, String viewStatement, long updateCacheFrequency, PName tenantId) throws SQLException {
+            return new PTableImpl(
+                    tenantId, table.getSchemaName(), tableName, table.getType(), table.getIndexState(), timeStamp,
+                    table.getSequenceNumber(), table.getPKName(), table.getBucketNum(), getColumnsToClone(table), table.getParentSchemaName(), table.getParentTableName(),
+                    indexes, table.isImmutableRows(), physicalNames, table.getDefaultFamilyName(), viewStatement,
+                    table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), table.getIndexType(),
+                    table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), table.isTransactional(), updateCacheFrequency,
+                    table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema());
+        }
 
     public static PTableImpl makePTable(PTable table, long timeStamp, List<PTable> indexes, PName parentSchemaName, String viewStatement) throws SQLException {
         return new PTableImpl(
@@ -335,7 +345,7 @@ public class PTableImpl implements PTable {
             int baseColumnCount, boolean rowKeyOrderOptimizable, boolean isTransactional, long updateCacheFrequency,
             long indexDisableTimestamp, boolean isNamespaceMapped, String autoPartitionSeqName, boolean isAppendOnlySchema) throws SQLException {
         init(tenantId, schemaName, tableName, type, state, timeStamp, sequenceNumber, pkName, bucketNum, columns,
-                schemaName, parentTableName, indexes, isImmutableRows, physicalNames, defaultFamilyName,
+                parentSchemaName, parentTableName, indexes, isImmutableRows, physicalNames, defaultFamilyName,
                 viewExpression, disableWAL, multiTenant, storeNulls, viewType, viewIndexId, indexType, baseColumnCount, rowKeyOrderOptimizable,
                 isTransactional, updateCacheFrequency, indexDisableTimestamp, isNamespaceMapped, autoPartitionSeqName, isAppendOnlySchema);
     }
@@ -519,7 +529,7 @@ public class PTableImpl implements PTable {
         this.parentSchemaName = parentSchemaName;
         this.parentTableName = parentTableName;
         this.parentName = parentTableName == null ? null : PNameFactory.newName(SchemaUtil.getTableName(
-                parentSchemaName.getString(), parentTableName.getString()));
+            parentSchemaName!=null ? parentSchemaName.getString() : null, parentTableName.getString()));
         estimatedSize += PNameFactory.getEstimatedSize(this.parentName);
 
         this.physicalNames = physicalNames == null ? ImmutableList.<PName>of() : ImmutableList.copyOf(physicalNames);
@@ -945,12 +955,15 @@ public class PTableImpl implements PTable {
 
     @Override
     public PName getParentTableName() {
-        return parentTableName;
+        // a view on a table will not have a parent name but will have a physical table name (which is the parent)
+        return (type!=PTableType.VIEW || parentName!=null) ? parentTableName : 
+            PNameFactory.newName(SchemaUtil.getTableNameFromFullName(getPhysicalName().getBytes()));
     }
 
     @Override
     public PName getParentName() {
-        return parentName;
+        // a view on a table will not have a parent name but will have a physical table name (which is the parent)
+        return (type!=PTableType.VIEW || parentName!=null) ? parentName : getPhysicalName();
     }
 
     @Override
@@ -1058,9 +1071,11 @@ public class PTableImpl implements PTable {
       }
 
       boolean isImmutableRows = table.getIsImmutableRows();
-      PName dataTableName = null;
+      PName parentSchemaName = null;
+      PName parentTableName = null;
       if (table.hasDataTableNameBytes()) {
-        dataTableName = PNameFactory.newName(table.getDataTableNameBytes().toByteArray());
+        parentSchemaName = PNameFactory.newName(SchemaUtil.getSchemaNameFromFullName((table.getDataTableNameBytes().toByteArray())));
+        parentTableName = PNameFactory.newName(SchemaUtil.getTableNameFromFullName(table.getDataTableNameBytes().toByteArray()));
       }
       PName defaultFamilyName = null;
       if (table.hasDefaultFamilyName()) {
@@ -1115,7 +1130,7 @@ public class PTableImpl implements PTable {
       try {
         PTableImpl result = new PTableImpl();
         result.init(tenantId, schemaName, tableName, tableType, indexState, timeStamp, sequenceNumber, pkName,
-            (bucketNum == NO_SALTING) ? null : bucketNum, columns, schemaName,dataTableName, indexes,
+            (bucketNum == NO_SALTING) ? null : bucketNum, columns, parentSchemaName, parentTableName, indexes,
             isImmutableRows, physicalNames, defaultFamilyName, viewStatement, disableWAL,
             multiTenant, storeNulls, viewType, viewIndexId, indexType, baseColumnCount, rowKeyOrderOptimizable,
             isTransactional, updateCacheFrequency, indexDisableTimestamp, isNamespaceMapped, autoParititonSeqName, isAppendOnlySchema);
@@ -1172,7 +1187,7 @@ public class PTableImpl implements PTable {
       builder.setIsImmutableRows(table.isImmutableRows());
 
       if (table.getParentName() != null) {
-        builder.setDataTableNameBytes(ByteStringer.wrap(table.getParentTableName().getBytes()));
+        builder.setDataTableNameBytes(ByteStringer.wrap(table.getParentName().getBytes()));
       }
       if (table.getDefaultFamilyName()!= null) {
         builder.setDefaultFamilyName(ByteStringer.wrap(table.getDefaultFamilyName().getBytes()));
@@ -1211,7 +1226,9 @@ public class PTableImpl implements PTable {
 
     @Override
     public PName getParentSchemaName() {
-        return parentSchemaName;
+        // a view on a table will not have a parent name but will have a physical table name (which is the parent)
+        return (type!=PTableType.VIEW || parentName!=null) ? parentSchemaName : 
+            PNameFactory.newName(SchemaUtil.getSchemaNameFromFullName(getPhysicalName().getBytes()));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a6496e1/phoenix-core/src/main/java/org/apache/phoenix/util/ExpressionUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ExpressionUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ExpressionUtil.java
index 6032aec..6f8b19f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ExpressionUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ExpressionUtil.java
@@ -10,34 +10,21 @@
 package org.apache.phoenix.util;
 
 import java.sql.SQLException;
-import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Determinism;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
-import org.apache.phoenix.expression.function.CurrentDateFunction;
-import org.apache.phoenix.expression.function.CurrentTimeFunction;
-import org.apache.phoenix.expression.function.FunctionExpression;
 import org.apache.phoenix.schema.types.PDataType;
 
-import com.google.common.collect.Lists;
-
 public class ExpressionUtil {
 
-	@SuppressWarnings("unchecked")
-	private static final List<Class<? extends FunctionExpression>> OVERRIDE_LITERAL_FUNCTIONS = Lists
-			.<Class<? extends FunctionExpression>> newArrayList(
-					CurrentDateFunction.class, CurrentTimeFunction.class);
-
 	private ExpressionUtil() {
 	}
 
 	public static boolean isConstant(Expression expression) {
 		return (expression.isStateless() && (expression.getDeterminism() == Determinism.ALWAYS
-				|| expression.getDeterminism() == Determinism.PER_STATEMENT 
-				// TODO remove this in 3.4/4.4 (need to support clients on 3.1/4.1)
-				|| OVERRIDE_LITERAL_FUNCTIONS.contains(expression.getClass())));
+				|| expression.getDeterminism() == Determinism.PER_STATEMENT));
 	}
 
     public static LiteralExpression getConstantExpression(Expression expression, ImmutableBytesWritable ptr)


[29/47] phoenix git commit: PHOENIX-3280 Automatic attempt to rebuild all disabled index

Posted by ma...@apache.org.
PHOENIX-3280 Automatic attempt to rebuild all disabled index


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

Branch: refs/heads/calcite
Commit: 2a223adfbeb32f598308da1dc6d3251ee0980d79
Parents: 27697b3
Author: James Taylor <ja...@apache.org>
Authored: Thu Sep 15 00:48:24 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Thu Sep 15 00:48:24 2016 -0700

----------------------------------------------------------------------
 .../coprocessor/MetaDataRegionObserver.java     | 179 +++++++++++--------
 1 file changed, 104 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/2a223adf/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
index f1dc982..00981f5 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
@@ -20,8 +20,8 @@ package org.apache.phoenix.coprocessor;
 import java.io.IOException;
 import java.sql.SQLException;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 import java.util.TimerTask;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
@@ -79,6 +79,7 @@ import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.UpgradeUtil;
 
 import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
 
 
 /**
@@ -223,13 +224,11 @@ public class MetaDataRegionObserver extends BaseRegionObserver {
                 scan.addColumn(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,
                     PhoenixDatabaseMetaData.INDEX_DISABLE_TIMESTAMP_BYTES);
 
-                PTable dataPTable = null;
+                Map<PTable, List<PTable>> dataTableToIndexesMap = null;
                 MetaDataClient client = null;
                 boolean hasMore = false;
                 List<Cell> results = new ArrayList<Cell>();
-                List<PTable> indexesToPartiallyRebuild = Collections.emptyList();
                 scanner = this.env.getRegion().getScanner(scan);
-                long earliestDisableTimestamp = Long.MAX_VALUE;
 
                 do {
                     results.clear();
@@ -249,19 +248,12 @@ public class MetaDataRegionObserver extends BaseRegionObserver {
                     if (disabledTimeStampVal <= 0) {
                         continue;
                     }
-                    if (disabledTimeStampVal < earliestDisableTimestamp) {
-                        earliestDisableTimestamp = disabledTimeStampVal;
-                    }
-
                     byte[] dataTable = r.getValue(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,
                         PhoenixDatabaseMetaData.DATA_TABLE_NAME_BYTES);
-                    byte[] indexStat = r.getValue(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,
+                    byte[] indexState = r.getValue(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,
                         PhoenixDatabaseMetaData.INDEX_STATE_BYTES);
-                    if ((dataTable == null || dataTable.length == 0) || (indexStat == null || indexStat.length == 0)
-                            || (dataPTable != null
-                                    && Bytes.compareTo(dataPTable.getName().getBytes(), dataTable) != 0)) {
+                    if ((dataTable == null || dataTable.length == 0) || (indexState == null || indexState.length == 0)) {
                         // data table name can't be empty
-                        // we need to build indexes of same data table. so skip other indexes for this task.
                         continue;
                     }
 
@@ -284,14 +276,19 @@ public class MetaDataRegionObserver extends BaseRegionObserver {
                     	// don't run a second index populations upsert select 
                         props.setProperty(QueryServices.INDEX_POPULATION_SLEEP_TIME, "0"); 
                         conn = QueryUtil.getConnectionOnServer(props, env.getConfiguration()).unwrap(PhoenixConnection.class);
-                        String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTable);
-                        dataPTable = PhoenixRuntime.getTable(conn, dataTableFullName);
-                        indexesToPartiallyRebuild = Lists.newArrayListWithExpectedSize(dataPTable.getIndexes().size());
                         client = new MetaDataClient(conn);
+                        dataTableToIndexesMap = Maps.newHashMap();
                     }
+                    String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTable);
+                    PTable dataPTable = PhoenixRuntime.getTableNoCache(conn, dataTableFullName);
 
                     String indexTableFullName = SchemaUtil.getTableName(schemaName, indexTable);
-                    PTable indexPTable = PhoenixRuntime.getTable(conn, indexTableFullName);
+                    PTable indexPTable = PhoenixRuntime.getTableNoCache(conn, indexTableFullName);
+                    // Sanity check in case index was removed from table
+                    if (!dataPTable.getIndexes().contains(indexPTable)) {
+                        continue;
+                    }
+                    
                     if (!MetaDataUtil.tableRegionsOnline(this.env.getConfiguration(), indexPTable)) {
                         LOG.debug("Index rebuild has been skipped because not all regions of index table="
                                 + indexPTable.getName() + " are online.");
@@ -299,82 +296,114 @@ public class MetaDataRegionObserver extends BaseRegionObserver {
                     }
                     // Allow index to begin incremental maintenance as index is back online and we
                     // cannot transition directly from DISABLED -> ACTIVE
-                    if (Bytes.compareTo(PIndexState.DISABLE.getSerializedBytes(), indexStat) == 0) {
+                    if (Bytes.compareTo(PIndexState.DISABLE.getSerializedBytes(), indexState) == 0) {
                         AlterIndexStatement statement = new AlterIndexStatement(
                                 NamedTableNode.create(indexPTable.getSchemaName().getString(), indexPTable.getTableName().getString()),
                                 dataPTable.getTableName().getString(),
                                 false, PIndexState.INACTIVE);
                         client.alterIndex(statement);
                     }
+                    List<PTable> indexesToPartiallyRebuild = dataTableToIndexesMap.get(dataPTable);
+                    if (indexesToPartiallyRebuild == null) {
+                        indexesToPartiallyRebuild = Lists.newArrayListWithExpectedSize(dataPTable.getIndexes().size());
+                        dataTableToIndexesMap.put(dataPTable, indexesToPartiallyRebuild);
+                    }
                     indexesToPartiallyRebuild.add(indexPTable);
                 } while (hasMore);
 
-                if (!indexesToPartiallyRebuild.isEmpty()) {
+                if (dataTableToIndexesMap != null) {
                     long overlapTime = env.getConfiguration().getLong(
-                        QueryServices.INDEX_FAILURE_HANDLING_REBUILD_OVERLAP_TIME_ATTRIB,
-                        QueryServicesOptions.DEFAULT_INDEX_FAILURE_HANDLING_REBUILD_OVERLAP_TIME);
-                    long timeStamp = Math.max(0, earliestDisableTimestamp - overlapTime);
-                    
-                    LOG.info("Starting to build indexes=" + indexesToPartiallyRebuild + " from timestamp=" + timeStamp);
-                    new Scan();
-                    List<IndexMaintainer> maintainers = Lists.newArrayListWithExpectedSize(indexesToPartiallyRebuild.size());
-                    for (PTable index : indexesToPartiallyRebuild) {
-                        maintainers.add(index.getIndexMaintainer(dataPTable, conn));
-                    }
-                    Scan dataTableScan = IndexManagementUtil.newLocalStateScan(maintainers);
-                    dataTableScan.setTimeRange(timeStamp, HConstants.LATEST_TIMESTAMP);
-                    byte[] physicalTableName = dataPTable.getPhysicalName().getBytes();
-                    try (HTableInterface dataHTable = conn.getQueryServices().getTable(physicalTableName)) {
-                        Result result;
-                        try (ResultScanner dataTableScanner = dataHTable.getScanner(dataTableScan)) {
-                            int batchSize = conn.getMutateBatchSize();
-                            List<Mutation> mutations = Lists.newArrayListWithExpectedSize(batchSize);
-                            ImmutableBytesWritable indexMetaDataPtr = new ImmutableBytesWritable(ByteUtil.EMPTY_BYTE_ARRAY);
-                            IndexMaintainer.serializeAdditional(dataPTable, indexMetaDataPtr, indexesToPartiallyRebuild, conn);
-                            byte[] attribValue = ByteUtil.copyKeyBytesIfNecessary(indexMetaDataPtr);
-                            byte[] uuidValue = ServerCacheClient.generateId();
-        
-                            while ((result = dataTableScanner.next()) != null && !result.isEmpty()) {
-                                Put put = null;
-                                Delete del = null;
-                                for (Cell cell : result.rawCells()) {
-                                    if (KeyValue.Type.codeToType(cell.getTypeByte()) == KeyValue.Type.Put) {
-                                        if (put == null) {
-                                            put = new Put(CellUtil.cloneRow(cell));
-                                            put.setAttribute(PhoenixIndexCodec.INDEX_UUID, uuidValue);
-                                            put.setAttribute(PhoenixIndexCodec.INDEX_MD, attribValue);
-                                            put.setAttribute(BaseScannerRegionObserver.IGNORE_NEWER_MUTATIONS, PDataType.TRUE_BYTES);
-                                            mutations.add(put);
+                            QueryServices.INDEX_FAILURE_HANDLING_REBUILD_OVERLAP_TIME_ATTRIB,
+                            QueryServicesOptions.DEFAULT_INDEX_FAILURE_HANDLING_REBUILD_OVERLAP_TIME);
+                    for (Map.Entry<PTable, List<PTable>> entry : dataTableToIndexesMap.entrySet()) {
+                        PTable dataPTable = entry.getKey();
+                        List<PTable> indexesToPartiallyRebuild = entry.getValue();
+                        try {
+                            long earliestDisableTimestamp = Long.MAX_VALUE;
+                            List<IndexMaintainer> maintainers = Lists
+                                    .newArrayListWithExpectedSize(indexesToPartiallyRebuild.size());
+                            for (PTable index : indexesToPartiallyRebuild) {
+                                long disabledTimeStampVal = index.getIndexDisableTimestamp();
+                                if (disabledTimeStampVal > 0) {
+                                    if (disabledTimeStampVal < earliestDisableTimestamp) {
+                                        earliestDisableTimestamp = disabledTimeStampVal;
+                                    }
+    
+                                    maintainers.add(index.getIndexMaintainer(dataPTable, conn));
+                                }
+                            }
+                            // No indexes are disabled, so skip this table
+                            if (earliestDisableTimestamp == Long.MAX_VALUE) {
+                                continue;
+                            }
+
+                            long timeStamp = Math.max(0, earliestDisableTimestamp - overlapTime);
+                            LOG.info("Starting to build " + dataPTable + " indexes " + indexesToPartiallyRebuild
+                                    + " from timestamp=" + timeStamp);
+                            Scan dataTableScan = IndexManagementUtil.newLocalStateScan(maintainers);
+                            dataTableScan.setTimeRange(timeStamp, HConstants.LATEST_TIMESTAMP);
+                            byte[] physicalTableName = dataPTable.getPhysicalName().getBytes();
+                            try (HTableInterface dataHTable = conn.getQueryServices().getTable(physicalTableName)) {
+                                Result result;
+                                try (ResultScanner dataTableScanner = dataHTable.getScanner(dataTableScan)) {
+                                    int batchSize = conn.getMutateBatchSize();
+                                    List<Mutation> mutations = Lists.newArrayListWithExpectedSize(batchSize);
+                                    ImmutableBytesWritable indexMetaDataPtr = new ImmutableBytesWritable(
+                                            ByteUtil.EMPTY_BYTE_ARRAY);
+                                    IndexMaintainer.serializeAdditional(dataPTable, indexMetaDataPtr,
+                                            indexesToPartiallyRebuild, conn);
+                                    byte[] attribValue = ByteUtil.copyKeyBytesIfNecessary(indexMetaDataPtr);
+                                    byte[] uuidValue = ServerCacheClient.generateId();
+
+                                    while ((result = dataTableScanner.next()) != null && !result.isEmpty()) {
+                                        Put put = null;
+                                        Delete del = null;
+                                        for (Cell cell : result.rawCells()) {
+                                            if (KeyValue.Type.codeToType(cell.getTypeByte()) == KeyValue.Type.Put) {
+                                                if (put == null) {
+                                                    put = new Put(CellUtil.cloneRow(cell));
+                                                    put.setAttribute(PhoenixIndexCodec.INDEX_UUID, uuidValue);
+                                                    put.setAttribute(PhoenixIndexCodec.INDEX_MD, attribValue);
+                                                    put.setAttribute(BaseScannerRegionObserver.IGNORE_NEWER_MUTATIONS,
+                                                            PDataType.TRUE_BYTES);
+                                                    mutations.add(put);
+                                                }
+                                                put.add(cell);
+                                            } else {
+                                                if (del == null) {
+                                                    del = new Delete(CellUtil.cloneRow(cell));
+                                                    del.setAttribute(PhoenixIndexCodec.INDEX_UUID, uuidValue);
+                                                    del.setAttribute(PhoenixIndexCodec.INDEX_MD, attribValue);
+                                                    del.setAttribute(BaseScannerRegionObserver.IGNORE_NEWER_MUTATIONS,
+                                                            PDataType.TRUE_BYTES);
+                                                    mutations.add(del);
+                                                }
+                                                del.addDeleteMarker(cell);
+                                            }
                                         }
-                                        put.add(cell);
-                                    } else {
-                                        if (del == null) {
-                                            del = new Delete(CellUtil.cloneRow(cell));
-                                            del.setAttribute(PhoenixIndexCodec.INDEX_UUID, uuidValue);
-                                            del.setAttribute(PhoenixIndexCodec.INDEX_MD, attribValue);
-                                            del.setAttribute(BaseScannerRegionObserver.IGNORE_NEWER_MUTATIONS, PDataType.TRUE_BYTES);
-                                            mutations.add(del);
+                                        if (mutations.size() == batchSize) {
+                                            dataHTable.batch(mutations);
+                                            uuidValue = ServerCacheClient.generateId();
+                                            mutations.clear();
                                         }
-                                        del.addDeleteMarker(cell);
                                     }
-                                }
-                                if (mutations.size() == batchSize) {
-                                    dataHTable.batch(mutations);
-                                    uuidValue = ServerCacheClient.generateId();
+                                    if (!mutations.isEmpty()) {
+                                        dataHTable.batch(mutations);
+                                    }
                                 }
                             }
-                            if (!mutations.isEmpty()) {
-                                dataHTable.batch(mutations);
+                            for (PTable indexPTable : indexesToPartiallyRebuild) {
+                                AlterIndexStatement statement = new AlterIndexStatement(
+                                        NamedTableNode.create(indexPTable.getSchemaName().getString(), indexPTable
+                                                .getTableName().getString()), dataPTable.getTableName().getString(),
+                                        false, PIndexState.ACTIVE);
+                                client.alterIndex(statement);
                             }
+                        } catch (Exception e) { // Log, but try next table's indexes
+                            LOG.warn("Unable to rebuild " + dataPTable + " indexes " + indexesToPartiallyRebuild
+                                    + ". Will try again next on next scheduled invocation.", e);
                         }
                     }
-                    for (PTable indexPTable : indexesToPartiallyRebuild) {
-                        AlterIndexStatement statement = new AlterIndexStatement(
-                                NamedTableNode.create(indexPTable.getSchemaName().getString(), indexPTable.getTableName().getString()),
-                                dataPTable.getTableName().getString(),
-                                false, PIndexState.ACTIVE);
-                        client.alterIndex(statement);
-                    }
                 }
             } catch (Throwable t) {
                 LOG.warn("ScheduledBuildIndexTask failed!", t);


[47/47] phoenix git commit: Fix sync conflicts

Posted by ma...@apache.org.
Fix sync conflicts


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

Branch: refs/heads/calcite
Commit: b612f16964e80b7ca97441e9b7183c80853bea01
Parents: b8c8a4f 7601d59
Author: maryannxue <ma...@gmail.com>
Authored: Tue Sep 20 11:05:09 2016 -0700
Committer: maryannxue <ma...@gmail.com>
Committed: Tue Sep 20 11:05:09 2016 -0700

----------------------------------------------------------------------
 .../phoenix/end2end/AbsFunctionEnd2EndIT.java   |    2 +-
 .../phoenix/end2end/AggregateQueryIT.java       |   36 +
 .../AlterMultiTenantTableWithViewsIT.java       |    2 +-
 .../apache/phoenix/end2end/AlterSessionIT.java  |    2 +-
 .../apache/phoenix/end2end/AlterTableIT.java    |  705 +++----
 .../phoenix/end2end/AlterTableWithViewsIT.java  |    6 +-
 .../phoenix/end2end/AppendOnlySchemaIT.java     |    2 +-
 .../phoenix/end2end/ArithmeticQueryIT.java      |    2 +-
 .../phoenix/end2end/ArrayAppendFunctionIT.java  |    2 +-
 .../phoenix/end2end/ArrayConcatFunctionIT.java  |    2 +-
 .../phoenix/end2end/ArrayFillFunctionIT.java    |    2 +-
 .../phoenix/end2end/ArrayPrependFunctionIT.java |    2 +-
 .../end2end/ArrayToStringFunctionIT.java        |   80 +-
 .../phoenix/end2end/ArraysWithNullsIT.java      |    2 +-
 .../apache/phoenix/end2end/AutoCommitIT.java    |    2 +-
 .../phoenix/end2end/AutoPartitionViewsIT.java   |    4 +-
 .../BaseHBaseManagedTimeTableReuseIT.java       |   73 -
 .../apache/phoenix/end2end/BaseParallelIT.java  |   69 +
 .../end2end/BaseTenantSpecificViewIndexIT.java  |    2 +-
 .../org/apache/phoenix/end2end/BaseViewIT.java  |    1 -
 .../apache/phoenix/end2end/BinaryRowKeyIT.java  |    2 +-
 .../phoenix/end2end/CSVCommonsLoaderIT.java     |    2 +-
 .../apache/phoenix/end2end/CaseStatementIT.java |    2 +-
 .../apache/phoenix/end2end/CastAndCoerceIT.java |    2 +-
 .../phoenix/end2end/CbrtFunctionEnd2EndIT.java  |    2 +-
 .../end2end/ClientTimeArithmeticQueryIT.java    |    2 +-
 .../phoenix/end2end/CoalesceFunctionIT.java     |    2 +-
 .../ConnectionQueryServicesTestImpl.java        |   33 +-
 .../end2end/ConvertTimezoneFunctionIT.java      |    2 +-
 .../phoenix/end2end/CsvBulkLoadToolIT.java      |    6 +-
 .../org/apache/phoenix/end2end/DateTimeIT.java  |  761 ++++++-
 .../phoenix/end2end/DecodeFunctionIT.java       |    2 +-
 .../org/apache/phoenix/end2end/DeleteIT.java    |   12 +-
 .../apache/phoenix/end2end/DerivedTableIT.java  |   15 +-
 .../phoenix/end2end/DisableLocalIndexIT.java    |    4 +-
 .../phoenix/end2end/DistinctPrefixFilterIT.java |    4 +-
 .../apache/phoenix/end2end/DropSchemaIT.java    |    2 +-
 .../apache/phoenix/end2end/DynamicColumnIT.java |    2 +-
 .../apache/phoenix/end2end/DynamicFamilyIT.java |    2 +-
 .../apache/phoenix/end2end/DynamicUpsertIT.java |   33 +-
 .../phoenix/end2end/EncodeFunctionIT.java       |    2 +-
 .../phoenix/end2end/EvaluationOfORIT.java       |    2 +-
 .../phoenix/end2end/ExecuteStatementsIT.java    |    2 +-
 .../phoenix/end2end/ExpFunctionEnd2EndIT.java   |    2 +-
 .../phoenix/end2end/FirstValueFunctionIT.java   |    2 +-
 .../end2end/GetSetByteBitFunctionEnd2EndIT.java |    2 +-
 .../apache/phoenix/end2end/GroupByCaseIT.java   |   29 +-
 .../org/apache/phoenix/end2end/GroupByIT.java   |    5 +-
 .../end2end/HBaseManagedTimeTableReuseTest.java |   47 -
 .../phoenix/end2end/HBaseManagedTimeTest.java   |    2 +-
 .../apache/phoenix/end2end/HashJoinMoreIT.java  |   18 +-
 .../org/apache/phoenix/end2end/InListIT.java    |    2 +-
 .../phoenix/end2end/InMemoryOrderByIT.java      |    2 +-
 .../apache/phoenix/end2end/IndexExtendedIT.java |  578 ++++++
 .../org/apache/phoenix/end2end/IndexToolIT.java |  257 ---
 .../apache/phoenix/end2end/InstrFunctionIT.java |    2 +-
 .../org/apache/phoenix/end2end/IsNullIT.java    |    2 +-
 .../org/apache/phoenix/end2end/KeyOnlyIT.java   |    5 +-
 .../phoenix/end2end/LastValueFunctionIT.java    |    2 +-
 .../phoenix/end2end/LikeExpressionIT.java       |  125 +-
 .../phoenix/end2end/LnLogFunctionEnd2EndIT.java |    2 +-
 .../apache/phoenix/end2end/MD5FunctionIT.java   |    2 +-
 .../org/apache/phoenix/end2end/MapReduceIT.java |    2 +-
 .../phoenix/end2end/MappingTableDataTypeIT.java |    2 +-
 .../end2end/MinMaxAggregateFunctionIT.java      |    2 +-
 .../phoenix/end2end/ModulusExpressionIT.java    |    2 +-
 .../phoenix/end2end/MultiCfQueryExecIT.java     |    1 -
 .../phoenix/end2end/MutableIndexToolIT.java     |  129 --
 .../end2end/NamespaceSchemaMappingIT.java       |    2 +-
 .../org/apache/phoenix/end2end/NotQueryIT.java  |    2 +-
 .../phoenix/end2end/NthValueFunctionIT.java     |    2 +-
 .../end2end/OctetLengthFunctionEnd2EndIT.java   |    2 +-
 .../org/apache/phoenix/end2end/OrderByIT.java   |    2 +-
 .../end2end/ParallelStatsDisabledIT.java        |   30 +
 .../end2end/ParallelStatsDisabledTest.java      |   45 +
 .../phoenix/end2end/ParallelStatsEnabledIT.java |   31 +
 .../end2end/ParallelStatsEnabledTest.java       |   45 +
 .../apache/phoenix/end2end/PercentileIT.java    |   31 +-
 .../phoenix/end2end/PhoenixRuntimeIT.java       |   50 +-
 .../phoenix/end2end/PowerFunctionEnd2EndIT.java |    2 +-
 .../apache/phoenix/end2end/PrimitiveTypeIT.java |   62 +-
 .../end2end/QueryDatabaseMetaDataIT.java        |    9 +-
 .../phoenix/end2end/QueryExecWithoutSCNIT.java  |    2 +-
 .../org/apache/phoenix/end2end/QueryMoreIT.java |    8 +-
 .../apache/phoenix/end2end/RTrimFunctionIT.java |    2 +-
 .../org/apache/phoenix/end2end/ReadOnlyIT.java  |    2 +-
 .../end2end/RegexpReplaceFunctionIT.java        |    6 +-
 .../phoenix/end2end/RegexpSplitFunctionIT.java  |   54 +-
 .../phoenix/end2end/RegexpSubstrFunctionIT.java |    6 +-
 .../phoenix/end2end/ReverseFunctionIT.java      |    2 +-
 .../apache/phoenix/end2end/ReverseScanIT.java   |    2 +-
 .../phoenix/end2end/RoundFloorCeilFuncIT.java   |  683 +++++++
 .../RoundFloorCeilFunctionsEnd2EndIT.java       |  686 -------
 .../org/apache/phoenix/end2end/ScanQueryIT.java |    2 +-
 .../end2end/SequenceBulkAllocationIT.java       |    2 +-
 .../phoenix/end2end/SerialIteratorsIT.java      |    2 +-
 .../phoenix/end2end/ServerExceptionIT.java      |    2 +-
 .../phoenix/end2end/SignFunctionEnd2EndIT.java  |    2 +-
 .../end2end/SkipScanAfterManualSplitIT.java     |    4 +-
 .../apache/phoenix/end2end/SkipScanQueryIT.java |    4 +-
 .../phoenix/end2end/SortMergeJoinMoreIT.java    |    4 +-
 .../org/apache/phoenix/end2end/SortOrderIT.java |   11 +-
 .../phoenix/end2end/SpillableGroupByIT.java     |   21 +-
 .../phoenix/end2end/SpooledTmpFileDeleteIT.java |    2 +-
 .../phoenix/end2end/SqrtFunctionEnd2EndIT.java  |    2 +-
 .../phoenix/end2end/StatementHintsIT.java       |    2 +-
 .../org/apache/phoenix/end2end/StddevIT.java    |    2 +-
 .../apache/phoenix/end2end/StoreNullsIT.java    |   92 +-
 .../org/apache/phoenix/end2end/StringIT.java    |    2 +-
 .../end2end/StringToArrayFunctionIT.java        |    2 +-
 .../apache/phoenix/end2end/TenantIdTypeIT.java  |   14 +-
 .../end2end/TimezoneOffsetFunctionIT.java       |    2 +-
 .../phoenix/end2end/ToCharFunctionIT.java       |   13 +-
 .../phoenix/end2end/ToDateFunctionIT.java       |    2 +-
 .../phoenix/end2end/TransactionalViewIT.java    |    5 +-
 .../org/apache/phoenix/end2end/UnionAllIT.java  |  288 +--
 .../org/apache/phoenix/end2end/UpgradeIT.java   |  156 +-
 .../phoenix/end2end/UpsertBigValuesIT.java      |    2 +-
 .../end2end/UpsertSelectAutoCommitIT.java       |    2 +-
 .../org/apache/phoenix/end2end/UseSchemaIT.java |    2 +-
 .../end2end/index/AsyncImmutableIndexIT.java    |  114 --
 .../end2end/index/AsyncIndexDisabledIT.java     |    4 +-
 .../index/ChildViewsUseParentViewIndexIT.java   |  254 +++
 .../phoenix/end2end/index/DropMetadataIT.java   |    6 +-
 .../index/GlobalIndexOptimizationIT.java        |   21 +-
 .../phoenix/end2end/index/ImmutableIndexIT.java |   10 +-
 .../index/ImmutableIndexWithStatsIT.java        |    5 +-
 .../end2end/index/IndexExpressionIT.java        |   51 +-
 .../apache/phoenix/end2end/index/IndexIT.java   | 1147 +++++------
 .../phoenix/end2end/index/IndexMetadataIT.java  |   30 +-
 .../phoenix/end2end/index/LocalIndexIT.java     |  219 +--
 .../end2end/index/MutableIndexFailureIT.java    |  271 ++-
 .../phoenix/end2end/index/MutableIndexIT.java   |   12 +-
 .../end2end/index/ReadOnlyIndexFailureIT.java   |    2 +-
 .../phoenix/end2end/index/SaltedIndexIT.java    |    6 +-
 .../phoenix/end2end/index/ViewIndexIT.java      |   72 +-
 .../end2end/index/txn/MutableRollbackIT.java    |    8 +-
 .../phoenix/end2end/index/txn/RollbackIT.java   |    8 +-
 .../end2end/index/txn/TxWriteFailureIT.java     |    2 +-
 .../salted/SaltedTableUpsertSelectIT.java       |    4 +-
 .../salted/SaltedTableVarLengthRowKeyIT.java    |    4 +-
 .../apache/phoenix/execute/PartialCommitIT.java |    5 +-
 .../phoenix/iterate/PhoenixQueryTimeoutIT.java  |    4 +-
 .../iterate/RoundRobinResultIteratorIT.java     |    6 +-
 .../org/apache/phoenix/rpc/UpdateCacheIT.java   |   15 +-
 .../phoenix/rpc/UpdateCacheWithScnIT.java       |   12 +-
 .../apache/phoenix/trace/BaseTracingTestIT.java |    4 +-
 .../trace/PhoenixTableMetricsWriterIT.java      |   22 +-
 .../phoenix/trace/PhoenixTraceReaderIT.java     |   16 +-
 .../phoenix/trace/PhoenixTracingEndToEndIT.java |   50 +-
 .../org/apache/phoenix/tx/TransactionIT.java    |   87 +-
 .../org/apache/phoenix/tx/TxCheckpointIT.java   |   11 +-
 phoenix-core/src/main/antlr3/PhoenixSQL.g       |   15 +-
 .../phoenix/compile/ExpressionCompiler.java     |   26 +-
 .../coprocessor/MetaDataEndpointImpl.java       |   30 +-
 .../phoenix/coprocessor/MetaDataProtocol.java   |   23 +-
 .../coprocessor/MetaDataRegionObserver.java     |  216 +-
 .../phoenix/exception/SQLExceptionCode.java     |    3 +
 .../exception/UpgradeInProgressException.java   |   28 +
 .../exception/UpgradeNotRequiredException.java  |   27 +
 .../exception/UpgradeRequiredException.java     |   29 +
 .../apache/phoenix/execute/BaseQueryPlan.java   |   23 +-
 .../phoenix/execute/ClientAggregatePlan.java    |    7 +-
 .../phoenix/execute/ClientProcessingPlan.java   |    9 -
 .../apache/phoenix/execute/ClientScanPlan.java  |    4 -
 .../apache/phoenix/execute/CorrelatePlan.java   |   15 +-
 .../phoenix/execute/DelegateQueryPlan.java      |   13 +
 .../apache/phoenix/execute/HashJoinPlan.java    |   15 +-
 .../phoenix/execute/TupleProjectionPlan.java    |   11 -
 .../org/apache/phoenix/execute/UnionPlan.java   |   21 +-
 .../apache/phoenix/execute/UnnestArrayPlan.java |   11 -
 .../phoenix/expression/ExpressionType.java      |    9 +-
 .../expression/function/CeilDateExpression.java |    3 +
 .../function/CeilTimestampExpression.java       |    3 +
 .../expression/function/DateScalarFunction.java |   54 +
 .../expression/function/DayOfMonthFunction.java |    4 +-
 .../expression/function/DayOfWeekFunction.java  |   86 +
 .../expression/function/DayOfYearFunction.java  |   78 +
 .../expression/function/HourFunction.java       |    4 +-
 .../expression/function/MinuteFunction.java     |    4 +-
 .../expression/function/MonthFunction.java      |    4 +-
 .../function/RoundDateExpression.java           |    3 +
 .../function/RoundDecimalExpression.java        |    2 +-
 .../function/RoundJodaDateExpression.java       |    3 +
 .../expression/function/SecondFunction.java     |    4 +-
 .../expression/function/ToDateFunction.java     |   10 +-
 .../expression/function/WeekFunction.java       |    4 +-
 .../expression/function/YearFunction.java       |    4 +-
 .../hbase/index/covered/NonTxIndexBuilder.java  |    4 +-
 .../hbase/index/covered/data/IndexMemStore.java |   10 +-
 .../covered/update/IndexUpdateManager.java      |    4 +-
 .../apache/phoenix/index/IndexMaintainer.java   |   16 +-
 .../index/PhoenixIndexFailurePolicy.java        |    5 +-
 .../phoenix/iterate/BaseResultIterators.java    |    6 +-
 .../iterate/MergeSortResultIterator.java        |    2 +-
 .../phoenix/iterate/UnionResultIterators.java   |    4 +-
 .../apache/phoenix/jdbc/PhoenixConnection.java  |   27 +-
 .../phoenix/jdbc/PhoenixDatabaseMetaData.java   |    2 +-
 .../phoenix/jdbc/PhoenixPreparedStatement.java  |   26 +-
 .../apache/phoenix/jdbc/PhoenixStatement.java   |   78 +-
 .../mapreduce/FormatToBytesWritableMapper.java  |    3 +-
 .../index/automation/PhoenixMRJobSubmitter.java |    4 +
 .../phoenix/parse/ExecuteUpgradeStatement.java  |   34 +
 .../apache/phoenix/parse/ParseNodeFactory.java  |    4 +
 .../org/apache/phoenix/parse/SQLParser.java     |    2 +-
 .../phoenix/query/ConnectionQueryServices.java  |    3 +
 .../query/ConnectionQueryServicesImpl.java      | 1849 ++++++++++--------
 .../query/ConnectionlessQueryServicesImpl.java  |    8 +
 .../query/DelegateConnectionQueryServices.java  |   10 +
 .../apache/phoenix/query/QueryConstants.java    |    7 +
 .../org/apache/phoenix/query/QueryServices.java |    2 +-
 .../phoenix/query/QueryServicesOptions.java     |    6 +-
 .../apache/phoenix/schema/MetaDataClient.java   |  647 +++---
 .../apache/phoenix/schema/PMetaDataImpl.java    |    2 +-
 .../java/org/apache/phoenix/schema/PTable.java  |   20 +-
 .../org/apache/phoenix/schema/PTableImpl.java   |   54 +-
 .../org/apache/phoenix/schema/SortOrder.java    |   11 +
 .../phoenix/schema/stats/StatisticsScanner.java |   72 +-
 .../apache/phoenix/schema/types/PDataType.java  |   19 +-
 .../org/apache/phoenix/schema/types/PDate.java  |  283 +--
 .../apache/phoenix/schema/types/PDecimal.java   |    6 +-
 .../org/apache/phoenix/schema/types/PLong.java  |  519 ++---
 .../org/apache/phoenix/schema/types/PTime.java  |    2 +-
 .../apache/phoenix/schema/types/PTimestamp.java |   42 +-
 .../phoenix/schema/types/PUnsignedDate.java     |  259 ++-
 .../phoenix/schema/types/PUnsignedLong.java     |  317 +--
 .../phoenix/schema/types/PUnsignedTime.java     |    2 +-
 .../schema/types/PUnsignedTimestamp.java        |  152 +-
 .../phoenix/trace/PhoenixMetricsSink.java       |   42 +-
 .../org/apache/phoenix/trace/TraceReader.java   |   12 +-
 .../apache/phoenix/util/CSVCommonsLoader.java   |    2 +-
 .../java/org/apache/phoenix/util/DateUtil.java  |   23 +-
 .../org/apache/phoenix/util/ExpressionUtil.java |   15 +-
 .../phoenix/util/PhoenixContextExecutor.java    |    6 +-
 .../org/apache/phoenix/util/PhoenixRuntime.java |    2 +-
 .../java/org/apache/phoenix/util/QueryUtil.java |    6 +-
 .../org/apache/phoenix/util/UpgradeUtil.java    |   24 +-
 .../phoenix/util/csv/CsvUpsertExecutor.java     |    8 +-
 .../phoenix/expression/LikeExpressionTest.java  |    6 +
 .../RoundFloorCeilExpressionsTest.java          |   14 +
 .../apache/phoenix/jdbc/PhoenixTestDriver.java  |    2 +-
 .../apache/phoenix/parse/QueryParserTest.java   |   10 +
 .../java/org/apache/phoenix/query/BaseTest.java |   83 +-
 .../phoenix/query/QueryServicesTestImpl.java    |    4 +-
 .../schema/stats/StatisticsScannerTest.java     |  144 ++
 .../phoenix/schema/types/PDataTypeTest.java     |   18 +
 .../java/org/apache/phoenix/util/TestUtil.java  |   29 +
 .../org/apache/phoenix/flume/PhoenixSinkIT.java |    4 +-
 .../phoenix/flume/RegexEventSerializerIT.java   |    4 +-
 .../apache/phoenix/pherf/ResultBaseTestIT.java  |    4 +-
 .../apache/phoenix/pherf/SchemaReaderIT.java    |    4 +-
 .../java/org/apache/phoenix/pig/BasePigIT.java  |    6 +-
 .../phoenix/end2end/QueryServerBasicsIT.java    |    2 +-
 .../apache/phoenix/queryserver/server/Main.java |    4 -
 pom.xml                                         |   86 +-
 255 files changed, 8201 insertions(+), 5705 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/main/java/org/apache/phoenix/execute/CorrelatePlan.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/execute/CorrelatePlan.java
index 9e6dad3,b1d00ab..be0c7c0
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/CorrelatePlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/CorrelatePlan.java
@@@ -28,9 -27,7 +28,8 @@@ import org.apache.phoenix.compile.Order
  import org.apache.phoenix.compile.QueryPlan;
  import org.apache.phoenix.exception.SQLExceptionCode;
  import org.apache.phoenix.exception.SQLExceptionInfo;
 +import org.apache.phoenix.execute.RuntimeContext.CorrelateVariable;
  import org.apache.phoenix.execute.TupleProjector.ProjectedValueTuple;
- import org.apache.phoenix.iterate.DefaultParallelScanGrouper;
  import org.apache.phoenix.iterate.ParallelScanGrouper;
  import org.apache.phoenix.iterate.ResultIterator;
  import org.apache.phoenix.parse.JoinTableNode.JoinType;
@@@ -101,20 -98,9 +100,10 @@@ public class CorrelatePlan extends Dele
      }
  
      @Override
-     public ResultIterator iterator() throws SQLException {
-         return iterator(DefaultParallelScanGrouper.getInstance());
-     }
- 
-     @Override
-     public ResultIterator iterator(ParallelScanGrouper scanGrouper) 
-                 throws SQLException {
-         return iterator(scanGrouper, null);
-     }
-     @Override
-     public ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan)
+     public ResultIterator iterator(final ParallelScanGrouper scanGrouper, final Scan scan)
              throws SQLException {
          return new ResultIterator() {
 +            private final CorrelateVariable variable = runtimeContext.getCorrelateVariable(variableId);
              private final ValueBitSet destBitSet = ValueBitSet.newInstance(joinedSchema);
              private final ValueBitSet lhsBitSet = ValueBitSet.newInstance(lhsSchema);
              private final ValueBitSet rhsBitSet = 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateQueryPlan.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateQueryPlan.java
index c1d893d,46eec91..3f120fd
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateQueryPlan.java
@@@ -128,4 -127,14 +131,14 @@@ public abstract class DelegateQueryPla
      public Integer getOffset() {
          return delegate.getOffset();
      }
+      
 -     @Override
 -     public ResultIterator iterator() throws SQLException {
 -         return iterator(DefaultParallelScanGrouper.getInstance());
 -     }
++    @Override
++    public ResultIterator iterator() throws SQLException {
++        return iterator(DefaultParallelScanGrouper.getInstance());
++    }
+  
 -     @Override
 -     public ResultIterator iterator(ParallelScanGrouper scanGrouper) throws SQLException {
 -         return iterator(scanGrouper, null);
 -     }
 -}
++    @Override
++    public ResultIterator iterator(ParallelScanGrouper scanGrouper) throws SQLException {
++        return iterator(scanGrouper, null);
++    }
 +}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjectionPlan.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/main/java/org/apache/phoenix/execute/UnionPlan.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/execute/UnionPlan.java
index 56c8340,e2c18b1..1467824
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/UnionPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/UnionPlan.java
@@@ -30,8 -29,10 +29,9 @@@ import org.apache.phoenix.compile.Group
  import org.apache.phoenix.compile.OrderByCompiler.OrderBy;
  import org.apache.phoenix.compile.QueryPlan;
  import org.apache.phoenix.compile.RowProjector;
 -import org.apache.phoenix.compile.ScanRanges;
  import org.apache.phoenix.compile.StatementContext;
  import org.apache.phoenix.iterate.ConcatResultIterator;
+ import org.apache.phoenix.iterate.DefaultParallelScanGrouper;
  import org.apache.phoenix.iterate.LimitingResultIterator;
  import org.apache.phoenix.iterate.MergeSortTopNResultIterator;
  import org.apache.phoenix.iterate.OffsetResultIterator;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/main/java/org/apache/phoenix/execute/UnnestArrayPlan.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/main/java/org/apache/phoenix/expression/ExpressionType.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixTestDriver.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
index e064dc9,57df138..7dfa9cc
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
@@@ -141,9 -136,7 +136,8 @@@ import org.apache.phoenix.end2end.BaseH
  import org.apache.phoenix.exception.SQLExceptionCode;
  import org.apache.phoenix.exception.SQLExceptionInfo;
  import org.apache.phoenix.jdbc.PhoenixConnection;
 +import org.apache.phoenix.jdbc.PhoenixCalciteTestDriver;
  import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
- import org.apache.phoenix.jdbc.PhoenixDriver;
  import org.apache.phoenix.jdbc.PhoenixEmbeddedDriver;
  import org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo;
  import org.apache.phoenix.jdbc.PhoenixTestDriver;
@@@ -504,9 -489,7 +491,8 @@@ public abstract class BaseTest 
      }
      
      protected static String url;
 +    protected static String calciteUrl;
      protected static PhoenixTestDriver driver;
-     protected static PhoenixDriver realDriver;
      protected static boolean clusterInitialized = false;
      private static HBaseTestingUtility utility;
      protected static final Configuration config = HBaseConfiguration.create(); 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b612f169/pom.xml
----------------------------------------------------------------------
diff --cc pom.xml
index 49af7f2,3c000e2..d871784
--- a/pom.xml
+++ b/pom.xml
@@@ -97,9 -97,8 +97,9 @@@
      <jodatime.version>1.6</jodatime.version>
      <joni.version>2.1.2</joni.version>
      <avatica.version>1.8.0</avatica.version>
 +    <calcite.version>1.9.0-SNAPSHOT</calcite.version>
      <jettyVersion>8.1.7.v20120910</jettyVersion>
-     <tephra.version>0.8.0-incubating</tephra.version>
+     <tephra.version>0.9.0-incubating</tephra.version>
      <spark.version>1.6.1</spark.version>
      <scala.version>2.10.4</scala.version>
      <scala.binary.version>2.10</scala.binary.version>


[36/47] phoenix git commit: PHOENIX-3290 Move and/or combine as many NeedsOwnCluster tests to bring down test run time

Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java
index d9a59a9..a3c36fa 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java
@@ -69,7 +69,6 @@ public abstract class BaseViewIT extends BaseOwnClusterHBaseManagedTimeIT {
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
         props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Integer.toString(20));
-        props.put(QueryServices.QUEUE_SIZE_ATTRIB, Integer.toString(1024));
         props.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.toString(true));
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java
index 8968555..4971fc3 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java
@@ -40,7 +40,9 @@ import org.apache.phoenix.mapreduce.CsvBulkLoadTool;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.util.DateUtil;
+import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.TestUtil;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -57,8 +59,8 @@ public class CsvBulkLoadToolIT extends BaseOwnClusterHBaseManagedTimeIT {
         serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
         Map<String, String> clientProps = Maps.newHashMapWithExpectedSize(1);
         clientProps.put(QueryServices.TRANSACTIONS_ENABLED, "true");
-        setUpRealDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet().iterator()));
-        zkQuorum = "localhost:" + getUtility().getZkCluster().getClientPort();
+        setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet().iterator()));
+        zkQuorum = TestUtil.LOCALHOST + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + getUtility().getZkCluster().getClientPort();
         conn = DriverManager.getConnection(getUrl());
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java
new file mode 100644
index 0000000..b23e342
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java
@@ -0,0 +1,578 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+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;
+import java.util.UUID;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.MetaTableAccessor;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.mapreduce.index.IndexTool;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.QueryUtil;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
+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.Lists;
+import com.google.common.collect.Maps;
+
+/**
+ * Tests for the {@link IndexTool}
+ */
+@RunWith(Parameterized.class)
+public class IndexExtendedIT extends BaseOwnClusterHBaseManagedTimeIT {
+    private final boolean localIndex;
+    private final boolean transactional;
+    private final boolean directApi;
+    private final String tableDDLOptions;
+    private final boolean mutable;
+    
+    public IndexExtendedIT(boolean transactional, boolean mutable, boolean localIndex, boolean directApi) {
+        this.localIndex = localIndex;
+        this.transactional = transactional;
+        this.directApi = directApi;
+        this.mutable = mutable;
+        StringBuilder optionBuilder = new StringBuilder();
+        if (!mutable) {
+            optionBuilder.append(" IMMUTABLE_ROWS=true ");
+        }
+        if (transactional) {
+            if (!(optionBuilder.length()==0)) {
+                optionBuilder.append(",");
+            }
+            optionBuilder.append(" TRANSACTIONAL=true ");
+        }
+        optionBuilder.append(" SPLIT ON(1,2)");
+        this.tableDDLOptions = optionBuilder.toString();
+    }
+    
+    @BeforeClass
+    public static void doSetup() throws Exception {
+        Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(1);
+        serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
+        Map<String, String> clientProps = Maps.newHashMapWithExpectedSize(1);
+        clientProps.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.TRUE.toString());
+        setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet()
+                .iterator()));
+    }
+    
+    @Parameters(name="transactional = {0} , mutable = {1} , localIndex = {2}, directApi = {3}")
+    public static Collection<Boolean[]> data() {
+        return Arrays.asList(new Boolean[][] {     
+                 { false, false, false, false }, { false, false, false, true }, { false, false, true, false }, { false, false, true, true }, 
+                 { false, true, false, false }, { false, true, false, true }, { false, true, true, false }, { false, true, true, true }, 
+                 { true, false, false, false }, { true, false, false, true }, { true, false, true, false }, { true, false, true, true }, 
+                 { true, true, false, false }, { true, true, false, true }, { true, true, true, false }, { true, true, true, true }
+           });
+    }
+    
+    /**
+     * This test is to assert that updates that happen to rows of a mutable table after an index is created in ASYNC mode and before
+     * the MR job runs, do show up in the index table . 
+     * @throws Exception
+     */
+    @Test
+    public void testMutableIndexWithUpdates() throws Exception {
+        if (!mutable || transactional) {
+            return;
+        }
+        String schemaName = generateRandomString();
+        String dataTableName = generateRandomString();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+        String indexTableName = generateRandomString();
+        String indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        Statement stmt = conn.createStatement();
+        try {
+            stmt.execute(String.format("CREATE TABLE %s (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, ZIP INTEGER)",dataTableFullName));
+            String upsertQuery = String.format("UPSERT INTO %s VALUES(?, ?, ?)",dataTableFullName);
+            PreparedStatement stmt1 = conn.prepareStatement(upsertQuery);
+            
+            int id = 1;
+            // insert two rows
+            IndexExtendedIT.upsertRow(stmt1, id++);
+            IndexExtendedIT.upsertRow(stmt1, id++);
+            conn.commit();
+            
+            stmt.execute(String.format("CREATE " + (localIndex ? "LOCAL" : "") + " INDEX %s ON %s (UPPER(NAME)) ASYNC ", indexTableName,dataTableFullName));
+            
+            //update a row 
+            stmt1.setInt(1, 1);
+            stmt1.setString(2, "uname" + String.valueOf(10));
+            stmt1.setInt(3, 95050 + 1);
+            stmt1.executeUpdate();
+            conn.commit();  
+            
+            //verify rows are fetched from data table.
+            String selectSql = String.format("SELECT ID FROM %s WHERE UPPER(NAME) ='UNAME2'",dataTableFullName);
+            ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
+            String actualExplainPlan = QueryUtil.getExplainPlan(rs);
+            
+            //assert we are pulling from data table.
+            assertEquals(String.format("CLIENT PARALLEL 1-WAY FULL SCAN OVER %s\n" +
+                    "    SERVER FILTER BY UPPER(NAME) = 'UNAME2'",dataTableFullName),actualExplainPlan);
+            
+            rs = stmt1.executeQuery(selectSql);
+            assertTrue(rs.next());
+            assertEquals(2, rs.getInt(1));
+            assertFalse(rs.next());
+           
+            //run the index MR job.
+            runIndexTool(schemaName, dataTableName, indexTableName);
+            
+            //assert we are pulling from index table.
+            rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
+            actualExplainPlan = QueryUtil.getExplainPlan(rs);
+            // TODO: why is it a 1-WAY parallel scan only for !transactional && mutable && localIndex
+            assertExplainPlan(actualExplainPlan, dataTableFullName, indexTableFullName);
+            
+            rs = stmt.executeQuery(selectSql);
+            assertTrue(rs.next());
+            assertEquals(2, rs.getInt(1));
+            assertFalse(rs.next());
+        } finally {
+            conn.close();
+        }
+    }
+
+    private void runIndexTool(String schemaName, String dataTableName, String indexTableName) throws Exception {
+        IndexTool indexingTool = new IndexTool();
+        Configuration conf = new Configuration(getUtility().getConfiguration());
+        conf.set(QueryServices.TRANSACTIONS_ENABLED, Boolean.TRUE.toString());
+        indexingTool.setConf(conf);
+        final String[] cmdArgs = getArgValues(schemaName, dataTableName, indexTableName);
+        int status = indexingTool.run(cmdArgs);
+        assertEquals(0, status);
+    }
+
+    @Test
+    public void testSecondaryIndex() throws Exception {
+        String schemaName = generateRandomString();
+        String dataTableName = generateRandomString();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+        String indexTableName = generateRandomString();
+        String indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        try {
+            String stmString1 = "CREATE TABLE " + dataTableFullName + " (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, ZIP INTEGER) " +  tableDDLOptions;
+            conn.createStatement().execute(stmString1);
+            String upsertQuery = String.format("UPSERT INTO %s VALUES(?, ?, ?)", dataTableFullName);
+            PreparedStatement stmt1 = conn.prepareStatement(upsertQuery);
+            
+            // insert two rows
+            upsertRow(stmt1, 1);
+            upsertRow(stmt1, 2);
+            conn.commit();
+            
+            if (transactional) {
+                // insert two rows in another connection without committing so that they are not visible to other transactions
+                try (Connection conn2 = DriverManager.getConnection(getUrl(), props)) {
+                    conn2.setAutoCommit(false);
+                    PreparedStatement stmt2 = conn2.prepareStatement(upsertQuery);
+                    upsertRow(stmt2, 5);
+                    upsertRow(stmt2, 6);
+                    ResultSet rs = conn.createStatement().executeQuery("SELECT count(*) from "+dataTableFullName);
+                    assertTrue(rs.next());
+                    assertEquals("Unexpected row count ", 2, rs.getInt(1));
+                    assertFalse(rs.next());
+                    rs = conn2.createStatement().executeQuery("SELECT count(*) from "+dataTableFullName);
+                    assertTrue(rs.next());
+                    assertEquals("Unexpected row count ", 4, rs.getInt(1));
+                    assertFalse(rs.next());
+                }
+            }
+            
+            String stmtString2 = String.format("CREATE %s INDEX %s ON %s  (LPAD(UPPER(NAME),8,'x')||'_xyz') ASYNC ", (localIndex ? "LOCAL" : ""), indexTableName, dataTableFullName);
+            conn.createStatement().execute(stmtString2);
+   
+            //verify rows are fetched from data table.
+            String selectSql = String.format("SELECT ID FROM %s WHERE LPAD(UPPER(NAME),8,'x')||'_xyz' = 'xxUNAME2_xyz'", dataTableFullName);
+            ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
+            String actualExplainPlan = QueryUtil.getExplainPlan(rs);
+            
+            //assert we are pulling from data table.
+            assertEquals(
+                    String.format("CLIENT PARALLEL 1-WAY FULL SCAN OVER %s\n"
+                    + "    SERVER FILTER BY (LPAD(UPPER(NAME), 8, 'x') || '_xyz') = 'xxUNAME2_xyz'", dataTableFullName), actualExplainPlan);
+            
+            rs = stmt1.executeQuery(selectSql);
+            assertTrue(rs.next());
+            assertEquals(2, rs.getInt(1));
+            assertFalse(rs.next());
+            conn.commit();
+           
+            //run the index MR job.
+            runIndexTool(schemaName, dataTableName, indexTableName);
+            
+            // insert two more rows
+            upsertRow(stmt1, 3);
+            upsertRow(stmt1, 4);
+            conn.commit();
+            
+            //assert we are pulling from index table.
+            rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
+            actualExplainPlan = QueryUtil.getExplainPlan(rs);
+            assertExplainPlan(actualExplainPlan, dataTableFullName, indexTableFullName);
+            
+            rs = conn.createStatement().executeQuery(selectSql);
+            assertTrue(rs.next());
+            assertEquals(2, rs.getInt(1));
+            assertFalse(rs.next());
+        } finally {
+            conn.close();
+        }
+    }
+    
+    private void assertExplainPlan(final String actualExplainPlan, String dataTableFullName, String indexTableFullName) {
+        String expectedExplainPlan;
+        if(localIndex) {
+            expectedExplainPlan = String.format(" RANGE SCAN OVER %s [1,",
+                    dataTableFullName);
+        } else {
+            expectedExplainPlan = String.format(" RANGE SCAN OVER %s",
+                    indexTableFullName);
+        }
+        assertTrue(actualExplainPlan + "\n expected to contain \n" + expectedExplainPlan, actualExplainPlan.contains(expectedExplainPlan));
+    }
+
+    private String[] getArgValues(String schemaName, String dataTable, String indxTable) {
+        final List<String> args = Lists.newArrayList();
+        if (schemaName!=null) {
+            args.add("-s");
+            args.add(schemaName);
+        }
+        args.add("-dt");
+        args.add(dataTable);
+        args.add("-it");
+        args.add(indxTable);
+        if(directApi) {
+            args.add("-direct");
+            // Need to run this job in foreground for the test to be deterministic
+            args.add("-runfg");
+        }
+
+        args.add("-op");
+        args.add("/tmp/"+UUID.randomUUID().toString());
+        return args.toArray(new String[0]);
+    }
+
+    private static void upsertRow(PreparedStatement stmt, int i) throws SQLException {
+        // insert row
+        stmt.setInt(1, i);
+        stmt.setString(2, "uname" + String.valueOf(i));
+        stmt.setInt(3, 95050 + i);
+        stmt.executeUpdate();
+    }
+
+    @Test
+    public void testDeleteFromImmutable() throws Exception {
+        if (transactional || mutable) {
+            return;
+        }
+        if (localIndex) { // TODO: remove this return once PHOENIX-3292 is fixed
+            return;
+        }
+        String schemaName = generateRandomString();
+        String dataTableName = generateRandomString();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+        String indexTableName = generateRandomString();
+        String indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.createStatement().execute("CREATE TABLE " + dataTableFullName + " (\n" + 
+                    "        pk1 VARCHAR NOT NULL,\n" + 
+                    "        pk2 VARCHAR NOT NULL,\n" + 
+                    "        pk3 VARCHAR\n" + 
+                    "        CONSTRAINT PK PRIMARY KEY \n" + 
+                    "        (\n" + 
+                    "        pk1,\n" + 
+                    "        pk2,\n" + 
+                    "        pk3\n" + 
+                    "        )\n" + 
+                    "        ) IMMUTABLE_ROWS=true");
+            conn.createStatement().execute("upsert into " + dataTableFullName + " (pk1, pk2, pk3) values ('a', '1', '1')");
+            conn.createStatement().execute("upsert into " + dataTableFullName + " (pk1, pk2, pk3) values ('b', '2', '2')");
+            conn.commit();
+            conn.createStatement().execute("CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexTableName + " ON " + dataTableFullName + " (pk3, pk2) ASYNC");
+            
+            // this delete will be issued at a timestamp later than the above timestamp of the index table
+            conn.createStatement().execute("delete from " + dataTableFullName + " where pk1 = 'a'");
+            conn.commit();
+
+            //run the index MR job.
+            runIndexTool(schemaName, dataTableName, indexTableName);
+
+            // upsert two more rows
+            conn.createStatement().execute(
+                "upsert into " + dataTableFullName + " (pk1, pk2, pk3) values ('a', '3', '3')");
+            conn.createStatement().execute(
+                "upsert into " + dataTableFullName + " (pk1, pk2, pk3) values ('b', '4', '4')");
+            conn.commit();
+
+            // validate that delete markers were issued correctly and only ('a', '1', 'value1') was
+            // deleted
+            String query = "SELECT pk3 from " + dataTableFullName + " ORDER BY pk3";
+            ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + query);
+            String expectedPlan =
+                    "CLIENT PARALLEL 1-WAY FULL SCAN OVER " + indexTableFullName + "\n"
+                            + "    SERVER FILTER BY FIRST KEY ONLY";
+            assertEquals("Wrong plan ", expectedPlan, QueryUtil.getExplainPlan(rs));
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals("2", rs.getString(1));
+            assertTrue(rs.next());
+            assertEquals("3", rs.getString(1));
+            assertTrue(rs.next());
+            assertEquals("4", rs.getString(1));
+            assertFalse(rs.next());
+        }
+    }
+
+    private Connection getConnectionForLocalIndexTest() throws SQLException{
+        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+        props.put(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, Boolean.TRUE.toString());
+        return DriverManager.getConnection(getUrl(),props);
+    }
+
+    private void createBaseTable(String tableName, String splits) throws SQLException {
+        Connection conn = getConnectionForLocalIndexTest();
+        String ddl = "CREATE TABLE " + tableName + " (t_id VARCHAR NOT NULL,\n" +
+                "k1 INTEGER NOT NULL,\n" +
+                "k2 INTEGER NOT NULL,\n" +
+                "k3 INTEGER,\n" +
+                "v1 VARCHAR,\n" +
+                "CONSTRAINT pk PRIMARY KEY (t_id, k1, k2))\n"
+                        + (splits != null ? (" split on " + splits) : "");
+        conn.createStatement().execute(ddl);
+        conn.close();
+    }
+
+    // Moved from LocalIndexIT because it was causing parallel runs to hang
+    @Test
+    public void testLocalIndexScanAfterRegionSplit() throws Exception {
+        // This test just needs be run once
+        if (!localIndex || transactional || mutable || directApi) {
+            return;
+        }
+        String schemaName = generateRandomString();
+        String tableName = schemaName + "." + generateRandomString();
+        String indexName = "IDX_" + generateRandomString();
+        TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), false);
+        String indexPhysicalTableName = physicalTableName.getNameAsString();
+
+        createBaseTable(tableName, "('e','j','o')");
+        Connection conn1 = getConnectionForLocalIndexTest();
+        try{
+            String[] strings = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
+            for (int i = 0; i < 26; i++) {
+                conn1.createStatement().execute(
+                    "UPSERT INTO " + tableName + " values('"+strings[i]+"'," + i + ","
+                            + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')");
+            }
+            conn1.commit();
+            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)");
+            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + "_2 ON " + tableName + "(k3)");
+
+            ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + tableName);
+            assertTrue(rs.next());
+            
+            HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
+            for (int i = 1; i < 5; i++) {
+                admin.split(physicalTableName, ByteUtil.concat(Bytes.toBytes(strings[3*i])));
+                List<HRegionInfo> regionsOfUserTable =
+                        MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
+                                physicalTableName, false);
+
+                while (regionsOfUserTable.size() != (4+i)) {
+                    Thread.sleep(100);
+                    regionsOfUserTable = MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(),
+                            admin.getConnection(), physicalTableName, false);
+                }
+                assertEquals(4+i, regionsOfUserTable.size());
+                String[] tIdColumnValues = new String[26]; 
+                String[] v1ColumnValues = new String[26];
+                int[] k1ColumnValue = new int[26];
+                String query = "SELECT t_id,k1,v1 FROM " + tableName;
+                rs = conn1.createStatement().executeQuery(query);
+                Thread.sleep(1000);
+                for (int j = 0; j < 26; j++) {
+                    assertTrue(rs.next());
+                    tIdColumnValues[j] = rs.getString("t_id");
+                    k1ColumnValue[j] = rs.getInt("k1");
+                    v1ColumnValues[j] = rs.getString("V1");
+                }
+                Arrays.sort(tIdColumnValues);
+                Arrays.sort(v1ColumnValues);
+                Arrays.sort(k1ColumnValue);
+                assertTrue(Arrays.equals(strings, tIdColumnValues));
+                assertTrue(Arrays.equals(strings, v1ColumnValues));
+                for(int m=0;m<26;m++) {
+                    assertEquals(m, k1ColumnValue[m]);
+                }
+
+                rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
+                assertEquals(
+                        "CLIENT PARALLEL " + (4 + i) + "-WAY RANGE SCAN OVER "
+                                + indexPhysicalTableName + " [1]\n"
+                                        + "    SERVER FILTER BY FIRST KEY ONLY\n"
+                                + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+                
+                query = "SELECT t_id,k1,k3 FROM " + tableName;
+                rs = conn1.createStatement().executeQuery("EXPLAIN "+query);
+                assertEquals(
+                    "CLIENT PARALLEL "
+                            + ((strings[3 * i].compareTo("j") < 0) ? (4 + i) : (4 + i - 1))
+                            + "-WAY RANGE SCAN OVER "
+                            + indexPhysicalTableName + " [2]\n"
+                                    + "    SERVER FILTER BY FIRST KEY ONLY\n"
+                            + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+                rs = conn1.createStatement().executeQuery(query);
+                Thread.sleep(1000);
+                int[] k3ColumnValue = new int[26];
+                for (int j = 0; j < 26; j++) {
+                    assertTrue(rs.next());
+                    tIdColumnValues[j] = rs.getString("t_id");
+                    k1ColumnValue[j] = rs.getInt("k1");
+                    k3ColumnValue[j] = rs.getInt("k3");
+                }
+                Arrays.sort(tIdColumnValues);
+                Arrays.sort(k1ColumnValue);
+                Arrays.sort(k3ColumnValue);
+                assertTrue(Arrays.equals(strings, tIdColumnValues));
+                for(int m=0;m<26;m++) {
+                    assertEquals(m, k1ColumnValue[m]);
+                    assertEquals(m+2, k3ColumnValue[m]);
+                }
+            }
+       } finally {
+            conn1.close();
+        }
+    }
+
+    // Moved from LocalIndexIT because it was causing parallel runs to hang
+    @Test
+    public void testLocalIndexScanAfterRegionsMerge() throws Exception {
+        // This test just needs be run once
+        if (!localIndex || transactional || mutable || directApi) {
+            return;
+        }
+        String schemaName = generateRandomString();
+        String tableName = schemaName + "." + generateRandomString();
+        String indexName = "IDX_" + generateRandomString();
+        TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), false);
+        String indexPhysicalTableName = physicalTableName.getNameAsString();
+
+        createBaseTable(tableName, "('e','j','o')");
+        Connection conn1 = getConnectionForLocalIndexTest();
+        try{
+            String[] strings = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
+            for (int i = 0; i < 26; i++) {
+                conn1.createStatement().execute(
+                    "UPSERT INTO " + tableName + " values('"+strings[i]+"'," + i + ","
+                            + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')");
+            }
+            conn1.commit();
+            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)");
+            conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + "_2 ON " + tableName + "(k3)");
+
+            ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + tableName);
+            assertTrue(rs.next());
+
+            HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
+            List<HRegionInfo> regionsOfUserTable =
+                    MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
+                        physicalTableName, false);
+            admin.mergeRegions(regionsOfUserTable.get(0).getEncodedNameAsBytes(),
+                regionsOfUserTable.get(1).getEncodedNameAsBytes(), false);
+            regionsOfUserTable =
+                    MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
+                            physicalTableName, false);
+
+            while (regionsOfUserTable.size() != 3) {
+                Thread.sleep(100);
+                regionsOfUserTable = MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(),
+                        admin.getConnection(), physicalTableName, false);
+            }
+            String query = "SELECT t_id,k1,v1 FROM " + tableName;
+            rs = conn1.createStatement().executeQuery(query);
+            Thread.sleep(1000);
+            for (int j = 0; j < 26; j++) {
+                assertTrue(rs.next());
+                assertEquals(strings[25 - j], rs.getString("t_id"));
+                assertEquals(25 - j, rs.getInt("k1"));
+                assertEquals(strings[j], rs.getString("V1"));
+            }
+            rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
+            assertEquals(
+                "CLIENT PARALLEL " + 3 + "-WAY RANGE SCAN OVER "
+                        + indexPhysicalTableName
+                        + " [1]\n" + "    SERVER FILTER BY FIRST KEY ONLY\n"
+                        + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+
+            query = "SELECT t_id,k1,k3 FROM " + tableName;
+            rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
+            assertEquals(
+                "CLIENT PARALLEL " + 3 + "-WAY RANGE SCAN OVER "
+                        + indexPhysicalTableName
+                        + " [2]\n" + "    SERVER FILTER BY FIRST KEY ONLY\n"
+                        + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+
+            rs = conn1.createStatement().executeQuery(query);
+            Thread.sleep(1000);
+            for (int j = 0; j < 26; j++) {
+                assertTrue(rs.next());
+                assertEquals(strings[j], rs.getString("t_id"));
+                assertEquals(j, rs.getInt("k1"));
+                assertEquals(j + 2, rs.getInt("k3"));
+            }
+       } finally {
+            conn1.close();
+        }
+    }    
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
deleted file mode 100644
index 16db876..0000000
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.phoenix.end2end;
-
-import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-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;
-import java.util.UUID;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.phoenix.mapreduce.index.IndexTool;
-import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.query.QueryServicesOptions;
-import org.apache.phoenix.util.PropertiesUtil;
-import org.apache.phoenix.util.QueryUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
-import org.apache.phoenix.util.SchemaUtil;
-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.Lists;
-import com.google.common.collect.Maps;
-
-/**
- * Tests for the {@link IndexTool}
- */
-@RunWith(Parameterized.class)
-public class IndexToolIT extends BaseOwnClusterHBaseManagedTimeIT {
-    
-    private final String schemaName;
-    private final String dataTable;
-    
-    private final boolean localIndex;
-    private final boolean transactional;
-    private final boolean directApi;
-    private final String tableDDLOptions;
-    
-    public IndexToolIT(boolean transactional, boolean localIndex, boolean mutable, boolean directApi) {
-        this.schemaName = "S";
-        this.dataTable = "T" + (transactional ? "_TXN" : "");
-        this.localIndex = localIndex;
-        this.transactional = transactional;
-        this.directApi = directApi;
-        StringBuilder optionBuilder = new StringBuilder();
-        if (!mutable) 
-            optionBuilder.append(" IMMUTABLE_ROWS=true ");
-        if (transactional) {
-            if (!(optionBuilder.length()==0))
-                optionBuilder.append(",");
-            optionBuilder.append(" TRANSACTIONAL=true ");
-        }
-        optionBuilder.append(" SPLIT ON(1,2)");
-        this.tableDDLOptions = optionBuilder.toString();
-    }
-    
-    @BeforeClass
-    public static void doSetup() throws Exception {
-        Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(1);
-        serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
-        Map<String, String> clientProps = Maps.newHashMapWithExpectedSize(1);
-        clientProps.put(QueryServices.TRANSACTIONS_ENABLED, "true");
-        setUpRealDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet().iterator()));
-    }
-    
-    @Parameters(name="transactional = {0} , mutable = {1} , localIndex = {2}, directApi = {3}")
-    public static Collection<Boolean[]> data() {
-        return Arrays.asList(new Boolean[][] {     
-                 { false, false, false, false }, { false, false, false, true }, { false, false, true, false }, { false, false, true, true }, 
-                 { false, true, false, false }, { false, true, false, true }, { false, true, true, false }, { false, true, true, true }, 
-                 { true, false, false, false }, { true, false, false, true }, { true, false, true, false }, { true, false, true, true }, 
-                 { true, true, false, false }, { true, true, false, true }, { true, true, true, false }, { true, true, true, true }
-           });
-    }
-    
-    @Test
-    public void testSecondaryIndex() throws Exception {
-        final String fullTableName = SchemaUtil.getTableName(schemaName, dataTable);
-        final String indxTable = String.format("%s_%s", dataTable, "INDX");
-        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        props.setProperty(QueryServices.TRANSACTIONS_ENABLED, Boolean.TRUE.toString());
-        props.setProperty(QueryServices.EXPLAIN_ROW_COUNT_ATTRIB, Boolean.FALSE.toString());
-        Connection conn = DriverManager.getConnection(getUrl(), props);
-        Statement stmt = conn.createStatement();
-        try {
-        
-            stmt.execute(String.format("CREATE TABLE %s (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, ZIP INTEGER) %s", fullTableName, tableDDLOptions));
-            String upsertQuery = String.format("UPSERT INTO %s VALUES(?, ?, ?)", fullTableName);
-            PreparedStatement stmt1 = conn.prepareStatement(upsertQuery);
-            
-            // insert two rows
-            upsertRow(stmt1, 1);
-            upsertRow(stmt1, 2);
-            conn.commit();
-            
-            if (transactional) {
-                // insert two rows in another connection without committing so that they are not visible to other transactions
-                try (Connection conn2 = DriverManager.getConnection(getUrl(), props)) {
-                    conn2.setAutoCommit(false);
-                    PreparedStatement stmt2 = conn2.prepareStatement(upsertQuery);
-                    upsertRow(stmt2, 5);
-                    upsertRow(stmt2, 6);
-                    ResultSet rs = conn.createStatement().executeQuery("SELECT count(*) from "+fullTableName);
-                    assertTrue(rs.next());
-                    assertEquals("Unexpected row count ", 2, rs.getInt(1));
-                    assertFalse(rs.next());
-                    rs = conn2.createStatement().executeQuery("SELECT count(*) from "+fullTableName);
-                    assertTrue(rs.next());
-                    assertEquals("Unexpected row count ", 4, rs.getInt(1));
-                    assertFalse(rs.next());
-                }
-            }
-            
-            stmt.execute(String.format("CREATE %s INDEX %s ON %s  (LPAD(UPPER(NAME),8,'x')||'_xyz') ASYNC ", (localIndex ? "LOCAL" : ""), indxTable, fullTableName));
-   
-            //verify rows are fetched from data table.
-            String selectSql = String.format("SELECT LPAD(UPPER(NAME),8,'x')||'_xyz',ID FROM %s", fullTableName);
-            ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
-            String actualExplainPlan = QueryUtil.getExplainPlan(rs);
-            
-            //assert we are pulling from data table.
-            assertEquals(String.format("CLIENT 3-CHUNK PARALLEL 1-WAY ROUND ROBIN FULL SCAN OVER %s", fullTableName), actualExplainPlan);
-            
-            rs = stmt1.executeQuery(selectSql);
-            assertTrue(rs.next());
-            assertEquals("xxUNAME1_xyz", rs.getString(1));    
-            assertTrue(rs.next());
-            assertEquals("xxUNAME2_xyz", rs.getString(1));
-            assertFalse(rs.next());
-            conn.commit();
-           
-            //run the index MR job.
-            final IndexTool indexingTool = new IndexTool();
-            Configuration conf = new Configuration(getUtility().getConfiguration());
-            conf.set(QueryServices.TRANSACTIONS_ENABLED, Boolean.TRUE.toString());
-            indexingTool.setConf(conf);
-
-            final String[] cmdArgs = getArgValues(schemaName, dataTable, indxTable, directApi);
-            int status = indexingTool.run(cmdArgs);
-            assertEquals(0, status);
-            
-            // insert two more rows
-            upsertRow(stmt1, 3);
-            upsertRow(stmt1, 4);
-            conn.commit();
-            
-            rs = stmt1.executeQuery("SELECT LPAD(UPPER(NAME),8,'x')||'_xyz',ID FROM "+fullTableName);
-
-            //assert we are pulling from index table.
-            rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
-            actualExplainPlan = QueryUtil.getExplainPlan(rs);
-            assertExplainPlan(actualExplainPlan, schemaName, dataTable, indxTable, localIndex);
-            
-            rs = stmt.executeQuery(selectSql);
-            assertTrue(rs.next());
-            assertEquals("xxUNAME1_xyz", rs.getString(1));
-            assertEquals(1, rs.getInt(2));
-            
-            assertTrue(rs.next());
-            assertEquals("xxUNAME2_xyz", rs.getString(1));
-            assertEquals(2, rs.getInt(2));
-
-            assertTrue(rs.next());
-            assertEquals("xxUNAME3_xyz", rs.getString(1));
-            assertEquals(3, rs.getInt(2));
-            
-            assertTrue(rs.next());
-            assertEquals("xxUNAME4_xyz", rs.getString(1));
-            assertEquals(4, rs.getInt(2));
-      
-            assertFalse(rs.next());
-            
-            conn.createStatement().execute(String.format("DROP INDEX  %s ON %s",indxTable , fullTableName));
-        } finally {
-            conn.close();
-        }
-    }
-    
-    public static void assertExplainPlan(final String actualExplainPlan, String schemaName, String dataTable,
-            String indxTable, boolean isLocal) {
-        
-        String expectedExplainPlan = "";
-        if(isLocal) {
-            final String localIndexName = SchemaUtil.getTableName(schemaName, dataTable);
-            expectedExplainPlan = String.format("CLIENT 3-CHUNK PARALLEL 3-WAY ROUND ROBIN RANGE SCAN OVER %s [1]"
-                + "\n    SERVER FILTER BY FIRST KEY ONLY", localIndexName);
-        } else {
-            expectedExplainPlan = String.format("CLIENT 1-CHUNK PARALLEL 1-WAY ROUND ROBIN FULL SCAN OVER %s"
-                    + "\n    SERVER FILTER BY FIRST KEY ONLY",SchemaUtil.getTableName(schemaName, indxTable));
-        }
-        assertEquals(expectedExplainPlan,actualExplainPlan);
-    }
-
-    public static String[] getArgValues(String schemaName, String dataTable, String indxTable) {
-        return getArgValues(schemaName, dataTable, indxTable, false);
-    }
-    
-    public static String[] getArgValues(String schemaName, String dataTable, String indxTable, boolean directApi) {
-        final List<String> args = Lists.newArrayList();
-        if (schemaName!=null) {
-            args.add("-s");
-            args.add(schemaName);
-        }
-        args.add("-dt");
-        args.add(dataTable);
-        args.add("-it");
-        args.add(indxTable);
-        if(directApi) {
-            args.add("-direct");
-            // Need to run this job in foreground for the test to be deterministic
-            args.add("-runfg");
-        }
-
-        args.add("-op");
-        args.add("/tmp/"+UUID.randomUUID().toString());
-        return args.toArray(new String[0]);
-    }
-
-    public static void upsertRow(PreparedStatement stmt, int i) throws SQLException {
-        // insert row
-        stmt.setInt(1, i);
-        stmt.setString(2, "uname" + String.valueOf(i));
-        stmt.setInt(3, 95050 + i);
-        stmt.executeUpdate();
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/KeyOnlyIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/KeyOnlyIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/KeyOnlyIT.java
index 4497c49..50e0709 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/KeyOnlyIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/KeyOnlyIT.java
@@ -52,8 +52,7 @@ public class KeyOnlyIT extends BaseOwnClusterClientManagedTimeIT {
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
         // Must update config before starting server
-        props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Long.toString(50));
-        props.put(QueryServices.QUEUE_SIZE_ATTRIB, Integer.toString(100));
+        props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Long.toString(20));
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
     
@@ -81,7 +80,7 @@ public class KeyOnlyIT extends BaseOwnClusterClientManagedTimeIT {
         assertEquals(4, rs.getInt(2));
         assertFalse(rs.next());
         List<KeyRange> splits = getAllSplits(conn5, "KEYONLY");
-        assertEquals(2, splits.size());
+        assertEquals(3, splits.size());
         conn5.close();
         
         props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts+60));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java
index 15fc01d..b9d27ca 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java
@@ -52,7 +52,6 @@ public class MultiCfQueryExecIT extends BaseOwnClusterClientManagedTimeIT {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
         // Must update config before starting server
         props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Long.toString(20));
-        props.put(QueryServices.QUEUE_SIZE_ATTRIB, Long.toString(200));
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/MutableIndexToolIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MutableIndexToolIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MutableIndexToolIT.java
deleted file mode 100644
index c335ff8..0000000
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MutableIndexToolIT.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.phoenix.end2end;
-
-import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.Statement;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.phoenix.mapreduce.index.IndexTool;
-import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.query.QueryServicesOptions;
-import org.apache.phoenix.util.PropertiesUtil;
-import org.apache.phoenix.util.QueryUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.google.common.collect.Maps;
-
-public class MutableIndexToolIT extends BaseOwnClusterHBaseManagedTimeIT {
-    
-    @BeforeClass
-    public static void doSetup() throws Exception {
-        Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(1);
-        serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
-        setUpRealDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), ReadOnlyProps.EMPTY_PROPS);
-    }
-
-    /**
-     * This test is to assert that updates that happen to rows of a mutable table after an index is created in ASYNC mode and before
-     * the MR job runs, do show up in the index table . 
-     * @throws Exception
-     */
-    @Test
-    public void testMutableIndexWithUpdates() throws Exception {
-        
-        final String dataTable = "DATA_TABLE5";
-        final String indxTable = String.format("%s_%s",dataTable,"INDX");
-        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        props.setProperty(QueryServices.EXPLAIN_ROW_COUNT_ATTRIB, Boolean.FALSE.toString());
-        Connection conn = DriverManager.getConnection(getUrl(), props);
-        Statement stmt = conn.createStatement();
-        try {
-        
-            stmt.execute(String.format("CREATE TABLE %s (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, ZIP INTEGER)",dataTable));
-            String upsertQuery = String.format("UPSERT INTO %s VALUES(?, ?, ?)",dataTable);
-            PreparedStatement stmt1 = conn.prepareStatement(upsertQuery);
-            
-            int id = 1;
-            // insert two rows
-            IndexToolIT.upsertRow(stmt1, id++);
-            IndexToolIT.upsertRow(stmt1, id++);
-            conn.commit();
-            
-            stmt.execute(String.format("CREATE INDEX %s ON %s (UPPER(NAME)) ASYNC ", indxTable,dataTable));
-            
-            //update a row 
-            stmt1.setInt(1, 1);
-            stmt1.setString(2, "uname" + String.valueOf(10));
-            stmt1.setInt(3, 95050 + 1);
-            stmt1.executeUpdate();
-            conn.commit();  
-            
-            //verify rows are fetched from data table.
-            String selectSql = String.format("SELECT UPPER(NAME),ID FROM %s",dataTable);
-            ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
-            String actualExplainPlan = QueryUtil.getExplainPlan(rs);
-            
-            //assert we are pulling from data table.
-            assertEquals(String.format("CLIENT 1-CHUNK PARALLEL 1-WAY ROUND ROBIN FULL SCAN OVER %s",dataTable),actualExplainPlan);
-            
-            rs = stmt1.executeQuery(selectSql);
-            assertTrue(rs.next());
-            assertEquals("UNAME10", rs.getString(1));
-            assertTrue(rs.next());
-            assertEquals("UNAME2", rs.getString(1));
-           
-            //run the index MR job.
-            final IndexTool indexingTool = new IndexTool();
-            indexingTool.setConf(new Configuration(getUtility().getConfiguration()));
-            
-            final String[] cmdArgs = IndexToolIT.getArgValues(null, dataTable,indxTable);
-            int status = indexingTool.run(cmdArgs);
-            assertEquals(0, status);
-            
-            //assert we are pulling from index table.
-            rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
-            actualExplainPlan = QueryUtil.getExplainPlan(rs);
-            IndexToolIT.assertExplainPlan(actualExplainPlan,null,dataTable,indxTable,false);
-            
-            rs = stmt.executeQuery(selectSql);
-            assertTrue(rs.next());
-            assertEquals("UNAME10", rs.getString(1));
-            assertEquals(1, rs.getInt(2));
-            
-            assertTrue(rs.next());
-            assertEquals("UNAME2", rs.getString(1));
-            assertEquals(2, rs.getInt(2));
-            conn.createStatement().execute(String.format("DROP INDEX  %s ON %s",indxTable , dataTable));
-        } finally {
-            conn.close();
-        }
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFuncIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFuncIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFuncIT.java
new file mode 100644
index 0000000..a5251a9
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFuncIT.java
@@ -0,0 +1,683 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.apache.phoenix.util.TestUtil.closeStmtAndConn;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.Date;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Properties;
+
+import org.apache.phoenix.expression.function.CeilFunction;
+import org.apache.phoenix.expression.function.FloorFunction;
+import org.apache.phoenix.expression.function.RoundFunction;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.util.DateUtil;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.primitives.Doubles;
+import com.google.common.primitives.Floats;
+
+/**
+ * 
+ * End to end tests for {@link RoundFunction}, {@link FloorFunction}, {@link CeilFunction} 
+ *
+ */
+public class RoundFloorCeilFuncIT extends BaseHBaseManagedTimeTableReuseIT {
+    private static final long millisPart = 660;
+    private static final int nanosPart = 500100;
+    private static final BigDecimal decimalUpserted = BigDecimal.valueOf(1.264);
+    private static final double doubleUpserted = 1.264d;
+    private static final double unsignedDoubleUpserted = 1.264d;
+    private static final float floatUpserted = 1.264f;
+    private static final float unsignedFloatUpserted = 1.264f;
+
+    private String tableName;
+    
+    @Before
+    public void initTable() throws Exception {
+        tableName = generateRandomString();
+        String testString = "abc";
+        Connection conn = null;
+        PreparedStatement stmt = null;
+        try {
+            conn = DriverManager.getConnection(getUrl());
+            String ddl = "CREATE TABLE IF NOT EXISTS " + tableName
+                + " (s VARCHAR NOT NULL PRIMARY KEY, dt DATE, t TIME, ts TIMESTAMP, dec DECIMAL, doub DOUBLE, undoub UNSIGNED_DOUBLE, fl FLOAT, unfl UNSIGNED_FLOAT)";
+            conn.createStatement().execute(ddl);
+            
+            Date dateUpserted = DateUtil.parseDate("2012-01-01 14:25:28");
+            dateUpserted = new Date(dateUpserted.getTime() + millisPart); // this makes the dateUpserted equivalent to 2012-01-01 14:25:28.660 
+            long millis = dateUpserted.getTime();
+
+            Time timeUpserted = new Time(millis);
+            Timestamp tsUpserted = DateUtil.getTimestamp(millis, nanosPart);
+            
+            stmt =  conn.prepareStatement(
+                "UPSERT INTO " + tableName + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
+            stmt.setString(1, testString);
+            stmt.setDate(2, dateUpserted);
+            stmt.setTime(3, timeUpserted);
+            stmt.setTimestamp(4, tsUpserted);
+            stmt.setBigDecimal(5, decimalUpserted);
+            stmt.setDouble(6, doubleUpserted);
+            stmt.setDouble(7, unsignedDoubleUpserted);
+            stmt.setFloat(8, floatUpserted);
+            stmt.setFloat(9, unsignedFloatUpserted);
+            stmt.executeUpdate();
+            conn.commit();
+        } finally {
+            closeStmtAndConn(stmt, conn);
+        }
+    }
+
+    @Test
+    public void testRoundingUpDate() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery("SELECT ROUND(dt, 'day'), ROUND(dt, 'hour', 1), ROUND(dt, 'minute', 1), ROUND(dt, 'second', 1), "
+                + " ROUND(dt,'week'), ROUND(dt,'month') , ROUND(dt,'year') FROM " + tableName);
+        assertTrue(rs.next());
+        Date expectedDate = DateUtil.parseDate("2012-01-02 00:00:00");
+        assertEquals(expectedDate, rs.getDate(1));
+        expectedDate = DateUtil.parseDate("2012-01-01 14:00:00");
+        assertEquals(expectedDate, rs.getDate(2));
+        expectedDate = DateUtil.parseDate("2012-01-01 14:25:00");
+        assertEquals(expectedDate, rs.getDate(3));
+        expectedDate = DateUtil.parseDate("2012-01-01 14:25:29"); 
+        assertEquals(expectedDate, rs.getDate(4));
+        expectedDate = DateUtil.parseDate("2012-01-02 00:00:00"); 
+        assertEquals(expectedDate, rs.getDate(5));
+        expectedDate = DateUtil.parseDate("2012-01-01 00:00:00"); 
+        assertEquals(expectedDate, rs.getDate(6));
+        expectedDate = DateUtil.parseDate("2012-01-01 00:00:00"); 
+        assertEquals(expectedDate, rs.getDate(7));
+    }
+    
+    @Test
+    public void testRoundingUpDateInWhere() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName
+            + " WHERE ROUND(dt, 'day') = to_date('2012-01-02 00:00:00')");
+        assertTrue(rs.next());
+    }
+    
+    @Test
+    public void testFloorDate() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery("SELECT FLOOR(dt, 'day', 1), FLOOR(dt, 'hour', 1), FLOOR(dt, 'minute', 1), FLOOR(dt, 'second', 1),"
+                + " FLOOR(dt,'week'), FLOOR(dt,'month'), FLOOR(dt,'year') FROM " + tableName);
+        assertTrue(rs.next());
+        Date expectedDate = DateUtil.parseDate("2012-01-01 00:00:00");
+        assertEquals(expectedDate, rs.getDate(1));
+        expectedDate = DateUtil.parseDate("2012-01-01 14:00:00");
+        assertEquals(expectedDate, rs.getDate(2));
+        expectedDate = DateUtil.parseDate("2012-01-01 14:25:00");
+        assertEquals(expectedDate, rs.getDate(3));
+        expectedDate = DateUtil.parseDate("2012-01-01 14:25:28");
+        assertEquals(expectedDate, rs.getDate(4));
+        expectedDate = DateUtil.parseDate("2011-12-26 00:00:00");
+        assertEquals(expectedDate, rs.getDate(5));
+        expectedDate = DateUtil.parseDate("2012-01-01 00:00:00");
+        assertEquals(expectedDate, rs.getDate(6));
+        expectedDate = DateUtil.parseDate("2012-01-01 00:00:00");
+        assertEquals(expectedDate, rs.getDate(7));
+    }
+    
+    @Test
+    public void testFloorDateInWhere() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName
+            + " WHERE FLOOR(dt, 'hour') = to_date('2012-01-01 14:00:00')");
+        assertTrue(rs.next());
+    }
+    
+    @Test
+    public void testCeilDate() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery("SELECT CEIL(dt, 'day', 1), CEIL(dt, 'hour', 1), CEIL(dt, 'minute', 1), CEIL(dt, 'second', 1), "
+                + " CEIL(dt,'week') , CEIL(dt,'month') , CEIL(dt,'year')  FROM " + tableName);
+        assertTrue(rs.next());
+        //Date upserted is 2012-01-01 14:25:28.660. So we will end up bumping up in every case.
+        Date expectedDate = DateUtil.parseDate("2012-01-02 00:00:00");
+        assertEquals(expectedDate, rs.getDate(1));
+        expectedDate = DateUtil.parseDate("2012-01-01 15:00:00");
+        assertEquals(expectedDate, rs.getDate(2));
+        expectedDate = DateUtil.parseDate("2012-01-01 14:26:00");
+        assertEquals(expectedDate, rs.getDate(3));
+        expectedDate = DateUtil.parseDate("2012-01-01 14:25:29");
+        assertEquals(expectedDate, rs.getDate(4));
+        expectedDate = DateUtil.parseDate("2012-01-02 00:00:00");
+        System.out.println(String.format(" the expected time is [%s] and the actual time is [%s]",expectedDate.getTime(),rs.getDate(5).getTime()));
+        assertEquals(expectedDate, rs.getDate(5));
+        expectedDate = DateUtil.parseDate("2012-02-01 00:00:00");
+        assertEquals(expectedDate, rs.getDate(6));
+        expectedDate = DateUtil.parseDate("2013-01-01 00:00:00");
+        assertEquals(expectedDate, rs.getDate(7));
+    }
+    
+    @Test
+    public void testCeilDateInWhere() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName
+            + " WHERE CEIL(dt, 'second') = to_date('2012-01-01 14:25:29')");
+        assertTrue(rs.next());
+    }
+    
+    @Test
+    public void testRoundingUpTimestamp() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery(
+            "SELECT ROUND(ts, 'day'), ROUND(ts, 'hour', 1), ROUND(ts, 'minute', 1), ROUND(ts, 'second', 1), ROUND(ts, 'millisecond', 1) FROM "
+                + tableName);
+        assertTrue(rs.next());
+        Timestamp expectedTimestamp;
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(1));
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:00:00").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(2));
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:00").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(3));
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:29").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(4));
+        
+        // Rounding of "2012-01-01 14:25:28.660" + nanosPart will end up bumping up the millisecond part of date. 
+        // That is, it should be  evaluated as "2012-01-01 14:25:28.661". 
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:28").getTime() + millisPart + 1);
+        assertEquals(expectedTimestamp, rs.getTimestamp(5));
+    }
+    
+    @Test
+    public void testRoundingUpTimestampInWhere() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName
+            + " WHERE ROUND(ts, 'second') = to_date('2012-01-01 14:25:29')");
+        assertTrue(rs.next());
+    }
+    
+    @Test
+    public void testFloorTimestamp() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery("SELECT FLOOR(ts, 'day'), FLOOR(ts, 'hour', 1), FLOOR(ts, 'minute', 1), FLOOR(ts, 'second', 1), "
+                + " FLOOR(ts, 'millisecond', 1) , FLOOR(ts,'week') , FLOOR(ts,'month') FROM "
+            + tableName);
+        assertTrue(rs.next());
+        Timestamp expectedTimestamp;
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(1));
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:00:00").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(2));
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:00").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(3));
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:28").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(4));
+        
+        // FLOOR of "2012-01-01 14:25:28.660" + nanosPart will end up removing the nanos part. 
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:28").getTime() + millisPart);
+        assertEquals(expectedTimestamp, rs.getTimestamp(5));
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2011-12-26 00:00:00").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(6));
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(7));
+    }
+    
+    @Test
+    public void testFloorTimestampInWhere() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName
+            + " WHERE FLOOR(ts, 'second') = to_date('2012-01-01 14:25:28')");
+        assertTrue(rs.next());
+    }
+    
+    @Test
+    public void testWeekFloorTimestampInWhere() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName
+            + " WHERE FLOOR(ts, 'week') = to_date('2011-12-26 00:00:00')");
+        assertTrue(rs.next());
+    }
+    
+    @Test
+    public void testCeilTimestamp() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery("SELECT CEIL(ts, 'day'), CEIL(ts, 'hour', 1), CEIL(ts, 'minute', 1), CEIL(ts, 'second', 1), CEIL(ts, 'millisecond', 1),"
+                + " CEIL(ts,'week'), CEIL(ts,'month') , CEIL(ts,'year') FROM " + tableName);
+        assertTrue(rs.next());
+        Timestamp expectedTimestamp;
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(1));
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 15:00:00").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(2));
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:26:00").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(3));
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:29").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(4));
+        
+        // CEIL of "2012-01-01 14:25:28.660" + nanosPart will end up bumping up the millisecond part of date. 
+        // That is, it should be  evaluated as "2012-01-01 14:25:28.661". 
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:28").getTime() + millisPart + 1);
+        assertEquals(expectedTimestamp, rs.getTimestamp(5));
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(6));
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-02-01 00:00:00").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(7));
+        expectedTimestamp = new Timestamp(DateUtil.parseDate("2013-01-01 00:00:00").getTime());
+        assertEquals(expectedTimestamp, rs.getTimestamp(8));
+    }
+    
+    @Test
+    public void testCeilTimestampInWhere() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName
+            + " WHERE CEIL(ts, 'second') = to_date('2012-01-01 14:25:29')");
+        assertTrue(rs.next());
+    }
+    
+    @Test
+    public void testRoundingUpTime() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery("SELECT ROUND(t, 'day', 1), ROUND(t, 'hour', 1), ROUND(t, 'minute', 1), ROUND(t, 'second', 1),"
+                + " ROUND(t,'week') , ROUND(t,'month') , ROUND(t,'year') FROM " + tableName);
+        assertTrue(rs.next());
+        Time expectedTime = new Time(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
+        assertEquals(expectedTime, rs.getTime(1));
+        expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:00:00").getTime());
+        assertEquals(expectedTime, rs.getTime(2));
+        expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:00").getTime());
+        assertEquals(expectedTime, rs.getTime(3));
+        expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:29").getTime());
+        assertEquals(expectedTime, rs.getTime(4));
+        expectedTime = new Time(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
+        assertEquals(expectedTime, rs.getTime(5));
+        expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
+        assertEquals(expectedTime, rs.getTime(6));
+        expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
+        assertEquals(expectedTime, rs.getTime(7));
+    }
+    
+    @Test
+    public void testFloorTime() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery("SELECT FLOOR(t, 'day', 1), FLOOR(t, 'hour', 1), FLOOR(t, 'minute', 1), FLOOR(t, 'second', 1), "
+                + " FLOOR(t, 'week'),  FLOOR(t, 'month'), FLOOR(t, 'year') FROM " + tableName);
+        assertTrue(rs.next());
+        Time expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
+        assertEquals(expectedTime, rs.getTime(1));
+        expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:00:00").getTime());
+        assertEquals(expectedTime, rs.getTime(2));
+        expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:00").getTime());
+        assertEquals(expectedTime, rs.getTime(3));
+        expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:28").getTime());
+        assertEquals(expectedTime, rs.getTime(4));
+        expectedTime = new Time(DateUtil.parseDate("2011-12-26 00:00:00").getTime());
+        assertEquals(expectedTime, rs.getTime(5));
+        expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
+        assertEquals(expectedTime, rs.getTime(6));
+        expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
+        assertEquals(expectedTime, rs.getTime(7));
+    }
+    
+    @Test
+    public void testCeilTime() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery("SELECT CEIL(t, 'day', 1), CEIL(t, 'hour', 1), CEIL(t, 'minute', 1), CEIL(t, 'second', 1),"
+                + " CEIL(t,'week') , CEIL(t,'month') , CEIL(t,'year') FROM " + tableName);
+        assertTrue(rs.next());
+        Time expectedTime = new Time(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
+        assertEquals(expectedTime, rs.getTime(1));
+        expectedTime = new Time(DateUtil.parseDate("2012-01-01 15:00:00").getTime());
+        assertEquals(expectedTime, rs.getTime(2));
+        expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:26:00").getTime());
+        assertEquals(expectedTime, rs.getTime(3));
+        expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:29").getTime());
+        assertEquals(expectedTime, rs.getTime(4));
+        expectedTime = new Time(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
+        assertEquals(expectedTime, rs.getTime(5));
+        expectedTime = new Time(DateUtil.parseDate("2012-02-01 00:00:00").getTime());
+        assertEquals(expectedTime, rs.getTime(6));
+        expectedTime = new Time(DateUtil.parseDate("2013-01-01 00:00:00").getTime());
+        assertEquals(expectedTime, rs.getTime(7));
+    }
+
+    @Test
+    public void testRoundingUpDecimal() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery(
+            "SELECT ROUND(dec), ROUND(dec, 1), ROUND(dec, 2), ROUND(dec, 3) FROM " + tableName);
+        assertTrue(rs.next());
+        BigDecimal expectedBd = BigDecimal.valueOf(1);
+        assertEquals(expectedBd, rs.getBigDecimal(1));
+        expectedBd = BigDecimal.valueOf(1.3);
+        assertEquals(expectedBd, rs.getBigDecimal(2));
+        expectedBd = BigDecimal.valueOf(1.26);
+        assertEquals(expectedBd, rs.getBigDecimal(3));
+        expectedBd = BigDecimal.valueOf(1.264);
+        assertEquals(expectedBd, rs.getBigDecimal(4));
+    }
+    
+    @Test
+    public void testRoundingUpDecimalInWhere() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery(
+            "SELECT * FROM " + tableName + " WHERE ROUND(dec, 2) = 1.26");
+        assertTrue(rs.next());
+    }
+    
+    @Test
+    public void testFloorDecimal() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery(
+            "SELECT FLOOR(dec), FLOOR(dec, 1), FLOOR(dec, 2), FLOOR(dec, 3) FROM " + tableName);
+        assertTrue(rs.next());
+        BigDecimal expectedBd = BigDecimal.valueOf(1);
+        assertEquals(expectedBd, rs.getBigDecimal(1));
+        expectedBd = BigDecimal.valueOf(1.2);
+        assertEquals(expectedBd, rs.getBigDecimal(2));
+        expectedBd = BigDecimal.valueOf(1.26);
+        assertEquals(expectedBd, rs.getBigDecimal(3));
+        expectedBd = BigDecimal.valueOf(1.264);
+        assertEquals(expectedBd, rs.getBigDecimal(4));
+    }
+    
+    @Test
+    public void testFloorDecimalInWhere() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery(
+            "SELECT * FROM " + tableName + " WHERE FLOOR(dec, 2) = 1.26");
+        assertTrue(rs.next());
+    }
+    
+    @Test
+    public void testCeilDecimal() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery(
+            "SELECT CEIL(dec), CEIL(dec, 1), CEIL(dec, 2), CEIL(dec, 3) FROM " + tableName);
+        assertTrue(rs.next());
+        BigDecimal expectedBd = BigDecimal.valueOf(2);
+        assertEquals(expectedBd, rs.getBigDecimal(1));
+        expectedBd = BigDecimal.valueOf(1.3);
+        assertEquals(expectedBd, rs.getBigDecimal(2));
+        expectedBd = BigDecimal.valueOf(1.27);
+        assertEquals(expectedBd, rs.getBigDecimal(3));
+        expectedBd = BigDecimal.valueOf(1.264);
+        assertEquals(expectedBd, rs.getBigDecimal(4));
+    }
+    
+    @Test
+    public void testCeilDecimalInWhere() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        ResultSet rs = conn.createStatement().executeQuery(
+            "SELECT * FROM " + tableName + " WHERE CEIL(dec, 2) = 1.27");
+        assertTrue(rs.next());
+    }
+    @Test
+	public void testRoundingUpDouble() throws Exception {
+		Connection conn = DriverManager.getConnection(getUrl());
+		ResultSet rs = conn.createStatement().executeQuery(
+        "SELECT ROUND(doub), ROUND(doub, 1), ROUND(doub, 2), ROUND(doub, 3) FROM " + tableName);
+		assertTrue(rs.next());
+		assertEquals(0, Doubles.compare(1, rs.getDouble(1)));
+		assertEquals(0, Doubles.compare(1.3, rs.getDouble(2)));
+		assertEquals(0, Doubles.compare(1.26, rs.getDouble(3)));
+		assertEquals(0, Doubles.compare(1.264, rs.getDouble(4)));
+	}
+
+	@Test
+	public void testRoundingUpDoubleInWhere() throws Exception {
+		Connection conn = DriverManager.getConnection(getUrl());
+		ResultSet rs = conn.createStatement().executeQuery(
+        "SELECT * FROM " + tableName + " WHERE ROUND(dec, 2) = 1.26");
+		assertTrue(rs.next());
+	}
+
+	@Test
+	public void testCeilDouble() throws Exception {
+		Connection conn = DriverManager.getConnection(getUrl());
+		ResultSet rs = conn.createStatement().executeQuery(
+        "SELECT CEIL(doub), CEIL(doub, 1), CEIL(doub, 2), CEIL(doub, 3) FROM " + tableName);
+		assertTrue(rs.next());
+		assertEquals(0, Doubles.compare(2, rs.getDouble(1)));
+		assertEquals(0, Doubles.compare(1.3, rs.getDouble(2)));
+		assertEquals(0, Doubles.compare(1.27, rs.getDouble(3)));
+		assertEquals(0, Doubles.compare(1.264, rs.getDouble(4)));
+	}
+
+	@Test
+	public void testCeilDoubleInWhere() throws Exception {
+		Connection conn = DriverManager.getConnection(getUrl());
+		ResultSet rs = conn.createStatement().executeQuery(
+        "SELECT * FROM " + tableName + " WHERE CEIL(doub, 2) = 1.27");
+		assertTrue(rs.next());
+	}
+
+	@Test
+	public void testFloorDouble() throws Exception {
+		Connection conn = DriverManager.getConnection(getUrl());
+		ResultSet rs = conn.createStatement().executeQuery(
+        "SELECT FLOOR(doub), FLOOR(doub, 1), FLOOR(doub, 2), FLOOR(doub, 3) FROM " + tableName);
+		assertTrue(rs.next());
+		assertEquals(0, Doubles.compare(1, rs.getDouble(1)));
+		assertEquals(0, Doubles.compare(1.2, rs.getDouble(2)));
+		assertEquals(0, Doubles.compare(1.26, rs.getDouble(3)));
+		assertEquals(0, Doubles.compare(1.264, rs.getDouble(4)));
+	}
+
+	@Test
+	public void testFloorDoubleInWhere() throws Exception {
+		Connection conn = DriverManager.getConnection(getUrl());
+		ResultSet rs = conn.createStatement().executeQuery(
+        "SELECT * FROM " + tableName + " WHERE FLOOR(doub, 2) = 1.26");
+		assertTrue(rs.next());
+	}
+	
+	@Test
+	public void testRoundFloat() throws Exception {
+		Connection conn = DriverManager.getConnection(getUrl());
+		ResultSet rs = conn.createStatement().executeQuery(
+        "SELECT ROUND(fl), ROUND(fl, 1), ROUND(fl, 2), ROUND(fl, 3) FROM " + tableName);
+		assertTrue(rs.next());
+		assertEquals(0, Floats.compare(1, rs.getFloat(1)));
+		assertEquals(0, Floats.compare(1.3f, rs.getFloat(2)));
+		assertEquals(0, Floats.compare(1.26f, rs.getFloat(3)));
+		assertEquals(0, Floats.compare(1.264f, rs.getFloat(4)));
+	}
+	
+	@Test
+	public void testRoundUnsignedFloat() throws Exception {
+		Connection conn = DriverManager.getConnection(getUrl());
+		ResultSet rs = conn.createStatement().executeQuery(
+        "SELECT ROUND(unfl), ROUND(unfl, 1), ROUND(unfl, 2), ROUND(unfl, 3) FROM " + tableName);
+		assertTrue(rs.next());
+		assertEquals(0, Floats.compare(1, rs.getFloat(1)));
+		assertEquals(0, Floats.compare(1.3f, rs.getFloat(2)));
+		assertEquals(0, Floats.compare(1.26f, rs.getFloat(3)));
+		assertEquals(0, Floats.compare(1.264f, rs.getFloat(4)));
+	}
+	
+	@Test
+	public void testRoundUnsignedDouble() throws Exception {
+		Connection conn = DriverManager.getConnection(getUrl());
+		ResultSet rs = conn.createStatement().executeQuery(
+        "SELECT ROUND(undoub), ROUND(undoub, 1), ROUND(undoub, 2), ROUND(undoub, 3) FROM "
+            + tableName);
+		assertTrue(rs.next());
+		assertEquals(0, Floats.compare(1, rs.getFloat(1)));
+		assertEquals(0, Floats.compare(1.3f, rs.getFloat(2)));
+		assertEquals(0, Floats.compare(1.26f, rs.getFloat(3)));
+		assertEquals(0, Floats.compare(1.264f, rs.getFloat(4)));
+	}	
+	
+	@Test
+	public void testTimestampAggregateFunctions() throws Exception {
+		String dateString = "2015-03-08 09:09:11.665";
+		Properties props = new Properties();
+		props.setProperty(QueryServices.DATE_FORMAT_TIMEZONE_ATTRIB, "GMT+1");
+		Connection conn = DriverManager.getConnection(getUrl(), props);
+		try {
+			conn.prepareStatement(
+					"create table TIME_AGG_TABLE("
+							+ "ID unsigned_int NOT NULL, "
+							+ "THE_DATE TIMESTAMP, "
+							+ "constraint PK primary key (ID))").execute();
+			PreparedStatement stmt = conn.prepareStatement("upsert into "
+					+ "TIME_AGG_TABLE(" + "    ID, " + "    THE_DATE)"
+					+ "VALUES (?, ?)");
+			stmt.setInt(1, 1);
+			stmt.setTimestamp(2, DateUtil.parseTimestamp(dateString));
+			stmt.execute();
+			conn.commit();
+
+			ResultSet rs = conn.prepareStatement(
+					"SELECT THE_DATE ,TRUNC(THE_DATE,'DAY') AS day_from_dt "
+							+ ",TRUNC(THE_DATE,'HOUR') AS hour_from_dt "
+							+ ",TRUNC(THE_DATE,'MINUTE') AS min_from_dt "
+							+ ",TRUNC(THE_DATE,'SECOND') AS sec_from_dt "
+							+ ",TRUNC(THE_DATE,'MILLISECOND') AS mil_from_dt "
+							+ "FROM TIME_AGG_TABLE").executeQuery();
+			assertTrue(rs.next());
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
+					rs.getTimestamp("THE_DATE"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 00:00:00.0"),
+					rs.getTimestamp("day_from_dt"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:00:00.0"),
+					rs.getTimestamp("hour_from_dt"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:00.0"),
+					rs.getTimestamp("min_from_dt"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.0"),
+					rs.getTimestamp("sec_from_dt"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
+					rs.getTimestamp("mil_from_dt"));
+			rs.close();
+
+			rs = conn.prepareStatement(
+					"SELECT THE_DATE ,ROUND(THE_DATE,'DAY') AS day_from_dt "
+							+ ",ROUND(THE_DATE,'HOUR') AS hour_from_dt "
+							+ ",ROUND(THE_DATE,'MINUTE') AS min_from_dt "
+							+ ",ROUND(THE_DATE,'SECOND') AS sec_from_dt "
+							+ ",ROUND(THE_DATE,'MILLISECOND') AS mil_from_dt "
+							+ "FROM TIME_AGG_TABLE").executeQuery();
+			assertTrue(rs.next());
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
+					rs.getTimestamp("THE_DATE"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 00:00:00.0"),
+					rs.getTimestamp("day_from_dt"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:00:00.0"),
+					rs.getTimestamp("hour_from_dt"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:00.0"),
+					rs.getTimestamp("min_from_dt"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:12.0"),
+					rs.getTimestamp("sec_from_dt"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
+					rs.getTimestamp("mil_from_dt"));
+			rs.close();
+
+			rs = conn.prepareStatement(
+					"SELECT THE_DATE ,FLOOR(THE_DATE,'DAY') AS day_from_dt "
+							+ ",FLOOR(THE_DATE,'HOUR') AS hour_from_dt "
+							+ ",FLOOR(THE_DATE,'MINUTE') AS min_from_dt "
+							+ ",FLOOR(THE_DATE,'SECOND') AS sec_from_dt "
+							+ ",FLOOR(THE_DATE,'MILLISECOND') AS mil_from_dt "
+							+ "FROM TIME_AGG_TABLE").executeQuery();
+			assertTrue(rs.next());
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
+					rs.getTimestamp("THE_DATE"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 00:00:00.0"),
+					rs.getTimestamp("day_from_dt"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:00:00.0"),
+					rs.getTimestamp("hour_from_dt"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:00.0"),
+					rs.getTimestamp("min_from_dt"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.0"),
+					rs.getTimestamp("sec_from_dt"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
+					rs.getTimestamp("mil_from_dt"));
+			rs.close();
+
+			rs = conn.prepareStatement(
+					"SELECT THE_DATE ,CEIL(THE_DATE,'DAY') AS day_from_dt "
+							+ ",CEIL(THE_DATE,'HOUR') AS hour_from_dt "
+							+ ",CEIL(THE_DATE,'MINUTE') AS min_from_dt "
+							+ ",CEIL(THE_DATE,'SECOND') AS sec_from_dt "
+							+ ",CEIL(THE_DATE,'MILLISECOND') AS mil_from_dt "
+							+ "FROM TIME_AGG_TABLE").executeQuery();
+			assertTrue(rs.next());
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
+					rs.getTimestamp("THE_DATE"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-09 00:00:00.0"),
+					rs.getTimestamp("day_from_dt"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 10:00:00.0"),
+					rs.getTimestamp("hour_from_dt"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:10:00.0"),
+					rs.getTimestamp("min_from_dt"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:12.0"),
+					rs.getTimestamp("sec_from_dt"));
+			assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
+					rs.getTimestamp("mil_from_dt"));
+			rs.close();
+		} finally {
+			conn.close();
+		}
+	}
+
+  @Test
+  public void testRoundOffFunction() throws SQLException {
+    long ts = nextTimestamp();
+    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+    props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+    Connection conn = DriverManager.getConnection(getUrl(), props);
+    String ddl = "create table round_test(k bigint primary key)";
+    conn.createStatement().execute(ddl);
+    conn.close();
+    
+    props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
+    conn = DriverManager.getConnection(getUrl(), props);
+    PreparedStatement stmt = conn.prepareStatement("upsert into round_test values(1380603308885)");
+    stmt.execute();
+    conn.commit();
+    conn.close();
+    
+
+    props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
+    conn = DriverManager.getConnection(getUrl(), props);
+    ResultSet rs;
+    stmt = conn.prepareStatement("select round(k/1000000,0) from round_test");
+    rs = stmt.executeQuery();
+    assertTrue(rs.next());
+    assertEquals(1380603, rs.getLong(1));
+    
+    props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
+    conn = DriverManager.getConnection(getUrl(), props);
+    stmt = conn.prepareStatement("select round(k/1000000,0) x from round_test group by x");
+    rs = stmt.executeQuery();
+    assertTrue(rs.next());
+    assertEquals(1380603, rs.getLong(1));
+  }
+
+}


[25/47] phoenix git commit: PHOENIX-3072 Deadlock on region opening with secondary index recovery (Enis Soztutar)

Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/2c2b552c/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
index 155d1ba..ace228b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
@@ -168,6 +168,11 @@ public interface QueryConstants {
 
     public static final byte[] TRUE = new byte[] {1};
     
+    /**
+     * The priority property for an hbase table. This is already in HTD, but older versions of
+     * HBase do not have this, so we re-defined it here. Once Phoenix is HBase-1.3+, we can remote.
+     */
+    public static final String PRIORITY = "PRIORITY";
 
     /**
      * Separator used between variable length keys for a composite key.

http://git-wip-us.apache.org/repos/asf/phoenix/blob/2c2b552c/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index 7da7010..28ed11d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -228,168 +228,168 @@ public class MetaDataClient {
     private static final ParseNodeFactory FACTORY = new ParseNodeFactory();
     private static final String SET_ASYNC_CREATED_DATE =
             "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
-            TENANT_ID + "," +
-            TABLE_SCHEM + "," +
-            TABLE_NAME + "," +
-            ASYNC_CREATED_DATE + " " + PDate.INSTANCE.getSqlTypeName() +
-            ") VALUES (?, ?, ?, ?)";
+                    TENANT_ID + "," +
+                    TABLE_SCHEM + "," +
+                    TABLE_NAME + "," +
+                    ASYNC_CREATED_DATE + " " + PDate.INSTANCE.getSqlTypeName() +
+                    ") VALUES (?, ?, ?, ?)";
     private static final String CREATE_TABLE =
             "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
-            TENANT_ID + "," +
-            TABLE_SCHEM + "," +
-            TABLE_NAME + "," +
-            TABLE_TYPE + "," +
-            TABLE_SEQ_NUM + "," +
-            COLUMN_COUNT + "," +
-            SALT_BUCKETS + "," +
-            PK_NAME + "," +
-            DATA_TABLE_NAME + "," +
-            INDEX_STATE + "," +
-            IMMUTABLE_ROWS + "," +
-            DEFAULT_COLUMN_FAMILY_NAME + "," +
-            VIEW_STATEMENT + "," +
-            DISABLE_WAL + "," +
-            MULTI_TENANT + "," +
-            VIEW_TYPE + "," +
-            VIEW_INDEX_ID + "," +
-            INDEX_TYPE + "," +
-            STORE_NULLS + "," +
-            BASE_COLUMN_COUNT + "," +
-            TRANSACTIONAL + "," +
-            UPDATE_CACHE_FREQUENCY + "," +
-            IS_NAMESPACE_MAPPED + "," +
-            AUTO_PARTITION_SEQ +  "," +
-            APPEND_ONLY_SCHEMA +
-            ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+                    TENANT_ID + "," +
+                    TABLE_SCHEM + "," +
+                    TABLE_NAME + "," +
+                    TABLE_TYPE + "," +
+                    TABLE_SEQ_NUM + "," +
+                    COLUMN_COUNT + "," +
+                    SALT_BUCKETS + "," +
+                    PK_NAME + "," +
+                    DATA_TABLE_NAME + "," +
+                    INDEX_STATE + "," +
+                    IMMUTABLE_ROWS + "," +
+                    DEFAULT_COLUMN_FAMILY_NAME + "," +
+                    VIEW_STATEMENT + "," +
+                    DISABLE_WAL + "," +
+                    MULTI_TENANT + "," +
+                    VIEW_TYPE + "," +
+                    VIEW_INDEX_ID + "," +
+                    INDEX_TYPE + "," +
+                    STORE_NULLS + "," +
+                    BASE_COLUMN_COUNT + "," +
+                    TRANSACTIONAL + "," +
+                    UPDATE_CACHE_FREQUENCY + "," +
+                    IS_NAMESPACE_MAPPED + "," +
+                    AUTO_PARTITION_SEQ +  "," +
+                    APPEND_ONLY_SCHEMA +
+                    ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
 
     private static final String CREATE_SCHEMA = "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE
             + "\"( " + TABLE_SCHEM + "," + TABLE_NAME + ") VALUES (?,?)";
 
     private static final String CREATE_LINK =
             "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
-            TENANT_ID + "," +
-            TABLE_SCHEM + "," +
-            TABLE_NAME + "," +
-            COLUMN_FAMILY + "," +
-            LINK_TYPE + "," +
-            TABLE_SEQ_NUM +","+ // this is actually set to the parent table's sequence number
-            TABLE_TYPE +
-            ") VALUES (?, ?, ?, ?, ?, ?, ?)";
+                    TENANT_ID + "," +
+                    TABLE_SCHEM + "," +
+                    TABLE_NAME + "," +
+                    COLUMN_FAMILY + "," +
+                    LINK_TYPE + "," +
+                    TABLE_SEQ_NUM +","+ // this is actually set to the parent table's sequence number
+                    TABLE_TYPE +
+                    ") VALUES (?, ?, ?, ?, ?, ?, ?)";
     private static final String CREATE_VIEW_LINK =
             "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
-            TENANT_ID + "," +
-            TABLE_SCHEM + "," +
-            TABLE_NAME + "," +
-            COLUMN_FAMILY + "," +
-            LINK_TYPE + "," +
-            PARENT_TENANT_ID + " " + PVarchar.INSTANCE.getSqlTypeName() + // Dynamic column for now to prevent schema change
-            ") VALUES (?, ?, ?, ?, ?, ?)";
+                    TENANT_ID + "," +
+                    TABLE_SCHEM + "," +
+                    TABLE_NAME + "," +
+                    COLUMN_FAMILY + "," +
+                    LINK_TYPE + "," +
+                    PARENT_TENANT_ID + " " + PVarchar.INSTANCE.getSqlTypeName() + // Dynamic column for now to prevent schema change
+                    ") VALUES (?, ?, ?, ?, ?, ?)";
     private static final String INCREMENT_SEQ_NUM =
             "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
-            TENANT_ID + "," +
-            TABLE_SCHEM + "," +
-            TABLE_NAME + "," +
-            TABLE_SEQ_NUM  +
-            ") VALUES (?, ?, ?, ?)";
+                    TENANT_ID + "," +
+                    TABLE_SCHEM + "," +
+                    TABLE_NAME + "," +
+                    TABLE_SEQ_NUM  +
+                    ") VALUES (?, ?, ?, ?)";
     private static final String MUTATE_TABLE =
-        "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
-        TENANT_ID + "," +
-        TABLE_SCHEM + "," +
-        TABLE_NAME + "," +
-        TABLE_TYPE + "," +
-        TABLE_SEQ_NUM + "," +
-        COLUMN_COUNT +
-        ") VALUES (?, ?, ?, ?, ?, ?)";
+            "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
+                    TENANT_ID + "," +
+                    TABLE_SCHEM + "," +
+                    TABLE_NAME + "," +
+                    TABLE_TYPE + "," +
+                    TABLE_SEQ_NUM + "," +
+                    COLUMN_COUNT +
+                    ") VALUES (?, ?, ?, ?, ?, ?)";
     private static final String UPDATE_INDEX_STATE =
-        "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
-        TENANT_ID + "," +
-        TABLE_SCHEM + "," +
-        TABLE_NAME + "," +
-        INDEX_STATE +
-        ") VALUES (?, ?, ?, ?)";
+            "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
+                    TENANT_ID + "," +
+                    TABLE_SCHEM + "," +
+                    TABLE_NAME + "," +
+                    INDEX_STATE +
+                    ") VALUES (?, ?, ?, ?)";
     private static final String UPDATE_INDEX_STATE_TO_ACTIVE =
             "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
-            TENANT_ID + "," +
-            TABLE_SCHEM + "," +
-            TABLE_NAME + "," +
-            INDEX_STATE + "," +
-            INDEX_DISABLE_TIMESTAMP +
-            ") VALUES (?, ?, ?, ?, ?)";
+                    TENANT_ID + "," +
+                    TABLE_SCHEM + "," +
+                    TABLE_NAME + "," +
+                    INDEX_STATE + "," +
+                    INDEX_DISABLE_TIMESTAMP +
+                    ") VALUES (?, ?, ?, ?, ?)";
     //TODO: merge INSERT_COLUMN_CREATE_TABLE and INSERT_COLUMN_ALTER_TABLE column when
     // the new major release is out.
     private static final String INSERT_COLUMN_CREATE_TABLE =
-        "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
-        TENANT_ID + "," +
-        TABLE_SCHEM + "," +
-        TABLE_NAME + "," +
-        COLUMN_NAME + "," +
-        COLUMN_FAMILY + "," +
-        DATA_TYPE + "," +
-        NULLABLE + "," +
-        COLUMN_SIZE + "," +
-        DECIMAL_DIGITS + "," +
-        ORDINAL_POSITION + "," +
-        SORT_ORDER + "," +
-        DATA_TABLE_NAME + "," + // write this both in the column and table rows for access by metadata APIs
-        ARRAY_SIZE + "," +
-        VIEW_CONSTANT + "," +
-        IS_VIEW_REFERENCED + "," +
-        PK_NAME + "," +  // write this both in the column and table rows for access by metadata APIs
-        KEY_SEQ + "," +
-        COLUMN_DEF + "," +
-        IS_ROW_TIMESTAMP + 
-        ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+            "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
+                    TENANT_ID + "," +
+                    TABLE_SCHEM + "," +
+                    TABLE_NAME + "," +
+                    COLUMN_NAME + "," +
+                    COLUMN_FAMILY + "," +
+                    DATA_TYPE + "," +
+                    NULLABLE + "," +
+                    COLUMN_SIZE + "," +
+                    DECIMAL_DIGITS + "," +
+                    ORDINAL_POSITION + "," +
+                    SORT_ORDER + "," +
+                    DATA_TABLE_NAME + "," + // write this both in the column and table rows for access by metadata APIs
+                    ARRAY_SIZE + "," +
+                    VIEW_CONSTANT + "," +
+                    IS_VIEW_REFERENCED + "," +
+                    PK_NAME + "," +  // write this both in the column and table rows for access by metadata APIs
+                    KEY_SEQ + "," +
+                    COLUMN_DEF + "," +
+                    IS_ROW_TIMESTAMP +
+                    ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
     private static final String INSERT_COLUMN_ALTER_TABLE =
             "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
-            TENANT_ID + "," +
-            TABLE_SCHEM + "," +
-            TABLE_NAME + "," +
-            COLUMN_NAME + "," +
-            COLUMN_FAMILY + "," +
-            DATA_TYPE + "," +
-            NULLABLE + "," +
-            COLUMN_SIZE + "," +
-            DECIMAL_DIGITS + "," +
-            ORDINAL_POSITION + "," +
-            SORT_ORDER + "," +
-            DATA_TABLE_NAME + "," + // write this both in the column and table rows for access by metadata APIs
-            ARRAY_SIZE + "," +
-            VIEW_CONSTANT + "," +
-            IS_VIEW_REFERENCED + "," +
-            PK_NAME + "," +  // write this both in the column and table rows for access by metadata APIs
-            KEY_SEQ + "," +
-            COLUMN_DEF +
-            ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+                    TENANT_ID + "," +
+                    TABLE_SCHEM + "," +
+                    TABLE_NAME + "," +
+                    COLUMN_NAME + "," +
+                    COLUMN_FAMILY + "," +
+                    DATA_TYPE + "," +
+                    NULLABLE + "," +
+                    COLUMN_SIZE + "," +
+                    DECIMAL_DIGITS + "," +
+                    ORDINAL_POSITION + "," +
+                    SORT_ORDER + "," +
+                    DATA_TABLE_NAME + "," + // write this both in the column and table rows for access by metadata APIs
+                    ARRAY_SIZE + "," +
+                    VIEW_CONSTANT + "," +
+                    IS_VIEW_REFERENCED + "," +
+                    PK_NAME + "," +  // write this both in the column and table rows for access by metadata APIs
+                    KEY_SEQ + "," +
+                    COLUMN_DEF +
+                    ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
     private static final String UPDATE_COLUMN_POSITION =
-        "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\" ( " +
-        TENANT_ID + "," +
-        TABLE_SCHEM + "," +
-        TABLE_NAME + "," +
-        COLUMN_NAME + "," +
-        COLUMN_FAMILY + "," +
-        ORDINAL_POSITION +
-        ") VALUES (?, ?, ?, ?, ?, ?)";
+            "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\" ( " +
+                    TENANT_ID + "," +
+                    TABLE_SCHEM + "," +
+                    TABLE_NAME + "," +
+                    COLUMN_NAME + "," +
+                    COLUMN_FAMILY + "," +
+                    ORDINAL_POSITION +
+                    ") VALUES (?, ?, ?, ?, ?, ?)";
     private static final String CREATE_FUNCTION =
             "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_FUNCTION_TABLE + "\" ( " +
-            TENANT_ID +","+
-            FUNCTION_NAME + "," +
-            NUM_ARGS + "," +
-            CLASS_NAME + "," +
-            JAR_PATH + "," +
-            RETURN_TYPE +
-            ") VALUES (?, ?, ?, ?, ?, ?)";
+                    TENANT_ID +","+
+                    FUNCTION_NAME + "," +
+                    NUM_ARGS + "," +
+                    CLASS_NAME + "," +
+                    JAR_PATH + "," +
+                    RETURN_TYPE +
+                    ") VALUES (?, ?, ?, ?, ?, ?)";
     private static final String INSERT_FUNCTION_ARGUMENT =
             "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_FUNCTION_TABLE + "\" ( " +
-            TENANT_ID +","+
-            FUNCTION_NAME + "," +
-            TYPE + "," +
-            ARG_POSITION +","+
-            IS_ARRAY + "," +
-            IS_CONSTANT  + "," +
-            DEFAULT_VALUE + "," +
-            MIN_VALUE + "," +
-            MAX_VALUE +
-            ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
+                    TENANT_ID +","+
+                    FUNCTION_NAME + "," +
+                    TYPE + "," +
+                    ARG_POSITION +","+
+                    IS_ARRAY + "," +
+                    IS_CONSTANT  + "," +
+                    DEFAULT_VALUE + "," +
+                    MIN_VALUE + "," +
+                    MAX_VALUE +
+                    ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
 
     public static final String EMPTY_TABLE = " ";
 
@@ -408,7 +408,7 @@ public class MetaDataClient {
         MetaDataMutationResult result = updateCache(schemaName, tableName, true);
         return result.getMutationTime();
     }
-    
+
     /**
      * Update the cache with the latest as of the connection scn.
      * @param schemaName
@@ -427,7 +427,7 @@ public class MetaDataClient {
     public MetaDataMutationResult updateCache(PName tenantId, String schemaName, String tableName) throws SQLException {
         return updateCache(tenantId, schemaName, tableName, false);
     }
-    
+
     public MetaDataMutationResult updateCache(PName tenantId, String schemaName, String tableName, boolean alwaysHitServer) throws SQLException {
         return updateCache(tenantId, schemaName, tableName, alwaysHitServer, null);
     }
@@ -455,13 +455,13 @@ public class MetaDataClient {
         long clientTimeStamp = scn == null ? HConstants.LATEST_TIMESTAMP : scn;
         return clientTimeStamp;
     }
-    
+
     private long getCurrentScn() {
         Long scn = connection.getSCN();
         long currentScn = scn == null ? HConstants.LATEST_TIMESTAMP : scn;
         return currentScn;
     }
-    
+
     private MetaDataMutationResult updateCache(PName origTenantId, String schemaName, String tableName,
             boolean alwaysHitServer, Long resolvedTimestamp) throws SQLException { // TODO: pass byte[] herez
         boolean systemTable = SYSTEM_CATALOG_SCHEMA.equals(schemaName);
@@ -479,18 +479,18 @@ public class MetaDataClient {
             tableResolvedTimestamp = tableRef.getResolvedTimeStamp();
         } catch (TableNotFoundException e) {
         }
-        
+
         boolean defaultTransactional = connection.getQueryServices().getProps().getBoolean(
-                                            QueryServices.DEFAULT_TABLE_ISTRANSACTIONAL_ATTRIB,
-                                            QueryServicesOptions.DEFAULT_TRANSACTIONAL);
+                QueryServices.DEFAULT_TABLE_ISTRANSACTIONAL_ATTRIB,
+                QueryServicesOptions.DEFAULT_TRANSACTIONAL);
         // start a txn if all table are transactional by default or if we found the table in the cache and it is transactional
-        // TODO if system tables become transactional remove the check 
+        // TODO if system tables become transactional remove the check
         boolean isTransactional = defaultTransactional || (table!=null && table.isTransactional());
         if (!systemTable && isTransactional && !connection.getMutationState().isTransactionStarted()) {
             connection.getMutationState().startTransaction();
         }
         resolvedTimestamp = resolvedTimestamp==null ? TransactionUtil.getResolvedTimestamp(connection, isTransactional, HConstants.LATEST_TIMESTAMP) : resolvedTimestamp;
-        // Do not make rpc to getTable if 
+        // Do not make rpc to getTable if
         // 1. table is a system table
         // 2. table was already resolved as of that timestamp
         if (table != null && !alwaysHitServer
@@ -507,7 +507,7 @@ public class MetaDataClient {
             final byte[] tableBytes = PVarchar.INSTANCE.toBytes(tableName);
             ConnectionQueryServices queryServices = connection.getQueryServices();
             result = queryServices.getTable(tenantId, schemaBytes, tableBytes, tableTimestamp, resolvedTimestamp);
-            // if the table was assumed to be transactional, but is actually not transactional then re-resolve as of the right timestamp (and vice versa) 
+            // if the table was assumed to be transactional, but is actually not transactional then re-resolve as of the right timestamp (and vice versa)
             if (table==null && result.getTable()!=null && result.getTable().isTransactional()!=isTransactional) {
                 result = queryServices.getTable(tenantId, schemaBytes, tableBytes, tableTimestamp, TransactionUtil.getResolvedTimestamp(connection, result.getTable().isTransactional(), HConstants.LATEST_TIMESTAMP));
             }
@@ -545,7 +545,7 @@ public class MetaDataClient {
                             connection.addTable(result.getTable(), resolvedTime);
                         }
                         else {
-                            // if we aren't adding the table, we still need to update the resolved time of the table 
+                            // if we aren't adding the table, we still need to update the resolved time of the table
                             connection.updateResolvedTimestamp(table, resolvedTime);
                         }
                         return result;
@@ -596,7 +596,7 @@ public class MetaDataClient {
                 String functionName = iterator.next();
                 function =
                         connection.getMetaDataCache().getFunction(
-                            new PTableKey(tenantId, functionName));
+                                new PTableKey(tenantId, functionName));
                 if (function != null && !alwaysHitServer
                         && function.getTimeStamp() == clientTimeStamp - 1) {
                     functions.add(function);
@@ -622,7 +622,7 @@ public class MetaDataClient {
         MetaDataMutationResult result;
 
         do {
-            List<Pair<byte[], Long>> functionsToFecth = new ArrayList<Pair<byte[], Long>>(functionNames.size()); 
+            List<Pair<byte[], Long>> functionsToFecth = new ArrayList<Pair<byte[], Long>>(functionNames.size());
             for(int i = 0; i< functionNames.size(); i++) {
                 functionsToFecth.add(new Pair<byte[], Long>(PVarchar.INSTANCE.toBytes(functionNames.get(i)), functionTimeStamps.get(i)));
             }
@@ -643,9 +643,9 @@ public class MetaDataClient {
                 if (code == MutationCode.FUNCTION_NOT_FOUND && tryCount + 1 == maxTryCount) {
                     for (Pair<byte[], Long> f : functionsToFecth) {
                         connection.removeFunction(tenantId, Bytes.toString(f.getFirst()),
-                            f.getSecond());
+                                f.getSecond());
                     }
-                    // TODO removeFunctions all together from cache when 
+                    // TODO removeFunctions all together from cache when
                     throw new FunctionNotFoundException(functionNames.toString() + " not found");
                 }
             }
@@ -721,7 +721,7 @@ public class MetaDataClient {
                 }
             }
             // Ensure that constant columns (i.e. columns matched in the view WHERE clause)
-            // all exist in the index on the parent table. 
+            // all exist in the index on the parent table.
             for (PColumn col : view.getColumns()) {
                 if (col.getViewConstant() != null) {
                     try {
@@ -730,7 +730,7 @@ public class MetaDataClient {
                         // would fail to compile.
                         String indexColumnName = IndexUtil.getIndexColumnName(col);
                         index.getColumn(indexColumnName);
-                    } catch (ColumnNotFoundException e1) { 
+                    } catch (ColumnNotFoundException e1) {
                         PColumn indexCol = null;
                         try {
                             String cf = col.getFamilyName()!=null ? col.getFamilyName().getString() : null;
@@ -755,10 +755,10 @@ public class MetaDataClient {
             if (containsAllReqdCols) {
                 // Tack on view statement to index to get proper filtering for view
                 String viewStatement = IndexUtil.rewriteViewStatement(connection, index, parentTable, view.getViewStatement());
-                PName modifiedIndexName = PNameFactory.newName(index.getSchemaName().getString() + QueryConstants.CHILD_VIEW_INDEX_NAME_SEPARATOR 
-                    + index.getName().getString() + QueryConstants.CHILD_VIEW_INDEX_NAME_SEPARATOR + view.getName().getString());
-                // add the index table with a new name so that it does not conflict with the existing index table 
-                // also set update cache frequency to never since the renamed index is not present on the server 
+                PName modifiedIndexName = PNameFactory.newName(index.getSchemaName().getString() + QueryConstants.CHILD_VIEW_INDEX_NAME_SEPARATOR
+                        + index.getName().getString() + QueryConstants.CHILD_VIEW_INDEX_NAME_SEPARATOR + view.getName().getString());
+                // add the index table with a new name so that it does not conflict with the existing index table
+                // also set update cache frequency to never since the renamed index is not present on the server
                 indexesToAdd.add(PTableImpl.makePTable(index, modifiedIndexName, viewStatement, Long.MAX_VALUE, view.getTenantId()));
             }
         }
@@ -843,24 +843,24 @@ public class MetaDataClient {
             String columnName = columnDefName.getColumnName();
             if (isPK && sortOrder == SortOrder.DESC && def.getDataType() == PVarbinary.INSTANCE) {
                 throw new SQLExceptionInfo.Builder(SQLExceptionCode.DESC_VARBINARY_NOT_SUPPORTED)
-                    .setColumnName(columnName)
-                    .build().buildException();
+                .setColumnName(columnName)
+                .build().buildException();
             }
 
             PName familyName = null;
             if (def.isPK() && !pkConstraint.getColumnNames().isEmpty() ) {
                 throw new SQLExceptionInfo.Builder(SQLExceptionCode.PRIMARY_KEY_ALREADY_EXISTS)
-                    .setColumnName(columnName).build().buildException();
+                .setColumnName(columnName).build().buildException();
             }
             boolean isNull = def.isNull();
             if (def.getColumnDefName().getFamilyName() != null) {
                 String family = def.getColumnDefName().getFamilyName();
                 if (isPK) {
                     throw new SQLExceptionInfo.Builder(SQLExceptionCode.PRIMARY_KEY_WITH_FAMILY_NAME)
-                        .setColumnName(columnName).setFamilyName(family).build().buildException();
+                    .setColumnName(columnName).setFamilyName(family).build().buildException();
                 } else if (!def.isNull()) {
                     throw new SQLExceptionInfo.Builder(SQLExceptionCode.KEY_VALUE_NOT_NULL)
-                        .setColumnName(columnName).setFamilyName(family).build().buildException();
+                    .setColumnName(columnName).setFamilyName(family).build().buildException();
                 }
                 familyName = PNameFactory.newName(family);
             } else if (!isPK) {
@@ -888,7 +888,7 @@ public class MetaDataClient {
         Map<String,Object> tableProps = Maps.newHashMapWithExpectedSize(statement.getProps().size());
         Map<String,Object> commonFamilyProps = Maps.newHashMapWithExpectedSize(statement.getProps().size() + 1);
         populatePropertyMaps(statement.getProps(), tableProps, commonFamilyProps);
-        
+
         boolean isAppendOnlySchema = false;
         Boolean appendOnlySchemaProp = (Boolean) TableProperty.APPEND_ONLY_SCHEMA.getValue(tableProps);
         if (appendOnlySchemaProp != null) {
@@ -905,25 +905,25 @@ public class MetaDataClient {
             .setSchemaName(tableName.getSchemaName()).setTableName(tableName.getTableName())
             .build().buildException();
         }
-        // view isAppendOnlySchema property must match the parent table 
+        // view isAppendOnlySchema property must match the parent table
         if (parent!=null && isAppendOnlySchema!= parent.isAppendOnlySchema()) {
             throw new SQLExceptionInfo.Builder(SQLExceptionCode.VIEW_APPEND_ONLY_SCHEMA)
             .setSchemaName(tableName.getSchemaName()).setTableName(tableName.getTableName())
             .build().buildException();
         }
-        
+
         PTable table = null;
         // if the APPEND_ONLY_SCHEMA attribute is true first check if the table is present in the cache
         // if it is add columns that are not already present
         if (isAppendOnlySchema) {
-            // look up the table in the cache 
+            // look up the table in the cache
             MetaDataMutationResult result = updateCache(tableName.getSchemaName(), tableName.getTableName());
             if (result.getMutationCode()==MutationCode.TABLE_ALREADY_EXISTS) {
                 table = result.getTable();
                 if (!statement.ifNotExists()) {
                     throw new NewerTableAlreadyExistsException(tableName.getSchemaName(), tableName.getTableName(), table);
                 }
-                
+
                 List<ColumnDef> columnDefs = statement.getColumnDefs();
                 PrimaryKeyConstraint pkConstraint = statement.getPrimaryKeyConstraint();
                 // get the list of columns to add
@@ -932,13 +932,13 @@ public class MetaDataClient {
                         columnDef.setIsPK(true);
                     }
                 }
-                // if there are new columns to add 
+                // if there are new columns to add
                 return addColumn(table, columnDefs, statement.getProps(), statement.ifNotExists(),
-                    true, NamedTableNode.create(statement.getTableName()), statement.getTableType());
+                        true, NamedTableNode.create(statement.getTableName()), statement.getTableType());
             }
         }
         table = createTableInternal(statement, splits, parent, viewStatement, viewType, viewColumnConstants, isViewColumnReferenced, null, null, null, tableProps, commonFamilyProps);
-            
+
         if (table == null || table.getType() == PTableType.VIEW || table.isTransactional()) {
             return new MutationState(0,connection);
         }
@@ -1057,7 +1057,7 @@ public class MetaDataClient {
              * since it may not represent a "real" table in the case of the view indexes of a base table.
              */
             PostDDLCompiler compiler = new PostDDLCompiler(connection);
-            //even if table is transactional, while calculating stats we scan the table non-transactionally to 
+            //even if table is transactional, while calculating stats we scan the table non-transactionally to
             //view all the data belonging to the table
             PTable nonTxnLogicalTable = new DelegateTable(logicalTable) {
                 @Override
@@ -1165,7 +1165,7 @@ public class MetaDataClient {
             } catch (IOException e) {
                 throw new SQLException(e);
             }
-            
+
             // execute index population upsert select
             long startTime = System.currentTimeMillis();
             MutationState state = connection.getQueryServices().updateData(mutationPlan);
@@ -1176,10 +1176,10 @@ public class MetaDataClient {
             // that were being written on the server while the index was created
             long sleepTime =
                     connection
-                            .getQueryServices()
-                            .getProps()
-                            .getLong(QueryServices.INDEX_POPULATION_SLEEP_TIME,
-                                QueryServicesOptions.DEFAULT_INDEX_POPULATION_SLEEP_TIME);
+                    .getQueryServices()
+                    .getProps()
+                    .getLong(QueryServices.INDEX_POPULATION_SLEEP_TIME,
+                        QueryServicesOptions.DEFAULT_INDEX_POPULATION_SLEEP_TIME);
             if (!dataTableRef.getTable().isTransactional() && sleepTime > 0) {
                 long delta = sleepTime - firstUpsertSelectTime;
                 if (delta > 0) {
@@ -1188,7 +1188,7 @@ public class MetaDataClient {
                     } catch (InterruptedException e) {
                         Thread.currentThread().interrupt();
                         throw new SQLExceptionInfo.Builder(SQLExceptionCode.INTERRUPTED_EXCEPTION)
-                                .setRootCause(e).build().buildException();
+                        .setRootCause(e).build().buildException();
                     }
                 }
                 // set the min timestamp of second index upsert select some time before the index
@@ -1203,10 +1203,10 @@ public class MetaDataClient {
                         connection.getQueryServices().updateData(mutationPlan);
                 state.join(newMutationState);
             }
-            
+
             indexStatement = FACTORY.alterIndex(FACTORY.namedTable(null,
-            		TableName.create(index.getSchemaName().getString(), index.getTableName().getString())),
-            		dataTableRef.getTable().getTableName().getString(), false, PIndexState.ACTIVE);
+            		    TableName.create(index.getSchemaName().getString(), index.getTableName().getString())),
+            		    dataTableRef.getTable().getTableName().getString(), false, PIndexState.ACTIVE);
             alterIndex(indexStatement);
 
             return state;
@@ -1246,7 +1246,7 @@ public class MetaDataClient {
     public MutationState createIndex(CreateIndexStatement statement, byte[][] splits) throws SQLException {
         IndexKeyConstraint ik = statement.getIndexConstraint();
         TableName indexTableName = statement.getIndexTableName();
-        
+
         Map<String,Object> tableProps = Maps.newHashMapWithExpectedSize(statement.getProps().size());
         Map<String,Object> commonFamilyProps = Maps.newHashMapWithExpectedSize(statement.getProps().size() + 1);
         populatePropertyMaps(statement.getProps(), tableProps, commonFamilyProps);
@@ -1305,7 +1305,7 @@ public class MetaDataClient {
                 }
                 List<ColumnDefInPkConstraint> allPkColumns = Lists.newArrayListWithExpectedSize(unusedPkColumns.size());
                 List<ColumnDef> columnDefs = Lists.newArrayListWithExpectedSize(includedColumns.size() + indexParseNodeAndSortOrderList.size());
-                
+
                 /*
                  * Allocate an index ID in two circumstances:
                  * 1) for a local index, as all local indexes will reside in the same HBase table
@@ -1318,7 +1318,7 @@ public class MetaDataClient {
                     allPkColumns.add(new ColumnDefInPkConstraint(colName, SortOrder.getDefault(), false));
                     columnDefs.add(FACTORY.columnDef(colName, dataType.getSqlTypeName(), false, null, null, false, SortOrder.getDefault(), null, false));
                 }
-                
+
                 if (dataTable.isMultiTenant()) {
                     PColumn col = dataTable.getPKColumns().get(posOffset);
                     RowKeyColumnExpression columnExpression = new RowKeyColumnExpression(col, new RowKeyValueAccessor(pkColumns, posOffset), col.getName().getString());
@@ -1328,7 +1328,7 @@ public class MetaDataClient {
                     allPkColumns.add(new ColumnDefInPkConstraint(colName, col.getSortOrder(), false));
                     columnDefs.add(FACTORY.columnDef(colName, dataType.getSqlTypeName(), col.isNullable(), col.getMaxLength(), col.getScale(), false, SortOrder.getDefault(), col.getName().getString(), col.isRowTimestamp()));
                 }
-                
+
                 PhoenixStatement phoenixStatment = new PhoenixStatement(connection);
                 StatementContext context = new StatementContext(phoenixStatment, resolver);
                 IndexExpressionCompiler expressionIndexCompiler = new IndexExpressionCompiler(context);
@@ -1339,7 +1339,7 @@ public class MetaDataClient {
                     parseNode = StatementNormalizer.normalize(parseNode, resolver);
                     // compile the parseNode to get an expression
                     expressionIndexCompiler.reset();
-                    Expression expression = parseNode.accept(expressionIndexCompiler);   
+                    Expression expression = parseNode.accept(expressionIndexCompiler);
                     if (expressionIndexCompiler.isAggregate()) {
                         throw new SQLExceptionInfo.Builder(SQLExceptionCode.AGGREGATE_EXPRESSION_NOT_ALLOWED_IN_INDEX).build().buildException();
                     }
@@ -1350,25 +1350,25 @@ public class MetaDataClient {
                         throw new SQLExceptionInfo.Builder(SQLExceptionCode.STATELESS_EXPRESSION_NOT_ALLOWED_IN_INDEX).build().buildException();
                     }
                     unusedPkColumns.remove(expression);
-                    
+
                     // Go through parse node to get string as otherwise we
                     // can lose information during compilation
                     StringBuilder buf = new StringBuilder();
                     parseNode.toSQL(resolver, buf);
                     // need to escape backslash as this expression will be re-parsed later
                     String expressionStr = StringUtil.escapeBackslash(buf.toString());
-                    
+
                     ColumnName colName = null;
                     ColumnRef colRef = expressionIndexCompiler.getColumnRef();
                     boolean isRowTimestamp = false;
-                    if (colRef!=null) { 
+                    if (colRef!=null) {
                         // if this is a regular column
                         PColumn column = colRef.getColumn();
                         String columnFamilyName = column.getFamilyName()!=null ? column.getFamilyName().getString() : null;
                         colName = ColumnName.caseSensitiveColumnName(IndexUtil.getIndexColumnName(columnFamilyName, column.getName().getString()));
                         isRowTimestamp = column.isRowTimestamp();
                     }
-                    else { 
+                    else {
                         // if this is an expression
                         // TODO column names cannot have double quotes, remove this once this PHOENIX-1621 is fixed
                         String name = expressionStr.replaceAll("\"", "'");
@@ -1396,7 +1396,7 @@ public class MetaDataClient {
                         }
                     }
                 }
-                
+
                 // Last all the included columns (minus any PK columns)
                 for (ColumnName colName : includedColumns) {
                     PColumn col = resolver.resolveColumn(null, colName.getFamilyName(), colName.getColumnName()).getColumn();
@@ -1425,8 +1425,8 @@ public class MetaDataClient {
                     // if scn is set create at scn-1, so we can see the sequence or else use latest timestamp (so that latest server time is used)
                     long sequenceTimestamp = scn!=null ? scn-1 : HConstants.LATEST_TIMESTAMP;
                     createSequence(key.getTenantId(), key.getSchemaName(), key.getSequenceName(),
-                        true, Short.MIN_VALUE, 1, 1, false, Long.MIN_VALUE, Long.MAX_VALUE,
-                        sequenceTimestamp);
+                            true, Short.MIN_VALUE, 1, 1, false, Long.MIN_VALUE, Long.MAX_VALUE,
+                            sequenceTimestamp);
                     long[] seqValues = new long[1];
                     SQLException[] sqlExceptions = new SQLException[1];
                     long timestamp = scn == null ? HConstants.LATEST_TIMESTAMP : scn;
@@ -1465,13 +1465,13 @@ public class MetaDataClient {
 
         if (logger.isInfoEnabled()) logger.info("Created index " + table.getName().getString() + " at " + table.getTimeStamp());
         boolean asyncIndexBuildEnabled = connection.getQueryServices().getProps().getBoolean(
-            QueryServices.INDEX_ASYNC_BUILD_ENABLED,
-            QueryServicesOptions.DEFAULT_INDEX_ASYNC_BUILD_ENABLED);
+                QueryServices.INDEX_ASYNC_BUILD_ENABLED,
+                QueryServicesOptions.DEFAULT_INDEX_ASYNC_BUILD_ENABLED);
         // In async process, we return immediately as the MR job needs to be triggered .
         if(statement.isAsync() && asyncIndexBuildEnabled) {
             return new MutationState(0, connection);
         }
-        
+
         // If our connection is at a fixed point-in-time, we need to open a new
         // connection so that our new index table is visible.
         if (connection.getSCN() != null) {
@@ -1514,7 +1514,7 @@ public class MetaDataClient {
         }
         return createSequence(tenantId, schemaName, statement
                 .getSequenceName().getTableName(), statement.ifNotExists(), startWith, incrementBy,
-            cacheSize, statement.getCycle(), minValue, maxValue, timestamp);
+                cacheSize, statement.getCycle(), minValue, maxValue, timestamp);
     }
 
     private MutationState createSequence(String tenantId, String schemaName, String sequenceName,
@@ -1522,7 +1522,7 @@ public class MetaDataClient {
             long minValue, long maxValue, long timestamp) throws SQLException {
         try {
             connection.getQueryServices().createSequence(tenantId, schemaName, sequenceName,
-                startWith, incrementBy, cacheSize, minValue, maxValue, cycle, timestamp);
+                    startWith, incrementBy, cacheSize, minValue, maxValue, cycle, timestamp);
         } catch (SequenceAlreadyExistsException e) {
             if (ifNotExists) {
                 return new MutationState(0, connection);
@@ -1568,23 +1568,23 @@ public class MetaDataClient {
             case FUNCTION_ALREADY_EXISTS:
                 if (!function.isReplace()) {
                     throw new FunctionAlreadyExistsException(function.getFunctionName(), result
-                        .getFunctions().get(0));
+                            .getFunctions().get(0));
                 } else {
                     connection.removeFunction(function.getTenantId(), function.getFunctionName(),
-                        result.getMutationTime());
+                            result.getMutationTime());
                     addFunctionToCache(result);
                 }
             case NEWER_FUNCTION_FOUND:
-                    // Add function to ConnectionQueryServices so it's cached, but don't add
-                    // it to this connection as we can't see it.
-                    throw new NewerFunctionAlreadyExistsException(function.getFunctionName(), result.getFunctions().get(0));
+                // Add function to ConnectionQueryServices so it's cached, but don't add
+                // it to this connection as we can't see it.
+                throw new NewerFunctionAlreadyExistsException(function.getFunctionName(), result.getFunctions().get(0));
             default:
                 List<PFunction> functions = new ArrayList<PFunction>(1);
                 functions.add(function);
                 result = new MetaDataMutationResult(code, result.getMutationTime(), functions, true);
                 if(function.isReplace()) {
                     connection.removeFunction(function.getTenantId(), function.getFunctionName(),
-                        result.getMutationTime());
+                            result.getMutationTime());
                 }
                 addFunctionToCache(result);
             }
@@ -1593,7 +1593,7 @@ public class MetaDataClient {
         }
         return new MutationState(1, connection);
     }
-    
+
     private static ColumnDef findColumnDefOrNull(List<ColumnDef> colDefs, ColumnName colName) {
         for (ColumnDef colDef : colDefs) {
             if (colDef.getColumnDefName().getColumnName().equals(colName.getColumnName())) {
@@ -1602,7 +1602,7 @@ public class MetaDataClient {
         }
         return null;
     }
-    
+
     private static boolean checkAndValidateRowTimestampCol(ColumnDef colDef, PrimaryKeyConstraint pkConstraint,
             boolean rowTimeStampColAlreadyFound, PTableType tableType) throws SQLException {
 
@@ -1620,16 +1620,16 @@ public class MetaDataClient {
             if (isColumnDeclaredRowTimestamp) {
                 boolean isColumnPartOfPk = colDef.isPK() || pkConstraint.contains(columnDefName);
                 // A column can be declared as ROW_TIMESTAMP only if it is part of the primary key
-                if (isColumnDeclaredRowTimestamp && !isColumnPartOfPk) { 
+                if (isColumnDeclaredRowTimestamp && !isColumnPartOfPk) {
                     throw new SQLExceptionInfo.Builder(SQLExceptionCode.ROWTIMESTAMP_PK_COL_ONLY)
-                    .setColumnName(columnDefName.getColumnName()).build().buildException(); 
+                    .setColumnName(columnDefName.getColumnName()).build().buildException();
                 }
 
                 // A column can be declared as ROW_TIMESTAMP only if it can be represented as a long
                 PDataType dataType = colDef.getDataType();
-                if (isColumnDeclaredRowTimestamp && (dataType != PLong.INSTANCE && dataType != PUnsignedLong.INSTANCE && !dataType.isCoercibleTo(PTimestamp.INSTANCE))) { 
+                if (isColumnDeclaredRowTimestamp && (dataType != PLong.INSTANCE && dataType != PUnsignedLong.INSTANCE && !dataType.isCoercibleTo(PTimestamp.INSTANCE))) {
                     throw new SQLExceptionInfo.Builder(SQLExceptionCode.ROWTIMESTAMP_COL_INVALID_TYPE)
-                    .setColumnName(columnDefName.getColumnName()).build().buildException(); 
+                    .setColumnName(columnDefName.getColumnName()).build().buildException();
                 }
 
                 // Only one column can be declared as a ROW_TIMESTAMP column
@@ -1642,7 +1642,7 @@ public class MetaDataClient {
         }
         return false;
     }
-    
+
     private PTable createTableInternal(CreateTableStatement statement, byte[][] splits,
             final PTable parent, String viewStatement, ViewType viewType,
             final byte[][] viewColumnConstants, final BitSet isViewColumnReferenced, Short indexId,
@@ -1755,8 +1755,8 @@ public class MetaDataClient {
                     isImmutableRows = isImmutableRowsProp;
                 }
             }
-            
-            if (tableType == PTableType.TABLE) { 
+
+            if (tableType == PTableType.TABLE) {
                 Boolean isAppendOnlySchemaProp = (Boolean) TableProperty.APPEND_ONLY_SCHEMA.getValue(tableProps);
                 isAppendOnlySchema = isAppendOnlySchemaProp!=null ? isAppendOnlySchemaProp : false;
             }
@@ -1779,7 +1779,7 @@ public class MetaDataClient {
                 }
                 addSaltColumn = (saltBucketNum != null);
             }
-            
+
             // Can't set MULTI_TENANT or DEFAULT_COLUMN_FAMILY_NAME on an INDEX or a non mapped VIEW
             if (tableType != PTableType.INDEX && (tableType != PTableType.VIEW || viewType == ViewType.MAPPED)) {
                 Boolean multiTenantProp = (Boolean) tableProps.get(PhoenixDatabaseMetaData.MULTI_TENANT);
@@ -1840,7 +1840,7 @@ public class MetaDataClient {
                 .setSchemaName(schemaName).setTableName(tableName)
                 .build().buildException();
             }
-            
+
             // Put potentially inferred value into tableProps as it's used by the createTable call below
             // to determine which coprocessors to install on the new table.
             tableProps.put(PhoenixDatabaseMetaData.TRANSACTIONAL, transactional);
@@ -1851,9 +1851,9 @@ public class MetaDataClient {
                     commonFamilyProps.put(TxConstants.PROPERTY_TTL, ttl);
                 }
             }
-            
+
             boolean sharedTable = statement.getTableType() == PTableType.VIEW || indexId != null;
-            if (transactional) { 
+            if (transactional) {
                 // Tephra uses an empty value cell as its delete marker, so we need to turn on
                 // storeNulls for transactional tables.
                 // If we use regular column delete markers (which is what non transactional tables
@@ -1869,7 +1869,7 @@ public class MetaDataClient {
                 // Force STORE_NULLS to true when transactional as Tephra cannot deal with column deletes
                 storeNulls = true;
                 tableProps.put(PhoenixDatabaseMetaData.STORE_NULLS, Boolean.TRUE);
-                
+
                 if (!sharedTable) {
                     Integer maxVersionsProp = (Integer) commonFamilyProps.get(HConstants.VERSIONS);
                     if (maxVersionsProp == null) {
@@ -2010,7 +2010,7 @@ public class MetaDataClient {
             }
             int pkPositionOffset = pkColumns.size();
             int position = positionOffset;
-            
+
             for (ColumnDef colDef : colDefs) {
                 rowTimeStampColumnAlreadyFound = checkAndValidateRowTimestampCol(colDef, pkConstraint, rowTimeStampColumnAlreadyFound, tableType);
                 if (colDef.isPK()) { // i.e. the column is declared as CREATE TABLE COLNAME DATATYPE PRIMARY KEY...
@@ -2156,20 +2156,20 @@ public class MetaDataClient {
             }
 
             short nextKeySeq = 0;
-            
+
             List<Mutation> columnMetadata = Lists.newArrayListWithExpectedSize(columns.size());
             try (PreparedStatement colUpsert = connection.prepareStatement(INSERT_COLUMN_CREATE_TABLE)) {
                 for (Map.Entry<PColumn, PColumn> entry : columns.entrySet()) {
                     PColumn column = entry.getValue();
                     final int columnPosition = column.getPosition();
                     // For client-side cache, we need to update the column
-                    // set the autoPartition column attributes   
+                    // set the autoPartition column attributes
                     if (parent != null && parent.getAutoPartitionSeqName() != null
                             && parent.getPKColumns().get(MetaDataUtil.getAutoPartitionColIndex(parent)).equals(column)) {
                         entry.setValue(column = new DelegateColumn(column) {
                             @Override
                             public byte[] getViewConstant() {
-                                // set to non-null value so that we will generate a Put that 
+                                // set to non-null value so that we will generate a Put that
                                 // will be set correctly on the server
                                 return QueryConstants.EMPTY_COLUMN_VALUE_BYTES;
                             }
@@ -2230,7 +2230,7 @@ public class MetaDataClient {
             tableUpsert.setBoolean(11, isImmutableRows);
             tableUpsert.setString(12, defaultFamilyName);
             if (parent != null && parent.getAutoPartitionSeqName() != null && viewStatement==null) {
-                // set to non-null value so that we will generate a Put that 
+                // set to non-null value so that we will generate a Put that
                 // will be set correctly on the server
                 tableUpsert.setString(13, QueryConstants.EMPTY_COLUMN_VALUE);
             }
@@ -2428,7 +2428,7 @@ public class MetaDataClient {
         return dropTable(schemaName, tableName, parentTableName, PTableType.INDEX, statement.ifExists(), false);
     }
 
-    private MutationState dropFunction(String functionName, 
+    private MutationState dropFunction(String functionName,
             boolean ifExists) throws SQLException {
         connection.rollback();
         boolean wasAutoCommit = connection.getAutoCommit();
@@ -2446,7 +2446,7 @@ public class MetaDataClient {
                     return new MutationState(0, connection);
                 }
             } catch(FunctionNotFoundException e) {
-                
+
             }
             List<Mutation> functionMetaData = Lists.newArrayListWithExpectedSize(2);
             Delete functionDelete = new Delete(key, clientTimeStamp);
@@ -2523,7 +2523,7 @@ public class MetaDataClient {
                         // All multi-tenant tables have a view index table, so no need to check in that case
                         if (parentTableName == null) {
                             hasViewIndexTable = true;// keeping always true for deletion of stats if view index present
-                                                     // or not
+                            // or not
                             MetaDataUtil.deleteViewIndexSequences(connection, table.getPhysicalName(),
                                     table.isNamespaceMapped());
                             byte[] viewIndexPhysicalName = MetaDataUtil
@@ -2635,7 +2635,7 @@ public class MetaDataClient {
                 msg = "Cannot add/drop column referenced by VIEW";
             }
             throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_MUTATE_TABLE)
-                .setSchemaName(schemaName).setTableName(tableName).setFamilyName(familyName).setColumnName(columnName).setMessage(msg).build().buildException();
+            .setSchemaName(schemaName).setTableName(tableName).setFamilyName(familyName).setColumnName(columnName).setMessage(msg).build().buildException();
         case NO_OP:
         case COLUMN_ALREADY_EXISTS:
         case COLUMN_NOT_FOUND:
@@ -2648,18 +2648,18 @@ public class MetaDataClient {
             throw new ConcurrentTableMutationException(schemaName, tableName);
         case NEWER_TABLE_FOUND:
             // TODO: update cache?
-//            if (result.getTable() != null) {
-//                connection.addTable(result.getTable());
-//            }
+            //            if (result.getTable() != null) {
+            //                connection.addTable(result.getTable());
+            //            }
             throw new NewerTableAlreadyExistsException(schemaName, tableName, result.getTable());
         case NO_PK_COLUMNS:
             throw new SQLExceptionInfo.Builder(SQLExceptionCode.PRIMARY_KEY_MISSING)
-                .setSchemaName(schemaName).setTableName(tableName).build().buildException();
+            .setSchemaName(schemaName).setTableName(tableName).build().buildException();
         case TABLE_ALREADY_EXISTS:
             break;
         default:
             throw new SQLExceptionInfo.Builder(SQLExceptionCode.UNEXPECTED_MUTATION_CODE).setSchemaName(schemaName)
-                .setTableName(tableName).setMessage("mutation code: " + mutationCode).build().buildException();
+            .setTableName(tableName).setMessage("mutation code: " + mutationCode).build().buildException();
         }
         return mutationCode;
     }
@@ -2713,11 +2713,11 @@ public class MetaDataClient {
     private void mutateBooleanProperty(String tenantId, String schemaName, String tableName,
             String propertyName, boolean propertyValue) throws SQLException {
         String updatePropertySql = "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
-                        TENANT_ID + "," +
-                        TABLE_SCHEM + "," +
-                        TABLE_NAME + "," +
-                        propertyName +
-                        ") VALUES (?, ?, ?, ?)";
+                TENANT_ID + "," +
+                TABLE_SCHEM + "," +
+                TABLE_NAME + "," +
+                propertyName +
+                ") VALUES (?, ?, ?, ?)";
         try (PreparedStatement tableBoolUpsert = connection.prepareStatement(updatePropertySql)) {
             tableBoolUpsert.setString(1, tenantId);
             tableBoolUpsert.setString(2, schemaName);
@@ -2730,11 +2730,11 @@ public class MetaDataClient {
     private void mutateLongProperty(String tenantId, String schemaName, String tableName,
             String propertyName, long propertyValue) throws SQLException {
         String updatePropertySql = "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
-                        TENANT_ID + "," +
-                        TABLE_SCHEM + "," +
-                        TABLE_NAME + "," +
-                        propertyName +
-                        ") VALUES (?, ?, ?, ?)";
+                TENANT_ID + "," +
+                TABLE_SCHEM + "," +
+                TABLE_NAME + "," +
+                propertyName +
+                ") VALUES (?, ?, ?, ?)";
         try (PreparedStatement tableBoolUpsert = connection.prepareStatement(updatePropertySql)) {
             tableBoolUpsert.setString(1, tenantId);
             tableBoolUpsert.setString(2, schemaName);
@@ -2743,7 +2743,7 @@ public class MetaDataClient {
             tableBoolUpsert.execute();
         }
     }
-    
+
     public MutationState addColumn(AddColumnStatement statement) throws SQLException {
         PTable table = FromCompiler.getResolver(statement, connection).getTables().get(0).getTable();
         return addColumn(table, statement.getColumnDefs(), statement.getProps(), statement.ifNotExists(), false, statement.getTable(), statement.getTableType());
@@ -2752,7 +2752,7 @@ public class MetaDataClient {
     public MutationState addColumn(PTable table, List<ColumnDef> origColumnDefs,
             ListMultimap<String, Pair<String, Object>> stmtProperties, boolean ifNotExists,
             boolean removeTableProps, NamedTableNode namedTableNode, PTableType tableType)
-            throws SQLException {
+                    throws SQLException {
         connection.rollback();
         boolean wasAutoCommit = connection.getAutoCommit();
         try {
@@ -3029,12 +3029,12 @@ public class MetaDataClient {
                     connection.rollback();
                 }
                 long seqNum = table.getSequenceNumber();
-                if (changingPhoenixTableProperty || columnDefs.size() > 0) { 
+                if (changingPhoenixTableProperty || columnDefs.size() > 0) {
                     seqNum = incrementTableSeqNum(table, tableType, columnDefs.size(), isTransactional, updateCacheFrequency, isImmutableRows, disableWAL, multiTenant, storeNulls);
                     tableMetaData.addAll(connection.getMutationState().toMutations(timeStamp).next().getSecond());
                     connection.rollback();
                 }
-                
+
                 // Force the table header row to be first
                 Collections.reverse(tableMetaData);
                 // Add column metadata afterwards, maintaining the order so columns have more predictable ordinal position
@@ -3069,7 +3069,7 @@ public class MetaDataClient {
                         return new MutationState(0,connection);
                     }
 
-                    // Only update client side cache if we aren't adding a PK column to a table with indexes or 
+                    // Only update client side cache if we aren't adding a PK column to a table with indexes or
                     // transitioning a table from non transactional to transactional.
                     // We could update the cache manually then too, it'd just be a pain.
                     String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
@@ -3082,13 +3082,13 @@ public class MetaDataClient {
                                 result.getMutationTime(),
                                 seqNum,
                                 isImmutableRows == null ? table.isImmutableRows() : isImmutableRows,
-                                disableWAL == null ? table.isWALDisabled() : disableWAL,
-                                multiTenant == null ? table.isMultiTenant() : multiTenant,
-                                storeNulls == null ? table.getStoreNulls() : storeNulls, 
-                                isTransactional == null ? table.isTransactional() : isTransactional,
-                                updateCacheFrequency == null ? table.getUpdateCacheFrequency() : updateCacheFrequency,
-                                table.isNamespaceMapped(),
-                                resolvedTimeStamp);
+                                        disableWAL == null ? table.isWALDisabled() : disableWAL,
+                                                multiTenant == null ? table.isMultiTenant() : multiTenant,
+                                                        storeNulls == null ? table.getStoreNulls() : storeNulls,
+                                                                isTransactional == null ? table.isTransactional() : isTransactional,
+                                                                        updateCacheFrequency == null ? table.getUpdateCacheFrequency() : updateCacheFrequency,
+                                                                                table.isNamespaceMapped(),
+                                                                                resolvedTimeStamp);
                     } else if (updateCacheFrequency != null) {
                         // Force removal from cache as the update cache frequency has changed
                         // Note that clients outside this JVM won't be affected.
@@ -3172,7 +3172,7 @@ public class MetaDataClient {
         Collections.sort(columnsToDrop,new Comparator<PColumn> () {
             @Override
             public int compare(PColumn left, PColumn right) {
-               return Ints.compare(left.getPosition(), right.getPosition());
+                return Ints.compare(left.getPosition(), right.getPosition());
             }
         });
 
@@ -3194,7 +3194,7 @@ public class MetaDataClient {
             colUpdate.setInt(6, column.getPosition() - columnsToDropIndex - (isSalted ? 1 : 0));
             colUpdate.execute();
         }
-       return familyName;
+        return familyName;
     }
 
     /**
@@ -3227,7 +3227,7 @@ public class MetaDataClient {
                 final ColumnResolver resolver = FromCompiler.getResolver(statement, connection);
                 TableRef tableRef = resolver.getTables().get(0);
                 PTable table = tableRef.getTable();
-                
+
                 List<ColumnName> columnRefs = statement.getColumnRefs();
                 if(columnRefs == null) {
                     columnRefs = Lists.newArrayListWithCapacity(0);
@@ -3251,7 +3251,7 @@ public class MetaDataClient {
                     tableColumnsToDrop.add(columnToDrop);
                     if (SchemaUtil.isPKColumn(columnToDrop)) {
                         throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_DROP_PK)
-                            .setColumnName(columnToDrop.getName().getString()).build().buildException();
+                        .setColumnName(columnToDrop.getName().getString()).build().buildException();
                     }
                     else if (table.isAppendOnlySchema()) {
                         throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_DROP_COL_APPEND_ONLY_SCHEMA)
@@ -3267,18 +3267,18 @@ public class MetaDataClient {
                     IndexMaintainer indexMaintainer = index.getIndexMaintainer(table, connection);
                     // get the columns required for the index pk
                     Set<ColumnReference> indexColumns = indexMaintainer.getIndexedColumns();
-                    // get the covered columns 
+                    // get the covered columns
                     Set<ColumnReference> coveredColumns = indexMaintainer.getCoveredColumns();
                     List<PColumn> indexColumnsToDrop = Lists.newArrayListWithExpectedSize(columnRefs.size());
                     for(PColumn columnToDrop : tableColumnsToDrop) {
                         ColumnReference columnToDropRef = new ColumnReference(columnToDrop.getFamilyName().getBytes(), columnToDrop.getName().getBytes());
                         // if the columns being dropped is indexed and the physical index table is not shared
                         if (indexColumns.contains(columnToDropRef)) {
-                            if (index.getViewIndexId()==null) 
+                            if (index.getViewIndexId()==null)
                                 indexesToDrop.add(new TableRef(index));
                             connection.removeTable(tenantId, SchemaUtil.getTableName(schemaName, index.getName().getString()), index.getParentName() == null ? null : index.getParentName().getString(), index.getTimeStamp());
                             removedIndexTableOrColumn = true;
-                        } 
+                        }
                         else if (coveredColumns.contains(columnToDropRef)) {
                             String indexColumnName = IndexUtil.getIndexColumnName(columnToDrop);
                             PColumn indexColumn = index.getColumn(indexColumnName);
@@ -3293,8 +3293,8 @@ public class MetaDataClient {
                         dropColumnMutations(index, indexColumnsToDrop);
                         long clientTimestamp = MutationState.getMutationTimestamp(timeStamp, connection.getSCN());
                         connection.removeColumn(tenantId, index.getName().getString(),
-                            indexColumnsToDrop, clientTimestamp, indexTableSeqNum,
-                            TransactionUtil.getResolvedTimestamp(connection, index.isTransactional(), clientTimestamp));
+                                indexColumnsToDrop, clientTimestamp, indexTableSeqNum,
+                                TransactionUtil.getResolvedTimestamp(connection, index.isTransactional(), clientTimestamp));
                     }
                 }
                 tableMetaData.addAll(connection.getMutationState().toMutations(timeStamp).next().getSecond());
@@ -3332,8 +3332,8 @@ public class MetaDataClient {
                             connection.getQueryServices().addColumn(
                                     Collections.<Mutation>singletonList(new Put(SchemaUtil.getTableKey
                                             (tenantIdBytes, tableContainingColumnToDrop.getSchemaName().getBytes(),
-                                            tableContainingColumnToDrop.getTableName().getBytes()))),
-                                            tableContainingColumnToDrop, family, Sets.newHashSet(Bytes.toString(emptyCF)));
+                                                    tableContainingColumnToDrop.getTableName().getBytes()))),
+                                                    tableContainingColumnToDrop, family, Sets.newHashSet(Bytes.toString(emptyCF)));
 
                         }
                     }
@@ -3354,7 +3354,7 @@ public class MetaDataClient {
                     if (tableColumnsToDrop.size() > 0) {
                         if (removedIndexTableOrColumn)
                             connection.removeTable(tenantId, tableName, table.getParentName() == null ? null : table.getParentName().getString(), table.getTimeStamp());
-                        else  
+                        else
                             connection.removeColumn(tenantId, SchemaUtil.getTableName(schemaName, tableName) , tableColumnsToDrop, result.getMutationTime(), seqNum, TransactionUtil.getResolvedTime(connection, result));
                     }
                     // If we have a VIEW, then only delete the metadata, and leave the table data alone
@@ -3365,10 +3365,10 @@ public class MetaDataClient {
                         // Delete everything in the column. You'll still be able to do queries at earlier timestamps
                         long ts = (scn == null ? result.getMutationTime() : scn);
                         PostDDLCompiler compiler = new PostDDLCompiler(connection);
-                        
+
                         boolean dropMetaData = connection.getQueryServices().getProps().getBoolean(DROP_METADATA_ATTRIB, DEFAULT_DROP_METADATA);
                         // if the index is a local index or view index it uses a shared physical table
-                        // so we need to issue deletes markers for all the rows of the index 
+                        // so we need to issue deletes markers for all the rows of the index
                         final List<TableRef> tableRefsToDrop = Lists.newArrayList();
                         Map<String, List<TableRef>> tenantIdTableRefMap = Maps.newHashMap();
                         if (result.getSharedTablesToDelete()!=null) {
@@ -3389,7 +3389,7 @@ public class MetaDataClient {
                                     }
                                     tenantIdTableRefMap.get(indexTableTenantId.getString()).add(indexTableRef);
                                 }
-                                
+
                             }
                         }
                         // if dropMetaData is false delete all rows for the indexes (if it was true
@@ -3399,7 +3399,7 @@ public class MetaDataClient {
                         }
                         // Drop any index tables that had the dropped column in the PK
                         connection.getQueryServices().updateData(compiler.compile(tableRefsToDrop, null, null, Collections.<PColumn>emptyList(), ts));
-                        
+
                         // Drop any tenant-specific indexes
                         if (!tenantIdTableRefMap.isEmpty()) {
                             for (Entry<String, List<TableRef>> entry : tenantIdTableRefMap.entrySet()) {
@@ -3412,7 +3412,7 @@ public class MetaDataClient {
                                 }
                             }
                         }
-                        
+
                         // Update empty key value column if necessary
                         for (ColumnRef droppedColumnRef : columnsToDrop) {
                             // Painful, but we need a TableRef with a pre-set timestamp to prevent attempts
@@ -3572,21 +3572,21 @@ public class MetaDataClient {
     }
 
     private void throwIfLastPKOfParentIsFixedLength(PTable parent, String viewSchemaName, String viewName, ColumnDef col) throws SQLException {
-        if (isLastPKVariableLength(parent)) { 
+        if (isLastPKVariableLength(parent)) {
             throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_MODIFY_VIEW_PK)
-                .setSchemaName(viewSchemaName)
-                .setTableName(viewName)
-                .setColumnName(col.getColumnDefName().getColumnName())
-                .build().buildException(); }
+            .setSchemaName(viewSchemaName)
+            .setTableName(viewName)
+            .setColumnName(col.getColumnDefName().getColumnName())
+            .build().buildException(); }
     }
-    
+
     private boolean isLastPKVariableLength(PTable table) {
         List<PColumn> pkColumns = table.getPKColumns();
         return !pkColumns.get(pkColumns.size()-1).getDataType().isFixedWidth();
     }
-    
+
     private PTable getParentOfView(PTable view) throws SQLException {
-        //TODO just use view.getParentName().getString() after implementing https://issues.apache.org/jira/browse/PHOENIX-2114 
+        //TODO just use view.getParentName().getString() after implementing https://issues.apache.org/jira/browse/PHOENIX-2114
         SelectStatement select = new SQLParser(view.getViewStatement()).parseQuery();
         String parentName = SchemaUtil.normalizeFullTableName(select.getFrom().toString().trim());
         return connection.getTable(new PTableKey(view.getTenantId(), parentName));
@@ -3598,9 +3598,9 @@ public class MetaDataClient {
         try {
             if (!SchemaUtil.isNamespaceMappingEnabled(null,
                     connection.getQueryServices()
-                            .getProps())) { throw new SQLExceptionInfo.Builder(
-                                    SQLExceptionCode.CREATE_SCHEMA_NOT_ALLOWED).setSchemaName(create.getSchemaName())
-                                            .build().buildException(); }
+                    .getProps())) { throw new SQLExceptionInfo.Builder(
+                            SQLExceptionCode.CREATE_SCHEMA_NOT_ALLOWED).setSchemaName(create.getSchemaName())
+                            .build().buildException(); }
             boolean isIfNotExists = create.isIfNotExists();
             validateSchema(create.getSchemaName());
             PSchema schema = new PSchema(create.getSchemaName());
@@ -3639,7 +3639,7 @@ public class MetaDataClient {
     private void validateSchema(String schemaName) throws SQLException {
         if (SchemaUtil.NOT_ALLOWED_SCHEMA_LIST.contains(
                 schemaName.toUpperCase())) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.SCHEMA_NOT_ALLOWED)
-                        .setSchemaName(schemaName).build().buildException(); }
+                .setSchemaName(schemaName).build().buildException(); }
     }
 
     public MutationState dropSchema(DropSchemaStatement executableDropSchemaStatement) throws SQLException {
@@ -3667,7 +3667,7 @@ public class MetaDataClient {
                 throw new NewerSchemaAlreadyExistsException(schemaName);
             case TABLES_EXIST_ON_SCHEMA:
                 throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_MUTATE_SCHEMA).setSchemaName(schemaName)
-                        .build().buildException();
+                .build().buildException();
             default:
                 connection.removeSchema(schema, result.getMutationTime());
                 break;
@@ -3685,7 +3685,7 @@ public class MetaDataClient {
             connection.setSchema(null);
         } else {
             FromCompiler.getResolverForSchema(useSchemaStatement, connection)
-                    .resolveSchema(useSchemaStatement.getSchemaName());
+            .resolveSchema(useSchemaStatement.getSchemaName());
             connection.setSchema(useSchemaStatement.getSchemaName());
         }
         return new MutationState(0, connection);


[09/47] phoenix git commit: PHOENIX-2946 Projected comparison between date and timestamp columns always returns true

Posted by ma...@apache.org.
PHOENIX-2946 Projected comparison between date and timestamp columns always returns true


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

Branch: refs/heads/calcite
Commit: 210445ded95d9da503c13cac24b4148aa819e205
Parents: 3a8724e
Author: James Taylor <ja...@apache.org>
Authored: Wed Sep 7 20:18:04 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Thu Sep 8 11:13:43 2016 -0700

----------------------------------------------------------------------
 .../expression/function/CeilDateExpression.java |   3 +
 .../function/CeilTimestampExpression.java       |   3 +
 .../expression/function/DateScalarFunction.java |  54 ++
 .../expression/function/DayOfMonthFunction.java |   4 +-
 .../expression/function/DayOfWeekFunction.java  |   8 +-
 .../expression/function/DayOfYearFunction.java  |   7 +-
 .../expression/function/HourFunction.java       |   4 +-
 .../expression/function/MinuteFunction.java     |   4 +-
 .../expression/function/MonthFunction.java      |   4 +-
 .../function/RoundDateExpression.java           |   3 +
 .../function/RoundJodaDateExpression.java       |   3 +
 .../expression/function/SecondFunction.java     |   4 +-
 .../expression/function/ToDateFunction.java     |  10 +-
 .../expression/function/WeekFunction.java       |   4 +-
 .../expression/function/YearFunction.java       |   4 +-
 .../phoenix/jdbc/PhoenixPreparedStatement.java  |  26 +-
 .../org/apache/phoenix/schema/SortOrder.java    |  11 +
 .../apache/phoenix/schema/types/PDataType.java  |  19 +-
 .../org/apache/phoenix/schema/types/PDate.java  | 283 +++++-----
 .../apache/phoenix/schema/types/PDecimal.java   |   6 +-
 .../org/apache/phoenix/schema/types/PLong.java  | 519 ++++++++++---------
 .../org/apache/phoenix/schema/types/PTime.java  |   2 +-
 .../apache/phoenix/schema/types/PTimestamp.java |  42 +-
 .../phoenix/schema/types/PUnsignedDate.java     | 259 +++++----
 .../phoenix/schema/types/PUnsignedLong.java     | 317 +++++------
 .../phoenix/schema/types/PUnsignedTime.java     |   2 +-
 .../schema/types/PUnsignedTimestamp.java        | 152 ++----
 .../java/org/apache/phoenix/util/DateUtil.java  |  23 +-
 .../phoenix/util/csv/CsvUpsertExecutor.java     |   8 +-
 .../phoenix/schema/types/PDataTypeTest.java     |  18 +
 30 files changed, 977 insertions(+), 829 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDateExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDateExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDateExpression.java
index e3cd985..7629409 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDateExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDateExpression.java
@@ -93,6 +93,9 @@ public class CeilDateExpression extends RoundDateExpression {
     @Override
     public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
         if (children.get(0).evaluate(tuple, ptr)) {
+            if (ptr.getLength() == 0) {
+                return true; // child evaluated to null
+            }
             PDataType dataType = getDataType();
             long time = dataType.getCodec().decodeLong(ptr, children.get(0).getSortOrder());
             long value = roundTime(time);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilTimestampExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilTimestampExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilTimestampExpression.java
index f69f2f8..b3a2a97 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilTimestampExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilTimestampExpression.java
@@ -97,6 +97,9 @@ public class CeilTimestampExpression extends CeilDateExpression {
     @Override
     public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
         if (children.get(0).evaluate(tuple, ptr)) {
+            if (ptr.getLength() == 0) {
+                return true; // child evaluated to null
+            }
             SortOrder sortOrder = children.get(0).getSortOrder();
             PDataType dataType = getDataType();
             int nanos = dataType.getNanos(ptr, sortOrder);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DateScalarFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DateScalarFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DateScalarFunction.java
new file mode 100644
index 0000000..aa56a0f
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DateScalarFunction.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.expression.function;
+
+import java.io.DataInput;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDataType.PDataCodec;
+import org.apache.phoenix.util.DateUtil;
+
+public abstract class DateScalarFunction extends ScalarFunction {
+    protected PDataCodec inputCodec;
+
+    public DateScalarFunction() {
+    }
+
+    public DateScalarFunction(List<Expression> children) {
+        super(children);
+        init();
+    }
+
+    protected final PDataCodec getInputCodec() {
+        return inputCodec;
+    }
+    
+    @Override
+    public void readFields(DataInput input) throws IOException {
+        super.readFields(input);
+        init();
+    }
+    
+    private void init() {
+        PDataType returnType = getChildren().get(0).getDataType();
+        inputCodec = DateUtil.getCodecFor(returnType);
+    }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfMonthFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfMonthFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfMonthFunction.java
index 0c328cf..fb5a68a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfMonthFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfMonthFunction.java
@@ -38,7 +38,7 @@ import org.joda.time.DateTime;
  */
 @BuiltInFunction(name=DayOfMonthFunction.NAME, 
 args={@Argument(allowedTypes={PTimestamp.class})})
-public class DayOfMonthFunction extends ScalarFunction {
+public class DayOfMonthFunction extends DateScalarFunction {
     public static final String NAME = "DAYOFMONTH";
 
     public DayOfMonthFunction() {
@@ -57,7 +57,7 @@ public class DayOfMonthFunction extends ScalarFunction {
         if ( ptr.getLength() == 0) {
             return true; //means null
         }
-        long dateTime = expression.getDataType().getCodec().decodeLong(ptr, expression.getSortOrder());
+        long dateTime = inputCodec.decodeLong(ptr, expression.getSortOrder());
         DateTime dt = new DateTime(dateTime);
         int day = dt.getDayOfMonth();
         PDataType returnType = getDataType();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfWeekFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfWeekFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfWeekFunction.java
index 0330b83..e4d3d5f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfWeekFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfWeekFunction.java
@@ -17,6 +17,8 @@
  */
 package org.apache.phoenix.expression.function;
 
+import java.util.List;
+
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
@@ -27,8 +29,6 @@ import org.apache.phoenix.schema.types.PInteger;
 import org.apache.phoenix.schema.types.PTimestamp;
 import org.joda.time.DateTime;
 
-import java.util.List;
-
 /**
  * Implementation of DayOfWeekFunction(Date/Timestamp)
  *
@@ -44,7 +44,7 @@ import java.util.List;
  */
 @BuiltInFunction(name=DayOfWeekFunction.NAME,
         args={@Argument(allowedTypes={PTimestamp.class})})
-public class DayOfWeekFunction extends ScalarFunction {
+public class DayOfWeekFunction extends DateScalarFunction {
     public static final String NAME = "DAYOFWEEK";
 
     public DayOfWeekFunction(){
@@ -68,7 +68,7 @@ public class DayOfWeekFunction extends ScalarFunction {
         if (ptr.getLength() == 0) {
             return true;
         }
-        long dateTime = arg.getDataType().getCodec().decodeLong(ptr, arg.getSortOrder());
+        long dateTime = inputCodec.decodeLong(ptr, arg.getSortOrder());
         DateTime jodaDT = new DateTime(dateTime);
         int day = jodaDT.getDayOfWeek();
         PDataType returnDataType = getDataType();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfYearFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfYearFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfYearFunction.java
index d4e92d6..8da51d7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfYearFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DayOfYearFunction.java
@@ -17,6 +17,8 @@
  */
 package org.apache.phoenix.expression.function;
 
+import java.util.List;
+
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
@@ -26,7 +28,6 @@ import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.types.PInteger;
 import org.apache.phoenix.schema.types.PTimestamp;
 import org.joda.time.DateTime;
-import java.util.List;
 
 /**
  * Implementation of DayOfYearFunction(Date/Timestamp)
@@ -36,7 +37,7 @@ import java.util.List;
  */
 @BuiltInFunction(name=DayOfYearFunction.NAME,
         args={@Argument(allowedTypes={PTimestamp.class})})
-public class DayOfYearFunction extends ScalarFunction {
+public class DayOfYearFunction extends DateScalarFunction {
     public static final String NAME = "DAYOFYEAR";
 
     public DayOfYearFunction() {
@@ -60,7 +61,7 @@ public class DayOfYearFunction extends ScalarFunction {
         if (ptr.getLength() == 0) {
             return true;
         }
-        long dateTime = arg.getDataType().getCodec().decodeLong(ptr, arg.getSortOrder());
+        long dateTime = inputCodec.decodeLong(ptr, arg.getSortOrder());
         DateTime jodaDT = new DateTime(dateTime);
         int day = jodaDT.getDayOfYear();
         PDataType returnDataType = getDataType();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/expression/function/HourFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/HourFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/HourFunction.java
index 0e9efd8..7b9c8c0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/HourFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/HourFunction.java
@@ -37,7 +37,7 @@ import org.apache.phoenix.schema.types.PTimestamp;
  */
 @BuiltInFunction(name=HourFunction.NAME, 
 args={@Argument(allowedTypes={PTimestamp.class})})
-public class HourFunction extends ScalarFunction {
+public class HourFunction extends DateScalarFunction {
     public static final String NAME = "HOUR";
 
     public HourFunction() {
@@ -56,7 +56,7 @@ public class HourFunction extends ScalarFunction {
         if ( ptr.getLength() == 0) {
             return true; //means null
         }
-        long dateTime = expression.getDataType().getCodec().decodeLong(ptr, expression.getSortOrder());
+        long dateTime = inputCodec.decodeLong(ptr, expression.getSortOrder());
         int hour = (int)(((dateTime/1000) % (24*3600))/3600);
         PDataType returnType = getDataType();
         byte[] byteValue = new byte[returnType.getByteSize()];

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinuteFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinuteFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinuteFunction.java
index fc721fc..6766e35 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinuteFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinuteFunction.java
@@ -37,7 +37,7 @@ import org.apache.phoenix.schema.types.PTimestamp;
  */
 @BuiltInFunction(name=MinuteFunction.NAME, 
 args={@Argument(allowedTypes={PTimestamp.class})})
-public class MinuteFunction extends ScalarFunction {
+public class MinuteFunction extends DateScalarFunction {
     public static final String NAME = "MINUTE";
 
     public MinuteFunction() {
@@ -56,7 +56,7 @@ public class MinuteFunction extends ScalarFunction {
         if ( ptr.getLength() == 0) {
             return true; //means null
         }
-        long dateTime = expression.getDataType().getCodec().decodeLong(ptr, expression.getSortOrder());
+        long dateTime = inputCodec.decodeLong(ptr, expression.getSortOrder());
         int minute = (int)(((dateTime/1000) % 3600)/60);
         PDataType returnType = getDataType();
         byte[] byteValue = new byte[returnType.getByteSize()];

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MonthFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MonthFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MonthFunction.java
index 5ad6c34..bd6ff3e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MonthFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MonthFunction.java
@@ -38,7 +38,7 @@ import org.joda.time.DateTime;
  */
 @BuiltInFunction(name=MonthFunction.NAME, 
 args={@Argument(allowedTypes={PTimestamp.class})})
-public class MonthFunction extends ScalarFunction {
+public class MonthFunction extends DateScalarFunction {
     public static final String NAME = "MONTH";
 
     public MonthFunction() {
@@ -57,7 +57,7 @@ public class MonthFunction extends ScalarFunction {
         if ( ptr.getLength() == 0) {
             return true; //means null
         }
-        long dateTime = expression.getDataType().getCodec().decodeLong(ptr, expression.getSortOrder());
+        long dateTime = inputCodec.decodeLong(ptr, expression.getSortOrder());
         DateTime dt = new DateTime(dateTime);
         int month = dt.getMonthOfYear();
         PDataType returnType = getDataType();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDateExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDateExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDateExpression.java
index c560b43..069bf60 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDateExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDateExpression.java
@@ -151,6 +151,9 @@ public class RoundDateExpression extends ScalarFunction {
     @Override
     public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
         if (children.get(0).evaluate(tuple, ptr)) {
+            if (ptr.getLength() == 0) {
+                return true; // child evaluated to null
+            }
             PDataType dataType = getDataType();
             long time = dataType.getCodec().decodeLong(ptr, children.get(0).getSortOrder());
             long value = roundTime(time);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundJodaDateExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundJodaDateExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundJodaDateExpression.java
index 0dba80b..356c85f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundJodaDateExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundJodaDateExpression.java
@@ -43,6 +43,9 @@ public abstract class RoundJodaDateExpression extends RoundDateExpression{
     @Override
     public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
         if (children.get(0).evaluate(tuple, ptr)) {
+            if (ptr.getLength() == 0) {
+                return true; // child evaluated to null
+            }
             PDataType dataType = getDataType();
             long time = dataType.getCodec().decodeLong(ptr, children.get(0).getSortOrder());
             DateTime dt = new DateTime(time,ISOChronology.getInstanceUTC());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SecondFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SecondFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SecondFunction.java
index 5f39786..02bc455 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SecondFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SecondFunction.java
@@ -37,7 +37,7 @@ import org.apache.phoenix.schema.types.PTimestamp;
  */
 @BuiltInFunction(name=SecondFunction.NAME, 
 args={@Argument(allowedTypes={PTimestamp.class})})
-public class SecondFunction extends ScalarFunction {
+public class SecondFunction extends DateScalarFunction {
     public static final String NAME = "SECOND";
 
     public SecondFunction() {
@@ -56,7 +56,7 @@ public class SecondFunction extends ScalarFunction {
         if ( ptr.getLength() == 0) {
             return true; //means null
         }
-        long dateTime = expression.getDataType().getCodec().decodeLong(ptr, expression.getSortOrder());
+        long dateTime = inputCodec.decodeLong(ptr, expression.getSortOrder());
         int sec = (int)((dateTime/1000) % 60);
         PDataType returnType = getDataType();
         byte[] byteValue = new byte[returnType.getByteSize()];

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
index 17f6847..1930d92 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
@@ -32,6 +32,7 @@ import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
 import org.apache.phoenix.parse.ToDateParseNode;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDataType.PDataCodec;
 import org.apache.phoenix.schema.types.PDate;
 import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.util.DateUtil;
@@ -53,6 +54,7 @@ import org.apache.phoenix.util.DateUtil;
 public class ToDateFunction extends ScalarFunction {
     public static final String NAME = "TO_DATE";
     private DateUtil.DateTimeParser dateParser;
+    private PDataCodec codec;
     protected String dateFormat;
     protected String timeZoneId;
 
@@ -80,6 +82,7 @@ public class ToDateFunction extends ScalarFunction {
         // server to evaluate using the local time zone. Instead, we want
         // to use the client local time zone.
         this.timeZoneId = this.dateParser.getTimeZone().getID();
+        this.codec = DateUtil.getCodecFor(getDataType());
     }
 
     @Override
@@ -110,15 +113,18 @@ public class ToDateFunction extends ScalarFunction {
     @Override
     public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
         Expression expression = getExpression();
-        if (!expression.evaluate(tuple, ptr) || ptr.getLength() == 0) {
+        if (!expression.evaluate(tuple, ptr)) {
             return false;
         }
+        if (ptr.getLength() == 0) {
+            return true;
+        }
         PDataType type = expression.getDataType();
         String dateStr = (String)type.toObject(ptr, expression.getSortOrder());
         long epochTime = dateParser.parseDateTime(dateStr);
         PDataType returnType = getDataType();
         byte[] byteValue = new byte[returnType.getByteSize()];
-        returnType.getCodec().encodeLong(epochTime, byteValue, 0);
+        codec.encodeLong(epochTime, byteValue, 0);
         ptr.set(byteValue);
         return true;
      }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/expression/function/WeekFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/WeekFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/WeekFunction.java
index 126aba8..3f6d772 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/WeekFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/WeekFunction.java
@@ -38,7 +38,7 @@ import org.joda.time.DateTime;
  */
 @BuiltInFunction(name=WeekFunction.NAME, 
 args={@Argument(allowedTypes={PTimestamp.class})})
-public class WeekFunction extends ScalarFunction {
+public class WeekFunction extends DateScalarFunction {
     public static final String NAME = "WEEK";
 
     public WeekFunction() {
@@ -57,7 +57,7 @@ public class WeekFunction extends ScalarFunction {
         if ( ptr.getLength() == 0) {
             return true; //means null
         }
-        long dateTime = expression.getDataType().getCodec().decodeLong(ptr, expression.getSortOrder());
+        long dateTime = inputCodec.decodeLong(ptr, expression.getSortOrder());
         DateTime dt = new DateTime(dateTime);
         int week = dt.getWeekOfWeekyear();
         PDataType returnType = getDataType();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/expression/function/YearFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/YearFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/YearFunction.java
index f1958e1..fcab8d2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/YearFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/YearFunction.java
@@ -37,7 +37,7 @@ import org.joda.time.DateTime;
  */
 @BuiltInFunction(name=YearFunction.NAME, 
 args={@Argument(allowedTypes={PTimestamp.class})})
-public class YearFunction extends ScalarFunction {
+public class YearFunction extends DateScalarFunction {
     public static final String NAME = "YEAR";
 
     public YearFunction() {
@@ -56,7 +56,7 @@ public class YearFunction extends ScalarFunction {
         if ( ptr.getLength() == 0) {
             return true; //means null
         }
-        long dateTime = expression.getDataType().getCodec().decodeLong(ptr, expression.getSortOrder());
+        long dateTime = inputCodec.decodeLong(ptr, expression.getSortOrder());
         DateTime dt = new DateTime(dateTime);
         int year = dt.getYear();
         PDataType returnType = getDataType();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java
index 9c6a94b..9bba3d3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java
@@ -361,11 +361,17 @@ public class PhoenixPreparedStatement extends PhoenixStatement implements Prepar
 
     @Override
     public void setDate(int parameterIndex, Date x) throws SQLException {
+        if (x != null) { // Since Date is mutable, make a copy
+            x = new Date(x.getTime());
+        }
         setParameter(parameterIndex, x);
     }
 
     @Override
     public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
+        if (x != null) { // Since Date is mutable, make a copy
+            x = new Date(x.getTime());
+        }
         cal.setTime(x);
         setParameter(parameterIndex, new Date(cal.getTimeInMillis()));
     }
@@ -475,23 +481,39 @@ public class PhoenixPreparedStatement extends PhoenixStatement implements Prepar
 
     @Override
     public void setTime(int parameterIndex, Time x) throws SQLException {
+        if (x != null) { // Since Time is mutable, make a copy
+            x = new Time(x.getTime());
+        }
         setParameter(parameterIndex, x);
     }
 
     @Override
     public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
+        if (x != null) { // Since Time is mutable, make a copy
+            x = new Time(x.getTime());
+        }
         cal.setTime(x);
         setParameter(parameterIndex, new Time(cal.getTimeInMillis()));
     }
 
+    private void setTimestampParameter(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
+        if (x != null) { // Since Timestamp is mutable, make a copy
+            int nanos = x.getNanos();
+            x = new Timestamp(x.getTime());
+            x.setNanos(nanos);
+        }
+        // TODO: deal with Calendar
+        setParameter(parameterIndex, x);
+    }
+    
     @Override
     public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
-        setParameter(parameterIndex, x);
+        setTimestampParameter(parameterIndex, x, null);
     }
 
     @Override
     public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
-        setParameter(parameterIndex,  x);
+        setTimestampParameter(parameterIndex, x, cal);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/schema/SortOrder.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/SortOrder.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/SortOrder.java
index 977ae7c..3bfc7ed 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/SortOrder.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/SortOrder.java
@@ -54,6 +54,11 @@ public enum SortOrder {
 		public CompareOp transform(CompareOp op) {
 			return op;
 		}
+
+        @Override
+        public byte normalize(byte b) {
+            return b;
+        }
 	},
 
 	DESC(1) {
@@ -70,6 +75,11 @@ public enum SortOrder {
 			}
 			throw new IllegalArgumentException("Add the missing case statement!");
 		}
+
+        @Override
+        public byte normalize(byte b) {
+            return SortOrder.invert(b);
+        }
 	};
 	
 	/**
@@ -136,4 +146,5 @@ public enum SortOrder {
 	}
 
 	public abstract CompareOp transform(CompareOp op);
+    public abstract byte normalize(byte b);
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java
index 0f0328a..5d611e9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java
@@ -89,8 +89,7 @@ public abstract class PDataType<T> implements DataType<T>, Comparable<PDataType<
     }
 
     public boolean isBytesComparableWith(PDataType otherType) {
-        return this == otherType || this.getClass() == PVarbinary.class || otherType == PVarbinary.INSTANCE
-                || this.getClass() == PBinary.class || otherType == PBinary.INSTANCE;
+        return equalsAny(this, otherType, PVarbinary.INSTANCE, PBinary.INSTANCE);
     }
 
     public int estimateByteSize(Object o) {
@@ -151,6 +150,18 @@ public abstract class PDataType<T> implements DataType<T>, Comparable<PDataType<
             // Special case as we may be comparing two arrays that have different separator characters due to PHOENIX-2067
             if (!this.isArrayType() || !rhsType.isArrayType() || 
                     PArrayDataType.isRowKeyOrderOptimized(this, lhsSortOrder, lhs, lhsOffset, lhsLength) == PArrayDataType.isRowKeyOrderOptimized(rhsType, rhsSortOrder, rhs, rhsOffset, rhsLength)) {
+                // Ignore trailing zero bytes if fixed byte length (for example TIMESTAMP compared to DATE)
+                if (lhsLength != rhsLength && this.isFixedWidth() && rhsType.isFixedWidth() && this.getByteSize() != null && rhsType.getByteSize() != null) {
+                    if (lhsLength > rhsLength) {
+                        int minOffset = lhsOffset + rhsLength;
+                        for (int i = lhsOffset + lhsLength - 1; i >= minOffset && lhsSortOrder.normalize(lhs[i]) == 0; i--,lhsLength--) {
+                        }
+                    } else {
+                        int minOffset = rhsOffset + lhsLength;
+                        for (int i = rhsOffset + rhsLength - 1; i >= minOffset && rhsSortOrder.normalize(rhs[i]) == 0; i--,rhsLength--) {
+                        }
+                    }
+                }
                 return compareTo(lhs, lhsOffset, lhsLength, lhsSortOrder, rhs, rhsOffset, rhsLength, rhsSortOrder);
             }
         }
@@ -196,8 +207,8 @@ public abstract class PDataType<T> implements DataType<T>, Comparable<PDataType<
             return Bytes.compareTo(lhsConverted, 0, lhsConverted.length, rhs, rhsOffset, rhsLength);
         }
         // convert to native and compare
-        if (this.isCoercibleTo(PLong.INSTANCE) && rhsType.isCoercibleTo(PLong.INSTANCE)) { // native long to long
-                                                                                           // comparison
+        if ( (this.isCoercibleTo(PLong.INSTANCE) || this.isCoercibleTo(PDate.INSTANCE)) && 
+             (rhsType.isCoercibleTo(PLong.INSTANCE) || rhsType.isCoercibleTo(PDate.INSTANCE)) ) {
             return Longs.compare(this.getCodec().decodeLong(lhs, lhsOffset, lhsSortOrder), rhsType.getCodec()
                     .decodeLong(rhs, rhsOffset, rhsSortOrder));
         } else if (isDoubleOrFloat(this) && isDoubleOrFloat(rhsType)) { // native double to double comparison

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDate.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDate.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDate.java
index c27d0fc..d70a658 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDate.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDate.java
@@ -30,122 +30,124 @@ import org.apache.phoenix.util.StringUtil;
 
 public class PDate extends PDataType<Date> {
 
-  public static final PDate INSTANCE = new PDate();
-
-  private PDate() {
-    super("DATE", Types.DATE, Date.class,
-        new DateCodec(), 11); // After TIMESTAMP and DATE to ensure toLiteral finds those first
-  }
-
-  @Override
-  public byte[] toBytes(Object object) {
-    byte[] bytes = new byte[getByteSize()];
-    toBytes(object, bytes, 0);
-    return bytes;
-  }
-
-  @Override
-  public int toBytes(Object object, byte[] bytes, int offset) {
-    if (object == null) {
-        getCodec().encodeLong(0l, bytes, offset);
+    public static final PDate INSTANCE = new PDate();
+
+    private PDate() {
+        super("DATE", Types.DATE, Date.class,
+                new DateCodec(), 11); // After TIMESTAMP and DATE to ensure toLiteral finds those first
+    }
+
+    @Override
+    public byte[] toBytes(Object object) {
+        byte[] bytes = new byte[getByteSize()];
+        toBytes(object, bytes, 0);
+        return bytes;
+    }
+
+    @Override
+    public int toBytes(Object object, byte[] bytes, int offset) {
+        if (object == null) {
+            getCodec().encodeLong(0l, bytes, offset);
+            return this.getByteSize();
+        }
+        getCodec().encodeLong(((java.util.Date) object).getTime(), bytes, offset);
         return this.getByteSize();
     }
-    getCodec().encodeLong(((java.util.Date) object).getTime(), bytes, offset);
-    return this.getByteSize();
-  }
-
-  @Override
-  public Object toObject(Object object, PDataType actualType) {
-    if (object == null) {
-      return null;
-    }
-    if (equalsAny(actualType, PTime.INSTANCE, PUnsignedTime.INSTANCE)) {
-      return new Date(((java.sql.Time) object).getTime());
-    } else if (equalsAny(actualType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE)) {
-      return new Date(((java.sql.Timestamp) object).getTime());
-    } else if (equalsAny(actualType, PDate.INSTANCE, PUnsignedDate.INSTANCE)) {
-      return object;
-    } else if (equalsAny(actualType, PLong.INSTANCE, PUnsignedLong.INSTANCE)) {
-      return new Date((Long) object);
-    } else if (actualType == PDecimal.INSTANCE) {
-      return new Date(((BigDecimal) object).longValueExact());
-    } else if (actualType == PVarchar.INSTANCE) {
-      return DateUtil.parseDate((String) object);
-    }
-    return throwConstraintViolationException(actualType, this);
-  }
-
-  @Override
-  public Date toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-    if (l == 0) {
-      return null;
-    }
-    if (equalsAny(actualType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE, PDate.INSTANCE,
-        PUnsignedDate.INSTANCE, PTime.INSTANCE, PUnsignedTime.INSTANCE, PLong.INSTANCE,
-        PUnsignedLong.INSTANCE)) {
-      return new Date(actualType.getCodec().decodeLong(b, o, sortOrder));
-    } else if (actualType == PDecimal.INSTANCE) {
-      BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder);
-      return new Date(bd.longValueExact());
-    }
-    throwConstraintViolationException(actualType, this);
-    return null;
-  }
-
-  @Override
-  public boolean isCastableTo(PDataType targetType) {
-    return super.isCastableTo(targetType) ||
-            equalsAny(targetType, PDecimal.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE);
-  }
-
-  @Override
-  public boolean isCoercibleTo(PDataType targetType) {
-    return equalsAny(targetType, PDate.INSTANCE, PTime.INSTANCE, PTimestamp.INSTANCE, PVarbinary.INSTANCE, PBinary.INSTANCE);
-  }
-
-  @Override
-  public boolean isCoercibleTo(PDataType targetType, Object value) {
-    if (value != null) {
-      if (equalsAny(targetType, PUnsignedTimestamp.INSTANCE, PUnsignedDate.INSTANCE,
-          PUnsignedTime.INSTANCE)) {
-        return ((java.util.Date) value).getTime() >= 0;
-      }
-    }
-    return super.isCoercibleTo(targetType, value);
-  }
-
-  @Override
-  public boolean isFixedWidth() {
-    return true;
-  }
-
-  @Override
-  public Integer getByteSize() {
-    return Bytes.SIZEOF_LONG;
-  }
-
-  @Override
-  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-    if (rhsType == PTimestamp.INSTANCE || rhsType == PUnsignedTimestamp.INSTANCE) {
-      return -rhsType.compareTo(rhs, lhs, PTime.INSTANCE);
-    }
-    return ((java.util.Date) lhs).compareTo((java.util.Date) rhs);
-  }
-
-  @Override
-  public Object toObject(String value) {
-    if (value == null || value.length() == 0) {
-      return null;
-    }
-    return DateUtil.parseDate(value);
-  }
-
-  @Override
-  public boolean isBytesComparableWith(PDataType otherType) {
-    return super.isBytesComparableWith(otherType) || otherType == PTime.INSTANCE;
-  }
-
-  @Override
+
+    @Override
+    public Object toObject(Object object, PDataType actualType) {
+        if (object == null) {
+            return null;
+        }
+        if (equalsAny(actualType, PTime.INSTANCE, PUnsignedTime.INSTANCE)) {
+            return new Date(((java.sql.Time) object).getTime());
+        } else if (equalsAny(actualType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE)) {
+            return new Date(((java.sql.Timestamp) object).getTime());
+        } else if (equalsAny(actualType, PDate.INSTANCE, PUnsignedDate.INSTANCE)) {
+            return object;
+        } else if (equalsAny(actualType, PLong.INSTANCE, PUnsignedLong.INSTANCE)) {
+            return new Date((Long) object);
+        } else if (actualType == PDecimal.INSTANCE) {
+            return new Date(((BigDecimal) object).longValueExact());
+        } else if (actualType == PVarchar.INSTANCE) {
+            return DateUtil.parseDate((String) object);
+        }
+        return throwConstraintViolationException(actualType, this);
+    }
+
+    @Override
+    public Date toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
+        if (l == 0) {
+            return null;
+        }
+        if (actualType.getCodec() != null ) {
+            return new Date(actualType.getCodec().decodeLong(b, o, sortOrder));
+        } else if (actualType == PTimestamp.INSTANCE) {
+            return new Date(PDate.INSTANCE.getCodec().decodeLong(b, o, sortOrder));
+        } else if (actualType == PUnsignedTimestamp.INSTANCE) {
+            return new Date(PUnsignedDate.INSTANCE.getCodec().decodeLong(b, o, sortOrder));
+        } else if (actualType == PDecimal.INSTANCE) {
+            BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder);
+            return new Date(bd.longValueExact());
+        }
+        throwConstraintViolationException(actualType, this);
+        return null;
+    }
+
+    @Override
+    public boolean isCastableTo(PDataType targetType) {
+        return super.isCastableTo(targetType) ||
+                equalsAny(targetType, PDecimal.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE);
+    }
+
+    @Override
+    public boolean isCoercibleTo(PDataType targetType) {
+        return equalsAny(targetType, PDate.INSTANCE, PTime.INSTANCE, PTimestamp.INSTANCE, PVarbinary.INSTANCE, PBinary.INSTANCE);
+    }
+
+    @Override
+    public boolean isCoercibleTo(PDataType targetType, Object value) {
+        if (value != null) {
+            if (equalsAny(targetType, PUnsignedTimestamp.INSTANCE, PUnsignedDate.INSTANCE,
+                    PUnsignedTime.INSTANCE)) {
+                return ((java.util.Date) value).getTime() >= 0;
+            }
+        }
+        return super.isCoercibleTo(targetType, value);
+    }
+
+    @Override
+    public boolean isFixedWidth() {
+        return true;
+    }
+
+    @Override
+    public Integer getByteSize() {
+        return Bytes.SIZEOF_LONG;
+    }
+
+    @Override
+    public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+        if (rhsType == PTimestamp.INSTANCE || rhsType == PUnsignedTimestamp.INSTANCE) {
+            return -rhsType.compareTo(rhs, lhs, PTime.INSTANCE);
+        }
+        return ((java.util.Date) lhs).compareTo((java.util.Date) rhs);
+    }
+
+    @Override
+    public Object toObject(String value) {
+        if (value == null || value.length() == 0) {
+            return null;
+        }
+        return DateUtil.parseDate(value);
+    }
+
+    @Override
+    public boolean isBytesComparableWith(PDataType otherType) {
+        return super.isBytesComparableWith(otherType) || otherType == PTime.INSTANCE || otherType == PTimestamp.INSTANCE || otherType == PLong.INSTANCE;
+    }
+
+    @Override
     public String toStringLiteral(Object o, Format formatter) {
         if (formatter == null) {
             // If default formatter has not been overridden,
@@ -156,40 +158,39 @@ public class PDate extends PDataType<Date> {
                 + StringUtil.escapeStringConstant(super.toStringLiteral(o, formatter)) + "'";
     }
 
-  @Override
-  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
-      Integer maxLength, Integer scale, SortOrder actualModifier, Integer desiredMaxLength, Integer desiredScale,
-      SortOrder expectedModifier) {
-    if (ptr.getLength() > 0 && actualType == PTimestamp.INSTANCE
-        && actualModifier == expectedModifier) {
-      ptr.set(ptr.get(), ptr.getOffset(), getByteSize());
-      return;
+    @Override
+    public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+            Integer maxLength, Integer scale, SortOrder actualModifier, Integer desiredMaxLength, Integer desiredScale,
+            SortOrder expectedModifier) {
+        // Decrease size of TIMESTAMP to size of DATE and continue coerce
+        if (ptr.getLength() > getByteSize()) {
+            ptr.set(ptr.get(), ptr.getOffset(), getByteSize());
+        }
+        super.coerceBytes(ptr, object, actualType, maxLength, scale, actualModifier, desiredMaxLength,
+                desiredScale, expectedModifier);
     }
-    super.coerceBytes(ptr, object, actualType, maxLength, scale, actualModifier, desiredMaxLength,
-        desiredScale, expectedModifier);
-  }
-
-  @Override
-  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-    return new Date((Long) PLong.INSTANCE.getSampleValue(maxLength, arrayLength));
-  }
-
-  static class DateCodec extends PLong.LongCodec {
 
     @Override
-    public int decodeInt(byte[] b, int o, SortOrder sortOrder) {
-      throw new UnsupportedOperationException();
+    public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+        return new Date((Long) PLong.INSTANCE.getSampleValue(maxLength, arrayLength));
     }
 
-    @Override
-    public PhoenixArrayFactory getPhoenixArrayFactory() {
-      return new PhoenixArrayFactory() {
+    static class DateCodec extends PLong.LongCodec {
+
+        @Override
+        public int decodeInt(byte[] b, int o, SortOrder sortOrder) {
+            throw new UnsupportedOperationException();
+        }
 
         @Override
-        public PhoenixArray newArray(PDataType type, Object[] elements) {
-          return new PhoenixArray(type, elements);
+        public PhoenixArrayFactory getPhoenixArrayFactory() {
+            return new PhoenixArrayFactory() {
+
+                @Override
+                public PhoenixArray newArray(PDataType type, Object[] elements) {
+                    return new PhoenixArray(type, elements);
+                }
+            };
         }
-      };
     }
-  }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimal.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimal.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimal.java
index ff6e186..17910de 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimal.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimal.java
@@ -28,6 +28,7 @@ import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.TypeMismatchException;
 import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.DateUtil;
 import org.apache.phoenix.util.NumberUtil;
 
 import com.google.common.base.Preconditions;
@@ -136,9 +137,8 @@ public class PDecimal extends PRealNumber<BigDecimal> {
       return BigDecimal.valueOf(actualType.getCodec().decodeFloat(b, o, sortOrder));
     } else if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) {
       return BigDecimal.valueOf(actualType.getCodec().decodeDouble(b, o, sortOrder));
-    } else if (equalsAny(actualType, PTimestamp.INSTANCE,
-        PUnsignedTimestamp.INSTANCE)) {
-      long millisPart = actualType.getCodec().decodeLong(b, o, sortOrder);
+    } else if (equalsAny(actualType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE)) {
+      long millisPart = DateUtil.getCodecFor(actualType).decodeLong(b, o, sortOrder);
       int nanoPart = PUnsignedInt.INSTANCE.getCodec().decodeInt(b, o + Bytes.SIZEOF_LONG, sortOrder);
       BigDecimal nanosPart = BigDecimal.valueOf(
           (nanoPart % QueryConstants.MILLIS_TO_NANOS_CONVERTOR)

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLong.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLong.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLong.java
index 82fd8d3..2d6ff27 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLong.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLong.java
@@ -20,6 +20,7 @@ package org.apache.phoenix.schema.types;
 import java.math.BigDecimal;
 import java.sql.Types;
 
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.schema.SortOrder;
 
@@ -29,304 +30,316 @@ import com.google.common.primitives.Longs;
 
 public class PLong extends PWholeNumber<Long> {
 
-  public static final PLong INSTANCE = new PLong();
+    public static final PLong INSTANCE = new PLong();
 
-  private PLong() {
-    super("BIGINT", Types.BIGINT, Long.class, new LongCodec(), 2);
-  }
-
-  @Override
-  public Integer getScale(Object o) {
-    return ZERO;
-  }
-
-  @Override
-  public byte[] toBytes(Object object) {
-    byte[] b = new byte[Bytes.SIZEOF_LONG];
-    toBytes(object, b, 0);
-    return b;
-  }
-
-  @Override
-  public int toBytes(Object object, byte[] b, int o) {
-    if (object == null) {
-      throw newIllegalDataException(this + " may not be null");
+    private PLong() {
+        super("BIGINT", Types.BIGINT, Long.class, new LongCodec(), 2);
     }
-    return this.getCodec().encodeLong(((Number) object).longValue(), b, o);
-  }
 
-  @Override
-  public Object toObject(Object object, PDataType actualType) {
-    if (object == null) {
-      return null;
-    }
-    long s;
-    if (equalsAny(actualType, PLong.INSTANCE, PUnsignedLong.INSTANCE)) {
-      return object;
-    } else if (equalsAny(actualType, PUnsignedInt.INSTANCE,
-        PInteger.INSTANCE)) {
-      s = (Integer) object;
-      return s;
-    } else if (equalsAny(actualType, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) {
-      s = (Byte) object;
-      return s;
-    } else if (equalsAny(actualType, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE)) {
-      s = (Short) object;
-      return s;
-    } else if (equalsAny(actualType, PFloat.INSTANCE, PUnsignedFloat.INSTANCE)) {
-      Float f = (Float) object;
-      if (f > Long.MAX_VALUE || f < Long.MIN_VALUE) {
-        throw newIllegalDataException(
-            actualType + " value " + f + " cannot be cast to Long without changing its value");
-      }
-      s = f.longValue();
-      return s;
-    } else if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) {
-      Double de = (Double) object;
-      if (de > Long.MAX_VALUE || de < Long.MIN_VALUE) {
-        throw newIllegalDataException(
-            actualType + " value " + de + " cannot be cast to Long without changing its value");
-      }
-      s = de.longValue();
-      return s;
-    } else if (actualType == PDecimal.INSTANCE) {
-      BigDecimal d = (BigDecimal) object;
-      return d.longValueExact();
-    } else if (equalsAny(actualType, PDate.INSTANCE, PUnsignedDate.INSTANCE, PTime.INSTANCE,
-        PUnsignedTime.INSTANCE)) {
-      java.util.Date date = (java.util.Date) object;
-      return date.getTime();
-    }
-    return throwConstraintViolationException(actualType, this);
-  }
-
-  @Override
-  public Long toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
-      Integer maxLength, Integer scale) {
-    if (l == 0) {
-      return null;
-    }
-    if (equalsAny(actualType, PLong.INSTANCE, PUnsignedLong.INSTANCE,
-        PInteger.INSTANCE, PUnsignedInt.INSTANCE, PSmallint.INSTANCE,
-        PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE, PFloat.INSTANCE,
-        PUnsignedFloat.INSTANCE, PDouble.INSTANCE, PUnsignedDouble.INSTANCE, PDate.INSTANCE,
-        PUnsignedDate.INSTANCE, PTime.INSTANCE, PUnsignedTime.INSTANCE)) {
-      return actualType.getCodec().decodeLong(b, o, sortOrder);
-    } else if (actualType == PDecimal.INSTANCE) {
-      BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder);
-      return bd.longValueExact();
-    }
-    throwConstraintViolationException(actualType, this);
-    return null;
-  }
-
-  @Override
-  public boolean isCoercibleTo(PDataType targetType) {
-    // In general, don't allow conversion of LONG to INTEGER. There are times when
-    // we check isComparableTo for a more relaxed check and then throw a runtime
-    // exception if we overflow
-    return equalsAny(targetType, this, PDecimal.INSTANCE, PVarbinary.INSTANCE, PBinary.INSTANCE, PDouble.INSTANCE);
-  }
-
-  @Override
-  public boolean isComparableTo(PDataType targetType) {
-    return PDecimal.INSTANCE.isComparableTo(targetType);
-  }
-
-  @Override
-  public boolean isCoercibleTo(PDataType targetType, Object value) {
-    if (value != null) {
-      long l;
-      if (equalsAny(targetType, PUnsignedDouble.INSTANCE, PUnsignedFloat.INSTANCE,
-          PUnsignedLong.INSTANCE)) {
-        l = (Long) value;
-        return l >= 0;
-      } else if (targetType.equals(PUnsignedInt.INSTANCE)) {
-        l = (Long) value;
-        return (l >= 0 && l <= Integer.MAX_VALUE);
-      } else if (targetType.equals(PInteger.INSTANCE)) {
-        l = (Long) value;
-        return (l >= Integer.MIN_VALUE && l <= Integer.MAX_VALUE);
-      } else if (targetType.equals(PUnsignedSmallint.INSTANCE)) {
-        l = (Long) value;
-        return (l >= 0 && l <= Short.MAX_VALUE);
-      } else if (targetType.equals(PSmallint.INSTANCE)) {
-        l = (Long) value;
-        return (l >= Short.MIN_VALUE && l <= Short.MAX_VALUE);
-      } else if (targetType.equals(PTinyint.INSTANCE)) {
-        l = (Long) value;
-        return (l >= Byte.MIN_VALUE && l <= Byte.MAX_VALUE);
-      } else if (targetType.equals(PUnsignedTinyint.INSTANCE)) {
-        l = (Long) value;
-        return (l >= 0 && l <= Byte.MAX_VALUE);
-      }
-    }
-    return super.isCoercibleTo(targetType, value);
-  }
-
-  @Override
-  public boolean isCastableTo(PDataType targetType) {
-    return super.isCastableTo(targetType) || targetType.isCoercibleTo(PTimestamp.INSTANCE);
-  }
-
-  @Override
-  public boolean isFixedWidth() {
-    return true;
-  }
-
-  @Override
-  public Integer getByteSize() {
-    return Bytes.SIZEOF_LONG;
-  }
-
-  @Override
-  public Integer getMaxLength(Object o) {
-    return LONG_PRECISION;
-  }
-
-  @Override
-  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-    if (rhsType == PDecimal.INSTANCE) {
-      return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).longValue()));
-    } else if (equalsAny(rhsType, PDouble.INSTANCE, PFloat.INSTANCE, PUnsignedDouble.INSTANCE, PUnsignedFloat.INSTANCE)) {
-      return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue());
+    @Override
+    public Integer getScale(Object o) {
+        return ZERO;
     }
-    return Longs.compare(((Number) lhs).longValue(), ((Number) rhs).longValue());
-  }
 
-  @Override
-  public Object toObject(String value) {
-    if (value == null || value.length() == 0) {
-      return null;
-    }
-    try {
-      return Long.parseLong(value);
-    } catch (NumberFormatException e) {
-      throw newIllegalDataException(e);
+    @Override
+    public byte[] toBytes(Object object) {
+        byte[] b = new byte[Bytes.SIZEOF_LONG];
+        toBytes(object, b, 0);
+        return b;
     }
-  }
 
-  @Override
-  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-    return RANDOM.get().nextLong();
-  }
+    @Override
+    public int toBytes(Object object, byte[] b, int o) {
+        if (object == null) {
+            throw newIllegalDataException(this + " may not be null");
+        }
+        return this.getCodec().encodeLong(((Number) object).longValue(), b, o);
+    }
 
-  static class LongCodec extends BaseCodec {
+    @Override
+    public Object toObject(Object object, PDataType actualType) {
+        if (object == null) {
+            return null;
+        }
+        long s;
+        if (equalsAny(actualType, PLong.INSTANCE, PUnsignedLong.INSTANCE)) {
+            return object;
+        } else if (equalsAny(actualType, PUnsignedInt.INSTANCE,
+                PInteger.INSTANCE)) {
+            s = (Integer) object;
+            return s;
+        } else if (equalsAny(actualType, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) {
+            s = (Byte) object;
+            return s;
+        } else if (equalsAny(actualType, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE)) {
+            s = (Short) object;
+            return s;
+        } else if (equalsAny(actualType, PFloat.INSTANCE, PUnsignedFloat.INSTANCE)) {
+            Float f = (Float) object;
+            if (f > Long.MAX_VALUE || f < Long.MIN_VALUE) {
+                throw newIllegalDataException(
+                        actualType + " value " + f + " cannot be cast to Long without changing its value");
+            }
+            s = f.longValue();
+            return s;
+        } else if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) {
+            Double de = (Double) object;
+            if (de > Long.MAX_VALUE || de < Long.MIN_VALUE) {
+                throw newIllegalDataException(
+                        actualType + " value " + de + " cannot be cast to Long without changing its value");
+            }
+            s = de.longValue();
+            return s;
+        } else if (actualType == PDecimal.INSTANCE) {
+            BigDecimal d = (BigDecimal) object;
+            return d.longValueExact();
+        } else if (equalsAny(actualType, PDate.INSTANCE, PUnsignedDate.INSTANCE, PTime.INSTANCE,
+                PUnsignedTime.INSTANCE)) {
+            java.util.Date date = (java.util.Date) object;
+            return date.getTime();
+        }
+        return throwConstraintViolationException(actualType, this);
+    }
 
     @Override
-    public float decodeFloat(byte[] b, int o, SortOrder sortOrder) {
-      return decodeLong(b, o, sortOrder);
+    public Long toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
+            Integer maxLength, Integer scale) {
+        if (l == 0) {
+            return null;
+        }
+        if (equalsAny(actualType, PLong.INSTANCE, PUnsignedLong.INSTANCE,
+                PInteger.INSTANCE, PUnsignedInt.INSTANCE, PSmallint.INSTANCE,
+                PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE, PFloat.INSTANCE,
+                PUnsignedFloat.INSTANCE, PDouble.INSTANCE, PUnsignedDouble.INSTANCE, PDate.INSTANCE,
+                PUnsignedDate.INSTANCE, PTime.INSTANCE, PUnsignedTime.INSTANCE)) {
+            return actualType.getCodec().decodeLong(b, o, sortOrder);
+        } else if (actualType == PDecimal.INSTANCE) {
+            BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder);
+            return bd.longValueExact();
+        }
+        throwConstraintViolationException(actualType, this);
+        return null;
     }
 
     @Override
-    public double decodeDouble(byte[] b, int o, SortOrder sortOrder) {
-      return decodeLong(b, o, sortOrder);
+    public boolean isCoercibleTo(PDataType targetType) {
+        // In general, don't allow conversion of LONG to INTEGER. There are times when
+        // we check isComparableTo for a more relaxed check and then throw a runtime
+        // exception if we overflow
+        return equalsAny(targetType, this, PDecimal.INSTANCE, PVarbinary.INSTANCE, PBinary.INSTANCE, PDouble.INSTANCE);
     }
 
     @Override
-    public long decodeLong(byte[] bytes, int o, SortOrder sortOrder) {
-      Preconditions.checkNotNull(sortOrder);
-      checkForSufficientLength(bytes, o, Bytes.SIZEOF_LONG);
-      long v;
-      byte b = bytes[o];
-      if (sortOrder == SortOrder.ASC) {
-        v = b ^ 0x80; // Flip sign bit back
-        for (int i = 1; i < Bytes.SIZEOF_LONG; i++) {
-          b = bytes[o + i];
-          v = (v << 8) + (b & 0xff);
+    public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+            Integer maxLength, Integer scale, SortOrder actualModifier, Integer desiredMaxLength, Integer desiredScale,
+            SortOrder expectedModifier) {
+        // Decrease size of TIMESTAMP to size of LONG and continue coerce
+        if (ptr.getLength() > getByteSize()) {
+            ptr.set(ptr.get(), ptr.getOffset(), getByteSize());
         }
-      } else {
-        b = (byte) (b ^ 0xff);
-        v = b ^ 0x80; // Flip sign bit back
-        for (int i = 1; i < Bytes.SIZEOF_LONG; i++) {
-          b = bytes[o + i];
-          b ^= 0xff;
-          v = (v << 8) + (b & 0xff);
-        }
-      }
-      return v;
+        super.coerceBytes(ptr, object, actualType, maxLength, scale, actualModifier, desiredMaxLength,
+                desiredScale, expectedModifier);
     }
 
     @Override
-    public int decodeInt(byte[] b, int o, SortOrder sortOrder) {
-      long v = decodeLong(b, o, sortOrder);
-      if (v < Integer.MIN_VALUE || v > Integer.MAX_VALUE) {
-        throw newIllegalDataException(
-            "Value " + v + " cannot be cast to Integer without changing its value");
-      }
-      return (int) v;
+    public boolean isComparableTo(PDataType targetType) {
+        return PDecimal.INSTANCE.isComparableTo(targetType);
     }
 
     @Override
-    public int encodeFloat(float v, byte[] b, int o) {
-      if (v < Long.MIN_VALUE || v > Long.MAX_VALUE) {
-        throw newIllegalDataException(
-            "Value " + v + " cannot be encoded as an Long without changing its value");
-      }
-      return encodeLong((long) v, b, o);
+    public boolean isCoercibleTo(PDataType targetType, Object value) {
+        if (value != null) {
+            long l;
+            if (equalsAny(targetType, PUnsignedDouble.INSTANCE, PUnsignedFloat.INSTANCE,
+                    PUnsignedLong.INSTANCE)) {
+                l = (Long) value;
+                return l >= 0;
+            } else if (targetType.equals(PUnsignedInt.INSTANCE)) {
+                l = (Long) value;
+                return (l >= 0 && l <= Integer.MAX_VALUE);
+            } else if (targetType.equals(PInteger.INSTANCE)) {
+                l = (Long) value;
+                return (l >= Integer.MIN_VALUE && l <= Integer.MAX_VALUE);
+            } else if (targetType.equals(PUnsignedSmallint.INSTANCE)) {
+                l = (Long) value;
+                return (l >= 0 && l <= Short.MAX_VALUE);
+            } else if (targetType.equals(PSmallint.INSTANCE)) {
+                l = (Long) value;
+                return (l >= Short.MIN_VALUE && l <= Short.MAX_VALUE);
+            } else if (targetType.equals(PTinyint.INSTANCE)) {
+                l = (Long) value;
+                return (l >= Byte.MIN_VALUE && l <= Byte.MAX_VALUE);
+            } else if (targetType.equals(PUnsignedTinyint.INSTANCE)) {
+                l = (Long) value;
+                return (l >= 0 && l <= Byte.MAX_VALUE);
+            }
+        }
+        return super.isCoercibleTo(targetType, value);
     }
 
     @Override
-    public int encodeDouble(double v, byte[] b, int o) {
-      if (v < Long.MIN_VALUE || v > Long.MAX_VALUE) {
-        throw newIllegalDataException(
-            "Value " + v + " cannot be encoded as an Long without changing its value");
-      }
-      return encodeLong((long) v, b, o);
+    public boolean isCastableTo(PDataType targetType) {
+        return super.isCastableTo(targetType) || targetType.isCoercibleTo(PTimestamp.INSTANCE);
     }
 
     @Override
-    public int encodeLong(long v, byte[] b, int o) {
-      checkForSufficientLength(b, o, Bytes.SIZEOF_LONG);
-      b[o + 0] = (byte) ((v >> 56) ^ 0x80); // Flip sign bit so that INTEGER is binary comparable
-      b[o + 1] = (byte) (v >> 48);
-      b[o + 2] = (byte) (v >> 40);
-      b[o + 3] = (byte) (v >> 32);
-      b[o + 4] = (byte) (v >> 24);
-      b[o + 5] = (byte) (v >> 16);
-      b[o + 6] = (byte) (v >> 8);
-      b[o + 7] = (byte) v;
-      return Bytes.SIZEOF_LONG;
+    public boolean isFixedWidth() {
+        return true;
     }
 
     @Override
-    public byte decodeByte(byte[] b, int o, SortOrder sortOrder) {
-      long v = decodeLong(b, o, sortOrder);
-      if (v < Byte.MIN_VALUE || v > Byte.MAX_VALUE) {
-        throw newIllegalDataException(
-            "Value " + v + " cannot be cast to Byte without changing its value");
-      }
-      return (byte) v;
+    public Integer getByteSize() {
+        return Bytes.SIZEOF_LONG;
     }
 
     @Override
-    public short decodeShort(byte[] b, int o, SortOrder sortOrder) {
-      long v = decodeLong(b, o, sortOrder);
-      if (v < Short.MIN_VALUE || v > Short.MAX_VALUE) {
-        throw newIllegalDataException(
-            "Value " + v + " cannot be cast to Short without changing its value");
-      }
-      return (short) v;
+    public Integer getMaxLength(Object o) {
+        return LONG_PRECISION;
     }
 
     @Override
-    public int encodeByte(byte v, byte[] b, int o) {
-      return encodeLong(v, b, o);
+    public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+        if (rhsType == PDecimal.INSTANCE) {
+            return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).longValue()));
+        } else if (equalsAny(rhsType, PDouble.INSTANCE, PFloat.INSTANCE, PUnsignedDouble.INSTANCE, PUnsignedFloat.INSTANCE)) {
+            return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue());
+        }
+        return Longs.compare(((Number) lhs).longValue(), ((Number) rhs).longValue());
     }
 
     @Override
-    public int encodeShort(short v, byte[] b, int o) {
-      return encodeLong(v, b, o);
+    public Object toObject(String value) {
+        if (value == null || value.length() == 0) {
+            return null;
+        }
+        try {
+            return Long.parseLong(value);
+        } catch (NumberFormatException e) {
+            throw newIllegalDataException(e);
+        }
     }
 
     @Override
-    public PhoenixArrayFactory getPhoenixArrayFactory() {
-      return new PhoenixArrayFactory() {
+    public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+        return RANDOM.get().nextLong();
+    }
+
+    static class LongCodec extends BaseCodec {
+
+        @Override
+        public float decodeFloat(byte[] b, int o, SortOrder sortOrder) {
+            return decodeLong(b, o, sortOrder);
+        }
+
+        @Override
+        public double decodeDouble(byte[] b, int o, SortOrder sortOrder) {
+            return decodeLong(b, o, sortOrder);
+        }
+
+        @Override
+        public long decodeLong(byte[] bytes, int o, SortOrder sortOrder) {
+            Preconditions.checkNotNull(sortOrder);
+            checkForSufficientLength(bytes, o, Bytes.SIZEOF_LONG);
+            long v;
+            byte b = bytes[o];
+            if (sortOrder == SortOrder.ASC) {
+                v = b ^ 0x80; // Flip sign bit back
+                for (int i = 1; i < Bytes.SIZEOF_LONG; i++) {
+                    b = bytes[o + i];
+                    v = (v << 8) + (b & 0xff);
+                }
+            } else {
+                b = (byte) (b ^ 0xff);
+                v = b ^ 0x80; // Flip sign bit back
+                for (int i = 1; i < Bytes.SIZEOF_LONG; i++) {
+                    b = bytes[o + i];
+                    b ^= 0xff;
+                    v = (v << 8) + (b & 0xff);
+                }
+            }
+            return v;
+        }
+
+        @Override
+        public int decodeInt(byte[] b, int o, SortOrder sortOrder) {
+            long v = decodeLong(b, o, sortOrder);
+            if (v < Integer.MIN_VALUE || v > Integer.MAX_VALUE) {
+                throw newIllegalDataException(
+                        "Value " + v + " cannot be cast to Integer without changing its value");
+            }
+            return (int) v;
+        }
+
+        @Override
+        public int encodeFloat(float v, byte[] b, int o) {
+            if (v < Long.MIN_VALUE || v > Long.MAX_VALUE) {
+                throw newIllegalDataException(
+                        "Value " + v + " cannot be encoded as an Long without changing its value");
+            }
+            return encodeLong((long) v, b, o);
+        }
+
+        @Override
+        public int encodeDouble(double v, byte[] b, int o) {
+            if (v < Long.MIN_VALUE || v > Long.MAX_VALUE) {
+                throw newIllegalDataException(
+                        "Value " + v + " cannot be encoded as an Long without changing its value");
+            }
+            return encodeLong((long) v, b, o);
+        }
+
+        @Override
+        public int encodeLong(long v, byte[] b, int o) {
+            checkForSufficientLength(b, o, Bytes.SIZEOF_LONG);
+            b[o + 0] = (byte) ((v >> 56) ^ 0x80); // Flip sign bit so that INTEGER is binary comparable
+            b[o + 1] = (byte) (v >> 48);
+            b[o + 2] = (byte) (v >> 40);
+            b[o + 3] = (byte) (v >> 32);
+            b[o + 4] = (byte) (v >> 24);
+            b[o + 5] = (byte) (v >> 16);
+            b[o + 6] = (byte) (v >> 8);
+            b[o + 7] = (byte) v;
+            return Bytes.SIZEOF_LONG;
+        }
+
+        @Override
+        public byte decodeByte(byte[] b, int o, SortOrder sortOrder) {
+            long v = decodeLong(b, o, sortOrder);
+            if (v < Byte.MIN_VALUE || v > Byte.MAX_VALUE) {
+                throw newIllegalDataException(
+                        "Value " + v + " cannot be cast to Byte without changing its value");
+            }
+            return (byte) v;
+        }
+
+        @Override
+        public short decodeShort(byte[] b, int o, SortOrder sortOrder) {
+            long v = decodeLong(b, o, sortOrder);
+            if (v < Short.MIN_VALUE || v > Short.MAX_VALUE) {
+                throw newIllegalDataException(
+                        "Value " + v + " cannot be cast to Short without changing its value");
+            }
+            return (short) v;
+        }
+
+        @Override
+        public int encodeByte(byte v, byte[] b, int o) {
+            return encodeLong(v, b, o);
+        }
+
+        @Override
+        public int encodeShort(short v, byte[] b, int o) {
+            return encodeLong(v, b, o);
+        }
+
         @Override
-        public PhoenixArray newArray(PDataType type, Object[] elements) {
-          return new PhoenixArray.PrimitiveLongPhoenixArray(type, elements);
+        public PhoenixArrayFactory getPhoenixArrayFactory() {
+            return new PhoenixArrayFactory() {
+                @Override
+                public PhoenixArray newArray(PDataType type, Object[] elements) {
+                    return new PhoenixArray.PrimitiveLongPhoenixArray(type, elements);
+                }
+            };
         }
-      };
     }
-  }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTime.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTime.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTime.java
index 0cfb0e8..03afae9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTime.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTime.java
@@ -123,7 +123,7 @@ public class PTime extends PDataType<Time> {
 
   @Override
   public boolean isBytesComparableWith(PDataType otherType) {
-    return super.isBytesComparableWith(otherType) || otherType.equals(PDate.INSTANCE);
+    return super.isBytesComparableWith(otherType) || otherType == PDate.INSTANCE || otherType == PTimestamp.INSTANCE || otherType == PLong.INSTANCE;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestamp.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestamp.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestamp.java
index cdfb533..c35a039 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestamp.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestamp.java
@@ -31,13 +31,19 @@ import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.DateUtil;
 
+import com.google.common.base.Preconditions;
+
 public class PTimestamp extends PDataType<Timestamp> {
     public static final int MAX_NANOS_VALUE_EXCLUSIVE = 1000000;
     public static final PTimestamp INSTANCE = new PTimestamp();
 
+    protected PTimestamp(String sqlTypeName, int sqlType, int ordinal) {
+        super(sqlTypeName, sqlType, java.sql.Timestamp.class, null, ordinal);
+    }
+
     private PTimestamp() {
         super("TIMESTAMP", Types.TIMESTAMP, java.sql.Timestamp.class,
-                new PDate.DateCodec(), 9);
+                null, 9);
     }
 
     @Override
@@ -48,6 +54,28 @@ public class PTimestamp extends PDataType<Timestamp> {
     }
 
     @Override
+    public void coerceBytes(ImmutableBytesWritable ptr, Object o, PDataType actualType, Integer actualMaxLength,
+            Integer actualScale, SortOrder actualModifier, Integer desiredMaxLength, Integer desiredScale,
+            SortOrder expectedModifier) {
+        Preconditions.checkNotNull(actualModifier);
+        Preconditions.checkNotNull(expectedModifier);
+        if (ptr.getLength() == 0) { return; }
+        if (this.isBytesComparableWith(actualType)) { // No coerce necessary
+            if (actualModifier != expectedModifier || (actualType.isFixedWidth() && actualType.getByteSize() < this.getByteSize())) {
+                byte[] b = new byte[this.getByteSize()];
+                System.arraycopy(ptr.get(), ptr.getOffset(), b, 0, actualType.getByteSize());
+                ptr.set(b);
+                
+                if (actualModifier != expectedModifier) {
+                    SortOrder.invert(b, 0, b, 0, b.length);
+                }
+            }
+            return;
+        }
+        super.coerceBytes(ptr, o, actualType, actualMaxLength, actualScale, actualModifier, desiredMaxLength, desiredScale, expectedModifier);
+    }
+
+    @Override
     public int toBytes(Object object, byte[] bytes, int offset) {
         if (object == null) {
             // Create the byte[] of size MAX_TIMESTAMP_BYTES
@@ -61,7 +89,7 @@ public class PTimestamp extends PDataType<Timestamp> {
         java.sql.Timestamp value = (java.sql.Timestamp) object;
         // For Timestamp, the getTime() method includes milliseconds that may
         // be stored in the nanos part as well.
-        PDate.INSTANCE.getCodec().encodeLong(value.getTime(), bytes, offset);
+        DateUtil.getCodecFor(this).encodeLong(value.getTime(), bytes, offset);
 
         /*
          * By not getting the stuff that got spilled over from the millis part,
@@ -73,6 +101,11 @@ public class PTimestamp extends PDataType<Timestamp> {
     }
 
     @Override
+    public boolean isBytesComparableWith(PDataType otherType) {
+      return super.isBytesComparableWith(otherType) || otherType == PTime.INSTANCE || otherType == PDate.INSTANCE || otherType == PLong.INSTANCE;
+    }
+
+    @Override
     public Object toObject(Object object, PDataType actualType) {
         if (object == null) {
             return null;
@@ -106,8 +139,7 @@ public class PTimestamp extends PDataType<Timestamp> {
         java.sql.Timestamp v;
         if (equalsAny(actualType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE)) {
             long millisDeserialized =
-                    (actualType == PTimestamp.INSTANCE ? PDate.INSTANCE : PUnsignedDate.INSTANCE).getCodec()
-                    .decodeLong(b, o, sortOrder);
+                    DateUtil.getCodecFor(actualType).decodeLong(b, o, sortOrder);
             v = new java.sql.Timestamp(millisDeserialized);
             int nanosDeserialized =
                     PUnsignedInt.INSTANCE.getCodec().decodeInt(b, o + Bytes.SIZEOF_LONG, sortOrder);
@@ -205,7 +237,7 @@ public class PTimestamp extends PDataType<Timestamp> {
 
     @Override
     public long getMillis(ImmutableBytesWritable ptr, SortOrder sortOrder) {
-        long millis = PLong.INSTANCE.getCodec().decodeLong(ptr.get(), ptr.getOffset(), sortOrder);
+        long millis = DateUtil.getCodecFor(this).decodeLong(ptr.get(), ptr.getOffset(), sortOrder);
         return millis;
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/210445de/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDate.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDate.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDate.java
index a6b1bc3..863b0d1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDate.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDate.java
@@ -27,138 +27,137 @@ import org.apache.phoenix.util.DateUtil;
 
 public class PUnsignedDate extends PDataType<Date> {
 
-  public static final PUnsignedDate INSTANCE = new PUnsignedDate();
-
-  private PUnsignedDate() {
-    super("UNSIGNED_DATE", 19, Date.class,
-        new UnsignedDateCodec(), 14); // After TIMESTAMP and DATE to ensure toLiteral finds those first
-  }
-
-  @Override
-  public byte[] toBytes(Object object) {
-    if (object == null) {
-      throw newIllegalDataException(this + " may not be null");
-    }
-    byte[] bytes = new byte[getByteSize()];
-    toBytes(object, bytes, 0);
-    return bytes;
-  }
-
-  @Override
-  public int toBytes(Object object, byte[] bytes, int offset) {
-    if (object == null) {
-      throw newIllegalDataException(this + " may not be null");
-    }
-    getCodec().encodeLong(((java.util.Date) object).getTime(), bytes, offset);
-    return this.getByteSize();
-  }
-
-  @Override
-  public Object toObject(Object object, PDataType actualType) {
-    Date d = (Date) PDate.INSTANCE.toObject(object, actualType);
-    throwIfNonNegativeDate(d);
-    return d;
-  }
-
-  @Override
-  public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-    Date d = (Date) PDate.INSTANCE.toObject(b, o, l, actualType, sortOrder);
-    throwIfNonNegativeDate(d);
-    return d;
-  }
-
-  @Override
-  public boolean isCastableTo(PDataType targetType) {
-    return PDate.INSTANCE.isCastableTo(targetType);
-  }
-
-  @Override
-  public boolean isCoercibleTo(PDataType targetType) {
-    return equalsAny(targetType, this, PUnsignedTime.INSTANCE, PUnsignedTimestamp.INSTANCE)
-        || PDate.INSTANCE.isCoercibleTo(targetType);
-  }
-
-  @Override
-  public boolean isCoercibleTo(PDataType targetType, Object value) {
-    return super.isCoercibleTo(targetType, value) || PDate.INSTANCE.isCoercibleTo(targetType, value);
-  }
-
-  @Override
-  public boolean isFixedWidth() {
-    return true;
-  }
-
-  @Override
-  public Integer getByteSize() {
-    return PDate.INSTANCE.getByteSize();
-  }
-
-  @Override
-  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-    return PDate.INSTANCE.compareTo(lhs, rhs, rhsType);
-  }
-
-  @Override
-  public Object toObject(String value) {
-    return PDate.INSTANCE.toObject(value);
-  }
-
-  @Override
-  public boolean isBytesComparableWith(PDataType otherType) {
-    return super.isBytesComparableWith(otherType) || otherType.equals(PUnsignedTime.INSTANCE);
-  }
-
-  @Override
-  public String toStringLiteral(Object o, Format formatter) {
-    // Can't delegate, as the super.toStringLiteral calls this.toBytes
-    if (formatter == null || formatter == DateUtil.DEFAULT_DATE_FORMATTER) {
-      // If default formatter has not been overridden,
-      // use one that displays milliseconds.
-      formatter = DateUtil.DEFAULT_MS_DATE_FORMATTER;
-    }
-    return "'" + super.toStringLiteral(o, formatter) + "'";
-  }
-
-  @Override
-  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
-      Integer maxLength, Integer scale, SortOrder actualModifier,
-      Integer desiredMaxLength, Integer desiredScale,
-      SortOrder expectedModifier) {
-    if (ptr.getLength() > 0 && actualType == PUnsignedTimestamp.INSTANCE
-        && actualModifier == expectedModifier) {
-      ptr.set(ptr.get(), ptr.getOffset(), getByteSize());
-      return;
-    }
-    super.coerceBytes(ptr, object, actualType, maxLength, scale, actualModifier, desiredMaxLength,
-        desiredScale, expectedModifier);
-  }
-
-  @Override
-  public int getResultSetSqlType() {
-    return Types.DATE;
-  }
-
-  @Override
-  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-    return new Date((Long) PUnsignedLong.INSTANCE.getSampleValue(maxLength, arrayLength));
-  }
-
-  static class UnsignedDateCodec extends PUnsignedLong.UnsignedLongCodec {
-
-    @Override
-    public int decodeInt(byte[] b, int o, SortOrder sortOrder) {
-      throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public PhoenixArrayFactory getPhoenixArrayFactory() {
-      return new PhoenixArrayFactory() {
+    public static final PUnsignedDate INSTANCE = new PUnsignedDate();
+
+    private PUnsignedDate() {
+        super("UNSIGNED_DATE", 19, Date.class,
+                new UnsignedDateCodec(), 14); // After TIMESTAMP and DATE to ensure toLiteral finds those first
+    }
+
+    @Override
+    public byte[] toBytes(Object object) {
+        if (object == null) {
+            throw newIllegalDataException(this + " may not be null");
+        }
+        byte[] bytes = new byte[getByteSize()];
+        toBytes(object, bytes, 0);
+        return bytes;
+    }
+
+    @Override
+    public int toBytes(Object object, byte[] bytes, int offset) {
+        if (object == null) {
+            throw newIllegalDataException(this + " may not be null");
+        }
+        getCodec().encodeLong(((java.util.Date) object).getTime(), bytes, offset);
+        return this.getByteSize();
+    }
+
+    @Override
+    public Object toObject(Object object, PDataType actualType) {
+        Date d = (Date) PDate.INSTANCE.toObject(object, actualType);
+        throwIfNonNegativeDate(d);
+        return d;
+    }
+
+    @Override
+    public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
+        Date d = (Date) PDate.INSTANCE.toObject(b, o, l, actualType, sortOrder);
+        throwIfNonNegativeDate(d);
+        return d;
+    }
+
+    @Override
+    public boolean isCastableTo(PDataType targetType) {
+        return PDate.INSTANCE.isCastableTo(targetType);
+    }
+
+    @Override
+    public boolean isCoercibleTo(PDataType targetType) {
+        return equalsAny(targetType, this, PUnsignedTime.INSTANCE, PUnsignedTimestamp.INSTANCE)
+                || PDate.INSTANCE.isCoercibleTo(targetType);
+    }
+
+    @Override
+    public boolean isCoercibleTo(PDataType targetType, Object value) {
+        return super.isCoercibleTo(targetType, value) || PDate.INSTANCE.isCoercibleTo(targetType, value);
+    }
+
+    @Override
+    public boolean isFixedWidth() {
+        return true;
+    }
+
+    @Override
+    public Integer getByteSize() {
+        return PDate.INSTANCE.getByteSize();
+    }
+
+    @Override
+    public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+        return PDate.INSTANCE.compareTo(lhs, rhs, rhsType);
+    }
+
+    @Override
+    public Object toObject(String value) {
+        return PDate.INSTANCE.toObject(value);
+    }
+
+    @Override
+    public boolean isBytesComparableWith(PDataType otherType) {
+        return super.isBytesComparableWith(otherType) || otherType == PUnsignedTime.INSTANCE || otherType == PUnsignedTimestamp.INSTANCE || otherType == PUnsignedLong.INSTANCE;
+    }
+
+    @Override
+    public String toStringLiteral(Object o, Format formatter) {
+        // Can't delegate, as the super.toStringLiteral calls this.toBytes
+        if (formatter == null || formatter == DateUtil.DEFAULT_DATE_FORMATTER) {
+            // If default formatter has not been overridden,
+            // use one that displays milliseconds.
+            formatter = DateUtil.DEFAULT_MS_DATE_FORMATTER;
+        }
+        return "'" + super.toStringLiteral(o, formatter) + "'";
+    }
+
+    // TODO: derive PUnsignedDate from PDate to avoid copy/paste
+    @Override
+    public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+            Integer maxLength, Integer scale, SortOrder actualModifier,
+            Integer desiredMaxLength, Integer desiredScale,
+            SortOrder expectedModifier) {
+        if (ptr.getLength() > getByteSize()) {
+            ptr.set(ptr.get(), ptr.getOffset(), getByteSize());
+        }
+        super.coerceBytes(ptr, object, actualType, maxLength, scale, actualModifier, desiredMaxLength,
+                desiredScale, expectedModifier);
+    }
+
+    @Override
+    public int getResultSetSqlType() {
+        return Types.DATE;
+    }
+
+    @Override
+    public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+        return new Date((Long) PUnsignedLong.INSTANCE.getSampleValue(maxLength, arrayLength));
+    }
+
+    static class UnsignedDateCodec extends PUnsignedLong.UnsignedLongCodec {
+
+        @Override
+        public int decodeInt(byte[] b, int o, SortOrder sortOrder) {
+            throw new UnsupportedOperationException();
+        }
 
         @Override
-        public PhoenixArray newArray(PDataType type, Object[] elements) {
-          return new PhoenixArray(type, elements);
+        public PhoenixArrayFactory getPhoenixArrayFactory() {
+            return new PhoenixArrayFactory() {
+
+                @Override
+                public PhoenixArray newArray(PDataType type, Object[] elements) {
+                    return new PhoenixArray(type, elements);
+                }
+            };
         }
-      };
     }
-  }
 }


[40/47] phoenix git commit: PHOENIX-3293 Create separate test categories for stats enabled and disabled

Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/SerialIteratorsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SerialIteratorsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SerialIteratorsIT.java
index d4c71af..0494342 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SerialIteratorsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SerialIteratorsIT.java
@@ -37,7 +37,7 @@ import org.junit.Test;
 
 import com.google.common.collect.Maps;
 
-public class SerialIteratorsIT extends BaseHBaseManagedTimeTableReuseIT {
+public class SerialIteratorsIT extends ParallelStatsDisabledIT {
     private String tableName = generateRandomString();
     private final String[] strings = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
             "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ServerExceptionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ServerExceptionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ServerExceptionIT.java
index e4f3c1d..bf2e933 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ServerExceptionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ServerExceptionIT.java
@@ -32,7 +32,7 @@ import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
 
 
-public class ServerExceptionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ServerExceptionIT extends ParallelStatsDisabledIT {
 
     @Test
     public void testServerExceptionBackToClient() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/SignFunctionEnd2EndIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SignFunctionEnd2EndIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SignFunctionEnd2EndIT.java
index 5c86955..3cc8041 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SignFunctionEnd2EndIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SignFunctionEnd2EndIT.java
@@ -36,7 +36,7 @@ import org.junit.Test;
  * End to end tests for {@link SignFunction}
  * @since 4.0.0
  */
-public class SignFunctionEnd2EndIT extends BaseHBaseManagedTimeTableReuseIT {
+public class SignFunctionEnd2EndIT extends ParallelStatsDisabledIT {
 
     private static final String KEY = "key";
     private static final String TEST_SIGNED = generateRandomString();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanAfterManualSplitIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanAfterManualSplitIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanAfterManualSplitIT.java
index 39ba19e..d4dd088 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanAfterManualSplitIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanAfterManualSplitIT.java
@@ -43,7 +43,7 @@ import org.junit.Test;
 import com.google.common.collect.Maps;
 
 
-public class SkipScanAfterManualSplitIT extends BaseHBaseManagedTimeTableReuseIT {
+public class SkipScanAfterManualSplitIT extends ParallelStatsDisabledIT {
 
     private static final int BATCH_SIZE = 25;
     private static final int MAX_FILESIZE = 1024 * 10;
@@ -60,7 +60,7 @@ public class SkipScanAfterManualSplitIT extends BaseHBaseManagedTimeTableReuseIT
     private static final int MAX_CHAR = 'z';
 
     @BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(2);
         // needed for 64 region parallelization due to splitting

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
index 944acf7..17df5ba 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
@@ -41,7 +41,7 @@ import org.apache.phoenix.util.PhoenixRuntime;
 import org.junit.Test;
 
 
-public class SkipScanQueryIT extends BaseHBaseManagedTimeTableReuseIT {
+public class SkipScanQueryIT extends ParallelStatsDisabledIT {
     
     private String initIntInTable(Connection conn, List<Integer> data) throws SQLException {
         String tableName = generateRandomString();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index f1be09f..9570021 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -39,10 +39,10 @@ import org.junit.Test;
 
 import com.google.common.collect.Maps;
 
-public class SortMergeJoinMoreIT extends BaseHBaseManagedTimeTableReuseIT {
+public class SortMergeJoinMoreIT extends ParallelStatsDisabledIT {
     
     @BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
         // Forces server cache to be used

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
index 87814fc..dc22ff8 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
@@ -55,7 +55,7 @@ import com.google.common.collect.Lists;
  */
 
 
-public class SortOrderIT extends BaseHBaseManagedTimeTableReuseIT {
+public class SortOrderIT extends ParallelStatsDisabledIT {
     private String baseTableName;
     
     @Before

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledTmpFileDeleteIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledTmpFileDeleteIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledTmpFileDeleteIT.java
index 728aa6f..02a5d71 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledTmpFileDeleteIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledTmpFileDeleteIT.java
@@ -38,7 +38,7 @@ import com.google.common.io.Files;
 
 
 
-public class SpooledTmpFileDeleteIT extends BaseHBaseManagedTimeTableReuseIT {
+public class SpooledTmpFileDeleteIT extends ParallelStatsDisabledIT {
 	
     private Connection conn = null;
     private Properties props = null;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/SqrtFunctionEnd2EndIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SqrtFunctionEnd2EndIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SqrtFunctionEnd2EndIT.java
index 877b46d..1426564 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SqrtFunctionEnd2EndIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SqrtFunctionEnd2EndIT.java
@@ -34,7 +34,7 @@ import org.junit.Test;
 /**
  * End to end tests for {@link SqrtFunction}
  */
-public class SqrtFunctionEnd2EndIT extends BaseHBaseManagedTimeTableReuseIT {
+public class SqrtFunctionEnd2EndIT extends ParallelStatsDisabledIT {
 
     private static final String KEY = "key";
     private static final double ZERO = 1e-8;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatementHintsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatementHintsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatementHintsIT.java
index 887a30e..a0960e5 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatementHintsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatementHintsIT.java
@@ -37,7 +37,7 @@ import org.junit.Test;
  */
 
 
-public class StatementHintsIT extends BaseHBaseManagedTimeTableReuseIT {
+public class StatementHintsIT extends ParallelStatsDisabledIT {
 
     private static final String TABLE_NAME = generateRandomString();
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/StddevIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StddevIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StddevIT.java
index 280b0aa..79c2be2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StddevIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StddevIT.java
@@ -30,7 +30,7 @@ import java.sql.ResultSet;
 
 import org.junit.Test;
 
-public class StddevIT extends BaseHBaseManagedTimeTableReuseIT {
+public class StddevIT extends ParallelStatsDisabledIT {
 
     @Test
     public void testSTDDEV_POP() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
index 363198c..904743a 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
@@ -58,7 +58,7 @@ import com.google.common.collect.Lists;
  * functionality allows having row-level versioning (similar to how KEEP_DELETED_CELLS works), but
  * also allows permanently deleting a row.
  */
-public class StoreNullsIT extends BaseHBaseManagedTimeTableReuseIT {
+public class StoreNullsIT extends ParallelStatsDisabledIT {
     private static final Log LOG = LogFactory.getLog(StoreNullsIT.class);
     
     private String WITH_NULLS;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/StringIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StringIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StringIT.java
index d5aad53..bcf31ca 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StringIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StringIT.java
@@ -40,7 +40,7 @@ import com.google.common.collect.Lists;
  * Tests for the LPAD built-in function.
  */
 
-public class StringIT extends BaseHBaseManagedTimeTableReuseIT {
+public class StringIT extends ParallelStatsDisabledIT {
     
     /**
      * Helper to test LPAD function

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/StringToArrayFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StringToArrayFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StringToArrayFunctionIT.java
index d341646..d0f45c7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StringToArrayFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StringToArrayFunctionIT.java
@@ -28,7 +28,7 @@ import org.apache.phoenix.schema.types.PhoenixArray;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-public class StringToArrayFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class StringToArrayFunctionIT extends ParallelStatsDisabledIT {
 
     private static final String TABLE_NAME = generateRandomString();
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantIdTypeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantIdTypeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantIdTypeIT.java
index a3ca355..22b3655 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantIdTypeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantIdTypeIT.java
@@ -42,7 +42,7 @@ import org.junit.runners.Parameterized.Parameters;
 import com.google.common.collect.Lists;
 
 @RunWith(Parameterized.class)
-public class TenantIdTypeIT extends BaseHBaseManagedTimeTableReuseIT {
+public class TenantIdTypeIT extends ParallelStatsDisabledIT {
 
     private Connection regularConnection(String url) throws SQLException {
         Properties props = new Properties();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/TimezoneOffsetFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TimezoneOffsetFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TimezoneOffsetFunctionIT.java
index e899eb2..48eb87e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TimezoneOffsetFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TimezoneOffsetFunctionIT.java
@@ -34,7 +34,7 @@ import org.apache.phoenix.exception.SQLExceptionCode;
 import org.junit.Test;
 
 
-public class TimezoneOffsetFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class TimezoneOffsetFunctionIT extends ParallelStatsDisabledIT {
 
 	@Test
 	public void testTimezoneOffset() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java
index 27d593a..7181918 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java
@@ -47,7 +47,7 @@ import org.junit.Test;
  * @since 0.1
  */
 
-public class ToCharFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ToCharFunctionIT extends ParallelStatsDisabledIT {
     
     private String TO_CHAR_TABLE_NAME;
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToDateFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToDateFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToDateFunctionIT.java
index b530d2a..3b11419 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToDateFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToDateFunctionIT.java
@@ -30,7 +30,7 @@ import java.util.Properties;
 import static org.junit.Assert.*;
 
 
-public class ToDateFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ToDateFunctionIT extends ParallelStatsDisabledIT {
 
     private static final long ONE_HOUR_IN_MILLIS = 1000L * 60L * 60L;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java
index c6a7bf0..8f9a294 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java
@@ -37,7 +37,7 @@ import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.junit.Test;
 
-public class UnionAllIT extends BaseHBaseManagedTimeTableReuseIT {
+public class UnionAllIT extends ParallelStatsDisabledIT {
 
     @Test
     public void testUnionAllSelects() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertBigValuesIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertBigValuesIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertBigValuesIT.java
index 564fdd9..132c0ae 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertBigValuesIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertBigValuesIT.java
@@ -30,7 +30,7 @@ import java.util.Properties;
 import org.junit.Test;
 
 
-public class UpsertBigValuesIT extends BaseHBaseManagedTimeTableReuseIT {
+public class UpsertBigValuesIT extends ParallelStatsDisabledIT {
 
     private static final long INTEGER_MIN_MINUS_ONE = (long)Integer.MIN_VALUE - 1;
     private static final long INTEGER_MAX_PLUS_ONE = (long)Integer.MAX_VALUE + 1;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java
index a0b3939..3fbe5d7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java
@@ -37,7 +37,7 @@ import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
 
 
-public class UpsertSelectAutoCommitIT extends BaseHBaseManagedTimeTableReuseIT {
+public class UpsertSelectAutoCommitIT extends ParallelStatsDisabledIT {
 
     public UpsertSelectAutoCommitIT() {
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/UseSchemaIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UseSchemaIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UseSchemaIT.java
index c42c287..ec84282 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UseSchemaIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UseSchemaIT.java
@@ -41,7 +41,7 @@ import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.TestUtil;
 import org.junit.Test;
 
-public class UseSchemaIT extends BaseHBaseManagedTimeTableReuseIT {
+public class UseSchemaIT extends ParallelStatsDisabledIT {
 
     @Test
     public void testUseSchemaCaseInsensitive() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/AsyncIndexDisabledIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/AsyncIndexDisabledIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/AsyncIndexDisabledIT.java
index 1e4cbcc..a6228e7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/AsyncIndexDisabledIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/AsyncIndexDisabledIT.java
@@ -27,7 +27,7 @@ import java.sql.ResultSet;
 import java.sql.Statement;
 import java.util.Map;
 
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.PTable;
@@ -38,7 +38,7 @@ import org.junit.Test;
 
 import com.google.common.collect.Maps;
 
-public class AsyncIndexDisabledIT extends BaseHBaseManagedTimeTableReuseIT {
+public class AsyncIndexDisabledIT extends ParallelStatsDisabledIT {
 
     @BeforeClass
     public static void doSetup() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ChildViewsUseParentViewIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ChildViewsUseParentViewIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ChildViewsUseParentViewIndexIT.java
index 60a428c..a0efd52 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ChildViewsUseParentViewIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ChildViewsUseParentViewIndexIT.java
@@ -12,11 +12,11 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Properties;
 
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.util.QueryUtil;
 import org.junit.Test;
 
-public class ChildViewsUseParentViewIndexIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ChildViewsUseParentViewIndexIT extends ParallelStatsDisabledIT {
 
     @Test
     public void testIndexOnParentViewWithTenantSpecificConnection() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java
index 93f8e27..9ee00d2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java
@@ -39,7 +39,7 @@ import org.apache.hadoop.hbase.client.ResultScanner;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
 import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.QueryConstants;
@@ -59,12 +59,12 @@ import org.junit.Test;
 
 import com.google.common.collect.Maps;
 
-public class DropMetadataIT extends BaseHBaseManagedTimeTableReuseIT {
+public class DropMetadataIT extends ParallelStatsDisabledIT {
     private static final byte[] FAMILY_NAME = Bytes.toBytes(SchemaUtil.normalizeIdentifier("1"));
     public static final String SCHEMA_NAME = "";
     private final String TENANT_SPECIFIC_URL = getUrl() + ';' + TENANT_ID_ATTRIB + "=tenant1";
     
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     @BeforeClass 
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(1);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java
index 0ab171a..b84cf5d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java
@@ -28,7 +28,7 @@ import java.sql.SQLException;
 import java.util.Map;
 import java.util.regex.Pattern;
 
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.*;
@@ -37,10 +37,10 @@ import org.junit.Test;
 
 import com.google.common.collect.Maps;
 
-public class GlobalIndexOptimizationIT extends BaseHBaseManagedTimeTableReuseIT {
+public class GlobalIndexOptimizationIT extends ParallelStatsDisabledIT {
 
     @BeforeClass 
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
         // Drop the HBase table metadata for this test

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
index ec5267d..3e413e2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
@@ -48,7 +48,7 @@ import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
 import org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver;
 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
 import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.query.BaseTest;
@@ -69,7 +69,7 @@ import com.google.common.collect.Maps;
 
 
 @RunWith(Parameterized.class)
-public class ImmutableIndexIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ImmutableIndexIT extends ParallelStatsDisabledIT {
 
     private final boolean localIndex;
     private final String tableDDLOptions;
@@ -91,7 +91,7 @@ public class ImmutableIndexIT extends BaseHBaseManagedTimeTableReuseIT {
     }
 
     @BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(1);
         serverProps.put("hbase.coprocessor.region.classes", CreateIndexRegionObserver.class.getName());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
index 0dc2036..3235c52 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
@@ -28,7 +28,7 @@ import java.sql.SQLException;
 import java.util.Properties;
 
 import org.apache.commons.lang.StringUtils;
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.execute.CommitException;
 import org.apache.phoenix.query.QueryConstants;
@@ -38,7 +38,7 @@ import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.junit.Test;
 
-public class IndexExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class IndexExpressionIT extends ParallelStatsDisabledIT {
 
     @Test
     public void testImmutableIndexCreateAndUpdate() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
index f06ac82..2e07aef 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
@@ -54,7 +54,7 @@ import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.ipc.PhoenixRpcSchedulerFactory;
 import org.apache.phoenix.compile.ColumnResolver;
 import org.apache.phoenix.compile.FromCompiler;
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixConnection;
@@ -82,7 +82,7 @@ import org.junit.runners.Parameterized.Parameters;
 import com.google.common.collect.Maps;
 
 @RunWith(Parameterized.class)
-public class IndexIT extends BaseHBaseManagedTimeTableReuseIT {
+public class IndexIT extends ParallelStatsDisabledIT {
 
     private final boolean localIndex;
     private final boolean transactional;
@@ -106,7 +106,7 @@ public class IndexIT extends BaseHBaseManagedTimeTableReuseIT {
     }
 
     @BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(1);
         props.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.toString(true));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexMetadataIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexMetadataIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexMetadataIT.java
index 2e1fe1d..3372b6a 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexMetadataIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexMetadataIT.java
@@ -35,7 +35,7 @@ import java.sql.Types;
 import java.util.Properties;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
@@ -53,7 +53,7 @@ import org.apache.phoenix.util.StringUtil;
 import org.junit.Test;
 
 
-public class IndexMetadataIT extends BaseHBaseManagedTimeTableReuseIT {
+public class IndexMetadataIT extends ParallelStatsDisabledIT {
 
 	private enum Order {ASC, DESC};
 	

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/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 d3d775b..9a279bb 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
@@ -47,7 +47,7 @@ import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.hbase.index.IndexRegionSplitPolicy;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixStatement;
@@ -70,7 +70,7 @@ import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
 @RunWith(Parameterized.class)
-public class LocalIndexIT extends BaseHBaseManagedTimeTableReuseIT {
+public class LocalIndexIT extends ParallelStatsDisabledIT {
     private boolean isNamespaceMapped;
     private String schemaName;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/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 6dc4657..e5dfb0d 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
@@ -44,7 +44,7 @@ import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Threads;
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.QueryServices;
@@ -66,7 +66,7 @@ import com.google.common.collect.Maps;
 import com.google.common.primitives.Doubles;
 
 @RunWith(Parameterized.class)
-public class MutableIndexIT extends BaseHBaseManagedTimeTableReuseIT {
+public class MutableIndexIT extends ParallelStatsDisabledIT {
     
     protected final boolean localIndex;
     private final String tableDDLOptions;
@@ -81,7 +81,7 @@ public class MutableIndexIT extends BaseHBaseManagedTimeTableReuseIT {
 	}
     
     @BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(1);
         props.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.toString(true));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/SaltedIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/SaltedIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/SaltedIndexIT.java
index e47c055..ebdd565 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/SaltedIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/SaltedIndexIT.java
@@ -29,7 +29,7 @@ import java.sql.ResultSet;
 import java.util.Map;
 import java.util.Properties;
 
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.QueryServices;
@@ -41,12 +41,12 @@ import org.junit.Test;
 import com.google.common.collect.Maps;
 
 
-public class SaltedIndexIT extends BaseHBaseManagedTimeTableReuseIT {
+public class SaltedIndexIT extends ParallelStatsDisabledIT {
     private static final int TABLE_SPLITS = 3;
     private static final int INDEX_SPLITS = 4;
     
     @BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
         // Forces server cache to be used

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
index a886bca..7bd1478 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
@@ -34,7 +34,7 @@ import java.util.Collection;
 import java.util.Properties;
 
 import org.apache.phoenix.compile.QueryPlan;
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.PNameFactory;
@@ -45,7 +45,7 @@ import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
 @RunWith(Parameterized.class)
-public class ViewIndexIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ViewIndexIT extends ParallelStatsDisabledIT {
     private boolean isNamespaceMapped;
 
     @Parameters(name = "ViewIndexIT_isNamespaceMapped={0}") // name is used by failsafe as file name in reports

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
index 8562c0a..44ec7a5 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
@@ -35,7 +35,7 @@ import java.util.Properties;
 
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.QueryServices;
@@ -52,7 +52,7 @@ import org.junit.runners.Parameterized.Parameters;
 import com.google.common.collect.Maps;
 
 @RunWith(Parameterized.class)
-public class MutableRollbackIT extends BaseHBaseManagedTimeTableReuseIT {
+public class MutableRollbackIT extends ParallelStatsDisabledIT {
 	
 	private final boolean localIndex;
 
@@ -61,7 +61,7 @@ public class MutableRollbackIT extends BaseHBaseManagedTimeTableReuseIT {
 	}
 	
 	@BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(2);
         props.put(QueryServices.DEFAULT_TABLE_ISTRANSACTIONAL_ATTRIB, Boolean.toString(true));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java
index 92a69d0..fb50548 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java
@@ -31,7 +31,7 @@ import java.util.Collection;
 import java.util.Map;
 import java.util.Properties;
 
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PropertiesUtil;
@@ -47,7 +47,7 @@ import org.junit.runners.Parameterized.Parameters;
 import com.google.common.collect.Maps;
 
 @RunWith(Parameterized.class)
-public class RollbackIT extends BaseHBaseManagedTimeTableReuseIT {
+public class RollbackIT extends ParallelStatsDisabledIT {
 	
 	private final boolean localIndex;
 	private final boolean mutable;
@@ -58,7 +58,7 @@ public class RollbackIT extends BaseHBaseManagedTimeTableReuseIT {
 	}
 	
 	@BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(2);
         props.put(QueryServices.DEFAULT_TABLE_ISTRANSACTIONAL_ATTRIB, Boolean.toString(true));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableUpsertSelectIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableUpsertSelectIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableUpsertSelectIT.java
index a7ac817..d680954 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableUpsertSelectIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableUpsertSelectIT.java
@@ -31,12 +31,12 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Properties;
 
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
 
 
-public class SaltedTableUpsertSelectIT extends BaseHBaseManagedTimeTableReuseIT {
+public class SaltedTableUpsertSelectIT extends ParallelStatsDisabledIT {
 
     @Test
     public void testUpsertIntoSaltedTableFromNormalTable() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableVarLengthRowKeyIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableVarLengthRowKeyIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableVarLengthRowKeyIT.java
index e3688ca..c3f331b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableVarLengthRowKeyIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableVarLengthRowKeyIT.java
@@ -29,12 +29,12 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.util.Properties;
 
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
 
 
-public class SaltedTableVarLengthRowKeyIT extends BaseHBaseManagedTimeTableReuseIT {
+public class SaltedTableVarLengthRowKeyIT extends ParallelStatsDisabledIT {
 
     private static final String TEST_TABLE = generateRandomString();
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/iterate/PhoenixQueryTimeoutIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/iterate/PhoenixQueryTimeoutIT.java b/phoenix-core/src/it/java/org/apache/phoenix/iterate/PhoenixQueryTimeoutIT.java
index 7a93333..7b3b286 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/iterate/PhoenixQueryTimeoutIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/iterate/PhoenixQueryTimeoutIT.java
@@ -26,7 +26,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Properties;
 
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -35,7 +35,7 @@ import org.junit.Test;
  * Tests to validate that user specified property phoenix.query.timeoutMs
  * works as expected.
  */
-public class PhoenixQueryTimeoutIT extends BaseHBaseManagedTimeTableReuseIT {
+public class PhoenixQueryTimeoutIT extends ParallelStatsDisabledIT {
 
     private static final String QUERY_TIMEOUT_TEST = generateRandomString();
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/iterate/RoundRobinResultIteratorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/iterate/RoundRobinResultIteratorIT.java b/phoenix-core/src/it/java/org/apache/phoenix/iterate/RoundRobinResultIteratorIT.java
index f065f28..ba35f4e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/iterate/RoundRobinResultIteratorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/iterate/RoundRobinResultIteratorIT.java
@@ -42,7 +42,7 @@ import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.compile.StatementContext;
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixResultSet;
@@ -58,12 +58,12 @@ import org.junit.Test;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 
-public class RoundRobinResultIteratorIT extends BaseHBaseManagedTimeTableReuseIT {
+public class RoundRobinResultIteratorIT extends ParallelStatsDisabledIT {
 
     private static final int NUM_SALT_BUCKETS = 4; 
 
     @BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(1);
         props.put(QueryServices.THREAD_POOL_SIZE_ATTRIB, Integer.toString(32));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java b/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java
index f1eafc2..56f9f4b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java
@@ -36,7 +36,7 @@ import java.sql.SQLException;
 import java.util.Map;
 import java.util.Properties;
 
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.jdbc.PhoenixEmbeddedDriver;
 import org.apache.phoenix.query.ConnectionQueryServices;
@@ -60,12 +60,12 @@ import com.google.common.collect.Maps;
  * Verifies the number of rpcs calls from {@link MetaDataClient} updateCache() 
  * for transactional and non-transactional tables.
  */
-public class UpdateCacheIT extends BaseHBaseManagedTimeTableReuseIT {
+public class UpdateCacheIT extends ParallelStatsDisabledIT {
 	
 	public static final int NUM_MILLIS_IN_DAY = 86400000;
 
     @BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(1);
         props.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.toString(true));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/trace/BaseTracingTestIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/trace/BaseTracingTestIT.java b/phoenix-core/src/it/java/org/apache/phoenix/trace/BaseTracingTestIT.java
index 66f3e87..7e5d17f 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/trace/BaseTracingTestIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/trace/BaseTracingTestIT.java
@@ -36,7 +36,7 @@ import org.apache.hadoop.metrics2.MetricsTag;
 import org.apache.hadoop.metrics2.impl.ExposedMetricCounterLong;
 import org.apache.hadoop.metrics2.impl.ExposedMetricsRecordImpl;
 import org.apache.hadoop.metrics2.lib.ExposedMetricsInfoImpl;
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.metrics.MetricInfo;
 import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.schema.TableNotFoundException;
@@ -51,7 +51,7 @@ import org.junit.Before;
  * connections, as well as any supporting utils.
  */
 
-public class BaseTracingTestIT extends BaseHBaseManagedTimeTableReuseIT {
+public class BaseTracingTestIT extends ParallelStatsDisabledIT {
     @Before
     public void resetTracingTableIfExists() throws Exception {
         Connection conn = getConnectionWithoutTracing();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
index e1eac48..c219158 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
@@ -46,7 +46,7 @@ import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.coprocessor.PhoenixTransactionalProcessor;
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixConnection;
@@ -72,11 +72,11 @@ import org.junit.Test;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 
-public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class TransactionIT extends ParallelStatsDisabledIT {
     
 
     @BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(1);
         props.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.toString(true));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
index 8f877ac..5a42a97 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
@@ -33,7 +33,7 @@ import java.util.Collection;
 import java.util.Map;
 import java.util.Properties;
 
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.execute.MutationState;
 import org.apache.phoenix.jdbc.PhoenixConnection;
@@ -51,7 +51,7 @@ import org.junit.runners.Parameterized.Parameters;
 import com.google.common.collect.Maps;
 
 @RunWith(Parameterized.class)
-public class TxCheckpointIT extends BaseHBaseManagedTimeTableReuseIT {
+public class TxCheckpointIT extends ParallelStatsDisabledIT {
 	
 	private final boolean localIndex;
 	private final boolean mutable;
@@ -63,7 +63,7 @@ public class TxCheckpointIT extends BaseHBaseManagedTimeTableReuseIT {
 	}
 	
 	@BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(2);
         props.put(QueryServices.DEFAULT_TABLE_ISTRANSACTIONAL_ATTRIB, Boolean.toString(true));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-flume/src/it/java/org/apache/phoenix/flume/PhoenixSinkIT.java
----------------------------------------------------------------------
diff --git a/phoenix-flume/src/it/java/org/apache/phoenix/flume/PhoenixSinkIT.java b/phoenix-flume/src/it/java/org/apache/phoenix/flume/PhoenixSinkIT.java
index 22dfa36..9b5988c 100644
--- a/phoenix-flume/src/it/java/org/apache/phoenix/flume/PhoenixSinkIT.java
+++ b/phoenix-flume/src/it/java/org/apache/phoenix/flume/PhoenixSinkIT.java
@@ -29,7 +29,7 @@ import org.apache.flume.lifecycle.LifecycleState;
 import org.apache.flume.sink.DefaultSinkFactory;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.flume.serializer.EventSerializers;
 import org.apache.phoenix.flume.serializer.CustomSerializer;
 import org.apache.phoenix.flume.sink.NullPhoenixSink;
@@ -48,7 +48,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
 
-public class PhoenixSinkIT extends BaseHBaseManagedTimeTableReuseIT {
+public class PhoenixSinkIT extends ParallelStatsDisabledIT {
 
     private Context sinkContext;
     private PhoenixSink sink;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-flume/src/it/java/org/apache/phoenix/flume/RegexEventSerializerIT.java
----------------------------------------------------------------------
diff --git a/phoenix-flume/src/it/java/org/apache/phoenix/flume/RegexEventSerializerIT.java b/phoenix-flume/src/it/java/org/apache/phoenix/flume/RegexEventSerializerIT.java
index 6863401..eb3f9e8 100644
--- a/phoenix-flume/src/it/java/org/apache/phoenix/flume/RegexEventSerializerIT.java
+++ b/phoenix-flume/src/it/java/org/apache/phoenix/flume/RegexEventSerializerIT.java
@@ -40,7 +40,7 @@ import org.apache.flume.conf.Configurables;
 import org.apache.flume.event.EventBuilder;
 import org.apache.flume.lifecycle.LifecycleState;
 import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.flume.serializer.EventSerializers;
 import org.apache.phoenix.flume.sink.PhoenixSink;
 import org.apache.phoenix.util.PropertiesUtil;
@@ -51,7 +51,7 @@ import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 
 
-public class RegexEventSerializerIT extends BaseHBaseManagedTimeTableReuseIT {
+public class RegexEventSerializerIT extends ParallelStatsDisabledIT {
 
     private Context sinkContext;
     private PhoenixSink sink;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/ResultBaseTestIT.java
----------------------------------------------------------------------
diff --git a/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/ResultBaseTestIT.java b/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/ResultBaseTestIT.java
index 07618a7..c300701 100644
--- a/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/ResultBaseTestIT.java
+++ b/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/ResultBaseTestIT.java
@@ -18,7 +18,7 @@
 
 package org.apache.phoenix.pherf;
 
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.pherf.configuration.XMLConfigParser;
 import org.apache.phoenix.pherf.result.ResultUtil;
 import org.apache.phoenix.pherf.schema.SchemaReader;
@@ -30,7 +30,7 @@ import java.nio.file.Path;
 import java.util.List;
 import java.util.Properties;
 
-public class ResultBaseTestIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ResultBaseTestIT extends ParallelStatsDisabledIT {
     protected static final String matcherScenario = ".*scenario/.*test.*xml";
     protected static final String matcherSchema = ".*datamodel/.*test.*sql";
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/SchemaReaderIT.java
----------------------------------------------------------------------
diff --git a/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/SchemaReaderIT.java b/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/SchemaReaderIT.java
index 4f6d3c1..c2bfdc1 100644
--- a/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/SchemaReaderIT.java
+++ b/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/SchemaReaderIT.java
@@ -30,7 +30,7 @@ import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.pherf.configuration.Column;
 import org.apache.phoenix.pherf.configuration.DataModel;
 import org.apache.phoenix.pherf.configuration.Scenario;
@@ -40,7 +40,7 @@ import org.apache.phoenix.pherf.util.PhoenixUtil;
 import org.junit.Test;
 
 
-public class SchemaReaderIT extends BaseHBaseManagedTimeTableReuseIT {
+public class SchemaReaderIT extends ParallelStatsDisabledIT {
     protected static PhoenixUtil util = PhoenixUtil.create(true);
 
     @Test 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-pig/src/it/java/org/apache/phoenix/pig/BasePigIT.java
----------------------------------------------------------------------
diff --git a/phoenix-pig/src/it/java/org/apache/phoenix/pig/BasePigIT.java b/phoenix-pig/src/it/java/org/apache/phoenix/pig/BasePigIT.java
index 4ff818f..2840a62 100644
--- a/phoenix-pig/src/it/java/org/apache/phoenix/pig/BasePigIT.java
+++ b/phoenix-pig/src/it/java/org/apache/phoenix/pig/BasePigIT.java
@@ -27,7 +27,7 @@ import java.util.Map;
 import java.util.Properties;
 
 import org.apache.hadoop.conf.Configuration;
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeTableReuseIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
@@ -42,7 +42,7 @@ import org.junit.BeforeClass;
 
 import com.google.common.collect.Maps;
 
-public class BasePigIT extends BaseHBaseManagedTimeTableReuseIT {
+public class BasePigIT extends ParallelStatsDisabledIT {
     protected TupleFactory tupleFactory;
     protected String zkQuorum;
     protected Connection conn;
@@ -50,7 +50,7 @@ public class BasePigIT extends BaseHBaseManagedTimeTableReuseIT {
     protected PigServer pigServer;
 
     @BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
         props.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-queryserver/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-queryserver/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java b/phoenix-queryserver/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java
index b7db592..967e320 100644
--- a/phoenix-queryserver/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java
+++ b/phoenix-queryserver/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java
@@ -50,7 +50,7 @@ import org.junit.Test;
 /**
  * Smoke test for query server.
  */
-public class QueryServerBasicsIT extends BaseHBaseManagedTimeTableReuseIT {
+public class QueryServerBasicsIT extends ParallelStatsDisabledIT {
 
   private static final Log LOG = LogFactory.getLog(QueryServerBasicsIT.class);
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index b5edb6c..242c987 100644
--- a/pom.xml
+++ b/pom.xml
@@ -118,7 +118,7 @@
 
     <!-- Plugin options -->
     <numForkedUT>3</numForkedUT>
-    <numForkedIT>5</numForkedIT>
+    <numForkedIT>7</numForkedIT>
 
     <!-- Set default encoding so multi-byte tests work correctly on the Mac -->
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -227,17 +227,20 @@
           <version>${maven-failsafe-plugin.version}</version>
           <executions>
             <execution>
-              <id>ClientManagedTimeTests</id>
+              <id>ParallelStatsEnabledTest</id>
               <configuration>
                 <encoding>UTF-8</encoding>
                 <forkCount>${numForkedIT}</forkCount>
                 <runOrder>alphabetical</runOrder>
                 <reuseForks>true</reuseForks>
-                <argLine>-enableassertions -Xmx2000m -XX:MaxPermSize=128m -Djava.security.egd=file:/dev/./urandom "-Djava.library.path=${hadoop.library.path}${path.separator}${java.library.path}"</argLine>
+                <runOrder>alphabetical</runOrder>
+                <!--parallel>methods</parallel>
+                <threadCount>20</threadCount-->
+                <argLine>-enableassertions -Xmx3072m -XX:MaxPermSize=256m -Djava.security.egd=file:/dev/./urandom "-Djava.library.path=${hadoop.library.path}${path.separator}${java.library.path}" -XX:NewRatio=4 -XX:SurvivorRatio=8 -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+DisableExplicitGC -XX:+UseCMSInitiatingOccupancyOnly -XX:+CMSClassUnloadingEnabled -XX:+CMSScavengeBeforeRemark -XX:CMSInitiatingOccupancyFraction=68</argLine>
                 <redirectTestOutputToFile>${test.output.tofile}</redirectTestOutputToFile>
-                <testSourceDirectory>${basedir}/src/it/java</testSourceDirectory>
-                <groups>org.apache.phoenix.end2end.ClientManagedTimeTest</groups>
                 <shutdown>kill</shutdown>
+                <testSourceDirectory>${basedir}/src/it/java</testSourceDirectory>
+                <groups>org.apache.phoenix.end2end.ParallelStatsEnabledTest</groups>
               </configuration>
               <goals>
                 <goal>integration-test</goal>
@@ -245,17 +248,23 @@
               </goals>
             </execution>
             <execution>
-              <id>HBaseManagedTimeTests</id>
+              <id>ParallelStatsDisabledTest</id>
               <configuration>
+		<!--includes>
+		  <include>TenantIdTypeIT</include>
+		</includes-->
                 <encoding>UTF-8</encoding>
                 <forkCount>${numForkedIT}</forkCount>
                 <runOrder>alphabetical</runOrder>
                 <reuseForks>true</reuseForks>
-                <argLine>-enableassertions -Xmx2000m -XX:MaxPermSize=128m -Djava.security.egd=file:/dev/./urandom "-Djava.library.path=${hadoop.library.path}${path.separator}${java.library.path}"</argLine>
+                <runOrder>alphabetical</runOrder>
+                <!--parallel>methods</parallel>
+                <threadCount>20</threadCount-->
+                <argLine>-enableassertions -Xmx3072m -XX:MaxPermSize=256m -Djava.security.egd=file:/dev/./urandom "-Djava.library.path=${hadoop.library.path}${path.separator}${java.library.path}" -XX:NewRatio=4 -XX:SurvivorRatio=8 -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+DisableExplicitGC -XX:+UseCMSInitiatingOccupancyOnly -XX:+CMSClassUnloadingEnabled -XX:+CMSScavengeBeforeRemark -XX:CMSInitiatingOccupancyFraction=68</argLine>
                 <redirectTestOutputToFile>${test.output.tofile}</redirectTestOutputToFile>
-                <testSourceDirectory>${basedir}/src/it/java</testSourceDirectory>
-                <groups>org.apache.phoenix.end2end.HBaseManagedTimeTest</groups>
                 <shutdown>kill</shutdown>
+                <testSourceDirectory>${basedir}/src/it/java</testSourceDirectory>
+                <groups>org.apache.phoenix.end2end.ParallelStatsDisabledTest</groups>
               </configuration>
               <goals>
                 <goal>integration-test</goal>
@@ -263,7 +272,25 @@
               </goals>
             </execution>
             <execution>
-              <id>HBaseManagedTimeTableReuseTest</id>
+               <id>ClientManagedTimeTests</id>
+                 <configuration>
+                 <encoding>UTF-8</encoding>
+                 <forkCount>${numForkedIT}</forkCount>
+                 <runOrder>alphabetical</runOrder>
+                 <reuseForks>true</reuseForks>
+                 <argLine>-enableassertions -Xmx2000m -XX:MaxPermSize=128m -Djava.security.egd=file:/dev/./urandom "-Djava.library.path=${hadoop.library.path}${path.separator}${java.library.path}"</argLine>
+                 <redirectTestOutputToFile>${test.output.tofile}</redirectTestOutputToFile>
+                 <testSourceDirectory>${basedir}/src/it/java</testSourceDirectory>
+                 <groups>org.apache.phoenix.end2end.ClientManagedTimeTest</groups>
+                 <shutdown>kill</shutdown>
+               </configuration>
+               <goals>
+                 <goal>integration-test</goal>
+                 <goal>verify</goal>
+               </goals>
+            </execution>
+            <execution>
+              <id>HBaseManagedTimeTests</id>
               <configuration>
                 <encoding>UTF-8</encoding>
                 <forkCount>${numForkedIT}</forkCount>
@@ -272,7 +299,7 @@
                 <argLine>-enableassertions -Xmx2000m -XX:MaxPermSize=128m -Djava.security.egd=file:/dev/./urandom "-Djava.library.path=${hadoop.library.path}${path.separator}${java.library.path}"</argLine>
                 <redirectTestOutputToFile>${test.output.tofile}</redirectTestOutputToFile>
                 <testSourceDirectory>${basedir}/src/it/java</testSourceDirectory>
-                <groups>org.apache.phoenix.end2end.HBaseManagedTimeTableReuseTest</groups>
+                <groups>org.apache.phoenix.end2end.HBaseManagedTimeTest</groups>
                 <shutdown>kill</shutdown>
               </configuration>
               <goals>
@@ -280,23 +307,23 @@
                 <goal>verify</goal>
               </goals>
             </execution>
-            <execution>
-              <id>NeedTheirOwnClusterTests</id>
-              <configuration>
-                <encoding>UTF-8</encoding>
-                <forkCount>${numForkedIT}</forkCount>
-                <runOrder>alphabetical</runOrder>
-                <reuseForks>false</reuseForks>
-                <argLine>-enableassertions -Xmx2000m -XX:MaxPermSize=256m -Djava.security.egd=file:/dev/./urandom "-Djava.library.path=${hadoop.library.path}${path.separator}${java.library.path}"</argLine>
-                <redirectTestOutputToFile>${test.output.tofile}</redirectTestOutputToFile>
-                <testSourceDirectory>${basedir}/src/it/java</testSourceDirectory>
-                <groups>org.apache.phoenix.end2end.NeedsOwnMiniClusterTest</groups>
-                <shutdown>kill</shutdown>
-              </configuration>
-              <goals>
-                <goal>integration-test</goal>
-                <goal>verify</goal>
-              </goals>
+	    <execution>
+               <id>NeedTheirOwnClusterTests</id>
+                 <configuration>
+                 <encoding>UTF-8</encoding>
+                 <forkCount>${numForkedIT}</forkCount>
+                 <runOrder>alphabetical</runOrder>
+                 <reuseForks>false</reuseForks>
+                 <argLine>-enableassertions -Xmx2000m -XX:MaxPermSize=256m -Djava.security.egd=file:/dev/./urandom "-Djava.library.path=${hadoop.library.path}${path.separator}${java.library.path}"</argLine>
+                 <redirectTestOutputToFile>${test.output.tofile}</redirectTestOutputToFile>
+                 <testSourceDirectory>${basedir}/src/it/java</testSourceDirectory>
+                 <groups>org.apache.phoenix.end2end.NeedsOwnMiniClusterTest</groups>
+                 <shutdown>kill</shutdown>
+               </configuration>
+               <goals>
+                 <goal>integration-test</goal>
+                 <goal>verify</goal>
+               </goals>
             </execution>
           </executions>
         </plugin>
@@ -394,6 +421,7 @@
         <artifactId>maven-surefire-plugin</artifactId>
         <version>${maven-surefire-plugin.version}</version>
         <configuration>
+          <!--skip>true</skip-->
           <forkCount>${numForkedUT}</forkCount>
           <reuseForks>true</reuseForks>
           <argLine>-enableassertions -Xmx2250m -XX:MaxPermSize=128m
@@ -927,4 +955,4 @@
       </build>
     </profile>
   </profiles>
-</project>
\ No newline at end of file
+</project>


[44/47] phoenix git commit: PHOENIX-3174 Make minor upgrade a manual step

Posted by ma...@apache.org.
PHOENIX-3174 Make minor upgrade a manual step


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

Branch: refs/heads/calcite
Commit: e90feaa31bd928645ecc3596437b822d980939ed
Parents: e8ffc9c
Author: Samarth <sa...@salesforce.com>
Authored: Mon Sep 19 18:31:49 2016 -0700
Committer: Samarth <sa...@salesforce.com>
Committed: Mon Sep 19 18:31:49 2016 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/UpgradeIT.java   | 156 ++-
 phoenix-core/src/main/antlr3/PhoenixSQL.g       |  10 +-
 .../coprocessor/MetaDataEndpointImpl.java       |  16 +-
 .../coprocessor/MetaDataRegionObserver.java     |  47 +-
 .../phoenix/exception/SQLExceptionCode.java     |   2 +
 .../exception/UpgradeInProgressException.java   |  28 +
 .../exception/UpgradeNotRequiredException.java  |  27 +
 .../exception/UpgradeRequiredException.java     |  29 +
 .../apache/phoenix/jdbc/PhoenixConnection.java  |  27 +-
 .../phoenix/jdbc/PhoenixDatabaseMetaData.java   |   2 +-
 .../apache/phoenix/jdbc/PhoenixStatement.java   |  72 +-
 .../index/automation/PhoenixMRJobSubmitter.java |   4 +
 .../phoenix/parse/ExecuteUpgradeStatement.java  |  34 +
 .../apache/phoenix/parse/ParseNodeFactory.java  |   4 +
 .../phoenix/query/ConnectionQueryServices.java  |   3 +
 .../query/ConnectionQueryServicesImpl.java      | 951 ++++++++++---------
 .../query/ConnectionlessQueryServicesImpl.java  |   8 +
 .../query/DelegateConnectionQueryServices.java  |  10 +
 .../org/apache/phoenix/query/QueryServices.java |   1 +
 .../phoenix/query/QueryServicesOptions.java     |   5 +-
 .../apache/phoenix/schema/MetaDataClient.java   |   2 +-
 .../phoenix/trace/PhoenixMetricsSink.java       |  37 +-
 .../org/apache/phoenix/util/PhoenixRuntime.java |   2 +-
 .../java/org/apache/phoenix/util/QueryUtil.java |   6 +-
 .../org/apache/phoenix/util/UpgradeUtil.java    |  19 +-
 25 files changed, 1027 insertions(+), 475 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java
index b47738d..bdd94a2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java
@@ -24,7 +24,9 @@ import static org.apache.phoenix.query.QueryConstants.DIVERGED_VIEW_BASE_COLUMN_
 import static org.apache.phoenix.util.UpgradeUtil.SELECT_BASE_COLUMN_COUNT_FROM_HEADER_ROW;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.IOException;
 import java.sql.Connection;
@@ -33,6 +35,9 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
@@ -41,8 +46,14 @@ import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.RowMutations;
 import org.apache.hadoop.hbase.snapshot.SnapshotCreationException;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.coprocessor.MetaDataProtocol;
+import org.apache.phoenix.exception.UpgradeInProgressException;
+import org.apache.phoenix.exception.UpgradeRequiredException;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.query.ConnectionQueryServices;
+import org.apache.phoenix.query.ConnectionQueryServicesImpl;
+import org.apache.phoenix.query.DelegateConnectionQueryServices;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.PName;
@@ -51,7 +62,6 @@ import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.UpgradeUtil;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class UpgradeIT extends BaseHBaseManagedTimeIT {
@@ -576,6 +586,150 @@ public class UpgradeIT extends BaseHBaseManagedTimeIT {
             }
         }
     }
+    
+    @Test
+    public void testUpgradeRequiredPreventsSQL() throws SQLException {
+        String tableName = generateRandomString();
+        try (Connection conn = getConnection(false, null)) {
+            conn.createStatement().execute(
+                    "CREATE TABLE " + tableName
+                            + " (PK1 VARCHAR NOT NULL, PK2 VARCHAR, KV1 VARCHAR, KV2 VARCHAR CONSTRAINT PK PRIMARY KEY(PK1, PK2))");
+            final ConnectionQueryServices delegate = conn.unwrap(PhoenixConnection.class).getQueryServices();
+            ConnectionQueryServices servicesWithUpgrade = new DelegateConnectionQueryServices(delegate) {
+                @Override
+                public boolean isUpgradeRequired() {
+                    return true;
+                }
+            };
+            try (PhoenixConnection phxConn = new PhoenixConnection(servicesWithUpgrade,
+                    conn.unwrap(PhoenixConnection.class), HConstants.LATEST_TIMESTAMP)) {
+                try {
+                    phxConn.createStatement().execute(
+                            "CREATE TABLE " + generateRandomString()
+                                    + " (k1 VARCHAR NOT NULL, k2 VARCHAR, CONSTRAINT PK PRIMARY KEY(K1,K2))");
+                    fail("CREATE TABLE should have failed with UpgradeRequiredException");
+                } catch (UpgradeRequiredException expected) {
+
+                }
+                try {
+                    phxConn.createStatement().execute("SELECT * FROM " + tableName);
+                    fail("SELECT should have failed with UpgradeRequiredException");
+                } catch (UpgradeRequiredException expected) {
+
+                }
+                try {
+                    phxConn.createStatement().execute("DELETE FROM " + tableName);
+                    fail("DELETE should have failed with UpgradeRequiredException");
+                } catch (UpgradeRequiredException expected) {
+
+                }
+                try {
+                    phxConn.createStatement().execute(
+                            "CREATE INDEX " + tableName + "_IDX ON " + tableName + " (KV1) INCLUDE (KV2)" );
+                    fail("CREATE INDEX should have failed with UpgradeRequiredException");
+                } catch (UpgradeRequiredException expected) {
+
+                }
+                try {
+                    phxConn.createStatement().execute(
+                            "UPSERT INTO " + tableName + " VALUES ('PK1', 'PK2', 'KV1', 'KV2')" );
+                    fail("UPSERT VALUES should have failed with UpgradeRequiredException");
+                } catch (UpgradeRequiredException expected) {
+
+                }
+            }
+        }
+    }
+    
+    @Test
+    public void testUpgradingConnectionBypassesUpgradeRequiredCheck() throws Exception {
+        String tableName = generateRandomString();
+        try (Connection conn = getConnection(false, null)) {
+            conn.createStatement()
+                    .execute(
+                            "CREATE TABLE "
+                                    + tableName
+                                    + " (PK1 VARCHAR NOT NULL, PK2 VARCHAR, KV1 VARCHAR, KV2 VARCHAR CONSTRAINT PK PRIMARY KEY(PK1, PK2))");
+            final ConnectionQueryServices delegate = conn.unwrap(PhoenixConnection.class).getQueryServices();
+            ConnectionQueryServices servicesWithUpgrade = new DelegateConnectionQueryServices(delegate) {
+                @Override
+                public boolean isUpgradeRequired() {
+                    return true;
+                }
+            };
+            try (PhoenixConnection phxConn = new PhoenixConnection(servicesWithUpgrade,
+                    conn.unwrap(PhoenixConnection.class), HConstants.LATEST_TIMESTAMP)) {
+                // Because upgrade is required, this SQL should fail.
+                try {
+                    phxConn.createStatement().executeQuery("SELECT * FROM " + tableName);
+                    fail("SELECT should have failed with UpgradeRequiredException");
+                } catch (UpgradeRequiredException expected) {
+
+                }
+                // Marking connection as the one running upgrade should let SQL execute fine.
+                phxConn.setRunningUpgrade(true);
+                phxConn.createStatement().execute(
+                        "UPSERT INTO " + tableName + " VALUES ('PK1', 'PK2', 'KV1', 'KV2')" );
+                phxConn.commit();
+                try (ResultSet rs = phxConn.createStatement().executeQuery("SELECT * FROM " + tableName)) {
+                    assertTrue(rs.next());
+                    assertFalse(rs.next());
+                }
+            }
+        }
+    }
+    
+    @Test
+    public void testConcurrentUpgradeThrowsUprgadeInProgressException() throws Exception {
+        final AtomicBoolean mutexStatus1 = new AtomicBoolean(false);
+        final AtomicBoolean mutexStatus2 = new AtomicBoolean(false);
+        final CountDownLatch latch = new CountDownLatch(2);
+        final AtomicInteger numExceptions = new AtomicInteger(0);
+        try (Connection conn = getConnection(false, null)) {
+            final ConnectionQueryServices services = conn.unwrap(PhoenixConnection.class).getQueryServices();
+            Thread t1 = new Thread(new AcquireMutexRunnable(mutexStatus1, services, latch, numExceptions));
+            t1.setDaemon(true);
+            Thread t2 = new Thread(new AcquireMutexRunnable(mutexStatus2, services, latch, numExceptions));
+            t2.setDaemon(true);;
+            t1.start();
+            t2.start();
+            latch.await();
+            assertTrue("One of the threads should have acquired the mutex", mutexStatus1.get() || mutexStatus2.get());
+            assertNotEquals("One and only one thread should have acquired the mutex ", mutexStatus1.get(), mutexStatus2.get());
+            assertEquals("One and only one thread should have caught UpgradeRequiredException ", 1, numExceptions.get());
+        }
+    }
+    
+    private static class AcquireMutexRunnable implements Runnable {
+        
+        private final AtomicBoolean acquireStatus;
+        private final ConnectionQueryServices services;
+        private final CountDownLatch latch;
+        private final AtomicInteger numExceptions;
+        public AcquireMutexRunnable(AtomicBoolean acquireStatus, ConnectionQueryServices services, CountDownLatch latch, AtomicInteger numExceptions) {
+            this.acquireStatus = acquireStatus;
+            this.services = services;
+            this.latch = latch;
+            this.numExceptions = numExceptions;
+        }
+        @Override
+        public void run() {
+            try {
+                ((ConnectionQueryServicesImpl)services).acquireUpgradeMutex(
+                        MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0,
+                        PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
+                acquireStatus.set(true);
+            } catch (UpgradeInProgressException e) {
+                numExceptions.incrementAndGet();
+            }
+            catch (IOException | SQLException ignore) {
+
+            } finally {
+                latch.countDown();
+            }
+        }
+        
+    }
 
     private Connection createTenantConnection(String tenantId) throws SQLException {
         Properties props = new Properties();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/antlr3/PhoenixSQL.g
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/antlr3/PhoenixSQL.g b/phoenix-core/src/main/antlr3/PhoenixSQL.g
index bc48b19..7e81a3a 100644
--- a/phoenix-core/src/main/antlr3/PhoenixSQL.g
+++ b/phoenix-core/src/main/antlr3/PhoenixSQL.g
@@ -133,6 +133,8 @@ tokens
     ROW = 'row';
     ROWS = 'rows';
     ONLY = 'only';
+    EXECUTE = 'execute';
+    UPGRADE = 'upgrade';
 }
 
 
@@ -419,6 +421,7 @@ oneStatement returns [BindableStatement ret]
     |	s=drop_schema_node
     |	s=use_schema_node
     |   s=update_statistics_node
+    |   s=execute_upgrade_node
     |   s=explain_node) { $ret = s; }
     ;
 finally{ contextStack.pop(); }
@@ -570,7 +573,7 @@ trace_node returns [TraceStatement ret]
        {ret = factory.trace(Tracing.isTraceOn(flag.getText()), s == null ? Tracing.isTraceOn(flag.getText()) ? 1.0 : 0.0 : (((BigDecimal)s.getValue())).doubleValue());}
     ;
 
-// Parse a trace statement.
+// Parse a create function statement.
 create_function_node returns [CreateFunctionStatement ret]
     :   CREATE (OR replace=REPLACE)? (temp=TEMPORARY)? FUNCTION function=identifier 
        (LPAREN args=zero_or_more_data_types RPAREN)
@@ -619,6 +622,11 @@ update_statistics_node returns [UpdateStatisticsStatement ret]
 		{ret = factory.updateStatistics(factory.namedTable(null, t), s == null ? StatisticsCollectionScope.getDefault() : StatisticsCollectionScope.valueOf(SchemaUtil.normalizeIdentifier(s.getText())), p);}
 	;
 
+execute_upgrade_node returns [ExecuteUpgradeStatement ret]
+	:   EXECUTE UPGRADE
+		{ret = factory.executeUpgrade();}
+	;
+
 prop_name returns [String ret]
     :   p=identifier {$ret = SchemaUtil.normalizeIdentifier(p); }
     ;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index a5d77bc..142f700 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -79,7 +79,6 @@ import static org.apache.phoenix.util.SchemaUtil.getVarChars;
 
 import java.io.IOException;
 import java.sql.DriverManager;
-import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.Statement;
@@ -127,6 +126,7 @@ import org.apache.phoenix.cache.GlobalCache;
 import org.apache.phoenix.cache.GlobalCache.FunctionBytesPtr;
 import org.apache.phoenix.compile.ColumnResolver;
 import org.apache.phoenix.compile.FromCompiler;
+import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.compile.ScanRanges;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.compile.WhereCompiler;
@@ -162,8 +162,10 @@ import org.apache.phoenix.hbase.index.util.GenericKeyValueBuilder;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
 import org.apache.phoenix.hbase.index.util.KeyValueBuilder;
 import org.apache.phoenix.index.IndexMaintainer;
+import org.apache.phoenix.iterate.ResultIterator;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.jdbc.PhoenixResultSet;
 import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.metrics.Metrics;
 import org.apache.phoenix.parse.LiteralParseNode;
@@ -212,7 +214,6 @@ import org.apache.phoenix.util.EnvironmentEdgeManager;
 import org.apache.phoenix.util.IndexUtil;
 import org.apache.phoenix.util.KeyValueUtil;
 import org.apache.phoenix.util.MetaDataUtil;
-import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
 import org.apache.phoenix.util.SchemaUtil;
@@ -1433,12 +1434,17 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
                 if (parentTable!=null && parentTable.getAutoPartitionSeqName()!=null) {
                     long autoPartitionNum = 1;
                     final Properties props = new Properties();
-                    props.setProperty(PhoenixRuntime.NO_UPGRADE_ATTRIB, Boolean.TRUE.toString());
+                    UpgradeUtil.doNotUpgradeOnFirstConnection(props);
                     try (PhoenixConnection connection = DriverManager.getConnection(MetaDataUtil.getJdbcUrl(env), props).unwrap(PhoenixConnection.class);
-                            Statement stmt = connection.createStatement()) {
+                        Statement stmt = connection.createStatement()) {
                         String seqName = parentTable.getAutoPartitionSeqName();
+                        // Not going through the standard route of using statement.execute() as that code path
+                        // is blocked if the metadata hasn't been been upgraded to the new minor release.
                         String seqNextValueSql = String.format("SELECT NEXT VALUE FOR %s", seqName);
-                        ResultSet rs = stmt.executeQuery(seqNextValueSql);
+                        PhoenixStatement ps = stmt.unwrap(PhoenixStatement.class);
+                        QueryPlan plan = ps.compileQuery(seqNextValueSql);
+                        ResultIterator resultIterator = plan.iterator();
+                        PhoenixResultSet rs = ps.newResultSet(resultIterator, plan.getProjector(), plan.getContext());
                         rs.next();
                         autoPartitionNum = rs.getLong(1);
                     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
index 00981f5..c645cf4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
@@ -18,8 +18,10 @@
 package org.apache.phoenix.coprocessor;
 
 import java.io.IOException;
+import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -54,6 +56,10 @@ import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.apache.phoenix.cache.GlobalCache;
 import org.apache.phoenix.cache.ServerCacheClient;
+import org.apache.phoenix.coprocessor.MetaDataProtocol.MetaDataMutationResult;
+import org.apache.phoenix.coprocessor.MetaDataProtocol.MutationCode;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.hbase.index.util.IndexManagementUtil;
 import org.apache.phoenix.index.IndexMaintainer;
 import org.apache.phoenix.index.PhoenixIndexCodec;
@@ -68,6 +74,7 @@ import org.apache.phoenix.schema.MetaDataClient;
 import org.apache.phoenix.schema.PIndexState;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.util.ByteUtil;
@@ -80,6 +87,7 @@ import org.apache.phoenix.util.UpgradeUtil;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
+import com.google.protobuf.ServiceException;
 
 
 /**
@@ -297,11 +305,7 @@ public class MetaDataRegionObserver extends BaseRegionObserver {
                     // Allow index to begin incremental maintenance as index is back online and we
                     // cannot transition directly from DISABLED -> ACTIVE
                     if (Bytes.compareTo(PIndexState.DISABLE.getSerializedBytes(), indexState) == 0) {
-                        AlterIndexStatement statement = new AlterIndexStatement(
-                                NamedTableNode.create(indexPTable.getSchemaName().getString(), indexPTable.getTableName().getString()),
-                                dataPTable.getTableName().getString(),
-                                false, PIndexState.INACTIVE);
-                        client.alterIndex(statement);
+                        updateIndexState(indexTableFullName, env, PIndexState.DISABLE, PIndexState.INACTIVE);
                     }
                     List<PTable> indexesToPartiallyRebuild = dataTableToIndexesMap.get(dataPTable);
                     if (indexesToPartiallyRebuild == null) {
@@ -393,11 +397,9 @@ public class MetaDataRegionObserver extends BaseRegionObserver {
                                 }
                             }
                             for (PTable indexPTable : indexesToPartiallyRebuild) {
-                                AlterIndexStatement statement = new AlterIndexStatement(
-                                        NamedTableNode.create(indexPTable.getSchemaName().getString(), indexPTable
-                                                .getTableName().getString()), dataPTable.getTableName().getString(),
-                                        false, PIndexState.ACTIVE);
-                                client.alterIndex(statement);
+                                String indexTableFullName = SchemaUtil.getTableName(indexPTable.getSchemaName()
+                                        .getString(), indexPTable.getTableName().getString());
+                                updateIndexState(indexTableFullName, env, PIndexState.INACTIVE, PIndexState.ACTIVE);
                             }
                         } catch (Exception e) { // Log, but try next table's indexes
                             LOG.warn("Unable to rebuild " + dataPTable + " indexes " + indexesToPartiallyRebuild
@@ -426,4 +428,29 @@ public class MetaDataRegionObserver extends BaseRegionObserver {
             }
         }
     }
+    
+    private static void updateIndexState(String indexTableName, RegionCoprocessorEnvironment env, PIndexState oldState,
+            PIndexState newState) throws ServiceException, Throwable {
+        byte[] indexTableKey = SchemaUtil.getTableKeyFromFullName(indexTableName);
+        String schemaName = SchemaUtil.getSchemaNameFromFullName(indexTableName);
+        String indexName = SchemaUtil.getSchemaNameFromFullName(indexTableName);
+        // Mimic the Put that gets generated by the client on an update of the index state
+        Put put = new Put(indexTableKey);
+        put.addColumn(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES, PhoenixDatabaseMetaData.INDEX_STATE_BYTES,
+                newState.getSerializedBytes());
+        if (newState == PIndexState.ACTIVE) {
+            put.addColumn(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES, PhoenixDatabaseMetaData.INDEX_DISABLE_TIMESTAMP_BYTES,
+                    PLong.INSTANCE.toBytes(0));
+        }
+        final List<Mutation> tableMetadata = Collections.<Mutation> singletonList(put);
+        Connection conn = QueryUtil.getConnection(env.getConfiguration());
+        MetaDataMutationResult result = conn.unwrap(PhoenixConnection.class).getQueryServices()
+                .updateIndexState(tableMetadata, null);
+        MutationCode code = result.getMutationCode();
+        if (code == MutationCode.TABLE_NOT_FOUND) { throw new TableNotFoundException(schemaName, indexName); }
+        if (code == MutationCode.UNALLOWED_TABLE_MUTATION) { throw new SQLExceptionInfo.Builder(
+                SQLExceptionCode.INVALID_INDEX_STATE_TRANSITION)
+                .setMessage(" currentState=" + oldState + ". requestedState=" + newState).setSchemaName(schemaName)
+                .setTableName(indexName).build().buildException(); }
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
index 0ccecae..e6a26ae 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
@@ -371,6 +371,8 @@ public enum SQLExceptionCode {
     INDEX_METADATA_NOT_FOUND(2008, "INT10", "Unable to find cached index metadata. "),
     UNKNOWN_ERROR_CODE(2009, "INT11", "Unknown error code."),
     CONCURRENT_UPGRADE_IN_PROGRESS(2010, "INT12", ""),
+    UPGRADE_REQUIRED(2011, "INT13", ""),
+    UPGRADE_NOT_REQUIRED(2012, "INT14", ""),
     OPERATION_TIMED_OUT(6000, "TIM01", "Operation timed out.", new Factory() {
         @Override
         public SQLException newException(SQLExceptionInfo info) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeInProgressException.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeInProgressException.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeInProgressException.java
new file mode 100644
index 0000000..5b15216
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeInProgressException.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.exception;
+
+import java.sql.SQLException;
+
+public class UpgradeInProgressException extends SQLException {
+    public UpgradeInProgressException(String upgradeFrom, String upgradeTo) {
+        super("Cluster is being concurrently upgraded from " + upgradeFrom + " to " + upgradeTo
+                + ". Please retry establishing connection.", SQLExceptionCode.CONCURRENT_UPGRADE_IN_PROGRESS
+                .getSQLState(), SQLExceptionCode.CONCURRENT_UPGRADE_IN_PROGRESS.getErrorCode());
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeNotRequiredException.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeNotRequiredException.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeNotRequiredException.java
new file mode 100644
index 0000000..0490319
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeNotRequiredException.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.exception;
+
+import java.sql.SQLException;
+
+public class UpgradeNotRequiredException extends SQLException {
+    public UpgradeNotRequiredException() {
+        super("Operation not allowed since cluster has already been upgraded. ", SQLExceptionCode.UPGRADE_NOT_REQUIRED
+                .getSQLState(), SQLExceptionCode.UPGRADE_NOT_REQUIRED.getErrorCode());
+    }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeRequiredException.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeRequiredException.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeRequiredException.java
new file mode 100644
index 0000000..005a1bd
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeRequiredException.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.exception;
+
+import java.sql.SQLException;
+
+public class UpgradeRequiredException extends SQLException {
+
+    public UpgradeRequiredException() {
+        super("Operation not allowed since cluster hasn't been upgraded. Call EXECUTE UPGRADE. ",
+                SQLExceptionCode.UPGRADE_REQUIRED.getSQLState(), SQLExceptionCode.UPGRADE_REQUIRED.getErrorCode());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
index 7bd4b9a..cef77d2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
@@ -164,6 +164,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea
     private ParallelIteratorFactory parallelIteratorFactory;
     private final LinkedBlockingQueue<WeakReference<TableResultIterator>> scannerQueue;
     private TableResultIteratorFactory tableResultIteratorFactory;
+    private boolean isRunningUpgrade;
     
     static {
         Tracing.addTraceMetricsSource();
@@ -175,8 +176,8 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea
         return props;
     }
 
-    public PhoenixConnection(PhoenixConnection connection, boolean isDescRowKeyOrderUpgrade) throws SQLException {
-        this(connection.getQueryServices(), connection.getURL(), connection.getClientInfo(), connection.metaData, connection.getMutationState(), isDescRowKeyOrderUpgrade);
+    public PhoenixConnection(PhoenixConnection connection, boolean isDescRowKeyOrderUpgrade, boolean isRunningUpgrade) throws SQLException {
+        this(connection.getQueryServices(), connection.getURL(), connection.getClientInfo(), connection.metaData, connection.getMutationState(), isDescRowKeyOrderUpgrade, isRunningUpgrade);
         this.isAutoCommit = connection.isAutoCommit;
         this.isAutoFlush = connection.isAutoFlush;
         this.sampler = connection.sampler;
@@ -184,11 +185,11 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea
     }
 
     public PhoenixConnection(PhoenixConnection connection) throws SQLException {
-        this(connection, connection.isDescVarLengthRowKeyUpgrade());
+        this(connection, connection.isDescVarLengthRowKeyUpgrade(), connection.isRunningUpgrade());
     }
     
     public PhoenixConnection(PhoenixConnection connection, MutationState mutationState) throws SQLException {
-        this(connection.getQueryServices(), connection.getURL(), connection.getClientInfo(), connection.getMetaDataCache(), mutationState, connection.isDescVarLengthRowKeyUpgrade());
+        this(connection.getQueryServices(), connection.getURL(), connection.getClientInfo(), connection.getMetaDataCache(), mutationState, connection.isDescVarLengthRowKeyUpgrade(), connection.isRunningUpgrade());
     }
     
     public PhoenixConnection(PhoenixConnection connection, long scn) throws SQLException {
@@ -196,7 +197,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea
     }
     
     public PhoenixConnection(ConnectionQueryServices services, PhoenixConnection connection, long scn) throws SQLException {
-        this(services, connection.getURL(), newPropsWithSCN(scn,connection.getClientInfo()), connection.metaData, connection.getMutationState(), connection.isDescVarLengthRowKeyUpgrade());
+        this(services, connection.getURL(), newPropsWithSCN(scn,connection.getClientInfo()), connection.metaData, connection.getMutationState(), connection.isDescVarLengthRowKeyUpgrade(), connection.isRunningUpgrade());
         this.isAutoCommit = connection.isAutoCommit;
         this.isAutoFlush = connection.isAutoFlush;
         this.sampler = connection.sampler;
@@ -204,14 +205,14 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea
     }
     
     public PhoenixConnection(ConnectionQueryServices services, String url, Properties info, PMetaData metaData) throws SQLException {
-        this(services, url, info, metaData, null, false);
+        this(services, url, info, metaData, null, false, false);
     }
     
     public PhoenixConnection(PhoenixConnection connection, ConnectionQueryServices services, Properties info) throws SQLException {
-        this(services, connection.url, info, connection.metaData, null, connection.isDescVarLengthRowKeyUpgrade());
+        this(services, connection.url, info, connection.metaData, null, connection.isDescVarLengthRowKeyUpgrade(), connection.isRunningUpgrade());
     }
     
-    public PhoenixConnection(ConnectionQueryServices services, String url, Properties info, PMetaData metaData, MutationState mutationState, boolean isDescVarLengthRowKeyUpgrade) throws SQLException {
+    public PhoenixConnection(ConnectionQueryServices services, String url, Properties info, PMetaData metaData, MutationState mutationState, boolean isDescVarLengthRowKeyUpgrade, boolean isRunningUpgrade) throws SQLException {
         this.url = url;
         this.isDescVarLengthRowKeyUpgrade = isDescVarLengthRowKeyUpgrade;
         // Copy so client cannot change
@@ -300,6 +301,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea
         this.customTracingAnnotations = getImmutableCustomTracingAnnotations();
         this.scannerQueue = new LinkedBlockingQueue<>();
         this.tableResultIteratorFactory = new DefaultTableResultIteratorFactory();
+        this.isRunningUpgrade = isRunningUpgrade;
         GLOBAL_OPEN_PHOENIX_CONNECTIONS.increment();
     }
     
@@ -1069,4 +1071,13 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea
         getQueryServices().removeSchema(schema, schemaTimeStamp);
 
     }
+    
+    public boolean isRunningUpgrade() {
+        return isRunningUpgrade;
+    }
+    
+    public void setRunningUpgrade(boolean isRunningUpgrade) {
+        this.isRunningUpgrade = isRunningUpgrade;
+    }
+    
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
index 2fed40c..47dfd4e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
@@ -515,7 +515,7 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData {
                 public PhoenixStatement newStatement(PhoenixConnection connection) {
                     return new PhoenixStatement(connection) {
                         @Override
-                        protected PhoenixResultSet newResultSet(ResultIterator iterator, RowProjector projector,
+                        public PhoenixResultSet newResultSet(ResultIterator iterator, RowProjector projector,
                                 StatementContext context) throws SQLException {
                             return new PhoenixResultSet(new TenantColumnFilteringIterator(iterator, projector),
                                     projector, context);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
index 0fbc81a..60e32e5 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
@@ -37,6 +37,7 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
 import org.apache.hadoop.conf.Configuration;
@@ -78,6 +79,7 @@ import org.apache.phoenix.coprocessor.MetaDataProtocol;
 import org.apache.phoenix.exception.BatchUpdateExecution;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
+import org.apache.phoenix.exception.UpgradeRequiredException;
 import org.apache.phoenix.execute.MutationState;
 import org.apache.phoenix.expression.RowKeyColumnExpression;
 import org.apache.phoenix.iterate.MaterializedResultIterator;
@@ -104,6 +106,7 @@ import org.apache.phoenix.parse.DropIndexStatement;
 import org.apache.phoenix.parse.DropSchemaStatement;
 import org.apache.phoenix.parse.DropSequenceStatement;
 import org.apache.phoenix.parse.DropTableStatement;
+import org.apache.phoenix.parse.ExecuteUpgradeStatement;
 import org.apache.phoenix.parse.ExplainStatement;
 import org.apache.phoenix.parse.FilterableStatement;
 import org.apache.phoenix.parse.HintNode;
@@ -192,7 +195,8 @@ public class PhoenixStatement implements Statement, SQLCloseable {
     public enum Operation {
         QUERY("queried", false),
         DELETE("deleted", true),
-        UPSERT("upserted", true);
+        UPSERT("upserted", true),
+        UPGRADE("upgrade", true);
         
         private final String toString;
         private final boolean isMutation;
@@ -241,7 +245,7 @@ public class PhoenixStatement implements Statement, SQLCloseable {
         return resultSets;
     }
     
-    protected PhoenixResultSet newResultSet(ResultIterator iterator, RowProjector projector, StatementContext context) throws SQLException {
+    public PhoenixResultSet newResultSet(ResultIterator iterator, RowProjector projector, StatementContext context) throws SQLException {
         return new PhoenixResultSet(iterator, projector, context);
     }
     
@@ -268,7 +272,12 @@ public class PhoenixStatement implements Statement, SQLCloseable {
                     public PhoenixResultSet call() throws SQLException {
                     final long startTime = System.currentTimeMillis();
                     try {
-						QueryPlan plan = stmt.compilePlan(PhoenixStatement.this, Sequence.ValueOp.VALIDATE_SEQUENCE);
+                        PhoenixConnection conn = getConnection();
+                        if (conn.getQueryServices().isUpgradeRequired() && !conn.isRunningUpgrade()
+                                && stmt.getOperation() != Operation.UPGRADE) {
+                            throw new UpgradeRequiredException();
+                        }
+                        QueryPlan plan = stmt.compilePlan(PhoenixStatement.this, Sequence.ValueOp.VALIDATE_SEQUENCE);
                         // Send mutations to hbase, so they are visible to subsequent reads.
                         // Use original plan for data table so that data and immutable indexes will be sent
                         // TODO: for joins, we need to iterate through all tables, but we need the original table,
@@ -333,6 +342,11 @@ public class PhoenixStatement implements Statement, SQLCloseable {
                         @Override
                             public Integer call() throws SQLException {
                             try {
+                                PhoenixConnection conn = getConnection();
+                                if (conn.getQueryServices().isUpgradeRequired() && !conn.isRunningUpgrade()
+                                        && stmt.getOperation() != Operation.UPGRADE) {
+                                    throw new UpgradeRequiredException();
+                                }
                                 MutationState state = connection.getMutationState();
                                 MutationPlan plan = stmt.compilePlan(PhoenixStatement.this, Sequence.ValueOp.VALIDATE_SEQUENCE);
                                 if (plan.getTargetRef() != null && plan.getTargetRef().getTable() != null && plan.getTargetRef().getTable().isTransactional()) {
@@ -1079,6 +1093,53 @@ public class PhoenixStatement implements Statement, SQLCloseable {
         }
 
     }
+    
+    private static class ExecutableExecuteUpgradeStatement extends ExecuteUpgradeStatement implements CompilableStatement {
+        @SuppressWarnings("unchecked")
+        @Override
+        public MutationPlan compilePlan(final PhoenixStatement stmt, Sequence.ValueOp seqAction) throws SQLException {
+            return new MutationPlan() {
+                
+                @Override
+                public Set<TableRef> getSourceRefs() {
+                    return Collections.emptySet();
+                }
+                
+                @Override
+                public ParameterMetaData getParameterMetaData() {
+                    return PhoenixParameterMetaData.EMPTY_PARAMETER_META_DATA;
+                }
+                
+                @Override
+                public Operation getOperation() {
+                    return Operation.UPGRADE;
+                }
+                
+                @Override
+                public ExplainPlan getExplainPlan() throws SQLException {
+                    return new ExplainPlan(Collections.singletonList("EXECUTE UPGRADE"));
+                }
+                
+                @Override
+                public StatementContext getContext() {
+                    return new StatementContext(stmt);
+                }
+                
+                @Override
+                public TableRef getTargetRef() {
+                    return TableRef.EMPTY_TABLE_REF;
+                }
+                
+                @Override
+                public MutationState execute() throws SQLException {
+                    PhoenixConnection phxConn = stmt.getConnection();
+                    Properties props = new Properties();
+                    phxConn.getQueryServices().upgradeSystemTables(phxConn.getURL(), props);
+                    return MutationState.emptyMutationState(-1, phxConn);
+                }
+            };
+        }
+    }
 
     private static class ExecutableAddColumnStatement extends AddColumnStatement implements CompilableStatement {
 
@@ -1261,6 +1322,11 @@ public class PhoenixStatement implements Statement, SQLCloseable {
         public UpdateStatisticsStatement updateStatistics(NamedTableNode table, StatisticsCollectionScope scope, Map<String,Object> props) {
             return new ExecutableUpdateStatisticsStatement(table, scope, props);
         }
+        
+        @Override
+        public ExecuteUpgradeStatement executeUpgrade() {
+            return new ExecutableExecuteUpgradeStatement();
+        }
     }
     
     static class PhoenixStatementParser extends SQLParser {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java
index f6f2482..9c447e8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java
@@ -28,6 +28,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
@@ -52,6 +53,7 @@ import org.apache.phoenix.schema.PTable.IndexType;
 import org.apache.phoenix.schema.PTableType;
 import org.apache.phoenix.schema.types.PDate;
 import org.apache.phoenix.util.PhoenixMRJobUtil;
+import org.apache.phoenix.util.UpgradeUtil;
 import org.apache.phoenix.util.PhoenixMRJobUtil.MR_SCHEDULER_TYPE;
 import org.apache.phoenix.util.ZKBasedMasterElectionUtil;
 import org.codehaus.jettison.json.JSONArray;
@@ -158,6 +160,8 @@ public class PhoenixMRJobSubmitter {
     }
 
     public Map<String, PhoenixAsyncIndex> getCandidateJobs() throws SQLException {
+        Properties props = new Properties();
+        UpgradeUtil.doNotUpgradeOnFirstConnection(props);
         Connection con = DriverManager.getConnection("jdbc:phoenix:" + zkQuorum);
         Statement s = con.createStatement();
         ResultSet rs = s.executeQuery(CANDIDATE_INDEX_INFO_QUERY);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/parse/ExecuteUpgradeStatement.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/ExecuteUpgradeStatement.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/ExecuteUpgradeStatement.java
new file mode 100644
index 0000000..29edf8f
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/ExecuteUpgradeStatement.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.parse;
+
+import org.apache.phoenix.jdbc.PhoenixStatement.Operation;
+
+public class ExecuteUpgradeStatement implements BindableStatement {
+
+    @Override
+    public int getBindCount() {
+        return 0;
+    }
+
+    @Override
+    public Operation getOperation() {
+        return Operation.UPGRADE;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
index 024e2c7..332ff15 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
@@ -393,6 +393,10 @@ public class ParseNodeFactory {
     public UpdateStatisticsStatement updateStatistics(NamedTableNode table, StatisticsCollectionScope scope, Map<String,Object> props) {
       return new UpdateStatisticsStatement(table, scope, props);
     }
+    
+    public ExecuteUpgradeStatement executeUpgrade() {
+        return new ExecuteUpgradeStatement();
+    }
 
 
     public FunctionParseNode functionDistinct(String name, List<ParseNode> args) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e90feaa3/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServices.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServices.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServices.java
index 7154d58..6f8b528 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServices.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServices.java
@@ -139,4 +139,7 @@ public interface ConnectionQueryServices extends QueryServices, MetaDataMutated
      * @param tableName The table to remove stats for
      */
     void invalidateStats(ImmutableBytesPtr tableName);
+    
+    boolean isUpgradeRequired();
+    void upgradeSystemTables(String url, Properties props) throws SQLException;
 }
\ No newline at end of file


[41/47] phoenix git commit: PHOENIX-3293 Create separate test categories for stats enabled and disabled

Posted by ma...@apache.org.
PHOENIX-3293 Create separate test categories for stats enabled and disabled


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

Branch: refs/heads/calcite
Commit: 6b868392b1ac4c9729d3e9510eb8f9784f5d6a62
Parents: 14d16c8
Author: James Taylor <ja...@apache.org>
Authored: Sat Sep 17 15:20:01 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Sat Sep 17 15:20:01 2016 -0700

----------------------------------------------------------------------
 .../phoenix/end2end/AbsFunctionEnd2EndIT.java   |  2 +-
 .../AlterMultiTenantTableWithViewsIT.java       |  2 +-
 .../apache/phoenix/end2end/AlterSessionIT.java  |  2 +-
 .../apache/phoenix/end2end/AlterTableIT.java    |  2 +-
 .../phoenix/end2end/AlterTableWithViewsIT.java  |  4 +-
 .../phoenix/end2end/AppendOnlySchemaIT.java     |  2 +-
 .../phoenix/end2end/ArithmeticQueryIT.java      |  2 +-
 .../phoenix/end2end/ArrayAppendFunctionIT.java  |  2 +-
 .../phoenix/end2end/ArrayConcatFunctionIT.java  |  2 +-
 .../phoenix/end2end/ArrayFillFunctionIT.java    |  2 +-
 .../phoenix/end2end/ArrayPrependFunctionIT.java |  2 +-
 .../end2end/ArrayToStringFunctionIT.java        |  2 +-
 .../phoenix/end2end/ArraysWithNullsIT.java      |  2 +-
 .../apache/phoenix/end2end/AutoCommitIT.java    |  2 +-
 .../phoenix/end2end/AutoPartitionViewsIT.java   |  2 +-
 .../BaseHBaseManagedTimeTableReuseIT.java       | 70 ----------------
 .../apache/phoenix/end2end/BaseParallelIT.java  | 69 ++++++++++++++++
 .../end2end/BaseTenantSpecificViewIndexIT.java  |  2 +-
 .../apache/phoenix/end2end/BinaryRowKeyIT.java  |  2 +-
 .../phoenix/end2end/CSVCommonsLoaderIT.java     |  2 +-
 .../phoenix/end2end/CbrtFunctionEnd2EndIT.java  |  2 +-
 .../phoenix/end2end/CoalesceFunctionIT.java     |  2 +-
 .../end2end/ConvertTimezoneFunctionIT.java      |  2 +-
 .../org/apache/phoenix/end2end/DateTimeIT.java  |  2 +-
 .../phoenix/end2end/DecodeFunctionIT.java       |  2 +-
 .../org/apache/phoenix/end2end/DeleteIT.java    |  2 +-
 .../phoenix/end2end/DisableLocalIndexIT.java    |  4 +-
 .../phoenix/end2end/DistinctPrefixFilterIT.java |  4 +-
 .../apache/phoenix/end2end/DynamicColumnIT.java |  2 +-
 .../apache/phoenix/end2end/DynamicFamilyIT.java |  2 +-
 .../apache/phoenix/end2end/DynamicUpsertIT.java |  2 +-
 .../phoenix/end2end/EncodeFunctionIT.java       |  2 +-
 .../phoenix/end2end/EvaluationOfORIT.java       |  2 +-
 .../phoenix/end2end/ExecuteStatementsIT.java    |  2 +-
 .../phoenix/end2end/ExpFunctionEnd2EndIT.java   |  2 +-
 .../phoenix/end2end/FirstValueFunctionIT.java   |  2 +-
 .../end2end/GetSetByteBitFunctionEnd2EndIT.java |  2 +-
 .../apache/phoenix/end2end/GroupByCaseIT.java   |  2 +-
 .../end2end/HBaseManagedTimeTableReuseTest.java | 47 -----------
 .../phoenix/end2end/HBaseManagedTimeTest.java   |  2 +-
 .../apache/phoenix/end2end/HashJoinMoreIT.java  |  4 +-
 .../org/apache/phoenix/end2end/InListIT.java    |  2 +-
 .../phoenix/end2end/InMemoryOrderByIT.java      |  2 +-
 .../apache/phoenix/end2end/InstrFunctionIT.java |  2 +-
 .../org/apache/phoenix/end2end/IsNullIT.java    |  2 +-
 .../phoenix/end2end/LastValueFunctionIT.java    |  2 +-
 .../phoenix/end2end/LikeExpressionIT.java       |  2 +-
 .../phoenix/end2end/LnLogFunctionEnd2EndIT.java |  2 +-
 .../apache/phoenix/end2end/MD5FunctionIT.java   |  2 +-
 .../org/apache/phoenix/end2end/MapReduceIT.java |  2 +-
 .../phoenix/end2end/MappingTableDataTypeIT.java |  2 +-
 .../end2end/MinMaxAggregateFunctionIT.java      |  2 +-
 .../phoenix/end2end/ModulusExpressionIT.java    |  2 +-
 .../end2end/NamespaceSchemaMappingIT.java       |  2 +-
 .../phoenix/end2end/NthValueFunctionIT.java     |  2 +-
 .../end2end/OctetLengthFunctionEnd2EndIT.java   |  2 +-
 .../org/apache/phoenix/end2end/OrderByIT.java   |  2 +-
 .../end2end/ParallelStatsDisabledIT.java        | 30 +++++++
 .../end2end/ParallelStatsDisabledTest.java      | 45 ++++++++++
 .../phoenix/end2end/ParallelStatsEnabledIT.java | 31 +++++++
 .../end2end/ParallelStatsEnabledTest.java       | 45 ++++++++++
 .../apache/phoenix/end2end/PercentileIT.java    |  2 +-
 .../phoenix/end2end/PhoenixRuntimeIT.java       |  2 +-
 .../phoenix/end2end/PowerFunctionEnd2EndIT.java |  2 +-
 .../apache/phoenix/end2end/PrimitiveTypeIT.java |  2 +-
 .../phoenix/end2end/QueryExecWithoutSCNIT.java  |  2 +-
 .../org/apache/phoenix/end2end/QueryMoreIT.java |  2 +-
 .../apache/phoenix/end2end/RTrimFunctionIT.java |  2 +-
 .../org/apache/phoenix/end2end/ReadOnlyIT.java  |  2 +-
 .../end2end/RegexpReplaceFunctionIT.java        |  2 +-
 .../phoenix/end2end/RegexpSplitFunctionIT.java  |  2 +-
 .../phoenix/end2end/RegexpSubstrFunctionIT.java |  2 +-
 .../phoenix/end2end/ReverseFunctionIT.java      |  2 +-
 .../apache/phoenix/end2end/ReverseScanIT.java   |  2 +-
 .../phoenix/end2end/RoundFloorCeilFuncIT.java   |  2 +-
 .../phoenix/end2end/SerialIteratorsIT.java      |  2 +-
 .../phoenix/end2end/ServerExceptionIT.java      |  2 +-
 .../phoenix/end2end/SignFunctionEnd2EndIT.java  |  2 +-
 .../end2end/SkipScanAfterManualSplitIT.java     |  4 +-
 .../apache/phoenix/end2end/SkipScanQueryIT.java |  2 +-
 .../phoenix/end2end/SortMergeJoinMoreIT.java    |  4 +-
 .../org/apache/phoenix/end2end/SortOrderIT.java |  2 +-
 .../phoenix/end2end/SpooledTmpFileDeleteIT.java |  2 +-
 .../phoenix/end2end/SqrtFunctionEnd2EndIT.java  |  2 +-
 .../phoenix/end2end/StatementHintsIT.java       |  2 +-
 .../org/apache/phoenix/end2end/StddevIT.java    |  2 +-
 .../apache/phoenix/end2end/StoreNullsIT.java    |  2 +-
 .../org/apache/phoenix/end2end/StringIT.java    |  2 +-
 .../end2end/StringToArrayFunctionIT.java        |  2 +-
 .../apache/phoenix/end2end/TenantIdTypeIT.java  |  2 +-
 .../end2end/TimezoneOffsetFunctionIT.java       |  2 +-
 .../phoenix/end2end/ToCharFunctionIT.java       |  2 +-
 .../phoenix/end2end/ToDateFunctionIT.java       |  2 +-
 .../org/apache/phoenix/end2end/UnionAllIT.java  |  2 +-
 .../phoenix/end2end/UpsertBigValuesIT.java      |  2 +-
 .../end2end/UpsertSelectAutoCommitIT.java       |  2 +-
 .../org/apache/phoenix/end2end/UseSchemaIT.java |  2 +-
 .../end2end/index/AsyncIndexDisabledIT.java     |  4 +-
 .../index/ChildViewsUseParentViewIndexIT.java   |  4 +-
 .../phoenix/end2end/index/DropMetadataIT.java   |  6 +-
 .../index/GlobalIndexOptimizationIT.java        |  6 +-
 .../phoenix/end2end/index/ImmutableIndexIT.java |  6 +-
 .../end2end/index/IndexExpressionIT.java        |  4 +-
 .../apache/phoenix/end2end/index/IndexIT.java   |  6 +-
 .../phoenix/end2end/index/IndexMetadataIT.java  |  4 +-
 .../phoenix/end2end/index/LocalIndexIT.java     |  4 +-
 .../phoenix/end2end/index/MutableIndexIT.java   |  6 +-
 .../phoenix/end2end/index/SaltedIndexIT.java    |  6 +-
 .../phoenix/end2end/index/ViewIndexIT.java      |  4 +-
 .../end2end/index/txn/MutableRollbackIT.java    |  6 +-
 .../phoenix/end2end/index/txn/RollbackIT.java   |  6 +-
 .../salted/SaltedTableUpsertSelectIT.java       |  4 +-
 .../salted/SaltedTableVarLengthRowKeyIT.java    |  4 +-
 .../phoenix/iterate/PhoenixQueryTimeoutIT.java  |  4 +-
 .../iterate/RoundRobinResultIteratorIT.java     |  6 +-
 .../org/apache/phoenix/rpc/UpdateCacheIT.java   |  6 +-
 .../apache/phoenix/trace/BaseTracingTestIT.java |  4 +-
 .../org/apache/phoenix/tx/TransactionIT.java    |  6 +-
 .../org/apache/phoenix/tx/TxCheckpointIT.java   |  6 +-
 .../org/apache/phoenix/flume/PhoenixSinkIT.java |  4 +-
 .../phoenix/flume/RegexEventSerializerIT.java   |  4 +-
 .../apache/phoenix/pherf/ResultBaseTestIT.java  |  4 +-
 .../apache/phoenix/pherf/SchemaReaderIT.java    |  4 +-
 .../java/org/apache/phoenix/pig/BasePigIT.java  |  6 +-
 .../phoenix/end2end/QueryServerBasicsIT.java    |  2 +-
 pom.xml                                         | 86 +++++++++++++-------
 126 files changed, 441 insertions(+), 310 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/AbsFunctionEnd2EndIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AbsFunctionEnd2EndIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AbsFunctionEnd2EndIT.java
index f053b2f..c70bed2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AbsFunctionEnd2EndIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AbsFunctionEnd2EndIT.java
@@ -34,7 +34,7 @@ import org.junit.Test;
 /**
  * End to end tests for {@link AbsFunction}
  */
-public class AbsFunctionEnd2EndIT extends BaseHBaseManagedTimeTableReuseIT {
+public class AbsFunctionEnd2EndIT extends ParallelStatsDisabledIT {
 
     private static final String TABLE_NAME = generateRandomString();
     private static final String KEY = "key";

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
index 8ec93bc..7a4e391 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
@@ -54,7 +54,7 @@ import org.junit.Test;
 
 import com.google.common.base.Objects;
 
-public class AlterMultiTenantTableWithViewsIT extends BaseHBaseManagedTimeTableReuseIT {
+public class AlterMultiTenantTableWithViewsIT extends ParallelStatsDisabledIT {
 
     private Connection getTenantConnection(String tenantId) throws Exception {
         Properties tenantProps = new Properties();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterSessionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterSessionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterSessionIT.java
index 5ad1f2a..6e0cdd5 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterSessionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterSessionIT.java
@@ -40,7 +40,7 @@ import static org.junit.Assert.assertTrue;
  * Basic tests for Alter Session Statements
  *
  */
-public class AlterSessionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class AlterSessionIT extends ParallelStatsDisabledIT {
 
     private static final String TABLE_NAME = generateRandomString();
     private static Connection testConn;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
index 857f953..2634335 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
@@ -71,7 +71,7 @@ import org.junit.Test;
  * or at the end of test class.
  *
  */
-public class AlterTableIT extends BaseHBaseManagedTimeTableReuseIT {
+public class AlterTableIT extends ParallelStatsDisabledIT {
     private String schemaName;
     private String dataTableName;
     private String indexTableName;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
index 177a5c7..64627f1 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
@@ -56,7 +56,7 @@ import org.junit.runners.Parameterized.Parameters;
 import com.google.common.collect.Maps;
 
 @RunWith(Parameterized.class)
-public class AlterTableWithViewsIT extends BaseHBaseManagedTimeTableReuseIT {
+public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
     
     private final boolean isMultiTenant;
     
@@ -73,7 +73,7 @@ public class AlterTableWithViewsIT extends BaseHBaseManagedTimeTableReuseIT {
     }
 	
 	@BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(1);
         props.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.toString(true));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java
index 017a477..1aedc0d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java
@@ -60,7 +60,7 @@ import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
 import org.mockito.Mockito;
 
-public class AppendOnlySchemaIT extends BaseHBaseManagedTimeTableReuseIT {
+public class AppendOnlySchemaIT extends ParallelStatsDisabledIT {
 
     
     private void testTableWithSameSchema(boolean notExists, boolean sameClient) throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArithmeticQueryIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArithmeticQueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArithmeticQueryIT.java
index 3f02448..87fdee6 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArithmeticQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArithmeticQueryIT.java
@@ -40,7 +40,7 @@ import com.google.common.primitives.Doubles;
 import com.google.common.primitives.Floats;
 
 
-public class ArithmeticQueryIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ArithmeticQueryIT extends ParallelStatsDisabledIT {
 
     @Test
     public void testDecimalUpsertValue() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayAppendFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayAppendFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayAppendFunctionIT.java
index 17c6b72..de42af1 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayAppendFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayAppendFunctionIT.java
@@ -26,7 +26,7 @@ import java.sql.*;
 import org.apache.phoenix.schema.TypeMismatchException;
 import org.junit.Test;
 
-public class ArrayAppendFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ArrayAppendFunctionIT extends ParallelStatsDisabledIT {
     private String initTables(Connection conn) throws Exception {
         String tableName = generateRandomString();
         String ddl = "CREATE TABLE " + tableName + " (region_name VARCHAR PRIMARY KEY,varchars VARCHAR[],integers INTEGER[],doubles DOUBLE[],bigints BIGINT[],chars CHAR(15)[],double1 DOUBLE,char1 CHAR(17),nullcheck INTEGER,chars2 CHAR(15)[])";

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayConcatFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayConcatFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayConcatFunctionIT.java
index 168000e..d2c76bd 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayConcatFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayConcatFunctionIT.java
@@ -26,7 +26,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-public class ArrayConcatFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ArrayConcatFunctionIT extends ParallelStatsDisabledIT {
 
     private String initTables(Connection conn) throws Exception {
         String tableName = generateRandomString();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayFillFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayFillFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayFillFunctionIT.java
index dd9a64a..9eece23 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayFillFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayFillFunctionIT.java
@@ -28,7 +28,7 @@ import java.sql.*;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-public class ArrayFillFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ArrayFillFunctionIT extends ParallelStatsDisabledIT {
 
     private static final String REGIONS = generateRandomString();
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayPrependFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayPrependFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayPrependFunctionIT.java
index f3386d9..1fc04e7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayPrependFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayPrependFunctionIT.java
@@ -27,7 +27,7 @@ import org.apache.phoenix.schema.TypeMismatchException;
 import org.apache.phoenix.schema.types.PhoenixArray;
 import org.junit.Test;
 
-public class ArrayPrependFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ArrayPrependFunctionIT extends ParallelStatsDisabledIT {
 
     private void initTableWithVarArray(Connection conn, String tableName, String type, Object[] objectArray, String value) throws SQLException {
         conn.createStatement().execute("CREATE TABLE " + tableName + " ( k VARCHAR PRIMARY KEY, a " + type + "[],b " + type + ")");

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayToStringFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayToStringFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayToStringFunctionIT.java
index 86ff7b6..39d6c77 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayToStringFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayToStringFunctionIT.java
@@ -29,7 +29,7 @@ import java.sql.ResultSet;
 import org.junit.Before;
 import org.junit.Test;
 
-public class ArrayToStringFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ArrayToStringFunctionIT extends ParallelStatsDisabledIT {
     private String tableName;
     private Connection conn;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArraysWithNullsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArraysWithNullsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArraysWithNullsIT.java
index 5444e7f..4d487c5 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArraysWithNullsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArraysWithNullsIT.java
@@ -26,7 +26,7 @@ import org.apache.phoenix.schema.types.PTimestamp;
 import org.apache.phoenix.schema.types.PhoenixArray;
 import org.junit.Test;
 
-public class ArraysWithNullsIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ArraysWithNullsIT extends ParallelStatsDisabledIT {
 
     @Test
     public void testArrayUpsertIntWithNulls() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/AutoCommitIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AutoCommitIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AutoCommitIT.java
index 3797884..8928248 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AutoCommitIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AutoCommitIT.java
@@ -32,7 +32,7 @@ import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
 
 
-public class AutoCommitIT extends BaseHBaseManagedTimeTableReuseIT {
+public class AutoCommitIT extends ParallelStatsDisabledIT {
 
     @Test
     public void testMutationJoin() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/AutoPartitionViewsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AutoPartitionViewsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AutoPartitionViewsIT.java
index f44c083..eb7bbdf 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AutoPartitionViewsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AutoPartitionViewsIT.java
@@ -47,7 +47,7 @@ import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
 @RunWith(Parameterized.class)
-public class AutoPartitionViewsIT extends BaseHBaseManagedTimeTableReuseIT {
+public class AutoPartitionViewsIT extends ParallelStatsDisabledIT {
 
     private String tableDDLOptions;
     private boolean isMultiTenant;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTableReuseIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTableReuseIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTableReuseIT.java
deleted file mode 100644
index b09984b..0000000
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTableReuseIT.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.phoenix.end2end;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.phoenix.query.BaseTest;
-import org.apache.phoenix.util.ReadOnlyProps;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.experimental.categories.Category;
-
-/**
- * Base class for tests that let HBase set timestamps.
- * We need to separate these from tests that rely on clients
- * to set timestamps, because we create/destroy the Phoenix tables
- * between tests and only allow a table time stamp to increase.
- * Without this separation table deletion/creation would fail.
- *
- * All tests extending this class use the mini cluster that is
- * shared by all classes extending this class
- *
- * Remember to use BaseTest.generateRandomString() to generate table
- * names for your tests otherwise there might be naming collisions between
- * other tests.
- * {@link BaseClientManagedTimeIT}.
- *
- * @since 0.1
- */
-@Category(HBaseManagedTimeTableReuseTest.class)
-public class BaseHBaseManagedTimeTableReuseIT extends BaseTest {
-    protected static Configuration getTestClusterConfig() {
-        // don't want callers to modify config.
-        return new Configuration(config);
-    }
-
-    @BeforeClass
-    public static void doSetup() throws Exception {
-        setUpTestDriver(ReadOnlyProps.EMPTY_PROPS);
-    }
-
-    @AfterClass
-    public static void doTeardown() throws Exception {
-        // no teardown since we are creating unique table names
-        // just destroy our test driver
-        destroyDriver();
-    }
-
-    @After
-    public void cleanUpAfterTest() throws Exception {
-        // no cleanup since we are using unique table names
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseParallelIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseParallelIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseParallelIT.java
new file mode 100644
index 0000000..14473f1
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseParallelIT.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.phoenix.end2end;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * Base class for tests that create unique tables for
+ * every test enabling them to be
+ * 1) run in parallel
+ * 2) not have to delete any tables
+ * 
+ * We need to separate these from tests that rely on clients
+ * to set timestamps, because we create/destroy the Phoenix tables
+ * between tests and only allow a table time stamp to increase.
+ * Without this separation table deletion/creation would fail.
+ *
+ * All tests extending this class use the mini cluster that is
+ * shared by all classes extending this class
+ *
+ * Remember to use BaseTest.generateRandomString() to generate table
+ * names for your tests otherwise there might be naming collisions between
+ * other tests.
+ */
+public abstract class BaseParallelIT extends BaseTest {
+    protected static Configuration getTestClusterConfig() {
+        // don't want callers to modify config.
+        return new Configuration(config);
+    }
+
+    @BeforeClass
+    public static void doSetup() throws Exception {
+        setUpTestDriver(ReadOnlyProps.EMPTY_PROPS);
+    }
+
+    @AfterClass
+    public static void doTeardown() throws Exception {
+        // no teardown since we are creating unique table names
+        // just destroy our test driver
+        destroyDriver();
+    }
+
+    @After
+    public void cleanUpAfterTest() throws Exception {
+        // no cleanup since we are using unique table names
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseTenantSpecificViewIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseTenantSpecificViewIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseTenantSpecificViewIndexIT.java
index e0916a9..6b53cd5 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseTenantSpecificViewIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseTenantSpecificViewIndexIT.java
@@ -35,7 +35,7 @@ import org.apache.phoenix.util.QueryUtil;
 
 import com.google.common.collect.Lists;
 
-public class BaseTenantSpecificViewIndexIT extends BaseHBaseManagedTimeTableReuseIT {
+public class BaseTenantSpecificViewIndexIT extends ParallelStatsDisabledIT {
     
     public static final String TENANT1_ID = "tenant1";
     public static final String TENANT2_ID = "tenant2";

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/BinaryRowKeyIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BinaryRowKeyIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BinaryRowKeyIT.java
index 5f656e9..02c27cd 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BinaryRowKeyIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BinaryRowKeyIT.java
@@ -34,7 +34,7 @@ import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
 
 
-public class BinaryRowKeyIT extends BaseHBaseManagedTimeTableReuseIT {
+public class BinaryRowKeyIT extends ParallelStatsDisabledIT {
 
     private static void initTableValues(String tableName) throws SQLException {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
index 7466cd3..8de2eda 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
@@ -45,7 +45,7 @@ import org.apache.phoenix.util.DateUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.junit.Test;
 
-public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeTableReuseIT {
+public class CSVCommonsLoaderIT extends ParallelStatsDisabledIT {
 
     private static final String DATATYPE_TABLE = "DATATYPE";
     private static final String DATATYPES_CSV_VALUES = "CKEY, CVARCHAR, CCHAR, CINTEGER, CDECIMAL, CUNSIGNED_INT, CBOOLEAN, CBIGINT, CUNSIGNED_LONG, CTIME, CDATE\n"

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/CbrtFunctionEnd2EndIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CbrtFunctionEnd2EndIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CbrtFunctionEnd2EndIT.java
index 25fc43f..6c5d209 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CbrtFunctionEnd2EndIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CbrtFunctionEnd2EndIT.java
@@ -34,7 +34,7 @@ import org.junit.Test;
 /**
  * End to end tests for {@link CbrtFunction}
  */
-public class CbrtFunctionEnd2EndIT extends BaseHBaseManagedTimeTableReuseIT {
+public class CbrtFunctionEnd2EndIT extends ParallelStatsDisabledIT {
 
     private static final String KEY = "key";
     private static final double ZERO = 1e-8;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/CoalesceFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CoalesceFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CoalesceFunctionIT.java
index 0c270f2..89a5fc9 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CoalesceFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CoalesceFunctionIT.java
@@ -38,7 +38,7 @@ import org.junit.Assert;
 import org.junit.Test;
 
 
-public class CoalesceFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class CoalesceFunctionIT extends ParallelStatsDisabledIT {
 
     @Test
     public void testCoalesce() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConvertTimezoneFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConvertTimezoneFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConvertTimezoneFunctionIT.java
index 1fc4b2c..be5470e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConvertTimezoneFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConvertTimezoneFunctionIT.java
@@ -36,7 +36,7 @@ import org.junit.Test;
  *
  */
 
-public class ConvertTimezoneFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ConvertTimezoneFunctionIT extends ParallelStatsDisabledIT {
 
     @Test
     public void testConvertTimezoneEurope() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
index fe02c57..97fbaf4 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
@@ -50,7 +50,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 
-public class DateTimeIT extends BaseHBaseManagedTimeTableReuseIT {
+public class DateTimeIT extends ParallelStatsDisabledIT {
 
     protected Connection conn;
     protected Date date;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeFunctionIT.java
index 041649b..424aa7b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeFunctionIT.java
@@ -35,7 +35,7 @@ import org.apache.phoenix.schema.types.PUnsignedLong;
 import org.junit.Test;
 
 
-public class DecodeFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class DecodeFunctionIT extends ParallelStatsDisabledIT {
 
 	@Test
 	public void shouldPass() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
index 5234d10..a289634 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
@@ -37,7 +37,7 @@ import org.apache.phoenix.util.QueryUtil;
 import org.junit.Test;
 
 
-public class DeleteIT extends BaseHBaseManagedTimeTableReuseIT {
+public class DeleteIT extends ParallelStatsDisabledIT {
     private static final int NUMBER_OF_ROWS = 20;
     private static final int NTH_ROW_NULL = 5;
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/DisableLocalIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DisableLocalIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DisableLocalIndexIT.java
index 38dfa8c..b34c61d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DisableLocalIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DisableLocalIndexIT.java
@@ -43,9 +43,9 @@ import org.junit.Test;
 
 import com.google.common.collect.Maps;
 
-public class DisableLocalIndexIT extends BaseHBaseManagedTimeTableReuseIT {
+public class DisableLocalIndexIT extends ParallelStatsDisabledIT {
     @BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(1);
         // Must update config before starting server

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctPrefixFilterIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctPrefixFilterIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctPrefixFilterIT.java
index e8e9e07..df10c84 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctPrefixFilterIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctPrefixFilterIT.java
@@ -35,7 +35,7 @@ import org.apache.phoenix.util.QueryUtil;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-public class DistinctPrefixFilterIT extends BaseHBaseManagedTimeTableReuseIT {
+public class DistinctPrefixFilterIT extends ParallelStatsDisabledIT {
     private static final String testTableF = generateRandomString();
     private static final String testTableV = generateRandomString();
     private static final String testSeq = testTableF + "_seq";
@@ -44,7 +44,7 @@ public class DistinctPrefixFilterIT extends BaseHBaseManagedTimeTableReuseIT {
 
     @BeforeClass
     public static void doSetup() throws Exception {
-        BaseHBaseManagedTimeTableReuseIT.doSetup();
+        ParallelStatsDisabledIT.doSetup();
 
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         conn = DriverManager.getConnection(getUrl(), props);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java
index e30c474..3fc05a7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java
@@ -59,7 +59,7 @@ import org.junit.Test;
  */
 
 
-public class DynamicColumnIT extends BaseHBaseManagedTimeTableReuseIT {
+public class DynamicColumnIT extends ParallelStatsDisabledIT {
     private static final byte[] FAMILY_NAME_A = Bytes.toBytes(SchemaUtil.normalizeIdentifier("A"));
     private static final byte[] FAMILY_NAME_B = Bytes.toBytes(SchemaUtil.normalizeIdentifier("B"));
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicFamilyIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicFamilyIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicFamilyIT.java
index 52e2a64..0b6a728 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicFamilyIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicFamilyIT.java
@@ -62,7 +62,7 @@ import org.junit.Test;
         value="RV_RETURN_VALUE_IGNORED", 
         justification="Designed to ignore.")
 
-public class DynamicFamilyIT extends BaseHBaseManagedTimeTableReuseIT {
+public class DynamicFamilyIT extends ParallelStatsDisabledIT {
     private static final String WEB_STATS = generateRandomString();
     private static final String WEB_STATS_SCHEMA_NAME = "";
     private static final byte[] A_CF = Bytes.toBytes(SchemaUtil.normalizeIdentifier("A"));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java
index c0fd38a..4cd2c6b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java
@@ -46,7 +46,7 @@ import org.junit.Test;
  */
 
 
-public class DynamicUpsertIT extends BaseHBaseManagedTimeTableReuseIT {
+public class DynamicUpsertIT extends ParallelStatsDisabledIT {
     private String tableName;
 
     @Before

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/EncodeFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/EncodeFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/EncodeFunctionIT.java
index d32b900..b61ac73 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/EncodeFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/EncodeFunctionIT.java
@@ -35,7 +35,7 @@ import org.junit.Test;
 
 import com.google.common.collect.Lists;
 
-public class EncodeFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class EncodeFunctionIT extends ParallelStatsDisabledIT {
 
     /**
      * Helper to test ENCODE function

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/EvaluationOfORIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/EvaluationOfORIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/EvaluationOfORIT.java
index 3b40d51..d976d23 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/EvaluationOfORIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/EvaluationOfORIT.java
@@ -33,7 +33,7 @@ import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
 
 
-public class EvaluationOfORIT extends BaseHBaseManagedTimeTableReuseIT{
+public class EvaluationOfORIT extends ParallelStatsDisabledIT{
 
     @Test
     public void testFalseOrFalse() throws SQLException {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExecuteStatementsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExecuteStatementsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExecuteStatementsIT.java
index 41d3ee7..f82fffe 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExecuteStatementsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExecuteStatementsIT.java
@@ -48,7 +48,7 @@ import org.apache.phoenix.util.PhoenixRuntime;
 import org.junit.Test;
 
 
-public class ExecuteStatementsIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ExecuteStatementsIT extends ParallelStatsDisabledIT {
     
     @Test
     public void testExecuteStatements() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExpFunctionEnd2EndIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExpFunctionEnd2EndIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExpFunctionEnd2EndIT.java
index 88bf763..40b0637 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExpFunctionEnd2EndIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExpFunctionEnd2EndIT.java
@@ -34,7 +34,7 @@ import org.junit.Test;
 /**
  * End to end tests for {@link ExpFunction}
  */
-public class ExpFunctionEnd2EndIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ExpFunctionEnd2EndIT extends ParallelStatsDisabledIT {
 
     private static final String KEY = "key";
     private static final double ZERO = 1e-8;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/FirstValueFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/FirstValueFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/FirstValueFunctionIT.java
index 7978291..e78c130 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/FirstValueFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/FirstValueFunctionIT.java
@@ -27,7 +27,7 @@ import java.sql.ResultSet;
 
 import org.junit.Test;
 
-public class FirstValueFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class FirstValueFunctionIT extends ParallelStatsDisabledIT {
 
     @Test
     public void signedLongAsBigInt() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/GetSetByteBitFunctionEnd2EndIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/GetSetByteBitFunctionEnd2EndIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/GetSetByteBitFunctionEnd2EndIT.java
index 734f2c4..e95ca4c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/GetSetByteBitFunctionEnd2EndIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/GetSetByteBitFunctionEnd2EndIT.java
@@ -39,7 +39,7 @@ import org.junit.Test;
  * End to end tests for {@link GetByteFunction} {@link SetByteFunction} {@link GetBitFunction}
  * {@link SetBitFunction}
  */
-public class GetSetByteBitFunctionEnd2EndIT extends BaseHBaseManagedTimeTableReuseIT {
+public class GetSetByteBitFunctionEnd2EndIT extends ParallelStatsDisabledIT {
 
     private static final String KEY = "key";
     private static final String TABLE_NAME = generateRandomString();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java
index 7cbbcbe..4830a75 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java
@@ -39,7 +39,7 @@ import org.apache.phoenix.util.QueryUtil;
 import org.junit.Test;
 
 
-public class GroupByCaseIT extends BaseHBaseManagedTimeTableReuseIT {
+public class GroupByCaseIT extends ParallelStatsDisabledIT {
     private static void initData(Connection conn, String tableName) throws SQLException {
         conn.createStatement().execute("create table " + tableName +
                 "   (id varchar not null primary key,\n" +

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/HBaseManagedTimeTableReuseTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HBaseManagedTimeTableReuseTest.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HBaseManagedTimeTableReuseTest.java
deleted file mode 100644
index f0afae4..0000000
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HBaseManagedTimeTableReuseTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you maynot use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicablelaw or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.phoenix.end2end;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.apache.phoenix.query.BaseTest;
-
-/**
- * 
- * Annotation to denote that the test lets HBase manage timestamp 
- * itself. Tests in these category do not drop HBase tables at 
- * the end of every test class. To prevent table name collisions that could happen otherwise,
- * these tests use random table names generated by {@link BaseTest#generateRandomString}.
- * 
- * Tests using a mini cluster need to be classified either 
- * as {@link HBaseManagedTimeTableReuseTest} or {@link ClientManagedTimeTest}
- * or {@link NeedsOwnMiniClusterTest} or {@link HBaseManagedTimeTest} otherwise they won't be run
- * when one runs mvn verify or mvn install.
- * 
- * @since 4.1
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-@Inherited
-public @interface HBaseManagedTimeTableReuseTest {
-
-}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/HBaseManagedTimeTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HBaseManagedTimeTest.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HBaseManagedTimeTest.java
index f57eb4c..c9eee86 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HBaseManagedTimeTest.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HBaseManagedTimeTest.java
@@ -30,7 +30,7 @@ import java.lang.annotation.Target;
  * 
  * Tests using a mini cluster need to be classified either 
  * as {@link HBaseManagedTimeTest} or {@link ClientManagedTimeTest} 
- * or {@link NeedsOwnMiniClusterTest} or {@link HBaseManagedTimeTableReuseTest}
+ * or {@link NeedsOwnMiniClusterTest} or {@link ParallelStatsDisabledTest}
  * otherwise they won't be run when one runs mvn verify or mvn install.
  * 
  * @since 4.1

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java
index 715132f..c9530a8 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java
@@ -40,7 +40,7 @@ import org.junit.Test;
 
 import com.google.common.collect.Maps;
 
-public class HashJoinMoreIT extends BaseHBaseManagedTimeTableReuseIT {
+public class HashJoinMoreIT extends ParallelStatsDisabledIT {
     private final String[] plans = new String[] {
             /*
              * testJoinWithKeyRangeOptimization()
@@ -92,7 +92,7 @@ public class HashJoinMoreIT extends BaseHBaseManagedTimeTableReuseIT {
     };
     
     @BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
         // Forces server cache to be used

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java
index 0038c3a..b0c661e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java
@@ -45,7 +45,7 @@ import com.google.common.base.Joiner;
 import com.google.common.collect.Lists;
 
 
-public class InListIT extends BaseHBaseManagedTimeTableReuseIT {
+public class InListIT extends ParallelStatsDisabledIT {
 
     @Test
     public void testLeadingPKWithTrailingRVC() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java
index c6bfe9a..87a0b4b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java
@@ -32,7 +32,7 @@ public class InMemoryOrderByIT extends OrderByIT {
     }
 
     @BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class)
+    @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class)
     public static void doSetup() throws Exception {
         Map<String,String> props = Maps.newHashMapWithExpectedSize(1);
         props.put(QueryServices.SPOOL_THRESHOLD_BYTES_ATTRIB, Integer.toString(1024*1024));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/InstrFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InstrFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InstrFunctionIT.java
index 0adcc10..e77499a 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InstrFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InstrFunctionIT.java
@@ -28,7 +28,7 @@ import java.sql.ResultSet;
 
 import org.junit.Test;
 
-public class InstrFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class InstrFunctionIT extends ParallelStatsDisabledIT {
     private void initTable(Connection conn, String tableName, String sortOrder, String s, String subStr) throws Exception {
         String ddl = "CREATE TABLE " + tableName + " (name VARCHAR NOT NULL PRIMARY KEY " + sortOrder + ", substr VARCHAR)";
         conn.createStatement().execute(ddl);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/IsNullIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IsNullIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IsNullIT.java
index 504b18c..fb12fc4 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IsNullIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IsNullIT.java
@@ -30,7 +30,7 @@ import java.sql.ResultSet;
 import org.junit.Test;
 
 
-public class IsNullIT extends BaseHBaseManagedTimeTableReuseIT {
+public class IsNullIT extends ParallelStatsDisabledIT {
     @Test
     public void testIsNullInPk() throws Exception {
         String tableName = generateRandomString();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/LastValueFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/LastValueFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/LastValueFunctionIT.java
index f8d2d32..e28f510 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/LastValueFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/LastValueFunctionIT.java
@@ -28,7 +28,7 @@ import java.sql.ResultSet;
 import org.junit.Test;
 
 
-public class LastValueFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class LastValueFunctionIT extends ParallelStatsDisabledIT {
 
     @Test
     public void unsignedLong() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java
index 2fcee45..2d6b2cb 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.java
@@ -33,7 +33,7 @@ import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-public class LikeExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class LikeExpressionIT extends ParallelStatsDisabledIT {
 
     private static final String TEST_TABLE = generateRandomString();
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/LnLogFunctionEnd2EndIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/LnLogFunctionEnd2EndIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/LnLogFunctionEnd2EndIT.java
index 466e71d..ad4efbc 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/LnLogFunctionEnd2EndIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/LnLogFunctionEnd2EndIT.java
@@ -33,7 +33,7 @@ import org.junit.Test;
 /**
  * End to end tests for {@link LnFunction} and {@link LogFunction}
  */
-public class LnLogFunctionEnd2EndIT extends BaseHBaseManagedTimeTableReuseIT {
+public class LnLogFunctionEnd2EndIT extends ParallelStatsDisabledIT {
 
     private static final String KEY = "key";
     private static final double ZERO = 1e-9;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/MD5FunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MD5FunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MD5FunctionIT.java
index 0b63aa8..b5fc2e9 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MD5FunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MD5FunctionIT.java
@@ -30,7 +30,7 @@ import java.sql.ResultSet;
 import org.junit.Test;
 
 
-public class MD5FunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class MD5FunctionIT extends ParallelStatsDisabledIT {
   
   @Test
   public void testRetrieve() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/MapReduceIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MapReduceIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MapReduceIT.java
index 275d524..0b42a1f 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MapReduceIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MapReduceIT.java
@@ -41,7 +41,7 @@ import static org.junit.Assert.*;
 /**
  * Test that our MapReduce basic tools work as expected
  */
-public class MapReduceIT extends BaseHBaseManagedTimeTableReuseIT {
+public class MapReduceIT extends ParallelStatsDisabledIT {
 
     private static final String STOCK_NAME = "STOCK_NAME";
     private static final String RECORDING_YEAR = "RECORDING_YEAR";

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/MappingTableDataTypeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MappingTableDataTypeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MappingTableDataTypeIT.java
index 3ae33fb..4bbbd03 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MappingTableDataTypeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MappingTableDataTypeIT.java
@@ -49,7 +49,7 @@ import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
 
 
-public class MappingTableDataTypeIT extends BaseHBaseManagedTimeTableReuseIT {
+public class MappingTableDataTypeIT extends ParallelStatsDisabledIT {
     @Test
     public void testMappingHbaseTableToPhoenixTable() throws Exception {
         String mtest = generateRandomString();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/MinMaxAggregateFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MinMaxAggregateFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MinMaxAggregateFunctionIT.java
index 3a5088d..c2228ff 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MinMaxAggregateFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MinMaxAggregateFunctionIT.java
@@ -23,7 +23,7 @@ import java.util.Properties;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
 
-public class MinMaxAggregateFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class MinMaxAggregateFunctionIT extends ParallelStatsDisabledIT {
 
     private static final String TABLE_NAME = generateRandomString();
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ModulusExpressionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ModulusExpressionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ModulusExpressionIT.java
index 8cb061f..06ffb16 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ModulusExpressionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ModulusExpressionIT.java
@@ -32,7 +32,7 @@ import java.sql.SQLException;
 import org.junit.Test;
 
 
-public class ModulusExpressionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ModulusExpressionIT extends ParallelStatsDisabledIT {
     
     private static final long SMALL_VALUE = 31L;
     private static final long LARGE_VALUE = 0x5dec6f3847021a9bL;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/NamespaceSchemaMappingIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NamespaceSchemaMappingIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NamespaceSchemaMappingIT.java
index 444cf0d..d092b08 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NamespaceSchemaMappingIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NamespaceSchemaMappingIT.java
@@ -44,7 +44,7 @@ import org.junit.Test;
 /*
  * since 4.8
  */
-public class NamespaceSchemaMappingIT extends BaseHBaseManagedTimeTableReuseIT {
+public class NamespaceSchemaMappingIT extends ParallelStatsDisabledIT {
     /**
      * Tests that when: There is a table created with older version of phoenix and a table created with newer version
      * having {@code QueryServices#IS_NAMESPACE_MAPPING_ENABLED} true, then there is only a flag

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/NthValueFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NthValueFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NthValueFunctionIT.java
index 697c04c..4538cd0 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NthValueFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NthValueFunctionIT.java
@@ -29,7 +29,7 @@ import java.util.ArrayList;
 import org.junit.Test;
 
 
-public class NthValueFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class NthValueFunctionIT extends ParallelStatsDisabledIT {
 
     @Test
     public void simpleTest() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/OctetLengthFunctionEnd2EndIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OctetLengthFunctionEnd2EndIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OctetLengthFunctionEnd2EndIT.java
index 7977ab5..0554814 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OctetLengthFunctionEnd2EndIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OctetLengthFunctionEnd2EndIT.java
@@ -33,7 +33,7 @@ import org.junit.Test;
 /**
  * End to end tests for {@link OctetLengthFunction}
  */
-public class OctetLengthFunctionEnd2EndIT extends BaseHBaseManagedTimeTableReuseIT {
+public class OctetLengthFunctionEnd2EndIT extends ParallelStatsDisabledIT {
 
     private static final String KEY = "key";
     private static final String TABLE_NAME = generateRandomString();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
index dcb2a0d..0f6641c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
@@ -43,7 +43,7 @@ import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
 
 
-public class OrderByIT extends BaseHBaseManagedTimeTableReuseIT {
+public class OrderByIT extends ParallelStatsDisabledIT {
 
     @Test
     public void testMultiOrderByExpr() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledIT.java
new file mode 100644
index 0000000..4575867
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledIT.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.phoenix.end2end;
+
+import org.junit.experimental.categories.Category;
+
+/**
+ * Base class for tests that do not have statistics enabled.
+ *
+ */
+@Category(ParallelStatsDisabledTest.class)
+public abstract class ParallelStatsDisabledIT extends BaseParallelIT {
+
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledTest.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledTest.java
new file mode 100644
index 0000000..bb8c19f
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledTest.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you maynot use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicablelaw or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.phoenix.query.BaseTest;
+
+/**
+ * 
+ * Annotation to denote that the test lets HBase manage timestamp 
+ * itself. Tests in these category do not drop HBase tables at 
+ * the end of every test class. To prevent table name collisions that could happen otherwise,
+ * these tests use random table names generated by {@link BaseTest#generateRandomString}.
+ * 
+ * Tests using a mini cluster need to be classified either 
+ * as {@link ParallelStatsDisabledTest} or {@link ClientManagedTimeTest}
+ * or {@link NeedsOwnMiniClusterTest} or {@link HBaseManagedTimeTest} otherwise they won't be run
+ * when one runs mvn verify or mvn install.
+ * 
+ * @since 4.1
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface ParallelStatsDisabledTest {
+
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledIT.java
new file mode 100644
index 0000000..8ecb7b4
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledIT.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.phoenix.end2end;
+
+import org.junit.experimental.categories.Category;
+
+/**
+ * 
+ * Base class for tests that have statistics enabled.
+ *
+ */
+@Category(ParallelStatsEnabledTest.class)
+public abstract class ParallelStatsEnabledIT extends BaseParallelIT {
+
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledTest.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledTest.java
new file mode 100644
index 0000000..6607b05
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledTest.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you maynot use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicablelaw or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.phoenix.query.BaseTest;
+
+/**
+ * 
+ * Annotation to denote that the test lets HBase manage timestamp 
+ * itself. Tests in these category do not drop HBase tables at 
+ * the end of every test class. To prevent table name collisions that could happen otherwise,
+ * these tests use random table names generated by {@link BaseTest#generateRandomString}.
+ * 
+ * Tests using a mini cluster need to be classified either 
+ * as {@link ParallelStatsEnabledTest} or {@link ClientManagedTimeTest}
+ * or {@link NeedsOwnMiniClusterTest} or {@link HBaseManagedTimeTest} otherwise they won't be run
+ * when one runs mvn verify or mvn install.
+ * 
+ * @since 4.1
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface ParallelStatsEnabledTest {
+
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java
index 598785c..31423db 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java
@@ -55,7 +55,7 @@ import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
 
 
-public class PercentileIT extends BaseHBaseManagedTimeTableReuseIT {
+public class PercentileIT extends ParallelStatsDisabledIT {
 
     @Test
     public void testPercentile() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
index c84a76c..1d48944 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
@@ -54,7 +54,7 @@ import org.junit.Test;
 
 import com.google.common.collect.Sets;
 
-public class PhoenixRuntimeIT extends BaseHBaseManagedTimeTableReuseIT {
+public class PhoenixRuntimeIT extends ParallelStatsDisabledIT {
     private static void assertTenantIds(Expression e, HTableInterface htable, Filter filter, String[] tenantIds) throws IOException {
         ImmutableBytesWritable ptr = new ImmutableBytesWritable();
         Scan scan = new Scan();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/PowerFunctionEnd2EndIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PowerFunctionEnd2EndIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PowerFunctionEnd2EndIT.java
index cb120bd..3535ec0 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PowerFunctionEnd2EndIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PowerFunctionEnd2EndIT.java
@@ -33,7 +33,7 @@ import org.junit.Test;
 /**
  * End to end tests for {@link PowerFunction}
  */
-public class PowerFunctionEnd2EndIT extends BaseHBaseManagedTimeTableReuseIT {
+public class PowerFunctionEnd2EndIT extends ParallelStatsDisabledIT {
 
     private static final String KEY = "key";
     private static final double ZERO = 1e-9;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/PrimitiveTypeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PrimitiveTypeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PrimitiveTypeIT.java
index 5891a62..2b66118 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PrimitiveTypeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PrimitiveTypeIT.java
@@ -32,7 +32,7 @@ import org.apache.phoenix.util.TestUtil;
 import org.junit.Test;
 
 
-public class PrimitiveTypeIT extends BaseHBaseManagedTimeTableReuseIT {
+public class PrimitiveTypeIT extends ParallelStatsDisabledIT {
 
     private static final Properties PROPS = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryExecWithoutSCNIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryExecWithoutSCNIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryExecWithoutSCNIT.java
index 6819e57..51d08d8 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryExecWithoutSCNIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryExecWithoutSCNIT.java
@@ -32,7 +32,7 @@ import java.util.Properties;
 import org.junit.Test;
 
 
-public class QueryExecWithoutSCNIT extends BaseHBaseManagedTimeTableReuseIT {
+public class QueryExecWithoutSCNIT extends ParallelStatsDisabledIT {
     @Test
     public void testScanNoSCN() throws Exception {
         long ts = System.currentTimeMillis();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java
index 6da9144..d87b954 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java
@@ -44,7 +44,7 @@ import org.junit.Test;
 import com.google.common.collect.Lists;
 
 
-public class QueryMoreIT extends BaseHBaseManagedTimeTableReuseIT {
+public class QueryMoreIT extends ParallelStatsDisabledIT {
     
     private String dataTableName;
     //queryAgainstTenantSpecificView = true, dataTableSalted = true 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/RTrimFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RTrimFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RTrimFunctionIT.java
index f691dd0..b425476 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RTrimFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RTrimFunctionIT.java
@@ -33,7 +33,7 @@ import org.apache.phoenix.util.QueryUtil;
 import org.junit.Test;
 
 
-public class RTrimFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class RTrimFunctionIT extends ParallelStatsDisabledIT {
     
     @Test
     public void testWithFixedLengthAscPK() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReadOnlyIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReadOnlyIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReadOnlyIT.java
index 0b86af0..ed3c4f9 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReadOnlyIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReadOnlyIT.java
@@ -32,7 +32,7 @@ import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
 
 
-public class ReadOnlyIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ReadOnlyIT extends ParallelStatsDisabledIT {
 
     @Test
     public void testConnectionReadOnly() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpReplaceFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpReplaceFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpReplaceFunctionIT.java
index 5ce04eb..037d48d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpReplaceFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpReplaceFunctionIT.java
@@ -33,7 +33,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 
-public class RegexpReplaceFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class RegexpReplaceFunctionIT extends ParallelStatsDisabledIT {
 
     private int id;
     protected  String tableName;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSplitFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSplitFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSplitFunctionIT.java
index 806d589..f9a0873 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSplitFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSplitFunctionIT.java
@@ -34,7 +34,7 @@ import java.sql.Types;
 import org.junit.Test;
 
 
-public class RegexpSplitFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class RegexpSplitFunctionIT extends ParallelStatsDisabledIT {
 
     private String tableName;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSubstrFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSubstrFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSubstrFunctionIT.java
index 777ccd1..889451e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSubstrFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpSubstrFunctionIT.java
@@ -33,7 +33,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 
-public class RegexpSubstrFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class RegexpSubstrFunctionIT extends ParallelStatsDisabledIT {
 
     private int id;
     String tableName;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReverseFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReverseFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReverseFunctionIT.java
index 3a1f8c2..d2c89dc 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReverseFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReverseFunctionIT.java
@@ -30,7 +30,7 @@ import java.sql.ResultSet;
 import org.junit.Test;
 
 
-public class ReverseFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ReverseFunctionIT extends ParallelStatsDisabledIT {
 
     private String initTable(Connection conn, String sortOrder, String s) throws Exception {
         String reverseTest =  generateRandomString();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReverseScanIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReverseScanIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReverseScanIT.java
index ff29840..16ccc53 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReverseScanIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReverseScanIT.java
@@ -52,7 +52,7 @@ import org.junit.Test;
 import com.google.common.collect.Maps;
 
 
-public class ReverseScanIT extends BaseHBaseManagedTimeTableReuseIT {
+public class ReverseScanIT extends ParallelStatsDisabledIT {
 
     private static byte[][] getSplitsAtRowKeys(String tenantId) {
         return new byte[][] { 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b868392/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFuncIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFuncIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFuncIT.java
index a5251a9..c94cf50 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFuncIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFuncIT.java
@@ -51,7 +51,7 @@ import com.google.common.primitives.Floats;
  * End to end tests for {@link RoundFunction}, {@link FloorFunction}, {@link CeilFunction} 
  *
  */
-public class RoundFloorCeilFuncIT extends BaseHBaseManagedTimeTableReuseIT {
+public class RoundFloorCeilFuncIT extends ParallelStatsDisabledIT {
     private static final long millisPart = 660;
     private static final int nanosPart = 500100;
     private static final BigDecimal decimalUpserted = BigDecimal.valueOf(1.264);


[31/47] phoenix git commit: PHOENIX-3253 Make changes to BaseHBaseTimeManagedIT tests to support method level parallelization

Posted by ma...@apache.org.
PHOENIX-3253 Make changes to BaseHBaseTimeManagedIT tests to support method level parallelization


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

Branch: refs/heads/calcite
Commit: 1a3bd43a595f3ba23db823486f476c31e890b3d2
Parents: a4ebcfd
Author: James Taylor <ja...@apache.org>
Authored: Thu Sep 15 15:57:38 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Thu Sep 15 15:57:38 2016 -0700

----------------------------------------------------------------------
 .../phoenix/trace/PhoenixTracingEndToEndIT.java | 27 ++++++++++----------
 .../org/apache/phoenix/tx/TransactionIT.java    |  5 ++--
 2 files changed, 17 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/1a3bd43a/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTracingEndToEndIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTracingEndToEndIT.java b/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTracingEndToEndIT.java
index 2e21846..d6ca23b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTracingEndToEndIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/trace/PhoenixTracingEndToEndIT.java
@@ -44,7 +44,6 @@ import org.apache.htrace.impl.ProbabilitySampler;
 import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.metrics.Metrics;
-import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.trace.TraceReader.SpanInfo;
 import org.apache.phoenix.trace.TraceReader.TraceHolder;
 import org.junit.After;
@@ -61,8 +60,8 @@ public class PhoenixTracingEndToEndIT extends BaseTracingTestIT {
 
     private static final Log LOG = LogFactory.getLog(PhoenixTracingEndToEndIT.class);
     private static final int MAX_RETRIES = 10;
-    private final String table = "ENABLED_FOR_LOGGING";
-    private final String index = "ENABALED_FOR_LOGGING_INDEX";
+    private String enabledForLoggingTable;
+    private String enableForLoggingIndex;
 
     private DisableableMetricsWriter sink;
     private String tableName;
@@ -74,6 +73,8 @@ public class PhoenixTracingEndToEndIT extends BaseTracingTestIT {
         tableName = generateRandomString();
         pWriter.initForTesting(conn, tableName);
         sink = new DisableableMetricsWriter(pWriter);
+        enabledForLoggingTable = "ENABLED_FOR_LOGGING_" + generateRandomString();
+        enableForLoggingIndex = "ENABALED_FOR_LOGGING_INDEX" + generateRandomString();
 
         TracingTestUtil.registerSink(sink);
     }
@@ -184,7 +185,7 @@ public class PhoenixTracingEndToEndIT extends BaseTracingTestIT {
         // trace the requests we send
         Connection traceable = getTracingConnection();
         LOG.debug("Doing dummy the writes to the tracked table");
-        String insert = "UPSERT INTO " + table + " VALUES (?, ?)";
+        String insert = "UPSERT INTO " + enabledForLoggingTable + " VALUES (?, ?)";
         PreparedStatement stmt = traceable.prepareStatement(insert);
         stmt.setString(1, "key1");
         stmt.setLong(2, 1);
@@ -222,7 +223,7 @@ public class PhoenixTracingEndToEndIT extends BaseTracingTestIT {
             public boolean foundTrace(TraceHolder trace, SpanInfo span) {
                 String traceInfo = trace.toString();
                 // skip logging traces that are just traces about tracing
-                if (traceInfo.contains(QueryServicesOptions.DEFAULT_TRACING_STATS_TABLE_NAME)) {
+                if (traceInfo.contains(tableName)) {
                     return false;
                 }
                 return traceInfo.contains("Completing index");
@@ -235,7 +236,7 @@ public class PhoenixTracingEndToEndIT extends BaseTracingTestIT {
     private void createTestTable(Connection conn, boolean withIndex) throws SQLException {
         // create a dummy table
         String ddl =
-                "create table if not exists " + table + "(" + "k varchar not null, " + "c1 bigint"
+                "create table if not exists " + enabledForLoggingTable + "(" + "k varchar not null, " + "c1 bigint"
                         + " CONSTRAINT pk PRIMARY KEY (k))";
         conn.createStatement().execute(ddl);
 
@@ -244,7 +245,7 @@ public class PhoenixTracingEndToEndIT extends BaseTracingTestIT {
             return;
         }
         // create an index on the table - we know indexing has some basic tracing
-        ddl = "CREATE INDEX IF NOT EXISTS " + index + " on " + table + " (c1)";
+        ddl = "CREATE INDEX IF NOT EXISTS " + enableForLoggingIndex + " on " + enabledForLoggingTable + " (c1)";
         conn.createStatement().execute(ddl);
         conn.commit();
     }
@@ -264,7 +265,7 @@ public class PhoenixTracingEndToEndIT extends BaseTracingTestIT {
 
         // update the table, but don't trace these, to simplify the traces we read
         LOG.debug("Doing dummy the writes to the tracked table");
-        String insert = "UPSERT INTO " + table + " VALUES (?, ?)";
+        String insert = "UPSERT INTO " + enabledForLoggingTable + " VALUES (?, ?)";
         PreparedStatement stmt = conn.prepareStatement(insert);
         stmt.setString(1, "key1");
         stmt.setLong(2, 1);
@@ -280,7 +281,7 @@ public class PhoenixTracingEndToEndIT extends BaseTracingTestIT {
         conn.rollback();
 
         // do a scan of the table
-        String read = "SELECT * FROM " + table;
+        String read = "SELECT * FROM " + enabledForLoggingTable;
         ResultSet results = traceable.createStatement().executeQuery(read);
         assertTrue("Didn't get first result", results.next());
         assertTrue("Didn't get second result", results.next());
@@ -314,7 +315,7 @@ public class PhoenixTracingEndToEndIT extends BaseTracingTestIT {
 
         // update the table, but don't trace these, to simplify the traces we read
         LOG.debug("Doing dummy the writes to the tracked table");
-        String insert = "UPSERT INTO " + table + " VALUES (?, ?)";
+        String insert = "UPSERT INTO " + enabledForLoggingTable + " VALUES (?, ?)";
         PreparedStatement stmt = conn.prepareStatement(insert);
         stmt.setString(1, "key1");
         stmt.setLong(2, 1);
@@ -330,7 +331,7 @@ public class PhoenixTracingEndToEndIT extends BaseTracingTestIT {
         conn.rollback();
 
         // do a scan of the table
-        String read = "SELECT COUNT(*) FROM " + table;
+        String read = "SELECT COUNT(*) FROM " + enabledForLoggingTable;
         ResultSet results = traceable.createStatement().executeQuery(read);
         assertTrue("Didn't get count result", results.next());
         // make sure we got the expected count
@@ -367,7 +368,7 @@ public class PhoenixTracingEndToEndIT extends BaseTracingTestIT {
 
         // update the table, but don't trace these, to simplify the traces we read
         LOG.debug("Doing dummy the writes to the tracked table");
-        String insert = "UPSERT INTO " + table + " VALUES (?, ?)";
+        String insert = "UPSERT INTO " + enabledForLoggingTable + " VALUES (?, ?)";
         PreparedStatement stmt = conn.prepareStatement(insert);
         stmt.setString(1, "key1");
         stmt.setLong(2, 1);
@@ -383,7 +384,7 @@ public class PhoenixTracingEndToEndIT extends BaseTracingTestIT {
         conn.rollback();
 
         // do a scan of the table
-        String read = "SELECT * FROM " + table;
+        String read = "SELECT * FROM " + enabledForLoggingTable;
         ResultSet results = traceable.createStatement().executeQuery(read);
         assertTrue("Didn't get first result", results.next());
         assertTrue("Didn't get second result", results.next());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1a3bd43a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
index 3d94eba..cbd1472 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
@@ -788,9 +788,10 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
         String transTableName = generateRandomString();
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + transTableName;
         String selectSQL = "SELECT * FROM " + fullTableName;
-        try (Connection conn1 = DriverManager.getConnection(getUrl()); 
+        try (Connection conn = DriverManager.getConnection(getUrl());
+                Connection conn1 = DriverManager.getConnection(getUrl()); 
                 Connection conn2 = DriverManager.getConnection(getUrl())) {
-            createTable(conn1, fullTableName);
+            createTable(conn, fullTableName);
             conn1.setAutoCommit(false);
             conn2.setAutoCommit(true);
             ResultSet rs = conn1.createStatement().executeQuery(selectSQL);


[37/47] phoenix git commit: PHOENIX-3290 Move and/or combine as many NeedsOwnCluster tests to bring down test run time

Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
index e09dcea..857f953 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
@@ -35,8 +35,6 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Collections;
-import java.util.Map;
 import java.util.Properties;
 
 import org.apache.hadoop.hbase.HColumnDescriptor;
@@ -48,20 +46,18 @@ import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.ResultScanner;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.coprocessor.MetaDataProtocol;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.query.BaseTest;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTableKey;
 import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.util.IndexUtil;
-import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
 import org.apache.phoenix.util.SchemaUtil;
-import org.junit.BeforeClass;
+import org.junit.Before;
 import org.junit.Test;
 
 /**
@@ -75,19 +71,24 @@ import org.junit.Test;
  * or at the end of test class.
  *
  */
-public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
-    public static final String SCHEMA_NAME = "";
-    public static final String DATA_TABLE_NAME = "T";
-    public static final String INDEX_TABLE_NAME = "I";
-    public static final String LOCAL_INDEX_TABLE_NAME = "LI";
-    public static final String DATA_TABLE_FULL_NAME = SchemaUtil.getTableName(SCHEMA_NAME, "T");
-    public static final String INDEX_TABLE_FULL_NAME = SchemaUtil.getTableName(SCHEMA_NAME, "I");
-    public static final String LOCAL_INDEX_TABLE_FULL_NAME = SchemaUtil.getTableName(SCHEMA_NAME, "LI");
-
-    @BeforeClass
-    public static void doSetup() throws Exception {
-        Map<String, String> props = Collections.emptyMap();
-        setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+public class AlterTableIT extends BaseHBaseManagedTimeTableReuseIT {
+    private String schemaName;
+    private String dataTableName;
+    private String indexTableName;
+    private String localIndexTableName;
+    private String dataTableFullName;
+    private String indexTableFullName;
+    private String localIndexTableFullName;
+
+    @Before
+    public void setupTableNames() throws Exception {
+        schemaName = "";
+        dataTableName = generateRandomString();
+        indexTableName = "I_" + generateRandomString();
+        localIndexTableName = "LI_" + generateRandomString();
+        dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+        indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
+        localIndexTableFullName = SchemaUtil.getTableName(schemaName, localIndexTableName);
     }
 
     @Test
@@ -97,12 +98,12 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE test_table " +
+            String ddl = "CREATE TABLE  " + dataTableFullName +
                     "  (a_string varchar not null, a_binary varbinary not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string, a_binary))\n";
             createTestTable(getUrl(), ddl);
 
-            ddl = "ALTER TABLE test_table ADD b_string VARCHAR NULL PRIMARY KEY";
+            ddl = "ALTER TABLE " + dataTableFullName + " ADD b_string VARCHAR NULL PRIMARY KEY";
             PreparedStatement stmt = conn.prepareStatement(ddl);
             stmt.execute();
             fail("Should have caught bad alter.");
@@ -114,27 +115,6 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     }
 
     @Test
-    public void testAddColsIntoSystemTable() throws Exception {
-        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
-                Long.toString(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP + 1));
-        Connection conn = DriverManager.getConnection(getUrl(), props);
-
-      try{
-        conn.createStatement().executeUpdate("ALTER TABLE " + PhoenixDatabaseMetaData.SYSTEM_CATALOG +
-          " ADD IF NOT EXISTS testNewColumn integer");
-        String query = "SELECT testNewColumn FROM " + PhoenixDatabaseMetaData.SYSTEM_CATALOG;
-        try {
-          conn.createStatement().executeQuery(query);
-        } catch(SQLException e) {
-          assertFalse("testNewColumn wasn't created successfully:" + e, true);
-        }
-      } finally {
-        conn.close();
-      }
-    }
-
-    @Test
     public void testDropSystemTable() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
@@ -159,12 +139,12 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE test_table " +
+            String ddl = "CREATE TABLE " + dataTableFullName +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             conn.createStatement().execute(ddl);
 
-            String dml = "UPSERT INTO test_table VALUES(?)";
+            String dml = "UPSERT INTO " + dataTableFullName + " VALUES(?)";
             PreparedStatement stmt = conn.prepareStatement(dml);
             stmt.setString(1, "b");
             stmt.execute();
@@ -172,7 +152,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
             stmt.execute();
             conn.commit();
 
-            String query = "SELECT * FROM test_table";
+            String query = "SELECT * FROM " + dataTableFullName;
             ResultSet rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals("a",rs.getString(1));
@@ -180,35 +160,35 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
             assertEquals("b",rs.getString(1));
             assertFalse(rs.next());
 
-            ddl = "ALTER TABLE test_table ADD  b_string VARCHAR  NULL PRIMARY KEY  ";
+            ddl = "ALTER TABLE " + dataTableFullName + " ADD  b_string VARCHAR  NULL PRIMARY KEY  ";
             conn.createStatement().execute(ddl);
 
-            query = "SELECT * FROM test_table WHERE a_string = 'a' AND b_string IS NULL";
+            query = "SELECT * FROM " + dataTableFullName + " WHERE a_string = 'a' AND b_string IS NULL";
             rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals("a",rs.getString(1));
             assertFalse(rs.next());
 
-            dml = "UPSERT INTO test_table VALUES(?)";
+            dml = "UPSERT INTO " + dataTableFullName + " VALUES(?)";
             stmt = conn.prepareStatement(dml);
             stmt.setString(1, "c");
             stmt.execute();
             conn.commit();
 
-            query = "SELECT * FROM test_table WHERE a_string = 'c' AND b_string IS NULL";
+            query = "SELECT * FROM " + dataTableFullName + " WHERE a_string = 'c' AND b_string IS NULL";
             rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals("c",rs.getString(1));
             assertFalse(rs.next());
 
-            dml = "UPSERT INTO test_table(a_string,col1) VALUES(?,?)";
+            dml = "UPSERT INTO " + dataTableFullName + "(a_string,col1) VALUES(?,?)";
             stmt = conn.prepareStatement(dml);
             stmt.setString(1, "a");
             stmt.setInt(2, 5);
             stmt.execute();
             conn.commit();
 
-            query = "SELECT a_string,col1 FROM test_table WHERE a_string = 'a' AND b_string IS NULL";
+            query = "SELECT a_string,col1 FROM " + dataTableFullName + " WHERE a_string = 'a' AND b_string IS NULL";
             rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals("a",rs.getString(1));
@@ -226,14 +206,14 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     public void testSetPropertyAndAddColumnForNewColumnFamily() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
-        String ddl = "CREATE TABLE SETPROPNEWCF " +
+        String ddl = "CREATE TABLE  " + dataTableFullName +
                 "  (a_string varchar not null, col1 integer" +
                 "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
         try {
             conn.createStatement().execute(ddl);
-            conn.createStatement().execute("ALTER TABLE SETPROPNEWCF ADD CF.col2 integer CF.IN_MEMORY=true");
+            conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " ADD CF.col2 integer CF.IN_MEMORY=true");
             try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-                HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("SETPROPNEWCF")).getColumnFamilies();
+                HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName)).getColumnFamilies();
                 assertEquals(2, columnFamilies.length);
                 assertEquals("0", columnFamilies[0].getNameAsString());
                 assertFalse(columnFamilies[0].isInMemory());
@@ -245,8 +225,8 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         }
     }
 
-    private static void assertIndexExists(Connection conn, boolean exists) throws SQLException {
-        ResultSet rs = conn.getMetaData().getIndexInfo(null, SCHEMA_NAME, DATA_TABLE_NAME, false, false);
+    private void assertIndexExists(Connection conn, boolean exists) throws SQLException {
+        ResultSet rs = conn.getMetaData().getIndexInfo(null, schemaName, dataTableName, false, false);
         assertEquals(exists, rs.next());
     }
 
@@ -262,23 +242,23 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
 
         // make sure that the tables are empty, but reachable
         conn.createStatement().execute(
-          "CREATE TABLE " + DATA_TABLE_FULL_NAME
+          "CREATE TABLE " + dataTableFullName
               + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
-        query = "SELECT * FROM " + DATA_TABLE_FULL_NAME;
+        query = "SELECT * FROM " + dataTableFullName;
         rs = conn.createStatement().executeQuery(query);
         assertFalse(rs.next());
 
         conn.createStatement().execute(
-          "CREATE INDEX " + INDEX_TABLE_NAME + " ON " + DATA_TABLE_FULL_NAME + " (v1, v2)");
+          "CREATE INDEX " + indexTableName + " ON " + dataTableFullName + " (v1, v2)");
         conn.createStatement().execute(
-            "CREATE LOCAL INDEX " + LOCAL_INDEX_TABLE_NAME + " ON " + DATA_TABLE_FULL_NAME + " (v1, v2)");
+            "CREATE LOCAL INDEX " + localIndexTableName + " ON " + dataTableFullName + " (v1, v2)");
 
-        query = "SELECT * FROM " + INDEX_TABLE_FULL_NAME;
+        query = "SELECT * FROM " + indexTableFullName;
         rs = conn.createStatement().executeQuery(query);
         assertFalse(rs.next());
 
         // load some data into the table
-        stmt = conn.prepareStatement("UPSERT INTO " + DATA_TABLE_FULL_NAME + " VALUES(?,?,?)");
+        stmt = conn.prepareStatement("UPSERT INTO " + dataTableFullName + " VALUES(?,?,?)");
         stmt.setString(1, "a");
         stmt.setString(2, "x");
         stmt.setString(3, "1");
@@ -286,10 +266,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         conn.commit();
 
         assertIndexExists(conn,true);
-        conn.createStatement().execute("ALTER TABLE " + DATA_TABLE_FULL_NAME + " DROP COLUMN v1");
+        conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " DROP COLUMN v1");
         assertIndexExists(conn,false);
 
-        query = "SELECT * FROM " + DATA_TABLE_FULL_NAME;
+        query = "SELECT * FROM " + dataTableFullName;
         rs = conn.createStatement().executeQuery(query);
         assertTrue(rs.next());
         assertEquals("a",rs.getString(1));
@@ -297,13 +277,13 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         assertFalse(rs.next());
 
         // load some data into the table
-        stmt = conn.prepareStatement("UPSERT INTO " + DATA_TABLE_FULL_NAME + " VALUES(?,?)");
+        stmt = conn.prepareStatement("UPSERT INTO " + dataTableFullName + " VALUES(?,?)");
         stmt.setString(1, "a");
         stmt.setString(2, "2");
         stmt.execute();
         conn.commit();
 
-        query = "SELECT * FROM " + DATA_TABLE_FULL_NAME;
+        query = "SELECT * FROM " + dataTableFullName;
         rs = conn.createStatement().executeQuery(query);
         assertTrue(rs.next());
         assertEquals("a",rs.getString(1));
@@ -322,27 +302,27 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
 
         // make sure that the tables are empty, but reachable
         conn.createStatement().execute(
-          "CREATE TABLE " + DATA_TABLE_FULL_NAME
+          "CREATE TABLE " + dataTableFullName
               + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR, v3 VARCHAR)");
-        String dataTableQuery = "SELECT * FROM " + DATA_TABLE_FULL_NAME;
+        String dataTableQuery = "SELECT * FROM " + dataTableFullName;
         rs = conn.createStatement().executeQuery(dataTableQuery);
         assertFalse(rs.next());
 
         conn.createStatement().execute(
-          "CREATE INDEX " + INDEX_TABLE_NAME + " ON " + DATA_TABLE_FULL_NAME + " (v1) include (v2, v3)");
+          "CREATE INDEX " + indexTableName + " ON " + dataTableFullName + " (v1) include (v2, v3)");
         conn.createStatement().execute(
-            "CREATE LOCAL INDEX " + LOCAL_INDEX_TABLE_NAME + " ON " + DATA_TABLE_FULL_NAME + " (v1) include (v2, v3)");
+            "CREATE LOCAL INDEX " + localIndexTableName + " ON " + dataTableFullName + " (v1) include (v2, v3)");
         rs = conn.createStatement().executeQuery(dataTableQuery);
         assertFalse(rs.next());
-        String indexTableQuery = "SELECT * FROM " + INDEX_TABLE_NAME;
+        String indexTableQuery = "SELECT * FROM " + indexTableName;
         rs = conn.createStatement().executeQuery(indexTableQuery);
         assertFalse(rs.next());
-        String localIndexTableQuery = "SELECT * FROM " + LOCAL_INDEX_TABLE_FULL_NAME;
+        String localIndexTableQuery = "SELECT * FROM " + localIndexTableFullName;
         rs = conn.createStatement().executeQuery(localIndexTableQuery);
         assertFalse(rs.next());
 
         // load some data into the table
-        stmt = conn.prepareStatement("UPSERT INTO " + DATA_TABLE_FULL_NAME + " VALUES(?,?,?,?)");
+        stmt = conn.prepareStatement("UPSERT INTO " + dataTableFullName + " VALUES(?,?,?,?)");
         stmt.setString(1, "a");
         stmt.setString(2, "x");
         stmt.setString(3, "1");
@@ -351,12 +331,12 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         conn.commit();
 
         assertIndexExists(conn,true);
-        conn.createStatement().execute("ALTER TABLE " + DATA_TABLE_FULL_NAME + " DROP COLUMN v2");
+        conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " DROP COLUMN v2");
         assertIndexExists(conn,true);
 
         // verify data table rows
         Scan scan = new Scan();
-        HTable table = (HTable) conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(DATA_TABLE_FULL_NAME));
+        HTable table = (HTable) conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(dataTableFullName));
         ResultScanner results = table.getScanner(scan);
         for (Result res : results) {
         	assertNull("Column value was not deleted",res.getValue(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, Bytes.toBytes("V2")));
@@ -371,7 +351,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         
         // verify index table rows
         scan = new Scan();
-        table = (HTable) conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(INDEX_TABLE_FULL_NAME));
+        table = (HTable) conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(indexTableFullName));
         results = table.getScanner(scan);
         for (Result res : results) {
         	assertNull("Column value was not deleted",res.getValue(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, Bytes.toBytes("0:V2")));
@@ -393,7 +373,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         assertFalse(rs.next());
 
         // load some data into the table
-        stmt = conn.prepareStatement("UPSERT INTO " + DATA_TABLE_FULL_NAME + " VALUES(?,?,?)");
+        stmt = conn.prepareStatement("UPSERT INTO " + dataTableFullName + " VALUES(?,?,?)");
         stmt.setString(1, "a");
         stmt.setString(2, "y");
         stmt.setString(3, "k");
@@ -437,20 +417,20 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
 
         // make sure that the tables are empty, but reachable
         conn.createStatement().execute(
-          "CREATE TABLE " + DATA_TABLE_FULL_NAME
+          "CREATE TABLE " + dataTableFullName
               + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
-        query = "SELECT * FROM " + DATA_TABLE_FULL_NAME;
+        query = "SELECT * FROM " + dataTableFullName;
         rs = conn.createStatement().executeQuery(query);
         assertFalse(rs.next());
 
         conn.createStatement().execute(
-          "CREATE INDEX " + INDEX_TABLE_NAME + " ON " + DATA_TABLE_FULL_NAME + " (v1) include (v2)");
-        query = "SELECT * FROM " + INDEX_TABLE_FULL_NAME;
+          "CREATE INDEX " + indexTableName + " ON " + dataTableFullName + " (v1) include (v2)");
+        query = "SELECT * FROM " + indexTableFullName;
         rs = conn.createStatement().executeQuery(query);
         assertFalse(rs.next());
 
         // load some data into the table
-        stmt = conn.prepareStatement("UPSERT INTO " + DATA_TABLE_FULL_NAME + " VALUES(?,?,?)");
+        stmt = conn.prepareStatement("UPSERT INTO " + dataTableFullName + " VALUES(?,?,?)");
         stmt.setString(1, "a");
         stmt.setString(2, "x");
         stmt.setString(3, "1");
@@ -458,8 +438,8 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         conn.commit();
 
         assertIndexExists(conn,true);
-        conn.createStatement().execute("ALTER TABLE " + DATA_TABLE_FULL_NAME + " ADD v3 VARCHAR, k2 DECIMAL PRIMARY KEY, k3 DECIMAL PRIMARY KEY");
-        rs = conn.getMetaData().getPrimaryKeys("", SCHEMA_NAME, DATA_TABLE_NAME);
+        conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " ADD v3 VARCHAR, k2 DECIMAL PRIMARY KEY, k3 DECIMAL PRIMARY KEY");
+        rs = conn.getMetaData().getPrimaryKeys("", schemaName, dataTableName);
         assertTrue(rs.next());
         assertEquals("K",rs.getString("COLUMN_NAME"));
         assertEquals(1, rs.getShort("KEY_SEQ"));
@@ -471,7 +451,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         assertEquals(3, rs.getShort("KEY_SEQ"));
         assertFalse(rs.next());
 
-        rs = conn.getMetaData().getPrimaryKeys("", SCHEMA_NAME, INDEX_TABLE_NAME);
+        rs = conn.getMetaData().getPrimaryKeys("", schemaName, indexTableName);
         assertTrue(rs.next());
         assertEquals(QueryConstants.DEFAULT_COLUMN_FAMILY + IndexUtil.INDEX_COLUMN_NAME_SEP + "V1",rs.getString("COLUMN_NAME"));
         assertEquals(1, rs.getShort("KEY_SEQ"));
@@ -486,7 +466,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         assertEquals(4, rs.getShort("KEY_SEQ"));
         assertFalse(rs.next());
 
-        query = "SELECT * FROM " + DATA_TABLE_FULL_NAME;
+        query = "SELECT * FROM " + dataTableFullName;
         rs = conn.createStatement().executeQuery(query);
         assertTrue(rs.next());
         assertEquals("a",rs.getString(1));
@@ -496,7 +476,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         assertFalse(rs.next());
 
         // load some data into the table
-        stmt = conn.prepareStatement("UPSERT INTO " + DATA_TABLE_FULL_NAME + "(K,K2,V1,V2,K3) VALUES(?,?,?,?,?)");
+        stmt = conn.prepareStatement("UPSERT INTO " + dataTableFullName + "(K,K2,V1,V2,K3) VALUES(?,?,?,?,?)");
         stmt.setString(1, "b");
         stmt.setBigDecimal(2, BigDecimal.valueOf(2));
         stmt.setString(3, "y");
@@ -505,7 +485,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         stmt.execute();
         conn.commit();
 
-        query = "SELECT k,k2,k3 FROM " + DATA_TABLE_FULL_NAME + " WHERE v1='y'";
+        query = "SELECT k,k2,k3 FROM " + dataTableFullName + " WHERE v1='y'";
         rs = conn.createStatement().executeQuery(query);
         assertTrue(rs.next());
         assertEquals("b",rs.getString(1));
@@ -521,7 +501,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE MESSAGES (\n" +
+            String ddl = "CREATE TABLE " + dataTableFullName + "(\n" +
             		"        SENDER_ID UNSIGNED_LONG NOT NULL,\n" +
             		"        RECIPIENT_ID UNSIGNED_LONG NOT NULL,\n" +
             		"        M_TIMESTAMP DATE  NOT NULL,\n" +
@@ -537,10 +517,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
             		"SALT_BUCKETS=4";
             conn.createStatement().execute(ddl);
 
-            ddl = "ALTER TABLE MESSAGES SET IMMUTABLE_ROWS=true";
+            ddl = "ALTER TABLE " + dataTableFullName + " SET IMMUTABLE_ROWS=true";
             conn.createStatement().execute(ddl);
 
-            conn.createStatement().executeQuery("select count(*) from messages").next();
+            conn.createStatement().executeQuery("select count(*) from " + dataTableFullName).next();
 
         } finally {
             conn.close();
@@ -555,7 +535,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE MESSAGES (\n" +
+            String ddl = "CREATE TABLE " + dataTableFullName + " (\n" +
                     "        SENDER_ID UNSIGNED_LONG NOT NULL,\n" +
                     "        RECIPIENT_ID UNSIGNED_LONG NOT NULL,\n" +
                     "        M_TIMESTAMP DATE  NOT NULL,\n" +
@@ -571,10 +551,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                     "SALT_BUCKETS=4";
             conn.createStatement().execute(ddl);
 
-            ddl = "ALTER TABLE MESSAGES DROP COLUMN B.JSON";
+            ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN B.JSON";
             conn.createStatement().execute(ddl);
 
-            conn.createStatement().executeQuery("select count(*) from messages").next();
+            conn.createStatement().executeQuery("select count(*) from " + dataTableFullName).next();
         } finally {
             conn.close();
         }
@@ -589,12 +569,12 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         conn.setAutoCommit(false);
 
         try {
-            String ddl = "CREATE TABLE test_table " +
+            String ddl = "CREATE TABLE " + dataTableFullName +
                     "  (a_string varchar not null, col1 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             conn.createStatement().execute(ddl);
 
-            String dml = "UPSERT INTO test_table VALUES(?)";
+            String dml = "UPSERT INTO " + dataTableFullName + " VALUES(?)";
             PreparedStatement stmt = conn.prepareStatement(dml);
             stmt.setString(1, "b");
             stmt.execute();
@@ -602,7 +582,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
             stmt.execute();
             conn.commit();
 
-            String query = "SELECT * FROM test_table";
+            String query = "SELECT * FROM " + dataTableFullName;
             ResultSet rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals("a",rs.getString(1));
@@ -611,15 +591,15 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
             assertFalse(rs.next());
 
 
-            query = "SELECT * FROM test_table WHERE a_string = 'a' ";
+            query = "SELECT * FROM " + dataTableFullName + " WHERE a_string = 'a' ";
             rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals("a",rs.getString(1));
 
-            ddl = "ALTER TABLE test_table ADD  c1.col2 VARCHAR  , c1.col3 integer , c2.col4 integer";
+            ddl = "ALTER TABLE " + dataTableFullName + " ADD  c1.col2 VARCHAR  , c1.col3 integer , c2.col4 integer";
             conn.createStatement().execute(ddl);
 
-            ddl = "ALTER TABLE test_table ADD   col5 integer , c1.col2 VARCHAR";
+            ddl = "ALTER TABLE " + dataTableFullName + " ADD   col5 integer , c1.col2 VARCHAR";
             try {
                 conn.createStatement().execute(ddl);
                 fail();
@@ -627,7 +607,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 assertEquals(SQLExceptionCode.COLUMN_EXIST_IN_DEF.getErrorCode(), e.getErrorCode());
             }
 
-            query = "SELECT col5 FROM test_table";
+            query = "SELECT col5 FROM " + dataTableFullName;
             try {
                 conn.createStatement().executeQuery(query);
                 fail();
@@ -635,10 +615,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 assertTrue(e.getMessage(), e.getMessage().contains("ERROR 504 (42703): Undefined column."));
             }
 
-            ddl = "ALTER TABLE test_table ADD IF NOT EXISTS col5 integer , c1.col2 VARCHAR";
+            ddl = "ALTER TABLE " + dataTableFullName + " ADD IF NOT EXISTS col5 integer , c1.col2 VARCHAR";
             conn.createStatement().execute(ddl);
 
-            dml = "UPSERT INTO test_table VALUES(?,?,?,?,?)";
+            dml = "UPSERT INTO " + dataTableFullName + " VALUES(?,?,?,?,?)";
             stmt = conn.prepareStatement(dml);
             stmt.setString(1, "c");
             stmt.setInt(2, 100);
@@ -648,7 +628,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
             stmt.execute();
             conn.commit();
 
-            query = "SELECT * FROM test_table WHERE a_string = 'c' ";
+            query = "SELECT * FROM " + dataTableFullName + " WHERE a_string = 'c' ";
             rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals("c",rs.getString(1));
@@ -658,10 +638,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
             assertEquals(102,rs.getInt(5));
             assertFalse(rs.next());
 
-            ddl = "ALTER TABLE test_table ADD  col5 integer";
+            ddl = "ALTER TABLE " + dataTableFullName + " ADD  col5 integer";
             conn.createStatement().execute(ddl);
 
-            query = "SELECT c1.* FROM test_table WHERE a_string = 'c' ";
+            query = "SELECT c1.* FROM " + dataTableFullName + " WHERE a_string = 'c' ";
             rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals("d",rs.getString(1));
@@ -669,7 +649,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
             assertFalse(rs.next());
 
 
-            dml = "UPSERT INTO test_table(a_string,col1,col5) VALUES(?,?,?)";
+            dml = "UPSERT INTO " + dataTableFullName + "(a_string,col1,col5) VALUES(?,?,?)";
             stmt = conn.prepareStatement(dml);
             stmt.setString(1, "e");
             stmt.setInt(2, 200);
@@ -678,7 +658,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
             conn.commit();
 
 
-            query = "SELECT a_string,col1,col5 FROM test_table WHERE a_string = 'e' ";
+            query = "SELECT a_string,col1,col5 FROM " + dataTableFullName + " WHERE a_string = 'e' ";
             rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals("e",rs.getString(1));
@@ -697,14 +677,14 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.setAutoCommit(false);
         try {
-            String ddl = "CREATE TABLE test_table " + "  (a_string varchar not null, col1 integer, cf1.col2 integer"
+            String ddl = "CREATE TABLE " + dataTableFullName + " " + "  (a_string varchar not null, col1 integer, cf1.col2 integer"
                     + "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             conn.createStatement().execute(ddl);
 
-            ddl = "ALTER TABLE test_table DROP COLUMN col1";
+            ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN col1";
             conn.createStatement().execute(ddl);
 
-            ddl = "ALTER TABLE test_table DROP COLUMN cf1.col2";
+            ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN cf1.col2";
             conn.createStatement().execute(ddl);
         } finally {
             conn.close();
@@ -720,7 +700,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
             conn = DriverManager.getConnection(getUrl(), props);
             conn.setAutoCommit(false);
             try {
-                String ddl = "CREATE TABLE test_table " + "  (a_string varchar not null, col1 integer, cf1.col2 integer"
+                String ddl = "CREATE TABLE " + dataTableFullName + " " + "  (a_string varchar not null, col1 integer, cf1.col2 integer"
                         + "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
                 stmt = conn.prepareStatement(ddl);
                 stmt.execute();
@@ -728,7 +708,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 closeStatement(stmt);
             }
             try {
-                stmt = conn.prepareStatement("ALTER TABLE test_table ADD b_string VARCHAR NOT NULL");
+                stmt = conn.prepareStatement("ALTER TABLE " + dataTableFullName + " ADD b_string VARCHAR NOT NULL");
                 stmt.execute();
                 fail("Should have failed since altering a table by adding a non-nullable column is not allowed.");
             } catch (SQLException e) {
@@ -747,94 +727,100 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     }
 
     @Test
-    public void testDisableWAL() throws Exception {
-        String fullTableName = "TEST_TABLE";
-        String fullIndexName = "I";
+    public void testDisableWAL1() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
 
         try {
             conn.createStatement()
                     .execute(
-                            "CREATE TABLE test_table "
+                            "CREATE TABLE " + dataTableFullName
                                     + "  (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
                                     + "  CONSTRAINT pk PRIMARY KEY (a_string)) immutable_rows=true, disable_wal=true ");
 
             Connection conn2 = DriverManager.getConnection(getUrl(), props);
-            String query = "SELECT * FROM test_table";
+            String query = "SELECT * FROM " + dataTableFullName;
             ResultSet rs = conn2.createStatement().executeQuery(query);
             assertFalse(rs.next());
-            asssertIsWALDisabled(conn2,fullTableName, true);
+            asssertIsWALDisabled(conn2,dataTableFullName, true);
             conn2.close();
-            asssertIsWALDisabled(conn,fullTableName, true);
+            asssertIsWALDisabled(conn,dataTableFullName, true);
 
-            conn.createStatement().execute("CREATE INDEX i ON test_table (col1) include (cf1.col2) SALT_BUCKETS=4");
+            conn.createStatement().execute("CREATE INDEX " + indexTableName + " ON " + dataTableFullName + " (col1) include (cf1.col2) SALT_BUCKETS=4");
             conn2 = DriverManager.getConnection(getUrl(), props);
-            query = "SELECT * FROM i";
+            query = "SELECT * FROM " + indexTableFullName;
             rs = conn2.createStatement().executeQuery(query);
-            asssertIsWALDisabled(conn2,fullIndexName, false);
+            asssertIsWALDisabled(conn2,indexTableFullName, false);
             assertFalse(rs.next());
             conn2.close();
-            asssertIsWALDisabled(conn,fullIndexName, false);
-
-            conn.createStatement().execute("DROP TABLE test_table");
+            asssertIsWALDisabled(conn,indexTableFullName, false);
         } finally {
             conn.close();
         }
-        conn = DriverManager.getConnection(getUrl(), props);
-
+    }
+    
+    @Test
+    public void testDisableWAL2() throws Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             conn.createStatement()
                     .execute(
-                            "CREATE TABLE test_table "
+                            "CREATE TABLE " + dataTableFullName
                                     + "  (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
                                     + "  CONSTRAINT pk PRIMARY KEY (a_string)) immutable_rows=true");
 
             Connection conn2 = DriverManager.getConnection(getUrl(), props);
-            String query = "SELECT * FROM test_table";
+            String query = "SELECT * FROM " + dataTableFullName;
             ResultSet rs = conn2.createStatement().executeQuery(query);
             assertFalse(rs.next());
-            asssertIsWALDisabled(conn,fullTableName, false);
+            asssertIsWALDisabled(conn,dataTableFullName, false);
             conn2.close();
-            asssertIsWALDisabled(conn,fullTableName, false);
+            asssertIsWALDisabled(conn,dataTableFullName, false);
 
-            conn.createStatement().execute("CREATE INDEX i ON test_table (col1) include (cf1.col2) SALT_BUCKETS=4");
+            conn.createStatement().execute("CREATE INDEX " + indexTableName + " ON " + dataTableFullName + " (col1) include (cf1.col2) SALT_BUCKETS=4");
             conn2 = DriverManager.getConnection(getUrl(), props);
-            query = "SELECT * FROM i";
+            query = "SELECT * FROM " + indexTableFullName;
             rs = conn2.createStatement().executeQuery(query);
-            asssertIsWALDisabled(conn2,fullIndexName, false);
+            asssertIsWALDisabled(conn2,indexTableFullName, false);
             assertFalse(rs.next());
             conn2.close();
-            asssertIsWALDisabled(conn,fullIndexName, false);
-            conn.createStatement().execute("DROP TABLE test_table");
+            asssertIsWALDisabled(conn,indexTableFullName, false);
         } finally {
             conn.close();
         }
-        conn = DriverManager.getConnection(getUrl(), props);
+    }
+    
+    @Test
+    public void testDisableWAL3() throws Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
 
         try {
             conn.createStatement()
                     .execute(
-                            "CREATE TABLE test_table "
+                            "CREATE TABLE " + dataTableFullName
                                     + "  (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
                                     + "  CONSTRAINT pk PRIMARY KEY (a_string))");
 
             Connection conn2 = DriverManager.getConnection(getUrl(), props);
-            String query = "SELECT * FROM test_table";
+            String query = "SELECT * FROM " + dataTableFullName;
             ResultSet rs = conn2.createStatement().executeQuery(query);
             assertFalse(rs.next());
-            asssertIsWALDisabled(conn2,fullTableName, false);
+            asssertIsWALDisabled(conn2,dataTableFullName, false);
             conn2.close();
-            asssertIsWALDisabled(conn,fullTableName, false);
+            asssertIsWALDisabled(conn,dataTableFullName, false);
 
-            conn.createStatement().execute("CREATE INDEX i ON test_table (col1) include (cf1.col2) SALT_BUCKETS=4");
+            conn.createStatement().execute(
+                    "CREATE INDEX " + indexTableName + " ON " + dataTableFullName
+                            + " (col1) include (cf1.col2) SALT_BUCKETS=4");
             conn2 = DriverManager.getConnection(getUrl(), props);
-            query = "SELECT * FROM i";
+            query = "SELECT * FROM " + indexTableFullName;
             rs = conn2.createStatement().executeQuery(query);
-            asssertIsWALDisabled(conn2,fullIndexName, false);
+            asssertIsWALDisabled(conn2,indexTableFullName, false);
             assertFalse(rs.next());
             conn2.close();
-            asssertIsWALDisabled(conn,fullIndexName, false);
+            asssertIsWALDisabled(conn,indexTableFullName, false);
 
         } finally {
             conn.close();
@@ -851,20 +837,20 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         try {
             conn.createStatement()
                     .execute(
-                            "CREATE TABLE test_table "
+                            "CREATE TABLE " + dataTableFullName
                                     + "  (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
                                     + "  CONSTRAINT pk PRIMARY KEY (a_string)) immutable_rows=true , SALT_BUCKETS=3 ");
 
-            String query = "SELECT * FROM test_table";
+            String query = "SELECT * FROM " + dataTableFullName;
             ResultSet rs = conn.createStatement().executeQuery(query);
             assertFalse(rs.next());
 
-            conn.createStatement().execute("CREATE INDEX i ON test_table (col1) include (cf1.col2) SALT_BUCKETS=4");
-            query = "SELECT * FROM i";
+            conn.createStatement().execute("CREATE INDEX " + indexTableName + " ON " + dataTableFullName + " (col1) include (cf1.col2) SALT_BUCKETS=4");
+            query = "SELECT * FROM " + indexTableFullName;
             rs = conn.createStatement().executeQuery(query);
             assertFalse(rs.next());
 
-            String dml = "UPSERT INTO test_table VALUES(?,?,?,?,?)";
+            String dml = "UPSERT INTO " + dataTableFullName + " VALUES(?,?,?,?,?)";
             PreparedStatement stmt = conn.prepareStatement(dml);
             stmt.setString(1, "b");
             stmt.setInt(2, 10);
@@ -880,7 +866,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
             stmt.execute();
             conn.commit();
 
-            query = "SELECT * FROM test_table order by col1";
+            query = "SELECT * FROM " + dataTableFullName + " order by col1";
             rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals("b", rs.getString(1));
@@ -888,10 +874,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
             assertEquals("a", rs.getString(1));
             assertFalse(rs.next());
 
-            String ddl = "ALTER TABLE test_table DROP COLUMN IF EXISTS col2,col3";
+            String ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN IF EXISTS col2,col3";
             conn.createStatement().execute(ddl);
 
-            ddl = "ALTER TABLE test_table DROP COLUMN a_string,col1";
+            ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN a_string,col1";
             try{
                 conn.createStatement().execute(ddl);
                 fail();
@@ -899,7 +885,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 assertEquals(SQLExceptionCode.CANNOT_DROP_PK.getErrorCode(), e.getErrorCode());
             }
 
-            ddl = "ALTER TABLE test_table DROP COLUMN col4,col5";
+            ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN col4,col5";
             try {
                 conn.createStatement().execute(ddl);
                 fail();
@@ -908,21 +894,21 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 assertTrue(e.getMessage(), e.getMessage().contains("ERROR 504 (42703): Undefined column. columnName=COL5"));
             }
 
-            ddl = "ALTER TABLE test_table DROP COLUMN IF EXISTS col1";
+            ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN IF EXISTS col1";
             conn.createStatement().execute(ddl);
 
-            query = "SELECT * FROM i";
+            query = "SELECT * FROM " + indexTableFullName;
             try {
                 rs = conn.createStatement().executeQuery(query);
                 fail();
             } catch (TableNotFoundException e) {}
 
-            query = "select col4 FROM test_table";
+            query = "select col4 FROM " + dataTableFullName;
             rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertTrue(rs.next());
 
-            query = "select col2,col3 FROM test_table";
+            query = "select col2,col3 FROM " + dataTableFullName;
             try {
                 rs = conn.createStatement().executeQuery(query);
                 fail();
@@ -942,8 +928,8 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
 
         // here we insert into the orig schema with one column
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
-        conn1.createStatement().execute("create table test_simpletable(id VARCHAR PRIMARY KEY, field1 BIGINT)");
-        PreparedStatement stmtInsert1 = conn1.prepareStatement("upsert into test_simpletable (id, field1) values ( ?, ?)");
+        conn1.createStatement().execute("create table " + dataTableFullName + "(id VARCHAR PRIMARY KEY, field1 BIGINT)");
+        PreparedStatement stmtInsert1 = conn1.prepareStatement("upsert into " + dataTableFullName + " (id, field1) values ( ?, ?)");
         stmtInsert1.setString(1, "key1");
         stmtInsert1.setLong(2, 1L);
         stmtInsert1.execute();
@@ -952,10 +938,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         conn1.close();
 
         // Do the alter through a separate client.
-        conn3.createStatement().execute("alter table test_simpletable add field2 BIGINT");
+        conn3.createStatement().execute("alter table " + dataTableFullName + " add field2 BIGINT");
 
         //Connection conn1 = DriverManager.getConnection(getUrl(), props);
-        PreparedStatement pstmt2 = conn1.prepareStatement("upsert into test_simpletable (id, field1, field2) values ( ?, ?, ?)");
+        PreparedStatement pstmt2 = conn1.prepareStatement("upsert into " + dataTableFullName + " (id, field1, field2) values ( ?, ?, ?)");
         pstmt2.setString(1, "key2");
         pstmt2.setLong(2, 2L);
         pstmt2.setLong(3, 2L);
@@ -968,7 +954,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testAddColumnsUsingNewConnection() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE T (\n"
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
                 +"ID1 VARCHAR(15) NOT NULL,\n"
                 +"ID2 VARCHAR(15) NOT NULL,\n"
                 +"CREATED_DATE DATE,\n"
@@ -977,11 +963,11 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 +"CONSTRAINT PK PRIMARY KEY (ID1, ID2))";
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
         conn1.createStatement().execute(ddl);
-        ddl = "ALTER TABLE T ADD STRING VARCHAR, STRING_DATA_TYPES VARCHAR";
+        ddl = "ALTER TABLE " + dataTableFullName + " ADD STRING VARCHAR, STRING_DATA_TYPES VARCHAR";
         conn1.createStatement().execute(ddl);
-        ddl = "ALTER TABLE T DROP COLUMN STRING, STRING_DATA_TYPES";
+        ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN STRING, STRING_DATA_TYPES";
         conn1.createStatement().execute(ddl);
-        ddl = "ALTER TABLE T ADD STRING_ARRAY1 VARCHAR[]";
+        ddl = "ALTER TABLE " + dataTableFullName + " ADD STRING_ARRAY1 VARCHAR[]";
         conn1.createStatement().execute(ddl);
         conn1.close();
     }
@@ -989,16 +975,16 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testAddMultipleColumns() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE T (\n"
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
                 +"ID VARCHAR(15) PRIMARY KEY,\n"
                 +"COL1 BIGINT)";
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
         conn1.createStatement().execute(ddl);
-        conn1.createStatement().execute("CREATE INDEX I ON T(COL1)");
+        conn1.createStatement().execute("CREATE INDEX " + indexTableName + " ON " + dataTableFullName + "(COL1)");
         
-        ddl = "ALTER TABLE T ADD COL2 VARCHAR PRIMARY KEY, COL3 VARCHAR PRIMARY KEY";
+        ddl = "ALTER TABLE " + dataTableFullName + " ADD COL2 VARCHAR PRIMARY KEY, COL3 VARCHAR PRIMARY KEY";
         conn1.createStatement().execute(ddl);
-        ResultSet rs = conn1.getMetaData().getColumns("", "", "T", null);
+        ResultSet rs = conn1.getMetaData().getColumns("", "", dataTableFullName, null);
         assertTrue(rs.next());
         assertEquals("ID",rs.getString(4));
         assertTrue(rs.next());
@@ -1011,7 +997,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         
         rs = conn1.createStatement().executeQuery("SELECT COLUMN_COUNT FROM SYSTEM.CATALOG\n"
                 + "WHERE TENANT_ID IS NULL AND\n"
-                + "TABLE_SCHEM IS NULL AND TABLE_NAME = 'T' AND\n"
+                + "(TABLE_SCHEM, TABLE_NAME) = ('" + schemaName + "','"+ dataTableName + "') AND\n"
                 + "COLUMN_FAMILY IS NULL AND COLUMN_NAME IS NULL");
         assertTrue(rs.next());
         assertEquals(4,rs.getInt(1));
@@ -1019,18 +1005,18 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
 
         rs = conn1.createStatement().executeQuery("SELECT COLUMN_COUNT FROM SYSTEM.CATALOG\n"
                 + "WHERE TENANT_ID IS NULL AND\n"
-                + "TABLE_SCHEM IS NULL AND TABLE_NAME = 'I' AND\n"
+                + "(TABLE_SCHEM, TABLE_NAME) = ('" + schemaName + "','"+ indexTableName + "') AND\n"
                 + "COLUMN_FAMILY IS NULL AND COLUMN_NAME IS NULL");
         assertTrue(rs.next());
         assertEquals(4,rs.getInt(1));
         assertFalse(rs.next());
         
-        conn1.createStatement().execute("UPSERT INTO T VALUES ('a',2,'a','b')");
-        conn1.createStatement().execute("UPSERT INTO T VALUES ('b',3,'b','c')");
-        conn1.createStatement().execute("UPSERT INTO T VALUES ('c',4,'c','c')");
+        conn1.createStatement().execute("UPSERT INTO " + dataTableFullName + " VALUES ('a',2,'a','b')");
+        conn1.createStatement().execute("UPSERT INTO " + dataTableFullName + " VALUES ('b',3,'b','c')");
+        conn1.createStatement().execute("UPSERT INTO " + dataTableFullName + " VALUES ('c',4,'c','c')");
         conn1.commit();
         
-        rs = conn1.createStatement().executeQuery("SELECT ID,COL1 FROM T WHERE COL1=3");
+        rs = conn1.createStatement().executeQuery("SELECT ID,COL1 FROM " + dataTableFullName + " WHERE COL1=3");
         assertTrue(rs.next());
         assertEquals("b",rs.getString(1));
         assertEquals(3,rs.getLong(2));
@@ -1043,7 +1029,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testDropMultipleColumns() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE T (\n"
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
                 + "ID VARCHAR(15) PRIMARY KEY,\n"
                 + "COL1 BIGINT,"
                 + "COL2 BIGINT,"
@@ -1051,11 +1037,11 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 + "COL4 BIGINT)";
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
         conn1.createStatement().execute(ddl);
-        conn1.createStatement().execute("CREATE INDEX I ON T(COL1) INCLUDE (COL2,COL3,COL4)");
+        conn1.createStatement().execute("CREATE INDEX " + indexTableName + " ON " + dataTableFullName + "(COL1) INCLUDE (COL2,COL3,COL4)");
         
-        ddl = "ALTER TABLE T DROP COLUMN COL2, COL3";
+        ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN COL2, COL3";
         conn1.createStatement().execute(ddl);
-        ResultSet rs = conn1.getMetaData().getColumns("", "", "T", null);
+        ResultSet rs = conn1.getMetaData().getColumns("", "", dataTableFullName, null);
         assertTrue(rs.next());
         assertEquals("ID",rs.getString(4));
         assertTrue(rs.next());
@@ -1066,7 +1052,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         
         rs = conn1.createStatement().executeQuery("SELECT COLUMN_COUNT FROM SYSTEM.CATALOG\n"
                 + "WHERE TENANT_ID IS NULL AND\n"
-                + "TABLE_SCHEM IS NULL AND TABLE_NAME = 'T' AND\n"
+                + "(TABLE_SCHEM, TABLE_NAME) = ('" + schemaName + "','"+ dataTableName + "') AND\n"
                 + "COLUMN_FAMILY IS NULL AND COLUMN_NAME IS NULL");
         assertTrue(rs.next());
         assertEquals(3,rs.getInt(1));
@@ -1074,18 +1060,18 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
 
         rs = conn1.createStatement().executeQuery("SELECT COLUMN_COUNT FROM SYSTEM.CATALOG\n"
                 + "WHERE TENANT_ID IS NULL AND\n"
-                + "TABLE_SCHEM IS NULL AND TABLE_NAME = 'I' AND\n"
+                + "(TABLE_SCHEM, TABLE_NAME) = ('" + schemaName + "','"+ indexTableName + "') AND\n"
                 + "COLUMN_FAMILY IS NULL AND COLUMN_NAME IS NULL");
         assertTrue(rs.next());
         assertEquals(3,rs.getInt(1));
         assertFalse(rs.next());
         
-        conn1.createStatement().execute("UPSERT INTO T VALUES ('a',2, 20)");
-        conn1.createStatement().execute("UPSERT INTO T VALUES ('b',3, 30)");
-        conn1.createStatement().execute("UPSERT INTO T VALUES ('c',4, 40)");
+        conn1.createStatement().execute("UPSERT INTO " + dataTableFullName + " VALUES ('a',2, 20)");
+        conn1.createStatement().execute("UPSERT INTO " + dataTableFullName + " VALUES ('b',3, 30)");
+        conn1.createStatement().execute("UPSERT INTO " + dataTableFullName + " VALUES ('c',4, 40)");
         conn1.commit();
         
-        rs = conn1.createStatement().executeQuery("SELECT ID,COL1,COL4 FROM T WHERE COL1=3");
+        rs = conn1.createStatement().executeQuery("SELECT ID,COL1,COL4 FROM " + dataTableFullName + " WHERE COL1=3");
         assertTrue(rs.next());
         assertEquals("b",rs.getString(1));
         assertEquals(3,rs.getLong(2));
@@ -1098,7 +1084,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testAddColumnForNewColumnFamily() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE testAddColumnForNewColumnFamily (\n"
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
                 +"ID1 VARCHAR(15) NOT NULL,\n"
                 +"ID2 VARCHAR(15) NOT NULL,\n"
                 +"CREATED_DATE DATE,\n"
@@ -1107,10 +1093,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
         conn1.createStatement().execute(ddl);
-        ddl = "ALTER TABLE testAddColumnForNewColumnFamily ADD CF.STRING VARCHAR";
+        ddl = "ALTER TABLE " + dataTableFullName + " ADD CF.STRING VARCHAR";
         conn1.createStatement().execute(ddl);
         try (HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-            HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("testAddColumnForNewColumnFamily".toUpperCase())).getColumnFamilies();
+            HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName)).getColumnFamilies();
             assertEquals(2, columnFamilies.length);
             assertEquals("0", columnFamilies[0].getNameAsString());
             assertEquals(HColumnDescriptor.DEFAULT_TTL, columnFamilies[0].getTimeToLive());
@@ -1122,7 +1108,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testSetHColumnProperties() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE T1 (\n"
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
                 +"ID1 VARCHAR(15) NOT NULL,\n"
                 +"ID2 VARCHAR(15) NOT NULL,\n"
                 +"CREATED_DATE DATE,\n"
@@ -1131,10 +1117,11 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
         conn1.createStatement().execute(ddl);
-        ddl = "ALTER TABLE T1 SET REPLICATION_SCOPE=1";
+        ddl = "ALTER TABLE " + dataTableFullName + " SET REPLICATION_SCOPE=1";
         conn1.createStatement().execute(ddl);
         try (HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-            HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("T1")).getColumnFamilies();
+            HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName))
+                    .getColumnFamilies();
             assertEquals(1, columnFamilies.length);
             assertEquals("0", columnFamilies[0].getNameAsString());
             assertEquals(1, columnFamilies[0].getScope());
@@ -1144,7 +1131,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testSetHTableProperties() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE T2 (\n"
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
                 +"ID1 VARCHAR(15) NOT NULL,\n"
                 +"ID2 VARCHAR(15) NOT NULL,\n"
                 +"CREATED_DATE DATE,\n"
@@ -1153,10 +1140,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
         conn1.createStatement().execute(ddl);
-        ddl = "ALTER TABLE T2 SET COMPACTION_ENABLED=FALSE";
+        ddl = "ALTER TABLE " + dataTableFullName + " SET COMPACTION_ENABLED=FALSE";
         conn1.createStatement().execute(ddl);
         try (HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-            HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes("T2"));
+            HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
             assertEquals(1, tableDesc.getColumnFamilies().length);
             assertEquals("0", tableDesc.getColumnFamilies()[0].getNameAsString());
             assertEquals(Boolean.toString(false), tableDesc.getValue(HTableDescriptor.COMPACTION_ENABLED));
@@ -1166,7 +1153,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testSetHTableAndHColumnProperties() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE T3 (\n"
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
                 +"ID1 VARCHAR(15) NOT NULL,\n"
                 +"ID2 VARCHAR(15) NOT NULL,\n"
                 +"CREATED_DATE DATE,\n"
@@ -1175,10 +1162,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
         conn1.createStatement().execute(ddl);
-        ddl = "ALTER TABLE T3 SET COMPACTION_ENABLED = FALSE, REPLICATION_SCOPE = 1";
+        ddl = "ALTER TABLE " + dataTableFullName + " SET COMPACTION_ENABLED = FALSE, REPLICATION_SCOPE = 1";
         conn1.createStatement().execute(ddl);
         try (HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-            HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes("T3"));
+            HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
             HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
             assertEquals(1, columnFamilies.length);
             assertEquals("0", columnFamilies[0].getNameAsString());
@@ -1190,7 +1177,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testSetHTableHColumnAndPhoenixTableProperties() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE T3 (\n"
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
                 +"ID1 VARCHAR(15) NOT NULL,\n"
                 +"ID2 VARCHAR(15) NOT NULL,\n"
                 +"CREATED_DATE DATE,\n"
@@ -1199,15 +1186,15 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) IMMUTABLE_ROWS=true";
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.createStatement().execute(ddl);
-        assertImmutableRows(conn, "T3", true);
-        ddl = "ALTER TABLE T3 SET COMPACTION_ENABLED = FALSE, VERSIONS = 10";
+        assertImmutableRows(conn, dataTableFullName, true);
+        ddl = "ALTER TABLE " + dataTableFullName + " SET COMPACTION_ENABLED = FALSE, VERSIONS = 10";
         conn.createStatement().execute(ddl);
-        ddl = "ALTER TABLE T3 SET COMPACTION_ENABLED = FALSE, CF1.MIN_VERSIONS = 1, CF2.MIN_VERSIONS = 3, MIN_VERSIONS = 8, IMMUTABLE_ROWS=false, CF1.KEEP_DELETED_CELLS = true, KEEP_DELETED_CELLS = false";
+        ddl = "ALTER TABLE " + dataTableFullName + " SET COMPACTION_ENABLED = FALSE, CF1.MIN_VERSIONS = 1, CF2.MIN_VERSIONS = 3, MIN_VERSIONS = 8, IMMUTABLE_ROWS=false, CF1.KEEP_DELETED_CELLS = true, KEEP_DELETED_CELLS = false";
         conn.createStatement().execute(ddl);
-        assertImmutableRows(conn, "T3", false);
+        assertImmutableRows(conn, dataTableFullName, false);
 
         try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-            HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes("T3"));
+            HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
             HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
             assertEquals(3, columnFamilies.length);
 
@@ -1233,7 +1220,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testSpecifyingColumnFamilyForHTablePropertyFails() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE T4 (\n"
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
                 +"ID1 VARCHAR(15) NOT NULL,\n"
                 +"ID2 VARCHAR(15) NOT NULL,\n"
                 +"CREATED_DATE DATE,\n"
@@ -1242,7 +1229,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
         conn1.createStatement().execute(ddl);
-        ddl = "ALTER TABLE T4 SET CF.COMPACTION_ENABLED = FALSE";
+        ddl = "ALTER TABLE " + dataTableFullName + " SET CF.COMPACTION_ENABLED = FALSE";
         try {
             conn1.createStatement().execute(ddl);
             fail();
@@ -1254,7 +1241,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testSpecifyingColumnFamilyForPhoenixTablePropertyFails() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE T5 (\n"
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
                 +"ID1 VARCHAR(15) NOT NULL,\n"
                 +"ID2 VARCHAR(15) NOT NULL,\n"
                 +"CREATED_DATE DATE,\n"
@@ -1263,7 +1250,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
         conn1.createStatement().execute(ddl);
-        ddl = "ALTER TABLE T5 SET CF.DISABLE_WAL = TRUE";
+        ddl = "ALTER TABLE " + dataTableFullName + " SET CF.DISABLE_WAL = TRUE";
         try {
             conn1.createStatement().execute(ddl);
             fail();
@@ -1275,7 +1262,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testSpecifyingColumnFamilyForTTLFails() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE T6 (\n"
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
                 +"ID1 VARCHAR(15) NOT NULL,\n"
                 +"ID2 VARCHAR(15) NOT NULL,\n"
                 +"CREATED_DATE DATE,\n"
@@ -1284,7 +1271,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
         conn1.createStatement().execute(ddl);
-        ddl = "ALTER TABLE T6 SET CF.TTL = 86400";
+        ddl = "ALTER TABLE " + dataTableFullName + " SET CF.TTL = 86400";
         try {
             conn1.createStatement().execute(ddl);
             fail();
@@ -1296,7 +1283,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testSetPropertyNeedsColumnFamilyToExist() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE T7 (\n"
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
                 +"ID1 VARCHAR(15) NOT NULL,\n"
                 +"ID2 VARCHAR(15) NOT NULL,\n"
                 +"CREATED_DATE DATE,\n"
@@ -1305,7 +1292,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
         conn1.createStatement().execute(ddl);
-        ddl = "ALTER TABLE T7 SET CF.REPLICATION_SCOPE = 1";
+        ddl = "ALTER TABLE " + dataTableFullName + " SET CF.REPLICATION_SCOPE = 1";
         try {
             conn1.createStatement().execute(ddl);
             fail();
@@ -1317,7 +1304,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testSetDefaultColumnFamilyNotAllowed() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE T8 (\n"
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
                 +"ID1 VARCHAR(15) NOT NULL,\n"
                 +"ID2 VARCHAR(15) NOT NULL,\n"
                 +"CREATED_DATE DATE,\n"
@@ -1326,7 +1313,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
         conn1.createStatement().execute(ddl);
-        ddl = "ALTER TABLE T8 SET DEFAULT_COLUMN_FAMILY = 'A'";
+        ddl = "ALTER TABLE " + dataTableFullName + " SET DEFAULT_COLUMN_FAMILY = 'A'";
         try {
             conn1.createStatement().execute(ddl);
             fail();
@@ -1338,7 +1325,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testSetHColumnOrHTablePropertiesOnViewsNotAllowed() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE T9 (\n"
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
                 +"ID1 VARCHAR(15) NOT NULL,\n"
                 +"ID2 VARCHAR(15) NOT NULL,\n"
                 +"CREATED_DATE DATE,\n"
@@ -1347,7 +1334,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
         conn1.createStatement().execute(ddl);
-        ddl = "CREATE VIEW v AS SELECT * FROM T9 WHERE CREATION_TIME = 1";
+        ddl = "CREATE VIEW v AS SELECT * FROM " + dataTableFullName + " WHERE CREATION_TIME = 1";
         conn1.createStatement().execute(ddl);
         ddl = "ALTER VIEW v SET REPLICATION_SCOPE = 1";
         try {
@@ -1368,7 +1355,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testSetForSomePhoenixTablePropertiesOnViewsAllowed() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE T10 (\n"
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
                 +"ID1 VARCHAR(15) NOT NULL,\n"
                 +"ID2 VARCHAR(15) NOT NULL,\n"
                 +"CREATED_DATE DATE,\n"
@@ -1377,15 +1364,16 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
         conn1.createStatement().execute(ddl);
-        ddl = "CREATE VIEW v AS SELECT * FROM T10 WHERE CREATION_TIME = 1";
+        String viewFullName = SchemaUtil.getTableName(schemaName, generateRandomString());
+        ddl = "CREATE VIEW " + viewFullName + " AS SELECT * FROM " + dataTableFullName + " WHERE CREATION_TIME = 1";
         conn1.createStatement().execute(ddl);
-        ddl = "ALTER VIEW v SET IMMUTABLE_ROWS = TRUE";
+        ddl = "ALTER VIEW " + viewFullName + " SET IMMUTABLE_ROWS = TRUE";
         conn1.createStatement().execute(ddl);
-        assertImmutableRows(conn1, "V", true);
-        ddl = "ALTER VIEW v SET IMMUTABLE_ROWS = FALSE";
+        assertImmutableRows(conn1, viewFullName, true);
+        ddl = "ALTER VIEW " + viewFullName + " SET IMMUTABLE_ROWS = FALSE";
         conn1.createStatement().execute(ddl);
-        assertImmutableRows(conn1, "V", false);
-        ddl = "ALTER VIEW v SET DISABLE_WAL = TRUE";
+        assertImmutableRows(conn1, viewFullName, false);
+        ddl = "ALTER VIEW " + viewFullName + " SET DISABLE_WAL = TRUE";
         try {
             conn1.createStatement().execute(ddl);
             fail();
@@ -1397,7 +1385,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testSettingPropertiesWhenTableHasDefaultColFamilySpecified() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE T11 (\n"
+        String ddl = "CREATE TABLE  " + dataTableFullName + " (\n"
                 +"ID1 VARCHAR(15) NOT NULL,\n"
                 +"ID2 VARCHAR(15) NOT NULL,\n"
                 +"CREATED_DATE DATE,\n"
@@ -1406,12 +1394,13 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) IMMUTABLE_ROWS=true, DEFAULT_COLUMN_FAMILY = 'XYZ'";
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.createStatement().execute(ddl);
-        assertImmutableRows(conn, "T11", true);
-        ddl = "ALTER TABLE T11 SET COMPACTION_ENABLED = FALSE, CF.REPLICATION_SCOPE=1, IMMUTABLE_ROWS = TRUE, TTL=1000";
+        assertImmutableRows(conn, dataTableFullName, true);
+        ddl = "ALTER TABLE  " + dataTableFullName
+                + " SET COMPACTION_ENABLED = FALSE, CF.REPLICATION_SCOPE=1, IMMUTABLE_ROWS = TRUE, TTL=1000";
         conn.createStatement().execute(ddl);
-        assertImmutableRows(conn, "T11", true);
+        assertImmutableRows(conn, dataTableFullName, true);
         try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-            HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes("T11"));
+            HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
             HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
             assertEquals(2, columnFamilies.length);
             assertEquals("CF", columnFamilies[0].getNameAsString());
@@ -1427,7 +1416,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     @Test
     public void testNewColumnFamilyInheritsTTLOfEmptyCF() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String ddl = "CREATE TABLE NEWCFTTLTEST (\n"
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
                 +"ID1 VARCHAR(15) NOT NULL,\n"
                 +"ID2 VARCHAR(15) NOT NULL,\n"
                 +"CREATED_DATE DATE,\n"
@@ -1436,10 +1425,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
                 +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8, TTL = 1000";
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
         conn1.createStatement().execute(ddl);
-        ddl = "ALTER TABLE NEWCFTTLTEST ADD CF.STRING VARCHAR";
+        ddl = "ALTER TABLE " + dataTableFullName + " ADD CF.STRING VARCHAR";
         conn1.createStatement().execute(ddl);
         try (HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-            HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes("NEWCFTTLTEST"));
+            HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
             HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
             assertEquals(2, columnFamilies.length);
             assertEquals("0", columnFamilies[0].getNameAsString());
@@ -1458,14 +1447,17 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     public void testSetPropertyAndAddColumnForExistingColumnFamily() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
-        String ddl = "CREATE TABLE SETPROPEXISTINGCF " +
+        String ddl = "CREATE TABLE " + dataTableFullName
+                +
                 "  (a_string varchar not null, col1 integer, CF.col2 integer" +
                 "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
         try {
             conn.createStatement().execute(ddl);
-            conn.createStatement().execute("ALTER TABLE SETPROPEXISTINGCF ADD CF.col3 integer CF.IN_MEMORY=true");
+            conn.createStatement().execute(
+                    "ALTER TABLE " + dataTableFullName + " ADD CF.col3 integer CF.IN_MEMORY=true");
             try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-                HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("SETPROPEXISTINGCF")).getColumnFamilies();
+                HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName))
+                        .getColumnFamilies();
                 assertEquals(2, columnFamilies.length);
                 assertEquals("0", columnFamilies[0].getNameAsString());
                 assertFalse(columnFamilies[0].isInMemory());
@@ -1481,14 +1473,20 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     public void testSetPropertyAndAddColumnForNewAndExistingColumnFamily() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
-        String ddl = "CREATE TABLE SETPROPNEWEXISTCF " +
+        String ddl = "CREATE TABLE " + dataTableFullName + " "
+                +
                 "  (a_string varchar not null, col1 integer, CF1.col2 integer" +
                 "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
         try {
             conn.createStatement().execute(ddl);
-            conn.createStatement().execute("ALTER TABLE SETPROPNEWEXISTCF ADD col4 integer, CF1.col5 integer, CF2.col6 integer IN_MEMORY=true, CF1.REPLICATION_SCOPE=1, CF2.IN_MEMORY=false ");
+            conn.createStatement()
+                    .execute(
+                            "ALTER TABLE "
+                                    + dataTableFullName
+                                    + " ADD col4 integer, CF1.col5 integer, CF2.col6 integer IN_MEMORY=true, CF1.REPLICATION_SCOPE=1, CF2.IN_MEMORY=false ");
             try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-                HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("SETPROPNEWEXISTCF")).getColumnFamilies();
+                HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName))
+                        .getColumnFamilies();
                 assertEquals(3, columnFamilies.length);
                 assertEquals("0", columnFamilies[0].getNameAsString());
                 assertTrue(columnFamilies[0].isInMemory());
@@ -1509,14 +1507,20 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     public void testSetPropertyAndAddColumnWhenTableHasExplicitDefaultColumnFamily() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
-        String ddl = "CREATE TABLE SETPROPNEWEXISTDEFCOLFAM " +
+        String ddl = "CREATE TABLE " + dataTableFullName + " "
+                +
                 "  (a_string varchar not null, col1 integer, CF1.col2 integer" +
                 "  CONSTRAINT pk PRIMARY KEY (a_string)) DEFAULT_COLUMN_FAMILY = 'XYZ'\n";
         try {
             conn.createStatement().execute(ddl);
-            conn.createStatement().execute("ALTER TABLE SETPROPNEWEXISTDEFCOLFAM ADD col4 integer, CF1.col5 integer, CF2.col6 integer IN_MEMORY=true, CF1.REPLICATION_SCOPE=1, CF2.IN_MEMORY=false, XYZ.REPLICATION_SCOPE=1 ");
+            conn.createStatement()
+                    .execute(
+                            "ALTER TABLE "
+                                    + dataTableFullName
+                                    + " ADD col4 integer, CF1.col5 integer, CF2.col6 integer IN_MEMORY=true, CF1.REPLICATION_SCOPE=1, CF2.IN_MEMORY=false, XYZ.REPLICATION_SCOPE=1 ");
             try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-                HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("SETPROPNEWEXISTDEFCOLFAM")).getColumnFamilies();
+                HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName))
+                        .getColumnFamilies();
                 assertEquals(3, columnFamilies.length);
                 assertEquals("CF1", columnFamilies[0].getNameAsString());
                 assertTrue(columnFamilies[0].isInMemory());
@@ -1537,13 +1541,16 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     public void testSetPropertyAndAddColumnFailsForColumnFamilyNotPresentInAddCol() throws Exception {
     	Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
     	Connection conn = DriverManager.getConnection(getUrl(), props);
-    	String ddl = "CREATE TABLE ADDCOLNOTPRESENT " +
+        String ddl = "CREATE TABLE " + dataTableFullName + " "
+                +
     			"  (a_string varchar not null, col1 integer, CF1.col2 integer" +
     			"  CONSTRAINT pk PRIMARY KEY (a_string)) DEFAULT_COLUMN_FAMILY = 'XYZ'\n";
     	try {
     		conn.createStatement().execute(ddl);
     		try {
-    			conn.createStatement().execute("ALTER TABLE ADDCOLNOTPRESENT ADD col4 integer CF1.REPLICATION_SCOPE=1, XYZ.IN_MEMORY=true ");
+                conn.createStatement().execute(
+                        "ALTER TABLE " + dataTableFullName
+                                + " ADD col4 integer CF1.REPLICATION_SCOPE=1, XYZ.IN_MEMORY=true ");
     			fail();
     		} catch(SQLException e) {
     			assertEquals(SQLExceptionCode.CANNOT_SET_PROPERTY_FOR_COLUMN_NOT_ADDED.getErrorCode(), e.getErrorCode());
@@ -1557,14 +1564,20 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     public void testSetPropertyAndAddColumnForDifferentColumnFamilies() throws Exception {
     	Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
     	Connection conn = DriverManager.getConnection(getUrl(), props);
-    	String ddl = "CREATE TABLE XYZ.SETPROPDIFFCFSTABLE " +
+        String ddl = "CREATE TABLE " + dataTableFullName
+                +
                 "  (a_string varchar not null, col1 integer, CF1.col2 integer, CF2.col3 integer" +
                 "  CONSTRAINT pk PRIMARY KEY (a_string)) DEFAULT_COLUMN_FAMILY = 'XYZ'\n";
         try {
             conn.createStatement().execute(ddl);
-            conn.createStatement().execute("ALTER TABLE XYZ.SETPROPDIFFCFSTABLE ADD col4 integer, CF1.col5 integer, CF2.col6 integer, CF3.col7 integer CF1.REPLICATION_SCOPE=1, CF1.IN_MEMORY=false, IN_MEMORY=true ");
+            conn.createStatement()
+                    .execute(
+                            "ALTER TABLE "
+                                    + dataTableFullName
+                                    + " ADD col4 integer, CF1.col5 integer, CF2.col6 integer, CF3.col7 integer CF1.REPLICATION_SCOPE=1, CF1.IN_MEMORY=false, IN_MEMORY=true ");
             try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-                HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(SchemaUtil.getTableName("XYZ", "SETPROPDIFFCFSTABLE"))).getColumnFamilies();
+                HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName))
+                        .getColumnFamilies();
                 assertEquals(4, columnFamilies.length);
                 assertEquals("CF1", columnFamilies[0].getNameAsString());
                 assertFalse(columnFamilies[0].isInMemory());
@@ -1588,15 +1601,19 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     public void testSetPropertyAndAddColumnUsingDefaultColumnFamilySpecifier() throws Exception {
     	Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
     	Connection conn = DriverManager.getConnection(getUrl(), props);
-    	String ddl = "CREATE TABLE SETPROPDEFCF " +
+        String ddl = "CREATE TABLE " + dataTableFullName
+                +
     			"  (a_string varchar not null, col1 integer, CF1.col2 integer" +
     			"  CONSTRAINT pk PRIMARY KEY (a_string)) DEFAULT_COLUMN_FAMILY = 'XYZ'\n";
     	try {
             conn.createStatement().execute(ddl);
-            conn.createStatement().execute("ALTER TABLE SETPROPDEFCF ADD col4 integer XYZ.REPLICATION_SCOPE=1 ");
-            conn.createStatement().execute("ALTER TABLE SETPROPDEFCF ADD XYZ.col5 integer IN_MEMORY=true ");
+            conn.createStatement().execute(
+                    "ALTER TABLE " + dataTableFullName + " ADD col4 integer XYZ.REPLICATION_SCOPE=1 ");
+            conn.createStatement()
+                    .execute("ALTER TABLE " + dataTableFullName + " ADD XYZ.col5 integer IN_MEMORY=true ");
             try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-                HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("SETPROPDEFCF")).getColumnFamilies();
+                HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName))
+                        .getColumnFamilies();
                 assertEquals(2, columnFamilies.length);
                 assertEquals("CF1", columnFamilies[0].getNameAsString());
                 assertFalse(columnFamilies[0].isInMemory());
@@ -1615,14 +1632,15 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     	Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
     	Connection conn = DriverManager.getConnection(getUrl(), props);
     	conn.setAutoCommit(false);
-    	String ddl = "CREATE TABLE TT " +
+        String ddl = "CREATE TABLE " + dataTableFullName +
     			"  (a_string varchar not null, col1 integer" +
     			"  CONSTRAINT pk PRIMARY KEY (a_string))\n";
     	try {
     		conn.createStatement().execute(ddl);
-    		conn.createStatement().execute("ALTER TABLE TT ADD col2 integer IN_MEMORY=true");
+            conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " ADD col2 integer IN_MEMORY=true");
     		try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-    			HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("TT")).getColumnFamilies();
+                HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName))
+                        .getColumnFamilies();
     			assertEquals(1, columnFamilies.length);
     			assertEquals("0", columnFamilies[0].getNameAsString());
     			assertTrue(columnFamilies[0].isInMemory());
@@ -1641,15 +1659,16 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     	try {
     		conn.createStatement()
     		.execute(
-    				"CREATE TABLE mixed_add_table "
+                            "CREATE TABLE "
+                                    + dataTableFullName
     						+ "  (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
     						+ "  CONSTRAINT pk PRIMARY KEY (a_string)) immutable_rows=true , SALT_BUCKETS=3 ");
 
-    		String ddl = "Alter table mixed_add_table add cf3.col5 integer, cf4.col6 integer in_memory=true";
+            String ddl = "Alter table " + dataTableFullName + " add cf3.col5 integer, cf4.col6 integer in_memory=true";
     		conn.createStatement().execute(ddl);
 
     		try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-    			HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes("MIXED_ADD_TABLE"));
+                HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
     			assertTrue(tableDesc.isCompactionEnabled());
     			HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
     			assertEquals(5, columnFamilies.length);
@@ -1678,15 +1697,16 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     	try {
     		conn.createStatement()
     		.execute(
-    				"CREATE TABLE exist_table "
+                            "CREATE TABLE "
+                                    + dataTableFullName
     						+ "  (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
     						+ "  CONSTRAINT pk PRIMARY KEY (a_string)) immutable_rows=true , SALT_BUCKETS=3 ");
 
-    		String ddl = "Alter table exist_table add cf1.col5 integer in_memory=true";
+            String ddl = "Alter table " + dataTableFullName + " add cf1.col5 integer in_memory=true";
     		conn.createStatement().execute(ddl);
 
     		try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-    			HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes("EXIST_TABLE"));
+                HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
     			assertTrue(tableDesc.isCompactionEnabled());
     			HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
     			assertEquals(3, columnFamilies.length);
@@ -1709,9 +1729,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     	conn.setAutoCommit(false);
 
     	try {
-    		String ddl = "CREATE TABLE exist_test (pk char(2) not null primary key, col1 integer, b.col1 integer) SPLIT ON ('EA','EZ')";
+            String ddl = "CREATE TABLE " + dataTableFullName
+                    + " (pk char(2) not null primary key, col1 integer, b.col1 integer) SPLIT ON ('EA','EZ')";
     		conn.createStatement().execute(ddl);
-    		ddl = "ALTER TABLE exist_test add b.col2 varchar ttl=30";
+            ddl = "ALTER TABLE " + dataTableFullName + " add b.col2 varchar ttl=30";
     		conn.createStatement().execute(ddl);
     		fail();
     	} catch (SQLException e) {
@@ -1728,16 +1749,17 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     	conn.setAutoCommit(false);
 
     	try {
-    		String ddl = "CREATE TABLE ttl_test (pk char(2) not null primary key) TTL=100 SPLIT ON ('EA','EZ')";
+            String ddl = "CREATE TABLE " + dataTableFullName
+                    + " (pk char(2) not null primary key) TTL=100 SPLIT ON ('EA','EZ')";
     		conn.createStatement().execute(ddl);
-    		ddl = "ALTER TABLE ttl_test add col1 varchar ttl=30";
+            ddl = "ALTER TABLE " + dataTableFullName + " add col1 varchar ttl=30";
     		conn.createStatement().execute(ddl);
     		fail();
     	} catch (SQLException e) {
     		assertEquals(SQLExceptionCode.CANNOT_SET_TABLE_PROPERTY_ADD_COLUMN.getErrorCode(), e.getErrorCode());
     	}
     	try {
-    		String ddl = "ALTER TABLE ttl_test add col1 varchar a.ttl=30";
+            String ddl = "ALTER TABLE " + dataTableFullName + " add col1 varchar a.ttl=30";
     		conn.createStatement().execute(ddl);
     		fail();
     	} catch (SQLException e) {
@@ -1753,7 +1775,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     	Connection conn = DriverManager.getConnection(getUrl(), props);
     	conn.setAutoCommit(false);
     	try {
-    	   	String ddl = "create table IF NOT EXISTS ttl_test2 ("
+            String ddl = "create table " + dataTableFullName + " ("
         		    + " id char(1) NOT NULL,"
         		    + " col1 integer NOT NULL,"
         		    + " col2 bigint NOT NULL,"
@@ -1761,17 +1783,17 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
         		    + " ) TTL=86400, SALT_BUCKETS = 4, DEFAULT_COLUMN_FAMILY='XYZ'";
             conn.createStatement().execute(ddl);
             try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
-    			HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes("TTL_TEST2"));
+                HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
     			HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
     			assertEquals(1, columnFamilies.lengt

<TRUNCATED>