-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Support sorting on complex columns in MSQ #16322
Merged
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
1c46cb4
init
LakshSingla 486d29a
working, almost
LakshSingla 260206b
stuff working
LakshSingla b93b53e
Merge branch 'master' into msq-complex-sorting
LakshSingla ac8ba6b
tests, checkstyle
LakshSingla abbf49b
tests
LakshSingla b7ea7b8
more changes
LakshSingla f3caaf6
test comments
LakshSingla c852c35
changes
LakshSingla d2dd402
tests
LakshSingla a0d29d4
tests
LakshSingla ae87dab
tests
LakshSingla 4b86b31
better comment
LakshSingla 1ec5796
tests fix
LakshSingla b68948e
tests fix
LakshSingla 08633f0
tests fix, test framework fix, comments
LakshSingla 8d49678
Trigger Build
LakshSingla 76fd60e
Merge branch 'master' into msq-complex-sorting
LakshSingla cd29bec
merge fix
LakshSingla 690c5cf
convert list to array
LakshSingla d1d28e1
add back old tests
LakshSingla 7f27724
preserve old tests, add new tests for complexcol + byte comparable col
LakshSingla ae77984
tests
LakshSingla 2af2977
add benchmarks for nested data
LakshSingla b1c61cb
final set, have separate methods
LakshSingla eaa0593
some more final changes
LakshSingla 2e23831
Merge branch 'master' into msq-complex-sorting
LakshSingla 7356aa2
review comments
LakshSingla 806b1ec
Update FrameWriterUtils.java
LakshSingla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
changes
- Loading branch information
commit c852c35555d552a3fef2896637bf693af7734f79
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
128 changes: 128 additions & 0 deletions
128
processing/src/test/java/org/apache/druid/frame/key/RowKeyComparisonRunLengthsTest.java
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,128 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
package org.apache.druid.frame.key; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import org.apache.druid.error.DruidException; | ||
import org.apache.druid.segment.column.ColumnType; | ||
import org.apache.druid.segment.column.RowSignature; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class RowKeyComparisonRunLengthsTest | ||
{ | ||
|
||
@Test | ||
public void testRunLengthsWithNoKeyColumns() | ||
{ | ||
final List<KeyColumn> keyColumns = Collections.emptyList(); | ||
final RowSignature signature = RowSignature.empty(); | ||
final RowKeyComparisonRunLengths runLengths = RowKeyComparisonRunLengths.create(keyColumns, signature); | ||
Assert.assertEquals(0, runLengths.getRunLengthEntries().size()); | ||
} | ||
|
||
@Test | ||
public void testRunLengthsWithInvalidOrder() | ||
{ | ||
final List<KeyColumn> keyColumns = Collections.singletonList(new KeyColumn("a", KeyOrder.NONE)); | ||
final RowSignature signature = RowSignature.builder() | ||
.add("a", ColumnType.LONG) | ||
.build(); | ||
Assert.assertThrows(DruidException.class, () -> RowKeyComparisonRunLengths.create(keyColumns, signature)); | ||
} | ||
|
||
@Test | ||
public void testRunLengthsWithIncompleteRowSignature() | ||
{ | ||
final List<KeyColumn> keyColumns = Collections.singletonList(new KeyColumn("a", KeyOrder.NONE)); | ||
final RowSignature signature = RowSignature.empty(); | ||
Assert.assertThrows(DruidException.class, () -> RowKeyComparisonRunLengths.create(keyColumns, signature)); | ||
} | ||
|
||
@Test | ||
public void testRunLengthsWithEmptyType() | ||
{ | ||
final List<KeyColumn> keyColumns = Collections.singletonList(new KeyColumn("a", KeyOrder.NONE)); | ||
final RowSignature signature1 = RowSignature.builder() | ||
.add("a", null) | ||
.build(); | ||
Assert.assertThrows(DruidException.class, () -> RowKeyComparisonRunLengths.create(keyColumns, signature1)); | ||
|
||
final RowSignature signature2 = RowSignature.builder() | ||
.add("a", ColumnType.UNKNOWN_COMPLEX) | ||
.build(); | ||
Assert.assertThrows(DruidException.class, () -> RowKeyComparisonRunLengths.create(keyColumns, signature2)); | ||
} | ||
|
||
@Test | ||
public void testRunLengthsWithByteComparableTypes() | ||
{ | ||
final List<KeyColumn> keyColumns = Collections.singletonList(new KeyColumn("a", KeyOrder.ASCENDING)); | ||
final List<ColumnType> byteComparableTypes = ImmutableList.of( | ||
ColumnType.LONG, | ||
ColumnType.FLOAT, | ||
ColumnType.DOUBLE, | ||
ColumnType.STRING, | ||
ColumnType.LONG_ARRAY, | ||
ColumnType.FLOAT_ARRAY, | ||
ColumnType.DOUBLE_ARRAY, | ||
ColumnType.STRING_ARRAY | ||
); | ||
|
||
for (final ColumnType columnType : byteComparableTypes) { | ||
final RowSignature signature = RowSignature.builder() | ||
.add("a", columnType) | ||
.build(); | ||
final RowKeyComparisonRunLengths runLengths = RowKeyComparisonRunLengths.create(keyColumns, signature); | ||
Assert.assertEquals(1, runLengths.getRunLengthEntries().size()); | ||
Assert.assertTrue(runLengths.getRunLengthEntries().get(0).isByteComparable()); | ||
Assert.assertEquals(1, runLengths.getRunLengthEntries().get(0).getRunLength()); | ||
Assert.assertEquals(KeyOrder.ASCENDING, runLengths.getRunLengthEntries().get(0).getOrder()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRunLengthsWithNonByteComparableTypes() | ||
{ | ||
final List<KeyColumn> keyColumns = Collections.singletonList(new KeyColumn("a", KeyOrder.ASCENDING)); | ||
// Any known complex type | ||
final List<ColumnType> byteComparableTypes = ImmutableList.of(ColumnType.NESTED_DATA); | ||
|
||
for (final ColumnType columnType : byteComparableTypes) { | ||
final RowSignature signature = RowSignature.builder() | ||
.add("a", columnType) | ||
.build(); | ||
final RowKeyComparisonRunLengths runLengths = RowKeyComparisonRunLengths.create(keyColumns, signature); | ||
Assert.assertEquals(1, runLengths.getRunLengthEntries().size()); | ||
Assert.assertFalse(runLengths.getRunLengthEntries().get(0).isByteComparable()); | ||
Assert.assertEquals(1, runLengths.getRunLengthEntries().get(0).getRunLength()); | ||
Assert.assertEquals(KeyOrder.ASCENDING, runLengths.getRunLengthEntries().get(0).getOrder()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRunLengthsWithMultipleColumns() | ||
{ | ||
// | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a situation like this, I like to have one test that does a whole space of things. Here I suggest a test case that checks all possible length-3 keys where we vary each key element's type between string and complex, and direction between asc and desc. So that's 4 possibilities for each key element (string asc, string desc, complex asc, complex desc) and therefore 64 keys we're testing. It will run fast since it's only 64 cases, and it gets good coverage of different possibilities for runs and orderings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was considering having a parameterized test, however, how do I add the expected results for each test case generically, without repeating the logic in
RowKeyComparisonRunLengths
.For example, if the input test case is "complex ASC, string DESC, string DESC"; how can I get the expected value of the result, without repeating what I have written in
RowKeyComparisonRunLength
? One way would be iterating the results of all 64 combinations, which can be done, but I wanted to confirm if that's what you referred to in the comment.The test case would read something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of having all 64 test cases enumerated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the test cases - the tests are generated programmatically in the loop (mapping each index to the corresponding permutation of the key column), and the expectations are enumerated corresponding to each test case