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

Add PrestoQueryRunner #7628

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions velox/exec/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,11 @@ add_test(
COMMAND cpr_http_client_test
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(cpr_http_client_test cpr::cpr gtest gtest_main)

add_executable(presto_query_runner_test PrestoQueryRunnerTest.cpp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a separate executable for his test? We used to have a problem with CI ran out of disk space because all these executables are very large. CC: @kgpai

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbasmanova Removed this executable, and linked the runner test into velox_exec_infra_test.

add_test(
NAME presto_query_runner_test
COMMAND presto_query_runner_test
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(presto_query_runner_test velox_presto_serializer
velox_dwio_dwrf_writer velox_exec_test_lib)
101 changes: 101 additions & 0 deletions velox/exec/tests/PrestoQueryRunnerTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <folly/init/Init.h>
#include <gtest/gtest.h>

#include "velox/exec/tests/utils/AssertQueryBuilder.h"
#include "velox/exec/tests/utils/PlanBuilder.h"
#include "velox/exec/tests/utils/PrestoQueryRunner.h"
#include "velox/functions/prestosql/aggregates/RegisterAggregateFunctions.h"
#include "velox/functions/prestosql/registration/RegistrationFunctions.h"
#include "velox/parse/TypeResolver.h"
#include "velox/vector/tests/utils/VectorTestBase.h"

using namespace facebook::velox;
using namespace facebook::velox::test;

namespace facebook::velox::exec::test {

class PrestoQueryRunnerTest : public ::testing::Test,
public velox::test::VectorTestBase {
protected:
void SetUp() override {
velox::functions::prestosql::registerAllScalarFunctions();
velox::aggregate::prestosql::registerAllAggregateFunctions();
velox::parse::registerTypeResolver();
}
};

TEST_F(PrestoQueryRunnerTest, DISABLED_basic) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you add a comment here that this is disabled because it requires a presto co-ordinator running at localhost etc ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments.

auto queryRunner = std::make_unique<PrestoQueryRunner>(
"http://127.0.0.1:8080", "hive", 20'000);

auto results = queryRunner->execute("SELECT count(*) FROM nation");
auto expected = makeRowVector({
makeConstant<int64_t>(25, 1),
});
velox::exec::test::assertEqualResults({expected}, {results});

results =
queryRunner->execute("SELECT regionkey, count(*) FROM nation GROUP BY 1");

expected = makeRowVector({
makeFlatVector<int64_t>({0, 1, 2, 3, 4}),
makeFlatVector<int64_t>({5, 5, 5, 5, 5}),
});
velox::exec::test::assertEqualResults({expected}, {results});
}

TEST_F(PrestoQueryRunnerTest, DISABLED_fuzzer) {
auto data = makeRowVector({
makeFlatVector<int64_t>({1, 2, 3, 4, 5}),
makeArrayVectorFromJson<int64_t>({
"[]",
"[1, 2, 3]",
"null",
"[1, 2, 3, 4]",
}),
});

auto plan = velox::exec::test::PlanBuilder()
.values({data})
.singleAggregation({}, {"min(c0)", "max(c0)", "set_agg(c1)"})
.project({"a0", "a1", "array_sort(a2)"})
.planNode();

auto queryRunner =
std::make_unique<PrestoQueryRunner>("http://127.0.0.1:8080", "hive");
auto sql = queryRunner->toSql(plan);
ASSERT_TRUE(sql.has_value());

auto prestoResults = queryRunner->execute(
sql.value(),
{data},
ROW({"a", "b", "c"}, {BIGINT(), BIGINT(), ARRAY(BIGINT())}));

auto veloxResults =
velox::exec::test::AssertQueryBuilder(plan).copyResults(pool());
velox::exec::test::assertEqualResults(
prestoResults, plan->outputType(), {veloxResults});
}
} // namespace facebook::velox::exec::test

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
folly::Init init(&argc, &argv, true);
return RUN_ALL_TESTS();
}
8 changes: 6 additions & 2 deletions velox/exec/tests/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ add_library(
SumNonPODAggregate.cpp
TpchQueryBuilder.cpp
VectorTestUtil.cpp
PortUtil.cpp)
PortUtil.cpp
PrestoQueryRunner.cpp)

target_link_libraries(
velox_exec_test_lib
Expand All @@ -49,7 +50,10 @@ target_link_libraries(
velox_tpch_connector
velox_presto_serializer
velox_functions_prestosql
velox_aggregates)
velox_aggregates
cpr::cpr
velox_type_parser
Folly::folly)

add_library(velox_aggregation_fuzzer AggregationFuzzer.cpp)

Expand Down
Loading
Loading