Add comment about double-close in ColumnSelectorColumnIndexSelector. (#12735)

This commit is contained in:
Gian Merlino 2022-07-06 00:50:35 -07:00 committed by GitHub
parent 682ea7f32d
commit 49feffff1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -29,6 +29,7 @@ import org.apache.druid.segment.column.NumericColumn;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/** /**
*
*/ */
public class ColumnSelectorColumnIndexSelector implements ColumnIndexSelector public class ColumnSelectorColumnIndexSelector implements ColumnIndexSelector
{ {
@ -50,7 +51,17 @@ public class ColumnSelectorColumnIndexSelector implements ColumnIndexSelector
@Override @Override
public int getNumRows() public int getNumRows()
{ {
try (final NumericColumn column = (NumericColumn) columnSelector.getColumnHolder(ColumnHolder.TIME_COLUMN_NAME).getColumn()) { // This closes the __time column, which may initially seem like good behavior, but in reality leads to a
// double-close when columnSelector is a ColumnCache (because all columns from a ColumnCache are closed when
// the cache itself is closed). We're closing it here anyway, however, for two reasons:
//
// 1) Sometimes, columnSelector is DeprecatedQueryableIndexColumnSelector, not ColumnCache, and so the close
// here is important.
// 2) Double-close is OK for the __time column when this method is expected to be used: the __time column is
// expected to be a ColumnarLongs, which is safe to double-close.
try (final NumericColumn column = (NumericColumn) columnSelector.getColumnHolder(ColumnHolder.TIME_COLUMN_NAME)
.getColumn()) {
return column.length(); return column.length();
} }
} }