diff --git a/tikv-client/src/main/java/com/pingcap/tikv/meta/TiDAGRequest.java b/tikv-client/src/main/java/com/pingcap/tikv/meta/TiDAGRequest.java index bc49c96c57..15caea32ea 100644 --- a/tikv-client/src/main/java/com/pingcap/tikv/meta/TiDAGRequest.java +++ b/tikv-client/src/main/java/com/pingcap/tikv/meta/TiDAGRequest.java @@ -358,9 +358,7 @@ private DAGRequest.Builder buildScan(boolean buildIndexScan) { if (pos != null) { TiColumnInfo columnInfo = columnInfoList.get(indexColOffsets.get(pos)); if (col.getColumnInfo().equals(columnInfo)) { - dagRequestBuilder.addOutputOffsets(pos); colOffsetInFieldMap.put(col, pos); - addRequiredIndexDataType(col.getType()); } // TODO: primary key may also be considered if pkIsHandle } diff --git a/tikv-client/src/main/java/com/pingcap/tikv/operation/iterator/CoprocessIterator.java b/tikv-client/src/main/java/com/pingcap/tikv/operation/iterator/CoprocessIterator.java index a35922a7ea..f42b1ba337 100644 --- a/tikv-client/src/main/java/com/pingcap/tikv/operation/iterator/CoprocessIterator.java +++ b/tikv-client/src/main/java/com/pingcap/tikv/operation/iterator/CoprocessIterator.java @@ -30,7 +30,6 @@ import com.pingcap.tikv.util.RangeSplitter.RegionTask; import java.util.Iterator; import java.util.List; -import java.util.NoSuchElementException; public abstract class CoprocessIterator implements Iterator { protected final TiSession session; @@ -80,11 +79,7 @@ public static CoprocessIterator getRowIterator( dagRequest.getPushDownType()) { @Override public Row next() { - if (hasNext()) { - return rowReader.readRow(schemaInfer.getTypes().toArray(new DataType[0])); - } else { - throw new NoSuchElementException(); - } + return rowReader.readRow(schemaInfer.getTypes().toArray(new DataType[0])); } }; } @@ -109,11 +104,7 @@ public static CoprocessIterator getHandleIterator( req.getPushDownType()) { @Override public Long next() { - if (hasNext()) { - return rowReader.readRow(handleTypes).getLong(handleTypes.length - 1); - } else { - throw new NoSuchElementException(); - } + return rowReader.readRow(handleTypes).getLong(handleTypes.length - 1); } }; } diff --git a/tikv-client/src/test/java/com/pingcap/tikv/operation/iterator/DAGIteratorTest.java b/tikv-client/src/test/java/com/pingcap/tikv/operation/iterator/DAGIteratorTest.java index f68950d93b..c6f5dd0f97 100644 --- a/tikv-client/src/test/java/com/pingcap/tikv/operation/iterator/DAGIteratorTest.java +++ b/tikv-client/src/test/java/com/pingcap/tikv/operation/iterator/DAGIteratorTest.java @@ -81,10 +81,14 @@ public void staleEpochTest() { server.put("key1", cdo.toByteString()); List tasks = ImmutableList.of(RegionTask.newInstance(region, store, keyRanges)); CoprocessIterator iter = CoprocessIterator.getRowIterator(req, tasks, session); - Row r = iter.next(); - SchemaInfer infer = SchemaInfer.create(req); - assertEquals(r.get(0, infer.getType(0)), 666L); - assertEquals(r.get(1, infer.getType(1)), "value1"); + if (!iter.hasNext()) { + assertEquals("iterator has next should be true", true, false); + } else { + Row r = iter.next(); + SchemaInfer infer = SchemaInfer.create(req); + assertEquals(r.get(0, infer.getType(0)), 666L); + assertEquals(r.get(1, infer.getType(1)), "value1"); + } } private static KeyRange createByteStringRange(ByteString sKey, ByteString eKey) {