-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[native] Fix bug when parsing SqlFunctionHandle
- Loading branch information
Showing
4 changed files
with
204 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
presto-native-execution/presto_cpp/main/types/tests/PrestoToVeloxQueryPlanTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* | ||
* 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 "presto_cpp/main/types/PrestoToVeloxQueryPlan.h" | ||
#include <gtest/gtest.h> | ||
#include "velox/common/base/tests/GTestUtils.h" | ||
#include "velox/functions/prestosql/types/HyperLogLogType.h" | ||
#include "velox/functions/prestosql/types/IPAddressType.h" | ||
#include "velox/functions/prestosql/types/IPPrefixType.h" | ||
#include "velox/functions/prestosql/types/JsonType.h" | ||
#include "velox/functions/prestosql/types/TimestampWithTimeZoneType.h" | ||
#include "velox/functions/prestosql/types/UuidType.h" | ||
|
||
using namespace facebook::presto; | ||
using namespace facebook::velox; | ||
|
||
namespace { | ||
inline void validateSqlFunctionHandleParsing( | ||
const std::shared_ptr<facebook::presto::protocol::FunctionHandle>& | ||
functionHandle, | ||
std::vector<TypePtr> expectedRawInputTypes) { | ||
std::vector<TypePtr> actualRawInputTypes; | ||
TypeParser typeParser; | ||
auto sqlFunctionHandle = | ||
std::static_pointer_cast<protocol::SqlFunctionHandle>(functionHandle); | ||
facebook::presto::parseSqlFunctionHandle( | ||
sqlFunctionHandle, actualRawInputTypes, typeParser); | ||
EXPECT_EQ(expectedRawInputTypes.size(), actualRawInputTypes.size()); | ||
for (int i = 0; i < expectedRawInputTypes.size(); i++) { | ||
EXPECT_EQ(*expectedRawInputTypes[i], *actualRawInputTypes[i]); | ||
} | ||
} | ||
} // namespace | ||
|
||
class PrestoToVeloxQueryPlanTest : public ::testing::Test { | ||
public: | ||
PrestoToVeloxQueryPlanTest() { | ||
registerHyperLogLogType(); | ||
registerIPAddressType(); | ||
registerIPPrefixType(); | ||
registerJsonType(); | ||
registerTimestampWithTimeZoneType(); | ||
registerUuidType(); | ||
} | ||
}; | ||
|
||
TEST_F(PrestoToVeloxQueryPlanTest, parseSqlFunctionHandleWithZeroParam) { | ||
std::string str = R"( | ||
{ | ||
"@type": "json_file", | ||
"functionId": "json_file.test.count;", | ||
"version": "1" | ||
} | ||
)"; | ||
|
||
json j = json::parse(str); | ||
std::shared_ptr<facebook::presto::protocol::FunctionHandle> functionHandle = | ||
j; | ||
ASSERT_NE(functionHandle, nullptr); | ||
validateSqlFunctionHandleParsing(functionHandle, {}); | ||
} | ||
|
||
TEST_F(PrestoToVeloxQueryPlanTest, parseSqlFunctionHandleWithOneParam) { | ||
std::string str = R"( | ||
{ | ||
"@type": "json_file", | ||
"functionId": "json_file.test.count;tinyint", | ||
"version": "1" | ||
} | ||
)"; | ||
|
||
json j = json::parse(str); | ||
std::shared_ptr<facebook::presto::protocol::FunctionHandle> functionHandle = | ||
j; | ||
ASSERT_NE(functionHandle, nullptr); | ||
|
||
std::vector<TypePtr> expectedRawInputTypes{TINYINT()}; | ||
validateSqlFunctionHandleParsing(functionHandle, expectedRawInputTypes); | ||
} | ||
|
||
TEST_F(PrestoToVeloxQueryPlanTest, parseSqlFunctionHandleWithMultipleParam) { | ||
std::string str = R"( | ||
{ | ||
"@type": "json_file", | ||
"functionId": "json_file.test.sum;array(decimal(15, 2));varchar", | ||
"version": "1" | ||
} | ||
)"; | ||
|
||
json j = json::parse(str); | ||
std::shared_ptr<facebook::presto::protocol::FunctionHandle> functionHandle = | ||
j; | ||
ASSERT_NE(functionHandle, nullptr); | ||
|
||
std::vector<TypePtr> expectedRawInputTypes{ARRAY(DECIMAL(15, 2)), VARCHAR()}; | ||
validateSqlFunctionHandleParsing(functionHandle, expectedRawInputTypes); | ||
} | ||
|
||
TEST_F(PrestoToVeloxQueryPlanTest, parseSqlFunctionHandleMapComplexType) { | ||
std::string str = R"( | ||
{ | ||
"@type": "json_file", | ||
"functionId": "json_file.test.sum;map(smallint, decimal(15, 2));REAL", | ||
"version": "1" | ||
} | ||
)"; | ||
|
||
json j = json::parse(str); | ||
std::shared_ptr<facebook::presto::protocol::FunctionHandle> functionHandle = | ||
j; | ||
ASSERT_NE(functionHandle, nullptr); | ||
|
||
std::vector<TypePtr> expectedRawInputTypes{ | ||
MAP(SMALLINT(), DECIMAL(15, 2)), REAL()}; | ||
validateSqlFunctionHandleParsing(functionHandle, expectedRawInputTypes); | ||
} | ||
|
||
TEST_F(PrestoToVeloxQueryPlanTest, parseSqlFunctionHandleRowComplexType) { | ||
std::string str = R"( | ||
{ | ||
"@type": "json_file", | ||
"functionId": "json_file.test.all_complex_types;row(map(hugeint, ipaddress), ipprefix);row(array(varbinary), timestamp, date, json, hyperloglog, timestamp with time zone, interval year to month, interval day to second);function(double, boolean);uuid", | ||
"version": "1" | ||
} | ||
)"; | ||
|
||
json j = json::parse(str); | ||
std::shared_ptr<facebook::presto::protocol::FunctionHandle> functionHandle = | ||
j; | ||
ASSERT_NE(functionHandle, nullptr); | ||
|
||
std::vector<TypePtr> expectedRawInputTypes{ | ||
ROW({MAP(HUGEINT(), IPADDRESS()), IPPREFIX()}), | ||
ROW( | ||
{ARRAY(VARBINARY()), | ||
TIMESTAMP(), | ||
DATE(), | ||
JSON(), | ||
HYPERLOGLOG(), | ||
TIMESTAMP_WITH_TIME_ZONE(), | ||
INTERVAL_YEAR_MONTH(), | ||
INTERVAL_DAY_TIME()}), | ||
FUNCTION({DOUBLE()}, BOOLEAN()), | ||
UUID()}; | ||
validateSqlFunctionHandleParsing(functionHandle, expectedRawInputTypes); | ||
} |