Skip to content

Commit

Permalink
Revert "Fix: use rows.end() instead of rows.size() in functions. (fac…
Browse files Browse the repository at this point in the history
…ebookincubator#4456)"

This reverts commit c69efa5.
  • Loading branch information
zhejiangxiaomai committed Apr 23, 2023
1 parent 2239c26 commit ba4a625
Show file tree
Hide file tree
Showing 24 changed files with 69 additions and 64 deletions.
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 = rows.end();
auto numRows = args[0]->size();
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.end();
idx_t nrow = rows.size();

if (!result) {
result = createVeloxVector(rows, function.return_type, nrow, context);
Expand Down
15 changes: 10 additions & 5 deletions velox/functions/lib/IsNull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ class IsNullFunction : public exec::VectorFunction {
if (arg->isConstantEncoding()) {
bool isNull = arg->isNullAt(rows.begin());
auto localResult = BaseVector::createConstant(
BOOLEAN(), IsNotNULL ? !isNull : isNull, rows.end(), pool);
BOOLEAN(), IsNotNULL ? !isNull : isNull, rows.size(), pool);
context.moveOrCopyResult(localResult, rows, result);
return;
}

if (!arg->mayHaveNulls()) {
// No nulls.
auto localResult = BaseVector::createConstant(
BOOLEAN(), IsNotNULL ? true : false, rows.end(), pool);
BOOLEAN(), IsNotNULL ? true : false, rows.size(), pool);
context.moveOrCopyResult(localResult, rows, result);
return;
}
Expand All @@ -56,7 +56,7 @@ class IsNullFunction : public exec::VectorFunction {
if constexpr (IsNotNULL) {
isNull = arg->nulls();
} else {
isNull = AlignedBuffer::allocate<bool>(rows.end(), pool);
isNull = AlignedBuffer::allocate<bool>(rows.size(), pool);
memcpy(
isNull->asMutable<int64_t>(),
arg->rawNulls(),
Expand All @@ -66,7 +66,7 @@ class IsNullFunction : public exec::VectorFunction {
} else {
exec::DecodedArgs decodedArgs(rows, args, context);

isNull = AlignedBuffer::allocate<bool>(rows.end(), pool);
isNull = AlignedBuffer::allocate<bool>(rows.size(), pool);
memcpy(
isNull->asMutable<int64_t>(),
decodedArgs.at(0)->nulls(),
Expand All @@ -78,7 +78,12 @@ class IsNullFunction : public exec::VectorFunction {
}

auto localResult = std::make_shared<FlatVector<bool>>(
pool, BOOLEAN(), nullptr, rows.end(), isNull, std::vector<BufferPtr>{});
pool,
BOOLEAN(),
nullptr,
rows.size(),
isNull,
std::vector<BufferPtr>{});
context.moveOrCopyResult(localResult, rows, result);
}

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.end(), decodedVector.base()->pool());
AlignedBuffer::allocate<bool>(rows.size(), 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.end(),
rows.size(),
newOffsets,
newSizes,
BaseVector::wrapInDictionary(
Expand Down Expand Up @@ -142,7 +142,7 @@ MapVectorPtr flattenMap(
map->pool(),
map->type(),
newNulls,
rows.end(),
rows.size(),
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.end(), pool);
BufferPtr offsets = allocateOffsets(rows.size(), pool);
auto rawOffsets = offsets->asMutable<vector_size_t>();

BufferPtr sizes = allocateSizes(rows.end(), pool);
BufferPtr sizes = allocateSizes(rows.size(), 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.end(),
rows.size(),
offsets,
sizes,
combinedKeys,
Expand Down Expand Up @@ -148,7 +148,7 @@ class MapConcatFunction : public exec::VectorFunction {
pool,
outputType,
BufferPtr(nullptr),
rows.end(),
rows.size(),
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 @@ -156,11 +156,11 @@ class SubscriptImpl : public exec::VectorFunction {
exec::EvalCtx& context) const {
auto* pool = context.pool();

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

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

exec::LocalDecodedVector arrayHolder(context, *arrayArg, rows);
auto decodedArray = arrayHolder.get();
Expand Down Expand Up @@ -211,11 +211,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.end(), context.pool());
baseArray->elements()->type(), rows.size(), context.pool());
}

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

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

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

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

// Get base MapVector.
// TODO: Optimize the case when indices are identity.
Expand Down Expand Up @@ -364,11 +364,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.end(), context.pool());
baseMap->mapValues()->type(), rows.size(), context.pool());
}

return BaseVector::wrapInDictionary(
nullsBuilder.build(), indices, rows.end(), baseMap->mapValues());
nullsBuilder.build(), indices, rows.size(), 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.end());
auto sizes = arrayResult->mutableSizes(rows.size());
auto rawSizes = sizes->asMutable<int32_t>();
auto offsets = arrayResult->mutableOffsets(rows.end());
auto offsets = arrayResult->mutableOffsets(rows.size());
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.end(), flatIndex, localResult);
BaseVector::wrapInConstant(rows.size(), 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.end();
vector_size_t rowCount = rows.end();
vector_size_t elementsCount = elementsRows.size();
vector_size_t rowCount = arrayVector->size();

// 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.end(), flatIndex, localResult);
BaseVector::wrapInConstant(rows.size(), 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.end();
vector_size_t numRows = rows.end();
vector_size_t numElements = elementsRows.size();
vector_size_t numRows = arrayVector->size();

// 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.end(), context.pool());
BufferPtr sizes = allocateSizes(rows.end(), context.pool());
BufferPtr offsets = allocateOffsets(rows.size(), context.pool());
BufferPtr sizes = allocateSizes(rows.size(), 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.end(),
rows.size(),
std::move(offsets),
std::move(sizes),
std::move(resultElements));
Expand Down
4 changes: 2 additions & 2 deletions velox/functions/prestosql/ArraySort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void applyScalarType(
VELOX_DCHECK(kind == inputElements->typeKind());
const SelectivityVector inputElementRows =
toElementRows(inputElements->size(), rows, inputArray);
const vector_size_t elementsCount = inputElementRows.end();
const vector_size_t elementsCount = inputElementRows.size();

// TODO: consider to use dictionary wrapping to avoid the direct sorting on
// the scalar values as we do for complex data type if this runs slow in
Expand Down 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.end(), flatIndex, localResult);
BaseVector::wrapInConstant(rows.size(), 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.end(), pool);
resultOffsets = allocateOffsets(rows.end(), pool);
resultSizes = allocateSizes(rows.size(), pool);
resultOffsets = allocateOffsets(rows.size(), 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.end(),
rows.size(),
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.end(),
rows.size(),
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.end(),
rows.size(),
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 @@ -244,7 +244,7 @@ class InPredicate : public exec::VectorFunction {
VectorPtr& result,
F&& testFunction) const {
if (alwaysNull_) {
auto localResult = createBoolConstantNull(rows.end(), context);
auto localResult = createBoolConstantNull(rows.size(), context);
context.moveOrCopyResult(localResult, rows, result);
return;
}
Expand All @@ -257,13 +257,13 @@ class InPredicate : public exec::VectorFunction {
auto simpleArg = arg->asUnchecked<SimpleVector<T>>();
VectorPtr localResult;
if (simpleArg->isNullAt(rows.begin())) {
localResult = createBoolConstantNull(rows.end(), context);
localResult = createBoolConstantNull(rows.size(), context);
} else {
bool pass = testFunction(simpleArg->valueAt(rows.begin()));
if (!pass && passOrNull) {
localResult = createBoolConstantNull(rows.end(), context);
localResult = createBoolConstantNull(rows.size(), context);
} else {
localResult = createBoolConstant(pass, rows.end(), context);
localResult = createBoolConstant(pass, rows.size(), 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 @@ -119,10 +119,10 @@ class MapFunction : public exec::VectorFunction {
totalElements += keysArray->sizeAt(keyIndices[row]);
});

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

BufferPtr sizes = allocateSizes(rows.end(), context.pool());
BufferPtr sizes = allocateSizes(rows.size(), 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.end(), flatIndex, localResult);
BaseVector::wrapInConstant(rows.size(), 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.end(), context.pool(), !value);
AlignedBuffer::allocate<bool>(rows.size(), context.pool(), !value);
} else {
negated = AlignedBuffer::allocate<bool>(rows.end(), context.pool());
negated = AlignedBuffer::allocate<bool>(rows.size(), 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.end(),
rows.size(),
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.end();
const auto numRows = rows.size();
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.end();
const auto numRows = rows.size();
auto pool = context.pool();

// Allocate new vector for nulls if necessary.
Expand Down
Loading

0 comments on commit ba4a625

Please sign in to comment.