Updated Branches: refs/heads/master d9f51871c -> 8eca44cc1
Making the mutate command a little easier to use. Also fixed a problem in the indexmanager that would an exception on an update if the row did not exist. That was wrong, if it doesn't exist it should be treated like a replace/add. Also disabled caching from the query command. Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/8eca44cc Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/8eca44cc Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/8eca44cc Branch: refs/heads/master Commit: 8eca44cc1b61b6ff77c7297cce3d42872bd7b79d Parents: d9f5187 Author: Aaron McCurry <[email protected]> Authored: Tue Aug 27 09:13:55 2013 -0400 Committer: Aaron McCurry <[email protected]> Committed: Tue Aug 27 09:13:55 2013 -0400 ---------------------------------------------------------------------- .../org/apache/blur/manager/IndexManager.java | 92 ++++++++++---------- .../apache/blur/shell/CreateTableCommand.java | 1 - .../org/apache/blur/shell/MutateRowCommand.java | 20 +++-- .../org/apache/blur/shell/QueryCommand.java | 2 + docs/getting-started.html | 2 +- docs/using-blur.html | 2 +- 6 files changed, 64 insertions(+), 55 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/8eca44cc/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 dc3073d..9184219 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 @@ -961,57 +961,61 @@ public class IndexManager { Selector selector = new Selector(); selector.setRowId(mutation.rowId); fetchRow(mutation.table, selector, fetchResult); + Row existingRow; if (fetchResult.exists) { // We will examine the contents of the existing row and add records // onto a new replacement row based on the mutation we have been given. - Row existingRow = fetchResult.rowResult.row; - Row newRow = new Row().setId(existingRow.id); - - // Create a local copy of the mutation we can modify - RowMutation mutationCopy = mutation.deepCopy(); - - // Match existing records against record mutations. Once a record - // mutation has been processed, remove it from our local copy. - for (Record existingRecord : existingRow.records) { - RecordMutation recordMutation = findRecordMutation(mutationCopy, existingRecord); - if (recordMutation != null) { - mutationCopy.recordMutations.remove(recordMutation); - doUpdateRecordMutation(recordMutation, existingRecord, newRow); - } else { - // Copy existing records over to the new row unmodified if there - // is no matching mutation. - newRow.addToRecords(existingRecord); - } + existingRow = fetchResult.rowResult.row; + } else { + // The row does not exist, create empty new row. + existingRow = new Row().setId(mutation.getRowId()); + existingRow.records = new ArrayList<Record>(); + } + Row newRow = new Row().setId(existingRow.id); + + // Create a local copy of the mutation we can modify + RowMutation mutationCopy = mutation.deepCopy(); + + // Match existing records against record mutations. Once a record + // mutation has been processed, remove it from our local copy. + for (Record existingRecord : existingRow.records) { + RecordMutation recordMutation = findRecordMutation(mutationCopy, existingRecord); + if (recordMutation != null) { + mutationCopy.recordMutations.remove(recordMutation); + doUpdateRecordMutation(recordMutation, existingRecord, newRow); + } else { + // Copy existing records over to the new row unmodified if there + // is no matching mutation. + newRow.addToRecords(existingRecord); } + } - // Examine all remaining record mutations. For any record replacements - // we need to create a new record in the table even though an existing - // record did not match. Record deletions are also ok here since the - // record is effectively already deleted. Other record mutations are - // an error and should generate an exception. - for (RecordMutation recordMutation : mutationCopy.recordMutations) { - RecordMutationType type = recordMutation.recordMutationType; - switch (type) { - case DELETE_ENTIRE_RECORD: - // 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: - 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 + "]"); - } + // Examine all remaining record mutations. For any record replacements + // we need to create a new record in the table even though an existing + // record did not match. Record deletions are also ok here since the + // record is effectively already deleted. Other record mutations are + // an error and should generate an exception. + for (RecordMutation recordMutation : mutationCopy.recordMutations) { + RecordMutationType type = recordMutation.recordMutationType; + switch (type) { + case DELETE_ENTIRE_RECORD: + // 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: + 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 + "]"); } - - // Finally, replace the existing row with the new row we have built. - blurIndex.replaceRow(mutation.waitToBeVisible, mutation.wal, updateMetrics(newRow)); - } else { - throw new BException("Mutation cannot update row that does not exist.", mutation); } + + // Finally, replace the existing row with the new row we have built. + blurIndex.replaceRow(mutation.waitToBeVisible, mutation.wal, updateMetrics(newRow)); + } private static void doUpdateRecordMutation(RecordMutation recordMutation, Record existingRecord, Row newRow) { http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/8eca44cc/blur-shell/src/main/java/org/apache/blur/shell/CreateTableCommand.java ---------------------------------------------------------------------- diff --git a/blur-shell/src/main/java/org/apache/blur/shell/CreateTableCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/CreateTableCommand.java index c337d74..0ecd479 100644 --- a/blur-shell/src/main/java/org/apache/blur/shell/CreateTableCommand.java +++ b/blur-shell/src/main/java/org/apache/blur/shell/CreateTableCommand.java @@ -83,7 +83,6 @@ public class CreateTableCommand extends Command { } if (cmd.hasOption("l")) { String tableUri = cmd.getOptionValue("l"); - td.setReadOnly(true); td.setTableUri(tableUri); } if (cmd.hasOption("P")) { http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/8eca44cc/blur-shell/src/main/java/org/apache/blur/shell/MutateRowCommand.java ---------------------------------------------------------------------- diff --git a/blur-shell/src/main/java/org/apache/blur/shell/MutateRowCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/MutateRowCommand.java index d7e1498..0b56fb1 100644 --- a/blur-shell/src/main/java/org/apache/blur/shell/MutateRowCommand.java +++ b/blur-shell/src/main/java/org/apache/blur/shell/MutateRowCommand.java @@ -34,20 +34,24 @@ import org.apache.blur.thrift.generated.RowMutationType; public class MutateRowCommand extends Command implements TableFirstArgCommand { @Override - public void doit(PrintWriter out, Blur.Iface client, String[] args) - throws CommandException, TException, BlurException { - if (args.length != 7) { + public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException, TException, + BlurException { + if (args.length < 6) { throw new CommandException("Invalid args: " + help()); } String tablename = args[1]; String rowid = args[2]; String recordid = args[3]; String columnfamily = args[4]; - String columnname = args[5]; - String value = args[6]; List<Column> columns = new ArrayList<Column>(); - columns.add(new Column(columnname, value)); + for (int i = 5; i < args.length; i++) { + String namePlusValue = args[i]; + int index = namePlusValue.indexOf(":"); + String name = namePlusValue.substring(0, index); + String value = namePlusValue.substring(index + 1); + columns.add(new Column(name, value)); + } Record record = new Record(); record.setRecordId(recordid); @@ -64,7 +68,7 @@ public class MutateRowCommand extends Command implements TableFirstArgCommand { RowMutation mutation = new RowMutation(); mutation.setTable(tablename); mutation.setRowId(rowid); - mutation.setRowMutationType(RowMutationType.REPLACE_ROW); + mutation.setRowMutationType(RowMutationType.UPDATE_ROW); mutation.setRecordMutations(recordMutations); client.mutate(mutation); @@ -77,7 +81,7 @@ public class MutateRowCommand extends Command implements TableFirstArgCommand { @Override public String usage() { - return "<tablename> <rowid> <recordid> <columnfamily> <columnname> <value>"; + return "<tablename> <rowid> <recordid> <columnfamily> <columnname>:<value>*"; } @Override http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/8eca44cc/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java ---------------------------------------------------------------------- diff --git a/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java index cbc8e91..60e89ae 100644 --- a/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java +++ b/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java @@ -67,6 +67,8 @@ public class QueryCommand extends Command implements TableFirstArgCommand { query.setQuery(queryStr); blurQuery.setQuery(query); blurQuery.setSelector(Main.selector); + blurQuery.setCacheResult(false); + blurQuery.setUseCacheIfPresent(false); if (Main.highlight) { blurQuery.getSelector().setHighlightOptions(new HighlightOptions()); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/8eca44cc/docs/getting-started.html ---------------------------------------------------------------------- diff --git a/docs/getting-started.html b/docs/getting-started.html index 66f6432..2bc1dde 100644 --- a/docs/getting-started.html +++ b/docs/getting-started.html @@ -190,7 +190,7 @@ localhost: Stopping ZooKeeper with pid [6650].</code></pre> <h3 id="shell-create">Create Table</h3> <p> <pre><code class="bash">blur> #Creates a table called testtable in the local directory of /data/testtable with 11 shards -blur> create testtable file:///data/testtable 11 +blur> create -t testtable -c 11 -l file:///data/testtable </code></pre> </p> <h3 id="shell-mutate">Mutate</h3> http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/8eca44cc/docs/using-blur.html ---------------------------------------------------------------------- diff --git a/docs/using-blur.html b/docs/using-blur.html index f2b19d9..02fd69f 100644 --- a/docs/using-blur.html +++ b/docs/using-blur.html @@ -318,7 +318,7 @@ The following rules are used when interacting with the shell: <pre><code class="bash">get <tablename> <rowid></code></pre></p> <h4 id="shell_command_mutate">mutate</h4> <p>Description: Mutate the specified row.<br/> -<pre><code class="bash">mutate <tablename> <rowid> <recordid> <columnfamily> <columnname> <value></code></pre></p> +<pre><code class="bash">mutate <tablename> <rowid> <recordid> <columnfamily> <columnname>:<value>*</code></pre></p> <h4 id="shell_command_delete">delete</h4> <p>Description: Delete the specified row.<br/> <pre><code class="bash">delete <tablename> <rowid></code></pre></p>
