@Override public void preGetOp(final ObserverContext<RegionCoprocessorEnvironment> c, final Get get, final List<Cell> result) throws IOException { if (get.getAttribute("count") != null) { result.clear(); // order is important! result.add(new KeyValue(count, count, delete, Bytes.toBytes(nDelete))); result.add(new KeyValue(count, count, put, Bytes.toBytes(nCount))); c.bypass(); } } }
@Test public void testAttributesSerialization() throws IOException { Get get = new Get(Bytes.toBytes("row")); get.setAttribute("attribute1", Bytes.toBytes("value1")); get.setAttribute("attribute2", Bytes.toBytes("value2")); get.setAttribute("attribute3", Bytes.toBytes("value3")); ClientProtos.Get getProto = ProtobufUtil.toGet(get); Get get2 = ProtobufUtil.toGet(getProto); Assert.assertNull(get2.getAttribute("absent")); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), get2.getAttribute("attribute1"))); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), get2.getAttribute("attribute2"))); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value3"), get2.getAttribute("attribute3"))); Assert.assertEquals(3, get2.getAttributesMap().size()); }
Get get = new Get(ROW); Assert.assertTrue(get.getAttributesMap().isEmpty()); Assert.assertNull(get.getAttribute("absent")); Assert.assertNull(get.getAttribute("absent")); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), get.getAttribute("attribute1"))); Assert.assertEquals(1, get.getAttributesMap().size()); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), get.getAttributesMap().get("attribute1"))); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"), get.getAttribute("attribute1"))); Assert.assertEquals(1, get.getAttributesMap().size()); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"), get.getAttributesMap().get("attribute1"))); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), get.getAttribute("attribute2"))); Assert.assertEquals(2, get.getAttributesMap().size()); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), get.getAttributesMap().get("attribute2"))); Assert.assertNull(get.getAttribute("attribute2")); Assert.assertEquals(1, get.getAttributesMap().size()); Assert.assertNull(get.getAttributesMap().get("attribute2")); Assert.assertNull(get.getAttribute("attribute2")); Assert.assertEquals(1, get.getAttributesMap().size()); Assert.assertNull(get.getAttributesMap().get("attribute2")); Assert.assertNull(get.getAttribute("attribute1")); Assert.assertTrue(get.getAttributesMap().isEmpty()); Assert.assertNull(get.getAttributesMap().get("attribute1"));
tGet.setAttributes(attributes); Get get = getFromThrift(tGet); assertArrayEquals(get.getAttribute("attribute1"), attributeValue);
@Test public void testAttributesSerialization() throws IOException { Get get = new Get(Bytes.toBytes("row")); get.setAttribute("attribute1", Bytes.toBytes("value1")); get.setAttribute("attribute2", Bytes.toBytes("value2")); get.setAttribute("attribute3", Bytes.toBytes("value3")); ClientProtos.Get getProto = ProtobufUtil.toGet(get); Get get2 = ProtobufUtil.toGet(getProto); Assert.assertNull(get2.getAttribute("absent")); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), get2.getAttribute("attribute1"))); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), get2.getAttribute("attribute2"))); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value3"), get2.getAttribute("attribute3"))); Assert.assertEquals(3, get2.getAttributesMap().size()); }
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { byte[] errorType = get.getAttribute(SHOULD_ERROR_ATTRIBUTE); if (errorType != null) { ErrorType type = ErrorType.valueOf(Bytes.toString(errorType)); switch (type) { case CALL_QUEUE_TOO_BIG: throw new CallQueueTooBigException("Failing for test"); case MULTI_ACTION_RESULT_TOO_LARGE: throw new MultiActionResultTooLarge("Failing for test"); case FAILED_SANITY_CHECK: throw new FailedSanityCheckException("Failing for test"); case NOT_SERVING_REGION: throw new NotServingRegionException("Failing for test"); case REGION_MOVED: throw new RegionMovedException(e.getEnvironment().getServerName(), 1); case SCANNER_RESET: throw new ScannerResetException("Failing for test"); case UNKNOWN_SCANNER: throw new UnknownScannerException("Failing for test"); case REGION_TOO_BUSY: throw new RegionTooBusyException("Failing for test"); case OUT_OF_ORDER_SCANNER_NEXT: throw new OutOfOrderScannerNextException("Failing for test"); default: throw new DoNotRetryIOException("Failing for test"); } } }
Get get = new Get(ROW); Assert.assertTrue(get.getAttributesMap().isEmpty()); Assert.assertNull(get.getAttribute("absent")); Assert.assertNull(get.getAttribute("absent")); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), get.getAttribute("attribute1"))); Assert.assertEquals(1, get.getAttributesMap().size()); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), get.getAttributesMap().get("attribute1"))); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"), get.getAttribute("attribute1"))); Assert.assertEquals(1, get.getAttributesMap().size()); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"), get.getAttributesMap().get("attribute1"))); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), get.getAttribute("attribute2"))); Assert.assertEquals(2, get.getAttributesMap().size()); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), get.getAttributesMap().get("attribute2"))); Assert.assertNull(get.getAttribute("attribute2")); Assert.assertEquals(1, get.getAttributesMap().size()); Assert.assertNull(get.getAttributesMap().get("attribute2")); Assert.assertNull(get.getAttribute("attribute2")); Assert.assertEquals(1, get.getAttributesMap().size()); Assert.assertNull(get.getAttributesMap().get("attribute2")); Assert.assertNull(get.getAttribute("attribute1")); Assert.assertTrue(get.getAttributesMap().isEmpty()); Assert.assertNull(get.getAttributesMap().get("attribute1"));
assertEquals(get.getTimeRange().getMin(), scan.getTimeRange().getMin()); assertEquals(get.getTimeRange().getMax(), scan.getTimeRange().getMax()); assertTrue(Bytes.equals(get.getAttribute("att_v0"), scan.getAttribute("att_v0"))); assertEquals(get.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMin(), scan.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMin());
public static TupleProjector deserializeProjectorFromGet(Get get) { byte[] proj = get.getAttribute(SCAN_PROJECTOR); if (proj == null) { return null; } return deserializeProjectorFromBytes(proj); }
assertEquals(get.getTimeRange().getMin(), scan.getTimeRange().getMin()); assertEquals(get.getTimeRange().getMax(), scan.getTimeRange().getMax()); assertTrue(Bytes.equals(get.getAttribute("att_v0"), scan.getAttribute("att_v0"))); assertEquals(get.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMin(), scan.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMin());
@Override public void preGetOp(final ObserverContext<RegionCoprocessorEnvironment> c, final Get get, final List<Cell> result) throws IOException { if (get.getAttribute("count") != null) { result.clear(); // order is important! result.add(new KeyValue(count, count, delete, Bytes.toBytes(nDelete))); result.add(new KeyValue(count, count, put, Bytes.toBytes(nCount))); c.bypass(); } } }
@Override public void postGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { if (results.isEmpty()) { return; } ResultTuple rsTuple = new ResultTuple(Result.create(results)); //filter rows by the where expression byte[] whereBytes = get.getAttribute(GET_WHERE_EXPRESSION); if (whereBytes != null) { Expression expression = deserializeExpression(whereBytes); if (!expression.evaluate(rsTuple, ptr) || ptr.getLength() == 0 || !Boolean.TRUE.equals(expression.getDataType().toObject(ptr))) { results.clear(); return; } } boolean useNewValueColumnQualifier = get.getAttribute(BaseScannerRegionObserver.USE_NEW_VALUE_COLUMN_QUALIFIER) == null ? false : true; TupleProjector projector = TupleProjector.deserializeProjectorFromGet(get); if (projector != null) { Tuple projectTuple = projector.projectResults(rsTuple, useNewValueColumnQualifier); results.clear(); results.add(projectTuple.getValue(0)); } }
tGet.setAttributes(attributes); Get get = getFromThrift(tGet); assertArrayEquals(get.getAttribute("attribute1"), attributeValue);
tGet.setAttributes(attributes); Get get = getFromThrift(tGet); assertArrayEquals(get.getAttribute("attribute1"), attributeValue);
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { byte[] errorType = get.getAttribute(SHOULD_ERROR_ATTRIBUTE); if (errorType != null) { ErrorType type = ErrorType.valueOf(Bytes.toString(errorType)); switch (type) { case CALL_QUEUE_TOO_BIG: throw new CallQueueTooBigException("Failing for test"); case MULTI_ACTION_RESULT_TOO_LARGE: throw new MultiActionResultTooLarge("Failing for test"); case FAILED_SANITY_CHECK: throw new FailedSanityCheckException("Failing for test"); case NOT_SERVING_REGION: throw new NotServingRegionException("Failing for test"); case REGION_MOVED: throw new RegionMovedException(e.getEnvironment().getServerName(), 1); case SCANNER_RESET: throw new ScannerResetException("Failing for test"); case UNKNOWN_SCANNER: throw new UnknownScannerException("Failing for test"); case REGION_TOO_BUSY: throw new RegionTooBusyException("Failing for test"); case OUT_OF_ORDER_SCANNER_NEXT: throw new OutOfOrderScannerNextException("Failing for test"); default: throw new DoNotRetryIOException("Failing for test"); } } }
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { byte[] errorType = get.getAttribute(SHOULD_ERROR_ATTRIBUTE); if (errorType != null) { ErrorType type = ErrorType.valueOf(Bytes.toString(errorType)); switch (type) { case CALL_QUEUE_TOO_BIG: throw new CallQueueTooBigException("Failing for test"); case MULTI_ACTION_RESULT_TOO_LARGE: throw new MultiActionResultTooLarge("Failing for test"); case FAILED_SANITY_CHECK: throw new FailedSanityCheckException("Failing for test"); case NOT_SERVING_REGION: throw new NotServingRegionException("Failing for test"); case REGION_MOVED: throw new RegionMovedException(e.getEnvironment().getServerName(), 1); case SCANNER_RESET: throw new ScannerResetException("Failing for test"); case UNKNOWN_SCANNER: throw new UnknownScannerException("Failing for test"); case REGION_TOO_BUSY: throw new RegionTooBusyException("Failing for test"); case OUT_OF_ORDER_SCANNER_NEXT: throw new OutOfOrderScannerNextException("Failing for test"); default: throw new DoNotRetryIOException("Failing for test"); } } }