diff --git a/presto-hive/src/main/java/com/facebook/presto/hive/util/MergingPageIterator.java b/presto-hive/src/main/java/com/facebook/presto/hive/util/MergingPageIterator.java index 103eb67029cd..bc04d077b6ca 100644 --- a/presto-hive/src/main/java/com/facebook/presto/hive/util/MergingPageIterator.java +++ b/presto-hive/src/main/java/com/facebook/presto/hive/util/MergingPageIterator.java @@ -13,11 +13,13 @@ */ package com.facebook.presto.hive.util; +import com.facebook.presto.common.NotSupportedException; import com.facebook.presto.common.Page; import com.facebook.presto.common.PageBuilder; import com.facebook.presto.common.block.Block; import com.facebook.presto.common.block.SortOrder; import com.facebook.presto.common.type.Type; +import com.facebook.presto.spi.PrestoException; import com.google.common.collect.AbstractIterator; import com.google.common.collect.ImmutableList; @@ -26,6 +28,7 @@ import java.util.List; import static com.facebook.presto.hive.util.SortBuffer.appendPositionTo; +import static com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.Iterators.concat; import static com.google.common.collect.Iterators.mergeSorted; @@ -131,7 +134,14 @@ public int compareTo(PagePosition other) Block block = page.getBlock(channel); Block otherBlock = other.page.getBlock(channel); - int result = order.compareBlockValue(type, block, position, otherBlock, other.position); + int result; + try { + result = order.compareBlockValue(type, block, position, otherBlock, other.position); + } + catch (NotSupportedException e) { + throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e); + } + if (result != 0) { return result; } diff --git a/presto-main/src/main/java/com/facebook/presto/operator/RowComparator.java b/presto-main/src/main/java/com/facebook/presto/operator/RowComparator.java index 2d552f7072d1..8a28772fb97a 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/RowComparator.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/RowComparator.java @@ -13,15 +13,18 @@ */ package com.facebook.presto.operator; +import com.facebook.presto.common.NotSupportedException; import com.facebook.presto.common.Page; import com.facebook.presto.common.block.Block; import com.facebook.presto.common.block.SortOrder; import com.facebook.presto.common.type.Type; +import com.facebook.presto.spi.PrestoException; import com.google.common.collect.ImmutableList; import java.util.Comparator; import java.util.List; +import static com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; @@ -52,7 +55,14 @@ public int compare(Page leftRow, Page rightRow) Block left = leftRow.getBlock(channel); Block right = rightRow.getBlock(channel); - int comparison = sortOrder.compareBlockValue(type, left, 0, right, 0); + int comparison; + try { + comparison = sortOrder.compareBlockValue(type, left, 0, right, 0); + } + catch (NotSupportedException e) { + throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e); + } + if (comparison != 0) { return comparison; } diff --git a/presto-main/src/main/java/com/facebook/presto/operator/SimplePageWithPositionComparator.java b/presto-main/src/main/java/com/facebook/presto/operator/SimplePageWithPositionComparator.java index e0bbbace8e55..8c23be0b66a9 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/SimplePageWithPositionComparator.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/SimplePageWithPositionComparator.java @@ -13,14 +13,17 @@ */ package com.facebook.presto.operator; +import com.facebook.presto.common.NotSupportedException; import com.facebook.presto.common.Page; import com.facebook.presto.common.block.Block; import com.facebook.presto.common.block.SortOrder; import com.facebook.presto.common.type.Type; +import com.facebook.presto.spi.PrestoException; import com.google.common.collect.ImmutableList; import java.util.List; +import static com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED; import static java.util.Objects.requireNonNull; public class SimplePageWithPositionComparator @@ -46,7 +49,15 @@ public int compareTo(Page left, int leftPosition, Page right, int rightPosition) Block rightBlock = right.getBlock(sortChannel); SortOrder sortOrder = sortOrders.get(i); - int compare = sortOrder.compareBlockValue(types.get(sortChannel), leftBlock, leftPosition, rightBlock, rightPosition); + + int compare; + try { + compare = sortOrder.compareBlockValue(types.get(sortChannel), leftBlock, leftPosition, rightBlock, rightPosition); + } + catch (NotSupportedException e) { + throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e); + } + if (compare != 0) { return compare; } diff --git a/presto-main/src/main/java/com/facebook/presto/operator/SimplePagesHashStrategy.java b/presto-main/src/main/java/com/facebook/presto/operator/SimplePagesHashStrategy.java index b0e8f01ce8c7..ea28bb3bf89f 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/SimplePagesHashStrategy.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/SimplePagesHashStrategy.java @@ -13,11 +13,13 @@ */ package com.facebook.presto.operator; +import com.facebook.presto.common.NotSupportedException; import com.facebook.presto.common.Page; import com.facebook.presto.common.PageBuilder; import com.facebook.presto.common.block.Block; import com.facebook.presto.common.type.Type; import com.facebook.presto.metadata.FunctionManager; +import com.facebook.presto.spi.PrestoException; import com.facebook.presto.type.TypeUtils; import com.google.common.collect.ImmutableList; import org.openjdk.jol.info.ClassLayout; @@ -29,6 +31,7 @@ import static com.facebook.presto.common.function.OperatorType.IS_DISTINCT_FROM; import static com.facebook.presto.common.type.BigintType.BIGINT; +import static com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED; import static com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes; import static com.facebook.presto.util.Failures.internalError; import static com.google.common.base.Preconditions.checkArgument; @@ -173,8 +176,13 @@ public boolean positionEqualsRowIgnoreNulls(int leftBlockIndex, int leftPosition Type type = types.get(hashChannel); Block leftBlock = channels.get(hashChannel).get(leftBlockIndex); Block rightBlock = rightPage.getBlock(i); - if (!type.equalTo(leftBlock, leftPosition, rightBlock, rightPosition)) { - return false; + try { + if (!type.equalTo(leftBlock, leftPosition, rightBlock, rightPosition)) { + return false; + } + } + catch (NotSupportedException e) { + throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e); } } return true; @@ -241,8 +249,13 @@ public boolean positionEqualsPositionIgnoreNulls(int leftBlockIndex, int leftPos List channel = channels.get(hashChannel); Block leftBlock = channel.get(leftBlockIndex); Block rightBlock = channel.get(rightBlockIndex); - if (!type.equalTo(leftBlock, leftPosition, rightBlock, rightPosition)) { - return false; + try { + if (!type.equalTo(leftBlock, leftPosition, rightBlock, rightPosition)) { + return false; + } + } + catch (NotSupportedException e) { + throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e); } } return true; diff --git a/presto-main/src/main/java/com/facebook/presto/operator/SimplePagesIndexComparator.java b/presto-main/src/main/java/com/facebook/presto/operator/SimplePagesIndexComparator.java index df724f85e8a4..1f33a3321507 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/SimplePagesIndexComparator.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/SimplePagesIndexComparator.java @@ -13,15 +13,18 @@ */ package com.facebook.presto.operator; +import com.facebook.presto.common.NotSupportedException; import com.facebook.presto.common.block.Block; import com.facebook.presto.common.block.SortOrder; import com.facebook.presto.common.type.Type; +import com.facebook.presto.spi.PrestoException; import com.google.common.collect.ImmutableList; import java.util.List; import static com.facebook.presto.operator.SyntheticAddress.decodePosition; import static com.facebook.presto.operator.SyntheticAddress.decodeSliceIndex; +import static com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED; import static java.util.Objects.requireNonNull; public class SimplePagesIndexComparator @@ -55,7 +58,14 @@ public int compareTo(PagesIndex pagesIndex, int leftPosition, int rightPosition) Block rightBlock = pagesIndex.getChannel(sortChannel).get(rightBlockIndex); SortOrder sortOrder = sortOrders.get(i); - int compare = sortOrder.compareBlockValue(sortTypes.get(i), leftBlock, leftBlockPosition, rightBlock, rightBlockPosition); + int compare; + try { + compare = sortOrder.compareBlockValue(sortTypes.get(i), leftBlock, leftBlockPosition, rightBlock, rightBlockPosition); + } + catch (NotSupportedException e) { + throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e); + } + if (compare != 0) { return compare; } diff --git a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/histogram/GroupedTypedHistogram.java b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/histogram/GroupedTypedHistogram.java index a573ebe490a7..5e20758e325b 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/histogram/GroupedTypedHistogram.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/histogram/GroupedTypedHistogram.java @@ -15,6 +15,7 @@ import com.facebook.presto.array.IntBigArray; import com.facebook.presto.array.LongBigArray; +import com.facebook.presto.common.NotSupportedException; import com.facebook.presto.common.block.Block; import com.facebook.presto.common.block.BlockBuilder; import com.facebook.presto.common.type.Type; @@ -27,6 +28,7 @@ import static com.facebook.presto.operator.aggregation.histogram.HashUtil.nextBucketId; import static com.facebook.presto.operator.aggregation.histogram.HashUtil.nextProbeLinear; import static com.facebook.presto.spi.StandardErrorCode.GENERIC_INSUFFICIENT_RESOURCES; +import static com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static it.unimi.dsi.fastutil.HashCommon.arraySize; @@ -500,7 +502,12 @@ private boolean groupAndValueMatches(long groupId, Block block, int position, in { long existingGroupId = groupIds.get(nodePointer); - return existingGroupId == groupId && type.equalTo(block, position, values, valuePosition); + try { + return existingGroupId == groupId && type.equalTo(block, position, values, valuePosition); + } + catch (NotSupportedException e) { + throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e); + } } private ValueNode createValueNode(int nodePointer) diff --git a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/histogram/SingleTypedHistogram.java b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/histogram/SingleTypedHistogram.java index 5dcdfc052696..55901f995a9c 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/histogram/SingleTypedHistogram.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/histogram/SingleTypedHistogram.java @@ -15,6 +15,7 @@ import com.facebook.presto.array.IntBigArray; import com.facebook.presto.array.LongBigArray; +import com.facebook.presto.common.NotSupportedException; import com.facebook.presto.common.block.Block; import com.facebook.presto.common.block.BlockBuilder; import com.facebook.presto.common.type.Type; @@ -24,6 +25,7 @@ import static com.facebook.presto.common.type.BigintType.BIGINT; import static com.facebook.presto.spi.StandardErrorCode.GENERIC_INSUFFICIENT_RESOURCES; +import static com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED; import static com.google.common.base.Preconditions.checkArgument; import static it.unimi.dsi.fastutil.HashCommon.arraySize; import static it.unimi.dsi.fastutil.HashCommon.murmurHash3; @@ -133,10 +135,16 @@ public void add(int position, Block block, long count) break; } - if (type.equalTo(block, position, values, hashPositions.get(hashPosition))) { - counts.add(hashPositions.get(hashPosition), count); - return; + try { + if (type.equalTo(block, position, values, hashPositions.get(hashPosition))) { + counts.add(hashPositions.get(hashPosition), count); + return; + } } + catch (NotSupportedException e) { + throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e); + } + // increment position and mask to handle wrap around hashPosition = (hashPosition + 1) & mask; } diff --git a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/histogram/ValueStore.java b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/histogram/ValueStore.java index 4b89ba6f201c..f6c282fe3422 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/histogram/ValueStore.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/histogram/ValueStore.java @@ -15,6 +15,7 @@ import com.facebook.presto.array.IntBigArray; import com.facebook.presto.array.LongBigArray; +import com.facebook.presto.common.NotSupportedException; import com.facebook.presto.common.block.Block; import com.facebook.presto.common.block.BlockBuilder; import com.facebook.presto.common.type.Type; @@ -27,6 +28,7 @@ import static com.facebook.presto.operator.aggregation.histogram.HashUtil.nextBucketId; import static com.facebook.presto.operator.aggregation.histogram.HashUtil.nextProbeLinear; import static com.facebook.presto.spi.StandardErrorCode.GENERIC_INSUFFICIENT_RESOURCES; +import static com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED; import static com.google.common.base.Preconditions.checkState; /** @@ -84,22 +86,27 @@ public int addAndGetPosition(Type type, Block block, int position, long valueHas checkState(probeCount < bucketCount, "could not find match for value nor empty slot in %s buckets", bucketCount); valuePointer = buckets.get(bucketId); - if (valuePointer == EMPTY_BUCKET) { - valuePointer = values.getPositionCount(); - valueHashes.set(valuePointer, (int) valueHash); - type.appendTo(block, position, values); - buckets.set(bucketId, valuePointer); - - return valuePointer; - } - else if (type.equalTo(block, position, values, valuePointer)) { - // value at position - return valuePointer; + try { + if (valuePointer == EMPTY_BUCKET) { + valuePointer = values.getPositionCount(); + valueHashes.set(valuePointer, (int) valueHash); + type.appendTo(block, position, values); + buckets.set(bucketId, valuePointer); + + return valuePointer; + } + else if (type.equalTo(block, position, values, valuePointer)) { + // value at position + return valuePointer; + } + else { + int probe = nextProbe(probeCount); + bucketId = nextBucketId(originalBucketId, mask, probe); + probeCount++; + } } - else { - int probe = nextProbe(probeCount); - bucketId = nextBucketId(originalBucketId, mask, probe); - probeCount++; + catch (NotSupportedException e) { + throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e); } } } diff --git a/presto-main/src/main/java/com/facebook/presto/operator/index/TuplePageFilter.java b/presto-main/src/main/java/com/facebook/presto/operator/index/TuplePageFilter.java index bc32edf35490..85e6d416b7ba 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/index/TuplePageFilter.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/index/TuplePageFilter.java @@ -13,6 +13,7 @@ */ package com.facebook.presto.operator.index; +import com.facebook.presto.common.NotSupportedException; import com.facebook.presto.common.Page; import com.facebook.presto.common.block.Block; import com.facebook.presto.common.function.SqlFunctionProperties; @@ -20,10 +21,12 @@ import com.facebook.presto.operator.project.InputChannels; import com.facebook.presto.operator.project.PageFilter; import com.facebook.presto.operator.project.SelectedPositions; +import com.facebook.presto.spi.PrestoException; import com.google.common.collect.ImmutableList; import java.util.List; +import static com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; @@ -85,8 +88,13 @@ private boolean matches(Page page, int position) Type type = types.get(channel); Block outputBlock = page.getBlock(channel); Block singleTupleBlock = tuplePage.getBlock(channel); - if (!type.equalTo(singleTupleBlock, 0, outputBlock, position)) { - return false; + try { + if (!type.equalTo(singleTupleBlock, 0, outputBlock, position)) { + return false; + } + } + catch (NotSupportedException e) { + throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e); } } return true; diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArraysOverlapFunction.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArraysOverlapFunction.java index 48e205384aad..8ba84b1e3707 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArraysOverlapFunction.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArraysOverlapFunction.java @@ -13,10 +13,12 @@ */ package com.facebook.presto.operator.scalar; +import com.facebook.presto.common.NotSupportedException; import com.facebook.presto.common.block.Block; import com.facebook.presto.common.type.AbstractType; import com.facebook.presto.common.type.StandardTypes; import com.facebook.presto.common.type.Type; +import com.facebook.presto.spi.PrestoException; import com.facebook.presto.spi.function.Description; import com.facebook.presto.spi.function.OperatorDependency; import com.facebook.presto.spi.function.ScalarFunction; @@ -33,6 +35,7 @@ import static com.facebook.presto.common.function.OperatorType.LESS_THAN; import static com.facebook.presto.common.type.BigintType.BIGINT; import static com.facebook.presto.common.type.IntegerType.INTEGER; +import static com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED; @ScalarFunction("arrays_overlap") @Description("Returns true if arrays have common elements") @@ -63,7 +66,12 @@ public int compare(int left, int right) if (block.isNull(right)) { return -1; } - return type.compareTo(block, left, block, right); + try { + return type.compareTo(block, left, block, right); + } + catch (NotSupportedException e) { + throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e); + } } }; } @@ -128,7 +136,15 @@ public Boolean arraysOverlap( // Nulls are in the end of the array. Non-null elements do not overlap. return null; } - int compareValue = type.compareTo(leftArray, leftPositions[leftCurrentPosition], rightArray, rightPositions[rightCurrentPosition]); + + int compareValue; + try { + compareValue = type.compareTo(leftArray, leftPositions[leftCurrentPosition], rightArray, rightPositions[rightCurrentPosition]); + } + catch (NotSupportedException e) { + throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e); + } + if (compareValue > 0) { rightCurrentPosition++; } diff --git a/presto-main/src/main/java/com/facebook/presto/type/TypeUtils.java b/presto-main/src/main/java/com/facebook/presto/type/TypeUtils.java index 57a821ab624e..57e899d3c134 100644 --- a/presto-main/src/main/java/com/facebook/presto/type/TypeUtils.java +++ b/presto-main/src/main/java/com/facebook/presto/type/TypeUtils.java @@ -13,6 +13,7 @@ */ package com.facebook.presto.type; +import com.facebook.presto.common.NotSupportedException; import com.facebook.presto.common.Page; import com.facebook.presto.common.block.Block; import com.facebook.presto.common.block.BlockBuilder; @@ -99,7 +100,13 @@ public static boolean positionEqualsPosition(Type type, Block leftBlock, int lef if (leftIsNull || rightIsNull) { return leftIsNull && rightIsNull; } - return type.equalTo(leftBlock, leftPosition, rightBlock, rightPosition); + + try { + return type.equalTo(leftBlock, leftPosition, rightBlock, rightPosition); + } + catch (NotSupportedException e) { + throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e); + } } public static Type resolveType(TypeSignature typeName, TypeManager typeManager) diff --git a/presto-main/src/test/java/com/facebook/presto/operator/scalar/AbstractTestFunctions.java b/presto-main/src/test/java/com/facebook/presto/operator/scalar/AbstractTestFunctions.java index 514e4389d5b8..5e1d760af84f 100644 --- a/presto-main/src/test/java/com/facebook/presto/operator/scalar/AbstractTestFunctions.java +++ b/presto-main/src/test/java/com/facebook/presto/operator/scalar/AbstractTestFunctions.java @@ -14,7 +14,6 @@ package com.facebook.presto.operator.scalar; import com.facebook.presto.Session; -import com.facebook.presto.common.NotSupportedException; import com.facebook.presto.common.function.OperatorType; import com.facebook.presto.common.type.DecimalParseResult; import com.facebook.presto.common.type.Decimals; @@ -167,11 +166,9 @@ protected void assertNotSupported(String projection, String message) functionAssertions.executeProjectionWithFullEngine(projection); fail("expected exception"); } - catch (PrestoException | NotSupportedException e) { + catch (PrestoException e) { try { - if (e instanceof PrestoException) { - assertEquals(((PrestoException) e).getErrorCode(), NOT_SUPPORTED.toErrorCode()); - } + assertEquals(e.getErrorCode(), NOT_SUPPORTED.toErrorCode()); assertEquals(e.getMessage(), message); } catch (Throwable failure) { diff --git a/presto-raptor/src/main/java/com/facebook/presto/raptor/storage/organization/ShardCompactor.java b/presto-raptor/src/main/java/com/facebook/presto/raptor/storage/organization/ShardCompactor.java index 7fea1985a099..7b4cb5776f4b 100644 --- a/presto-raptor/src/main/java/com/facebook/presto/raptor/storage/organization/ShardCompactor.java +++ b/presto-raptor/src/main/java/com/facebook/presto/raptor/storage/organization/ShardCompactor.java @@ -15,6 +15,7 @@ import com.facebook.airlift.stats.CounterStat; import com.facebook.airlift.stats.DistributionStat; +import com.facebook.presto.common.NotSupportedException; import com.facebook.presto.common.Page; import com.facebook.presto.common.block.Block; import com.facebook.presto.common.block.SortOrder; @@ -27,6 +28,7 @@ import com.facebook.presto.raptor.storage.StorageManager; import com.facebook.presto.raptor.storage.StoragePageSink; import com.facebook.presto.spi.ConnectorPageSource; +import com.facebook.presto.spi.PrestoException; import com.google.common.collect.ImmutableList; import org.weakref.jmx.Managed; import org.weakref.jmx.Nested; @@ -47,6 +49,7 @@ import static com.facebook.airlift.concurrent.MoreFutures.getFutureValue; import static com.facebook.presto.hive.HiveFileContext.DEFAULT_HIVE_FILE_CONTEXT; +import static com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED; import static com.google.common.base.Preconditions.checkArgument; import static io.airlift.units.Duration.nanosSince; import static java.util.Objects.requireNonNull; @@ -295,7 +298,14 @@ public int compareTo(SortedPageSource other) Block rightBlock = other.currentPage.getBlock(channel); int rightBlockPosition = other.currentPosition; - int compare = sortOrders.get(i).compareBlockValue(type, leftBlock, leftBlockPosition, rightBlock, rightBlockPosition); + int compare; + try { + compare = sortOrders.get(i).compareBlockValue(type, leftBlock, leftBlockPosition, rightBlock, rightBlockPosition); + } + catch (NotSupportedException e) { + throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e); + } + if (compare != 0) { return compare; }