Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,41 @@ class FunctionMetadataTest : public ::testing::Test {
functionMetadata_ = getFunctionsMetadata();
}

void sortMetadataList(json::array_t& list) {
for (auto& metadata : list) {
// Sort constraint arrays for deterministic test comparisons.
for (auto const& [key, val] : metadata.items()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain the relevant of this check in a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if (key.ends_with("Constraints") && metadata[key].is_array()) {
std::sort(
metadata[key].begin(),
metadata[key].end(),
[](const json& a, const json& b) { return a.dump() < b.dump(); });
}
}
}
std::sort(list.begin(), list.end(), [](const json& a, const json& b) {
return folly::hasher<std::string>()(
a["functionKind"].dump() + a["paramTypes"].dump()) <
folly::hasher<std::string>()(
b["functionKind"].dump() + b["paramTypes"].dump());
});
}

void testFunction(
const std::string& name,
const std::string& expectedFile,
size_t expectedSize) {
json metadataList = functionMetadata_.at(name);
json::array_t metadataList = functionMetadata_.at(name);
EXPECT_EQ(metadataList.size(), expectedSize);
std::string expectedStr = slurp(
test::utils::getDataPath(
"/github/presto-trunk/presto-native-execution/presto_cpp/main/functions/tests/data/",
expectedFile));
auto expected = json::parse(expectedStr);
auto comparator = [](const json& a, const json& b) {
return (a["outputType"] < b["outputType"]);
};

json::array_t expectedList = expected[name];
std::sort(expectedList.begin(), expectedList.end(), comparator);
std::sort(metadataList.begin(), metadataList.end(), comparator);
sortMetadataList(expectedList);
sortMetadataList(metadataList);
for (auto i = 0; i < expectedSize; i++) {
EXPECT_EQ(expectedList[i], metadataList[i]) << "Position: " << i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,6 @@
"schema": "default",
"typeVariableConstraints":[],
"variableArity":false
},
{
"aggregateMetadata": {
"intermediateType": "row(bigint,double,double)",
"isOrderSensitive": true
},
"docString": "presto.default.variance",
"functionKind": "WINDOW",
"longVariableConstraints":[],
"outputType": "double",
"paramTypes": [
"smallint"
],
"routineCharacteristics": {
"determinism": "DETERMINISTIC",
"language": "CPP",
"nullCallClause": "CALLED_ON_NULL_INPUT"
},
"schema": "default",
"typeVariableConstraints":[],
"variableArity":false
}
]
}
Loading