From cdd63cfde316302ec031e7992d324734a2d73d08 Mon Sep 17 00:00:00 2001 From: Laksh Singla Date: Wed, 4 Oct 2023 16:44:02 +0530 Subject: [PATCH] refactor name --- .../{CloseableCursor.java => CursorAndCloseable.java} | 7 +++---- .../apache/druid/query/IterableRowsCursorHelper.java | 10 +++++----- .../query/groupby/GroupByQueryQueryToolChest.java | 4 ++-- .../druid/query/scan/ScanQueryQueryToolChest.java | 4 ++-- .../timeseries/TimeseriesQueryQueryToolChest.java | 4 ++-- .../druid/query/topn/TopNQueryQueryToolChest.java | 4 ++-- 6 files changed, 16 insertions(+), 17 deletions(-) rename processing/src/main/java/org/apache/druid/query/{CloseableCursor.java => CursorAndCloseable.java} (92%) diff --git a/processing/src/main/java/org/apache/druid/query/CloseableCursor.java b/processing/src/main/java/org/apache/druid/query/CursorAndCloseable.java similarity index 92% rename from processing/src/main/java/org/apache/druid/query/CloseableCursor.java rename to processing/src/main/java/org/apache/druid/query/CursorAndCloseable.java index f42ff6cc4051..d430b8ec0272 100644 --- a/processing/src/main/java/org/apache/druid/query/CloseableCursor.java +++ b/processing/src/main/java/org/apache/druid/query/CursorAndCloseable.java @@ -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 diff --git a/processing/src/main/java/org/apache/druid/query/IterableRowsCursorHelper.java b/processing/src/main/java/org/apache/druid/query/IterableRowsCursorHelper.java index 48687bf24935..60e7f4f7a912 100644 --- a/processing/src/main/java/org/apache/druid/query/IterableRowsCursorHelper.java +++ b/processing/src/main/java/org/apache/druid/query/IterableRowsCursorHelper.java @@ -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 rows, RowSignature rowSignature) + public static CursorAndCloseable getCursorFromIterable(Iterable rows, RowSignature rowSignature) { return getCursorFromSequence(Sequences.simple(rows), rowSignature); } @@ -49,10 +49,10 @@ public static CloseableCursor getCursorFromIterable(Iterable rows, Row * Creates a cursor that iterates over all the rows generated by the sequence. Presence of __time column is not a * necessity. *

- * 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 rows, RowSignature rowSignature) + public static CursorAndCloseable getCursorFromSequence(Sequence rows, RowSignature rowSignature) { RowAdapter rowAdapter = columnName -> { if (rowSignature == null) { @@ -78,6 +78,6 @@ public static CloseableCursor getCursorFromSequence(Sequence rows, Row rowSignature != null ? rowSignature : RowSignature.empty() ); - return CloseableCursor.cursorWithCloseable(baseCursor, rowWalker); + return CursorAndCloseable.create(baseCursor, rowWalker); } } diff --git a/processing/src/main/java/org/apache/druid/query/groupby/GroupByQueryQueryToolChest.java b/processing/src/main/java/org/apache/druid/query/groupby/GroupByQueryQueryToolChest.java index a24248e79064..75099b278cfb 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/GroupByQueryQueryToolChest.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/GroupByQueryQueryToolChest.java @@ -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; @@ -726,7 +726,7 @@ public Optional> resultsAsFrames( ); - CloseableCursor cursor = IterableRowsCursorHelper.getCursorFromSequence( + CursorAndCloseable cursor = IterableRowsCursorHelper.getCursorFromSequence( resultsAsArrays(query, resultSequence), rowSignature ); diff --git a/processing/src/main/java/org/apache/druid/query/scan/ScanQueryQueryToolChest.java b/processing/src/main/java/org/apache/druid/query/scan/ScanQueryQueryToolChest.java index 424afa39e5b5..552077a27830 100644 --- a/processing/src/main/java/org/apache/druid/query/scan/ScanQueryQueryToolChest.java +++ b/processing/src/main/java/org/apache/druid/query/scan/ScanQueryQueryToolChest.java @@ -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; @@ -284,7 +284,7 @@ private Sequence convertScanResultValuesToFrame( final Function mapper = getResultFormatMapper(query.getResultFormat(), rowSignature.getColumnNames()); final Iterable 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 diff --git a/processing/src/main/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChest.java b/processing/src/main/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChest.java index 1e699ec84566..779976bc452e 100644 --- a/processing/src/main/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChest.java +++ b/processing/src/main/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChest.java @@ -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; @@ -474,7 +474,7 @@ public Optional> resultsAsFrames( ) { final RowSignature rowSignature = resultArraySignature(query); - final CloseableCursor cursor = IterableRowsCursorHelper.getCursorFromSequence( + final CursorAndCloseable cursor = IterableRowsCursorHelper.getCursorFromSequence( resultsAsArrays(query, resultSequence), rowSignature ); diff --git a/processing/src/main/java/org/apache/druid/query/topn/TopNQueryQueryToolChest.java b/processing/src/main/java/org/apache/druid/query/topn/TopNQueryQueryToolChest.java index 9bae043cd8ae..1adf95220adf 100644 --- a/processing/src/main/java/org/apache/druid/query/topn/TopNQueryQueryToolChest.java +++ b/processing/src/main/java/org/apache/druid/query/topn/TopNQueryQueryToolChest.java @@ -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; @@ -558,7 +558,7 @@ public Optional> resultsAsFrames( ) { final RowSignature rowSignature = resultArraySignature(query); - final CloseableCursor cursor = IterableRowsCursorHelper.getCursorFromSequence( + final CursorAndCloseable cursor = IterableRowsCursorHelper.getCursorFromSequence( resultsAsArrays(query, resultSequence), rowSignature );