You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ec...@apache.org on 2013/10/15 19:42:13 UTC
[1/3] git commit: ACCUMULO-1730 Rename variable for clarity.
Updated Branches:
refs/heads/master 95ea4e1f8 -> 876c5ce5e
ACCUMULO-1730 Rename variable for clarity.
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/9ceb320e
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/9ceb320e
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/9ceb320e
Branch: refs/heads/master
Commit: 9ceb320e1742a7b0fbb3bd753d28453e9313f517
Parents: 95ea4e1
Author: John Stoneham <js...@texeltek.com>
Authored: Tue Oct 15 13:14:14 2013 -0400
Committer: John Stoneham <js...@texeltek.com>
Committed: Tue Oct 15 13:14:14 2013 -0400
----------------------------------------------------------------------
.../core/security/ColumnVisibility.java | 38 ++++++++++----------
1 file changed, 19 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/9ceb320e/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 17d4fd4..55a9df0 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
@@ -247,13 +247,13 @@ public class ColumnVisibility {
Node parse_(byte[] expression) {
Node result = null;
Node expr = null;
- int termStart = index;
- boolean termComplete = false;
+ int subtermStart = index;
+ boolean subtermComplete = false;
while (index < expression.length) {
switch (expression[index++]) {
case '&': {
- expr = processTerm(termStart, index - 1, expr, expression);
+ expr = processTerm(subtermStart, index - 1, expr, expression);
if (result != null) {
if (!result.type.equals(NodeType.AND))
throw new BadArgumentException("cannot mix & and |", new String(expression), index - 1);
@@ -262,12 +262,12 @@ public class ColumnVisibility {
}
result.add(expr);
expr = null;
- termStart = index;
- termComplete = false;
+ subtermStart = index;
+ subtermComplete = false;
break;
}
case '|': {
- expr = processTerm(termStart, index - 1, expr, expression);
+ expr = processTerm(subtermStart, index - 1, expr, expression);
if (result != null) {
if (!result.type.equals(NodeType.OR))
throw new BadArgumentException("cannot mix | and &", new String(expression), index - 1);
@@ -276,22 +276,22 @@ public class ColumnVisibility {
}
result.add(expr);
expr = null;
- termStart = index;
- termComplete = false;
+ subtermStart = index;
+ subtermComplete = false;
break;
}
case '(': {
parens++;
- if (termStart != index - 1 || expr != null)
+ if (subtermStart != index - 1 || expr != null)
throw new BadArgumentException("expression needs & or |", new String(expression), index - 1);
expr = parse_(expression);
- termStart = index;
- termComplete = false;
+ subtermStart = index;
+ subtermComplete = false;
break;
}
case ')': {
parens--;
- Node child = processTerm(termStart, index - 1, expr, expression);
+ Node child = processTerm(subtermStart, index - 1, expr, expression);
if (child == null && result == null)
throw new BadArgumentException("empty expression not allowed", new String(expression), index);
if (result == null)
@@ -304,7 +304,7 @@ public class ColumnVisibility {
return result;
}
case '"': {
- if (termStart != index - 1)
+ if (subtermStart != index - 1)
throw new BadArgumentException("expression needs & or |", new String(expression), index - 1);
while (index < expression.length && expression[index] != '"') {
@@ -317,19 +317,19 @@ public class ColumnVisibility {
}
if (index == expression.length)
- throw new BadArgumentException("unclosed quote", new String(expression), termStart);
+ throw new BadArgumentException("unclosed quote", new String(expression), subtermStart);
- if (termStart + 1 == index)
- throw new BadArgumentException("empty term", new String(expression), termStart);
+ if (subtermStart + 1 == index)
+ throw new BadArgumentException("empty term", new String(expression), subtermStart);
index++;
- termComplete = true;
+ subtermComplete = true;
break;
}
default: {
- if (termComplete)
+ if (subtermComplete)
throw new BadArgumentException("expression needs & or |", new String(expression), index - 1);
byte c = expression[index - 1];
@@ -338,7 +338,7 @@ public class ColumnVisibility {
}
}
}
- Node child = processTerm(termStart, index, expr, expression);
+ Node child = processTerm(subtermStart, index, expr, expression);
if (result != null)
result.add(child);
else
[3/3] git commit: ACCUMULO-1730 Expose ColumnVisibility
normalize/stringify methods.
Posted by ec...@apache.org.
ACCUMULO-1730 Expose ColumnVisibility normalize/stringify methods.
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/876c5ce5
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/876c5ce5
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/876c5ce5
Branch: refs/heads/master
Commit: 876c5ce5ee9a039d56c8e4c7ca04d0401a47cdac
Parents: 33118cb
Author: John Stoneham <js...@texeltek.com>
Authored: Tue Oct 15 13:15:19 2013 -0400
Committer: John Stoneham <js...@texeltek.com>
Committed: Tue Oct 15 13:15:19 2013 -0400
----------------------------------------------------------------------
.../org/apache/accumulo/core/security/ColumnVisibility.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/876c5ce5/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 2b9b49d..55763bc 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
@@ -144,7 +144,7 @@ public class ColumnVisibility {
/*
* Convience method that delegates to normalize with a new NodeComparator constructed using the supplied expression.
*/
- private static Node normalize(Node root, byte[] expression) {
+ public static Node normalize(Node root, byte[] expression) {
return normalize(root, expression, new NodeComparator(expression));
}
@@ -156,7 +156,7 @@ public class ColumnVisibility {
* 3) dedupes labels (`a&b&a` becomes `a&b`)
*/
// @formatter:on
- private static Node normalize(Node root, byte[] expression, NodeComparator comparator) {
+ public static Node normalize(Node root, byte[] expression, NodeComparator comparator) {
if (root.type != NodeType.TERM) {
TreeSet<Node> rolledUp = new TreeSet<Node>(comparator);
java.util.Iterator<Node> itr = root.children.iterator();
@@ -183,7 +183,7 @@ public class ColumnVisibility {
/*
* Walks an expression's AST and appends a string representation to a supplied StringBuilder. This method adds parens where necessary.
*/
- private static void stringify(Node root, byte[] expression, StringBuilder out) {
+ public static void stringify(Node root, byte[] expression, StringBuilder out) {
if (root.type == NodeType.TERM) {
out.append(new String(expression, root.start, root.end - root.start));
} else {
[2/3] git commit: ACCUMULO-1730 Correct ParseTree start/end markers
for logical connector nodes.
Posted by ec...@apache.org.
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 <js...@texeltek.com>
Authored: Tue Oct 15 13:15:00 2013 -0400
Committer: John Stoneham <js...@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);
-
}
}