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 def25e0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
17 changes: 13 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(executeVector(sql, input, resultType));
}

std::vector<velox::RowVectorPtr> PrestoQueryRunner::executeVector(
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 executeVector(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,8 @@ std::string PrestoQueryRunner::fetchNext(const std::string& nextUri) {
return response.text;
}

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

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

bool supportsVeloxVectorResults() const override;

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

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

/// Returns true if 'executeVector' can be called to get results as Velox
/// Vector.
virtual bool supportsVeloxVectorResults() const {
return false;
}

/// Similar to 'execute' but returns results in RowVector format.
/// Caller should ensure 'supportsVeloxVectorResults' returns true.
virtual std::vector<RowVectorPtr> executeVector(
const std::string& sql,
const std::vector<RowVectorPtr>& input,
const RowTypePtr& resultType) {
VELOX_UNSUPPORTED();
}
};

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

0 comments on commit def25e0

Please sign in to comment.