Repository: phoenix
Updated Branches:
  refs/heads/master 416b8a67a -> bdf873f5a


http://git-wip-us.apache.org/repos/asf/phoenix/blob/bdf873f5/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 c8c031b..68cdb26 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
@@ -525,6 +525,38 @@ public class IndexMaintainer implements Writable, 
Iterable<ColumnReference> {
         }
     }
     
+    /*
+     * return the view index id from the index row key
+     */
+    public byte[] getViewIndexIdFromIndexRowKey(ImmutableBytesWritable 
indexRowKeyPtr) {
+        assert(isLocalIndex);
+        RowKeySchema indexRowKeySchema = getIndexRowKeySchema();
+        // TODO add logic to skip region start key as well because we cannot 
find the region startkey in indexhalfstorefilereader.
+        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+        TrustedByteArrayOutputStream stream =
+                new TrustedByteArrayOutputStream(estimatedIndexRowKeyBytes);
+        DataOutput output = new DataOutputStream(stream);
+        try {
+            int indexPosOffset = (!isLocalIndex && nIndexSaltBuckets > 0 ? 1 : 
0) + (isMultiTenant ? 1 : 0) + (viewIndexId == null ? 0 : 1);
+            Boolean hasValue =
+                    indexRowKeySchema.iterator(indexRowKeyPtr, ptr, 
indexPosOffset);
+            if (Boolean.TRUE.equals(hasValue)) {
+                    output.write(ptr.get(), ptr.getOffset(), ptr.getLength());
+            }
+            int length = stream.size();
+            byte[] dataRowKey = stream.getBuffer();
+            return dataRowKey.length == length ? dataRowKey : 
Arrays.copyOf(dataRowKey, length);
+        } catch (IOException e) {
+            throw new RuntimeException(e); // Impossible
+        } finally {
+            try {
+                stream.close();
+            } catch (IOException e) {
+                throw new RuntimeException(e); // Impossible
+            }
+        }
+    }
+
     private volatile RowKeySchema indexRowKeySchema;
     
     // We have enough information to generate the index row key schema

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bdf873f5/phoenix-core/src/main/java/org/apache/phoenix/iterate/LocalIndexParallelIteratorRegionSplitter.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/iterate/LocalIndexParallelIteratorRegionSplitter.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/LocalIndexParallelIteratorRegionSplitter.java
index c3a38d5..0ccd738 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/iterate/LocalIndexParallelIteratorRegionSplitter.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/LocalIndexParallelIteratorRegionSplitter.java
@@ -37,6 +37,7 @@ public class LocalIndexParallelIteratorRegionSplitter extends 
DefaultParallelIte
 
     @Override
     protected List<HRegionLocation> getAllRegions() throws SQLException {
+        
context.getConnection().getQueryServices().clearTableRegionCache(tableRef.getTable().getPhysicalName().getBytes());
         return 
context.getConnection().getQueryServices().getAllTableRegions(tableRef.getTable().getPhysicalName().getBytes());
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bdf873f5/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 9bfd0df..94a6b12 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
@@ -59,6 +59,8 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 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.regionserver.LocalIndexSplitter;
 import org.apache.hadoop.hbase.security.User;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
@@ -620,6 +622,21 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
                 Indexer.enableIndexing(descriptor, PhoenixIndexBuilder.class, 
opts);
             }
             
+            if 
(descriptor.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES) != null
+                    && 
Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(descriptor
+                            
.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) {
+                if 
(!descriptor.hasCoprocessor(IndexHalfStoreFileReaderGenerator.class.getName())) 
{
+                    
descriptor.addCoprocessor(IndexHalfStoreFileReaderGenerator.class.getName(),
+                        null, 1, null);
+                }
+            } else {
+                if 
(!descriptor.hasCoprocessor(LocalIndexSplitter.class.getName())
+                        && !SchemaUtil.isMetaTable(tableName)
+                        && !SchemaUtil.isSequenceTable(tableName)) {
+                    
descriptor.addCoprocessor(LocalIndexSplitter.class.getName(), null, 1, null);
+                }
+            }
+
             // Setup split policy on Phoenix metadata table to ensure that the 
key values of a Phoenix table
             // stay on the same region.
             if (SchemaUtil.isMetaTable(tableName)) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bdf873f5/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 2147026..c57b555 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
@@ -153,7 +153,7 @@ import com.google.common.collect.Sets;
 public abstract class BaseTest {
     private static final Map<String,String> tableDDLMap;
     private static Logger logger = Logger.getLogger("BaseTest.class");
-    
+    private static HBaseTestingUtility utility = null; 
     static {
         ImmutableMap.Builder<String,String> builder = ImmutableMap.builder();
         builder.put(ENTITY_HISTORY_TABLE_NAME,"create table " + 
ENTITY_HISTORY_TABLE_NAME +
@@ -473,7 +473,7 @@ public abstract class BaseTest {
      */
     private static String initMiniCluster(Configuration conf) {
         setUpConfigForMiniCluster(conf);
-        final HBaseTestingUtility utility = new HBaseTestingUtility(conf);
+        utility = new HBaseTestingUtility(conf);
         try {
             utility.startMiniCluster();
             String clientPort = 
utility.getConfiguration().get(QueryServices.ZOOKEEPER_PORT_ATTRIB);
@@ -504,6 +504,7 @@ public abstract class BaseTest {
         setTestConfigForDistribuedCluster(conf);
         try {
             IntegrationTestingUtility util =  new 
IntegrationTestingUtility(conf);
+            utility = util;
             util.initializeCluster(NUM_SLAVES_BASE);
         } catch (Exception e) {
             throw new RuntimeException(e);
@@ -1285,4 +1286,8 @@ public abstract class BaseTest {
         assertTrue("Could not find " + errorResult + " in expected results: " 
+ expectedResults + " with actual results: " + actualResults, errorResult == 
null);
         assertEquals(count, expectedCount);
     }
+    
+    public HBaseTestingUtility getUtility() {
+        return utility;
+    }
 }

Reply via email to