diff --git a/omnioperator/omniop-openlookeng-extension/src/main/java/nova/hetu/olk/block/RowOmniBlock.java b/omnioperator/omniop-openlookeng-extension/src/main/java/nova/hetu/olk/block/RowOmniBlock.java index 5730818abcda43d5fb2786bc326884c7223daf1b..818f8122655a5a267c749a2df1b5ef621d8a1190 100644 --- a/omnioperator/omniop-openlookeng-extension/src/main/java/nova/hetu/olk/block/RowOmniBlock.java +++ b/omnioperator/omniop-openlookeng-extension/src/main/java/nova/hetu/olk/block/RowOmniBlock.java @@ -69,6 +69,8 @@ public class RowOmniBlock private boolean[] isNull; + private ContainerVec containerVec; + /** * Create a row block directly from columnar nulls and field blocks. * @@ -79,7 +81,7 @@ public class RowOmniBlock * @return the block */ public static Block fromFieldBlocks(VecAllocator vecAllocator, int positionCount, Optional rowIsNull, - Block[] fieldBlocks, Type blockType) + Block[] fieldBlocks, Type blockType, ContainerVec containerVec) { int[] fieldBlockOffsets = new int[positionCount + 1]; for (int position = 0; position < positionCount; position++) { @@ -96,7 +98,7 @@ public class RowOmniBlock blockType == null ? null : blockType.getTypeParameters().get(blockIndex)); } return new RowOmniBlock(0, positionCount, rowIsNull.orElse(null), fieldBlockOffsets, newOffHeapFieldBlocks, - OperatorUtils.toDataType(blockType)); + OperatorUtils.toDataType(blockType), containerVec); } /** @@ -114,7 +116,7 @@ public class RowOmniBlock int[] fieldBlockOffsets, Block[] fieldBlocks, DataType dataType) { validateConstructorArguments(startOffset, positionCount, rowIsNull, fieldBlockOffsets, fieldBlocks); - return new RowOmniBlock(startOffset, positionCount, rowIsNull, fieldBlockOffsets, fieldBlocks, dataType); + return new RowOmniBlock(startOffset, positionCount, rowIsNull, fieldBlockOffsets, fieldBlocks, dataType, null); } /** @@ -163,20 +165,24 @@ public class RowOmniBlock @Override public Vec getValues() + { + return containerVec; + } + + private ContainerVec buildContainVec() { Block[] rawFieldBlocks = this.getRawFieldBlocks(); int numFields = rawFieldBlocks.length; long[] vectorAddresses = new long[numFields]; - DataType[] dataTypes = new DataType[numFields]; for (int i = 0; i < numFields; ++i) { Vec vec = (Vec) rawFieldBlocks[i].getValues(); long nativeVectorAddress = vec.getNativeVector(); vectorAddresses[i] = nativeVectorAddress; } - ContainerVec containerVec = new ContainerVec(vecAllocator, numFields, this.getPositionCount(), vectorAddresses, + ContainerVec vec = new ContainerVec(vecAllocator, numFields, this.getPositionCount(), vectorAddresses, ((ContainerDataType) dataType).getFieldTypes()); - containerVec.setNulls(0, this.getRowIsNull(), 0, this.getPositionCount()); - return containerVec; + vec.setNulls(0, this.getRowIsNull(), 0, this.getPositionCount()); + return vec; } /** @@ -192,7 +198,7 @@ public class RowOmniBlock * @param dataType data type of block */ public RowOmniBlock(int startOffset, int positionCount, @Nullable byte[] rowIsNull, int[] fieldBlockOffsets, - Block[] fieldBlocks, DataType dataType) + Block[] fieldBlocks, DataType dataType, ContainerVec containerVec) { super(fieldBlocks.length); this.vecAllocator = getVecAllocatorFromBlocks(fieldBlocks); @@ -210,6 +216,7 @@ public class RowOmniBlock } this.retainedSizeInBytes = retainedSizeInBytes; this.dataType = dataType; + this.containerVec = containerVec == null ? buildContainVec() : containerVec; } @Override @@ -353,8 +360,8 @@ public class RowOmniBlock @Override public void close() { - for (Block fieldBlock : fieldBlocks) { - fieldBlock.close(); + if (containerVec != null) { + containerVec.close(); } } } diff --git a/omnioperator/omniop-openlookeng-extension/src/main/java/nova/hetu/olk/tool/OperatorUtils.java b/omnioperator/omniop-openlookeng-extension/src/main/java/nova/hetu/olk/tool/OperatorUtils.java index ada60b2e5a7ec148f4389a598a5453804e183e9c..9d158089c3fd0123772fd49a0809313fb9cfcc24 100644 --- a/omnioperator/omniop-openlookeng-extension/src/main/java/nova/hetu/olk/tool/OperatorUtils.java +++ b/omnioperator/omniop-openlookeng-extension/src/main/java/nova/hetu/olk/tool/OperatorUtils.java @@ -623,7 +623,7 @@ public final class OperatorUtils } } return RowOmniBlock.fromFieldBlocks(vecAllocator, rowBlock.getPositionCount(), Optional.of(valueIsNull), - rowBlock.getRawFieldBlocks(), blockType); + rowBlock.getRawFieldBlocks(), blockType, null); } /** @@ -802,7 +802,7 @@ public final class OperatorUtils fieldBlockOffsets[position + 1] = fieldBlockOffsets[position] + (nulls[position] == Vec.NULL ? 0 : 1); } return new RowOmniBlock(0, positionCount, nulls, fieldBlockOffsets, rowBlocks, - new ContainerDataType(dataTypes)); + new ContainerDataType(dataTypes), containerVec); } /** diff --git a/omnioperator/omniop-openlookeng-extension/src/test/java/nova/hetu/olk/block/RowOmniBlockTest.java b/omnioperator/omniop-openlookeng-extension/src/test/java/nova/hetu/olk/block/RowOmniBlockTest.java index 8f0dca756971f52ccbd5fc7f4d4e58b4e272be5d..c1e2c125657e77d6eb8e7ee03583ffb6001b0e10 100644 --- a/omnioperator/omniop-openlookeng-extension/src/test/java/nova/hetu/olk/block/RowOmniBlockTest.java +++ b/omnioperator/omniop-openlookeng-extension/src/test/java/nova/hetu/olk/block/RowOmniBlockTest.java @@ -21,6 +21,7 @@ import io.prestosql.spi.block.BlockBuilder; import io.prestosql.spi.type.RowType; import io.prestosql.spi.type.Type; import nova.hetu.omniruntime.vector.BooleanVec; +import nova.hetu.omniruntime.vector.ContainerVec; import nova.hetu.omniruntime.vector.DoubleVec; import nova.hetu.omniruntime.vector.IntVec; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -35,6 +36,7 @@ import static nova.hetu.olk.block.RowOmniBlock.fromFieldBlocks; import static nova.hetu.olk.mock.MockUtil.fill; import static nova.hetu.olk.mock.MockUtil.mockBlock; import static nova.hetu.olk.mock.MockUtil.mockNewVecWithAnyArguments; +import static nova.hetu.olk.mock.MockUtil.mockVec; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; @@ -44,7 +46,7 @@ public class RowOmniBlockTest { private Block rowBlock(Block block, Type dataType) { - return fromFieldBlocks(getVecAllocator(), block.getPositionCount(), Optional.empty(), new Block[]{block}, dataType); + return fromFieldBlocks(getVecAllocator(), block.getPositionCount(), Optional.empty(), new Block[]{block}, dataType, mockVec(ContainerVec.class, new Block[]{block}, getVecAllocator())); } @Override @@ -54,6 +56,7 @@ public class RowOmniBlockTest mockNewVecWithAnyArguments(BooleanVec.class); mockNewVecWithAnyArguments(IntVec.class); mockNewVecWithAnyArguments(DoubleVec.class); + mockNewVecWithAnyArguments(ContainerVec.class); } @Override diff --git a/omnioperator/omniop-openlookeng-extension/src/test/java/nova/hetu/olk/mock/MockUtil.java b/omnioperator/omniop-openlookeng-extension/src/test/java/nova/hetu/olk/mock/MockUtil.java index 7d66eddb3c3bfaeb6227dd5fdd672390ab238cce..e2b53f848a074a84111f79ac86376ba74dace314 100644 --- a/omnioperator/omniop-openlookeng-extension/src/test/java/nova/hetu/olk/mock/MockUtil.java +++ b/omnioperator/omniop-openlookeng-extension/src/test/java/nova/hetu/olk/mock/MockUtil.java @@ -32,6 +32,7 @@ import nova.hetu.olk.block.VariableWidthOmniBlock; import nova.hetu.omniruntime.operator.OmniOperator; import nova.hetu.omniruntime.type.DataType; import nova.hetu.omniruntime.vector.BooleanVec; +import nova.hetu.omniruntime.vector.ContainerVec; import nova.hetu.omniruntime.vector.Decimal128Vec; import nova.hetu.omniruntime.vector.DictionaryVec; import nova.hetu.omniruntime.vector.DoubleVec; @@ -117,7 +118,7 @@ public class MockUtil if (blockModel.rowBlock) { for (Object value : blockModel.values) { Page page = mockPage(block(blockModel.lazy, blockModel.dictionary, (Object[]) value)); - blocks.put(j, RowOmniBlock.fromFieldBlocks(vecAllocator, page.getPositionCount(), Optional.empty(), page.getBlocks(), null)); + blocks.put(j, RowOmniBlock.fromFieldBlocks(vecAllocator, page.getPositionCount(), Optional.empty(), page.getBlocks(), null, mockVec(ContainerVec.class, page.getBlocks(), vecAllocator))); } }