-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Make map and array functions use IS DISTINCT semantics as appropriate #9841
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
losipiuk
merged 5 commits into
trinodb:master
from
jirassimok:fix-array-functions-distinctness
Apr 7, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d229c21
Make array_except use 'is distinct' semantics
jirassimok 6f95e19
Make array_union use 'is distinct' semantics
jirassimok 654a3a5
Make map functions use 'is distinct' semantics for key uniqueness
jirassimok 1be1311
Make multimap_agg compare keys with 'is distinct' semantics
jirassimok 8ae6fe0
Make MapToMapCast check for duplicate keys with 'is distinct' semantics
jirassimok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,8 +31,8 @@ | |
| import io.trino.spi.type.Type; | ||
| import io.trino.spi.type.TypeSignature; | ||
| import io.trino.type.BlockTypeOperators; | ||
| import io.trino.type.BlockTypeOperators.BlockPositionEqual; | ||
| import io.trino.type.BlockTypeOperators.BlockPositionHashCode; | ||
| import io.trino.type.BlockTypeOperators.BlockPositionIsDistinctFrom; | ||
|
|
||
| import java.lang.invoke.MethodHandle; | ||
| import java.lang.invoke.MethodHandles; | ||
|
|
@@ -41,7 +41,7 @@ | |
| import static com.google.common.base.Preconditions.checkState; | ||
| import static io.trino.metadata.Signature.castableToTypeParameter; | ||
| import static io.trino.metadata.Signature.typeVariable; | ||
| import static io.trino.operator.aggregation.TypedSet.createEqualityTypedSet; | ||
| import static io.trino.operator.aggregation.TypedSet.createDistinctTypedSet; | ||
| import static io.trino.spi.StandardErrorCode.INVALID_CAST_ARGUMENT; | ||
| import static io.trino.spi.block.MethodHandleUtil.compose; | ||
| import static io.trino.spi.block.MethodHandleUtil.nativeValueWriter; | ||
|
|
@@ -66,7 +66,7 @@ public final class MapToMapCast | |
| MethodHandle.class, | ||
| MethodHandle.class, | ||
| Type.class, | ||
| BlockPositionEqual.class, | ||
| BlockPositionIsDistinctFrom.class, | ||
| BlockPositionHashCode.class, | ||
| ConnectorSession.class, | ||
| Block.class); | ||
|
|
@@ -116,7 +116,7 @@ public ScalarFunctionImplementation specialize(BoundSignature boundSignature, Fu | |
|
|
||
| MethodHandle keyProcessor = buildProcessor(functionDependencies, fromKeyType, toKeyType, true); | ||
| MethodHandle valueProcessor = buildProcessor(functionDependencies, fromValueType, toValueType, false); | ||
| BlockPositionEqual keyEqual = blockTypeOperators.getEqualOperator(toKeyType); | ||
| BlockPositionIsDistinctFrom keyEqual = blockTypeOperators.getDistinctFromOperator(toKeyType); | ||
| BlockPositionHashCode keyHashCode = blockTypeOperators.getHashCodeOperator(toKeyType); | ||
| MethodHandle target = MethodHandles.insertArguments(METHOD_HANDLE, 0, keyProcessor, valueProcessor, toMapType, keyEqual, keyHashCode); | ||
| return new ChoicesScalarFunctionImplementation(boundSignature, NULLABLE_RETURN, ImmutableList.of(NEVER_NULL), target); | ||
|
|
@@ -238,14 +238,14 @@ public static Block mapCast( | |
| MethodHandle keyProcessFunction, | ||
| MethodHandle valueProcessFunction, | ||
| Type targetType, | ||
| BlockPositionEqual keyEqual, | ||
| BlockPositionIsDistinctFrom keyDistinctOperator, | ||
| BlockPositionHashCode keyHashCode, | ||
| ConnectorSession session, | ||
| Block fromMap) | ||
| { | ||
| checkState(targetType.getTypeParameters().size() == 2, "Expect two type parameters for targetType"); | ||
| Type toKeyType = targetType.getTypeParameters().get(0); | ||
| TypedSet resultKeys = createEqualityTypedSet(toKeyType, keyEqual, keyHashCode, fromMap.getPositionCount() / 2, "map-to-map cast"); | ||
| TypedSet resultKeys = createDistinctTypedSet(toKeyType, keyDistinctOperator, keyHashCode, fromMap.getPositionCount() / 2, "map-to-map cast"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can somewhat test it with: It will fail now. It used to not.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a test. |
||
|
|
||
| // Cast the keys into a new block | ||
| BlockBuilder keyBlockBuilder = toKeyType.createBlockBuilder(null, fromMap.getPositionCount() / 2); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.