diff --git a/src/java/org/apache/cassandra/index/sai/memory/TrieMemoryIndex.java b/src/java/org/apache/cassandra/index/sai/memory/TrieMemoryIndex.java index c531ba6696c3..9773570816cc 100644 --- a/src/java/org/apache/cassandra/index/sai/memory/TrieMemoryIndex.java +++ b/src/java/org/apache/cassandra/index/sai/memory/TrieMemoryIndex.java @@ -90,6 +90,7 @@ public TrieMemoryIndex(StorageAttachedIndex index) @Override public synchronized long add(DecoratedKey key, Clustering clustering, ByteBuffer value) { + //pranav: this one value = index.termType().asIndexBytes(value); final PrimaryKey primaryKey = index.hasClustering() ? index.keyFactory().create(key, clustering) : index.keyFactory().create(key); @@ -147,6 +148,9 @@ public KeyRangeIterator search(QueryContext queryContext, Expression expression, case CONTAINS_KEY: case CONTAINS_VALUE: return exactMatch(expression, keyRange); + case LIKE_PREFIX: + //TODO: this needs to be handled cleaner way + expression.upper = null; case RANGE: KeyRangeIterator keyIterator = rangeMatch(expression, keyRange); int keyCount = (int) keyIterator.getMaxKeys(); diff --git a/src/java/org/apache/cassandra/index/sai/utils/IndexTermType.java b/src/java/org/apache/cassandra/index/sai/utils/IndexTermType.java index 2f07f76ad44f..4a2359c995fa 100644 --- a/src/java/org/apache/cassandra/index/sai/utils/IndexTermType.java +++ b/src/java/org/apache/cassandra/index/sai/utils/IndexTermType.java @@ -592,9 +592,9 @@ public float[] decomposeVector(ByteBuffer byteBuffer) public boolean supports(Operator operator) { - if (operator == Operator.LIKE || - operator == Operator.LIKE_CONTAINS || - operator == Operator.LIKE_PREFIX || + if (operator == Operator.LIKE || operator == Operator.LIKE_PREFIX) + return true; + if (operator == Operator.LIKE_CONTAINS || operator == Operator.LIKE_MATCHES || operator == Operator.LIKE_SUFFIX || operator == Operator.IN) return false; diff --git a/src/java/org/apache/cassandra/io/tries/IncrementalTrieWriterPageAware.java b/src/java/org/apache/cassandra/io/tries/IncrementalTrieWriterPageAware.java index 2274975e48e0..7d094e3b842d 100644 --- a/src/java/org/apache/cassandra/io/tries/IncrementalTrieWriterPageAware.java +++ b/src/java/org/apache/cassandra/io/tries/IncrementalTrieWriterPageAware.java @@ -79,8 +79,8 @@ * Since this was the root of the trie, the current page is padded and the remaining nodes 0, 5 are written. */ @NotThreadSafe -public class IncrementalTrieWriterPageAware -extends IncrementalTrieWriterBase> +public class IncrementalTrieWriterPageAware> +extends IncrementalTrieWriterBase implements IncrementalTrieWriter { final int maxBytesPerPage; @@ -103,22 +103,21 @@ public class IncrementalTrieWriterPageAware return c; }; - IncrementalTrieWriterPageAware(TrieSerializer trieSerializer, DataOutputPlus dest) + IncrementalTrieWriterPageAware(TrieSerializer trieSerializer, DataOutputPlus dest, NODE root) { - super(trieSerializer, dest, new Node<>((byte) 0)); + super(trieSerializer, dest, root); this.maxBytesPerPage = dest.maxBytesInPage(); } @Override public void reset() { - reset(new Node<>((byte) 0)); + reset(new Node((byte) 0)); } - @Override - Node performCompletion() throws IOException + NODE performCompletion() throws IOException { - Node root = super.performCompletion(); + NODE root = super.performCompletion(); int actualSize = recalcTotalSize(root, dest.position()); int bytesLeft = dest.bytesLeftInPage(); @@ -153,12 +152,12 @@ Node performCompletion() throws IOException } @Override - void complete(Node node) throws IOException + void complete(NODE node) throws IOException { assert node.filePos == -1; int branchSize = 0; - for (Node child : node.children) + for (NODE child : node.children) branchSize += child.branchSize + child.nodeSize; node.branchSize = branchSize; @@ -171,7 +170,7 @@ void complete(Node node) throws IOException node.hasOutOfPageChildren = false; node.hasOutOfPageInBranch = false; - for (Node child : node.children) + for (Node child : node.children) if (child.filePos != -1) node.hasOutOfPageChildren = true; else if (child.hasOutOfPageChildren || child.hasOutOfPageInBranch) @@ -184,19 +183,19 @@ else if (child.hasOutOfPageChildren || child.hasOutOfPageInBranch) layoutChildren(node); } - private void layoutChildren(Node node) throws IOException + private void layoutChildren(Node node) throws IOException { assert node.filePos == -1; - NavigableSet> children = node.getChildrenWithUnsetPosition(); + NavigableSet> children = node.getChildrenWithUnsetPosition(); int bytesLeft = dest.bytesLeftInPage(); - Node cmp = new Node<>(256); // goes after all equal-sized unplaced nodes (whose transition character is 0-255) + Node cmp = new Node(256); // goes after all equal-sized unplaced nodes (whose transition character is 0-255) cmp.nodeSize = 0; while (!children.isEmpty()) { cmp.branchSize = bytesLeft; - Node child = children.headSet(cmp, true).pollLast(); // grab biggest that could fit + Node child = children.headSet(cmp, true).pollLast(); // grab biggest that could fit if (child == null) { dest.padToPageBoundary(); @@ -245,12 +244,12 @@ private void layoutChildren(Node node) throws IOException } @SuppressWarnings("DuplicatedCode") // intentionally duplicated in IncrementalDeepTrieWriterPageAware - protected int recalcTotalSize(Node node, long nodePosition) throws IOException + protected int recalcTotalSize(Node node, long nodePosition) throws IOException { if (node.hasOutOfPageInBranch) { int sz = 0; - for (Node child : node.children) + for (Node child : node.children) sz += recalcTotalSize(child, nodePosition + sz); node.branchSize = sz; } @@ -264,10 +263,10 @@ protected int recalcTotalSize(Node node, long nodePosition) throws IOExce } @SuppressWarnings("DuplicatedCode") // intentionally duplicated in IncrementalDeepTrieWriterPageAware - protected long write(Node node) throws IOException + protected long write(Node node) throws IOException { long nodePosition = dest.position(); - for (Node child : node.children) + for (Node child : node.children) if (child.filePos == -1) child.filePos = write(child); @@ -283,14 +282,14 @@ protected long write(Node node) throws IOException return nodePosition; } - protected String dumpNode(Node node, long nodePosition) + protected String dumpNode(NODE node, long nodePosition) { StringBuilder res = new StringBuilder(String.format("At %,d(%x) type %s child count %s nodeSize %,d branchSize %,d %s%s%n", nodePosition, nodePosition, TrieNode.typeFor(node, nodePosition), node.childCount(), node.nodeSize, node.branchSize, node.hasOutOfPageChildren ? "C" : "", node.hasOutOfPageInBranch ? "B" : "")); - for (Node child : node.children) + for (NODE child : node.children) res.append(String.format("Child %2x at %,d(%x) type %s child count %s size %s nodeSize %,d branchSize %,d %s%s%n", child.transition & 0xFF, child.filePos, @@ -327,12 +326,12 @@ public PartialTail makePartialRoot() throws IOException } @SuppressWarnings("DuplicatedCode") // intentionally duplicated in IncrementalDeepTrieWriterPageAware - protected long writePartial(Node node, DataOutputPlus dest, long baseOffset) throws IOException + protected long writePartial(NODE node, DataOutputPlus dest, long baseOffset) throws IOException { long startPosition = dest.position() + baseOffset; - List> childrenToClear = new ArrayList<>(); - for (Node child : node.children) + List childrenToClear = new ArrayList<>(); + for (NODE child : node.children) { if (child.filePos == -1) { @@ -360,12 +359,12 @@ protected long writePartial(Node node, DataOutputPlus dest, long baseOffs node.nodeSize = (int) (endPosition - nodePosition); } - for (Node child : childrenToClear) + for (NODE child : childrenToClear) child.filePos = -1; return nodePosition; } - static class Node extends IncrementalTrieWriterBase.BaseNode> + static class Node> extends IncrementalTrieWriterBase.BaseNode { /** * Currently calculated size of the branch below this node, not including the node itself. @@ -397,9 +396,9 @@ static class Node extends IncrementalTrieWriterBase.BaseNode newNode(byte transition) + NODE newNode(byte transition) { - return new Node<>(transition & 0xFF); + return new Node(transition & 0xFF); } public long serializedPositionDelta(int i, long nodePosition) @@ -427,7 +426,7 @@ public long maxPositionDelta(long nodePosition) long minPlaced = 0; long minUnplaced = 1; - for (Node child : children) + for (NODE child : children) { if (child.filePos != -1) minPlaced = Math.min(minPlaced, child.filePos - nodePosition); @@ -438,10 +437,10 @@ else if (minUnplaced > 0) // triggers once return Math.min(minPlaced, minUnplaced); } - NavigableSet> getChildrenWithUnsetPosition() + NavigableSet> getChildrenWithUnsetPosition() { - NavigableSet> result = new TreeSet<>(BRANCH_SIZE_COMPARATOR); - for (Node child : children) + NavigableSet> result = new TreeSet<>(BRANCH_SIZE_COMPARATOR); + for (Node child : children) if (child.filePos == -1) result.add(child);