jg.writeStartArray(); while (resultIterator.hasNext()) { jg.writeObject(resultIterator.next());
try { while (iterator.hasNext()) { final Map<String, Object> row = iterator.next();
private List<SegmentIdWithShardSpec> getPendingSegmentsForIntervalWithHandle( final Handle handle, final String dataSource, final Interval interval ) throws IOException { final List<SegmentIdWithShardSpec> identifiers = new ArrayList<>(); final ResultIterator<byte[]> dbSegments = handle.createQuery( StringUtils.format( "SELECT payload FROM %1$s WHERE dataSource = :dataSource AND start <= :end and %2$send%2$s >= :start", dbTables.getPendingSegmentsTable(), connector.getQuoteString() ) ) .bind("dataSource", dataSource) .bind("start", interval.getStart().toString()) .bind("end", interval.getEnd().toString()) .map(ByteArrayMapper.FIRST) .iterator(); while (dbSegments.hasNext()) { final byte[] payload = dbSegments.next(); final SegmentIdWithShardSpec identifier = jsonMapper.readValue(payload, SegmentIdWithShardSpec.class); if (interval.overlaps(identifier.getInterval())) { identifiers.add(identifier); } } dbSegments.close(); return identifiers; }
private static VersionedIntervalTimeline<String, DataSegment> getTimelineForIntervalWithHandle(final Handle handle, final String dataSource, final Interval interval, final MetadataStorageTablesConfig dbTables) throws IOException { Query<Map<String, Object>> sql = handle.createQuery(String.format( "SELECT payload FROM %s WHERE used = true AND dataSource = ? AND start <= ? AND \"end\" >= ?", dbTables.getSegmentsTable())) .bind(0, dataSource) .bind(1, interval.getEnd().toString()) .bind(2, interval.getStart().toString()); final VersionedIntervalTimeline<String, DataSegment> timeline = new VersionedIntervalTimeline<>(Ordering.natural()); try (ResultIterator<byte[]> dbSegments = sql.map(ByteArrayMapper.FIRST).iterator()) { while (dbSegments.hasNext()) { final byte[] payload = dbSegments.next(); DataSegment segment = JSON_MAPPER.readValue(payload, DataSegment.class); timeline.add(segment.getInterval(), segment.getVersion(), segment.getShardSpec().createChunk(segment)); } } return timeline; }
user.next();
.bind("collection", checkProject(collection)) .bind("schema", checkProject(project)) .map(LongMapper.FIRST).iterator().next();
@Override public synchronized T next() { checkState(!closed, "already closed"); return iterator.next(); }
@Override public synchronized T next() { checkState(!closed, "already closed"); return iterator.next(); }
@Override public T next() { return withContainer(serializer.<T>bytesToObject(resultIterator.next())); } };
@Override public T next() { return withContainer(serializer.<T>bytesToObject(resultIterator.next())); } };
public Object next() { Object rs = itty.next(); boolean has_next = itty.hasNext(); if (!has_next) { baton.release("iterator"); } return rs; }
// Iterate through the results. final ResultIterator iterator = baseApi.getResultIterator(); String lastUTF8Text; float lastConfidence; int count = 0; iterator.begin(); do { lastUTF8Text = iterator.getUTF8Text(PageIteratorLevel.RIL_WORD); lastConfidence = iterator.confidence(PageIteratorLevel.RIL_WORD); count++; } while (iterator.next(PageIteratorLevel.RIL_WORD));
@Override protected void run(Environment env, Namespace namespace, T configuration) throws Exception { CliConveniences.quietLogging("ifar"); final DBIFactory factory = new DBIFactory(); final DBI jdbi = factory.build(env, getSkidRoadReadOnlyConfiguration(configuration).getDatabaseConfiguration(), "logfile"); JDBILogFileDAO dao = jdbi.onDemand(DefaultJDBILogFileDAO.class); try (ResultIterator<String> ownerUris = dao.listOwnerUris()) { while (ownerUris.hasNext()) { System.out.println(ownerUris.next()); } } } }
@Test public void testJustNext() throws Exception { h.createStatement("insert into something (id, name) values (1, 'eric')").execute(); h.createStatement("insert into something (id, name) values (2, 'brian')").execute(); h.createStatement("insert into something (id, name) values (3, 'john')").execute(); ResultIterator<Map<String, Object>> it = h.createQuery("select * from something order by id") .cleanupHandle() .iterator(); it.next(); it.next(); it.next(); }
@Test public void testJustNext() throws Exception { h.createStatement("insert into something (id, name) values (1, 'eric')").execute(); h.createStatement("insert into something (id, name) values (2, 'brian')").execute(); h.createStatement("insert into something (id, name) values (3, 'john')").execute(); ResultIterator<Map<String, Object>> it = h.createQuery("select * from something order by id") .cleanupHandle() .iterator(); it.next(); it.next(); it.next(); }
@Test public void testNonPathologicalJustNext() throws Exception { h.createStatement("insert into something (id, name) values (1, 'eric')").execute(); // Yes, you *should* use first(). But sometimes, an iterator is passed 17 levels deep and then // used in this way (Hello Jackson!). final Map<String, Object> result = h.createQuery("select * from something order by id") .cleanupHandle() .iterator() .next(); assertEquals(1, result.get("id")); assertEquals("eric", result.get("name")); }
@Test public void testNonPathologicalJustNext() throws Exception { h.createStatement("insert into something (id, name) values (1, 'eric')").execute(); // Yes, you *should* use first(). But sometimes, an iterator is passed 17 levels deep and then // used in this way (Hello Jackson!). final Map<String, Object> result = h.createQuery("select * from something order by id") .cleanupHandle() .iterator() .next(); assertEquals(1, result.get("id")); assertEquals("eric", result.get("name")); }
@Test public void testEmptyExplosion() throws Exception { ResultIterator<Map<String, Object>> it = h.createQuery("select * from something order by id") .cleanupHandle() .iterator(); try { it.next(); fail("Expected IllegalStateException did not show up!"); } catch (IllegalStateException iae) { // TestCase does not deal with the annotations... } }
@Test public void testFetchSize() throws Exception { h.createScript("default-data").execute(); Query<Something> q = h.createQuery("select id, name from something order by id").map(Something.class); q.setFetchSize(1); ResultIterator<Something> r = q.iterator(); assertTrue(r.hasNext()); r.next(); assertTrue(r.hasNext()); r.next(); assertFalse(r.hasNext()); }
@Test public void testFetchSize() throws Exception { h.createScript("default-data").execute(); Query<Something> q = h.createQuery("select id, name from something order by id").map(Something.class); q.setFetchSize(1); ResultIterator<Something> r = q.iterator(); assertTrue(r.hasNext()); r.next(); assertTrue(r.hasNext()); r.next(); assertFalse(r.hasNext()); }