You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by br...@apache.org on 2014/01/26 16:05:24 UTC
git commit: Add iterable CqlPagingRecordReader. Patch by Luca
Rosellini, reviewed by brandonwilliams for CASSANDRA-6497
Updated Branches:
refs/heads/trunk f5d542c5a -> 4d13d0998
Add iterable CqlPagingRecordReader.
Patch by Luca Rosellini, reviewed by brandonwilliams for CASSANDRA-6497
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/4d13d099
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/4d13d099
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/4d13d099
Branch: refs/heads/trunk
Commit: 4d13d09985722e1a06e45f1e96dff7d771959068
Parents: f5d542c
Author: Brandon Williams <br...@apache.org>
Authored: Sun Jan 26 09:02:29 2014 -0600
Committer: Brandon Williams <br...@apache.org>
Committed: Sun Jan 26 09:03:31 2014 -0600
----------------------------------------------------------------------
.../hadoop/cql3/CqlPagingRecordReader.java | 4 +-
.../cql3/IterableCqlPagingRecordReader.java | 75 ++++++++++++++++++++
2 files changed, 77 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4d13d099/src/java/org/apache/cassandra/hadoop/cql3/CqlPagingRecordReader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/hadoop/cql3/CqlPagingRecordReader.java b/src/java/org/apache/cassandra/hadoop/cql3/CqlPagingRecordReader.java
index d9b9a39..002992f 100644
--- a/src/java/org/apache/cassandra/hadoop/cql3/CqlPagingRecordReader.java
+++ b/src/java/org/apache/cassandra/hadoop/cql3/CqlPagingRecordReader.java
@@ -65,7 +65,7 @@ public class CqlPagingRecordReader extends RecordReader<Map<String, ByteBuffer>,
public static final int DEFAULT_CQL_PAGE_LIMIT = 1000; // TODO: find the number large enough but not OOM
private ColumnFamilySplit split;
- private RowIterator rowIterator;
+ protected RowIterator rowIterator;
private Pair<Map<String, ByteBuffer>, Map<String, ByteBuffer>> currentRow;
private int totalRowCount; // total number of rows to fetch
@@ -282,7 +282,7 @@ public class CqlPagingRecordReader extends RecordReader<Map<String, ByteBuffer>,
}
/** CQL row iterator */
- private class RowIterator extends AbstractIterator<Pair<Map<String, ByteBuffer>, Map<String, ByteBuffer>>>
+ protected class RowIterator extends AbstractIterator<Pair<Map<String, ByteBuffer>, Map<String, ByteBuffer>>>
{
protected int totalRead = 0; // total number of cf rows read
protected Iterator<CqlRow> rows;
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4d13d099/src/java/org/apache/cassandra/hadoop/cql3/IterableCqlPagingRecordReader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/hadoop/cql3/IterableCqlPagingRecordReader.java b/src/java/org/apache/cassandra/hadoop/cql3/IterableCqlPagingRecordReader.java
new file mode 100644
index 0000000..85beed9
--- /dev/null
+++ b/src/java/org/apache/cassandra/hadoop/cql3/IterableCqlPagingRecordReader.java
@@ -0,0 +1,75 @@
+/*
+ * 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.cassandra.hadoop.cql3;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.commons.lang.NotImplementedException;
+
+import org.apache.cassandra.utils.Pair;
+
+/**
+ * Implements an iterable-friendly {@link CqlPagingRecordReader}.
+ */
+public class IterableCqlPagingRecordReader extends CqlPagingRecordReader
+ implements Iterable<Pair<Map<String, ByteBuffer>, Map<String, ByteBuffer>>>, Closeable
+{
+ public Iterator<Pair<Map<String, ByteBuffer>, Map<String, ByteBuffer>>> iterator()
+ {
+ return new Iterator<Pair<Map<String, ByteBuffer>, Map<String, ByteBuffer>>>()
+ {
+ public boolean hasNext()
+ {
+ return rowIterator.hasNext();
+ }
+
+ public Pair<Map<String, ByteBuffer>, Map<String, ByteBuffer>> next()
+ {
+ return rowIterator.next();
+ }
+
+ public void remove()
+ {
+ throw new NotImplementedException("Cannot remove an element on this iterator!");
+
+ }
+ };
+ }
+
+ /**
+ * @throws NotImplementedException Always throws this exception, this operation does not make sense in this implementation.
+ */
+ @Override
+ public boolean nextKeyValue() throws IOException
+ {
+ throw new NotImplementedException("Calling method nextKeyValue() does not make sense in this implementation");
+ }
+
+ /**
+ * @throws NotImplementedException Always throws this exception, this operation does not make sense in this implementation.
+ */
+ @Override
+ public boolean next(Map<String, ByteBuffer> keys, Map<String, ByteBuffer> value) throws IOException
+ {
+ throw new NotImplementedException("Calling method next() does not make sense in this implementation");
+ }
+}