Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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 jakarta.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.OptionalInt;
import java.util.function.Consumer;
import java.util.function.ObjLongConsumer;
import static io.airlift.slice.SizeOf.instanceSize;
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;
// This class is not considered thread-safe.
public final class LazyBlock
implements Block
{
private static final int INSTANCE_SIZE = instanceSize(LazyBlock.class) + instanceSize(LazyData.class);
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 ValueBlock getSingleValueBlock(int position)
{
return getBlock().getSingleValueBlock(position);
}
@Override
public OptionalInt fixedSizeInBytesPerPosition()
{
if (!isLoaded()) {
return OptionalInt.empty();
}
return getBlock().fixedSizeInBytesPerPosition();
}
@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, int selectedPositionsCount)
{
if (!isLoaded()) {
return 0;
}
return getBlock().getPositionsSizeInBytes(positions, selectedPositionsCount);
}
@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(ObjLongConsumer