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 Sort Operator for Window Functions #13619

Merged
merged 10 commits into from Jan 6, 2023
Merged

Conversation

imply-cheddar
Copy link
Contributor

Adds the NaiveSortMaker and NaiveSortOperator which handle sorting.

This adds a default implementation of the sort operation as well.

Additionally, SortedGroupPartitioner has been renamed to ClusteredGroupPartitioner as the semantics actually don't require sorting (which requires definition of a direction).

This PR has:

  • been self-reviewed.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.

@@ -891,6 +891,7 @@ public void assertResultsEquals(String sql, List<Object[]> expectedResults, List
results.get(i)
);
}
Assert.assertEquals(expectedResults.size(), results.size());
Copy link
Contributor

Choose a reason for hiding this comment

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

This change seems fine. Didn't look at the rest of the PR.


// Rename the file and the file's extension from .tmp to .gz to prevent issues with 'parsing' the file
toRead = new File(tempFile.getParentFile(), "unparseable.gz");
tempFile.renameTo(toRead);

Check notice

Code scanning / CodeQL

Ignored error status of call

Method setUp3 ignores exceptional return value of File.renameTo.

import java.util.Objects;

public class ColumnWithDirection
Copy link
Member

Choose a reason for hiding this comment

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

sort of sad to have another one of these (ScanQuery.OrderBy, OrderByColumnSpec of the group by query). It would be nice to standardize these someday...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I started using OrderByColumnSpec, it had a comparator on it that I was ignoring and it didn't have a good way to get at the comparator with the direction for me, so I gave up on it.

I wasn't aware of ScanQuery.OrderBy, that one looks closer to what I need and could maybe be adjusted to have the comparator multiplier on it. I'm not quite sure what NONE means for an ordering though...

I agree that we should not have so many, can probably look to converge what I have here with ScanQuery.OrderBy.

import java.util.LinkedHashMap;
import java.util.Map;

public class RearrangedRowsAndColumns implements RowsAndColumns
Copy link
Member

Choose a reason for hiding this comment

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

why "rearranged" instead of "sorted"? I don't really care, just curious 😅

also javadocs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because there's no guarantee that the re-arrangement is actually a sort.

Comment on lines +67 to +68
* Makes the NaiveSorter that will actually do the sort. This method uses {@code List<OrderByColumnSpec>} to avoid
* littering the code with extra objects for the same thing. {@code OrderByColumnSpec} is only used to identify
Copy link
Member

Choose a reason for hiding this comment

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

ah, I see that maybe you were originally using one of the other "order by" things, specifically the group by version? I guess the 'none' probably makes the scan query order by inappropriate too?

anyway, javadocs are stale

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the callout.

import java.util.LinkedHashMap;
import java.util.Map;

public class ConcatRowsAndColumns implements RowsAndColumns
Copy link
Member

Choose a reason for hiding this comment

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

nit: javadocs

@cheddar cheddar merged commit f1821a7 into apache:master Jan 6, 2023
@imply-cheddar imply-cheddar deleted the sort-op branch January 6, 2023 08:27
@clintropolis clintropolis added this to the 26.0 milestone Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants