Skip to content

Commit

Permalink
Handle NotSupportedException from RowType, MapType, ArrayType
Browse files Browse the repository at this point in the history
checkElementNotNull() throws NotSupportedException for the above
mentioned types. This is mainly invoked from equalTo() and
compareTo() functions of these 3 types. So this commit has the
code changes to add try-cath-throw around all the callers of
compareTo() and equalTo() .
  • Loading branch information
Nikhil Collooru authored and highker committed May 6, 2020
1 parent e7a2cb0 commit 9057aea
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -241,8 +249,13 @@ public boolean positionEqualsPositionIgnoreNulls(int leftBlockIndex, int leftPos
List<Block> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
*/
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;
import com.facebook.presto.common.type.Type;
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;

Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 9057aea

Please sign in to comment.