accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject [2/3] git commit: ACCUMULO-1730 Correct ParseTree start/end markers for logical connector nodes.
Date Tue, 15 Oct 2013 17:42:14 GMT
ACCUMULO-1730 Correct ParseTree start/end markers for logical connector nodes.


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/33118cb7
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/33118cb7
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/33118cb7

Branch: refs/heads/master
Commit: 33118cb721b9598af5cbe26cd4048ecb7189f0a0
Parents: 9ceb320
Author: John Stoneham <jstoneham@texeltek.com>
Authored: Tue Oct 15 13:15:00 2013 -0400
Committer: John Stoneham <jstoneham@texeltek.com>
Committed: Tue Oct 15 13:15:00 2013 -0400

----------------------------------------------------------------------
 .../core/security/ColumnVisibility.java         | 14 +++---
 .../core/security/ColumnVisibilityTest.java     | 52 ++++++++++++++++++--
 2 files changed, 56 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/33118cb7/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java b/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java
index 55a9df0..2b9b49d 100644
--- a/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java
+++ b/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java
@@ -56,8 +56,8 @@ public class ColumnVisibility {
   public static class Node {
     public final static List<Node> EMPTY = Collections.emptyList();
     NodeType type;
-    final int start;
-    final int end;
+    int start;
+    int end;
     List<Node> children = EMPTY;
     
     public Node(NodeType type, int start) {
@@ -247,6 +247,7 @@ public class ColumnVisibility {
     Node parse_(byte[] expression) {
       Node result = null;
       Node expr = null;
+      int wholeTermStart = index;
       int subtermStart = index;
       boolean subtermComplete = false;
       
@@ -258,7 +259,7 @@ public class ColumnVisibility {
               if (!result.type.equals(NodeType.AND))
                 throw new BadArgumentException("cannot mix & and |", new String(expression),
index - 1);
             } else {
-              result = new Node(NodeType.AND, index - 1);
+              result = new Node(NodeType.AND, wholeTermStart);
             }
             result.add(expr);
             expr = null;
@@ -272,7 +273,7 @@ public class ColumnVisibility {
               if (!result.type.equals(NodeType.OR))
                 throw new BadArgumentException("cannot mix | and &", new String(expression),
index - 1);
             } else {
-              result = new Node(NodeType.OR, index - 1);
+              result = new Node(NodeType.OR, wholeTermStart);
             }
             result.add(expr);
             expr = null;
@@ -339,9 +340,10 @@ public class ColumnVisibility {
         }
       }
       Node child = processTerm(subtermStart, index, expr, expression);
-      if (result != null)
+      if (result != null) {
         result.add(child);
-      else
+        result.end = index;
+      } else
         result = child;
       if (result.type != NodeType.TERM)
         if (result.children.size() < 2)

http://git-wip-us.apache.org/repos/asf/accumulo/blob/33118cb7/core/src/test/java/org/apache/accumulo/core/security/ColumnVisibilityTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/security/ColumnVisibilityTest.java
b/core/src/test/java/org/apache/accumulo/core/security/ColumnVisibilityTest.java
index 1e81b54..b5f08a2 100644
--- a/core/src/test/java/org/apache/accumulo/core/security/ColumnVisibilityTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/security/ColumnVisibilityTest.java
@@ -20,6 +20,7 @@ import static org.apache.accumulo.core.security.ColumnVisibility.quote;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 
 import org.apache.accumulo.core.security.ColumnVisibility.Node;
 import org.apache.accumulo.core.security.ColumnVisibility.NodeType;
@@ -148,21 +149,64 @@ public class ColumnVisibilityTest {
     assertEquals("[\"δΊ”\"]", cv.toString());
   }
 
+  @Test
   public void testParseTree() {
-    String s = "(W)|(U&V)";
-    ColumnVisibility v = new ColumnVisibility(s);
-    Node node = v.getParseTree();
+    Node node = parse("(W)|(U&V)";
     assertNode(node, NodeType.OR, 3, 4);
     assertNode(node.getChildren().get(0), NodeType.TERM, 1, 2);
     assertNode(node.getChildren().get(1), NodeType.AND, 6, 7);
+  }
+
+  @Test
+  public void testParseTreeWithNoChildren() {
+    Node node = parse("ABC");
+    assertNode(node, NodeType.TERM, 0, 3);
+  }
+
+  @Test
+  public void testParseTreeWithTwoChildren() {
+    Node node = parse("ABC|DEF");
+    assertNode(node, NodeType.OR, 0, 7);
+    assertNode(node.getChildren().get(0), NodeType.TERM, 0, 3);
+    assertNode(node.getChildren().get(1), NodeType.TERM, 4, 7);
+  }
+
+  @Test
+  public void testParseTreeWithParenthesesAndTwoChildren() {
+    Node node = parse("(ABC|DEF)");
+    assertNode(node, NodeType.OR, 1, 8);
+    assertNode(node.getChildren().get(0), NodeType.TERM, 1, 4);
+    assertNode(node.getChildren().get(1), NodeType.TERM, 5, 8);
+  }
+
+  @Test
+  public void testParseTreeWithParenthesizedChildren() {
+    Node node = parse("ABC|(DEF&GHI)");
+    assertNode(node, NodeType.OR, 0, 13);
+    assertNode(node.getChildren().get(0), NodeType.TERM, 0, 3);
+    assertNode(node.getChildren().get(1), NodeType.AND, 5, 12);
+    assertNode(node.getChildren().get(1).children.get(0), NodeType.TERM, 5, 8);
+    assertNode(node.getChildren().get(1).children.get(1), NodeType.TERM, 9, 12);
+  }
+
+  @Test
+  public void testParseTreeWithMoreParentheses() {
+    Node node = parse("(W)|(U&V)");
+    assertNode(node, NodeType.OR, 0, 9);
+    assertNode(node.getChildren().get(0), NodeType.TERM, 1, 2);
+    assertNode(node.getChildren().get(1), NodeType.AND, 5, 8);
     assertNode(node.getChildren().get(1).children.get(0), NodeType.TERM, 5, 6);
     assertNode(node.getChildren().get(1).children.get(1), NodeType.TERM, 7, 8);
   }
 
+  private Node parse(String s) {
+    ColumnVisibility v = new ColumnVisibility(s);
+    return v.getParseTree();
+  }
+
   private void assertNode(Node node, NodeType nodeType, int start, int end) {
     assertEquals(node.type, nodeType);
     assertEquals(start, node.start);
     assertEquals(end, node.end);
-
   }
 }


Mime
View raw message