com.facebook.presto.jdbc.internal.common.block.LazyBlock Maven / Gradle / Ivy
The newest version!
/*
* 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 com.facebook.presto.jdbc.internal.common.block;
import com.facebook.presto.jdbc.internal.io.airlift.slice.Slice;
import com.facebook.presto.jdbc.internal.io.airlift.slice.SliceOutput;
import com.facebook.presto.jdbc.internal.jol.info.ClassLayout;
import java.util.OptionalInt;
import java.util.function.ObjLongConsumer;
import static java.util.Objects.requireNonNull;
public class LazyBlock
implements Block
{
private static final int INSTANCE_SIZE = ClassLayout.parseClass(LazyBlock.class).instanceSize();
private final int positionCount;
private LazyBlockLoader loader;
private Block block;
public LazyBlock(int positionCount, LazyBlockLoader loader)
{
this.positionCount = positionCount;
this.loader = requireNonNull(loader, "loader is null");
}
@Override
public int getPositionCount()
{
return positionCount;
}
@Override
public int getSliceLength(int position)
{
assureLoaded();
return block.getSliceLength(position);
}
@Override
public byte getByte(int position)
{
assureLoaded();
return block.getByte(position);
}
@Override
public short getShort(int position)
{
assureLoaded();
return block.getShort(position);
}
@Override
public int getInt(int position)
{
assureLoaded();
return block.getInt(position);
}
@Override
public long getLong(int position)
{
assureLoaded();
return block.getLong(position);
}
@Override
public long getLong(int position, int offset)
{
assureLoaded();
return block.getLong(position, offset);
}
@Override
public Slice getSlice(int position, int offset, int length)
{
assureLoaded();
return block.getSlice(position, offset, length);
}
@Override
public Block getBlock(int position)
{
assureLoaded();
return block.getBlock(position);
}
@Override
public boolean bytesEqual(int position, int offset, Slice otherSlice, int otherOffset, int length)
{
assureLoaded();
return block.bytesEqual(position, offset, otherSlice, otherOffset, length);
}
@Override
public int bytesCompare(int position, int offset, int length, Slice otherSlice, int otherOffset, int otherLength)
{
assureLoaded();
return block.bytesCompare(position,
offset,
length,
otherSlice,
otherOffset,
otherLength);
}
@Override
public void writeBytesTo(int position, int offset, int length, BlockBuilder blockBuilder)
{
assureLoaded();
block.writeBytesTo(position, offset, length, blockBuilder);
}
@Override
public void writeBytesTo(int position, int offset, int length, SliceOutput sliceOutput)
{
assureLoaded();
block.writeBytesTo(position, offset, length, sliceOutput);
}
@Override
public void writePositionTo(int position, BlockBuilder blockBuilder)
{
assureLoaded();
block.writePositionTo(position, blockBuilder);
}
@Override
public void writePositionTo(int position, SliceOutput output)
{
assureLoaded();
block.writePositionTo(position, output);
}
@Override
public boolean equals(int position, int offset, Block otherBlock, int otherPosition, int otherOffset, int length)
{
assureLoaded();
return block.equals(position,
offset,
otherBlock,
otherPosition,
otherOffset,
length);
}
@Override
public long hash(int position, int offset, int length)
{
assureLoaded();
return block.hash(position, offset, length);
}
@Override
public int compareTo(int leftPosition, int leftOffset, int leftLength, Block rightBlock, int rightPosition, int rightOffset, int rightLength)
{
assureLoaded();
return block.compareTo(leftPosition,
leftOffset,
leftLength,
rightBlock,
rightPosition,
rightOffset,
rightLength);
}
@Override
public Block getSingleValueBlock(int position)
{
assureLoaded();
return block.getSingleValueBlock(position);
}
@Override
public long getSizeInBytes()
{
assureLoaded();
return block.getSizeInBytes();
}
@Override
public OptionalInt fixedSizeInBytesPerPosition()
{
assureLoaded();
return block.fixedSizeInBytesPerPosition();
}
@Override
public long getRegionSizeInBytes(int position, int length)
{
assureLoaded();
return block.getRegionSizeInBytes(position, length);
}
@Override
public long getPositionsSizeInBytes(boolean[] positions, int usedPositionCount)
{
assureLoaded();
return block.getPositionsSizeInBytes(positions, usedPositionCount);
}
@Override
public long getRetainedSizeInBytes()
{
assureLoaded();
return INSTANCE_SIZE + block.getRetainedSizeInBytes();
}
@Override
public long getEstimatedDataSizeForStats(int position)
{
assureLoaded();
return block.getEstimatedDataSizeForStats(position);
}
@Override
public void retainedBytesForEachPart(ObjLongConsumer
© 2015 - 2024 Weber Informatics LLC | Privacy Policy