accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ktur...@apache.org
Subject [accumulo] branch 1.8 updated: [ACCUMULO-4775] Skip negate column entirely in ColumnAgeOffFilter (#349)
Date Wed, 17 Jan 2018 18:04:35 GMT
This is an automated email from the ASF dual-hosted git repository.

kturner pushed a commit to branch 1.8
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/1.8 by this push:
     new 53c3077  [ACCUMULO-4775] Skip negate column entirely in ColumnAgeOffFilter (#349)
53c3077 is described below

commit 53c30777e96e6880a466eb8282d2b1a9ac9abf93
Author: Adam J. Shook <adamjshook@gmail.com>
AuthorDate: Wed Jan 17 13:04:33 2018 -0500

    [ACCUMULO-4775] Skip negate column entirely in ColumnAgeOffFilter (#349)
---
 .../core/iterators/user/ColumnAgeOffFilter.java    |   6 +-
 .../shell/commands/SetIterCommandTest.java         | 120 +++++++++++++++++++++
 2 files changed, 124 insertions(+), 2 deletions(-)

diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/user/ColumnAgeOffFilter.java
b/core/src/main/java/org/apache/accumulo/core/iterators/user/ColumnAgeOffFilter.java
index 8093e92..71be2e9 100644
--- a/core/src/main/java/org/apache/accumulo/core/iterators/user/ColumnAgeOffFilter.java
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/user/ColumnAgeOffFilter.java
@@ -42,10 +42,12 @@ public class ColumnAgeOffFilter extends Filter {
 
       for (Entry<String,String> entry : objectStrings.entrySet()) {
         String column = entry.getKey();
-        String ttl = entry.getValue();
+        String ttl = entry.getValue().trim();
         // skip the negate option, it will cause an exception to be thrown
-        if (column.equals(NEGATE) && (ttl.equalsIgnoreCase("true") || ttl.equalsIgnoreCase("false")))
+        if (column.equals(NEGATE) && (ttl.isEmpty() || ttl.equalsIgnoreCase("true")
|| ttl.equalsIgnoreCase("false"))) {
           continue;
+        }
+
         Long l = Long.parseLong(ttl);
 
         Pair<Text,Text> colPair = ColumnSet.decodeColumns(column);
diff --git a/shell/src/test/java/org/apache/accumulo/shell/commands/SetIterCommandTest.java
b/shell/src/test/java/org/apache/accumulo/shell/commands/SetIterCommandTest.java
new file mode 100644
index 0000000..70c798f
--- /dev/null
+++ b/shell/src/test/java/org/apache/accumulo/shell/commands/SetIterCommandTest.java
@@ -0,0 +1,120 @@
+/*
+ * 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.accumulo.shell.commands;
+
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.lang.reflect.Field;
+import java.util.EnumSet;
+
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.admin.TableOperations;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.shell.Shell;
+import org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader;
+import org.apache.commons.cli.CommandLine;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+import jline.console.ConsoleReader;
+
+public class SetIterCommandTest {
+  private SetIterCommand cmd;
+
+  @Before
+  public void setup() {
+    cmd = new SetIterCommand();
+
+    // Initialize that internal state
+    cmd.getOptions();
+  }
+
+  @Test
+  public void addColumnAgeOffFilter() throws Exception {
+    Connector conn = EasyMock.createMock(Connector.class);
+    CommandLine cli = EasyMock.createMock(CommandLine.class);
+    Shell shellState = EasyMock.createMock(Shell.class);
+    ConsoleReader reader = EasyMock.createMock(ConsoleReader.class);
+    Writer out = EasyMock.createMock(PrintWriter.class);
+    TableOperations tableOperations = EasyMock.createMock(TableOperations.class);
+
+    // Command line parsing
+    EasyMock.expect(cli.hasOption("all")).andReturn(true);
+    EasyMock.expect(cli.hasOption("all")).andReturn(true);
+    EasyMock.expect(cli.hasOption("all")).andReturn(true);
+    EasyMock.expect(cli.hasOption("t")).andReturn(true);
+    EasyMock.expect(cli.hasOption("t")).andReturn(true);
+    EasyMock.expect(cli.getOptionValue("t")).andReturn("foo");
+    EasyMock.expect(cli.hasOption("ns")).andReturn(false);
+    EasyMock.expect(cli.getOptionValue("p")).andReturn("21");
+    EasyMock.expect(cli.getOptionValue("class")).andReturn("org.apache.accumulo.core.iterators.user.ColumnAgeOffFilter");
+    EasyMock.expect(cli.hasOption("ageoff")).andReturn(false);
+    EasyMock.expect(cli.hasOption("agg")).andReturn(false);
+    EasyMock.expect(cli.hasOption("regex")).andReturn(false);
+    EasyMock.expect(cli.hasOption("reqvis")).andReturn(false);
+    EasyMock.expect(cli.hasOption("vers")).andReturn(false);
+    EasyMock.expect(cli.getOptionValue("n", null)).andReturn(null);
+
+    // Loading the class
+    EasyMock.expect(shellState.getClassLoader(cli, shellState)).andReturn(AccumuloVFSClassLoader.getClassLoader());
+
+    // Set the output object
+    Field field = reader.getClass().getSuperclass().getDeclaredField("out");
+    field.setAccessible(true);
+    field.set(reader, out);
+
+    // Parsing iterator options
+    reader.flush();
+    EasyMock.expectLastCall().times(3);
+
+    EasyMock.expect(shellState.getReader()).andReturn(reader);
+
+    // Shell asking for negate option, we pass in an empty string to pickup the default value
of 'false'
+    EasyMock.expect(reader.readLine(EasyMock.anyObject(String.class))).andReturn("");
+
+    // Shell asking for the unnamed option for the column (a:a) and the TTL (1)
+    EasyMock.expect(reader.readLine(EasyMock.anyObject(String.class))).andReturn("a:a 1");
+
+    // Shell asking for another unnamed option; we pass in an empty string to signal that
we are done adding options
+    EasyMock.expect(reader.readLine(EasyMock.anyObject(String.class))).andReturn("");
+    EasyMock.expect(shellState.getConnector()).andReturn(conn);
+
+    // Table exists
+    EasyMock.expect(conn.tableOperations()).andReturn(tableOperations);
+    EasyMock.expect(tableOperations.exists("foo")).andReturn(true);
+
+    // Testing class load
+    EasyMock.expect(shellState.getConnector()).andReturn(conn);
+    EasyMock.expect(conn.tableOperations()).andReturn(tableOperations);
+    EasyMock.expect(tableOperations.testClassLoad("foo", "org.apache.accumulo.core.iterators.user.ColumnAgeOffFilter",
SortedKeyValueIterator.class.getName()))
+        .andReturn(true);
+
+    // Attach iterator
+    EasyMock.expect(shellState.getConnector()).andReturn(conn);
+    EasyMock.expect(conn.tableOperations()).andReturn(tableOperations);
+    tableOperations.attachIterator(EasyMock.anyString(), EasyMock.anyObject(IteratorSetting.class),
EasyMock.anyObject(EnumSet.class));
+    EasyMock.expectLastCall().once();
+
+    EasyMock.replay(conn, cli, shellState, reader, tableOperations);
+
+    cmd.execute("setiter -all -p 21 -t foo -class org.apache.accumulo.core.iterators.user.ColumnAgeOffFilter",
cli, shellState);
+
+    EasyMock.verify(conn, cli, shellState, reader, tableOperations);
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
['"commits@accumulo.apache.org" <commits@accumulo.apache.org>'].

Mime
View raw message