From b9b91ae68d5ecc7a94d9aa14f3a93bb892c5da38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfonso=20Nishikawa=20Mu=C3=B1umer?= Date: Sun, 28 May 2017 11:36:26 -0100 Subject: [PATCH] GORA-510 Conform Query.setEndKey to inclusive query for HBaseStore Fix + enabled ignored Tests --- .../apache/gora/store/DataStoreTestUtil.java | 2 +- .../apache/gora/hbase/store/HBaseStore.java | 6 +++++- .../gora/hbase/store/TestHBaseStore.java | 18 ------------------ 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java b/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java index 30792cd7f..b9e58cda8 100644 --- a/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java +++ b/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java @@ -1083,7 +1083,7 @@ public static void testDeleteByQueryFields(DataStore store) for (int i = 0; i < URLS.length; i++) { WebPage page = store.get(URLS[i]); assertNotNull(page); - if( URLS[i].compareTo(startKey) < 0 || URLS[i].compareTo(endKey) >= 0) { + if( URLS[i].compareTo(startKey) < 0 || URLS[i].compareTo(endKey) > 0) { //not deleted assertWebPage(page, i); } else { diff --git a/gora-hbase/src/main/java/org/apache/gora/hbase/store/HBaseStore.java b/gora-hbase/src/main/java/org/apache/gora/hbase/store/HBaseStore.java index 389f5dfe1..d614ad7c9 100644 --- a/gora-hbase/src/main/java/org/apache/gora/hbase/store/HBaseStore.java +++ b/gora-hbase/src/main/java/org/apache/gora/hbase/store/HBaseStore.java @@ -490,7 +490,11 @@ public ResultScanner createScanner(Query query) throws IOException { scan.setStartRow(toBytes(query.getStartKey())); } if (query.getEndKey() != null) { - scan.setStopRow(toBytes(query.getEndKey())); + // In HBase the end key is exclusive, so we add a trail zero to make it inclusive + // as the Gora's query interface declares. + byte[] endKey = toBytes(query.getEndKey()); + byte[] inclusiveEndKey = Arrays.copyOf(endKey, endKey.length+1); + scan.setStopRow(inclusiveEndKey); } addFields(scan, query); if (query.getFilter() != null) { diff --git a/gora-hbase/src/test/java/org/apache/gora/hbase/store/TestHBaseStore.java b/gora-hbase/src/test/java/org/apache/gora/hbase/store/TestHBaseStore.java index 695dea196..7fd320aab 100644 --- a/gora-hbase/src/test/java/org/apache/gora/hbase/store/TestHBaseStore.java +++ b/gora-hbase/src/test/java/org/apache/gora/hbase/store/TestHBaseStore.java @@ -245,22 +245,4 @@ public void assertScannerCachingValue() { assertEquals(1000, ((HBaseStore)this.employeeStore).getScannerCaching()) ; } - @Ignore("We need to skip this test since gora considers endRow inclusive, while its exclusive for HBase.") - @Override - public void testQueryEndKey() throws IOException { - //TODO: We should raise an issue for HBase to allow us to specify if the endRow will be inclusive or exclusive. - } - - @Ignore("We need to skip this test since gora considers endRow inclusive, while its exclusive for HBase.") - @Override - public void testQueryKeyRange() throws IOException { - //TODO: We should raise an issue for HBase to allow us to specify if the endRow will be inclusive or exclusive. - } - - @Ignore("We need to skip this test since gora considers endRow inclusive, while its exclusive for HBase.") - @Override - public void testDeleteByQuery() throws IOException { - //TODO: We should raise an issue for HBase to allow us to specify if the endRow will be inclusive or exclusive. - } - }