diff --git a/presto-native-execution/presto_cpp/main/functions/tests/FunctionMetadataTest.cpp b/presto-native-execution/presto_cpp/main/functions/tests/FunctionMetadataTest.cpp index 226133c9e437c..5a83dc75d8a06 100644 --- a/presto-native-execution/presto_cpp/main/functions/tests/FunctionMetadataTest.cpp +++ b/presto-native-execution/presto_cpp/main/functions/tests/FunctionMetadataTest.cpp @@ -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()) { + 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()( + a["functionKind"].dump() + a["paramTypes"].dump()) < + folly::hasher()( + 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; } diff --git a/presto-native-execution/presto_cpp/main/functions/tests/data/Variance.json b/presto-native-execution/presto_cpp/main/functions/tests/data/Variance.json index 633d5d89e95a4..8bb21b981855f 100644 --- a/presto-native-execution/presto_cpp/main/functions/tests/data/Variance.json +++ b/presto-native-execution/presto_cpp/main/functions/tests/data/Variance.json @@ -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 } ] }