Skip to content

Commit

Permalink
refactor name
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshSingla committed Oct 4, 2023
1 parent 6d51692 commit cdd63cf
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@
* {@link Cursor} that also has a {@link #close()}. Used for cursors that hold some resources and need to be closed by
* the caller
*/
public interface CloseableCursor extends Cursor, Closeable
public interface CursorAndCloseable extends Cursor, Closeable
{
static CloseableCursor cursorWithCloseable(Cursor cursor, Closeable closeable)
static CursorAndCloseable create(Cursor cursor, Closeable closeable)
{

return new CloseableCursor()
return new CursorAndCloseable()
{
@Override
public void close() throws IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class IterableRowsCursorHelper
* Creates a cursor that iterates over all the rows generated by the iterable. Presence of __time column is not a
* necessity
*/
public static CloseableCursor getCursorFromIterable(Iterable<Object[]> rows, RowSignature rowSignature)
public static CursorAndCloseable getCursorFromIterable(Iterable<Object[]> rows, RowSignature rowSignature)
{
return getCursorFromSequence(Sequences.simple(rows), rowSignature);
}
Expand All @@ -49,10 +49,10 @@ public static CloseableCursor getCursorFromIterable(Iterable<Object[]> rows, Row
* Creates a cursor that iterates over all the rows generated by the sequence. Presence of __time column is not a
* necessity.
* <p>
* Returns a {@link CloseableCursor} that iterates over the rows and cleans up the row sequence when
* {@link CloseableCursor#close()} is called on the returned cursor.
* Returns a {@link CursorAndCloseable} that iterates over the rows and cleans up the created rowWalker when
* {@link CursorAndCloseable#close()} is called on the returned object.
*/
public static CloseableCursor getCursorFromSequence(Sequence<Object[]> rows, RowSignature rowSignature)
public static CursorAndCloseable getCursorFromSequence(Sequence<Object[]> rows, RowSignature rowSignature)
{
RowAdapter<Object[]> rowAdapter = columnName -> {
if (rowSignature == null) {
Expand All @@ -78,6 +78,6 @@ public static CloseableCursor getCursorFromSequence(Sequence<Object[]> rows, Row
rowSignature != null ? rowSignature : RowSignature.empty()
);

return CloseableCursor.cursorWithCloseable(baseCursor, rowWalker);
return CursorAndCloseable.create(baseCursor, rowWalker);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import org.apache.druid.java.util.common.guava.Sequences;
import org.apache.druid.java.util.common.jackson.JacksonUtils;
import org.apache.druid.query.CacheStrategy;
import org.apache.druid.query.CloseableCursor;
import org.apache.druid.query.CursorAndCloseable;
import org.apache.druid.query.DataSource;
import org.apache.druid.query.FrameSignaturePair;
import org.apache.druid.query.IterableRowsCursorHelper;
Expand Down Expand Up @@ -726,7 +726,7 @@ public Optional<Sequence<FrameSignaturePair>> resultsAsFrames(
);


CloseableCursor cursor = IterableRowsCursorHelper.getCursorFromSequence(
CursorAndCloseable cursor = IterableRowsCursorHelper.getCursorFromSequence(
resultsAsArrays(query, resultSequence),
rowSignature
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.apache.druid.java.util.common.guava.Sequence;
import org.apache.druid.java.util.common.guava.Sequences;
import org.apache.druid.java.util.common.io.Closer;
import org.apache.druid.query.CloseableCursor;
import org.apache.druid.query.CursorAndCloseable;
import org.apache.druid.query.FrameSignaturePair;
import org.apache.druid.query.GenericQueryMetricsFactory;
import org.apache.druid.query.IterableRowsCursorHelper;
Expand Down Expand Up @@ -284,7 +284,7 @@ private Sequence<FrameSignaturePair> convertScanResultValuesToFrame(
final Function<?, Object[]> mapper = getResultFormatMapper(query.getResultFormat(), rowSignature.getColumnNames());
final Iterable<Object[]> formattedRows = Lists.newArrayList(Iterables.transform(rows, (Function) mapper));

CloseableCursor cursor = IterableRowsCursorHelper.getCursorFromIterable(formattedRows, rowSignature);
CursorAndCloseable cursor = IterableRowsCursorHelper.getCursorFromIterable(formattedRows, rowSignature);
cursors.add(cursor);

// Cursors created from iterators don't have any resources, therefore this is mostly a defensive check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import org.apache.druid.java.util.common.guava.Sequence;
import org.apache.druid.java.util.common.guava.Sequences;
import org.apache.druid.query.CacheStrategy;
import org.apache.druid.query.CloseableCursor;
import org.apache.druid.query.CursorAndCloseable;
import org.apache.druid.query.FrameSignaturePair;
import org.apache.druid.query.IterableRowsCursorHelper;
import org.apache.druid.query.Query;
Expand Down Expand Up @@ -474,7 +474,7 @@ public Optional<Sequence<FrameSignaturePair>> resultsAsFrames(
)
{
final RowSignature rowSignature = resultArraySignature(query);
final CloseableCursor cursor = IterableRowsCursorHelper.getCursorFromSequence(
final CursorAndCloseable cursor = IterableRowsCursorHelper.getCursorFromSequence(
resultsAsArrays(query, resultSequence),
rowSignature
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.apache.druid.java.util.common.guava.Sequences;
import org.apache.druid.query.BySegmentResultValue;
import org.apache.druid.query.CacheStrategy;
import org.apache.druid.query.CloseableCursor;
import org.apache.druid.query.CursorAndCloseable;
import org.apache.druid.query.FrameSignaturePair;
import org.apache.druid.query.IterableRowsCursorHelper;
import org.apache.druid.query.Query;
Expand Down Expand Up @@ -558,7 +558,7 @@ public Optional<Sequence<FrameSignaturePair>> resultsAsFrames(
)
{
final RowSignature rowSignature = resultArraySignature(query);
final CloseableCursor cursor = IterableRowsCursorHelper.getCursorFromSequence(
final CursorAndCloseable cursor = IterableRowsCursorHelper.getCursorFromSequence(
resultsAsArrays(query, resultSequence),
rowSignature
);
Expand Down

0 comments on commit cdd63cf

Please sign in to comment.