Skip to content

Commit

Permalink
Add support of velox vectors in ReferenceQueryRunner.
Browse files Browse the repository at this point in the history
  • Loading branch information
kgpai committed Feb 29, 2024
1 parent 87a0519 commit d658fb0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
24 changes: 20 additions & 4 deletions velox/exec/fuzzer/PrestoQueryRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,13 @@ std::multiset<std::vector<variant>> PrestoQueryRunner::execute(
const std::string& sql,
const std::vector<RowVectorPtr>& input,
const RowTypePtr& resultType) {
return exec::test::materialize(executeImpl(sql, input, resultType));
}

std::vector<velox::RowVectorPtr> PrestoQueryRunner::executeImpl(
const std::string& sql,
const std::vector<velox::RowVectorPtr>& input,
const velox::RowTypePtr& resultType) {
auto inputType = asRowType(input[0]->type());
if (inputType->size() == 0) {
// The query doesn't need to read any columns, but it needs to see a
Expand All @@ -509,7 +516,7 @@ std::multiset<std::vector<variant>> PrestoQueryRunner::execute(
nullptr,
numInput,
std::vector<VectorPtr>{column});
return execute(sql, {rowVector}, resultType);
return executeImpl(sql, {rowVector}, resultType);
}

// Create tmp table in Presto using DWRF file format and add a single
Expand Down Expand Up @@ -548,9 +555,7 @@ std::multiset<std::vector<variant>> PrestoQueryRunner::execute(
writeToFile(newFilePath, input, writerPool.get());

// Run the query.
results = execute(sql);

return exec::test::materialize(results);
return execute(sql);
}

std::vector<RowVectorPtr> PrestoQueryRunner::execute(const std::string& sql) {
Expand Down Expand Up @@ -611,4 +616,15 @@ std::string PrestoQueryRunner::fetchNext(const std::string& nextUri) {
return response.text;
}

bool PrestoQueryRunner::supportsVeloxVectors() const {
return true;
}

std::vector<RowVectorPtr> PrestoQueryRunner::executeVector(
const std::string& sql,
const std::vector<RowVectorPtr>& input,
const RowTypePtr& resultType) {
return executeImpl(sql, input, resultType);
}

} // namespace facebook::velox::exec::test
12 changes: 12 additions & 0 deletions velox/exec/fuzzer/PrestoQueryRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,19 @@ class PrestoQueryRunner : public velox::exec::test::ReferenceQueryRunner {
/// the query must already exist.
std::vector<velox::RowVectorPtr> execute(const std::string& sql);

bool supportsVeloxVectors() const override;

std::vector<RowVectorPtr> executeVector(
const std::string& sql,
const std::vector<RowVectorPtr>& input,
const RowTypePtr& resultType) override;

private:
std::vector<velox::RowVectorPtr> executeImpl(
const std::string& sql,
const std::vector<velox::RowVectorPtr>& input,
const velox::RowTypePtr& resultType);

velox::memory::MemoryPool* rootPool() {
return rootPool_.get();
}
Expand Down
17 changes: 17 additions & 0 deletions velox/exec/fuzzer/ReferenceQueryRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ class ReferenceQueryRunner {
const std::string& sql,
const std::vector<RowVectorPtr>& input,
const RowTypePtr& resultType) = 0;

/// Returns true if the underlying Query Runner supports
/// returning the results of a query in Velox Vector format. If supported
/// then 'executeVector' can be called to get results as Velox Vector.
virtual bool supportsVeloxVectors() const {
return false;
}

/// Executes SQL query returned by the 'toSql' method using 'input' data
/// and returns the results in RowVector format. Check if this function is
/// supported by calling the 'supportsVeloxVectors' function before calling.
virtual std::vector<RowVectorPtr> executeVector(
const std::string& sql,
const std::vector<RowVectorPtr>& input,
const RowTypePtr& resultType) {
VELOX_NYI("Not supported in this Reference Query Runner.");
}
};

} // namespace facebook::velox::exec::test

0 comments on commit d658fb0

Please sign in to comment.