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

Fix ValidateLimitWithPresortedInput for multiple sorted inputs #8184

Merged
merged 1 commit into from
Jun 7, 2021
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 @@ -101,7 +101,7 @@ public Void visitLimit(LimitNode node, Void context)
.flatMap(property -> property.getColumns().stream())
.collect(toImmutableList());

if (sortedColumns.size() > node.getPreSortedInputs().size() ||
if (sortedColumns.size() < node.getPreSortedInputs().size() ||
!sortedColumns.subList(0, node.getPreSortedInputs().size()).equals(node.getPreSortedInputs())) {
throw new VerifyException(format("Expected Limit input to be sorted by: %s, but was %s", node.getPreSortedInputs(), sortedColumns));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ public void testValidateSuccessful()
p.symbol(COLUMN_NAME_A, VARCHAR), COLUMN_HANDLE_A,
p.symbol(COLUMN_NAME_B, VARCHAR), COLUMN_HANDLE_B,
p.symbol(COLUMN_NAME_C, VARCHAR), COLUMN_HANDLE_C))));

validatePlan(
p -> p.limit(
10,
ImmutableList.of(),
true,
ImmutableList.of(p.symbol(COLUMN_NAME_A, VARCHAR)),
p.tableScan(
MOCK_TABLE_HANDLE,
ImmutableList.of(p.symbol(COLUMN_NAME_A, VARCHAR), p.symbol(COLUMN_NAME_B, VARCHAR), p.symbol(COLUMN_NAME_C, VARCHAR)),
ImmutableMap.of(
p.symbol(COLUMN_NAME_A, VARCHAR), COLUMN_HANDLE_A,
p.symbol(COLUMN_NAME_B, VARCHAR), COLUMN_HANDLE_B,
p.symbol(COLUMN_NAME_C, VARCHAR), COLUMN_HANDLE_C))));
}

@Test(expectedExceptions = VerifyException.class, expectedExceptionsMessageRegExp = "Expected Limit input to be sorted by: \\[col_b], but was \\[col_a]")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,31 @@ public void testAnalyze()
assertQueryFails("ANALYZE orders WITH (foo = 'bar')", ".* does not support analyze property 'foo'.*");
}

@Test
public void testPreSortedInput()
{
// TPCH connector produces pre-sorted data for orders and lineitem tables
assertExplain(
"EXPLAIN SELECT * FROM orders ORDER BY orderkey ASC NULLS FIRST LIMIT 10",
"\\QLimitPartial[10, input pre-sorted by (orderkey)]");
assertExplain(
"EXPLAIN SELECT * FROM lineitem ORDER BY orderkey ASC NULLS FIRST LIMIT 10",
"\\QLimitPartial[10, input pre-sorted by (orderkey)]");
assertExplain(
"EXPLAIN SELECT * FROM lineitem ORDER BY orderkey ASC NULLS FIRST, linenumber ASC NULLS FIRST LIMIT 10",
"\\QLimitPartial[10, input pre-sorted by (orderkey, linenumber)]");
assertExplain(
"EXPLAIN SELECT * FROM lineitem ORDER BY orderkey ASC NULLS FIRST, linenumber LIMIT 10",
"\\QTopNPartial[10 by (orderkey ASC NULLS FIRST, linenumber ASC NULLS LAST)]");
assertExplain(
"EXPLAIN SELECT * FROM lineitem ORDER BY orderkey ASC LIMIT 10",
"\\QTopNPartial[10 by (orderkey ASC NULLS LAST)]");

assertQuery(
"SELECT * FROM lineitem WHERE orderkey IS NOT NULL ORDER BY orderkey ASC NULLS FIRST LIMIT 10",
"SELECT * FROM lineitem ORDER BY orderkey ASC LIMIT 10");
}

@Test
@Override
public void testShowTables()
Expand Down