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.jdbc.internal.common.block;
import com.facebook.presto.jdbc.internal.common.type.Type;
import com.facebook.presto.jdbc.internal.io.airlift.slice.SliceInput;
import com.facebook.presto.jdbc.internal.jol.info.ClassLayout;
import com.facebook.presto.jdbc.internal.javax.annotation.Nullable;
import java.util.Arrays;
import java.util.function.ObjLongConsumer;
import static com.facebook.presto.jdbc.internal.common.block.ArrayBlock.createArrayBlockInternal;
import static com.facebook.presto.jdbc.internal.common.block.BlockUtil.calculateBlockResetSize;
import static com.facebook.presto.jdbc.internal.io.airlift.slice.SizeOf.sizeOf;
import static java.lang.Math.max;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
public class ArrayBlockBuilder
extends AbstractArrayBlock
implements BlockBuilder
{
private static final int INSTANCE_SIZE = ClassLayout.parseClass(ArrayBlockBuilder.class).instanceSize();
private int positionCount;
@Nullable
private final BlockBuilderStatus blockBuilderStatus;
private final int initialEntryCount;
private boolean initialized;
private int[] offsets = new int[1];
private boolean[] valueIsNull = new boolean[0];
private boolean hasNullValue;
private final BlockBuilder values;
private boolean currentEntryOpened;
private long retainedSizeInBytes;
/**
* Caller of this constructor is responsible for making sure `valuesBlock` is constructed with the same `blockBuilderStatus` as the one in the argument
*/
public ArrayBlockBuilder(BlockBuilder valuesBlock, BlockBuilderStatus blockBuilderStatus, int expectedEntries)
{
this(
blockBuilderStatus,
valuesBlock,
expectedEntries);
}
public ArrayBlockBuilder(Type elementType, BlockBuilderStatus blockBuilderStatus, int expectedEntries, int expectedBytesPerEntry)
{
this(
blockBuilderStatus,
elementType.createBlockBuilder(blockBuilderStatus, expectedEntries, expectedBytesPerEntry),
expectedEntries);
}
public ArrayBlockBuilder(Type elementType, BlockBuilderStatus blockBuilderStatus, int expectedEntries)
{
this(
blockBuilderStatus,
elementType.createBlockBuilder(blockBuilderStatus, expectedEntries),
expectedEntries);
}
/**
* Caller of this private constructor is responsible for making sure `values` is constructed with the same `blockBuilderStatus` as the one in the argument
*/
private ArrayBlockBuilder(@Nullable BlockBuilderStatus blockBuilderStatus, BlockBuilder values, int expectedEntries)
{
this.blockBuilderStatus = blockBuilderStatus;
this.values = requireNonNull(values, "values is null");
this.initialEntryCount = max(expectedEntries, 1);
updateDataSize();
}
@Override
public int getPositionCount()
{
return positionCount;
}
@Override
public long getSizeInBytes()
{
return values.getSizeInBytes() + ((Integer.BYTES + Byte.BYTES) * (long) positionCount);
}
@Override
public long getRetainedSizeInBytes()
{
return retainedSizeInBytes + values.getRetainedSizeInBytes();
}
@Override
public void retainedBytesForEachPart(ObjLongConsumer