/secondaryindex/src/test/java/org/apache/hadoop/hbase/index/coprocessor/regionserver/TestMultipleIndicesInScan.java
Java | 3493 lines | 3064 code | 329 blank | 100 comment | 180 complexity | 95f01d4f2d92d3ef1204bf8dd29772c6 MD5 | raw file
Possible License(s): Apache-2.0
Large files files are truncated, but you can click here to view the full file
- /**
- * Copyright 2011 The Apache Software Foundation
- *
- * 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.hadoop.hbase.index.coprocessor.regionserver;
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertTrue;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import junit.framework.Assert;
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.hbase.HBaseTestingUtility;
- import org.apache.hadoop.hbase.HColumnDescriptor;
- import org.apache.hadoop.hbase.HConstants;
- import org.apache.hadoop.hbase.HTableDescriptor;
- import org.apache.hadoop.hbase.LargeTests;
- import org.apache.hadoop.hbase.client.HBaseAdmin;
- import org.apache.hadoop.hbase.client.HTable;
- import org.apache.hadoop.hbase.client.Put;
- 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.coprocessor.CoprocessorHost;
- import org.apache.hadoop.hbase.filter.BinaryComparator;
- import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
- import org.apache.hadoop.hbase.filter.DoubleComparator;
- import org.apache.hadoop.hbase.filter.Filter;
- import org.apache.hadoop.hbase.filter.FilterList;
- import org.apache.hadoop.hbase.filter.FilterList.Operator;
- import org.apache.hadoop.hbase.filter.FloatComparator;
- import org.apache.hadoop.hbase.filter.IntComparator;
- import org.apache.hadoop.hbase.filter.RowFilter;
- import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
- import org.apache.hadoop.hbase.index.ColumnQualifier.ValueType;
- import org.apache.hadoop.hbase.index.Constants;
- import org.apache.hadoop.hbase.index.IndexSpecification;
- import org.apache.hadoop.hbase.index.IndexedHTableDescriptor;
- import org.apache.hadoop.hbase.index.coprocessor.master.IndexMasterObserver;
- import org.apache.hadoop.hbase.index.coprocessor.wal.IndexWALObserver;
- import org.apache.hadoop.hbase.index.util.ByteArrayBuilder;
- import org.apache.hadoop.hbase.index.util.IndexUtils;
- import org.apache.hadoop.hbase.util.Bytes;
- import org.apache.hadoop.hbase.zookeeper.ZKAssign;
- import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
- import org.apache.zookeeper.KeeperException;
- import org.junit.After;
- import org.junit.AfterClass;
- import org.junit.Before;
- import org.junit.BeforeClass;
- import org.junit.Test;
- import org.junit.experimental.categories.Category;
- @Category(LargeTests.class)
- public class TestMultipleIndicesInScan {
- private static HBaseTestingUtility UTIL = new HBaseTestingUtility();
- @BeforeClass
- public static void setupBeforeClass() throws Exception {
- Configuration conf = UTIL.getConfiguration();
- conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, IndexMasterObserver.class.getName());
- conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, IndexRegionObserver.class.getName());
- conf.set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, IndexWALObserver.class.getName());
- conf.setInt("hbase.regionserver.lease.period", 10 * 60 * 1000);
- conf.setInt("hbase.rpc.timeout", 10 * 60 * 1000);
- UTIL.startMiniCluster(1);
- }
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- UTIL.shutdownMiniCluster();
- }
- @After
- public void tearDown() throws Exception {
- IndexRegionObserver.setIsTestingEnabled(false);
- }
- @Before
- public void setUp() throws Exception {
- IndexRegionObserver.setIndexedFlowUsed(false);
- IndexRegionObserver.setSeekpointAdded(false);
- IndexRegionObserver.setSeekPoints(null);
- IndexRegionObserver.setIsTestingEnabled(true);
- IndexRegionObserver.addSeekPoints(null);
- }
- @Test(timeout = 180000)
- public void testAndOrCombinationWithMultipleIndices() throws IOException, KeeperException,
- InterruptedException {
- HBaseAdmin admin = UTIL.getHBaseAdmin();
- ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
- Configuration conf = UTIL.getConfiguration();
- String userTableName = "testSimpleScenarioForMultipleIndices";
- IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
- HColumnDescriptor hcd = new HColumnDescriptor("cf1");
- ihtd.addFamily(hcd);
- IndexSpecification indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10,
- new String[] { "c3", "c4", "c5", "c6" }, "idx1");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c1" }, "idx2");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c2" }, "idx3");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c2", "c1" }, "idx4");
- ihtd.addIndex(indexSpecification);
- admin.createTable(ihtd);
- ZKAssign.blockUntilNoRIT(zkw);
- HTable table = new HTable(conf, "testSimpleScenarioForMultipleIndices");
- putforIDX1(Bytes.toBytes("row0"), table);
- putforIDX1(Bytes.toBytes("row1"), table);
- putforIDX2(Bytes.toBytes("row2"), table);
- putforIDX3(Bytes.toBytes("row3"), table);
- putforIDX1(Bytes.toBytes("row4"), table);
- putforIDX2(Bytes.toBytes("row4"), table);
- putforIDX3(Bytes.toBytes("row4"), table);
- putforIDX1(Bytes.toBytes("row5"), table);
- putforIDX1(Bytes.toBytes("row6"), table);
- putforIDX2(Bytes.toBytes("row7"), table);
- putforIDX3(Bytes.toBytes("row8"), table);
- putforIDX1(Bytes.toBytes("row9"), table);
- putforIDX2(Bytes.toBytes("row9"), table);
- FilterList masterFilter = new FilterList(Operator.MUST_PASS_ALL);
- // create the filter
- FilterList filter = new FilterList(Operator.MUST_PASS_ONE);
- SingleColumnValueFilter iscvf1 =
- new SingleColumnValueFilter("cf1".getBytes(), "c1".getBytes(), CompareOp.EQUAL,
- "apple".getBytes());
- SingleColumnValueFilter iscvf2 =
- new SingleColumnValueFilter("cf1".getBytes(), "c2".getBytes(), CompareOp.EQUAL,
- "bat".getBytes());
- filter.addFilter(iscvf1);
- filter.addFilter(iscvf2);
- FilterList filter1 = new FilterList(Operator.MUST_PASS_ALL);
- iscvf1 =
- new SingleColumnValueFilter("cf1".getBytes(), "c3".getBytes(), CompareOp.EQUAL,
- "cat".getBytes());
- iscvf2 =
- new SingleColumnValueFilter("cf1".getBytes(), "c4".getBytes(), CompareOp.EQUAL,
- "dog".getBytes());
- filter1.addFilter(iscvf1);
- filter1.addFilter(iscvf2);
- FilterList filter2 = new FilterList(Operator.MUST_PASS_ALL);
- iscvf1 =
- new SingleColumnValueFilter("cf1".getBytes(), "c5".getBytes(), CompareOp.EQUAL,
- "ele".getBytes());
- iscvf2 =
- new SingleColumnValueFilter("cf1".getBytes(), "c6".getBytes(), CompareOp.EQUAL,
- "fan".getBytes());
- filter2.addFilter(iscvf1);
- filter2.addFilter(iscvf2);
- masterFilter.addFilter(filter);
- masterFilter.addFilter(filter1);
- masterFilter.addFilter(filter2);
- Scan scan = new Scan();
- scan.setFilter(masterFilter);
- int i = 0;
- ResultScanner scanner = table.getScanner(scan);
- List<Result> testRes = new ArrayList<Result>();
- Result[] result = scanner.next(1);
- while (result != null && result.length > 0) {
- testRes.add(result[0]);
- i++;
- result = scanner.next(1);
- }
- Assert.assertTrue("Index flow should get used.", IndexRegionObserver.getIndexedFlowUsed());
- Assert.assertTrue("Seekpoints should get added by index scanner",
- IndexRegionObserver.getSeekpointAdded());
- Assert.assertEquals("It should get two seek points from index scanner.", 2, IndexRegionObserver
- .getMultipleSeekPoints().size());
- Assert.assertTrue("Overall result should have only 2 rows", testRes.size() == 2);
- }
- @Test(timeout = 180000)
- public void testReseekWhenSomeScannerAlreadyScannedGreaterValueThanSeekPoint()
- throws IOException, KeeperException, InterruptedException {
- HBaseAdmin admin = UTIL.getHBaseAdmin();
- ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
- Configuration conf = UTIL.getConfiguration();
- String userTableName = "testReseekWhenSomeScannerAlreadyScannedGreaterValueThanSeekPoint";
- IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
- HColumnDescriptor hcd = new HColumnDescriptor("cf1");
- ihtd.addFamily(hcd);
- IndexSpecification indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10,
- new String[] { "c3", "c4", "c5", "c6" }, "idx1");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c1" }, "idx2");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c2" }, "idx3");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c2", "c1" }, "idx4");
- ihtd.addIndex(indexSpecification);
- admin.createTable(ihtd);
- ZKAssign.blockUntilNoRIT(zkw);
- HTable table =
- new HTable(conf, "testReseekWhenSomeScannerAlreadyScannedGreaterValueThanSeekPoint");
- putforIDX1(Bytes.toBytes("row0"), table);
- putforIDX1(Bytes.toBytes("row3"), table);
- putforIDX1(Bytes.toBytes("row5"), table);
- putforIDX2(Bytes.toBytes("row5"), table);
- putforIDX2(Bytes.toBytes("row6"), table);
- putforIDX3(Bytes.toBytes("row1"), table);
- putforIDX3(Bytes.toBytes("row3"), table);
- FilterList masterFilter = new FilterList(Operator.MUST_PASS_ALL);
- // create the filter
- FilterList filter = new FilterList(Operator.MUST_PASS_ONE);
- SingleColumnValueFilter iscvf1 =
- new SingleColumnValueFilter("cf1".getBytes(), "c1".getBytes(), CompareOp.EQUAL,
- "apple".getBytes());
- SingleColumnValueFilter iscvf2 =
- new SingleColumnValueFilter("cf1".getBytes(), "c2".getBytes(), CompareOp.EQUAL,
- "bat".getBytes());
- filter.addFilter(iscvf1);
- filter.addFilter(iscvf2);
- FilterList filter1 = new FilterList(Operator.MUST_PASS_ALL);
- iscvf1 =
- new SingleColumnValueFilter("cf1".getBytes(), "c3".getBytes(), CompareOp.EQUAL,
- "cat".getBytes());
- iscvf2 =
- new SingleColumnValueFilter("cf1".getBytes(), "c4".getBytes(), CompareOp.EQUAL,
- "dog".getBytes());
- filter1.addFilter(iscvf1);
- filter1.addFilter(iscvf2);
- FilterList filter2 = new FilterList(Operator.MUST_PASS_ALL);
- iscvf1 =
- new SingleColumnValueFilter("cf1".getBytes(), "c5".getBytes(), CompareOp.EQUAL,
- "ele".getBytes());
- iscvf2 =
- new SingleColumnValueFilter("cf1".getBytes(), "c6".getBytes(), CompareOp.EQUAL,
- "fan".getBytes());
- filter2.addFilter(iscvf1);
- filter2.addFilter(iscvf2);
- masterFilter.addFilter(filter);
- masterFilter.addFilter(filter1);
- masterFilter.addFilter(filter2);
- Scan scan = new Scan();
- scan.setFilter(masterFilter);
- int i = 0;
- ResultScanner scanner = table.getScanner(scan);
- List<Result> testRes = new ArrayList<Result>();
- Result[] result = scanner.next(1);
- while (result != null && result.length > 0) {
- testRes.add(result[0]);
- i++;
- result = scanner.next(1);
- }
- Assert.assertTrue("Index flow should get used.", IndexRegionObserver.getIndexedFlowUsed());
- Assert.assertTrue("Seekpoints should get added by index scanner",
- IndexRegionObserver.getSeekpointAdded());
- Assert.assertEquals("It should get two seek points from index scanner.", 2, IndexRegionObserver
- .getMultipleSeekPoints().size());
- Assert.assertTrue("Overall result should have only 2 rows", testRes.size() == 2);
- }
- private void putforIDX3(byte[] row, HTable htable) throws IOException {
- Put p = new Put(row);
- p.add(Bytes.toBytes("cf1"), Bytes.toBytes("c2"), Bytes.toBytes("bat"));
- htable.put(p);
- }
- private void putforIDX2(byte[] row, HTable htable) throws IOException {
- Put p = new Put(row);
- p.add(Bytes.toBytes("cf1"), Bytes.toBytes("c1"), Bytes.toBytes("apple"));
- htable.put(p);
- }
- private void putforIDX1(byte[] row, HTable htable) throws IOException {
- Put p = new Put(row);
- p.add(Bytes.toBytes("cf1"), Bytes.toBytes("c3"), Bytes.toBytes("cat"));
- p.add(Bytes.toBytes("cf1"), Bytes.toBytes("c4"), Bytes.toBytes("dog"));
- p.add(Bytes.toBytes("cf1"), Bytes.toBytes("c5"), Bytes.toBytes("ele"));
- p.add(Bytes.toBytes("cf1"), Bytes.toBytes("c6"), Bytes.toBytes("fan"));
- htable.put(p);
- }
- private IndexSpecification createIndexSpecification(HColumnDescriptor hcd, ValueType type,
- int maxValueLength, String[] qualifiers, String name) {
- IndexSpecification index = new IndexSpecification(name.getBytes());
- for (String qualifier : qualifiers) {
- index.addIndexColumn(hcd, qualifier, type, maxValueLength);
- }
- return index;
- }
- @Test(timeout = 180000)
- public void testWhenAppliedFilterGetsNoScanScheme() throws Exception {
- HBaseAdmin admin = UTIL.getHBaseAdmin();
- ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
- Configuration conf = UTIL.getConfiguration();
- String userTableName = "testWhenAppliedFilterGetsNoScanScheme";
- IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
- HColumnDescriptor hcd = new HColumnDescriptor("cf1");
- ihtd.addFamily(hcd);
- IndexSpecification indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10,
- new String[] { "c3", "c4", "c5", "c6" }, "idx1");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c1" }, "idx2");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c2" }, "idx3");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c2", "c1" }, "idx4");
- ihtd.addIndex(indexSpecification);
- SingleColumnValueFilter filter =
- new SingleColumnValueFilter("cf1".getBytes(), "c5".getBytes(), CompareOp.EQUAL,
- "ele".getBytes());
- admin.createTable(ihtd);
- ZKAssign.blockUntilNoRIT(zkw);
- HTable table = new HTable(conf, "testWhenAppliedFilterGetsNoScanScheme");
- putforIDX1(Bytes.toBytes("row1"), table);
- putforIDX1(Bytes.toBytes("row2"), table);
- putforIDX1(Bytes.toBytes("row3"), table);
- putforIDX1(Bytes.toBytes("row4"), table);
- Scan scan = new Scan();
- scan.setFilter(filter);
- int i = 0;
- ResultScanner scanner = table.getScanner(scan);
- List<Result> testRes = new ArrayList<Result>();
- Result[] result = scanner.next(1);
- while (result != null && result.length > 0) {
- testRes.add(result[0]);
- i++;
- result = scanner.next(1);
- }
- Assert.assertFalse("Index table should not be used", IndexRegionObserver.getIndexedFlowUsed());
- Assert.assertFalse("No seek points should get added from index flow",
- IndexRegionObserver.getSeekpointAdded());
- Assert.assertTrue(testRes.size() == 4);
- }
- @Test(timeout = 180000)
- public void testTheOROperation() throws Exception {
- HBaseAdmin admin = UTIL.getHBaseAdmin();
- ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
- Configuration conf = UTIL.getConfiguration();
- String userTableName = "testTheOROperation";
- IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
- HColumnDescriptor hcd = new HColumnDescriptor("cf1");
- ihtd.addFamily(hcd);
- IndexSpecification indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10,
- new String[] { "c3", "c4", "c5", "c6" }, "idx1");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c1" }, "idx2");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c2" }, "idx3");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c2", "c1" }, "idx4");
- ihtd.addIndex(indexSpecification);
- SingleColumnValueFilter filter =
- new SingleColumnValueFilter("cf1".getBytes(), "c1".getBytes(), CompareOp.EQUAL,
- "apple".getBytes());
- SingleColumnValueFilter filter1 =
- new SingleColumnValueFilter("cf1".getBytes(), "c2".getBytes(), CompareOp.EQUAL,
- "bat".getBytes());
- FilterList masterFilter = new FilterList(Operator.MUST_PASS_ONE);
- masterFilter.addFilter(filter1);
- masterFilter.addFilter(filter);
- admin.createTable(ihtd);
- ZKAssign.blockUntilNoRIT(zkw);
- HTable table = new HTable(conf, "testTheOROperation");
- putforIDX2(Bytes.toBytes("row1"), table);
- putforIDX3(Bytes.toBytes("row1"), table);
- putforIDX2(Bytes.toBytes("row2"), table);
- putforIDX2(Bytes.toBytes("row3"), table);
- putforIDX3(Bytes.toBytes("row4"), table);
- putforIDX3(Bytes.toBytes("row5"), table);
- putforIDX2(Bytes.toBytes("row5"), table);
- putforIDX2(Bytes.toBytes("row6"), table);
- putforIDX3(Bytes.toBytes("row7"), table);
- Scan scan = new Scan();
- scan.setFilter(masterFilter);
- int i = 0;
- ResultScanner scanner = table.getScanner(scan);
- List<Result> testRes = new ArrayList<Result>();
- Result[] result = scanner.next(1);
- while (result != null && result.length > 0) {
- testRes.add(result[0]);
- i++;
- result = scanner.next(1);
- }
- Assert.assertTrue("Index flow should be used.", IndexRegionObserver.getIndexedFlowUsed());
- Assert.assertTrue("Index should fetch some seek points.",
- IndexRegionObserver.getSeekpointAdded());
- Assert.assertEquals("Index should fetch 7 seek points", 7, IndexRegionObserver
- .getMultipleSeekPoints().size());
- Assert.assertEquals("Final result should have 7 rows.", 7, testRes.size());
- }
- @Test(timeout = 180000)
- public void testTheANDOpeartion() throws Exception {
- HBaseAdmin admin = UTIL.getHBaseAdmin();
- ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
- Configuration conf = UTIL.getConfiguration();
- String userTableName = "testTheANDOpeartion";
- IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
- HColumnDescriptor hcd = new HColumnDescriptor("cf1");
- ihtd.addFamily(hcd);
- IndexSpecification indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10,
- new String[] { "c3", "c4", "c5", "c6" }, "idx1");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c1" }, "idx2");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c2" }, "idx3");
- ihtd.addIndex(indexSpecification);
- SingleColumnValueFilter filter =
- new SingleColumnValueFilter("cf1".getBytes(), "c1".getBytes(), CompareOp.EQUAL,
- "apple".getBytes());
- SingleColumnValueFilter filter1 =
- new SingleColumnValueFilter("cf1".getBytes(), "c2".getBytes(), CompareOp.EQUAL,
- "bat".getBytes());
- FilterList masterFilter = new FilterList(Operator.MUST_PASS_ALL);
- masterFilter.addFilter(filter1);
- masterFilter.addFilter(filter);
- admin.createTable(ihtd);
- ZKAssign.blockUntilNoRIT(zkw);
- HTable table = new HTable(conf, "testTheANDOpeartion");
- putforIDX2(Bytes.toBytes("row1"), table);
- putforIDX3(Bytes.toBytes("row1"), table);
- putforIDX2(Bytes.toBytes("row2"), table);
- putforIDX2(Bytes.toBytes("row3"), table);
- putforIDX3(Bytes.toBytes("row4"), table);
- putforIDX3(Bytes.toBytes("row5"), table);
- putforIDX2(Bytes.toBytes("row5"), table);
- putforIDX2(Bytes.toBytes("row6"), table);
- putforIDX3(Bytes.toBytes("row7"), table);
- Scan scan = new Scan();
- scan.setFilter(masterFilter);
- int i = 0;
- ResultScanner scanner = table.getScanner(scan);
- List<Result> testRes = new ArrayList<Result>();
- Result[] result = scanner.next(1);
- while (result != null && result.length > 0) {
- testRes.add(result[0]);
- i++;
- result = scanner.next(1);
- }
- Assert.assertTrue("Index flow should be used.", IndexRegionObserver.getIndexedFlowUsed());
- Assert.assertTrue("Index should fetch some seek points.",
- IndexRegionObserver.getSeekpointAdded());
- Assert.assertEquals("Index should fetch 2 seek points", 2, IndexRegionObserver
- .getMultipleSeekPoints().size());
- Assert.assertEquals("Final result should have 2 rows.", 2, testRes.size());
- }
- @Test(timeout = 180000)
- public void testAndOperationWithProperStartAndStopRow() throws Exception {
- HBaseAdmin admin = UTIL.getHBaseAdmin();
- HBaseTestingUtility.getZooKeeperWatcher(UTIL);
- Configuration conf = UTIL.getConfiguration();
- String userTableName = "testAndOperationWithProperStartAndStopRow";
- IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
- HColumnDescriptor hcd = new HColumnDescriptor("cf1");
- ihtd.addFamily(hcd);
- IndexSpecification indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c1" }, "idx1");
- ihtd.addIndex(indexSpecification);
- admin.createTable(ihtd);
- HTable table = new HTable(conf, userTableName);
- rangePutForIdx2(table);
- FilterList masterFilter = new FilterList(Operator.MUST_PASS_ALL);
- SingleColumnValueFilter scvf =
- new SingleColumnValueFilter("cf1".getBytes(), "c1".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("5"));
- masterFilter.addFilter(scvf);
- Scan scan = new Scan();
- scan.setFilter(masterFilter);
- ResultScanner scanner = table.getScanner(scan);
- List<Result> testRes = new ArrayList<Result>();
- Result[] result = scanner.next(1);
- while (result != null && result.length > 0) {
- testRes.add(result[0]);
- result = scanner.next(1);
- }
- assertTrue(testRes.size() == 1);
- }
- @Test(timeout = 180000)
- public void testAndOperationWithSimilarValuePattern() throws Exception {
- HBaseAdmin admin = UTIL.getHBaseAdmin();
- HBaseTestingUtility.getZooKeeperWatcher(UTIL);
- Configuration conf = UTIL.getConfiguration();
- String userTableName = "testAndOperationWithSimilarValuePattern";
- IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
- HColumnDescriptor hcd = new HColumnDescriptor("cf1");
- ihtd.addFamily(hcd);
- IndexSpecification indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c1" }, "idx1");
- ihtd.addIndex(indexSpecification);
- admin.createTable(ihtd);
- HTable table = new HTable(conf, userTableName);
- Put p = new Put(Bytes.toBytes("row0"));
- p.add(Bytes.toBytes("cf1"), Bytes.toBytes("c1"), Bytes.toBytes("aaa"));
- table.put(p);
- p = new Put(Bytes.toBytes("row9"));
- p.add(Bytes.toBytes("cf1"), Bytes.toBytes("c1"), Bytes.toBytes("aaa1"));
- table.put(p);
- p = new Put(Bytes.toBytes("row1"));
- p.add(Bytes.toBytes("cf1"), Bytes.toBytes("c1"), Bytes.toBytes("aaa3"));
- table.put(p);
- p = new Put(Bytes.toBytes("row3"));
- p.add(Bytes.toBytes("cf1"), Bytes.toBytes("c1"), Bytes.toBytes("aaa4"));
- table.put(p);
- p = new Put(Bytes.toBytes("row7"));
- p.add(Bytes.toBytes("cf1"), Bytes.toBytes("c1"), Bytes.toBytes("aaa5"));
- table.put(p);
- FilterList masterFilter = new FilterList(Operator.MUST_PASS_ALL);
- SingleColumnValueFilter scvf =
- new SingleColumnValueFilter("cf1".getBytes(), "c1".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("aaa"));
- masterFilter.addFilter(scvf);
- Scan scan = new Scan();
- scan.setFilter(masterFilter);
- ResultScanner scanner = table.getScanner(scan);
- List<Result> testRes = new ArrayList<Result>();
- Result[] result = scanner.next(1);
- while (result != null && result.length > 0) {
- testRes.add(result[0]);
- result = scanner.next(1);
- }
- assertTrue(testRes.size() == 1);
- Assert.assertTrue("Index should fetch some seek points.",
- IndexRegionObserver.getSeekpointAdded());
- Assert.assertEquals("Index should fetch 2 seek points", 1, IndexRegionObserver
- .getMultipleSeekPoints().size());
- }
- @Test(timeout = 180000)
- public void testScanWithMutlipleIndicesOnTheSameColAndSimilarPattern() throws Exception {
- HBaseAdmin admin = UTIL.getHBaseAdmin();
- HBaseTestingUtility.getZooKeeperWatcher(UTIL);
- Configuration conf = UTIL.getConfiguration();
- String userTableName = "testScanWithMutlipleIndicesOnTheSameColAndSimilarPattern";
- IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
- HColumnDescriptor hcd = new HColumnDescriptor("cf1");
- ihtd.addFamily(hcd);
- IndexSpecification indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10,
- new String[] { "c3", "c4", "c5", "c6" }, "idx1");
- ihtd.addIndex(indexSpecification);
- admin.createTable(ihtd);
- HTable table = new HTable(conf, userTableName);
- byte[][] val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("ele"),
- Bytes.toBytes("goat") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row1"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("ele"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row2"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row3"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog1"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row4"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat1"), Bytes.toBytes("ant") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row5"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elefe"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row6"), val, table);
- table.flushCommits();
- admin.flush(userTableName);
- admin.flush(userTableName + "_idx");
- FilterList masterFilter = new FilterList(Operator.MUST_PASS_ALL);
- SingleColumnValueFilter scvf =
- new SingleColumnValueFilter("cf1".getBytes(), "c3".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("cat"));
- SingleColumnValueFilter scvf1 =
- new SingleColumnValueFilter("cf1".getBytes(), "c4".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("dog"));
- SingleColumnValueFilter scvf2 =
- new SingleColumnValueFilter("cf1".getBytes(), "c5".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("elef"));
- masterFilter.addFilter(scvf);
- masterFilter.addFilter(scvf1);
- masterFilter.addFilter(scvf2);
- Scan scan = new Scan();
- scan.setFilter(masterFilter);
- ResultScanner scanner = table.getScanner(scan);
- List<Result> testRes = new ArrayList<Result>();
- Result[] result = scanner.next(1);
- while (result != null && result.length > 0) {
- testRes.add(result[0]);
- result = scanner.next(1);
- }
- assertTrue(testRes.size() == 2);
- }
- @Test(timeout = 180000)
- public void testScanWithMutlipleIndicesWithGreaterthanEqualCondOnTheSameColAndSimilarPattern()
- throws Exception {
- HBaseAdmin admin = UTIL.getHBaseAdmin();
- HBaseTestingUtility.getZooKeeperWatcher(UTIL);
- Configuration conf = UTIL.getConfiguration();
- String userTableName =
- "testScanWithMutlipleIndicesWithGreaterthanEqualCondOnTheSameColAndSimilarPattern";
- IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
- HColumnDescriptor hcd = new HColumnDescriptor("cf1");
- ihtd.addFamily(hcd);
- IndexSpecification indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10,
- new String[] { "c3", "c4", "c5", "c6" }, "idx1");
- ihtd.addIndex(indexSpecification);
- admin.createTable(ihtd);
- HTable table = new HTable(conf, userTableName);
- byte[][] val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("ele"),
- Bytes.toBytes("goat") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row1"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("ele"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row2"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row3"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog1"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row4"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat1"), Bytes.toBytes("ant") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row5"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elefe"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row6"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row7"), val, table);
- table.flushCommits();
- admin.flush(userTableName);
- admin.flush(userTableName + "_idx");
- FilterList masterFilter = new FilterList(Operator.MUST_PASS_ALL);
- SingleColumnValueFilter scvf =
- new SingleColumnValueFilter("cf1".getBytes(), "c3".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("cat"));
- SingleColumnValueFilter scvf1 =
- new SingleColumnValueFilter("cf1".getBytes(), "c4".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("dog"));
- SingleColumnValueFilter scvf2 =
- new SingleColumnValueFilter("cf1".getBytes(), "c5".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("elef"));
- SingleColumnValueFilter scvf3 =
- new SingleColumnValueFilter("cf1".getBytes(), "c6".getBytes(), CompareOp.GREATER_OR_EQUAL,
- Bytes.toBytes("goat"));
- masterFilter.addFilter(scvf);
- masterFilter.addFilter(scvf1);
- masterFilter.addFilter(scvf2);
- masterFilter.addFilter(scvf3);
- Scan scan = new Scan();
- scan.setFilter(masterFilter);
- ResultScanner scanner = table.getScanner(scan);
- List<Result> testRes = new ArrayList<Result>();
- Result[] result = scanner.next(1);
- while (result != null && result.length > 0) {
- testRes.add(result[0]);
- result = scanner.next(1);
- }
- assertEquals(testRes.size(), 3);
- }
- @Test(timeout = 180000)
- public void testScanWithMutlipleIndicesWithGreaterCondOnTheSameColAndSimilarPattern()
- throws Exception {
- HBaseAdmin admin = UTIL.getHBaseAdmin();
- HBaseTestingUtility.getZooKeeperWatcher(UTIL);
- Configuration conf = UTIL.getConfiguration();
- String userTableName =
- "testScanWithMutlipleIndicesWithGreaterCondOnTheSameColAndSimilarPattern";
- IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
- HColumnDescriptor hcd = new HColumnDescriptor("cf1");
- ihtd.addFamily(hcd);
- IndexSpecification indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10,
- new String[] { "c3", "c4", "c5", "c6" }, "idx1");
- ihtd.addIndex(indexSpecification);
- admin.createTable(ihtd);
- HTable table = new HTable(conf, userTableName);
- byte[][] val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("ele"),
- Bytes.toBytes("goat") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row1"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("ele"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row2"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row3"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog1"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row4"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat1"), Bytes.toBytes("ant") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row5"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elefe"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row6"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row7"), val, table);
- table.flushCommits();
- admin.flush(userTableName);
- admin.flush(userTableName + "_idx");
- FilterList masterFilter = new FilterList(Operator.MUST_PASS_ALL);
- SingleColumnValueFilter scvf =
- new SingleColumnValueFilter("cf1".getBytes(), "c3".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("cat"));
- SingleColumnValueFilter scvf1 =
- new SingleColumnValueFilter("cf1".getBytes(), "c4".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("dog"));
- SingleColumnValueFilter scvf2 =
- new SingleColumnValueFilter("cf1".getBytes(), "c5".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("elef"));
- SingleColumnValueFilter scvf3 =
- new SingleColumnValueFilter("cf1".getBytes(), "c6".getBytes(), CompareOp.GREATER,
- Bytes.toBytes("goat"));
- masterFilter.addFilter(scvf);
- masterFilter.addFilter(scvf1);
- masterFilter.addFilter(scvf2);
- masterFilter.addFilter(scvf3);
- Scan scan = new Scan();
- scan.setFilter(masterFilter);
- ResultScanner scanner = table.getScanner(scan);
- List<Result> testRes = new ArrayList<Result>();
- Result[] result = scanner.next(1);
- while (result != null && result.length > 0) {
- testRes.add(result[0]);
- result = scanner.next(1);
- }
- assertEquals(testRes.size(), 2);
- }
- @Test(timeout = 180000)
- public void testScanWithMutlipleIndicesWithLesserCondOnTheSameColAndSimilarPattern()
- throws Exception {
- HBaseAdmin admin = UTIL.getHBaseAdmin();
- HBaseTestingUtility.getZooKeeperWatcher(UTIL);
- Configuration conf = UTIL.getConfiguration();
- String userTableName = "testScanWithMutlipleIndicesWithLesserCondOnTheSameColAndSimilarPattern";
- IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
- HColumnDescriptor hcd = new HColumnDescriptor("cf1");
- ihtd.addFamily(hcd);
- IndexSpecification indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10,
- new String[] { "c3", "c4", "c5", "c6" }, "idx1");
- ihtd.addIndex(indexSpecification);
- admin.createTable(ihtd);
- HTable table = new HTable(conf, userTableName);
- byte[][] val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("ele"),
- Bytes.toBytes("goat") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row1"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("ele"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row2"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row3"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog1"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row4"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat1"), Bytes.toBytes("ant") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row5"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elefe"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row6"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row7"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("gda") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row8"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("goa") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row9"), val, table);
- table.flushCommits();
- admin.flush(userTableName);
- admin.flush(userTableName + "_idx");
- FilterList masterFilter = new FilterList(Operator.MUST_PASS_ALL);
- SingleColumnValueFilter scvf =
- new SingleColumnValueFilter("cf1".getBytes(), "c3".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("cat"));
- SingleColumnValueFilter scvf1 =
- new SingleColumnValueFilter("cf1".getBytes(), "c4".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("dog"));
- SingleColumnValueFilter scvf2 =
- new SingleColumnValueFilter("cf1".getBytes(), "c5".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("elef"));
- SingleColumnValueFilter scvf3 =
- new SingleColumnValueFilter("cf1".getBytes(), "c6".getBytes(), CompareOp.LESS,
- Bytes.toBytes("goat"));
- masterFilter.addFilter(scvf);
- masterFilter.addFilter(scvf1);
- masterFilter.addFilter(scvf2);
- masterFilter.addFilter(scvf3);
- Scan scan = new Scan();
- scan.setFilter(masterFilter);
- ResultScanner scanner = table.getScanner(scan);
- List<Result> testRes = new ArrayList<Result>();
- Result[] result = scanner.next(1);
- while (result != null && result.length > 0) {
- testRes.add(result[0]);
- result = scanner.next(1);
- }
- assertEquals(testRes.size(), 2);
- }
- @Test(timeout = 180000)
- public void testScanWithMutlipleIndicesWithLesserEqualCondOnTheSameColAndSimilarPattern()
- throws Exception {
- HBaseAdmin admin = UTIL.getHBaseAdmin();
- HBaseTestingUtility.getZooKeeperWatcher(UTIL);
- Configuration conf = UTIL.getConfiguration();
- String userTableName =
- "testScanWithMutlipleIndicesWithLesserEqualCondOnTheSameColAndSimilarPattern";
- IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
- HColumnDescriptor hcd = new HColumnDescriptor("cf1");
- ihtd.addFamily(hcd);
- IndexSpecification indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10,
- new String[] { "c3", "c4", "c5", "c6" }, "idx1");
- ihtd.addIndex(indexSpecification);
- admin.createTable(ihtd);
- HTable table = new HTable(conf, userTableName);
- byte[][] val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("ele"),
- Bytes.toBytes("goat") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row1"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("ele"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row2"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row3"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog1"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row4"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat1"), Bytes.toBytes("ant") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row5"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elefe"),
- Bytes.toBytes("goat1") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row6"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("goat") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row7"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("gda") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row8"), val, table);
- val =
- new byte[][] { Bytes.toBytes("cat"), Bytes.toBytes("dog"), Bytes.toBytes("elef"),
- Bytes.toBytes("goa") };
- putsForIdx1WithDiffValues(Bytes.toBytes("row9"), val, table);
- table.flushCommits();
- admin.flush(userTableName);
- admin.flush(userTableName + "_idx");
- FilterList masterFilter = new FilterList(Operator.MUST_PASS_ALL);
- SingleColumnValueFilter scvf =
- new SingleColumnValueFilter("cf1".getBytes(), "c3".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("cat"));
- SingleColumnValueFilter scvf1 =
- new SingleColumnValueFilter("cf1".getBytes(), "c4".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("dog"));
- SingleColumnValueFilter scvf2 =
- new SingleColumnValueFilter("cf1".getBytes(), "c5".getBytes(), CompareOp.EQUAL,
- Bytes.toBytes("elef"));
- SingleColumnValueFilter scvf3 =
- new SingleColumnValueFilter("cf1".getBytes(), "c6".getBytes(), CompareOp.LESS_OR_EQUAL,
- Bytes.toBytes("goat"));
- masterFilter.addFilter(scvf);
- masterFilter.addFilter(scvf1);
- masterFilter.addFilter(scvf2);
- masterFilter.addFilter(scvf3);
- Scan scan = new Scan();
- scan.setFilter(masterFilter);
- ResultScanner scanner = table.getScanner(scan);
- List<Result> testRes = new ArrayList<Result>();
- Result[] result = scanner.next(1);
- while (result != null && result.length > 0) {
- testRes.add(result[0]);
- result = scanner.next(1);
- }
- assertEquals(testRes.size(), 3);
- }
- private void putsForIdx1WithDiffValues(byte[] row, byte[][] valList, HTable table)
- throws IOException {
- Put p = new Put(row);
- p.add(Bytes.toBytes("cf1"), Bytes.toBytes("c3"), (valList[0]));
- p.add(Bytes.toBytes("cf1"), Bytes.toBytes("c4"), valList[1]);
- p.add(Bytes.toBytes("cf1"), Bytes.toBytes("c5"), valList[2]);
- p.add(Bytes.toBytes("cf1"), Bytes.toBytes("c6"), valList[3]);
- table.put(p);
- }
- @Test(timeout = 180000)
- public void testWhenSomePointsAreFetchedFromIndexButMainScanStillHasSomeFiltersToApply()
- throws Exception {
- HBaseAdmin admin = UTIL.getHBaseAdmin();
- ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
- Configuration conf = UTIL.getConfiguration();
- String userTableName = "MainScanStillHasSomeFiltersToApply";
- IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
- HColumnDescriptor hcd = new HColumnDescriptor("cf1");
- ihtd.addFamily(hcd);
- IndexSpecification indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c1" }, "idx2");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c2" }, "idx3");
- ihtd.addIndex(indexSpecification);
- SingleColumnValueFilter scvf =
- new SingleColumnValueFilter("cf1".getBytes(), "c1".getBytes(), CompareOp.EQUAL,
- "apple".getBytes());
- scvf.setFilterIfMissing(true);
- SingleColumnValueFilter scvf1 =
- new SingleColumnValueFilter("cf1".getBytes(), "c2".getBytes(), CompareOp.EQUAL,
- "bat".getBytes());
- scvf1.setFilterIfMissing(true);
- FilterList orFilter = new FilterList(Operator.MUST_PASS_ONE);
- orFilter.addFilter(scvf);
- orFilter.addFilter(scvf1);
- FilterList andFilter = new FilterList(Operator.MUST_PASS_ALL);
- SingleColumnValueFilter scvf2 =
- new SingleColumnValueFilter("cf1".getBytes(), "c3".getBytes(), CompareOp.EQUAL,
- "cat".getBytes());
- scvf2.setFilterIfMissing(true);
- SingleColumnValueFilter scvf3 =
- new SingleColumnValueFilter("cf1".getBytes(), "c4".getBytes(), CompareOp.EQUAL,
- "dog".getBytes());
- scvf3.setFilterIfMissing(true);
- SingleColumnValueFilter scvf4 =
- new SingleColumnValueFilter("cf1".getBytes(), "c5".getBytes(), CompareOp.EQUAL,
- "ele".getBytes());
- scvf4.setFilterIfMissing(true);
- SingleColumnValueFilter scvf5 =
- new SingleColumnValueFilter("cf1".getBytes(), "c6".getBytes(), CompareOp.EQUAL,
- "fan".getBytes());
- scvf5.setFilterIfMissing(true);
- andFilter.addFilter(scvf5);
- andFilter.addFilter(scvf4);
- andFilter.addFilter(scvf3);
- andFilter.addFilter(scvf2);
- FilterList master = new FilterList(Operator.MUST_PASS_ALL);
- master.addFilter(andFilter);
- master.addFilter(orFilter);
- admin.createTable(ihtd);
- ZKAssign.blockUntilNoRIT(zkw);
- HTable table = new HTable(conf, "MainScanStillHasSomeFiltersToApply");
- putforIDX1(Bytes.toBytes("row0"), table);
- putforIDX1(Bytes.toBytes("row1"), table);
- putforIDX2(Bytes.toBytes("row2"), table);
- putforIDX3(Bytes.toBytes("row3"), table);
- putforIDX1(Bytes.toBytes("row4"), table);
- putforIDX2(Bytes.toBytes("row4"), table);
- putforIDX3(Bytes.toBytes("row4"), table);
- putforIDX1(Bytes.toBytes("row5"), table);
- putforIDX1(Bytes.toBytes("row6"), table);
- putforIDX2(Bytes.toBytes("row7"), table);
- putforIDX3(Bytes.toBytes("row8"), table);
- putforIDX1(Bytes.toBytes("row9"), table);
- putforIDX2(Bytes.toBytes("row9"), table);
- Scan scan = new Scan();
- scan.setFilter(master);
- // scan.setCaching(10);
- int i = 0;
- ResultScanner scanner = table.getScanner(scan);
- List<Result> testRes = new ArrayList<Result>();
- Result[] result = scanner.next(1);
- while (result != null && result.length > 0) {
- testRes.add(result[0]);
- i++;
- result = scanner.next(1);
- }
- Assert.assertTrue("Index flow should be used.", IndexRegionObserver.getIndexedFlowUsed());
- Assert.assertTrue("Index should fetch some seek points.",
- IndexRegionObserver.getSeekpointAdded());
- Assert.assertEquals("Index should fetch 6 seek points", 6, IndexRegionObserver
- .getMultipleSeekPoints().size());
- Assert.assertEquals("Final result should have 2 rows.", 2, testRes.size());
- }
- @Test(timeout = 180000)
- public void testWhenThereIsNoDataInIndexRegion() throws Exception {
- HBaseAdmin admin = UTIL.getHBaseAdmin();
- ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
- Configuration conf = UTIL.getConfiguration();
- String userTableName = "testWhenThereIsNoDataInIndexRegion";
- IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
- HColumnDescriptor hcd = new HColumnDescriptor("cf1");
- ihtd.addFamily(hcd);
- IndexSpecification indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10,
- new String[] { "c3", "c4", "c5", "c6" }, "idx1");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c1" }, "idx2");
- ihtd.addIndex(indexSpecification);
- indexSpecification =
- createIndexSpecification(hcd, ValueType.String, 10, new String[] { "c2" }, "idx3");
- ihtd.addIndex(indexSpecification);
- SingleColumnValueFilter filter =
- new SingleColumnValueFilter("cf1".getBytes(), "c1".getBytes(), CompareOp.EQUAL,
- "apple".getBytes());
- SingleColumnValueFilter filter1 =
- new SingleColumnValueFilter("cf1".getBytes(), "c2".getBytes(), CompareOp.EQUAL,
- "bat".getBytes());
- FilterList masterFilter = new FilterList(Operator.MUST_PASS_ALL);
- masterFilter.addFilter(filter1);
- masterFilter.addFilter(filter);
- admin.createTable(ihtd);
- ZKAssign.blockUntilNoRIT(zkw);
- HTable table = new HTable(conf, "testWhenThereIsNoDataInIndexRegion");
- Scan scan = new Scan();
- scan.setFilter(masterFilter);
- int i = 0;
- ResultScanner scanner = table.…
Large files files are truncated, but you can click here to view the full file