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

refactor: upgrade multi-key sort #77

Merged
merged 3 commits into from
Jun 27, 2023
Merged
Changes from 1 commit
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
34 changes: 13 additions & 21 deletions src/substrait/textplan/converter/ReferenceNormalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,19 @@ namespace {
bool compareExtensionFunctions(
const ::substrait::proto::extensions::SimpleExtensionDeclaration& a,
const ::substrait::proto::extensions::SimpleExtensionDeclaration& b) {
// First sort so that extension functions proceed any other kind of extension.
if (a.has_extension_function() && !b.has_extension_function()) {
return true;
} else if (!a.has_extension_function() && b.has_extension_function()) {
// Extension functions always come first.
return false;
} else if (!a.has_extension_function() && !b.has_extension_function()) {
// Both are not extension functions, no difference in ordering.
return false;
}
// Now sort by space.
if (a.extension_function().extension_uri_reference() <
b.extension_function().extension_uri_reference()) {
return true;
} else if (
a.extension_function().extension_uri_reference() >
b.extension_function().extension_uri_reference()) {
return false;
}
// Finally sort by name within a space.
return a.extension_function().name() < b.extension_function().name();
auto ord = [](const auto& decl) {
return make_tuple(
// First sort so that extension functions precede any other kind of
// extension.
not decl.has_extension_function(),
// Next sort by space.
decl.extension_function().extension_uri_reference(),
// Finally sort by name within a space.
decl.extension_function().name());
EpsilonPrime marked this conversation as resolved.
Show resolved Hide resolved
};

// Now let the default tuple compare do the rest of the work.
return ord(a) > ord(b);
}

void normalizeFunctionsForExpression(
Expand Down