From 4543777f35c936c0e5fabf30ab0cb57a953550ac Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Tue, 24 Sep 2024 15:03:44 -0400 Subject: [PATCH] Bug hunting --- .../presto/server/protocol/Query.java | 15 +++++++++++ .../presto/server/protocol/RowIterable.java | 25 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/presto-main/src/main/java/com/facebook/presto/server/protocol/Query.java b/presto-main/src/main/java/com/facebook/presto/server/protocol/Query.java index c944f0cd468b..173497579c6e 100644 --- a/presto-main/src/main/java/com/facebook/presto/server/protocol/Query.java +++ b/presto-main/src/main/java/com/facebook/presto/server/protocol/Query.java @@ -22,6 +22,7 @@ import com.facebook.presto.client.StatementStats; import com.facebook.presto.common.ErrorCode; import com.facebook.presto.common.Page; +import com.facebook.presto.common.block.Block; import com.facebook.presto.common.block.BlockEncodingSerde; import com.facebook.presto.common.transaction.TransactionId; import com.facebook.presto.common.type.BooleanType; @@ -445,6 +446,19 @@ else if (queryManager.getQueryRetryCount(queryId) == 1 && retryQueryWithHistoryB queryResults.getUpdateCount()); } + private static void validateBlockSizesInPage(Page page) + { + // debugging + for (int channel = 0; channel < page.getChannelCount(); channel++) { + Block block = page.getBlock(channel); + if (block.getPositionCount() != page.getPositionCount()) { + throw new IllegalArgumentException( + format("Wrongly sized block: channel: %d block poition count: %d page position count: %d %s", + channel, block.getPositionCount(), page.getPositionCount(), block.getClass().getCanonicalName())); + } + } + } + private synchronized QueryResults getNextResult(long token, UriInfo uriInfo, String scheme, DataSize targetResultSize, boolean binaryResults) { // check if the result for the token have already been created @@ -502,6 +516,7 @@ private synchronized QueryResults getNextResult(long token, UriInfo uriInfo, Str } Page page = serde.deserialize(serializedPage); + validateBlockSizesInPage(page); bytes += page.getLogicalSizeInBytes(); rows += page.getPositionCount(); pages.add(new RowIterable(session.toConnectorSession(), types, page)); diff --git a/presto-main/src/main/java/com/facebook/presto/server/protocol/RowIterable.java b/presto-main/src/main/java/com/facebook/presto/server/protocol/RowIterable.java index 9d1de7a65eef..e4dd04eda36f 100644 --- a/presto-main/src/main/java/com/facebook/presto/server/protocol/RowIterable.java +++ b/presto-main/src/main/java/com/facebook/presto/server/protocol/RowIterable.java @@ -25,6 +25,7 @@ import java.util.Iterator; import java.util.List; +import static java.lang.String.format; import static java.util.Objects.requireNonNull; class RowIterable @@ -39,6 +40,8 @@ class RowIterable this.session = session; this.types = ImmutableList.copyOf(requireNonNull(types, "types is null")); this.page = requireNonNull(page, "page is null"); + + validateBlockSizesInPage(page); } @Override @@ -60,6 +63,8 @@ private RowIterator(ConnectorSession session, List types, Page page) this.session = session; this.types = types; this.page = page; + + validateBlockSizesInPage(page); } @Override @@ -74,9 +79,29 @@ protected List computeNext() for (int channel = 0; channel < page.getChannelCount(); channel++) { Type type = types.get(channel); Block block = page.getBlock(channel); + // Caused by: java.lang.IllegalArgumentException: Invalid position 1 in block with 1 positions + // why does block onlly have one position when we're asking for at least 12? + // It's not an off by one error. It's that there's only one row ID in the block. + // That's why it works with LIMIT 1 and not LIMIT 2 + // maybe an issue with compressed dictionary blocks or something like that? + // only some tables/rows use dictionary blocks + // and exception changes from LIMIT 2 to 3 values.add(type.getObjectValue(session.getSqlFunctionProperties(), block, position)); } return Collections.unmodifiableList(values); } } + + private static void validateBlockSizesInPage(Page page) + { + // debugging + for (int channel = 0; channel < page.getChannelCount(); channel++) { + Block block = page.getBlock(channel); + if (block.getPositionCount() != page.getPositionCount()) { + throw new IllegalArgumentException( + format("Wrongly sized block: channel: %d block poition count: %d page position count: %d %s", + channel, block.getPositionCount(), page.getPositionCount(), block.getClass().getCanonicalName())); + } + } + } }