Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix flatvector size #436

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions velox/duckdb/functions/DuckFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ static void toDuck(
if (args.size() == 0) {
return;
}
auto numRows = args[0]->size();
auto numRows = rows.end();
auto cardinality = std::min<size_t>(numRows - offset, STANDARD_VECTOR_SIZE);
result.SetCardinality(cardinality);

Expand Down Expand Up @@ -453,7 +453,7 @@ class DuckDBFunction : public exec::VectorFunction {
auto state = initializeState(std::move(inputTypes), duckDBAllocator);
assert(state->functionIndex < set_.size());
auto& function = set_[state->functionIndex];
idx_t nrow = rows.size();
idx_t nrow = rows.end();

if (!result) {
result = createVeloxVector(rows, function.return_type, nrow, context);
Expand Down
3 changes: 0 additions & 3 deletions velox/functions/lib/IsNull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "velox/expression/DecodedArgs.h"
#include "velox/expression/EvalCtx.h"
#include "velox/expression/VectorFunction.h"

namespace facebook::velox::functions {
namespace {

Expand Down Expand Up @@ -65,7 +64,6 @@ class IsNullFunction : public exec::VectorFunction {
}
} else {
exec::DecodedArgs decodedArgs(rows, args, context);

isNull = AlignedBuffer::allocate<bool>(rows.size(), pool);
memcpy(
isNull->asMutable<int64_t>(),
Expand All @@ -76,7 +74,6 @@ class IsNullFunction : public exec::VectorFunction {
bits::negate(isNull->asMutable<char>(), rows.end());
}
}

auto localResult = std::make_shared<FlatVector<bool>>(
pool,
BOOLEAN(),
Expand Down
6 changes: 3 additions & 3 deletions velox/functions/lib/LambdaFunctionUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ BufferPtr flattenNulls(
}

BufferPtr nulls =
AlignedBuffer::allocate<bool>(rows.size(), decodedVector.base()->pool());
AlignedBuffer::allocate<bool>(rows.end(), decodedVector.base()->pool());
auto rawNulls = nulls->asMutable<uint64_t>();
rows.applyToSelected([&](vector_size_t row) {
bits::setNull(rawNulls, row, decodedVector.isNullAt(row));
Expand Down Expand Up @@ -104,7 +104,7 @@ ArrayVectorPtr flattenArray(
array->pool(),
array->type(),
newNulls,
rows.size(),
rows.end(),
newOffsets,
newSizes,
BaseVector::wrapInDictionary(
Expand Down Expand Up @@ -142,7 +142,7 @@ MapVectorPtr flattenMap(
map->pool(),
map->type(),
newNulls,
rows.size(),
rows.end(),
newOffsets,
newSizes,
BaseVector::wrapInDictionary(
Expand Down
8 changes: 4 additions & 4 deletions velox/functions/lib/MapConcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class MapConcatFunction : public exec::VectorFunction {

// Initialize offsets and sizes to 0 so that canonicalize() will
// work also for sparse 'rows'.
BufferPtr offsets = allocateOffsets(rows.size(), pool);
BufferPtr offsets = allocateOffsets(rows.end(), pool);
auto rawOffsets = offsets->asMutable<vector_size_t>();

BufferPtr sizes = allocateSizes(rows.size(), pool);
BufferPtr sizes = allocateSizes(rows.end(), pool);
auto rawSizes = sizes->asMutable<vector_size_t>();

vector_size_t offset = 0;
Expand Down Expand Up @@ -99,7 +99,7 @@ class MapConcatFunction : public exec::VectorFunction {
pool,
outputType,
BufferPtr(nullptr),
rows.size(),
rows.end(),
offsets,
sizes,
combinedKeys,
Expand Down Expand Up @@ -148,7 +148,7 @@ class MapConcatFunction : public exec::VectorFunction {
pool,
outputType,
BufferPtr(nullptr),
rows.size(),
rows.end(),
offsets,
sizes,
keys,
Expand Down
16 changes: 8 additions & 8 deletions velox/functions/lib/SubscriptUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ class SubscriptImpl : public exec::VectorFunction {
exec::EvalCtx& context) const {
auto* pool = context.pool();

BufferPtr indices = allocateIndices(rows.size(), pool);
BufferPtr indices = allocateIndices(rows.end(), pool);
auto rawIndices = indices->asMutable<vector_size_t>();

// Create nulls for lazy initialization.
NullsBuilder nullsBuilder(rows.size(), pool);
NullsBuilder nullsBuilder(rows.end(), pool);

exec::LocalDecodedVector arrayHolder(context, *arrayArg, rows);
auto decodedArray = arrayHolder.get();
Expand Down Expand Up @@ -222,11 +222,11 @@ class SubscriptImpl : public exec::VectorFunction {
// to ensure user error checks for indices are not skipped.
if (baseArray->elements()->size() == 0) {
return BaseVector::createNullConstant(
baseArray->elements()->type(), rows.size(), context.pool());
baseArray->elements()->type(), rows.end(), context.pool());
}

return BaseVector::wrapInDictionary(
nullsBuilder.build(), indices, rows.size(), baseArray->elements());
nullsBuilder.build(), indices, rows.end(), baseArray->elements());
}

// Normalize indices from 1 or 0-based into always 0-based (according to
Expand Down Expand Up @@ -301,11 +301,11 @@ class SubscriptImpl : public exec::VectorFunction {
exec::EvalCtx& context) const {
auto* pool = context.pool();

BufferPtr indices = allocateIndices(rows.size(), pool);
BufferPtr indices = allocateIndices(rows.end(), pool);
auto rawIndices = indices->asMutable<vector_size_t>();

// Create nulls for lazy initialization.
NullsBuilder nullsBuilder(rows.size(), pool);
NullsBuilder nullsBuilder(rows.end(), pool);

// Get base MapVector.
// TODO: Optimize the case when indices are identity.
Expand Down Expand Up @@ -375,11 +375,11 @@ class SubscriptImpl : public exec::VectorFunction {
// ensure user error checks for indices are not skipped.
if (baseMap->mapValues()->size() == 0) {
return BaseVector::createNullConstant(
baseMap->mapValues()->type(), rows.size(), context.pool());
baseMap->mapValues()->type(), rows.end(), context.pool());
}

return BaseVector::wrapInDictionary(
nullsBuilder.build(), indices, rows.size(), baseMap->mapValues());
nullsBuilder.build(), indices, rows.end(), baseMap->mapValues());
}
};

Expand Down
4 changes: 2 additions & 2 deletions velox/functions/prestosql/ArrayConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class ArrayConstructor : public exec::VectorFunction {
context.ensureWritable(rows, outputType, result);
result->clearNulls(rows);
auto arrayResult = result->as<ArrayVector>();
auto sizes = arrayResult->mutableSizes(rows.size());
auto sizes = arrayResult->mutableSizes(rows.end());
auto rawSizes = sizes->asMutable<int32_t>();
auto offsets = arrayResult->mutableOffsets(rows.size());
auto offsets = arrayResult->mutableOffsets(rows.end());
auto rawOffsets = offsets->asMutable<int32_t>();

auto elementsResult = arrayResult->elements();
Expand Down
6 changes: 3 additions & 3 deletions velox/functions/prestosql/ArrayDistinct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ArrayDistinctFunction : public exec::VectorFunction {
exec::LocalSingleRow singleRow(context, flatIndex);
localResult = applyFlat(*singleRow, flatArray, context);
localResult =
BaseVector::wrapInConstant(rows.size(), flatIndex, localResult);
BaseVector::wrapInConstant(rows.end(), flatIndex, localResult);
} else {
localResult = applyFlat(rows, arg, context);
}
Expand All @@ -81,8 +81,8 @@ class ArrayDistinctFunction : public exec::VectorFunction {
toElementRows(elementsVector->size(), rows, arrayVector);
exec::LocalDecodedVector elements(context, *elementsVector, elementsRows);

vector_size_t elementsCount = elementsRows.size();
vector_size_t rowCount = arrayVector->size();
vector_size_t elementsCount = elementsRows.end();
vector_size_t rowCount = rows.end();

// Allocate new vectors for indices, length and offsets.
memory::MemoryPool* pool = context.pool();
Expand Down
6 changes: 3 additions & 3 deletions velox/functions/prestosql/ArrayDuplicates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ArrayDuplicatesFunction : public exec::VectorFunction {
exec::LocalSingleRow singleRow(context, flatIndex);
localResult = applyFlat(*singleRow, flatArray, context);
localResult =
BaseVector::wrapInConstant(rows.size(), flatIndex, localResult);
BaseVector::wrapInConstant(rows.end(), flatIndex, localResult);
} else {
localResult = applyFlat(rows, arg, context);
}
Expand All @@ -84,8 +84,8 @@ class ArrayDuplicatesFunction : public exec::VectorFunction {
toElementRows(elementsVector->size(), rows, arrayVector);
exec::LocalDecodedVector elements(context, *elementsVector, elementsRows);

vector_size_t numElements = elementsRows.size();
vector_size_t numRows = arrayVector->size();
vector_size_t numElements = elementsRows.end();
vector_size_t numRows = rows.end();

// Allocate new vectors for indices, length and offsets.
memory::MemoryPool* pool = context.pool();
Expand Down
6 changes: 3 additions & 3 deletions velox/functions/prestosql/ArrayShuffle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class ArrayShuffleFunction : public exec::VectorFunction {

// Allocate new buffer to hold shuffled indices.
BufferPtr shuffledIndices = allocateIndices(numElements, context.pool());
BufferPtr offsets = allocateOffsets(rows.size(), context.pool());
BufferPtr sizes = allocateSizes(rows.size(), context.pool());
BufferPtr offsets = allocateOffsets(rows.end(), context.pool());
BufferPtr sizes = allocateSizes(rows.end(), context.pool());

vector_size_t* rawIndices = shuffledIndices->asMutable<vector_size_t>();
vector_size_t* rawOffsets = offsets->asMutable<vector_size_t>();
Expand Down Expand Up @@ -98,7 +98,7 @@ class ArrayShuffleFunction : public exec::VectorFunction {
context.pool(),
arrayVector->type(),
nullptr,
rows.size(),
rows.end(),
std::move(offsets),
std::move(sizes),
std::move(resultElements));
Expand Down
2 changes: 1 addition & 1 deletion velox/functions/prestosql/ArraySort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class ArraySortFunction : public exec::VectorFunction {
exec::LocalSingleRow singleRow(context, flatIndex);
localResult = applyFlat(*singleRow, flatArray, context);
localResult =
BaseVector::wrapInConstant(rows.size(), flatIndex, localResult);
BaseVector::wrapInConstant(rows.end(), flatIndex, localResult);
} else {
localResult = applyFlat(rows, arg, context);
}
Expand Down
8 changes: 4 additions & 4 deletions velox/functions/prestosql/FilterFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class FilterFunctionBase : public exec::VectorFunction {
auto inputSizes = input->rawSizes();

auto* pool = context.pool();
resultSizes = allocateSizes(rows.size(), pool);
resultOffsets = allocateOffsets(rows.size(), pool);
resultSizes = allocateSizes(rows.end(), pool);
resultOffsets = allocateOffsets(rows.end(), pool);
auto rawResultSizes = resultSizes->asMutable<vector_size_t>();
auto rawResultOffsets = resultOffsets->asMutable<vector_size_t>();
auto numElements = lambdaArgs[0]->size();
Expand Down Expand Up @@ -163,7 +163,7 @@ class ArrayFilterFunction : public FilterFunctionBase {
flatArray->pool(),
flatArray->type(),
flatArray->nulls(),
rows.size(),
rows.end(),
std::move(resultOffsets),
std::move(resultSizes),
wrappedElements);
Expand Down Expand Up @@ -228,7 +228,7 @@ class MapFilterFunction : public FilterFunctionBase {
flatMap->pool(),
outputType,
flatMap->nulls(),
rows.size(),
rows.end(),
std::move(resultOffsets),
std::move(resultSizes),
wrappedKeys,
Expand Down
2 changes: 1 addition & 1 deletion velox/functions/prestosql/FromUnixTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class FromUnixtimeFunction : public exec::VectorFunction {
pool,
outputType,
BufferPtr(nullptr),
rows.size(),
rows.end(),
std::vector<VectorPtr>{timestamps, timezones},
0 /*nullCount*/);

Expand Down
8 changes: 4 additions & 4 deletions velox/functions/prestosql/InPredicate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class InPredicate : public exec::VectorFunction {
VectorPtr& result,
F&& testFunction) const {
if (alwaysNull_) {
auto localResult = createBoolConstantNull(rows.size(), context);
auto localResult = createBoolConstantNull(rows.end(), context);
context.moveOrCopyResult(localResult, rows, result);
return;
}
Expand All @@ -294,13 +294,13 @@ class InPredicate : public exec::VectorFunction {
auto simpleArg = arg->asUnchecked<SimpleVector<T>>();
VectorPtr localResult;
if (simpleArg->isNullAt(rows.begin())) {
localResult = createBoolConstantNull(rows.size(), context);
localResult = createBoolConstantNull(rows.end(), context);
} else {
bool pass = testFunction(simpleArg->valueAt(rows.begin()));
if (!pass && passOrNull) {
localResult = createBoolConstantNull(rows.size(), context);
localResult = createBoolConstantNull(rows.end(), context);
} else {
localResult = createBoolConstant(pass, rows.size(), context);
localResult = createBoolConstant(pass, rows.end(), context);
}
}

Expand Down
4 changes: 2 additions & 2 deletions velox/functions/prestosql/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ class MapFunction : public exec::VectorFunction {
totalElements += keysArray->sizeAt(keyIndices[row]);
});

BufferPtr offsets = allocateOffsets(rows.size(), context.pool());
BufferPtr offsets = allocateOffsets(rows.end(), context.pool());
auto rawOffsets = offsets->asMutable<vector_size_t>();

BufferPtr sizes = allocateSizes(rows.size(), context.pool());
BufferPtr sizes = allocateSizes(rows.end(), context.pool());
auto rawSizes = sizes->asMutable<vector_size_t>();

BufferPtr valuesIndices = allocateIndices(totalElements, context.pool());
Expand Down
2 changes: 1 addition & 1 deletion velox/functions/prestosql/MapKeysAndValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MapKeyValueFunction : public exec::VectorFunction {
exec::LocalSingleRow singleRow(context, flatIndex);
localResult = applyFlat(*singleRow, flatMap, context);
localResult =
BaseVector::wrapInConstant(rows.size(), flatIndex, localResult);
BaseVector::wrapInConstant(rows.end(), flatIndex, localResult);
} else {
localResult = applyFlat(rows, arg, context);
}
Expand Down
6 changes: 3 additions & 3 deletions velox/functions/prestosql/Not.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class NotFunction : public exec::VectorFunction {
if (input->isConstantEncoding()) {
bool value = input->as<ConstantVector<bool>>()->valueAt(0);
negated =
AlignedBuffer::allocate<bool>(rows.size(), context.pool(), !value);
AlignedBuffer::allocate<bool>(rows.end(), context.pool(), !value);
} else {
negated = AlignedBuffer::allocate<bool>(rows.size(), context.pool());
negated = AlignedBuffer::allocate<bool>(rows.end(), context.pool());
auto rawNegated = negated->asMutable<char>();

auto rawInput = input->asFlatVector<bool>()->rawValues<uint64_t>();
Expand All @@ -54,7 +54,7 @@ class NotFunction : public exec::VectorFunction {
context.pool(),
BOOLEAN(),
nullptr,
rows.size(),
rows.end(),
negated,
std::vector<BufferPtr>{});

Expand Down
4 changes: 2 additions & 2 deletions velox/functions/prestosql/Repeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class RepeatFunction : public exec::VectorFunction {
std::vector<VectorPtr>& args,
const TypePtr& outputType,
exec::EvalCtx& context) const {
const auto numRows = rows.size();
const auto numRows = rows.end();
auto pool = context.pool();

if (args[1]->as<ConstantVector<int32_t>>()->isNullAt(0)) {
Expand Down Expand Up @@ -120,7 +120,7 @@ class RepeatFunction : public exec::VectorFunction {
totalCount += count;
});

const auto numRows = rows.size();
const auto numRows = rows.end();
auto pool = context.pool();

// Allocate new vector for nulls if necessary.
Expand Down
2 changes: 1 addition & 1 deletion velox/functions/prestosql/Reverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class ReverseFunction : public exec::VectorFunction {
exec::LocalSingleRow singleRow(context, flatIndex);
localResult = applyArrayFlat(*singleRow, flatArray, context);
localResult =
BaseVector::wrapInConstant(rows.size(), flatIndex, localResult);
BaseVector::wrapInConstant(rows.end(), flatIndex, localResult);
} else {
localResult = applyArrayFlat(rows, arg, context);
}
Expand Down
2 changes: 1 addition & 1 deletion velox/functions/prestosql/RowFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RowFunction : public exec::VectorFunction {
context.pool(),
outputType,
BufferPtr(nullptr),
rows.size(),
rows.end(),
std::move(argsCopy),
0 /*nullCount*/);
context.moveOrCopyResult(row, rows, result);
Expand Down
2 changes: 1 addition & 1 deletion velox/functions/prestosql/VectorArithmetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class VectorArithmetic : public VectorFunction {
args[1].unique() && rightEncoding == VectorEncoding::Simple::FLAT) {
result = std::move(args[1]);
} else {
result = BaseVector::create(outputType, rows.size(), context.pool());
result = BaseVector::create(outputType, rows.end(), context.pool());
}
} else {
// if the output is previously initialized, we prepare it for writing
Expand Down
2 changes: 1 addition & 1 deletion velox/functions/prestosql/ZipWith.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class ZipWithFunction : public exec::VectorFunction {
auto* sizes = base->rawSizes();

if (!needsPadding && decoded->isIdentityMapping() && rows.isAllSelected() &&
areSameOffsets(offsets, resultOffsets, rows.size())) {
areSameOffsets(offsets, resultOffsets, rows.end())) {
return base->elements();
}

Expand Down
Loading
Loading