).iterator(); jg.writeStartArray(); while (resultIterator.hasNext()) {
try (final ResultIterator<byte[]> dbSegments = sql.map(ByteArrayMapper.FIRST).iterator()) { return VersionedIntervalTimeline.forSegments( Iterators.transform(
.bind("accountRecordId", context.getAccountRecordId()) .bind("tenantRecordId", context.getTenantRecordId()) .iterator(); try { while (iterator.hasNext()) {
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; }
.bind("dataSource", dataSource) .map(ByteArrayMapper.FIRST) .iterator(), payload -> { try {
@Override public Set<String> getProjects() { try (Handle handle = dbi.open()) { return ImmutableSet.copyOf( handle.createQuery("select name from project") .map(StringMapper.FIRST).iterator()); } }
@Override public Set<String> getProjects() { try (Handle handle = dbi.open()) { return ImmutableSet.copyOf( handle.createQuery("select name from project") .map(StringMapper.FIRST).iterator()); } }
p.apiKeys.add(ProjectApiKeys.create(r.getString(6), r.getString(7), r.getString(8))); return null; }).iterator();
.bind("collection", checkProject(collection)) .bind("schema", checkProject(project)) .map(LongMapper.FIRST).iterator().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 testEmptyWorksToo() throws Exception { ResultIterator<Map<String, Object>> it = h.createQuery("select * from something order by id") .cleanupHandle() .iterator(); assertFalse(it.hasNext()); }
@Test public void testEmptyWorksToo() throws Exception { ResultIterator<Map<String, Object>> it = h.createQuery("select * from something order by id") .cleanupHandle() .iterator(); assertFalse(it.hasNext()); }
@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 testBasicCleanupIterator() throws Exception { final Handle handle = dbi.open(); final Query<Integer> q = handle.createQuery("SELECT COUNT(1) FROM something") .cleanupHandle() .map(IntegerMapper.FIRST); final ResultIterator<Integer> it = q.iterator(); assertEquals(COUNT, Iterators.getOnlyElement(it).intValue()); assertFalse(it.hasNext()); assertTrue(handle.getConnection().isClosed()); }
@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 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()); }