io.trino.spi.block.LazyBlock Maven / Gradle / Ivy
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.spi.block;
import io.airlift.slice.Slice;
import org.openjdk.jol.info.ClassLayout;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import static io.trino.spi.block.BlockUtil.checkArrayRange;
import static io.trino.spi.block.BlockUtil.checkValidRegion;
import static java.lang.String.format;
import static java.util.Collections.singletonList;
import static java.util.Objects.requireNonNull;
@NotThreadSafe
public class LazyBlock
implements Block
{
private static final int INSTANCE_SIZE = ClassLayout.parseClass(LazyBlock.class).instanceSize() + ClassLayout.parseClass(LazyData.class).instanceSize();
private final int positionCount;
private final LazyData lazyData;
public LazyBlock(int positionCount, LazyBlockLoader loader)
{
this.positionCount = positionCount;
this.lazyData = new LazyData(positionCount, loader);
}
@Override
public int getPositionCount()
{
return positionCount;
}
@Override
public int getSliceLength(int position)
{
return getBlock().getSliceLength(position);
}
@Override
public byte getByte(int position, int offset)
{
return getBlock().getByte(position, offset);
}
@Override
public short getShort(int position, int offset)
{
return getBlock().getShort(position, offset);
}
@Override
public int getInt(int position, int offset)
{
return getBlock().getInt(position, offset);
}
@Override
public long getLong(int position, int offset)
{
return getBlock().getLong(position, offset);
}
@Override
public Slice getSlice(int position, int offset, int length)
{
return getBlock().getSlice(position, offset, length);
}
@Override
public T getObject(int position, Class clazz)
{
return getBlock().getObject(position, clazz);
}
@Override
public boolean bytesEqual(int position, int offset, Slice otherSlice, int otherOffset, int length)
{
return getBlock().bytesEqual(position, offset, otherSlice, otherOffset, length);
}
@Override
public int bytesCompare(int position, int offset, int length, Slice otherSlice, int otherOffset, int otherLength)
{
return getBlock().bytesCompare(
position,
offset,
length,
otherSlice,
otherOffset,
otherLength);
}
@Override
public void writeBytesTo(int position, int offset, int length, BlockBuilder blockBuilder)
{
getBlock().writeBytesTo(position, offset, length, blockBuilder);
}
@Override
public void writePositionTo(int position, BlockBuilder blockBuilder)
{
getBlock().writePositionTo(position, blockBuilder);
}
@Override
public boolean equals(int position, int offset, Block otherBlock, int otherPosition, int otherOffset, int length)
{
return getBlock().equals(
position,
offset,
otherBlock,
otherPosition,
otherOffset,
length);
}
@Override
public long hash(int position, int offset, int length)
{
return getBlock().hash(position, offset, length);
}
@Override
public int compareTo(int leftPosition, int leftOffset, int leftLength, Block rightBlock, int rightPosition, int rightOffset, int rightLength)
{
return getBlock().compareTo(
leftPosition,
leftOffset,
leftLength,
rightBlock,
rightPosition,
rightOffset,
rightLength);
}
@Override
public Block getSingleValueBlock(int position)
{
return getBlock().getSingleValueBlock(position);
}
@Override
public long getSizeInBytes()
{
if (!isLoaded()) {
return 0;
}
return getBlock().getSizeInBytes();
}
@Override
public long getRegionSizeInBytes(int position, int length)
{
if (!isLoaded()) {
return 0;
}
return getBlock().getRegionSizeInBytes(position, length);
}
@Override
public long getPositionsSizeInBytes(boolean[] positions)
{
if (!isLoaded()) {
return 0;
}
return getBlock().getPositionsSizeInBytes(positions);
}
@Override
public long getRetainedSizeInBytes()
{
if (!isLoaded()) {
return INSTANCE_SIZE;
}
return INSTANCE_SIZE + getBlock().getRetainedSizeInBytes();
}
@Override
public long getEstimatedDataSizeForStats(int position)
{
return getBlock().getEstimatedDataSizeForStats(position);
}
@Override
public void retainedBytesForEachPart(BiConsumer
© 2015 - 2025 Weber Informatics LLC | Privacy Policy