Skip to content

Prevent window operator from failing when it's aborted #18061

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

Merged
merged 1 commit into from
Jun 27, 2023
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 @@ -219,7 +219,10 @@ public Optional<IndexInfo> build()
}
double avgSize = partitions.stream().mapToLong(Integer::longValue).average().getAsDouble();
double squaredDifferences = partitions.stream().mapToDouble(size -> Math.pow(size - avgSize, 2)).sum();
checkState(partitions.stream().mapToLong(Integer::longValue).sum() == rowsNumber, "Total number of rows in index does not match number of rows in partitions within that index");
if (partitions.stream().mapToLong(Integer::longValue).sum() != rowsNumber) {
// when operator is cancelled, then rows in index might not match row count from processed partitions
return Optional.empty();
}

return Optional.of(new IndexInfo(rowsNumber, sizeInBytes, squaredDifferences, partitions.size()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.common.primitives.Ints;
import io.airlift.units.DataSize;
import io.trino.ExceededMemoryLimitException;
import io.trino.RowPagesBuilder;
import io.trino.operator.WindowOperator.WindowOperatorFactory;
import io.trino.operator.window.FirstValueFunction;
import io.trino.operator.window.FrameInfo;
Expand Down Expand Up @@ -71,6 +72,7 @@
import static java.util.concurrent.Executors.newCachedThreadPool;
import static java.util.concurrent.Executors.newScheduledThreadPool;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

@Test(singleThreaded = true)
Expand Down Expand Up @@ -432,6 +434,41 @@ public void testFirstValuePartition(boolean spillEnabled, boolean revokeMemoryWh
assertOperatorEquals(operatorFactory, driverContext, input, expected, revokeMemoryWhenAddingPages);
}

@Test
public void testClose()
throws Exception
{
RowPagesBuilder pageBuilder = rowPagesBuilder(VARCHAR, BIGINT);
for (int i = 0; i < 500_000; ++i) {
pageBuilder.row("a", 0L);
}
for (int i = 0; i < 500_000; ++i) {
pageBuilder.row("b", 0L);
}
List<Page> input = pageBuilder.build();

WindowOperatorFactory operatorFactory = createFactoryUnbounded(
ImmutableList.of(VARCHAR, BIGINT),
Ints.asList(0, 1),
ROW_NUMBER,
Ints.asList(0),
Ints.asList(1),
ImmutableList.copyOf(new SortOrder[] {SortOrder.ASC_NULLS_LAST}),
false);

DriverContext driverContext = createDriverContext(1000);
Operator operator = operatorFactory.createOperator(driverContext);
operatorFactory.noMoreOperators();
assertFalse(operator.isFinished());
assertTrue(operator.needsInput());
operator.addInput(input.get(0));
operator.finish();
operator.getOutput();

// this should not fail
operator.close();
}

@Test(dataProvider = "spillEnabled")
public void testLastValuePartition(boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimit)
{
Expand Down