|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * You may obtain a copy of the License at |
| 5 | + * |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + */ |
| 14 | +package com.facebook.presto.sql.planner.optimizations; |
| 15 | + |
| 16 | +import com.facebook.presto.spi.plan.Partitioning; |
| 17 | +import com.facebook.presto.spi.relation.VariableReferenceExpression; |
| 18 | +import com.google.common.collect.ImmutableList; |
| 19 | +import com.google.common.collect.ImmutableSet; |
| 20 | +import org.testng.annotations.Test; |
| 21 | + |
| 22 | +import java.util.Optional; |
| 23 | + |
| 24 | +import static com.facebook.presto.common.type.BigintType.BIGINT; |
| 25 | +import static com.facebook.presto.sql.planner.SystemPartitioningHandle.COORDINATOR_DISTRIBUTION; |
| 26 | +import static com.facebook.presto.sql.planner.SystemPartitioningHandle.FIXED_ARBITRARY_DISTRIBUTION; |
| 27 | +import static com.facebook.presto.sql.planner.SystemPartitioningHandle.FIXED_BROADCAST_DISTRIBUTION; |
| 28 | +import static com.facebook.presto.sql.planner.SystemPartitioningHandle.FIXED_HASH_DISTRIBUTION; |
| 29 | +import static com.facebook.presto.sql.planner.SystemPartitioningHandle.SINGLE_DISTRIBUTION; |
| 30 | +import static com.facebook.presto.sql.planner.SystemPartitioningHandle.SOURCE_DISTRIBUTION; |
| 31 | +import static com.facebook.presto.sql.planner.optimizations.PartitioningUtils.isPartitionedOn; |
| 32 | +import static org.testng.Assert.assertFalse; |
| 33 | +import static org.testng.Assert.assertTrue; |
| 34 | + |
| 35 | +public class TestPartitioningUtils |
| 36 | +{ |
| 37 | + @Test |
| 38 | + public void testIsPartitionedOnEmptyArgumentsSingleDistribution() |
| 39 | + { |
| 40 | + Partitioning partitioning = Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()); |
| 41 | + assertTrue(isPartitionedOn(partitioning, ImmutableList.of(), ImmutableSet.of())); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testIsPartitionedOnEmptyArgumentsCoordinatorDistribution() |
| 46 | + { |
| 47 | + Partitioning partitioning = Partitioning.create(COORDINATOR_DISTRIBUTION, ImmutableList.of()); |
| 48 | + assertTrue(isPartitionedOn(partitioning, ImmutableList.of(), ImmutableSet.of())); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void testIsPartitionedOnEmptyArgumentsHashDistribution() |
| 53 | + { |
| 54 | + Partitioning partitioning = Partitioning.create(FIXED_HASH_DISTRIBUTION, ImmutableList.of()); |
| 55 | + assertFalse(isPartitionedOn(partitioning, ImmutableList.of(), ImmutableSet.of())); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void testIsPartitionedOnEmptyArgumentsBroadcastDistribution() |
| 60 | + { |
| 61 | + Partitioning partitioning = Partitioning.create(FIXED_BROADCAST_DISTRIBUTION, ImmutableList.of()); |
| 62 | + assertFalse(isPartitionedOn(partitioning, ImmutableList.of(), ImmutableSet.of())); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + public void testIsPartitionedOnEmptyArgumentsArbitraryDistribution() |
| 67 | + { |
| 68 | + Partitioning partitioning = Partitioning.create(FIXED_ARBITRARY_DISTRIBUTION, ImmutableList.of()); |
| 69 | + assertFalse(isPartitionedOn(partitioning, ImmutableList.of(), ImmutableSet.of())); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void testIsPartitionedOnEmptyArgumentsSourceDistribution() |
| 74 | + { |
| 75 | + Partitioning partitioning = Partitioning.create(SOURCE_DISTRIBUTION, ImmutableList.of()); |
| 76 | + assertFalse(isPartitionedOn(partitioning, ImmutableList.of(), ImmutableSet.of())); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + public void testIsPartitionedOnWithMatchingColumns() |
| 81 | + { |
| 82 | + VariableReferenceExpression column = new VariableReferenceExpression(Optional.empty(), "col", BIGINT); |
| 83 | + Partitioning partitioning = Partitioning.create(FIXED_HASH_DISTRIBUTION, ImmutableList.of(column)); |
| 84 | + assertTrue(isPartitionedOn(partitioning, ImmutableList.of(column), ImmutableSet.of())); |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + public void testIsPartitionedOnWithNonMatchingColumns() |
| 89 | + { |
| 90 | + VariableReferenceExpression column1 = new VariableReferenceExpression(Optional.empty(), "col1", BIGINT); |
| 91 | + VariableReferenceExpression column2 = new VariableReferenceExpression(Optional.empty(), "col2", BIGINT); |
| 92 | + Partitioning partitioning = Partitioning.create(FIXED_HASH_DISTRIBUTION, ImmutableList.of(column1)); |
| 93 | + assertFalse(isPartitionedOn(partitioning, ImmutableList.of(column2), ImmutableSet.of())); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + public void testIsPartitionedOnWithKnownConstants() |
| 98 | + { |
| 99 | + VariableReferenceExpression column = new VariableReferenceExpression(Optional.empty(), "col", BIGINT); |
| 100 | + Partitioning partitioning = Partitioning.create(FIXED_HASH_DISTRIBUTION, ImmutableList.of(column)); |
| 101 | + assertTrue(isPartitionedOn(partitioning, ImmutableList.of(), ImmutableSet.of(column))); |
| 102 | + } |
| 103 | + |
| 104 | + @Test |
| 105 | + public void testIsPartitionedOnEmptyArgumentsSingleDistributionWithColumns() |
| 106 | + { |
| 107 | + VariableReferenceExpression column = new VariableReferenceExpression(Optional.empty(), "col", BIGINT); |
| 108 | + Partitioning partitioning = Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()); |
| 109 | + assertTrue(isPartitionedOn(partitioning, ImmutableList.of(column), ImmutableSet.of())); |
| 110 | + } |
| 111 | + |
| 112 | + @Test |
| 113 | + public void testIsPartitionedOnEmptyArgumentsCoordinatorDistributionWithColumns() |
| 114 | + { |
| 115 | + VariableReferenceExpression column = new VariableReferenceExpression(Optional.empty(), "col", BIGINT); |
| 116 | + Partitioning partitioning = Partitioning.create(COORDINATOR_DISTRIBUTION, ImmutableList.of()); |
| 117 | + assertTrue(isPartitionedOn(partitioning, ImmutableList.of(column), ImmutableSet.of())); |
| 118 | + } |
| 119 | +} |
0 commit comments