Correcting some mutation behavior. While updating a Row and using replace columns or append columns if the record was missing an exception was thrown. This was incorrect, the behavior should be to simply add the record if it did not exist.
Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/32947c7b Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/32947c7b Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/32947c7b Branch: refs/heads/apache-blur-0.2 Commit: 32947c7b4dbd10f028e0aa9d9bbcd4b27e1fe58a Parents: ffd7018 Author: Aaron McCurry <[email protected]> Authored: Sat Sep 14 20:25:01 2013 -0400 Committer: Aaron McCurry <[email protected]> Committed: Sat Sep 14 20:25:01 2013 -0400 ---------------------------------------------------------------------- .../org/apache/blur/manager/IndexManager.java | 15 ++------- .../apache/blur/manager/IndexManagerTest.java | 33 +++++++++++++++----- 2 files changed, 27 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/32947c7b/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java b/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java index 477c238..37b4393 100644 --- a/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java +++ b/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java @@ -1005,12 +1005,11 @@ public class IndexManager { // do nothing as missing record is already in desired state break; case APPEND_COLUMN_VALUES: - throw new BException("Mutation cannot append column values to non-existent record", recordMutation); case REPLACE_ENTIRE_RECORD: + case REPLACE_COLUMNS: + // If record do not exist, create new record in Row newRow.addToRecords(recordMutation.record); break; - case REPLACE_COLUMNS: - throw new BException("Mutation cannot replace columns in non-existent record", recordMutation); default: throw new RuntimeException("Unsupported record mutation type [" + type + "]"); } @@ -1056,16 +1055,6 @@ public class IndexManager { } } - // private boolean isSameRecord(Record existingRecord, Record mutationRecord) - // { - // if (existingRecord.recordId.equals(mutationRecord.recordId)) { - // if (existingRecord.family.equals(mutationRecord.family)) { - // return true; - // } - // } - // return false; - // } - private int getNumberOfShards(String table) { return _indexServer.getShardCount(table); } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/32947c7b/blur-core/src/test/java/org/apache/blur/manager/IndexManagerTest.java ---------------------------------------------------------------------- diff --git a/blur-core/src/test/java/org/apache/blur/manager/IndexManagerTest.java b/blur-core/src/test/java/org/apache/blur/manager/IndexManagerTest.java index be4487e..82748f0 100644 --- a/blur-core/src/test/java/org/apache/blur/manager/IndexManagerTest.java +++ b/blur-core/src/test/java/org/apache/blur/manager/IndexManagerTest.java @@ -1052,24 +1052,32 @@ public class IndexManagerTest { assertTrue("column 2 should be in record", r.columns.contains(c2)); } - @Test(expected = BlurException.class) + @Test public void testMutationUpdateRowMissingRecordReplaceColumns() throws Exception { Column c1 = newColumn("testcol4", "value999"); Column c2 = newColumn("testcol5", "value9999"); String rec = "record-1B"; RecordMutation rm = newRecordMutation(REPLACE_COLUMNS, FAMILY, rec, c1, c2); - updateAndFetchRecord("row-1", rec, rm); + Record r = updateAndFetchRecord("row-1", rec, rm); + assertNotNull("record should exist", r); + assertEquals("only 2 columns in record", 2, r.getColumnsSize()); + assertTrue("column 1 should be in record", r.columns.contains(c1)); + assertTrue("column 2 should be in record", r.columns.contains(c2)); } - @Test(expected = BlurException.class) + @Test public void testMutationUpdateMissingRowReplaceColumns() throws Exception { Column c1 = newColumn("testcol1", "value999"); Column c2 = newColumn("testcol2", "value9999"); String rec = "record-6"; RecordMutation rm = newRecordMutation(REPLACE_COLUMNS, FAMILY, rec, c1, c2); - updateAndFetchRecord("row-6", rec, rm); + Record r = updateAndFetchRecord("row-6", rec, rm); + assertNotNull("record should exist", r); + assertEquals("only 2 columns in record", 2, r.getColumnsSize()); + assertTrue("column 1 should be in record", r.columns.contains(c1)); + assertTrue("column 2 should be in record", r.columns.contains(c2)); } @Test @@ -1112,7 +1120,7 @@ public class IndexManagerTest { assertEquals("should not find other columns", 0, others); } - @Test(expected = BlurException.class) + @Test public void testMutationUpdateRowMissingRecordAppendColumns() throws Exception { Column c1 = newColumn("testcol1", "value999"); Column c2 = newColumn("testcol2", "value9999"); @@ -1120,17 +1128,26 @@ public class IndexManagerTest { String rec = "record-1B"; RecordMutation rm = newRecordMutation(APPEND_COLUMN_VALUES, FAMILY, rec, c1, c2, c3); - updateAndFetchRecord("row-1", rec, rm); + Record r = updateAndFetchRecord("row-1", rec, rm); + assertNotNull("record should exist", r); + assertEquals("only 3 columns in record", 3, r.getColumnsSize()); + assertTrue("column 1 should be in record", r.columns.contains(c1)); + assertTrue("column 2 should be in record", r.columns.contains(c2)); + assertTrue("column 3 should be in record", r.columns.contains(c3)); } - @Test(expected = BlurException.class) + @Test public void testMutationUpdateMissingRowAppendColumns() throws Exception { Column c1 = newColumn("testcol1", "value999"); Column c2 = newColumn("testcol2", "value9999"); String rec = "record-6"; RecordMutation rm = newRecordMutation(APPEND_COLUMN_VALUES, FAMILY, rec, c1, c2); - updateAndFetchRecord("row-6", rec, rm); + Record r = updateAndFetchRecord("row-6", rec, rm); + assertNotNull("record should exist", r); + assertEquals("only 2 columns in record", 2, r.getColumnsSize()); + assertTrue("column 1 should be in record", r.columns.contains(c1)); + assertTrue("column 2 should be in record", r.columns.contains(c2)); } private Record updateAndFetchRecord(String rowId, String recordId, RecordMutation... recordMutations)
