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 com.facebook.presto.spi.type.Type;
import org.openjdk.jol.info.ClassLayout;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiConsumer;
import static com.facebook.presto.spi.block.BlockUtil.calculateBlockResetSize;
import static com.facebook.presto.spi.block.RowBlock.createRowBlockInternal;
import static io.airlift.slice.SizeOf.sizeOf;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
public class RowBlockBuilder
extends AbstractRowBlock
implements BlockBuilder
{
private static final int INSTANCE_SIZE = ClassLayout.parseClass(RowBlockBuilder.class).instanceSize();
@Nullable
private final BlockBuilderStatus blockBuilderStatus;
private int positionCount;
private int[] fieldBlockOffsets;
private boolean[] rowIsNull;
private final BlockBuilder[] fieldBlockBuilders;
private boolean currentEntryOpened;
public RowBlockBuilder(List fieldTypes, BlockBuilderStatus blockBuilderStatus, int expectedEntries)
{
this(
blockBuilderStatus,
createFieldBlockBuilders(fieldTypes, blockBuilderStatus, expectedEntries),
new int[expectedEntries + 1],
new boolean[expectedEntries]);
}
private RowBlockBuilder(@Nullable BlockBuilderStatus blockBuilderStatus, BlockBuilder[] fieldBlockBuilders, int[] fieldBlockOffsets, boolean[] rowIsNull)
{
super(fieldBlockBuilders.length);
this.blockBuilderStatus = blockBuilderStatus;
this.positionCount = 0;
this.fieldBlockOffsets = requireNonNull(fieldBlockOffsets, "fieldBlockOffsets is null");
this.rowIsNull = requireNonNull(rowIsNull, "rowIsNull is null");
this.fieldBlockBuilders = requireNonNull(fieldBlockBuilders, "fieldBlockBuilders is null");
}
private static BlockBuilder[] createFieldBlockBuilders(List fieldTypes, BlockBuilderStatus blockBuilderStatus, int expectedEntries)
{
// Stream API should not be used since constructor can be called in performance sensitive sections
BlockBuilder[] fieldBlockBuilders = new BlockBuilder[fieldTypes.size()];
for (int i = 0; i < fieldTypes.size(); i++) {
fieldBlockBuilders[i] = fieldTypes.get(i).createBlockBuilder(blockBuilderStatus, expectedEntries);
}
return fieldBlockBuilders;
}
@Override
protected Block[] getRawFieldBlocks()
{
return fieldBlockBuilders;
}
@Override
protected int[] getFieldBlockOffsets()
{
return fieldBlockOffsets;
}
@Override
protected int getOffsetBase()
{
return 0;
}
@Override
protected boolean[] getRowIsNull()
{
return rowIsNull;
}
@Override
public int getPositionCount()
{
return positionCount;
}
@Override
public long getSizeInBytes()
{
long sizeInBytes = (Integer.BYTES + Byte.BYTES) * (long) positionCount;
for (int i = 0; i < numFields; i++) {
sizeInBytes += fieldBlockBuilders[i].getSizeInBytes();
}
return sizeInBytes;
}
@Override
public long getRetainedSizeInBytes()
{
long size = INSTANCE_SIZE + sizeOf(fieldBlockOffsets) + sizeOf(rowIsNull);
for (int i = 0; i < numFields; i++) {
size += fieldBlockBuilders[i].getRetainedSizeInBytes();
}
if (blockBuilderStatus != null) {
size += BlockBuilderStatus.INSTANCE_SIZE;
}
return size;
}
@Override
public void retainedBytesForEachPart(BiConsumer