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 com.facebook.presto.spi.block;
import io.airlift.slice.DynamicSliceOutput;
import io.airlift.slice.Slice;
import io.airlift.slice.SliceOutput;
import io.airlift.slice.Slices;
import org.openjdk.jol.info.ClassLayout;
import javax.annotation.Nullable;
import java.util.function.BiConsumer;
import static com.facebook.presto.spi.block.BlockUtil.MAX_ARRAY_SIZE;
import static com.facebook.presto.spi.block.BlockUtil.calculateBlockResetSize;
import static com.facebook.presto.spi.block.BlockUtil.checkArrayRange;
import static com.facebook.presto.spi.block.BlockUtil.checkValidPosition;
import static com.facebook.presto.spi.block.BlockUtil.checkValidRegion;
import static io.airlift.slice.SizeOf.SIZE_OF_BYTE;
import static io.airlift.slice.SizeOf.SIZE_OF_INT;
import static io.airlift.slice.SizeOf.SIZE_OF_LONG;
import static io.airlift.slice.SizeOf.SIZE_OF_SHORT;
public class FixedWidthBlockBuilder
extends AbstractFixedWidthBlock
implements BlockBuilder
{
private static final int INSTANCE_SIZE = ClassLayout.parseClass(FixedWidthBlockBuilder.class).instanceSize();
@Nullable
private BlockBuilderStatus blockBuilderStatus;
private boolean initialized;
private int initialEntryCount;
private SliceOutput sliceOutput = new DynamicSliceOutput(0);
private SliceOutput valueIsNull = new DynamicSliceOutput(0);
private boolean hasNullValue;
private int positionCount;
private int currentEntrySize;
public FixedWidthBlockBuilder(int fixedSize, @Nullable BlockBuilderStatus blockBuilderStatus, int expectedEntries)
{
super(fixedSize);
this.blockBuilderStatus = blockBuilderStatus;
initialEntryCount = expectedEntries;
}
public FixedWidthBlockBuilder(int fixedSize, int positionCount)
{
super(fixedSize);
initialized = true;
Slice slice = Slices.allocate(fixedSize * positionCount);
this.blockBuilderStatus = null;
this.sliceOutput = slice.getOutput();
this.valueIsNull = Slices.allocate(positionCount).getOutput();
}
@Override
protected Slice getRawSlice()
{
return sliceOutput.getUnderlyingSlice();
}
@Override
public int getPositionCount()
{
return positionCount;
}
@Override
public long getSizeInBytes()
{
return sliceOutput.size() + (long) valueIsNull.size();
}
@Override
public long getRetainedSizeInBytes()
{
long size = INSTANCE_SIZE + sliceOutput.getRetainedSize() + valueIsNull.getRetainedSize();
if (blockBuilderStatus != null) {
size += BlockBuilderStatus.INSTANCE_SIZE;
}
return size;
}
@Override
public void retainedBytesForEachPart(BiConsumer