diff --git a/velox/dwio/common/tests/utils/BatchMaker.cpp b/velox/dwio/common/tests/utils/BatchMaker.cpp index 60019a788afe..14dd39df8fd5 100644 --- a/velox/dwio/common/tests/utils/BatchMaker.cpp +++ b/velox/dwio/common/tests/utils/BatchMaker.cpp @@ -48,7 +48,7 @@ VectorPtr createScalar( BufferPtr values = AlignedBuffer::allocate(size, &pool); auto valuesPtr = values->asMutableRange(); - BufferPtr nulls = AlignedBuffer::allocate(bits::nbytes(size), &pool); + BufferPtr nulls = allocateNulls(size, &pool); auto* nullsPtr = nulls->asMutable(); size_t nullCount = 0; @@ -68,7 +68,7 @@ VectorPtr createScalar( template VectorPtr BatchMaker::createVector( - const std::shared_ptr& /* unused */, + const TypePtr& /* unused */, size_t /* unused */, memory::MemoryPool& /* unused */, std::mt19937& /* unused */, @@ -78,7 +78,7 @@ VectorPtr BatchMaker::createVector( template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& /* unused */, + const TypePtr& /* unused */, size_t size, MemoryPool& pool, std::mt19937& gen, @@ -93,7 +93,7 @@ VectorPtr BatchMaker::createVector( template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& /* unused */, + const TypePtr& /* unused */, size_t size, MemoryPool& pool, std::mt19937& gen, @@ -108,7 +108,7 @@ VectorPtr BatchMaker::createVector( template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& /* unused */, + const TypePtr& /* unused */, size_t size, MemoryPool& pool, std::mt19937& gen, @@ -123,7 +123,7 @@ VectorPtr BatchMaker::createVector( template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& /* unused */, + const TypePtr& type, size_t size, MemoryPool& pool, std::mt19937& gen, @@ -133,12 +133,13 @@ VectorPtr BatchMaker::createVector( gen, [&gen]() { return static_cast(Random::rand32(gen)); }, pool, - isNullAt); + isNullAt, + type); } template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& /* unused */, + const TypePtr& /*type*/, size_t size, MemoryPool& pool, std::mt19937& gen, @@ -149,7 +150,7 @@ VectorPtr BatchMaker::createVector( template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& /* unused */, + const TypePtr& /* unused */, size_t size, MemoryPool& pool, std::mt19937& gen, @@ -164,7 +165,7 @@ VectorPtr BatchMaker::createVector( template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& /* unused */, + const TypePtr& /* unused */, size_t size, MemoryPool& pool, std::mt19937& gen, @@ -179,7 +180,7 @@ VectorPtr BatchMaker::createVector( template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& type, + const TypePtr& type, size_t size, MemoryPool& pool, std::mt19937& gen, @@ -249,7 +250,7 @@ VectorPtr createBinary( template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& /* unused */, + const TypePtr& /* unused */, size_t size, MemoryPool& pool, std::mt19937& gen, @@ -259,7 +260,7 @@ VectorPtr BatchMaker::createVector( template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& /* unused */, + const TypePtr& /* unused */, size_t size, MemoryPool& pool, std::mt19937& gen, @@ -269,7 +270,7 @@ VectorPtr BatchMaker::createVector( template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& /* unused */, + const TypePtr& /* unused */, size_t size, MemoryPool& pool, std::mt19937& gen, @@ -289,7 +290,7 @@ VectorPtr BatchMaker::createVector( template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& type, + const TypePtr& type, size_t size, MemoryPool& pool, std::mt19937& gen, @@ -297,7 +298,7 @@ VectorPtr BatchMaker::createVector( template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& type, + const TypePtr& type, size_t size, MemoryPool& pool, std::mt19937& gen, @@ -305,14 +306,14 @@ VectorPtr BatchMaker::createVector( template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& type, + const TypePtr& type, size_t size, MemoryPool& pool, std::mt19937& gen, std::function isNullAt); VectorPtr createRows( - const std::shared_ptr& type, + const TypePtr& type, size_t size, bool allowNulls, MemoryPool& pool, @@ -322,7 +323,7 @@ VectorPtr createRows( size_t nullCount = 0; if (allowNulls) { - nulls = AlignedBuffer::allocate(bits::nbytes(size), &pool); + nulls = allocateNulls(size, &pool); auto* nullsPtr = nulls->asMutable(); for (size_t i = 0; i < size; ++i) { auto notNull = isNotNull(gen, i, isNullAt); @@ -353,7 +354,7 @@ VectorPtr createRows( template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& type, + const TypePtr& type, size_t size, MemoryPool& pool, std::mt19937& gen, @@ -363,18 +364,18 @@ VectorPtr BatchMaker::createVector( template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& type, + const TypePtr& type, size_t size, MemoryPool& pool, std::mt19937& gen, std::function isNullAt) { - BufferPtr offsets = AlignedBuffer::allocate(size, &pool); + BufferPtr offsets = allocateOffsets(size, &pool); auto* offsetsPtr = offsets->asMutable(); - BufferPtr lengths = AlignedBuffer::allocate(size, &pool); + BufferPtr lengths = allocateSizes(size, &pool); auto* lengthsPtr = lengths->asMutable(); - BufferPtr nulls = AlignedBuffer::allocate(bits::nbytes(size), &pool); + BufferPtr nulls = allocateNulls(size, &pool); auto* nullsPtr = nulls->asMutable(); size_t nullCount = 0; @@ -564,18 +565,18 @@ VectorPtr createMapKeys( template <> VectorPtr BatchMaker::createVector( - const std::shared_ptr& type, + const TypePtr& type, size_t size, MemoryPool& pool, std::mt19937& gen, std::function isNullAt) { - BufferPtr offsets = AlignedBuffer::allocate(size, &pool); + BufferPtr offsets = allocateOffsets(size, &pool); auto* offsetsPtr = offsets->asMutable(); - BufferPtr lengths = AlignedBuffer::allocate(size, &pool); + BufferPtr lengths = allocateSizes(size, &pool); auto* lengthsPtr = lengths->asMutable(); - BufferPtr nulls = AlignedBuffer::allocate(bits::nbytes(size), &pool); + BufferPtr nulls = allocateNulls(size, &pool); auto* nullsPtr = nulls->asMutable(); size_t nullCount = 0; @@ -613,7 +614,7 @@ VectorPtr BatchMaker::createVector( } VectorPtr BatchMaker::createBatch( - const std::shared_ptr& type, + const TypePtr& type, uint64_t capacity, MemoryPool& memoryPool, std::mt19937& gen, @@ -625,7 +626,7 @@ VectorPtr BatchMaker::createBatch( } VectorPtr BatchMaker::createBatch( - const std::shared_ptr& type, + const TypePtr& type, uint64_t capacity, MemoryPool& memoryPool, std::function isNullAt, diff --git a/velox/dwio/common/tests/utils/BatchMaker.h b/velox/dwio/common/tests/utils/BatchMaker.h index 10588f30702d..4a15cbbc4fc4 100644 --- a/velox/dwio/common/tests/utils/BatchMaker.h +++ b/velox/dwio/common/tests/utils/BatchMaker.h @@ -31,14 +31,14 @@ void propagateNullsRecursive(BaseVector& vector); struct BatchMaker { static VectorPtr createBatch( - const std::shared_ptr& type, + const TypePtr& type, uint64_t capacity, memory::MemoryPool& memoryPool, std::mt19937& gen, std::function isNullAt = nullptr); static VectorPtr createBatch( - const std::shared_ptr& type, + const TypePtr& type, uint64_t capacity, memory::MemoryPool& memoryPool, std::function isNullAt = nullptr, @@ -46,7 +46,7 @@ struct BatchMaker { template static VectorPtr createVector( - const std::shared_ptr& type, + const TypePtr& type, size_t size, memory::MemoryPool& pool, std::mt19937& gen, @@ -54,7 +54,7 @@ struct BatchMaker { template static VectorPtr createVector( - const std::shared_ptr& type, + const TypePtr& type, size_t size, memory::MemoryPool& pool, std::function isNullAt = nullptr, diff --git a/velox/exec/tests/utils/QueryAssertions.cpp b/velox/exec/tests/utils/QueryAssertions.cpp index 8cfffbf2de48..3c64fa2bcf76 100644 --- a/velox/exec/tests/utils/QueryAssertions.cpp +++ b/velox/exec/tests/utils/QueryAssertions.cpp @@ -67,6 +67,18 @@ ::duckdb::Value duckValueAt( veloxTimestampToDuckDB(vector->as>()->valueAt(index))); } +template <> +::duckdb::Value duckValueAt( + const VectorPtr& vector, + vector_size_t index) { + auto type = vector->type(); + if (type->isDate()) { + return ::duckdb::Value::DATE(::duckdb::Date::EpochDaysToDate( + vector->as>()->valueAt(index))); + } + return ::duckdb::Value(vector->as>()->valueAt(index)); +} + template <> ::duckdb::Value duckValueAt( const VectorPtr& vector, @@ -871,11 +883,12 @@ void DuckDbQueryRunner::createTable( auto value = ::duckdb::Value::INTERVAL( 0, 0, columnVector->as>()->valueAt(row)); appender.Append(value); - } else if (type->isDate()) { - auto value = ::duckdb::Value::DATE(::duckdb::Date::EpochDaysToDate( - columnVector->as>()->valueAt(row))); - appender.Append(value); } else { + VELOX_CHECK( + type->equivalent(*columnVector->type()), + "{} vs. {}", + type->toString(), + columnVector->toString()) auto value = VELOX_DYNAMIC_SCALAR_TYPE_DISPATCH( duckValueAt, type->kind(), columnVector, row); appender.Append(value);