diff --git a/processing/src/main/java/org/apache/druid/query/rowsandcols/concrete/RowBasedFrameRowsAndColumns.java b/processing/src/main/java/org/apache/druid/query/rowsandcols/concrete/RowBasedFrameRowsAndColumns.java index 5afd3102ded..234410bc070 100644 --- a/processing/src/main/java/org/apache/druid/query/rowsandcols/concrete/RowBasedFrameRowsAndColumns.java +++ b/processing/src/main/java/org/apache/druid/query/rowsandcols/concrete/RowBasedFrameRowsAndColumns.java @@ -22,24 +22,26 @@ package org.apache.druid.query.rowsandcols.concrete; import org.apache.druid.frame.Frame; import org.apache.druid.frame.FrameType; import org.apache.druid.frame.read.FrameReader; +import org.apache.druid.frame.read.columnar.FrameColumnReaders; import org.apache.druid.frame.segment.FrameStorageAdapter; +import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.Intervals; -import org.apache.druid.query.operator.OffsetLimit; -import org.apache.druid.query.rowsandcols.LazilyDecoratedRowsAndColumns; import org.apache.druid.query.rowsandcols.RowsAndColumns; import org.apache.druid.query.rowsandcols.column.Column; import org.apache.druid.segment.CloseableShapeshifter; import org.apache.druid.segment.StorageAdapter; +import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.column.RowSignature; import javax.annotation.Nullable; import java.util.Collection; +import java.util.LinkedHashMap; public class RowBasedFrameRowsAndColumns implements RowsAndColumns, AutoCloseable, CloseableShapeshifter { private final Frame frame; private final RowSignature signature; - private LazilyDecoratedRowsAndColumns rac; + private final LinkedHashMap colCache = new LinkedHashMap<>(); public RowBasedFrameRowsAndColumns(Frame frame, RowSignature signature) { @@ -63,10 +65,19 @@ public class RowBasedFrameRowsAndColumns implements RowsAndColumns, AutoCloseabl @Override public Column findColumn(String name) { - if( rac == null) { - LazilyDecoratedRowsAndColumns rac = new LazilyDecoratedRowsAndColumns(this, null, null, null, OffsetLimit.limit(Integer.MAX_VALUE), null, null); + if (!colCache.containsKey(name)) { + final int columnIndex = signature.indexOf(name); + if (columnIndex < 0) { + colCache.put(name, null); + } else { + final ColumnType columnType = signature + .getColumnType(columnIndex) + .orElseThrow(() -> new ISE("just got the id, why is columnType not there?")); + + colCache.put(name, FrameColumnReaders.create(name, columnIndex, columnType).readRACColumn(frame)); + } } - return rac.findColumn(name); + return colCache.get(name); } @SuppressWarnings("unchecked") diff --git a/processing/src/test/java/org/apache/druid/frame/read/FrameReaderTest.java b/processing/src/test/java/org/apache/druid/frame/read/FrameReaderTest.java index 23e480921f0..bf24b6cb5f0 100644 --- a/processing/src/test/java/org/apache/druid/frame/read/FrameReaderTest.java +++ b/processing/src/test/java/org/apache/druid/frame/read/FrameReaderTest.java @@ -23,13 +23,10 @@ import com.google.common.collect.Iterables; import org.apache.druid.frame.Frame; import org.apache.druid.frame.FrameType; import org.apache.druid.frame.allocation.HeapMemoryAllocator; -import org.apache.druid.frame.read.columnar.FrameColumnReaders; import org.apache.druid.frame.testutil.FrameSequenceBuilder; import org.apache.druid.segment.QueryableIndexStorageAdapter; import org.apache.druid.segment.StorageAdapter; import org.apache.druid.segment.TestIndex; -import org.apache.druid.segment.column.ColumnType; -import org.apache.druid.segment.column.RowSignature; import org.apache.druid.testing.InitializedNullHandlingTest; import org.junit.Assert; import org.junit.Before; @@ -97,14 +94,4 @@ public class FrameReaderTest extends InitializedNullHandlingTest ); } } - - @Test - public void testReadRacColumn() - { - RowSignature rs = inputAdapter.getRowSignature(); - int colNo = 1; - String name = rs.getColumnName(colNo); - ColumnType type = rs.getColumnType(colNo).get(); - FrameColumnReaders.create(name, colNo, type).readRACColumn(frame); - } }